2017-02-28 22:34:02 +00:00
|
|
|
module TS.SpaceTac.UI {
|
|
|
|
/**
|
|
|
|
* Display a ship slot, with equipment attached to it
|
|
|
|
*/
|
|
|
|
export class CharacterSlot extends Phaser.Image {
|
2017-03-05 23:29:02 +00:00
|
|
|
sheet: CharacterSheet;
|
|
|
|
|
2017-02-28 22:34:02 +00:00
|
|
|
constructor(sheet: CharacterSheet, x: number, y: number, slot: SlotType) {
|
|
|
|
super(sheet.game, x, y, "character-equipment-slot");
|
|
|
|
|
2017-03-05 23:29:02 +00:00
|
|
|
this.sheet = sheet;
|
|
|
|
|
2017-03-15 21:40:19 +00:00
|
|
|
let sloticon = new Phaser.Button(this.game, 150, 150, `character-slot-${SlotType[slot].toLowerCase()}`);
|
2017-02-28 22:34:02 +00:00
|
|
|
sloticon.anchor.set(0.5, 0.5);
|
|
|
|
this.addChild(sloticon);
|
2017-03-15 21:40:19 +00:00
|
|
|
sheet.view.tooltip.bindStaticText(sloticon, `${SlotType[slot]} slot`);
|
2017-02-28 22:34:02 +00:00
|
|
|
}
|
2017-03-05 17:48:13 +00:00
|
|
|
|
|
|
|
/**
|
2017-03-05 23:29:02 +00:00
|
|
|
* Snap the equipment icon inside the slot
|
|
|
|
*/
|
|
|
|
snapEquipment(equipment: CharacterEquipment) {
|
2017-03-14 17:48:04 +00:00
|
|
|
equipment.position.set(this.x + this.parent.x + 84 * this.scale.x, this.y + this.parent.y + 83 * this.scale.y);
|
|
|
|
equipment.setContainerScale(this.scale.x);
|
2017-03-05 23:29:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if an equipment can be dropped in this slot
|
2017-03-05 17:48:13 +00:00
|
|
|
*/
|
2017-03-05 23:29:02 +00:00
|
|
|
canDropEquipment(equipment: Equipment, x: number, y: number): CharacterEquipmentDrop | null {
|
|
|
|
if (this.getBounds().contains(x, y)) {
|
|
|
|
return {
|
|
|
|
message: "Equip",
|
|
|
|
callback: () => this.sheet.ship.equip(equipment)
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2017-03-05 17:48:13 +00:00
|
|
|
}
|
2017-02-28 22:34:02 +00:00
|
|
|
}
|
|
|
|
}
|