From ca4f493b65011edbeb0fe097e1f10ece1617db31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Thu, 22 Jan 2015 01:00:00 +0100 Subject: [PATCH] Added action points display in action bar --- src/scripts/view/battle/ActionBar.ts | 24 +++++++++++++++++++++++- src/scripts/view/battle/ActionIcon.ts | 4 ++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/scripts/view/battle/ActionBar.ts b/src/scripts/view/battle/ActionBar.ts index a457e6d..b926c26 100644 --- a/src/scripts/view/battle/ActionBar.ts +++ b/src/scripts/view/battle/ActionBar.ts @@ -12,10 +12,14 @@ module SpaceTac.View { // Progress bar displaying action points actionpoints: ValueBar; + // Current ship, whose actions are displayed + ship: Game.Ship; + // Create an empty action bar constructor(battleview: BattleView) { this.battleview = battleview; this.actions = []; + this.ship = null; super(battleview.game, 170, 0, "ui-battle-actionbar"); battleview.ui.add(this); @@ -23,7 +27,6 @@ module SpaceTac.View { // Action points progress bar this.actionpoints = new ValueBar(battleview.game, 119, 76, "ui-battle-actionpointsempty"); this.actionpoints.setBarImage("ui-battle-actionpointsfull"); - this.actionpoints.setValue(50, 100); this.addChild(this.actionpoints); } @@ -42,6 +45,16 @@ module SpaceTac.View { return icon; } + // Update the action points indicator + updateActionPoints(): void { + if (this.ship) { + this.actionpoints.setValue(this.ship.ap_current.current, this.ship.ap_current.maximal); + this.actionpoints.visible = true; + } else { + this.actionpoints.visible = false; + } + } + // Set action icons from selected ship setShip(ship: Game.Ship): void { var action_bar = this; @@ -51,6 +64,15 @@ module SpaceTac.View { actions.forEach((action: Game.BaseAction) => { action_bar.addAction(ship, action); }); + + this.ship = ship; + + this.updateActionPoints(); + } + + // Called by an action icon when the action has been applied + actionEnded(): void { + this.updateActionPoints(); } } } diff --git a/src/scripts/view/battle/ActionIcon.ts b/src/scripts/view/battle/ActionIcon.ts index 006de7a..3e81082 100644 --- a/src/scripts/view/battle/ActionIcon.ts +++ b/src/scripts/view/battle/ActionIcon.ts @@ -3,6 +3,8 @@ module SpaceTac.View { // Icon to activate a ship capability (move, fire...) export class ActionIcon extends Phaser.Button { + // Link to the parent bar + bar: ActionBar; // Link to the parent battle view battleview: BattleView; @@ -18,6 +20,7 @@ module SpaceTac.View { // Create an icon for a single ship action constructor(bar: ActionBar, x: number, y: number, ship: Game.Ship, action: Game.BaseAction) { + this.bar = bar; this.battleview = bar.battleview; this.ship = ship; this.action = action; @@ -64,6 +67,7 @@ module SpaceTac.View { if (this.action.apply(this.battleview.battle, this.ship, target)) { this.battleview.exitTargettingMode(); + this.bar.actionEnded(); } } }