diff --git a/TODO.md b/TODO.md index 71acad7..0a28d0e 100644 --- a/TODO.md +++ b/TODO.md @@ -5,7 +5,7 @@ Phaser 3 migration ------------------ * Restore fullscreen mode (and add a fullscreen incentive before the menu) -* Fix valuebar requiring to be in root display list +* Fix valuebar requiring to be in root display list (use tile sprite ?) * Restore unit tests about boundaries (in UITools) Menu/settings/saves diff --git a/data/stage2/image/battle/hud/grid-invalid.png b/data/stage2/image/battle/hud/grid-invalid.png new file mode 100644 index 0000000..0424653 Binary files /dev/null and b/data/stage2/image/battle/hud/grid-invalid.png differ diff --git a/data/stage2/image/battle/hud/grid-ok.png b/data/stage2/image/battle/hud/grid-ok.png new file mode 100644 index 0000000..3ddda64 Binary files /dev/null and b/data/stage2/image/battle/hud/grid-ok.png differ diff --git a/data/stage2/image/battle/hud/grid-power.png b/data/stage2/image/battle/hud/grid-power.png new file mode 100644 index 0000000..60cab26 Binary files /dev/null and b/data/stage2/image/battle/hud/grid-power.png differ diff --git a/src/ui/battle/Targetting.ts b/src/ui/battle/Targetting.ts index d176e0d..797134e 100644 --- a/src/ui/battle/Targetting.ts +++ b/src/ui/battle/Targetting.ts @@ -27,6 +27,11 @@ module TK.SpaceTac.UI { impact_area: UIGraphics impact_indicators: UIContainer + // Grid indicators + grid_ok: UIBatch + grid_power: UIBatch + grid_invalid: UIBatch + // Diffs display diffs_move: UIGraphics @@ -57,6 +62,9 @@ module TK.SpaceTac.UI { this.fire_arrow.setOrigin(1, 0.5); this.fire_arrow.setVisible(false); this.impact_indicators = builder.container("impact-indicators", 0, 0, false); + this.grid_ok = builder.batch({ image: "battle-hud-grid-ok", x: -24, y: -20 }); + this.grid_power = builder.batch({ image: "battle-hud-grid-power", x: -24, y: -20 }); + this.grid_invalid = builder.batch({ image: "battle-hud-grid-invalid", x: -24, y: -20 }); } /** @@ -221,6 +229,35 @@ module TK.SpaceTac.UI { }); } + /** + * Update the grid indicators + */ + updateGridIndicators(): void { + this.grid_ok.clear(); + this.grid_power.clear(); + this.grid_invalid.clear(); + + if (this.ship && this.action) { + let grid = this.ship.grid; + let action = this.action; + let simulator = new MoveFireSimulator(this.ship, grid); + + range(35).forEach(x => { + range(20).forEach(y => { + let target = Target.newFromLocation(x * 50, y * 50).snap(grid); + let result = simulator.simulateAction(action, target); + if (result.status == MoveFireStatus.OK) { + this.grid_ok.add(target.x, target.y); + } else if (result.status == MoveFireStatus.NOT_ENOUGH_POWER) { + this.grid_power.add(target.x, target.y); + } else { + this.grid_invalid.add(target.x, target.y); + } + }); + }); + } + } + /** * Update visual effects to show the simulation of current action/target */ @@ -329,6 +366,8 @@ module TK.SpaceTac.UI { this.setTarget(null); } + + this.updateGridIndicators(); } /** diff --git a/src/ui/common/UIBatch.ts b/src/ui/common/UIBatch.ts new file mode 100644 index 0000000..1a6ace6 --- /dev/null +++ b/src/ui/common/UIBatch.ts @@ -0,0 +1,50 @@ +module TK.SpaceTac.UI { + export interface UIBatchOptions { + // Image key + image: string + + // Initial location + x?: number + y?: number + } + + /** + * UI component to display a batch of the same image repeated a great number of times + */ + export class UIBatch { + private internal: Phaser.GameObjects.Blitter + + constructor(view: BaseView, options: UIBatchOptions) { + let info = view.getImageInfo(options.image); + this.internal = view.add.blitter(options.x || 0, options.y || 0, info.key, info.frame); + } + + /** + * Add to a container + */ + addToContainer(container: UIContainer): void { + container.add(this.internal); + } + + /** + * Set the location of the whole batch + */ + setPosition(x: number, y: number): void { + this.internal.setPosition(x, y); + } + + /** + * Clear the batch of all items + */ + clear(): void { + this.internal.clear(); + } + + /** + * Add an item to the batch + */ + add(x: number, y: number): void { + this.internal.create(x, y); + } + } +} diff --git a/src/ui/common/UIBuilder.ts b/src/ui/common/UIBuilder.ts index d0ae2f3..c67536e 100644 --- a/src/ui/common/UIBuilder.ts +++ b/src/ui/common/UIBuilder.ts @@ -180,6 +180,19 @@ module TK.SpaceTac.UI { return result; } + /** + * Add a batch of images + */ + batch(options: UIBatchOptions): UIBatch { + let result = new UIBatch(this.view, options); + if (this.parent instanceof UIContainer) { + result.addToContainer(this.parent); + } else { + console.error("Cannot add a batch to an image parent"); + } + return result; + } + /** * Add a hoverable and/or clickable button *