diff --git a/scenes/controls_panel.tscn b/scenes/controls_panel.tscn new file mode 100644 index 0000000..9199215 --- /dev/null +++ b/scenes/controls_panel.tscn @@ -0,0 +1,190 @@ +[gd_scene load_steps=4 format=3 uid="uid://bqjnp7uypupog"] + +[ext_resource type="FontFile" uid="uid://d0cxd77jybrcn" path="res://fonts/lilita_one_regular.ttf" id="1_tnlhn"] +[ext_resource type="Script" path="res://scripts/controls_panel.gd" id="1_xyuqg"] + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_f2mso"] +bg_color = Color(0.145098, 0.172549, 0.231373, 0.941176) +border_width_left = 2 +border_width_top = 2 +border_width_right = 2 +border_width_bottom = 2 +border_color = Color(0.356863, 0.670588, 0.768627, 1) +corner_radius_top_left = 8 +corner_radius_top_right = 8 +corner_radius_bottom_right = 8 +corner_radius_bottom_left = 8 +shadow_size = 5 +shadow_offset = Vector2(2, 2) + +[node name="ControlsPanel" type="PanelContainer"] +process_mode = 3 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -500.0 +offset_top = -300.0 +offset_right = 500.0 +offset_bottom = 300.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_styles/panel = SubResource("StyleBoxFlat_f2mso") +script = ExtResource("1_xyuqg") + +[node name="MarginContainer" type="MarginContainer" parent="."] +layout_mode = 2 +theme_override_constants/margin_left = 30 +theme_override_constants/margin_top = 30 +theme_override_constants/margin_right = 30 +theme_override_constants/margin_bottom = 30 + +[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"] +layout_mode = 2 +theme_override_constants/separation = 20 + +[node name="TitleLabel" type="Label" parent="MarginContainer/VBoxContainer"] +layout_mode = 2 +theme_override_fonts/font = ExtResource("1_tnlhn") +theme_override_font_sizes/font_size = 36 +text = "Game Controls" +horizontal_alignment = 1 + +[node name="HSeparator" type="HSeparator" parent="MarginContainer/VBoxContainer"] +layout_mode = 2 + +[node name="ScrollContainer" type="ScrollContainer" parent="MarginContainer/VBoxContainer"] +layout_mode = 2 +size_flags_vertical = 3 + +[node name="ControlsGrid" type="GridContainer" parent="MarginContainer/VBoxContainer/ScrollContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 +theme_override_constants/h_separation = 40 +theme_override_constants/v_separation = 20 +columns = 2 + +[node name="CameraMovementLabel" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/ControlsGrid"] +layout_mode = 2 +theme_override_font_sizes/font_size = 22 +text = "Camera Movement:" + +[node name="CameraMovementValue" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/ControlsGrid"] +layout_mode = 2 +theme_override_font_sizes/font_size = 20 +text = "W, A, S, D keys" + +[node name="CameraRotationLabel" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/ControlsGrid"] +layout_mode = 2 +theme_override_font_sizes/font_size = 22 +text = "Camera Rotation:" + +[node name="CameraRotationValue" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/ControlsGrid"] +layout_mode = 2 +theme_override_font_sizes/font_size = 20 +text = "Hold Middle Mouse Button + Move Mouse" + +[node name="CameraCenterLabel" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/ControlsGrid"] +layout_mode = 2 +theme_override_font_sizes/font_size = 22 +text = "Center Camera:" + +[node name="CameraCenterValue" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/ControlsGrid"] +layout_mode = 2 +theme_override_font_sizes/font_size = 20 +text = "F key" + +[node name="PlaceBuildingLabel" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/ControlsGrid"] +layout_mode = 2 +theme_override_font_sizes/font_size = 22 +text = "Place Building/Road:" + +[node name="PlaceBuildingValue" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/ControlsGrid"] +layout_mode = 2 +theme_override_font_sizes/font_size = 20 +text = "Left Mouse Button" + +[node name="DemolishLabel" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/ControlsGrid"] +layout_mode = 2 +theme_override_font_sizes/font_size = 22 +text = "Demolish Structure:" + +[node name="DemolishValue" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/ControlsGrid"] +layout_mode = 2 +theme_override_font_sizes/font_size = 20 +text = "Delete key" + +[node name="RotateStructureLabel" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/ControlsGrid"] +layout_mode = 2 +theme_override_font_sizes/font_size = 22 +text = "Rotate Structure:" + +[node name="RotateStructureValue" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/ControlsGrid"] +layout_mode = 2 +theme_override_font_sizes/font_size = 20 +text = "Right Mouse Button" + +[node name="NextStructureLabel" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/ControlsGrid"] +layout_mode = 2 +theme_override_font_sizes/font_size = 22 +text = "Next Structure:" + +[node name="NextStructureValue" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/ControlsGrid"] +layout_mode = 2 +theme_override_font_sizes/font_size = 20 +text = "E key" + +[node name="PrevStructureLabel" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/ControlsGrid"] +layout_mode = 2 +theme_override_font_sizes/font_size = 22 +text = "Previous Structure:" + +[node name="PrevStructureValue" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/ControlsGrid"] +layout_mode = 2 +theme_override_font_sizes/font_size = 20 +text = "Q key" + +[node name="SaveLabel" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/ControlsGrid"] +layout_mode = 2 +theme_override_font_sizes/font_size = 22 +text = "Save City:" + +[node name="SaveValue" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/ControlsGrid"] +layout_mode = 2 +theme_override_font_sizes/font_size = 20 +text = "F9 key" + +[node name="LoadLabel" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/ControlsGrid"] +layout_mode = 2 +theme_override_font_sizes/font_size = 22 +text = "Load City:" + +[node name="LoadValue" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/ControlsGrid"] +layout_mode = 2 +theme_override_font_sizes/font_size = 20 +text = "F10 key" + +[node name="DisplayControlsLabel" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/ControlsGrid"] +layout_mode = 2 +theme_override_font_sizes/font_size = 22 +text = "Show Controls:" + +[node name="DisplayControlsValue" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/ControlsGrid"] +layout_mode = 2 +theme_override_font_sizes/font_size = 20 +text = "Click on '?' button" + +[node name="CloseButtonContainer" type="HBoxContainer" parent="MarginContainer/VBoxContainer"] +layout_mode = 2 +alignment = 1 + +[node name="CloseButton" type="Button" parent="MarginContainer/VBoxContainer/CloseButtonContainer"] +custom_minimum_size = Vector2(150, 50) +layout_mode = 2 +theme_override_fonts/font = ExtResource("1_tnlhn") +theme_override_font_sizes/font_size = 20 +text = "Close" + +[connection signal="pressed" from="MarginContainer/VBoxContainer/CloseButtonContainer/CloseButton" to="." method="_on_close_button_pressed"] \ No newline at end of file diff --git a/scenes/hud.tscn b/scenes/hud.tscn index e6b9814..4d5482e 100644 --- a/scenes/hud.tscn +++ b/scenes/hud.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=8 format=3 uid="uid://cgk66f6rg03mj"] +[gd_scene load_steps=9 format=3 uid="uid://cgk66f6rg03mj"] [ext_resource type="Script" path="res://scripts/hud_manager.gd" id="1_6vdxc"] [ext_resource type="Texture2D" uid="uid://hendpftbt4iw" path="res://sprites/population_icon.png" id="2_28oy1"] [ext_resource type="Texture2D" uid="uid://jk3mremfu7lm" path="res://sprites/electricity_icon.png" id="3_2u5bk"] [ext_resource type="FontFile" uid="uid://d0cxd77jybrcn" path="res://fonts/lilita_one_regular.ttf" id="4_qfmf5"] [ext_resource type="Texture2D" uid="uid://bng0d1sou7c8a" path="res://sprites/coin.png" id="5_vd1bj"] +[ext_resource type="Texture2D" uid="uid://cgpwknjrqnuae" path="res://sprites/help_icon.png" id="6_i1y88"] [sub_resource type="LabelSettings" id="LabelSettings_q176i"] font = ExtResource("4_qfmf5") @@ -30,6 +31,7 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +mouse_filter = 0 script = ExtResource("1_6vdxc") [node name="HBoxContainer" type="HBoxContainer" parent="."] @@ -42,10 +44,12 @@ offset_right = -20.0 offset_bottom = 84.0 grow_horizontal = 2 scale = Vector2(0.8, 0.8) +mouse_filter = 0 theme_override_constants/separation = 40 [node name="CashItem" type="HBoxContainer" parent="HBoxContainer"] layout_mode = 2 +mouse_filter = 0 theme_override_constants/separation = 8 [node name="CashIcon" type="TextureRect" parent="HBoxContainer/CashItem"] @@ -65,6 +69,7 @@ theme_override_constants/separation = 10 [node name="PopulationItem" type="HBoxContainer" parent="HBoxContainer"] layout_mode = 2 +mouse_filter = 0 theme_override_constants/separation = 8 [node name="PopulationIcon" type="TextureRect" parent="HBoxContainer/PopulationItem"] @@ -84,6 +89,7 @@ theme_override_constants/separation = 10 [node name="ElectricityItem" type="HBoxContainer" parent="HBoxContainer"] layout_mode = 2 +mouse_filter = 0 theme_override_constants/separation = 8 [node name="ElectricityIcon" type="TextureRect" parent="HBoxContainer/ElectricityItem"] @@ -109,6 +115,25 @@ layout_mode = 2 size_flags_horizontal = 4 color = Color(1, 0, 0, 1) +[node name="Separator3" type="VSeparator" parent="HBoxContainer"] +layout_mode = 2 +theme_override_constants/separation = 10 + +[node name="HelpItem" type="HBoxContainer" parent="HBoxContainer"] +layout_mode = 2 +mouse_filter = 0 +theme_override_constants/separation = 8 + +[node name="HelpButton" type="TextureButton" parent="HBoxContainer/HelpItem"] +custom_minimum_size = Vector2(40, 40) +layout_mode = 2 +size_flags_vertical = 4 +mouse_filter = 0 +mouse_default_cursor_shape = 2 +texture_normal = ExtResource("6_i1y88") +ignore_texture_size = true +stretch_mode = 5 + [node name="PopulationTooltip" type="Control" parent="."] visible = false layout_mode = 1 @@ -163,3 +188,4 @@ autowrap_mode = 3 [connection signal="mouse_exited" from="HBoxContainer/PopulationItem/PopulationIcon" to="." method="_on_population_icon_mouse_exited"] [connection signal="mouse_entered" from="HBoxContainer/ElectricityItem/ElectricityIcon" to="." method="_on_electricity_icon_mouse_entered"] [connection signal="mouse_exited" from="HBoxContainer/ElectricityItem/ElectricityIcon" to="." method="_on_electricity_icon_mouse_exited"] +[connection signal="pressed" from="HBoxContainer/HelpItem/HelpButton" to="." method="_on_help_button_pressed"] diff --git a/scenes/main.tscn b/scenes/main.tscn index fa82a93..df9d178 100644 --- a/scenes/main.tscn +++ b/scenes/main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=24 format=3 uid="uid://vgwrcfy1qawf"] +[gd_scene load_steps=26 format=3 uid="uid://vgwrcfy1qawf"] [ext_resource type="Script" path="res://scripts/builder.gd" id="1_jybm7"] [ext_resource type="Environment" uid="uid://jbptgqvstei3" path="res://scenes/main-environment.tres" id="1_yndf3"] @@ -19,6 +19,8 @@ [ext_resource type="FontFile" uid="uid://d0cxd77jybrcn" path="res://fonts/lilita_one_regular.ttf" id="17_vlub6"] [ext_resource type="PackedScene" uid="uid://b4gkfwf4i3ydl" path="res://scenes/character.tscn" id="18_8lrh8"] [ext_resource type="PackedScene" uid="uid://cgk66f6rg03mj" path="res://scenes/hud.tscn" id="18_hud"] +[ext_resource type="PackedScene" uid="uid://bqjnp7uypupog" path="res://scenes/controls_panel.tscn" id="19_controls"] +[ext_resource type="Script" path="res://scripts/game_manager.gd" id="20_game_manager"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_mission"] bg_color = Color(0.145098, 0.172549, 0.231373, 0.941176) @@ -73,6 +75,7 @@ corner_radius_bottom_right = 4 corner_radius_bottom_left = 4 [node name="Main" type="Node3D"] +script = ExtResource("20_game_manager") [node name="Builder" type="Node3D" parent="." node_paths=PackedStringArray("selector", "selector_container", "view_camera", "gridmap", "cash_display")] script = ExtResource("1_jybm7") @@ -115,6 +118,8 @@ shadow_opacity = 0.75 [node name="HUD" parent="CanvasLayer" instance=ExtResource("18_hud")] +[node name="ControlsPanel" parent="CanvasLayer" instance=ExtResource("19_controls")] + [node name="MissionManager" type="Node" parent="." node_paths=PackedStringArray("mission_ui", "builder")] script = ExtResource("10_oe3re") missions = Array[ExtResource("11_msovb")]([ExtResource("12_ms7i7"), ExtResource("13_s13s0"), ExtResource("14_bnke0"), ExtResource("15_plrw2"), ExtResource("16_5fmk3")]) diff --git a/scripts/builder.gd b/scripts/builder.gd index 69c8137..6d4e4fc 100644 --- a/scripts/builder.gd +++ b/scripts/builder.gd @@ -70,9 +70,9 @@ func _ready(): update_cash() func _process(delta): - # Skip all building functionality if disabled - if disabled: - # Hide selector when disabled + # Skip all building functionality if disabled or game is paused + if disabled or get_tree().paused: + # Hide selector when disabled or paused if selector.visible: selector.visible = false return @@ -99,6 +99,43 @@ func _process(delta): action_build(gridmap_position) action_demolish(gridmap_position) +# Function to check if the mouse is over any UI elements +func is_mouse_over_ui() -> bool: + # Get the viewport + var viewport = get_viewport() + if not viewport: + return false + + # Get mouse position + var mouse_pos = viewport.get_mouse_position() + + # Check if mouse is over any UI elements + # Find the HUD node + var hud = get_node_or_null("/root/Main/CanvasLayer/HUD") + if hud and hud.get_global_rect().has_point(mouse_pos): + print("Mouse over HUD") + return true + + # Also check if mouse is over mission panel + var mission_panel = get_node_or_null("/root/Main/MissionManager/MissionPanel") + if mission_panel and mission_panel.visible and mission_panel.get_global_rect().has_point(mouse_pos): + print("Mouse over mission panel") + return true + + # Check learning panel too + var learning_panel = get_node_or_null("/root/Main/MissionManager/LearningPanel") + if learning_panel and learning_panel.visible and learning_panel.get_global_rect().has_point(mouse_pos): + print("Mouse over learning panel") + return true + + # Check controls panel + var controls_panel = get_node_or_null("/root/Main/CanvasLayer/ControlsPanel") + if controls_panel and controls_panel.visible and controls_panel.get_global_rect().has_point(mouse_pos): + print("Mouse over controls panel") + return true + + return false + # Retrieve the mesh from a PackedScene, used for dynamically creating a MeshLibrary func get_mesh(packed_scene): @@ -141,6 +178,9 @@ func find_mesh_instance(node): func action_build(gridmap_position): if Input.is_action_just_pressed("build"): + # Check if the mouse is over any UI elements before building + if is_mouse_over_ui(): + return var previous_tile = gridmap.get_cell_item(gridmap_position) @@ -244,6 +284,10 @@ signal structure_removed(structure_index, position) func action_demolish(gridmap_position): if Input.is_action_just_pressed("demolish"): + # Check if the mouse is over any UI elements + if is_mouse_over_ui(): + return + # Check if there's a road at this position var is_road = false var road_name = "Road_" + str(int(gridmap_position.x)) + "_" + str(int(gridmap_position.z)) diff --git a/scripts/controls_panel.gd b/scripts/controls_panel.gd new file mode 100644 index 0000000..83693f1 --- /dev/null +++ b/scripts/controls_panel.gd @@ -0,0 +1,29 @@ +extends PanelContainer + +signal closed + +func _ready(): + # Hide the panel initially - it will be shown when the game starts + # or when the question mark button is clicked + visible = false + + # Make sure this control blocks mouse input from passing through + mouse_filter = Control.MOUSE_FILTER_STOP + +func show_panel(): + visible = true + # Pause the game (optional, depending on desired behavior) + get_tree().paused = true + +func hide_panel(): + visible = false + # Resume the game + get_tree().paused = false + +func _on_close_button_pressed(): + hide_panel() + # Emit signal that panel was closed + closed.emit() + + # Consume the event to prevent click-through + get_viewport().set_input_as_handled() \ No newline at end of file diff --git a/scripts/game_manager.gd b/scripts/game_manager.gd new file mode 100644 index 0000000..d544fcb --- /dev/null +++ b/scripts/game_manager.gd @@ -0,0 +1,22 @@ +extends Node + +# This script handles overall game management tasks + +func _ready(): + # Reference to the controls panel and HUD + var controls_panel = $CanvasLayer/ControlsPanel + var hud = $CanvasLayer/HUD + + # Set up the HUD's reference to the controls panel + hud.controls_panel = controls_panel + + # Auto-show controls at start + if controls_panel: + controls_panel.show_panel() + + # Connect the closed signal to handle when player closes the controls + controls_panel.closed.connect(_on_controls_panel_closed) + +# This function is called when the controls panel is closed +func _on_controls_panel_closed(): + print("Controls panel closed by player") \ No newline at end of file diff --git a/scripts/hud_manager.gd b/scripts/hud_manager.gd index 6703ab3..4f13a35 100644 --- a/scripts/hud_manager.gd +++ b/scripts/hud_manager.gd @@ -16,6 +16,7 @@ var electricity_label: Label var electricity_indicator: ColorRect var population_tooltip: Control var electricity_tooltip: Control +var controls_panel: PanelContainer func _ready(): # Connect to signals from the builder @@ -169,3 +170,11 @@ func _on_electricity_icon_mouse_entered(): func _on_electricity_icon_mouse_exited(): if electricity_tooltip: electricity_tooltip.visible = false + +# Called when the help button is pressed +func _on_help_button_pressed(): + # Consume the event to prevent click-through to the world + get_viewport().set_input_as_handled() + + if controls_panel: + controls_panel.show_panel() diff --git a/sprites/help_icon.png b/sprites/help_icon.png new file mode 100644 index 0000000..449b64d Binary files /dev/null and b/sprites/help_icon.png differ diff --git a/sprites/help_icon.png.import b/sprites/help_icon.png.import new file mode 100644 index 0000000..10a156a --- /dev/null +++ b/sprites/help_icon.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cgpwknjrqnuae" +path="res://.godot/imported/help_icon.png-699c955d925642d964042e5e30ee4511.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://sprites/help_icon.png" +dest_files=["res://.godot/imported/help_icon.png-699c955d925642d964042e5e30ee4511.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1