Added range hint display on actions
This commit is contained in:
parent
e18ad47c78
commit
b3bb84b81a
|
@ -44,6 +44,15 @@ module SpaceTac.Game {
|
|||
}
|
||||
}
|
||||
|
||||
// Get the range of this action
|
||||
getRangeRadius(ship: Ship): number {
|
||||
if (this.equipment) {
|
||||
return this.equipment.distance;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Method to check if a target is applicable for this action
|
||||
// Will call checkLocationTarget or checkShipTarget by default
|
||||
checkTarget(battle: Battle, ship: Ship, target: Target): Target {
|
||||
|
|
|
@ -28,6 +28,10 @@ module SpaceTac.Game {
|
|||
return this.equipment.ap_usage * distance / this.equipment.distance;
|
||||
}
|
||||
|
||||
getRangeRadius(ship: Ship): number {
|
||||
return ship.ap_current.current * this.equipment.distance / this.equipment.ap_usage;
|
||||
}
|
||||
|
||||
checkLocationTarget(battle: Battle, ship: Ship, target: Target): Target {
|
||||
// TODO Should forbid to move too much near another ship
|
||||
var max_distance = this.equipment.distance * ship.ap_current.current / this.equipment.ap_usage;
|
||||
|
|
|
@ -62,7 +62,15 @@ module SpaceTac.View {
|
|||
// Click process
|
||||
this.onInputUp.add(() => {
|
||||
this.processClick();
|
||||
}, this);
|
||||
});
|
||||
|
||||
// Range hints on hover
|
||||
this.onInputOver.add(() => {
|
||||
this.battleview.arena.range_hint.setSecondary(this.ship, this.action);
|
||||
});
|
||||
this.onInputOut.add(() => {
|
||||
this.battleview.arena.range_hint.clearSecondary();
|
||||
});
|
||||
|
||||
// Initialize
|
||||
this.updateActiveStatus();
|
||||
|
@ -80,6 +88,9 @@ module SpaceTac.View {
|
|||
this.bar.actionEnded();
|
||||
this.bar.actionStarted();
|
||||
|
||||
// Update range hint
|
||||
this.battleview.arena.range_hint.setPrimary(this.ship, this.action);
|
||||
|
||||
// Update fading statuses
|
||||
this.bar.updateFadings(this.action.getActionPointsUsage(this.battleview.battle, this.ship, null));
|
||||
|
||||
|
@ -126,6 +137,7 @@ module SpaceTac.View {
|
|||
this.layer_active.tint = 0xFFFFFF;
|
||||
this.updateActiveStatus();
|
||||
this.updateFadingStatus(this.ship.ap_current.current);
|
||||
this.battleview.arena.range_hint.clearPrimary();
|
||||
}
|
||||
|
||||
// Update the active status, from the action canBeUsed result
|
||||
|
|
|
@ -7,6 +7,9 @@ module SpaceTac.View {
|
|||
// Arena background
|
||||
background: Phaser.Button;
|
||||
|
||||
// Hint for weapon or move range
|
||||
range_hint: RangeHint;
|
||||
|
||||
// Input callback to receive mouse move events
|
||||
private input_callback: any;
|
||||
|
||||
|
@ -27,6 +30,7 @@ module SpaceTac.View {
|
|||
this.ship_sprites = [];
|
||||
this.playing = null;
|
||||
this.hovered = null;
|
||||
this.range_hint = null;
|
||||
|
||||
super(battleview.game);
|
||||
|
||||
|
@ -52,6 +56,9 @@ module SpaceTac.View {
|
|||
this.position.set(196, 100);
|
||||
this.addChild(this.background);
|
||||
|
||||
this.range_hint = new RangeHint(this);
|
||||
this.addChild(this.range_hint);
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
|
|
72
src/scripts/view/battle/RangeHint.ts
Normal file
72
src/scripts/view/battle/RangeHint.ts
Normal file
|
@ -0,0 +1,72 @@
|
|||
module SpaceTac.View {
|
||||
"use strict";
|
||||
|
||||
// Graphical hints for movement and weapon range
|
||||
export class RangeHint extends Phaser.Group {
|
||||
// Link to the arena
|
||||
parent: Arena;
|
||||
|
||||
// Displayed circle
|
||||
circle: Phaser.Graphics;
|
||||
|
||||
// Stored information of primary circle, when secondary one overrides it
|
||||
primary: Phaser.Circle;
|
||||
|
||||
constructor(parent: Arena) {
|
||||
super(parent.game, parent);
|
||||
|
||||
this.parent = parent;
|
||||
|
||||
this.circle = new Phaser.Graphics(this.game, 0, 0);
|
||||
this.addChild(this.circle);
|
||||
|
||||
this.primary = null;
|
||||
}
|
||||
|
||||
// Clear the primary hint
|
||||
clearPrimary(): void {
|
||||
this.primary = null;
|
||||
this.circle.visible = false;
|
||||
}
|
||||
|
||||
// Clear the secondary hint
|
||||
clearSecondary(): void {
|
||||
if (this.primary) {
|
||||
this.draw(this.primary);
|
||||
} else {
|
||||
this.circle.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Set currently selected action
|
||||
setPrimary(ship: Game.Ship, action: Game.BaseAction): void {
|
||||
var radius = action.getRangeRadius(ship);
|
||||
if (radius) {
|
||||
this.primary = new Phaser.Circle(ship.arena_x, ship.arena_y, radius * 2);
|
||||
this.draw(this.primary);
|
||||
} else {
|
||||
this.circle.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Set currently hovered action
|
||||
setSecondary(ship: Game.Ship, action: Game.BaseAction): void {
|
||||
var radius = action.getRangeRadius(ship);
|
||||
if (radius) {
|
||||
this.draw(new Phaser.Circle(ship.arena_x, ship.arena_y, radius * 2));
|
||||
} else {
|
||||
this.circle.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Draw a circle, hinting available range
|
||||
private draw(circle: Phaser.Circle): void {
|
||||
this.circle.clear();
|
||||
this.circle.lineStyle(5, 0x862080, 0.4);
|
||||
this.circle.beginFill(0xD860D0, 0.2);
|
||||
this.circle.drawCircle(circle.x, circle.y, circle.diameter);
|
||||
this.circle.endFill();
|
||||
this.circle.visible = true;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue