mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-19 09:39:48 +00:00
Change tile editing mode from the UI
This commit is contained in:
parent
7893ae2531
commit
cadd7c57f1
|
@ -1,10 +1,7 @@
|
||||||
class_name CelTileMap
|
class_name CelTileMap
|
||||||
extends PixelCel
|
extends PixelCel
|
||||||
|
|
||||||
enum TileEditingMode { MANUAL, AUTO, STACK }
|
|
||||||
|
|
||||||
var tileset: TileSetCustom
|
var tileset: TileSetCustom
|
||||||
var tile_editing_mode := TileEditingMode.AUTO
|
|
||||||
var indices := PackedInt32Array()
|
var indices := PackedInt32Array()
|
||||||
var indices_x: int
|
var indices_x: int
|
||||||
var indices_y: int
|
var indices_y: int
|
||||||
|
@ -20,7 +17,7 @@ func _init(_tileset: TileSetCustom, _image: ImageExtended, _opacity := 1.0) -> v
|
||||||
|
|
||||||
func update_tileset() -> void:
|
func update_tileset() -> void:
|
||||||
var removed_tile_indices: Array[int] = []
|
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):
|
for j in range(tileset.tiles.size() - 1, 0, -1):
|
||||||
var tile := tileset.tiles[j]
|
var tile := tileset.tiles[j]
|
||||||
var tile_used := false
|
var tile_used := false
|
||||||
|
@ -45,7 +42,7 @@ func update_tileset() -> void:
|
||||||
if image_portion.is_invisible():
|
if image_portion.is_invisible():
|
||||||
continue
|
continue
|
||||||
var index := indices[i]
|
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 index == 0 or tileset.tiles.size() <= index:
|
||||||
if tileset.tiles.size() <= 1:
|
if tileset.tiles.size() <= 1:
|
||||||
tileset.add_tile(image_portion)
|
tileset.add_tile(image_portion)
|
||||||
|
|
|
@ -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:
|
func _ready() -> void:
|
||||||
|
@ -34,3 +40,18 @@ func _update_tileset() -> void:
|
||||||
texture_rect.custom_minimum_size = Vector2i(32, 32)
|
texture_rect.custom_minimum_size = Vector2i(32, 32)
|
||||||
texture_rect.texture_normal = ImageTexture.create_from_image(tile)
|
texture_rect.texture_normal = ImageTexture.create_from_image(tile)
|
||||||
h_flow_container.add_child(texture_rect)
|
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
|
||||||
|
|
|
@ -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"]
|
[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
|
anchors_preset = 15
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
|
@ -10,9 +12,40 @@ grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
script = ExtResource("1_d2oc5")
|
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
|
layout_mode = 2
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
|
size_flags_vertical = 3
|
||||||
|
|
||||||
[node name="HFlowContainer" type="HFlowContainer" parent="PanelContainer"]
|
[connection signal="toggled" from="VBoxContainer/HBoxContainer/Manual" to="." method="_on_manual_toggled"]
|
||||||
layout_mode = 2
|
[connection signal="toggled" from="VBoxContainer/HBoxContainer/Auto" to="." method="_on_auto_toggled"]
|
||||||
|
[connection signal="toggled" from="VBoxContainer/HBoxContainer/Stack" to="." method="_on_stack_toggled"]
|
||||||
|
|
Loading…
Reference in a new issue