1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-31 15:39:49 +00:00

Add a dialog when creating a tilemap layer to allow users to set the tileset's settings

This commit is contained in:
Emmanouil Papadeas 2024-11-25 02:44:32 +02:00
parent fc8f21a436
commit 46ebb0930c
5 changed files with 147 additions and 23 deletions

View file

@ -42,3 +42,7 @@ func new_cel_from_image(image: Image) -> PixelCel:
var image_extended := ImageExtended.new() var image_extended := ImageExtended.new()
image_extended.copy_from_custom(image, project.is_indexed()) image_extended.copy_from_custom(image, project.is_indexed())
return CelTileMap.new(tileset, image_extended) return CelTileMap.new(tileset, image_extended)
func set_name_to_default(number: int) -> void:
name = tr("Tilemap") + " %s" % number

View file

@ -55,9 +55,10 @@ var global_layer_expand := true
@onready var play_forward := %PlayForward as Button @onready var play_forward := %PlayForward as Button
@onready var fps_spinbox := %FPSValue as ValueSlider @onready var fps_spinbox := %FPSValue as ValueSlider
@onready var onion_skinning_button := %OnionSkinning as BaseButton @onready var onion_skinning_button := %OnionSkinning as BaseButton
@onready var timeline_settings := $TimelineSettings as Popup
@onready var cel_size_slider := %CelSizeSlider as ValueSlider @onready var cel_size_slider := %CelSizeSlider as ValueSlider
@onready var loop_animation_button := %LoopAnim as BaseButton @onready var loop_animation_button := %LoopAnim as BaseButton
@onready var timeline_settings := $TimelineSettings as Popup
@onready var new_tile_map_layer_dialog := $NewTileMapLayerDialog as ConfirmationDialog
@onready var drag_highlight := $DragHighlight as ColorRect @onready var drag_highlight := $DragHighlight as ColorRect
@ -70,7 +71,7 @@ func _ready() -> void:
cel_size_slider.min_value = min_cel_size cel_size_slider.min_value = min_cel_size
cel_size_slider.max_value = max_cel_size cel_size_slider.max_value = max_cel_size
cel_size_slider.value = cel_size cel_size_slider.value = cel_size
add_layer_list.get_popup().id_pressed.connect(add_layer) add_layer_list.get_popup().id_pressed.connect(_on_add_layer_list_id_pressed)
frame_scroll_bar.value_changed.connect(_frame_scroll_changed) frame_scroll_bar.value_changed.connect(_frame_scroll_changed)
animation_timer.wait_time = 1 / Global.current_project.fps animation_timer.wait_time = 1 / Global.current_project.fps
fps_spinbox.value = Global.current_project.fps fps_spinbox.value = Global.current_project.fps
@ -832,26 +833,34 @@ func _on_FuturePlacement_item_selected(index: int) -> void:
# Layer buttons # Layer buttons
func _on_add_layer_pressed() -> void:
func add_layer(type := 0) -> void:
var project := Global.current_project var project := Global.current_project
var current_layer := project.layers[project.current_layer] var layer := PixelLayer.new(project)
var l: BaseLayer add_layer(layer, project)
match type:
Global.LayerTypes.PIXEL:
l = PixelLayer.new(project)
Global.LayerTypes.GROUP:
l = GroupLayer.new(project)
Global.LayerTypes.THREE_D:
l = Layer3D.new(project)
SteamManager.set_achievement("ACH_3D_LAYER")
Global.LayerTypes.TILEMAP:
l = LayerTileMap.new(project, TileSetCustom.new(Vector2i(16, 16), project))
func _on_add_layer_list_id_pressed(id: int) -> void:
if id == Global.LayerTypes.TILEMAP:
new_tile_map_layer_dialog.popup_centered()
else:
var project := Global.current_project
var layer: BaseLayer
match id:
Global.LayerTypes.PIXEL:
layer = PixelLayer.new(project)
Global.LayerTypes.GROUP:
layer = GroupLayer.new(project)
Global.LayerTypes.THREE_D:
layer = Layer3D.new(project)
SteamManager.set_achievement("ACH_3D_LAYER")
add_layer(layer, project)
func add_layer(layer: BaseLayer, project: Project) -> void:
var current_layer := project.layers[project.current_layer]
var cels := [] var cels := []
for f in project.frames: for f in project.frames:
cels.append(l.new_empty_cel()) cels.append(layer.new_empty_cel())
var new_layer_idx := project.current_layer + 1 var new_layer_idx := project.current_layer + 1
if current_layer is GroupLayer: if current_layer is GroupLayer:
@ -864,14 +873,14 @@ func add_layer(type := 0) -> void:
layer_button.visible = expanded layer_button.visible = expanded
Global.cel_vbox.get_child(layer_button.get_index()).visible = expanded Global.cel_vbox.get_child(layer_button.get_index()).visible = expanded
# make layer child of group # make layer child of group
l.parent = Global.current_project.layers[project.current_layer] layer.parent = Global.current_project.layers[project.current_layer]
else: else:
# set the parent of layer to be the same as the layer below it # set the parent of layer to be the same as the layer below it
l.parent = Global.current_project.layers[project.current_layer].parent layer.parent = Global.current_project.layers[project.current_layer].parent
project.undos += 1 project.undos += 1
project.undo_redo.create_action("Add Layer") project.undo_redo.create_action("Add Layer")
project.undo_redo.add_do_method(project.add_layers.bind([l], [new_layer_idx], [cels])) project.undo_redo.add_do_method(project.add_layers.bind([layer], [new_layer_idx], [cels]))
project.undo_redo.add_undo_method(project.remove_layers.bind([new_layer_idx])) project.undo_redo.add_undo_method(project.remove_layers.bind([new_layer_idx]))
project.undo_redo.add_do_method(project.change_cel.bind(-1, new_layer_idx)) project.undo_redo.add_do_method(project.change_cel.bind(-1, new_layer_idx))
project.undo_redo.add_undo_method(project.change_cel.bind(-1, project.current_layer)) project.undo_redo.add_undo_method(project.change_cel.bind(-1, project.current_layer))

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=76 format=3 uid="uid://dbr6mulku2qju"] [gd_scene load_steps=77 format=3 uid="uid://dbr6mulku2qju"]
[ext_resource type="Script" path="res://src/UI/Timeline/AnimationTimeline.gd" id="1"] [ext_resource type="Script" path="res://src/UI/Timeline/AnimationTimeline.gd" id="1"]
[ext_resource type="Texture2D" uid="uid://d36mlbmq06q4e" path="res://assets/graphics/layers/new.png" id="2"] [ext_resource type="Texture2D" uid="uid://d36mlbmq06q4e" path="res://assets/graphics/layers/new.png" id="2"]
@ -26,6 +26,7 @@
[ext_resource type="Texture2D" uid="uid://cerkv5yx4cqeh" path="res://assets/graphics/timeline/copy_frame.png" id="27"] [ext_resource type="Texture2D" uid="uid://cerkv5yx4cqeh" path="res://assets/graphics/timeline/copy_frame.png" id="27"]
[ext_resource type="Texture2D" uid="uid://dndlglvqc7v6a" path="res://assets/graphics/layers/group_expanded.png" id="27_lrc8y"] [ext_resource type="Texture2D" uid="uid://dndlglvqc7v6a" path="res://assets/graphics/layers/group_expanded.png" id="27_lrc8y"]
[ext_resource type="Texture2D" uid="uid://dukip7mvotxsp" path="res://assets/graphics/timeline/onion_skinning_off.png" id="29"] [ext_resource type="Texture2D" uid="uid://dukip7mvotxsp" path="res://assets/graphics/timeline/onion_skinning_off.png" id="29"]
[ext_resource type="PackedScene" uid="uid://hbgwxlin4jun" path="res://src/UI/Timeline/NewTileMapLayerDialog.tscn" id="29_t0mtf"]
[ext_resource type="Texture2D" uid="uid://dinubfua8gqhw" path="res://assets/graphics/timeline/expandable.png" id="30"] [ext_resource type="Texture2D" uid="uid://dinubfua8gqhw" path="res://assets/graphics/timeline/expandable.png" id="30"]
[ext_resource type="Texture2D" uid="uid://fbwld5ofmocm" path="res://assets/graphics/timeline/loop.png" id="31"] [ext_resource type="Texture2D" uid="uid://fbwld5ofmocm" path="res://assets/graphics/timeline/loop.png" id="31"]
@ -1116,6 +1117,8 @@ size_flags_horizontal = 0
mouse_default_cursor_shape = 2 mouse_default_cursor_shape = 2
text = "Color mode" text = "Color mode"
[node name="NewTileMapLayerDialog" parent="." instance=ExtResource("29_t0mtf")]
[node name="DragHighlight" type="ColorRect" parent="."] [node name="DragHighlight" type="ColorRect" parent="."]
visible = false visible = false
z_index = 2 z_index = 2
@ -1125,7 +1128,7 @@ offset_bottom = 40.0
mouse_filter = 2 mouse_filter = 2
color = Color(0, 0.741176, 1, 0.501961) color = Color(0, 0.741176, 1, 0.501961)
[connection signal="pressed" from="TimelineContainer/TimelineButtons/LayerTools/MarginContainer/LayerSettingsContainer/LayerButtons/AddLayer" to="." method="add_layer"] [connection signal="pressed" from="TimelineContainer/TimelineButtons/LayerTools/MarginContainer/LayerSettingsContainer/LayerButtons/AddLayer" to="." method="_on_add_layer_pressed"]
[connection signal="pressed" from="TimelineContainer/TimelineButtons/LayerTools/MarginContainer/LayerSettingsContainer/LayerButtons/RemoveLayer" to="." method="_on_RemoveLayer_pressed"] [connection signal="pressed" from="TimelineContainer/TimelineButtons/LayerTools/MarginContainer/LayerSettingsContainer/LayerButtons/RemoveLayer" to="." method="_on_RemoveLayer_pressed"]
[connection signal="pressed" from="TimelineContainer/TimelineButtons/LayerTools/MarginContainer/LayerSettingsContainer/LayerButtons/MoveUpLayer" to="." method="change_layer_order" binds= [true]] [connection signal="pressed" from="TimelineContainer/TimelineButtons/LayerTools/MarginContainer/LayerSettingsContainer/LayerButtons/MoveUpLayer" to="." method="change_layer_order" binds= [true]]
[connection signal="pressed" from="TimelineContainer/TimelineButtons/LayerTools/MarginContainer/LayerSettingsContainer/LayerButtons/MoveDownLayer" to="." method="change_layer_order" binds= [false]] [connection signal="pressed" from="TimelineContainer/TimelineButtons/LayerTools/MarginContainer/LayerSettingsContainer/LayerButtons/MoveDownLayer" to="." method="change_layer_order" binds= [false]]

