From a2f43f83b4b5abd6ea3929ae2925091efab58a22 Mon Sep 17 00:00:00 2001 From: rainlizard Date: Wed, 1 Nov 2023 23:39:20 +1100 Subject: [PATCH] fix division by 0 bug, slabset format, grid data window --- Scenes/Camera2D.gd | 4 +- Scenes/ExportPreview.gd | 2 +- Scenes/GridDataButtongroup.tres | 3 ++ Scenes/Main.tscn | 85 ++++++++++++++++++++++++++++++++- Scenes/Menu.gd | 17 ++++--- Scenes/SlabPalette.gd | 2 +- Scenes/oAnalyzeGrids.gd | 80 +++++++++++++++++++++++++++++++ 7 files changed, 180 insertions(+), 13 deletions(-) create mode 100644 Scenes/GridDataButtongroup.tres create mode 100644 Scenes/oAnalyzeGrids.gd diff --git a/Scenes/Camera2D.gd b/Scenes/Camera2D.gd index 5ca2ee30..9ce928ba 100644 --- a/Scenes/Camera2D.gd +++ b/Scenes/Camera2D.gd @@ -42,8 +42,8 @@ func reset_camera(x, y): desired_offset = offset # Determine the zoom levels required to fit the map's width and height within the viewport - var zoomForWidth = mapWidthInPixels / OS.window_size.x - var zoomForHeight = mapHeightInPixels / OS.window_size.y + var zoomForWidth = mapWidthInPixels / max(1, OS.window_size.x) + var zoomForHeight = mapHeightInPixels / max(1, OS.window_size.y) # Set the zoom level to the maximum of the two calculated zoom levels to ensure the entire map fits within the viewport var initialZoom = max(zoomForWidth, zoomForHeight) * Settings.UI_SCALE.y diff --git a/Scenes/ExportPreview.gd b/Scenes/ExportPreview.gd index 325ebdac..31b61af4 100644 --- a/Scenes/ExportPreview.gd +++ b/Scenes/ExportPreview.gd @@ -99,7 +99,7 @@ func set_basic_camera_stuff(): func calculate_zoom(): var terrain_size = Vector3(M.xSize * 3, 8, M.ySize * 3) # Calculate the window's aspect ratio - var window_aspect_ratio = OS.window_size.x / OS.window_size.y + var window_aspect_ratio = OS.window_size.x / max(1, OS.window_size.y) # Zoom out based on the dominant dimension if window_aspect_ratio > 1: # Landscape mode diff --git a/Scenes/GridDataButtongroup.tres b/Scenes/GridDataButtongroup.tres new file mode 100644 index 00000000..0e55d740 --- /dev/null +++ b/Scenes/GridDataButtongroup.tres @@ -0,0 +1,3 @@ +[gd_resource type="ButtonGroup" format=2] + +[resource] diff --git a/Scenes/Main.tscn b/Scenes/Main.tscn index 8841284d..796bd05b 100644 --- a/Scenes/Main.tscn +++ b/Scenes/Main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=175 format=2] +[gd_scene load_steps=177 format=2] [ext_resource path="res://Scenes/SlabStyle.gd" type="Script" id=1] [ext_resource path="res://Scenes/SlabPlacement.gd" type="Script" id=2] @@ -153,6 +153,8 @@ [ext_resource path="res://Scenes/ExportPreview.gd" type="Script" id=151] [ext_resource path="res://Scenes/SpinBoxPropertiesValue.tscn" type="PackedScene" id=152] [ext_resource path="res://Scenes/ResizeCurrentMapSize.gd" type="Script" id=153] +[ext_resource path="res://Scenes/oAnalyzeGrids.gd" type="Script" id=154] +[ext_resource path="res://Scenes/GridDataButtongroup.tres" type="ButtonGroup" id=155] [sub_resource type="TileSet" id=1] 0/name = "Wibble_0.png 0" @@ -623,6 +625,9 @@ color = Color( 0.172549, 0.164706, 0.196078, 1 ) material = SubResource( 19 ) expand = true +[node name="oAnalyzeGrids" type="Node2D" parent="Game2D"] +script = ExtResource( 154 ) + [node name="Ui" type="CanvasLayer" parent="."] layer = 2 script = ExtResource( 78 ) @@ -1671,7 +1676,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 = "View" align = 0 -items = [ "Map folder", null, 0, false, false, 0, 0, null, "", false, "Script file", null, 0, false, false, 1, 0, null, "", false, "Log file", null, 0, false, false, 2, 0, null, "", false, "", null, 0, false, true, -1, 0, null, "", true, "3D: 1st person", null, 0, false, false, 3, 0, null, "", false ] +items = [ "Map folder", null, 0, false, false, 0, 0, null, "", false, "Script file", null, 0, false, false, 1, 0, null, "", false, "Log file", null, 0, false, false, 2, 0, null, "", false, "", null, 0, false, true, -1, 0, null, "", true, "3D: 1st person", null, 0, false, false, 3, 0, null, "", false, "", null, 0, false, true, -1, 0, null, "", true, "Grid data", null, 0, false, false, 4, 0, null, "", false ] switch_on_hover = true __meta__ = { "_edit_use_anchors_": false @@ -5875,6 +5880,82 @@ size_flags_horizontal = 6 size_flags_vertical = 8 text = "Apply" +[node name="GridDataWindow" type="WindowDialog" parent="Ui/UiSystem"] +visible = true +margin_left = 1704.0 +margin_top = -2160.0 +margin_right = 1985.0 +margin_bottom = -1894.0 +rect_min_size = Vector2( 281, 266 ) +mouse_filter = 1 +window_title = "Display grid data" +resizable = true + +[node name="MarginContainer" type="MarginContainer" parent="Ui/UiSystem/GridDataWindow"] +anchor_right = 1.0 +anchor_bottom = 1.0 +mouse_filter = 1 +size_flags_horizontal = 3 +size_flags_vertical = 3 +custom_constants/margin_right = 20 +custom_constants/margin_top = 20 +custom_constants/margin_left = 20 +custom_constants/margin_bottom = 20 + +[node name="VBoxContainer" type="VBoxContainer" parent="Ui/UiSystem/GridDataWindow/MarginContainer"] +margin_left = 20.0 +margin_top = 20.0 +margin_right = 262.0 +margin_bottom = 247.0 + +[node name="GridDataCheckBox1" type="CheckBox" parent="Ui/UiSystem/GridDataWindow/MarginContainer/VBoxContainer"] +margin_right = 242.0 +margin_bottom = 29.0 +group = ExtResource( 155 ) +text = "Slab (.slb)" + +[node name="GridDataCheckBox2" type="CheckBox" parent="Ui/UiSystem/GridDataWindow/MarginContainer/VBoxContainer"] +margin_top = 33.0 +margin_right = 242.0 +margin_bottom = 62.0 +group = ExtResource( 155 ) +text = "Ownership (.own)" + +[node name="GridDataCheckBox3" type="CheckBox" parent="Ui/UiSystem/GridDataWindow/MarginContainer/VBoxContainer"] +margin_top = 66.0 +margin_right = 242.0 +margin_bottom = 95.0 +group = ExtResource( 155 ) +text = "Column Positions (.dat)" + +[node name="GridDataCheckBox4" type="CheckBox" parent="Ui/UiSystem/GridDataWindow/MarginContainer/VBoxContainer"] +margin_top = 99.0 +margin_right = 242.0 +margin_bottom = 128.0 +group = ExtResource( 155 ) +text = "Wibble (.wib)" + +[node name="GridDataCheckBox5" type="CheckBox" parent="Ui/UiSystem/GridDataWindow/MarginContainer/VBoxContainer"] +margin_top = 132.0 +margin_right = 242.0 +margin_bottom = 161.0 +group = ExtResource( 155 ) +text = "Liquid (.wlb)" + +[node name="GridDataCheckBox6" type="CheckBox" parent="Ui/UiSystem/GridDataWindow/MarginContainer/VBoxContainer"] +margin_top = 165.0 +margin_right = 242.0 +margin_bottom = 194.0 +group = ExtResource( 155 ) +text = "Style (.slx)" + +[node name="GridDataCheckBox7" type="CheckBox" parent="Ui/UiSystem/GridDataWindow/MarginContainer/VBoxContainer"] +margin_top = 198.0 +margin_right = 242.0 +margin_bottom = 227.0 +group = ExtResource( 155 ) +text = "Custom Slabs (.une)" + [node name="UiMessages" type="Control" parent="Ui"] anchor_right = 1.0 anchor_bottom = 1.0 diff --git a/Scenes/Menu.gd b/Scenes/Menu.gd index 4b002ad4..5b25f51e 100644 --- a/Scenes/Menu.gd +++ b/Scenes/Menu.gd @@ -38,6 +38,7 @@ onready var oDataLof = Nodelist.list["oDataLof"] onready var oDkClm = Nodelist.list["oDkClm"] onready var oExportPreview = Nodelist.list["oExportPreview"] onready var oResizeCurrentMapSize = Nodelist.list["oResizeCurrentMapSize"] +onready var oGridDataWindow = Nodelist.list["oGridDataWindow"] var recentlyOpened = [] var recentlyOpenedPopupMenu = PopupMenu.new() @@ -248,13 +249,15 @@ func _on_ViewSubmenu_Pressed(pressedID): oGenerateTerrain.start() oUi.switch_to_1st_person() 4: - if oEditor.currentView == oEditor.VIEW_2D: - oEditor.set_view_3d() - oGenerateTerrain.start() - oUi.switch_to_3D_overhead() - 5: - if oEditor.currentView == oEditor.VIEW_3D: - oEditor.set_view_2d() + Utils.popup_centered(oGridDataWindow) +# 4: +# if oEditor.currentView == oEditor.VIEW_2D: +# oEditor.set_view_3d() +# oGenerateTerrain.start() +# oUi.switch_to_3D_overhead() +# 5: +# if oEditor.currentView == oEditor.VIEW_3D: +# oEditor.set_view_2d() func _on_MenuButtonSettings_pressed(): oMenuButtonSettings.get_popup().visible = false diff --git a/Scenes/SlabPalette.gd b/Scenes/SlabPalette.gd index 971d81dd..16196de9 100644 --- a/Scenes/SlabPalette.gd +++ b/Scenes/SlabPalette.gd @@ -447,7 +447,7 @@ func create_cfg_slabset(filePath): #"res://slabset.cfg" 4: beginLine = 'RelativeY' 5: beginLine = 'RelativeZ' 6: beginLine = 'ThingType' - 7: beginLine = 'ThingSubtype' + 7: beginLine = 'Subtype' 8: beginLine = 'EffectRange' if z == 1: continue # skip "VariationIndex" diff --git a/Scenes/oAnalyzeGrids.gd b/Scenes/oAnalyzeGrids.gd new file mode 100644 index 00000000..38296661 --- /dev/null +++ b/Scenes/oAnalyzeGrids.gd @@ -0,0 +1,80 @@ +extends Node2D + +onready var oDataWibble = Nodelist.list["oDataWibble"] +onready var oDataLiquid = Nodelist.list["oDataLiquid"] +onready var oDataSlab = Nodelist.list["oDataSlab"] +onready var oDataOwnership = Nodelist.list["oDataOwnership"] +onready var oDataClmPos = Nodelist.list["oDataClmPos"] +onready var oDataCustomSlab = Nodelist.list["oDataCustomSlab"] +onready var oDataSlx = Nodelist.list["oDataSlx"] +onready var oGridDataCheckBox1 = Nodelist.list["oGridDataCheckBox1"] +onready var oGridDataCheckBox2 = Nodelist.list["oGridDataCheckBox2"] +onready var oGridDataCheckBox3 = Nodelist.list["oGridDataCheckBox3"] +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 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 + } +} + +var tileDrawDist = 96 # Example value, adjust as needed +var dynamic_font = DynamicFont.new() # Initialize DynamicFont + +func _ready(): + 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"]) + +func _on_checkbox(aaa): + print(aaa) + +func _draw(): + return + if is_instance_valid(oDataWibble) == false: return + + var node = tilemap_data["Slab"]["node"] + + for x in range(M.xSize): + for y in range(M.ySize): + var 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 + draw_string(dynamic_font, pos, string, Color(1, 1, 1, 1))