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

72 lines
2.6 KiB
TypeScript
Raw Normal View History

/// <reference path="../common/UIDialog.ts" />
2017-05-25 23:09:29 +00:00
2017-09-24 22:23:22 +00:00
module TK.SpaceTac.UI {
2017-03-12 23:32:41 +00:00
/**
* Dialog to display battle outcome
*/
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) {
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) {
2018-04-12 22:03:29 +00:00
let button = this.addButton(x, 885, action, "common-dialog-textbutton", 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 && this.player.is(outcome.winner.player);
2017-03-12 23:32:41 +00:00
this.clearContent();
2017-03-12 23:32:41 +00:00
this.addImage(747, 180, victory ? "battle-outcome-title-victory" : "battle-outcome-title-defeat");
2017-03-15 21:40:19 +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();
});
} else if (victory) {
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 {
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-03-15 21:40:19 +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-03-12 23:32:41 +00:00
}
}
}
}