/// module TK.SpaceTac.UI { /** * Bar on the border of screen to display all available action icons */ export class ActionBar extends UIContainer { // Link to the parent battleview battleview: BattleView // List of action icons actions: UIContainer action_icons: ActionIcon[] // Current ship, whose actions are displayed ship: Ship | null // Interactivity interactive = true; // Create an empty action bar constructor(battleview: BattleView) { super(battleview); this.battleview = battleview; this.action_icons = []; this.ship = null; battleview.layer_borders.add(this); let builder = new UIBuilder(battleview, this); // Group for actions this.actions = builder.container("actions", 86, 6); builder.in(this.actions).image("battle-actionbar-actions-background"); this.setInteractivity(false); } /** * Check if an action is selected */ hasActionSelected(): boolean { return any(this.action_icons, icon => icon.selected); } /** * Set the interactivity state */ setInteractivity(interactive: boolean) { if (this.interactive != interactive) { this.interactive = interactive; this.battleview.animations.setVisible(this.actions, interactive, 100, 1, 0.3); } } /** * 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(); } } } /** * Remove all the action icons */ clearAll(): void { this.action_icons.forEach(action => action.destroy()); this.action_icons = []; } /** * Add an action icon */ addAction(ship: Ship, action: BaseAction): ActionIcon { 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); 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; } } // 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(); this.action_icons.forEach(action => action.refresh()); } } }