Show power gain on action icons
This commit is contained in:
parent
09d6e897dc
commit
9543bb0452
|
@ -21,6 +21,10 @@ module TK.SpaceTac {
|
|||
getActionPointsUsage(ship: Ship, target: Target | null): number {
|
||||
let toggled_cost = isum(imap(ship.iToggleActions(true), action => action.power));
|
||||
let power_diff = ship.getAttribute("power_generation") - toggled_cost;
|
||||
let power_excess = ship.getValue("power") + power_diff - ship.getAttribute("power_capacity");
|
||||
if (power_excess > 0) {
|
||||
power_diff -= power_excess;
|
||||
}
|
||||
return -power_diff;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,10 +14,19 @@ module TK.SpaceTac.UI.Specs {
|
|||
icon.refresh();
|
||||
check.same(icon.img_power.visible, false, "no change");
|
||||
|
||||
check.patch(action, "getActionPointsUsage", () => 3);
|
||||
let cost = 3;
|
||||
check.patch(action, "getActionPointsUsage", () => cost);
|
||||
icon.refresh();
|
||||
check.equals(icon.img_power.visible, true);
|
||||
check.equals(icon.text_power.text, "3");
|
||||
check.in("power cost = 3", check => {
|
||||
check.equals(icon.img_power.visible, true);
|
||||
check.equals(icon.text_power.text, "3\n-");
|
||||
});
|
||||
cost = -2;
|
||||
icon.refresh();
|
||||
check.in("power cost = -2", check => {
|
||||
check.equals(icon.img_power.visible, true);
|
||||
check.equals(icon.text_power.text, "2\n+");
|
||||
});
|
||||
})
|
||||
|
||||
test.case("displays disabled and fading states", check => {
|
||||
|
|
|
@ -68,7 +68,7 @@ module TK.SpaceTac.UI {
|
|||
this.img_power.anchor.set(0.5);
|
||||
this.img_power.visible = false;
|
||||
this.container.addChild(this.img_power);
|
||||
this.text_power = new Phaser.Text(bar.game, 0, 0, "", { align: "left", font: "16pt SpaceTac", fill: "#ffdd4b" });
|
||||
this.text_power = new Phaser.Text(bar.game, 0, 4, "", { align: "left", font: "16pt SpaceTac", fill: "#ffdd4b" });
|
||||
this.text_power.setShadow(1, 1, "#000000");
|
||||
this.text_power.anchor.set(0.5);
|
||||
this.img_power.addChild(this.text_power);
|
||||
|
@ -206,10 +206,10 @@ module TK.SpaceTac.UI {
|
|||
}
|
||||
|
||||
// left
|
||||
let power = this.action.getActionPointsUsage(this.ship, null);
|
||||
this.img_power.visible = bool(power);
|
||||
this.text_power.text = `${Math.abs(power)}`;
|
||||
this.text_power.fill = (power > 0) ? "#ffdd4b" : "#dbe748";
|
||||
let cost = this.action.getActionPointsUsage(this.ship, null);
|
||||
this.img_power.visible = bool(cost);
|
||||
this.text_power.text = `${Math.abs(cost)}\n${cost < 0 ? "+" : "-"}`;
|
||||
this.text_power.fill = (cost > 0) ? "#ffdd4b" : "#dbe748";
|
||||
this.text_power.alpha = disabled ? 0.2 : 1;
|
||||
if (disabled != this.disabled || selected != this.selected || toggled != this.toggled) {
|
||||
if (disabled) {
|
||||
|
|
Loading…
Reference in a new issue