mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-31 07:29:49 +00:00
Remove pre-set tool button nodes, tool setup now being done only in the Tools singleton
Now when making a new tool we only have to set it up in Tools.gd, along with its button and cursor textures and its tool options scene. Previously, we also had to put it in ToolButtons.gd and manually create a button in Tools.tscn
This commit is contained in:
parent
5bf9da243f
commit
add9ba926e
|
@ -809,9 +809,9 @@ msgid "Elliptical Selection\n\n"
|
|||
msgstr ""
|
||||
|
||||
msgid "Polygonal Selection\n"
|
||||
"Double-click to connect the last point to the starting point\n\n"
|
||||
"%s for left mouse button\n"
|
||||
"%s for right mouse button"
|
||||
"%s for right mouse button\n\n"
|
||||
"Double-click to connect the last point to the starting point"
|
||||
msgstr ""
|
||||
|
||||
msgid "Select By Color\n\n"
|
||||
|
@ -845,9 +845,9 @@ msgid "Pan\n\n"
|
|||
msgstr ""
|
||||
|
||||
msgid "Color Picker\n"
|
||||
"Select a color from a pixel of the sprite\n\n"
|
||||
"%s for left mouse button\n"
|
||||
"%s for right mouse button"
|
||||
"%s for right mouse button\n\n"
|
||||
"Select a color from a pixel of the sprite"
|
||||
msgstr ""
|
||||
|
||||
msgid "Pencil\n\n"
|
||||
|
|
|
@ -323,8 +323,7 @@ func change_button_texturerect(texture_button: TextureRect, new_file_name: Strin
|
|||
|
||||
|
||||
func update_hint_tooltips() -> void:
|
||||
var tool_buttons: Container = control.find_node("ToolButtons")
|
||||
tool_buttons.update_hintooltips()
|
||||
Tools.update_hint_tooltips()
|
||||
|
||||
for tip in ui_tooltips:
|
||||
tip.hint_tooltip = tr(ui_tooltips[tip]) % tip.shortcut.get_as_text()
|
||||
|
|
|
@ -9,32 +9,118 @@ var control := false
|
|||
var shift := false
|
||||
var alt := false
|
||||
|
||||
var _tools = {
|
||||
"RectSelect": preload("res://src/Tools/SelectionTools/RectSelect.tscn"),
|
||||
"EllipseSelect": preload("res://src/Tools/SelectionTools/EllipseSelect.tscn"),
|
||||
"PolygonSelect": preload("res://src/Tools/SelectionTools/PolygonSelect.tscn"),
|
||||
"ColorSelect": preload("res://src/Tools/SelectionTools/ColorSelect.tscn"),
|
||||
"MagicWand": preload("res://src/Tools/SelectionTools/MagicWand.tscn"),
|
||||
"Lasso": preload("res://src/Tools/SelectionTools/Lasso.tscn"),
|
||||
"Move": preload("res://src/Tools/Move.tscn"),
|
||||
"Zoom": preload("res://src/Tools/Zoom.tscn"),
|
||||
"Pan": preload("res://src/Tools/Pan.tscn"),
|
||||
"ColorPicker": preload("res://src/Tools/ColorPicker.tscn"),
|
||||
"Pencil": preload("res://src/Tools/Pencil.tscn"),
|
||||
"Eraser": preload("res://src/Tools/Eraser.tscn"),
|
||||
"Bucket": preload("res://src/Tools/Bucket.tscn"),
|
||||
"Shading": preload("res://src/Tools/Shading.tscn"),
|
||||
"LineTool": preload("res://src/Tools/LineTool.tscn"),
|
||||
"RectangleTool": preload("res://src/Tools/RectangleTool.tscn"),
|
||||
"EllipseTool": preload("res://src/Tools/EllipseTool.tscn"),
|
||||
var tools := {
|
||||
"RectSelect":
|
||||
Tool.new("RectSelect", "Rectangular Selection", "rectangle_select", "", [], "SelectionTools"),
|
||||
"EllipseSelect":
|
||||
Tool.new("EllipseSelect", "Elliptical Selection", "ellipse_select", "", [], "SelectionTools"),
|
||||
"PolygonSelect":
|
||||
Tool.new(
|
||||
"PolygonSelect",
|
||||
"Polygonal Selection",
|
||||
"polygon_select",
|
||||
"Double-click to connect the last point to the starting point",
|
||||
[],
|
||||
"SelectionTools"
|
||||
),
|
||||
"ColorSelect":
|
||||
Tool.new("ColorSelect", "Select By Color", "color_select", "", [], "SelectionTools"),
|
||||
"MagicWand": Tool.new("MagicWand", "Magic Wand", "magic_wand", "", [], "SelectionTools"),
|
||||
"Lasso": Tool.new("Lasso", "Lasso / Free Select Tool", "lasso", "", [], "SelectionTools"),
|
||||
"Move": Tool.new("Move", "Move", "move"),
|
||||
"Zoom": Tool.new("Zoom", "Zoom", "zoom"),
|
||||
"Pan": Tool.new("Pan", "Pan", "pan"),
|
||||
"ColorPicker":
|
||||
Tool.new(
|
||||
"ColorPicker", "Color Picker", "colorpicker", "Select a color from a pixel of the sprite"
|
||||
),
|
||||
"Pencil": Tool.new("Pencil", "Pencil", "pencil", "Hold %s to make a line", ["Shift"]),
|
||||
"Eraser": Tool.new("Eraser", "Eraser", "eraser", "Hold %s to make a line", ["Shift"]),
|
||||
"Bucket": Tool.new("Bucket", "Bucket", "fill"),
|
||||
"Shading": Tool.new("Shading", "Shading Tool", "shading"),
|
||||
"LineTool":
|
||||
Tool.new(
|
||||
"LineTool",
|
||||
"Line Tool",
|
||||
"linetool",
|
||||
"""Hold %s to snap the angle of the line
|
||||
Hold %s to center the shape on the click origin
|
||||
Hold %s to displace the shape's origin""",
|
||||
["Shift", "Ctrl", "Alt"]
|
||||
),
|
||||
"RectangleTool":
|
||||
Tool.new(
|
||||
"RectangleTool",
|
||||
"Rectangle Tool",
|
||||
"rectangletool",
|
||||
"""Hold %s to create a 1:1 shape
|
||||
Hold %s to center the shape on the click origin
|
||||
Hold %s to displace the shape's origin""",
|
||||
["Shift", "Ctrl", "Alt"]
|
||||
),
|
||||
"EllipseTool":
|
||||
Tool.new(
|
||||
"EllipseTool",
|
||||
"Ellipse Tool",
|
||||
"ellipsetool",
|
||||
"""Hold %s to create a 1:1 shape
|
||||
Hold %s to center the shape on the click origin
|
||||
Hold %s to displace the shape's origin""",
|
||||
["Shift", "Ctrl", "Alt"]
|
||||
),
|
||||
}
|
||||
var _slots = {}
|
||||
var _panels = {}
|
||||
|
||||
var _tool_button_scene: PackedScene = preload("res://src/Tools/ToolButton.tscn")
|
||||
var _slots := {}
|
||||
var _panels := {}
|
||||
var _tool_buttons: Node
|
||||
var _active_button := -1
|
||||
var _last_position := Vector2.INF
|
||||
|
||||
|
||||
class Tool:
|
||||
var name := ""
|
||||
var display_name := ""
|
||||
var scene: PackedScene
|
||||
var icon: Texture
|
||||
var shortcut := ""
|
||||
var extra_hint := ""
|
||||
var extra_shortcuts := [] # Array of String(s)
|
||||
var button_node: BaseButton
|
||||
|
||||
func _init(
|
||||
_name: String,
|
||||
_display_name: String,
|
||||
_shortcut: String,
|
||||
_extra_hint := "",
|
||||
_extra_shortucts := [],
|
||||
subdir := ""
|
||||
) -> void:
|
||||
name = _name
|
||||
display_name = _display_name
|
||||
shortcut = _shortcut
|
||||
extra_hint = _extra_hint
|
||||
extra_shortcuts = _extra_shortucts
|
||||
icon = load("res://assets/graphics/tools/%s.png" % name.to_lower())
|
||||
if subdir.empty():
|
||||
scene = load("res://src/Tools/%s.tscn" % name)
|
||||
else:
|
||||
scene = load("res://src/Tools/%s/%s.tscn" % [subdir, name])
|
||||
|
||||
func generate_hint_tooltip() -> String:
|
||||
var left_shortcut: String = InputMap.get_action_list("left_" + shortcut + "_tool")[0].as_text()
|
||||
var right_shortcut: String = InputMap.get_action_list("right_" + shortcut + "_tool")[0].as_text()
|
||||
var hint := display_name
|
||||
hint += "\n\n%s for left mouse button\n%s for right mouse button"
|
||||
if !extra_hint.empty():
|
||||
hint += "\n\n" + extra_hint
|
||||
|
||||
var shortcuts := [left_shortcut, right_shortcut]
|
||||
shortcuts.append_array(extra_shortcuts)
|
||||
hint = tr(hint) % shortcuts
|
||||
return hint
|
||||
|
||||
|
||||
class Slot:
|
||||
var name: String
|
||||
var kname: String
|
||||
|
@ -62,6 +148,8 @@ class Slot:
|
|||
|
||||
func _ready() -> void:
|
||||
_tool_buttons = Global.control.find_node("ToolButtons")
|
||||
for t in tools:
|
||||
add_tool_button(tools[t])
|
||||
_slots[BUTTON_LEFT] = Slot.new("Left tool")
|
||||
_slots[BUTTON_RIGHT] = Slot.new("Right tool")
|
||||
_panels[BUTTON_LEFT] = Global.control.find_node("LeftPanelContainer", true, false)
|
||||
|
@ -70,11 +158,11 @@ func _ready() -> void:
|
|||
var tool_name: String = Global.config_cache.get_value(
|
||||
_slots[BUTTON_LEFT].kname, "tool", "Pencil"
|
||||
)
|
||||
if not tool_name in _tools:
|
||||
if not tool_name in tools:
|
||||
tool_name = "Pencil"
|
||||
set_tool(tool_name, BUTTON_LEFT)
|
||||
tool_name = Global.config_cache.get_value(_slots[BUTTON_RIGHT].kname, "tool", "Eraser")
|
||||
if not tool_name in _tools:
|
||||
if not tool_name in tools:
|
||||
tool_name = "Eraser"
|
||||
set_tool(tool_name, BUTTON_RIGHT)
|
||||
|
||||
|
@ -94,10 +182,19 @@ func _ready() -> void:
|
|||
assign_color(color_value, BUTTON_RIGHT, false)
|
||||
|
||||
|
||||
func add_tool_button(t: Tool) -> void:
|
||||
var tool_button: BaseButton = _tool_button_scene.instance()
|
||||
tool_button.name = t.name
|
||||
tool_button.get_node("ToolIcon").texture = t.icon
|
||||
t.button_node = tool_button
|
||||
_tool_buttons.add_child(tool_button)
|
||||
tool_button.connect("pressed", _tool_buttons, "_on_Tool_pressed", [tool_button])
|
||||
|
||||
|
||||
func set_tool(name: String, button: int) -> void:
|
||||
var slot = _slots[button]
|
||||
var panel: Node = _panels[button]
|
||||
var node: Node = _tools[name].instance()
|
||||
var node: Node = tools[name].scene.instance()
|
||||
if button == BUTTON_LEFT: # As guides are only moved with left mouse
|
||||
if name == "Pan": # tool you want to give more access at guides
|
||||
Global.move_guides_on_canvas = true
|
||||
|
@ -176,6 +273,12 @@ func update_tool_buttons() -> void:
|
|||
right_background.visible = _slots[BUTTON_RIGHT].tool_node.name == child.name
|
||||
|
||||
|
||||
func update_hint_tooltips() -> void:
|
||||
for tool_name in tools:
|
||||
var t: Tool = tools[tool_name]
|
||||
t.button_node.hint_tooltip = t.generate_hint_tooltip()
|
||||
|
||||
|
||||
func update_tool_cursors() -> void:
|
||||
var left_image = load(
|
||||
"res://assets/graphics/tools/cursors/%s.png" % _slots[BUTTON_LEFT].tool_node.name.to_lower()
|
||||
|
|
66
src/Tools/ToolButton.tscn
Normal file
66
src/Tools/ToolButton.tscn
Normal file
|
@ -0,0 +1,66 @@
|
|||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://assets/graphics/tools/tool_background.png" type="Texture" id=1]
|
||||
[ext_resource path="res://assets/graphics/tools/rectselect.png" type="Texture" id=2]
|
||||
|
||||
[node name="Tool" type="Button" groups=["UIButtons"]]
|
||||
margin_right = 24.0
|
||||
margin_bottom = 24.0
|
||||
rect_min_size = Vector2( 24, 24 )
|
||||
hint_tooltip = "Rectangular Selection
|
||||
|
||||
%s for left mouse button
|
||||
%s for right mouse button"
|
||||
mouse_default_cursor_shape = 2
|
||||
button_mask = 3
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="BackgroundLeft" type="NinePatchRect" parent="."]
|
||||
visible = false
|
||||
modulate = Color( 0, 0.52549, 0.811765, 1 )
|
||||
anchor_bottom = 1.0
|
||||
margin_right = 12.0
|
||||
texture = ExtResource( 1 )
|
||||
region_rect = Rect2( 0, 0, 11, 24 )
|
||||
patch_margin_left = 2
|
||||
patch_margin_top = 1
|
||||
patch_margin_right = 10
|
||||
patch_margin_bottom = 1
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="BackgroundRight" type="NinePatchRect" parent="."]
|
||||
visible = false
|
||||
modulate = Color( 0.992157, 0.427451, 0.0784314, 1 )
|
||||
anchor_bottom = 1.0
|
||||
margin_left = 24.0
|
||||
margin_top = 24.0
|
||||
margin_right = 36.0
|
||||
margin_bottom = 24.0
|
||||
rect_rotation = 180.0
|
||||
texture = ExtResource( 1 )
|
||||
region_rect = Rect2( 0, 0, 11, 24 )
|
||||
patch_margin_left = 2
|
||||
patch_margin_top = 1
|
||||
patch_margin_right = 10
|
||||
patch_margin_bottom = 1
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="ToolIcon" type="TextureRect" parent="."]
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
margin_left = -11.0
|
||||
margin_top = -11.0
|
||||
margin_right = 11.0
|
||||
margin_bottom = 11.0
|
||||
texture = ExtResource( 2 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
|
@ -1,49 +1,11 @@
|
|||
extends GridContainer
|
||||
|
||||
var tooltips := []
|
||||
|
||||
# Node, shortcut
|
||||
onready var tools := [
|
||||
[$RectSelect, "rectangle_select"],
|
||||
[$EllipseSelect, "ellipse_select"],
|
||||
[$PolygonSelect, "polygon_select"],
|
||||
[$ColorSelect, "color_select"],
|
||||
[$MagicWand, "magic_wand"],
|
||||
[$Lasso, "lasso"],
|
||||
[$Move, "move"],
|
||||
[$Zoom, "zoom"],
|
||||
[$Pan, "pan"],
|
||||
[$ColorPicker, "colorpicker"],
|
||||
[$Pencil, "pencil", "Shift"],
|
||||
[$Eraser, "eraser", "Shift"],
|
||||
[$Bucket, "fill"],
|
||||
[$Shading, "shading"],
|
||||
[$LineTool, "linetool", "Shift", "Ctrl", "Alt"],
|
||||
[$RectangleTool, "rectangletool", "Shift", "Ctrl", "Alt"],
|
||||
[$EllipseTool, "ellipsetool", "Shift", "Ctrl", "Alt"],
|
||||
]
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
for t in tools:
|
||||
t[0].connect("pressed", self, "_on_Tool_pressed", [t[0]])
|
||||
tooltips.append(t[0].hint_tooltip)
|
||||
|
||||
# Resize tools panel when window gets resized
|
||||
get_tree().get_root().connect("size_changed", self, "_on_Tools_resized")
|
||||
|
||||
|
||||
func update_hintooltips() -> void:
|
||||
for i in tools.size():
|
||||
var toolname: String = tools[i][1]
|
||||
var shortcuts := []
|
||||
shortcuts.append(InputMap.get_action_list("left_" + toolname + "_tool")[0].as_text())
|
||||
shortcuts.append(InputMap.get_action_list("right_" + toolname + "_tool")[0].as_text())
|
||||
for j in range(2, tools[i].size()):
|
||||
shortcuts.append(tools[i][j])
|
||||
tools[i][0].hint_tooltip = tr(tooltips[i]) % shortcuts
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if not Global.has_focus or not event is InputEventKey:
|
||||
return
|
||||
|
@ -51,13 +13,14 @@ func _input(event: InputEvent) -> void:
|
|||
if event.is_action_pressed(action):
|
||||
return
|
||||
|
||||
for t in tools: # Handle tool shortcuts
|
||||
if event.is_action_pressed("right_" + t[1] + "_tool") and !event.control:
|
||||
for tool_name in Tools.tools: # Handle tool shortcuts
|
||||
var t: Tools.Tool = Tools.tools[tool_name]
|
||||
if event.is_action_pressed("right_" + t.shortcut + "_tool") and !event.control:
|
||||
# Shortcut for right button (with Alt)
|
||||
Tools.assign_tool(t[0].name, BUTTON_RIGHT)
|
||||
elif event.is_action_pressed("left_" + t[1] + "_tool") and !event.control:
|
||||
Tools.assign_tool(t.name, BUTTON_RIGHT)
|
||||
elif event.is_action_pressed("left_" + t.shortcut + "_tool") and !event.control:
|
||||
# Shortcut for left button
|
||||
Tools.assign_tool(t[0].name, BUTTON_LEFT)
|
||||
Tools.assign_tool(t.name, BUTTON_LEFT)
|
||||
|
||||
|
||||
func _on_Tool_pressed(tool_pressed: BaseButton) -> void:
|
||||
|
|
1063
src/UI/Tools.tscn
1063
src/UI/Tools.tscn
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue