2015-04-07 00:00:00 +00:00
|
|
|
/// <reference path="../BaseView.ts"/>
|
|
|
|
|
2015-03-19 00:00:00 +00:00
|
|
|
module SpaceTac.View {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
// Interactive map of the universe
|
2015-04-07 00:00:00 +00:00
|
|
|
export class UniverseMapView extends BaseView {
|
2015-03-19 00:00:00 +00:00
|
|
|
|
|
|
|
// Displayed universe
|
|
|
|
universe: Game.Universe;
|
|
|
|
|
|
|
|
// Interacting player
|
|
|
|
player: Game.Player;
|
|
|
|
|
|
|
|
// Group for the stars and links
|
2015-03-24 00:00:00 +00:00
|
|
|
private stars: Phaser.Group;
|
|
|
|
|
|
|
|
// Scaling used to transform game coordinates in screen ones
|
|
|
|
private scaling: number;
|
2015-03-19 00:00:00 +00:00
|
|
|
|
|
|
|
// Init the view, binding it to a universe
|
|
|
|
init(universe: Game.Universe, player: Game.Player) {
|
2015-04-07 00:00:00 +00:00
|
|
|
super.init();
|
|
|
|
|
2015-03-19 00:00:00 +00:00
|
|
|
this.universe = universe;
|
|
|
|
this.player = player;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create view graphics
|
|
|
|
create() {
|
2015-04-07 00:00:00 +00:00
|
|
|
super.create();
|
|
|
|
|
2015-03-19 00:00:00 +00:00
|
|
|
this.stars = this.add.group();
|
|
|
|
|
2015-03-30 00:00:00 +00:00
|
|
|
var display_margin = 50;
|
|
|
|
var display_width = 720 - (display_margin * 2);
|
|
|
|
this.scaling = display_width / (this.universe.radius * 2);
|
|
|
|
this.stars.position.set(display_margin + display_width / 2, display_margin + display_width / 2);
|
2015-03-24 00:00:00 +00:00
|
|
|
this.stars.scale.set(this.scaling);
|
2015-03-19 00:00:00 +00:00
|
|
|
|
2015-03-30 00:00:00 +00:00
|
|
|
this.drawAll();
|
2015-03-25 00:00:00 +00:00
|
|
|
|
2015-03-19 00:00:00 +00:00
|
|
|
// Inputs
|
|
|
|
this.input.keyboard.addKey(Phaser.Keyboard.R).onUp.addOnce(this.revealAll, this);
|
2015-03-19 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Leaving the view, unbind and destroy
|
|
|
|
shutdown() {
|
|
|
|
this.universe = null;
|
|
|
|
this.player = null;
|
2015-04-07 00:00:00 +00:00
|
|
|
|
|
|
|
super.shutdown();
|
2015-03-19 00:00:00 +00:00
|
|
|
}
|
2015-03-19 00:00:00 +00:00
|
|
|
|
2015-03-30 00:00:00 +00:00
|
|
|
// Redraw the whole scene
|
|
|
|
drawAll(): void {
|
2015-03-19 00:00:00 +00:00
|
|
|
this.stars.removeAll(true, true);
|
2015-03-30 00:00:00 +00:00
|
|
|
|
|
|
|
this.drawStars();
|
|
|
|
|
|
|
|
this.drawFleet();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw the fleet marker
|
|
|
|
drawFleet(): void {
|
|
|
|
var location = this.player.fleet.location.star;
|
|
|
|
var fleet = this.add.sprite(location.x, location.y, "map-fleet-icon", 0, this.stars);
|
|
|
|
fleet.scale.set(1.0 / this.scaling, 1.0 / this.scaling);
|
|
|
|
fleet.anchor.set(0.5, -0.5);
|
|
|
|
this.game.tweens.create(fleet).to({angle: -360}, 5000, undefined, true, 0, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw the stars and links
|
|
|
|
drawStars(): void {
|
2015-03-19 00:00:00 +00:00
|
|
|
this.universe.starlinks.forEach((link: Game.StarLink) => {
|
|
|
|
if (this.player.hasVisited(link.first) || this.player.hasVisited(link.second)) {
|
|
|
|
var line = this.add.graphics(0, 0, this.stars);
|
|
|
|
line.lineStyle(0.3, 0xA0A0A0);
|
|
|
|
line.moveTo(link.first.x, link.first.y);
|
|
|
|
line.lineTo(link.second.x, link.second.y);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.universe.stars.forEach((star: Game.Star) => {
|
|
|
|
if (this.player.hasVisited(star)) {
|
2015-03-24 00:00:00 +00:00
|
|
|
var sprite = new Phaser.Button(this.game, star.x, star.y, "map-star-icon");
|
|
|
|
sprite.scale.set(1.0 / this.scaling, 1.0 / this.scaling);
|
2015-03-19 00:00:00 +00:00
|
|
|
sprite.anchor.set(0.5, 0.5);
|
2015-03-24 00:00:00 +00:00
|
|
|
|
|
|
|
sprite.onInputUp.add(() => {
|
2015-04-07 00:00:00 +00:00
|
|
|
(<GameUI>this.game).star = star;
|
|
|
|
this.game.state.start("router", true, false);
|
2015-03-24 00:00:00 +00:00
|
|
|
});
|
2015-03-25 00:00:00 +00:00
|
|
|
sprite.input.useHandCursor = true;
|
2015-03-24 00:00:00 +00:00
|
|
|
|
|
|
|
this.stars.addChild(sprite);
|
2015-03-25 00:00:00 +00:00
|
|
|
|
|
|
|
var name = new Phaser.Text(this.game, star.x, star.y, star.name,
|
|
|
|
{align: "center", font: "bold 14px Arial", fill: "#90FEE3"});
|
|
|
|
name.scale.set(1.0 / this.scaling, 1.0 / this.scaling);
|
|
|
|
name.anchor.set(0.5, -0.4);
|
|
|
|
this.stars.addChild(name);
|
2015-03-19 00:00:00 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reveal the whole map (this is a cheat)
|
|
|
|
revealAll(): void {
|
|
|
|
console.warn("Cheat : reveal whole map");
|
|
|
|
this.universe.stars.forEach((star: Game.Star) => {
|
|
|
|
this.player.setVisited(star);
|
|
|
|
});
|
2015-03-30 00:00:00 +00:00
|
|
|
this.drawAll();
|
2015-03-19 00:00:00 +00:00
|
|
|
}
|
2015-03-19 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|