2015-04-07 00:00:00 +00:00
|
|
|
/// <reference path="BaseView.ts"/>
|
|
|
|
|
2015-03-12 00:00:00 +00:00
|
|
|
module SpaceTac.View {
|
|
|
|
"use strict";
|
|
|
|
|
2015-04-07 00:00:00 +00:00
|
|
|
export class MainMenu extends BaseView {
|
2015-03-19 00:00:00 +00:00
|
|
|
button_new_game: Phaser.Button;
|
2015-03-12 00:00:00 +00:00
|
|
|
button_quick_battle: Phaser.Button;
|
|
|
|
button_load_game: Phaser.Button;
|
|
|
|
|
|
|
|
preload() {
|
2015-04-07 00:00:00 +00:00
|
|
|
var basex = this.getMidWidth();
|
|
|
|
var y = Math.floor(this.getHeight() * 0.6);
|
|
|
|
var space = this.getWidth() * 0.2;
|
|
|
|
this.button_new_game = this.addButton(basex - space, y, "New Game", this.onNewGame);
|
|
|
|
this.button_quick_battle = this.addButton(basex, y, "Quick Battle", this.onQuickBattle);
|
|
|
|
this.button_load_game = this.addButton(basex + space, y, "Load Game", this.onLoadGame);
|
2015-03-12 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
addButton(x: number, y: number, caption: string, callback: Function): Phaser.Button {
|
|
|
|
var button = this.add.button(x, y, "menu-button", callback, this);
|
|
|
|
button.anchor.set(0.5, 0.5);
|
|
|
|
button.input.useHandCursor = true;
|
|
|
|
|
|
|
|
var text = new Phaser.Text(this.game, 0, 0, caption,
|
|
|
|
{align: "center", font: "bold 20px Arial", fill: "#303030"});
|
|
|
|
text.anchor.set(0.5, 0.5);
|
|
|
|
button.addChild(text);
|
|
|
|
|
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
2015-03-19 00:00:00 +00:00
|
|
|
// Called when "New Game" is clicked
|
|
|
|
onNewGame(): void {
|
|
|
|
var gameui = <GameUI>this.game;
|
|
|
|
|
2015-04-07 00:00:00 +00:00
|
|
|
gameui.session.startNewGame();
|
2015-03-19 00:00:00 +00:00
|
|
|
|
|
|
|
this.game.state.start("router");
|
|
|
|
}
|
|
|
|
|
2015-03-12 00:00:00 +00:00
|
|
|
// Called when "Quick Battle" is clicked
|
|
|
|
onQuickBattle(): void {
|
|
|
|
var gameui = <GameUI>this.game;
|
|
|
|
|
2015-04-07 00:00:00 +00:00
|
|
|
gameui.session.startQuickBattle(true);
|
2015-03-12 00:00:00 +00:00
|
|
|
|
|
|
|
this.game.state.start("router");
|
|
|
|
}
|
|
|
|
|
2015-03-19 00:00:00 +00:00
|
|
|
// Called when "Load Game" is clicked
|
2015-03-12 00:00:00 +00:00
|
|
|
onLoadGame(): void {
|
|
|
|
var gameui = <GameUI>this.game;
|
|
|
|
|
|
|
|
if (gameui.loadGame()) {
|
|
|
|
this.game.state.start("router");
|
|
|
|
} else {
|
|
|
|
var error = this.game.add.text(this.button_load_game.x, this.button_load_game.y + 40,
|
|
|
|
"No saved game found",
|
|
|
|
{font: "bold 16px Arial", fill: "#e04040"});
|
|
|
|
error.anchor.set(0.5, 0.5);
|
|
|
|
var tween = this.game.tweens.create(error);
|
|
|
|
tween.to({y: error.y + 100, alpha: 0}, 1000, Phaser.Easing.Exponential.In);
|
|
|
|
tween.onComplete.addOnce(() => {
|
|
|
|
error.destroy();
|
|
|
|
});
|
|
|
|
tween.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|