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

Added another palette option and got the selector button working

This commit is contained in:
CheetoHead 2019-12-15 00:06:04 -05:00
parent 582ee8e790
commit f2e858866e
4 changed files with 59 additions and 13 deletions

View file

@ -0,0 +1,22 @@
{
"name": "BubbleGum16",
"colors" : [
{ "data" : "#FF000000", "name" : "no name" },
{ "data" : "#FF7f0622", "name" : "no name" },
{ "data" : "#FFd62411", "name" : "no name" },
{ "data" : "#FFff8426", "name" : "no name" },
{ "data" : "#FFffd100", "name" : "no name" },
{ "data" : "#FFfafdff", "name" : "no name" },
{ "data" : "#FFff80a4", "name" : "no name" },
{ "data" : "#FFff2674", "name" : "no name" },
{ "data" : "#FF94216a", "name" : "no name" },
{ "data" : "#FF430067", "name" : "no name" },
{ "data" : "#FF234975", "name" : "no name" },
{ "data" : "#FF68aed4", "name" : "no name" },
{ "data" : "#FFbfff3c", "name" : "no name" },
{ "data" : "#FF10d275", "name" : "no name" },
{ "data" : "#FF007899", "name" : "no name" },
{ "data" : "#FF002859", "name" : "no name" },
],
"comments": "by PineTreePizza - https://twitter.com/PineTreePizza"
}

View file

@ -133,14 +133,12 @@ anchor_bottom = 1.0
custom_constants/separation = 0
[node name="MenuContainer" type="Panel" parent="MenuAndUI"]
editor/display_folded = true
margin_right = 1152.0
margin_bottom = 28.0
rect_min_size = Vector2( 0, 28 )
custom_styles/panel = SubResource( 1 )
[node name="MenuItems" type="HBoxContainer" parent="MenuAndUI/MenuContainer"]
editor/display_folded = true
margin_left = 2.0
margin_top = 4.0
margin_right = 1010.0
@ -1766,6 +1764,8 @@ visible = false
[connection signal="pressed" from="MenuAndUI/UI/LayerPanel/LayersAndMisc/LayerVBoxContainer/CenterLayerButtons/LayerButtons/MoveDownLayer" to="." method="change_layer_order" binds= [ -1 ]]
[connection signal="pressed" from="MenuAndUI/UI/LayerPanel/LayersAndMisc/LayerVBoxContainer/CenterLayerButtons/LayerButtons/CloneLayer" to="." method="add_layer" binds= [ false ]]
[connection signal="pressed" from="MenuAndUI/UI/LayerPanel/LayersAndMisc/LayerVBoxContainer/CenterLayerButtons/LayerButtons/MergeDownLayer" to="." method="_on_MergeLayer_pressed"]
[connection signal="pressed" from="MenuAndUI/UI/LayerPanel/LayersAndMisc/PaletteVBoxContainer/PaletteButtons/AddPalette" to="." method="_on_AddPalette_pressed"]
[connection signal="item_selected" from="MenuAndUI/UI/LayerPanel/LayersAndMisc/PaletteVBoxContainer/PaletteButtons/PaletteOptionButton" to="." method="_on_PaletteOptionButton_item_selected"]
[connection signal="toggled" from="SplitScreenButton" to="." method="_on_SplitScreenButton_toggled"]
[connection signal="confirmed" from="CreateNewImage" to="." method="_on_CreateNewImage_confirmed"]
[connection signal="popup_hide" from="CreateNewImage" to="." method="_can_draw_true"]

View file

@ -1034,3 +1034,8 @@ func _exit_tree() -> void:
config_cache.set_value("window", "position", OS.window_position)
config_cache.set_value("window", "size", OS.window_size)
config_cache.save("user://cache.ini")
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)
pass

View file

@ -55,7 +55,7 @@ func _clear_swatches() -> void:
child.queue_free()
pass
func on_palette_select(palette_name) -> void:
func on_palette_select(palette_name : String) -> void:
_clear_swatches()
if Global.palettes.has(palette_name):
_display_palette(Global.palettes[palette_name])
@ -63,7 +63,7 @@ func on_palette_select(palette_name) -> void:
_display_palette(Global.palettes["Default"])
pass
func _display_palette(palette) -> void:
func _display_palette(palette : Array) -> void:
var index := 0
for color_data in palette:
var color = Color(color_data.data)
@ -78,11 +78,9 @@ func _display_palette(palette) -> void:
func on_color_select(index : int) -> void:
var color = Color(Global.palettes[current_palette][index].data)
if Input.is_action_just_released("left_mouse"):
print("left")
Global.left_color_picker.color = color
Global.update_left_custom_brush()
elif Input.is_action_just_released("right_mouse"):
print("right")
Global.right_color_picker.color = color
Global.update_right_custom_brush()
pass
@ -95,6 +93,7 @@ func _load_palettes() -> void:
if not dir.dir_exists("user://palettes"):
dir.make_dir("user://palettes");
dir.copy("res://Assets/Graphics/Palette/default_palette.json","user://palettes/default_palette.json");
dir.copy("res://Assets/Graphics/Palette/bubblegum16.json","user://palettes/bubblegum16.json");
dir.open("user://palettes")
dir.list_dir_begin()
@ -109,12 +108,19 @@ func _load_palettes() -> void:
dir.list_dir_end()
for file_name in files:
var success = _load_palette("user://palettes/" + file_name)
if success:
Global.palette_option_button.add_item(success)
var result : String = load_palette("user://palettes/" + 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)
if result == "Default":
Global.palette_option_button.select(index)
for item in Global.palette_option_button.items:
print(item)
pass
func _load_palette(path) -> String:
func load_palette(path : String) -> String:
var file := File.new()
file.open(path, File.READ)
@ -130,12 +136,25 @@ func _load_palette(path) -> String:
print("Error String: ", result_json.error_string)
else: # If parse OK
var data = result_json.result
palette_name = data.name
Global.palettes[data.name] = data.colors
if data.has("name"):
palette_name = data.name
Global.palettes[data.name] = data.colors
file.close()
return palette_name
func _save_palette(palette, path):
func _save_palette(palette : Array, name : String, path : String):
var file := File.new()
file.open(path, File.WRITE)
var data := {}
data.name = name
data.colors = palette
file.store_string(JSON.print(data))
file.close()
pass
# Called every frame. 'delta' is the elapsed time since the previous frame.