mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-02-22 13:33:13 +00:00
Created ToolButtons.gd, moved code from Main.gd there
This commit is contained in:
parent
5f9c1976d2
commit
12c6118763
3 changed files with 124 additions and 116 deletions
115
src/Main.gd
115
src/Main.gd
|
@ -3,7 +3,6 @@ extends Control
|
||||||
var opensprite_file_selected := false
|
var opensprite_file_selected := false
|
||||||
var file_menu : PopupMenu
|
var file_menu : PopupMenu
|
||||||
var view_menu : PopupMenu
|
var view_menu : PopupMenu
|
||||||
var tools := []
|
|
||||||
var redone := false
|
var redone := false
|
||||||
var unsaved_canvas_state := 0
|
var unsaved_canvas_state := 0
|
||||||
var is_quitting_on_save := false
|
var is_quitting_on_save := false
|
||||||
|
@ -132,21 +131,6 @@ func _ready() -> void:
|
||||||
image_menu.connect("id_pressed", self, "image_menu_id_pressed")
|
image_menu.connect("id_pressed", self, "image_menu_id_pressed")
|
||||||
help_menu.connect("id_pressed", self, "help_menu_id_pressed")
|
help_menu.connect("id_pressed", self, "help_menu_id_pressed")
|
||||||
|
|
||||||
var root = get_tree().get_root()
|
|
||||||
# Node, left mouse shortcut, right mouse shortcut
|
|
||||||
tools.append([Global.find_node_by_name(root, "Pencil"), "left_pencil_tool", "right_pencil_tool"])
|
|
||||||
tools.append([Global.find_node_by_name(root, "Eraser"), "left_eraser_tool", "right_eraser_tool"])
|
|
||||||
tools.append([Global.find_node_by_name(root, "Bucket"), "left_fill_tool", "right_fill_tool"])
|
|
||||||
tools.append([Global.find_node_by_name(root, "LightenDarken"), "left_lightdark_tool", "right_lightdark_tool"])
|
|
||||||
tools.append([Global.find_node_by_name(root, "RectSelect"), "left_rectangle_select_tool", "right_rectangle_select_tool"])
|
|
||||||
tools.append([Global.find_node_by_name(root, "ColorPicker"), "left_colorpicker_tool", "right_colorpicker_tool"])
|
|
||||||
tools.append([Global.find_node_by_name(root, "Zoom"), "left_zoom_tool", "right_zoom_tool"])
|
|
||||||
|
|
||||||
for t in tools:
|
|
||||||
t[0].connect("pressed", self, "_on_Tool_pressed", [t[0]])
|
|
||||||
|
|
||||||
Global.update_hint_tooltips()
|
|
||||||
|
|
||||||
# Checks to see if it's 3.1.x
|
# Checks to see if it's 3.1.x
|
||||||
if Engine.get_version_info().major == 3 and Engine.get_version_info().minor < 2:
|
if Engine.get_version_info().major == 3 and Engine.get_version_info().minor < 2:
|
||||||
Global.left_color_picker.get_picker().move_child(Global.left_color_picker.get_picker().get_child(0), 1)
|
Global.left_color_picker.get_picker().move_child(Global.left_color_picker.get_picker().get_child(0), 1)
|
||||||
|
@ -229,15 +213,6 @@ func _input(event : InputEvent) -> void:
|
||||||
Global.undo_redo.redo()
|
Global.undo_redo.redo()
|
||||||
redone = false
|
redone = false
|
||||||
|
|
||||||
if Global.has_focus:
|
|
||||||
if event.is_action_pressed("undo") or event.is_action_pressed("redo") or event.is_action_pressed("redo_secondary"):
|
|
||||||
return
|
|
||||||
for t in tools: # Handle tool shortcuts
|
|
||||||
if event.is_action_pressed(t[2]): # Shortcut for right button (with Alt)
|
|
||||||
_on_Tool_pressed(t[0], false, false)
|
|
||||||
elif event.is_action_pressed(t[1]): # Shortcut for left button
|
|
||||||
_on_Tool_pressed(t[0], false, true)
|
|
||||||
|
|
||||||
|
|
||||||
func _notification(what : int) -> void:
|
func _notification(what : int) -> void:
|
||||||
if what == MainLoop.NOTIFICATION_WM_QUIT_REQUEST: # Handle exit
|
if what == MainLoop.NOTIFICATION_WM_QUIT_REQUEST: # Handle exit
|
||||||
|
@ -526,96 +501,6 @@ func _can_draw_true() -> void:
|
||||||
Global.dialog_open(false)
|
Global.dialog_open(false)
|
||||||
|
|
||||||
|
|
||||||
func _on_Tool_pressed(tool_pressed : BaseButton, mouse_press := true, key_for_left := true) -> void:
|
|
||||||
var current_action := tool_pressed.name
|
|
||||||
if (mouse_press and Input.is_action_just_released("left_mouse")) or (!mouse_press and key_for_left):
|
|
||||||
Global.current_left_tool = current_action
|
|
||||||
|
|
||||||
# Start from 1, so the label won't get invisible
|
|
||||||
for i in range(1, Global.left_tool_options_container.get_child_count()):
|
|
||||||
Global.left_tool_options_container.get_child(i).visible = false
|
|
||||||
|
|
||||||
Global.left_tool_options_container.get_node("EmptySpacer").visible = true
|
|
||||||
|
|
||||||
# Tool options visible depending on the selected tool
|
|
||||||
if current_action == "Pencil":
|
|
||||||
Global.left_brush_type_container.visible = true
|
|
||||||
Global.left_brush_size_slider.visible = true
|
|
||||||
Global.left_pixel_perfect_container.visible = true
|
|
||||||
Global.left_mirror_container.visible = true
|
|
||||||
if Global.current_left_brush_type == Global.Brush_Types.FILE or Global.current_left_brush_type == Global.Brush_Types.CUSTOM or Global.current_left_brush_type == Global.Brush_Types.RANDOM_FILE:
|
|
||||||
Global.left_color_interpolation_container.visible = true
|
|
||||||
elif current_action == "Eraser":
|
|
||||||
Global.left_brush_type_container.visible = true
|
|
||||||
Global.left_brush_size_slider.visible = true
|
|
||||||
Global.left_pixel_perfect_container.visible = true
|
|
||||||
Global.left_mirror_container.visible = true
|
|
||||||
elif current_action == "Bucket":
|
|
||||||
Global.left_fill_area_container.visible = true
|
|
||||||
Global.left_mirror_container.visible = true
|
|
||||||
elif current_action == "LightenDarken":
|
|
||||||
Global.left_brush_type_container.visible = true
|
|
||||||
Global.left_brush_size_slider.visible = true
|
|
||||||
Global.left_pixel_perfect_container.visible = true
|
|
||||||
Global.left_ld_container.visible = true
|
|
||||||
Global.left_mirror_container.visible = true
|
|
||||||
elif current_action == "ColorPicker":
|
|
||||||
Global.left_colorpicker_container.visible = true
|
|
||||||
elif current_action == "Zoom":
|
|
||||||
Global.left_zoom_container.visible = true
|
|
||||||
|
|
||||||
elif (mouse_press and Input.is_action_just_released("right_mouse")) or (!mouse_press and !key_for_left):
|
|
||||||
Global.current_right_tool = current_action
|
|
||||||
# Start from 1, so the label won't get invisible
|
|
||||||
for i in range(1, Global.right_tool_options_container.get_child_count()):
|
|
||||||
Global.right_tool_options_container.get_child(i).visible = false
|
|
||||||
|
|
||||||
Global.right_tool_options_container.get_node("EmptySpacer").visible = true
|
|
||||||
|
|
||||||
# Tool options visible depending on the selected tool
|
|
||||||
if current_action == "Pencil":
|
|
||||||
Global.right_brush_type_container.visible = true
|
|
||||||
Global.right_brush_size_slider.visible = true
|
|
||||||
Global.right_pixel_perfect_container.visible = true
|
|
||||||
Global.right_mirror_container.visible = true
|
|
||||||
if Global.current_right_brush_type == Global.Brush_Types.FILE or Global.current_right_brush_type == Global.Brush_Types.CUSTOM or Global.current_right_brush_type == Global.Brush_Types.RANDOM_FILE:
|
|
||||||
Global.right_color_interpolation_container.visible = true
|
|
||||||
elif current_action == "Eraser":
|
|
||||||
Global.right_brush_type_container.visible = true
|
|
||||||
Global.right_brush_size_slider.visible = true
|
|
||||||
Global.right_pixel_perfect_container.visible = true
|
|
||||||
Global.right_mirror_container.visible = true
|
|
||||||
elif current_action == "Bucket":
|
|
||||||
Global.right_fill_area_container.visible = true
|
|
||||||
Global.right_mirror_container.visible = true
|
|
||||||
elif current_action == "LightenDarken":
|
|
||||||
Global.right_brush_type_container.visible = true
|
|
||||||
Global.right_brush_size_slider.visible = true
|
|
||||||
Global.right_pixel_perfect_container.visible = true
|
|
||||||
Global.right_ld_container.visible = true
|
|
||||||
Global.right_mirror_container.visible = true
|
|
||||||
elif current_action == "ColorPicker":
|
|
||||||
Global.right_colorpicker_container.visible = true
|
|
||||||
elif current_action == "Zoom":
|
|
||||||
Global.right_zoom_container.visible = true
|
|
||||||
|
|
||||||
for t in tools:
|
|
||||||
var tool_name : String = t[0].name
|
|
||||||
var texture_button : TextureRect = t[0].get_child(0)
|
|
||||||
|
|
||||||
if tool_name == Global.current_left_tool and tool_name == Global.current_right_tool:
|
|
||||||
Global.change_button_texturerect(texture_button, "%s_l_r.png" % tool_name.to_lower())
|
|
||||||
elif tool_name == Global.current_left_tool:
|
|
||||||
Global.change_button_texturerect(texture_button, "%s_l.png" % tool_name.to_lower())
|
|
||||||
elif tool_name == Global.current_right_tool:
|
|
||||||
Global.change_button_texturerect(texture_button, "%s_r.png" % tool_name.to_lower())
|
|
||||||
else:
|
|
||||||
Global.change_button_texturerect(texture_button, "%s.png" % tool_name.to_lower())
|
|
||||||
|
|
||||||
Global.left_cursor_tool_texture.create_from_image(load("res://assets/graphics/cursor_icons/%s_cursor.png" % Global.current_left_tool.to_lower()), 0)
|
|
||||||
Global.right_cursor_tool_texture.create_from_image(load("res://assets/graphics/cursor_icons/%s_cursor.png" % Global.current_right_tool.to_lower()), 0)
|
|
||||||
|
|
||||||
|
|
||||||
func show_quit_dialog() -> void:
|
func show_quit_dialog() -> void:
|
||||||
if !$QuitDialog.visible:
|
if !$QuitDialog.visible:
|
||||||
if !Global.project_has_changed:
|
if !Global.project_has_changed:
|
||||||
|
|
121
src/UI/ToolButtons.gd
Normal file
121
src/UI/ToolButtons.gd
Normal file
|
@ -0,0 +1,121 @@
|
||||||
|
extends VBoxContainer
|
||||||
|
|
||||||
|
|
||||||
|
var tools := []
|
||||||
|
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
# Node, left mouse shortcut, right mouse shortcut
|
||||||
|
tools.append([Global.find_node_by_name(self, "Pencil"), "left_pencil_tool", "right_pencil_tool"])
|
||||||
|
tools.append([Global.find_node_by_name(self, "Eraser"), "left_eraser_tool", "right_eraser_tool"])
|
||||||
|
tools.append([Global.find_node_by_name(self, "Bucket"), "left_fill_tool", "right_fill_tool"])
|
||||||
|
tools.append([Global.find_node_by_name(self, "LightenDarken"), "left_lightdark_tool", "right_lightdark_tool"])
|
||||||
|
tools.append([Global.find_node_by_name(self, "RectSelect"), "left_rectangle_select_tool", "right_rectangle_select_tool"])
|
||||||
|
tools.append([Global.find_node_by_name(self, "ColorPicker"), "left_colorpicker_tool", "right_colorpicker_tool"])
|
||||||
|
tools.append([Global.find_node_by_name(self, "Zoom"), "left_zoom_tool", "right_zoom_tool"])
|
||||||
|
|
||||||
|
for t in tools:
|
||||||
|
t[0].connect("pressed", self, "_on_Tool_pressed", [t[0]])
|
||||||
|
|
||||||
|
Global.update_hint_tooltips()
|
||||||
|
|
||||||
|
|
||||||
|
func _input(event : InputEvent) -> void:
|
||||||
|
if Global.has_focus:
|
||||||
|
if event.is_action_pressed("undo") or event.is_action_pressed("redo") or event.is_action_pressed("redo_secondary"):
|
||||||
|
return
|
||||||
|
for t in tools: # Handle tool shortcuts
|
||||||
|
if event.is_action_pressed(t[2]): # Shortcut for right button (with Alt)
|
||||||
|
_on_Tool_pressed(t[0], false, false)
|
||||||
|
elif event.is_action_pressed(t[1]): # Shortcut for left button
|
||||||
|
_on_Tool_pressed(t[0], false, true)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_Tool_pressed(tool_pressed : BaseButton, mouse_press := true, key_for_left := true) -> void:
|
||||||
|
var current_action := tool_pressed.name
|
||||||
|
if (mouse_press and Input.is_action_just_released("left_mouse")) or (!mouse_press and key_for_left):
|
||||||
|
Global.current_left_tool = current_action
|
||||||
|
|
||||||
|
# Start from 1, so the label won't get invisible
|
||||||
|
for i in range(1, Global.left_tool_options_container.get_child_count()):
|
||||||
|
Global.left_tool_options_container.get_child(i).visible = false
|
||||||
|
|
||||||
|
Global.left_tool_options_container.get_node("EmptySpacer").visible = true
|
||||||
|
|
||||||
|
# Tool options visible depending on the selected tool
|
||||||
|
if current_action == "Pencil":
|
||||||
|
Global.left_brush_type_container.visible = true
|
||||||
|
Global.left_brush_size_slider.visible = true
|
||||||
|
Global.left_pixel_perfect_container.visible = true
|
||||||
|
Global.left_mirror_container.visible = true
|
||||||
|
if Global.current_left_brush_type == Global.Brush_Types.FILE or Global.current_left_brush_type == Global.Brush_Types.CUSTOM or Global.current_left_brush_type == Global.Brush_Types.RANDOM_FILE:
|
||||||
|
Global.left_color_interpolation_container.visible = true
|
||||||
|
elif current_action == "Eraser":
|
||||||
|
Global.left_brush_type_container.visible = true
|
||||||
|
Global.left_brush_size_slider.visible = true
|
||||||
|
Global.left_pixel_perfect_container.visible = true
|
||||||
|
Global.left_mirror_container.visible = true
|
||||||
|
elif current_action == "Bucket":
|
||||||
|
Global.left_fill_area_container.visible = true
|
||||||
|
Global.left_mirror_container.visible = true
|
||||||
|
elif current_action == "LightenDarken":
|
||||||
|
Global.left_brush_type_container.visible = true
|
||||||
|
Global.left_brush_size_slider.visible = true
|
||||||
|
Global.left_pixel_perfect_container.visible = true
|
||||||
|
Global.left_ld_container.visible = true
|
||||||
|
Global.left_mirror_container.visible = true
|
||||||
|
elif current_action == "ColorPicker":
|
||||||
|
Global.left_colorpicker_container.visible = true
|
||||||
|
elif current_action == "Zoom":
|
||||||
|
Global.left_zoom_container.visible = true
|
||||||
|
|
||||||
|
elif (mouse_press and Input.is_action_just_released("right_mouse")) or (!mouse_press and !key_for_left):
|
||||||
|
Global.current_right_tool = current_action
|
||||||
|
# Start from 1, so the label won't get invisible
|
||||||
|
for i in range(1, Global.right_tool_options_container.get_child_count()):
|
||||||
|
Global.right_tool_options_container.get_child(i).visible = false
|
||||||
|
|
||||||
|
Global.right_tool_options_container.get_node("EmptySpacer").visible = true
|
||||||
|
|
||||||
|
# Tool options visible depending on the selected tool
|
||||||
|
if current_action == "Pencil":
|
||||||
|
Global.right_brush_type_container.visible = true
|
||||||
|
Global.right_brush_size_slider.visible = true
|
||||||
|
Global.right_pixel_perfect_container.visible = true
|
||||||
|
Global.right_mirror_container.visible = true
|
||||||
|
if Global.current_right_brush_type == Global.Brush_Types.FILE or Global.current_right_brush_type == Global.Brush_Types.CUSTOM or Global.current_right_brush_type == Global.Brush_Types.RANDOM_FILE:
|
||||||
|
Global.right_color_interpolation_container.visible = true
|
||||||
|
elif current_action == "Eraser":
|
||||||
|
Global.right_brush_type_container.visible = true
|
||||||
|
Global.right_brush_size_slider.visible = true
|
||||||
|
Global.right_pixel_perfect_container.visible = true
|
||||||
|
Global.right_mirror_container.visible = true
|
||||||
|
elif current_action == "Bucket":
|
||||||
|
Global.right_fill_area_container.visible = true
|
||||||
|
Global.right_mirror_container.visible = true
|
||||||
|
elif current_action == "LightenDarken":
|
||||||
|
Global.right_brush_type_container.visible = true
|
||||||
|
Global.right_brush_size_slider.visible = true
|
||||||
|
Global.right_pixel_perfect_container.visible = true
|
||||||
|
Global.right_ld_container.visible = true
|
||||||
|
Global.right_mirror_container.visible = true
|
||||||
|
elif current_action == "ColorPicker":
|
||||||
|
Global.right_colorpicker_container.visible = true
|
||||||
|
elif current_action == "Zoom":
|
||||||
|
Global.right_zoom_container.visible = true
|
||||||
|
|
||||||
|
for t in tools:
|
||||||
|
var tool_name : String = t[0].name
|
||||||
|
var texture_button : TextureRect = t[0].get_child(0)
|
||||||
|
|
||||||
|
if tool_name == Global.current_left_tool and tool_name == Global.current_right_tool:
|
||||||
|
Global.change_button_texturerect(texture_button, "%s_l_r.png" % tool_name.to_lower())
|
||||||
|
elif tool_name == Global.current_left_tool:
|
||||||
|
Global.change_button_texturerect(texture_button, "%s_l.png" % tool_name.to_lower())
|
||||||
|
elif tool_name == Global.current_right_tool:
|
||||||
|
Global.change_button_texturerect(texture_button, "%s_r.png" % tool_name.to_lower())
|
||||||
|
else:
|
||||||
|
Global.change_button_texturerect(texture_button, "%s.png" % tool_name.to_lower())
|
||||||
|
|
||||||
|
Global.left_cursor_tool_texture.create_from_image(load("res://assets/graphics/cursor_icons/%s_cursor.png" % Global.current_left_tool.to_lower()), 0)
|
||||||
|
Global.right_cursor_tool_texture.create_from_image(load("res://assets/graphics/cursor_icons/%s_cursor.png" % Global.current_right_tool.to_lower()), 0)
|
|
@ -1,5 +1,6 @@
|
||||||
[gd_scene load_steps=23 format=2]
|
[gd_scene load_steps=24 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://src/UI/ToolButtons.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://src/UI/SecondViewport.gd" type="Script" id=2]
|
[ext_resource path="res://src/UI/SecondViewport.gd" type="Script" id=2]
|
||||||
[ext_resource path="res://src/UI/Rulers/VerticalRuler.gd" type="Script" id=4]
|
[ext_resource path="res://src/UI/Rulers/VerticalRuler.gd" type="Script" id=4]
|
||||||
[ext_resource path="res://src/UI/Rulers/HorizontalRuler.gd" type="Script" id=6]
|
[ext_resource path="res://src/UI/Rulers/HorizontalRuler.gd" type="Script" id=6]
|
||||||
|
@ -63,6 +64,7 @@ margin_left = 7.0
|
||||||
margin_top = 7.0
|
margin_top = 7.0
|
||||||
margin_right = 39.0
|
margin_right = 39.0
|
||||||
margin_bottom = 255.0
|
margin_bottom = 255.0
|
||||||
|
script = ExtResource( 1 )
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
"_edit_use_anchors_": false
|
"_edit_use_anchors_": false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue