From 33c496e9bde738a18727df3317b55576d7889117 Mon Sep 17 00:00:00 2001 From: klingbolt Date: Fri, 17 Nov 2023 21:07:32 -0500 Subject: [PATCH 01/10] Updated generated code to reflect proto changes. Slight change to visibility because of the changes made --- Icon.gd | 1 + Route.gd | 1 + Spatial.gd | 6 +- waypoint.gd | 243 +++++++++++++++++++--------------------------------- 4 files changed, 96 insertions(+), 155 deletions(-) diff --git a/Icon.gd b/Icon.gd index 1cd9164c..cc171b55 100644 --- a/Icon.gd +++ b/Icon.gd @@ -4,6 +4,7 @@ const Waypoint = preload("res://waypoint.gd") var texture_path var waypoint: Waypoint.Icon +var category: TreeItem func set_icon_image(texture_path: String): self.texture_path = texture_path diff --git a/Route.gd b/Route.gd index 392b2ffd..24717e1e 100644 --- a/Route.gd +++ b/Route.gd @@ -5,6 +5,7 @@ const Waypoint = preload("res://waypoint.gd") var texture_path var color = Color(0.9, 0.1, 0.1) var waypoint: Waypoint.Trail +var category: TreeItem var point_list := PoolVector3Array() diff --git a/Spatial.gd b/Spatial.gd index 63cc880f..b423f146 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -502,7 +502,7 @@ func _waypoint_categories_to_godot_nodes(item: TreeItem, category, full_category category_item.set_metadata(0, "") print("Category found with no name.") return - category_item.set_text(0, category.get_display_name()) + category_item.set_text(0, category.get_name()) category_item.set_metadata(0, full_category_name) category_item.set_cell_mode(1, TreeItem.CELL_MODE_CHECK) category_item.set_checked(1, Settings.local_category_data.get(full_category_name, {}).get("checked", false)) @@ -564,7 +564,7 @@ func populate_update_dict(category_item: TreeItem, category_visibility_data): #Updates the visibilty of a node and all children. func update_node_visibility(cateogry_data, nodes): for node in nodes.get_children(): - var node_name = node.waypoint.get_category().get_name() + var node_name = node.category.get_metadata(0) if node_name in cateogry_data: if cateogry_data[node_name]: node.visible = true @@ -616,6 +616,7 @@ func gen_new_path(points: Array, texture_path: String, waypoint_trail, category_ new_route.create_mesh(points_3d) new_route.set_texture(texture) new_route.waypoint = waypoint_trail + new_route.category = category_item if category_item != null: new_route.visible = is_category_visible(category_item) else: @@ -643,6 +644,7 @@ func gen_new_icon(position: Vector3, texture_path: String, waypoint_icon, catego new_icon.translation = position new_icon.set_icon_image(texture_path) new_icon.waypoint = waypoint_icon + new_icon.category = category_item if category_item != null: new_icon.visible = is_category_visible(category_item) else: diff --git a/waypoint.gd b/waypoint.gd index 9af1a9f5..d8cfe0f5 100644 --- a/waypoint.gd +++ b/waypoint.gd @@ -708,101 +708,60 @@ class Category: func _init(): var service - _default_visibility = PBField.new("default_visibility", PB_DATA_TYPE.BOOL, PB_RULE.OPTIONAL, 1, true, DEFAULT_VALUES_3[PB_DATA_TYPE.BOOL]) - service = PBServiceField.new() - service.field = _default_visibility - data[_default_visibility.tag] = service - - _display_name = PBField.new("display_name", PB_DATA_TYPE.STRING, PB_RULE.OPTIONAL, 2, true, DEFAULT_VALUES_3[PB_DATA_TYPE.STRING]) - service = PBServiceField.new() - service.field = _display_name - data[_display_name.tag] = service - - _is_separator = PBField.new("is_separator", PB_DATA_TYPE.BOOL, PB_RULE.OPTIONAL, 3, true, DEFAULT_VALUES_3[PB_DATA_TYPE.BOOL]) - service = PBServiceField.new() - service.field = _is_separator - data[_is_separator.tag] = service - - _name = PBField.new("name", PB_DATA_TYPE.STRING, PB_RULE.OPTIONAL, 4, true, DEFAULT_VALUES_3[PB_DATA_TYPE.STRING]) + _name = PBField.new("name", PB_DATA_TYPE.STRING, PB_RULE.OPTIONAL, 1, true, DEFAULT_VALUES_3[PB_DATA_TYPE.STRING]) service = PBServiceField.new() service.field = _name data[_name.tag] = service - _tip_description = PBField.new("tip_description", PB_DATA_TYPE.STRING, PB_RULE.OPTIONAL, 5, true, DEFAULT_VALUES_3[PB_DATA_TYPE.STRING]) - service = PBServiceField.new() - service.field = _tip_description - data[_tip_description.tag] = service - - _children = PBField.new("children", PB_DATA_TYPE.MESSAGE, PB_RULE.REPEATED, 6, true, []) + _children = PBField.new("children", PB_DATA_TYPE.MESSAGE, PB_RULE.REPEATED, 2, true, []) service = PBServiceField.new() service.field = _children service.func_ref = funcref(self, "add_children") data[_children.tag] = service - _icon = PBField.new("icon", PB_DATA_TYPE.MESSAGE, PB_RULE.REPEATED, 7, true, []) + _icon = PBField.new("icon", PB_DATA_TYPE.MESSAGE, PB_RULE.REPEATED, 3, true, []) service = PBServiceField.new() service.field = _icon service.func_ref = funcref(self, "add_icon") data[_icon.tag] = service - _trail = PBField.new("trail", PB_DATA_TYPE.MESSAGE, PB_RULE.REPEATED, 8, true, []) + _trail = PBField.new("trail", PB_DATA_TYPE.MESSAGE, PB_RULE.REPEATED, 4, true, []) service = PBServiceField.new() service.field = _trail service.func_ref = funcref(self, "add_trail") data[_trail.tag] = service + _is_separator = PBField.new("is_separator", PB_DATA_TYPE.BOOL, PB_RULE.OPTIONAL, 5, true, DEFAULT_VALUES_3[PB_DATA_TYPE.BOOL]) + service = PBServiceField.new() + service.field = _is_separator + data[_is_separator.tag] = service + + _default_visibility = PBField.new("default_visibility", PB_DATA_TYPE.BOOL, PB_RULE.OPTIONAL, 6, true, DEFAULT_VALUES_3[PB_DATA_TYPE.BOOL]) + service = PBServiceField.new() + service.field = _default_visibility + data[_default_visibility.tag] = service + + _tip_description = PBField.new("tip_description", PB_DATA_TYPE.STRING, PB_RULE.OPTIONAL, 7, true, DEFAULT_VALUES_3[PB_DATA_TYPE.STRING]) + service = PBServiceField.new() + service.field = _tip_description + data[_tip_description.tag] = service + var data = {} - var _default_visibility: PBField - func get_default_visibility() -> bool: - return _default_visibility.value - func clear_default_visibility() -> void: - data[1].state = PB_SERVICE_STATE.UNFILLED - _default_visibility.value = DEFAULT_VALUES_3[PB_DATA_TYPE.BOOL] - func set_default_visibility(value : bool) -> void: - _default_visibility.value = value - - var _display_name: PBField - func get_display_name() -> String: - return _display_name.value - func clear_display_name() -> void: - data[2].state = PB_SERVICE_STATE.UNFILLED - _display_name.value = DEFAULT_VALUES_3[PB_DATA_TYPE.STRING] - func set_display_name(value : String) -> void: - _display_name.value = value - - var _is_separator: PBField - func get_is_separator() -> bool: - return _is_separator.value - func clear_is_separator() -> void: - data[3].state = PB_SERVICE_STATE.UNFILLED - _is_separator.value = DEFAULT_VALUES_3[PB_DATA_TYPE.BOOL] - func set_is_separator(value : bool) -> void: - _is_separator.value = value - var _name: PBField func get_name() -> String: return _name.value func clear_name() -> void: - data[4].state = PB_SERVICE_STATE.UNFILLED + data[1].state = PB_SERVICE_STATE.UNFILLED _name.value = DEFAULT_VALUES_3[PB_DATA_TYPE.STRING] func set_name(value : String) -> void: _name.value = value - var _tip_description: PBField - func get_tip_description() -> String: - return _tip_description.value - func clear_tip_description() -> void: - data[5].state = PB_SERVICE_STATE.UNFILLED - _tip_description.value = DEFAULT_VALUES_3[PB_DATA_TYPE.STRING] - func set_tip_description(value : String) -> void: - _tip_description.value = value - var _children: PBField func get_children() -> Array: return _children.value func clear_children() -> void: - data[6].state = PB_SERVICE_STATE.UNFILLED + data[2].state = PB_SERVICE_STATE.UNFILLED _children.value = [] func add_children() -> Category: var element = Category.new() @@ -813,7 +772,7 @@ class Category: func get_icon() -> Array: return _icon.value func clear_icon() -> void: - data[7].state = PB_SERVICE_STATE.UNFILLED + data[3].state = PB_SERVICE_STATE.UNFILLED _icon.value = [] func add_icon() -> Icon: var element = Icon.new() @@ -824,13 +783,40 @@ class Category: func get_trail() -> Array: return _trail.value func clear_trail() -> void: - data[8].state = PB_SERVICE_STATE.UNFILLED + data[4].state = PB_SERVICE_STATE.UNFILLED _trail.value = [] func add_trail() -> Trail: var element = Trail.new() _trail.value.append(element) return element + var _is_separator: PBField + func get_is_separator() -> bool: + return _is_separator.value + func clear_is_separator() -> void: + data[5].state = PB_SERVICE_STATE.UNFILLED + _is_separator.value = DEFAULT_VALUES_3[PB_DATA_TYPE.BOOL] + func set_is_separator(value : bool) -> void: + _is_separator.value = value + + var _default_visibility: PBField + func get_default_visibility() -> bool: + return _default_visibility.value + func clear_default_visibility() -> void: + data[6].state = PB_SERVICE_STATE.UNFILLED + _default_visibility.value = DEFAULT_VALUES_3[PB_DATA_TYPE.BOOL] + func set_default_visibility(value : bool) -> void: + _default_visibility.value = value + + var _tip_description: PBField + func get_tip_description() -> String: + return _tip_description.value + func clear_tip_description() -> void: + data[7].state = PB_SERVICE_STATE.UNFILLED + _tip_description.value = DEFAULT_VALUES_3[PB_DATA_TYPE.STRING] + func set_tip_description(value : String) -> void: + _tip_description.value = value + func to_string() -> String: return PBPacker.message_to_string(data) @@ -862,10 +848,9 @@ class Icon: service.func_ref = funcref(self, "new_texture_path") data[_texture_path.tag] = service - _guid = PBField.new("guid", PB_DATA_TYPE.MESSAGE, PB_RULE.OPTIONAL, 3, true, DEFAULT_VALUES_3[PB_DATA_TYPE.MESSAGE]) + _guid = PBField.new("guid", PB_DATA_TYPE.BYTES, PB_RULE.OPTIONAL, 3, true, DEFAULT_VALUES_3[PB_DATA_TYPE.BYTES]) service = PBServiceField.new() service.field = _guid - service.func_ref = funcref(self, "new_guid") data[_guid.tag] = service _map_id = PBField.new("map_id", PB_DATA_TYPE.INT32, PB_RULE.OPTIONAL, 4, true, DEFAULT_VALUES_3[PB_DATA_TYPE.INT32]) @@ -916,10 +901,10 @@ class Icon: service.field = _achievement_id data[_achievement_id.tag] = service - _can_fade = PBField.new("can_fade", PB_DATA_TYPE.BOOL, PB_RULE.OPTIONAL, 19, true, DEFAULT_VALUES_3[PB_DATA_TYPE.BOOL]) + _disable_player_cutout = PBField.new("disable_player_cutout", PB_DATA_TYPE.BOOL, PB_RULE.OPTIONAL, 19, true, DEFAULT_VALUES_3[PB_DATA_TYPE.BOOL]) service = PBServiceField.new() - service.field = _can_fade - data[_can_fade.tag] = service + service.field = _disable_player_cutout + data[_disable_player_cutout.tag] = service _minimum_size_on_screen = PBField.new("minimum_size_on_screen", PB_DATA_TYPE.INT32, PB_RULE.OPTIONAL, 20, true, DEFAULT_VALUES_3[PB_DATA_TYPE.INT32]) service = PBServiceField.new() @@ -1028,10 +1013,9 @@ class Icon: service.field = _bhdraft__schedule_duration data[_bhdraft__schedule_duration.tag] = service - _category = PBField.new("category", PB_DATA_TYPE.MESSAGE, PB_RULE.OPTIONAL, 2054, true, DEFAULT_VALUES_3[PB_DATA_TYPE.MESSAGE]) + _category = PBField.new("category", PB_DATA_TYPE.BOOL, PB_RULE.OPTIONAL, 2054, true, DEFAULT_VALUES_3[PB_DATA_TYPE.BOOL]) service = PBServiceField.new() service.field = _category - service.func_ref = funcref(self, "new_category") data[_category.tag] = service var data = {} @@ -1047,14 +1031,13 @@ class Icon: return _texture_path.value var _guid: PBField - func get_guid() -> GUID: + func get_guid() -> PoolByteArray: return _guid.value func clear_guid() -> void: data[3].state = PB_SERVICE_STATE.UNFILLED - _guid.value = DEFAULT_VALUES_3[PB_DATA_TYPE.MESSAGE] - func new_guid() -> GUID: - _guid.value = GUID.new() - return _guid.value + _guid.value = DEFAULT_VALUES_3[PB_DATA_TYPE.BYTES] + func set_guid(value : PoolByteArray) -> void: + _guid.value = value var _map_id: PBField func get_map_id() -> int: @@ -1140,14 +1123,14 @@ class Icon: func set_achievement_id(value : int) -> void: _achievement_id.value = value - var _can_fade: PBField - func get_can_fade() -> bool: - return _can_fade.value - func clear_can_fade() -> void: + var _disable_player_cutout: PBField + func get_disable_player_cutout() -> bool: + return _disable_player_cutout.value + func clear_disable_player_cutout() -> void: data[19].state = PB_SERVICE_STATE.UNFILLED - _can_fade.value = DEFAULT_VALUES_3[PB_DATA_TYPE.BOOL] - func set_can_fade(value : bool) -> void: - _can_fade.value = value + _disable_player_cutout.value = DEFAULT_VALUES_3[PB_DATA_TYPE.BOOL] + func set_disable_player_cutout(value : bool) -> void: + _disable_player_cutout.value = value var _minimum_size_on_screen: PBField func get_minimum_size_on_screen() -> int: @@ -1337,14 +1320,13 @@ class Icon: _bhdraft__schedule_duration.value = value var _category: PBField - func get_category() -> Category: + func get_category() -> bool: return _category.value func clear_category() -> void: data[2054].state = PB_SERVICE_STATE.UNFILLED - _category.value = DEFAULT_VALUES_3[PB_DATA_TYPE.MESSAGE] - func new_category() -> Category: - _category.value = Category.new() - return _category.value + _category.value = DEFAULT_VALUES_3[PB_DATA_TYPE.BOOL] + func set_category(value : bool) -> void: + _category.value = value func to_string() -> String: return PBPacker.message_to_string(data) @@ -1377,10 +1359,9 @@ class Trail: service.func_ref = funcref(self, "new_texture_path") data[_texture_path.tag] = service - _guid = PBField.new("guid", PB_DATA_TYPE.MESSAGE, PB_RULE.OPTIONAL, 3, true, DEFAULT_VALUES_3[PB_DATA_TYPE.MESSAGE]) + _guid = PBField.new("guid", PB_DATA_TYPE.BYTES, PB_RULE.OPTIONAL, 3, true, DEFAULT_VALUES_3[PB_DATA_TYPE.BYTES]) service = PBServiceField.new() service.field = _guid - service.func_ref = funcref(self, "new_guid") data[_guid.tag] = service _map_id = PBField.new("map_id", PB_DATA_TYPE.INT32, PB_RULE.OPTIONAL, 4, true, DEFAULT_VALUES_3[PB_DATA_TYPE.INT32]) @@ -1419,10 +1400,10 @@ class Trail: service.field = _achievement_id data[_achievement_id.tag] = service - _can_fade = PBField.new("can_fade", PB_DATA_TYPE.BOOL, PB_RULE.OPTIONAL, 19, true, DEFAULT_VALUES_3[PB_DATA_TYPE.BOOL]) + _disable_player_cutout = PBField.new("disable_player_cutout", PB_DATA_TYPE.BOOL, PB_RULE.OPTIONAL, 19, true, DEFAULT_VALUES_3[PB_DATA_TYPE.BOOL]) service = PBServiceField.new() - service.field = _can_fade - data[_can_fade.tag] = service + service.field = _disable_player_cutout + data[_disable_player_cutout.tag] = service _is_wall = PBField.new("is_wall", PB_DATA_TYPE.BOOL, PB_RULE.OPTIONAL, 20, true, DEFAULT_VALUES_3[PB_DATA_TYPE.BOOL]) service = PBServiceField.new() @@ -1511,10 +1492,9 @@ class Trail: service.field = _bhdraft__schedule_duration data[_bhdraft__schedule_duration.tag] = service - _category = PBField.new("category", PB_DATA_TYPE.MESSAGE, PB_RULE.OPTIONAL, 2054, true, DEFAULT_VALUES_3[PB_DATA_TYPE.MESSAGE]) + _category = PBField.new("category", PB_DATA_TYPE.BOOL, PB_RULE.OPTIONAL, 2054, true, DEFAULT_VALUES_3[PB_DATA_TYPE.BOOL]) service = PBServiceField.new() service.field = _category - service.func_ref = funcref(self, "new_category") data[_category.tag] = service var data = {} @@ -1530,14 +1510,13 @@ class Trail: return _texture_path.value var _guid: PBField - func get_guid() -> GUID: + func get_guid() -> PoolByteArray: return _guid.value func clear_guid() -> void: data[3].state = PB_SERVICE_STATE.UNFILLED - _guid.value = DEFAULT_VALUES_3[PB_DATA_TYPE.MESSAGE] - func new_guid() -> GUID: - _guid.value = GUID.new() - return _guid.value + _guid.value = DEFAULT_VALUES_3[PB_DATA_TYPE.BYTES] + func set_guid(value : PoolByteArray) -> void: + _guid.value = value var _map_id: PBField func get_map_id() -> int: @@ -1603,14 +1582,14 @@ class Trail: func set_achievement_id(value : int) -> void: _achievement_id.value = value - var _can_fade: PBField - func get_can_fade() -> bool: - return _can_fade.value - func clear_can_fade() -> void: + var _disable_player_cutout: PBField + func get_disable_player_cutout() -> bool: + return _disable_player_cutout.value + func clear_disable_player_cutout() -> void: data[19].state = PB_SERVICE_STATE.UNFILLED - _can_fade.value = DEFAULT_VALUES_3[PB_DATA_TYPE.BOOL] - func set_can_fade(value : bool) -> void: - _can_fade.value = value + _disable_player_cutout.value = DEFAULT_VALUES_3[PB_DATA_TYPE.BOOL] + func set_disable_player_cutout(value : bool) -> void: + _disable_player_cutout.value = value var _is_wall: PBField func get_is_wall() -> bool: @@ -1764,14 +1743,13 @@ class Trail: _bhdraft__schedule_duration.value = value var _category: PBField - func get_category() -> Category: + func get_category() -> bool: return _category.value func clear_category() -> void: data[2054].state = PB_SERVICE_STATE.UNFILLED - _category.value = DEFAULT_VALUES_3[PB_DATA_TYPE.MESSAGE] - func new_category() -> Category: - _category.value = Category.new() - return _category.value + _category.value = DEFAULT_VALUES_3[PB_DATA_TYPE.BOOL] + func set_category(value : bool) -> void: + _category.value = value func to_string() -> String: return PBPacker.message_to_string(data) @@ -2257,47 +2235,6 @@ class Trigger: return PB_ERR.PARSE_INCOMPLETE return result -class GUID: - func _init(): - var service - - _guid = PBField.new("guid", PB_DATA_TYPE.BYTES, PB_RULE.OPTIONAL, 1, true, DEFAULT_VALUES_3[PB_DATA_TYPE.BYTES]) - service = PBServiceField.new() - service.field = _guid - data[_guid.tag] = service - - var data = {} - - var _guid: PBField - func get_guid() -> PoolByteArray: - return _guid.value - func clear_guid() -> void: - data[1].state = PB_SERVICE_STATE.UNFILLED - _guid.value = DEFAULT_VALUES_3[PB_DATA_TYPE.BYTES] - func set_guid(value : PoolByteArray) -> void: - _guid.value = value - - func to_string() -> String: - return PBPacker.message_to_string(data) - - func to_bytes() -> PoolByteArray: - return PBPacker.pack_message(data) - - func from_bytes(bytes : PoolByteArray, offset : int = 0, limit : int = -1) -> int: - var cur_limit = bytes.size() - if limit != -1: - cur_limit = limit - var result = PBPacker.unpack_message(data, bytes, offset, cur_limit) - if result == cur_limit: - if PBPacker.check_required(data): - if limit == -1: - return PB_ERR.NO_ERRORS - else: - return PB_ERR.REQUIRED_FIELDS - elif limit == -1 && result > 0: - return PB_ERR.PARSE_INCOMPLETE - return result - enum CullChirality { none = 0, clockwise = 1, From 0d1ed2ab857b575dcefee42dacd010f9bf3dc596 Mon Sep 17 00:00:00 2001 From: klingbolt Date: Tue, 28 Nov 2023 22:32:25 -0500 Subject: [PATCH 02/10] Reworked Icon and Path nodes to be children on Category nodes --- Category.gd | 7 +++ Category.tscn | 6 ++ Route.gd | 1 + Spatial.gd | 167 +++++++++++++++++++++++++++++--------------------- Spatial.tscn | 2 + project.godot | 5 +- 6 files changed, 114 insertions(+), 74 deletions(-) create mode 100644 Category.gd create mode 100644 Category.tscn diff --git a/Category.gd b/Category.gd new file mode 100644 index 00000000..a5a5eac1 --- /dev/null +++ b/Category.gd @@ -0,0 +1,7 @@ +extends Spatial + +const Waypoint = preload("res://waypoint.gd") +var waypoint_category: Waypoint.Category + +func _ready(): + pass diff --git a/Category.tscn b/Category.tscn new file mode 100644 index 00000000..397d2de9 --- /dev/null +++ b/Category.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://Category.gd" type="Script" id=1] + +[node name="Category" type="Spatial"] +script = ExtResource( 1 ) diff --git a/Route.gd b/Route.gd index 24717e1e..9da5beff 100644 --- a/Route.gd +++ b/Route.gd @@ -6,6 +6,7 @@ var texture_path var color = Color(0.9, 0.1, 0.1) var waypoint: Waypoint.Trail var category: TreeItem +var minimap_path: NodePath var point_list := PoolVector3Array() diff --git a/Spatial.gd b/Spatial.gd index b423f146..e3d1cad5 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -51,13 +51,13 @@ var is_transient:bool = false # Scenes used throughout this scene const route_scene = preload("res://Route.tscn") const icon_scene = preload("res://Icon.tscn") +const category_scene = preload("res://Category.tscn") const path2d_scene = preload("res://Route2D.tscn") const gizmo_scene = preload("res://Gizmo/PointEdit.tscn") ##########Node Connections########### onready var marker_packs := $Control/Dialogs/MarkerPacks/MarkerPacks as Tree -onready var icons := $Icons as Spatial -onready var paths := $Paths as Spatial +onready var categories := $Categories as Spatial onready var minimap := $Control/MiniMap as Node2D @@ -232,8 +232,7 @@ func decode_frame_packet(spb: StreamPeerBuffer): var unchecked_flag = (ui_flags & 0xFFFFFF80) != 0x00000000; if map_is_open != map_was_open: - $Paths.visible = !map_is_open - $Icons.visible = !map_is_open + self.categories.visible = !map_is_open reset_minimap_masks() map_was_open = map_is_open @@ -344,15 +343,19 @@ func decode_context_packet(spb: StreamPeerBuffer): load_waypoint_markers(self.map_id) # 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)) + set_shader_param(self.categories, compass_width, compass_height) reset_minimap_masks() +func set_shader_param(node: Spatial, compass_width, compass_height): + for child in node.get_children(): + if child.get_name().find("Path") != -1: + child.get_node("MeshInstance").material_override.set_shader_param("map_size", Vector2(compass_width, compass_height)) + if child.get_name().find("Icon") != -1: + child.material_override.set_shader_param("map_size", Vector2(compass_width, compass_height)) + if child.get_name().find("Category") != -1: + set_shader_param(child, compass_width, compass_height) + func decode_timeout_packet(spb: StreamPeerBuffer): if Settings.burrito_link_auto_launch_enabled: @@ -470,16 +473,12 @@ func _unhandled_input(event): ################################################################################ func clear_map_markers(): # Clear all the rendered assets to make way for the new ones - for path in paths.get_children(): - path.queue_free() + for cateogry in self.categories.get_children(): + cateogry.queue_free() for path2d in minimap.get_children(): path2d.queue_free() - for icon in icons.get_children(): - icon.queue_free() - - func init_category_tree(): self.marker_packs.clear() var root : TreeItem @@ -490,19 +489,22 @@ func init_category_tree(): func waypoint_categories_to_godot_nodes(): - for category in self.waypoint_data.get_category(): - _waypoint_categories_to_godot_nodes(null, category, category.get_name(), false) + for waypoint_category in self.waypoint_data.get_category(): + _waypoint_categories_to_godot_nodes(null, waypoint_category, waypoint_category.get_name(), self.categories, false) -func _waypoint_categories_to_godot_nodes(item: TreeItem, category, full_category_name: String, collapsed: bool): +func _waypoint_categories_to_godot_nodes(item: TreeItem, waypoint_category, full_category_name: String, parent_category: Spatial, collapsed: bool): + var new_category = category_scene.instance() + parent_category.add_child(new_category) + new_category.waypoint_category = waypoint_category var category_item: TreeItem = self.marker_packs.create_item(item) - if category.get_name() == "": + if waypoint_category.get_name() == "": # If this is called, there is an error in the Waypoint data category_item.set_text(0, "No name") category_item.set_metadata(0, "") print("Category found with no name.") return - category_item.set_text(0, category.get_name()) + category_item.set_text(0, waypoint_category.get_name()) category_item.set_metadata(0, full_category_name) category_item.set_cell_mode(1, TreeItem.CELL_MODE_CHECK) category_item.set_checked(1, Settings.local_category_data.get(full_category_name, {}).get("checked", false)) @@ -511,7 +513,7 @@ func _waypoint_categories_to_godot_nodes(item: TreeItem, category, full_category category_item.set_collapsed(collapsed) category_item.set_selectable(1, false) - for path in category.get_trail(): + for path in waypoint_category.get_trail(): var path_points := PoolVector3Array() var trail_data = path.get_trail_data() if trail_data.get_points_x().size() != trail_data.get_points_y().size() or trail_data.get_points_x().size() != trail_data.get_points_z().size(): @@ -523,9 +525,10 @@ func _waypoint_categories_to_godot_nodes(item: TreeItem, category, full_category print("Warning: No texture found in " , full_category_name) continue var full_texture_path = self.marker_file_dir + texture_path.get_path() - gen_new_path(path_points, full_texture_path, path, category_item) + gen_new_path(path_points, full_texture_path, path, category_item, new_category) + - for icon in category.get_icon(): + for icon in waypoint_category.get_icon(): var position = icon.get_position() if position == null: print("Warning: No position found for icon ", full_category_name) @@ -536,10 +539,10 @@ func _waypoint_categories_to_godot_nodes(item: TreeItem, category, full_category print("Warning: No texture found in " , full_category_name) continue var full_texture_path = self.marker_file_dir + texture_path.get_path() - gen_new_icon(position_vector, full_texture_path, icon, category_item) + gen_new_icon(position_vector, full_texture_path, icon, category_item, new_category) - for category_child in category.get_children(): - _waypoint_categories_to_godot_nodes(category_item, category_child, full_category_name + "." + category_child.get_name(), true) + for category_child in waypoint_category.get_children(): + _waypoint_categories_to_godot_nodes(category_item, category_child, full_category_name + "." + category_child.get_name(), new_category, true) func apply_category_visibility_to_nodes(category_item: TreeItem): @@ -547,9 +550,8 @@ func apply_category_visibility_to_nodes(category_item: TreeItem): "checked" : category_item.is_checked(1), } Settings.save() - var temporary_cateogry_visibility_data = populate_update_dict(category_item, {}) - update_node_visibility(temporary_cateogry_visibility_data, self.paths) - update_node_visibility(temporary_cateogry_visibility_data, self.icons) + var temporary_category_visibility_data = populate_update_dict(category_item, {}) + update_node_visibility(temporary_category_visibility_data) # Builds a dictionary of the visibility of a specific category and all children @@ -561,19 +563,22 @@ func populate_update_dict(category_item: TreeItem, category_visibility_data): child_item = child_item.get_next() return category_visibility_data + #Updates the visibilty of a node and all children. -func update_node_visibility(cateogry_data, nodes): - for node in nodes.get_children(): - var node_name = node.category.get_metadata(0) - if node_name in cateogry_data: - if cateogry_data[node_name]: - node.visible = true - else: - node.visible = false - if node.get_name() == "Path": - var index = node.get_index() - var route2d = self.minimap.get_child(index) - route2d.visible= node.visible +func update_node_visibility(category_data): + for key in category_data.keys(): + var category = search_node_by_name(self.categories, key) + category.print_tree_pretty() + for node in category.get_children(): + print(node.get_name()) + if node.get_name().find("Category") == -1: + if category_data[key]: + node.visible = true + else: + node.visible = false + if node.get_name().find("Path") != -1: + self.minimap.get_node(node.minimap_path).visible = node.visible + #Child visibility is contigent on all parents having permission func is_category_visible(category_item: TreeItem) -> bool: @@ -587,7 +592,7 @@ func is_category_visible(category_item: TreeItem) -> bool: return false -func gen_new_path(points: Array, texture_path: String, waypoint_trail, category_item: TreeItem): +func gen_new_path(points: Array, texture_path: String, waypoint_trail, category_item: TreeItem, category: Spatial): # 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. @@ -616,13 +621,11 @@ func gen_new_path(points: Array, texture_path: String, waypoint_trail, category_ new_route.create_mesh(points_3d) new_route.set_texture(texture) new_route.waypoint = waypoint_trail - new_route.category = category_item if category_item != null: new_route.visible = is_category_visible(category_item) else: new_route.visible = false - - paths.add_child(new_route) + category.add_child(new_route) # Create a new 2D Path var new_2d_path = path2d_scene.instance() @@ -632,24 +635,43 @@ func gen_new_path(points: Array, texture_path: String, waypoint_trail, category_ new_2d_path.points = points_2d new_2d_path.texture = texture new_2d_path.visible = new_route.visible - minimap.add_child(new_2d_path) + self.minimap.add_child(new_2d_path) + new_route.minimap_path= new_2d_path.get_path() self.currently_active_path = new_route self.currently_active_path_2d = new_2d_path -func gen_new_icon(position: Vector3, texture_path: String, waypoint_icon, category_item: TreeItem): +func gen_new_icon(position: Vector3, texture_path: String, waypoint_icon, category_item: TreeItem, category: Spatial): position.z = -position.z var new_icon = icon_scene.instance() new_icon.translation = position new_icon.set_icon_image(texture_path) new_icon.waypoint = waypoint_icon - new_icon.category = category_item if category_item != null: new_icon.visible = is_category_visible(category_item) else: new_icon.visible = false - icons.add_child(new_icon) + category.add_child(new_icon) + +func search_node_by_name(node, target_name): + for child in node.get_children(): + var result = _search_node_by_name(child, target_name) + if result: + return result + +func _search_node_by_name(node: Spatial, target_name: String): + var split_name = target_name.split(".") + if "waypoint_category" in node and node.waypoint_category.get_name() == split_name[0]: + if split_name.size() > 1: + split_name.remove(0) + for child in node.get_children(): + if child.get_name().find("Category") != -1: + var result = _search_node_by_name(child, split_name.join(".")) + if result: + return result + else: + return node # This function take all of the currently rendered objects and converts it into # the data format that is saved/loaded from. @@ -696,13 +718,15 @@ func gen_adjustment_nodes(): print("No category selected") return - for index in range(self.paths.get_child_count()): - var route = self.paths.get_child(index) - var path2d = self.minimap.get_child(index) - if self.currently_active_category.get_metadata(0) == route.waypoint.get_category().get_name(): + var category = search_node_by_name(self.categories, self.currently_active_category.get_metadata(0)) + for child in category.get_children(): + if child.get_name().find("Path") != -1: + var route = child + print(route.minimap_path) + var path2d = self.minimap.get_node(route.minimap_path) + print(path2d.texture) 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. @@ -714,16 +738,15 @@ func gen_adjustment_nodes(): 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) - if self.currently_active_category.get_metadata(0) == icon.waypoint.get_category().get_name(): - 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) + if child.get_name().find("Icon") != -1: + var icon = child + if self.currently_active_category.get_metadata(0) == icon.waypoint.get_category().get_name(): + 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 @@ -826,16 +849,18 @@ func _on_NewPath_pressed(): # Create a new icon and give it the texture ################################################################################ func _on_NewIcon_pressed(): - var waypoint_icon = Waypoint.Icon.new() - waypoint_icon.new_category().set_name(self.currently_active_category.get_metadata(0)) - gen_new_icon(self.player_position, self.next_texture_path, waypoint_icon, self.currently_active_category) + var category = search_node_by_name(self.categories, self.currently_active_category.get_metadata(0)) + var waypoint_category = category.waypoint_category + var waypoint_icon = waypoint_category.new_icon() + gen_new_icon(self.player_position, self.next_texture_path, waypoint_icon, self.currently_active_category, category) # A new path point is created func _on_NewPathPoint_pressed(): if self.currently_active_path == null: - var waypoint_trail = Waypoint.Trail.new() - waypoint_trail.new_category().set_name(self.currently_active_category.get_metadata(0)) - gen_new_path([self.player_position], self.next_texture_path, waypoint_trail, self.currently_active_category) + var category = search_node_by_name(self.categories, self.currently_active_category.get_metadata(0)) + var waypoint_category = category.waypoint_category + var waypoint_trail = waypoint_category.new_trail() + gen_new_path([self.player_position], self.next_texture_path, waypoint_trail, self.currently_active_category, category) else: var z_accurate_player_position = player_position z_accurate_player_position.z = -z_accurate_player_position.z diff --git a/Spatial.tscn b/Spatial.tscn index 62d5b1ad..88df13b7 100644 --- a/Spatial.tscn +++ b/Spatial.tscn @@ -867,6 +867,8 @@ color = Color( 0, 0, 0, 1 ) mesh = SubResource( 3 ) material/0 = SubResource( 4 ) +[node name="Categories" type="Spatial" parent="."] + [connection signal="pressed" from="Control/GlobalMenuButton/main_menu_toggle" to="." method="_on_main_menu_toggle_pressed"] [connection signal="pressed" from="Control/GlobalMenuButton/EditorQuckPanel/HBoxContainer/CloseEditorQuickPanel" to="." method="_on_CloseEditorQuickPanel_pressed"] [connection signal="pressed" from="Control/GlobalMenuButton/EditorQuckPanel/HBoxContainer/ChangeTexture" to="." method="_on_ChangeTexture_pressed"] diff --git a/project.godot b/project.godot index e7ec8f21..fb41ab1c 100644 --- a/project.godot +++ b/project.godot @@ -14,7 +14,7 @@ _global_script_classes=[ { "language": "NativeScript", "path": "res://tacoparser.gdns" }, { -"base": "Node", +"base": "", "class": "X11_FG", "language": "NativeScript", "path": "res://Spatial.gdns" @@ -49,8 +49,7 @@ window/per_pixel_transparency/enabled=true [editor_plugins] -enabled=PoolStringArray( "res://addons/protobuf/plugin.cfg" ) -enabled=PoolStringArray( "res://addons/version_restrict/plugin.cfg" ) +enabled=PoolStringArray( "res://addons/protobuf/plugin.cfg", "res://addons/version_restrict/plugin.cfg" ) [global] From f1dc817083cc81ae4be383a42c2b1c3a5df297d2 Mon Sep 17 00:00:00 2001 From: klingbolt Date: Thu, 30 Nov 2023 22:53:01 -0500 Subject: [PATCH 03/10] Change how children into arrays of categorized nodes --- Category.gd | 16 +++++++ Spatial.gd | 120 +++++++++++++++++++++++++-------------------------- Spatial.tscn | 4 +- 3 files changed, 78 insertions(+), 62 deletions(-) diff --git a/Category.gd b/Category.gd index a5a5eac1..a425c060 100644 --- a/Category.gd +++ b/Category.gd @@ -3,5 +3,21 @@ extends Spatial const Waypoint = preload("res://waypoint.gd") var waypoint_category: Waypoint.Category +var paths: Array = [] +var icons: Array = [] +var subcategories: Array = [] + +func add_path(path): + self.add_child(path) + paths.push_back(path) + +func add_icon(icon): + self.add_child(icon) + icons.push_back(icon) + +func add_subcategory(subcategory): + self.add_child(subcategory) + subcategories.push_back(subcategory) + func _ready(): pass diff --git a/Spatial.gd b/Spatial.gd index e3d1cad5..4aa4f4b3 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -233,7 +233,7 @@ func decode_frame_packet(spb: StreamPeerBuffer): if map_is_open != map_was_open: self.categories.visible = !map_is_open - reset_minimap_masks() + reset_masks() map_was_open = map_is_open if unchecked_flag: @@ -337,24 +337,12 @@ func decode_context_packet(spb: StreamPeerBuffer): if self.map_id != old_map_id: print("New Map") - print("Saving Old Map") print("Loading New Map") load_waypoint_markers(self.map_id) - # TODO move this to reset_minimap_masks - set_shader_param(self.categories, compass_width, compass_height) - - reset_minimap_masks() + reset_masks() -func set_shader_param(node: Spatial, compass_width, compass_height): - for child in node.get_children(): - if child.get_name().find("Path") != -1: - child.get_node("MeshInstance").material_override.set_shader_param("map_size", Vector2(compass_width, compass_height)) - if child.get_name().find("Icon") != -1: - child.material_override.set_shader_param("map_size", Vector2(compass_width, compass_height)) - if child.get_name().find("Category") != -1: - set_shader_param(child, compass_width, compass_height) func decode_timeout_packet(spb: StreamPeerBuffer): @@ -364,7 +352,7 @@ func decode_timeout_packet(spb: StreamPeerBuffer): launch_burrito_link() -func reset_minimap_masks(): +func reset_masks(): var viewport_size = get_viewport().size compass_corner1 = Vector2(0, 0) compass_corner2 = viewport_size @@ -379,6 +367,23 @@ func reset_minimap_masks(): minimap_path.material.set_shader_param("minimap_corner", compass_corner1) minimap_path.material.set_shader_param("minimap_corner2", compass_corner2) + for category in self.categories.get_children(): + _reset_masks(category) + + +func _reset_masks(category: Spatial): + print(category.paths) + print(category.icons) + print(category.subcategories) + for path in category.paths: + path.print_tree_pretty() + path.get_node("MeshInstance").material_override.set_shader_param("map_size", Vector2(self.compass_width, self.compass_height)) + for icon in category.icons: + icon.material_override.set_shader_param("map_size", Vector2(self.compass_width, self.compass_height)) + for subcategory in category.subcategories: + _reset_masks(subcategory) + + var waypoint_data = Waypoint.Waypoint.new() var marker_file_dir = "user://protobins/" var marker_file_path = "" @@ -495,7 +500,7 @@ func waypoint_categories_to_godot_nodes(): func _waypoint_categories_to_godot_nodes(item: TreeItem, waypoint_category, full_category_name: String, parent_category: Spatial, collapsed: bool): var new_category = category_scene.instance() - parent_category.add_child(new_category) + parent_category.add_subcategory(new_category) new_category.waypoint_category = waypoint_category var category_item: TreeItem = self.marker_packs.create_item(item) if waypoint_category.get_name() == "": @@ -568,16 +573,14 @@ func populate_update_dict(category_item: TreeItem, category_visibility_data): func update_node_visibility(category_data): for key in category_data.keys(): var category = search_node_by_name(self.categories, key) - category.print_tree_pretty() - for node in category.get_children(): - print(node.get_name()) - if node.get_name().find("Category") == -1: - if category_data[key]: - node.visible = true - else: - node.visible = false - if node.get_name().find("Path") != -1: - self.minimap.get_node(node.minimap_path).visible = node.visible + var visibility = false + if category_data[key]: + visibility = true + for node in category.icons: + node.visible = visibility + for node in category.paths: + node.visible = visibility + self.minimap.get_node(node.minimap_path).visible = node.visible #Child visibility is contigent on all parents having permission @@ -625,7 +628,7 @@ func gen_new_path(points: Array, texture_path: String, waypoint_trail, category_ new_route.visible = is_category_visible(category_item) else: new_route.visible = false - category.add_child(new_route) + category.add_path(new_route) # Create a new 2D Path var new_2d_path = path2d_scene.instance() @@ -652,7 +655,7 @@ func gen_new_icon(position: Vector3, texture_path: String, waypoint_icon, catego new_icon.visible = is_category_visible(category_item) else: new_icon.visible = false - category.add_child(new_icon) + category.add_icon(new_icon) func search_node_by_name(node, target_name): for child in node.get_children(): @@ -665,11 +668,10 @@ func _search_node_by_name(node: Spatial, target_name: String): if "waypoint_category" in node and node.waypoint_category.get_name() == split_name[0]: if split_name.size() > 1: split_name.remove(0) - for child in node.get_children(): - if child.get_name().find("Category") != -1: - var result = _search_node_by_name(child, split_name.join(".")) - if result: - return result + for subcategory in node.subcategories: + var result = _search_node_by_name(subcategory, split_name.join(".")) + if result: + return result else: return node @@ -719,34 +721,30 @@ func gen_adjustment_nodes(): return var category = search_node_by_name(self.categories, self.currently_active_category.get_metadata(0)) - for child in category.get_children(): - if child.get_name().find("Path") != -1: - var route = child - print(route.minimap_path) - var path2d = self.minimap.get_node(route.minimap_path) - print(path2d.texture) - 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) - if child.get_name().find("Icon") != -1: - var icon = child - if self.currently_active_category.get_metadata(0) == icon.waypoint.get_category().get_name(): - 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) + for route in category.paths: + print(route.minimap_path) + var path2d = self.minimap.get_node(route.minimap_path) + print(path2d.texture) + 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 icon in category.icons: + 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 diff --git a/Spatial.tscn b/Spatial.tscn index 88df13b7..00e06f1c 100644 --- a/Spatial.tscn +++ b/Spatial.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=17 format=2] +[gd_scene load_steps=18 format=2] [ext_resource path="res://Spatial.gd" type="Script" id=1] [ext_resource path="res://shaders/range_indicators.shader" type="Shader" id=2] @@ -12,6 +12,7 @@ [ext_resource path="res://icon_new_path.png" type="Texture" id=10] [ext_resource path="res://icon_new_point.png" type="Texture" id=11] [ext_resource path="res://SettingsDialog.gd" type="Script" id=12] +[ext_resource path="res://Category.gd" type="Script" id=13] [sub_resource type="Shader" id=1] code = "shader_type canvas_item; @@ -868,6 +869,7 @@ mesh = SubResource( 3 ) material/0 = SubResource( 4 ) [node name="Categories" type="Spatial" parent="."] +script = ExtResource( 13 ) [connection signal="pressed" from="Control/GlobalMenuButton/main_menu_toggle" to="." method="_on_main_menu_toggle_pressed"] [connection signal="pressed" from="Control/GlobalMenuButton/EditorQuckPanel/HBoxContainer/CloseEditorQuickPanel" to="." method="_on_CloseEditorQuickPanel_pressed"] From 7a287a25746618183a8da2df2f02888fa2e74cc4 Mon Sep 17 00:00:00 2001 From: klingbolt Date: Sun, 10 Dec 2023 23:23:08 -0500 Subject: [PATCH 04/10] Added class CategoryData to hold refrences to 3d and 2d trees inside the UI tree --- Category.gd | 15 ++--- Category2D.gd | 12 ++++ Category2D.tscn | 6 ++ CategoryData.gd | 6 ++ Spatial.gd | 171 ++++++++++++++++++++---------------------------- Spatial.tscn | 14 ++-- 6 files changed, 109 insertions(+), 115 deletions(-) create mode 100644 Category2D.gd create mode 100644 Category2D.tscn create mode 100644 CategoryData.gd diff --git a/Category.gd b/Category.gd index a425c060..e0eee3d6 100644 --- a/Category.gd +++ b/Category.gd @@ -1,23 +1,18 @@ extends Spatial -const Waypoint = preload("res://waypoint.gd") -var waypoint_category: Waypoint.Category - var paths: Array = [] var icons: Array = [] var subcategories: Array = [] + func add_path(path): - self.add_child(path) + self.add_child(path, true) paths.push_back(path) func add_icon(icon): - self.add_child(icon) + self.add_child(icon, true) icons.push_back(icon) - + func add_subcategory(subcategory): - self.add_child(subcategory) + self.add_child(subcategory, true) subcategories.push_back(subcategory) - -func _ready(): - pass diff --git a/Category2D.gd b/Category2D.gd new file mode 100644 index 00000000..79260a49 --- /dev/null +++ b/Category2D.gd @@ -0,0 +1,12 @@ +extends Node2D + +var paths2d: Array = [] +var subcategories: Array = [] + +func add_path2d(path): + self.add_child(path, true) + paths2d.push_back(path) + +func add_subcategory(subcategory): + self.add_child(subcategory, true) + subcategories.push_back(subcategory) diff --git a/Category2D.tscn b/Category2D.tscn new file mode 100644 index 00000000..37bc52c6 --- /dev/null +++ b/Category2D.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://Category2D.gd" type="Script" id=1] + +[node name="Category2D" type="Node2D"] +script = ExtResource( 1 ) diff --git a/CategoryData.gd b/CategoryData.gd new file mode 100644 index 00000000..8e307708 --- /dev/null +++ b/CategoryData.gd @@ -0,0 +1,6 @@ +const Waypoint = preload("res://waypoint.gd") + +var category: Spatial +var category2d: Node2D +var waypoint_category: Waypoint.Category +var is_visible = false diff --git a/Spatial.gd b/Spatial.gd index 4aa4f4b3..98867c1b 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -52,8 +52,10 @@ var is_transient:bool = false const route_scene = preload("res://Route.tscn") const icon_scene = preload("res://Icon.tscn") const category_scene = preload("res://Category.tscn") +const category2d_scene = preload("res://Category2D.tscn") const path2d_scene = preload("res://Route2D.tscn") const gizmo_scene = preload("res://Gizmo/PointEdit.tscn") +const CategoryData = preload("res://CategoryData.gd") ##########Node Connections########### onready var marker_packs := $Control/Dialogs/MarkerPacks/MarkerPacks as Tree @@ -363,25 +365,27 @@ func reset_masks(): 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) + for child in $Control/MiniMap.get_children(): + if child.get_name() == "Category2D": + _reset_2D_masks(child, compass_corner1, compass_corner2) for category in self.categories.get_children(): - _reset_masks(category) + _reset_3D_masks(category) +func _reset_2D_masks(category2d: Node2D, compass_corner1, compass_corner2): + for path2d in category2d.paths2d: + path2d.material.set_shader_param("minimap_corner", compass_corner1) + path2d.material.set_shader_param("minimap_corner2", compass_corner2) + for subcategory in category2d.subcategories: + _reset_2D_masks(subcategory, compass_corner1, compass_corner2) -func _reset_masks(category: Spatial): - print(category.paths) - print(category.icons) - print(category.subcategories) +func _reset_3D_masks(category: Spatial): for path in category.paths: - path.print_tree_pretty() path.get_node("MeshInstance").material_override.set_shader_param("map_size", Vector2(self.compass_width, self.compass_height)) for icon in category.icons: icon.material_override.set_shader_param("map_size", Vector2(self.compass_width, self.compass_height)) for subcategory in category.subcategories: - _reset_masks(subcategory) + _reset_3D_masks(subcategory) var waypoint_data = Waypoint.Waypoint.new() @@ -495,93 +499,87 @@ func init_category_tree(): func waypoint_categories_to_godot_nodes(): for waypoint_category in self.waypoint_data.get_category(): - _waypoint_categories_to_godot_nodes(null, waypoint_category, waypoint_category.get_name(), self.categories, false) + _waypoint_categories_to_godot_nodes(null, waypoint_category, self.categories, self.minimap, false) -func _waypoint_categories_to_godot_nodes(item: TreeItem, waypoint_category, full_category_name: String, parent_category: Spatial, collapsed: bool): - var new_category = category_scene.instance() - parent_category.add_subcategory(new_category) - new_category.waypoint_category = waypoint_category - var category_item: TreeItem = self.marker_packs.create_item(item) +func _waypoint_categories_to_godot_nodes(item: TreeItem, waypoint_category, parent_category: Spatial, parent_category2d: Node2D, collapsed: bool): if waypoint_category.get_name() == "": - # If this is called, there is an error in the Waypoint data - category_item.set_text(0, "No name") - category_item.set_metadata(0, "") + # If this is called, there is an empty Category in the Waypoint data print("Category found with no name.") return + + var godot_category = category_scene.instance() + var godot_category2d = category2d_scene.instance() + parent_category.add_subcategory(godot_category) + parent_category2d.add_subcategory(godot_category2d) + + var category_item: TreeItem = self.marker_packs.create_item(item) + var category_data = CategoryData.new() + category_data.waypoint_category = waypoint_category + category_data.category = godot_category + category_data.category2d = godot_category2d + category_item.set_metadata(0, category_data) + category_item.set_text(0, waypoint_category.get_name()) - category_item.set_metadata(0, full_category_name) category_item.set_cell_mode(1, TreeItem.CELL_MODE_CHECK) - category_item.set_checked(1, Settings.local_category_data.get(full_category_name, {}).get("checked", false)) + # TODO: Without unique category names, this could give false info when + # switching maps or changes to marker pack files. + godot_category.name = waypoint_category.get_name() + var relative_path: String = self.categories.get_path_to(godot_category) + category_item.set_checked(1, Settings.local_category_data.get(relative_path, {}).get("checked", false)) + category_item.set_tooltip(1, "Show/Hide") category_item.set_editable(1, true) category_item.set_collapsed(collapsed) category_item.set_selectable(1, false) + + category_data.is_visible = is_category_visible(category_item) + godot_category.visible = category_data.is_visible + godot_category2d.visible = category_data.is_visible for path in waypoint_category.get_trail(): var path_points := PoolVector3Array() var trail_data = path.get_trail_data() if trail_data.get_points_x().size() != trail_data.get_points_y().size() or trail_data.get_points_x().size() != trail_data.get_points_z().size(): - print("Warning: Trail ", full_category_name, " does not have equal number of X, Y, and Z coordinates.") + print("Warning: Trail ", waypoint_category.get_name(), " does not have equal number of X, Y, and Z coordinates.") for index in range(0, trail_data.get_points_z().size()): path_points.append(Vector3(trail_data.get_points_x()[index], trail_data.get_points_y()[index], trail_data.get_points_z()[index])) var texture_path = path.get_texture_path() if texture_path == null: - print("Warning: No texture found in " , full_category_name) + print("Warning: No texture found in " , waypoint_category.get_name()) continue var full_texture_path = self.marker_file_dir + texture_path.get_path() - gen_new_path(path_points, full_texture_path, path, category_item, new_category) + gen_new_path(path_points, full_texture_path, path, category_item) for icon in waypoint_category.get_icon(): var position = icon.get_position() if position == null: - print("Warning: No position found for icon ", full_category_name) + print("Warning: No position found for icon ", waypoint_category.get_name()) continue var position_vector = Vector3(position.get_x(), position.get_y(), position.get_z()) var texture_path = icon.get_texture_path() if texture_path == null: - print("Warning: No texture found in " , full_category_name) + print("Warning: No texture found in " , waypoint_category.get_name()) continue var full_texture_path = self.marker_file_dir + texture_path.get_path() - gen_new_icon(position_vector, full_texture_path, icon, category_item, new_category) + gen_new_icon(position_vector, full_texture_path, icon, category_item) for category_child in waypoint_category.get_children(): - _waypoint_categories_to_godot_nodes(category_item, category_child, full_category_name + "." + category_child.get_name(), new_category, true) + _waypoint_categories_to_godot_nodes(category_item, category_child, godot_category, godot_category2d, true) func apply_category_visibility_to_nodes(category_item: TreeItem): - Settings.local_category_data[category_item.get_metadata(0)] = { + var category_data = category_item.get_metadata(0) + var relative_path: String = self.categories.get_path_to(category_data.category) + Settings.local_category_data[relative_path] = { "checked" : category_item.is_checked(1), } Settings.save() - var temporary_category_visibility_data = populate_update_dict(category_item, {}) - update_node_visibility(temporary_category_visibility_data) - - -# Builds a dictionary of the visibility of a specific category and all children -func populate_update_dict(category_item: TreeItem, category_visibility_data): - category_visibility_data[category_item.get_metadata(0)] = is_category_visible(category_item) - var child_item = category_item.get_children() - while child_item != null: - category_visibility_data = populate_update_dict(child_item, category_visibility_data) - child_item = child_item.get_next() - return category_visibility_data - - -#Updates the visibilty of a node and all children. -func update_node_visibility(category_data): - for key in category_data.keys(): - var category = search_node_by_name(self.categories, key) - var visibility = false - if category_data[key]: - visibility = true - for node in category.icons: - node.visible = visibility - for node in category.paths: - node.visible = visibility - self.minimap.get_node(node.minimap_path).visible = node.visible - + + category_data.is_visible = category_item.is_checked(1) + category_data.category.visible = category_data.is_visible + category_data.category2d.visible = category_data.is_visible #Child visibility is contigent on all parents having permission func is_category_visible(category_item: TreeItem) -> bool: @@ -595,7 +593,7 @@ func is_category_visible(category_item: TreeItem) -> bool: return false -func gen_new_path(points: Array, texture_path: String, waypoint_trail, category_item: TreeItem, category: Spatial): +func gen_new_path(points: Array, texture_path: String, waypoint_trail, category_item: TreeItem): # 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. @@ -624,11 +622,9 @@ func gen_new_path(points: Array, texture_path: String, waypoint_trail, category_ new_route.create_mesh(points_3d) new_route.set_texture(texture) new_route.waypoint = waypoint_trail - if category_item != null: - new_route.visible = is_category_visible(category_item) - else: - new_route.visible = false - category.add_path(new_route) + var category_data = category_item.get_metadata(0) + category_data.category.add_path(new_route) + # Create a new 2D Path var new_2d_path = path2d_scene.instance() @@ -637,43 +633,22 @@ func gen_new_path(points: Array, texture_path: String, waypoint_trail, category_ points_2d.append(Vector2(point[0], -point[2])) new_2d_path.points = points_2d new_2d_path.texture = texture - new_2d_path.visible = new_route.visible - self.minimap.add_child(new_2d_path) - new_route.minimap_path= new_2d_path.get_path() + category_data.category2d.add_path2d(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, waypoint_icon, category_item: TreeItem, category: Spatial): +func gen_new_icon(position: Vector3, texture_path: String, waypoint_icon, category_item: TreeItem): position.z = -position.z var new_icon = icon_scene.instance() new_icon.translation = position new_icon.set_icon_image(texture_path) new_icon.waypoint = waypoint_icon - if category_item != null: - new_icon.visible = is_category_visible(category_item) - else: - new_icon.visible = false - category.add_icon(new_icon) + var category_data = category_item.get_metadata(0) + new_icon.visible = category_data.is_visible + category_data.category.add_icon(new_icon) -func search_node_by_name(node, target_name): - for child in node.get_children(): - var result = _search_node_by_name(child, target_name) - if result: - return result - -func _search_node_by_name(node: Spatial, target_name: String): - var split_name = target_name.split(".") - if "waypoint_category" in node and node.waypoint_category.get_name() == split_name[0]: - if split_name.size() > 1: - split_name.remove(0) - for subcategory in node.subcategories: - var result = _search_node_by_name(subcategory, split_name.join(".")) - if result: - return result - else: - return node # This function take all of the currently rendered objects and converts it into # the data format that is saved/loaded from. @@ -720,11 +695,11 @@ func gen_adjustment_nodes(): print("No category selected") return - var category = search_node_by_name(self.categories, self.currently_active_category.get_metadata(0)) - for route in category.paths: - print(route.minimap_path) - var path2d = self.minimap.get_node(route.minimap_path) - print(path2d.texture) + var category = self.currently_active_category.get_metadata(0).category + var category2d = self.currently_active_category.get_metadata(0).category2d + for index in category.paths.size(): + var route = category.paths[index] + var path2d = category2d.paths2d[index] 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 @@ -847,18 +822,16 @@ func _on_NewPath_pressed(): # Create a new icon and give it the texture ################################################################################ func _on_NewIcon_pressed(): - var category = search_node_by_name(self.categories, self.currently_active_category.get_metadata(0)) - var waypoint_category = category.waypoint_category + var waypoint_category = self.currently_active_category.get_metadata(0).waypoint_category var waypoint_icon = waypoint_category.new_icon() - gen_new_icon(self.player_position, self.next_texture_path, waypoint_icon, self.currently_active_category, category) + gen_new_icon(self.player_position, self.next_texture_path, waypoint_icon, self.currently_active_category) # A new path point is created func _on_NewPathPoint_pressed(): if self.currently_active_path == null: - var category = search_node_by_name(self.categories, self.currently_active_category.get_metadata(0)) - var waypoint_category = category.waypoint_category + var waypoint_category = self.currently_active_category.get_metadata(0).waypoint_category var waypoint_trail = waypoint_category.new_trail() - gen_new_path([self.player_position], self.next_texture_path, waypoint_trail, self.currently_active_category, category) + gen_new_path([self.player_position], self.next_texture_path, waypoint_trail, self.currently_active_category) else: var z_accurate_player_position = player_position z_accurate_player_position.z = -z_accurate_player_position.z diff --git a/Spatial.tscn b/Spatial.tscn index 00e06f1c..2cc9dc2e 100644 --- a/Spatial.tscn +++ b/Spatial.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=18 format=2] +[gd_scene load_steps=19 format=2] [ext_resource path="res://Spatial.gd" type="Script" id=1] [ext_resource path="res://shaders/range_indicators.shader" type="Shader" id=2] @@ -13,6 +13,7 @@ [ext_resource path="res://icon_new_point.png" type="Texture" id=11] [ext_resource path="res://SettingsDialog.gd" type="Script" id=12] [ext_resource path="res://Category.gd" type="Script" id=13] +[ext_resource path="res://Category2D.gd" type="Script" id=15] [sub_resource type="Shader" id=1] code = "shader_type canvas_item; @@ -51,6 +52,11 @@ shader_param/custom_7_value = 500.0 [node name="Spatial" type="Spatial"] script = ExtResource( 1 ) +[node name="Categories" type="Spatial" parent="."] +script = ExtResource( 13 ) + +[node name="Gizmos" type="Spatial" parent="."] + [node name="CameraMount" type="Spatial" parent="."] [node name="Camera" type="Camera" parent="CameraMount"] @@ -68,6 +74,7 @@ __meta__ = { [node name="MiniMap" type="Node2D" parent="Control"] material = SubResource( 2 ) scale = Vector2( 2, 2 ) +script = ExtResource( 15 ) [node name="Line2D" parent="Control/MiniMap" instance=ExtResource( 4 )] @@ -860,17 +867,12 @@ color = Color( 0, 0, 0, 1 ) [node name="Icons" type="Spatial" parent="."] -[node name="Gizmos" type="Spatial" parent="."] - [node name="FeetLocation" type="Spatial" parent="."] [node name="DistanceIndicator" type="MeshInstance" parent="FeetLocation"] mesh = SubResource( 3 ) material/0 = SubResource( 4 ) -[node name="Categories" type="Spatial" parent="."] -script = ExtResource( 13 ) - [connection signal="pressed" from="Control/GlobalMenuButton/main_menu_toggle" to="." method="_on_main_menu_toggle_pressed"] [connection signal="pressed" from="Control/GlobalMenuButton/EditorQuckPanel/HBoxContainer/CloseEditorQuickPanel" to="." method="_on_CloseEditorQuickPanel_pressed"] [connection signal="pressed" from="Control/GlobalMenuButton/EditorQuckPanel/HBoxContainer/ChangeTexture" to="." method="_on_ChangeTexture_pressed"] From 6548c343be1c1ae759d4c4a625c3fd166e143f5f Mon Sep 17 00:00:00 2001 From: klingbolt Date: Mon, 11 Dec 2023 18:05:55 -0500 Subject: [PATCH 05/10] Removed unused code --- Icon.gd | 1 - Route.gd | 2 -- Spatial.gd | 34 ++++++++++++---------------------- 3 files changed, 12 insertions(+), 25 deletions(-) diff --git a/Icon.gd b/Icon.gd index cc171b55..1cd9164c 100644 --- a/Icon.gd +++ b/Icon.gd @@ -4,7 +4,6 @@ const Waypoint = preload("res://waypoint.gd") var texture_path var waypoint: Waypoint.Icon -var category: TreeItem func set_icon_image(texture_path: String): self.texture_path = texture_path diff --git a/Route.gd b/Route.gd index 9da5beff..392b2ffd 100644 --- a/Route.gd +++ b/Route.gd @@ -5,8 +5,6 @@ const Waypoint = preload("res://waypoint.gd") var texture_path var color = Color(0.9, 0.1, 0.1) var waypoint: Waypoint.Trail -var category: TreeItem -var minimap_path: NodePath var point_list := PoolVector3Array() diff --git a/Spatial.gd b/Spatial.gd index 98867c1b..daf49bf3 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -518,24 +518,23 @@ func _waypoint_categories_to_godot_nodes(item: TreeItem, waypoint_category, pare category_data.waypoint_category = waypoint_category category_data.category = godot_category category_data.category2d = godot_category2d - category_item.set_metadata(0, category_data) + category_item.set_metadata(0, category_data) category_item.set_text(0, waypoint_category.get_name()) category_item.set_cell_mode(1, TreeItem.CELL_MODE_CHECK) - # TODO: Without unique category names, this could give false info when - # switching maps or changes to marker pack files. + # TODO 214: The format for the category name stored here is a/b/c. + # This could be changed to some UUID. godot_category.name = waypoint_category.get_name() var relative_path: String = self.categories.get_path_to(godot_category) category_item.set_checked(1, Settings.local_category_data.get(relative_path, {}).get("checked", false)) - category_item.set_tooltip(1, "Show/Hide") category_item.set_editable(1, true) category_item.set_collapsed(collapsed) category_item.set_selectable(1, false) - - category_data.is_visible = is_category_visible(category_item) - godot_category.visible = category_data.is_visible - godot_category2d.visible = category_data.is_visible + + category_data.is_visible = category_item.is_checked(1) + godot_category.visible = category_data.is_visible + godot_category2d.visible = category_data.is_visible for path in waypoint_category.get_trail(): var path_points := PoolVector3Array() @@ -550,7 +549,7 @@ func _waypoint_categories_to_godot_nodes(item: TreeItem, waypoint_category, pare continue var full_texture_path = self.marker_file_dir + texture_path.get_path() gen_new_path(path_points, full_texture_path, path, category_item) - + for icon in waypoint_category.get_icon(): var position = icon.get_position() @@ -572,26 +571,17 @@ func _waypoint_categories_to_godot_nodes(item: TreeItem, waypoint_category, pare func apply_category_visibility_to_nodes(category_item: TreeItem): var category_data = category_item.get_metadata(0) var relative_path: String = self.categories.get_path_to(category_data.category) + # TODO 214: The format for the category name stored here is a/b/c. + # This could be changed to some UUID. Settings.local_category_data[relative_path] = { "checked" : category_item.is_checked(1), } Settings.save() - + category_data.is_visible = category_item.is_checked(1) category_data.category.visible = category_data.is_visible category_data.category2d.visible = category_data.is_visible -#Child visibility is contigent on all parents having permission -func is_category_visible(category_item: TreeItem) -> bool: - if category_item == marker_packs.get_root(): - return true - if category_item == null: - return false - if category_item.is_checked(1): - return is_category_visible(category_item.get_parent()) - else: - return false - func gen_new_path(points: Array, texture_path: String, waypoint_trail, category_item: TreeItem): # Create the texture to use from an image file @@ -624,7 +614,7 @@ func gen_new_path(points: Array, texture_path: String, waypoint_trail, category_ new_route.waypoint = waypoint_trail var category_data = category_item.get_metadata(0) category_data.category.add_path(new_route) - + # Create a new 2D Path var new_2d_path = path2d_scene.instance() From 6082ac9ddb4fc6600d2c90aaad8f5d8f93d82b60 Mon Sep 17 00:00:00 2001 From: klingbolt Date: Fri, 15 Dec 2023 16:05:34 -0500 Subject: [PATCH 06/10] addressing comments --- Spatial.gd | 1 - 1 file changed, 1 deletion(-) diff --git a/Spatial.gd b/Spatial.gd index daf49bf3..fd0ffaba 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -506,7 +506,6 @@ func _waypoint_categories_to_godot_nodes(item: TreeItem, waypoint_category, pare if waypoint_category.get_name() == "": # If this is called, there is an empty Category in the Waypoint data print("Category found with no name.") - return var godot_category = category_scene.instance() var godot_category2d = category2d_scene.instance() From 6af7877c37bdfd97258b846acd6ede67b21f07ef Mon Sep 17 00:00:00 2001 From: klingbolt Date: Fri, 15 Dec 2023 18:24:00 -0500 Subject: [PATCH 07/10] Forgot to save in Godot --- Spatial.gd | 52 ++++++++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/Spatial.gd b/Spatial.gd index fd0ffaba..64e11ace 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -5,7 +5,6 @@ var peers = [] var map_id:int = 0 -var Waypoint = preload("res://waypoint.gd") var map_is_open: bool var compass_is_top_right: bool @@ -39,9 +38,6 @@ var compass_width: int = 0; # 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 @@ -56,6 +52,7 @@ const category2d_scene = preload("res://Category2D.tscn") const path2d_scene = preload("res://Route2D.tscn") const gizmo_scene = preload("res://Gizmo/PointEdit.tscn") const CategoryData = preload("res://CategoryData.gd") +const Waypoint = preload("res://waypoint.gd") ##########Node Connections########### onready var marker_packs := $Control/Dialogs/MarkerPacks/MarkerPacks as Tree @@ -356,21 +353,21 @@ func decode_timeout_packet(spb: StreamPeerBuffer): func reset_masks(): var viewport_size = get_viewport().size - compass_corner1 = Vector2(0, 0) - compass_corner2 = viewport_size + var compass_corner1 = Vector2(0, 0) + var compass_corner2 = viewport_size if !map_is_open && !compass_is_top_right: - compass_corner1 = Vector2(viewport_size.x-compass_width, 36) - compass_corner2 = compass_corner1 + Vector2(compass_width, compass_height) + compass_corner1 = Vector2(viewport_size.x-self.compass_width, 36) + compass_corner2 = compass_corner1 + Vector2(self.compass_width, self.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) + compass_corner1 = viewport_size - Vector2(self.compass_width, self.compass_height) + compass_corner2 = compass_corner1 + Vector2(self.compass_width, self.compass_height) - for child in $Control/MiniMap.get_children(): - if child.get_name() == "Category2D": - _reset_2D_masks(child, compass_corner1, compass_corner2) + for category in self.minimap.subcategories(): + _reset_2D_masks(category, compass_corner1, compass_corner2) - for category in self.categories.get_children(): - _reset_3D_masks(category) + if self.categories.visible: + for category in self.categories.subcategories(): + _reset_3D_masks(category) func _reset_2D_masks(category2d: Node2D, compass_corner1, compass_corner2): for path2d in category2d.paths2d: @@ -482,11 +479,11 @@ func _unhandled_input(event): ################################################################################ func clear_map_markers(): # Clear all the rendered assets to make way for the new ones - for cateogry in self.categories.get_children(): - cateogry.queue_free() + for child in self.categories.get_children(): + child.queue_free() - for path2d in minimap.get_children(): - path2d.queue_free() + for child in self.minimap.get_children(): + child.queue_free() func init_category_tree(): self.marker_packs.clear() @@ -502,11 +499,7 @@ func waypoint_categories_to_godot_nodes(): _waypoint_categories_to_godot_nodes(null, waypoint_category, self.categories, self.minimap, false) -func _waypoint_categories_to_godot_nodes(item: TreeItem, waypoint_category, parent_category: Spatial, parent_category2d: Node2D, collapsed: bool): - if waypoint_category.get_name() == "": - # If this is called, there is an empty Category in the Waypoint data - print("Category found with no name.") - +func _waypoint_categories_to_godot_nodes(item: TreeItem, waypoint_category: Waypoint.Category, parent_category: Spatial, parent_category2d: Node2D, collapsed: bool): var godot_category = category_scene.instance() var godot_category2d = category2d_scene.instance() parent_category.add_subcategory(godot_category) @@ -519,7 +512,11 @@ func _waypoint_categories_to_godot_nodes(item: TreeItem, waypoint_category, pare category_data.category2d = godot_category2d category_item.set_metadata(0, category_data) - category_item.set_text(0, waypoint_category.get_name()) + if waypoint_category.get_name() == "": + print("Category found with no name.") + category_item.set_text(0, "No Name") + else: + category_item.set_text(0, waypoint_category.get_name()) category_item.set_cell_mode(1, TreeItem.CELL_MODE_CHECK) # TODO 214: The format for the category name stored here is a/b/c. # This could be changed to some UUID. @@ -635,7 +632,6 @@ func gen_new_icon(position: Vector3, texture_path: String, waypoint_icon, catego new_icon.set_icon_image(texture_path) new_icon.waypoint = waypoint_icon var category_data = category_item.get_metadata(0) - new_icon.visible = category_data.is_visible category_data.category.add_icon(new_icon) @@ -811,14 +807,14 @@ func _on_NewPath_pressed(): # Create a new icon and give it the texture ################################################################################ func _on_NewIcon_pressed(): - var waypoint_category = self.currently_active_category.get_metadata(0).waypoint_category + var waypoint_category: Waypoint.Category = self.currently_active_category.get_metadata(0).waypoint_category var waypoint_icon = waypoint_category.new_icon() gen_new_icon(self.player_position, self.next_texture_path, waypoint_icon, self.currently_active_category) # A new path point is created func _on_NewPathPoint_pressed(): if self.currently_active_path == null: - var waypoint_category = self.currently_active_category.get_metadata(0).waypoint_category + var waypoint_category: Waypoint.Category = self.currently_active_category.get_metadata(0).waypoint_category var waypoint_trail = waypoint_category.new_trail() gen_new_path([self.player_position], self.next_texture_path, waypoint_trail, self.currently_active_category) else: From cc1e2253b52a30b581d2dd8fa97a2fa0bb729265 Mon Sep 17 00:00:00 2001 From: klingbolt Date: Fri, 15 Dec 2023 18:25:17 -0500 Subject: [PATCH 08/10] Removing node from scene --- Spatial.tscn | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Spatial.tscn b/Spatial.tscn index 2cc9dc2e..180a85ad 100644 --- a/Spatial.tscn +++ b/Spatial.tscn @@ -1,9 +1,8 @@ -[gd_scene load_steps=19 format=2] +[gd_scene load_steps=18 format=2] [ext_resource path="res://Spatial.gd" type="Script" id=1] [ext_resource path="res://shaders/range_indicators.shader" type="Shader" id=2] [ext_resource path="res://burrito.png" type="Texture" id=3] -[ext_resource path="res://Route2D.tscn" type="PackedScene" id=4] [ext_resource path="res://icon_close.png" type="Texture" id=5] [ext_resource path="res://RangeDialog.gd" type="Script" id=6] [ext_resource path="res://icon_new_icon.png" type="Texture" id=7] @@ -76,8 +75,6 @@ material = SubResource( 2 ) scale = Vector2( 2, 2 ) script = ExtResource( 15 ) -[node name="Line2D" parent="Control/MiniMap" instance=ExtResource( 4 )] - [node name="GlobalMenuButton" type="Control" parent="Control"] margin_left = 323.0 margin_right = 349.0 From ce3d01ebf1f8455af1f0f8e38655c15b99f3a2cc Mon Sep 17 00:00:00 2001 From: klingbolt Date: Thu, 21 Dec 2023 00:10:27 -0500 Subject: [PATCH 09/10] Changed variable names of marker collections. Addressed other comments --- Category.gd => Category3D.gd | 0 Category.tscn => Category3D.tscn | 2 +- CategoryData.gd | 2 +- Spatial.gd | 115 ++++++++++++++++--------------- Spatial.tscn | 22 +++--- 5 files changed, 72 insertions(+), 69 deletions(-) rename Category.gd => Category3D.gd (100%) rename Category.tscn => Category3D.tscn (61%) diff --git a/Category.gd b/Category3D.gd similarity index 100% rename from Category.gd rename to Category3D.gd diff --git a/Category.tscn b/Category3D.tscn similarity index 61% rename from Category.tscn rename to Category3D.tscn index 397d2de9..83bf5edb 100644 --- a/Category.tscn +++ b/Category3D.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=2 format=2] -[ext_resource path="res://Category.gd" type="Script" id=1] +[ext_resource path="res://Category3D.gd" type="Script" id=1] [node name="Category" type="Spatial"] script = ExtResource( 1 ) diff --git a/CategoryData.gd b/CategoryData.gd index 8e307708..dfad8d30 100644 --- a/CategoryData.gd +++ b/CategoryData.gd @@ -1,6 +1,6 @@ const Waypoint = preload("res://waypoint.gd") -var category: Spatial +var category3d: Spatial var category2d: Node2D var waypoint_category: Waypoint.Category var is_visible = false diff --git a/Spatial.gd b/Spatial.gd index 64e11ace..d738bd3d 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -47,7 +47,7 @@ var is_transient:bool = false # Scenes used throughout this scene const route_scene = preload("res://Route.tscn") const icon_scene = preload("res://Icon.tscn") -const category_scene = preload("res://Category.tscn") +const category3d_scene = preload("res://Category3D.tscn") const category2d_scene = preload("res://Category2D.tscn") const path2d_scene = preload("res://Route2D.tscn") const gizmo_scene = preload("res://Gizmo/PointEdit.tscn") @@ -55,15 +55,15 @@ const CategoryData = preload("res://CategoryData.gd") const Waypoint = preload("res://waypoint.gd") ##########Node Connections########### -onready var marker_packs := $Control/Dialogs/MarkerPacks/MarkerPacks as Tree -onready var categories := $Categories as Spatial -onready var minimap := $Control/MiniMap as Node2D +onready var markers_ui := $Control/Dialogs/CategoriesDialog/MarkersUI as Tree +onready var markers_3d := $Markers3D as Spatial +onready var markers_2d := $Control/Markers2D as Node2D # Called when the node enters the scene tree for the first time. func _ready(): - self.marker_packs.set_column_expand(1, false) - self.marker_packs.set_column_min_width(1, 24) + self.markers_ui.set_column_expand(1, false) + self.markers_ui.set_column_min_width(1, 24) get_tree().get_root().set_transparent_background(true) x11_fg = X11_FG.new() taco_parser = TacoParser.new() @@ -231,8 +231,8 @@ func decode_frame_packet(spb: StreamPeerBuffer): var unchecked_flag = (ui_flags & 0xFFFFFF80) != 0x00000000; if map_is_open != map_was_open: - self.categories.visible = !map_is_open - reset_masks() + self.markers_3d.visible = !map_is_open + reset_minimap_masks(false) map_was_open = map_is_open if unchecked_flag: @@ -282,15 +282,15 @@ func decode_frame_packet(spb: StreamPeerBuffer): delta_position = player_map_position - Vector2(x, y); #print(map_rotation) - $Control/MiniMap.rotation = map_rotation + $Control/Markers2D.rotation = map_rotation else: - $Control/MiniMap.rotation = 0 + $Control/Markers2D.rotation = 0 var map_midpoint = map_size/2 + map_corner; - $Control/MiniMap.scale=Vector2(map_object_scaling, map_object_scaling) + $Control/Markers2D.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 + $Control/Markers2D.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 @@ -340,7 +340,7 @@ func decode_context_packet(spb: StreamPeerBuffer): print("Loading New Map") load_waypoint_markers(self.map_id) - reset_masks() + reset_minimap_masks() @@ -351,7 +351,7 @@ func decode_timeout_packet(spb: StreamPeerBuffer): launch_burrito_link() -func reset_masks(): +func reset_minimap_masks(reset_3d: bool = true): var viewport_size = get_viewport().size var compass_corner1 = Vector2(0, 0) var compass_corner2 = viewport_size @@ -362,27 +362,27 @@ func reset_masks(): compass_corner1 = viewport_size - Vector2(self.compass_width, self.compass_height) compass_corner2 = compass_corner1 + Vector2(self.compass_width, self.compass_height) - for category in self.minimap.subcategories(): - _reset_2D_masks(category, compass_corner1, compass_corner2) + for category in self.markers_2d.subcategories: + reset_2D_minimap_masks(category, compass_corner1, compass_corner2) - if self.categories.visible: - for category in self.categories.subcategories(): - _reset_3D_masks(category) + if reset_3d: + for category in self.markers_3d.subcategories: + reset_3D_minimap_masks(category) -func _reset_2D_masks(category2d: Node2D, compass_corner1, compass_corner2): +func reset_2D_minimap_masks(category2d: Node2D, compass_corner1: Vector2, compass_corner2: Vector2): for path2d in category2d.paths2d: path2d.material.set_shader_param("minimap_corner", compass_corner1) path2d.material.set_shader_param("minimap_corner2", compass_corner2) for subcategory in category2d.subcategories: - _reset_2D_masks(subcategory, compass_corner1, compass_corner2) + reset_2D_minimap_masks(subcategory, compass_corner1, compass_corner2) -func _reset_3D_masks(category: Spatial): +func reset_3D_minimap_masks(category: Spatial): for path in category.paths: path.get_node("MeshInstance").material_override.set_shader_param("map_size", Vector2(self.compass_width, self.compass_height)) for icon in category.icons: icon.material_override.set_shader_param("map_size", Vector2(self.compass_width, self.compass_height)) for subcategory in category.subcategories: - _reset_3D_masks(subcategory) + reset_3D_minimap_masks(subcategory) var waypoint_data = Waypoint.Waypoint.new() @@ -479,16 +479,16 @@ func _unhandled_input(event): ################################################################################ func clear_map_markers(): # Clear all the rendered assets to make way for the new ones - for child in self.categories.get_children(): + for child in self.markers_3d.get_children(): child.queue_free() - for child in self.minimap.get_children(): + for child in self.markers_2d.get_children(): child.queue_free() func init_category_tree(): - self.marker_packs.clear() + self.markers_ui.clear() var root : TreeItem - root = self.marker_packs.create_item() + root = self.markers_ui.create_item() root.set_text(0, "Markers") root.set_expand_right(0, true) @@ -496,32 +496,32 @@ func init_category_tree(): func waypoint_categories_to_godot_nodes(): for waypoint_category in self.waypoint_data.get_category(): - _waypoint_categories_to_godot_nodes(null, waypoint_category, self.categories, self.minimap, false) + _waypoint_categories_to_godot_nodes(null, waypoint_category, self.markers_3d, self.markers_2d, false) -func _waypoint_categories_to_godot_nodes(item: TreeItem, waypoint_category: Waypoint.Category, parent_category: Spatial, parent_category2d: Node2D, collapsed: bool): - var godot_category = category_scene.instance() +func _waypoint_categories_to_godot_nodes(item: TreeItem, waypoint_category: Waypoint.Category, parent_category3d: Spatial, parent_category2d: Node2D, collapsed: bool): + var godot_category3d = category3d_scene.instance() var godot_category2d = category2d_scene.instance() - parent_category.add_subcategory(godot_category) + parent_category3d.add_subcategory(godot_category3d) parent_category2d.add_subcategory(godot_category2d) - var category_item: TreeItem = self.marker_packs.create_item(item) + var category_item: TreeItem = self.markers_ui.create_item(item) var category_data = CategoryData.new() category_data.waypoint_category = waypoint_category - category_data.category = godot_category + category_data.category3d = godot_category3d category_data.category2d = godot_category2d category_item.set_metadata(0, category_data) - if waypoint_category.get_name() == "": + var category_name: String = waypoint_category.get_name() + if category_name == "": print("Category found with no name.") - category_item.set_text(0, "No Name") - else: - category_item.set_text(0, waypoint_category.get_name()) + category_name = "No Name" + category_item.set_text(0, category_name) category_item.set_cell_mode(1, TreeItem.CELL_MODE_CHECK) # TODO 214: The format for the category name stored here is a/b/c. # This could be changed to some UUID. - godot_category.name = waypoint_category.get_name() - var relative_path: String = self.categories.get_path_to(godot_category) + godot_category3d.name = category_name + var relative_path: String = self.markers_3d.get_path_to(godot_category3d) category_item.set_checked(1, Settings.local_category_data.get(relative_path, {}).get("checked", false)) category_item.set_tooltip(1, "Show/Hide") category_item.set_editable(1, true) @@ -529,19 +529,19 @@ func _waypoint_categories_to_godot_nodes(item: TreeItem, waypoint_category: Wayp category_item.set_selectable(1, false) category_data.is_visible = category_item.is_checked(1) - godot_category.visible = category_data.is_visible + godot_category3d.visible = category_data.is_visible godot_category2d.visible = category_data.is_visible for path in waypoint_category.get_trail(): var path_points := PoolVector3Array() var trail_data = path.get_trail_data() if trail_data.get_points_x().size() != trail_data.get_points_y().size() or trail_data.get_points_x().size() != trail_data.get_points_z().size(): - print("Warning: Trail ", waypoint_category.get_name(), " does not have equal number of X, Y, and Z coordinates.") + print("Warning: Trail ", category_name, " does not have equal number of X, Y, and Z coordinates.") for index in range(0, trail_data.get_points_z().size()): path_points.append(Vector3(trail_data.get_points_x()[index], trail_data.get_points_y()[index], trail_data.get_points_z()[index])) var texture_path = path.get_texture_path() if texture_path == null: - print("Warning: No texture found in " , waypoint_category.get_name()) + print("Warning: No texture found in " , category_name) continue var full_texture_path = self.marker_file_dir + texture_path.get_path() gen_new_path(path_points, full_texture_path, path, category_item) @@ -550,23 +550,23 @@ func _waypoint_categories_to_godot_nodes(item: TreeItem, waypoint_category: Wayp for icon in waypoint_category.get_icon(): var position = icon.get_position() if position == null: - print("Warning: No position found for icon ", waypoint_category.get_name()) + print("Warning: No position found for icon ", category_name) continue var position_vector = Vector3(position.get_x(), position.get_y(), position.get_z()) var texture_path = icon.get_texture_path() if texture_path == null: - print("Warning: No texture found in " , waypoint_category.get_name()) + print("Warning: No texture found in " , category_name) continue var full_texture_path = self.marker_file_dir + texture_path.get_path() gen_new_icon(position_vector, full_texture_path, icon, category_item) for category_child in waypoint_category.get_children(): - _waypoint_categories_to_godot_nodes(category_item, category_child, godot_category, godot_category2d, true) + _waypoint_categories_to_godot_nodes(category_item, category_child, godot_category3d, godot_category2d, true) func apply_category_visibility_to_nodes(category_item: TreeItem): var category_data = category_item.get_metadata(0) - var relative_path: String = self.categories.get_path_to(category_data.category) + var relative_path: String = self.markers_3d.get_path_to(category_data.category3d) # TODO 214: The format for the category name stored here is a/b/c. # This could be changed to some UUID. Settings.local_category_data[relative_path] = { @@ -575,7 +575,7 @@ func apply_category_visibility_to_nodes(category_item: TreeItem): Settings.save() category_data.is_visible = category_item.is_checked(1) - category_data.category.visible = category_data.is_visible + category_data.category3d.visible = category_data.is_visible category_data.category2d.visible = category_data.is_visible @@ -609,7 +609,7 @@ func gen_new_path(points: Array, texture_path: String, waypoint_trail, category_ new_route.set_texture(texture) new_route.waypoint = waypoint_trail var category_data = category_item.get_metadata(0) - category_data.category.add_path(new_route) + category_data.category3d.add_path(new_route) # Create a new 2D Path @@ -632,7 +632,7 @@ func gen_new_icon(position: Vector3, texture_path: String, waypoint_icon, catego new_icon.set_icon_image(texture_path) new_icon.waypoint = waypoint_icon var category_data = category_item.get_metadata(0) - category_data.category.add_icon(new_icon) + category_data.category3d.add_icon(new_icon) # This function take all of the currently rendered objects and converts it into @@ -680,7 +680,7 @@ func gen_adjustment_nodes(): print("No category selected") return - var category = self.currently_active_category.get_metadata(0).category + var category = self.currently_active_category.get_metadata(0).category3d var category2d = self.currently_active_category.get_metadata(0).category2d for index in category.paths.size(): var route = category.paths[index] @@ -755,10 +755,10 @@ func _on_Dialog_hide(): func _on_LoadPath_pressed(): - if $Control/Dialogs/MarkerPacks.is_visible(): - $Control/Dialogs/MarkerPacks.hide() + if $Control/Dialogs/CategoriesDialog.is_visible(): + $Control/Dialogs/CategoriesDialog.hide() else: - $Control/Dialogs/MarkerPacks.show() + $Control/Dialogs/CategoriesDialog.show() func _on_RangesButton_pressed(): @@ -920,11 +920,12 @@ func _on_Settings_pressed(): settings_dialog.show() -func _on_MarkerPacks_cell_selected(): - var category_item = self.marker_packs.get_selected() +func _on_MarkersUI_cell_selected(): + var category_item = self.markers_ui.get_selected() self.currently_active_category = category_item -func _on_MarkerPacks_item_edited(): - var category_item = self.marker_packs.get_edited() +func _on_MarkersUI_item_edited(): + var category_item = self.markers_ui.get_edited() apply_category_visibility_to_nodes(category_item) + diff --git a/Spatial.tscn b/Spatial.tscn index 180a85ad..a661e21b 100644 --- a/Spatial.tscn +++ b/Spatial.tscn @@ -11,7 +11,7 @@ [ext_resource path="res://icon_new_path.png" type="Texture" id=10] [ext_resource path="res://icon_new_point.png" type="Texture" id=11] [ext_resource path="res://SettingsDialog.gd" type="Script" id=12] -[ext_resource path="res://Category.gd" type="Script" id=13] +[ext_resource path="res://Category3D.gd" type="Script" id=13] [ext_resource path="res://Category2D.gd" type="Script" id=15] [sub_resource type="Shader" id=1] @@ -51,7 +51,7 @@ shader_param/custom_7_value = 500.0 [node name="Spatial" type="Spatial"] script = ExtResource( 1 ) -[node name="Categories" type="Spatial" parent="."] +[node name="Markers3D" type="Spatial" parent="."] script = ExtResource( 13 ) [node name="Gizmos" type="Spatial" parent="."] @@ -70,7 +70,7 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="MiniMap" type="Node2D" parent="Control"] +[node name="Markers2D" type="Node2D" parent="Control"] material = SubResource( 2 ) scale = Vector2( 2, 2 ) script = ExtResource( 15 ) @@ -774,7 +774,7 @@ margin_right = 384.0 margin_bottom = 304.0 text = "Load Lutris Profile" -[node name="MarkerPacks" type="WindowDialog" parent="Control/Dialogs"] +[node name="CategoriesDialog" type="WindowDialog" parent="Control/Dialogs"] margin_left = 280.0 margin_top = 105.0 margin_right = 751.0 @@ -784,7 +784,7 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="MarkerPacks" type="Tree" parent="Control/Dialogs/MarkerPacks"] +[node name="MarkersUI" type="Tree" parent="Control/Dialogs/CategoriesDialog"] anchor_right = 1.0 anchor_bottom = 1.0 size_flags_vertical = 3 @@ -922,8 +922,10 @@ material/0 = SubResource( 4 ) [connection signal="pressed" from="Control/Dialogs/SettingsDialog/ScrollContainer/GridContainer/AutoLaunchBurritoLink" to="Control/Dialogs/SettingsDialog" method="save_settings"] [connection signal="text_changed" from="Control/Dialogs/SettingsDialog/ScrollContainer/GridContainer/WinePath" to="Control/Dialogs/SettingsDialog" method="save_settings"] [connection signal="text_changed" from="Control/Dialogs/SettingsDialog/ScrollContainer/GridContainer/EnvironmentVars" to="Control/Dialogs/SettingsDialog" method="save_settings"] -[connection signal="hide" from="Control/Dialogs/MarkerPacks" to="." method="_on_Dialog_hide"] -[connection signal="cell_selected" from="Control/Dialogs/MarkerPacks/MarkerPacks" to="." method="_on_MarkerPacks_cell_selected"] -[connection signal="item_edited" from="Control/Dialogs/MarkerPacks/MarkerPacks" to="." method="_on_MarkerPacks_item_edited"] -[connection signal="multi_selected" from="Control/Dialogs/MarkerPacks/MarkerPacks" to="." method="_on_Tree_multi_selected"] -[connection signal="tree_entered" from="Control/Dialogs/MarkerPacks/MarkerPacks" to="." method="_on_Tree_tree_entered"] +[connection signal="hide" from="Control/Dialogs/CategoriesDialog" to="." method="_on_Dialog_hide"] +[connection signal="cell_selected" from="Control/Dialogs/CategoriesDialog/MarkersUI" to="." method="_on_MarkerPacks_cell_selected"] +[connection signal="cell_selected" from="Control/Dialogs/CategoriesDialog/MarkersUI" to="." method="_on_MarkersUI_cell_selected"] +[connection signal="item_edited" from="Control/Dialogs/CategoriesDialog/MarkersUI" to="." method="_on_MarkerPacks_item_edited"] +[connection signal="item_edited" from="Control/Dialogs/CategoriesDialog/MarkersUI" to="." method="_on_MarkersUI_item_edited"] +[connection signal="multi_selected" from="Control/Dialogs/CategoriesDialog/MarkersUI" to="." method="_on_Tree_multi_selected"] +[connection signal="tree_entered" from="Control/Dialogs/CategoriesDialog/MarkersUI" to="." method="_on_Tree_tree_entered"] From 2dcb0f4febbe0e6cd0ee9a0ee8d8da74cb2bc406 Mon Sep 17 00:00:00 2001 From: klingbolt Date: Thu, 21 Dec 2023 21:54:14 -0500 Subject: [PATCH 10/10] Missed some changes --- Spatial.gd | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Spatial.gd b/Spatial.gd index d738bd3d..25350832 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -680,10 +680,10 @@ func gen_adjustment_nodes(): print("No category selected") return - var category = self.currently_active_category.get_metadata(0).category3d + var category3d = self.currently_active_category.get_metadata(0).category3d var category2d = self.currently_active_category.get_metadata(0).category2d - for index in category.paths.size(): - var route = category.paths[index] + for index in category3d.paths.size(): + var route = category3d.paths[index] var path2d = category2d.paths2d[index] for i in range(route.get_point_count()): var gizmo_position = route.get_point_position(i) @@ -698,7 +698,7 @@ func gen_adjustment_nodes(): new_gizmo.connect("selected", self, "on_gizmo_selected") new_gizmo.connect("deselected", self, "on_gizmo_deselected") $Gizmos.add_child(new_gizmo) - for icon in category.icons: + for icon in category3d.icons: var new_gizmo = gizmo_scene.instance() new_gizmo.translation = icon.translation new_gizmo.link_point("icon", icon)