-
Notifications
You must be signed in to change notification settings - Fork 17
/
editor.lua
4701 lines (4102 loc) · 148 KB
/
editor.lua
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
function editor_load()
print("Better editor loaded!")
currentanimation = 1
tilecount1 = 168
tilecount2 = 74
brush = {1, 1}
brushmax = 10
middlemode = {false, 0, 0}
tooltipa = 0
tilesoffset = 0
multitilesoffset = 0
minimapscroll = 0
minimapx = 3
minimapy = 30
minimapheight = 15
currenttile = 1
rightclicka = 0
minimapscrollspeed = 30
minimapdragging = false
allowdrag = true
savestates = {}
maxstates = 15
currentstate = 1
tileswitcherkey = controls[1]["use"][1] == "joy" and "e" or controls[1]["use"][1]
if musiclist[#musiclist] ~= "princessmusic.ogg" then
musiclist[#musiclist+1] = "princessmusic.ogg"
end
rightclickmenues.pipe = {
{t="text", value="destination:"},
{t="input", default="1"},
{t="text", value="note: 1 is main"}
}
rightclickmenues.vine = {
{t="text", value="destination:"},
{t="input", default="1"},
{t="text", value="note: 1 is main"}
}
rightclickmenues.pipespawn = {
{t="text", value="source:"},
{t="input", default="1"},
{t="text", value="note: 1 is main"}
}
rightclickmenues.warppipe = {
{t="text", value="world:"},
{t="input", default="1"},
{t="text", value="level:"},
{t="input", default="1"}
}
powerlinedrawtable = {
{"up", "down", 43, true},
{"down", "up", 43, true},
{"left", "right", 44, true},
{"right", "left", 44, true},
{"up", "right", 45, true},
{"right", "up", 45, true},
{"right", "down", 46, true},
{"down", "right", 46, true},
{"down", "left", 47, true},
{"left", "down", 47, true},
{"left", "up", 48, true},
{"up", "left", 48, true}}
tileselection = false
tileselectionclick1 = false
tileselectionclick1x = 0
tileselectionclick1y = 0
tileselectionclick2 = false
tileselectionclick2x = 0
tileselectionclick2y = 0
mtsavehighlighttime = 5
mtsavetimer = 0
mtjustsaved = 0
pastingtiles = false
pastemode = false -- 1 transparent, 2 opaque
pastecenter = {0, 0}
mtclipboard = {} -- fill with x, y, tile
splitxscroll = {0, 0}
animationguiarea = {12, 33, 399, 212}
objectsguiarea = {5, 21, 378, 203}
mapbuttonarea = {4, 21, 381, 220}
animationlineinset = 14
secretcheckboxtext = {"secret feature", "really secret feature", "super secret feature", "very secret feature", "don't enable this", "exit editor", "copy enemies", "copy entities", "all of the above", "play music in editor", "shmuck bait", "disable tiles", "enable tiles", "goombas are cats", "hat stacking", "auto-update", "horizontal tileset scrollbar", "show mazes", "play space jam while editing", "get rid of this checkbox", "old editor", "disable better editor", "1.6 editor", "enable autocorrect", "make cool maps like willware", "snes mode", "disable crashing", "enable this checkbox", "enable the super secret checkbox", ""}
guielements["tabmain"] = guielement:new("button", 1, 1, "main", maintab, 3)
guielements["tabmain"].fillcolor = {0.25, 0.25, 0.25}
guielements["tabtiles"] = guielement:new("button", 43, 1, "tiles", tilestab, 3)
guielements["tabtiles"].fillcolor = {0.25, 0.25, 0.25}
guielements["tabtools"] = guielement:new("button", 93, 1, "tools", toolstab, 3)
guielements["tabtools"].fillcolor = {0.25, 0.25, 0.25}
guielements["tabmaps"] = guielement:new("button", 143, 1, "maps", mapstab, 3)
guielements["tabmaps"].fillcolor = {0.25, 0.25, 0.25}
guielements["tabanimations"] = guielement:new("button", 185, 1, "animations", animationstab, 3)
guielements["tabanimations"].fillcolor = {0.25, 0.25, 0.25}
guielements["tabobjects"] = guielement:new("button", 275, 1, "objects", objectstab, 3)
guielements["tabobjects"].fillcolor = {0.25, 0.25, 0.25}
--MAIN
--left side
guielements["colorsliderr"] = guielement:new("scrollbar", 17, 75, 101, 11, 11, background[1], "hor")
guielements["colorsliderr"].backgroundcolor = {1, 0, 0}
guielements["colorsliderg"] = guielement:new("scrollbar", 17, 87, 101, 11, 11, background[2], "hor")
guielements["colorsliderg"].backgroundcolor = {0, 1, 0}
guielements["colorsliderb"] = guielement:new("scrollbar", 17, 99, 101, 11, 11, background[3], "hor")
guielements["colorsliderb"].backgroundcolor = {0, 0, 1}
for i = 1, #backgroundcolor do
guielements["defaultcolor" .. i] = guielement:new("button", 125+(math.mod(i-1, 3))*12, 63+(math.ceil(i/3))*12, "", defaultbackground, 0, {i}, 1, 8)
guielements["defaultcolor" .. i].fillcolor = backgroundcolor[i]
end
local args = {unpack(musiclist)}
local musici = 1
for i = 1, #args do
if args[i] == musicname then
musici = i
end
args[i] = string.lower(string.sub(args[i], 1, -5))
end
guielements["musicdropdown"] = guielement:new("dropdown", 17, 125, 11, changemusic, musici, unpack(args))
guielements["spritesetdropdown"] = guielement:new("dropdown", 17, 150, 11, changespriteset, spriteset, "overworld", "underground", "castle", "underwater")
guielements["timelimitdecrease"] = guielement:new("button", 17, 175, "{", decreasetimelimit, 0, nil, nil, nil, true)
guielements["timelimitincrease"] = guielement:new("button", 31 + string.len(mariotimelimit)*8, 175, "}", increasetimelimit, 0, nil, nil, nil, true)
local i = 1
if portalsavailable[1] and not portalsavailable[2] then
i = 2
elseif not portalsavailable[1] and portalsavailable[2] then
i = 3
elseif not portalsavailable[1] and not portalsavailable[2] then
i = 4
end
guielements["portalgundropdown"] = guielement:new("dropdown", 87, 187, 6, changeportalgun, i, "both", "blue", "orange", "none")
--right side
guielements["autoscrollcheckbox"] = guielement:new("checkbox", 290, 20, toggleautoscroll, autoscroll, "follow mario")
guielements["intermissioncheckbox"] = guielement:new("checkbox", 200, 66, toggleintermission, intermission, "intermission")
guielements["warpzonecheckbox"] = guielement:new("checkbox", 200, 81, togglewarpzone, haswarpzone, "warpzone text")
guielements["underwatercheckbox"] = guielement:new("checkbox", 200, 96, toggleunderwater, underwater, "underwater")
guielements["bonusstagecheckbox"] = guielement:new("checkbox", 200, 111, togglebonusstage, bonusstage, "bonus stage")
guielements["custombackgroundcheckbox"] = guielement:new("checkbox", 200, 126, togglecustombackground, custombackground, "background:")
guielements["customforegroundcheckbox"] = guielement:new("checkbox", 200, 156, togglecustomforeground, customforeground, "foreground:")
--bottom
guielements["savebutton"] = guielement:new("button", 10, 200, "save", savelevel, 2)
guielements["menubutton"] = guielement:new("button", 54, 200, "return to menu", editorexit, 2)
guielements["testbutton"] = guielement:new("button", 204, 200, "test level", test_level, 2)
guielements["widthbutton"] = guielement:new("button", 296, 200, "change size", openchangewidth, 2)
guielements["savebutton"].bordercolor = {1, 0, 0}
guielements["savebutton"].bordercolorhigh = {1, 0.5, 0.5}
--maybe I should use webkit next time
--hahahahhahahaha no
--mapsize stuff
guielements["maptopup"] = guielement:new("button", 0, 0, "_dir4", changenewmapsize, nil, {"top", "up"}, nil, 8, 0.02)
guielements["maptopdown"] = guielement:new("button", 0, 0, "_dir6", changenewmapsize, nil, {"top", "down"}, nil, 8, 0.02)
guielements["mapleftleft"] = guielement:new("button", 0, 0, "_dir3", changenewmapsize, nil, {"left", "left"}, nil, 8, 0.02)
guielements["mapleftright"] = guielement:new("button", 0, 0, "_dir5", changenewmapsize, nil, {"left", "right"}, nil, 8, 0.02)
guielements["maprightleft"] = guielement:new("button", 0, 0, "_dir3", changenewmapsize, nil, {"right", "left"}, nil, 8, 0.02)
guielements["maprightright"] = guielement:new("button", 0, 0, "_dir5", changenewmapsize, nil, {"right", "right"}, nil, 8, 0.02)
guielements["mapbottomup"] = guielement:new("button", 0, 0, "_dir4", changenewmapsize, nil, {"bottom", "up"}, nil, 8, 0.02)
guielements["mapbottomdown"] = guielement:new("button", 0, 0, "_dir6", changenewmapsize, nil, {"bottom", "down"}, nil, 8, 0.02)
guielements["mapwidthapply"] = guielement:new("button", 0, 0, "apply", mapwidthapply, 3)
guielements["mapwidthcancel"] = guielement:new("button", 0, 0, "cancel", mapwidthcancel, 3)
local args = {unpack(custombackgrounds)}
table.insert(args, 1, "default")
local i = 1
for j = 1, #custombackgrounds do
if custombackground == custombackgrounds[j] then
i = j+1
end
end
guielements["backgrounddropdown"] = guielement:new("dropdown", 298, 125, 10, changebackground, i, unpack(args))
args = {unpack(custombackgrounds)}
table.insert(args, 1, "none")
i = 1
for j = 1, #custombackgrounds do
if customforeground == custombackgrounds[j] then
i = j+1
end
end
guielements["foregrounddropdown"] = guielement:new("dropdown", 298, 155, 10, changeforeground, i, unpack(args))
guielements["scrollfactorscrollbar"] = guielement:new("scrollbar", 298, 140, 93, 35, 11, reversescrollfactor(), "hor")
guielements["fscrollfactorscrollbar"] = guielement:new("scrollbar", 298, 170, 93, 35, 11, reversefscrollfactor(), "hor")
args = {unpack(levelscreens)}
table.insert(args, 1, "none")
i = 1
for j = 1, #levelscreens do
if levelscreenbackname == levelscreens[j] then
i = j+1
end
end
--get current description and shit
local mappackname = ""
local mappackauthor = ""
local mappackdescription = ""
if love.filesystem.getInfo("mappacks/" .. mappack .. "/settings.txt") then
local data = love.filesystem.read("mappacks/" .. mappack .. "/settings.txt")
local split1 = data:split("\n")
for i = 1, #split1 do
local split2 = split1[i]:split("=")
if split2[1] == "name" then
mappackname = split2[2]:lower()
elseif split2[1] == "author" then
mappackauthor = split2[2]:lower()
elseif split2[1] == "description" then
mappackdescription = split2[2]:lower()
end
end
end
guielements["levelscreendropdown"] = guielement:new("dropdown", 298, 185, 10, changelevelscreen, i, unpack(args))
--TILES
guielements["tilesall"] = guielement:new("button", 4, 20, "all", tilesall, 2) --72
guielements["tilessmb"] = guielement:new("button", 37, 20, "smb", tilessmb, 2)
guielements["tilesportal"] = guielement:new("button", 70, 20, "portal", tilesportal, 2)
guielements["tilescustom"] = guielement:new("button", 127, 20, "custom", tilescustom, 2)
guielements["tilesanimated"] = guielement:new("button", 184, 20, "animated", tilesanimated, 2)
guielements["tilesentities"] = guielement:new("button", 257, 20, "entities", tilesentities, 2)
guielements["tilesenemies"] = guielement:new("button", 330, 20, "enemies", tilesenemies, 2)
guielements["tilesscrollbar"] = guielement:new("scrollbar", 381, 37, 167, 15, 40, 0, "ver", nil, nil, nil, nil, true)
--TOOLS
guielements["selectionbutton"] = guielement:new("button", 5, 22, "selection tool|click and drag to select entities|rightclick to configure all at once|hit del to delete.", selectionbutton, 2, false, 4, 383)
guielements["selectionbutton"].bordercolor = {0, 1, 0}
guielements["selectionbutton"].bordercolorhigh = {0.86, 1, 0.86}
guielements["lightdrawbutton"] = guielement:new("button", 5, 71, "advanced draw tool|place tiles seamlessly using premade tools", powerlinestab, 2, false, 2, 383)
guielements["lightdrawbutton"].bordercolor = {0, 0, 1}
guielements["lightdrawbutton"].bordercolorhigh = {0.5, 0.5, 1}
guielements["livesdecrease"] = guielement:new("button", 198, 104, "{", livesdecrease, 0)
guielements["livesincrease"] = guielement:new("button", 194, 104, "}", livesincrease, 0)
guielements["pastemodedropdown"] = guielement:new("checkbox", 149, 135, changepastemode, pastemode, "opaque paste")
guielements["clipboardcheckbox"] = guielement:new("checkbox", 149, 145, toggleclipboardenabled, clipboardenabled, "copy to clipboard")
guielements["linktoolkindabutnotreally"] = guielement:new("checkbox", 149, 155, toggledrawalllinks, drawalllinks, "draw all links")
guielements["editordebugcheckbox"] = guielement:new("checkbox", 149, 165, toggleeditordebug, editordebug, "show hitboxes")
guielements["levelscreencheckbox"] = guielement:new("checkbox", 149, 175, toggleskiplevelscreen, skiplevelscreen, "skip level screens")
guielements["secretcheckbox"] = guielement:new("checkbox", 149, 185, editorexit, nil, secretcheckboxtext[math.random(1,#secretcheckboxtext)])
guielements["edittitle"] = guielement:new("input", 5, 115, 17, nil, mappackname, 17)
guielements["editauthor"] = guielement:new("input", 5, 140, 13, nil, mappackauthor, 13)
guielements["editdescription"] = guielement:new("input", 5, 165, 17, nil, mappackdescription, 51, 3)
guielements["savesettings"] = guielement:new("button", 5, 203, "save settings", savesettings, 2)
guielements["savesettings"].bordercolor = {1, 0, 0}
guielements["savesettings"].bordercolorhigh = {1, 0.5, 0.5}
--[[MAPS
guielements["savebutton2"] = guielement:new("button", 10, 140, "save", savelevel, 2)
guielements["savebutton2"].bordercolor = {1, 0, 0}
guielements["savebutton2"].bordercolorhigh = {1, 0.5, 0.5}]]
guielements["mapscrollbar"] = guielement:new("scrollbar", 381, 21, 199, 15, 40, 0, "ver", nil, nil, nil, nil, true)
guielements["mapsworldbox"] = guielement:new("input", 332, 21, 2, nil, nil, 2, 1, true, 0)
guielements["mapslevelbox"] = guielement:new("input", 361, 21, 2, nil, nil, 2, 1, true, 0)
guielements["mapsnewlevel"] = guielement:new("button", 320, 21, "+", newlevel, 0)
--animationS
guielements["animationsscrollbarver"] = guielement:new("scrollbar", animationguiarea[1]-10, animationguiarea[2], animationguiarea[4]-animationguiarea[2], 10, 40, 0, "ver", nil, nil, nil, nil, true)
guielements["animationsscrollbarhor"] = guielement:new("scrollbar", animationguiarea[1], animationguiarea[4], animationguiarea[3]-animationguiarea[1], 40, 10, 0, "hor", nil, nil, nil, nil, false)
addanimationtriggerbutton = guielement:new("button", 0, 0, "+", addanimationtrigger, nil, nil, nil, 8)
addanimationtriggerbutton.textcolor = {0, 0.8, 0}
addanimationconditionbutton = guielement:new("button", 0, 0, "+", addanimationcondition, nil, nil, nil, 8)
addanimationconditionbutton.textcolor = {0, 0.8, 0}
addanimationactionbutton = guielement:new("button", 0, 0, "+", addanimationaction, nil, nil, nil, 8)
addanimationactionbutton.textcolor = {0, 0.8, 0}
local args = {}
for i, v in ipairs(animations) do
table.insert(args, string.sub(v.name, 1, -6))
end
guielements["animationselectdrop"] = guielement:new("dropdown", 15, 20, 15, selectanimation, 1, unpack(args))
guielements["animationnewbutton"] = guielement:new("button", 3, 20, "+", createnewanimation, nil)
guielements["animationsavebutton"] = guielement:new("button", 150, 19, "save", saveanimation, 1)
--OBJECTS fun fact: objects were originally in the tiles tab
guielements["objectscrollbar"] = guielement:new("scrollbar", 381, 21, objectsguiarea[4]-objectsguiarea[2], 15, 40, 0, "ver", nil, nil, nil, nil, true)
guielements["renamebar"] = guielement:new("input", 7, 0, 20, nil, nil, 20, 1, false, 0)
guielements["renamebar"].active = false
--POWERLINE "SUBTAB"
drawtools = 2
guielements["drawtool1"] = guielement:new("button", 5, 21, "power line draw", drawpowerlines, 2)
guielements["drawtool1"].bordercolor = {0, 0, 1}
guielements["drawtool1"].bordercolorhigh = {0.5, 0.5, 1}
guielements["drawtool2"] = guielement:new("button", 5, 38, "mushroom platforms", drawmushrooms, 2)
guielements["drawtool2"].bordercolor = {1, 0, 0}
guielements["drawtool2"].bordercolorhigh = {1, 0.5, 0.5}
multitileobjects = {}
multitileobjectnames = {}
loadmtobjects()
loadmtgroups()
helpui = {4, 4, width*16-4, height*16-4}
hotkeys = {}
loadHotKeys()
tilesall()
if editorloadopen then
editoropen()
editorloadopen = false
else
editorclose()
editorstate = "main"
editentities = false
end
savestate()
end
function editor_start()
editormode = true
players = 1
playertype = "portal"
playertypei = 1
bullettime = false
portalknockback = false
bigmario = false
goombaattack = false
sonicrainboom = false
playercollisions = false
infinitetime = false
infinitelives = false
game_load()
end
function editor_update(dt)
----------
--EDITOR--
----------
if middlemode[1] == false and not love.mouse.isDown("m") then
middlemode[2], middlemode[3] = getMouseTile(love.mouse.getX(), love.mouse.getY()-8*scale)
end
if rightclickm then
rightclickm:update(dt)
if rightclicka < 1 then
rightclicka = math.min(1, rightclicka + dt/linktoolfadeouttime)
end
elseif not rightclickactive then
if rightclicka > 0 then
rightclicka = math.max(0, rightclicka - dt/linktoolfadeouttime)
end
end
if changemapwidthmenu then
return
end
--key scroll
if editormenuopen == false then
if not (love.keyboard.isDown("lshift") or love.keyboard.isDown("rshift")) then
local xdir = love.keyboard.isDown("left") and -1 or (love.keyboard.isDown("right") and 1 or 0)
local ydir = love.keyboard.isDown("up") and -1 or (love.keyboard.isDown("down") and 1 or 0)
--xdir
local oldxscroll = xscroll
xscroll = math.max(0, math.min(mapwidth-width, xscroll + 30*gdt*xdir))
splitxscroll[1] = math.max(0, math.min(mapwidth-width, splitxscroll[1]))
--ydir
local oldyscroll = yscroll
yscroll = math.max(0, math.min(mapheight-1-height, yscroll + 30*gdt*ydir))
if oldxscroll ~= xscroll or oldyscroll ~= yscroll then
autoscroll = false
guielements["autoscrollcheckbox"].var = autoscroll
generatespritebatch()
if regiondragging and regiondragging.movex and regiondragging.movey then
regiondragging.movex = regiondragging.movex + (oldxscroll-xscroll)*16*scale
regiondragging.movey = regiondragging.movey + (oldyscroll-yscroll)*16*scale
end
end
end
end
if regiondragging then
if regiondragging:update(dt) then
regiondragging = nil
end
return
end
if love.keyboard.isDown("rctrl") or love.keyboard.isDown("lctrl") then
ctrlpressed = true
else
ctrlpressed = false
end
if love.keyboard.isDown(tileswitcherkey) then
tileswitcherpressed = true
else
tileswitcherpressed = false
end
if ctrlpressed then
tileselection = true
elseif tileselectionclick1 == true and tileselectionclick2 == true then
-- both points selected: keep highlighting the area
else
tileselection = false
tileselectionclick1 = false
tileselectionclick1x = 0
tileselectionclick1y = 0
tileselectionclick2 = false
tileselectionclick2x = 0
tileselectionclick2y = 0
end
if editormenuopen == false then
if editorstate == "lightdraw" then
if love.mouse.isDown("l") then
local mousex, mousey = mouse.getPosition()
local currentx, currenty = getMouseTile(mousex, mousey+8*scale)
if lightdrawX and (currentx ~= lightdrawX or currenty ~= lightdrawY) then
local xdir = 0
if currentx > lightdrawX then
xdir = 1
elseif currentx < lightdrawX then
xdir = -1
end
local ydir = 0
if currenty > lightdrawY then
ydir = 1
elseif currenty < lightdrawY then
ydir = -1
end
--fill in the gaps
local x, y = lightdrawX, lightdrawY
while x ~= currentx or y ~= currenty do
if x ~= currentx then
if x < currentx then
x = x + 1
else
x = x - 1
end
else
if y < currenty then
y = y + 1
else
y = y - 1
end
end
table.insert(lightdrawtable, {x=x,y=y})
if #lightdrawtable >= 3 then
local prevx, prevy = lightdrawtable[#lightdrawtable-2].x, lightdrawtable[#lightdrawtable-2].y
local currx, curry = lightdrawtable[#lightdrawtable-1].x, lightdrawtable[#lightdrawtable-1].y
local nextx, nexty = lightdrawtable[#lightdrawtable].x, lightdrawtable[#lightdrawtable].y
local prev = "up"
if prevx < currx then
prev = "left"
hprev = hprev - 2
vprev = 0
elseif prevx > currx then
prev = "right"
hprev = hprev + 2
vprev = 0
elseif prevy > curry then
prev = "down"
vprev = vprev + 2
hprev = 0
else
vprev = vprev - 2
hprev = 0
end
local next = "up"
if nextx < currx then
next = "left"
elseif nextx > currx then
next = "right"
elseif nexty > curry then
next = "down"
end
if advanceddrawtool == "mushroom" then
powerlinedrawtable = { --mushroom platform
{"down", "up", 65, false},
{"left", "right", 22, false, hprev, 0, 20, false, (hprev/math.abs(hprev)), 0, 21, false, hprev-(hprev/math.abs(hprev)), 0, 21},
{"right", "left", 20, false, hprev, 0, 22, false, (hprev/math.abs(hprev)), 0, 21, false, hprev-(hprev/math.abs(hprev)), 0, 21},
{"down", "right", 21, false, 0, 1, 43},
{"down", "left", 21, false, 0, 1, 43}}
elseif advanceddrawtool == "powerlines" then
powerlinedrawtable = { --powerlines
{"up", "down", 43, true},
{"down", "up", 43, true},
{"left", "right", 44, true},
{"right", "left", 44, true},
{"up", "right", 45, true},
{"right", "up", 45, true},
{"right", "down", 46, true},
{"down", "right", 46, true},
{"down", "left", 47, true},
{"left", "down", 47, true},
{"left", "up", 48, true},
{"up", "left", 48, true}}
end
local ii
for i = 1, #powerlinedrawtable do
if prev == powerlinedrawtable[i][1] and next == powerlinedrawtable[i][2] then
ii = i
end
end
if powerlinedrawtable[ii] then
placetile((currx-xscroll-.5)*16*scale, (curry-yscroll-1)*16*scale, powerlinedrawtable[ii][3], powerlinedrawtable[ii][4] or false)
for i = 5, #powerlinedrawtable[ii], 4 do
placetile((currx-xscroll-.5+powerlinedrawtable[ii][i])*16*scale, (curry-yscroll-1+powerlinedrawtable[ii][i+1])*16*scale, powerlinedrawtable[ii][i+2] or powerlinedrawtable[ii][3], powerlinedrawtable[ii][1+3] or powerlinedrawtable[ii][4] or false)
end
end
end
end
lightdrawX = currentx
lightdrawY = currenty
end
return
end
end
if rightclickactive or editorstate == "lightdraw" or editorstate == "selection" then
return
end
if love.mouse.isDown("l") and allowdrag then
if not (pastingtiles or tileselection) then
local x, y = mouse.getPosition()
for t1 = 1, brush[1] do
for t2 = 1, brush[2] do
placetile(x+(t1-1)*16*scale, y+(t2-1)*16*scale)
end
end
end
elseif love.mouse.isDown("m") and not middlemode[1] then
if math.abs(love.mouse.getX() - middlemode[2]) >= 8*scale or math.abs(love.mouse.getY() - middlemode[3]) >= 8*scale then
middlemode[1] = true
love.mouse.setVisible(false)
end
end
if middlemode[1] then
local xx, yy = love.mouse.getX() - middlemode[2], love.mouse.getY() - middlemode[3]
if math.abs(xx) < 8*scale and math.abs(yy) < 8*scale then
--ignore
else
if math.abs(yy) > math.abs(xx) then
xx = 0
if yy < 0 then yy = -1 else yy = 1 end
else
if xx < 0 then xx = -1 else xx = 1 end
yy = 0
end
if editentities and editenemies then
for i = 1, #enemies do
if enemies[i] == currenttile then
currenttile = i
break
end
end
if xx > 0 then
currenttile = math.min(currenttile+1, math.ceil(currenttile/22)*22, #enemies)
elseif xx < 0 then
currenttile = math.max(currenttile-1, math.ceil(currenttile/22)*22-21, 1)
elseif yy > 0 and currenttile+22 <= #enemies then
currenttile = currenttile+22
elseif yy < 0 and currenttile-22 >= 1 then
currenttile = currenttile-22
end
currenttile = enemies[currenttile]
elseif editentities then
local list = 1
local id = 1
for i, v in ipairs(entitylistitems) do
for j, w in ipairs(v.entries) do
if w.i == currenttile then
list = i
id = j
end
end
end
if xx > 0 then
id = math.min(id+1, #entitylistitems[list].entries)
elseif xx < 0 then
id = math.max(1, id-1)
elseif yy > 0 then
list = math.min(list+1, #entitylistitems)
id = math.min(id, #entitylistitems[list].entries)
elseif yy < 0 then
list = math.max(list-1, 1)
id = math.min(id, #entitylistitems[list].entries)
end
currenttile = entitylistitems[list].entries[id].i
else
if xx > 0 then
currenttile = math.min(currenttile+1, math.ceil(currenttile/22)*22, tilelistcount+tileliststart)
elseif xx < 0 then
currenttile = math.max(currenttile-1, math.ceil(currenttile/22)*22-21, tileliststart)
elseif yy > 0 and currenttile+22 <= tilelistcount+tileliststart then
currenttile = currenttile+22
elseif yy < 0 and currenttile-22 >= tileliststart then
currenttile = currenttile-22
end
currenttile = math.max(1, currenttile)
currenttile = math.min(currenttile, smbtilecount + portaltilecount + customtilecount + (modcustomtilecount[modcustomtiles] or 0))
end
love.mouse.setPosition(middlemode[2], middlemode[3])
end
end
elseif editorstate == "main" then
if love.mouse.isDown("l") then
local mousex, mousey = mouse.getPosition()
if mousey >= minimapy*scale and mousey < (minimapy+minimapheight*2+4)*scale then
if mousex >= minimapx*scale and mousex < (minimapx+394)*scale then
--HORIZONTAL
if mousex < (minimapx+width)*scale then
if minimapscroll > 0 then
minimapscroll = minimapscroll - minimapscrollspeed*dt
if minimapscroll < 0 then
minimapscroll = 0
end
end
elseif mousex >= (minimapx+394-width)*scale then
if minimapscroll < mapwidth-width-170 then
minimapscroll = minimapscroll + minimapscrollspeed*dt
if minimapscroll > mapwidth-width-170 then
minimapscroll = mapwidth-width-170
end
end
end
splitxscroll[1] = (mousex/scale-3-width) / 2 + minimapscroll
if splitxscroll[1] < minimapscroll then
splitxscroll[1] = minimapscroll
end
if splitxscroll[1] > 170 + minimapscroll then
splitxscroll[1] = 170 + minimapscroll
end
if splitxscroll[1] > mapwidth-width then
splitxscroll[1] = mapwidth-width
end
--SPRITEBATCH UPDATE
if math.floor(splitxscroll[1]) ~= spritebatchX[1] then
spritebatchX[1] = math.floor(splitxscroll[1])
end
generatespritebatch()
--VERTICAL
if mousey < (minimapy+5)*scale then
if yscroll > 0 then
yscroll = yscroll - minimapscrollspeed*dt
if yscroll < 0 then
yscroll = 0
end
end
elseif mousey >= (minimapy+minimapheight*2+4-5)*scale then
if yscroll < mapheight-height then
yscroll = yscroll + minimapscrollspeed*dt
if yscroll > mapheight-height-1 then
yscroll = mapheight-height-1
end
end
end
xscroll = (mousex/scale-3-width) / 2 + minimapscroll
if xscroll < minimapscroll then
xscroll = minimapscroll
end
if xscroll > 170 + minimapscroll then
xscroll = 170 + minimapscroll
end
if xscroll > mapwidth-width then
xscroll = mapwidth-width
end
--SPRITEBATCH UPDATE
if math.floor(xscroll) ~= spritebatchX[1] then
spritebatchX[1] = math.floor(xscroll)
elseif math.floor(yscroll) ~= spritebatchY[1] then
spritebatchY[1] = math.floor(yscroll)
end
generatespritebatch()
end
end
updatescrollfactor()
updatefscrollfactor()
updatebackground()
end
elseif editorstate == "tiles" then
tilesoffset = guielements["tilesscrollbar"].value * tilescrollbarheight * scale
if editentities and not editenemies then
local x, y = mouse.getPosition()
local tile = getentityhighlight(x, y)
if tile ~= prevtile then
if tile and tooltipimages[tile.i] then
entitytooltipobject = entitytooltip:new(tile)
end
end
if tile and tooltipimages[tile.i] then
entitytooltipobject:update(dt)
tooltipa = math.min(255, tooltipa + dt*4000)
else
tooltipa = math.max(-1000, tooltipa - dt*4000)
end
prevtile = tile
end
elseif editorstate == "objects" then
multitilesoffset = guielements["objectscrollbar"].value * objectscrollbarheight * scale
if guielements["renamebar"].active then
guielements["renamebar"].y = objectsguiarea[2]+1-multitilesoffset/scale + (guielements["renamebar"].tile*17)
-- guielements["renamebar"]:update(dt)
end
end
if animationguilines then
for i, v in pairs(animationguilines) do
for k, w in pairs(v) do
w:update(dt)
end
end
end
end
function editor_draw()
love.graphics.setColor(1, 1, 1)
local mousex, mousey = mouse.getPosition()
--EDITOR
if editormenuopen == false then
if editorstate == "selection" then
if selectiondragging or selectionwidth then
local x, y, width, height
x, y = selectionx, selectiony
if selectiondragging then
width, height = mousex-selectionx, mousey-selectiony
else
width, height = selectionwidth, selectionheight
end
if width < 0 then
x = x + width
width = -width
end
if height < 0 then
y = y + height
height = -height
end
if selectiondragging then
drawrectangle(x/scale, y/scale, width/scale, height/scale)
end
local selectionlist = selectiongettiles(x, y, width, height)
love.graphics.setColor(1, 1, 1, 0.4)
for i = 1, #selectionlist do
local v = selectionlist[i]
if map[v.x][v.y][2] and entitylist[map[v.x][v.y][2]] and rightclickmenues[entitylist[map[v.x][v.y][2]].t] then
love.graphics.rectangle("fill", (v.x-xscroll-1)*16*scale, (v.y-yscroll-1.5)*16*scale, 16*scale, 16*scale)
end
end
end
elseif not rightclickactive and not rightclickm and editorstate ~= "lightdraw" and not regiondragging then
local x, y = getMouseTile(mouse.getX(), mouse.getY()-8*scale)
if inmap(x, y+1) then
if pastingtiles then
-- draw mtclipboard
for i, v in ipairs(mtclipboard) do
for j, w in ipairs(v) do
--w = tonumber(w)
local quad = tilequads[w]:quad() --[[tilequads[w].quad]]
if w == 1 and pastemode == false then
-- well, do nothing
-- or better: draw empty tiles almost transparent
love.graphics.setColor(1, 1, 1, 0.03)
love.graphics.draw(tilequads[w].image, quad, math.floor((x-xscroll-1 + pastecenter[1])*16*scale+(i-1)*16*scale), ((y-yscroll-1 + pastecenter[2])*16+8)*scale+((j-1)*16*scale), 0, scale, scale)
else
love.graphics.setColor(1, 1, 1, 0.3)
love.graphics.draw(tilequads[w].image, quad, math.floor((x-xscroll-1 + pastecenter[1])*16*scale+(i-1)*16*scale), ((y-yscroll-1 + pastecenter[2])*16+8)*scale+((j-1)*16*scale), 0, scale, scale)
end
end
end
--end
end
love.graphics.setColor(1, 1, 1, 0.8)
if tileswitcherpressed then
-- draw temporal overlay for all the tiles that will be switched
local cox, coy = getMouseTile(love.mouse.getX(), love.mouse.getY()+8*scale)
-- now replace everything thats == map[cox][coy][1] to: currenttile
local mousetile = map[cox][coy][1]
for i, v in ipairs(map) do
for j, w in ipairs(v) do
local quad = tilequads[currenttile]:quad() --[[tilequads[w].quad]]
if w[1] == mousetile then
--print(i,j,w[1],"SWITCHED")
love.graphics.draw(tilequads[currenttile].image, quad, (i-1)*16*scale-xscroll*16*scale, (((j-1)*16*scale)-8*scale)-yscroll*16*scale, 0, scale, scale)
end
end
end
elseif tileselection then
if tileselectionclick1 == false then
if pastingtiles == false then
-- no clicks yet - draw layer on single block
love.graphics.setColor(0.5, 1, 0.5, 0.3)
love.graphics.rectangle("fill",math.floor((x-xscroll-1)*16*scale), (((y-1)*16+8)*scale)-yscroll*16*scale, 16*scale, 16*scale)
end
elseif tileselectionclick2 == false then
-- first click done - draw area: click1xy->mousexy
local lx1, ly1
lx1 = math.min(tileselectionclick1x, x)
ly1 = math.min(tileselectionclick1y, y)
love.graphics.setColor(0.44,0.44,1,0.44)
love.graphics.rectangle("fill",math.floor((lx1-xscroll-1)*16*scale), (((ly1-1)*16+8)*scale)-yscroll*16*scale, (math.max(tileselectionclick1x, x)-lx1)*16*scale+16*scale, (math.max(tileselectionclick1y, y)-ly1)*16*scale+16*scale)
else
-- two clicks done
local lx1, ly1, lx2, ly2
lx1 = math.min(tileselectionclick1x, tileselectionclick2x)
ly1 = math.min(tileselectionclick1y, tileselectionclick2y)
lx2 = math.max(tileselectionclick1x, tileselectionclick2x)
ly2 = math.max(tileselectionclick1y, tileselectionclick2y)
-- Laziness or cleverness?
local px, py = math.floor((lx1-xscroll-1)*16*scale), ((ly1-yscroll-1)*16+8)*scale
local pw, ph = (lx2-lx1)*16*scale+16*scale, (ly2-ly1)*16*scale+16*scale
love.graphics.setColor(0.67,1,0.67,0.7)
local timeOscilator = love.timer.getTime() % 2
timeOscilator = 1 - math.abs( math.cos(timeOscilator * math.pi) )
-- Highlight thing
love.graphics.rectangle("fill", px - (2 + timeOscilator*3)*scale, py - (2 + timeOscilator*3)*scale, 5*scale, scale)
love.graphics.rectangle("fill", px - (2 + timeOscilator*3)*scale, py - (1 + timeOscilator*3)*scale, scale, 4*scale)
love.graphics.rectangle("fill", px + pw + (2 + timeOscilator*3 - 5)*scale, py - (2 + timeOscilator*3)*scale, 5*scale, scale)
love.graphics.rectangle("fill", px + pw + (1 + timeOscilator*3)*scale, py - (1 + timeOscilator*3)*scale, scale, 4*scale)
love.graphics.rectangle("fill", px - (2 + timeOscilator*3)*scale, py + ph + (1 + timeOscilator*3)*scale, 5*scale, scale)
love.graphics.rectangle("fill", px - (2 + timeOscilator*3)*scale, py + ph + (1 + timeOscilator*3 - 4)*scale, scale, 4*scale)
love.graphics.rectangle("fill", px + pw + (2 + timeOscilator*3 - 5)*scale, py + ph + (1 + timeOscilator*3)*scale, 5*scale, scale)
love.graphics.rectangle("fill", px + pw + (1 + timeOscilator*3)*scale, py + ph + (1 + timeOscilator*3 - 4)*scale, scale, 4*scale)
local saveColors = {1, 0.44, 0.44, 0.7}
local selectColors = {0.67, 1, 0.67, 0.3}
love.graphics.setColor(selectColors)
if mtjustsaved > 0 then
local r, g, b, a = gradient(selectColors, saveColors, mtjustsaved)
love.graphics.setColor(r, g, b, a)
mtjustsaved = math.max(mtjustsaved - love.timer.getDelta(), 0)
if mtjustsaved == 0 then -- Negative 0 thing
mtjustsaved = 0
end
end
love.graphics.rectangle("fill", px, py, pw, ph)
end
elseif middlemode[1] then
love.graphics.push()
love.graphics.translate(-xscroll*16*scale, -yscroll*16*scale)
if editentities and editenemies then
for i = 1, #enemies do
if enemies[i] == currenttile then
currenttile = i
break
end
end
local offy = math.ceil(currenttile/22)-1
local offx = currenttile-offy*22
local cox, coy = getMouseTile(middlemode[2], middlemode[3]-8*scale)
for i = 1, #enemies do
local v = enemiesdata[ enemies[i] ]
love.graphics.setColor(1, 1, 1, 0.2)
if i == currenttile then
love.graphics.setColor(1, 1, 1, 0.8)
end
local t = "setStencil"
local action = nil
local int = nil
if loveVersion > 9 then
t = "stencil"
action = "replace"
int = 1
end
love.graphics[t](function() love.graphics.rectangle("fill", (math.mod((i-1), 22)-offx)*17*scale+cox*16*scale+scale, (math.floor((i-1)/22)-offy)*17*scale+coy*16*scale-8*scale, 16*scale, 16*scale) end, action, int)
if loveVersion > 9 then
love.graphics.setStencilTest("greater", 0)
end
love.graphics.draw(v.graphic, v.quad, (math.mod((i-1), 22)-offx)*17*scale+cox*16*scale+scale, (math.floor((i-1)/22)-offy)*17*scale+coy*16*scale-8*scale, 0, scale, scale)
if loveVersion > 9 then
love.graphics.setStencilTest()
else
love.graphics.setStencil()
end
if i == currenttile then
love.graphics.setColor(1, 0, 0, 0.6)
drawrectangle((math.mod((i-1), 22)-offx)*17+cox*16, (math.floor((i-1)/22)-offy)*17+coy*16-9, 18, 18)
end
end
currenttile = enemies[currenttile]
elseif editentities then
local list, id = 1, 1
for i, v in ipairs(entitylistitems) do
for j, w in ipairs(v.entries) do
if w.i == currenttile then
list = i
id = j
end
end
end
local offy = list-1
local offx = id
local cox, coy = getMouseTile(middlemode[2], middlemode[3]-8*scale)
for i2, v in ipairs(entitylistitems) do
for j, w in ipairs(v.entries) do
local i = (i2-1)*22+j
love.graphics.setColor(1, 1, 1, 0.2)
if w.i == currenttile then
love.graphics.setColor(1, 1, 1, 0.8)
end
love.graphics.draw(entityquads[w.i].image, entityquads[w.i].quad, (math.mod((i-1), 22)-offx)*17*scale+cox*16*scale+scale, (math.floor((i-1)/22)-offy)*17*scale+coy*16*scale-8*scale, 0, scale, scale)
if w.i == currenttile then