View file

@ -0,0 +1,39 @@
extends ConfirmationDialog
@onready var animation_timeline := get_parent() as Control
@onready var name_line_edit: LineEdit = $GridContainer/NameLineEdit
@onready var tileset_option_button: OptionButton = $GridContainer/TilesetOptionButton
@onready var tileset_name_line_edit: LineEdit = $GridContainer/TilesetNameLineEdit
@onready var tile_size_slider: ValueSliderV2 = $GridContainer/TileSizeSlider
func _on_confirmed() -> void:
var project := Global.current_project
var layer_name := name_line_edit.text
var tileset_name := tileset_name_line_edit.text
var tile_size := tile_size_slider.value
var tileset: TileSetCustom
if tileset_option_button.selected == 0:
tileset = TileSetCustom.new(tile_size, project, tileset_name)
else:
tileset = project.tilesets[tileset_option_button.selected - 1]
var layer := LayerTileMap.new(project, tileset, layer_name)
animation_timeline.add_layer(layer, project)
func _on_visibility_changed() -> void:
Global.dialog_open(visible)
func _on_about_to_popup() -> void:
var project := Global.current_project
var default_name := tr("Tilemap") + " %s" % (project.layers.size() + 1)
name_line_edit.text = default_name
tileset_option_button.clear()
tileset_option_button.add_item("New tileset")
for i in project.tilesets.size():
var tileset := project.tilesets[i]
var item_string := " %s (%s×%s)" % [i, tileset.tile_size.x, tileset.tile_size.y]
if not tileset.name.is_empty():
item_string += ": " + tileset.name
tileset_option_button.add_item(tr("Tileset" + item_string))

