-
Notifications
You must be signed in to change notification settings - Fork 19
/
Spatial.gd
892 lines (700 loc) · 31.6 KB
/
Spatial.gd
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
extends Spatial
var server := UDPServer.new()
var peers = []
var map_id:int = 0
var map_is_open: bool
var compass_is_top_right: bool
var edit_panel_open: bool = false
# This is the path to the texture that will be used for the next created 3d-path
# object or icon object in the UI
var next_texture_path: String = ""
# A pointer to the path object that any new nodes should be appended to. If
# the value is null then a new path will be created the next time a path point
# will be created.
var currently_active_path = null
var currently_active_path_2d = null
var map_was_open = false
# Player Position as accurate to Guild Wars 2
var player_position := Vector3(0,0,0)
# Player Position as accurate to Godot (z value sign is flipped)
var correct_player_position := Vector3(0,0,0)
var compass_height: int = 0;
var compass_width: int = 0;
# A temporary setting able to be configured by the user. It is used to allow
# for faster trail mesh generation. The higher the value the fewer samples are
# taken for the MeshCSG leading to an overall lower number of polygons.
var path_resolution = 1
# Variables that store opposit corners of the compass
var compass_corner1
var compass_corner2
#x11 fg and window id
var x11_fg: X11_FG
var taco_parser: TacoParser
var x11_window_id_burrito: int
var is_transient:bool = false
# Variables that store informations about ui scaling
# The ui-size as read from the link can have the values [0=small; 1=normal; 2=large; 3=larger]
var ui_size: int = 1
# This dictionary holds the left and right margin for the main button for every ui-scale
const button_margin = {
0: {"left": 292, "right": 318}, # small
1: {"left": 323, "right": 352}, # normal
2: {"left": 361, "right": 394}, # large
3: {"left": 395, "right": 431} # larger
}
const minimap_scale = {
0: {"offset": 32, "factor": 0.9}, # small
1: {"offset": 36, "factor": 1}, # normal
2: {"offset": 40, "factor": 1.11}, # large
3: {"offset": 44, "factor": 1.22} # larger
}
# Called when the node enters the scene tree for the first time.
func _ready():
get_tree().get_root().set_transparent_background(true)
x11_fg = X11_FG.new()
taco_parser = TacoParser.new()
x11_window_id_burrito = OS.get_native_handle(OS.WINDOW_HANDLE)
OS.window_maximized = false
# Start off with a small size before GW2 client is up
if Settings.override_size_enabled:
OS.window_size = Vector2(Settings.override_size_width, Settings.override_size_height)
else:
OS.window_size = Vector2(Settings.minimum_width, Settings.minimum_height)
# Postion at top left corner
OS.set_window_position(Vector2(0,0))
set_minimal_mouse_block()
server.listen(4242)
if (Settings.burrito_link_auto_launch_enabled):
launch_burrito_link()
################################################################################
# show_error
#
# This function prints a user error out. Currently it prints to stdout but may
# one day be shown to the user.
################################################################################
func show_user_error(error_string: String):
print(error_string)
# The process id of burrito link if it is launched automatically by burrito
var burrito_link_process_id = 0
################################################################################
# launch_burrito_link
#
# This function launches the burrito link binary using the values for it that
# are saved in "settings".
################################################################################
func launch_burrito_link():
for env_arg in Settings.burrito_link_env_args.split("\n"):
env_arg = env_arg.trim_prefix("export ")
var key_values = env_arg.split('=', true, 1)
if len(key_values) != 2:
show_user_error("Invalid burrito_link environment arg: " + env_arg)
return
var key = key_values[0]
var value = key_values[1].trim_prefix('"').trim_suffix('"')
OS.set_environment(key, value)
# Launch burrito link with a 2 hour timeout
# If burrito crashes then burrito_link will automatically exit at the timeout.
# If burrito does not crash and the timeout expires then burrito will relaunch burrito_link automatically
burrito_link_process_id = OS.execute(Settings.burrito_link_wine_path, ["burrito_link/burrito_link.exe", "--timeout", "7200"], false)
func close_burrito_link():
if (burrito_link_process_id != 0):
OS.kill(burrito_link_process_id)
burrito_link_process_id = 0
func exit_burrito():
if Settings.burrito_link_auto_launch_enabled:
close_burrito_link()
get_tree().quit()
func set_minimal_mouse_block():
var menu_button = $Control/GlobalMenuButton
var top_corner = menu_button.get_position()
var bottom_corner = menu_button.get_position() + menu_button.get_size()
if self.edit_panel_open:
var editor_panel = $Control/GlobalMenuButton/EditorQuckPanel
bottom_corner = menu_button.get_position() + editor_panel.get_position() + editor_panel.get_size()
var clickthrough: PoolVector2Array = [
Vector2(top_corner.x ,top_corner.y),
Vector2(bottom_corner.x, top_corner.y),
Vector2(bottom_corner.x,bottom_corner.y),
Vector2(top_corner.x ,bottom_corner.y)
]
OS.set_window_mouse_passthrough(clickthrough)
$Control/Border.hide()
func set_maximal_mouse_block():
OS.set_window_mouse_passthrough([])
$Control/Border.show()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
#OS.window_position = Vector2(1920, 0) # TODO: This does not seem to work
#OS.set_window_position(Vector2(1920,0))
#print(OS.window_position)
server.poll() # Important
if server.is_connection_available():
var peer: PacketPeerUDP = server.take_connection()
print("accepted peer: %s:%s" % [peer.get_packet_ip(), peer.get_packet_port()])
peers.append(peer)
for i in range(0, peers.size()):
var peer: PacketPeerUDP = peers[i]
for j in range(0, peer.get_available_packet_count()):
var spb := StreamPeerBuffer.new()
spb.data_array = peer.get_packet()
var packet_type:int = spb.get_8()
if packet_type == 1:
decode_frame_packet(spb)
elif packet_type == 2:
decode_context_packet(spb)
elif packet_type == 3:
decode_timeout_packet(spb)
return
func decode_frame_packet(spb: StreamPeerBuffer):
# Extract the position of the camera
var camera_position = Vector3(
spb.get_float(),
spb.get_float(),
spb.get_float()
)
# Extract the rotation of the camera in the form of a normal vector
var camera_facing = Vector3(
spb.get_float(),
spb.get_float(),
spb.get_float()
)
# Extract the position of the player's foot
self.player_position = Vector3(
spb.get_float(),
spb.get_float(),
spb.get_float()
)
self.correct_player_position = Vector3(player_position.x, player_position.y, -player_position.z)
if $Control/Position.visible:
$Control/Position.text = "X " + str(player_position.x) + " Y " + str(player_position.y) + " Z " + str(-player_position.z)
var map_offset = Vector2(
spb.get_float(),
spb.get_float()
)
var map_scale: float = spb.get_float()
if map_scale == 0: #fixing a divide by zero error that occurs when the game loads
map_scale = 0.000001
var map_rotation: float = spb.get_float()
var ui_flags: int = spb.get_32()
map_is_open = (ui_flags & 0x01) == 0x01;
compass_is_top_right = (ui_flags & 0x02) == 0x02;
var compass_rotation_is_enabled: bool = (ui_flags & 0x04) == 0x04;
var game_is_focused: bool = (ui_flags & 0x08) == 0x08;
var in_competitive_game_mode: bool = (ui_flags & 0x10) == 0x10;
var chatbox_has_focus: bool = (ui_flags & 0x20) == 0x20;
var in_combat: bool = (ui_flags & 0x40) == 0x40;
var unchecked_flag = (ui_flags & 0xFFFFFF80) != 0x00000000;
if map_is_open != map_was_open:
$Paths.visible = !map_is_open
$Icons.visible = !map_is_open
reset_minimap_masks()
map_was_open = map_is_open
if unchecked_flag:
print("Unchecked Flag", (ui_flags & 0xFFFFFF80))
# Position the camera in the same location as it in in-game
$CameraMount.translation.x = camera_position.x
$CameraMount.translation.y = camera_position.y
$CameraMount.translation.z = -camera_position.z
# Orent the camera in the same rotation as it is facing in game
$CameraMount/Camera.rotation.x = asin(camera_facing.y)
$CameraMount.rotation.y = -atan2(camera_facing.x, camera_facing.z)
# in-engine units are meters
# in-game units are inches
# continent map units are 24inches to 1 condinenet map unit
# 1 meter = 39.37008 inches
# 39.37008 / 24 = 1.64042
# meters -> 24 inches
# Info gathered from https://wiki.guildwars2.com/wiki/API:Maps
var map_object_scaling = 1.64042/map_scale
var map_size = get_viewport().size
var map_corner = Vector2(0, 0)
if (!map_is_open):
map_size = Vector2(compass_width, compass_height)
if !compass_is_top_right:
map_corner = get_viewport().size - Vector2(compass_width, compass_height + self.minimap_scale[self.ui_size]["offset"])
else:
map_corner = Vector2(get_viewport().size.x - compass_width, 0)
var player_map_position: Vector2 = Vector2(player_position.x, -player_position.z)*map_object_scaling
var delta_position = Vector2(0,0)
if (map_rotation != 0 && !map_is_open):
var pivot = Vector2(0,0)
var radians = map_rotation
var cosTheta = cos(radians)
var sinTheta = sin(radians)
var x = (cosTheta * (player_map_position.x - pivot.x) - sinTheta * (player_map_position.y - pivot.y) + pivot.x);
var y = (sinTheta * (player_map_position.x - pivot.x) + cosTheta * (player_map_position.y - pivot.y) + pivot.y);
delta_position = player_map_position - Vector2(x, y);
#print(map_rotation)
$Control/MiniMap.rotation = map_rotation
else:
$Control/MiniMap.rotation = 0
var map_midpoint = map_size/2 + map_corner;
$Control/MiniMap.scale=Vector2(map_object_scaling, map_object_scaling)
var map_translation = map_offset
$Control/MiniMap.position = (map_translation / map_scale) + map_midpoint - player_map_position + delta_position
var new_feet_location = Vector3(player_position.x, player_position.y, -player_position.z)
$FeetLocation.translation = new_feet_location
func decode_context_packet(spb: StreamPeerBuffer):
compass_width = spb.get_16()
compass_height = spb.get_16()
var old_map_id = self.map_id
self.map_id = spb.get_32()
var x11_window_id_gw2 = spb.get_32()
if !is_transient:
is_transient = x11_fg.set_transient_for(x11_window_id_burrito, x11_window_id_gw2)
var size = Vector2(Settings.minimum_width, Settings.minimum_height)
if Settings.override_size_enabled:
size.x = Settings.override_size_width
size.y = Settings.override_size_height
else:
var size_tuple = x11_fg.get_window_geometry(x11_window_id_gw2)
size.x = size_tuple[0]
size.y = size_tuple[1]
if size.x < Settings.minimum_width:
size.x = Settings.minimum_width
if size.y < Settings.minimum_height:
size.y = Settings.minimum_height
OS.window_size = size
var identity_length: int = spb.get_32()
var identity_str = spb.get_utf8_string(identity_length)
var identity = JSON.parse(identity_str).result
# FOV Calculations
# The minimum value on the FOV slider gives a float value in this field of 0.436
# The maximum value on the FOV slider gives a float value in this field of 1.222
# According to https://thatshaman.com/tools/fov/ the FOV range is (25 -> 70)
# This function maps a value between 0.436 and 1.222 to a value between 25 and 70
$CameraMount/Camera.fov = (((identity["fov"] - 0.436) / 0.786) * 45) + 25
# TODO: after looking back at this it has become obvious this is just degrees
# vs radians. 70deg = 1.22173rad and 25deg = 0.4363323rad. We should redo
# this to just be a radian to degree conversion.
# Calculations to dynamically place the main icon/button
self.ui_size = int(identity["uisz"])
# If the value is not part of the dictionary use the "normal" size.
if !self.button_margin.has(self.ui_size):
self.ui_size = 1
$Control/GlobalMenuButton.margin_left = self.button_margin[self.ui_size]["left"]
$Control/GlobalMenuButton.margin_right = self.button_margin[self.ui_size]["right"]
if !is_any_dialog_visible():
set_minimal_mouse_block()
compass_width = compass_width * self.minimap_scale[self.ui_size]["factor"]
compass_height = compass_height * self.minimap_scale[self.ui_size]["factor"]
if self.map_id != old_map_id:
print("New Map")
print("Saving Old Map")
self.markerdata[str(old_map_id)] = data_from_renderview()
print("Loading New Map")
gen_map_markers()
# TODO move this to reset_minimap_masks
for child in $Paths.get_children():
child.get_node("MeshInstance").material_override.set_shader_param("map_size", Vector2(compass_width, compass_height))
# TODO move this to reset_minimap_masks
for icon in $Icons.get_children():
icon.material_override.set_shader_param("map_size", Vector2(compass_width, compass_height))
reset_minimap_masks()
func decode_timeout_packet(spb: StreamPeerBuffer):
if Settings.burrito_link_auto_launch_enabled:
print("Link Timeout Reached, should restart link if started by burrito automatically")
close_burrito_link()
launch_burrito_link()
func reset_minimap_masks():
var viewport_size = get_viewport().size
compass_corner1 = Vector2(0, 0)
compass_corner2 = viewport_size
if !map_is_open && !compass_is_top_right:
compass_corner1 = Vector2(viewport_size.x-compass_width, self.minimap_scale[self.ui_size]["offset"])
compass_corner2 = compass_corner1 + Vector2(compass_width, compass_height)
elif !map_is_open && compass_is_top_right:
compass_corner1 = viewport_size - Vector2(compass_width, compass_height)
compass_corner2 = compass_corner1 + Vector2(compass_width, compass_height)
for minimap_path in $Control/MiniMap.get_children():
minimap_path.material.set_shader_param("minimap_corner", compass_corner1)
minimap_path.material.set_shader_param("minimap_corner2", compass_corner2)
var markerdata = {}
var marker_file_path = ""
func load_taco_markers(marker_json_file):
self.marker_file_path = marker_json_file
if is_xml_file(marker_json_file):
print("Loading XML file from path ", marker_json_file)
var parsed_taco_tuple = taco_parser.parse_taco_xml(marker_json_file)
var json_payload = parsed_taco_tuple[0]
var error_message = parsed_taco_tuple[1]
if error_message != "":
print("XML parsing failed with error message: ", error_message)
self.markerdata = JSON.parse(json_payload).result
else:
print("Loading Json file from path ", marker_json_file)
var file = File.new()
file.open(marker_json_file, file.READ)
var text = file.get_as_text()
self.markerdata = JSON.parse(text).result
relative_textures_to_absolute_textures(marker_file_path.get_base_dir())
gen_map_markers()
func is_xml_file(input_file):
return input_file.split(".")[-1] == "xml"
func relative_textures_to_absolute_textures(marker_file_dir):
for map in markerdata:
for icon in markerdata[map]["icons"]:
if !icon["texture"].is_abs_path():
icon["texture"] = marker_file_dir + "/" + icon["texture"]
#print("ABS", icon["texture"])
for path in markerdata[map]["paths"]:
if !path["texture"].is_abs_path():
path["texture"] = marker_file_dir + "/" + path["texture"]
var route_scene = load("res://Route.tscn")
var icon_scene = load("res://Icon.tscn")
var path2d_scene = load("res://Route2D.tscn")
var gizmo_scene = load("res://Gizmo/PointEdit.tscn")
##########Gizmo Stuff###########
# How long the ray to search for 3D clickable object should be.
# Shorter is faster but cannot click thing far away.
# Longer is slower but can click things farther away.
var ray_length = 1000
# The last object that was hovered by the mouse. May be null, may be a dangling
# reference to a non-existant node.
var last_hover = null
# The last object that was selected by a click. May be null, may be a dangling
# reference to a non-existant node.
var last_selected = null
################################################################################
# Hand the mouse input of clicking and hovering over an object
################################################################################
func _unhandled_input(event):
# If the left mouse button is clicked.
if event is InputEventMouseButton and event.pressed and event.button_index == 1:
# Emit a ray from the mouse position to see if it intersects with any
# clickable items.
var camera = $CameraMount/Camera
var start_coordinate = camera.project_ray_origin(event.position)
var end_coordinate = start_coordinate + camera.project_ray_normal(event.position) * self.ray_length
var space_state = get_world().direct_space_state
var result = space_state.intersect_ray(start_coordinate, end_coordinate)
# If if the ray intersects with a node then the mouse successfully
# clicked something.
if result:
if is_instance_valid(self.last_selected) and self.last_selected.has_method("clear_selection") and self.last_selected != result["collider"].get_parent():
last_selected.clear_selection()
# Call the select() function on the object that was clicked
result["collider"].select(camera, event)
self.last_selected = result["collider"].get_parent()
else:
if is_instance_valid(self.last_selected) and self.last_selected.has_method("clear_selection"):
last_selected.clear_selection()
self.last_selected = null
# If the mouse is moved.
if event is InputEventMouseMotion:
# Emit a ray from the mouse position to see if it intersects with any
# clickable items.
var camera = $CameraMount/Camera
var start_coordinate = camera.project_ray_origin(event.position)
var end_coordinate = start_coordinate + camera.project_ray_normal(event.position) * self.ray_length
var space_state = get_world().direct_space_state
var result = space_state.intersect_ray(start_coordinate, end_coordinate)
# If the ray intersects with a node then the mouse is visually hovering
# over something.
if result:
# If there is something that is currently hovered then unhover it
if is_instance_valid(self.last_hover) and self.last_hover.has_method("unhover") and self.last_hover != result["collider"]:
self.last_hover.unhover()
# Call the hover function on the new object that is being hovered
result["collider"].hover()
self.last_hover = result["collider"]
# If nothing is hovere then try to unhover the object and set the
# currently hovered object to null.
else:
if is_instance_valid(self.last_hover) and self.last_hover.has_method("unhover"):
self.last_hover.unhover()
self.last_hover = null
################################################################################
#
################################################################################
onready var icons = $Icons
onready var paths = $Paths
onready var minimap = $Control/MiniMap
func gen_map_markers():
# Clear all the rendered assets to mak way for the new ones
for path in paths.get_children():
path.queue_free()
for path2d in minimap.get_children():
path2d.queue_free()
for icon in icons.get_children():
icon.queue_free()
# Load the data from the markers
if str(map_id) in markerdata:
var map_markerdata = markerdata[str(map_id)]
for path in map_markerdata["paths"]:
gen_new_path(path["points"], path["texture"])
for icon in map_markerdata["icons"]:
var position = Vector3(icon["position"][0], icon["position"][1], icon["position"][2])
gen_new_icon(position, icon["texture"])
func gen_new_path(points: Array, texture_path: String):
var points_2d: PoolVector2Array = []
# Create the texture to use from an image file
# TODO: We want to be able to cache this data so that if a texture is used
# by multiple objects we only need to keep ony copy of it in memory. #22.
# TODO: We want to have two copies of each texture in memory one for 2D
# which does not use srgb to render properly, and one for 3D which forces
# srgb to render properly. Issue #23.
var texture_file = File.new()
var image = Image.new()
if !texture_file.file_exists(texture_path):
print("Warning: File does not exist: ", texture_path)
texture_file.open(texture_path, File.READ)
image.load_png_from_buffer(texture_file.get_buffer(texture_file.get_len()))
texture_file.close()
image.lock()
var texture = ImageTexture.new()
texture.storage = ImageTexture.STORAGE_COMPRESS_LOSSLESS
texture.create_from_image(image, 22)
# Create a new 3D route
var new_route = route_scene.instance()
# var new_curve = Curve3D.new()
# for point in points:
# new_curve.add_point(Vector3(point[0], point[1], -point[2]))
# points_2d.append(Vector2(point[0], -point[2]))
# new_path.curve = new_curve
new_route.texture_path = texture_path # Save the location of the image for later
#path_3d_markers.append(new_path)
var points_3d := PoolVector3Array()
for point in points:
points_3d.append(Vector3(point[0], point[1], -point[2]))
new_route.create_mesh(points_3d)
new_route.set_texture(texture)
paths.add_child(new_route)
for point in points:
points_2d.append(Vector2(point[0], -point[2]))
# Create a new 2D Path
var new_2d_path = path2d_scene.instance()
new_2d_path.points = points_2d
new_2d_path.texture = texture
minimap.add_child(new_2d_path)
self.currently_active_path = new_route
self.currently_active_path_2d = new_2d_path
################################################################################
#
################################################################################
func gen_new_icon(position: Vector3, texture_path: String):
position.z = -position.z
var new_icon = icon_scene.instance()
new_icon.translation = position
new_icon.set_icon_image(texture_path)
#icon_markers.append(new_icon)
icons.add_child(new_icon)
# This function take all of the currently rendered objects and converts it into
# the data format that is saved/loaded from.
func data_from_renderview():
var icons_data = []
var paths_data = []
for icon in $Icons.get_children():
icons_data.append({
"position": [icon.translation.x, icon.translation.y, -icon.translation.z],
"texture": icon.texture_path
})
for path in $Paths.get_children():
#print(path)
var points = []
for point in range(path.get_point_count()):
var point_position:Vector3 = path.get_point_position(point)
points.append([point_position.x, point_position.y, -point_position.z])
paths_data.append({
"points": points,
"texture": path.texture_path
})
var data_out = {"icons": icons_data, "paths": paths_data}
return data_out
func _on_main_menu_toggle_pressed():
$Control/Dialogs/MainMenu.show()
set_maximal_mouse_block()
func _on_FileDialog_file_selected(path):
load_taco_markers(path)
################################################################################
# The adjust nodes button creates handles at all the node points to allow for
# editing of them via in-game interface. (Nodes can only be edited if the input
# passthrough is blocked, thus preventing any camera movement or player movement
################################################################################
var adjusting = false
func _on_AdjustNodesButton_pressed():
$Control/Dialogs/NodeEditorDialog.show()
set_maximal_mouse_block()
gen_adjustment_nodes()
func gen_adjustment_nodes():
for index in range(self.paths.get_child_count()):
var route = self.paths.get_child(index)
var path2d = self.minimap.get_child(index)
#var curve: Curve3D = path.curve
for i in range(route.get_point_count()):
var gizmo_position = route.get_point_position(i)
# Simplistic cull to prevent nodes that are too far away to be
# visible from being created. Additional work can be done here
# if this is not enough of an optimization in the future.
if (gizmo_position.distance_squared_to(self.correct_player_position) > 10000):
continue
var new_gizmo = gizmo_scene.instance()
new_gizmo.translation = gizmo_position
new_gizmo.link_point("path", route, path2d, i)
new_gizmo.connect("selected", self, "on_gizmo_selected")
new_gizmo.connect("deselected", self, "on_gizmo_deselected")
$Gizmos.add_child(new_gizmo)
for index in range(self.icons.get_child_count()):
var icon = self.icons.get_child(index)
var new_gizmo = gizmo_scene.instance()
new_gizmo.translation = icon.translation
new_gizmo.link_point("icon", icon)
new_gizmo.connect("selected", self, "on_gizmo_selected")
new_gizmo.connect("deselected", self, "on_gizmo_deselected")
$Gizmos.add_child(new_gizmo)
var currently_selected_node = null
func on_gizmo_selected(object):
self.currently_selected_node = object
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/DeleteNode.disabled = false
# Only enable these buttons if the object selected is a point on the path not an icon
if object.point_type == "path":
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/NewNodeAfter.disabled = false
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/ReversePathDirection.disabled = false
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/SetActivePath.disabled = false
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/SnapSelectedToPlayer.disabled = false
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/XZSnapToPlayer.disabled = false
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/YSnapToPlayer.disabled = false
func on_gizmo_deselected(object):
self.currently_selected_node = null
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/DeleteNode.disabled = true
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/NewNodeAfter.disabled = true
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/SnapSelectedToPlayer.disabled = true
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/XZSnapToPlayer.disabled = true
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/YSnapToPlayer.disabled = true
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/SetActivePath.disabled = true
$Control/Dialogs/NodeEditorDialog/ScrollContainer/VBoxContainer/ReversePathDirection.disabled = true
func clear_adjustment_nodes():
for child in $Gizmos.get_children():
$Gizmos.remove_child(child)
child.queue_free()
func is_any_dialog_visible():
for dialog in $Control/Dialogs.get_children():
if dialog.visible:
return true
return false
func _on_Dialog_hide():
if !is_any_dialog_visible():
set_minimal_mouse_block()
func _on_LoadPath_pressed():
var open_dialog: FileDialog = $Control/Dialogs/FileDialog
open_dialog.show()
open_dialog.set_current_dir(open_dialog.current_dir)
func _on_RangesButton_pressed():
$Control/Dialogs/RangesDialog.show()
func _on_PathResolution_value_changed(value):
path_resolution = value
for path in $Paths.get_children():
var csg:CSGPolygon = path.get_node("CSGPolygon")
csg.path_interval = path_resolution
csg.material.set_shader_param("interval", path_resolution)
func _on_CloseEditorQuickPanel_pressed():
$Control/GlobalMenuButton/EditorQuckPanel.hide()
edit_panel_open = false
func _on_OpenEditorQuickPanel_pressed():
$Control/GlobalMenuButton/EditorQuckPanel.show()
edit_panel_open = true
func _on_ChangeTexture_pressed():
$Control/Dialogs/TexturePathOpen.show()
var texture_path_dialog:FileDialog = $Control/Dialogs/TexturePathOpen
texture_path_dialog.set_current_dir(texture_path_dialog.current_dir)
set_maximal_mouse_block()
################################################################################
# Set the file that will be used to create a new path or icon when a new path
# or icon is created.
################################################################################
func _on_TexturePathOpen_file_selected(path):
self.next_texture_path = path
################################################################################
# Null out the currently active path so that a new one is created the next time
# a path node is created.
################################################################################
func _on_NewPath_pressed():
self.currently_active_path = null
################################################################################
# Create a new icon and give it the texture
################################################################################
func _on_NewIcon_pressed():
gen_new_icon(self.player_position, self.next_texture_path)
# A new path point is created
func _on_NewPathPoint_pressed():
if self.currently_active_path == null:
gen_new_path([self.player_position], self.next_texture_path)
else:
var z_accurate_player_position = player_position
z_accurate_player_position.z = -z_accurate_player_position.z
self.currently_active_path.add_point(z_accurate_player_position)
self.currently_active_path_2d.add_point(Vector2(self.player_position.x, -self.player_position.z))
################################################################################
# open the save dialog window. When a path is selected
# _on_SaveDialog_file_selected() will be called with the user specified path.
################################################################################
func _on_SavePath_pressed():
$Control/Dialogs/SaveDialog.show()
################################################################################
# Save the current markers to a file, this includes all markers in memory not
# just the markers on the current map.
################################################################################
func _on_SaveDialog_file_selected(path):
self.markerdata[str(self.map_id)] = data_from_renderview()
var save_game = File.new()
save_game.open(path, File.WRITE)
save_game.store_string(JSON.print(self.markerdata))
func _on_NodeEditorDialog_hide():
self.currently_selected_node = null
clear_adjustment_nodes()
_on_Dialog_hide()
func _on_DeleteNode_pressed():
if self.currently_selected_node.point_type == "icon":
self.currently_selected_node.object_link.get_parent().remove_child(self.currently_selected_node.object_link)
self.currently_selected_node.object_link.queue_free()
elif self.currently_selected_node.point_type == "path":
var path = self.currently_selected_node.object_link
var path2d = self.currently_selected_node.object_2d_link
var index = self.currently_selected_node.object_index
path.remove_point(index)
path2d.remove_point(index)
clear_adjustment_nodes()
gen_adjustment_nodes()
on_gizmo_deselected(self.currently_selected_node)
func _on_NewNodeAfter_pressed():
if self.currently_selected_node.point_type == "icon":
print("Warning: Cannot add node to icon")
elif self.currently_selected_node.point_type == "path":
print("insert path node")
var path = self.currently_selected_node.object_link
var path2d = self.currently_selected_node.object_2d_link
var index = self.currently_selected_node.object_index
var start = path.get_point_position(index)
var midpoint = self.player_position
midpoint.z = -midpoint.z
if path.get_point_count() > index+1:
var end = path.get_point_position(index+1)
midpoint = ((start-end)/2) + end
path.add_point(midpoint, index+1)
path2d.add_point(Vector2(midpoint.x, midpoint.z), index+1)
clear_adjustment_nodes()
gen_adjustment_nodes()
on_gizmo_deselected(self.currently_selected_node)
func _on_XZSnapToPlayer_pressed():
self.currently_selected_node.translation.x = self.player_position.x
self.currently_selected_node.translation.z = -self.player_position.z
func _on_YSnapToPlayer_pressed():
self.currently_selected_node.translation.y = self.player_position.y
func _on_SnapSelectedToPlayer_pressed():
self.currently_selected_node.translation.x = self.player_position.x
self.currently_selected_node.translation.z = -self.player_position.z
self.currently_selected_node.translation.y = self.player_position.y
func _on_SetActivePath_pressed():
if self.currently_selected_node.point_type == "icon":
print("Warning: Cannot set icon as active path")
elif self.currently_selected_node.point_type == "path":
self.currently_active_path = self.currently_selected_node.object_link
self.currently_active_path_2d = self.currently_selected_node.object_2d_link
func _on_ReversePathDirection_pressed():
self.currently_selected_node.object_link.reverse()
func _on_ExitButton_pressed():
exit_burrito()
func _on_Settings_pressed():
var settings_dialog: WindowDialog = $Control/Dialogs/SettingsDialog
settings_dialog.load_settings()
settings_dialog.show()