Added targetting visual line for move action
This commit is contained in:
parent
8870b8839e
commit
16b67b94a7
|
@ -11,6 +11,9 @@ module SpaceTac.View {
|
|||
// Related game action
|
||||
action: Game.BaseAction;
|
||||
|
||||
// Current targetting
|
||||
private targetting: Targetting;
|
||||
|
||||
// Create an icon for a single ship action
|
||||
constructor(bar: ActionBar, x: number, y:number, ship: Game.Ship, action: Game.BaseAction) {
|
||||
this.battleview = bar.battleview;
|
||||
|
@ -29,15 +32,25 @@ module SpaceTac.View {
|
|||
processClick() {
|
||||
console.log("Action started", this.action);
|
||||
|
||||
var targetting = this.battleview.enterTargettingMode();
|
||||
targetting.targetSelected.add(this.processTarget, this);
|
||||
this.targetting = this.battleview.enterTargettingMode();
|
||||
this.targetting.setSource(this.battleview.arena.findShipSprite(this.ship));
|
||||
this.targetting.targetSelected.add(this.processSelection, this);
|
||||
this.targetting.targetHovered.add(this.processHover, this);
|
||||
}
|
||||
|
||||
// Receive a target for the action
|
||||
processTarget(target: Game.Target) {
|
||||
// Called when a target is hovered
|
||||
// This will check the target against current action and adjust it if needed
|
||||
processHover(target: Game.Target) {
|
||||
target = this.action.checkTarget(this.battleview.battle, this.ship, target);
|
||||
this.targetting.setTarget(target, false);
|
||||
}
|
||||
|
||||
// Called when a target is selected
|
||||
processSelection(target: Game.Target) {
|
||||
console.log("Action target", this.action, target);
|
||||
|
||||
this.action.apply(this.battleview.battle, this.ship, target);
|
||||
this.battleview.exitTargettingMode();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -21,7 +21,7 @@ module SpaceTac.View {
|
|||
super(battleview.game);
|
||||
|
||||
var background = new Phaser.Button(battleview.game, 0, 0, 'ui-arena-background');
|
||||
background.scale.set(5, 5);
|
||||
background.scale.set(20, 10);
|
||||
this.background = background;
|
||||
|
||||
// Capture clicks on background
|
||||
|
|
|
@ -118,7 +118,6 @@ module SpaceTac.View {
|
|||
// Method called when cursor moves in space
|
||||
cursorInSpace(x: number, y: number): void {
|
||||
if (!this.ship_hovered) {
|
||||
console.log("In space", x, y);
|
||||
if (this.targetting) {
|
||||
this.targetting.setTargetSpace(x, y);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,9 @@ module SpaceTac.View {
|
|||
// Access to the parent battle view
|
||||
private battleview: BattleView;
|
||||
|
||||
// Source of the targetting
|
||||
private source: PIXI.Sprite;
|
||||
|
||||
// Current target
|
||||
private target: Game.Target;
|
||||
|
||||
|
@ -14,29 +17,76 @@ module SpaceTac.View {
|
|||
// Signal to receive targetting events
|
||||
targetSelected: Phaser.Signal;
|
||||
|
||||
// Target visual line
|
||||
line: Phaser.Graphics;
|
||||
|
||||
// Create a default targetting mode
|
||||
constructor(battleview: BattleView) {
|
||||
this.battleview = battleview;
|
||||
this.targetHovered = new Phaser.Signal();
|
||||
this.targetSelected = new Phaser.Signal();
|
||||
|
||||
// Visual effects
|
||||
if (battleview) {
|
||||
this.line = new Phaser.Graphics(battleview.game, 0, 0);
|
||||
battleview.arena.add(this.line);
|
||||
}
|
||||
|
||||
this.source = null;
|
||||
this.target = null;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
destroy(): void {
|
||||
this.targetHovered.dispose();
|
||||
this.targetSelected.dispose();
|
||||
if (this.line) {
|
||||
this.line.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
// Update visual effects for current targetting
|
||||
update(): void {
|
||||
if (this.battleview) {
|
||||
if (this.source) {
|
||||
this.line.clear();
|
||||
this.line.lineStyle(3, 0xFFFFFF);
|
||||
this.line.moveTo(this.source.x, this.source.y);
|
||||
this.line.lineTo(this.target.x, this.target.y);
|
||||
this.line.visible = true;
|
||||
} else {
|
||||
this.line.visible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set the source sprite for the targetting (for visual effects)
|
||||
setSource(sprite: PIXI.Sprite) {
|
||||
this.source = sprite;
|
||||
}
|
||||
|
||||
// Set a target from a target object
|
||||
setTarget(target: Game.Target, dispatch: boolean = true):void {
|
||||
this.target = target;
|
||||
if (dispatch) {
|
||||
this.targetHovered.dispatch(this.target);
|
||||
}
|
||||
this.update();
|
||||
}
|
||||
|
||||
// Set no target
|
||||
unsetTarget(dispatch: boolean = true): void {
|
||||
this.setTarget(null, dispatch);
|
||||
}
|
||||
|
||||
// Set the current target ship (when hovered)
|
||||
setTargetShip(ship: Game.Ship): void {
|
||||
this.target = Game.Target.newFromShip(ship);
|
||||
this.targetHovered.dispatch(this.target);
|
||||
setTargetShip(ship: Game.Ship, dispatch: boolean = true): void {
|
||||
this.setTarget(Game.Target.newFromShip(ship), dispatch);
|
||||
}
|
||||
|
||||
// Set the current target in space (when hovered)
|
||||
setTargetSpace(x: number, y: number): void {
|
||||
this.target = Game.Target.newFromLocation(x, y);
|
||||
this.targetHovered.dispatch(this.target);
|
||||
setTargetSpace(x: number, y: number, dispatch: boolean = true): void {
|
||||
this.setTarget(Game.Target.newFromLocation(x, y));
|
||||
}
|
||||
|
||||
// Validate the current target (when clicked)
|
||||
|
|
Loading…
Reference in a new issue