actionbar: Restored overheat/cooldown display
This commit is contained in:
parent
5a730762d1
commit
3b4c5f0d7c
BIN
graphics/exported/battle/actionbar/cooldown-front.png
Normal file
BIN
graphics/exported/battle/actionbar/cooldown-front.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 974 B |
BIN
graphics/exported/battle/actionbar/cooldown-one.png
Normal file
BIN
graphics/exported/battle/actionbar/cooldown-one.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 203 B |
|
@ -1487,16 +1487,6 @@
|
|||
y1="-13.091659"
|
||||
x2="245.46188"
|
||||
y2="-23.06498" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient6137"
|
||||
id="linearGradient7417"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
gradientTransform="translate(0,-0.31249999)"
|
||||
x1="454.06946"
|
||||
y1="-40.707054"
|
||||
x2="462.69446"
|
||||
y2="-40.707054" />
|
||||
<radialGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient7875"
|
||||
|
@ -2323,6 +2313,16 @@
|
|||
result="composite2"
|
||||
id="feComposite6702" />
|
||||
</filter>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient6137"
|
||||
id="linearGradient5607"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
gradientTransform="matrix(1,0,0,0.78455817,0,-9.4822313)"
|
||||
x1="454.06946"
|
||||
y1="-40.707054"
|
||||
x2="462.69446"
|
||||
y2="-40.707054" />
|
||||
</defs>
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
|
@ -2331,11 +2331,11 @@
|
|||
borderopacity="1"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="2.8284272"
|
||||
inkscape:cx="553.74511"
|
||||
inkscape:cy="-146.19875"
|
||||
inkscape:zoom="11.313709"
|
||||
inkscape:cx="796.46023"
|
||||
inkscape:cy="-149.64343"
|
||||
inkscape:document-units="px"
|
||||
inkscape:current-layer="use6422"
|
||||
inkscape:current-layer="g5614-1"
|
||||
showgrid="false"
|
||||
units="px"
|
||||
showguides="true"
|
||||
|
@ -5217,24 +5217,19 @@
|
|||
style="display:inline;enable-background:new"
|
||||
id="use8243-6"
|
||||
transform="translate(845.76337,-0.279008)">
|
||||
<rect
|
||||
style="fill:#523218;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
id="rect6261"
|
||||
width="8.8388348"
|
||||
height="36.415997"
|
||||
x="453.96255"
|
||||
y="-43.090988"
|
||||
ry="2.2944183" />
|
||||
<g
|
||||
id="g5614-1">
|
||||
<rect
|
||||
style="fill:url(#linearGradient7417);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1.17963755px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
style="fill:url(#linearGradient5607);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1.0448674px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
id="rect5606-5"
|
||||
width="8.625"
|
||||
height="5.7437167"
|
||||
height="4.5062799"
|
||||
x="454.06946"
|
||||
y="-42.874947"
|
||||
ry="0.57452422" />
|
||||
ry="0.45074767"
|
||||
inkscape:export-filename="/home/michael/workspace/perso/spacetac/graphics/exported/battle/actionbar/cooldown-one.png"
|
||||
inkscape:export-xdpi="96"
|
||||
inkscape:export-ydpi="96" />
|
||||
<use
|
||||
x="0"
|
||||
y="0"
|
||||
|
@ -5242,7 +5237,7 @@
|
|||
id="use6141"
|
||||
width="100%"
|
||||
height="100%"
|
||||
transform="translate(0,7.8602294)" />
|
||||
transform="translate(0,7.1935271)" />
|
||||
<use
|
||||
x="0"
|
||||
y="0"
|
||||
|
@ -5250,7 +5245,7 @@
|
|||
id="use6143"
|
||||
width="100%"
|
||||
height="100%"
|
||||
transform="translate(0,15.720337)" />
|
||||
transform="translate(0,14.387039)" />
|
||||
<use
|
||||
x="0"
|
||||
y="0"
|
||||
|
@ -5258,7 +5253,7 @@
|
|||
id="use6145"
|
||||
width="100%"
|
||||
height="100%"
|
||||
transform="translate(0,23.580569)" />
|
||||
transform="translate(0,21.580569)" />
|
||||
</g>
|
||||
<rect
|
||||
ry="2.2944183"
|
||||
|
@ -5267,13 +5262,19 @@
|
|||
height="36.415997"
|
||||
width="8.8388348"
|
||||
id="rect5616-5"
|
||||
style="fill:none;fill-rule:evenodd;stroke:#e8bb84;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
|
||||
style="fill:none;fill-rule:evenodd;stroke:#e8bb84;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
inkscape:export-filename="/home/michael/workspace/perso/spacetac/graphics/exported/battle/actionbar/cooldown-front.png"
|
||||
inkscape:export-xdpi="96"
|
||||
inkscape:export-ydpi="96" />
|
||||
<circle
|
||||
id="circle5618-6"
|
||||
style="fill:url(#radialGradient7419);fill-opacity:1;fill-rule:evenodd;stroke:#e8bb84;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
cy="-7.3820977"
|
||||
cx="458.38196"
|
||||
r="7.0710673" />
|
||||
r="7.0710673"
|
||||
inkscape:export-filename="/home/michael/workspace/perso/spacetac/graphics/exported/battle/actionbar/cooldown-front.png"
|
||||
inkscape:export-xdpi="96"
|
||||
inkscape:export-ydpi="96" />
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
|
|
Before Width: | Height: | Size: 320 KiB After Width: | Height: | Size: 321 KiB |
|
@ -56,11 +56,20 @@ module TK.SpaceTac {
|
|||
}
|
||||
|
||||
getRangeRadius(ship: Ship): number {
|
||||
return ship.getValue("power") * this.getDistanceByActionPoint(ship);
|
||||
return this.getRangeRadiusForPower(ship);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the distance reachable with a given power
|
||||
*/
|
||||
getRangeRadiusForPower(ship: Ship, power = ship.getValue("power")): number {
|
||||
return power * this.getDistanceByActionPoint(ship);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the distance range that may be traveled with 1 action point
|
||||
*
|
||||
* The actual range will then depend on the ship maneuvrability
|
||||
*/
|
||||
getDistanceRangeByActionPoint(): IntegerRange {
|
||||
let min_distance = Math.ceil(this.distance_per_power * (1 - this.maneuvrability_factor * 0.01));
|
||||
|
|
|
@ -146,10 +146,7 @@ module TK.SpaceTac.UI {
|
|||
let power_capacity = this.ship_power_capacity;
|
||||
|
||||
if (current_power > power_capacity) {
|
||||
range(current_power - power_capacity).forEach(i => {
|
||||
this.power_icons.removeChildAt(current_power - 1 - i)
|
||||
});
|
||||
//this.power.removeChildren(ship_power, current_power); // TODO bugged in phaser 2.6
|
||||
destroyChildren(this.power_icons, power_capacity, current_power);
|
||||
} else if (power_capacity > current_power) {
|
||||
range(power_capacity - current_power).forEach(i => {
|
||||
let x = (current_power + i) % 5;
|
||||
|
|
|
@ -82,7 +82,33 @@ module TK.SpaceTac.UI.Specs {
|
|||
})
|
||||
|
||||
it("displays overheat/cooldown", function () {
|
||||
let bar = testgame.battleview.action_bar;
|
||||
let ship = new Ship();
|
||||
TestTools.setShipAP(ship, 5);
|
||||
let action = nn(TestTools.addWeapon(ship, 50, 3).action);
|
||||
action.cooldown.configure(1, 3);
|
||||
let icon = new ActionIcon(bar, ship, action, 0);
|
||||
expect(icon.img_sticky.visible).toBe(false, "initial");
|
||||
expect(icon.img_sticky.name).toBe("battle-actionbar-sticky-untoggled", "initial");
|
||||
expect(icon.img_sticky.children.length).toBe(0, "initial");
|
||||
|
||||
icon.refresh(action);
|
||||
expect(icon.img_sticky.visible).toBe(true, "overheat");
|
||||
expect(icon.img_sticky.name).toBe("battle-actionbar-sticky-overheat", "overheat");
|
||||
expect(icon.img_sticky.children.length).toBe(3, "overheat");
|
||||
|
||||
action.cooldown.configure(1, 12);
|
||||
icon.refresh(action);
|
||||
expect(icon.img_sticky.visible).toBe(true, "superheat");
|
||||
expect(icon.img_sticky.name).toBe("battle-actionbar-sticky-overheat", "superheat");
|
||||
expect(icon.img_sticky.children.length).toBe(5, "superheat");
|
||||
|
||||
action.cooldown.configure(1, 4);
|
||||
action.cooldown.use();
|
||||
icon.refresh(action);
|
||||
expect(icon.img_sticky.visible).toBe(true, "cooling");
|
||||
expect(icon.img_sticky.name).toBe("battle-actionbar-sticky-disabled", "cooling");
|
||||
expect(icon.img_sticky.children.length).toBe(4, "cooling");
|
||||
})
|
||||
|
||||
it("displays currently targetting", function () {
|
||||
|
|
|
@ -21,6 +21,7 @@ module TK.SpaceTac.UI {
|
|||
disabled = true
|
||||
selected = false
|
||||
toggled = false
|
||||
cooldown = 0
|
||||
|
||||
// Images
|
||||
img_targetting: Phaser.Image
|
||||
|
@ -159,8 +160,10 @@ module TK.SpaceTac.UI {
|
|||
let selected = (used === this.action);
|
||||
let toggled = (this.action instanceof ToggleAction) && this.action.activated;
|
||||
let fading = bool(this.action.checkCannotBeApplied(this.ship, this.ship.getValue("power") - power_consumption));
|
||||
let cooldown = this.action.cooldown.heat;
|
||||
if (this.action == used && this.action.cooldown.willOverheat()) {
|
||||
fading = true;
|
||||
cooldown = this.action.cooldown.cooling;
|
||||
}
|
||||
|
||||
// inputs
|
||||
|
@ -220,7 +223,8 @@ module TK.SpaceTac.UI {
|
|||
}
|
||||
|
||||
// right
|
||||
if (toggled != this.toggled || disabled != this.disabled) {
|
||||
if (toggled != this.toggled || disabled != this.disabled || cooldown != this.cooldown) {
|
||||
destroyChildren(this.img_sticky);
|
||||
if (this.action instanceof ToggleAction) {
|
||||
if (toggled) {
|
||||
this.view.changeImage(this.img_sticky, "battle-actionbar-sticky-toggled");
|
||||
|
@ -228,8 +232,18 @@ module TK.SpaceTac.UI {
|
|||
this.view.changeImage(this.img_sticky, "battle-actionbar-sticky-untoggled");
|
||||
}
|
||||
this.img_sticky.visible = !disabled;
|
||||
} else if (cooldown) {
|
||||
if (disabled) {
|
||||
this.view.changeImage(this.img_sticky, "battle-actionbar-sticky-disabled");
|
||||
} else {
|
||||
this.view.changeImage(this.img_sticky, "battle-actionbar-sticky-overheat");
|
||||
}
|
||||
range(Math.min(cooldown - 1, 4)).forEach(i => {
|
||||
this.img_sticky.addChild(this.view.newImage("battle-actionbar-cooldown-one", -4, 2 - i * 7));
|
||||
});
|
||||
this.img_sticky.addChild(this.view.newImage("battle-actionbar-cooldown-front", -8, -20));
|
||||
this.img_sticky.visible = true;
|
||||
} else {
|
||||
// TODO overheat
|
||||
this.img_sticky.visible = false;
|
||||
}
|
||||
}
|
||||
|
@ -238,6 +252,7 @@ module TK.SpaceTac.UI {
|
|||
this.selected = selected;
|
||||
this.fading = fading;
|
||||
this.toggled = toggled;
|
||||
this.cooldown = cooldown;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ module TK.SpaceTac.UI {
|
|||
filler.addText(150, 80, "Cooling down ...", "#c9604c", 20);
|
||||
} else if (cooldown.willOverheat() && cost != "Not enough power") {
|
||||
if (cooldown.cooling > 1) {
|
||||
let turns = cooldown.cooling;
|
||||
let turns = cooldown.cooling - 1;
|
||||
filler.addText(150, 80, `Unavailable for ${turns} turn${turns > 1 ? "s" : ""} if used`, "#c9604c", 20);
|
||||
} else {
|
||||
filler.addText(150, 80, "Unavailable until next turn if used", "#c9604c", 20);
|
||||
|
|
|
@ -43,18 +43,17 @@ module TK.SpaceTac.UI {
|
|||
/**
|
||||
* Update displayed information
|
||||
*/
|
||||
update(ship: Ship, action: BaseAction, location: ArenaLocation = ship.location): void {
|
||||
update(ship: Ship, action: BaseAction, radius = action.getRangeRadius(ship)): void {
|
||||
let yescolor = 0x000000;
|
||||
let nocolor = 0x242022;
|
||||
this.info.clear();
|
||||
|
||||
var radius = action.getRangeRadius(ship);
|
||||
if (radius) {
|
||||
this.info.beginFill(nocolor);
|
||||
this.info.drawRect(0, 0, this.width, this.height);
|
||||
|
||||
this.info.beginFill(yescolor);
|
||||
this.info.drawCircle(location.x, location.y, radius * 2);
|
||||
this.info.drawCircle(ship.arena_x, ship.arena_y, radius * 2);
|
||||
|
||||
if (action instanceof MoveAction) {
|
||||
let exclusions = action.getExclusionAreas(ship);
|
||||
|
|
|
@ -148,5 +148,33 @@ module TK.SpaceTac.UI.Specs {
|
|||
targetting.setTargetFromLocation({ x: 0, y: 0 });
|
||||
expect(targetting.target).toEqual(Target.newFromShip(playing_ship), "self 2");
|
||||
})
|
||||
|
||||
it("updates the range hint display", function () {
|
||||
let targetting = newTargetting();
|
||||
let ship = nn(testgame.battleview.battle.playing_ship);
|
||||
ship.setArenaPosition(0, 0);
|
||||
ship.listEquipment(SlotType.Engine).forEach(engine => engine.detach());
|
||||
TestTools.setShipAP(ship, 8);
|
||||
let move = TestTools.addEngine(ship, 100).action;
|
||||
let fire = TestTools.addWeapon(ship, 50, 2, 300, 100).action;
|
||||
let last_call: any = null;
|
||||
spyOn(targetting.range_hint, "clear").and.callFake(() => last_call = null);
|
||||
spyOn(targetting.range_hint, "update").and.callFake((ship: Ship, action: BaseAction, radius: number) => last_call = [ship, action, radius]);
|
||||
|
||||
// move action
|
||||
targetting.setAction(move);
|
||||
targetting.setTargetFromLocation({ x: 200, y: 0 });
|
||||
expect(last_call).toEqual([ship, move, 800]);
|
||||
|
||||
// fire action
|
||||
targetting.setAction(fire);
|
||||
targetting.setTargetFromLocation({ x: 200, y: 0 });
|
||||
expect(last_call).toEqual([ship, fire, undefined]);
|
||||
|
||||
// move+fire
|
||||
targetting.setAction(fire);
|
||||
targetting.setTargetFromLocation({ x: 400, y: 0 });
|
||||
expect(last_call).toEqual([ship, move, 600]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -216,21 +216,28 @@ module TK.SpaceTac.UI {
|
|||
// Toggle range hint
|
||||
if (this.ship && this.action) {
|
||||
if (this.simulation.need_move) {
|
||||
let move_action: MoveAction | null = null;
|
||||
if (this.simulation.success) {
|
||||
let last_move = first(acopy(this.simulation.parts).reverse(), part => part.action instanceof MoveAction);
|
||||
if (last_move) {
|
||||
this.range_hint.update(this.ship, last_move.action);
|
||||
} else {
|
||||
this.range_hint.clear();
|
||||
move_action = <MoveAction>last_move.action;
|
||||
}
|
||||
} else {
|
||||
let engine = new MoveFireSimulator(this.ship).findBestEngine();
|
||||
if (engine && engine.action) {
|
||||
this.range_hint.update(this.ship, engine.action);
|
||||
} else {
|
||||
this.range_hint.clear();
|
||||
move_action = <MoveAction>engine.action;
|
||||
}
|
||||
}
|
||||
if (move_action) {
|
||||
let power = this.ship.getValue("power");
|
||||
if (this.action !== move_action) {
|
||||
power = Math.max(power - this.action.getActionPointsUsage(this.ship, this.target), 0);
|
||||
}
|
||||
let radius = move_action.getRangeRadiusForPower(this.ship, power);
|
||||
this.range_hint.update(this.ship, move_action, radius);
|
||||
} else {
|
||||
this.range_hint.clear();
|
||||
}
|
||||
} else {
|
||||
this.range_hint.update(this.ship, this.action);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,21 @@ module TK.SpaceTac.UI.Specs {
|
|||
describe("in UI", function () {
|
||||
let testgame = setupEmptyView();
|
||||
|
||||
it("destroys children", function () {
|
||||
let parent = testgame.baseview.add.group();
|
||||
let child1 = testgame.baseview.add.graphics(0, 0, parent);
|
||||
let child2 = testgame.baseview.add.image(0, 0, "", 0, parent);
|
||||
let child3 = testgame.baseview.add.button(0, 0, "", undefined, undefined, undefined, undefined, undefined, undefined, parent);
|
||||
let child4 = testgame.baseview.add.text(0, 0, "", {}, parent);
|
||||
expect(parent.children.length).toBe(4);
|
||||
|
||||
destroyChildren(parent, 1, 2);
|
||||
expect(parent.children.length).toBe(2);
|
||||
|
||||
destroyChildren(parent);
|
||||
expect(parent.children.length).toBe(0);
|
||||
});
|
||||
|
||||
it("keeps objects inside bounds", function () {
|
||||
let image = testgame.baseview.add.graphics(150, 100);
|
||||
image.beginFill(0xff0000);
|
||||
|
|
|
@ -6,6 +6,15 @@ module TK.SpaceTac.UI {
|
|||
height: number
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy all children of a Phaser object
|
||||
*
|
||||
* This is a workaround for a removeChildren bug
|
||||
*/
|
||||
export function destroyChildren(obj: Phaser.Image | Phaser.Sprite | Phaser.Group, start = 0, end = obj.children.length - 1) {
|
||||
obj.children.slice(start, end + 1).forEach(child => (<any>child).destroy());
|
||||
}
|
||||
|
||||
// Common UI tools functions
|
||||
export class UITools {
|
||||
static hovered: Phaser.Button | null = null;
|
||||
|
|
Loading…
Reference in a new issue