2015-01-14 00:00:00 +00:00
|
|
|
module SpaceTac.View {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
// Bar with all playing ships, by play order
|
|
|
|
export class ShipList extends Phaser.Group {
|
|
|
|
// Link to the parent battleview
|
|
|
|
battleview: BattleView;
|
|
|
|
|
|
|
|
// List of ship items
|
|
|
|
ships: ShipListItem[];
|
|
|
|
|
2015-02-03 00:00:00 +00:00
|
|
|
// Playing ship
|
|
|
|
playing: ShipListItem;
|
|
|
|
|
2015-02-04 00:00:00 +00:00
|
|
|
// Hovered ship
|
|
|
|
hovered: ShipListItem;
|
|
|
|
|
2015-01-14 00:00:00 +00:00
|
|
|
// Create an empty action bar
|
|
|
|
constructor(battleview: BattleView) {
|
|
|
|
this.battleview = battleview;
|
|
|
|
this.ships = [];
|
2015-02-03 00:00:00 +00:00
|
|
|
this.playing = null;
|
2015-02-04 00:00:00 +00:00
|
|
|
this.hovered = null;
|
2015-01-14 00:00:00 +00:00
|
|
|
|
|
|
|
super(battleview.game, battleview.ui);
|
|
|
|
battleview.ui.add(this);
|
|
|
|
|
|
|
|
if (battleview.battle) {
|
|
|
|
this.setShipsFromBattle(battleview.battle);
|
|
|
|
}
|
|
|
|
this.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the bar status (and position)
|
|
|
|
update() {
|
|
|
|
super.update();
|
|
|
|
|
2015-02-03 00:00:00 +00:00
|
|
|
this.y = 76;
|
2015-01-14 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the action icons
|
|
|
|
clearAll(): void {
|
|
|
|
this.ships.forEach((ship: ShipListItem) => {
|
|
|
|
ship.destroy();
|
|
|
|
});
|
|
|
|
this.ships = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the ship list from a battle
|
|
|
|
setShipsFromBattle(battle: Game.Battle): void {
|
|
|
|
this.clearAll();
|
|
|
|
battle.play_order.forEach((ship: Game.Ship) => {
|
|
|
|
this.addShip(ship);
|
|
|
|
}, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a ship icon
|
|
|
|
addShip(ship: Game.Ship): ShipListItem {
|
|
|
|
var owned = ship.getPlayer() === this.battleview.player;
|
2015-02-03 00:00:00 +00:00
|
|
|
var result = new ShipListItem(this, 0, this.ships.length * 80, ship, owned);
|
2015-01-14 00:00:00 +00:00
|
|
|
this.ships.push(result);
|
|
|
|
this.add(result);
|
|
|
|
return result;
|
|
|
|
}
|
2015-01-28 00:00:00 +00:00
|
|
|
|
|
|
|
// Find an item for a ship
|
|
|
|
// Returns null if not found
|
|
|
|
findItem(ship: Game.Ship): ShipListItem {
|
|
|
|
var found: ShipListItem = null;
|
|
|
|
this.ships.forEach((item: ShipListItem) => {
|
|
|
|
if (item.ship === ship) {
|
|
|
|
found = item;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return found;
|
|
|
|
}
|
2015-02-03 00:00:00 +00:00
|
|
|
|
2015-02-18 00:00:00 +00:00
|
|
|
// Remove a ship from the list
|
|
|
|
removeShip(ship: Game.Ship): void {
|
|
|
|
var item = this.findItem(ship);
|
|
|
|
if (item) {
|
|
|
|
this.ships.splice(this.ships.indexOf(item), 1);
|
|
|
|
item.destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-03 00:00:00 +00:00
|
|
|
// Set the currently playing ship
|
|
|
|
setPlaying(ship: Game.Ship): void {
|
|
|
|
if (this.playing) {
|
|
|
|
this.playing.setPlaying(false);
|
|
|
|
}
|
|
|
|
this.playing = this.findItem(ship);
|
|
|
|
if (this.playing) {
|
|
|
|
this.playing.setPlaying(true);
|
|
|
|
}
|
|
|
|
}
|
2015-02-04 00:00:00 +00:00
|
|
|
|
|
|
|
// Set the currently hovered ship
|
|
|
|
setHovered(ship: Game.Ship): void {
|
|
|
|
if (this.hovered) {
|
|
|
|
this.hovered.setHovered(false);
|
|
|
|
}
|
|
|
|
this.hovered = this.findItem(ship);
|
|
|
|
if (this.hovered) {
|
|
|
|
this.hovered.setHovered(true);
|
|
|
|
}
|
|
|
|
}
|
2015-01-14 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|