2017-08-21 22:01:11 +00:00
|
|
|
/// <reference path="../common/UIDialog.ts" />
|
2017-05-25 23:09:29 +00:00
|
|
|
|
2017-03-12 23:32:41 +00:00
|
|
|
module TS.SpaceTac.UI {
|
|
|
|
/**
|
|
|
|
* Dialog to display battle outcome
|
|
|
|
*/
|
2017-08-21 22:01:11 +00:00
|
|
|
export class OutcomeDialog extends UIDialog {
|
|
|
|
battleview: BattleView
|
|
|
|
player: Player
|
|
|
|
outcome: BattleOutcome
|
|
|
|
stats: BattleStats
|
|
|
|
|
2017-05-25 23:09:29 +00:00
|
|
|
constructor(parent: BattleView, player: Player, outcome: BattleOutcome, stats: BattleStats) {
|
2017-08-21 22:01:11 +00:00
|
|
|
super(parent);
|
|
|
|
|
|
|
|
this.battleview = parent;
|
|
|
|
this.player = player;
|
|
|
|
this.outcome = outcome;
|
|
|
|
this.stats = stats;
|
|
|
|
|
|
|
|
this.refreshContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shortcut to add a single action button at the bottom of dialog
|
|
|
|
*/
|
|
|
|
addActionButton(x: number, text: string, tooltip: string, action: Function) {
|
|
|
|
let button = this.addButton(x, 885, action, "common-dialog-textbutton", 0, 1, tooltip);
|
|
|
|
button.addChild(this.addText(0, 0, text, "#d9e0e5"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Refresh the whole dialog
|
|
|
|
*/
|
|
|
|
refreshContent(): void {
|
|
|
|
let parent = this.battleview;
|
|
|
|
let outcome = this.outcome;
|
|
|
|
let victory = outcome.winner && (outcome.winner.player == this.player);
|
2017-03-12 23:32:41 +00:00
|
|
|
|
2017-08-21 22:01:11 +00:00
|
|
|
this.clearContent();
|
2017-03-12 23:32:41 +00:00
|
|
|
|
2017-08-21 22:01:11 +00:00
|
|
|
this.addImage(747, 180, victory ? "battle-outcome-title-victory" : "battle-outcome-title-defeat");
|
2017-03-15 21:40:19 +00:00
|
|
|
|
2017-08-21 22:01:11 +00:00
|
|
|
this.addText(815, 320, "You", "#ffffff", 20);
|
|
|
|
this.addText(1015, 320, "Enemy", "#ffffff", 20);
|
|
|
|
this.stats.getImportant(10).forEach((stat, index) => {
|
|
|
|
this.addText(530, 364 + 40 * index, stat.name, "#ffffff", 20);
|
|
|
|
this.addText(815, 364 + 40 * index, stat.attacker.toString(), "#8ba883", 20, true);
|
|
|
|
this.addText(1015, 364 + 40 * index, stat.defender.toString(), "#cd6767", 20, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!this.battleview.session.hasUniverse()) {
|
|
|
|
this.addActionButton(747, "Main menu", "Exit the battle and go back to the main menu", () => {
|
2017-03-12 23:32:41 +00:00
|
|
|
parent.exitBattle();
|
2017-08-21 22:01:11 +00:00
|
|
|
});
|
|
|
|
} else if (victory) {
|
|
|
|
if (this.outcome.loot.length) {
|
|
|
|
this.addActionButton(535, "Loot equipment", "Open character sheet to loot equipment from defeated fleet", () => {
|
|
|
|
let sheet = new CharacterSheet(this.view, undefined, undefined, () => {
|
|
|
|
sheet.destroy(true);
|
|
|
|
this.refreshContent();
|
|
|
|
});
|
|
|
|
sheet.show(this.player.fleet.ships[0], false);
|
|
|
|
sheet.setLoot(outcome.loot);
|
|
|
|
this.view.add.existing(sheet);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.addActionButton(957, "Back to map", "Exit the battle and go back to the map", () => {
|
|
|
|
parent.exitBattle();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.addActionButton(747, "Back to map", "Exit the battle and go back to the map", () => {
|
|
|
|
parent.exitBattle();
|
|
|
|
});
|
|
|
|
}
|
2017-03-12 23:32:41 +00:00
|
|
|
} else {
|
2017-08-21 22:01:11 +00:00
|
|
|
this.addActionButton(535, "Revert battle", "Go back to where the fleet was before the battle happened", () => {
|
2017-03-14 22:28:07 +00:00
|
|
|
parent.revertBattle();
|
2017-08-21 22:01:11 +00:00
|
|
|
});
|
2017-03-15 21:40:19 +00:00
|
|
|
|
2017-08-21 22:01:11 +00:00
|
|
|
this.addActionButton(957, "Main menu", "Quit the game, and go back to main menu", () => {
|
2017-03-12 23:32:41 +00:00
|
|
|
parent.gameui.quitGame();
|
2017-08-21 22:01:11 +00:00
|
|
|
});
|
2017-03-12 23:32:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|