simple composable grid context and grid controller, fiend sprite, godotxel addon
This commit is contained in:
29
addons/Godoxel/dialogs/ChangeCanvasDialog.gd
Normal file
29
addons/Godoxel/dialogs/ChangeCanvasDialog.gd
Normal file
@ -0,0 +1,29 @@
|
||||
extends GEDraggableWindow
|
||||
tool
|
||||
|
||||
|
||||
var width_comp: SpinBox
|
||||
var height_comp: SpinBox
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
connect("on_ok", self, "_on_ConfirmationDialog_confirmed")
|
||||
connect("visibility_changed", self, "_on_ChangeCanvasSize_visibility_changed")
|
||||
|
||||
yield(owner, "ready")
|
||||
|
||||
width_comp = add_component_float("Width (px)", owner.paint_canvas.canvas_width, 1, 5000)
|
||||
height_comp = add_component_float("Height (px)", owner.paint_canvas.canvas_height, 1, 5000)
|
||||
|
||||
|
||||
func _on_ConfirmationDialog_confirmed():
|
||||
var width = width_comp.value
|
||||
var height = height_comp.value
|
||||
print("change canvas size: ", width, " ", height)
|
||||
owner.resize(width, height)
|
||||
|
||||
|
||||
func _on_ChangeCanvasSize_visibility_changed():
|
||||
if visible:
|
||||
width_comp.value = owner.paint_canvas.canvas_width
|
||||
height_comp.value = owner.paint_canvas.canvas_height
|
28
addons/Godoxel/dialogs/ChangeGridSizeDialog.gd
Normal file
28
addons/Godoxel/dialogs/ChangeGridSizeDialog.gd
Normal file
@ -0,0 +1,28 @@
|
||||
extends AcceptDialog
|
||||
tool
|
||||
|
||||
func _ready():
|
||||
yield(owner, "ready")
|
||||
find_node("GridValue").value = owner.paint_canvas.grid_size
|
||||
find_node("BigGridValue").value = owner.paint_canvas.big_grid_size
|
||||
|
||||
|
||||
func _on_ChangeGridSizeDialog_confirmed():
|
||||
var grid_size = find_node("GridValue").value
|
||||
var big_grid_size = find_node("BigGridValue").value
|
||||
owner.paint_canvas.grid_size = grid_size
|
||||
owner.paint_canvas.big_grid_size = big_grid_size
|
||||
|
||||
|
||||
func _on_GridValue_value_changed(value):
|
||||
var grid_size = value
|
||||
owner.paint_canvas.grid_size = grid_size
|
||||
|
||||
|
||||
func _on_BigGridValue_value_changed(value):
|
||||
var big_grid_size = value
|
||||
owner.paint_canvas.big_grid_size = big_grid_size
|
||||
|
||||
|
||||
func _on_ChangeGridSizeDialog_visibility_changed():
|
||||
pass # Replace with function body.
|
20
addons/Godoxel/dialogs/ConfirmationDialog.gd
Normal file
20
addons/Godoxel/dialogs/ConfirmationDialog.gd
Normal file
@ -0,0 +1,20 @@
|
||||
extends ConfirmationDialog
|
||||
tool
|
||||
|
||||
func _ready():
|
||||
yield(owner, "ready")
|
||||
find_node("Width").value = owner.paint_canvas.canvas_width
|
||||
find_node("Height").value = owner.paint_canvas.canvas_height
|
||||
|
||||
|
||||
func _on_ConfirmationDialog_confirmed():
|
||||
var width = find_node("Width").value
|
||||
var height = find_node("Height").value
|
||||
print("change canvas size: ", width, " ", height)
|
||||
owner.paint_canvas.resize(width, height)
|
||||
|
||||
|
||||
func _on_ChangeCanvasSize_visibility_changed():
|
||||
if visible:
|
||||
find_node("Width").value = owner.paint_canvas.canvas_width
|
||||
find_node("Height").value = owner.paint_canvas.canvas_height
|
128
addons/Godoxel/dialogs/DraggableWindow.gd
Normal file
128
addons/Godoxel/dialogs/DraggableWindow.gd
Normal file
@ -0,0 +1,128 @@
|
||||
extends Control
|
||||
class_name GEDraggableWindow
|
||||
tool
|
||||
|
||||
signal on_cancel()
|
||||
signal on_ok()
|
||||
|
||||
export(bool) var show_ok_cancel = true setget set_ok_cancel_visible
|
||||
export(bool) var show_close = true setget set_close_visible
|
||||
export(String) var title = "" setget set_title
|
||||
|
||||
onready var title_bar = find_node("TitleBar")
|
||||
onready var close_button = find_node("CloseButton")
|
||||
onready var title_label = find_node("Title")
|
||||
onready var main = find_node("Main")
|
||||
var _main_child = null
|
||||
|
||||
var dragging = false
|
||||
var mouse_offset = Vector2.ZERO
|
||||
var children = []
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_main_child = main.get_child(0)
|
||||
|
||||
set_title(title)
|
||||
set_ok_cancel_visible(show_ok_cancel)
|
||||
set_close_visible(show_close)
|
||||
|
||||
hide()
|
||||
|
||||
|
||||
func set_title(new_title: String):
|
||||
title = new_title
|
||||
|
||||
if title_label:
|
||||
title_label.text = title
|
||||
|
||||
|
||||
func set_ok_cancel_visible(new_visible: bool):
|
||||
show_ok_cancel = new_visible
|
||||
if _main_child:
|
||||
_main_child.visible = show_ok_cancel
|
||||
|
||||
|
||||
func set_close_visible(new_visible: bool):
|
||||
show_close = new_visible
|
||||
if close_button:
|
||||
close_button.visible = show_close
|
||||
|
||||
|
||||
func _add_child(child, legible_unique_name=false):
|
||||
main.add_child(child, legible_unique_name)
|
||||
_main_child.raise()
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if not dragging or not visible:
|
||||
return
|
||||
rect_global_position = get_global_mouse_position() - mouse_offset
|
||||
if event is InputEventMouseButton:
|
||||
if event.button_index == BUTTON_LEFT and not event.pressed:
|
||||
dragging = false
|
||||
|
||||
|
||||
func _on_ColorRect2_gui_input(event: InputEvent) -> void:
|
||||
if not visible:
|
||||
return
|
||||
|
||||
if event is InputEventMouseButton:
|
||||
if not Rect2(title_bar.rect_global_position, title_bar.rect_size).has_point(
|
||||
get_global_mouse_position()):
|
||||
return
|
||||
if event.button_index == BUTTON_LEFT and event.pressed:
|
||||
dragging = true
|
||||
mouse_offset = get_global_mouse_position() - rect_global_position
|
||||
|
||||
|
||||
|
||||
##################################################
|
||||
# Components
|
||||
##################################################
|
||||
|
||||
func add_component_float(comp_name: String,
|
||||
default: float, from: float = -1, to: float = -1) -> SpinBox:
|
||||
var label = Label.new()
|
||||
label.text = comp_name
|
||||
|
||||
var spinbox = SpinBox.new()
|
||||
spinbox.value = default
|
||||
|
||||
if not is_equal_approx(from, to):
|
||||
spinbox.min_value = from
|
||||
spinbox.max_value = to
|
||||
|
||||
var hbox = HBoxContainer.new()
|
||||
hbox.add_child(label)
|
||||
hbox.add_child(spinbox)
|
||||
label.size_flags_horizontal = Label.SIZE_EXPAND_FILL
|
||||
label.size_flags_vertical = Label.SIZE_EXPAND_FILL
|
||||
spinbox.size_flags_horizontal = Label.SIZE_EXPAND_FILL
|
||||
spinbox.size_flags_vertical = Label.SIZE_EXPAND_FILL
|
||||
|
||||
_add_child(hbox)
|
||||
|
||||
return spinbox
|
||||
|
||||
|
||||
|
||||
##################################################
|
||||
# Signals
|
||||
##################################################
|
||||
|
||||
func _on_Button_pressed() -> void:
|
||||
hide()
|
||||
emit_signal("on_cancel")
|
||||
|
||||
|
||||
func _on_Ok_pressed() -> void:
|
||||
emit_signal("on_ok")
|
||||
hide()
|
||||
|
||||
|
||||
func _on_Cancel_pressed() -> void:
|
||||
hide()
|
||||
emit_signal("on_cancel")
|
||||
|
||||
|
172
addons/Godoxel/dialogs/DraggableWindow.tscn
Normal file
172
addons/Godoxel/dialogs/DraggableWindow.tscn
Normal file
@ -0,0 +1,172 @@
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://addons/Godoxel/dialogs/DraggableWindow.gd" type="Script" id=1]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id=62]
|
||||
bg_color = Color( 0.88, 0.3696, 0.3696, 1 )
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id=63]
|
||||
content_margin_left = 5.0
|
||||
content_margin_right = 5.0
|
||||
content_margin_top = 5.0
|
||||
content_margin_bottom = 5.0
|
||||
|
||||
[node name="Window" type="Control"]
|
||||
visible = false
|
||||
margin_right = 236.0
|
||||
margin_bottom = 136.0
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": true
|
||||
}
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="."]
|
||||
anchor_right = 1.0
|
||||
rect_min_size = Vector2( 0, 24 )
|
||||
size_flags_horizontal = 3
|
||||
color = Color( 0.12549, 0.141176, 0.192157, 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="VBoxContainer" type="HBoxContainer" parent="ColorRect"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
custom_constants/separation = 0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="TitleBar" type="Control" parent="ColorRect/VBoxContainer"]
|
||||
margin_right = 212.0
|
||||
margin_bottom = 24.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="Title" type="Label" parent="ColorRect/VBoxContainer/TitleBar"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
align = 1
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="CloseButton" type="Button" parent="ColorRect/VBoxContainer"]
|
||||
margin_left = 212.0
|
||||
margin_right = 236.0
|
||||
margin_bottom = 24.0
|
||||
rect_min_size = Vector2( 24, 24 )
|
||||
custom_styles/normal = SubResource( 62 )
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="ColorRect/VBoxContainer/CloseButton"]
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
margin_left = -5.0
|
||||
margin_top = -6.0
|
||||
margin_right = 11.0
|
||||
margin_bottom = -5.0
|
||||
rect_rotation = 45.0
|
||||
mouse_filter = 2
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="ColorRect2" type="ColorRect" parent="ColorRect/VBoxContainer/CloseButton"]
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
margin_left = -6.0
|
||||
margin_top = 5.0
|
||||
margin_right = 10.0
|
||||
margin_bottom = 6.0
|
||||
rect_rotation = -45.0
|
||||
mouse_filter = 2
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="ColorRect2" type="ColorRect" parent="."]
|
||||
show_behind_parent = true
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
color = Color( 0.2, 0.227451, 0.309804, 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="ColorRect2"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_left = 5.0
|
||||
margin_top = 5.0
|
||||
margin_right = -5.0
|
||||
margin_bottom = -5.0
|
||||
mouse_filter = 2
|
||||
color = Color( 0.234, 0.2655, 0.36, 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Main" type="VBoxContainer" parent="ColorRect2"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_left = 5.0
|
||||
margin_top = 5.0
|
||||
margin_right = -5.0
|
||||
margin_bottom = -5.0
|
||||
mouse_filter = 2
|
||||
alignment = 2
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="ColorRect2/Main"]
|
||||
margin_top = 98.0
|
||||
margin_right = 226.0
|
||||
margin_bottom = 126.0
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="ColorRect2/Main/VBoxContainer"]
|
||||
margin_right = 226.0
|
||||
margin_bottom = 24.0
|
||||
mouse_filter = 2
|
||||
alignment = 1
|
||||
|
||||
[node name="Ok" type="Button" parent="ColorRect2/Main/VBoxContainer/HBoxContainer"]
|
||||
margin_left = 58.0
|
||||
margin_right = 88.0
|
||||
margin_bottom = 24.0
|
||||
rect_min_size = Vector2( 30, 19 )
|
||||
custom_styles/normal = SubResource( 63 )
|
||||
text = "Ok"
|
||||
|
||||
[node name="Control" type="Control" parent="ColorRect2/Main/VBoxContainer/HBoxContainer"]
|
||||
margin_left = 92.0
|
||||
margin_right = 112.0
|
||||
margin_bottom = 24.0
|
||||
rect_min_size = Vector2( 20, 0 )
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="Cancel" type="Button" parent="ColorRect2/Main/VBoxContainer/HBoxContainer"]
|
||||
margin_left = 116.0
|
||||
margin_right = 168.0
|
||||
margin_bottom = 24.0
|
||||
rect_min_size = Vector2( 30, 19 )
|
||||
custom_styles/normal = SubResource( 63 )
|
||||
text = "Cancel"
|
||||
|
||||
[node name="Control" type="Control" parent="ColorRect2/Main/VBoxContainer"]
|
||||
margin_top = 28.0
|
||||
margin_right = 226.0
|
||||
margin_bottom = 28.0
|
||||
mouse_filter = 2
|
||||
|
||||
[connection signal="pressed" from="ColorRect/VBoxContainer/CloseButton" to="." method="_on_Button_pressed"]
|
||||
[connection signal="gui_input" from="ColorRect2" to="." method="_on_ColorRect2_gui_input"]
|
||||
[connection signal="pressed" from="ColorRect2/Main/VBoxContainer/HBoxContainer/Ok" to="." method="_on_Ok_pressed"]
|
||||
[connection signal="pressed" from="ColorRect2/Main/VBoxContainer/HBoxContainer/Cancel" to="." method="_on_Cancel_pressed"]
|
112
addons/Godoxel/dialogs/LoadFileDialog.gd
Normal file
112
addons/Godoxel/dialogs/LoadFileDialog.gd
Normal file
@ -0,0 +1,112 @@
|
||||
tool
|
||||
extends FileDialog
|
||||
|
||||
|
||||
enum LoadMode {
|
||||
IMPORT_IMAGE,
|
||||
LOAD_PROJECT,
|
||||
}
|
||||
|
||||
var canvas: GECanvas
|
||||
var file_path = ""
|
||||
var load_mode = LoadMode.IMPORT_IMAGE
|
||||
|
||||
|
||||
func _ready():
|
||||
get_line_edit().connect("text_entered", self, "_on_LineEdit_text_entered")
|
||||
invalidate()
|
||||
clear_filters()
|
||||
add_filter("*.png ; PNG Images")
|
||||
|
||||
|
||||
func _on_LineEdit_text_entered(_text):
|
||||
return
|
||||
# print(_text)
|
||||
#load_img()
|
||||
# print("hsadfasd")
|
||||
|
||||
|
||||
|
||||
#######################################################
|
||||
# dialogs
|
||||
#######################################################
|
||||
|
||||
func open_load_project():
|
||||
invalidate()
|
||||
clear_filters()
|
||||
add_filter("*.godoxel ; Godot - Godoxel")
|
||||
load_mode = LoadMode.LOAD_PROJECT
|
||||
show()
|
||||
|
||||
|
||||
func open_import_image():
|
||||
invalidate()
|
||||
clear_filters()
|
||||
add_filter("*.png ; PNG Images")
|
||||
load_mode = LoadMode.IMPORT_IMAGE
|
||||
show()
|
||||
|
||||
|
||||
|
||||
#######################################################
|
||||
# dialogs
|
||||
#######################################################
|
||||
|
||||
func _on_LoadFileDialog_file_selected(path):
|
||||
file_path = path
|
||||
|
||||
match load_mode:
|
||||
LoadMode.IMPORT_IMAGE:
|
||||
import_image()
|
||||
LoadMode.LOAD_PROJECT:
|
||||
load_project()
|
||||
|
||||
|
||||
func load_project():
|
||||
var file = File.new()
|
||||
file.open(file_path, File.READ)
|
||||
var data = JSON.parse(file.get_as_text()).result
|
||||
file.close()
|
||||
|
||||
owner.load_project(data)
|
||||
|
||||
|
||||
func import_image():
|
||||
var image = Image.new()
|
||||
if image.load(file_path) != OK:
|
||||
print("couldn't load image!")
|
||||
return
|
||||
|
||||
var image_data = image.get_data()
|
||||
var layer: GELayer = owner.add_new_layer()
|
||||
|
||||
var width = image.get_width()
|
||||
var height = image.get_height()
|
||||
|
||||
if owner.paint_canvas.canvas_width < width:
|
||||
owner.resize(width, owner.paint_canvas.canvas_height)
|
||||
|
||||
if owner.paint_canvas.canvas_height < height:
|
||||
owner.resize(owner.paint_canvas.canvas_width, height)
|
||||
|
||||
for i in range(image_data.size() / 4):
|
||||
var color = Color(image_data[i*4] / 255.0, image_data[i*4+1] / 255.0, image_data[i*4+2] / 255.0, image_data[i*4+3] / 255.0)
|
||||
var pos = GEUtils.to_2D(i, image.get_width())
|
||||
if pos.x > layer.layer_width:
|
||||
continue
|
||||
|
||||
layer.set_pixel(pos.x, pos.y, color)
|
||||
layer.update_texture()
|
||||
owner._update_frame_button_previews()
|
||||
|
||||
|
||||
func _on_LoadFileDialog_confirmed():
|
||||
return
|
||||
|
||||
|
||||
func _on_LoadFileDialog_about_to_show():
|
||||
invalidate()
|
||||
|
||||
|
||||
func _on_LoadFileDialog_visibility_changed():
|
||||
invalidate()
|
22
addons/Godoxel/dialogs/LoadFileDialog.tscn
Normal file
22
addons/Godoxel/dialogs/LoadFileDialog.tscn
Normal file
@ -0,0 +1,22 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[sub_resource type="GDScript" id=1]
|
||||
script/source = "extends ConfirmationDialog
|
||||
|
||||
func _ready():
|
||||
get_ok().connect(\"pressed\", self, \"hide\")
|
||||
get_cancel().connect(\"pressed\", self, \"hide\")
|
||||
|
||||
|
||||
|
||||
"
|
||||
|
||||
[node name="LoadFileDialog" type="FileDialog"]
|
||||
margin_right = 604.0
|
||||
margin_bottom = 367.0
|
||||
window_title = "Open a File"
|
||||
mode = 0
|
||||
access = 2
|
||||
current_dir = "/Projects/BitBucket/GraphicsEditor"
|
||||
current_path = "/Projects/BitBucket/GraphicsEditor/"
|
||||
script = SubResource( 1 )
|
Reference in New Issue
Block a user