character sheet: Added pagination for loot and shop
This commit is contained in:
parent
eb28591abd
commit
2f706aa8c5
1
TODO
1
TODO
|
@ -1,7 +1,6 @@
|
|||
* UI: Use a common component class, and a layer abstraction
|
||||
* Character sheet: add initial character creation
|
||||
* Character sheet: disable interaction during battle (except for loot screen)
|
||||
* Character sheet: paginate loot and shop items
|
||||
* Character sheet: improve eye-catching for shop and loot section
|
||||
* Character sheet: highlight allowed destinations during drag-and-drop
|
||||
* Add permanent effects to ship models to ease balancing
|
||||
|
|
|
@ -11,7 +11,9 @@ module TS.SpaceTac.Specs {
|
|||
it("buys and sells items", function () {
|
||||
let shop = new Shop();
|
||||
let equ1 = new Equipment(SlotType.Shield, "shield");
|
||||
equ1.price = 50;
|
||||
let equ2 = new Equipment(SlotType.Hull, "hull");
|
||||
equ2.price = 150;
|
||||
shop.stock = [equ1, equ2];
|
||||
let fleet = new Fleet();
|
||||
fleet.credits = 1000;
|
||||
|
@ -28,7 +30,7 @@ module TS.SpaceTac.Specs {
|
|||
|
||||
result = shop.buyFromFleet(equ1, fleet);
|
||||
expect(result).toBe(true);
|
||||
expect(shop.stock).toEqual([equ2, equ1]);
|
||||
expect(shop.stock).toEqual([equ1, equ2]);
|
||||
expect(fleet.credits).toEqual(1000);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -64,6 +64,7 @@ module TS.SpaceTac {
|
|||
buyFromFleet(equipment: Equipment, fleet: Fleet) {
|
||||
let price = this.getPrice(equipment);
|
||||
if (add(this.stock, equipment)) {
|
||||
this.sortStock();
|
||||
fleet.credits += price;
|
||||
return true;
|
||||
} else {
|
||||
|
|
|
@ -43,6 +43,9 @@ module TS.SpaceTac.UI {
|
|||
// Loot items
|
||||
loot_slots: Phaser.Group;
|
||||
loot_items: Equipment[] = [];
|
||||
loot_page = 0;
|
||||
loot_next: Phaser.Button;
|
||||
loot_prev: Phaser.Button;
|
||||
|
||||
// Shop
|
||||
shop: Shop | null = null;
|
||||
|
@ -117,6 +120,15 @@ module TS.SpaceTac.UI {
|
|||
this.mode_title.anchor.set(0.5, 0.5);
|
||||
this.addChild(this.mode_title);
|
||||
|
||||
this.loot_next = new Phaser.Button(this.game, 1890, 850, "character-scroll", () => this.paginate(1));
|
||||
this.loot_next.anchor.set(0.5, 0.5);
|
||||
this.addChild(this.loot_next);
|
||||
|
||||
this.loot_prev = new Phaser.Button(this.game, 1238, 850, "character-scroll", () => this.paginate(-1));
|
||||
this.loot_prev.anchor.set(0.5, 0.5);
|
||||
this.loot_prev.angle = 180;
|
||||
this.addChild(this.loot_prev);
|
||||
|
||||
let x1 = 664;
|
||||
let x2 = 1066;
|
||||
let y = 662;
|
||||
|
@ -269,6 +281,8 @@ module TS.SpaceTac.UI {
|
|||
* This list will be shown until sheet is closed
|
||||
*/
|
||||
setLoot(loot: Equipment[]) {
|
||||
this.loot_page = 0;
|
||||
|
||||
this.loot_items = loot;
|
||||
this.updateLoot();
|
||||
this.loot_slots.visible = true;
|
||||
|
@ -283,6 +297,8 @@ module TS.SpaceTac.UI {
|
|||
* This shop will be shown until sheet is closed
|
||||
*/
|
||||
setShop(shop: Shop) {
|
||||
this.loot_page = 0;
|
||||
|
||||
this.shop = shop;
|
||||
this.updateLoot();
|
||||
this.loot_slots.visible = true;
|
||||
|
@ -300,26 +316,39 @@ module TS.SpaceTac.UI {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the page displayed in loot/shop section
|
||||
*/
|
||||
paginate(offset: number) {
|
||||
let items = this.shop ? this.shop.stock : this.loot_items;
|
||||
this.loot_page = clamp(this.loot_page + offset, 0, 1 + Math.floor(items.length / 12));
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the loot slots
|
||||
*/
|
||||
private updateLoot() {
|
||||
let per_page = 12;
|
||||
this.loot_slots.removeAll(true);
|
||||
|
||||
let info = CharacterSheet.getSlotPositions(12, 588, 354, 196, 196);
|
||||
range(12).forEach(idx => {
|
||||
let items = this.shop ? this.shop.stock : this.loot_items;
|
||||
range(per_page).forEach(idx => {
|
||||
let loot_slot = this.shop ? new CharacterShopSlot(this, info.positions[idx].x, info.positions[idx].y) : new CharacterLootSlot(this, info.positions[idx].x, info.positions[idx].y);
|
||||
loot_slot.scale.set(info.scaling, info.scaling);
|
||||
this.loot_slots.addChild(loot_slot);
|
||||
|
||||
if (idx < this.loot_items.length) {
|
||||
let equipment = new CharacterEquipment(this, this.loot_items[idx], loot_slot);
|
||||
this.equipments.addChild(equipment);
|
||||
} else if (this.shop && idx < this.shop.stock.length) {
|
||||
let equipment = new CharacterEquipment(this, this.shop.stock[idx], loot_slot);
|
||||
idx += per_page * this.loot_page;
|
||||
|
||||
if (idx < items.length) {
|
||||
let equipment = new CharacterEquipment(this, items[idx], loot_slot);
|
||||
this.equipments.addChild(equipment);
|
||||
}
|
||||
});
|
||||
|
||||
this.view.animations.setVisible(this.loot_prev, this.loot_page > 0, 200);
|
||||
this.view.animations.setVisible(this.loot_next, (this.loot_page + 1) * per_page < items.length, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,12 +6,20 @@ module TS.SpaceTac.UI {
|
|||
game: Phaser.Game;
|
||||
};
|
||||
|
||||
/**
|
||||
* Interface of an object that may be enabled/disabled.
|
||||
*/
|
||||
interface IAnimationEnableable {
|
||||
enabled: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface of an object that may be shown/hidden, with opacity transition.
|
||||
*/
|
||||
interface IAnimationFadeable {
|
||||
alpha: number;
|
||||
visible: boolean;
|
||||
input?: IAnimationEnableable;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -62,6 +70,10 @@ module TS.SpaceTac.UI {
|
|||
|
||||
let tween = this.createTween(obj);
|
||||
tween.to({ alpha: alpha }, duration);
|
||||
if (obj.input) {
|
||||
let input = obj.input;
|
||||
tween.onComplete.addOnce(() => input.enabled = true);
|
||||
}
|
||||
tween.start();
|
||||
}
|
||||
|
||||
|
@ -69,6 +81,10 @@ module TS.SpaceTac.UI {
|
|||
* Hide an object, with opacity transition
|
||||
*/
|
||||
hide(obj: IAnimationFadeable, duration = 1000): void {
|
||||
if (obj.input) {
|
||||
obj.input.enabled = false;
|
||||
}
|
||||
|
||||
let tween = this.createTween(obj);
|
||||
tween.to({ alpha: 0 }, duration);
|
||||
tween.onComplete.addOnce(() => obj.visible = false);
|
||||
|
|
Loading…
Reference in a new issue