mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-02-21 21:13: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:
parent
4a2c0eb291
commit
9b73e4f661
9 changed files with 20 additions and 19 deletions
|
@ -250,6 +250,7 @@ text = "[64×64]"
|
||||||
align = 2
|
align = 2
|
||||||
|
|
||||||
[node name="UI" type="HBoxContainer" parent="MenuAndUI"]
|
[node name="UI" type="HBoxContainer" parent="MenuAndUI"]
|
||||||
|
editor/display_folded = true
|
||||||
margin_top = 28.0
|
margin_top = 28.0
|
||||||
margin_right = 1152.0
|
margin_right = 1152.0
|
||||||
margin_bottom = 648.0
|
margin_bottom = 648.0
|
||||||
|
@ -580,6 +581,7 @@ text = "Brush color from"
|
||||||
margin_left = 94.0
|
margin_left = 94.0
|
||||||
margin_right = 149.0
|
margin_right = 149.0
|
||||||
margin_bottom = 17.0
|
margin_bottom = 17.0
|
||||||
|
hint_tooltip = "COLORFROM_HT"
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
size_flags_vertical = 1
|
size_flags_vertical = 1
|
||||||
value = 100.0
|
value = 100.0
|
||||||
|
|
|
@ -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.png" type="Texture" id=4]
|
||||||
[ext_resource path="res://Assets/Graphics/Palette/remove_swatch_button_hover.png" type="Texture" id=5]
|
[ext_resource path="res://Assets/Graphics/Palette/remove_swatch_button_hover.png" type="Texture" id=5]
|
||||||
|
|
||||||
|
|
||||||
[node name="EditPalettePopup" type="WindowDialog"]
|
[node name="EditPalettePopup" type="WindowDialog"]
|
||||||
visible = true
|
visible = true
|
||||||
margin_right = 600.0
|
margin_right = 600.0
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
[ext_resource path="res://Scripts/Palette/PaletteButton.gd" type="Script" id=5]
|
[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]
|
[ext_resource path="res://Assets/Graphics/Palette/palette_button_fill.png" type="Texture" id=6]
|
||||||
|
|
||||||
|
|
||||||
[sub_resource type="ImageTexture" id=1]
|
[sub_resource type="ImageTexture" id=1]
|
||||||
|
|
||||||
[node name="PaletteButton" type="Button"]
|
[node name="PaletteButton" type="Button"]
|
||||||
|
@ -19,6 +18,7 @@ custom_styles/hover = ExtResource( 1 )
|
||||||
custom_styles/pressed = ExtResource( 2 )
|
custom_styles/pressed = ExtResource( 2 )
|
||||||
custom_styles/focus = ExtResource( 3 )
|
custom_styles/focus = ExtResource( 3 )
|
||||||
custom_styles/normal = ExtResource( 4 )
|
custom_styles/normal = ExtResource( 4 )
|
||||||
|
action_mode = 0
|
||||||
button_mask = 3
|
button_mask = 3
|
||||||
icon = SubResource( 1 )
|
icon = SubResource( 1 )
|
||||||
script = ExtResource( 5 )
|
script = ExtResource( 5 )
|
||||||
|
|
|
@ -33,26 +33,32 @@ func _display_palette() -> void:
|
||||||
new_button.draggable = true
|
new_button.draggable = true
|
||||||
new_button.index = index
|
new_button.index = index
|
||||||
new_button.connect("on_drop_data", self, "on_move_swatch")
|
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)
|
palette_grid.add_child(new_button)
|
||||||
index += 1
|
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:
|
func _clear_swatches() -> void:
|
||||||
for child in palette_grid.get_children():
|
for child in palette_grid.get_children():
|
||||||
if child is BaseButton:
|
if child is BaseButton:
|
||||||
child.disconnect("on_drop_data", self, "on_move_swatch")
|
child.disconnect("on_drop_data", self, "on_move_swatch")
|
||||||
child.queue_free()
|
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
|
current_swatch = index
|
||||||
color_name_edit.text = working_palette.get_color_name(index)
|
color_name_edit.text = working_palette.get_color_name(index)
|
||||||
color_picker.color = working_palette.get_color(index)
|
color_picker.color = working_palette.get_color(index)
|
||||||
|
|
||||||
func on_move_swatch(from : int, to : int) -> void:
|
func on_move_swatch(from : int, to : int) -> void:
|
||||||
working_palette.move_color(from, to)
|
working_palette.move_color(from, to)
|
||||||
|
|
||||||
palette_grid.move_child(palette_grid.get_child(from), to)
|
palette_grid.move_child(palette_grid.get_child(from), to)
|
||||||
|
current_swatch = to
|
||||||
|
|
||||||
# Re-index swatches with new order
|
# Re-index swatches with new order
|
||||||
var index := 0
|
var index := 0
|
||||||
|
@ -61,7 +67,7 @@ func on_move_swatch(from : int, to : int) -> void:
|
||||||
index += 1
|
index += 1
|
||||||
|
|
||||||
func _on_AddSwatchButton_pressed() -> void:
|
func _on_AddSwatchButton_pressed() -> void:
|
||||||
var color = Color.white
|
var color : Color = color_picker.color
|
||||||
var new_index : int = working_palette.colors.size()
|
var new_index : int = working_palette.colors.size()
|
||||||
working_palette.add_color(color)
|
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)
|
working_palette.set_color_name(current_swatch, new_text)
|
||||||
_refresh_hint_tooltip(current_swatch)
|
_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():
|
if current_swatch >= 0 && current_swatch < working_palette.colors.size():
|
||||||
palette_grid.get_child(current_swatch).get_child(0).modulate = color
|
palette_grid.get_child(current_swatch).get_child(0).modulate = color
|
||||||
working_palette.set_color(current_swatch, color)
|
working_palette.set_color(current_swatch, color)
|
||||||
|
|
|
@ -12,13 +12,12 @@ var comments : String = ""
|
||||||
var editable : bool = true
|
var editable : bool = true
|
||||||
|
|
||||||
func insert_color(index : int, new_color : Color, _name : String = "no name") -> void:
|
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)
|
var c := PaletteColor.new(new_color, _name)
|
||||||
colors.insert(index, c)
|
colors.insert(index, c)
|
||||||
|
|
||||||
func add_color(new_color : Color, _name : String = "no name") -> void:
|
func add_color(new_color : Color, _name : String = "no name") -> void:
|
||||||
var c := PaletteColor.new(new_color, _name)
|
var c := PaletteColor.new(new_color, _name)
|
||||||
|
|
||||||
colors.push_back(c)
|
colors.push_back(c)
|
||||||
|
|
||||||
func remove_color(index : int) -> void:
|
func remove_color(index : int) -> void:
|
||||||
|
@ -101,7 +100,7 @@ func deserialize(input_string : String) -> Palette:
|
||||||
var result = get_script().new()
|
var result = get_script().new()
|
||||||
|
|
||||||
var result_json = JSON.parse(input_string)
|
var result_json = JSON.parse(input_string)
|
||||||
#
|
|
||||||
if result_json.error != OK: # If parse has errors
|
if result_json.error != OK: # If parse has errors
|
||||||
print("Error: ", result_json.error)
|
print("Error: ", result_json.error)
|
||||||
print("Error Line: ", result_json.error_line)
|
print("Error Line: ", result_json.error_line)
|
||||||
|
@ -109,7 +108,7 @@ func deserialize(input_string : String) -> Palette:
|
||||||
result = null
|
result = null
|
||||||
else: # If parse OK
|
else: # If parse OK
|
||||||
var data = result_json.result
|
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 = get_script().new()
|
||||||
result.name = data.name
|
result.name = data.name
|
||||||
if data.has("comments"):
|
if data.has("comments"):
|
||||||
|
|
|
@ -23,4 +23,3 @@ func can_drop_data(position, data):
|
||||||
|
|
||||||
func drop_data(position, data):
|
func drop_data(position, data):
|
||||||
emit_signal("on_drop_data", data.source_index, index);
|
emit_signal("on_drop_data", data.source_index, index);
|
||||||
pass;
|
|
||||||
|
|
|
@ -38,11 +38,9 @@ func on_new_empty_palette() -> void:
|
||||||
Global.new_palette_name_line_edit.text = "Custom_Palette"
|
Global.new_palette_name_line_edit.text = "Custom_Palette"
|
||||||
from_palette = null
|
from_palette = null
|
||||||
Global.new_palette_dialog.popup_centered()
|
Global.new_palette_dialog.popup_centered()
|
||||||
pass
|
|
||||||
|
|
||||||
func on_import_palette() -> void:
|
func on_import_palette() -> void:
|
||||||
Global.palette_import_file_dialog.popup_centered()
|
Global.palette_import_file_dialog.popup_centered()
|
||||||
pass
|
|
||||||
|
|
||||||
func on_palette_import_file_selected(path) -> void:
|
func on_palette_import_file_selected(path) -> void:
|
||||||
var file := File.new()
|
var file := File.new()
|
||||||
|
@ -67,7 +65,6 @@ func on_palette_import_file_selected(path) -> void:
|
||||||
else:
|
else:
|
||||||
Global.error_dialog.set_text("Invalid Palette file!")
|
Global.error_dialog.set_text("Invalid Palette file!")
|
||||||
Global.error_dialog.popup_centered()
|
Global.error_dialog.popup_centered()
|
||||||
pass
|
|
||||||
|
|
||||||
func on_edit_palette() -> void:
|
func on_edit_palette() -> void:
|
||||||
var palette : Dictionary = Global.palettes[current_palette]
|
var palette : Dictionary = Global.palettes[current_palette]
|
||||||
|
@ -138,10 +135,10 @@ func _display_palette(palette : Palette) -> void:
|
||||||
func on_color_select(index : int) -> void:
|
func on_color_select(index : int) -> void:
|
||||||
var color : Color = Global.palettes[current_palette].get_color(index)
|
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.left_color_picker.color = color
|
||||||
Global.update_left_custom_brush()
|
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.right_color_picker.color = color
|
||||||
Global.update_right_custom_brush()
|
Global.update_right_custom_brush()
|
||||||
|
|
||||||
|
@ -208,7 +205,6 @@ func remove_current_palette() -> void:
|
||||||
if(selected_index - 1 >= 0):
|
if(selected_index - 1 >= 0):
|
||||||
Global.palette_option_button.select(selected_index - 1)
|
Global.palette_option_button.select(selected_index - 1)
|
||||||
on_palette_select(Global.palette_option_button.get_item_metadata(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:
|
func _delete_palette_file(file_name : String) -> void:
|
||||||
var dir = Directory.new()
|
var dir = Directory.new()
|
||||||
|
|
|
@ -17,7 +17,7 @@ _global_script_classes=[ {
|
||||||
"base": "Line2D",
|
"base": "Line2D",
|
||||||
"class": "Guide",
|
"class": "Guide",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://Scripts/Guides.gd"
|
"path": "res://Scripts/Rulers/Guides.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "Button",
|
"base": "Button",
|
||||||
"class": "LayerContainer",
|
"class": "LayerContainer",
|
||||||
|
|
Loading…
Add table
Reference in a new issue