2017-07-06 22:55:29 +00:00
|
|
|
module TS.SpaceTac.UI {
|
|
|
|
/**
|
|
|
|
* Dialog to show available missions
|
|
|
|
*/
|
|
|
|
export class MissionsDialog extends UIDialog {
|
|
|
|
shop: Shop
|
|
|
|
player: Player
|
|
|
|
location: StarLocation
|
2017-07-09 21:18:05 +00:00
|
|
|
on_change: Function
|
2017-07-06 22:55:29 +00:00
|
|
|
|
2017-07-09 21:18:05 +00:00
|
|
|
constructor(view: BaseView, shop: Shop, player: Player, on_change?: Function) {
|
2017-07-06 22:55:29 +00:00
|
|
|
super(view);
|
|
|
|
|
|
|
|
this.shop = shop;
|
|
|
|
this.player = player;
|
|
|
|
this.location = player.fleet.location || new StarLocation();
|
2017-07-09 21:18:05 +00:00
|
|
|
this.on_change = on_change || (() => null);
|
2017-07-06 22:55:29 +00:00
|
|
|
|
|
|
|
this.refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Refresh the dialog content
|
|
|
|
*/
|
|
|
|
refresh() {
|
|
|
|
this.clearContent();
|
|
|
|
this.addCloseButton();
|
|
|
|
|
|
|
|
let offset = 160;
|
|
|
|
|
|
|
|
let active = this.player.missions.getCurrent().filter(mission => !mission.main);
|
|
|
|
if (active.length) {
|
|
|
|
this.addText(this.width / 2, offset, "Active jobs", "#b8d2f1", 36);
|
|
|
|
offset += 110;
|
|
|
|
|
|
|
|
active.forEach(mission => {
|
2017-07-10 22:50:38 +00:00
|
|
|
this.addMission(offset, mission, 0, () => null);
|
2017-07-06 22:55:29 +00:00
|
|
|
offset += 110;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
let proposed = this.shop.getMissions(this.location);
|
|
|
|
if (proposed.length) {
|
|
|
|
this.addText(this.width / 2, offset, "Proposed jobs", "#b8d2f1", 36);
|
|
|
|
offset += 110;
|
|
|
|
|
|
|
|
proposed.forEach(mission => {
|
2017-07-10 22:50:38 +00:00
|
|
|
this.addMission(offset, mission, 2, () => {
|
2017-07-06 22:55:29 +00:00
|
|
|
this.shop.acceptMission(mission, this.player);
|
2017-07-16 18:25:36 +00:00
|
|
|
this.close();
|
2017-07-09 21:18:05 +00:00
|
|
|
this.on_change();
|
2017-07-06 22:55:29 +00:00
|
|
|
});
|
|
|
|
offset += 110;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a mission text
|
|
|
|
*/
|
2017-07-10 22:50:38 +00:00
|
|
|
addMission(yoffset: number, mission: Mission, button_frame: number, button_callback: Function) {
|
|
|
|
let title = mission.title;
|
|
|
|
let subtitle = `${capitalize(MissionDifficulty[mission.difficulty])} - Reward: ${mission.getRewardText()}`;
|
|
|
|
|
2017-07-06 22:55:29 +00:00
|
|
|
this.addImage(320, yoffset, "map-missions", 1);
|
|
|
|
if (title) {
|
|
|
|
this.addText(380, yoffset - 15, title, "#d2e1f3", 22, false, false, 620, true);
|
|
|
|
}
|
|
|
|
if (subtitle) {
|
2017-07-10 22:50:38 +00:00
|
|
|
this.addText(380, yoffset + 22, subtitle, "#d2e1f3", 18, false, false, 620, true);
|
2017-07-06 22:55:29 +00:00
|
|
|
}
|
|
|
|
this.addButton(1120, yoffset, button_callback, "map-mission-action", button_frame, button_frame + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|