forked from kaliuresis/WandDBG
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
1698 lines (1495 loc) · 68 KB
/
init.lua
File metadata and controls
1698 lines (1495 loc) · 68 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
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
base_dir = "mods/wand_dbg/"
mod_name = "wand_dbg"
dofile_once("data/scripts/lib/utilities.lua");
dofile_once(base_dir .. "files/debugger.lua");
dofile_once(base_dir .. "files/spell_info.lua");
dofile_once(base_dir .. "files/utils.lua");
dofile_once(base_dir .. "files/ui.lua");
local gui = GuiCreate()
debug_wand = nil
action_table, projectile_table, projectile_list, extra_entity_table = nil
-- actions_list, projectile_table, extra_entity_table = {}, {}, {}
dofile_once(base_dir .. "files/cast_state_properties.lua");
local show_wand_dbg = ModSettingGet(mod_name..".show")
local show_animation = ModSettingGet(mod_name..".show_animation")
local need_to_remake_cards = false
-- id x y w h show title
local config_window = make_window( "config_window", 390, 150, 230, 180, false, "Wand Options")
local tree_window = make_window( "tree_window", 10, 54, 300, 170, false, "Flowchart")
local cast_state_window = make_window("cast_state_window", 320, 54, 300, 170, false, "Cast States")
local current_cast_states = {}
local final_cast_states = {}
local cast_states = final_cast_states
local cast_state_collapsed = {}
local use_final_cast_state = ModSettingGet(mod_name..".use_final_cast_state") or true
local current_i = 0
local current_i_target = nil
local playing = true
local playback_timer = 20
local looping = true
local last_wand_deck
local last_wand_stats
local wand_changed = false
local cast_history, action_trees, start_deck, always_casts, always_cast_cards
local options = {
{id="maximize_uses", name="Spell Uses", type="boolean", value=false, true_text="Max", false_text="0"},
{id="unlimited_spells", name="Unlimited Spells", type="boolean", value=false},
{id="mana", name="Mana", type="number", value=0, min=0, max=100},
{id="every_other_state", name="Every Other State", type="boolean", value=false, true_text="Skip", false_text="Don't skip"},
{id="n_enemies", name="Nearby enemies", type="number", value=0, min=0, max=100, integer=true},
{id="n_projectiles", name="Nearby Projectiles", type="number", value=0, min=0, max=100, integer=true},
{id="n_omega_black_holes", name="Nearby Omega Black Holes", type="number", value=0, min=0, max=100, integer=true},
{id="money", name="Gold", type="number", value=0, min=0, max=2147483648, inf_value=2147483648, log_scale=true},
{id="hp", name="HP", type="number", type = "number", value=4, min=0, max=400000000000, display_multiplier=25, log_scale=true},
{id="max_hp", name="Max HP", type="number", type="number", value=4, min=0, max=400000000000, display_multiplier=25, log_scale=true},
{id="n_stainless", name="Number of Stainless", type="number", value=0, min=0, max=100, integer=true},
{id="ambrosia", name="Ambrosia Stain", type="boolean", value=false},
-- {id="damage_multipliers", name="Damage Multipliers", type="custom", value={ curse = 1,
-- drill = 1,
-- electricity = 1,
-- explosion = 0.35,
-- fire = 1,
-- healing = 1,
-- ice = 1,
-- melee = 1,
-- overeating = 1,
-- physics_hit = 1,
-- poison = 1,
-- projectile = 1,
-- radioactive = 1,
-- slice = 1 }},
-- {id="zeta_options", name="Zeta Options", type="custom", value = {}},
{id="frame_number", name="Frame Number", type="text_number", value = 0, integer=true},
{id="show_with_inventory", name="Show Windows when Inventory is Open", type="boolean", value = false, always_override = true},
}
local config = {}
for i, option in ipairs(options) do
option.default = option.value
option.override = ModSettingGet(mod_name.."."..option.id.."_override") or nil
option.value = ModSettingGet(mod_name.."."..option.id.."_value") or option.value
option.value = option.value or false
config[option.id] = option.override and option.value
end
local discarded = {}
local hand = {}
local deck = {}
-- debug_wand = dofile_once( "mods/wand_dbg/files/debugger.lua" );
function OnWorldInitialized()
end
local _ModTextFileGetContent = ModTextFileGetContent;
function OnWorldPreUpdate()
-- dofile( "mods/spell_lab/files/gui/update.lua" );
end
function get_bg_sprite(type)
local bg_sprite = "data/ui_gfx/inventory/item_bg_"
if(type == ACTION_TYPE_PROJECTILE) then
bg_sprite = bg_sprite .. "projectile"
elseif(type == ACTION_TYPE_STATIC_PROJECTILE) then
bg_sprite = bg_sprite .. "static_projectile"
elseif(type == ACTION_TYPE_MODIFIER) then
bg_sprite = bg_sprite .. "modifier"
elseif(type == ACTION_TYPE_DRAW_MANY) then
bg_sprite = bg_sprite .. "draw_many"
elseif(type == ACTION_TYPE_MATERIAL) then
bg_sprite = bg_sprite .. "material"
elseif(type == ACTION_TYPE_OTHER) then
bg_sprite = bg_sprite .. "other"
elseif(type == ACTION_TYPE_UTILITY) then
bg_sprite = bg_sprite .. "utility"
elseif(type == ACTION_TYPE_PASSIVE) then
bg_sprite = bg_sprite .. "passive"
end
bg_sprite = bg_sprite .. ".png"
return bg_sprite
end
local player
local action_sprites = {}
local dying_action_sprites = {}
function make_debug_card(action)
card = {action = action, x = 0, y = 0, theta = 0, scale = 1.0, dx = 0, dy = 0, dtheta = 0, dscale = 0.0, x_target = 0, y_target = 0}
action.debug_card = card
return card
end
function clear_card_sprites(always_casts_only)
local children = EntityGetAllChildren(player)
if children ~= nil then
for i, c in ipairs(children) do
if(not always_casts_only) then
if(EntityHasTag(c, "dbg_card")) then
EntityKill(c)
end
else
if(EntityHasTag(c, "ac_dbg_card")) then
EntityKill(c)
end
end
end
end
end
function add_sprite(card, is_always_cast)
local bg_sprite = get_bg_sprite(card.action.type)
local card_sprite = EntityCreateNew("debug_card")
EntityAddChild(player, card_sprite)
if(is_always_cast) then
EntityAddTag(card_sprite, "ac_dbg_card")
end
EntityAddTag(card_sprite, "dbg_card")
-- EntityAddComponent(card_sprite, "VariableStorageComponent",
-- {value_int = i})
EntityAddComponent(card_sprite, "SpriteComponent",
{_tags = "enabled_in_world,ui,no_hitbox,",
image_file = bg_sprite,
emissive="1",
offset_x="10",
offset_y="19",
-- has_special_scale="1",
-- special_scale_x="1.0",
-- special_scale_y="1.0",
z_index="-1.5"})
EntityAddComponent(card_sprite, "SpriteComponent",
{_tags = "enabled_in_world,ui,no_hitbox,",
image_file = card.action.sprite,
emissive="1",
offset_x="8",
offset_y="17",
-- has_special_scale="1",
-- special_scale_x="1.0",
-- special_scale_y="1.0",
z_index="-1.51"})
return card_sprite
end
function clear_action_sprites()
local children = EntityGetAllChildren(player)
if(children ~= nil) then
for i, c in ipairs(children) do
if(EntityHasTag(c, "dbg_action")) then
EntityKill(c)
end
end
end
action_sprites = {}
dying_action_sprites = {}
end
function add_action_sprite(action)
local bg_sprite = get_bg_sprite(action.type)
local card_sprite = EntityCreateNew("debug_action")
EntityAddChild(player, card_sprite)
EntityAddTag(card_sprite, "dbg_action")
-- EntityAddComponent(card_sprite, "VariableStorageComponent",
-- {value_int = i})
-- EntityAddComponent(card_sprite, "SpriteComponent",
-- {_tags = "enabled_in_world,ui,no_hitbox,",
-- image_file = bg_sprite,
-- emissive="1",
-- offset_x="10",
-- offset_y="19",
-- -- has_special_scale="1",
-- -- special_scale_x="1.0",
-- -- special_scale_y="1.0",
-- z_index="-1.5"})
EntityAddComponent(card_sprite, "SpriteComponent",
{_tags = "enabled_in_world,ui,no_hitbox,",
image_file = action_table[action.id].sprite,
emissive="1",
offset_x="8",
offset_y="17",
-- has_special_scale="1",
-- special_scale_x="1.0",
-- special_scale_y="1.0",
z_index="-1.51"})
EntityAddComponent(card_sprite, "SpriteComponent",
{_tags = "enabled_in_world,ui,no_hitbox,line1,",
image_file = "data/fonts/font_pixel_white.xml",
is_text_sprite="1",
emissive="1",
offset_x="15",
offset_y="4",
text="",
has_special_scale="1",
special_scale_x="0.6",
special_scale_y="0.6",
z_index="-1.51"})
EntityAddComponent(card_sprite, "SpriteComponent",
{_tags = "enabled_in_world,ui,no_hitbox,line2,",
image_file = "data/fonts/font_pixel_white.xml",
is_text_sprite="1",
emissive="1",
offset_x="15",
offset_y="-4",
text="",
has_special_scale="1",
special_scale_x="0.6",
special_scale_y="0.6",
z_index="-1.51"})
return card_sprite
end
function push_action(node)
local action = node.action
local new_action_sprite = {node = node, sprite=add_action_sprite(action), x = (action.debug_card and action.debug_card.x) or 0, y = (action.debug_card and action.debug_card.y) or 0, theta = 0, scale = 1.0, dx = 0, dy = 0, dtheta = 0, dscale = 0.0, x_target = 0, y_target = 0, line1 = "", line2 = ""}
table.insert(action_sprites, new_action_sprite)
return new_action_sprite
end
function pop_action(fadetime)
local action_sprite = action_sprites[#action_sprites]
action_sprite.dy = action_sprite.dy+2
action_sprite.dscale = action_sprite.dscale+1
action_sprite.lifetime = fadetime
action_sprite.max_lifetime = fadetime
table.remove(action_sprites, #action_sprites)
table.insert(dying_action_sprites, action_sprite)
end
local playback_wait = 20
function animate_card(card, sprite_entity, cx, cy, gui_to_world_scale)
local rx = 0
local ry = 0
if(card.x_target ~= nil and card.y_target ~= nil) then
rx = card.x_target - card.x
ry = card.y_target - card.y
end
local k = 0.1
local c = 0.5
local ddx = -c*card.dx + k*rx
card.dx = card.dx + ddx
card.dy = (1.0-c)*card.dy + k*ry
local k_theta = 0.1
local c_theta = 0.5
card.dtheta = (1.0-c)*card.dtheta - k_theta*card.theta
card.dtheta = card.dtheta - 0.01*ddx
local k_scale = 0.2
local c_scale = 0.5
card.dscale = (1.0-c_scale)*card.dscale + k_scale*(1.0-card.scale)
card.x = card.x + card.dx
card.y = card.y + card.dy
card.theta = card.theta + card.dtheta
card.scale = card.scale + card.dscale
if(card.scale < 0.1) then card.scale = 0.1 end
EntitySetTransform(sprite_entity,
cx+gui_to_world_scale*card.x, cy+gui_to_world_scale*card.y, card.theta, card.scale, card.scale)
local line1 = EntityGetFirstComponent(sprite_entity, "SpriteComponent", "line1")
local line2 = EntityGetFirstComponent(sprite_entity, "SpriteComponent", "line2")
if(line1 ~= nil) then
local old_text = ComponentGetValue2(line1, "text")
if(card.line1 ~= old_text) then
ComponentSetValue2(line1, "text", card.line1)
EntityRefreshSprite(sprite_entity, line1)
end
end
if(line2 ~= nil) then
local old_text = ComponentGetValue2(line2, "text")
if(card.line2 ~= old_text) then
ComponentSetValue2(line2, "text", card.line2)
EntityRefreshSprite(sprite_entity, line2)
end
end
end
function animate_dying_card(card, sprite_entity, cx, cy, gui_to_world_scale)
local c = 0.1
local ddx = -c*card.dx
card.dx = card.dx + ddx
card.dy = (1.0-c)*card.dy
local k_theta = 0.1
local c_theta = 0.5
card.dtheta = (1.0-c)*card.dtheta - k_theta*card.theta
card.dtheta = card.dtheta - 0.01*ddx
local c_scale = 0.1
card.dscale = (1.0-c_scale)*card.dscale
card.x = card.x + card.dx
card.y = card.y + card.dy
card.theta = card.theta + card.dtheta
card.scale = card.scale + card.dscale
if(card.scale < 0.1) then card.scale = 0.1 end
local alpha = 1
card.lifetime = card.lifetime-1
alpha = card.lifetime/card.max_lifetime
if(card.lifetime <= 0) then
EntityKill(card.sprite)
return false
end
EntitySetTransform(sprite_entity,
cx+gui_to_world_scale*card.x, cy+gui_to_world_scale*card.y, card.theta, card.scale, card.scale)
local sprites = EntityGetComponent(sprite_entity, "SpriteComponent")
if(sprites ~= inl) then
for i, s in ipairs(sprites) do
ComponentSetValue2(s, "alpha", alpha)
end
end
local line1 = EntityGetFirstComponent(sprite_entity, "SpriteComponent", "line1")
local line2 = EntityGetFirstComponent(sprite_entity, "SpriteComponent", "line2")
if(line1 ~= nil) then
local old_text = ComponentGetValue2(line1, "text")
if(card.line1 ~= old_text) then
ComponentSetValue2(line1, "text", card.line1)
EntityRefreshSprite(sprite_entity, line1)
end
end
if(line2 ~= nil) then
local old_text = ComponentGetValue2(line2, "text")
if(card.line2 ~= old_text) then
ComponentSetValue2(line2, "text", card.line2)
EntityRefreshSprite(sprite_entity, line2)
end
end
return true
end
function draw_deck(base_x, base_y, cx, cy, gui_to_world_scale, deck, focus)
-- if(focus_on_end == nil) then focus_on_end = true end
focus = focus or "middle"
for i, card in ipairs(deck) do
-- local sprite = card.action.sprite
-- local bg_sprite = get_bg_sprite(card.action.type)
-- local im_w, im_h = GuiGetImageDimensions(gui, bg_sprite, scale)
-- local x_rel = 16*i
-- local y_rel = 0
-- GuiImage(gui, get_id(), base_x+x_rel-im_w/2, base_y+y_rel-im_h/2, bg_sprite,
-- 1.0, scale, 0, 0)
-- im_w, im_h = GuiGetImageDimensions(gui, sprite, scale)
-- GuiImage(gui, get_id(), base_x+x_rel-im_w/2, base_y+y_rel-im_h/2, sprite,
-- 1.0, scale, 0, 0)
local spacing = 24
local max_spacings = 6
if(#deck > max_spacings) then
local a2 = math.min((#deck-1)/max_spacings-1, 1)
local a1 = 1-a2
if(focus=="right") then
local z = (i-1)/(#deck-1)
card.x_target = base_x + spacing*max_spacings*(a1*z+a2*z*z)
elseif(focus=="left") then
local z = (#deck-i)/(#deck-1)
card.x_target = base_x + spacing*max_spacings*(1-a1*z-a2*z*z)
elseif(focus=="middle") then
card.x_target = base_x + spacing*max_spacings*(i-1)/(#deck-1)
end
else
card.x_target = base_x + spacing*(i-1)
end
card.y_target = base_y + 0.0
animate_card(card, card.sprite, cx, cy, gui_to_world_scale)
end
end
function draw_playback(base_x, base_y, width, mx, my)
local button_width = 8
local button_spacing = 4
local bar_width = width - (4*button_width+4*button_spacing)
if(cast_history == nil) then return current_i_target end
local play_pause = base_dir.."files/ui_gfx/play.png"
local play_pause_text = "play"
if(playing) then
play_pause = base_dir.."files/ui_gfx/pause.png"
play_pause_text = "pause"
end
local loop_text = "loop"
if(looping) then
loop_text = "don't loop"
end
local x = base_x+bar_width
x = x+button_spacing
local prev_pressed = GuiImageButton(gui, get_id("playback_previous"), x, base_y-3.5, "", base_dir.."files/ui_gfx/prev.png")
get_previous_widget_info()
GuiTooltip(gui, "previous", "")
x = x+button_spacing+button_width
local play_pause_pressed = GuiImageButton(gui, get_id("playback_play"), x, base_y-3.5, "", play_pause)
get_previous_widget_info()
GuiTooltip(gui, play_pause_text, "")
x = x+button_spacing+button_width
local next_pressed = GuiImageButton(gui, get_id("playback_next"), x, base_y-3.5, "", base_dir.."files/ui_gfx/next.png")
get_previous_widget_info()
GuiTooltip(gui, "next", "")
x = x+button_spacing+button_width
if(not looping) then GuiColorSetForNextWidget( gui, 0.5, 0.5, 0.5, 0.5) end
local loop_pressed = GuiImageButton(gui, get_id("playback_loop"), x, base_y-3.5, "", base_dir.."files/ui_gfx/loop.png")
get_previous_widget_info()
GuiTooltip(gui, loop_text, "")
if(play_pause_pressed) then
playing = not playing
end
if(loop_pressed) then
looping = not looping
end
if(next_pressed) then
current_i_target = current_i+1
end
if(prev_pressed) then
current_i_target = current_i-1
end
local last_x_rel = 0
local last_y_rel = 0
local last_indent_offset = 0
local base_scale = 0.5
local scale = base_scale
local first_action = true
local j = 0
local x_rel = 0
local y_rel = 0
local mouse_t = clamp((mx-base_x)/bar_width*#cast_history, 0.001, #cast_history)
local ui_hover = (math.abs(mx-(base_x+bar_width/2)) <= bar_width/2+button_width/2 and math.abs(my-(base_y)) <= button_width)
--invisible line to block clicks from casting spells
draw_line(gui, base_x, base_y,
base_x+bar_width, base_y,
2*button_width, "white", 0.0, 0)
draw_line(gui, base_x, base_y,
base_x+bar_width, base_y,
1.0, "white", 1.0, 0)
GuiImage(gui, get_id("playback_indicator"), base_x+bar_width*(current_i-1)/#cast_history-3.5, base_y-3.5, base_dir.."files/ui_gfx/big_dot.png",
1, 1)
if(ui_hover and not other_window_blocking) then
local clicked = GuiImageButton(gui, get_id("playback_click_blocker"), base_x+bar_width*mouse_t/#cast_history-50.5, base_y-50.5, "", base_dir.."files/ui_gfx/invisible_button.png")
get_previous_widget_info()
GuiText(gui, base_x+bar_width*mouse_t/#cast_history, base_y, math.ceil(mouse_t).."/"..#cast_history)
GuiImage(gui, get_id("playback_hover_indicator"), base_x+bar_width*mouse_t/#cast_history-3.5, base_y-3.5, base_dir.."files/ui_gfx/big_dot.png", 0.5, 1)
if(clicked) then
current_i_target = math.ceil(mouse_t)
end
end
if #cast_history < bar_width then
for i, e in ipairs(cast_history) do
if(e.type == "action") then
GuiImage(gui, get_id(), base_x+bar_width*i/#cast_history-1.5, base_y-1.5, base_dir.."files/ui_gfx/small_dot.png",
1, 1)
end
end
end
return current_i_target
end
function process_node(tree)
local name = tree.action and tree.action.id or "shot_"..tree.cast_number
tree.str = "(" .. name
local previous_child_string = nil
for i, c in ipairs(tree.children) do
if(c.str == nil) then
process_node(c)
end
if(i ~= 0) then
tree.str = tree.str .. " "
end
tree.str = tree.str .. c.str
c.identical_to_previous = (c.str == previous_child_string)
previous_child_string = c.str
end
tree.str = tree.str..")"
end
function draw_ellipses(number_identical, width, x_spacing, y_spacing, scale, x, y, parent_x, parent_y)
-- if(parent_x ~= nil and parent_y ~= nil) then
-- local x_start = parent_x+8*scale
-- local y_start = parent_y
-- local x_end = x-8*scale
-- local y_end = y
-- draw_spline(gui, x_start, y_start, x_start+0.5*x_spacing, y_start,
-- x_end-0.5*x_spacing, y_end, x_end, y_end,
-- 0.5, "white", 1.0, 0, 4, 1)
-- end
x = x-8*scale
y = y-10*scale
draw_spline(gui, x, y, x, y+4,
x+0.5*width, y, x+0.5*width, y+4,
0.5, "white", 1.0, 0)
draw_spline(gui, x+width, y, x+width, y+4,
x+0.5*width, y, x+0.5*width, y+4,
0.5, "white", 1.0, 0)
GuiOptionsAddForNextWidget(gui, GUI_OPTION.Align_HorizontalCenter)
GuiText(gui, x+0.5*width, y+2.5,"x" .. number_identical)
height = 11
return width, height
end
function draw_node(tree, x_spacing, y_spacing, scale, x, y, parent_x, parent_y)
local spline_offset = 0
local node_height = 0
if(tree.action ~= nil) then
local sprite = tree.action.sprite
local bg_sprite = get_bg_sprite(tree.action.type)
local im_w, im_h = GuiGetImageDimensions(gui, bg_sprite, scale)
z_set_next_relative(gui, 0.5)
gui_image_bounded(gui, get_id("node_background"..tostring(tree)), x-im_w/2, y-im_h/2, bg_sprite,
1.0, scale, 0, 0)
local clicked, right_clicked, hovered, text_x, text_y, bwidth, bheight = get_previous_widget_info_bounded(gui)
local foreground_scale = scale
if(hovered) then
foreground_scale = 1.5*foreground_scale
end
im_w, im_h = GuiGetImageDimensions(gui, sprite, foreground_scale)
z_set_next_relative(gui, 0.25)
gui_image_bounded(gui, get_id("node_foreground"..tostring(tree)), x-im_w/2, y-im_h/2, sprite,
1.0, foreground_scale, 0, 0)
if(clicked) then
current_i_target = tree.event_index
end
if(tree.flavor) then
local fscale = 0.75
local fx = x-im_w*(0.5+0.5*fscale)
local fy = y+im_h*(0.5-0.5*fscale)
draw_text_image_list(format_projectiles(tree.flavor), fx, fy, fscale*scale, -im_h*(1.0-fscale)*0.5)
node_height = node_height+im_h*(0.5)
end
if(tree.recursion_limited) then
local cross_half = 0.6*y_spacing
draw_line(gui, x-cross_half, y-cross_half, x+cross_half, y+cross_half, 1.0, "red", 0.8)
draw_line(gui, x-cross_half, y+cross_half, x+cross_half, y-cross_half, 1.0, "red", 0.8)
end
else
-- GuiOptionsAddForNextWidget(gui, GUI_OPTION.Align_Left)
GuiOptionsAddForNextWidget(gui, GUI_OPTION.Align_HorizontalCenter)
GuiText(gui, x, y-5, tree.cast_number)
local clicked, right_clicked, hovered, text_x, text_y, twidth, theight = get_previous_widget_info(gui)
spline_offset = twidth/2-3
end
if(parent_x ~= nil and parent_y ~= nil) then
local x_start = parent_x+8*scale
local y_start = parent_y
local x_end = x-8*scale
local y_end = y
local color
if(tree.explanation == "draw") then
color = "white"
elseif(tree.explanation == "always_cast") then
color = "light_blue"
else
color = "gold"
end
draw_spline(gui, x_start, y_start, x_start+0.5*x_spacing, y_start,
x_end-0.5*x_spacing, y_end, x_end, y_end,
0.5, color, 1.0, 0, 4, 1)
end
if(tree.width and tree.height and (x+tree.width < bound_x_min or x > bound_x_max or y+tree.height < bound_y_min or y > bound_y_max)) then
return tree.width, tree.height
end
local height = 0
local width = x_spacing
local max_child_width = 0
local previous_width = 0
local number_identical = 1
for i, c in ipairs(tree.children) do
local child_x = x+x_spacing
local child_y = y+height
if(c.identical_to_previous) then
number_identical = number_identical + 1
else
if(number_identical > 1) then
local ellipses_width, ellipses_height = draw_ellipses(number_identical, previous_width, x_spacing, y_spacing, scale, child_x, child_y, x, y)
height = height + ellipses_height
child_y = y+height
end
number_identical = 1
local child_width, child_height = draw_node(c, x_spacing, y_spacing, scale, child_x, child_y, x+spline_offset, y)
if(child_width > max_child_width) then
max_child_width = child_width
end
previous_width = child_width
height = height+child_height
end
end
if(number_identical > 1) then
local child_x = x+x_spacing
local child_y = y+height
local ellipses_width, ellipses_height = draw_ellipses(number_identical, previous_width, x_spacing, y_spacing, scale, child_x, child_y, x, y)
height = height + ellipses_height
end
if(tree.draw_how_many ~= nil and tree.dont_draw_actions
or (tree.draw_how_many == 1 and tree.playing_permanent_card)) then
local x_start = x+8*scale
local y_start = y
local x_text = x+x_spacing
if(#tree.children == 0) then
x_text = x+0.7*x_spacing
end
local x_end = x_text-4*scale
local y_end = y+height
height = height+y_spacing
draw_spline(gui, x_start, y_start, x_start+0.5*x_spacing, y_start,
x_end-0.5*x_spacing, y_end, x_end, y_end,
0.5, "red", 1.0, 0, 4, 1)
local text = tree.draw_how_many
local text_width, text_height = GuiGetTextDimensions(gui, text, 1, 0)
GuiColorSetForNextWidget(gui,1.0,0,0,1)
GuiOptionsAddForNextWidget(gui, GUI_OPTION.Align_HorizontalCenter)
GuiText(gui, x_text+0.5, y_end-0.5*text_height+0.5, text)
local cross_half = 0.3*y_spacing
draw_line(gui, x_text-cross_half+0.5, y_end-cross_half+0.5, x_text+cross_half, y_end+cross_half, 1.0, "red", 0.8)
draw_line(gui, x_text-cross_half+0.5, y_end+cross_half-0.5, x_text+cross_half, y_end-cross_half, 1.0, "red", 0.8)
max_child_width = math.max(max_child_width, x_text-x_start+cross_half)
end
width = width+max_child_width
if(#tree.children == 0) then
width = 8+max_child_width
height = y_spacing
end
height = math.max(y_spacing+node_height, height)
tree.width = width
tree.height = height
return width, height
end
function draw_trees(base_x, base_y, min_height)
base_x = base_x or 0
base_y = base_y or 0
local x_spacing = 20
local y_spacing = 10
local scale = 0.5
local x = base_x+8
local y = base_y+8
for i, t in ipairs(action_trees) do
local width, height = draw_node(t, x_spacing, y_spacing, scale, x, y)
y = y + height
extend_max_bound(width+8+0.5*x_spacing, y-base_y)
end
--invisible dot for bottom margin
local dot_sprite = base_dir .. "files/ui_gfx/line_dot_white.png"
GuiImage(gui, get_id(), x, y, dot_sprite, 0.0, 1, 0, 0)
return y-base_y
end
function draw_text_image_list(value, x, y, scale, text_offset)
scale = scale or 0.5
text_offset = text_offset or 0
local width = 0
if(type(value) == "string") then
width = GuiGetTextDimensions(gui, value)
GuiText(gui, x, y+text_offset, value)
elseif(type(value) == "table") then
for i,t in ipairs(value) do
local item_width = 0
local item_height = 0
if(type(t) == "string") then
item_width = GuiGetTextDimensions(gui, t)
GuiText(gui, x, y+text_offset, t)
else
item_width, item_height = GuiGetImageDimensions(gui, t[1], scale)
gui_image_bounded(gui, get_id, x, y+1, t[1], 1, scale)
GuiTooltip(gui, t[2], "")
item_width = item_width+1
end
width = width+item_width
x = x+item_width
end
width = width-4
end
return width
end
function draw_cast_state(state, x, y)
local base_x = x
local base_y = y
local width = 0
local height = 0
if(state.width and state.height and (x+state.width < bound_x_min or x > bound_x_max or y+state.height < bound_y_min or y > bound_y_max)) then
return state.width, state.height
end
local c = state.current
if(c.projectiles ~= nil and #c.projectiles > 0) then
width = draw_text_image_list(format_projectiles(c.projectiles), x+6, y)+10
else
text = cast_state_collapsed[state.c] and "no proj." or "no projectiles"
width = draw_text_image_list(text, x+6, y)+10
end
y = y+8
height = height+8
if(not cast_state_collapsed[state.c]) then
for i, p in ipairs(cast_state_properties) do
local raw_value = p.get(c)
if(raw_value ~= nil and raw_value ~= p.default) then
local value
if(p.format ~= nil) then
value = p.format(raw_value)
else
value = to_string(raw_value)
end
local text = p.name..": "
local name_width = GuiGetTextDimensions(gui, text)
GuiText(gui, x+4, y, text)
local value_width = draw_text_image_list(value, x+4+name_width, y)
width = math.max(width, name_width+value_width+8)
y = y+8
height = height+8
end
end
-- else
-- width = 10
-- height = 8
end
height = height+4
-- draw_box(gui, x, base_y, width, height, 1, 1)
--invisible image to get offsets
GuiImage(gui, get_id("cast_state_offset_"..tostring(state)), 0, 0, base_dir .. "files/ui_gfx/line_dot_white.png", 0.0)
local clicked, right_clicked, hovered, x0, y0, widget_width, widget_height = get_previous_widget_info(gui)
local widg_x = x0+math.max(x, bound_x_min)
local widg_y = y0+math.max(base_y, bound_y_min)
local widg_w = x0+math.min(width+x, bound_x_max)-widg_x
local widg_h = y0+math.min(height+base_y, bound_y_max)-widg_y
if(widg_w > 0 and widg_h > 0) then
GuiOptionsAddForNextWidget(gui, GUI_OPTION.ForceFocusable)
z_set_next_relative(gui, 1.0)
local nine_piece = base_dir.."files/ui_gfx/9piece_outline.png"
local highlight_nine_piece = base_dir.."files/ui_gfx/9piece_outline_highlight.png"
if(other_window_blocking or not inner_window_hovered) then
highlight_nine_piece = nine_piece
end
GuiImageNinePiece(gui, get_id("cast_state_collapse_button_"..tostring(state)), widg_x, widg_y, widg_w, widg_h, 1,
nine_piece, highlight_nine_piece)
local clicked, right_clicked, hovered, widget_x, widget_y, widget_width, widget_height = get_previous_widget_info(gui)
if(hovered) then
-- GuiOptionsAddForNextWidget(gui, GUI_OPTION.Layout_NoLayouting)
-- GuiImage(gui, get_id(), mx, my, base_dir .. "files/ui_gfx/line_dot_white.png", 1, 10, 10)
GuiOptionsAddForNextWidget(gui, GUI_OPTION.Layout_NoLayouting)
-- GuiText(gui, mx, my, "width = "..width..", height = "..height.."; widget_width = "..widget_width..", widget_height = "..widget_height)
local tooltip_text = cast_state_collapsed[state.c] and "expand" or "collapse"
GuiText(gui, mx, my, tooltip_text)
end
if(clicked) then
cast_state_collapsed[state.c] = not cast_state_collapsed[state.c]
end
local image = base_dir.."files/ui_gfx/black_circle.png"
local im_w, im_h = GuiGetImageDimensions(gui, image, 1)
GuiImage(gui, get_id(), base_x-0.5*im_w, base_y-0.5*im_h, image, 1, 1)
z_set_next_relative(gui, -0.5)
if(state.c.shot_type == "root") then
local cast_number = state.c.root_node.cast_number or "error"
local im_w, im_h = GuiGetTextDimensions(gui, cast_number)
GuiText(gui, base_x-0.5*im_w+0.5, base_y-0.5*im_h, cast_number)
else
local image = get_projectile_icon(state.c.parent_projectile)
local im_w, im_h = GuiGetImageDimensions(gui, image, 0.5)
gui_image_bounded(gui, get_id(), base_x-0.5*im_w, base_y-0.5*im_h, image, 1, 0.5)
local description = ""
local trigger_name = ""
if(state.c.shot_type == "timer") then
trigger_name = "a "..state.c.timer.." frame timer"
elseif(state.c.shot_type == "trigger") then
trigger_name = "a trigger"
elseif(state.c.shot_type == "death_trigger") then
trigger_name = "an expiration trigger"
else
trigger_name = "an unknown trigger type"
end
GuiTooltip(gui, state.c.parent_projectile.." with "..trigger_name, description)
z_set_next_relative(gui, -1.0)
local image = base_dir.."files/ui_gfx/"..state.c.shot_type..".png"
local im_w, im_h = GuiGetImageDimensions(gui, image, 0.5)
GuiImage(gui, get_id(), base_x-0.5*im_w-3, base_y-0.5*im_h-3, image, 1, 0.5)
end
end
state.width = width
state.height = height
return width, height
end
function draw_cast_states(states, x, y, parent_x, parent_y)
local width = 0
local height = 0
local x_spacing = 24
local base_x = x
local base_y = y
for i, c in ipairs(states) do
if(cast_states[c] == nil) then
break
end
if(parent_x ~= nil) then
local x_start = parent_x
local y_start = math.min(parent_y, y)
local x_end = x-4
local y_end = y
z_set_relative(gui, -1.5)
draw_spline(gui, x_start, y_start, x_start+0.5*x_spacing, y_start,
x_end-0.5*x_spacing, y_end, x_end, y_end,
0.5, "white", 1.0, 0, 4, 1)
z_set_relative(gui, 0)
end
local state_width, state_height = draw_cast_state(cast_states[c], x+4, y)
state_width = state_width+8
local child_x = x+state_width+x_spacing
local child_y = y
local children_width, children_height = draw_cast_states(cast_states[c].children, child_x, child_y,
x+state_width, y+state_height)
children_width = children_width+x_spacing+8
state_height = math.max(state_height+8, children_height)
y = y+state_height
width = math.max(width, state_width+children_width)
height = height+state_height
extend_max_bound(4+width, y)
end
--invisible dot for bottom margin
local dot_sprite = base_dir .. "files/ui_gfx/line_dot_white.png"
GuiImage(gui, get_id(), x, y, dot_sprite, 0.0, 1, 0, 0)
return width, height
end
function draw_config(x, y, window_x, window_y)
for i, option in ipairs(options) do
local option_changed = false
if(option.always_override) then
option.override = option.always_override
end
local button_text = option.name..": "
if(not option.override) then
button_text = button_text.."Use game value"
elseif(option.type == "boolean") then
button_text = button_text..""..(option.value and (option.true_text or "Yes") or (option.false_text or "No"))
elseif(option.type == "number") then
if(option.inf_value and option.value >= option.inf_value) then
button_text = button_text.."∞"
else
button_text = button_text..string.format("%.0f", option.value*(option.display_multiplier or 1))
end
end
local clicked, right_clicked = GuiButton(gui, get_id("config_button_"..option.id), x, y, button_text)
local _, __, hovered, button_x, button_y, button_width, button_height = get_previous_widget_info(gui)
local option_width = button_width
local option_height = button_height
if(option.override) then
if(option.type == "number") then
local old_value = option.value
GuiColorSetForNextWidget(gui,1,1,1,0)
local slider_width = 200
local slider_height = 12
local slider_value = option.log_scale and math.log(option.value+1) or option.value
local slider_min = option.log_scale and math.log(option.min+1) or option.min
local slider_max = option.log_scale and math.log(option.max*1.01+1) or option.max
local slider_default = option.log_scale and math.log(option.default+1) or option.default
option.value = GuiSlider(gui, get_id("config_slider_"..option.id), x+12, y+button_height, "",
slider_value, slider_min, slider_max, slider_default, option.display_multiplier or 1,
" ", slider_width)
get_previous_widget_info(gui)
if(option.log_scale) then
option.value = math.exp(option.value)-1
end
if(option.integer) then
option.value = math.floor(option.value)
end
if(option.value ~= old_value) then
option_changed = true
end
option_width = math.max(option_width, slider_width)
option_height = option_height+slider_height
elseif(option.type == "text_number") then
local old_value = option.value
local textbox_id = get_id("config_text_number_box_"..option.id)
if(gui_selected == textbox_id) then
-- GamePrint("text box "..textbox_id.." is selected")
textbox_id = ""
end
option.value = tonumber(GuiTextInput(gui, textbox_id, x+button_width, y,
string.format("%d", option.value), 60, 9, "0123456789")) or 0
local clicked, right_clicked, hovered, textbox_x, textbox_y, textbox_width, textbox_height = get_previous_widget_info(gui)
if(clicked) then
-- GamePrint("text box "..textbox_id.." is clicked")
gui_selected = textbox_id
new_gui_selected = textbox_id
end
if(option.integer) then
option.value = math.floor(option.value)
end
if(option.value ~= old_value) then
option_changed = true
end
option_width = option_width+textbox_width
option_height = math.max(option_height, textbox_height)
end
end
y = y+option_height
extend_max_bound(option_width, y)
if(clicked) then
if(option.type=="boolean") then
if(option.override) then