From 9de1ebcad22262c430dbeaabbf6d14cfe0074026 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Wed, 17 May 2017 20:14:45 +0200 Subject: [PATCH] arena: Added sticky effects indicator on ships --- TODO | 1 - .../images/battle/arena/ship-effect-bad.png | Bin 0 -> 410 bytes .../images/battle/arena/ship-effect-good.png | Bin 0 -> 413 bytes src/ui/Preload.ts | 2 + src/ui/battle/ArenaShip.spec.ts | 16 ++++++ src/ui/battle/ArenaShip.ts | 48 ++++++++++++++---- src/ui/battle/LogProcessor.ts | 18 ++++--- 7 files changed, 66 insertions(+), 19 deletions(-) create mode 100644 out/assets/images/battle/arena/ship-effect-bad.png create mode 100644 out/assets/images/battle/arena/ship-effect-good.png diff --git a/TODO b/TODO index b6a3cf9..58a5d06 100644 --- a/TODO +++ b/TODO @@ -17,7 +17,6 @@ * Menu: end appear animation when a button is clicked * Menu: allow to delete cloud saves * Arena: hide dead drones from tactical view -* Arena: add sticky effects indicators on ships * Arena: add power indicator in ship hover information * Arena: temporarily show ship information when it changes * Arena: display important changes (damages, effects...) instead of attribute changes diff --git a/out/assets/images/battle/arena/ship-effect-bad.png b/out/assets/images/battle/arena/ship-effect-bad.png new file mode 100644 index 0000000000000000000000000000000000000000..9b362a21b616d8928bd6d6ec63d5e8d7b7c6c708 GIT binary patch literal 410 zcmV;L0cHM)P)iyw+AyI0Ll6MC7R7z6op|Im8$)buCOf2Nmi@3e0DgTa_8%tV3vWF zlBrm!1j?8V5Zx4$BoT%C`+ywJ8|7`gpE2`)NlVFws9$&82>}2+wA(#XD*5|37D`G` zX$o5*#CE^;MYH+wv*QIZ7_^SNU6+-Dg5v~r*PUFlZ({q7JaXYt-~a#s07*qoM6N<$ Ef&}`jy8r+H literal 0 HcmV?d00001 diff --git a/out/assets/images/battle/arena/ship-effect-good.png b/out/assets/images/battle/arena/ship-effect-good.png new file mode 100644 index 0000000000000000000000000000000000000000..125fc44b991546b3eb7eae0cdfe4982bbc99b9ab GIT binary patch literal 413 zcmeAS@N?(olHy`uVBq!ia0vp^AT}2V8<6ZZI=>f4u@pObhHwBu4M$1`kk47*5m^jW ze;tGwoit`w00kvWTq8X}wEE-W=`!

G{L;6-C4cI? zo^y3V91I*RUX9gCJ1Tg0rM~O`)hoHY$!|f5_O{SBes*~~l?3&j84?@b6)@bmZJ(L8tbpxexkAg42%iV_ zzZ{>m`=#zF{Qv#&qT}z1E$8@4d1!!J{aR;R{O0cyw`aan;ROaIgQu&X%Q~lo FCIIEUt3Ch# literal 0 HcmV?d00001 diff --git a/src/ui/Preload.ts b/src/ui/Preload.ts index 8b6456f..6b0ad78 100644 --- a/src/ui/Preload.ts +++ b/src/ui/Preload.ts @@ -47,6 +47,8 @@ module TS.SpaceTac.UI { this.loadImage("battle/arena/ship-hull-full.png"); this.loadImage("battle/arena/ship-shield-base.png"); this.loadImage("battle/arena/ship-shield-full.png"); + this.loadImage("battle/arena/ship-effect-good.png"); + this.loadImage("battle/arena/ship-effect-bad.png"); this.loadImage("battle/arena/stasis.png"); this.loadImage("battle/arena/target.png"); this.loadImage("battle/arena/blast.png"); diff --git a/src/ui/battle/ArenaShip.spec.ts b/src/ui/battle/ArenaShip.spec.ts index c91df9f..c0c5da4 100644 --- a/src/ui/battle/ArenaShip.spec.ts +++ b/src/ui/battle/ArenaShip.spec.ts @@ -22,5 +22,21 @@ module TS.SpaceTac.UI.Specs { let t2 = sprite.effects.getChildAt(1); expect(t2.text).toBe("shield +12"); }); + + it("adds sticky effects display", function () { + let ship = nn(testgame.battleview.battle.playing_ship); + let sprite = nn(testgame.battleview.arena.findShipSprite(ship)); + + expect(sprite.sticky_effects.children.length).toBe(0); + + ship.addStickyEffect(new StickyEffect(new BaseEffect("test"))); + expect(sprite.sticky_effects.children.length).toBe(1); + + ship.addStickyEffect(new StickyEffect(new BaseEffect("test"))); + expect(sprite.sticky_effects.children.length).toBe(2); + + ship.cleanStickyEffects(); + expect(sprite.sticky_effects.children.length).toBe(0); + }); }); } diff --git a/src/ui/battle/ArenaShip.ts b/src/ui/battle/ArenaShip.ts index f859154..0fe2ec0 100644 --- a/src/ui/battle/ArenaShip.ts +++ b/src/ui/battle/ArenaShip.ts @@ -2,33 +2,34 @@ module TS.SpaceTac.UI { // Ship sprite in the arena (BattleView) export class ArenaShip extends Phaser.Group { // Link to the view - battleview: BattleView; + battleview: BattleView // Link to displayed ship - ship: Ship; + ship: Ship // Boolean to indicate if it is an enemy ship - enemy: boolean; + enemy: boolean // Ship sprite - sprite: Phaser.Button; + sprite: Phaser.Button // Statis effect - stasis: Phaser.Image; + stasis: Phaser.Image // Target effect - target: Phaser.Image; + target: Phaser.Image // Hover information - info: Phaser.Group; - info_hull: ValueBar; - info_shield: ValueBar; + info: Phaser.Group + info_hull: ValueBar + info_shield: ValueBar // Frame to indicate the owner of the ship, and if it is playing - frame: Phaser.Image; + frame: Phaser.Image // Effects display - effects: Phaser.Group; + sticky_effects: Phaser.Group + effects: Phaser.Group // Create a ship sprite usable in the Arena constructor(parent: Arena, ship: Ship) { @@ -76,6 +77,8 @@ module TS.SpaceTac.UI { this.add(this.info); // Effects display + this.sticky_effects = new Phaser.Group(this.game); + this.add(this.sticky_effects); this.effects = new Phaser.Group(this.game); this.add(this.effects); @@ -88,6 +91,13 @@ module TS.SpaceTac.UI { // Set location this.position.set(ship.arena_x, ship.arena_y); + + // Log processing + this.battleview.log_processor.registerForShip(ship, event => { + if (event instanceof EffectAddedEvent || event instanceof EffectRemovedEvent || event instanceof EffectDurationChangedEvent) { + this.updateStickyEffects(); + } + }); } /** @@ -174,5 +184,21 @@ module TS.SpaceTac.UI { this.info_shield.setValue(event.value.get(), this.ship.getAttribute("shield_capacity")); } } + + /** + * Update the stick effects + */ + updateStickyEffects() { + this.sticky_effects.removeAll(); + + let count = this.ship.sticky_effects.length + if (count) { + let positions = UITools.evenlySpace(70, 10, count); + this.ship.sticky_effects.forEach((effect, index) => { + let dot = new Phaser.Image(this.game, positions[index] - 40, -47, `battle-arena-ship-effect-${effect.isBeneficial() ? "good" : "bad"}`); + this.sticky_effects.add(dot); + }); + } + } } } diff --git a/src/ui/battle/LogProcessor.ts b/src/ui/battle/LogProcessor.ts index 65a862e..26e08e0 100644 --- a/src/ui/battle/LogProcessor.ts +++ b/src/ui/battle/LogProcessor.ts @@ -47,6 +47,17 @@ module TS.SpaceTac.UI { this.forwarding.push(callback); } + /** + * Register a sub-subscriber, to receive events for a specific ship + */ + registerForShip(ship: Ship, callback: LogSubscriber) { + this.register(event => { + if (event instanceof BaseLogShipEvent && event.ship === ship) { + callback(event); + } + }); + } + /** * Introduce a delay in event processing */ @@ -105,8 +116,6 @@ module TS.SpaceTac.UI { this.processDroneDestroyedEvent(event); } else if (event instanceof DroneAppliedEvent) { this.processDroneAppliedEvent(event); - } else if (event instanceof EffectAddedEvent || event instanceof EffectRemovedEvent || event instanceof EffectDurationChangedEvent) { - this.processEffectEvent(event); } } @@ -201,11 +210,6 @@ module TS.SpaceTac.UI { this.destroy(); } - // Sticky effect on ship added, changed or removed - private processEffectEvent(event: EffectAddedEvent | EffectRemovedEvent | EffectDurationChangedEvent): void { - // TODO - } - // New drone deployed private processDroneDeployedEvent(event: DroneDeployedEvent): void { let duration = this.view.arena.addDrone(event.drone, !event.initial);