mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-19 09:39:48 +00:00
Add tilesets in the project properties and a button to delete them
Can only delete tilesets that are not currently used by a tilemap layer
This commit is contained in:
parent
a9946099ef
commit
137ac25c00
|
@ -3395,6 +3395,11 @@ msgstr ""
|
||||||
msgid "Tileset:"
|
msgid "Tileset:"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#. A tileset is a collection of tiles.
|
||||||
|
#: src/UI/Dialogs/ProjectProperties.tscn
|
||||||
|
msgid "Tilesets"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
#: src/UI/Timeline/NewTileMapLayerDialog.tscn
|
#: src/UI/Timeline/NewTileMapLayerDialog.tscn
|
||||||
msgid "New tileset"
|
msgid "New tileset"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
|
@ -136,6 +136,17 @@ func get_text_info(tile_index: int) -> String:
|
||||||
return tr("Tileset") + item_string
|
return tr("Tileset") + item_string
|
||||||
|
|
||||||
|
|
||||||
|
## Finds and returns all of the [LayerTileMap]s that use this tileset.
|
||||||
|
func find_using_layers(project: Project) -> Array[LayerTileMap]:
|
||||||
|
var tilemaps: Array[LayerTileMap]
|
||||||
|
for layer in project.layers:
|
||||||
|
if layer is not LayerTileMap:
|
||||||
|
continue
|
||||||
|
if layer.tileset == self:
|
||||||
|
tilemaps.append(layer)
|
||||||
|
return tilemaps
|
||||||
|
|
||||||
|
|
||||||
## Serializes the data of this class into the form of a [Dictionary],
|
## Serializes the data of this class into the form of a [Dictionary],
|
||||||
## which is used so the data can be stored in pxo files.
|
## which is used so the data can be stored in pxo files.
|
||||||
func serialize() -> Dictionary:
|
func serialize() -> Dictionary:
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
extends AcceptDialog
|
extends AcceptDialog
|
||||||
|
|
||||||
@onready var size_value_label := $GridContainer/SizeValueLabel as Label
|
const CLOSE_TEXTURE := preload("res://assets/graphics/misc/close.svg")
|
||||||
@onready var color_mode_value_label := $GridContainer/ColorModeValueLabel as Label
|
|
||||||
@onready var frames_value_label := $GridContainer/FramesValueLabel as Label
|
@onready var size_value_label := $VBoxContainer/GridContainer/SizeValueLabel as Label
|
||||||
@onready var layers_value_label := $GridContainer/LayersValueLabel as Label
|
@onready var color_mode_value_label := $VBoxContainer/GridContainer/ColorModeValueLabel as Label
|
||||||
@onready var name_line_edit := $GridContainer/NameLineEdit as LineEdit
|
@onready var frames_value_label := $VBoxContainer/GridContainer/FramesValueLabel as Label
|
||||||
@onready var user_data_text_edit := $GridContainer/UserDataTextEdit as TextEdit
|
@onready var layers_value_label := $VBoxContainer/GridContainer/LayersValueLabel as Label
|
||||||
|
@onready var name_line_edit := $VBoxContainer/GridContainer/NameLineEdit as LineEdit
|
||||||
|
@onready var user_data_text_edit := $VBoxContainer/GridContainer/UserDataTextEdit as TextEdit
|
||||||
|
@onready var tilesets_container := $VBoxContainer/TilesetsContainer as VBoxContainer
|
||||||
|
@onready var tilesets_list := $VBoxContainer/TilesetsContainer/TilesetsList as Tree
|
||||||
|
|
||||||
|
|
||||||
func _on_visibility_changed() -> void:
|
func _on_visibility_changed() -> void:
|
||||||
|
@ -21,6 +25,25 @@ func _on_visibility_changed() -> void:
|
||||||
layers_value_label.text = str(Global.current_project.layers.size())
|
layers_value_label.text = str(Global.current_project.layers.size())
|
||||||
name_line_edit.text = Global.current_project.name
|
name_line_edit.text = Global.current_project.name
|
||||||
user_data_text_edit.text = Global.current_project.user_data
|
user_data_text_edit.text = Global.current_project.user_data
|
||||||
|
tilesets_container.visible = Global.current_project.tilesets.size() > 0
|
||||||
|
tilesets_list.clear()
|
||||||
|
var root_item := tilesets_list.create_item()
|
||||||
|
for i in Global.current_project.tilesets.size():
|
||||||
|
var tileset := Global.current_project.tilesets[i]
|
||||||
|
var tree_item := tilesets_list.create_item(root_item)
|
||||||
|
var item_text := tileset.get_text_info(i)
|
||||||
|
var using_layers := tileset.find_using_layers(Global.current_project)
|
||||||
|
for j in using_layers.size():
|
||||||
|
if j == 0:
|
||||||
|
item_text += " ("
|
||||||
|
item_text += using_layers[j].name
|
||||||
|
if j == using_layers.size() - 1:
|
||||||
|
item_text += ")"
|
||||||
|
else:
|
||||||
|
item_text += ", "
|
||||||
|
tree_item.set_text(0, item_text)
|
||||||
|
tree_item.set_metadata(0, i)
|
||||||
|
tree_item.add_button(0, CLOSE_TEXTURE, -1, using_layers.size() > 0)
|
||||||
|
|
||||||
|
|
||||||
func _on_name_line_edit_text_changed(new_text: String) -> void:
|
func _on_name_line_edit_text_changed(new_text: String) -> void:
|
||||||
|
@ -29,3 +52,20 @@ func _on_name_line_edit_text_changed(new_text: String) -> void:
|
||||||
|
|
||||||
func _on_user_data_text_edit_text_changed() -> void:
|
func _on_user_data_text_edit_text_changed() -> void:
|
||||||
Global.current_project.user_data = user_data_text_edit.text
|
Global.current_project.user_data = user_data_text_edit.text
|
||||||
|
|
||||||
|
|
||||||
|
func _on_tilesets_list_button_clicked(item: TreeItem, column: int, id: int, _mbi: int) -> void:
|
||||||
|
var tileset_index: int = item.get_metadata(column)
|
||||||
|
var project := Global.current_project
|
||||||
|
var tileset := project.tilesets[tileset_index]
|
||||||
|
if id == 0: # Delete
|
||||||
|
if tileset.find_using_layers(project).size() > 0:
|
||||||
|
return
|
||||||
|
project.undos += 1
|
||||||
|
project.undo_redo.create_action("Delete tileset")
|
||||||
|
project.undo_redo.add_do_method(func(): project.tilesets.erase(tileset))
|
||||||
|
project.undo_redo.add_do_method(Global.undo_or_redo.bind(false))
|
||||||
|
project.undo_redo.add_undo_method(func(): project.tilesets.insert(tileset_index, tileset))
|
||||||
|
project.undo_redo.add_undo_method(Global.undo_or_redo.bind(true))
|
||||||
|
project.undo_redo.commit_action()
|
||||||
|
item.free()
|
||||||
|
|
|
@ -4,75 +4,103 @@
|
||||||
|
|
||||||
[node name="ProjectProperties" type="AcceptDialog"]
|
[node name="ProjectProperties" type="AcceptDialog"]
|
||||||
title = "Project Properties"
|
title = "Project Properties"
|
||||||
size = Vector2i(197, 235)
|
position = Vector2i(0, 36)
|
||||||
|
size = Vector2i(300, 288)
|
||||||
script = ExtResource("1_0n4uc")
|
script = ExtResource("1_0n4uc")
|
||||||
|
|
||||||
[node name="GridContainer" type="GridContainer" parent="."]
|
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||||
offset_left = 8.0
|
offset_left = 8.0
|
||||||
offset_top = 8.0
|
offset_top = 8.0
|
||||||
offset_right = 189.0
|
offset_right = 292.0
|
||||||
offset_bottom = 186.0
|
offset_bottom = 239.0
|
||||||
|
|
||||||
|
[node name="GridContainer" type="GridContainer" parent="VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
columns = 2
|
columns = 2
|
||||||
|
|
||||||
[node name="SizeLabel" type="Label" parent="GridContainer"]
|
[node name="SizeLabel" type="Label" parent="VBoxContainer/GridContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
text = "Size:"
|
text = "Size:"
|
||||||
|
|
||||||
[node name="SizeValueLabel" type="Label" parent="GridContainer"]
|
[node name="SizeValueLabel" type="Label" parent="VBoxContainer/GridContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
text = "64x64"
|
text = "64x64"
|
||||||
|
|
||||||
[node name="ColorModeLabel" type="Label" parent="GridContainer"]
|
[node name="ColorModeLabel" type="Label" parent="VBoxContainer/GridContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
text = "Color mode:"
|
text = "Color mode:"
|
||||||
|
|
||||||
[node name="ColorModeValueLabel" type="Label" parent="GridContainer"]
|
[node name="ColorModeValueLabel" type="Label" parent="VBoxContainer/GridContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
text = "RGBA8"
|
text = "RGBA8"
|
||||||
|
|
||||||
[node name="FramesLabel" type="Label" parent="GridContainer"]
|
[node name="FramesLabel" type="Label" parent="VBoxContainer/GridContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
text = "Frames:"
|
text = "Frames:"
|
||||||
|
|
||||||
[node name="FramesValueLabel" type="Label" parent="GridContainer"]
|
[node name="FramesValueLabel" type="Label" parent="VBoxContainer/GridContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
text = "1"
|
text = "1"
|
||||||
|
|
||||||
[node name="LayersLabel" type="Label" parent="GridContainer"]
|
[node name="LayersLabel" type="Label" parent="VBoxContainer/GridContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
text = "Layers:"
|
text = "Layers:"
|
||||||
|
|
||||||
[node name="LayersValueLabel" type="Label" parent="GridContainer"]
|
[node name="LayersValueLabel" type="Label" parent="VBoxContainer/GridContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
text = "1"
|
text = "1"
|
||||||
|
|
||||||
[node name="NameLabel" type="Label" parent="GridContainer"]
|
[node name="NameLabel" type="Label" parent="VBoxContainer/GridContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
text = "Name:"
|
text = "Name:"
|
||||||
|
|
||||||
[node name="NameLineEdit" type="LineEdit" parent="GridContainer"]
|
[node name="NameLineEdit" type="LineEdit" parent="VBoxContainer/GridContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
||||||
[node name="UserDataLabel" type="Label" parent="GridContainer"]
|
[node name="UserDataLabel" type="Label" parent="VBoxContainer/GridContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
size_flags_vertical = 0
|
size_flags_vertical = 0
|
||||||
text = "User data:"
|
text = "User data:"
|
||||||
|
|
||||||
[node name="UserDataTextEdit" type="TextEdit" parent="GridContainer"]
|
[node name="UserDataTextEdit" type="TextEdit" parent="VBoxContainer/GridContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
scroll_fit_content_height = true
|
scroll_fit_content_height = true
|
||||||
|
|
||||||
|
[node name="TilesetsContainer" type="VBoxContainer" parent="VBoxContainer"]
|
||||||
|
visible = false
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_vertical = 3
|
||||||
|
|
||||||
|
[node name="TilesetsHeader" type="HBoxContainer" parent="VBoxContainer/TilesetsContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_constants/separation = 0
|
||||||
|
|
||||||
|
[node name="Label" type="Label" parent="VBoxContainer/TilesetsContainer/TilesetsHeader"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_type_variation = &"HeaderSmall"
|
||||||
|
text = "Tilesets"
|
||||||
|
|
||||||
|
[node name="HSeparator" type="HSeparator" parent="VBoxContainer/TilesetsContainer/TilesetsHeader"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
|
||||||
|
[node name="TilesetsList" type="Tree" parent="VBoxContainer/TilesetsContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_vertical = 3
|
||||||
|
hide_root = true
|
||||||
|
|
||||||
[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"]
|
[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"]
|
||||||
[connection signal="text_changed" from="GridContainer/NameLineEdit" to="." method="_on_name_line_edit_text_changed"]
|
[connection signal="text_changed" from="VBoxContainer/GridContainer/NameLineEdit" to="." method="_on_name_line_edit_text_changed"]
|
||||||
[connection signal="text_changed" from="GridContainer/UserDataTextEdit" to="." method="_on_user_data_text_edit_text_changed"]
|
[connection signal="text_changed" from="VBoxContainer/GridContainer/UserDataTextEdit" to="." method="_on_user_data_text_edit_text_changed"]
|
||||||
|
[connection signal="button_clicked" from="VBoxContainer/TilesetsContainer/TilesetsList" to="." method="_on_tilesets_list_button_clicked"]
|
||||||
|
|
Loading…
Reference in a new issue