1
0
Fork 0
This commit is contained in:
Michaël Lemaire 2018-07-13 16:15:01 +02:00
parent 458e439bcd
commit d0025b3de6
7 changed files with 103 additions and 1 deletions

View File

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -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();
}
/**

50
src/ui/common/UIBatch.ts Normal file
View File

@ -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);
}
}
}

View File

@ -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
*