2017-09-24 22:23:22 +00:00
|
|
|
module TK.SpaceTac.UI {
|
2017-05-16 23:12:05 +00:00
|
|
|
/**
|
|
|
|
* Tooltip displaying action information
|
|
|
|
*/
|
|
|
|
export class ActionTooltip {
|
|
|
|
/**
|
|
|
|
* Fill the tooltip
|
|
|
|
*/
|
2018-06-06 21:06:04 +00:00
|
|
|
static fill(filler: TooltipBuilder, ship: Ship, action: BaseAction, position?: number): boolean {
|
2017-10-10 22:32:46 +00:00
|
|
|
let builder = filler.styled({ size: 20 });
|
2015-03-03 00:00:00 +00:00
|
|
|
|
2018-02-08 15:16:03 +00:00
|
|
|
let icon = builder.image(`action-${action.code}`);
|
2018-05-15 14:57:45 +00:00
|
|
|
icon.setScale(0.5);
|
2017-10-10 22:32:46 +00:00
|
|
|
|
2018-02-08 15:16:03 +00:00
|
|
|
builder.text(action.getTitle(ship), 150, 0, { size: 24 });
|
2015-03-03 00:00:00 +00:00
|
|
|
|
2018-04-04 16:17:10 +00:00
|
|
|
let unavailable = action.checkCannotBeApplied(ship);
|
|
|
|
if (unavailable != null) {
|
|
|
|
builder.text(unavailable, 150, 40, { color: "#e54d2b" });
|
|
|
|
} else if (action instanceof MoveAction) {
|
|
|
|
let cost = `Cost: 1 power per ${action.distance_per_power}km`;
|
|
|
|
builder.text(cost, 150, 40, { color: "#ffdd4b" });
|
2017-11-29 22:50:40 +00:00
|
|
|
} else {
|
2018-03-05 21:28:06 +00:00
|
|
|
let power_usage = action.getPowerUsage(ship, null);
|
2017-05-16 23:12:05 +00:00
|
|
|
if (power_usage) {
|
2018-04-04 16:17:10 +00:00
|
|
|
let cost = (power_usage > 0) ? `Cost: ${power_usage} power` : `Recover: ${-power_usage} power`;
|
|
|
|
builder.text(cost, 150, 40, { color: "#ffdd4b" });
|
2017-01-19 18:33:56 +00:00
|
|
|
}
|
2017-05-16 23:12:05 +00:00
|
|
|
}
|
2017-01-08 22:42:53 +00:00
|
|
|
|
2018-02-08 15:16:03 +00:00
|
|
|
let cooldown = ship.actions.getCooldown(action);
|
|
|
|
if (cooldown.overheat) {
|
2017-05-22 16:29:04 +00:00
|
|
|
if (cooldown.heat > 0) {
|
2017-12-11 00:31:16 +00:00
|
|
|
builder.text("Cooling down ...", 150, 80, { color: "#d8894d" });
|
2018-04-04 16:17:10 +00:00
|
|
|
} else if (!unavailable && cooldown.willOverheat()) {
|
2017-05-22 16:29:04 +00:00
|
|
|
if (cooldown.cooling > 1) {
|
2017-10-01 18:16:41 +00:00
|
|
|
let turns = cooldown.cooling - 1;
|
2017-12-11 00:31:16 +00:00
|
|
|
builder.text(`Unavailable for ${turns} turn${turns > 1 ? "s" : ""} if used`, 150, 80, { color: "#d8894d" });
|
2017-05-16 23:12:05 +00:00
|
|
|
} else {
|
2017-12-11 00:31:16 +00:00
|
|
|
builder.text("Unavailable until next turn if used", 150, 80, { color: "#d8894d" });
|
2017-05-16 23:12:05 +00:00
|
|
|
}
|
2017-05-16 23:31:23 +00:00
|
|
|
}
|
2018-02-08 15:16:03 +00:00
|
|
|
} else if (action instanceof ToggleAction && ship.actions.isToggled(action)) {
|
2017-12-11 00:31:16 +00:00
|
|
|
builder.text(`Activated`, 150, 80, { color: "#dbe748" });
|
2017-05-16 23:12:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let description = action.getEffectsDescription();
|
|
|
|
if (description) {
|
2017-10-10 22:32:46 +00:00
|
|
|
builder.text(description, 30, 170, { size: 16 });
|
2017-05-16 23:12:05 +00:00
|
|
|
}
|
2017-02-12 18:54:09 +00:00
|
|
|
|
2018-06-06 21:06:04 +00:00
|
|
|
if (typeof position != "undefined") {
|
|
|
|
let shortcut = "";
|
|
|
|
if (action instanceof EndTurnAction) {
|
|
|
|
shortcut = "[ space ]";
|
|
|
|
} else if (position == 9) {
|
|
|
|
shortcut = "[ 0 ]";
|
|
|
|
} else if (position >= 0 && position < 9) {
|
|
|
|
shortcut = `[ ${position + 1} ]`;
|
|
|
|
}
|
|
|
|
if (shortcut) {
|
|
|
|
builder.text(shortcut, 150, 120, { color: "#aaaaaa", size: 12 });
|
|
|
|
}
|
2015-03-03 00:00:00 +00:00
|
|
|
}
|
2018-06-06 21:06:04 +00:00
|
|
|
|
|
|
|
return true;
|
2015-03-03 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|