From cadd7c57f1c571f2bd5051aeb979203756afe79e Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Fri, 22 Nov 2024 01:30:19 +0200 Subject: [PATCH] Change tile editing mode from the UI --- src/Classes/Cels/CelTileMap.gd | 7 ++---- src/UI/TilesPanel.gd | 25 ++++++++++++++++++-- src/UI/TilesPanel.tscn | 43 ++++++++++++++++++++++++++++++---- 3 files changed, 63 insertions(+), 12 deletions(-) diff --git a/src/Classes/Cels/CelTileMap.gd b/src/Classes/Cels/CelTileMap.gd index 0812b77d9..0e4207f1b 100644 --- a/src/Classes/Cels/CelTileMap.gd +++ b/src/Classes/Cels/CelTileMap.gd @@ -1,10 +1,7 @@ class_name CelTileMap extends PixelCel -enum TileEditingMode { MANUAL, AUTO, STACK } - var tileset: TileSetCustom -var tile_editing_mode := TileEditingMode.AUTO var indices := PackedInt32Array() var indices_x: int var indices_y: int @@ -20,7 +17,7 @@ func _init(_tileset: TileSetCustom, _image: ImageExtended, _opacity := 1.0) -> v func update_tileset() -> void: var removed_tile_indices: Array[int] = [] - if tile_editing_mode == TileEditingMode.AUTO: + if TileSetPanel.tile_editing_mode == TileSetPanel.TileEditingMode.AUTO: for j in range(tileset.tiles.size() - 1, 0, -1): var tile := tileset.tiles[j] var tile_used := false @@ -45,7 +42,7 @@ func update_tileset() -> void: if image_portion.is_invisible(): continue var index := indices[i] - if tile_editing_mode == TileEditingMode.MANUAL: + if TileSetPanel.tile_editing_mode == TileSetPanel.TileEditingMode.MANUAL: if index == 0 or tileset.tiles.size() <= index: if tileset.tiles.size() <= 1: tileset.add_tile(image_portion) diff --git a/src/UI/TilesPanel.gd b/src/UI/TilesPanel.gd index f5c62b09e..7e4d3fe1c 100644 --- a/src/UI/TilesPanel.gd +++ b/src/UI/TilesPanel.gd @@ -1,6 +1,12 @@ -extends ScrollContainer +class_name TileSetPanel +extends PanelContainer -@onready var h_flow_container: HFlowContainer = $PanelContainer/HFlowContainer +enum TileEditingMode { MANUAL, AUTO, STACK } + +var current_tileset: TileSetCustom +static var tile_editing_mode := TileEditingMode.AUTO + +@onready var h_flow_container: HFlowContainer = $VBoxContainer/ScrollContainer/HFlowContainer func _ready() -> void: @@ -34,3 +40,18 @@ func _update_tileset() -> void: texture_rect.custom_minimum_size = Vector2i(32, 32) texture_rect.texture_normal = ImageTexture.create_from_image(tile) h_flow_container.add_child(texture_rect) + + +func _on_manual_toggled(toggled_on: bool) -> void: + if toggled_on: + tile_editing_mode = TileEditingMode.MANUAL + + +func _on_auto_toggled(toggled_on: bool) -> void: + if toggled_on: + tile_editing_mode = TileEditingMode.AUTO + + +func _on_stack_toggled(toggled_on: bool) -> void: + if toggled_on: + tile_editing_mode = TileEditingMode.STACK diff --git a/src/UI/TilesPanel.tscn b/src/UI/TilesPanel.tscn index f7840dcbd..e764d491d 100644 --- a/src/UI/TilesPanel.tscn +++ b/src/UI/TilesPanel.tscn @@ -1,8 +1,10 @@ -[gd_scene load_steps=2 format=3 uid="uid://bfbragmmdwfbl"] +[gd_scene load_steps=3 format=3 uid="uid://bfbragmmdwfbl"] [ext_resource type="Script" path="res://src/UI/TilesPanel.gd" id="1_d2oc5"] -[node name="Tiles" type="ScrollContainer"] +[sub_resource type="ButtonGroup" id="ButtonGroup_uxnt0"] + +[node name="Tiles" type="PanelContainer"] anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 @@ -10,9 +12,40 @@ grow_horizontal = 2 grow_vertical = 2 script = ExtResource("1_d2oc5") -[node name="PanelContainer" type="PanelContainer" parent="."] +[node name="VBoxContainer" type="VBoxContainer" parent="."] +layout_mode = 2 + +[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"] +layout_mode = 2 + +[node name="Manual" type="CheckBox" parent="VBoxContainer/HBoxContainer"] +layout_mode = 2 +mouse_default_cursor_shape = 2 +button_group = SubResource("ButtonGroup_uxnt0") +text = "Manual" + +[node name="Auto" type="CheckBox" parent="VBoxContainer/HBoxContainer"] +layout_mode = 2 +mouse_default_cursor_shape = 2 +button_pressed = true +button_group = SubResource("ButtonGroup_uxnt0") +text = "Auto" + +[node name="Stack" type="CheckBox" parent="VBoxContainer/HBoxContainer"] +layout_mode = 2 +mouse_default_cursor_shape = 2 +button_group = SubResource("ButtonGroup_uxnt0") +text = "Stack" + +[node name="ScrollContainer" type="ScrollContainer" parent="VBoxContainer"] +layout_mode = 2 +size_flags_vertical = 3 + +[node name="HFlowContainer" type="HFlowContainer" parent="VBoxContainer/ScrollContainer"] layout_mode = 2 size_flags_horizontal = 3 +size_flags_vertical = 3 -[node name="HFlowContainer" type="HFlowContainer" parent="PanelContainer"] -layout_mode = 2 +[connection signal="toggled" from="VBoxContainer/HBoxContainer/Manual" to="." method="_on_manual_toggled"] +[connection signal="toggled" from="VBoxContainer/HBoxContainer/Auto" to="." method="_on_auto_toggled"] +[connection signal="toggled" from="VBoxContainer/HBoxContainer/Stack" to="." method="_on_stack_toggled"]