-
Notifications
You must be signed in to change notification settings - Fork 11
/
ui_mistletoe.js
271 lines (239 loc) · 12.2 KB
/
ui_mistletoe.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/*
Ethereal Farm
Copyright (C) 2020-2024 Lode Vandevenne
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// UI for the ethereal mistletoe
function getMistleInfoText(index, opt_multiline) {
var separator = opt_multiline ? '<br><br>' : '. ';
var m = mistletoeupgrades[index];
var m2 = state.mistletoeupgrades[index];
var done = m.onetime && m2.num;
var tooltiptext = 'Upgrade: ' + m.name;
if(done) {
tooltiptext += separator + 'Upgrade completed (no further levels available)';
} else {
if(m2.time == 0) tooltiptext += separator + 'Time: ' + util.formatDuration(m.getTime());
else tooltiptext += separator + 'Total time: ' + util.formatDuration(m.getTime(), true) + separator + 'Time left: ' + util.formatDuration(m.getTime() - m2.time, true, 4);
var res = m.getResourceCost();
if(res) {
tooltiptext += separator + 'Resource cost: ' + res.toString();
tooltiptext += ' (' /* + have: ' + Res.getMatchingResourcesOnly(res, state.res).toString() + ', '*/ + getCostAffordPercentage(res) + ')';
}
tooltiptext += separator + 'Current level: ' + toRomanUpTo(m2.num);
}
tooltiptext += separator + upper(m.description);
if(m.index != mistle_upgrade_evolve) tooltiptext += separator + 'Unlocked at evolution level ' + toRomanUpTo(m.evo);
if(m.index == mistle_upgrade_evolve) {
var next = etherealMistletoeNextEvolutionUnlockLevel();
//if(next >= 0) tooltiptext += separator + 'Next new upgrade unlocks at evolution level: ' + toRomanUpTo(next) + ' (current level: ' + toRomanUpTo(haveEtherealMistletoeUpgrade(mistle_upgrade_evolve)) + ')';
if(next >= 0) tooltiptext += separator + 'Next new upgrade unlocks at evolution level: ' + next + ' (current level: ' + haveEtherealMistletoeUpgrade(mistle_upgrade_evolve) + ')';
else tooltiptext += separator + 'Next new upgrade unlocks at evolution level: N/A';
tooltiptext += separator + 'Current evolution bonus: ' + getEtherealMistleToeBonusWithEvoString(m.index);
} else if(m.bonus != undefined) {
tooltiptext += separator + 'Current bonus: ' + getEtherealMistleToeBonusWithEvoString(m.index);
}
return tooltiptext;
}
function makeEtherealMistletoeDialog(x, y) {
var f = state.field2[y][x];
var fd = field2Divs[y][x];
var tree_ok = isNextToTree2(x, y, etherealMistletoeSupportsTreeDiagonal());
// uses variables from below, defined here to allow using it at updatedialogfun of the dialog
var updatecontent = function() {
if(!tree_ok) return; // buttons etc... not created, so the below code will crash
if(state.mistletoeupgrades[mistle_upgrade_evolve].num != prev_evo) {
// amount of visible updates changed, more update of all the HTML dialog needed, recreate it completely
closeTopDialog();
makeEtherealMistletoeDialog(x, y);
}
for(var i = 0; i < buttons.length; i++) {
buttons[i].updatefun();
}
var text = '';
if(state.mistletoeupgrade >= 0) {
var m = mistletoeupgrades[state.mistletoeupgrade];
var m2 = state.mistletoeupgrades[state.mistletoeupgrade];
text += 'Upgrading: ' + upper(m.name);
text += '<br>';
var timeleft = m.getTime() - m2.time;
text += 'Time left: ' + util.formatDuration(timeleft, true, 4);
} else {
text += 'Not upgrading';
}
if(state.mistletoeidletime) {
text += '<br>Unused time: ' + util.formatDuration(state.mistletoeidletime, true);// + '. Collected when not upgrading. Makes upgrades go twice as fast.';
} else {
//text += '<br>Unused time: none.';
}
if(haveEtherealMistletoeUpgrade(mistle_upgrade_second_mistletoe) && state.crop2count[mistletoe2_0] < 2) {
text += '<br><b>Note</b>: you can plant a second eth. mistletoe now!';
}
if(text != prevtext) textel.div.innerHTML = text;
prevtext = text;
};
var c = crops2[f.cropIndex()];
var dialog = createDialog({
icon:c.image[4],
title:'Ethereal mistletoe',
bgstyle:'efDialogTranslucent',
functions:[function() {makeField2Dialog(x, y, true); return true;}],
names:['crop info'],
scrollable:true,
help:function(){showRegisteredHelpDialog(41, true);},
cancelname:'close',
updatedialogfun:updatecontent
});
var buttonpos = 0;
var buttonh = 0.07;
var buttonextraseparater = 0.015;
var buttons = [];
if(!tree_ok) {
var replacebutton = new Flex(dialog.content, [0, 0, 0.2], [buttonpos, 0, 0.01], [1, 0, -0.2], buttonpos + buttonh).div;
buttonpos += buttonh;
styleButton(replacebutton);
replacebutton.textEl.innerText = 'Replace crop';
registerTooltip(replacebutton, 'Replace the crop with a new one you choose, same as delete then plant. Shows the list of unlocked ethereal crops.');
addButtonAction(replacebutton, function() {
makePlantDialog2(x, y, true, c.getRecoup());
});
}
// of all the standard plant buttons, the delete button is also shown in the mistletoe dialog. Others can be accessed through the 'crop info' button at the bottom
var deletebutton = new Flex(dialog.content, [0, 0, 0.2], [buttonpos, 0, 0.01], [1, 0, -0.2], buttonpos + buttonh).div;
buttonpos += buttonh;
styleButton(deletebutton);
deletebutton.textEl.innerText = 'Delete crop';
deletebutton.textEl.style.color = '#c00';
registerTooltip(deletebutton, 'Delete crop, get ' + (cropRecoup2 * 100) + '% of the original resin cost back. Only works if deleting in ethereal field is currently possible. While deleted or not planted next to the tree, the mistletoe upgrades are paused.');
addButtonAction(deletebutton, function() {
addAction({type:ACTION_DELETE2, x:x, y:y});
closeAllDialogs();
update(); // do update immediately rather than wait for tick, for faster feeling response time
});
buttonpos += buttonextraseparater;
if(!tree_ok) {
var textel = new Flex(dialog.content, [0, 0, 0.2], [buttonpos, 0, 0.01], [1, 0, -0.2], 0.8);
if(state.etherealmistletoenexttotree) {
textel.div.innerText = 'The ethereal mistletoe must be planted orthogonally (not diagonally) next to the tree, otherwise it does nothing and does not boost neighbors.'; // you still have another one next to the tree so upgrades not paused, but at least clearly indicate it still doesn't boost neighbors
} else {
textel.div.innerText = 'The ethereal mistletoe must be planted orthogonally (not diagonally) next to the tree, otherwise it does nothing. Its upgrades are currently paused.';
}
return;
}
// of all the standard plant buttons, the delete button is also shown in the mistletoe dialog. Others can be accessed through the 'crop info' button at the bottom
var cancelbutton = new Flex(dialog.content, [0, 0, 0.2], [buttonpos, 0, 0.01], [1, 0, -0.2], buttonpos + buttonh).div;
buttonpos += buttonh;
styleButton(cancelbutton);
cancelbutton.textEl.innerText = 'Stop current upgrade';
registerTooltip(cancelbutton, 'Stops current ongoing upgrade, if there is one. The current time duration of the ongoing upgrade will be remembered, so if you start it again later it will continue where it left off. This also works if doing other upgrades in-between.');
addButtonAction(cancelbutton, function() {
addAction({type:ACTION_CANCEL_MISTLE_UPGRADE});
update(); // do update immediately rather than wait for tick, for faster feeling response time
updatecontent();
});
buttons.push(cancelbutton);
cancelbutton.updatefun = function() {
if(state.mistletoeupgrade < 0) {
cancelbutton.textEl.style.color = '#888';
} else {
cancelbutton.textEl.style.color = '';
}
};
var textel = new Flex(dialog.content, [0, 0, 0.2], [buttonpos, 0, 0.01], [1, 0, -0.2], 0.8);
buttonpos += 0.12;
var buttonh2 = 0.08;
for(var i = 0; i < mistle_sort_order.length; i++) {
var index = mistle_sort_order[i];
//if(index == mistle_upgrade_resin) buttonpos += buttonextraseparater;
if(!knowEtherealMistletoeUpgrade(index)) continue;
var m = mistletoeupgrades[index];
var m2 = state.mistletoeupgrades[index];
var infobutton = new Flex(dialog.content, [1, 0, -0.19], [buttonpos + buttonh2 / 2, 0, -buttonh2 / 2], [1, 0, -0.19 + buttonh2], [buttonpos + buttonh2 / 2, 0, buttonh2 / 2]).div;
styleButton0(infobutton, true);
var infocanvas = createCanvas('0%', '0%', '100%', '100%', infobutton);
renderImage(image_info, infocanvas);
addButtonAction(infobutton, bind(function(index) {
var m = mistletoeupgrades[index];
var m2 = state.mistletoeupgrades[index];
var dialog = createDialog({title:('Mistletoe upgrade "' + m.name + '" info')});
dialog.content.div.innerHTML = getMistleInfoText(index, true);
}, index));
var button = new Flex(dialog.content, [0, 0, 0.2], [buttonpos, 0, 0.01], [1, 0, -0.2], buttonpos + buttonh2).div;
buttonpos += buttonh2;
//if(index == mistle_upgrade_evolve) buttonpos += buttonextraseparater;
styleButton(button);
addButtonAction(button, bind(function(index) {
if(state.mistletoeupgrade == index) {
addAction({type:ACTION_CANCEL_MISTLE_UPGRADE});
} else {
addAction({type:ACTION_MISTLE_UPGRADE, index});
}
update(); // do update immediately rather than wait for tick, for faster feeling response time
updatecontent();
}, m.index));
var tooltipfun = bind(function(i, opt_multiline) {
var index = mistle_sort_order[i];
return getMistleInfoText(index, false);
}, i);
registerTooltip(button, tooltipfun);
buttons.push(button);
button.updatefun = bind(function(i, button_index) {
var index = mistle_sort_order[i];
var m = mistletoeupgrades[index];
var m2 = state.mistletoeupgrades[index];
var button = buttons[button_index];
var res = m.getResourceCost();
var buttontext = '<b>' + upper(m.name);
if(!m.onetime) buttontext += ' ' + toRomanUpTo(m2.num + 1);
buttontext += '</b>';
if(!(m.onetime && m2.num)) {
var timetext = (m2.time == 0) ? ('Time: ' + util.formatDuration(m.getTime(), true)) : ('Time left: ' + util.formatDuration(m.getTime() - m2.time, true, 4));
if(res) buttontext += '. Cost: ' + res.toString() + ', ' + util.formatDuration(m.getTime() - m2.time, true);
else buttontext += '. ' + timetext;
} else if(m.onetime) {
buttontext += ' (done)';
}
if(m.bonus != undefined) {
var bonusname = 'bonus';
if(m.effectname) bonusname = m.effectname;
buttontext += '<br>';
buttontext += upper(bonusname) + ': ' + getEtherealMistleToeBonusWithEvoString(index);
}
button.textEl.innerHTML = buttontext;
if(state.mistletoeupgrade == index) {
// the currently ongoing upgrade
button.textEl.className = 'efButtonMistletoeOngoing';
} else if(state.mistletoeupgrade >= 0) {
button.textEl.className = 'efButtonMistletoeBusy';
} else if(m.onetime && m2.num) {
button.textEl.className = 'efButtonMistletoeBusy';
} else {
button.textEl.className = '';
}
}, i, buttons.length - 1);
//button.updatefun();
}
buttonpos += buttonextraseparater;
var textel2 = new Flex(dialog.content, [0, 0, 0.2], [buttonpos, 0, 0.01], [1, 0, -0.2], 0.8);
var text2 = '';
if(haveEtherealMistletoeUpgrade(mistle_upgrade_mistle_neighbor)) {
text2 += '<br/>Boosting non-lotus neighbors orthogonally and diagonally: ' + (getEtherealMistletoeNeighborBoost().toPercentString()) + '<br/>';
}
if(haveEtherealMistletoeUpgrade(mistle_upgrade_lotus_neighbor)) {
text2 += 'Boosting lotus neighbors orthogonally and diagonally: ' + (getEtherealMistletoeLotusNeighborBoost().toPercentString()) + '<br/>';
}
textel2.div.innerHTML = text2;
// variables used in updatecontent()
var prevtext = '';
var prev_evo = state.mistletoeupgrades[mistle_upgrade_evolve].num;
updatecontent();
}