From b3bb84b81a908019d9ca58c0662b8d367fb454be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Tue, 3 Mar 2015 01:00:00 +0100 Subject: [PATCH] Added range hint display on actions --- src/scripts/game/actions/BaseAction.ts | 9 ++++ src/scripts/game/actions/MoveAction.ts | 4 ++ src/scripts/view/battle/ActionIcon.ts | 14 ++++- src/scripts/view/battle/Arena.ts | 7 +++ src/scripts/view/battle/RangeHint.ts | 72 ++++++++++++++++++++++++++ 5 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 src/scripts/view/battle/RangeHint.ts diff --git a/src/scripts/game/actions/BaseAction.ts b/src/scripts/game/actions/BaseAction.ts index 40f8f14..48bd8f7 100644 --- a/src/scripts/game/actions/BaseAction.ts +++ b/src/scripts/game/actions/BaseAction.ts @@ -44,6 +44,15 @@ module SpaceTac.Game { } } + // Get the range of this action + getRangeRadius(ship: Ship): number { + if (this.equipment) { + return this.equipment.distance; + } else { + return 0; + } + } + // Method to check if a target is applicable for this action // Will call checkLocationTarget or checkShipTarget by default checkTarget(battle: Battle, ship: Ship, target: Target): Target { diff --git a/src/scripts/game/actions/MoveAction.ts b/src/scripts/game/actions/MoveAction.ts index 576b95e..a35650e 100644 --- a/src/scripts/game/actions/MoveAction.ts +++ b/src/scripts/game/actions/MoveAction.ts @@ -28,6 +28,10 @@ module SpaceTac.Game { return this.equipment.ap_usage * distance / this.equipment.distance; } + getRangeRadius(ship: Ship): number { + return ship.ap_current.current * this.equipment.distance / this.equipment.ap_usage; + } + checkLocationTarget(battle: Battle, ship: Ship, target: Target): Target { // TODO Should forbid to move too much near another ship var max_distance = this.equipment.distance * ship.ap_current.current / this.equipment.ap_usage; diff --git a/src/scripts/view/battle/ActionIcon.ts b/src/scripts/view/battle/ActionIcon.ts index 0ec9ff0..7cfd766 100644 --- a/src/scripts/view/battle/ActionIcon.ts +++ b/src/scripts/view/battle/ActionIcon.ts @@ -62,7 +62,15 @@ module SpaceTac.View { // Click process this.onInputUp.add(() => { this.processClick(); - }, this); + }); + + // Range hints on hover + this.onInputOver.add(() => { + this.battleview.arena.range_hint.setSecondary(this.ship, this.action); + }); + this.onInputOut.add(() => { + this.battleview.arena.range_hint.clearSecondary(); + }); // Initialize this.updateActiveStatus(); @@ -80,6 +88,9 @@ module SpaceTac.View { this.bar.actionEnded(); this.bar.actionStarted(); + // Update range hint + this.battleview.arena.range_hint.setPrimary(this.ship, this.action); + // Update fading statuses this.bar.updateFadings(this.action.getActionPointsUsage(this.battleview.battle, this.ship, null)); @@ -126,6 +137,7 @@ module SpaceTac.View { this.layer_active.tint = 0xFFFFFF; this.updateActiveStatus(); this.updateFadingStatus(this.ship.ap_current.current); + this.battleview.arena.range_hint.clearPrimary(); } // Update the active status, from the action canBeUsed result diff --git a/src/scripts/view/battle/Arena.ts b/src/scripts/view/battle/Arena.ts index cb2efd7..39bd4a3 100644 --- a/src/scripts/view/battle/Arena.ts +++ b/src/scripts/view/battle/Arena.ts @@ -7,6 +7,9 @@ module SpaceTac.View { // Arena background background: Phaser.Button; + // Hint for weapon or move range + range_hint: RangeHint; + // Input callback to receive mouse move events private input_callback: any; @@ -27,6 +30,7 @@ module SpaceTac.View { this.ship_sprites = []; this.playing = null; this.hovered = null; + this.range_hint = null; super(battleview.game); @@ -52,6 +56,9 @@ module SpaceTac.View { this.position.set(196, 100); this.addChild(this.background); + this.range_hint = new RangeHint(this); + this.addChild(this.range_hint); + this.init(); } diff --git a/src/scripts/view/battle/RangeHint.ts b/src/scripts/view/battle/RangeHint.ts new file mode 100644 index 0000000..3cf5117 --- /dev/null +++ b/src/scripts/view/battle/RangeHint.ts @@ -0,0 +1,72 @@ +module SpaceTac.View { + "use strict"; + + // Graphical hints for movement and weapon range + export class RangeHint extends Phaser.Group { + // Link to the arena + parent: Arena; + + // Displayed circle + circle: Phaser.Graphics; + + // Stored information of primary circle, when secondary one overrides it + primary: Phaser.Circle; + + constructor(parent: Arena) { + super(parent.game, parent); + + this.parent = parent; + + this.circle = new Phaser.Graphics(this.game, 0, 0); + this.addChild(this.circle); + + this.primary = null; + } + + // Clear the primary hint + clearPrimary(): void { + this.primary = null; + this.circle.visible = false; + } + + // Clear the secondary hint + clearSecondary(): void { + if (this.primary) { + this.draw(this.primary); + } else { + this.circle.visible = false; + } + } + + // Set currently selected action + setPrimary(ship: Game.Ship, action: Game.BaseAction): void { + var radius = action.getRangeRadius(ship); + if (radius) { + this.primary = new Phaser.Circle(ship.arena_x, ship.arena_y, radius * 2); + this.draw(this.primary); + } else { + this.circle.visible = false; + } + } + + // Set currently hovered action + setSecondary(ship: Game.Ship, action: Game.BaseAction): void { + var radius = action.getRangeRadius(ship); + if (radius) { + this.draw(new Phaser.Circle(ship.arena_x, ship.arena_y, radius * 2)); + } else { + this.circle.visible = false; + } + } + + // Draw a circle, hinting available range + private draw(circle: Phaser.Circle): void { + this.circle.clear(); + this.circle.lineStyle(5, 0x862080, 0.4); + this.circle.beginFill(0xD860D0, 0.2); + this.circle.drawCircle(circle.x, circle.y, circle.diameter); + this.circle.endFill(); + this.circle.visible = true; + } + } +}