give each debug info its own label

This commit is contained in:
Antti Hakkarainen 2023-02-18 23:49:16 +02:00
parent 01d896c7dc
commit 63afd68cbf
13 changed files with 262 additions and 128 deletions

View file

@ -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

View file

@ -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))

View file

@ -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

View file

@ -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),
# )

View file

@ -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)