1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-02-20 12:33:14 +00:00

Edit palette fixes

- If the palette has colors, automatically select the first one
- When adding a new color button, take the color currently selected on the picker instead of white
- Fixes issues with drag&dropping color buttons. The color that was dragged remains selected.
This commit is contained in:
OverloadedOrama 2019-12-26 02:01:04 +02:00
parent 4a2c0eb291
commit 9b73e4f661
9 changed files with 20 additions and 19 deletions

View file

@ -250,6 +250,7 @@ text = "[64×64]"
align = 2
[node name="UI" type="HBoxContainer" parent="MenuAndUI"]
editor/display_folded = true
margin_top = 28.0
margin_right = 1152.0
margin_bottom = 648.0
@ -580,6 +581,7 @@ text = "Brush color from"
margin_left = 94.0
margin_right = 149.0
margin_bottom = 17.0
hint_tooltip = "COLORFROM_HT"
size_flags_horizontal = 3
size_flags_vertical = 1
value = 100.0

View file

@ -6,7 +6,6 @@
[ext_resource path="res://Assets/Graphics/Palette/remove_swatch_button.png" type="Texture" id=4]
[ext_resource path="res://Assets/Graphics/Palette/remove_swatch_button_hover.png" type="Texture" id=5]
[node name="EditPalettePopup" type="WindowDialog"]
visible = true
margin_right = 600.0

View file

@ -7,7 +7,6 @@
[ext_resource path="res://Scripts/Palette/PaletteButton.gd" type="Script" id=5]
[ext_resource path="res://Assets/Graphics/Palette/palette_button_fill.png" type="Texture" id=6]
[sub_resource type="ImageTexture" id=1]
[node name="PaletteButton" type="Button"]
@ -19,6 +18,7 @@ custom_styles/hover = ExtResource( 1 )
custom_styles/pressed = ExtResource( 2 )
custom_styles/focus = ExtResource( 3 )
custom_styles/normal = ExtResource( 4 )
action_mode = 0
button_mask = 3
icon = SubResource( 1 )
script = ExtResource( 5 )

View file

@ -33,26 +33,32 @@ func _display_palette() -> void:
new_button.draggable = true
new_button.index = index
new_button.connect("on_drop_data", self, "on_move_swatch")
new_button.connect("pressed", self, "on_swatch_select", [index])
new_button.connect("pressed", self, "on_swatch_select", [new_button])
palette_grid.add_child(new_button)
index += 1
if index > 0: # If there are colors, select the first
current_swatch = 0
color_name_edit.text = working_palette.get_color_name(0)
color_picker.color = working_palette.get_color(0)
func _clear_swatches() -> void:
for child in palette_grid.get_children():
if child is BaseButton:
child.disconnect("on_drop_data", self, "on_move_swatch")
child.queue_free()
func on_swatch_select(index : int) -> void:
func on_swatch_select(new_button) -> void:
var index : int = new_button.index
current_swatch = index
color_name_edit.text = working_palette.get_color_name(index)
color_picker.color = working_palette.get_color(index)
func on_move_swatch(from : int, to : int) -> void:
working_palette.move_color(from, to)
palette_grid.move_child(palette_grid.get_child(from), to)
current_swatch = to
# Re-index swatches with new order
var index := 0
@ -61,7 +67,7 @@ func on_move_swatch(from : int, to : int) -> void:
index += 1
func _on_AddSwatchButton_pressed() -> void:
var color = Color.white
var color : Color = color_picker.color
var new_index : int = working_palette.colors.size()
working_palette.add_color(color)
@ -96,7 +102,7 @@ func _on_EditPaletteColorNameLineEdit_text_changed(new_text) -> void:
working_palette.set_color_name(current_swatch, new_text)
_refresh_hint_tooltip(current_swatch)
func _on_EditPaletteColorPicker_color_changed(color) -> void:
func _on_EditPaletteColorPicker_color_changed(color : Color) -> void:
if current_swatch >= 0 && current_swatch < working_palette.colors.size():
palette_grid.get_child(current_swatch).get_child(0).modulate = color
working_palette.set_color(current_swatch, color)

View file

@ -12,13 +12,12 @@ var comments : String = ""
var editable : bool = true
func insert_color(index : int, new_color : Color, _name : String = "no name") -> void:
if index < colors.size():
if index <= colors.size():
var c := PaletteColor.new(new_color, _name)
colors.insert(index, c)
func add_color(new_color : Color, _name : String = "no name") -> void:
var c := PaletteColor.new(new_color, _name)
colors.push_back(c)
func remove_color(index : int) -> void:
@ -101,7 +100,7 @@ func deserialize(input_string : String) -> Palette:
var result = get_script().new()
var result_json = JSON.parse(input_string)
#
if result_json.error != OK: # If parse has errors
print("Error: ", result_json.error)
print("Error Line: ", result_json.error_line)
@ -109,7 +108,7 @@ func deserialize(input_string : String) -> Palette:
result = null
else: # If parse OK
var data = result_json.result
if data.has("name"): #If data is 'valid' palette file
if data.has("name"): # If data is 'valid' palette file
result = get_script().new()
result.name = data.name
if data.has("comments"):

View file

@ -23,4 +23,3 @@ func can_drop_data(position, data):
func drop_data(position, data):
emit_signal("on_drop_data", data.source_index, index);
pass;

View file

@ -38,11 +38,9 @@ func on_new_empty_palette() -> void:
Global.new_palette_name_line_edit.text = "Custom_Palette"
from_palette = null
Global.new_palette_dialog.popup_centered()
pass
func on_import_palette() -> void:
Global.palette_import_file_dialog.popup_centered()
pass
func on_palette_import_file_selected(path) -> void:
var file := File.new()
@ -67,7 +65,6 @@ func on_palette_import_file_selected(path) -> void:
else:
Global.error_dialog.set_text("Invalid Palette file!")
Global.error_dialog.popup_centered()
pass
func on_edit_palette() -> void:
var palette : Dictionary = Global.palettes[current_palette]
@ -138,10 +135,10 @@ func _display_palette(palette : Palette) -> void:
func on_color_select(index : int) -> void:
var color : Color = Global.palettes[current_palette].get_color(index)
if Input.is_action_just_released("left_mouse"):
if Input.is_action_just_pressed("left_mouse"):
Global.left_color_picker.color = color
Global.update_left_custom_brush()
elif Input.is_action_just_released("right_mouse"):
elif Input.is_action_just_pressed("right_mouse"):
Global.right_color_picker.color = color
Global.update_right_custom_brush()
@ -208,7 +205,6 @@ func remove_current_palette() -> void:
if(selected_index - 1 >= 0):
Global.palette_option_button.select(selected_index - 1)
on_palette_select(Global.palette_option_button.get_item_metadata(selected_index - 1))
pass
func _delete_palette_file(file_name : String) -> void:
var dir = Directory.new()

View file

@ -17,7 +17,7 @@ _global_script_classes=[ {
"base": "Line2D",
"class": "Guide",
"language": "GDScript",
"path": "res://Scripts/Guides.gd"
"path": "res://Scripts/Rulers/Guides.gd"
}, {
"base": "Button",
"class": "LayerContainer",