1
0
Fork 0

Added character sheet to map view

This commit is contained in:
Michaël Lemaire 2017-02-28 01:07:37 +01:00
parent 760c8ddf27
commit b25e2dc248
4 changed files with 33 additions and 12 deletions

View file

@ -83,7 +83,7 @@ module TS.SpaceTac.UI {
this.ship_list = new ShipList(this);
this.ship_tooltip = new ShipTooltip(this);
this.add.existing(this.ship_tooltip);
this.character_sheet = new CharacterSheet(this);
this.character_sheet = new CharacterSheet(this, -this.getWidth());
this.add.existing(this.character_sheet);
// "Battle" animation

View file

@ -4,9 +4,9 @@ module TS.SpaceTac.UI.Specs {
it("displays fleet and ship information", function () {
let view = testgame.baseview;
let sheet = new CharacterSheet(view);
let sheet = new CharacterSheet(view, -1000);
expect(sheet.x).toEqual(-sheet.width);
expect(sheet.x).toEqual(-1000);
let fleet = new Fleet();
let ship1 = fleet.addShip();

View file

@ -3,6 +3,10 @@ module TS.SpaceTac.UI {
* Character sheet, displaying ship characteristics
*/
export class CharacterSheet extends Phaser.Image {
// X positions
xshown: number;
xhidden: number;
// Currently displayed fleet
fleet: Fleet;
@ -27,10 +31,12 @@ module TS.SpaceTac.UI {
// Attributes and skills
attributes: { [key: string]: Phaser.Text } = {};
constructor(view: BaseView) {
constructor(view: BaseView, xhidden = -2000, xshown = 0) {
super(view.game, 0, 0, "character-sheet");
this.x = -this.width;
this.x = xhidden;
this.xshown = xshown;
this.xhidden = xhidden;
this.inputEnabled = true;
let close_button = new Phaser.Button(this.game, view.getWidth(), 0, "character-close", () => this.hide());
@ -136,17 +142,24 @@ module TS.SpaceTac.UI {
this.updateFleet(ship.fleet);
if (animate) {
this.game.tweens.create(this).to({ x: 0 }, 800, Phaser.Easing.Circular.InOut, true);
this.game.tweens.create(this).to({ x: this.xshown }, 800, Phaser.Easing.Circular.InOut, true);
} else {
this.x = 0;
this.x = this.xshown;
}
}
/**
* Hide the sheet
*/
hide() {
this.game.tweens.create(this).to({ x: -this.width }, 800, Phaser.Easing.Circular.InOut, true);
hide(animate = true) {
this.portraits.children.forEach((portrait: Phaser.Button) => portrait.loadTexture("character-ship"));
if (animate) {
this.game.tweens.create(this).to({ x: this.xhidden }, 800, Phaser.Easing.Circular.InOut, true);
} else {
this.x = this.xhidden;
}
}
}
}

View file

@ -22,6 +22,9 @@ module TS.SpaceTac.UI {
// Button to jump to another system
button_jump: Phaser.Button;
// Character sheet
character_sheet: CharacterSheet;
// Zoom level
zoom = 0;
@ -69,8 +72,13 @@ module TS.SpaceTac.UI {
this.group.addChild(this.button_jump);
this.setZoom(2);
this.add.button(1830, 100, "map-zoom-in", () => this.setZoom(this.zoom + 1)).anchor.set(0.5, 0.5);
this.add.button(1830, 980, "map-zoom-out", () => this.setZoom(this.zoom - 1)).anchor.set(0.5, 0.5);
this.add.button(1520, 100, "map-zoom-in", () => this.setZoom(this.zoom + 1)).anchor.set(0.5, 0.5);
this.add.button(1520, 980, "map-zoom-out", () => this.setZoom(this.zoom - 1)).anchor.set(0.5, 0.5);
this.character_sheet = new CharacterSheet(this, this.getWidth() - 307);
this.character_sheet.show(this.player.fleet.ships[0], false);
this.character_sheet.hide(false);
this.add.existing(this.character_sheet);
this.gameui.audio.startMusic("walking-along");
@ -124,7 +132,7 @@ module TS.SpaceTac.UI {
*/
setCamera(x: number, y: number, span: number, duration = 500, easing = Phaser.Easing.Cubic.InOut) {
let scale = 1000 / span;
this.tweens.create(this.group.position).to({ x: 960 - x * scale, y: 540 - y * scale }, duration, easing).start();
this.tweens.create(this.group.position).to({ x: 800 - x * scale, y: 540 - y * scale }, duration, easing).start();
this.tweens.create(this.group.scale).to({ x: scale, y: scale }, duration, easing).start();
}