2019-12-29 22:24:37 +00:00
|
|
|
extends ConfirmationDialog
|
|
|
|
|
2020-04-03 00:12:42 +00:00
|
|
|
onready var templates_options = $VBoxContainer/OptionsContainer/TemplatesOptions
|
|
|
|
onready var ratio_box = $VBoxContainer/OptionsContainer/RatioCheckBox
|
2020-01-10 19:24:07 +00:00
|
|
|
onready var width_value = $VBoxContainer/OptionsContainer/WidthValue
|
|
|
|
onready var height_value = $VBoxContainer/OptionsContainer/HeightValue
|
2020-01-10 22:11:36 +00:00
|
|
|
onready var fill_color_node = $VBoxContainer/OptionsContainer/FillColor
|
2020-01-10 19:24:07 +00:00
|
|
|
|
2020-04-10 18:19:44 +00:00
|
|
|
onready var size_value = Vector2()
|
|
|
|
|
2020-04-11 02:36:51 +00:00
|
|
|
# Template Id identifier
|
2020-04-03 00:12:42 +00:00
|
|
|
enum Templates {
|
|
|
|
TDefault = 0,
|
|
|
|
T16 = 1,
|
|
|
|
T32 = 2,
|
|
|
|
T64 = 3,
|
|
|
|
T128 = 4,
|
2020-04-10 18:19:44 +00:00
|
|
|
GB = 5,
|
|
|
|
GBA = 6,
|
|
|
|
NES_NTSC = 7,
|
|
|
|
NES_PAL = 8,
|
|
|
|
SNES_NTSC = 9,
|
|
|
|
SNES_PAL = 10
|
2020-04-03 00:12:42 +00:00
|
|
|
}
|
2020-04-11 02:36:51 +00:00
|
|
|
# Template actual value, without Default because we get it from Global
|
2020-04-10 18:19:44 +00:00
|
|
|
var TResolutions = {
|
|
|
|
Templates.T16: Vector2(16,16),
|
|
|
|
Templates.T32: Vector2(32,32),
|
|
|
|
Templates.T64: Vector2(64,64),
|
|
|
|
Templates.T128: Vector2(128,128),
|
2020-04-11 02:36:51 +00:00
|
|
|
|
2020-04-10 18:19:44 +00:00
|
|
|
Templates.GB: Vector2(160,144),
|
|
|
|
Templates.GBA: Vector2(240,160),
|
|
|
|
Templates.NES_NTSC: Vector2(256,224),
|
|
|
|
Templates.NES_PAL: Vector2(256,240),
|
|
|
|
Templates.SNES_NTSC: Vector2(512,448),
|
|
|
|
Templates.SNES_PAL: Vector2(512,480),
|
2020-04-03 00:12:42 +00:00
|
|
|
}
|
|
|
|
|
2020-04-10 18:19:44 +00:00
|
|
|
var TStrings ={
|
|
|
|
Templates.T16: "",
|
|
|
|
Templates.T32: "",
|
|
|
|
Templates.T64: "",
|
|
|
|
Templates.T128: "",
|
2020-04-11 02:36:51 +00:00
|
|
|
|
2020-04-10 18:19:44 +00:00
|
|
|
Templates.GB: "GB",
|
|
|
|
Templates.GBA: "GBA",
|
|
|
|
Templates.NES_NTSC: "NES (NTSC)",
|
|
|
|
Templates.NES_PAL: "NES (PAL)",
|
|
|
|
Templates.SNES_NTSC: "SNES (NTSC)",
|
|
|
|
Templates.SNES_PAL: "SNES (PAL)"
|
|
|
|
}
|
|
|
|
|
2020-04-03 00:12:42 +00:00
|
|
|
func _ready() -> void:
|
|
|
|
ratio_box.connect("pressed", self, "_on_RatioCheckBox_toggled", [ratio_box.pressed])
|
|
|
|
templates_options.connect("item_selected", self, "_on_TemplatesOptions_item_selected")
|
2020-04-11 02:36:51 +00:00
|
|
|
|
2020-04-10 18:19:44 +00:00
|
|
|
_CreateOptionList()
|
|
|
|
|
|
|
|
func _CreateOptionList():
|
|
|
|
for i in Templates.values():
|
|
|
|
if i > 0:
|
|
|
|
if TStrings[i] != "":
|
|
|
|
templates_options.add_item("{width}x{height} - {name}".format({"width":TResolutions[i].x, "height":TResolutions[i].y, "name":TStrings[i]}), i)
|
|
|
|
else:
|
|
|
|
templates_options.add_item("{width}x{height}".format({"width":TResolutions[i].x, "height":TResolutions[i].y}), i)
|
2020-04-03 00:25:56 +00:00
|
|
|
|
2019-12-29 22:24:37 +00:00
|
|
|
func _on_CreateNewImage_confirmed() -> void:
|
2020-01-10 22:11:36 +00:00
|
|
|
var width : int = width_value.value
|
|
|
|
var height : int = height_value.value
|
|
|
|
var fill_color : Color = fill_color_node.color
|
2020-04-09 22:06:24 +00:00
|
|
|
Global.clear_canvases()
|
2020-03-10 23:07:35 +00:00
|
|
|
Global.layers.clear()
|
2020-03-14 19:40:10 +00:00
|
|
|
# Store [Layer name (0), Layer visibility boolean (1), Layer lock boolean (2), Frame container (3),
|
|
|
|
# will new frames be linked boolean (4), Array of linked frames (5)]
|
|
|
|
Global.layers.append([tr("Layer") + " 0", true, false, HBoxContainer.new(), false, []])
|
2019-12-29 22:24:37 +00:00
|
|
|
Global.canvas = load("res://Prefabs/Canvas.tscn").instance()
|
|
|
|
Global.canvas.size = Vector2(width, height).floor()
|
|
|
|
|
|
|
|
Global.canvases.append(Global.canvas)
|
|
|
|
Global.canvas_parent.add_child(Global.canvas)
|
2020-04-11 02:36:51 +00:00
|
|
|
Global.current_layer = 0
|
2020-03-10 23:07:35 +00:00
|
|
|
Global.canvases = Global.canvases # To trigger Global.canvases_changed()
|
2019-12-29 22:24:37 +00:00
|
|
|
Global.current_frame = 0
|
2020-03-10 23:07:35 +00:00
|
|
|
Global.layers = Global.layers # To trigger Global.layers_changed()
|
2020-04-02 12:28:47 +00:00
|
|
|
Global.saved = true
|
2019-12-29 22:24:37 +00:00
|
|
|
if fill_color.a > 0:
|
|
|
|
Global.canvas.layers[0][0].fill(fill_color)
|
|
|
|
Global.canvas.layers[0][0].lock()
|
|
|
|
Global.canvas.update_texture(0)
|
2020-01-10 19:24:07 +00:00
|
|
|
|
|
|
|
func _on_CreateNewImage_about_to_show() -> void:
|
|
|
|
width_value.value = Global.default_image_width
|
|
|
|
height_value.value = Global.default_image_height
|
2020-01-10 22:11:36 +00:00
|
|
|
fill_color_node.color = Global.default_fill_color
|
2020-04-03 00:12:42 +00:00
|
|
|
templates_options.selected = Templates.TDefault
|
2020-04-03 00:25:56 +00:00
|
|
|
ratio_box.pressed = false
|
2020-04-03 00:12:42 +00:00
|
|
|
for spin_box in [width_value, height_value]:
|
|
|
|
if spin_box.is_connected("value_changed", self, "_on_SizeValue_value_changed"):
|
|
|
|
spin_box.disconnect("value_changed", self, "_on_SizeValue_value_changed")
|
|
|
|
|
|
|
|
var aspect_ratio: float
|
|
|
|
|
|
|
|
# warning-ignore:unused_argument
|
|
|
|
func _on_RatioCheckBox_toggled(button_pressed: bool) -> void:
|
|
|
|
aspect_ratio = width_value.value / height_value.value
|
|
|
|
for spin_box in [width_value, height_value]:
|
|
|
|
if spin_box.is_connected("value_changed", self, "_on_SizeValue_value_changed"):
|
|
|
|
spin_box.disconnect("value_changed", self, "_on_SizeValue_value_changed")
|
|
|
|
else:
|
|
|
|
spin_box.connect("value_changed", self, "_on_SizeValue_value_changed")
|
|
|
|
|
|
|
|
func _on_SizeValue_value_changed(value: float) -> void:
|
|
|
|
if width_value.value == value:
|
|
|
|
height_value.value = width_value.value / aspect_ratio
|
|
|
|
if height_value.value == value:
|
|
|
|
width_value.value = height_value.value * aspect_ratio
|
|
|
|
|
|
|
|
func _on_TemplatesOptions_item_selected(id: int) -> void:
|
2020-04-10 18:19:44 +00:00
|
|
|
if id != Templates.TDefault:
|
|
|
|
size_value = TResolutions[id]
|
|
|
|
else:
|
|
|
|
width_value.value = Global.default_image_width
|
|
|
|
height_value.value = Global.default_image_height
|
2020-04-11 02:36:51 +00:00
|
|
|
|
2020-04-10 18:19:44 +00:00
|
|
|
width_value.value = size_value.x
|
|
|
|
height_value.value = size_value.y
|