-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathui_tree.js
368 lines (319 loc) · 16.3 KB
/
ui_tree.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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
/*
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/>.
*/
function makeTreeDialog() {
var div;
var have_buttons = state.challenge || automatonUnlocked() || state.challenges_unlocked || state.treelevel >= min_transcension_level;
var shortcutfun = function(e) {
var shift = util.eventHasShiftKey(e);
var ctrl = util.eventHasCtrlKey(e);
if(automatonUnlocked() && (e.key == 'b' || e.key == 'B') && !ctrl) {
if(!blueprintdialogopen) createBlueprintsDialog(false);
}
if(state.challenges_unlocked && (e.key == 'c' || e.key == 'C') && !ctrl) {
if(!challengedialogopen) createChallengeDialog();
}
if(state.treelevel >= min_transcension_level && (e.key == 't' || e.key == 'T') && !ctrl) {
createTranscendDialog();
}
};
var treedialogvisible = true;
var dialog = createDialog({
nocancel:have_buttons,
shortcutfun:shortcutfun,
scrollable:false,
onclose:function(){treedialogvisible = false;},
narrow:true,
title:'Tree',
bgstyle:'efDialogTranslucent'
});
var contentFlex = dialog.content;
var flex = new Flex(dialog.icon, 0, 0, 1, 1);
var canvas = createCanvas('0%', '0%', '100%', '100%', flex.div);
renderImage(tree_images[treeLevelIndex(state.treelevel)][1][getSeason()], canvas);
flex = new Flex(dialog.icon, 0, 1, 1, 2);
canvas = createCanvas('0%', '0%', '100%', '100%', flex.div);
renderImage(tree_images[treeLevelIndex(state.treelevel)][2][getSeason()], canvas);
var ypos = 0;
var ysize = 0.1;
var f0 = new Flex(contentFlex, 0, 0, 1, 0.65);
makeScrollable(f0);
var f1 = new Flex(contentFlex, 0, 0.67, 1, 1);
var createText = function() {
var text;
var show_resin = !state.challenge || challenges[state.challenge].allowsresin;
var show_twigs = !state.challenge || challenges[state.challenge].allowstwigs;
var resin_breakdown = [];
var twigs_breakdown = [];
text = '<b>' + upper(tree_images[treeLevelIndex(state.treelevel)][0]) + '</b><br/>';
text += 'Tree level: ' + state.treelevel + '<br/>';
if(state.treelevel == 0 && state.res.spores.eqr(0)) {
text += 'This tree needs to be rejuvenated first. Requires spores.<br/>';
}
if(state.challenge) {
var c = challenges[state.challenge];
var c2 = state.challenges[state.challenge];
var maxlevel = c2.maxlevel;
if(c.cycling > 1) maxlevel = c2.maxlevels[c2.num_completed % c.cycling];
text += '<br>';
var basic = basicChallenge();
var basicmaxlevel = (basic == 1) ? 30 : 25; // basic challenge capped at level 30, truly basic at 25
var basicfarlevel = 10 + 7; // level considered far enough above the goal of 10, to start showing the note that it's capped
var basiccapped = basic && (maxlevel >= basicmaxlevel || state.treelevel >= basicmaxlevel);
var basicfar = basic && (maxlevel >= basicfarlevel || state.treelevel >= basicfarlevel);
var addbasicmessage = false;
var bonus_before = oneChallengeBonus(0, state.challenge);
var bonus_after = oneChallengeBonusIncludingCurrentRun(0, state.challenge);
var total_bonus_before = totalChallengeBonus(0);
var total_bonus_after = totalChallengeBonusIncludingCurrentRun(0);
if(maxlevel > 0) {
if(state.treelevel > maxlevel) {
text += '<b>Challenge active</b>: ' + upper(c.name) + '. You beat your previous best of lvl ' + maxlevel + ' with lvl ' + state.treelevel;
text += '. This will bring your bonus for this challenge from ' + bonus_before.toPercentString() + ' to ' + bonus_after.toPercentString();
text += ', and your total challenge production bonus from ' + totalChallengeBonus(0).toPercentString() + ' to ' + totalChallengeBonusIncludingCurrentRun(0).toPercentString();
if(basicfar) addbasicmessage = true;
} else if(!basiccapped) {
text += '<b>Challenge active</b>: ' + upper(c.name) + '. You did not yet beat your previous best of lvl ' + maxlevel + '.';
if(basicfar) addbasicmessage = true;
} else {
text += '<b>Challenge active</b>: ' + upper(c.name) + '. You have capped this challenge, you reached ' + maxlevel + ' and it does not give any more bonus or achievements above ' + basicmaxlevel + '.';
}
} else {
text += '<b>Challenge active</b>: ' + upper(c.name);
if(bonus_before.neq(bonus_after)) {
text += '. So far, it will bring your bonus for this challenge from ' + bonus_before.toPercentString() + ' to ' + bonus_after.toPercentString();
text += ', and your total challenge production bonus from ' + total_bonus_before.toPercentString() + ' to ' + total_bonus_after.toPercentString();
if(basicfar) addbasicmessage = true;
}
}
if(addbasicmessage) text += '<br><b>Note:</b> this challenge is capped at level ' + basicmaxlevel + ' and will not give any further bonus or achievements beyond that level';
if(c.targetlevel == undefined) {
if(!c2.completed) {
text += '<br>Challenge goal: <b>' + c.targetdescription + '</b>';
}
} else if(c.targetlevel.length == 0) {
text += '<br>Challenge goal: <b>Increase max level reached for more production bonus</b>';
} else if(c.targetlevel.length > 1) {
if(!c.fullyCompleted()) {
text += '<br>Current challenge target level: <b>' + c.targetlevel[c2.completed] + '</b>';
}
} else {
if(!c2.completed) {
text += '<br>Challenge target level: <b>' + c.targetlevel[0] + '</b>';
}
}
text += '<br>';
}
if(state.treelevel > 0 || state.res.spores.gtr(0)) {
text += '<br/>';
var req = treeLevelReq(state.treelevel + 1);
var nextlevelprogress = state.res.spores.div(treeLevelReq(state.treelevel + 1).spores);
text += 'Next level requires: ' + req.toString() + ' (' + (getCostAffordTimer(req)) + ', ' + nextlevelprogress.toPercentString() + ') ' + '<br/>';
if(state.mistletoes > 0) {
text += 'This requirement was increased ' + (getMistletoeLeech().subr(1)).toPercentString() + ' by ' + state.mistletoes + ' mistletoes' + '<br/>';
}
text += 'Time at this level: ' + util.formatDuration(timeAtTreeLevel(state)) + '<br/>';
text += '<br>';
if(show_resin) {
if(state.challenge && state.treelevel > state.g_treelevel && !state.challenge.allowbeyondhighestlevel) {
text += 'No further resin gained during this challenge, higher level than max regular level reached';
} else {
var progress = state.res.spores.div(treeLevelReq(state.treelevel + 1).spores);
text += 'Resin added at next tree level: ' + nextTreeLevelResin(resin_breakdown).toString() + ' (getting ' + progress.toPercentString() + ' of this so far)';
}
text += '<br/>';
text += 'Total resin ready: ' + getUpcomingResinIncludingFerns().toString();
text += '<br/>';
} else {
text += 'The tree doesn\'t produce resin during this challenge.<br/>';
}
text += '<br/>';
if(state.mistletoes > 0) {
if(show_twigs) {
if(state.challenge && state.treelevel > state.g_treelevel && !state.challenge.allowbeyondhighestlevel) {
text += 'No further twigs gained during this challenge, higher level than max regular level reached';
} else {
var progress = state.res.spores.div(treeLevelReq(state.treelevel + 1).spores);
text += 'Twigs added at next tree level: ' + nextTwigs(twigs_breakdown).twigs.toString() + ' (getting ' + progress.toPercentString() + ' of this so far)';
}
text += '<br>';
text += 'Total twigs ready: ' + getUpcomingTwigs().toString();
text += '<br/>';
} else {
text += 'The tree doesn\'t produce twigs during this challenge.<br/>';
}
text += '<br/>';
}
text += 'Tree level production boost to crops: ' + (getTreeBoost()).toPercentString();
if(getFruitAbility(FRUIT_TREELEVEL, true) > 0) {
var mul = treeLevelFruitBoost(getFruitTier(true), getFruitAbility(FRUIT_TREELEVEL, true), state.treelevel).addr(1);
text += ' (of which ' + mul.toPercentString() + ' multiplicative from the fruit)';
}
text += '<br>';
if(getSeason() == 3) {
text += '<br/>';
text += 'During winter, the tree provides winter warmth: +' + getWinterTreeWarmth().subr(1).toPercentString() + ' berry / mushroom stats and no negative winter effect for any crop next to the tree<br>';
}
if(state.untriedchallenges) {
text += '<br/>';
text += '<span class="efWarningOnDialogText">New challenge available!</span><br>';
}
if(state.upgrades[upgrade_mistunlock].unlocked || state.upgrades[upgrade_sununlock].unlocked || state.upgrades[upgrade_rainbowunlock].unlocked) {
text += '<br/>';
text += 'Abilities discovered:<br>';
if(state.upgrades[upgrade_sununlock].unlocked) text += '• Sun: benefits berries when active<br>';
if(state.upgrades[upgrade_mistunlock].unlocked) text += '• Mist: benefits mushrooms when active<br>';
if(state.upgrades[upgrade_rainbowunlock].unlocked) text += '• Rainbow: benefits flowers when active<br>';
}
if(resin_breakdown && resin_breakdown.length >= 1) {
text += formatBreakdown(resin_breakdown, false, 'Resin gain breakdown');
}
if(twigs_breakdown && twigs_breakdown.length >= 1) {
text += formatBreakdown(twigs_breakdown, false, 'Twigs gain breakdown');
}
if(haveMultiplicity(CROPTYPE_BERRY)) text += '<br>Multiplicities:<br>';
if(haveMultiplicity(CROPTYPE_BERRY)) {
text += '• Berry: +' + (getMultiplicityBonusBase(CROPTYPE_BERRY)).toPercentString() + ' per other of same type of max 1 tier difference<br>';
}
if(haveMultiplicity(CROPTYPE_MUSH)) {
text += '• Mushroom: +' + (getMultiplicityBonusBase(CROPTYPE_MUSH)).toPercentString() + ' per other of same type of max 1 tier difference<br>';
}
if(haveMultiplicity(CROPTYPE_FLOWER)) {
text += '• Flower: +' + (getMultiplicityBonusBase(CROPTYPE_FLOWER)).toPercentString() + ' per other of same type of max 1 tier difference<br>';
}
if(haveMultiplicity(CROPTYPE_BEE)) {
text += '• Bee: +' + (getMultiplicityBonusBase(CROPTYPE_BEE)).toPercentString() + ' per other of same type of max 1 tier difference<br>';
}
if(haveMultiplicity(CROPTYPE_STINGING)) {
text += '• Stinging: +' + (getMultiplicityBonusBase(CROPTYPE_STINGING)).toPercentString() + ' per other of same type of max 1 tier difference<br>';
}
}
return text;
};
var text = createText();
f0.div.innerHTML = text;
var lastseentreelevel = state.treelevel;
registerUpdateListener(function() {
if(!treedialogvisible) return false;
if(lastseentreelevel != state.treelevel) {
lastseentreelevel = state.treelevel;
var text = createText();
f0.div.innerHTML = text;
}
return true;
});
var y = 0.05;
var h = 0.15;
// finetune the width of the buttons in flex f1
var button0 = 0.15;
var button1 = 0.85;
var buttonshift = h * 1.15;
if(state.challenge) {
var c = challenges[state.challenge];
var c2 = state.challenges[state.challenge];
var already_completed = c.fullyCompleted(false);
var success = c.nextCompleted();
var button = new Flex(f1, button0, y, button1, y + h, FONT_BIG_BUTTON).div;
y += buttonshift;
styleButton(button);
button.textEl.innerText = getEndChallengeButtonName(already_completed, success);
if(already_completed && success) {
// Successfully finish, but it already was completed beforehand, so it's called just "finish", not "complete"
registerTooltip(button, 'Finish the challenge. If you broke the max level record, your challenge production bonus will increase.');
} else if(already_completed && !success) {
// End the challenge early, but it already was completed beforehand, so it's called "end", not "abort"
registerTooltip(button, 'End the challenge.');
} else if(success) {
if(c.targetlevel != undefined && c.targetlevel.length == 0) {
registerTooltip(button, 'Finish the challenge. The higher the level reached, the higher the production bonus will be.');
} else if(c2.completed) {
// This is a completion of a higher stage of the challenge
registerTooltip(button, 'Successfully finish the next stage of this challenge.');
} else {
registerTooltip(button, 'Successfully finish the challenge for the first time.');
}
} else {
// Abort the attempt to complete this challenge, it remainds unfinished. But it can still give the challenge highest level production bonus.
if(c.targetlevel != undefined && c.targetlevel.length > 1) {
registerTooltip(button, 'Open the dialog to abort the challenge, you don\'t get its next reward, but if you broke the max level record, your challenge production bonus will still increase. The dialog will show the amounts.');
} else {
registerTooltip(button, 'Open the dialog to abort the challenge, you don\'t get its one-time reward, but if you broke the max level record, your challenge production bonus will still increase. The dialog will show the amounts.');
}
}
//button.textEl.style.boxShadow = '0px 0px 5px #f40';
button.textEl.style.textShadow = '0px 0px 5px #f40';
addButtonAction(button, function() {
createFinishChallengeDialog();
});
button = new Flex(f1, button0, y, button1, y + h, FONT_BIG_BUTTON).div;
y += buttonshift;
styleButton(button);
button.textEl.innerText = 'Current challenge info';
registerTooltip(button, 'Description and statistics for the current challenge');
addButtonAction(button, function() {
createChallengeDescriptionDialog(state.challenge, true, false);
});
} else if(state.treelevel < min_transcension_level) {
//if(state.treelevel >= 1) f1.div.innerText = 'Reach tree level ' + min_transcension_level + ' to unlock transcension';
if(state.treelevel >= 1) {
var temp = new Flex(f1, button0, y, button1, y + h);
temp.div.innerText = 'Reach tree level ' + min_transcension_level + ' to unlock transcension';
y += buttonshift;
}
} else {
var button = new Flex(f1, button0, y, button1, y + h, FONT_BIG_BUTTON).div;
y += buttonshift;
styleButton(button);
button.textEl.innerText = 'Transcension';
//button.textEl.style.boxShadow = '0px 0px 5px #ff0';
button.textEl.style.textShadow = '0px 0px 5px #ff0';
registerTooltip(button, 'Show the transcension dialog');
addButtonAction(button, function() {
createTranscendDialog();
});
if(state.challenges_unlocked) {
button = new Flex(f1, button0, y, button1, y + h, FONT_BIG_BUTTON).div;
y += buttonshift;
styleButton(button);
button.textEl.innerText = 'Challenges';
//button.textEl.style.boxShadow = '0px 0px 5px #f60';
button.textEl.style.textShadow = '0px 0px 5px #f60';
registerTooltip(button, 'Transcend and start a challenge');
addButtonAction(button, function() {
createChallengeDialog();
});
}
}
if(automatonUnlocked()) {
button = new Flex(f1, button0, y, button1, y + h, FONT_BIG_BUTTON).div;
y += buttonshift;
styleButton(button);
button.textEl.innerText = 'Blueprints';
//button.textEl.style.boxShadow = '0px 0px 5px #44f';
button.textEl.style.textShadow = '0px 0px 5px #008';
addButtonAction(button, function() {
//closeAllDialogs();
createBlueprintsDialog();
});
}
if(have_buttons) {
button = new Flex(f1, button0, y, button1, y + h, FONT_BIG_BUTTON).div;
y += buttonshift;
styleButton(button);
button.textEl.innerText = 'Back';
addButtonAction(button, function() {
dialog.cancelFun();
});
}
}