diff --git a/art/backgrounds/mainmenu_background.png b/art/backgrounds/mainmenu_background.png new file mode 100644 index 0000000..8ea1e38 Binary files /dev/null and b/art/backgrounds/mainmenu_background.png differ diff --git a/art/backgrounds/mainmenu_background.png.import b/art/backgrounds/mainmenu_background.png.import new file mode 100644 index 0000000..de2d64c --- /dev/null +++ b/art/backgrounds/mainmenu_background.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://ccbum282wlrrj" +path="res://.godot/imported/mainmenu_background.png-13d7e3d36cc60e2008c55f3fbe7d6423.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://art/backgrounds/mainmenu_background.png" +dest_files=["res://.godot/imported/mainmenu_background.png-13d7e3d36cc60e2008c55f3fbe7d6423.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 diff --git a/art/fonts/Flexi_IBM_VGA_False.ttf b/art/fonts/Flexi_IBM_VGA_False.ttf new file mode 100644 index 0000000..58044df Binary files /dev/null and b/art/fonts/Flexi_IBM_VGA_False.ttf differ diff --git a/art/fonts/Flexi_IBM_VGA_False.ttf.import b/art/fonts/Flexi_IBM_VGA_False.ttf.import new file mode 100644 index 0000000..7480449 --- /dev/null +++ b/art/fonts/Flexi_IBM_VGA_False.ttf.import @@ -0,0 +1,33 @@ +[remap] + +importer="font_data_dynamic" +type="FontFile" +uid="uid://bo6o24t6oku65" +path="res://.godot/imported/Flexi_IBM_VGA_False.ttf-c58176c3582ecf0b6343ac6a4c3f4772.fontdata" + +[deps] + +source_file="res://art/fonts/Flexi_IBM_VGA_False.ttf" +dest_files=["res://.godot/imported/Flexi_IBM_VGA_False.ttf-c58176c3582ecf0b6343ac6a4c3f4772.fontdata"] + +[params] + +Rendering=null +antialiasing=1 +generate_mipmaps=false +multichannel_signed_distance_field=false +msdf_pixel_range=8 +msdf_size=48 +allow_system_fallback=true +force_autohinter=false +hinting=1 +subpixel_positioning=1 +oversampling=0.0 +Fallbacks=null +fallbacks=[] +Compress=null +compress=true +preload=[] +language_support={} +script_support={} +opentype_features={} diff --git a/art/logos/mainmenu_logo.png b/art/logos/mainmenu_logo.png new file mode 100644 index 0000000..0b27270 Binary files /dev/null and b/art/logos/mainmenu_logo.png differ diff --git a/art/logos/mainmenu_logo.png.import b/art/logos/mainmenu_logo.png.import new file mode 100644 index 0000000..fab0597 --- /dev/null +++ b/art/logos/mainmenu_logo.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://jsnvlmenolg8" +path="res://.godot/imported/mainmenu_logo.png-082759c97df43b35ec514611fcc2c8bf.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://art/logos/mainmenu_logo.png" +dest_files=["res://.godot/imported/mainmenu_logo.png-082759c97df43b35ec514611fcc2c8bf.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 diff --git a/project.godot b/project.godot index 2205688..395b135 100644 --- a/project.godot +++ b/project.godot @@ -36,7 +36,7 @@ place_building={ "events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"pressed":false,"double_click":false,"script":null) ] } -cancel={ +open_main_menu={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"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,"echo":false,"script":null) ] diff --git a/scenes/Main.tscn b/scenes/Main.tscn index e4d0cef..9c760b6 100644 --- a/scenes/Main.tscn +++ b/scenes/Main.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=9 format=3 uid="uid://b1bahdquscsym"] +[gd_scene load_steps=10 format=3 uid="uid://b1bahdquscsym"] [ext_resource type="Script" path="res://scripts/Main.gd" id="1_ysxum"] [ext_resource type="Script" path="res://scripts/ChunkHandler.gd" id="2_6cequ"] +[ext_resource type="PackedScene" uid="uid://bflqpejouge8r" path="res://scenes/MainMenu.tscn" id="2_wfpe2"] [ext_resource type="Script" path="res://scripts/Control.gd" id="3_1t1c8"] [ext_resource type="PackedScene" uid="uid://2we3txfr812u" path="res://scenes/Camera_zoom_2d.tscn" id="4_rx82t"] [ext_resource type="Script" path="res://scripts/EntityPlacer.gd" id="5_8jju5"] @@ -12,10 +13,15 @@ [node name="Main" type="Node2D"] script = ExtResource("1_ysxum") -[node name="ChunkHandler" type="Node2D" parent="."] +[node name="MainMenu" parent="." instance=ExtResource("2_wfpe2")] + +[node name="Game" type="Node2D" parent="."] +visible = false + +[node name="ChunkHandler" type="Node2D" parent="Game"] script = ExtResource("2_6cequ") -[node name="CameraZoom2D" parent="." instance=ExtResource("4_rx82t")] +[node name="CameraZoom2D" parent="Game" instance=ExtResource("4_rx82t")] position = Vector2(1272, 720) ignore_rotation = false limit_left = 0 @@ -26,22 +32,23 @@ limit_smoothed = true rotation_smoothing_enabled = true editor_draw_limits = true -[node name="MapBackground" type="Sprite2D" parent="."] +[node name="MapBackground" type="Sprite2D" parent="Game"] z_index = -1 centered = false script = ExtResource("8_ron2j") -[node name="UILayer" type="CanvasLayer" parent="."] +[node name="UILayer" type="CanvasLayer" parent="Game"] +process_mode = 1 visible = false -[node name="EntityPlacer" type="Control" parent="UILayer"] +[node name="EntityPlacer" type="Control" parent="Game/UILayer"] layout_mode = 3 anchors_preset = 0 offset_right = 40.0 offset_bottom = 40.0 script = ExtResource("5_8jju5") -[node name="Control" type="Control" parent="UILayer"] +[node name="Control" type="Control" parent="Game/UILayer"] layout_mode = 3 anchors_preset = 15 anchor_right = 1.0 @@ -52,7 +59,7 @@ mouse_filter = 1 script = ExtResource("3_1t1c8") metadata/_edit_use_anchors_ = true -[node name="ConstructionPanel" type="Panel" parent="UILayer/Control"] +[node name="ConstructionPanel" type="Panel" parent="Game/UILayer/Control"] custom_minimum_size = Vector2(500, 100) layout_mode = 1 anchors_preset = 5 @@ -63,42 +70,42 @@ offset_right = 250.0 offset_bottom = 100.0 grow_horizontal = 2 -[node name="button_residental" type="Button" parent="UILayer/Control/ConstructionPanel"] +[node name="button_residental" type="Button" parent="Game/UILayer/Control/ConstructionPanel"] layout_mode = 0 offset_right = 8.0 offset_bottom = 8.0 -[node name="button_commercial" type="Button" parent="UILayer/Control/ConstructionPanel"] +[node name="button_commercial" type="Button" parent="Game/UILayer/Control/ConstructionPanel"] layout_mode = 0 offset_right = 8.0 offset_bottom = 8.0 -[node name="button_industrial" type="Button" parent="UILayer/Control/ConstructionPanel"] +[node name="button_industrial" type="Button" parent="Game/UILayer/Control/ConstructionPanel"] layout_mode = 0 offset_right = 8.0 offset_bottom = 8.0 -[node name="button_roads" type="Button" parent="UILayer/Control/ConstructionPanel"] +[node name="button_roads" type="Button" parent="Game/UILayer/Control/ConstructionPanel"] layout_mode = 0 offset_right = 8.0 offset_bottom = 8.0 -[node name="button_demolish" type="Button" parent="UILayer/Control/ConstructionPanel"] +[node name="button_demolish" type="Button" parent="Game/UILayer/Control/ConstructionPanel"] layout_mode = 0 offset_right = 8.0 offset_bottom = 8.0 -[node name="button_services" type="Button" parent="UILayer/Control/ConstructionPanel"] +[node name="button_services" type="Button" parent="Game/UILayer/Control/ConstructionPanel"] layout_mode = 0 offset_right = 8.0 offset_bottom = 8.0 -[node name="button_social" type="Button" parent="UILayer/Control/ConstructionPanel"] +[node name="button_social" type="Button" parent="Game/UILayer/Control/ConstructionPanel"] layout_mode = 0 offset_right = 8.0 offset_bottom = 8.0 -[node name="DebugContainer" type="GridContainer" parent="UILayer/Control"] +[node name="DebugContainer" type="GridContainer" parent="Game/UILayer/Control"] layout_mode = 1 anchors_preset = 1 anchor_left = 1.0 @@ -108,10 +115,10 @@ offset_top = 24.0 offset_bottom = 424.0 grow_horizontal = 0 -[node name="DebugInfo" type="Label" parent="UILayer/Control/DebugContainer"] +[node name="DebugInfo" type="Label" parent="Game/UILayer/Control/DebugContainer"] layout_mode = 2 -[node name="Minimap" type="Panel" parent="UILayer/Control"] +[node name="Minimap" type="Panel" parent="Game/UILayer/Control"] clip_contents = true custom_minimum_size = Vector2(512, 512) layout_mode = 1 @@ -127,32 +134,33 @@ grow_vertical = 0 mouse_filter = 1 script = ExtResource("5_rg28x") -[node name="CameraMarker" type="Sprite2D" parent="UILayer/Control/Minimap"] +[node name="CameraMarker" type="Sprite2D" parent="Game/UILayer/Control/Minimap"] z_index = 1 position = Vector2(-32, 0) centered = false script = ExtResource("7_6krn1") -[node name="MinimapSprite" type="Sprite2D" parent="UILayer/Control/Minimap"] +[node name="MinimapSprite" type="Sprite2D" parent="Game/UILayer/Control/Minimap"] texture_repeat = 1 centered = false -[connection signal="set_camera_position" from="." to="CameraZoom2D" method="_on_set_camera_position"] -[connection signal="worldgen_ready" from="." to="ChunkHandler" method="_on_main_worldgen_ready"] -[connection signal="worldgen_ready" from="." to="CameraZoom2D" method="_on_main_worldgen_ready"] -[connection signal="worldgen_ready" from="." to="UILayer/Control/Minimap" method="_on_main_worldgen_ready"] -[connection signal="worldgen_ready" from="." to="UILayer/Control/Minimap/CameraMarker" method="_on_main_worldgen_ready"] -[connection signal="chunk_stats" from="ChunkHandler" to="UILayer/Control" method="_on_chunk_handler_chunk_stats"] -[connection signal="camera_rotation_changed" from="CameraZoom2D" to="UILayer/Control/Minimap/CameraMarker" method="_on_camera_zoom_2d_camera_rotation_changed"] -[connection signal="camera_zoom_changed" from="CameraZoom2D" to="UILayer/Control/Minimap/CameraMarker" method="_on_camera_zoom_2d_camera_zoom_changed"] -[connection signal="pressed" from="UILayer/Control/ConstructionPanel/button_residental" to="UILayer/Control" method="_on_button_residental_pressed"] -[connection signal="pressed" from="UILayer/Control/ConstructionPanel/button_commercial" to="UILayer/Control" method="_on_button_commercial_pressed"] -[connection signal="pressed" from="UILayer/Control/ConstructionPanel/button_industrial" to="UILayer/Control" method="_on_button_industrial_pressed"] -[connection signal="pressed" from="UILayer/Control/ConstructionPanel/button_roads" to="UILayer/Control" method="_on_button_roads_pressed"] -[connection signal="pressed" from="UILayer/Control/ConstructionPanel/button_demolish" to="UILayer/Control" method="_on_button_demolish_pressed"] -[connection signal="pressed" from="UILayer/Control/ConstructionPanel/button_services" to="UILayer/Control" method="_on_button_services_pressed"] -[connection signal="pressed" from="UILayer/Control/ConstructionPanel/button_social" to="UILayer/Control" method="_on_button_social_pressed"] -[connection signal="mouse_entered" from="UILayer/Control/Minimap" to="UILayer/Control/Minimap" method="_on_mouse_entered"] -[connection signal="mouse_exited" from="UILayer/Control/Minimap" to="UILayer/Control/Minimap" method="_on_mouse_exited"] -[connection signal="set_camera_position" from="UILayer/Control/Minimap" to="CameraZoom2D" method="_on_set_camera_position"] -[connection signal="set_map_background_texture" from="UILayer/Control/Minimap" to="MapBackground" method="_on_minimap_set_map_background_texture"] +[connection signal="set_camera_position" from="." to="Game/CameraZoom2D" method="_on_set_camera_position"] +[connection signal="worldgen_ready" from="." to="Game/ChunkHandler" method="_on_main_worldgen_ready"] +[connection signal="worldgen_ready" from="." to="Game/CameraZoom2D" method="_on_main_worldgen_ready"] +[connection signal="worldgen_ready" from="." to="Game/UILayer/Control" method="_on_main_worldgen_ready"] +[connection signal="worldgen_ready" from="." to="Game/UILayer/Control/Minimap" method="_on_main_worldgen_ready"] +[connection signal="worldgen_ready" from="." to="Game/UILayer/Control/Minimap/CameraMarker" method="_on_main_worldgen_ready"] +[connection signal="chunk_stats" from="Game/ChunkHandler" to="Game/UILayer/Control" method="_on_chunk_handler_chunk_stats"] +[connection signal="camera_rotation_changed" from="Game/CameraZoom2D" to="Game/UILayer/Control/Minimap/CameraMarker" method="_on_camera_zoom_2d_camera_rotation_changed"] +[connection signal="camera_zoom_changed" from="Game/CameraZoom2D" to="Game/UILayer/Control/Minimap/CameraMarker" method="_on_camera_zoom_2d_camera_zoom_changed"] +[connection signal="pressed" from="Game/UILayer/Control/ConstructionPanel/button_residental" to="Game/UILayer/Control" method="_on_button_residental_pressed"] +[connection signal="pressed" from="Game/UILayer/Control/ConstructionPanel/button_commercial" to="Game/UILayer/Control" method="_on_button_commercial_pressed"] +[connection signal="pressed" from="Game/UILayer/Control/ConstructionPanel/button_industrial" to="Game/UILayer/Control" method="_on_button_industrial_pressed"] +[connection signal="pressed" from="Game/UILayer/Control/ConstructionPanel/button_roads" to="Game/UILayer/Control" method="_on_button_roads_pressed"] +[connection signal="pressed" from="Game/UILayer/Control/ConstructionPanel/button_demolish" to="Game/UILayer/Control" method="_on_button_demolish_pressed"] +[connection signal="pressed" from="Game/UILayer/Control/ConstructionPanel/button_services" to="Game/UILayer/Control" method="_on_button_services_pressed"] +[connection signal="pressed" from="Game/UILayer/Control/ConstructionPanel/button_social" to="Game/UILayer/Control" method="_on_button_social_pressed"] +[connection signal="mouse_entered" from="Game/UILayer/Control/Minimap" to="Game/UILayer/Control/Minimap" method="_on_mouse_entered"] +[connection signal="mouse_exited" from="Game/UILayer/Control/Minimap" to="Game/UILayer/Control/Minimap" method="_on_mouse_exited"] +[connection signal="set_camera_position" from="Game/UILayer/Control/Minimap" to="Game/CameraZoom2D" method="_on_set_camera_position"] +[connection signal="set_map_background_texture" from="Game/UILayer/Control/Minimap" to="Game/MapBackground" method="_on_minimap_set_map_background_texture"] diff --git a/scenes/MainMenu.tscn b/scenes/MainMenu.tscn index 7d93718..5c33815 100644 --- a/scenes/MainMenu.tscn +++ b/scenes/MainMenu.tscn @@ -1,11 +1,9 @@ -[gd_scene load_steps=3 format=3 uid="uid://bflqpejouge8r"] +[gd_scene load_steps=5 format=3 uid="uid://bflqpejouge8r"] -[sub_resource type="ImageTexture" id="ImageTexture_qii6u"] - -[sub_resource type="LabelSettings" id="LabelSettings_tb1vr"] -font_size = 64 -outline_size = 20 -outline_color = Color(0, 0, 0, 1) +[ext_resource type="Script" path="res://scripts/MainMenuBar.gd" id="1_50qd7"] +[ext_resource type="Theme" uid="uid://clswkwdkqsx87" path="res://themes/mainmenu_button_theme.tres" id="1_jy0t0"] +[ext_resource type="Texture2D" uid="uid://ccbum282wlrrj" path="res://art/backgrounds/mainmenu_background.png" id="2_7rmv5"] +[ext_resource type="Texture2D" uid="uid://jsnvlmenolg8" path="res://art/logos/mainmenu_logo.png" id="3_etjlt"] [node name="MainMenu" type="Control"] layout_mode = 3 @@ -15,48 +13,70 @@ anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -[node name="MenuBackground" type="Sprite2D" parent="."] -position = Vector2(-2, -3.99994) -scale = Vector2(2566, 1448) -texture = SubResource("ImageTexture_qii6u") -flip_h = true - -[node name="MarginContainer" type="MarginContainer" parent="."] +[node name="MainMenuBar" type="GridContainer" parent="."] layout_mode = 0 -offset_right = 2560.0 -offset_bottom = 1440.0 - -[node name="MenuBar" type="VSplitContainer" parent="MarginContainer"] -layout_mode = 2 +offset_left = 1050.0 +offset_top = 515.0 +offset_right = 1530.0 +offset_bottom = 1155.0 size_flags_horizontal = 4 size_flags_vertical = 4 +theme_override_constants/v_separation = 32 +script = ExtResource("1_50qd7") +metadata/_edit_use_anchors_ = true -[node name="Menu_NewGame" type="Label" parent="MarginContainer/MenuBar"] +[node name="Menu_NewGame" type="Button" parent="MainMenuBar"] layout_mode = 2 -text = "New Game" -label_settings = SubResource("LabelSettings_tb1vr") +theme = ExtResource("1_jy0t0") +text = " New Game" +alignment = 0 -[node name="Menu_LoadGame" type="Label" parent="MarginContainer/MenuBar"] +[node name="Menu_LoadGame" type="Button" parent="MainMenuBar"] layout_mode = 2 -text = "Load Game" -label_settings = SubResource("LabelSettings_tb1vr") +theme = ExtResource("1_jy0t0") +text = " Load Game" +alignment = 0 -[node name="Menu_ResumeGame" type="Label" parent="MarginContainer/MenuBar"] +[node name="Menu_ResumeGame" type="Button" parent="MainMenuBar"] layout_mode = 2 -text = "Resume Game" -label_settings = SubResource("LabelSettings_tb1vr") +size_flags_horizontal = 0 +size_flags_vertical = 0 +theme = ExtResource("1_jy0t0") +text = " Resume Game " +alignment = 0 -[node name="Menu_Options" type="Label" parent="MarginContainer/MenuBar"] +[node name="Menu_Options" type="Button" parent="MainMenuBar"] layout_mode = 2 -text = "Options" -label_settings = SubResource("LabelSettings_tb1vr") +size_flags_horizontal = 0 +theme = ExtResource("1_jy0t0") +text = " Options " -[node name="Menu_Credits" type="Label" parent="MarginContainer/MenuBar"] +[node name="Menu_Credits" type="Button" parent="MainMenuBar"] layout_mode = 2 -text = "Credits" -label_settings = SubResource("LabelSettings_tb1vr") +theme = ExtResource("1_jy0t0") +text = " Credits" +alignment = 0 -[node name="Menu_ExitGame" type="Label" parent="MarginContainer/MenuBar"] +[node name="Menu_ExitGame" type="Button" parent="MainMenuBar"] layout_mode = 2 -text = "Exit Game" -label_settings = SubResource("LabelSettings_tb1vr") +theme = ExtResource("1_jy0t0") +text = " Exit Game" +alignment = 0 + +[node name="MenuBackground" type="Sprite2D" parent="."] +z_index = -1 +position = Vector2(1320, 736) +texture = ExtResource("2_7rmv5") + +[node name="MenuLogo" type="Sprite2D" parent="."] +position = Vector2(856, 592) +rotation = -1.5708 +scale = Vector2(0.547831, 0.547831) +texture = ExtResource("3_etjlt") + +[connection signal="pressed" from="MainMenuBar/Menu_NewGame" to="MainMenuBar" method="_on_menu_new_game_pressed"] +[connection signal="pressed" from="MainMenuBar/Menu_LoadGame" to="MainMenuBar" method="_on_menu_load_game_pressed"] +[connection signal="pressed" from="MainMenuBar/Menu_ResumeGame" to="MainMenuBar" method="_on_menu_resume_game_pressed"] +[connection signal="pressed" from="MainMenuBar/Menu_Options" to="MainMenuBar" method="_on_menu_options_pressed"] +[connection signal="pressed" from="MainMenuBar/Menu_Credits" to="MainMenuBar" method="_on_menu_credits_pressed"] +[connection signal="pressed" from="MainMenuBar/Menu_ExitGame" to="MainMenuBar" method="_on_menu_exit_game_pressed"] diff --git a/scripts/ChunkHandler.gd b/scripts/ChunkHandler.gd index d87ec0d..841da41 100644 --- a/scripts/ChunkHandler.gd +++ b/scripts/ChunkHandler.gd @@ -39,20 +39,18 @@ func _init() -> void: func _on_main_worldgen_ready(): - thread.start(start_chunkgen, Thread.PRIORITY_NORMAL) - clean_up_chunks() + if !thread.is_started(): + thread.start(start_chunkgen, Thread.PRIORITY_NORMAL) + clean_up_chunks() -#func _process(_delta): -# update_chunks() - - func _ready(): mutex = Mutex.new() semaphore = Semaphore.new() exit_thread = false - thread = Thread.new() + if !thread: + thread = Thread.new() process_delay_chunks() process_delay_stats() diff --git a/scripts/Control.gd b/scripts/Control.gd index e6b43a3..ef6a2f1 100644 --- a/scripts/Control.gd +++ b/scripts/Control.gd @@ -8,6 +8,8 @@ signal button_pressed(button_name) var amount_of_chunks:int = 0 var size_of_chunk_removal_queue:int = 0 +var update_debug_info:bool = false + # name, position var buttons = { @@ -20,6 +22,45 @@ var buttons = { "button_social": [Vector2(150,50), "So"], } +func _on_chunk_handler_chunk_stats(chunks, removal_queue): + self.amount_of_chunks = chunks + self.size_of_chunk_removal_queue = removal_queue + + +# sends signals which View catches and places selected type of buildings +func _on_button_residental_pressed(): + emit_signal("button_pressed", Globals.TYPE_RESIDENTIAL) + + +func _on_button_commercial_pressed(): + emit_signal("button_pressed", Globals.TYPE_COMMERCIAL) + + +func _on_button_industrial_pressed(): + emit_signal("button_pressed", Globals.TYPE_INDUSTRIAL) + + +func _on_button_roads_pressed(): + emit_signal("button_pressed", Globals.TYPE_ROADS) + + +func _on_button_demolish_pressed(): + emit_signal("button_pressed", Globals.TYPE_DEMOLISH) + + +func _on_button_services_pressed(): + emit_signal("button_pressed", Globals.TYPE_SERVICES) + + +func _on_button_social_pressed(): + emit_signal("button_pressed", Globals.TYPE_SOCIAL) + + +func _on_main_worldgen_ready(): + self.set_process(true) + update_debug_info = true + + # Called when the node enters the scene tree for the first time. func _ready(): create_buttons() @@ -28,15 +69,9 @@ func _ready(): # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(_delta): - debug_info.set_text( - str(get_viewport().get_mouse_position()) +"\n" + - "FPS " + str(Engine.get_frames_per_second()) + "\n" + - "Zoom lvl: " + str(Globals.CAMERA_ZOOM_LEVEL) + "\n" + - "Camera pos: " + str(Globals.CAMERA_POSITION) + "\n" + - "Camera pos: " + str(Globals.camera_marker.position) + "\n" + - "Chunks: " + str(self.amount_of_chunks) + "\n" + - "Chunk del: " + str(self.size_of_chunk_removal_queue), - ) + if update_debug_info: + update_debug_info_func() + # defines construction toolbar buttons func create_buttons(): @@ -53,31 +88,16 @@ func create_buttons(): node_path.set_anchor(SIDE_TOP, anchor_top) node_path.set_text(values[1]) node_path.show() + +func update_debug_info_func(): + debug_info.set_text( + str(get_viewport().get_mouse_position()) +"\n" + + "FPS " + str(Engine.get_frames_per_second()) + "\n" + + "Zoom lvl: " + str(Globals.CAMERA_ZOOM_LEVEL) + "\n" + + "Camera pos: " + str(Globals.CAMERA_POSITION) + "\n" + + "Camera pos: " + str(Globals.camera_marker.position) + "\n" + + "Chunks: " + str(self.amount_of_chunks) + "\n" + + "Chunk del: " + str(self.size_of_chunk_removal_queue), + ) -# sends signals which View catches and places selected type of buildings -func _on_button_residental_pressed(): - emit_signal("button_pressed", Globals.TYPE_RESIDENTIAL) - -func _on_button_commercial_pressed(): - emit_signal("button_pressed", Globals.TYPE_COMMERCIAL) - -func _on_button_industrial_pressed(): - emit_signal("button_pressed", Globals.TYPE_INDUSTRIAL) - -func _on_button_roads_pressed(): - emit_signal("button_pressed", Globals.TYPE_ROADS) - -func _on_button_demolish_pressed(): - emit_signal("button_pressed", Globals.TYPE_DEMOLISH) - -func _on_button_services_pressed(): - emit_signal("button_pressed", Globals.TYPE_SERVICES) - -func _on_button_social_pressed(): - emit_signal("button_pressed", Globals.TYPE_SOCIAL) - - -func _on_chunk_handler_chunk_stats(chunks, removal_queue): - self.amount_of_chunks = chunks - self.size_of_chunk_removal_queue = removal_queue diff --git a/scripts/Globals.gd b/scripts/Globals.gd index 4f20f04..97d6b8d 100644 --- a/scripts/Globals.gd +++ b/scripts/Globals.gd @@ -87,6 +87,7 @@ const GUI_BUILD_BUTTON_SIZE_Y: int = 50 const GUI_BUILD_BUTTON_SIZE: Vector2i = Vector2i(GUI_BUILD_BUTTON_SIZE_X,GUI_BUILD_BUTTON_SIZE_Y) # maybe should use int for these instead for faster matching? +# ^ yes TODO switch to enum const TYPE_RESIDENTIAL:String = "residential" const TYPE_COMMERCIAL:String = "commercial" const TYPE_INDUSTRIAL:String = "industrial" @@ -96,6 +97,16 @@ const TYPE_POWERPLANT:String = "powerplant" const TYPE_ROADS:String = "roads" const TYPE_DEMOLISH:String = "demolish" +# Main menu buttons +enum { + MAINMENU_NEW_GAME, + MAINMENU_LOAD_GAME, + MAINMENU_RESUME_GAME, + MAINMENU_OPTIONS, + MAINMENU_CREDITS, + MAINMENU_QUIT_GAME, + } + ################################### # WORLD GENERATION SETTINGS # diff --git a/scripts/Main.gd b/scripts/Main.gd index e42e062..cc48950 100644 --- a/scripts/Main.gd +++ b/scripts/Main.gd @@ -16,6 +16,8 @@ extends Node2D signal worldgen_ready signal set_camera_position(pos:Vector2) +var start_new_game_pressed:bool = false + # The idea is for the user to be able to choose the map from GUI later var map_filenames:Array = [ "res://maps/tampere_10x10km_1000px.png", @@ -24,20 +26,19 @@ var map_filenames:Array = [ "res://maps/tampere_256px.png", "res://maps/tampere_10x10km_4096px.png" ] -var map_filename:String = map_filenames[1] +var map_filename:String = map_filenames[3] var _world_generator:WorldGenerator -func _init(): +func _init(): # DisplayServer.window_set_size( # #Vector2i(Globals.DEFAULT_X_RES, Globals.DEFAULT_Y_RES) # Vector2i(3800,2000) # ) Globals.CAMERA_POSITION = Vector2(16*256/2, 16*256/2) - - -# Called when the node enters the scene tree for the first time. -func _ready(): + + +func start_new_game(): # create a new world with worldgenerator _world_generator = WorldGenerator.new() if !_world_generator.generate_world(map_filename): @@ -45,9 +46,14 @@ func _ready(): quit_game() # connections are made from GUI - + # tell other classes they can start working after loading is done - emit_signal("worldgen_ready") + emit_signal("worldgen_ready") + + self.find_child("MainMenu").hide() + self.find_child("Game").show() + self.find_child("UILayer").show() + # center camera to world map emit_signal( "set_camera_position", @@ -55,6 +61,39 @@ func _ready(): Globals.map_size / 2.0 * Globals.TILE_SIZE_Y) ) +func _on_mainmenu_button_pressed(button:int): + match button: + 0: # new game + start_new_game() + self.find_child("Menu_NewGame").disabled = true + self.find_child("Menu_ResumeGame").disabled = false + 1: # load game: + pass + 2: # resume game + # TODO save camera position before opening menu, restore camera position when closing menu + self.find_child("Game").process_mode = PROCESS_MODE_INHERIT + self.find_child("Game").show() + self.find_child("UILayer").show() + self.find_child("MainMenu").hide() + _: + push_error("Error: Main: unknown signal at _on_mainmenu_button_pressed: ", button) + +func _unhandled_input(event) -> void: + if event.is_action_pressed("open_main_menu"): + emit_signal( + "set_camera_position", + Vector2( + DisplayServer.window_get_size(0).x/2, + DisplayServer.window_get_size(0).y/2 + ) + ) + self.find_child("Game").hide() + self.find_child("UILayer").hide() + self.find_child("MainMenu").show() + await get_tree().create_timer(0.2).timeout + self.find_child("Game").process_mode = PROCESS_MODE_DISABLED + + func quit_game(): get_tree().get_root().propagate_notification(NOTIFICATION_WM_CLOSE_REQUEST) diff --git a/scripts/MainMenuBar.gd b/scripts/MainMenuBar.gd new file mode 100644 index 0000000..5a6c0de --- /dev/null +++ b/scripts/MainMenuBar.gd @@ -0,0 +1,33 @@ +extends GridContainer + +signal button_pressed(button_name) + +# Connect main menu to Main game +func _ready(): + self.connect("button_pressed", self.find_parent("Main")._on_mainmenu_button_pressed, CONNECT_PERSIST) + self.find_child("Menu_ResumeGame").disabled = true + + +func _on_menu_new_game_pressed(): + emit_signal("button_pressed", Globals.MAINMENU_NEW_GAME) + + +func _on_menu_load_game_pressed(): + emit_signal("button_pressed", Globals.MAINMENU_LOAD_GAME) + + +func _on_menu_resume_game_pressed(): + emit_signal("button_pressed", Globals.MAINMENU_RESUME_GAME) + + +func _on_menu_options_pressed(): + emit_signal("button_pressed", Globals.MAINMENU_OPTIONS) + + +func _on_menu_credits_pressed(): + emit_signal("button_pressed", Globals.MAINMENU_CREDITS) + + +func _on_menu_exit_game_pressed(): + #emit_signal("button_pressed", Globals.MAINMENU_QUIT_GAME) + get_tree().quit() diff --git a/scripts/Minimap.gd b/scripts/Minimap.gd index ccd640d..6a66bfe 100644 --- a/scripts/Minimap.gd +++ b/scripts/Minimap.gd @@ -9,6 +9,7 @@ signal set_map_background_texture(texture) @onready var is_mouse_inside_minimap:bool = false @onready var position_multiplier:float @onready var area_size:Vector2 +var observe_mouse_inside_minimap:bool = false # Called when the node enters the scene tree for the first time. @@ -22,7 +23,7 @@ func _draw(): func _process(_delta): - if !is_mouse_inside_minimap: + if !is_mouse_inside_minimap and observe_mouse_inside_minimap: Globals.camera_marker.position = Vector2( Globals.CAMERA_POSITION.x / position_multiplier, Globals.CAMERA_POSITION.y / position_multiplier, @@ -31,6 +32,8 @@ func _process(_delta): func _on_main_worldgen_ready(): # Assuming the area has a child CollisionShape2D with a RectangleShape resource + self.set_process(true) + observe_mouse_inside_minimap = true area_size = self.get_rect().size position_multiplier = Globals.map_size / 32 diff --git a/themes/mainmenu_button_theme.tres b/themes/mainmenu_button_theme.tres new file mode 100644 index 0000000..97cb085 --- /dev/null +++ b/themes/mainmenu_button_theme.tres @@ -0,0 +1,9 @@ +[gd_resource type="Theme" load_steps=2 format=3 uid="uid://clswkwdkqsx87"] + +[ext_resource type="FontFile" uid="uid://bo6o24t6oku65" path="res://art/fonts/Flexi_IBM_VGA_False.ttf" id="1_vpce8"] + +[resource] +default_font = ExtResource("1_vpce8") +default_font_size = 72 +/colors/background_color = Color(0, 0, 0, 0) +/fonts/font_props = ExtResource("1_vpce8")