-
Notifications
You must be signed in to change notification settings - Fork 66
/
UIOutPopupInnSystem.js
98 lines (82 loc) · 3.85 KB
/
UIOutPopupInnSystem.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
define([
'ash',
'game/constants/UIConstants',
'game/constants/ItemConstants',
'game/constants/FightConstants',
'game/nodes/player/ItemsNode',
], function (Ash, UIConstants, ItemConstants, FightConstants, ItemsNode) {
var UIOutPopupInnSystem = Ash.System.extend({
uiFunctions: null,
itemNodes: null,
constructor: function (uiFunctions, gameState) {
this.uiFunctions = uiFunctions;
this.gameState = gameState;
return this;
},
addToEngine: function (engine) {
this.itemNodes = engine.getNodeList(ItemsNode);
},
removeFromEngine: function (engine) {
this.itemNodes = null;
},
update: function (time) {
if (!($("#inn-popup").is(":visible")) || $("inn-popup").data("fading") == true) {
this.wasVisible = false;
return;
}
if (!this.wasVisible) {
this.initializePopup();
}
this.wasVisible = true;
},
initializePopup: function () {
this.refreshCurrent();
var sys = this;
$("table#inn-popup-options-followers button").click(function (e) {
var followerID = $(this).attr("followerID");
sys.selectFollower(followerID);
});
},
refreshCurrent: function () {
var currentFollowers = this.itemNodes.head.items.getAllByType(ItemConstants.itemTypes.follower);
var numFollowers = currentFollowers.length;
$("#inn-popup-current-desc").text("Current followers: " + numFollowers + " / " + FightConstants.getMaxFollowers(this.gameState.numCamps));
$("table#inn-popup-current-followers").empty();
$("table#inn-popup-current-followers").append("<tr></tr>");
for (var i = 0; i < currentFollowers.length; i++) {
var td = "<td id='td-item-use_in_inn_select-" + currentFollowers[i].id + "'>";
td += UIConstants.getItemDiv(currentFollowers[i], false);
td += "</td>";
$("table#inn-popup-current-followers tr").append(td);
}
$("table#inn-popup-current-followers").append("<tr></tr>");
for (var j = 0; j < currentFollowers.length; j++) {
var td = "<td>";
td += "<button class='action btn-narrow' action='use_in_inn_disband_" + currentFollowers[j].id + "' followerID='" + currentFollowers[j].id + "'>Disband</button>";
td += "</td>";
$($("table#inn-popup-current-followers tr")[1]).append(td);
}
this.uiFunctions.generateCallouts("#inn-popup-current-followers");
this.uiFunctions.generateButtonOverlays("#inn-popup-current-followers");
var sys = this;
$("table#inn-popup-current-followers button").click(function (e) {
var followerID = $(this).attr("followerID");
sys.disbandFollower(followerID, sys);
});
},
selectFollower: function (followerID) {
var follower = ItemConstants.getFollowerByID(followerID);
this.uiFunctions.playerActions.playerActionsHelper.deductCosts("use_in_inn_select")
this.uiFunctions.playerActions.addFollower(follower);
this.uiFunctions.popupManager.closePopup("inn-popup");
},
disbandFollower: function (followerID) {
// TODO pass to player action functions & unify with UIOoutBagSystem
var item = this.itemNodes.head.items.getItem(followerID);
this.itemNodes.head.items.discardItem(item);
this.itemNodes.head.items.selectedItem = null;
this.refreshCurrent();
},
});
return UIOutPopupInnSystem;
});