-
Notifications
You must be signed in to change notification settings - Fork 7
/
sf-ship-ed.bmx
1601 lines (1438 loc) · 56.8 KB
/
sf-ship-ed.bmx
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
Rem
STARSECTOR Ship&Weapon Editor
Created by Trylobot
Updated by Deathfly
EndRem
SuperStrict
'Framework BRL.GLMax2D
Import BRL.GLMax2D
Import BRL.RamStream
Import BRL.PNGLoader
Import BRL.JPGLoader
Import BRL.FreeTypeFont
Import BRL.event
Import BRL.eventqueue
Import maxgui.MaxGUI
Import maxgui.drivers
Import maxgui.win32maxguiex
Import maxgui.localization
Import "src/rjson.bmx"
Import "src/console.bmx"
?Win32
Import "assets/sf_icon.o"
?
Incbin "release/sf-ship-ed-settings.json" 'for defaults
Incbin "release/ENG.ini"
Incbin "assets/bg.png"
Incbin "assets/kb_key.png"
Incbin "assets/kb_key_wide.png"
Incbin "assets/kb_key_space.png"
Incbin "assets/ms_left.png"
Incbin "assets/ms_mid.png"
Incbin "assets/ms_right.png"
Incbin "assets/consola.ttf"
Incbin "assets/lte50549.ttf"
Incbin "assets/ico_dim.png"
Incbin "assets/ico_pos.png"
Incbin "assets/ico_ang.png"
Incbin "assets/ico_zoom.png"
Incbin "assets/ico_mirr.png"
Incbin "assets/ico_exit.png"
Incbin "assets/engineflame32.png"
Incbin "assets/engineflamecore32.png"
Incbin "assets/engineflamecore32.png"
Incbin "assets/weapon-slot-icons/SMALL-BALLISTIC.png"
Incbin "assets/weapon-slot-icons/MEDIUM-BALLISTIC.png"
Incbin "assets/weapon-slot-icons/LARGE-BALLISTIC.png"
Incbin "assets/weapon-slot-icons/SMALL-ENERGY.png"
Incbin "assets/weapon-slot-icons/MEDIUM-ENERGY.png"
Incbin "assets/weapon-slot-icons/LARGE-ENERGY.png"
Incbin "assets/weapon-slot-icons/SMALL-MISSILE.png"
Incbin "assets/weapon-slot-icons/MEDIUM-MISSILE.png"
Incbin "assets/weapon-slot-icons/LARGE-MISSILE.png"
Incbin "assets/weapon-slot-icons/SMALL-HYBRID.png"
Incbin "assets/weapon-slot-icons/MEDIUM-HYBRID.png"
Incbin "assets/weapon-slot-icons/LARGE-HYBRID.png"
Incbin "assets/weapon-slot-icons/SMALL-COMPOSITE.png"
Incbin "assets/weapon-slot-icons/MEDIUM-COMPOSITE.png"
Incbin "assets/weapon-slot-icons/LARGE-COMPOSITE.png"
Incbin "assets/weapon-slot-icons/SMALL-SYNERGY.png"
Incbin "assets/weapon-slot-icons/MEDIUM-SYNERGY.png"
Incbin "assets/weapon-slot-icons/LARGE-SYNERGY.png"
Incbin "assets/weapon-slot-icons/SMALL-UNIVERSAL.png"
Incbin "assets/weapon-slot-icons/MEDIUM-UNIVERSAL.png"
Incbin "assets/weapon-slot-icons/LARGE-UNIVERSAL.png"
Incbin "assets/weapon-slot-icons/SMALL-BUILT_IN.png"
Incbin "assets/weapon-slot-icons/MEDIUM-BUILT_IN.png"
Incbin "assets/weapon-slot-icons/LARGE-BUILT_IN.png"
Const FLOAT_MAX# = 10e38:Float
Include "src/config_json_transforms.bmx"
Include "src/functions_misc.bmx"
Include "src/drawing_misc.bmx"
Include "src/instaquit.bmx"
Include "src/menu.bmx"
Include "src/TextWidget.type.bmx"
Include "src/TableWidget.type.bmx"
Include "src/TStarfarerShip.type.bmx"
Include "src/TStarfarerSkin.type.bmx"
Include "src/TStarfarerShipWeapon.type.bmx"
Include "src/TStarfarerShipWeaponChange.type.bmx" 'thin extension for skins
Include "src/TStarfarerCustomEngineStyleSpec.type.bmx"
Include "src/TStarfarerShipEngine.type.bmx"
Include "src/TStarfarerShipEngineChange.type.bmx" 'thin extension for skins
Include "src/TStarfarerVariant.type.bmx"
Include "src/TStarfarerVariantWeaponGroup.type.bmx"
Include "src/TStarfarerWeapon.type.bmx"
Include "src/TStarfarerWeaponMuzzleFlashSpec.type.bmx"
Include "src/TStarfarerWeaponSmokeSpec.type.bmx"
Include "src/TCSVLoader.type.bmx"
Include "src/ShipDataCSVFieldTemplate.bmx"
Include "src/WingDataCSVFieldTemplate.bmx"
Include "src/WeaponDataCSVFieldTemplate.bmx"
Include "src/TModalSetWeaponCSV.type.bmx"
Include "src/TData.type.bmx"
Include "src/TSprite.type.bmx"
Include "src/TEditor.type.bmx"
Include "src/TSubroutine.type.bmx"
Include "src/TGenericCSVSubroutine.type.bmx"
Include "src/TModalSetShip.type.bmx"
Include "src/TModalSetShipCenter.type.bmx"
Include "src/TModalSetShieldCenter.type.bmx"
Include "src/TModalSetBounds.type.bmx"
Include "src/TModalSetWeaponSlots.type.bmx"
Include "src/TModalSetBuiltInWeapons.type.bmx"
Include "src/TModalSetBuiltInHullMods.type.bmx"
Include "src/TModalSetBuiltInWings.type.bmx"
Include "src/TModalSetEngineSlots.type.bmx"
Include "src/TModalSetLaunchBays.type.bmx"
Include "src/TModalSetStringData.type.bmx"
Include "src/TModalPreviewAll.type.bmx"
Include "src/TModalSetVariant.type.bmx"
Include "src/TModalSetVariantWings.type.bmx"
Include "src/TModalSetSkin.type.bmx"
Include "src/TModalSetShipCSV.type.bmx"
Include "src/TModalSetWingCSV.type.bmx"
Include "src/TModalSetWeapon.type.bmx"
Include "src/Application.type.bmx"
Include "src/help.bmx"
Include "src/multiselect_values.bmx"
Include "src/TTextCoder.bmx"
Include "src/TWeaponDrawer.bmx"
Include "src/TWingrenderer.bmx"
'/////////////////////////////////////////////
'MARK init APP var
Global DEBUG_LOG_FILE:TStream = WriteStream( "sf-ship-ed.log" )
Global LOC:TMaxGuiLanguage
SetGraphicsDriver GLMax2DDriver()
AppTitle = "STARSECTOR Ship&Weapon Editor"
Global APP:Application = Application.Load()
Global Apprunning% = True
Global W_MAX# = APP.window_size[0], W_MID# = W_MAX / 2.0
Global H_MAX# = APP.window_size[1], H_MID# = H_MAX / 2.0
Global FONT:TImageFont = Null
Global GAME_FONT:TImageFont = Null
Global DATA_FONT:TImageFont = Null
Global LINE_HEIGHT% = APP.font_size + 1
Global DATA_LINE_HEIGHT% = APP.data_font_size
Global CODE_MODE% = 1' LATIN1
Global SHOW_MORE% = 0
Function cycle_show_more()
SHOW_MORE :+ 1; If SHOW_MORE > 2 Then SHOW_MORE = 0
EndFunction
Global DO_ROUND% = 1
Global ZOOM_LEVELS#[] = [ 0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 15.0, 20.0, 30.0, 40.0, 50.0, 100.0, 200.0 ]
Const ZOOM_SNAP# = 0.025
Const ZOOM_UPDATE_FACTOR# = 0.25 'per frame
'////////////////////////////////////////////////
Const MAX_VARIANT_WEAPON_GROUPS% = 5
Const ENGINE_MANEUVERING_JETS_CONTRAIL_SIZE% = 128 'hack: makes a custom engine style into a "maneuvering jet"
'////////////////////////////////////////////////
'MARK init main windows
Global MainWindow:TGadget = CreateWindow("{{wt_main}}", 200, 0, W_MAX, H_MAX, Null, WINDOW_TITLEBAR | WINDOW_MENU | WINDOW_RESIZABLE | WINDOW_ACCEPTFILES )
Global CSVEditor:TGadget = Null
H_MAX = MainWindow.ClientHeight()
H_MID = H_MAX / 2
W_MAX = MainWindow.ClientWidth()
W_MID = W_MAX / 2
Global Canvas:TGadget = CreateCanvas(0, 0, GadgetWidth( Desktop() ), GadgetHeight( Desktop() ), MainWindow)
Canvas.SetArea(0, 0, W_MAX, H_MAX )
Global graphic:TGraphics = CanvasGraphics (Canvas)
SetGraphics(graphic)
SetClsColor( 0, 0, 0 )
AutoMidHandle( True )
SetBlend( ALPHABLEND )
'FONT = LoadImageFont( "incbin::assets/consola.ttf", APP.font_size, SMOOTHFONT )
'DATA_FONT = LoadImageFont( "incbin::assets/consola.ttf", APP.data_font_size, SMOOTHFONT )
'SetImageFont( FONT )
'////////////////////////////////////////////////
'MARK UTF-8 and Font support testing
If APP.UTF8_support
CODE_MODE = 2
EndIf
If APP.custom_FONT.length > 0
FONT = LoadImageFont( APP.custom_FONT, APP.font_size, SMOOTHFONT )
GAME_FONT = LoadImageFont( APP.custom_FONT, APP.font_size, SMOOTHFONT )
DATA_FONT = LoadImageFont( APP.custom_FONT, APP.data_font_size, SMOOTHFONT )
SetImageFont( FONT )
Else
FONT = LoadImageFont( "incbin::assets/consola.ttf", APP.font_size, SMOOTHFONT )
GAME_FONT = LoadImageFont( "incbin::assets/lte50549.ttf", APP.font_size, SMOOTHFONT )
DATA_FONT = LoadImageFont( "incbin::assets/consola.ttf", APP.data_font_size, SMOOTHFONT )
SetImageFont( FONT )
EndIf
'////////////////////////////////////////////////
'MARK display loading message
Cls
draw_string( "Loadin' ...", W_MID, H_MID,,, 0.5, 0.5 )
Flip( 1 )
'////////////////////////////////////////////////
'MARK json
config_json_transforms()
'////////////////////////////////////////////////
'MARK Local var init
Global ed:TEditor = New TEditor
ed.show_help = True
Global sprite:TSprite = New TSprite
sprite.scale = ZOOM_LEVELS[ed.selected_zoom_level]
ed.target_sprite_scale = sprite.scale
Global data:TData = New TData
'MARK init UI
init_gui_menus()
rebuildFunctionMenu(MENU_MODE_SHIP) 'default mode: ship
'MARK init help
load_help()
'////////////////////////////////////////////////
'modifier keys
Global ModKeyAndMouseKey:Byte = False
Global SHIFT:Byte = False
Global CONTROL:Byte = False
Global ALT:Byte = False
Global quote:String = Chr(34)
'Mouse Local
Global MouseX% = 0
Global MouseY% = 0
Global MouseZ% = 0
Global z_delta% = 0
Global MouseDown% [4]
Global MouseClick% = 0
Local mouseInRange% = 0
Global TEXT_W:TextWidget = TextWidget.Create( "W" )
Global TEXT_E:TextWidget = TextWidget.Create( "E" )
Global TEXT_L:TextWidget = TextWidget.Create( "L" )
'////////////////////////////////////////////////
'init ui and data set
load_ui( ed )
load_starfarer_data( ed, data )
'////////////////////////////////////////////////
'MARK init modals
Global sub_set_ship:TModalSetShip = New TModalSetShip
Global sub_set_ship_center:TModalSetShipCenter = New TModalSetShipCenter
Global sub_set_bounds:TModalSetBounds = New TModalSetBounds
Global sub_set_shield_center:TModalSetShieldCenter = New TModalSetShieldCenter
Global sub_set_weapon_slots:TModalSetWeaponSlots = New TModalSetWeaponSlots
Global sub_set_built_in_weapons:TModalSetBuiltInWeapons = New TModalSetBuiltInWeapons
Global sub_set_built_in_hullmods:TModalSetBuiltInHullMods = New TModalSetBuiltInHullMods
Global sub_set_built_in_wings:TModalSetBuiltInWings = New TModalSetBuiltInWings
Global sub_set_engine_slots:TModalSetEngineSlots = New TModalSetEngineSlots
Global sub_string_data:TModalSetStringData = New TModalSetStringData
Global sub_set_launchbays:TModalSetLaunchBays = New TModalSetLaunchBays
Global sub_preview_all:TModalPreviewAll = New TModalPreviewAll
Global sub_set_variant:TModalSetVariant = New TModalSetVariant
Global sub_set_variant_wings:TModalSetVariantWings = New TModalSetVariantWings
Global sub_set_skin:TModalSetSkin = New TModalSetSkin
Global sub_ship_csv:TModalSetShipCSV = New TModalSetShipCSV
Global sub_wing_csv:TModalSetWingCSV = New TModalSetWingCSV
Global sub_set_weapon:TModalSetWeapon = New TModalSetWeapon
Global sub_weapon_csv:TModalSetWeaponCSV = New TModalSetWeaponCSV
Global SS:TSmoothScroll = New TSmoothScroll
'////////////////////////////////////////////////
'MARK init FPS limiter
Global Lmt_FPS% = APP.fps_limit
If Not Lmt_FPS Then Lmt_FPS = DesktopHertz()
If Not Lmt_FPS Or Lmt_FPS < 1 Then Lmt_FPS = 60
Global Timer:TTimer = CreateTimer(Lmt_FPS)
'////////////////////////////////////////////////
'MARK init weapon drawer
Global WD:TWeaponDrawer = New TWeaponDrawer
'MARK inti wing renderer
Global WR:TWingRenderer = New TWingRenderer
'MARK Enable Polled Input for test
'EnablePolledInput(Canvas)
data.changed = False
MainWindow.Activate(1)
MainWindow.SetSensitivity(SENSITIZE_ALL)
updata_weapondrawermenu(ed)
'//////////////////////////////////////////////////////////////////////////////
'//////////////////////////////////////////////////////////////////////////////
'/////// MARK MAIN LOOP //////////////////////////////////////////////////////
'//////////////////////////////////////////////////////////////////////////////
'//////////////////////////////////////////////////////////////////////////////
Repeat
'MARK Events
'TODO adding Events
WaitEvent()
'instaquit
escape_key_update()
'If EventID() <> EVENT_GADGETPAINT And EventID() <> EVENT_TIMERTICK Then Print CurrentEvent.ToString()
If Not Apprunning And EventID() <> EVENT_APPRESUME Then Continue
'
Select EventID()
Case EVENT_APPSUSPEND, EVENT_APPRESUME
'freeze after lose focus
Apprunning = (EventID() = EVENT_APPRESUME)
If Apprunning
ModKeyAndMouseKey = 0
Else
SetBlend(ALPHABLEND)
SetColor(0, 0, 0)
SetAlpha(0.8)
DrawRect(0, 0, W_MAX, H_MAX)
SetBlend(ALPHABLEND)
Flip(1)
EndIf
Case EVENT_KEYDOWN, EVENT_KEYUP, EVENT_KEYREPEAT
If EventID() = EVENT_KEYDOWN Or EventID() = EVENT_KEYUP
Select EventData()
Case KEY_LSHIFT, KEY_RSHIFT
If (SHIFT = (EventData() Or 1) ) = (EventID() = EVENT_KEYUP) Then SHIFT :~ EventData()
If SHIFT Then ModKeyAndMouseKey :| MODIFIER_SHIFT Else ModKeyAndMouseKey :& ( 255 - MODIFIER_SHIFT)
Case KEY_LCONTROL, KEY_RCONTROL
If (CONTROL = (EventData() Or 1) ) = (EventID() = EVENT_KEYUP) Then CONTROL :~ EventData()
If CONTROL Then ModKeyAndMouseKey :| MODIFIER_CONTROL Else ModKeyAndMouseKey :& ( 255 - MODIFIER_CONTROL)
Case KEY_LALT, KEY_RALT
If (ALT = (EventData() Or 1) ) = (EventID() = EVENT_KEYUP) Then ALT :~ EventData()
If ALT Then ModKeyAndMouseKey :| MODIFIER_ALT Else ModKeyAndMouseKey :& ( 255 - MODIFIER_ALT)
End Select
'fake a EVENT_MOUSEMOVE to
EmitEvent(CreateEvent(EVENT_MOUSEMOVE, Canvas, 0, 0, MouseX, MouseY) )
EndIf
'pass key event down when we are in string edit mode
If check_sub_routines( ed, data, sprite) Then Continue
Case EVENT_GADGETACTION , EVENT_MENUACTION
'DebugLog (EventSource().ToString() )
If EventSource() = optionMenu[MENU_OPTION_ABOUT]
Notify("STARSECTOR Ship&Weapon Editor~nCreated by Trylobot~nUpdated by Deathfly~n~n" + LocalizeString("{{msg_localisation_credits}}") )
EndIf
check_zoom_and_pan( ed, data, sprite )
If check_undo( ed, data, sprite ) Then Continue
'skip most hotkeys when we are in string edit mode or so.
If (ed.mode = "string_data" ..
Or (ed.program_mode = "csv" And (sub_ship_csv.loaded_csv_id_list Or sub_ship_csv.csv_row_values) )..
Or (ed.program_mode = "csv_wing" And (sub_wing_csv.loaded_csv_id_list Or sub_wing_csv.csv_row_values) ) ..
Or (ed.program_mode = "csv_weapon" And (sub_weapon_csv.loaded_csv_id_list Or sub_weapon_csv.csv_row_values) ) )
If check_sub_routines( ed, data, sprite) Then Continue
Else
If check_file_menu( ed, data, sprite ) Then Continue
If check_mode_menu( ed, data, sprite ) Then Continue
If check_option_menu( ed, data ) Then Continue
If check_function_menu( ed, data, sprite ) Then Continue
check_weapondrawer(ed, data, sprite)
If check_sub_routines( ed, data, sprite) Then Continue
EndIf
' Case EVENT_MOUSEENTER, EVENT_MOUSELEAVE
' mouseInRange = (EventID() = EVENT_MOUSEENTER)
' If Not mouseInRange
' ModKeyAndMouseKey = 0
' EndIf
Case EVENT_MOUSEDOWN, EVENT_MOUSEMOVE, EVENT_MOUSEUP
MouseClick = 0
'If mouseInRange
MouseX = EventX()
MouseY = EventY()
'EndIf
If EventID() = EVENT_MOUSEDOWN
MouseDown[EventData()] = 1
MouseClick = EventData()
ModKeyAndMouseKey :| 8 Shl EventData()
EndIf
'pass mouse event down
check_zoom_and_pan( ed, data, sprite )
check_sub_routines( ed, data, sprite)
If EventID() = EVENT_MOUSEUP
MouseDown[EventData()] = 0
ModKeyAndMouseKey :& 255 - (8 Shl EventData() )
EndIf
Case EVENT_MOUSEWHEEL
MouseZ :+ EventData()
check_zoom_and_pan( ed, data, sprite )
Case EVENT_WINDOWACCEPT
Case EVENT_WINDOWSIZE
If EventSource() = MainWindow
H_MAX = MainWindow.ClientHeight()
H_MID = H_MAX / 2
W_MAX = MainWindow.ClientWidth()
W_MID = W_MAX / 2
Canvas.SetArea( 0, 0, W_MAX, H_MAX)
SetGraphics( CanvasGraphics(Canvas) )
SetClsColor( 0, 0, 0 )
AutoMidHandle( True )
SetBlend( ALPHABLEND )
ed.bg_scale = Max( W_MAX / Float(ed.bg_image.width), H_MAX / Float(ed.bg_image.height) )
EndIf
Case EVENT_TIMERTICK
RedrawGadget(Canvas)
Case EVENT_GADGETPAINT
If EventSource() = Canvas
Cls
DebugDrawReset
'display string for mouse (usually context-help)
mouse_str = ""
'update
update_zoom( ed, data, sprite )
updatUndo( data )
sprite.update()
update_menu()
'draw
draw_bg( ed )
draw_sprite( ed, sprite )
'drawing order exception for variant/weapon mode
' variant editor decides on when to draw weapons
If ed.program_mode <> "variant"
draw_weapons( ed, data, sprite, WD )
EndIf
Select ed.program_mode
Case "ship"
Select ed.mode
Case "none"
sub_set_ship.Draw( ed, data, sprite )
Case "center"
sub_set_ship_center.Draw( ed, data, sprite )
Case "bounds"
sub_set_bounds.Draw( ed, data, sprite )
Case "shield_center"
sub_set_shield_center.Draw( ed, data, sprite )
Case "weapon_slots"
sub_set_weapon_slots.Draw( ed, data, sprite )
Case "built_in_weapons"
sub_set_built_in_weapons.Draw( ed, data, sprite )
Case "built_in_hullmods"
sub_set_built_in_hullmods.Draw( ed, data, sprite )
Case "built_in_wings"
sub_set_built_in_wings.Draw( ed, data, sprite )
Case "engine_slots"
sub_set_engine_slots.Draw( ed, data, sprite )
Case "launch_bays"
sub_set_launchbays.Draw( ed, data, sprite )
Case "preview_all"
sub_preview_all.Draw( ed, data, sprite )
'Case "string_data"
'performed below
End Select
Case "variant"
Select ed.mode
Case "normal"
sub_set_variant.Draw( ed, data, sprite )
Case "variant_wings"
sub_set_variant_wings.Draw( ed, data, sprite )
'Case "string_data"
'performed below
EndSelect
Case "skin"
If ed.mode <> "string_data"
sub_set_skin.Draw( ed, data, sprite )
EndIf
'string_data
' performed below
Case "csv"
sub_ship_csv.Draw( ed, data, sprite )
Case "csv_wing"
sub_wing_csv.Draw( ed, data, sprite )
Case "weapon"
sub_set_weapon.Draw( ed, data, sprite )
Case "csv_weapon"
sub_weapon_csv.Draw( ed, data, sprite )
End Select
draw_help( ed )
draw_data( ed, data )
draw_status( ed, data, sprite )
draw_mouse_str()
draw_debug( ed, data, sprite )
If ed.mode = "string_data"
sub_string_data.Draw( ed, data, sprite )
End If
'instaquit
draw_instaquit_progress( W_MAX, H_MAX )
Flip( 1 )
EndIf
Case EVENT_APPTERMINATE, EVENT_WINDOWCLOSE
end_program( data )
EndSelect
Until AppTerminate()
'//////////////////////////////////////////////////////////////////////////////
'//////////////////////////////////////////////////////////////////////////////
'/////// MARK MAIN LOOP END /////////////////////////////////////////////////
'//////////////////////////////////////////////////////////////////////////////
'//////////////////////////////////////////////////////////////////////////////
Function end_program( data:TData )
If data.changed
If Confirm( LocalizeString("{{msg_unsaved_exit}}") ) Then End
Else
End
EndIf
EndFunction
If DEBUG_LOG_FILE
CloseStream( DEBUG_LOG_FILE )
EndIf
End
'////////////////////////////////////////////////
'MARK Function set
Function check_sub_routines% ( ed:TEditor, data:TData, sprite:TSprite )
Local hit% = True
Select ed.program_mode
Case "ship"
Select ed.mode
Case "none"
sub_set_ship.Update( ed, data, sprite )
Case "center"
sub_set_ship_center.Update( ed, data, sprite )
Case "bounds"
sub_set_bounds.Update( ed, data, sprite )
Case "shield_center"
sub_set_shield_center.Update( ed, data, sprite )
Case "weapon_slots"
sub_set_weapon_slots.Update( ed, data, sprite )
Case "built_in_weapons"
sub_set_built_in_weapons.Update( ed, data, sprite )
Case "built_in_hullmods"
sub_set_built_in_hullmods.Update( ed, data, sprite )
Case "built_in_wings"
sub_set_built_in_wings.Update( ed, data, sprite )
Case "engine_slots"
sub_set_engine_slots.Update( ed, data, sprite )
Case "launch_bays"
sub_set_launchbays.Update( ed, data, sprite )
Case "string_data"
sub_string_data.Update( ed, data, sprite )
Case "preview_all"
sub_preview_all.Update( ed, data, sprite )
End Select
Case "variant"
Select ed.mode
Case "normal"
sub_set_variant.Update( ed, data, sprite )
Case "variant_wings"
sub_set_variant_wings.Update( ed, data, sprite )
Case "string_data"
sub_string_data.Update( ed, data, sprite )
EndSelect
Case "skin"
If ed.mode <> "string_data"
sub_set_skin.Update( ed, data, sprite )
Else
sub_string_data.Update( ed, data, sprite )
EndIf
Case "csv"
sub_ship_csv.Update( ed, data, sprite )
Case "csv_wing"
sub_wing_csv.Update( ed, data, sprite )
Case "weapon"
Select ed.mode
Case "string_data"
sub_string_data.Update( ed, data, sprite )
Default
sub_set_weapon.Update( ed, data, sprite )
EndSelect
Case "csv_weapon"
sub_weapon_csv.Update( ed, data, sprite )
Default
hit = False
End Select
Return hit
End Function
'MARK GAlist check
'-----------------------
' Return true if the input EventSource(Object) hit the checkes, so we can skip the rest
Function check_file_menu%(ed:TEditor, data:TData, sprite:TSprite)
Local hit% = True
Select EventSource()
Case fileMenu[MENU_FILE_NEW] 'new file
If data.changed
If Not Confirm(LocalizeString("{{msg_unsaved_open_new}}") ) Then Return hit
EndIf
WD.restAllAnimes()
Select ed.program_mode
Case "ship", "csv", "csv_wing"
data.ship = New TStarfarerShip
data.variant = New TStarfarerVariant
data.csv_row = ship_data_csv_field_template.Copy()
data.csv_row_wing = wing_data_csv_field_template.Copy()
sprite.img = Null
data.update()
data.update_variant()
data.changed = False
data.snapshots_undo:TList = CreateList()
data.snapshots_redo:TList = CreateList()
Case "variant"
data.variant = New TStarfarerVariant
data.variant.hullId = data.ship.hullId
data.variant.displayName = "New"
data.variant.variantId = data.ship.hullId + "_new"
data.update()
data.update_variant()
data.changed = False
data.snapshots_undo:TList = CreateList()
data.snapshots_redo:TList = CreateList()
Case "skin"
data.ship = New TStarfarerShip
data.variant = New TStarfarerVariant
data.skin = New TStarfarerSkin
sprite.img = Null
data.update()
data.update_variant()
data.update_skin()
data.changed = False
data.snapshots_undo:TList = CreateList()
data.snapshots_redo:TList = CreateList()
Case "weapon", "csv_weapon"
data.weapon = New TStarfarerWeapon
data.csv_row_weapon = weapon_data_csv_field_template.Copy()
sprite.img = Null
data.update_weapon()
data.changed = False
data.snapshots_undo:TList = CreateList()
data.snapshots_redo:TList = CreateList()
EndSelect
Case fileMenu[MENU_FILE_LOAD_MOD] 'load mod
load_mod( ed, data )
Case fileMenu[MENU_FILE_LOAD_DATA] 'load data
If data.changed
If Not Confirm(LocalizeString("{{msg_unsaved_open_new}}") ) Then Return hit
EndIf
data.snapshot_inited = False
Select ed.program_mode
Case "ship"
load_ship_data( ed, data, sprite )
Case "variant"
load_variant_data( ed, data, sprite )
Case "skin"
load_skin_data( ed, data, sprite )
Case "csv"
sub_ship_csv.Load( ed, data, sprite )
Case "csv_wing"
sub_wing_csv.Load( ed, data, sprite )
Case "weapon"
sub_set_weapon.Load( ed, data, sprite )
Case "csv_weapon"
sub_weapon_csv.Load( ed, data, sprite )
EndSelect
data.take_initshot()
data.changed = False
Case fileMenu[MENU_FILE_LOAD_IMAGE] 'load image
Select ed.program_mode
Case "ship", "variant", "csv", "csv_wing"
load_ship_image( ed, data, sprite )
Case "skin"
load_skin_image( ed, data, sprite )
EndSelect
Case fileMenu[MENU_FILE_SAVE] 'save data
Select ed.program_mode
Case "ship"
Local data_path$ = RequestFile( LocalizeString( "{{wt_save_ship}}"), "ship", True, APP.data_dir + data.ship.hullId + ".ship" )
FlushKeys()
If data_path
APP.data_dir = ExtractDir( data_path ) + "/"
APP.Save()
'SaveString( data.json_str, data_path )
SaveTextAs(data.json_str, data_path, CODE_MODE)
data.changed = False
End If
Case "variant"
Local variant_path$ = RequestFile( LocalizeString("{{wt_save_variant}}"), "variant", True, APP.variant_dir + data.variant.variantId + ".variant" )
FlushKeys()
If variant_path
APP.variant_dir = ExtractDir( variant_path ) + "/"
APP.Save()
'SaveString( data.json_str_variant, variant_path )
SaveTextAs(data.json_str_variant, variant_path, CODE_MODE)
data.changed = False
End If
Case "skin"
Local skin_path$ = RequestFile( LocalizeString("{{wt_save_skin}}"), "skin", True, APP.skin_dir + data.skin.skinHullId + ".skin" )
FlushKeys()
If skin_path
APP.skin_dir = ExtractDir( skin_path ) + "/"
APP.Save()
'SaveString( data.json_str_variant, variant_path )
SaveTextAs(data.json_str_skin, skin_path, CODE_MODE)
data.changed = False
End If
Case "csv"
sub_ship_csv.Save( ed, data, sprite )
Case "csv_wing"
sub_wing_csv.Save( ed, data, sprite )
Case "weapon"
sub_set_weapon.Save( ed, data, sprite )
Case "csv_weapon"
sub_weapon_csv.Save( ed, data, sprite )
EndSelect
Case fileMenu[MENU_FILE_EXIT] 'exit
end_program( data )
Default
hit = False
End Select
Return hit
End Function
'-----------------------
' if the input EventSource(Object) "hits," it is consumed and nothing that would normally follow gets to process it
' sort of like {Event}.preventDefault() in Javascript
Function check_mode_menu%( ed:TEditor, data:TData, sprite:TSprite )
Local hit% = True
Select EventSource()
Case modeMenu[MENU_MODE_SHIP] 'm_mode_ship
sub_set_ship.Activate( ed, data, sprite )
Case modeMenu[MENU_MODE_VARIANT] 'm_mode_variant
sub_set_variant.Activate( ed, data, sprite )
Case modeMenu[MENU_MODE_SKIN] 'm_mode_skin
sub_set_skin.Activate( ed, data, sprite )
Case modeMenu[MENU_MODE_SHIPSTATS] 'm_mode_ship_stats
sub_ship_csv.Activate( ed, data, sprite )
Case modeMenu[MENU_MODE_WING] 'm_mode_wing
sub_wing_csv.Activate( ed, data, sprite )
Case modeMenu[MENU_MODE_WEAPON] 'm_mode_weapon
sub_set_weapon.Activate( ed, data, sprite )
Case modeMenu[MENU_MODE_WEAPONSTATS] 'm_mode_weapon_stats
sub_weapon_csv.Activate( ed, data, sprite )
' Case modeMenu[MENU_MODE_PROJECTILE] 'm_mode_projectile
' sub_projectile.Activate( ed, data, sprite )
Default
hit = False
End Select
updata_weapondrawermenu(ed)
Return hit
End Function
Function check_option_menu%(ed:TEditor, data:TData)
Local hit% = True
Select EventSource()
Case optionMenu[MENU_OPTION_HELP]
ed.show_help = Not ed.show_help
Case optionMenu[MENU_OPTION_JSON]
ed.show_data = Not ed.show_data
Case optionMenu[MENU_OPTION_GUIDES]
ed.show_debug = Not ed.show_debug
If ed.show_debug Then SetPointer(POINTER_CROSS) Else SetPointer(POINTER_DEFAULT)
Case optionMenu[MENU_OPTION_MIRROR]
ed.bounds_symmetrical = Not ed.bounds_symmetrical
Case optionMenu[MENU_OPTION_VANILLA]
APP.hide_vanilla_data = Not APP.hide_vanilla_data
load_starfarer_data( ed, data )
Default
hit = False
End Select
Return hit
End Function
Function check_undo%(ed:TEditor, data:TData, sprite:TSprite)
Local hit% = True
Select EventSource()
Case functionMenu[MENU_FUNCTION_UNDO]
undo(ed, data, sprite, False)
Case functionMenu[MENU_FUNCTION_REDO]
undo(ed, data, sprite, True)
Default
hit = False
End Select
Return hit
End Function
Function check_weapondrawer%(ed:TEditor, data:TData, sprite:TSprite)
WD.check(ed, data)
End Function
Function updata_weapondrawermenu(ed:TEditor)
Local flag# =(ed.mode <> "string" ..
And ((ed.program_mode = "ship" And (ed.mode = "built_in_weapons" Or ed.mode = "weapon_slots") ) ..
Or (ed.program_mode = "skin" And (ed.mode = "changeremove_weaponslots" Or ed.mode = "addremove_builtin_weapons")) ..
Or (ed.program_mode = "variant" And ed.variant_hullMod_i = - 1 And ed.group_field_i = - 1) ..
Or (ed.program_mode = "weapon") ) )
If MenuEnabled(animateMenu[MENU_ANIMATE]) <> flag
For Local i# = 0 Until animateMenu.length
animateMenu[i].SetEnabled(flag)
Next
mainMenuNeedUpdate = True
EndIf
End Function
Function updatUndo(data:TData)
If (data.snapshots_undo.IsEmpty() And Not data.changed) = MenuEnabled(functionMenu[MENU_FUNCTION_UNDO])
functionMenu[MENU_FUNCTION_UNDO].setenabled(Not (data.snapshots_undo.IsEmpty() And Not data.changed) )
mainMenuNeedUpdate = True
EndIf
If (data.snapshots_redo.IsEmpty() ) = MenuEnabled(functionMenu[MENU_FUNCTION_REDO])
functionMenu[MENU_FUNCTION_REDO].setenabled(Not data.snapshots_redo.IsEmpty() )
mainMenuNeedUpdate = True
EndIf
End Function
Function check_function_menu% ( ed:TEditor, data:TData, sprite:TSprite )
Local hit% = True
Select ed.program_mode
Case "ship"
Select EventSource()
Case functionMenu[MENU_FUNCTION_EXIT] 'exit
ed.last_mode = ed.mode
ed.mode = "none"
ed.field_i = 0
Case functionMenuSub[MENU_MODE_SHIP][MENU_SUBFUNCTION_SHIP_CENTER] 'mass center
sub_set_ship_center.Activate( ed, data, sprite )
Case functionMenuSub[MENU_MODE_SHIP][MENU_SUBFUNCTION_SHIP_SHIELD] 'shield center
sub_set_shield_center.Activate( ed, data, sprite )
Case functionMenuSub[MENU_MODE_SHIP][MENU_SUBFUNCTION_SHIP_BOUNDS] 'bounds
sub_set_bounds.Activate( ed, data, sprite )
Case functionMenuSub[MENU_MODE_SHIP][MENU_SUBFUNCTION_SHIP_WEAPONSLOTS] 'weapon slots
sub_set_weapon_slots.Activate( ed, data, sprite )
Case functionMenuSub[MENU_MODE_SHIP][MENU_SUBFUNCTION_SHIP_BUILTINWEAPONS], functionMenuSub[MENU_MODE_SHIP][MENU_SUBFUNCTION_SHIP_DECORATIVE] 'built-in or decorative weapon mode, check it in Activate later
sub_set_built_in_weapons.Activate( ed, data, sprite )
Case functionMenuSub[MENU_MODE_SHIP][MENU_SUBFUNCTION_SHIP_BUILTINHULLMODS] 'built-in hullmods
sub_set_built_in_hullmods.Activate( ed, data, sprite )
Case functionMenuSub[MENU_MODE_SHIP][MENU_SUBFUNCTION_SHIP_BUILTINWINGS] 'built-in wings
sub_set_built_in_wings.Activate( ed, data, sprite )
Case functionMenuSub[MENU_MODE_SHIP][MENU_SUBFUNCTION_SHIP_ENGINE] 'engine slots
sub_set_engine_slots.Activate( ed, data, sprite )
Case functionMenuSub[MENU_MODE_SHIP][MENU_SUBFUNCTION_SHIP_LAUNCHBAYS] 'launch bays
sub_set_launchbays.Activate( ed, data, sprite )
Case functionMenuSub[MENU_MODE_SHIP][MENU_SUBFUNCTION_SHIP_PREVIEW] 'preview
sub_preview_all.Activate( ed, data, sprite )
Case functionMenuSub[MENU_MODE_SHIP][MENU_SUBFUNCTION_SHIP_MORE] 'show more
cycle_show_more()
Case functionMenu[MENU_FUNCTION_DETAILS] 'string edit
sub_string_data.Activate( ed, data, sprite )
Default
hit = False
EndSelect
Case "variant"
Select EventSource()
Case functionMenuSub[MENU_MODE_VARIANT][MENU_SUBFUNCTION_VARIANT_WINGS] 'variant wings
sub_set_variant_wings.Activate( ed, data, sprite )
Case functionMenuSub[MENU_MODE_VARIANT][MENU_SUBFUNCTION_VARIANT_STRIPALL]
load_variant_data( ed, data, sprite, True ) 'strip all
Case functionMenu[MENU_FUNCTION_DETAILS]
sub_string_data.Activate( ed, data, sprite ) 'string edit
Case functionMenuSub[MENU_MODE_VARIANT][MENU_SUBFUNCTION_VARIANT_MORE] 'show more
cycle_show_more()
Default
hit = False
EndSelect
Case "skin"
Select EventSource()
Case functionMenu[MENU_FUNCTION_EXIT] 'exit
sub_set_skin.Escape( ed, data, sprite )
Case functionMenuSub[MENU_MODE_SKIN][MENU_SUBFUNCTION_SKIN_CHANGEREMOVE_WEAPONSLOTS]
sub_set_skin.SetEditorMode( ed, data, sprite, "changeremove_weaponslots" )
Case functionMenuSub[MENU_MODE_SKIN][MENU_SUBFUNCTION_SKIN_ADDREMOVE_BUILTIN_WEAPONS]
sub_set_skin.SetEditorMode( ed, data, sprite, "addremove_builtin_weapons" )
Case functionMenuSub[MENU_MODE_SKIN][MENU_SUBFUNCTION_SKIN_CHANGEREMOVE_ENGINES]
sub_set_skin.SetEditorMode( ed, data, sprite, "changeremove_engines" )
Case functionMenuSub[MENU_MODE_SKIN][MENU_SUBFUNCTION_SKIN_ADDREMOVE_BUILTIN_HULLMODS]
sub_set_skin.SetEditorMode( ed, data, sprite, "addremove_hullmods" )
Case functionMenuSub[MENU_MODE_SKIN][MENU_SUBFUNCTION_SKIN_ADDREMOVE_HINTS]
sub_set_skin.SetEditorMode( ed, data, sprite, "addremove_hints" )
Case functionMenuSub[MENU_MODE_SKIN][MENU_SUBFUNCTION_SKIN_MORE]
cycle_show_more()
Case functionMenu[MENU_FUNCTION_DETAILS]
sub_string_data.Activate( ed, data, sprite ) ' string edit
Default
hit = False
EndSelect
Case "weapon"
Select EventSource()
Case functionMenu[MENU_FUNCTION_DETAILS]
sub_string_data.Activate( ed, data, sprite ) 'string edit
Default
hit = False
EndSelect
Default
hit = False
EndSelect
updata_weapondrawermenu(ed)
Return hit
EndFunction
'-----------------------
Function update_menu()
If mainMenuNeedUpdate
UpdateWindowMenu(MainWindow)
mainMenuNeedUpdate = False
EndIf
End Function
Function check_zoom_and_pan(ed:TEditor, data:TData, sprite:TSprite)
Select EventID()
Case EVENT_MOUSEDOWN, EVENT_MOUSEUP, EVENT_MOUSEMOVE
Select ModKeyAndMouseKey
Case 32 '(MODIFIER_RMOUSE)
'pan CONTROL
Select EventID()
Case EVENT_MOUSEDOWN
ed.pan_start_x = sprite.pan_x
ed.pan_start_y = sprite.pan_y
ed.pan_start_mouse_x = MouseX
ed.pan_start_mouse_y = MouseY
Case EVENT_MOUSEMOVE
sprite.pan_x = ed.pan_start_x + (MouseX - ed.pan_start_mouse_x)
sprite.pan_y = ed.pan_start_y + (MouseY - ed.pan_start_mouse_y)
EndSelect
EndSelect
Case EVENT_MOUSEWHEEL