Skip to content

Commit 3fe91b0

Browse files
committed
view grid data
1 parent a2f43f8 commit 3fe91b0

File tree

2 files changed

+86
-49
lines changed

2 files changed

+86
-49
lines changed

Scenes/Main.tscn

+3-2
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ color = Color( 0.172549, 0.164706, 0.196078, 1 )
625625
material = SubResource( 19 )
626626
expand = true
627627
628-
[node name="oAnalyzeGrids" type="Node2D" parent="Game2D"]
628+
[node name="AnalyzeGrids" type="Node2D" parent="Game2D"]
629629
script = ExtResource( 154 )
630630
631631
[node name="Ui" type="CanvasLayer" parent="."]
@@ -1656,7 +1656,7 @@ custom_colors/font_color_hover = Color( 1, 0.65098, 0.556863, 1 )
16561656
custom_colors/font_color_pressed = Color( 0.333333, 0.607843, 1, 1 )
16571657
text = "Edit"
16581658
align = 0
1659-
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 ]
1659+
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 ]
16601660
switch_on_hover = true
16611661
__meta__ = {
16621662
"_edit_use_anchors_": false
@@ -6590,6 +6590,7 @@ script = SubResource( 20 )
65906590
[connection signal="focus_exited" from="Ui/UiSystem/ResizeCurrentMapSize/MarginContainer/VBoxContainer/HBoxContainer/SettingsYSizeLine" to="Ui/UiSystem/ResizeCurrentMapSize" method="_on_SettingsYSizeLine_focus_exited"]
65916591
[connection signal="value_changed" from="Ui/UiSystem/ResizeCurrentMapSize/MarginContainer/VBoxContainer/HBoxContainer2/VBoxContainer/ResizeFillWithID" to="Ui/UiSystem/ResizeCurrentMapSize" method="_on_ResizeFillWithID_value_changed"]
65926592
[connection signal="pressed" from="Ui/UiSystem/ResizeCurrentMapSize/MarginContainer/VBoxContainer/ResizeApplyButton" to="Ui/UiSystem/ResizeCurrentMapSize" method="_on_ResizeApplyButton_pressed"]
6593+
[connection signal="visibility_changed" from="Ui/UiSystem/GridDataWindow" to="Game2D/AnalyzeGrids" method="_on_GridDataWindow_visibility_changed"]
65936594
[connection signal="timeout" from="Ui/UiMessages/FPScounter/Timer" to="Ui/UiMessages/FPScounter" method="_on_Wait_timeout"]
65946595
[connection signal="about_to_show" from="Ui/UiPreviewExporter/ExportPreview" to="Ui/UiPreviewExporter/ExportPreview" method="_on_ExportPreview_about_to_show"]
65956596
[connection signal="hide" from="Ui/UiPreviewExporter/ExportPreview" to="Ui/UiPreviewExporter/ExportPreview" method="_on_ExportPreview_hide"]

Scenes/oAnalyzeGrids.gd

+83-47
Original file line numberDiff line numberDiff line change
@@ -14,67 +14,103 @@ onready var oGridDataCheckBox4 = Nodelist.list["oGridDataCheckBox4"]
1414
onready var oGridDataCheckBox5 = Nodelist.list["oGridDataCheckBox5"]
1515
onready var oGridDataCheckBox6 = Nodelist.list["oGridDataCheckBox6"]
1616
onready var oGridDataCheckBox7 = Nodelist.list["oGridDataCheckBox7"]
17+
onready var oGridDataWindow = Nodelist.list["oGridDataWindow"]
18+
onready var oCamera2D = Nodelist.list["oCamera2D"]
1719

1820
onready var tilemap_data = {
19-
"Wibble": {
20-
"extension": ".wib",
21-
"node": oDataWibble
22-
},
23-
"Liquid": {
24-
"extension": ".wlb",
25-
"node": oDataLiquid
26-
},
27-
"Slab": {
28-
"extension": ".slb",
29-
"node": oDataSlab
30-
},
31-
"Ownership": {
32-
"extension": ".own",
33-
"node": oDataOwnership
34-
},
35-
"ColumnPositions": {
36-
"extension": ".dat",
37-
"node": oDataClmPos
38-
},
39-
"CustomSlabs": {
40-
"extension": ".une",
41-
"node": oDataCustomSlab
42-
},
43-
"Style": {
44-
"extension": ".slx",
45-
"node": oDataSlx
46-
}
21+
"Wibble": {"extension": ".wib", "grid_type": "SUBTILE", "node": oDataWibble},
22+
"Liquid": {"extension": ".wlb", "grid_type": "TILE", "node": oDataLiquid},
23+
"Slab": {"extension": ".slb", "grid_type": "TILE", "node": oDataSlab},
24+
"Ownership": {"extension": ".own", "grid_type": "TILE", "node": oDataOwnership},
25+
"Column Positions": {"extension": ".dat", "grid_type": "SUBTILE", "node": oDataClmPos},
26+
"Custom Slabs": {"extension": ".une", "grid_type": "TILE", "node": oDataCustomSlab},
27+
"Style": {"extension": ".slx", "grid_type": "TILE", "node": oDataSlx}
4728
}
4829

49-
var tileDrawDist = 96 # Example value, adjust as needed
30+
var currentlySelected = ""
31+
5032
var dynamic_font = DynamicFont.new() # Initialize DynamicFont
5133

5234
func _ready():
35+
set_process(false)
5336
dynamic_font.font_data = preload("res://Theme/ClassicConsole.ttf")
5437
dynamic_font.size = 36
5538

56-
oGridDataCheckBox1.connect("pressed", self, "_on_checkbox", ["Slab"])
57-
oGridDataCheckBox2.connect("pressed", self, "_on_checkbox", ["Ownership"])
58-
oGridDataCheckBox3.connect("pressed", self, "_on_checkbox", ["Column Positions"])
59-
oGridDataCheckBox4.connect("pressed", self, "_on_checkbox", ["Wibble"])
60-
oGridDataCheckBox5.connect("pressed", self, "_on_checkbox", ["Liquid"])
61-
oGridDataCheckBox6.connect("pressed", self, "_on_checkbox", ["Style"])
62-
oGridDataCheckBox7.connect("pressed", self, "_on_checkbox", ["Custom Slabs"])
39+
oGridDataCheckBox1.connect("pressed", self, "_on_checkbox", [oGridDataCheckBox1,"Slab"])
40+
oGridDataCheckBox2.connect("pressed", self, "_on_checkbox", [oGridDataCheckBox2,"Ownership"])
41+
oGridDataCheckBox3.connect("pressed", self, "_on_checkbox", [oGridDataCheckBox3,"Column Positions"])
42+
oGridDataCheckBox4.connect("pressed", self, "_on_checkbox", [oGridDataCheckBox4,"Wibble"])
43+
oGridDataCheckBox5.connect("pressed", self, "_on_checkbox", [oGridDataCheckBox5,"Liquid"])
44+
oGridDataCheckBox6.connect("pressed", self, "_on_checkbox", [oGridDataCheckBox6,"Style"])
45+
oGridDataCheckBox7.connect("pressed", self, "_on_checkbox", [oGridDataCheckBox7,"Custom Slabs"])
46+
47+
func _on_checkbox(checkboxNodeThatWasPressed, pressedString):
48+
for i in [oGridDataCheckBox1, oGridDataCheckBox2, oGridDataCheckBox3, oGridDataCheckBox4, oGridDataCheckBox5, oGridDataCheckBox6, oGridDataCheckBox7]:
49+
i.add_color_override("font_color", Color("40ffffff"))
50+
checkboxNodeThatWasPressed.add_color_override("font_color", Color("40ffffff"))
51+
52+
currentlySelected = pressedString
53+
54+
55+
func _on_GridDataWindow_visibility_changed():
56+
if is_instance_valid(oGridDataWindow) == false: return
57+
if oGridDataWindow.visible == true:
58+
set_process(true)
59+
yield(get_tree(),'idle_frame')
60+
oGridDataWindow.rect_position.x = 0
61+
else:
62+
update()
63+
set_process(false)
6364

64-
func _on_checkbox(aaa):
65-
print(aaa)
65+
var frame_counter = 0 # Initialize a frame counter
66+
67+
func _process(delta):
68+
frame_counter += 1 # Increment the frame counter each frame
69+
if frame_counter >= 30: # Check if 30 frames have passed
70+
update() # Call the update function to redraw the screen
71+
frame_counter = 0 # Reset the frame counter
6672

6773
func _draw():
68-
return
69-
if is_instance_valid(oDataWibble) == false: return
74+
if currentlySelected == "" or oGridDataWindow.visible == false:
75+
return
76+
77+
var node = tilemap_data[currentlySelected]["node"]
78+
var grid_type = tilemap_data[currentlySelected]["grid_type"]
79+
var value
80+
var pos
81+
var factor
82+
if grid_type == "TILE":
83+
factor = 1
84+
else:
85+
factor = 3
86+
var tileDrawDist = 96/factor
87+
if currentlySelected == "Column Positions":
88+
dynamic_font.size = 18
89+
else:
90+
dynamic_font.size = 36
91+
92+
var half_tileDrawDist = tileDrawDist * 0.5
93+
if currentlySelected == "Style": oDataSlx.slxImgData.lock()
7094

71-
var node = tilemap_data["Slab"]["node"]
95+
var offsetTilePos = Vector2(half_tileDrawDist, half_tileDrawDist)
96+
if currentlySelected == "Wibble":
97+
offsetTilePos = Vector2(0,0)
7298

73-
for x in range(M.xSize):
74-
for y in range(M.ySize):
75-
var value = node.get_cell(x,y)
99+
var viewport_size = get_viewport_rect().size
100+
var screen_start = oCamera2D.get_camera_screen_center() - (viewport_size * 0.5) * oCamera2D.zoom
101+
var screen_end = oCamera2D.get_camera_screen_center() + (viewport_size * 0.5) * oCamera2D.zoom
102+
103+
for x in range(max(0, floor(screen_start.x / tileDrawDist)), min(M.xSize * factor, ceil(screen_end.x / tileDrawDist))):
104+
for y in range(max(0, floor(screen_start.y / tileDrawDist)), min(M.ySize * factor, ceil(screen_end.y / tileDrawDist))):
105+
if currentlySelected == "Style":
106+
value = oDataSlx.slxImgData.get_pixel(x,y).r8
107+
else:
108+
value = node.get_cell(x,y)
76109
var string = str(value)
77-
var pos = Vector2(x * tileDrawDist, y * tileDrawDist) + Vector2(tileDrawDist * 0.5, tileDrawDist * 0.5)
78-
pos.x -= dynamic_font.get_string_size(string).x * 0.5 # Center string
79-
pos.y += dynamic_font.get_string_size(string).y * 0.25
110+
111+
pos = Vector2(x * tileDrawDist, y * tileDrawDist) + offsetTilePos
112+
var stringSize = dynamic_font.get_string_size(string)
113+
pos += Vector2(-stringSize.x * 0.5, stringSize.y * 0.25) # Center string
80114
draw_string(dynamic_font, pos, string, Color(1, 1, 1, 1))
115+
116+
if currentlySelected == "Style": oDataSlx.slxImgData.unlock()

0 commit comments

Comments
 (0)