1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 17:19:50 +00:00

Merge pull request #73 from greusser/palette_updates

Updates to new palette/import button
This commit is contained in:
Overloaded 2019-12-18 17:56:15 +02:00 committed by GitHub
commit 4586853636
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 404 additions and 149 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 B

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/new_swatch_button.png-37e4c5ebd7346f6c29db555ec99ae1f5.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Assets/Graphics/Palette/new_swatch_button.png"
dest_files=[ "res://.import/new_swatch_button.png-37e4c5ebd7346f6c29db555ec99ae1f5.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=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 B

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/new_swatch_button_hover.png-5a3842ea128669b8a5845c570dfb34de.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Assets/Graphics/Palette/new_swatch_button_hover.png"
dest_files=[ "res://.import/new_swatch_button_hover.png-5a3842ea128669b8a5845c570dfb34de.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=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 B

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/remove_swatch_button.png-e55ca10e4a33e81efd86e89e399c8786.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Assets/Graphics/Palette/remove_swatch_button.png"
dest_files=[ "res://.import/remove_swatch_button.png-e55ca10e4a33e81efd86e89e399c8786.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

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 B

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/remove_swatch_button_hover.png-3d8cfbbb669e326875ae170abbd7ecbf.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Assets/Graphics/Palette/remove_swatch_button_hover.png"
dest_files=[ "res://.import/remove_swatch_button_hover.png-3d8cfbbb669e326875ae170abbd7ecbf.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

179
Main.tscn

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,122 @@
[gd_scene load_steps=6 format=2]
[ext_resource path="res://Scripts/EditPalettePopup.gd" type="Script" id=1]
[ext_resource path="res://Assets/Graphics/Palette/new_swatch_button.png" type="Texture" id=2]
[ext_resource path="res://Assets/Graphics/Palette/new_swatch_button_hover.png" type="Texture" id=3]
[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
margin_bottom = 550.0
rect_min_size = Vector2( 600, 550 )
window_title = "Edit Palette"
script = ExtResource( 1 )
[node name="VBoxContainer" type="VBoxContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 10.0
margin_top = 10.0
margin_right = -10.0
margin_bottom = -10.0
size_flags_horizontal = 3
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
margin_right = 580.0
margin_bottom = 478.0
size_flags_vertical = 3
[node name="EditPaletteColorPicker" type="ColorPicker" parent="VBoxContainer/HBoxContainer"]
margin_right = 290.0
margin_bottom = 478.0
[node name="Panel" type="Panel" parent="VBoxContainer/HBoxContainer"]
margin_left = 294.0
margin_right = 556.0
margin_bottom = 478.0
size_flags_horizontal = 3
[node name="EditPaletteGridContainer" type="GridContainer" parent="VBoxContainer/HBoxContainer/Panel"]
anchor_right = 1.0
anchor_bottom = 1.0
size_flags_horizontal = 3
size_flags_vertical = 3
columns = 8
[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer/HBoxContainer"]
margin_left = 560.0
margin_right = 580.0
margin_bottom = 478.0
[node name="AddSwatchButton" type="TextureButton" parent="VBoxContainer/HBoxContainer/VBoxContainer"]
margin_right = 20.0
margin_bottom = 20.0
texture_normal = ExtResource( 2 )
texture_hover = ExtResource( 3 )
[node name="RemoveSwatchButton" type="TextureButton" parent="VBoxContainer/HBoxContainer/VBoxContainer"]
margin_top = 24.0
margin_right = 20.0
margin_bottom = 44.0
texture_normal = ExtResource( 4 )
texture_hover = ExtResource( 5 )
[node name="HBoxContainer3" type="HBoxContainer" parent="VBoxContainer"]
margin_top = 482.0
margin_right = 580.0
margin_bottom = 506.0
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer3"]
margin_top = 5.0
margin_right = 79.0
margin_bottom = 19.0
text = "Color Name:"
[node name="EditPaletteColorNameLineEdit" type="LineEdit" parent="VBoxContainer/HBoxContainer3"]
margin_left = 83.0
margin_right = 580.0
margin_bottom = 24.0
size_flags_horizontal = 3
[node name="HBoxContainer2" type="HBoxContainer" parent="VBoxContainer"]
margin_top = 510.0
margin_right = 580.0
margin_bottom = 530.0
size_flags_horizontal = 3
[node name="SpacerControl" type="Control" parent="VBoxContainer/HBoxContainer2"]
margin_right = 156.0
margin_bottom = 20.0
size_flags_horizontal = 3
[node name="EditPaletteSaveButton" type="Button" parent="VBoxContainer/HBoxContainer2"]
margin_left = 160.0
margin_right = 201.0
margin_bottom = 20.0
text = "Save"
[node name="SpacerControl2" type="Control" parent="VBoxContainer/HBoxContainer2"]
margin_left = 205.0
margin_right = 361.0
margin_bottom = 20.0
size_flags_horizontal = 3
[node name="EditPaletteCancelButton" type="Button" parent="VBoxContainer/HBoxContainer2"]
margin_left = 365.0
margin_right = 419.0
margin_bottom = 20.0
text = "Cancel"
[node name="SpacerControl3" type="Control" parent="VBoxContainer/HBoxContainer2"]
margin_left = 423.0
margin_right = 580.0
margin_bottom = 20.0
size_flags_horizontal = 3
[connection signal="color_changed" from="VBoxContainer/HBoxContainer/EditPaletteColorPicker" to="." method="_on_EditPaletteColorPicker_color_changed"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer/VBoxContainer/AddSwatchButton" to="." method="_on_AddSwatchButton_pressed"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer/VBoxContainer/RemoveSwatchButton" to="." method="_on_RemoveSwatchButton_pressed"]
[connection signal="text_changed" from="VBoxContainer/HBoxContainer3/EditPaletteColorNameLineEdit" to="." method="_on_EditPaletteColorNameLineEdit_text_changed"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer2/EditPaletteSaveButton" to="." method="_on_EditPaletteSaveButton_pressed"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer2/EditPaletteCancelButton" to="." method="_on_EditPaletteCancelButton_pressed"]

View file

@ -0,0 +1,25 @@
[gd_scene format=2]
[node name="NewPaletteDialog" type="ConfirmationDialog"]
margin_right = 200.0
margin_bottom = 70.0
window_title = "Create a new custom palette from existing default?"
[node name="HBoxContainer2" type="HBoxContainer" parent="."]
margin_left = 8.0
margin_top = 8.0
margin_right = 365.0
margin_bottom = 34.0
[node name="Label" type="Label" parent="HBoxContainer2"]
margin_top = 6.0
margin_right = 91.0
margin_bottom = 20.0
text = "Palette Name:"
[node name="NewPaletteNameLineEdit" type="LineEdit" parent="HBoxContainer2"]
margin_left = 95.0
margin_right = 357.0
margin_bottom = 26.0
size_flags_horizontal = 3
expand_to_text_length = true

View file

@ -0,0 +1,13 @@
[gd_scene format=2]
[node name="PaletteImportFileDialog" type="FileDialog"]
anchor_right = 1.0
anchor_bottom = 1.0
rect_min_size = Vector2( 500, 300 )
window_title = "Open a File"
resizable = true
mode = 0
access = 2
filters = PoolStringArray( "*.json ; JavaScript Object Notation" )
current_dir = "D:/GitHub/Pixelorama"
current_path = "D:/GitHub/Pixelorama/"

View file

@ -103,13 +103,13 @@ func _on_EditPaletteCancelButton_pressed() -> void:
pass # Replace with function body.
func _on_EditPaletteColorNameLineEdit_text_changed(new_text) -> void:
if current_swatch > 0 && current_swatch < working_palette.colors.size():
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():
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)

View file

@ -182,7 +182,7 @@ var move_up_layer_button : BaseButton
var move_down_layer_button : BaseButton
var merge_down_layer_button : BaseButton
var add_palette_button : TextureButton
var add_palette_button : MenuButton
var remove_palette_button : TextureButton
var palette_option_button : OptionButton
var edit_palette_button : BaseButton
@ -190,6 +190,7 @@ var palette_container : GridContainer
var edit_palette_popup : WindowDialog
var new_palette_dialog : ConfirmationDialog
var new_palette_name_line_edit : LineEdit
var palette_import_file_dialog : FileDialog
var error_dialog : AcceptDialog
@ -283,6 +284,7 @@ func _ready() -> void:
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")
palette_import_file_dialog = find_node_by_name(root, "PaletteImportFileDialog")
error_dialog = find_node_by_name(root, "ErrorDialog")

View file

@ -101,6 +101,7 @@ func _ready() -> void:
var edit_menu : PopupMenu = Global.edit_menu.get_popup()
view_menu = Global.view_menu.get_popup()
var help_menu : PopupMenu = Global.help_menu.get_popup()
var add_palette_menu : PopupMenu = Global.add_palette_button.get_popup()
var i = 0
for item in file_menu_items.keys():
@ -125,6 +126,7 @@ func _ready() -> void:
edit_menu.connect("id_pressed", self, "edit_menu_id_pressed")
view_menu.connect("id_pressed", self, "view_menu_id_pressed")
help_menu.connect("id_pressed", self, "help_menu_id_pressed")
add_palette_menu.connect("id_pressed", self, "add_palette_menu_id_pressed")
var root = get_tree().get_root()
#Node, left mouse shortcut, right mouse shortcut
@ -1066,6 +1068,18 @@ func _on_RemovePalette_pressed() -> void:
Global.palette_container.remove_current_palette()
pass
func add_palette_menu_id_pressed(id) -> void:
match id:
0: # New Empty Palette
Global.palette_container.on_new_empty_palette()
1: # Import Palette
Global.palette_container.on_import_palette()
pass
func _on_NewPaletteDialog_confirmed() -> void:
Global.palette_container.on_new_palette_confirmed()
pass
func _on_PaletteImportFileDialog_file_selected(path) -> void:
Global.palette_container.on_palette_import_file_selected(path)
pass

View file

@ -1,6 +1,6 @@
extends GridContainer
var palette_button = preload("res://Prefabs/PaletteButton.tscn");
const palette_button = preload("res://Prefabs/PaletteButton.tscn");
var current_palette = "Default"
var from_palette : = {}
@ -34,6 +34,48 @@ func on_palette_select(palette_name : String) -> void:
current_palette = "Default"
_display_palette(Global.palettes["Default"])
func on_new_empty_palette() -> void:
Global.new_palette_dialog.window_title = "Create a new empty palette?"
Global.new_palette_name_line_edit.text = "Custom_Palette"
from_palette = {}
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()
file.open(path, File.READ)
var text = file.get_as_text()
var result_json = JSON.parse(text)
var result = {}
var palette_name = null # Default error condition
if result_json.error != OK: # If parse has errors
print("Error: ", result_json.error)
print("Error Line: ", result_json.error_line)
print("Error String: ", result_json.error_string)
else: # If parse OK
var data = result_json.result
if data.has("name"): #If data is 'valid' palette file
palette_name = data.name
if not Global.palettes.has(palette_name):
Global.palettes[palette_name] = data
Global.palette_option_button.add_item(palette_name)
var index := Global.palette_option_button.get_item_count() - 1
Global.palette_option_button.set_item_metadata(index, palette_name)
Global.palette_option_button.select(index)
on_palette_select(palette_name)
save_palette(palette_name, palette_name + ".json")
else:
Global.error_dialog.set_text("Palette named '" + palette_name + "' already exists");
Global.error_dialog.popup_centered()
file.close()
pass
func on_edit_palette() -> void:
var palette : Dictionary = Global.palettes[current_palette]
@ -44,6 +86,7 @@ func on_edit_palette() -> void:
if create_new_palette:
from_palette = Global.palettes[current_palette]
Global.new_palette_dialog.window_title = "Create a new custom palette from existing default?"
Global.new_palette_name_line_edit.text = "Custom_" + current_palette
Global.new_palette_dialog.popup_centered()
else:

View file

@ -148,6 +148,17 @@ LineEdit/icons/clear = null
LineEdit/styles/focus = null
LineEdit/styles/normal = SubResource( 8 )
LineEdit/styles/read_only = null
MenuButton/colors/font_color = Color( 0.878431, 0.878431, 0.878431, 1 )
MenuButton/colors/font_color_disabled = Color( 1, 1, 1, 0.3 )
MenuButton/colors/font_color_hover = Color( 0.941176, 0.941176, 0.941176, 1 )
MenuButton/colors/font_color_pressed = Color( 1, 1, 1, 1 )
MenuButton/constants/hseparation = 3
MenuButton/fonts/font = null
MenuButton/styles/disabled = null
MenuButton/styles/focus = null
MenuButton/styles/hover = null
MenuButton/styles/normal = null
MenuButton/styles/pressed = null
TabContainer/colors/font_color_bg = Color( 0.690196, 0.690196, 0.690196, 1 )
TabContainer/colors/font_color_disabled = Color( 0.9, 0.9, 0.9, 0.2 )
TabContainer/colors/font_color_fg = Color( 0.941176, 0.941176, 0.941176, 1 )