1
0
Fork 0

arena: Activate tactical mode while targetting + fixed some toggle issues

This commit is contained in:
Michaël Lemaire 2017-09-13 22:56:57 +02:00
parent f962f52b97
commit 1dc6a5b768
9 changed files with 31 additions and 188 deletions

View file

@ -54,6 +54,8 @@ Battle
* Merge identical sticky effects
* Allow to undo last moves
* Add a battle log display
* Allow to target ships with number keys, using their play order
* Allow to validate the current targetting with enter
Ships models and equipments
---------------------------

@ -1 +1 @@
Subproject commit de41d5a99d9df6df6c5183c2e06185df7e2a055d
Subproject commit 18a9b3c75b576af53362b7ce6d5081d71050cde4

View file

@ -38,6 +38,7 @@ module TS.SpaceTac.UI {
active_effects_display: Phaser.Group
effects_radius: Phaser.Graphics
effects_messages: Phaser.Group
effects_messages_toggle: Toggle
// Create a ship sprite usable in the Arena
constructor(parent: Arena, ship: Ship) {
@ -115,6 +116,7 @@ module TS.SpaceTac.UI {
this.add(this.active_effects_display);
this.effects_messages = new Phaser.Group(this.game);
this.add(this.effects_messages);
this.effects_messages_toggle = this.battleview.animations.newVisibilityToggle(this.effects_messages, 500, false);
this.updateActiveEffects();
this.updateEffectsRadius();
@ -163,12 +165,12 @@ module TS.SpaceTac.UI {
return 0;
} else if (event instanceof ValueChangeEvent) {
if (event.value.name == "hull") {
this.toggle_hsp.start(1500, true);
this.toggle_hsp.manipulate("value")(1500);
this.hull_bar.setValue(event.value.get(), event.value.getMaximal() || 0);
this.hull_text.text = `${event.value.get()}`;
return 0;
} else if (event.value.name == "shield") {
this.toggle_hsp.start(1500, true);
this.toggle_hsp.manipulate("value")(1500);
this.shield_bar.setValue(event.value.get(), event.value.getMaximal() || 0);
this.shield_text.text = `${event.value.get()}`;
if (event.value.get() == 0) {
@ -176,7 +178,7 @@ module TS.SpaceTac.UI {
}
return 0;
} else if (event.value.name == "power") {
this.toggle_hsp.start(1500, true);
this.toggle_hsp.manipulate("value")(1500);
this.power_text.text = `${event.value.get()}`;
return 0;
} else {
@ -212,14 +214,16 @@ module TS.SpaceTac.UI {
* This will show the information HUD accordingly
*/
setHovered(hovered: boolean, tactical: boolean) {
let client = tactical ? "tactical" : "hover";
if (hovered && this.ship.alive) {
this.toggle_hsp.start();
this.toggle_hsp.manipulate(client)(true);
if (tactical) {
this.toggle_play_order.start();
this.toggle_play_order.manipulate(client)(true);
}
} else {
this.toggle_hsp.stop();
this.toggle_play_order.stop();
this.toggle_hsp.manipulate(client)(false);
this.toggle_play_order.manipulate(client)(false);
}
}
@ -288,6 +292,10 @@ module TS.SpaceTac.UI {
* Briefly show an effect on this ship
*/
displayEffect(message: string, beneficial: boolean) {
if (!this.effects_messages.visible) {
this.effects_messages.removeAll(true);
}
let text = new Phaser.Text(this.game, 0, 20 * this.effects_messages.children.length, message, { font: "14pt SpaceTac", fill: beneficial ? "#afe9c6" : "#e9afaf" });
this.effects_messages.addChild(text);
@ -297,10 +305,7 @@ module TS.SpaceTac.UI {
(this.ship.arena_y < arena.height * 0.9) ? 50 : (-50 - this.effects_messages.height)
);
this.game.tweens.removeFrom(this.effects_messages);
this.effects_messages.alpha = 1;
let tween = this.game.tweens.create(this.effects_messages).to({ alpha: 0 }, 500).delay(1000).start();
tween.onComplete.addOnce(() => this.effects_messages.removeAll(true));
this.effects_messages_toggle.manipulate("added")(1000);
}
/**

View file

@ -105,14 +105,14 @@ module TS.SpaceTac.UI {
this.layer_sheets.add(this.character_sheet);
// Targetting info
this.targetting = new Targetting(this, this.action_bar);
this.targetting = new Targetting(this, this.action_bar, this.toggle_tactical_mode);
this.targetting.moveToLayer(this.arena.layer_targetting);
// BGM
this.gameui.audio.startMusic("mechanolith", 0.2);
// Key mapping
this.inputs.bind("t", "Show tactical view", () => this.toggle_tactical_mode.switch(3000));
this.inputs.bind("t", "Show tactical view", () => this.toggle_tactical_mode.manipulate("keyboard")(3000));
this.inputs.bindCheat("w", "Win current battle", () => this.battle.cheats.win());
this.inputs.bindCheat("x", "Lose current battle", () => this.battle.cheats.lose());
this.inputs.bindCheat("a", "Use AI to play", () => this.playAI());

View file

@ -29,8 +29,8 @@ module TS.SpaceTac.UI {
this.info_button = new Phaser.Button(this.game, 0, 0, "battle-shiplist-info-button");
this.info_button.position.set(0, this.height - this.info_button.height);
UITools.setHoverClick(this.info_button,
() => this.battleview.toggle_tactical_mode.start(),
() => this.battleview.toggle_tactical_mode.stop(),
() => this.battleview.toggle_tactical_mode.manipulate("button")(true),
() => this.battleview.toggle_tactical_mode.manipulate("button")(false),
() => null);
this.addChild(this.info_button);

View file

@ -3,7 +3,7 @@ module TS.SpaceTac.UI.Specs {
let testgame = setupBattleview();
it("draws simulation parts", function () {
let targetting = new Targetting(testgame.battleview, testgame.battleview.action_bar);
let targetting = new Targetting(testgame.battleview, testgame.battleview.action_bar, new Toggle());
let ship = nn(testgame.battleview.battle.playing_ship);
ship.setArenaPosition(10, 20);
@ -35,7 +35,7 @@ module TS.SpaceTac.UI.Specs {
});
it("updates impact indicators on ships inside the blast radius", function () {
let targetting = new Targetting(testgame.battleview, testgame.battleview.action_bar);
let targetting = new Targetting(testgame.battleview, testgame.battleview.action_bar, new Toggle());
let ship = nn(testgame.battleview.battle.playing_ship);
let collect = spyOn(testgame.battleview.battle, "collectShipsInCircle").and.returnValues(
@ -71,7 +71,7 @@ module TS.SpaceTac.UI.Specs {
});
it("updates graphics from simulation", function () {
let targetting = new Targetting(testgame.battleview, testgame.battleview.action_bar);
let targetting = new Targetting(testgame.battleview, testgame.battleview.action_bar, new Toggle());
let ship = nn(testgame.battleview.battle.playing_ship);
let engine = TestTools.addEngine(ship, 8000);

View file

@ -25,13 +25,15 @@ module TS.SpaceTac.UI {
// Collaborators to update
actionbar: ActionBar
tactical_mode: ToggleClient
// Access to the parent view
view: BaseView
constructor(view: BaseView, actionbar: ActionBar) {
constructor(view: BaseView, actionbar: ActionBar, tactical_mode: Toggle) {
this.view = view;
this.actionbar = actionbar;
this.tactical_mode = tactical_mode.manipulate("targetting");
this.container = view.add.group();
@ -201,6 +203,8 @@ module TS.SpaceTac.UI {
} else {
this.container.visible = false;
}
this.tactical_mode(bool(this.action));
}
/**

View file

@ -1,107 +0,0 @@
/// <reference path="../TestGame.ts"/>
module TS.SpaceTac.UI.Specs {
describe("Toggle", function () {
let on_calls = 0;
let off_calls = 0;
beforeEach(function () {
on_calls = 0;
off_calls = 0;
jasmine.clock().install();
});
afterEach(function () {
jasmine.clock().uninstall();
});
function newToggle(): Toggle {
return new Toggle(() => on_calls++, () => off_calls++);
}
function check(on: number, off: number) {
expect(on_calls).toBe(on);
expect(off_calls).toBe(off);
on_calls = 0;
off_calls = 0;
}
it("handles simple toggling", function () {
let toggle = newToggle();
check(0, 0);
toggle.start();
check(1, 0);
jasmine.clock().tick(10000000);
check(0, 0);
toggle.stop();
check(0, 1);
jasmine.clock().tick(10000000);
check(0, 0);
toggle.stop();
check(0, 0);
toggle.start();
check(1, 0);
});
it("applies hard priority", function () {
let toggle = newToggle();
check(0, 0);
// hard
toggle.start(0, true);
check(1, 0);
toggle.stop(false);
check(0, 0);
toggle.stop(true);
check(0, 1);
// soft
toggle.start(0, false);
check(1, 0);
toggle.stop(true);
check(0, 1);
// soft lifted to hard
toggle.start(0, false);
check(1, 0);
toggle.start(0, true);
check(0, 0);
toggle.stop(false);
check(0, 0);
toggle.stop(true);
check(0, 1);
});
it("automatically stop after a duration", function () {
let toggle = newToggle();
check(0, 0);
toggle.start(10);
check(1, 0);
jasmine.clock().tick(9);
check(0, 0);
jasmine.clock().tick(2);
check(0, 1);
toggle.stop();
check(0, 0);
toggle.start();
check(1, 0);
});
});
}

View file

@ -1,61 +0,0 @@
module TS.SpaceTac {
/**
* A toggle between two states (on and off), with timing features.
*/
export class Toggle {
private on: Function
private off: Function
private status = false
private hard = false
private timer = Timer.global;
constructor(on: Function, off: Function) {
this.on = on;
this.off = off;
}
/**
* Start the toggle (set the status *on*)
*
* If *duration* is set, stop() will automatically be called after these milliseconds.
*
* If *hard* is true, it can only be stopped by a hard stop.
*/
start(duration = 0, hard = false) {
if (hard) {
this.hard = true;
}
if (!this.status) {
this.status = true;
this.on();
}
if (duration) {
this.timer.schedule(duration, () => this.stop(hard));
}
}
/**
* Stop the toggle (set the status *off*)
*/
stop(hard = false) {
if (this.status) {
if (hard || !this.hard) {
this.status = false;
this.hard = false;
this.off();
}
}
}
/**
* Switch between on and off status
*/
switch(duration = 0, hard = false) {
if (this.status) {
this.stop(hard);
} else {
this.start(duration, hard);
}
}
}
}