Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated gdscript code to reflect proto changes. #233

Merged
merged 10 commits into from
Dec 29, 2023
File renamed without changes.
2 changes: 1 addition & 1 deletion Category.tscn → Category3D.tscn
Original file line number Diff line number Diff line change
@@ -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 )
2 changes: 1 addition & 1 deletion CategoryData.gd
Original file line number Diff line number Diff line change
@@ -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
115 changes: 58 additions & 57 deletions Spatial.gd
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@ 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")
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()
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()



Expand All @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -479,69 +479,69 @@ 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)



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)
category_item.set_collapsed(collapsed)
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)
Expand All @@ -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] = {
Expand All @@ -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


Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3d?

var category2d = self.currently_active_category.get_metadata(0).category2d
for index in category.paths.size():
var route = category.paths[index]
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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)

22 changes: 12 additions & 10 deletions Spatial.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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="."]
Expand All @@ -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 )
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"]