1
0
Fork 0
spacetac/src/ui/battle/ActionBar.ts

114 lines
3.3 KiB
TypeScript
Raw Normal View History

2018-05-15 14:57:45 +00:00
/// <reference path="../common/UIContainer.ts" />
2017-09-24 22:23:22 +00:00
module TK.SpaceTac.UI {
2018-05-15 14:57:45 +00:00
/**
* Bar on the border of screen to display all available action icons
*/
export class ActionBar extends UIContainer {
// Link to the parent battleview
2017-09-28 23:18:46 +00:00
battleview: BattleView
// List of action icons
2018-05-15 14:57:45 +00:00
actions: UIContainer
2017-09-28 23:18:46 +00:00
action_icons: ActionIcon[]
// Current ship, whose actions are displayed
2017-09-28 23:18:46 +00:00
ship: Ship | null
2017-02-12 18:54:09 +00:00
// Interactivity
2017-07-20 15:49:47 +00:00
interactive = true;
2017-02-12 18:54:09 +00:00
// Create an empty action bar
constructor(battleview: BattleView) {
2018-05-15 14:57:45 +00:00
super(battleview);
this.battleview = battleview;
this.action_icons = [];
this.ship = null;
2017-03-15 21:40:19 +00:00
battleview.layer_borders.add(this);
2018-03-08 19:16:05 +00:00
let builder = new UIBuilder(battleview, this);
2017-09-28 23:18:46 +00:00
// Group for actions
2018-05-15 14:57:45 +00:00
this.actions = builder.container("actions", 86, 6);
2018-03-08 19:16:05 +00:00
builder.in(this.actions).image("battle-actionbar-actions-background");
2017-09-28 23:18:46 +00:00
2018-05-15 14:57:45 +00:00
this.setInteractivity(false);
2017-02-12 18:54:09 +00:00
}
/**
* Check if an action is selected
*/
hasActionSelected(): boolean {
return any(this.action_icons, icon => icon.selected);
}
2017-02-12 18:54:09 +00:00
/**
* Set the interactivity state
*/
2018-05-15 14:57:45 +00:00
setInteractivity(interactive: boolean) {
if (this.interactive != interactive) {
this.interactive = interactive;
2017-10-01 16:33:48 +00:00
this.battleview.animations.setVisible(this.actions, interactive, 100, 1, 0.3);
}
2017-02-12 18:54:09 +00:00
}
/**
* Called when an action shortcut key is pressed
*/
keyActionPressed(position: number) {
if (this.interactive) {
if (position < 0) {
this.action_icons[this.action_icons.length - 1].processClick();
} else if (position < this.action_icons.length - 1) {
this.action_icons[position].processClick();
2017-02-12 18:54:09 +00:00
}
}
}
2017-09-28 23:18:46 +00:00
/**
* Remove all the action icons
*/
clearAll(): void {
2017-09-28 23:18:46 +00:00
this.action_icons.forEach(action => action.destroy());
this.action_icons = [];
}
2017-09-28 23:18:46 +00:00
/**
* Add an action icon
*/
2017-02-09 00:00:35 +00:00
addAction(ship: Ship, action: BaseAction): ActionIcon {
2017-09-28 23:18:46 +00:00
var icon = new ActionIcon(this, ship, action, this.action_icons.length);
icon.moveTo(this.actions, 74 + this.action_icons.length * 138, 58);
this.action_icons.push(icon);
2015-03-03 00:00:00 +00:00
return icon;
}
/**
* Set the bar to display a given ship
*/
setShip(ship: Ship | null): void {
this.clearAll();
if (ship && this.battleview.player.is(ship.fleet.player) && ship.alive) {
ship.actions.listAll().forEach(action => this.addAction(ship, action));
this.ship = ship;
} else {
this.ship = null;
}
}
2015-02-28 00:00:00 +00:00
// Called by an action icon when the action is selected
actionStarted(): void {
}
// Called by an action icon when the action has been applied
actionEnded(): void {
this.battleview.exitTargettingMode();
2017-09-28 23:18:46 +00:00
this.action_icons.forEach(action => action.refresh());
}
}
2015-01-07 00:00:00 +00:00
}