2017-02-09 00:00:35 +00:00
|
|
|
module TS.SpaceTac.UI {
|
2015-01-14 00:00:00 +00:00
|
|
|
// Bar with all playing ships, by play order
|
2017-01-08 22:04:07 +00:00
|
|
|
export class ShipList extends Phaser.Image {
|
2015-01-14 00:00:00 +00:00
|
|
|
// Link to the parent battleview
|
|
|
|
battleview: BattleView;
|
|
|
|
|
|
|
|
// List of ship items
|
2017-05-14 21:03:03 +00:00
|
|
|
ships_container: Phaser.Group;
|
2015-01-14 00:00:00 +00:00
|
|
|
ships: ShipListItem[];
|
|
|
|
|
2015-02-03 00:00:00 +00:00
|
|
|
// Playing ship
|
2017-03-09 17:11:00 +00:00
|
|
|
playing: ShipListItem | null;
|
2015-02-03 00:00:00 +00:00
|
|
|
|
2015-02-04 00:00:00 +00:00
|
|
|
// Hovered ship
|
2017-03-09 17:11:00 +00:00
|
|
|
hovered: ShipListItem | null;
|
2015-02-04 00:00:00 +00:00
|
|
|
|
2017-05-14 21:03:03 +00:00
|
|
|
// Info button
|
|
|
|
info_button: Phaser.Button;
|
|
|
|
|
2015-01-14 00:00:00 +00:00
|
|
|
// Create an empty action bar
|
|
|
|
constructor(battleview: BattleView) {
|
2017-01-12 23:57:28 +00:00
|
|
|
super(battleview.game, 0, 133, "battle-shiplist-background");
|
2016-10-26 21:15:04 +00:00
|
|
|
|
2015-01-14 00:00:00 +00:00
|
|
|
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
|
|
|
|
2017-05-14 21:03:03 +00:00
|
|
|
this.info_button = new Phaser.Button(this.game, 0, 0, "battle-shiplist-info-button");
|
|
|
|
this.info_button.position.set(0, this.height - this.info_button.height);
|
|
|
|
this.addChild(this.info_button);
|
|
|
|
|
2017-03-15 21:40:19 +00:00
|
|
|
battleview.layer_borders.add(this);
|
2015-01-14 00:00:00 +00:00
|
|
|
|
|
|
|
if (battleview.battle) {
|
|
|
|
this.setShipsFromBattle(battleview.battle);
|
|
|
|
}
|
2015-04-26 19:09:52 +00:00
|
|
|
}
|
|
|
|
|
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
|
2017-02-09 00:00:35 +00:00
|
|
|
setShipsFromBattle(battle: Battle): void {
|
2015-01-14 00:00:00 +00:00
|
|
|
this.clearAll();
|
2017-02-09 00:00:35 +00:00
|
|
|
battle.play_order.forEach((ship: Ship) => {
|
2015-01-14 00:00:00 +00:00
|
|
|
this.addShip(ship);
|
|
|
|
}, this);
|
2015-04-26 17:15:45 +00:00
|
|
|
this.updateItemsLocation();
|
2015-01-14 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add a ship icon
|
2017-02-09 00:00:35 +00:00
|
|
|
addShip(ship: Ship): ShipListItem {
|
2015-01-14 00:00:00 +00:00
|
|
|
var owned = ship.getPlayer() === this.battleview.player;
|
2015-04-26 17:15:45 +00:00
|
|
|
var result = new ShipListItem(this, -200, 0, ship, owned);
|
2015-01-14 00:00:00 +00:00
|
|
|
this.ships.push(result);
|
2017-01-08 22:04:07 +00:00
|
|
|
this.addChild(result);
|
2015-01-14 00:00:00 +00:00
|
|
|
return result;
|
|
|
|
}
|
2015-01-28 00:00:00 +00:00
|
|
|
|
|
|
|
// Find an item for a ship
|
|
|
|
// Returns null if not found
|
2017-03-09 17:11:00 +00:00
|
|
|
findItem(ship: Ship): ShipListItem | null {
|
|
|
|
var found: ShipListItem | null = null;
|
2015-01-28 00:00:00 +00:00
|
|
|
this.ships.forEach((item: ShipListItem) => {
|
|
|
|
if (item.ship === ship) {
|
|
|
|
found = item;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return found;
|
|
|
|
}
|
2015-02-03 00:00:00 +00:00
|
|
|
|
2015-04-26 17:15:45 +00:00
|
|
|
// Find the play position in play_order for a given ship (0 is currently playing)
|
2017-02-09 00:00:35 +00:00
|
|
|
findPlayPosition(ship: Ship): number {
|
2015-04-26 17:15:45 +00:00
|
|
|
var battle = this.battleview.battle;
|
|
|
|
var idx = battle.play_order.indexOf(ship);
|
2017-03-09 17:11:00 +00:00
|
|
|
var diff = idx - (battle.playing_ship_index || 0);
|
2015-04-26 17:15:45 +00:00
|
|
|
if (diff < 0) {
|
|
|
|
diff += battle.play_order.length;
|
|
|
|
}
|
|
|
|
return diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the locations of all items
|
|
|
|
updateItemsLocation(animate: boolean = true): void {
|
|
|
|
this.ships.forEach((item: ShipListItem) => {
|
|
|
|
var position = this.findPlayPosition(item.ship);
|
|
|
|
if (position === 0) {
|
2017-05-14 21:03:03 +00:00
|
|
|
item.moveTo(18, 15 - this.y, animate);
|
2015-04-26 17:15:45 +00:00
|
|
|
} else {
|
2017-05-14 21:03:03 +00:00
|
|
|
item.moveTo(0, 33 + position * 99 - this.y, animate);
|
2015-04-26 17:15:45 +00:00
|
|
|
}
|
2017-01-08 22:04:07 +00:00
|
|
|
this.setChildIndex(item, position);
|
2015-04-26 17:15:45 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-02-18 00:00:00 +00:00
|
|
|
// Remove a ship from the list
|
2017-02-09 00:00:35 +00:00
|
|
|
markAsDead(ship: Ship): void {
|
2015-02-18 00:00:00 +00:00
|
|
|
var item = this.findItem(ship);
|
|
|
|
if (item) {
|
2017-01-12 00:37:05 +00:00
|
|
|
item.alpha = 0.5;
|
2015-02-18 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-03 00:00:00 +00:00
|
|
|
// Set the currently playing ship
|
2017-03-09 17:11:00 +00:00
|
|
|
setPlaying(ship: Ship | null): void {
|
|
|
|
if (ship) {
|
|
|
|
this.playing = this.findItem(ship);
|
|
|
|
} else {
|
|
|
|
this.playing = null;
|
|
|
|
}
|
2015-04-26 17:15:45 +00:00
|
|
|
this.updateItemsLocation();
|
2015-02-03 00:00:00 +00:00
|
|
|
}
|
2015-02-04 00:00:00 +00:00
|
|
|
|
|
|
|
// Set the currently hovered ship
|
2017-03-09 17:11:00 +00:00
|
|
|
setHovered(ship: Ship | null): void {
|
2015-02-04 00:00:00 +00:00
|
|
|
if (this.hovered) {
|
|
|
|
this.hovered.setHovered(false);
|
2017-03-09 17:11:00 +00:00
|
|
|
this.hovered = null;
|
2015-02-04 00:00:00 +00:00
|
|
|
}
|
2017-03-09 17:11:00 +00:00
|
|
|
if (ship) {
|
|
|
|
this.hovered = this.findItem(ship);
|
|
|
|
if (this.hovered) {
|
|
|
|
this.hovered.setHovered(true);
|
|
|
|
}
|
2015-02-04 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-14 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|