Merge pull request #118 from Gaarco/master

Add preference options for the Image: default width, default height, default fill color and their translation strings
This commit is contained in:
Manolis Papadeas 2020-01-11 00:21:35 +02:00 committed by GitHub
commit 8b4c42a576
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 284 additions and 28 deletions

View file

@ -5,6 +5,7 @@ var layers := []
var current_layer_index := 0
var location := Vector2.ZERO
var size := Vector2(64, 64)
var fill_color := Color(0, 0, 0, 0)
var frame := 0 setget frame_changed
var frame_button : VBoxContainer
var frame_texture_rect : TextureRect
@ -32,7 +33,17 @@ func _ready() -> void:
# The sprite itself
if layers.empty():
var sprite := Image.new()
if Global.is_default_image:
if Global.config_cache.has_section_key("preferences", "default_width"):
size.x = Global.config_cache.get_value("preferences", "default_width")
if Global.config_cache.has_section_key("preferences", "default_height"):
size.y = Global.config_cache.get_value("preferences", "default_height")
if Global.config_cache.has_section_key("preferences", "default_fill_color"):
fill_color = Global.config_cache.get_value("preferences", "default_fill_color")
Global.is_default_image = !Global.is_default_image
sprite.create(size.x, size.y, false, Image.FORMAT_RGBA8)
sprite.fill(fill_color)
sprite.lock()
var tex := ImageTexture.new()

View file

@ -1,9 +1,13 @@
extends ConfirmationDialog
onready var width_value = $VBoxContainer/OptionsContainer/WidthValue
onready var height_value = $VBoxContainer/OptionsContainer/HeightValue
onready var fill_color_node = $VBoxContainer/OptionsContainer/FillColor
func _on_CreateNewImage_confirmed() -> void:
var width : int = $VBoxContainer/OptionsContainer/WidthValue.value
var height : int = $VBoxContainer/OptionsContainer/HeightValue.value
var fill_color : Color = $VBoxContainer/OptionsContainer/FillColor.color
var width : int = width_value.value
var height : int = height_value.value
var fill_color : Color = fill_color_node.color
Global.control.clear_canvases()
Global.canvas = load("res://Prefabs/Canvas.tscn").instance()
Global.canvas.size = Vector2(width, height).floor()
@ -15,3 +19,8 @@ func _on_CreateNewImage_confirmed() -> void:
Global.canvas.layers[0][0].fill(fill_color)
Global.canvas.layers[0][0].lock()
Global.canvas.update_texture(0)
func _on_CreateNewImage_about_to_show() -> void:
width_value.value = Global.default_image_width
height_value.value = Global.default_image_height
fill_color_node.color = Global.default_fill_color

View file

@ -5,6 +5,11 @@ onready var right_side : VBoxContainer = $HSplitContainer/ScrollContainer/VBoxCo
onready var languages = $HSplitContainer/ScrollContainer/VBoxContainer/Languages
onready var themes = $HSplitContainer/ScrollContainer/VBoxContainer/Themes
onready var grid_guides = $"HSplitContainer/ScrollContainer/VBoxContainer/Grid&Guides"
onready var image = $HSplitContainer/ScrollContainer/VBoxContainer/Image
onready var default_width_value = $HSplitContainer/ScrollContainer/VBoxContainer/Image/ImageOptions/ImageDefaultWidth
onready var default_height_value = $HSplitContainer/ScrollContainer/VBoxContainer/Image/ImageOptions/ImageDefaultHeight
onready var default_fill_color = $HSplitContainer/ScrollContainer/VBoxContainer/Image/ImageOptions/DefaultFillColor
onready var grid_width_value = $"HSplitContainer/ScrollContainer/VBoxContainer/Grid&Guides/GridOptions/GridWidthValue"
onready var grid_height_value = $"HSplitContainer/ScrollContainer/VBoxContainer/Grid&Guides/GridOptions/GridHeightValue"
@ -28,7 +33,6 @@ func _ready() -> void:
change_theme(0)
themes.get_child(1).pressed = true
# Set default values for Grid & Guide options
if Global.config_cache.has_section_key("preferences", "grid_size"):
var grid_size = Global.config_cache.get_value("preferences", "grid_size")
@ -48,12 +52,29 @@ func _ready() -> void:
if guide is Guide:
guide.default_color = Global.guide_color
guide_color.color = Global.guide_color
# Set default values for Image
if Global.config_cache.has_section_key("preferences", "default_width"):
var default_width = Global.config_cache.get_value("preferences", "default_width")
Global.default_image_width = int(default_width)
default_width_value.value = Global.default_image_width
if Global.config_cache.has_section_key("preferences", "default_height"):
var default_height = Global.config_cache.get_value("preferences", "default_height")
Global.default_image_height = int(default_height)
default_height_value.value = Global.default_image_height
if Global.config_cache.has_section_key("preferences", "default_fill_color"):
var fill_color = Global.config_cache.get_value("preferences", "default_fill_color")
Global.default_fill_color = fill_color
default_fill_color.color = Global.default_fill_color
func _on_PreferencesDialog_about_to_show() -> void:
var root := tree.create_item()
var language_button := tree.create_item(root)
var theme_button := tree.create_item(root)
var grid_button := tree.create_item(root)
var image_button := tree.create_item(root)
language_button.set_text(0, " " + tr("Language"))
# We use metadata to avoid being affected by translations
@ -63,6 +84,8 @@ func _on_PreferencesDialog_about_to_show() -> void:
theme_button.set_metadata(0, "Themes")
grid_button.set_text(0, " " + tr("Guides & Grid"))
grid_button.set_metadata(0, "Guides & Grid")
image_button.set_text(0, " " + tr("Image"))
image_button.set_metadata(0, "Image")
func _on_PreferencesDialog_popup_hide() -> void:
@ -78,6 +101,8 @@ func _on_Tree_item_selected() -> void:
themes.visible = true
elif "Guides & Grid" in selected:
grid_guides.visible = true
elif "Image" in selected:
image.visible = true
func _on_Language_pressed(button : Button) -> void:
var index := 0
@ -222,3 +247,19 @@ func _on_GuideColor_color_changed(color : Color) -> void:
guide.default_color = color
Global.config_cache.set_value("preferences", "guide_color", color)
Global.config_cache.save("user://cache.ini")
func _on_ImageDefaultWidth_value_changed(value: float) -> void:
Global.default_image_width = value
Global.config_cache.set_value("preferences", "default_width", value)
Global.config_cache.save("user://cache.ini")
func _on_ImageDefaultHeight_value_changed(value: float) -> void:
Global.default_image_height = value
Global.config_cache.set_value("preferences", "default_height", value)
Global.config_cache.save("user://cache.ini")
func _on_DefaultBackground_color_changed(color: Color) -> void:
Global.default_fill_color = color
Global.config_cache.set_value("preferences", "default_fill_color", color)
Global.config_cache.save("user://cache.ini")

View file

@ -24,6 +24,14 @@ var image_clipboard : Image
# warning-ignore:unused_class_variable
var theme_type := "Dark"
# warning-ignore:unused_class_variable
var is_default_image := true
# warning-ignore:unused_class_variable
var default_image_width := 32
# warning-ignore:unused_class_variable
var default_image_height := 32
# warning-ignore:unused_class_variable
var default_fill_color := Color(0, 0, 0, 0)
# warning-ignore:unused_class_variable
var grid_width := 1
# warning-ignore:unused_class_variable
var grid_height := 1