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

81 lines
3.4 KiB
TypeScript
Raw Normal View History

2017-02-09 00:00:35 +00:00
module TS.SpaceTac.UI {
2015-03-03 00:00:00 +00:00
// Tooltip to display action information
export class ActionTooltip extends Phaser.Sprite {
2017-02-12 18:54:09 +00:00
bar: ActionBar;
2017-01-08 22:42:53 +00:00
icon: Phaser.Image | null;
main_title: Phaser.Text;
sub_title: Phaser.Text;
cost: Phaser.Text;
description: Phaser.Text;
2017-02-12 18:54:09 +00:00
shortcut: Phaser.Text;
2015-03-03 00:00:00 +00:00
constructor(parent: ActionBar) {
super(parent.game, 0, 0, "battle-action-tooltip");
2017-02-12 18:54:09 +00:00
this.bar = parent;
2015-03-03 00:00:00 +00:00
this.visible = false;
2017-01-08 22:42:53 +00:00
this.icon = null;
2017-01-11 00:38:08 +00:00
this.main_title = new Phaser.Text(this.game, 325, 20, "", { font: "24pt Arial", fill: "#ffffff" });
2017-01-08 22:42:53 +00:00
this.main_title.anchor.set(0.5, 0);
this.addChild(this.main_title);
2017-01-11 00:38:08 +00:00
this.sub_title = new Phaser.Text(this.game, 325, 60, "", { font: "22pt Arial", fill: "#ffffff" });
2017-01-08 22:42:53 +00:00
this.sub_title.anchor.set(0.5, 0);
this.addChild(this.sub_title);
2017-01-11 00:38:08 +00:00
this.cost = new Phaser.Text(this.game, 325, 100, "", { font: "20pt Arial", fill: "#ffff00" });
2017-01-08 22:42:53 +00:00
this.cost.anchor.set(0.5, 0);
this.addChild(this.cost);
this.description = new Phaser.Text(this.game, 21, 144, "", { font: "14pt Arial", fill: "#ffffff" });
this.description.wordWrap = true;
this.description.wordWrapWidth = 476;
this.addChild(this.description);
2017-02-12 18:54:09 +00:00
this.shortcut = new Phaser.Text(this.game, this.width - 5, this.height - 5, "", { font: "12pt Arial", fill: "#aaaaaa" });
this.shortcut.anchor.set(1, 1);
this.addChild(this.shortcut);
2015-03-03 00:00:00 +00:00
}
// Set current action to display, null to hide
2017-03-09 17:11:00 +00:00
setAction(action: ActionIcon | null): void {
2015-03-03 00:00:00 +00:00
if (action) {
2017-01-08 22:42:53 +00:00
if (this.icon) {
this.icon.destroy(true);
}
this.icon = new Phaser.Image(this.game, 76, 72, "battle-actions-" + action.action.code);
this.icon.anchor.set(0.5, 0.5);
this.icon.scale.set(0.44, 0.44);
2017-01-08 22:42:53 +00:00
this.addChild(this.icon);
this.position.set(action.x, action.y + action.height + 44);
2017-01-08 22:42:53 +00:00
this.main_title.setText(action.action.equipment ? action.action.equipment.name : action.action.name);
this.sub_title.setText(action.action.equipment ? action.action.name : "");
2017-02-09 00:00:35 +00:00
if (action.action instanceof MoveAction) {
this.cost.setText(`Cost: 1 power per ${action.action.distance_per_power}km`);
} else {
let cost = action.action.getActionPointsUsage(action.ship, null);
this.cost.setText(cost == 0 ? "" : `Cost: ${cost} power`);
}
this.description.setText(action.action.getEffectsDescription());
2017-01-08 22:42:53 +00:00
let position = this.bar.action_icons.indexOf(action);
2017-02-12 18:54:09 +00:00
if (action.action instanceof EndTurnAction) {
this.shortcut.setText("[ space ]");
} else if (position == 9) {
this.shortcut.setText("[ 0 ]");
} else if (position >= 0 && position < 9) {
this.shortcut.setText(`[ ${position + 1} ]`);
} else {
this.shortcut.setText("");
}
this.bar.battleview.animations.show(this, 200, 0.9);
2015-03-03 00:00:00 +00:00
} else {
this.bar.battleview.animations.hide(this, 200);
2015-03-03 00:00:00 +00:00
}
}
}
}