mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-19 01:29:49 +00:00
Merge pull request #62 from greusser/palette_updates
Added edit palette menu
This commit is contained in:
commit
2d96ed278d
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "BubbleGum16",
|
||||
"colors" : [
|
||||
"name": "BubbleGum16",
|
||||
"colors" : [
|
||||
{ "data" : "#FF000000", "name" : "no name" },
|
||||
{ "data" : "#FF7f0622", "name" : "no name" },
|
||||
{ "data" : "#FFd62411", "name" : "no name" },
|
||||
|
@ -18,5 +18,6 @@
|
|||
{ "data" : "#FF007899", "name" : "no name" },
|
||||
{ "data" : "#FF002859", "name" : "no name" },
|
||||
],
|
||||
"comments": "by PineTreePizza - https://twitter.com/PineTreePizza"
|
||||
"comments": "by PineTreePizza - https://twitter.com/PineTreePizza",
|
||||
"editable": false
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "Default",
|
||||
"colors" : [
|
||||
"name": "Default",
|
||||
"colors" : [
|
||||
{ "data" : "#FF000000", "name" : "no name" },
|
||||
{ "data" : "#FF222034", "name" : "no name" },
|
||||
{ "data" : "#FF45283c", "name" : "no name" },
|
||||
|
@ -33,5 +33,7 @@
|
|||
{ "data" : "#FFd77bba", "name" : "no name" },
|
||||
{ "data" : "#FF8f974a", "name" : "no name" },
|
||||
{ "data" : "#FF8a6f30", "name" : "no name" }
|
||||
]
|
||||
],
|
||||
"comments": "Aseprite default palette",
|
||||
"editable": false
|
||||
}
|
BIN
Assets/Graphics/Palette/swatch_drag_preview.png
Normal file
BIN
Assets/Graphics/Palette/swatch_drag_preview.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 111 B |
34
Assets/Graphics/Palette/swatch_drag_preview.png.import
Normal file
34
Assets/Graphics/Palette/swatch_drag_preview.png.import
Normal file
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/swatch_drag_preview.png-4e3b034338643b2d9a5d7daa883dd850.stex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://Assets/Graphics/Palette/swatch_drag_preview.png"
|
||||
dest_files=[ "res://.import/swatch_drag_preview.png-4e3b034338643b2d9a5d7daa883dd850.stex" ]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=0
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
flags/repeat=0
|
||||
flags/filter=false
|
||||
flags/mipmaps=false
|
||||
flags/anisotropic=false
|
||||
flags/srgb=2
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/HDR_as_SRGB=false
|
||||
process/invert_color=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=false
|
||||
svg/scale=1.0
|
|
@ -1,9 +1,11 @@
|
|||
[gd_scene load_steps=6 format=2]
|
||||
[gd_scene load_steps=8 format=2]
|
||||
|
||||
[ext_resource path="res://Themes & Styles/StyleBoxes/palette_stylebox_hover.tres" type="StyleBox" id=1]
|
||||
[ext_resource path="res://Themes & Styles/StyleBoxes/palette_stylebox_pressedr.tres" type="StyleBox" id=2]
|
||||
[ext_resource path="res://Themes & Styles/StyleBoxes/palette_stylebox_normal.tres" type="StyleBox" id=3]
|
||||
[ext_resource path="res://Assets/Graphics/Palette/palette_button_fill.png" type="Texture" id=4]
|
||||
[ext_resource path="res://Themes & Styles/StyleBoxes/palette_stylebox_focus.tres" type="StyleBox" id=3]
|
||||
[ext_resource path="res://Themes & Styles/StyleBoxes/palette_stylebox_normal.tres" type="StyleBox" id=4]
|
||||
[ext_resource path="res://Scripts/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]
|
||||
|
||||
|
@ -14,9 +16,11 @@ rect_min_size = Vector2( 26, 26 )
|
|||
hint_tooltip = "Color Name"
|
||||
custom_styles/hover = ExtResource( 1 )
|
||||
custom_styles/pressed = ExtResource( 2 )
|
||||
custom_styles/normal = ExtResource( 3 )
|
||||
custom_styles/focus = ExtResource( 3 )
|
||||
custom_styles/normal = ExtResource( 4 )
|
||||
button_mask = 3
|
||||
icon = SubResource( 1 )
|
||||
script = ExtResource( 5 )
|
||||
|
||||
[node name="NinePatchRect" type="NinePatchRect" parent="."]
|
||||
anchor_right = 1.0
|
||||
|
@ -27,7 +31,7 @@ margin_right = -1.0
|
|||
margin_bottom = -1.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
texture = ExtResource( 4 )
|
||||
texture = ExtResource( 6 )
|
||||
patch_margin_left = 2
|
||||
patch_margin_top = 2
|
||||
patch_margin_right = 2
|
||||
|
|
131
Scripts/EditPalettePopup.gd
Normal file
131
Scripts/EditPalettePopup.gd
Normal file
|
@ -0,0 +1,131 @@
|
|||
extends WindowDialog
|
||||
|
||||
# Declare member variables here. Examples:
|
||||
# var a = 2
|
||||
# var b = "text"
|
||||
|
||||
onready var palette_grid = $VBoxContainer/HBoxContainer/Panel/EditPaletteGridContainer
|
||||
onready var color_name_edit = $VBoxContainer/HBoxContainer3/EditPaletteColorNameLineEdit
|
||||
onready var color_picker = $VBoxContainer/HBoxContainer/EditPaletteColorPicker
|
||||
|
||||
var palette_button = preload("res://Prefabs/PaletteButton.tscn");
|
||||
|
||||
var current_palette : String
|
||||
var current_swatch := -1
|
||||
var working_palette : Dictionary
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
||||
func open(palette : String) -> void:
|
||||
current_palette = palette
|
||||
if Global.palettes.has(palette):
|
||||
working_palette = Global.palettes[palette].duplicate()
|
||||
|
||||
_display_palette()
|
||||
|
||||
self.popup_centered()
|
||||
pass
|
||||
|
||||
func _display_palette() -> void:
|
||||
_clear_swatches()
|
||||
var index := 0
|
||||
|
||||
for color_data in working_palette.colors:
|
||||
var color = Color(color_data.data)
|
||||
var new_button = palette_button.instance()
|
||||
|
||||
new_button.color = color
|
||||
new_button.get_child(0).modulate = color
|
||||
new_button.hint_tooltip = color_data.data.to_upper() + " " + color_data.name
|
||||
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])
|
||||
|
||||
palette_grid.add_child(new_button)
|
||||
index += 1
|
||||
|
||||
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:
|
||||
current_swatch = index
|
||||
color_name_edit.text = working_palette.colors[index].name
|
||||
color_picker.color = working_palette.colors[index].data
|
||||
pass
|
||||
|
||||
func on_move_swatch(from : int, to : int) -> void:
|
||||
var color_to_move = working_palette.colors[from]
|
||||
working_palette.colors.remove(from)
|
||||
working_palette.colors.insert(to, color_to_move)
|
||||
|
||||
palette_grid.move_child(palette_grid.get_child(from), to)
|
||||
|
||||
# Re-index swatches with new order
|
||||
var index := 0
|
||||
for child in palette_grid.get_children():
|
||||
child.index = index
|
||||
index += 1
|
||||
pass
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
#func _process(delta):
|
||||
# pass
|
||||
|
||||
func _on_AddSwatchButton_pressed() -> void:
|
||||
var color = Color.white
|
||||
var color_data = {}
|
||||
color_data.data = color.to_html(true)
|
||||
color_data.name = "no name"
|
||||
working_palette.colors.push_back(color_data)
|
||||
var new_button = palette_button.instance()
|
||||
|
||||
new_button.color = color
|
||||
new_button.get_child(0).modulate = color
|
||||
new_button.hint_tooltip = color_data.data.to_upper() + " " + color_data.name
|
||||
new_button.draggable = true
|
||||
var index : int = palette_grid.get_child_count()
|
||||
new_button.index = index
|
||||
new_button.connect("on_drop_data", self, "on_move_swatch")
|
||||
new_button.connect("pressed", self, "on_swatch_select", [index])
|
||||
|
||||
palette_grid.add_child(new_button)
|
||||
pass # Replace with function body.
|
||||
|
||||
func _on_RemoveSwatchButton_pressed() -> void:
|
||||
working_palette.colors.remove(current_swatch)
|
||||
palette_grid.remove_child(palette_grid.get_child(current_swatch))
|
||||
pass # Replace with function body.
|
||||
|
||||
func _on_EditPaletteSaveButton_pressed() -> void:
|
||||
Global.palettes[current_palette] = working_palette
|
||||
Global.palette_container.on_palette_select(current_palette)
|
||||
Global.palette_container.save_palette(current_palette, working_palette.name + ".json")
|
||||
self.hide()
|
||||
pass # Replace with function body.
|
||||
|
||||
func _on_EditPaletteCancelButton_pressed() -> void:
|
||||
self.hide()
|
||||
pass # Replace with function body.
|
||||
|
||||
func _on_EditPaletteColorNameLineEdit_text_changed(new_text) -> void:
|
||||
if current_swatch > 0 && current_swatch < working_palette.colors.size():
|
||||
working_palette.colors[current_swatch].name = new_text
|
||||
_refresh_hint_tooltip(current_swatch)
|
||||
pass
|
||||
|
||||
func _on_EditPaletteColorPicker_color_changed(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.colors[current_swatch].data = color.to_html(true)
|
||||
_refresh_hint_tooltip(current_swatch)
|
||||
pass
|
||||
|
||||
func _refresh_hint_tooltip(index : int):
|
||||
palette_grid.get_child(current_swatch).hint_tooltip = working_palette.colors[current_swatch].data.to_upper() + " " + working_palette.colors[current_swatch].name
|
||||
pass
|
|
@ -187,6 +187,11 @@ var remove_palette_button : TextureButton
|
|||
var palette_option_button : OptionButton
|
||||
var edit_palette_button : BaseButton
|
||||
var palette_container : GridContainer
|
||||
var edit_palette_popup : WindowDialog
|
||||
var new_palette_dialog : ConfirmationDialog
|
||||
var new_palette_name_line_edit : LineEdit
|
||||
|
||||
var error_dialog : AcceptDialog
|
||||
|
||||
func _ready() -> void:
|
||||
undo_redo = UndoRedo.new()
|
||||
|
@ -275,6 +280,11 @@ func _ready() -> void:
|
|||
palette_option_button = find_node_by_name(root, "PaletteOptionButton")
|
||||
edit_palette_button = find_node_by_name(root, "EditPalette")
|
||||
palette_container = find_node_by_name(root, "PaletteContainer")
|
||||
edit_palette_popup = find_node_by_name(root, "EditPalettePopup")
|
||||
new_palette_dialog = find_node_by_name(root, "NewPaletteDialog")
|
||||
new_palette_name_line_edit = find_node_by_name(new_palette_dialog, "NewPaletteNameLineEdit")
|
||||
|
||||
error_dialog = find_node_by_name(root, "ErrorDialog")
|
||||
|
||||
#Thanks to https://godotengine.org/qa/17524/how-to-find-an-instanced-scene-by-its-name
|
||||
func find_node_by_name(root, node_name) -> Node:
|
||||
|
|
|
@ -1047,3 +1047,16 @@ func _exit_tree() -> void:
|
|||
func _on_PaletteOptionButton_item_selected(ID) -> void:
|
||||
var palette_name = Global.palette_option_button.get_item_metadata(ID)
|
||||
Global.palette_container.on_palette_select(palette_name)
|
||||
|
||||
func _on_EditPalette_pressed() -> void:
|
||||
Global.palette_container.on_edit_palette()
|
||||
pass
|
||||
|
||||
func _on_RemovePalette_pressed() -> void:
|
||||
Global.palette_container.remove_current_palette()
|
||||
pass
|
||||
|
||||
func _on_NewPaletteDialog_confirmed() -> void:
|
||||
Global.palette_container.on_new_palette_confirmed()
|
||||
pass
|
||||
|
||||
|
|
39
Scripts/PaletteButton.gd
Normal file
39
Scripts/PaletteButton.gd
Normal file
|
@ -0,0 +1,39 @@
|
|||
extends Button
|
||||
|
||||
# Declare member variables here. Examples:
|
||||
# var a = 2
|
||||
# var b = "text"
|
||||
|
||||
signal on_drop_data
|
||||
|
||||
export var index := 0;
|
||||
export var color : Color = Color.white
|
||||
export var draggable := false
|
||||
|
||||
var drag_preview_texture = preload("res://Assets/Graphics/Palette/swatch_drag_preview.png")
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
||||
func get_drag_data(position):
|
||||
var data = null;
|
||||
if(draggable):
|
||||
#print(String(get_instance_id()) + ": Drag Start");
|
||||
data = {source_index = index};
|
||||
var drag_icon = TextureRect.new();
|
||||
drag_icon.texture = drag_preview_texture;
|
||||
drag_icon.modulate = color
|
||||
set_drag_preview(drag_icon);
|
||||
return data;
|
||||
|
||||
func can_drop_data(position, data):
|
||||
return true;
|
||||
|
||||
func drop_data(position, data):
|
||||
emit_signal("on_drop_data", data.source_index, index);
|
||||
pass;
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
#func _process(delta):
|
||||
# pass
|
|
@ -3,46 +3,13 @@ extends GridContainer
|
|||
var palette_button = preload("res://Prefabs/PaletteButton.tscn");
|
||||
|
||||
var current_palette = "Default"
|
||||
|
||||
var default_palette = [
|
||||
Color("#FF000000"),
|
||||
Color("#FF222034"),
|
||||
Color("#FF45283c"),
|
||||
Color("#FF663931"),
|
||||
Color("#FF8f563b"),
|
||||
Color("#FFdf7126"),
|
||||
Color("#FFd9a066"),
|
||||
Color("#FFeec39a"),
|
||||
Color("#FFfbf236"),
|
||||
Color("#FF99e550"),
|
||||
Color("#FF6abe30"),
|
||||
Color("#FF37946e"),
|
||||
Color("#FF4b692f"),
|
||||
Color("#FF524b24"),
|
||||
Color("#FF323c39"),
|
||||
Color("#FF3f3f74"),
|
||||
Color("#FF306082"),
|
||||
Color("#FF5b6ee1"),
|
||||
Color("#FF639bff"),
|
||||
Color("#FF5fcde4"),
|
||||
Color("#FFcbdbfc"),
|
||||
Color("#FFffffff"),
|
||||
Color("#FF9badb7"),
|
||||
Color("#FF847e87"),
|
||||
Color("#FF696a6a"),
|
||||
Color("#FF595652"),
|
||||
Color("#FF76428a"),
|
||||
Color("#FFac3232"),
|
||||
Color("#FFd95763"),
|
||||
Color("#FFd77bba"),
|
||||
Color("#FF8f974a"),
|
||||
Color("#FF8a6f30")
|
||||
]
|
||||
var from_palette : = {}
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
_load_palettes()
|
||||
|
||||
#Select default palette "Default"
|
||||
on_palette_select(current_palette)
|
||||
|
||||
func _clear_swatches() -> void:
|
||||
|
@ -53,25 +20,93 @@ func _clear_swatches() -> void:
|
|||
|
||||
func on_palette_select(palette_name : String) -> void:
|
||||
_clear_swatches()
|
||||
current_palette = palette_name
|
||||
if Global.palettes.has(palette_name):
|
||||
_display_palette(Global.palettes[palette_name])
|
||||
else:
|
||||
if Global.palettes.has(palette_name): #Palette exists in memory
|
||||
current_palette = palette_name
|
||||
var palette : Dictionary = Global.palettes[palette_name]
|
||||
|
||||
Global.remove_palette_button.disabled = true # Cannot remove by default
|
||||
if palette.has("editable"):
|
||||
if palette.editable:
|
||||
Global.remove_palette_button.disabled = false # Can remove if custom palette
|
||||
|
||||
_display_palette(palette)
|
||||
else: #Use default on fail
|
||||
current_palette = "Default"
|
||||
_display_palette(Global.palettes["Default"])
|
||||
|
||||
func _display_palette(palette : Array) -> void:
|
||||
func on_edit_palette() -> void:
|
||||
var palette : Dictionary = Global.palettes[current_palette]
|
||||
|
||||
var create_new_palette := true # Create new palette by default
|
||||
if palette.has("editable"):
|
||||
if palette.editable:
|
||||
create_new_palette = false # Edit if already a custom palette
|
||||
|
||||
if create_new_palette:
|
||||
from_palette = Global.palettes[current_palette]
|
||||
Global.new_palette_name_line_edit.text = "Custom_" + current_palette
|
||||
Global.new_palette_dialog.popup_centered()
|
||||
else:
|
||||
from_palette = {}
|
||||
Global.edit_palette_popup.open(current_palette)
|
||||
|
||||
func on_new_palette_confirmed() -> void:
|
||||
var new_palette_name : String = Global.new_palette_name_line_edit.text
|
||||
var result : String = create_new_palette(new_palette_name, from_palette)
|
||||
if not result.empty():
|
||||
Global.error_dialog.set_text(result);
|
||||
Global.error_dialog.popup_centered()
|
||||
|
||||
func create_new_palette(name : String, from_palette : Dictionary = {}) -> String: # Returns empty string, else error string
|
||||
var new_palette : Dictionary = {}
|
||||
|
||||
# Check if new name is valid
|
||||
if name.empty():
|
||||
return "Error: Palette must have a valid name."
|
||||
if Global.palettes.has(name):
|
||||
return "Error: Palette '" + name + "' already exists!"
|
||||
|
||||
new_palette.name = name
|
||||
|
||||
# Check if source palette has data
|
||||
if from_palette.has("name"):
|
||||
new_palette = from_palette.duplicate()
|
||||
new_palette.name = name
|
||||
new_palette.editable = true
|
||||
else:
|
||||
new_palette.colors = []
|
||||
new_palette.comments = ""
|
||||
new_palette.editable = true
|
||||
|
||||
# Add palette to Global and options
|
||||
Global.palettes[name] = new_palette
|
||||
Global.palette_option_button.add_item(name)
|
||||
var index := Global.palette_option_button.get_item_count() - 1
|
||||
Global.palette_option_button.set_item_metadata(index, name)
|
||||
Global.palette_option_button.select(index)
|
||||
|
||||
save_palette(name, name + ".json")
|
||||
|
||||
on_palette_select(name)
|
||||
return ""
|
||||
|
||||
func _display_palette(palette : Dictionary) -> void:
|
||||
var index := 0
|
||||
for color_data in palette:
|
||||
|
||||
for color_data in palette.colors:
|
||||
var color = Color(color_data.data)
|
||||
var new_button = palette_button.instance()
|
||||
|
||||
new_button.get_child(0).modulate = color
|
||||
new_button.hint_tooltip = color_data.data.to_upper() + " " + color_data.name
|
||||
new_button.connect("pressed", self, "on_color_select", [index])
|
||||
|
||||
add_child(new_button)
|
||||
index += 1
|
||||
|
||||
func on_color_select(index : int) -> void:
|
||||
var color = Color(Global.palettes[current_palette][index].data)
|
||||
var color = Color(Global.palettes[current_palette].colors[index].data)
|
||||
|
||||
if Input.is_action_just_released("left_mouse"):
|
||||
Global.left_color_picker.color = color
|
||||
Global.update_left_custom_brush()
|
||||
|
@ -80,28 +115,21 @@ func on_color_select(index : int) -> void:
|
|||
Global.update_right_custom_brush()
|
||||
|
||||
func _load_palettes() -> void:
|
||||
var files := []
|
||||
|
||||
var file := File.new()
|
||||
var dir := Directory.new()
|
||||
|
||||
if not dir.dir_exists("user://palettes"):
|
||||
dir.make_dir("user://palettes");
|
||||
if not dir.dir_exists("user://palettes/custom"):
|
||||
dir.make_dir("user://palettes/custom")
|
||||
if not file.file_exists("user://palettes/default_palette.json"):
|
||||
dir.copy("res://Assets/Graphics/Palette/default_palette.json","user://palettes/default_palette.json");
|
||||
if not file.file_exists("user://palettes/bubblegum16.json"):
|
||||
dir.copy("res://Assets/Graphics/Palette/bubblegum16.json","user://palettes/bubblegum16.json");
|
||||
|
||||
dir.open("user://palettes")
|
||||
dir.list_dir_begin()
|
||||
var palette_files : Array = get_palette_files("user://palettes")
|
||||
|
||||
while true:
|
||||
var file_name = dir.get_next()
|
||||
if file_name == "":
|
||||
break
|
||||
elif not file_name.begins_with(".") && file_name.to_lower().ends_with("json"):
|
||||
files.append(file_name)
|
||||
|
||||
dir.list_dir_end()
|
||||
|
||||
for file_name in files:
|
||||
for file_name in palette_files:
|
||||
var result : String = load_palette("user://palettes/" + file_name)
|
||||
if result:
|
||||
Global.palette_option_button.add_item(result)
|
||||
|
@ -109,11 +137,37 @@ func _load_palettes() -> void:
|
|||
Global.palette_option_button.set_item_metadata(index, result)
|
||||
if result == "Default":
|
||||
Global.palette_option_button.select(index)
|
||||
|
||||
dir.open("user://palettes/custom")
|
||||
var custom_palette_files : Array = get_palette_files("user://palettes/custom")
|
||||
|
||||
for file_name in custom_palette_files:
|
||||
var result : String = load_palette("user://palettes/custom/" + file_name)
|
||||
if result:
|
||||
Global.palette_option_button.add_item(result)
|
||||
var index := Global.palette_option_button.get_item_count() - 1
|
||||
Global.palette_option_button.set_item_metadata(index, result)
|
||||
|
||||
for item in Global.palette_option_button.items:
|
||||
print(item)
|
||||
func get_palette_files(path : String) -> Array:
|
||||
var dir := Directory.new()
|
||||
var results = []
|
||||
|
||||
dir.open(path)
|
||||
dir.list_dir_begin()
|
||||
|
||||
while true:
|
||||
var file_name = dir.get_next()
|
||||
if file_name == "":
|
||||
break
|
||||
elif not file_name.begins_with(".") && file_name.to_lower().ends_with("json"):
|
||||
results.append(file_name)
|
||||
|
||||
dir.list_dir_end()
|
||||
|
||||
return results
|
||||
|
||||
func load_palette(path : String) -> String:
|
||||
# Open file for reading
|
||||
var file := File.new()
|
||||
file.open(path, File.READ)
|
||||
|
||||
|
@ -121,7 +175,7 @@ func load_palette(path : String) -> String:
|
|||
var result_json = JSON.parse(text)
|
||||
var result = {}
|
||||
|
||||
var palette_name = null
|
||||
var palette_name = null # Default error condition
|
||||
|
||||
if result_json.error != OK: # If parse has errors
|
||||
print("Error: ", result_json.error)
|
||||
|
@ -129,21 +183,36 @@ func load_palette(path : String) -> String:
|
|||
print("Error String: ", result_json.error_string)
|
||||
else: # If parse OK
|
||||
var data = result_json.result
|
||||
if data.has("name"):
|
||||
if data.has("name"): #If data is 'valid' palette file
|
||||
palette_name = data.name
|
||||
Global.palettes[data.name] = data.colors
|
||||
Global.palettes[data.name] = data
|
||||
|
||||
file.close()
|
||||
|
||||
return palette_name
|
||||
|
||||
func _save_palette(palette : Array, name : String, path : String) -> void:
|
||||
func remove_current_palette() -> void:
|
||||
if Global.palettes[current_palette].has("editable"):
|
||||
if Global.palettes[current_palette].editable:
|
||||
_delete_palette_file(current_palette + ".json")
|
||||
Global.palettes.erase(current_palette)
|
||||
var selected_index := Global.palette_option_button.selected
|
||||
Global.palette_option_button.remove_item(selected_index)
|
||||
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()
|
||||
dir.remove("user://palettes/custom/" + file_name)
|
||||
|
||||
func save_palette(palette_name : String, filename : String) -> void:
|
||||
var palette_data = Global.palettes[palette_name]
|
||||
# Open file for writing
|
||||
var file := File.new()
|
||||
file.open(path, File.WRITE)
|
||||
file.open("user://palettes/custom/" + filename, File.WRITE)
|
||||
|
||||
var data := {}
|
||||
data.name = name
|
||||
data.colors = palette
|
||||
|
||||
file.store_string(JSON.print(data))
|
||||
# Write palette data to file
|
||||
file.store_string(JSON.print(palette_data))
|
||||
file.close()
|
||||
|
|
11
Themes & Styles/StyleBoxes/palette_stylebox_focus.tres
Normal file
11
Themes & Styles/StyleBoxes/palette_stylebox_focus.tres
Normal file
|
@ -0,0 +1,11 @@
|
|||
[gd_resource type="StyleBoxTexture" load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://Assets/Graphics/Palette/palette_button.png" type="Texture" id=1]
|
||||
|
||||
[resource]
|
||||
texture = ExtResource( 1 )
|
||||
region_rect = Rect2( 0, 0, 8, 8 )
|
||||
margin_left = 2.0
|
||||
margin_right = 2.0
|
||||
margin_top = 2.0
|
||||
margin_bottom = 2.0
|
|
@ -33,7 +33,6 @@ _global_script_class_icons={
|
|||
[application]
|
||||
|
||||
config/name="Pixelorama"
|
||||
config/description="A free & open-source 2D sprite editor"
|
||||
run/main_scene="res://Main.tscn"
|
||||
boot_splash/image="res://splash.png"
|
||||
boot_splash/bg_color=Color( 0.145098, 0.145098, 0.164706, 1 )
|
||||
|
@ -188,7 +187,7 @@ shift={
|
|||
|
||||
[locale]
|
||||
|
||||
translations=PoolStringArray( "res://Translations/#Translations.en.translation", "res://Translations/#Translations.el.translation", "res://Translations/#Translations.fr.translation", "res://Translations/#Translations.de.translation", "res://Translations/#Translations.pl.translation" )
|
||||
translations=PoolStringArray( "res://Translations/#Translations.en.translation", "res://Translations/#Translations.el.translation", "res://Translations/#Translations.fr.translation", "res://Translations/#Translations.de.translation" )
|
||||
locale_filter=[ 0, [ ] ]
|
||||
|
||||
[rendering]
|
||||
|
|
Loading…
Reference in a new issue