From 3fe91b08448bb15e82edc9af409b3a821ec1a241 Mon Sep 17 00:00:00 2001 From: rainlizard Date: Fri, 3 Nov 2023 12:08:09 +1100 Subject: [PATCH] view grid data --- Scenes/Main.tscn | 5 +- Scenes/oAnalyzeGrids.gd | 130 +++++++++++++++++++++++++--------------- 2 files changed, 86 insertions(+), 49 deletions(-) diff --git a/Scenes/Main.tscn b/Scenes/Main.tscn index 796bd05b..4913e19f 100644 --- a/Scenes/Main.tscn +++ b/Scenes/Main.tscn @@ -625,7 +625,7 @@ color = Color( 0.172549, 0.164706, 0.196078, 1 ) material = SubResource( 19 ) expand = true -[node name="oAnalyzeGrids" type="Node2D" parent="Game2D"] +[node name="AnalyzeGrids" type="Node2D" parent="Game2D"] script = ExtResource( 154 ) [node name="Ui" type="CanvasLayer" parent="."] @@ -1656,7 +1656,7 @@ custom_colors/font_color_hover = Color( 1, 0.65098, 0.556863, 1 ) custom_colors/font_color_pressed = Color( 0.333333, 0.607843, 1, 1 ) text = "Edit" align = 0 -items = [ "Columns", null, 0, false, false, 0, 0, null, "", false, "Custom objects", null, 0, false, false, 1, 0, null, "", false, "Resize and shift", null, 0, false, false, 2, 0, null, "", false, "Update all slabs", null, 0, false, false, 3, 0, null, "", false, "", null, 0, false, true, -1, 0, null, "", true, "Make a tileset", null, 0, false, false, 4, 0, null, "", false, "Slabset", null, 0, false, false, 5, 0, null, "", false ] +items = [ "Columns", null, 0, false, false, 0, 0, null, "", false, "Custom objects", null, 0, false, false, 1, 0, null, "", false, "Resize map", null, 0, false, false, 2, 0, null, "", false, "Update all slabs", null, 0, false, false, 3, 0, null, "", false, "", null, 0, false, true, -1, 0, null, "", true, "Make a tileset", null, 0, false, false, 4, 0, null, "", false, "Slabset", null, 0, false, false, 5, 0, null, "", false ] switch_on_hover = true __meta__ = { "_edit_use_anchors_": false @@ -6590,6 +6590,7 @@ script = SubResource( 20 ) [connection signal="focus_exited" from="Ui/UiSystem/ResizeCurrentMapSize/MarginContainer/VBoxContainer/HBoxContainer/SettingsYSizeLine" to="Ui/UiSystem/ResizeCurrentMapSize" method="_on_SettingsYSizeLine_focus_exited"] [connection signal="value_changed" from="Ui/UiSystem/ResizeCurrentMapSize/MarginContainer/VBoxContainer/HBoxContainer2/VBoxContainer/ResizeFillWithID" to="Ui/UiSystem/ResizeCurrentMapSize" method="_on_ResizeFillWithID_value_changed"] [connection signal="pressed" from="Ui/UiSystem/ResizeCurrentMapSize/MarginContainer/VBoxContainer/ResizeApplyButton" to="Ui/UiSystem/ResizeCurrentMapSize" method="_on_ResizeApplyButton_pressed"] +[connection signal="visibility_changed" from="Ui/UiSystem/GridDataWindow" to="Game2D/AnalyzeGrids" method="_on_GridDataWindow_visibility_changed"] [connection signal="timeout" from="Ui/UiMessages/FPScounter/Timer" to="Ui/UiMessages/FPScounter" method="_on_Wait_timeout"] [connection signal="about_to_show" from="Ui/UiPreviewExporter/ExportPreview" to="Ui/UiPreviewExporter/ExportPreview" method="_on_ExportPreview_about_to_show"] [connection signal="hide" from="Ui/UiPreviewExporter/ExportPreview" to="Ui/UiPreviewExporter/ExportPreview" method="_on_ExportPreview_hide"] diff --git a/Scenes/oAnalyzeGrids.gd b/Scenes/oAnalyzeGrids.gd index 38296661..210b59e9 100644 --- a/Scenes/oAnalyzeGrids.gd +++ b/Scenes/oAnalyzeGrids.gd @@ -14,67 +14,103 @@ onready var oGridDataCheckBox4 = Nodelist.list["oGridDataCheckBox4"] onready var oGridDataCheckBox5 = Nodelist.list["oGridDataCheckBox5"] onready var oGridDataCheckBox6 = Nodelist.list["oGridDataCheckBox6"] onready var oGridDataCheckBox7 = Nodelist.list["oGridDataCheckBox7"] +onready var oGridDataWindow = Nodelist.list["oGridDataWindow"] +onready var oCamera2D = Nodelist.list["oCamera2D"] onready var tilemap_data = { - "Wibble": { - "extension": ".wib", - "node": oDataWibble - }, - "Liquid": { - "extension": ".wlb", - "node": oDataLiquid - }, - "Slab": { - "extension": ".slb", - "node": oDataSlab - }, - "Ownership": { - "extension": ".own", - "node": oDataOwnership - }, - "ColumnPositions": { - "extension": ".dat", - "node": oDataClmPos - }, - "CustomSlabs": { - "extension": ".une", - "node": oDataCustomSlab - }, - "Style": { - "extension": ".slx", - "node": oDataSlx - } + "Wibble": {"extension": ".wib", "grid_type": "SUBTILE", "node": oDataWibble}, + "Liquid": {"extension": ".wlb", "grid_type": "TILE", "node": oDataLiquid}, + "Slab": {"extension": ".slb", "grid_type": "TILE", "node": oDataSlab}, + "Ownership": {"extension": ".own", "grid_type": "TILE", "node": oDataOwnership}, + "Column Positions": {"extension": ".dat", "grid_type": "SUBTILE", "node": oDataClmPos}, + "Custom Slabs": {"extension": ".une", "grid_type": "TILE", "node": oDataCustomSlab}, + "Style": {"extension": ".slx", "grid_type": "TILE", "node": oDataSlx} } -var tileDrawDist = 96 # Example value, adjust as needed +var currentlySelected = "" + var dynamic_font = DynamicFont.new() # Initialize DynamicFont func _ready(): + set_process(false) dynamic_font.font_data = preload("res://Theme/ClassicConsole.ttf") dynamic_font.size = 36 - oGridDataCheckBox1.connect("pressed", self, "_on_checkbox", ["Slab"]) - oGridDataCheckBox2.connect("pressed", self, "_on_checkbox", ["Ownership"]) - oGridDataCheckBox3.connect("pressed", self, "_on_checkbox", ["Column Positions"]) - oGridDataCheckBox4.connect("pressed", self, "_on_checkbox", ["Wibble"]) - oGridDataCheckBox5.connect("pressed", self, "_on_checkbox", ["Liquid"]) - oGridDataCheckBox6.connect("pressed", self, "_on_checkbox", ["Style"]) - oGridDataCheckBox7.connect("pressed", self, "_on_checkbox", ["Custom Slabs"]) + oGridDataCheckBox1.connect("pressed", self, "_on_checkbox", [oGridDataCheckBox1,"Slab"]) + oGridDataCheckBox2.connect("pressed", self, "_on_checkbox", [oGridDataCheckBox2,"Ownership"]) + oGridDataCheckBox3.connect("pressed", self, "_on_checkbox", [oGridDataCheckBox3,"Column Positions"]) + oGridDataCheckBox4.connect("pressed", self, "_on_checkbox", [oGridDataCheckBox4,"Wibble"]) + oGridDataCheckBox5.connect("pressed", self, "_on_checkbox", [oGridDataCheckBox5,"Liquid"]) + oGridDataCheckBox6.connect("pressed", self, "_on_checkbox", [oGridDataCheckBox6,"Style"]) + oGridDataCheckBox7.connect("pressed", self, "_on_checkbox", [oGridDataCheckBox7,"Custom Slabs"]) + +func _on_checkbox(checkboxNodeThatWasPressed, pressedString): + for i in [oGridDataCheckBox1, oGridDataCheckBox2, oGridDataCheckBox3, oGridDataCheckBox4, oGridDataCheckBox5, oGridDataCheckBox6, oGridDataCheckBox7]: + i.add_color_override("font_color", Color("40ffffff")) + checkboxNodeThatWasPressed.add_color_override("font_color", Color("40ffffff")) + + currentlySelected = pressedString + + +func _on_GridDataWindow_visibility_changed(): + if is_instance_valid(oGridDataWindow) == false: return + if oGridDataWindow.visible == true: + set_process(true) + yield(get_tree(),'idle_frame') + oGridDataWindow.rect_position.x = 0 + else: + update() + set_process(false) -func _on_checkbox(aaa): - print(aaa) +var frame_counter = 0 # Initialize a frame counter + +func _process(delta): + frame_counter += 1 # Increment the frame counter each frame + if frame_counter >= 30: # Check if 30 frames have passed + update() # Call the update function to redraw the screen + frame_counter = 0 # Reset the frame counter func _draw(): - return - if is_instance_valid(oDataWibble) == false: return + if currentlySelected == "" or oGridDataWindow.visible == false: + return + + var node = tilemap_data[currentlySelected]["node"] + var grid_type = tilemap_data[currentlySelected]["grid_type"] + var value + var pos + var factor + if grid_type == "TILE": + factor = 1 + else: + factor = 3 + var tileDrawDist = 96/factor + if currentlySelected == "Column Positions": + dynamic_font.size = 18 + else: + dynamic_font.size = 36 + + var half_tileDrawDist = tileDrawDist * 0.5 + if currentlySelected == "Style": oDataSlx.slxImgData.lock() - var node = tilemap_data["Slab"]["node"] + var offsetTilePos = Vector2(half_tileDrawDist, half_tileDrawDist) + if currentlySelected == "Wibble": + offsetTilePos = Vector2(0,0) - for x in range(M.xSize): - for y in range(M.ySize): - var value = node.get_cell(x,y) + var viewport_size = get_viewport_rect().size + var screen_start = oCamera2D.get_camera_screen_center() - (viewport_size * 0.5) * oCamera2D.zoom + var screen_end = oCamera2D.get_camera_screen_center() + (viewport_size * 0.5) * oCamera2D.zoom + + for x in range(max(0, floor(screen_start.x / tileDrawDist)), min(M.xSize * factor, ceil(screen_end.x / tileDrawDist))): + for y in range(max(0, floor(screen_start.y / tileDrawDist)), min(M.ySize * factor, ceil(screen_end.y / tileDrawDist))): + if currentlySelected == "Style": + value = oDataSlx.slxImgData.get_pixel(x,y).r8 + else: + value = node.get_cell(x,y) var string = str(value) - var pos = Vector2(x * tileDrawDist, y * tileDrawDist) + Vector2(tileDrawDist * 0.5, tileDrawDist * 0.5) - pos.x -= dynamic_font.get_string_size(string).x * 0.5 # Center string - pos.y += dynamic_font.get_string_size(string).y * 0.25 + + pos = Vector2(x * tileDrawDist, y * tileDrawDist) + offsetTilePos + var stringSize = dynamic_font.get_string_size(string) + pos += Vector2(-stringSize.x * 0.5, stringSize.y * 0.25) # Center string draw_string(dynamic_font, pos, string, Color(1, 1, 1, 1)) + + if currentlySelected == "Style": oDataSlx.slxImgData.unlock()