2015-01-02 00:00:00 +00:00
|
|
|
module SpaceTac.View {
|
2015-01-07 00:00:00 +00:00
|
|
|
"use strict";
|
|
|
|
|
2015-01-02 00:00:00 +00:00
|
|
|
// Bar with all available action icons displayed
|
2015-02-22 00:00:00 +00:00
|
|
|
export class ActionBar extends Phaser.Group {
|
2015-01-02 00:00:00 +00:00
|
|
|
// Link to the parent battleview
|
|
|
|
battleview: BattleView;
|
|
|
|
|
|
|
|
// List of action icons
|
|
|
|
actions: ActionIcon[];
|
|
|
|
|
2015-01-18 00:00:00 +00:00
|
|
|
// Progress bar displaying action points
|
|
|
|
actionpoints: ValueBar;
|
|
|
|
|
2015-03-03 00:00:00 +00:00
|
|
|
// Tooltip to display hovered action info
|
|
|
|
tooltip: ActionTooltip;
|
|
|
|
|
2015-01-22 00:00:00 +00:00
|
|
|
// Current ship, whose actions are displayed
|
|
|
|
ship: Game.Ship;
|
|
|
|
|
2015-02-28 00:00:00 +00:00
|
|
|
// Cancel button
|
|
|
|
cancel: Phaser.Button;
|
|
|
|
|
2015-01-02 00:00:00 +00:00
|
|
|
// Create an empty action bar
|
|
|
|
constructor(battleview: BattleView) {
|
|
|
|
this.battleview = battleview;
|
|
|
|
this.actions = [];
|
2015-01-22 00:00:00 +00:00
|
|
|
this.ship = null;
|
2015-01-02 00:00:00 +00:00
|
|
|
|
2015-02-22 00:00:00 +00:00
|
|
|
super(battleview.game);
|
|
|
|
this.x = 170;
|
|
|
|
this.y = 0;
|
2015-01-02 00:00:00 +00:00
|
|
|
battleview.ui.add(this);
|
|
|
|
|
2015-02-22 00:00:00 +00:00
|
|
|
// Background
|
2015-02-28 00:00:00 +00:00
|
|
|
this.addChild(new Phaser.Image(this.game, 0, 0, "battle-actionbar", 0));
|
2015-02-22 00:00:00 +00:00
|
|
|
|
2015-01-18 00:00:00 +00:00
|
|
|
// Action points progress bar
|
2015-02-28 00:00:00 +00:00
|
|
|
this.actionpoints = new ValueBar(this.game, 119, 76, "battle-actionpointsempty");
|
2015-01-23 00:00:00 +00:00
|
|
|
this.actionpoints.setBarImage("battle-actionpointsfull");
|
2015-01-18 00:00:00 +00:00
|
|
|
this.addChild(this.actionpoints);
|
2015-02-28 00:00:00 +00:00
|
|
|
|
|
|
|
// Cancel button
|
|
|
|
this.cancel = new Phaser.Button(this.game, 849, 8, "battle-actionbar-cancel", () => {
|
|
|
|
this.actionEnded();
|
|
|
|
});
|
|
|
|
this.cancel.visible = false;
|
|
|
|
this.cancel.input.useHandCursor = true;
|
|
|
|
this.addChild(this.cancel);
|
2015-03-03 00:00:00 +00:00
|
|
|
|
|
|
|
// Tooltip
|
|
|
|
this.tooltip = new ActionTooltip(this);
|
|
|
|
this.addChild(this.tooltip);
|
2015-01-02 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the action icons
|
|
|
|
clearAll(): void {
|
2015-01-07 00:00:00 +00:00
|
|
|
this.actions.forEach((action: ActionIcon) => {
|
2015-01-02 00:00:00 +00:00
|
|
|
action.destroy();
|
|
|
|
});
|
|
|
|
this.actions = [];
|
2015-03-05 00:00:00 +00:00
|
|
|
this.tooltip.setAction(null);
|
2015-02-28 00:00:00 +00:00
|
|
|
Animation.fadeOut(this.game, this.cancel, 200);
|
2015-01-02 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add an action icon
|
|
|
|
addAction(ship: Game.Ship, action: Game.BaseAction): ActionIcon {
|
2015-01-29 00:00:00 +00:00
|
|
|
var icon = new ActionIcon(this, 90 + this.actions.length * 62, 2, ship, action);
|
2015-01-02 00:00:00 +00:00
|
|
|
this.actions.push(icon);
|
2015-03-03 00:00:00 +00:00
|
|
|
|
|
|
|
this.tooltip.bringToTop();
|
|
|
|
|
2015-01-02 00:00:00 +00:00
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
|
2015-01-22 00:00:00 +00:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-26 00:00:00 +00:00
|
|
|
// Update fading flags
|
|
|
|
// ap_usage is the consumption of currently selected action
|
|
|
|
updateFadings(ap_usage: number): void {
|
|
|
|
var remaining_ap = this.ship.ap_current.current - ap_usage;
|
|
|
|
if (remaining_ap < 0) {
|
|
|
|
remaining_ap = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.actions.forEach((icon: ActionIcon) => {
|
|
|
|
icon.updateFadingStatus(remaining_ap);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-01-02 00:00:00 +00:00
|
|
|
// Set action icons from selected ship
|
|
|
|
setShip(ship: Game.Ship): void {
|
|
|
|
var action_bar = this;
|
|
|
|
this.clearAll();
|
|
|
|
|
2015-02-16 00:00:00 +00:00
|
|
|
if (ship.getPlayer() === this.battleview.player) {
|
|
|
|
var actions = ship.getAvailableActions();
|
|
|
|
actions.forEach((action: Game.BaseAction) => {
|
|
|
|
action_bar.addAction(ship, action);
|
|
|
|
});
|
2015-01-22 00:00:00 +00:00
|
|
|
|
2015-02-16 00:00:00 +00:00
|
|
|
this.ship = ship;
|
2015-02-28 00:00:00 +00:00
|
|
|
this.game.tweens.create(this).to({"alpha": 1}, 400).start();
|
2015-02-16 00:00:00 +00:00
|
|
|
} else {
|
|
|
|
this.ship = null;
|
2015-02-28 00:00:00 +00:00
|
|
|
this.game.tweens.create(this).to({"alpha": 0.5}, 400).start();
|
2015-02-16 00:00:00 +00:00
|
|
|
}
|
2015-01-22 00:00:00 +00:00
|
|
|
|
|
|
|
this.updateActionPoints();
|
|
|
|
}
|
|
|
|
|
2015-02-28 00:00:00 +00:00
|
|
|
// Called by an action icon when the action is selected
|
|
|
|
actionStarted(): void {
|
|
|
|
Animation.fadeIn(this.game, this.cancel, 200);
|
|
|
|
}
|
|
|
|
|
2015-01-22 00:00:00 +00:00
|
|
|
// Called by an action icon when the action has been applied
|
|
|
|
actionEnded(): void {
|
|
|
|
this.updateActionPoints();
|
2015-01-29 00:00:00 +00:00
|
|
|
this.actions.forEach((action: ActionIcon) => {
|
2015-02-04 00:00:00 +00:00
|
|
|
action.resetState();
|
2015-01-29 00:00:00 +00:00
|
|
|
});
|
2015-02-04 00:00:00 +00:00
|
|
|
this.battleview.exitTargettingMode();
|
2015-02-28 00:00:00 +00:00
|
|
|
Animation.fadeOut(this.game, this.cancel, 200);
|
2015-01-02 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-07 00:00:00 +00:00
|
|
|
}
|