diff --git a/src/scripts/view/battle/ActionIcon.ts b/src/scripts/view/battle/ActionIcon.ts index 808e1a6..c52e1ff 100644 --- a/src/scripts/view/battle/ActionIcon.ts +++ b/src/scripts/view/battle/ActionIcon.ts @@ -11,6 +11,9 @@ module SpaceTac.View { // Related game action action: Game.BaseAction; + // Current targetting + private targetting: Targetting; + // Create an icon for a single ship action constructor(bar: ActionBar, x: number, y:number, ship: Game.Ship, action: Game.BaseAction) { this.battleview = bar.battleview; @@ -29,15 +32,25 @@ module SpaceTac.View { processClick() { console.log("Action started", this.action); - var targetting = this.battleview.enterTargettingMode(); - targetting.targetSelected.add(this.processTarget, this); + this.targetting = this.battleview.enterTargettingMode(); + this.targetting.setSource(this.battleview.arena.findShipSprite(this.ship)); + this.targetting.targetSelected.add(this.processSelection, this); + this.targetting.targetHovered.add(this.processHover, this); } - // Receive a target for the action - processTarget(target: Game.Target) { + // Called when a target is hovered + // This will check the target against current action and adjust it if needed + processHover(target: Game.Target) { + target = this.action.checkTarget(this.battleview.battle, this.ship, target); + this.targetting.setTarget(target, false); + } + + // Called when a target is selected + processSelection(target: Game.Target) { console.log("Action target", this.action, target); this.action.apply(this.battleview.battle, this.ship, target); + this.battleview.exitTargettingMode(); } } } \ No newline at end of file diff --git a/src/scripts/view/battle/Arena.ts b/src/scripts/view/battle/Arena.ts index 8337e60..bac4dd6 100644 --- a/src/scripts/view/battle/Arena.ts +++ b/src/scripts/view/battle/Arena.ts @@ -21,7 +21,7 @@ module SpaceTac.View { super(battleview.game); var background = new Phaser.Button(battleview.game, 0, 0, 'ui-arena-background'); - background.scale.set(5, 5); + background.scale.set(20, 10); this.background = background; // Capture clicks on background diff --git a/src/scripts/view/battle/BattleView.ts b/src/scripts/view/battle/BattleView.ts index 9ce8be8..ff16d3b 100644 --- a/src/scripts/view/battle/BattleView.ts +++ b/src/scripts/view/battle/BattleView.ts @@ -118,7 +118,6 @@ module SpaceTac.View { // Method called when cursor moves in space cursorInSpace(x: number, y: number): void { if (!this.ship_hovered) { - console.log("In space", x, y); if (this.targetting) { this.targetting.setTargetSpace(x, y); } diff --git a/src/scripts/view/battle/Targetting.ts b/src/scripts/view/battle/Targetting.ts index a9c5583..2d2e9ad 100644 --- a/src/scripts/view/battle/Targetting.ts +++ b/src/scripts/view/battle/Targetting.ts @@ -5,6 +5,9 @@ module SpaceTac.View { // Access to the parent battle view private battleview: BattleView; + // Source of the targetting + private source: PIXI.Sprite; + // Current target private target: Game.Target; @@ -14,29 +17,76 @@ module SpaceTac.View { // Signal to receive targetting events targetSelected: Phaser.Signal; + // Target visual line + line: Phaser.Graphics; + // Create a default targetting mode constructor(battleview: BattleView) { this.battleview = battleview; this.targetHovered = new Phaser.Signal(); this.targetSelected = new Phaser.Signal(); + + // Visual effects + if (battleview) { + this.line = new Phaser.Graphics(battleview.game, 0, 0); + battleview.arena.add(this.line); + } + + this.source = null; + this.target = null; } // Destructor destroy(): void { this.targetHovered.dispose(); this.targetSelected.dispose(); + if (this.line) { + this.line.destroy(); + } + } + + // Update visual effects for current targetting + update(): void { + if (this.battleview) { + if (this.source) { + this.line.clear(); + this.line.lineStyle(3, 0xFFFFFF); + this.line.moveTo(this.source.x, this.source.y); + this.line.lineTo(this.target.x, this.target.y); + this.line.visible = true; + } else { + this.line.visible = false; + } + } + } + + // Set the source sprite for the targetting (for visual effects) + setSource(sprite: PIXI.Sprite) { + this.source = sprite; + } + + // Set a target from a target object + setTarget(target: Game.Target, dispatch: boolean = true):void { + this.target = target; + if (dispatch) { + this.targetHovered.dispatch(this.target); + } + this.update(); + } + + // Set no target + unsetTarget(dispatch: boolean = true): void { + this.setTarget(null, dispatch); } // Set the current target ship (when hovered) - setTargetShip(ship: Game.Ship): void { - this.target = Game.Target.newFromShip(ship); - this.targetHovered.dispatch(this.target); + setTargetShip(ship: Game.Ship, dispatch: boolean = true): void { + this.setTarget(Game.Target.newFromShip(ship), dispatch); } // Set the current target in space (when hovered) - setTargetSpace(x: number, y: number): void { - this.target = Game.Target.newFromLocation(x, y); - this.targetHovered.dispatch(this.target); + setTargetSpace(x: number, y: number, dispatch: boolean = true): void { + this.setTarget(Game.Target.newFromLocation(x, y)); } // Validate the current target (when clicked)