Merge pull request #29 from STEMuli-Tx/main

Update
pull/18/head
mrwadepro 2025-05-08 16:05:30 +07:00 committed by GitHub
commit 15f1b3b32a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 81 additions and 20 deletions

@ -118,6 +118,11 @@ camera_center={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":70,"key_label":0,"unicode":102,"location":0,"echo":false,"script":null)
]
}
clear_selection={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
[rendering]

@ -106,6 +106,16 @@ layout_mode = 2
theme_override_font_sizes/font_size = 20
text = "Left Mouse Button"
[node name="ClearSelectionLabel" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/ControlsGrid"]
layout_mode = 2
theme_override_font_sizes/font_size = 22
text = "Clear Current Selection:"
[node name="ClearSelectionValue" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/ControlsGrid"]
layout_mode = 2
theme_override_font_sizes/font_size = 20
text = "Escape Key"
[node name="DemolishLabel" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/ControlsGrid"]
layout_mode = 2
theme_override_font_sizes/font_size = 22

@ -58,6 +58,7 @@ show_mission_select = true
layout_mode = 0
offset_right = 1410.0
offset_bottom = 90.0
scale = Vector2(0.8, 0.8)
theme_override_styles/panel = SubResource("StyleBoxFlat_0m4u7")
[node name="HBoxContainer" type="HBoxContainer" parent="PanelContainer"]

@ -181,8 +181,8 @@ visible = false
[node name="StickyBuilder" parent="CanvasLayer" instance=ExtResource("25_qkpxi")]
offset_left = 7.0
offset_top = 124.0
offset_right = -2.0
offset_bottom = -23.0
offset_right = 162.0
offset_bottom = 364.0
[node name="MissionManager" type="Node" parent="." node_paths=PackedStringArray("mission_ui", "builder")]
script = ExtResource("10_oe3re")
@ -195,10 +195,12 @@ character_scene = ExtResource("18_8lrh8")
anchors_preset = 1
anchor_left = 1.0
anchor_right = 1.0
offset_left = -450.0
offset_left = -487.365
offset_top = 20.0
offset_right = -20.0
offset_right = -57.365
offset_bottom = 203.0
grow_horizontal = 0
scale = Vector2(1.1, 1.1)
size_flags_vertical = 0
theme_override_styles/panel = SubResource("StyleBoxFlat_mission")
script = ExtResource("13_xvw5w")

@ -12,11 +12,9 @@
[node name="StickyBuilder" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
anchors_preset = 0
offset_right = 155.0
offset_bottom = 240.0
[node name="Panel" type="Panel" parent="."]
layout_mode = 0

@ -31,6 +31,9 @@ var invalid_placement_material: StandardMaterial3D
# Central structure management
var _structures: Array[Structure] = []
# Variable to track selection state
var selectionEnabled: bool = false;
# Getter for structures that ensures deduplication
func get_structures() -> Array[Structure]:
return _structures
@ -145,14 +148,6 @@ func _ready():
update_cash()
# Override the setter for structures to ensure deduplication
func _set_structures(new_structures: Array[Structure]) -> void:
structures = new_structures
_deduplicate_structures()
# Update construction manager with deduplicated structures
if construction_manager:
construction_manager.structures = structures
# Function to add a structure to the array
func add_structure(structure: Structure) -> void:
structures.append(structure)
@ -178,8 +173,11 @@ func _process(delta):
return
# Make sure selector is visible
if !selector.visible:
if !selector.visible and selectionEnabled:
selector.visible = true
#Check for clear selection key press
action_clear_selection()
# Controls
action_rotate() # Rotates selection 90 degrees
@ -223,6 +221,10 @@ func is_mouse_over_ui() -> bool:
var panel_rect = building_selector.selection_panel.get_global_rect()
if panel_rect.has_point(mouse_pos):
return true
# Check sticky builder panel UI overlaps
if is_mouse_over_sticky_builder():
return true
# Let's try an extremely simple approach - just check coordinates
# most HUDs are at top of screen
@ -269,6 +271,35 @@ func is_mouse_over_ui() -> bool:
return false
func is_mouse_over_sticky_builder() -> bool:
var sticky_builder = get_node_or_null("/root/Main/CanvasLayer/StickyBuilder")
if not sticky_builder:
return false
var mouse_pos = get_viewport().get_mouse_position()
return _check_visible_controls(sticky_builder, mouse_pos)
# Helper function to check a node and it's control children's overlap with mouse position
func _check_visible_controls(node: Node, mouse_pos: Vector2) -> bool:
if node is Control and node.is_visible_in_tree():
if node.get_global_rect().has_point(mouse_pos):
return true
# check for popups
if "get_popup" in node and node.has_method("get_popup"):
var popup = node.get_popup()
if popup and popup is PopupMenu and popup.visible:
var popup_pos = popup.position
var popup_rect = Rect2(popup_pos, popup.size)
if popup_rect.has_point(mouse_pos):
return true
for child in node.get_children():
if _check_visible_controls(child, mouse_pos):
return true
return false
# Retrieve the mesh from a PackedScene, used for dynamically creating a MeshLibrary
func get_mesh(packed_scene):
@ -311,6 +342,10 @@ func find_mesh_instance(node):
func action_build(gridmap_position, can_place: bool):
if Input.is_action_just_pressed("build"):
#Check if selection is on
if(not selectionEnabled):
return
# Check if the mouse is over any UI elements before building
if is_mouse_over_ui():
return
@ -528,8 +563,17 @@ func remove_navigation_region(position: Vector3):
# Rotates the 'cursor' 90 degrees
func action_rotate():
if Input.is_action_just_pressed("rotate"):
if Input.is_action_just_pressed("rotate") and selectionEnabled:
selector.rotate_y(deg_to_rad(90))
# Clear current building selection
func action_clear_selection():
if Input.is_action_just_pressed("clear_selection"):
selectionEnabled = false
if selector:
selector.visible = false
index = -1
# Toggle between structures to build
@ -544,6 +588,7 @@ func action_structure_toggle(structure:Structure):
print("No structure found!")
else:
index = found_index
selectionEnabled = true
update_structure()
@ -1168,7 +1213,7 @@ func _on_structures_unlocked():
selector.visible = false
else:
# Show the selector since we have a structure to place
if selector:
if selector and selectionEnabled:
selector.visible = true
update_structure()