2017-01-09 23:24:33 +00:00
|
|
|
module SpaceTac.View {
|
|
|
|
// Tooltip to display ship information
|
|
|
|
export class ShipTooltip extends Phaser.Sprite {
|
|
|
|
battleview: BattleView;
|
|
|
|
title: Phaser.Text;
|
2017-01-11 00:38:08 +00:00
|
|
|
attr_hull: Phaser.Text;
|
|
|
|
attr_shield: Phaser.Text;
|
|
|
|
attr_power: Phaser.Text;
|
|
|
|
attr_materials: Phaser.Text;
|
|
|
|
attr_electronics: Phaser.Text;
|
|
|
|
attr_energy: Phaser.Text;
|
|
|
|
attr_human: Phaser.Text;
|
|
|
|
attr_gravity: Phaser.Text;
|
|
|
|
attr_time: Phaser.Text;
|
2017-01-16 23:20:33 +00:00
|
|
|
active_effects: Phaser.Group;
|
2017-01-09 23:24:33 +00:00
|
|
|
|
|
|
|
constructor(parent: BattleView) {
|
2017-01-11 00:38:08 +00:00
|
|
|
super(parent.game, 0, 0, "battle-ship-tooltip-own");
|
2017-01-09 23:24:33 +00:00
|
|
|
this.visible = false;
|
|
|
|
this.battleview = parent;
|
|
|
|
|
2017-01-11 00:38:08 +00:00
|
|
|
this.title = new Phaser.Text(this.game, 250, 10, "", { font: "24pt Arial", fill: "#ffffff" });
|
2017-01-09 23:24:33 +00:00
|
|
|
this.title.anchor.set(0.5, 0);
|
|
|
|
this.addChild(this.title);
|
|
|
|
|
2017-01-11 00:38:08 +00:00
|
|
|
this.attr_hull = new Phaser.Text(this.game, 97, 86, "", { font: "18pt Arial", fill: "#eb4e4a", fontWeight: "bold" });
|
|
|
|
this.attr_hull.anchor.set(0.5, 0.5);
|
|
|
|
this.addChild(this.attr_hull);
|
|
|
|
|
|
|
|
this.attr_shield = new Phaser.Text(this.game, 250, 86, "", { font: "18pt Arial", fill: "#2ad8dc", fontWeight: "bold" });
|
|
|
|
this.attr_shield.anchor.set(0.5, 0.5);
|
|
|
|
this.addChild(this.attr_shield);
|
|
|
|
|
|
|
|
this.attr_power = new Phaser.Text(this.game, 397, 86, "", { font: "18pt Arial", fill: "#ffdd4b", fontWeight: "bold" });
|
|
|
|
this.attr_power.anchor.set(0.5, 0.5);
|
|
|
|
this.addChild(this.attr_power);
|
|
|
|
|
|
|
|
this.attr_materials = new Phaser.Text(this.game, 217, 149, "", { font: "14pt Arial", fill: "#d5d5ff", fontWeight: "bold" });
|
|
|
|
this.attr_materials.anchor.set(0.5, 0.5);
|
|
|
|
this.addChild(this.attr_materials);
|
|
|
|
|
|
|
|
this.attr_electronics = new Phaser.Text(this.game, 447, 149, "", { font: "14pt Arial", fill: "#d5d5ff", fontWeight: "bold" });
|
|
|
|
this.attr_electronics.anchor.set(0.5, 0.5);
|
|
|
|
this.addChild(this.attr_electronics);
|
|
|
|
|
|
|
|
this.attr_energy = new Phaser.Text(this.game, 217, 176, "", { font: "14pt Arial", fill: "#d5d5ff", fontWeight: "bold" });
|
|
|
|
this.attr_energy.anchor.set(0.5, 0.5);
|
|
|
|
this.addChild(this.attr_energy);
|
|
|
|
|
|
|
|
this.attr_human = new Phaser.Text(this.game, 447, 176, "", { font: "14pt Arial", fill: "#d5d5ff", fontWeight: "bold" });
|
|
|
|
this.attr_human.anchor.set(0.5, 0.5);
|
|
|
|
this.addChild(this.attr_human);
|
|
|
|
|
|
|
|
this.attr_gravity = new Phaser.Text(this.game, 447, 203, "", { font: "14pt Arial", fill: "#d5d5ff", fontWeight: "bold" });
|
|
|
|
this.attr_gravity.anchor.set(0.5, 0.5);
|
|
|
|
this.addChild(this.attr_gravity);
|
|
|
|
|
|
|
|
this.attr_time = new Phaser.Text(this.game, 217, 203, "", { font: "14pt Arial", fill: "#d5d5ff", fontWeight: "bold" });
|
|
|
|
this.attr_time.anchor.set(0.5, 0.5);
|
|
|
|
this.addChild(this.attr_time);
|
|
|
|
|
2017-01-16 23:20:33 +00:00
|
|
|
this.active_effects = new Phaser.Group(this.game);
|
|
|
|
this.addChild(this.active_effects);
|
|
|
|
|
2017-01-09 23:24:33 +00:00
|
|
|
parent.ui.add(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set current ship to display, null to hide
|
|
|
|
setShip(ship: Game.Ship | null): void {
|
|
|
|
if (ship) {
|
2017-01-11 00:38:08 +00:00
|
|
|
var enemy = ship.getPlayer() != this.battleview.player;
|
|
|
|
this.loadTexture(`battle-ship-tooltip-${enemy ? "enemy" : "own"}`);
|
|
|
|
|
2017-01-09 23:24:33 +00:00
|
|
|
// Find ship sprite to position next to it
|
|
|
|
var sprite = this.battleview.arena.findShipSprite(ship);
|
|
|
|
if (sprite) {
|
2017-01-19 00:27:42 +00:00
|
|
|
var x = sprite.worldPosition.x + sprite.width * sprite.worldScale.x * 0.5;
|
|
|
|
var y = sprite.worldPosition.y - sprite.height * sprite.worldScale.y * 0.5;
|
2017-01-09 23:24:33 +00:00
|
|
|
if (y + this.height > this.battleview.getHeight()) {
|
|
|
|
y = this.battleview.getHeight() - this.height;
|
|
|
|
}
|
|
|
|
if (y < 0) {
|
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
if (x + this.width > this.battleview.getWidth()) {
|
2017-01-19 00:27:42 +00:00
|
|
|
x = sprite.worldPosition.x - sprite.width * sprite.worldScale.x * 0.5 - this.width;
|
2017-01-09 23:24:33 +00:00
|
|
|
}
|
|
|
|
this.position.set(x, y);
|
|
|
|
} else {
|
|
|
|
this.position.set(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fill info
|
|
|
|
this.title.setText(ship.name);
|
2017-01-11 17:31:21 +00:00
|
|
|
this.attr_hull.setText(ship.hull.current.toString());
|
|
|
|
this.attr_shield.setText(ship.shield.current.toString());
|
|
|
|
this.attr_power.setText(ship.ap_current.current.toString());
|
|
|
|
this.attr_materials.setText(ship.cap_material.current.toString());
|
|
|
|
this.attr_electronics.setText(ship.cap_electronics.current.toString());
|
|
|
|
this.attr_energy.setText(ship.cap_energy.current.toString());
|
|
|
|
this.attr_human.setText(ship.cap_human.current.toString());
|
|
|
|
this.attr_gravity.setText(ship.cap_gravity.current.toString());
|
|
|
|
this.attr_time.setText(ship.cap_time.current.toString());
|
2017-01-16 23:20:33 +00:00
|
|
|
this.active_effects.removeAll(true);
|
|
|
|
ship.temporary_effects.forEach((effect, index) => {
|
|
|
|
this.addEffect(effect, index);
|
|
|
|
});
|
2017-01-09 23:24:33 +00:00
|
|
|
|
|
|
|
Animation.fadeIn(this.game, this, 200, 0.9);
|
|
|
|
} else {
|
|
|
|
Animation.fadeOut(this.game, this, 200);
|
|
|
|
}
|
|
|
|
}
|
2017-01-16 23:20:33 +00:00
|
|
|
|
|
|
|
// Add a temporary effect display
|
|
|
|
addEffect(effect: Game.TemporaryEffect, index = 0) {
|
|
|
|
var effect_group = new Phaser.Image(this.game, 27, 243 + 60 * index, "battle-ship-tooltip-effect");
|
|
|
|
this.active_effects.addChild(effect_group);
|
|
|
|
|
|
|
|
var effect_icon = new Phaser.Image(this.game, 30, effect_group.height / 2, `battle-effect-${effect.getFullCode()}`);
|
|
|
|
effect_icon.anchor.set(0.5, 0.5);
|
|
|
|
effect_group.addChild(effect_icon);
|
|
|
|
|
|
|
|
var text = `${effect.getDescription()} (${effect.duration} turns)`;
|
|
|
|
var color = effect.isBeneficial() ? "afe9c6" : "#e9afaf";
|
|
|
|
var effect_text = new Phaser.Text(this.game, 60, effect_group.height / 2, text, { font: "16pt Arial", fill: color });
|
|
|
|
effect_text.anchor.set(0, 0.5);
|
|
|
|
effect_group.addChild(effect_text);
|
|
|
|
}
|
2017-01-09 23:24:33 +00:00
|
|
|
}
|
|
|
|
}
|