From 63afd68cbf85f6eb251237c2075001a016afa915 Mon Sep 17 00:00:00 2001 From: Antti Hakkarainen Date: Sat, 18 Feb 2023 23:49:16 +0200 Subject: [PATCH] give each debug info its own label --- scenes/Main.tscn | 96 +++++++++++++-------- scenes/MainMenu.tscn | 2 +- source/EventBus.gd | 68 ++++++++++----- source/Globals.gd | 2 +- source/WorldGenerator.gd | 71 +++++++-------- source/camera/Camera.gd | 7 +- source/game/ChunkHandler.gd | 2 +- source/mainmenu/MainMenu.gd | 6 +- source/uilayer/CameraMarker.gd | 4 +- source/uilayer/DebugInfo.gd | 85 ++++++++++++++++++ source/uilayer/Minimap.gd | 1 - source/uilayer/{Control.gd => UIControl.gd} | 34 ++------ source/uilayer/UILayer.gd | 12 +++ 13 files changed, 262 insertions(+), 128 deletions(-) create mode 100644 source/uilayer/DebugInfo.gd rename source/uilayer/{Control.gd => UIControl.gd} (69%) diff --git a/scenes/Main.tscn b/scenes/Main.tscn index f7eee56..f7458b1 100644 --- a/scenes/Main.tscn +++ b/scenes/Main.tscn @@ -1,8 +1,8 @@ -[gd_scene load_steps=15 format=3 uid="uid://b2jnn81mmg5wt"] +[gd_scene load_steps=16 format=3 uid="uid://do3kv0qm74wqa"] [ext_resource type="Script" path="res://source/Main.gd" id="1_vnd1v"] [ext_resource type="Script" path="res://source/EventBus.gd" id="2_qhcs8"] -[ext_resource type="PackedScene" path="res://scenes/MainMenu.tscn" id="2_wfpe2"] +[ext_resource type="PackedScene" uid="uid://eqxii3esb77q" path="res://scenes/MainMenu.tscn" id="2_wfpe2"] [ext_resource type="Script" path="res://source/camera/Camera.gd" id="3_4khcd"] [ext_resource type="Script" path="res://source/game/Game.gd" id="4_3cif6"] [ext_resource type="Script" path="res://source/game/Simulation.gd" id="5_hkn6c"] @@ -11,11 +11,12 @@ [ext_resource type="Script" path="res://source/infolayer/InfoLayer.gd" id="9_dg6uy"] [ext_resource type="Script" path="res://source/uilayer/UILayer.gd" id="10_l2a8p"] [ext_resource type="Script" path="res://source/uilayer/EntityPlacer.gd" id="11_gtqb3"] -[ext_resource type="Script" path="res://source/uilayer/Control.gd" id="12_vhsyq"] +[ext_resource type="Script" path="res://source/uilayer/UIControl.gd" id="12_3cfex"] [ext_resource type="Script" path="res://source/uilayer/Minimap.gd" id="13_80u53"] +[ext_resource type="Script" path="res://source/uilayer/DebugInfo.gd" id="13_tfg54"] [ext_resource type="Script" path="res://source/uilayer/CameraMarker.gd" id="14_rvt3n"] -[node name="Main" type="Node"] +[node name="Main" type="Node" groups=["camera_properties_listener"]] script = ExtResource("1_vnd1v") [node name="EventBus" type="Node" parent="."] @@ -62,7 +63,7 @@ offset_right = 40.0 offset_bottom = 40.0 script = ExtResource("11_gtqb3") -[node name="Control" type="Control" parent="EventBus/UILayer"] +[node name="UIControl" type="Control" parent="EventBus/UILayer" groups=["camera_properties_listener"]] layout_mode = 3 anchors_preset = 15 anchor_right = 1.0 @@ -70,10 +71,10 @@ anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 mouse_filter = 1 -script = ExtResource("12_vhsyq") +script = ExtResource("12_3cfex") metadata/_edit_use_anchors_ = true -[node name="ConstructionPanel" type="Panel" parent="EventBus/UILayer/Control"] +[node name="ConstructionPanel" type="Panel" parent="EventBus/UILayer/UIControl"] custom_minimum_size = Vector2(500, 100) layout_mode = 1 anchors_preset = 5 @@ -84,46 +85,52 @@ offset_right = 250.0 offset_bottom = 100.0 grow_horizontal = 2 -[node name="button_residental" type="Button" parent="EventBus/UILayer/Control/ConstructionPanel"] +[node name="button_residental" type="Button" parent="EventBus/UILayer/UIControl/ConstructionPanel"] layout_mode = 0 offset_right = 8.0 offset_bottom = 8.0 -[node name="button_commercial" type="Button" parent="EventBus/UILayer/Control/ConstructionPanel"] +[node name="button_commercial" type="Button" parent="EventBus/UILayer/UIControl/ConstructionPanel"] layout_mode = 0 offset_right = 8.0 offset_bottom = 8.0 -[node name="button_industrial" type="Button" parent="EventBus/UILayer/Control/ConstructionPanel"] +[node name="button_industrial" type="Button" parent="EventBus/UILayer/UIControl/ConstructionPanel"] layout_mode = 0 offset_right = 8.0 offset_bottom = 8.0 -[node name="button_roads" type="Button" parent="EventBus/UILayer/Control/ConstructionPanel"] +[node name="button_roads" type="Button" parent="EventBus/UILayer/UIControl/ConstructionPanel"] layout_mode = 0 offset_right = 8.0 offset_bottom = 8.0 -[node name="button_demolish" type="Button" parent="EventBus/UILayer/Control/ConstructionPanel"] +[node name="button_demolish" type="Button" parent="EventBus/UILayer/UIControl/ConstructionPanel"] layout_mode = 0 offset_right = 8.0 offset_bottom = 8.0 -[node name="button_services" type="Button" parent="EventBus/UILayer/Control/ConstructionPanel"] +[node name="button_services" type="Button" parent="EventBus/UILayer/UIControl/ConstructionPanel"] layout_mode = 0 offset_right = 8.0 offset_bottom = 8.0 -[node name="button_social" type="Button" parent="EventBus/UILayer/Control/ConstructionPanel"] +[node name="button_social" type="Button" parent="EventBus/UILayer/UIControl/ConstructionPanel"] layout_mode = 0 offset_right = 8.0 offset_bottom = 8.0 -[node name="button_infolayer_parcels" type="Button" parent="EventBus/UILayer/Control/ConstructionPanel"] +[node name="button_infolayer_parcels" type="Button" parent="EventBus/UILayer/UIControl/ConstructionPanel"] +layout_mode = 0 offset_right = 8.0 offset_bottom = 8.0 -[node name="DebugContainer" type="GridContainer" parent="EventBus/UILayer/Control"] +[node name="InfoButtonPanel" type="GridContainer" parent="EventBus/UILayer/UIControl"] +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 40.0 + +[node name="DebugInfo" type="GridContainer" parent="EventBus/UILayer/UIControl"] layout_mode = 1 anchors_preset = 1 anchor_left = 1.0 @@ -132,11 +139,27 @@ offset_left = -264.0 offset_top = 24.0 offset_bottom = 424.0 grow_horizontal = 0 +script = ExtResource("13_tfg54") -[node name="DebugInfo" type="Label" parent="EventBus/UILayer/Control/DebugContainer"] +[node name="FPSLabel" type="Label" parent="EventBus/UILayer/UIControl/DebugInfo"] layout_mode = 2 -[node name="Minimap" type="Panel" parent="EventBus/UILayer/Control"] +[node name="CamPosLabel" type="Label" parent="EventBus/UILayer/UIControl/DebugInfo"] +layout_mode = 2 + +[node name="CamRotationLabel" type="Label" parent="EventBus/UILayer/UIControl/DebugInfo"] +layout_mode = 2 + +[node name="CamZoomLabel" type="Label" parent="EventBus/UILayer/UIControl/DebugInfo"] +layout_mode = 2 + +[node name="ChunkLabel" type="Label" parent="EventBus/UILayer/UIControl/DebugInfo"] +layout_mode = 2 + +[node name="ChunkDelLabel" type="Label" parent="EventBus/UILayer/UIControl/DebugInfo"] +layout_mode = 2 + +[node name="Minimap" type="Panel" parent="EventBus/UILayer/UIControl"] clip_contents = true custom_minimum_size = Vector2(512, 512) layout_mode = 1 @@ -152,27 +175,32 @@ grow_vertical = 0 mouse_filter = 1 script = ExtResource("13_80u53") -[node name="CameraMarker" type="Sprite2D" parent="EventBus/UILayer/Control/Minimap"] +[node name="CameraMarker" type="Sprite2D" parent="EventBus/UILayer/UIControl/Minimap" groups=["camera_properties_listener"]] z_index = 10 position = Vector2(-32, 0) centered = false script = ExtResource("14_rvt3n") -[node name="MinimapSprite" type="Sprite2D" parent="EventBus/UILayer/Control/Minimap"] +[node name="MinimapSprite" type="Sprite2D" parent="EventBus/UILayer/UIControl/Minimap"] texture_repeat = 1 centered = false -[connection signal="chunk_stats" from="EventBus/Game/ChunkHandler" to="EventBus/UILayer/Control" method="_on_chunk_handler_chunk_stats"] -[connection signal="infolayer_button_pressed" from="EventBus/UILayer/Control" to="EventBus" method="_on_control_infolayer_button_pressed"] -[connection signal="pressed" from="EventBus/UILayer/Control/ConstructionPanel/button_residental" to="EventBus/UILayer/Control" method="_on_button_residental_pressed"] -[connection signal="pressed" from="EventBus/UILayer/Control/ConstructionPanel/button_commercial" to="EventBus/UILayer/Control" method="_on_button_commercial_pressed"] -[connection signal="pressed" from="EventBus/UILayer/Control/ConstructionPanel/button_industrial" to="EventBus/UILayer/Control" method="_on_button_industrial_pressed"] -[connection signal="pressed" from="EventBus/UILayer/Control/ConstructionPanel/button_roads" to="EventBus/UILayer/Control" method="_on_button_roads_pressed"] -[connection signal="pressed" from="EventBus/UILayer/Control/ConstructionPanel/button_demolish" to="EventBus/UILayer/Control" method="_on_button_demolish_pressed"] -[connection signal="pressed" from="EventBus/UILayer/Control/ConstructionPanel/button_services" to="EventBus/UILayer/Control" method="_on_button_services_pressed"] -[connection signal="pressed" from="EventBus/UILayer/Control/ConstructionPanel/button_social" to="EventBus/UILayer/Control" method="_on_button_social_pressed"] -[connection signal="pressed" from="EventBus/UILayer/Control/ConstructionPanel/button_infolayer_parcels" to="EventBus/UILayer/Control" method="_on_button_infolayer_parcels_pressed"] -[connection signal="mouse_entered" from="EventBus/UILayer/Control/Minimap" to="EventBus/UILayer/Control/Minimap" method="_on_mouse_entered"] -[connection signal="mouse_exited" from="EventBus/UILayer/Control/Minimap" to="EventBus/UILayer/Control/Minimap" method="_on_mouse_exited"] -[connection signal="set_camera_position" from="EventBus/UILayer/Control/Minimap" to="EventBus" method="set_camera_position"] -[connection signal="set_map_background_texture" from="EventBus/UILayer/Control/Minimap" to="EventBus/Game" method="_on_minimap_set_map_background_texture"] +[connection signal="camera_pos_changed" from="EventBus/Camera" to="EventBus/UILayer/UIControl/DebugInfo" method="_on_camera_pos_changed"] +[connection signal="camera_rotation_changed" from="EventBus/Camera" to="EventBus" method="_on_camera_rotation_changed"] +[connection signal="camera_rotation_changed" from="EventBus/Camera" to="EventBus/UILayer/UIControl/DebugInfo" method="_on_camera_rotation_changed"] +[connection signal="camera_zoom_changed" from="EventBus/Camera" to="EventBus" method="_on_camera_zoom_changed"] +[connection signal="camera_zoom_changed" from="EventBus/Camera" to="EventBus/UILayer/UIControl/DebugInfo" method="_on_camera_zoom_changed"] +[connection signal="chunk_stats" from="EventBus/Game/ChunkHandler" to="EventBus/UILayer/UIControl/DebugInfo" method="_on_chunk_handler_chunk_stats"] +[connection signal="infolayer_button_pressed" from="EventBus/UILayer/UIControl" to="EventBus" method="_on_control_infolayer_button_pressed"] +[connection signal="pressed" from="EventBus/UILayer/UIControl/ConstructionPanel/button_residental" to="EventBus/UILayer/UIControl" method="_on_button_residental_pressed"] +[connection signal="pressed" from="EventBus/UILayer/UIControl/ConstructionPanel/button_commercial" to="EventBus/UILayer/UIControl" method="_on_button_commercial_pressed"] +[connection signal="pressed" from="EventBus/UILayer/UIControl/ConstructionPanel/button_industrial" to="EventBus/UILayer/UIControl" method="_on_button_industrial_pressed"] +[connection signal="pressed" from="EventBus/UILayer/UIControl/ConstructionPanel/button_roads" to="EventBus/UILayer/UIControl" method="_on_button_roads_pressed"] +[connection signal="pressed" from="EventBus/UILayer/UIControl/ConstructionPanel/button_demolish" to="EventBus/UILayer/UIControl" method="_on_button_demolish_pressed"] +[connection signal="pressed" from="EventBus/UILayer/UIControl/ConstructionPanel/button_services" to="EventBus/UILayer/UIControl" method="_on_button_services_pressed"] +[connection signal="pressed" from="EventBus/UILayer/UIControl/ConstructionPanel/button_social" to="EventBus/UILayer/UIControl" method="_on_button_social_pressed"] +[connection signal="pressed" from="EventBus/UILayer/UIControl/ConstructionPanel/button_infolayer_parcels" to="EventBus/UILayer/UIControl" method="_on_button_infolayer_parcels_pressed"] +[connection signal="mouse_entered" from="EventBus/UILayer/UIControl/Minimap" to="EventBus/UILayer/UIControl/Minimap" method="_on_mouse_entered"] +[connection signal="mouse_exited" from="EventBus/UILayer/UIControl/Minimap" to="EventBus/UILayer/UIControl/Minimap" method="_on_mouse_exited"] +[connection signal="set_camera_position" from="EventBus/UILayer/UIControl/Minimap" to="EventBus" method="_on_set_camera_position"] +[connection signal="set_map_background_texture" from="EventBus/UILayer/UIControl/Minimap" to="EventBus/Game" method="_on_minimap_set_map_background_texture"] diff --git a/scenes/MainMenu.tscn b/scenes/MainMenu.tscn index 6ce8faf..04ed2f7 100644 --- a/scenes/MainMenu.tscn +++ b/scenes/MainMenu.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=5 format=3] +[gd_scene load_steps=5 format=3 uid="uid://eqxii3esb77q"] [ext_resource type="Theme" uid="uid://clswkwdkqsx87" path="res://themes/mainmenu_button_theme.tres" id="1_jy0t0"] [ext_resource type="Script" path="res://source/mainmenu/MainMenu.gd" id="1_rpwyu"] diff --git a/source/EventBus.gd b/source/EventBus.gd index 07cbb2a..1bd2309 100644 --- a/source/EventBus.gd +++ b/source/EventBus.gd @@ -9,6 +9,8 @@ extends Node @onready var node_uilayer:UILayer +var previous_zoom: float + # 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", @@ -51,17 +53,21 @@ func _unhandled_input(event) -> void: ################################### if event.is_action_pressed("open_main_menu"): - # move mainmenu to current game camera position - var mainmenu_pos = Globals.CAMERA_POSITION - mainmenu_pos.x -= DisplayServer.window_get_size(0).x/2 - mainmenu_pos.y -= DisplayServer.window_get_size(0).y/2 - node_mainmenu.set_position(mainmenu_pos, false) - # show the menu - node_mainmenu.set_visible(true) - node_game.set_visible(false) - node_uilayer.set_visible(false) - node_main.pause_game() + if node_mainmenu.visible: + self.toggle_mainmenu() + node_main.unpause_game() + else: + node_mainmenu.set_scale(Vector2(1.0/Globals.CAMERA_ZOOM_LEVEL, 1.0/Globals.CAMERA_ZOOM_LEVEL)) + + # move mainmenu to current game camera position + var mainmenu_pos = Globals.CAMERA_POSITION + mainmenu_pos.x -= DisplayServer.window_get_size(0).x/2 + mainmenu_pos.y -= DisplayServer.window_get_size(0).y/2 + node_mainmenu.set_position(mainmenu_pos, false) + + self.toggle_mainmenu() + node_main.pause_game() ################################### # GAME CAMERA # @@ -96,6 +102,14 @@ func _unhandled_input(event) -> void: node_camera.clamp_camera_position() +func _on_camera_rotation_changed(new_rotation): + node_uilayer.camera_rotation_changed(new_rotation) + + +func _on_camera_zoom_changed(new_zoom_factor): + node_uilayer.camera_zoom_changed(new_zoom_factor) + + func _on_control_infolayer_button_pressed(button_type): var current_layer:int = node_infolayer.get_draw_mode() @@ -116,7 +130,7 @@ func _on_mainmenu_button_pressed(button:int): pass Globals.MAINMENU_RESUME_GAME: - resume_game() + self.toggle_mainmenu() Globals.MAINMENU_OPTIONS: pass @@ -129,18 +143,27 @@ func _on_mainmenu_button_pressed(button:int): _: push_error("Error: Main: unknown signal at _on_mainmenu_button_pressed: ", button) - - -func resume_game() -> void: - # TODO save camera position before opening menu, restore camera position when closing menu - node_main.unpause_game() - node_mainmenu.set_visible(false) - node_game.set_visible(true) - node_uilayer.set_visible(true) - -func set_camera_position(pos:Vector2): + +func _on_set_camera_position(pos:Vector2): node_camera.set_camera_position(pos) + +func toggle_mainmenu() -> void: + # TODO save camera position before opening menu, restore camera position when closing menu + if node_mainmenu.visible: + node_mainmenu.set_visible(false) + else: + node_mainmenu.set_visible(true) + + if node_game.visible: + node_game.set_visible(false) + else: + node_game.set_visible(true) + + if node_uilayer.visible: + node_uilayer.set_visible(false) + else: + node_uilayer.set_visible(true) func start_new_game(): @@ -175,3 +198,6 @@ func start_new_game(): + + + diff --git a/source/Globals.gd b/source/Globals.gd index 4e78985..9563e77 100644 --- a/source/Globals.gd +++ b/source/Globals.gd @@ -22,7 +22,7 @@ var chunks_loaded:int = 0 @export var map_parcel_data:Array[Array] = [[]] # current camera zoom level -@export var CAMERA_ZOOM_LEVEL:float +@export var CAMERA_ZOOM_LEVEL:float = 1.0 @export var CAMERA_POSITION:Vector2i # minimap texture, used also as save game's imagetexture diff --git a/source/WorldGenerator.gd b/source/WorldGenerator.gd index ab1c1c7..97ed253 100644 --- a/source/WorldGenerator.gd +++ b/source/WorldGenerator.gd @@ -94,30 +94,6 @@ func generate_biomes() -> void: # can add other tresholds here for other biomes -# forests are not generated yet so can just compare water and terrain -func is_filled_with_water(coords:Vector2i) -> bool: - var terrain_tile_count:int = 0 - -# 0*64, 0*64 +64-1 = 0-63 -# 1*64, 1*64 +63 = 64-127 -# 2*64, 2*64 +63 = 128-191 -# 3*64, 3*64 +63 = 192-255 - for y in range( - coords.y*Globals.PARCEL_HEIGHT, - coords.y*Globals.PARCEL_HEIGHT + Globals.PARCEL_HEIGHT-1 - ): - for x in range( - coords.x*Globals.PARCEL_WIDTH, - coords.x*Globals.PARCEL_WIDTH + Globals.PARCEL_WIDTH-1 - ): - if Globals.map_terrain_data[y][x] == Globals.TILE_TERRAIN: - terrain_tile_count += 1 - - # parcel is ok if it has at least one land - if terrain_tile_count > 0: - return false - return true - func generate_parcels() -> void: # divide the land area Cadastres / Parcels # TODO better solution, this is something my skills were able to handle at proto stage @@ -145,16 +121,6 @@ func generate_parcels() -> void: var total_parcels = Globals.map_size/Globals.PARCEL_WIDTH * Globals.map_size / Globals.PARCEL_HEIGHT give_starting_parcels_for_city(total_parcels) -func give_starting_parcels_for_city(_amount:int) -> void: - # gives a x*y parcel initial starting area for the player - var p_x = Globals.map_size/Globals.PARCEL_WIDTH/2 - var p_y = Globals.map_size/Globals.PARCEL_HEIGHT/2 - - for y in range(0, Globals.STARTING_AREA_HEIGHT_IN_PARCELS): - for x in range(0, Globals.STARTING_AREA_WIDTH_IN_PARCELS): - if Globals.map_parcel_data[p_y-y][p_x-x] != null: - Globals.map_parcel_data[p_y-y][p_x-x].owner = Globals.PARCEL_CITY - func generate_world(filename) -> bool: # Try to load the image which we used to place water & ground to world map @@ -200,7 +166,44 @@ func generate_world(filename) -> bool: emit_signal("worldgenerator_function_called", (end-start)/1000.0, function[0]) return true + + +func give_starting_parcels_for_city(_amount:int) -> void: + # gives a x*y parcel initial starting area for the player + var p_x = Globals.map_size/Globals.PARCEL_WIDTH/2 + var p_y = Globals.map_size/Globals.PARCEL_HEIGHT/2 + for y in range(0, Globals.STARTING_AREA_HEIGHT_IN_PARCELS): + for x in range(0, Globals.STARTING_AREA_WIDTH_IN_PARCELS): + if Globals.map_parcel_data[p_y-y][p_x-x] != null: + Globals.map_parcel_data[p_y-y][p_x-x].owner = Globals.PARCEL_CITY + + +# forests are not generated yet so can just compare water and terrain +func is_filled_with_water(coords:Vector2i) -> bool: + #var terrain_tile_count:int = 0 + +# 0*64, 0*64 +64-1 = 0-63 +# 1*64, 1*64 +63 = 64-127 +# 2*64, 2*64 +63 = 128-191 +# 3*64, 3*64 +63 = 192-255 + for y in range( + coords.y*Globals.PARCEL_HEIGHT, + coords.y*Globals.PARCEL_HEIGHT + Globals.PARCEL_HEIGHT-1 + ): + for x in range( + coords.x*Globals.PARCEL_WIDTH, + coords.x*Globals.PARCEL_WIDTH + Globals.PARCEL_WIDTH-1 + ): + if Globals.map_terrain_data[y][x] == Globals.TILE_TERRAIN: + return false + #terrain_tile_count += 1 + + # parcel is ok if it has at least one land + #if terrain_tile_count > 0: + # return false + return true + func read_image_pixel_data() -> void: # initialize the array to have enough rows diff --git a/source/camera/Camera.gd b/source/camera/Camera.gd index 8c1650c..6154f63 100644 --- a/source/camera/Camera.gd +++ b/source/camera/Camera.gd @@ -4,6 +4,7 @@ extends Camera2D signal camera_rotation_changed(new_rotation) signal camera_zoom_changed(new_zoom_factor) +signal camera_pos_changed(new_pos) var is_panning_camera:bool = false var tween:Tween @@ -31,13 +32,17 @@ func get_camera_rotation(): return self.rotation +func get_camera_zoom_level() -> float: + return Globals.CAMERA_ZOOM_LEVEL + + func set_camera_panning(value:bool) -> void: self.is_panning_camera = value func set_camera_position(pos: Vector2) -> void: self.position = pos - print("camera pos set:", self.position) + emit_signal("camera_pos_changed", pos) func set_camera_limits() -> void: diff --git a/source/game/ChunkHandler.gd b/source/game/ChunkHandler.gd index 5b248a2..545a981 100644 --- a/source/game/ChunkHandler.gd +++ b/source/game/ChunkHandler.gd @@ -10,7 +10,7 @@ extends Node2D # which is extremely slow in godot 4.0, 4096x4096 takes minutes to fill with set_cell() commands -signal chunk_stats(chunks, removal_queue) +signal chunk_stats(chunks:int, removal_queue:int) var chunks:Dictionary = {} var chunks_to_remove:Array[Chunk] = [] diff --git a/source/mainmenu/MainMenu.gd b/source/mainmenu/MainMenu.gd index 973fa3f..c1e4453 100644 --- a/source/mainmenu/MainMenu.gd +++ b/source/mainmenu/MainMenu.gd @@ -3,13 +3,9 @@ extends Control signal button_pressed(button_name) -# Connect main menu to Main game - -#func _process(delta): -# print("aaa") - func set_ready(): + # Connect main menu to Main game self.connect("button_pressed", self.get_parent()._on_mainmenu_button_pressed, CONNECT_PERSIST) self.find_child("Menu_ResumeGame").disabled = true diff --git a/source/uilayer/CameraMarker.gd b/source/uilayer/CameraMarker.gd index 9e70292..6f708a3 100644 --- a/source/uilayer/CameraMarker.gd +++ b/source/uilayer/CameraMarker.gd @@ -11,12 +11,12 @@ func _draw(): # Rotates the box if camera is rotated -func _on_camera_zoom_2d_camera_rotation_changed(new_rotation): +func set_camera_marker_rotation(new_rotation): self.rotation = new_rotation # Redraws the box to a different size if camera is zoomed -func _on_camera_zoom_2d_camera_zoom_changed(new_zoom_factor): +func set_camera_marker_zoom(new_zoom_factor): w_s = DisplayServer.window_get_size(0) / size_multiplier w_s.x /= new_zoom_factor w_s.y /= new_zoom_factor diff --git a/source/uilayer/DebugInfo.gd b/source/uilayer/DebugInfo.gd new file mode 100644 index 0000000..5002a28 --- /dev/null +++ b/source/uilayer/DebugInfo.gd @@ -0,0 +1,85 @@ +class_name DebugInfo +extends GridContainer + + +@onready var fps_label:Label +@onready var cam_pos_label:Label +@onready var cam_rotation_label:Label +@onready var cam_zoom_label:Label +@onready var chunk_label:Label +@onready var chunk_del_label:Label + + +func set_ready(): + fps_label = find_child("FPSLabel") + cam_pos_label = find_child("CamPosLabel") + cam_rotation_label = find_child("CamRotationLabel") + cam_zoom_label = find_child("CamZoomLabel") + chunk_label = find_child("ChunkLabel") + chunk_del_label = find_child("ChunkDelLabel") + + +func _process(_delta): + self.set_fps_label(Engine.get_frames_per_second()) + + +func _on_camera_pos_changed(new_pos): + self.set_cam_pos_label(new_pos) + + +func _on_camera_rotation_changed(new_rotation): + self.set_cam_rotation(new_rotation) + + +func _on_camera_zoom_changed(new_zoom_factor): + self.set_cam_zoom_label(new_zoom_factor) + + +func _on_chunk_handler_chunk_stats(chunks:int, removal_queue:int): + if !chunk_label or !chunk_del_label: + return + self.set_chunk_label(chunks) + self.set_chunk_del_label(removal_queue) + + +func set_fps_label(info:float) -> void: + self.fps_label.set_text("FPS: " + str(info)) + + +func set_cam_pos_label(info:Vector2) -> void: + if info == null: + self.cam_pos_label.set_text("Cam pos: unknown") + return + self.cam_pos_label.set_text("Cam pos: " + str(info)) + + +func set_cam_rotation(info) -> void: + if info == null: + self.cam_rotation_label.set_text("Cam rot: unknown") + return + self.cam_rotation_label.set_text("Cam rot: " + str(info)) + + +func set_cam_zoom_label(info:float) -> void: + if info == null: + self.cam_zoom_label.set_text("Zoom : unknown") + return + self.cam_zoom_label.set_text("Zoom :" + str(info)) + + +func set_chunk_label(info:int) -> void: + if info == null: + self.chunk_label.set_text("Chunks: unknown") + return + self.chunk_label.set_text("Chunks: " + str(info)) + + +func set_chunk_del_label(info:int) -> void: + if info == null: + self.chunk_del_label.set_text("Chunk del: unknown") + return + self.chunk_del_label.set_text("Chunk del: " + str(info)) + + + + diff --git a/source/uilayer/Minimap.gd b/source/uilayer/Minimap.gd index a8e72f3..b82177f 100644 --- a/source/uilayer/Minimap.gd +++ b/source/uilayer/Minimap.gd @@ -94,7 +94,6 @@ func set_minimap() -> void: func set_ready() -> void: # 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 diff --git a/source/uilayer/Control.gd b/source/uilayer/UIControl.gd similarity index 69% rename from source/uilayer/Control.gd rename to source/uilayer/UIControl.gd index 1aec601..1eaf5cc 100644 --- a/source/uilayer/Control.gd +++ b/source/uilayer/UIControl.gd @@ -1,15 +1,15 @@ +class_name UIControl extends Control # var view = get_node("../View") signal construction_button_pressed(button_name, button_type) signal infolayer_button_pressed(button_type) -@onready var debug_info = get_node("DebugContainer/" + Globals.DEBUGINFO_NODE) -@onready var minimap:Minimap +#@onready var node_minimap:Minimap +@onready var node_debuginfo:DebugInfo var amount_of_chunks:int = 0 var size_of_chunk_removal_queue:int = 0 -var update_debug_info:bool = false # name, position @@ -30,16 +30,13 @@ func _on_chunk_handler_chunk_stats(chunks, removal_queue): # Called when the node enters the scene tree for the first time. -func _ready(): +func set_ready(): create_buttons() - minimap = Minimap.new() + ##node_minimap = Minimap.new() + node_debuginfo = find_child("DebugInfo") + node_debuginfo.set_ready() -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(_delta): - update_debug_info_func() - - # sends signals which View catches and places selected type of buildings func _on_button_residental_pressed(): emit_signal("construction_button_pressed", Globals.TYPE_RESIDENTIAL, 0) @@ -75,7 +72,6 @@ func _on_button_infolayer_parcels_pressed(): func _on_main_worldgen_ready(): self.set_process(true) - update_debug_info = true # defines construction toolbar buttons @@ -94,21 +90,5 @@ func create_buttons(): node_path.set_text(values[1]) node_path.show() -func update_debug_info_func(): - debug_info.set_text( - "FPS " + str(Engine.get_frames_per_second()) + "\n" + - "Camera pos: " + str(Globals.CAMERA_POSITION) + "\n" + - "Chunks: " + str(self.amount_of_chunks) + "\n" + - "Chunk del: " + str(self.size_of_chunk_removal_queue) - ) -# 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), -# ) diff --git a/source/uilayer/UILayer.gd b/source/uilayer/UILayer.gd index 0df4d76..88dba70 100644 --- a/source/uilayer/UILayer.gd +++ b/source/uilayer/UILayer.gd @@ -2,13 +2,25 @@ class_name UILayer extends CanvasLayer @onready var node_minimap:Minimap +@onready var node_ui_control:UIControl +@onready var node_camera_marker:CameraMarker func _ready() -> void: node_minimap = find_child("Minimap") + node_camera_marker = find_child("CameraMarker") + node_ui_control = find_child("UIControl") func set_ready() -> void: node_minimap.set_ready() + node_ui_control.set_ready() + +func camera_rotation_changed(new_rotation): + node_camera_marker.set_camera_marker_rotation(new_rotation) + + +func camera_zoom_changed(new_zoom_factor): + node_camera_marker.set_camera_marker_zoom(new_zoom_factor)