From f9034f8e4448251859a80db565581a6492f59fe0 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Wed, 29 Jan 2025 00:02:44 +0200 Subject: [PATCH] Add a n options button in the tiles panel --- Translations/Translations.pot | 31 ++++++++++++++ src/UI/TilesPanel.gd | 33 +++++++++++++-- src/UI/TilesPanel.tscn | 80 ++++++++++++++++++++++++++++++++++- 3 files changed, 138 insertions(+), 6 deletions(-) diff --git a/Translations/Translations.pot b/Translations/Translations.pot index 045f59023..900674b1f 100644 --- a/Translations/Translations.pot +++ b/Translations/Translations.pot @@ -3484,6 +3484,14 @@ msgstr "" msgid "Tile size:" msgstr "" +#: src/UI/TilesPanel.gd +msgid "Select a tile to place it on the canvas." +msgstr "" + +#: src/UI/TilesPanel.gd +msgid "Modify tiles on the canvas." +msgstr "" + #: src/UI/TilesPanel.tscn msgid "Draw tiles" msgstr "" @@ -3503,3 +3511,26 @@ msgstr "" #: src/UI/TilesPanel.tscn msgid "Flip tile vertically" msgstr "" + +#. Refers to manual mode, one of the three modes of tilemap layer pixel drawing. +#: src/UI/TilesPanel.tscn +msgid "Manual" +msgstr "" + +#. Refers to auto (automatic) mode, one of the three modes of tilemap layer pixel drawing. +#: src/UI/TilesPanel.tscn +msgid "Auto" +msgstr "" + +#. Refers to stack mode, one of the three modes of tilemap layer pixel drawing. +#: src/UI/TilesPanel.tscn +msgid "Stack" +msgstr "" + +#: src/UI/TilesPanel.tscn +msgid "Tile button size:" +msgstr "" + +#: src/UI/TilesPanel.tscn +msgid "Show empty tile:" +msgstr "" diff --git a/src/UI/TilesPanel.gd b/src/UI/TilesPanel.gd index 34f3a66dc..0a13f83ac 100644 --- a/src/UI/TilesPanel.gd +++ b/src/UI/TilesPanel.gd @@ -41,16 +41,21 @@ var button_size := 36: if button_size == value: return button_size = clampi(value, MIN_BUTTON_SIZE, MAX_BUTTON_SIZE) + tile_size_slider.value = button_size update_minimum_size() Global.config_cache.set_value("tileset_panel", "button_size", button_size) for button: Control in tile_button_container.get_children(): button.custom_minimum_size = Vector2(button_size, button_size) button.size = Vector2(button_size, button_size) +var show_empty_tile := true @onready var place_tiles: Button = %PlaceTiles @onready var transform_buttons_container: HFlowContainer = %TransformButtonsContainer @onready var tile_button_container: HFlowContainer = %TileButtonContainer @onready var mode_buttons_container: HFlowContainer = %ModeButtonsContainer +@onready var option_button: Button = %OptionButton +@onready var options: Popup = $Options +@onready var tile_size_slider: ValueSlider = %TileSizeSlider func _ready() -> void: @@ -59,6 +64,9 @@ func _ready() -> void: for child: Button in transform_buttons_container.get_children(): Global.disable_button(child, true) update_tip() + tile_size_slider.min_value = MIN_BUTTON_SIZE + tile_size_slider.max_value = MAX_BUTTON_SIZE + tile_size_slider.value = button_size func _gui_input(event: InputEvent) -> void: @@ -82,13 +90,13 @@ func set_tileset(tileset: TileSetCustom) -> void: current_tileset.updated.connect(_update_tileset) -func update_tip(): - var tip = %Tip +func update_tip() -> void: + var tip := %Tip tip.get_parent().visible = true if placing_tiles: - tip.text = "Select a tile to place it on the canvas." + tip.text = tr("Select a tile to place it on the canvas.") else: - tip.text = "Modify tiles on the canvas." + tip.text = tr("Modify tiles on the canvas.") func _on_cel_switched() -> void: @@ -142,6 +150,8 @@ func _create_tile_button(texture: Texture2D, index: int, button_group: ButtonGro button.add_child(texture_rect) button.tooltip_text = str(index) button.toggled.connect(_on_tile_button_toggled.bind(index)) + if index == 0 and not show_empty_tile: + button.visible = false return button @@ -219,3 +229,18 @@ func _on_rotate_pressed(clockwise: bool) -> void: is_flipped_v = ROTATION_MATRIX[final_i * 3 + 1] is_transposed = ROTATION_MATRIX[final_i * 3 + 2] break + + +func _on_option_button_pressed() -> void: + var pos := Vector2i(option_button.global_position) - options.size + options.popup_on_parent(Rect2i(pos.x - 16, pos.y + 32, options.size.x, options.size.y)) + + +func _on_tile_size_slider_value_changed(value: float) -> void: + button_size = value + + +func _on_show_empty_tile_toggled(toggled_on: bool) -> void: + show_empty_tile = toggled_on + if tile_button_container.get_child_count() > 0: + tile_button_container.get_child(0).visible = show_empty_tile diff --git a/src/UI/TilesPanel.tscn b/src/UI/TilesPanel.tscn index 19e75d440..13d0bbd79 100644 --- a/src/UI/TilesPanel.tscn +++ b/src/UI/TilesPanel.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=26 format=3 uid="uid://bfbragmmdwfbl"] +[gd_scene load_steps=28 format=3 uid="uid://bfbragmmdwfbl"] [ext_resource type="Script" path="res://src/UI/TilesPanel.gd" id="1_d2oc5"] [ext_resource type="Texture2D" uid="uid://d4by47alul2qw" path="res://assets/graphics/tiles_panel/tiles_draw.png" id="2_h0p0x"] @@ -8,6 +8,8 @@ [ext_resource type="Texture2D" uid="uid://dfq0wpxsd51co" path="res://assets/graphics/tiles_panel/tiles_manual.png" id="6_gwj5u"] [ext_resource type="Texture2D" uid="uid://7m4hln3mo2e5" path="res://assets/graphics/tiles_panel/tiles_auto.png" id="7_afsgi"] [ext_resource type="Texture2D" uid="uid://uo1ikty26del" path="res://assets/graphics/tiles_panel/tiles_stack.png" id="8_yoaya"] +[ext_resource type="Texture2D" uid="uid://dwoilatxfh1s7" path="res://assets/graphics/misc/options.png" id="9_macrc"] +[ext_resource type="Script" path="res://src/UI/Nodes/Sliders/ValueSlider.gd" id="10_wfr6s"] [sub_resource type="InputEventAction" id="InputEventAction_klv67"] action = &"toggle_draw_tiles_mode" @@ -84,7 +86,7 @@ unique_name_in_owner = true custom_minimum_size = Vector2(25, 25) layout_mode = 2 size_flags_vertical = 0 -tooltip_text = "Draw tiles mode" +tooltip_text = "Draw tiles" mouse_default_cursor_shape = 2 toggle_mode = true shortcut = SubResource("Shortcut_6ebuw") @@ -244,6 +246,24 @@ texture = ExtResource("8_yoaya") expand_mode = 1 stretch_mode = 3 +[node name="OptionButton" type="Button" parent="VBoxContainer/MarginContainer/VBoxContainer/Buttons" groups=["UIButtons"]] +unique_name_in_owner = true +custom_minimum_size = Vector2(24, 24) +layout_mode = 2 +size_flags_vertical = 4 +mouse_default_cursor_shape = 2 + +[node name="TextureRect" type="TextureRect" parent="VBoxContainer/MarginContainer/VBoxContainer/Buttons/OptionButton"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +texture = ExtResource("9_macrc") +expand_mode = 1 +stretch_mode = 3 + [node name="HSeparator" type="HSeparator" parent="VBoxContainer/MarginContainer/VBoxContainer"] layout_mode = 2 @@ -269,6 +289,59 @@ size_flags_vertical = 3 unique_name_in_owner = true layout_mode = 2 +[node name="Options" type="Popup" parent="."] +position = Vector2i(0, 36) +size = Vector2i(210, 100) +unresizable = false +borderless = false + +[node name="MarginContainer" type="MarginContainer" parent="Options"] +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="ScrollContainer" type="ScrollContainer" parent="Options/MarginContainer"] +layout_mode = 2 + +[node name="GridContainer" type="GridContainer" parent="Options/MarginContainer/ScrollContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +columns = 2 + +[node name="TileSizeLabel" type="Label" parent="Options/MarginContainer/ScrollContainer/GridContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +text = "Tile button size:" + +[node name="TileSizeSlider" type="TextureProgressBar" parent="Options/MarginContainer/ScrollContainer/GridContainer"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 3 +focus_mode = 2 +mouse_default_cursor_shape = 2 +theme_type_variation = &"ValueSlider" +min_value = 36.0 +max_value = 144.0 +value = 36.0 +nine_patch_stretch = true +stretch_margin_left = 3 +stretch_margin_top = 3 +stretch_margin_right = 3 +stretch_margin_bottom = 3 +script = ExtResource("10_wfr6s") + +[node name="ShowEmptyTileLabel" type="Label" parent="Options/MarginContainer/ScrollContainer/GridContainer"] +layout_mode = 2 +text = "Show empty tile:" + +[node name="ShowEmptyTile" type="CheckBox" parent="Options/MarginContainer/ScrollContainer/GridContainer"] +layout_mode = 2 +mouse_default_cursor_shape = 2 +button_pressed = true +text = "On" + [connection signal="toggled" from="VBoxContainer/MarginContainer/VBoxContainer/Buttons/PlaceTiles" to="." method="_on_place_tiles_toggled"] [connection signal="pressed" from="VBoxContainer/MarginContainer/VBoxContainer/Buttons/TransformButtonsContainer/RotateLeftButton" to="." method="_on_rotate_pressed" binds= [false]] [connection signal="pressed" from="VBoxContainer/MarginContainer/VBoxContainer/Buttons/TransformButtonsContainer/RotateRightButton" to="." method="_on_rotate_pressed" binds= [true]] @@ -277,3 +350,6 @@ layout_mode = 2 [connection signal="toggled" from="VBoxContainer/MarginContainer/VBoxContainer/Buttons/ModeButtonsContainer/Manual" to="." method="_on_manual_toggled"] [connection signal="toggled" from="VBoxContainer/MarginContainer/VBoxContainer/Buttons/ModeButtonsContainer/Auto" to="." method="_on_auto_toggled"] [connection signal="toggled" from="VBoxContainer/MarginContainer/VBoxContainer/Buttons/ModeButtonsContainer/Stack" to="." method="_on_stack_toggled"] +[connection signal="pressed" from="VBoxContainer/MarginContainer/VBoxContainer/Buttons/OptionButton" to="." method="_on_option_button_pressed"] +[connection signal="value_changed" from="Options/MarginContainer/ScrollContainer/GridContainer/TileSizeSlider" to="." method="_on_tile_size_slider_value_changed"] +[connection signal="toggled" from="Options/MarginContainer/ScrollContainer/GridContainer/ShowEmptyTile" to="." method="_on_show_empty_tile_toggled"]