-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobal_menu.lua
More file actions
908 lines (801 loc) · 25.1 KB
/
global_menu.lua
File metadata and controls
908 lines (801 loc) · 25.1 KB
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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
--
--Copyright (C) 2022 Matthias Gatto
--
--This program is free software: you can redistribute it and/or modify
--it under the terms of the GNU Lesser 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 Lesser General Public License
--along with this program. If not, see <http://www.gnu.org/licenses/>.
--
local lpcs = Entity.wrapp(ygGet("lpcs"))
local phq = Entity.wrapp(ygGet("phq"))
local stores = Entity.wrapp(ygGet("phq.stores"))
GM_INV_IDX = 0
GM_STATS_IDX = 1
GM_QUEST_IDX = 2
GM_MAP_IDX = 3
GM_MISC_IDX = 4
function globMnMoveOn(menu, current)
local main = Entity.wrapp(ywCntWidgetFather(menu))
current = yLovePtrToNumber(current)
if current == GM_INV_IDX then
invList(menu)
elseif current == GM_STATS_IDX then
pushStatus(menu)
elseif current == GM_QUEST_IDX then
pushQuests(menu)
elseif current == GM_MISC_IDX then
ywCntPopLastEntry(main)
pushMainMenu(main)
elseif current == GM_MAP_IDX then
ywCntPopLastEntry(main)
pushMetroMenu(main)
end
main.entries[1].in_subcontained = 1
main.current = 0
return YEVE_NOACTION;
end
function gmLooseFocus(mn)
local main = Entity.wrapp(ywCntWidgetFather(mn))
main.current = 1
return YEVE_NOACTION;
end
function gmGetBackFocus(mn)
local main = Entity.wrapp(ywCntWidgetFather(mn))
if main.isChildContainer then
main = Entity.wrapp(ywCntWidgetFather(main))
end
main.current = 0
return YEVE_NOACTION;
end
function openGlobalMenu(_useless0, _usless1, pos)
local idx = 0
pos = yeGetString(pos)
if pos == "stats" then
idx = GM_STATS_IDX
end
return openGlobMenu(main_widget, idx, true)
end
function openGlobMenu(main, on_idx, arg0)
local mn = Container.new_entity("horizontal")
--mn.ent.action = Entity.new_func("backToGameOnEnter")
mn.ent.background = "rgba: 155 155 255 190"
mn.ent.auto_foreground = "rgba: 0 0 120 50"
local force_in = false
if arg0 then
if type(arg0) ~= "boolean" then
backToGame(main)
main = main_widget
on_idx = yeGetInt(arg0)
usable_metro = true
end
force_in = true
end
local panel = Menu.new_entity()
local lf = Entity.new_func(gmLooseFocus)
panel.ent["mn-type"] = "panel"
panel:push("Inventory", lf)
panel:push("Status", lf)
panel:push("Quests")
panel:push("Map", lf)
panel:push("MISC (and boo)", lf)
panel.ent.in_subcontained = 1
panel.ent.size = 5
panel.ent.moveOn = Entity.new_func(globMnMoveOn)
panel.ent.onEsc = Entity.new_func(backToGame2)
local on_down = Entity.new_array()
on_down[0] = Y_DOWN_KEY
on_down[1] = lf
panel.ent.on = {}
panel.ent.on[0] = on_down
local ts = Entity.new_array()
ts["<type>"] = "text-screen"
ts.text = ""
mn.ent.entries[0] = panel.ent
mn.ent.entries[1] = ts
ywPushNewWidget(main, mn.ent)
ywCntConstructChilds(main)
ywMenuMove(panel.ent, on_idx)
if force_in == true then
mn.ent.current = 1
end
return YEVE_ACTION
end
function pushQuests(panel)
local main = ywCntWidgetFather(panel)
local txt = "----- quests -----\n"
ywCntPopLastEntry(main)
local txt_screen = Entity.new_array()
-- quests_info
local i = 0
while i < yeLen(quests_info) do
local quest = quests_info[i]
local stalk_sart = yeGetIntAt(quest, "stalk_sart")
local stalk_path = yeGetStringAt(quest, "stalk")
local cur = yeGetInt(ygGet(stalk_path))
if (cur > stalk_sart) then
local descs = quest.descriptions
txt = txt .. "[ " .. yeGetKeyAt(quests_info, i) .. " ]\n"
if cur >= yeLen(descs) then
txt = txt .. "completed !\n"
else
local gc = Entity.new_array()
local desc_txt = yeCreateYirlFmtString(yeGet(descs, cur), gc)
txt = txt .. yeGetString(desc_txt) .. "\n"
end
end
i = i + 1
end
-- widget boring stuff
txt_screen["<type>"] = "text-screen"
txt_screen["text-align"] = "center"
txt_screen.text = txt
txt_screen.action = Entity.new_func("gmGetBackFocus")
txt_screen.background = "rgba: 155 155 255 190"
ywPushNewWidget(main, txt_screen)
end
function pushSTatusTextScreen(container)
local txt_screen = Entity.new_array()
local knowledge_str = "----- Knowledge -----\n"
local knowledge = phq.pj.knowledge
local stats_str = "----- Stats -----\n"
local stats = phq.pj.stats
local invocks = phq.pj.invok
local invocks_str = "" -- "----- Invoks -----\n"
local trait_str = "----- Trait -----\n"
local trait = phq.pj.trait
local cmb_str = "-[Currrent Fighting Skill: {phq.pj.attack}]-\n"
local school_club = ""
local follower = ""
local i = 0
while i < yeLen(knowledge) do
if knowledge[i] then
knowledge_str = knowledge_str .. yeGetKeyAt(knowledge, i) ..
": {phq.pj.knowledge." .. math.floor(i) .. "}\n"
end
i = i + 1
end
i = 0
while i < yeLen(stats) do
if stats[i] then
stats_str = stats_str .. yeGetKeyAt(stats, i) ..
": {phq.pj.stats." .. math.floor(i) .. "}\n"
end
i = i + 1
end
i = 0
while i < yeLen(trait) do
if trait[i] then
local trait_k = yeGetKeyAt(trait, i)
local trait_v = math.floor(yeGetInt(trait[i]))
if trait_k == 'grumpy' then
trait_k = "positiveness"
trait_v = -trait_v
end
trait_str = trait_str ..
trait_k .. ": " .. trait_v .. "\n"
end
i = i + 1
end
if yIsNNil(invocks) then
invocks_str = "----- Invoks -----\n"
i = 0
while i < yeLen(invocks) do
if invocks[i] then
local invocks_k = yeGetKeyAt(invocks, i)
invocks_str = invocks_str .. invocks_k .. ""
end
i = i + 1
end
invocks_str = invocks_str .. "\n"
end
local chap_txt = "capter: "
if yeGetInt(phq.env.chapter) < 1 then
chap_txt = chap_txt .. "Prologue"
else
chap_txt = chap_txt .. math.floor(yeGetInt(phq.env.chapter))
end
local pj_orgas = phq.pj.organisations
if yeLen(pj_orgas) > 0 then
school_club = "club:"
for j = 0, yeLen(pj_orgas) - 1 do
if j ~= 0 then
school_club = school_club .. ";"
end
school_club = school_club .. " " .. pj_orgas[j]:to_string()
end
school_club = school_club .. "\n"
end
local allies = phq.pj.allies
if yeLen(allies) > 0 then
follower = "follower: "
for j = 0, yeLen(allies) - 1 do
if j > 0 then
follower = follower .. ", "
end
follower = follower .. yeGetKeyAt(allies, j)
end
end
txt_screen["<type>"] = "text-screen"
txt_screen["text-align"] = "center"
txt_screen.fmt = "yirl"
txt_screen.text = chap_txt .. "\nDay: " ..
DAY_STR[phq.env.day:to_int() + 1] .. ", {phq.env.time}\n" ..
"week: {phq.env.week}\n" ..
"days spend at school: {phq.env.school_day}\n" ..
"time point: {phq.env.time_point}\n" ..
"Status:\n" ..
"life: {phq.pj.life}\n" ..
"xp: {phq.pj.xp} \n" ..
invocks_str ..
alcohol_lvl_str() ..
knowledge_str ..
stats_str ..
trait_str ..
cmb_str ..
school_club ..
follower
txt_screen.background = "rgba: 155 155 255 190"
ywPushNewWidget(container, txt_screen)
end
function alcohol_lvl_str()
if (phq.pj.drunk:to_int() > 1) then
return "alcohol level: {phq.pj.drunk}\n"
end
return ""
end
function popGlobMnOtherMenu(mn)
local main = ywCntWidgetFather(ywCntWidgetFather(mn))
ywCntPopLastEntry(main)
return YEVE_ACTION
end
function spendXpBack(mn)
local main = ywCntWidgetFather(mn)
ywCntPopLastEntry(main)
return YEVE_ACTION
end
function computeStatCost(st_val)
return (st_val + 1) * 3
end
local function computeXpCost(player)
local ml = player.max_life:to_int()
ml = ml - 10
local multiplier = ml / 5
return 1 + multiplier
end
function spendXpLvlUpStat(mn)
local stats = phq.pj.stats
local st_idx = yeGetIntAt(ywMenuGetCurrentEntry(mn), "arg")
local st_val_ent = yeGet(stats, st_idx)
local st_val = yeGetInt(st_val_ent)
local cost = computeStatCost(st_val)
print("spendXpLvlUpStat", ywMenuGetCurrentEntry(mn))
print(Entity.wrapp(ywMenuGetCurrentEntry(mn)).arg,
st_val, cost, cost < phq.pj.xp)
if math.floor(cost) <= phq.pj.xp then
phq.pj.xp = phq.pj.xp - cost
yeSetInt(st_val_ent, st_val + 1)
else
print("someday, you will improve ",
yeGetKeyAt(stats, st_idx),
" but this day is not today !")
end
spendXpGenMenu(Menu.wrapp(mn))
return YEVE_ACTION
end
function sendXpLvlUpXp(mn)
local player = phq.pj
local ml = player.max_life
local life = player.life
local cost = computeXpCost(player)
if math.floor(cost) <= player.xp then
player.xp = player.xp - cost
yeSetInt(life, life + 1)
yeSetInt(ml, ml + 1)
else
print("someday, you be stronger but this day is not today !")
end
spendXpGenMenu(Menu.wrapp(mn))
return YEVE_ACTION
end
function spendXpGenMenu(statsMenu)
local stats = phq.pj.stats
statsMenu.ent["pre-text"] = "current xp: " .. yeGetInt(phq.pj.xp)
statsMenu.ent.entries = {}
local spendXpBack = Entity.new_func(spendXpBack)
statsMenu:push("<----", spendXpBack)
statsMenu.ent.onEsc = spendXpBack
local i = 0
while i < yeLen(stats) do
if stats[i] then
local st_val = yeGetInt(stats[i])
local stats_str = yeGetKeyAt(stats, i) .. "(" ..
math.floor(st_val) .. "): " ..
math.floor(computeStatCost(st_val)) .. " xp"
statsMenu:push(stats_str, Entity.new_func(spendXpLvlUpStat), i)
end
i = i + 1
end
local xp_cost = math.floor(computeXpCost(phq.pj))
statsMenu:push("max life: (" .. phq.pj.max_life:to_int() .. "): "
.. xp_cost .. " xp", Entity.new_func(sendXpLvlUpXp))
end
function spendXpOnStats(mn)
local main = ywCntWidgetFather(mn)
local statsMenu = Menu.new_entity()
spendXpGenMenu(statsMenu)
ywPushNewWidget(main, statsMenu.ent)
return YEVE_ACTION
end
function increase_recover_lvl(_mn)
phq.pj.recover_level = yeGetIntAt(phq.pj, "recover_level") + 1
return YEVE_ACTION
end
local function genLearnableSkill(nmn)
local cmbs = phq.pj.combots
local leanable_cmbs = phq.skills.combots
local recover_improvement = phq.skills.recovers
local i = 0
print(phq.pj.combots)
print(phq.skills.combots)
nmn.ent["pre-text"] = "current xp: " .. yeGetInt(phq.pj.xp)
nmn.ent.entries = {}
local spendXpBack = Entity.new_func("spendXpBack")
nmn:push( "<----", spendXpBack)
nmn.ent.onEsc = spendXpBack
while i < yeLen(leanable_cmbs) do
local ccmb = leanable_cmbs[i]
local cmb_name = yeGetKeyAt(leanable_cmbs, i)
if yIsNNil(yeFindString(cmbs, cmb_name)) then
goto next
end
nmn:push(cmb_name .. " : " .. ccmb.cost:to_int(),
Entity.new_func(learnSkillCombot), cmb_name)
:: next ::
i = i + 1
end
local r_level = yeGetIntAt(phq.pj, "recover_level")
local r_name = yeGetKeyAt(recover_improvement, r_level)
local r_skill = recover_improvement[r_level]
nmn:push(r_name .. " : " .. r_skill.cost:to_int(),
Entity.new_func(increase_recover_lvl))
end
function learnSkillCombot(mn)
print("learn combot:", Entity.wrapp(ywMenuGetCurrentEntry(mn)))
learn_combot(yeGetStringAt(ywMenuGetCurrentEntry(mn), "arg"))
genLearnableSkill(Menu.wrapp(mn))
return YEVE_ACTION
end
function learnableSkill(mn)
local main = ywCntWidgetFather(mn)
local nmn = Menu.new_entity()
genLearnableSkill(nmn)
ywPushNewWidget(main, nmn.ent)
return YEVE_ACTION
end
function pushSpendXpWid(mn)
-- 1: get status vertical container
-- 2: get global menu horizontal container
-- 3: get main stacking container
local main = ywCntWidgetFather(ywCntWidgetFather(ywCntWidgetFather(mn)))
main = Entity.wrapp(main)
local lvlUp = Container.new_entity("vertical")
lvlUp.ent.background = "rgba: 255 255 255 255"
local menu = Menu.new_entity()
menu:push("finish", Entity.new_func(popGlobMnOtherMenu))
menu.ent.onEsc = Entity.new_func(popGlobMnOtherMenu)
menu:push("improve stats", Entity.new_func(spendXpOnStats))
menu:push("learn skills", Entity.new_func(learnableSkill))
lvlUp.ent.entries[0] = menu.ent
menu.ent.size = 20
ywPushNewWidget(main, lvlUp.ent)
return YEVE_ACTION
end
function setCmbAsAttack(mn)
print("set smb !", "current: " .. phq.pj.attack:to_string(),
yeGetStringAt(mn, "pre-text"))
print(Entity.wrapp(ywMenuGetCurrentEntry(mn)))
phq.pj.attack = Entity.wrapp(ywMenuGetCurrentEntry(mn)).text
yeSetAt(mn, "pre-text", "current: " .. phq.pj.attack:to_string())
end
function chooseCombot(_mn)
print("choose combot")
local cmbs = phq.pj.combots
local m = main_widget
local ccw = Container.new_entity("vertical")
ccw.ent.background = "rgba: 255 255 255 255"
local menu = Menu.new_entity()
local i = 0
menu.ent["pre-text"] = "current: " .. phq.pj.attack:to_string()
menu:push("back", Entity.new_func("popGlobMnOtherMenu"))
menu.ent.onEsc = Entity.new_func("popGlobMnOtherMenu")
while i < yeLen(cmbs) do
local cmb = cmbs[i]
menu:push(cmb:to_string(), Entity.new_func(setCmbAsAttack))
i = i + 1
end
ccw.ent.entries[0] = menu.ent
--menu.ent.size = 20
ywPushNewWidget(m, ccw.ent)
return YEVE_ACTION
end
function wear_cloth(mn)
mn = Entity.wrapp(mn)
local desc = Entity.wrapp(yeGet(ywMenuGetCurrentEntry(mn), "arg"))
local where = yeGetString(desc.where)
local eq = phq.pj.equipement
if (desc.where == "torso" or desc.where == "legs") and
(desc.full_body or eq.full_body) then
eq.torso = nil
eq.legs = nil
end
eq[where] = yeGetString(desc.key_name)
dressup.dressUp(phq.pj)
lpcs.handlerReload(yeGet(main_widget, "pj"))
lpcs.handlerReload(mn.pj)
return YEVE_ACTION
end
function wear_clothes_mn(_mn)
local m = main_widget
local ccw = Container.new_entity("vertical")
ccw.ent.background = "rgba: 255 255 255 255"
local menu = Menu.new_entity()
local inv = phq.pj.inventory
local i = 0
--menu.ent["pre-text"] = "current: " .. phq.pj.attack:to_string()
local c = Canvas.new_entity()
menu.ent.pj = lpcs.createCaracterHandler(phq.pj, c.ent)
ylpcsHandlerSetPos(menu.ent.pj, Pos.new(20, 10).ent)
lpcs.handlerSetOrigXY(menu.ent.pj, 0, 10)
lpcs.handlerRefresh(menu.ent.pj)
menu:push("back", Entity.new_func("popGlobMnOtherMenu"))
menu.ent.onEsc = Entity.new_func("popGlobMnOtherMenu")
while i < yeLen(inv) do
local name = yeGetKeyAt(inv, i)
local ob_desc = phq.objects[name]
print(ob_desc, yIsNil(ob_desc), (yeGetStringAt(ob_desc, "type") ~= "equipement"))
if yIsNil(ob_desc) or (yeGetStringAt(ob_desc, "type") ~= "equipement") then
goto next
end
ob_desc.key_name = name
if ob_desc.name then
name = ob_desc.name:to_string()
end
menu:push(name, Entity.new_func(wear_cloth), ob_desc)
:: next ::
i = i + 1
end
ccw.ent.entries[0] = menu.ent
ccw.ent.entries[1] = c.ent
--menu.ent.size = 20
ywPushNewWidget(m, ccw.ent)
return YEVE_ACTION
end
function alliesMoveOn(_mn)
print("allies move on !\n")
end
function allies_mn(_mn)
local m = main_widget
local ccw = Container.new_entity("vertical")
ccw.ent.background = "rgba: 255 255 255 255"
local menu = Menu.new_entity()
local allies = phq.pj.allies
-- TODO ALLIES SCREEN
ccw.ent.entries[0] = menu.ent
menu:push("back", Entity.new_func(popGlobMnOtherMenu))
menu.ent.onEsc = Entity.new_func(popGlobMnOtherMenu)
for i = 0, yeLen(allies) do
menu:push(yeGetKeyAt(allies, i))
end
ywPushNewWidget(m, ccw.ent)
menu.ent.moveOn = Entity.new_func(alliesMoveOn)
return YEVE_ACTION
end
function doAdvanceTime(mn)
local f_mn = ywCntWidgetFather(mn)
backToGame(f_mn)
advance_time(main_widget)
end
function gotoEndChapter(mn)
local cur_chapter = yeGetInt(phq.env.chapter)
if cur_chapter == 1 then
print("GOTO CHATPER 2")
main_widget.sleep_script = "end_chapter_1"
elseif cur_chapter == 0 then
main_widget.sleep_script = "end_chapter_0"
elseif cur_chapter == 2 then
main_widget.sleep_script = "end_chapter_2"
end
phq.env.day = 7
phq.env.time = "night"
backToGame2()
sleep(main_widget)
end
function pushStatus(mn)
local gm_cnt = Entity.wrapp(ywCntWidgetFather(mn))
local main = main_widget
local stat_menu = Container.new_entity("vertical")
local hooks = main.gmenu_hook
ywCntPopLastEntry(gm_cnt)
ywPushNewWidget(gm_cnt, stat_menu.ent)
stat_menu.ent.isChildContainer = true
local menu = Menu.new_entity()
menu:push("Spend XP", Entity.new_func(pushSpendXpWid))
menu:push("Choose Combot", Entity.new_func(chooseCombot))
menu:push("wear clothes", Entity.new_func(wear_clothes_mn))
menu:push("God Mode", Entity.new_func(god_window))
menu:push("advence time", Entity.new_func(doAdvanceTime))
if phq.env.time:to_string() == "morning" then
menu:push("slack off the whole day", Entity.new_func(slack_off))
end
menu:push("Allies", Entity.new_func(allies_mn))
if yeGetInt(phq.env.is_end_of_chapter) > 0 then
menu:push("end chapter", Entity.new_func(gotoEndChapter))
end
local i = 0
while i < yeLen(hooks) do
local h = hooks[i]
print(hooks[i])
if (h[0]:to_int() == GM_STATS_IDX) then
h[1](main, menu.ent)
end
i = i + 1
end
menu.ent.size = 30
menu.ent.onEsc = Entity.new_func("gmGetBackFocus")
menu.ent.margin = {}
menu.ent.margin.size = 8
stat_menu.ent.entries[0] = menu.ent
ywCntConstructChilds(gm_cnt)
pushSTatusTextScreen(stat_menu.ent)
stat_menu.ent.current = 0
return YEVE_ACTION
end
local function doItemsListening(mn)
local inv = phq.pj.inventory
local i = 0
mn.ent.entries = {}
while i < yeLen(inv) do
if inv[i] then
local name = yeGetKeyAt(inv, i)
local ob_desc = phq.objects[name]
if ob_desc and ob_desc.name then
name = ob_desc.name:to_string()
end
local cur = mn:push(name .. ": " ..
math.floor(yeGetInt(inv[i])),
Entity.new_func(gmUseItem))
cur.obName = yeGetKeyAt(inv, i)
cur.inv_o = inv[i]
cur.inv = inv
end
i = i + 1
end
end
function gmUseItem(mn)
local main = Entity.wrapp(ywCntWidgetFather(mn))
local cur = Entity.wrapp(ywMenuGetCurrentEntry(mn))
local objs_list = phq.objects
local o_str = cur.obName
local o = objs_list[o_str:to_string()]
local been_used = false
print(objs_list:cent())
if yIsNil(o) then
return YEVE_NOTHANDLE
end
local time_consumption = o.time_consumption
if o.type:to_string() == "book" then
return read_book(o, o_str)
end
if o.func then
if yeType(o.func) == YFUNCTION then
o.func(main, o)
else
yesCall(ygGet(o.func:to_string()), main:cent(), o:cent())
end
been_used = true
elseif o["stats+"] then
local stats_p = o["stats+"]
been_used = true
local i = 0
while i < yeLen(stats_p) do
local k = yeGetKeyAt(stats_p, i)
increaseStat(mn, phq.pj, k, yeGetIntAt(stats_p, i))
if k == "life" and phq.pj.life > phq.pj.max_life then
printMessage(main_widget, nil, "life over max, set it to ", phq.pj.max_life)
phq.pj.life = yeGetInt(phq.pj.max_life)
end
i = i + 1
end
end
if o["tmp_increase_once"] and yIsNil(yeGet(phq.pj.tmp_stats, yeGetString(o_str))) then
local tio = o["tmp_increase_once"]
for j = 0, yeLen(tio) - 1 do
local what = 'phq.pj.' .. yeGetKeyAt(tio, j)
local val = yeGetIntAt(tio, j)
local tsts = new_pj_tmp_stat(yeGetString(o_str))
tsts[0] = what
tsts[1] = -val
printMessage(main_widget, nil, "temporary increase ", what, "of ", val)
ygIncreaseInt(what, val)
end
end
if been_used then
remove(mn, nil, o_str)
end
doItemsListening(Menu.wrapp(mn))
if yeGetString(time_consumption) == "time" then
backToGame2()
advance_time(main_widget)
end
end
function invList(mn)
local main = Entity.wrapp(ywCntWidgetFather(mn))
ywCntPopLastEntry(main)
mn = Menu.new_entity()
doItemsListening(mn)
mn.ent.background = "rgba: 255 255 255 190"
mn.ent.onEsc = Entity.new_func("gmGetBackFocus")
mn.ent["text-align"] = "center"
mn.ent.margin = {}
mn.ent.margin.size = 8
ywPushNewWidget(main, mn.ent)
return YEVE_ACTION
end
function gmBuyItem(mn)
local main = Entity.wrapp(ywCntWidgetFather(mn))
local cur = Entity.wrapp(ywMenuGetCurrentEntry(mn))
local o_name = cur.obName:to_string()
local who = phq.pj
local cost = cur.cost:to_int()
local money = who.inventory.money
if money >= cost then
yeSetInt(money, money:to_int() - cost)
addObject(main, who, o_name, 1)
else
printMessage(main, obj, Entity.new_string("Not enouth money"))
end
end
function storeMoveOn(mn, _current)
local cur = Entity.wrapp(ywMenuGetCurrentEntry(mn))
local img_p = cur.path
local cnt = ywCntWidgetFather(mn)
local cv = ywCntGetEntry(cnt, 1)
ywCanvasClear(cv)
if yIsNNil(img_p) then
local r = Rect.new(lpcs.x_threshold:to_int(),
lpcs.y_threshold:to_int(),
lpcs.w_sprite:to_int(),
lpcs.h_sprite:to_int())
ywContainerUpdate(cnt, cv)
cv = Canvas.wrapp(cv)
local ob = cv:new_img(
0, 0,
yeGetString(lpcs["$path"]) .. "/" .. "spritesheets" .. "/" .. yeGetString(img_p), r.ent)
ob:force_size(Size.new(100,200))
print("LEN", yeLen(cv.ent.objs))
end
print(cur.cost, cur.obName, yeGetString(lpcs["$path"]),
cur.path, yIsNNil(cur.path))
return YEVE_ACTION;
end
function openStore(main, _obj_or_eve, storeName)
if phq_only_fight == 1 then
main = main_widget
end
main = Entity.wrapp(main)
print(main.isDialogue)
if main.isDialogue then
main = Entity.wrapp(ywCntWidgetFather(yDialogueGetMain(main)))
ywCntPopLastEntry(main)
end
storeName = yeGetString(storeName)
print("open ", storeName, stores[storeName])
local store = stores[storeName]
local cnt = Container.new_entity("vertical")
local cv = Canvas.new_entity()
local mn = Menu.new_entity()
mn.ent.in_subcontained = 1
mn:push("Exit Store", Entity.new_func("backToGame"))
mn.ent.onEsc = Entity.new_func("backToGame")
local i = 0
while i < yeLen(store) do
if store[i] then
local name = yeGetKeyAt(store, i)
local ob_desc = phq.objects[name]
if ob_desc and ob_desc.name then
name = ob_desc.name:to_string()
end
local cost = yeGetInt(store[i])
local cur = mn:push(name .. ": " ..
math.floor(cost) .. "$",
Entity.new_func(gmBuyItem))
cur.obName = yeGetKeyAt(store, i)
if yIsNil(yeGet(ob_desc, "path")) then
cur.path = nil
else
cur.path = yeGet(ob_desc, "path")
end
cur.cost = cost
end
i = i + 1
end
mn.ent.moveOn = Entity.new_func(storeMoveOn)
mn.ent.size = 40
cnt.ent.background = "rgba: 255 255 255 190"
cnt.ent.entries[0] = mn.ent
cnt.ent.entries[1] = cv.ent
ywPushNewWidget(main, cnt.ent)
return YEVE_ACTION
end
function howtoplay(_mn)
local mncp = Entity.new_copy(ygGet("phq:menus.bagare"))
mncp.action = Entity.new_func("backToGameOnEnter")
ywPushNewWidget(main_widget, mncp)
end
function fillMiscMenu(mn)
mn = Menu.wrapp(mn)
mn.ent.entries = {}
mn:push("quick save", Entity.new_func(saveGameCallback))
mn:push("save", Entity.new_func(saveGameMenu))
mn:push("main menu", "callNext")
mn:push("How to Play", Entity.new_func(howtoplay))
mn:push("Back To Game", "phq.backToGame")
mn.ent.background = "rgba: 255 255 255 190"
mn.ent["text-align"] = "center"
end
function saveSlot(mn)
local slot = Entity.wrapp(ywMenuGetCurrentEntry(mn)).slot:to_string()
print("save on ", slot)
saveGame(main_widget, slot)
printMessage(main_widget, nil, "save on slot: " .. slot)
end
function saveGameMenu(mn)
print("push save game menu ?")
local e
mn = Entity.wrapp(mn)
mn.entries = {}
mn = Menu.wrapp(mn)
mn:push("back", Entity.new_func(fillMiscMenu))
e = mn:push("slot 0", Entity.new_func(saveSlot))
e.slot = "slot_0"
e = mn:push("slot 1", Entity.new_func(saveSlot))
e.slot = "slot_1"
e = mn:push("slot 2", Entity.new_func(saveSlot))
e.slot = "slot_2"
e = mn:push("slot 3", Entity.new_func(saveSlot))
e.slot = "slot_3"
e = mn:push("slot 4", Entity.new_func(saveSlot))
e.slot = "slot_4"
e = mn:push("slot 5", Entity.new_func(saveSlot))
e.slot = "slot_5"
e = mn:push("slot 6", Entity.new_func(saveSlot))
e.slot = "slot_6"
e = mn:push("slot 7", Entity.new_func(saveSlot))
e.slot = "slot_7"
e = mn:push("slot 8", Entity.new_func(saveSlot))
e.slot = "slot_8"
e = mn:push("slot 9", Entity.new_func(saveSlot))
e.slot = "slot_9"
e = mn:push("slot A", Entity.new_func(saveSlot))
e.slot = "slot_A"
e = mn:push("slot B", Entity.new_func(saveSlot))
e.slot = "slot_B"
e = mn:push("slot C", Entity.new_func(saveSlot))
e.slot = "slot_C"
e = mn:push("slot D", Entity.new_func(saveSlot))
e.slot = "slot_D"
e = mn:push("slot E", Entity.new_func(saveSlot))
e.slot = "slot_E"
e = mn:push("slot F", Entity.new_func(saveSlot))
e.slot = "slot_F"
e = mn:push("slot 10", Entity.new_func(saveSlot))
e.slot = "slot_10"
end