View file

@ -0,0 +1,69 @@
[gd_scene load_steps=3 format=3 uid="uid://hbgwxlin4jun"]
[ext_resource type="PackedScene" path="res://src/UI/Nodes/ValueSliderV2.tscn" id="1_uvdem"]
[ext_resource type="Script" path="res://src/UI/Timeline/NewTileMapLayerDialog.gd" id="1_y2r5h"]
[node name="NewTileMapLayerDialog" type="ConfirmationDialog"]
title = "New layer"
position = Vector2i(0, 36)
size = Vector2i(300, 230)
script = ExtResource("1_y2r5h")
[node name="GridContainer" type="GridContainer" parent="."]
offset_left = 8.0
offset_top = 8.0
offset_right = 292.0
offset_bottom = 181.0
columns = 2
[node name="NameLabel" type="Label" parent="GridContainer"]
layout_mode = 2
size_flags_horizontal = 3
text = "Name:"
[node name="NameLineEdit" type="LineEdit" parent="GridContainer"]
layout_mode = 2
size_flags_horizontal = 3
text = "Tilemap 1"
[node name="TilesetLabel" type="Label" parent="GridContainer"]
layout_mode = 2
size_flags_horizontal = 3
text = "Tileset:"
[node name="TilesetOptionButton" type="OptionButton" parent="GridContainer"]
layout_mode = 2
mouse_default_cursor_shape = 2
selected = 0
item_count = 1
popup/item_0/text = "New tileset"
[node name="TilesetNameLabel" type="Label" parent="GridContainer"]
layout_mode = 2
size_flags_horizontal = 3
text = "Tileset name:"
[node name="TilesetNameLineEdit" type="LineEdit" parent="GridContainer"]
layout_mode = 2
size_flags_horizontal = 3
[node name="TileSizeLabel" type="Label" parent="GridContainer"]
layout_mode = 2
size_flags_horizontal = 3
text = "Tile size:"
[node name="TileSizeSlider" parent="GridContainer" instance=ExtResource("1_uvdem")]
layout_mode = 2
value = Vector2(16, 16)
min_value = Vector2(1, 1)
max_value = Vector2(128, 128)
allow_greater = true
show_ratio = true
prefix_x = "Width:"
prefix_y = "Height:"
suffix_x = "px"
suffix_y = "px"
[connection signal="about_to_popup" from="." to="." method="_on_about_to_popup"]
[connection signal="confirmed" from="." to="." method="_on_confirmed"]
[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"]