mirror of
https://github.com/tonytins/CozyPixelStudio.git
synced 2025-06-25 22:34:43 -04:00
Refactoring tools (#281)
* Refactoring tools * Remove unused code * Fixed some inferring errors and added translations * Attempt to fix some Script Errors found in the CI workflow * Fix bucket crash. * Fix static type convert. Co-authored-by: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com>
This commit is contained in:
parent
e1724148fc
commit
4a668f71f5
42 changed files with 2489 additions and 2389 deletions
|
@ -1,70 +1,29 @@
|
|||
extends BaseButton
|
||||
|
||||
|
||||
export var brush_type := 0 # Global.Brush_Types.PIXEL
|
||||
export var custom_brush_index := -3
|
||||
var random_brushes := []
|
||||
var brush := Brushes.Brush.new()
|
||||
|
||||
|
||||
func _on_BrushButton_pressed() -> void:
|
||||
# Delete the brush on middle mouse press
|
||||
if Input.is_action_just_released("middle_mouse"):
|
||||
_on_DeleteButton_pressed()
|
||||
return
|
||||
|
||||
# Change brush
|
||||
Global.current_brush_types[Global.brush_type_window_position] = brush_type
|
||||
Global.custom_brush_indexes[Global.brush_type_window_position] = custom_brush_index
|
||||
if brush_type == Global.Brush_Types.FILE or brush_type == Global.Brush_Types.RANDOM_FILE or brush_type == Global.Brush_Types.CUSTOM:
|
||||
if Global.current_tools[Global.brush_type_window_position] == Global.Tools.PENCIL:
|
||||
Global.color_interpolation_containers[Global.brush_type_window_position].visible = true
|
||||
else:
|
||||
Global.color_interpolation_containers[Global.brush_type_window_position].visible = false
|
||||
|
||||
Global.update_custom_brush(Global.brush_type_window_position)
|
||||
Global.brushes_popup.hide()
|
||||
Global.brushes_popup.select_brush(brush)
|
||||
|
||||
|
||||
func _on_DeleteButton_pressed() -> void:
|
||||
if brush_type != Global.Brush_Types.CUSTOM:
|
||||
if brush.type != Brushes.CUSTOM:
|
||||
return
|
||||
|
||||
if Global.custom_brush_indexes[0] == custom_brush_index:
|
||||
Global.custom_brush_indexes[0] = -3
|
||||
Global.current_brush_types[0] = Global.Brush_Types.PIXEL
|
||||
Global.update_custom_brush(0)
|
||||
if Global.custom_brush_indexes[1] == custom_brush_index:
|
||||
Global.custom_brush_indexes[1] = -3
|
||||
Global.current_brush_types[1] = Global.Brush_Types.PIXEL
|
||||
Global.update_custom_brush(1)
|
||||
|
||||
Global.current_project.undos += 1
|
||||
Global.current_project.undo_redo.create_action("Delete Custom Brush")
|
||||
for i in range(Global.project_brush_container.get_child_count()):
|
||||
var bb = Global.project_brush_container.get_child(i)
|
||||
if Global.custom_brush_indexes[0] == bb.custom_brush_index:
|
||||
Global.custom_brush_indexes[0] -= 1
|
||||
if Global.custom_brush_indexes[1] == bb.custom_brush_index:
|
||||
Global.custom_brush_indexes[1] -= 1
|
||||
|
||||
Global.current_project.undo_redo.add_do_property(bb, "custom_brush_index", bb.custom_brush_index - 1)
|
||||
Global.current_project.undo_redo.add_undo_property(bb, "custom_brush_index", bb.custom_brush_index)
|
||||
|
||||
var custom_brushes: Array = Global.current_project.brushes.duplicate()
|
||||
custom_brushes.remove(custom_brush_index)
|
||||
|
||||
Global.current_project.undo_redo.add_do_property(Global.current_project, "brushes", custom_brushes)
|
||||
Global.current_project.undo_redo.add_undo_property(Global.current_project, "brushes", Global.current_project.brushes)
|
||||
Global.current_project.undo_redo.add_do_method(Global, "redo_custom_brush", self)
|
||||
Global.current_project.undo_redo.add_undo_method(Global, "undo_custom_brush", self)
|
||||
Global.current_project.undo_redo.commit_action()
|
||||
Global.brushes_popup.remove_brush(self)
|
||||
|
||||
|
||||
func _on_BrushButton_mouse_entered() -> void:
|
||||
if brush_type == Global.Brush_Types.CUSTOM:
|
||||
if brush.type == Brushes.CUSTOM:
|
||||
$DeleteButton.visible = true
|
||||
|
||||
|
||||
func _on_BrushButton_mouse_exited() -> void:
|
||||
if brush_type == Global.Brush_Types.CUSTOM:
|
||||
if brush.type == Brushes.CUSTOM:
|
||||
$DeleteButton.visible = false
|
||||
|
|
132
src/UI/BrushesPopup.gd
Normal file
132
src/UI/BrushesPopup.gd
Normal file
|
@ -0,0 +1,132 @@
|
|||
extends Popup
|
||||
class_name Brushes
|
||||
|
||||
|
||||
class Brush:
|
||||
var type : int
|
||||
var image : Image
|
||||
var random := []
|
||||
var index : int
|
||||
|
||||
|
||||
signal brush_selected(brush)
|
||||
signal brush_removed(brush)
|
||||
enum {PIXEL, CIRCLE, FILLED_CIRCLE, FILE, RANDOM_FILE, CUSTOM}
|
||||
|
||||
var pixel_image = preload("res://assets/graphics/pixel_image.png")
|
||||
var circle_image = preload("res://assets/graphics/circle_9x9.png")
|
||||
var circle_filled_image = preload("res://assets/graphics/circle_filled_9x9.png")
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
var container = Global.brushes_popup.get_node("TabContainer/File/FileBrushContainer")
|
||||
var button = create_button(pixel_image)
|
||||
button.brush.type = PIXEL
|
||||
button.hint_tooltip = "Pixel brush"
|
||||
container.add_child(button)
|
||||
button.brush.index = button.get_index()
|
||||
|
||||
button = create_button(circle_image)
|
||||
button.brush.type = CIRCLE
|
||||
button.hint_tooltip = "Circle brush"
|
||||
container.add_child(button)
|
||||
button.brush.index = button.get_index()
|
||||
|
||||
button = create_button(circle_filled_image)
|
||||
button.brush.type = FILLED_CIRCLE
|
||||
button.hint_tooltip = "Filled circle brush"
|
||||
container.add_child(button)
|
||||
button.brush.index = button.get_index()
|
||||
|
||||
|
||||
func select_brush(brush : Brush) -> void:
|
||||
emit_signal("brush_selected", brush)
|
||||
hide()
|
||||
|
||||
|
||||
static func get_default_brush() -> Brush:
|
||||
var brush = Brush.new()
|
||||
brush.type = PIXEL
|
||||
brush.index = 0
|
||||
return brush
|
||||
|
||||
|
||||
static func create_button(image : Image) -> Node:
|
||||
var button : BaseButton = load("res://src/UI/BrushButton.tscn").instance()
|
||||
var tex := ImageTexture.new()
|
||||
tex.create_from_image(image, 0)
|
||||
button.get_child(0).texture = tex
|
||||
button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
||||
return button
|
||||
|
||||
|
||||
static func add_file_brush(images : Array, hint := "") -> void:
|
||||
var button = create_button(images[0])
|
||||
button.brush.type = FILE if images.size() == 1 else RANDOM_FILE
|
||||
button.brush.image = images[0]
|
||||
button.brush.random = images
|
||||
button.hint_tooltip = hint
|
||||
var container = Global.brushes_popup.get_node("TabContainer/File/FileBrushContainer")
|
||||
container.add_child(button)
|
||||
button.brush.index = button.get_index()
|
||||
|
||||
|
||||
static func add_project_brush(image : Image) -> void:
|
||||
var button = create_button(image)
|
||||
button.brush.type = CUSTOM
|
||||
button.brush.image = image
|
||||
var container = Global.brushes_popup.get_node("TabContainer/Project/ProjectBrushContainer")
|
||||
container.add_child(button)
|
||||
button.brush.index = button.get_index()
|
||||
|
||||
|
||||
static func clear_project_brush() -> void:
|
||||
var container = Global.brushes_popup.get_node("TabContainer/Project/ProjectBrushContainer")
|
||||
for child in container.get_children():
|
||||
child.queue_free()
|
||||
Global.brushes_popup.emit_signal("brush_removed", child.brush)
|
||||
|
||||
|
||||
func get_brush(type : int, index : int) -> Brush:
|
||||
var container
|
||||
if type == CUSTOM:
|
||||
container = Global.brushes_popup.get_node("TabContainer/Project/ProjectBrushContainer")
|
||||
else:
|
||||
container = Global.brushes_popup.get_node("TabContainer/File/FileBrushContainer")
|
||||
var brush = get_default_brush()
|
||||
if index < container.get_child_count():
|
||||
brush = container.get_child(index).brush
|
||||
return brush
|
||||
|
||||
|
||||
func remove_brush(brush_button : Node) -> void:
|
||||
emit_signal("brush_removed", brush_button.brush)
|
||||
|
||||
var project = Global.current_project
|
||||
var undo_brushes = project.brushes.duplicate()
|
||||
project.brushes.erase(brush_button.brush.image)
|
||||
|
||||
project.undos += 1
|
||||
project.undo_redo.create_action("Delete Custom Brush")
|
||||
project.undo_redo.add_do_property(project, "brushes", project.brushes)
|
||||
project.undo_redo.add_undo_property(project, "brushes", undo_brushes)
|
||||
project.undo_redo.add_do_method(self, "redo_custom_brush", brush_button)
|
||||
project.undo_redo.add_undo_method(self, "undo_custom_brush", brush_button)
|
||||
project.undo_redo.add_undo_reference(brush_button)
|
||||
project.undo_redo.commit_action()
|
||||
|
||||
|
||||
func undo_custom_brush(brush_button : BaseButton = null) -> void:
|
||||
Global.general_undo()
|
||||
var action_name : String = Global.current_project.undo_redo.get_current_action_name()
|
||||
if action_name == "Delete Custom Brush":
|
||||
$TabContainer/Project/ProjectBrushContainer.add_child(brush_button)
|
||||
$TabContainer/Project/ProjectBrushContainer.move_child(brush_button, brush_button.brush.index)
|
||||
brush_button.get_node("DeleteButton").visible = false
|
||||
|
||||
|
||||
func redo_custom_brush(brush_button : BaseButton = null) -> void:
|
||||
Global.general_redo()
|
||||
var action_name : String = Global.current_project.undo_redo.get_current_action_name()
|
||||
if action_name == "Delete Custom Brush":
|
||||
$TabContainer/Project/ProjectBrushContainer.remove_child(brush_button)
|
|
@ -1,41 +1,12 @@
|
|||
[gd_scene load_steps=6 format=2]
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://src/UI/BrushButton.tscn" type="PackedScene" id=2]
|
||||
|
||||
[sub_resource type="Image" id=5]
|
||||
data = {
|
||||
"data": PoolByteArray( 0, 0, 0, 0, 0, 0, 0, 255, 0, 255, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 255, 0, 255, 0, 0, 0, 0, 0, 0 ),
|
||||
"format": "LumAlpha8",
|
||||
"height": 9,
|
||||
"mipmaps": false,
|
||||
"width": 9
|
||||
}
|
||||
|
||||
[sub_resource type="ImageTexture" id=2]
|
||||
flags = 3
|
||||
flags = 3
|
||||
image = SubResource( 5 )
|
||||
size = Vector2( 9, 9 )
|
||||
|
||||
[sub_resource type="Image" id=6]
|
||||
data = {
|
||||
"data": PoolByteArray( 0, 0, 0, 0, 0, 0, 0, 255, 0, 255, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 0, 0, 0, 0, 0, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 0, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 0, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 0, 0, 0, 0, 0, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 255, 0, 255, 0, 0, 0, 0, 0, 0 ),
|
||||
"format": "LumAlpha8",
|
||||
"height": 9,
|
||||
"mipmaps": false,
|
||||
"width": 9
|
||||
}
|
||||
|
||||
[sub_resource type="ImageTexture" id=4]
|
||||
flags = 3
|
||||
flags = 3
|
||||
image = SubResource( 6 )
|
||||
size = Vector2( 9, 9 )
|
||||
[ext_resource path="res://src/UI/BrushesPopup.gd" type="Script" id=1]
|
||||
|
||||
[node name="BrushesPopup" type="Popup"]
|
||||
margin_right = 226.0
|
||||
margin_bottom = 144.0
|
||||
rect_min_size = Vector2( 0, 144 )
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="TabContainer" type="TabContainer" parent="."]
|
||||
anchor_right = 1.0
|
||||
|
@ -55,36 +26,8 @@ size_flags_horizontal = 3
|
|||
scroll_horizontal_enabled = false
|
||||
|
||||
[node name="FileBrushContainer" type="GridContainer" parent="TabContainer/File"]
|
||||
margin_right = 104.0
|
||||
margin_bottom = 32.0
|
||||
columns = 6
|
||||
|
||||
[node name="PixelBrushButton" parent="TabContainer/File/FileBrushContainer" instance=ExtResource( 2 )]
|
||||
hint_tooltip = "Pixel brush"
|
||||
mouse_default_cursor_shape = 2
|
||||
|
||||
[node name="CircleBrushButton" parent="TabContainer/File/FileBrushContainer" instance=ExtResource( 2 )]
|
||||
margin_left = 36.0
|
||||
margin_right = 68.0
|
||||
hint_tooltip = "Filled circle brush"
|
||||
mouse_default_cursor_shape = 2
|
||||
brush_type = 1
|
||||
custom_brush_index = -2
|
||||
|
||||
[node name="BrushTexture" parent="TabContainer/File/FileBrushContainer/CircleBrushButton" index="0"]
|
||||
texture = SubResource( 2 )
|
||||
|
||||
[node name="FilledCircleBrushButton" parent="TabContainer/File/FileBrushContainer" instance=ExtResource( 2 )]
|
||||
margin_left = 72.0
|
||||
margin_right = 104.0
|
||||
hint_tooltip = "Circle brush"
|
||||
mouse_default_cursor_shape = 2
|
||||
brush_type = 2
|
||||
custom_brush_index = -1
|
||||
|
||||
[node name="BrushTexture" parent="TabContainer/File/FileBrushContainer/FilledCircleBrushButton" index="0"]
|
||||
texture = SubResource( 4 )
|
||||
|
||||
[node name="Project" type="ScrollContainer" parent="TabContainer"]
|
||||
visible = false
|
||||
anchor_right = 1.0
|
||||
|
@ -99,7 +42,3 @@ scroll_horizontal_enabled = false
|
|||
|
||||
[node name="ProjectBrushContainer" type="GridContainer" parent="TabContainer/Project"]
|
||||
columns = 5
|
||||
|
||||
[editable path="TabContainer/File/FileBrushContainer/CircleBrushButton"]
|
||||
|
||||
[editable path="TabContainer/File/FileBrushContainer/FilledCircleBrushButton"]
|
||||
|
|
|
@ -1,25 +1,23 @@
|
|||
extends VBoxContainer
|
||||
|
||||
|
||||
var previous_colors := [Color.black, Color.white]
|
||||
onready var left_picker := $ColorButtonsVertical/ColorPickersCenter/ColorPickersHorizontal/LeftColorPickerButton
|
||||
onready var right_picker := $ColorButtonsVertical/ColorPickersCenter/ColorPickersHorizontal/RightColorPickerButton
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
Tools.connect("color_changed", self, "update_color")
|
||||
left_picker.get_picker().presets_visible = false
|
||||
right_picker.get_picker().presets_visible = false
|
||||
|
||||
|
||||
func _on_ColorSwitch_pressed() -> void:
|
||||
var temp : Color = Global.color_pickers[0].color
|
||||
Global.color_pickers[0].color = Global.color_pickers[1].color
|
||||
Global.color_pickers[1].color = temp
|
||||
Global.update_custom_brush(0)
|
||||
Global.update_custom_brush(1)
|
||||
Tools.swap_color()
|
||||
|
||||
|
||||
func _on_ColorPickerButton_color_changed(color : Color, right : bool):
|
||||
var mouse_button := int(right)
|
||||
# If the color changed while it's on full transparency, make it opaque (GH issue #54)
|
||||
if color.a == 0:
|
||||
if previous_colors[mouse_button].r != color.r or previous_colors[mouse_button].g != color.g or previous_colors[mouse_button].b != color.b:
|
||||
Global.color_pickers[mouse_button].color.a = 1
|
||||
Global.update_custom_brush(mouse_button)
|
||||
previous_colors[mouse_button] = color
|
||||
var button := BUTTON_RIGHT if right else BUTTON_LEFT
|
||||
Tools.assign_color(color, button)
|
||||
|
||||
|
||||
func _on_ColorPickerButton_pressed() -> void:
|
||||
|
@ -31,108 +29,11 @@ func _on_ColorPickerButton_popup_closed() -> void:
|
|||
|
||||
|
||||
func _on_ColorDefaults_pressed() -> void:
|
||||
Global.color_pickers[0].color = Color.black
|
||||
Global.color_pickers[1].color = Color.white
|
||||
Global.update_custom_brush(0)
|
||||
Global.update_custom_brush(1)
|
||||
Tools.default_color()
|
||||
|
||||
|
||||
func _on_FitToFrameButton_pressed() -> void:
|
||||
Global.camera.fit_to_frame(Global.current_project.size)
|
||||
|
||||
|
||||
func _on_100ZoomButton_pressed() -> void:
|
||||
Global.camera.zoom = Vector2.ONE
|
||||
Global.camera.offset = Global.current_project.size / 2
|
||||
Global.zoom_level_label.text = str(round(100 / Global.camera.zoom.x)) + " %"
|
||||
Global.horizontal_ruler.update()
|
||||
Global.vertical_ruler.update()
|
||||
|
||||
|
||||
func _on_BrushTypeButton_pressed(right : bool) -> void:
|
||||
var mouse_button := int(right)
|
||||
Global.brushes_popup.popup(Rect2(Global.brush_type_buttons[mouse_button].rect_global_position, Vector2(226, 72)))
|
||||
Global.brush_type_window_position = mouse_button
|
||||
|
||||
|
||||
func _on_BrushSizeEdit_value_changed(value : float, right : bool) -> void:
|
||||
var mouse_button := int(right)
|
||||
var new_size = int(value)
|
||||
Global.brush_size_edits[mouse_button].value = value
|
||||
Global.brush_size_sliders[mouse_button].value = value
|
||||
Global.brush_sizes[mouse_button] = new_size
|
||||
Global.update_custom_brush(mouse_button)
|
||||
|
||||
|
||||
func _on_PixelPerfectMode_toggled(button_pressed : bool, right : bool) -> void:
|
||||
var mouse_button := int(right)
|
||||
Global.pixel_perfect[mouse_button] = button_pressed
|
||||
|
||||
|
||||
func _on_InterpolateFactor_value_changed(value : float, right : bool) -> void:
|
||||
var mouse_button := int(right)
|
||||
Global.interpolate_spinboxes[mouse_button].value = value
|
||||
Global.interpolate_sliders[mouse_button].value = value
|
||||
Global.update_custom_brush(mouse_button)
|
||||
|
||||
|
||||
func _on_FillAreaOptions_item_selected(ID : int, right : bool) -> void:
|
||||
var mouse_button := int(right)
|
||||
Global.fill_areas[mouse_button] = ID
|
||||
|
||||
|
||||
func _on_FillWithOptions_item_selected(ID : int, right : bool) -> void:
|
||||
var mouse_button := int(right)
|
||||
Global.fill_with[mouse_button] = ID
|
||||
if ID == 1:
|
||||
Global.fill_pattern_containers[mouse_button].visible = true
|
||||
func update_color(color : Color, button : int) -> void:
|
||||
if button == BUTTON_LEFT:
|
||||
left_picker.color = color
|
||||
else:
|
||||
Global.fill_pattern_containers[mouse_button].visible = false
|
||||
|
||||
|
||||
func _on_PatternTypeButton_pressed(right : bool) -> void:
|
||||
var mouse_button := int(right)
|
||||
Global.pattern_window_position = mouse_button
|
||||
Global.patterns_popup.popup(Rect2(Global.brush_type_buttons[mouse_button].rect_global_position, Vector2(226, 72)))
|
||||
|
||||
|
||||
func _on_PatternOffsetX_value_changed(value : float, right : bool) -> void:
|
||||
var mouse_button := int(right)
|
||||
Global.fill_pattern_offsets[mouse_button].x = value
|
||||
|
||||
|
||||
func _on_PatternOffsetY_value_changed(value : float, right : bool) -> void:
|
||||
var mouse_button := int(right)
|
||||
Global.fill_pattern_offsets[mouse_button].y = value
|
||||
|
||||
|
||||
func _on_LightenDarken_item_selected(ID : int, right : bool) -> void:
|
||||
var mouse_button := int(right)
|
||||
Global.ld_modes[mouse_button] = ID
|
||||
|
||||
|
||||
func _on_LDAmount_value_changed(value : float, right : bool) -> void:
|
||||
var mouse_button := int(right)
|
||||
Global.ld_amounts[mouse_button] = value / 100
|
||||
Global.ld_amount_sliders[mouse_button].value = value
|
||||
Global.ld_amount_spinboxes[mouse_button].value = value
|
||||
|
||||
|
||||
func _on_ForColorOptions_item_selected(ID : int, right : bool) -> void:
|
||||
var mouse_button := int(right)
|
||||
Global.color_picker_for[mouse_button] = ID
|
||||
|
||||
|
||||
func _on_ZoomModeOptions_item_selected(ID : int, right : bool) -> void:
|
||||
var mouse_button := int(right)
|
||||
Global.zoom_modes[mouse_button] = ID
|
||||
|
||||
|
||||
func _on_HorizontalMirroring_toggled(button_pressed : bool, right : bool) -> void:
|
||||
var mouse_button := int(right)
|
||||
Global.horizontal_mirror[mouse_button] = button_pressed
|
||||
|
||||
|
||||
func _on_VerticalMirroring_toggled(button_pressed : bool, right : bool) -> void:
|
||||
var mouse_button := int(right)
|
||||
Global.vertical_mirror[mouse_button] = button_pressed
|
||||
right_picker.color = color
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,22 +1,8 @@
|
|||
extends TextureButton
|
||||
|
||||
|
||||
var image : Image
|
||||
var image_size : Vector2
|
||||
var texture : ImageTexture
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
if image:
|
||||
image_size = image.get_size()
|
||||
texture = ImageTexture.new()
|
||||
texture.create_from_image(image, 0)
|
||||
var pattern := Patterns.Pattern.new()
|
||||
|
||||
|
||||
func _on_PatternButton_pressed() -> void:
|
||||
Global.pattern_images[Global.pattern_window_position] = image
|
||||
Global.fill_pattern_containers[Global.pattern_window_position].get_child(0).get_child(0).texture = texture
|
||||
Global.fill_pattern_containers[Global.pattern_window_position].get_child(2).get_child(1).max_value = image_size.x - 1
|
||||
Global.fill_pattern_containers[Global.pattern_window_position].get_child(3).get_child(1).max_value = image_size.y - 1
|
||||
|
||||
Global.patterns_popup.hide()
|
||||
Global.patterns_popup.select_pattern(pattern)
|
||||
|
|
45
src/UI/PatternsPopup.gd
Normal file
45
src/UI/PatternsPopup.gd
Normal file
|
@ -0,0 +1,45 @@
|
|||
extends PopupPanel
|
||||
class_name Patterns
|
||||
|
||||
|
||||
class Pattern:
|
||||
var image : Image
|
||||
var index : int
|
||||
|
||||
signal pattern_selected(pattern)
|
||||
|
||||
var default_pattern : Pattern = null
|
||||
|
||||
|
||||
func select_pattern(pattern : Pattern) -> void:
|
||||
emit_signal("pattern_selected", pattern)
|
||||
hide()
|
||||
|
||||
|
||||
static func create_button(image : Image) -> Node:
|
||||
var button : BaseButton = load("res://src/UI/PatternButton.tscn").instance()
|
||||
var tex := ImageTexture.new()
|
||||
tex.create_from_image(image, 0)
|
||||
button.get_child(0).texture = tex
|
||||
button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
||||
return button
|
||||
|
||||
|
||||
static func add(image : Image, hint := "") -> void:
|
||||
var button = create_button(image)
|
||||
button.pattern.image = image
|
||||
button.hint_tooltip = hint
|
||||
var container = Global.patterns_popup.get_node("ScrollContainer/PatternContainer")
|
||||
container.add_child(button)
|
||||
button.pattern.index = button.get_index()
|
||||
|
||||
if Global.patterns_popup.default_pattern == null:
|
||||
Global.patterns_popup.default_pattern = button.pattern
|
||||
|
||||
|
||||
func get_pattern(index : int) -> Pattern:
|
||||
var container = Global.patterns_popup.get_node("ScrollContainer/PatternContainer")
|
||||
var pattern = default_pattern
|
||||
if index < container.get_child_count():
|
||||
pattern = container.get_child(index).pattern
|
||||
return pattern
|
|
@ -1,8 +1,11 @@
|
|||
[gd_scene format=2]
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://src/UI/PatternsPopup.gd" type="Script" id=1]
|
||||
|
||||
[node name="PatternsPopup" type="PopupPanel"]
|
||||
margin_right = 226.0
|
||||
margin_bottom = 104.0
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
|
|
@ -1,98 +1,40 @@
|
|||
extends VBoxContainer
|
||||
|
||||
|
||||
var tools := []
|
||||
# Node, shortcut
|
||||
onready var tools := [
|
||||
[$RectSelect, "rectangle_select"],
|
||||
[$Zoom, "zoom"],
|
||||
[$ColorPicker, "colorpicker"],
|
||||
[$Pencil, "pencil"],
|
||||
[$Eraser, "eraser"],
|
||||
[$Bucket, "fill"],
|
||||
[$LightenDarken, "lightdark"],
|
||||
]
|
||||
|
||||
|
||||
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"):
|
||||
if not Global.has_focus:
|
||||
return
|
||||
for action in ["undo", "redo", "redo_secondary"]:
|
||||
if event.is_action_pressed(action):
|
||||
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)
|
||||
for t in tools: # Handle tool shortcuts
|
||||
if event.is_action_pressed("right_" + t[1] + "_tool"): # Shortcut for right button (with Alt)
|
||||
Tools.assign_tool(t[0].name, BUTTON_RIGHT)
|
||||
elif event.is_action_pressed("left_" + t[1] + "_tool"): # Shortcut for left button
|
||||
Tools.assign_tool(t[0].name, BUTTON_LEFT)
|
||||
|
||||
|
||||
func _on_Tool_pressed(tool_pressed : BaseButton, mouse_press := true, key_for_left := true) -> void:
|
||||
var current_action := tool_pressed.name
|
||||
var current_tool : int = Global.Tools.keys().find(current_action.to_upper())
|
||||
var left_tool_name := str(Global.Tools.keys()[Global.current_tools[0]]).to_lower()
|
||||
var right_tool_name := str(Global.Tools.keys()[Global.current_tools[1]]).to_lower()
|
||||
var current_mouse_button := -1
|
||||
|
||||
if (mouse_press and Input.is_action_just_released("left_mouse")) or (!mouse_press and key_for_left):
|
||||
left_tool_name = current_action.to_lower()
|
||||
current_mouse_button = Global.Mouse_Button.LEFT
|
||||
|
||||
elif (mouse_press and Input.is_action_just_released("right_mouse")) or (!mouse_press and !key_for_left):
|
||||
right_tool_name = current_action.to_lower()
|
||||
current_mouse_button = Global.Mouse_Button.RIGHT
|
||||
|
||||
if current_mouse_button != -1:
|
||||
Global.current_tools[current_mouse_button] = current_tool
|
||||
# Start from 1, so the label won't get invisible
|
||||
for i in range(1, Global.tool_options_containers[current_mouse_button].get_child_count()):
|
||||
Global.tool_options_containers[current_mouse_button].get_child(i).visible = false
|
||||
|
||||
Global.tool_options_containers[current_mouse_button].get_node("EmptySpacer").visible = true
|
||||
|
||||
# Tool options visible depending on the selected tool
|
||||
if current_tool == Global.Tools.PENCIL:
|
||||
Global.brush_type_containers[current_mouse_button].visible = true
|
||||
Global.brush_size_sliders[current_mouse_button].visible = true
|
||||
Global.pixel_perfect_containers[current_mouse_button].visible = true
|
||||
Global.mirror_containers[current_mouse_button].visible = true
|
||||
if Global.current_brush_types[current_mouse_button] == Global.Brush_Types.FILE or Global.current_brush_types[current_mouse_button] == Global.Brush_Types.CUSTOM or Global.current_brush_types[current_mouse_button] == Global.Brush_Types.RANDOM_FILE:
|
||||
Global.color_interpolation_containers[current_mouse_button].visible = true
|
||||
elif current_tool == Global.Tools.ERASER:
|
||||
Global.brush_type_containers[current_mouse_button].visible = true
|
||||
Global.brush_size_sliders[current_mouse_button].visible = true
|
||||
Global.pixel_perfect_containers[current_mouse_button].visible = true
|
||||
Global.mirror_containers[current_mouse_button].visible = true
|
||||
elif current_tool == Global.Tools.BUCKET:
|
||||
Global.fill_area_containers[current_mouse_button].visible = true
|
||||
Global.mirror_containers[current_mouse_button].visible = true
|
||||
elif current_tool == Global.Tools.LIGHTENDARKEN:
|
||||
Global.brush_type_containers[current_mouse_button].visible = true
|
||||
Global.brush_size_sliders[current_mouse_button].visible = true
|
||||
Global.pixel_perfect_containers[current_mouse_button].visible = true
|
||||
Global.ld_containers[current_mouse_button].visible = true
|
||||
Global.mirror_containers[current_mouse_button].visible = true
|
||||
elif current_tool == Global.Tools.COLORPICKER:
|
||||
Global.colorpicker_containers[current_mouse_button].visible = true
|
||||
elif current_tool == Global.Tools.ZOOM:
|
||||
Global.zoom_containers[current_mouse_button].visible = true
|
||||
|
||||
for t in tools:
|
||||
var tool_name : String = t[0].name.to_lower()
|
||||
var texture_button : TextureRect = t[0].get_child(0)
|
||||
|
||||
if tool_name == left_tool_name and tool_name == right_tool_name:
|
||||
Global.change_button_texturerect(texture_button, "%s_l_r.png" % tool_name.to_lower())
|
||||
elif tool_name == left_tool_name:
|
||||
Global.change_button_texturerect(texture_button, "%s_l.png" % tool_name.to_lower())
|
||||
elif tool_name == right_tool_name:
|
||||
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" % left_tool_name), 0)
|
||||
Global.right_cursor_tool_texture.create_from_image(load("res://assets/graphics/cursor_icons/%s_cursor.png" % right_tool_name), 0)
|
||||
func _on_Tool_pressed(tool_pressed : BaseButton) -> void:
|
||||
var button := -1
|
||||
button = BUTTON_LEFT if Input.is_action_just_released("left_mouse") else button
|
||||
button = BUTTON_RIGHT if Input.is_action_just_released("right_mouse") else button
|
||||
if button != -1:
|
||||
Tools.assign_tool(tool_pressed.name, button)
|
||||
|
|
|
@ -39,6 +39,9 @@ func setup_edit_menu() -> void:
|
|||
var edit_menu_items := {
|
||||
"Undo" : InputMap.get_action_list("undo")[0].get_scancode_with_modifiers(),
|
||||
"Redo" : InputMap.get_action_list("redo")[0].get_scancode_with_modifiers(),
|
||||
"Copy" : InputMap.get_action_list("copy")[0].get_scancode_with_modifiers(),
|
||||
"Paste" : InputMap.get_action_list("paste")[0].get_scancode_with_modifiers(),
|
||||
"Delete" : InputMap.get_action_list("delete")[0].get_scancode_with_modifiers(),
|
||||
"Clear Selection" : 0,
|
||||
"Preferences" : 0
|
||||
}
|
||||
|
@ -201,15 +204,16 @@ func edit_menu_id_pressed(id : int) -> void:
|
|||
Global.control.redone = true
|
||||
Global.current_project.undo_redo.redo()
|
||||
Global.control.redone = false
|
||||
2: # Clear selection
|
||||
Global.canvas.handle_undo("Rectangle Select")
|
||||
Global.selection_rectangle.polygon[0] = Vector2.ZERO
|
||||
Global.selection_rectangle.polygon[1] = Vector2.ZERO
|
||||
Global.selection_rectangle.polygon[2] = Vector2.ZERO
|
||||
Global.selection_rectangle.polygon[3] = Vector2.ZERO
|
||||
Global.current_project.selected_pixels.clear()
|
||||
Global.canvas.handle_redo("Rectangle Select")
|
||||
3: # Preferences
|
||||
2: # Copy
|
||||
Global.selection_rectangle.copy()
|
||||
3: # paste
|
||||
Global.selection_rectangle.paste()
|
||||
4: # Delete
|
||||
Global.selection_rectangle.delete()
|
||||
5: # Clear selection
|
||||
Global.selection_rectangle.set_rect(Rect2(0, 0, 0, 0))
|
||||
Global.selection_rectangle.select_rect()
|
||||
6: # Preferences
|
||||
Global.preferences_dialog.popup_centered(Vector2(400, 280))
|
||||
Global.dialog_open(true)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue