1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-02-23 22:13:14 +00:00

experimental support for texture changes

This commit is contained in:
Variable 2024-08-31 21:44:01 +05:00
parent a7f1486ec3
commit a4bcd6c5d6
4 changed files with 62 additions and 2 deletions

View file

@ -132,7 +132,18 @@ var config_cache := ConfigFile.new()
var loaded_locales: PackedStringArray = LANGUAGES_DICT.keys() var loaded_locales: PackedStringArray = LANGUAGES_DICT.keys()
var projects: Array[Project] = [] ## Array of currently open projects. var projects: Array[Project] = [] ## Array of currently open projects.
var current_project: Project ## The project that currently in focus. var current_project: Project: ## The project that currently in focus.
set(value):
current_project = value
if top_menu_container.file_menu:
if current_project is ResourceProject:
top_menu_container.file_menu.set_item_disabled(FileMenu.SAVE_AS, true)
top_menu_container.file_menu.set_item_disabled(FileMenu.EXPORT, true)
top_menu_container.file_menu.set_item_disabled(FileMenu.EXPORT_AS, true)
else:
top_menu_container.file_menu.set_item_disabled(FileMenu.SAVE_AS, false)
top_menu_container.file_menu.set_item_disabled(FileMenu.EXPORT, false)
top_menu_container.file_menu.set_item_disabled(FileMenu.EXPORT_AS, false)
## The index of project that is currently in focus. ## The index of project that is currently in focus.
var current_project_index := 0: var current_project_index := 0:
set(value): set(value):
@ -693,6 +704,15 @@ func _init() -> void:
) )
func modify_texture_resource(image: Image, resource_name: StringName, update_callable: Callable):
var resource_proj = ResourceProject.new([], resource_name, image.get_size())
resource_proj.layers.append(PixelLayer.new(resource_proj))
resource_proj.frames.append(resource_proj.new_empty_frame())
resource_proj.frames[0].cels[0].set_content(image)
resource_proj.resource_updated.connect(update_callable)
Global.projects.append(resource_proj)
func _ready() -> void: func _ready() -> void:
_initialize_keychain() _initialize_keychain()
default_width = config_cache.get_value("preferences", "default_width", default_width) default_width = config_cache.get_value("preferences", "default_width", default_width)

View file

@ -0,0 +1,9 @@
class_name ResourceProject
extends Project
signal resource_updated
func _init(_frames: Array[Frame] = [], _name := tr("untitled"), _size := Vector2i(64, 64)) -> void:
super._init(_frames, _name + " (Texture Resource)", _size)

View file

@ -212,7 +212,7 @@ static func create_ui_for_shader_uniforms(
func(_gradient, _cc): value_changed.call(gradient_edit.texture, u_name) func(_gradient, _cc): value_changed.call(gradient_edit.texture, u_name)
) )
hbox.add_child(gradient_edit) hbox.add_child(gradient_edit)
else: else: ## Simple texture
var file_dialog := FileDialog.new() var file_dialog := FileDialog.new()
file_dialog.file_mode = FileDialog.FILE_MODE_OPEN_FILE file_dialog.file_mode = FileDialog.FILE_MODE_OPEN_FILE
file_dialog.access = FileDialog.ACCESS_FILESYSTEM file_dialog.access = FileDialog.ACCESS_FILESYSTEM
@ -224,7 +224,19 @@ static func create_ui_for_shader_uniforms(
button.pressed.connect(file_dialog.popup_centered) button.pressed.connect(file_dialog.popup_centered)
button.size_flags_horizontal = Control.SIZE_EXPAND_FILL button.size_flags_horizontal = Control.SIZE_EXPAND_FILL
button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
var mod_button := Button.new()
mod_button.text = "Modify"
mod_button.pressed.connect(
func(): Global.modify_texture_resource(
_get_loaded_texture(params, u_name),
u_name,
_shader_update_texture.bind(value_changed, u_name)
)
)
mod_button.size_flags_horizontal = Control.SIZE_EXPAND_FILL
mod_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
hbox.add_child(button) hbox.add_child(button)
hbox.add_child(mod_button)
parent_node.add_child(file_dialog) parent_node.add_child(file_dialog)
parent_node.add_child(hbox) parent_node.add_child(hbox)
@ -334,3 +346,20 @@ static func _shader_update_palette_texture(
palette: Palette, value_changed: Callable, parameter_name: String palette: Palette, value_changed: Callable, parameter_name: String
) -> void: ) -> void:
value_changed.call(ImageTexture.create_from_image(palette.convert_to_image()), parameter_name) value_changed.call(ImageTexture.create_from_image(palette.convert_to_image()), parameter_name)
static func _get_loaded_texture(
params: Dictionary, parameter_name: String
) -> Image:
if parameter_name in params:
if params[parameter_name] is ImageTexture:
return params[parameter_name].get_image()
var image = Image.create_empty(64, 64, false, Image.FORMAT_RGBA8)
return image
static func _shader_update_texture(
resource_proj: ResourceProject, value_changed: Callable, parameter_name: String
) -> void:
var image = resource_proj.frames[0].cels[0].get_content()
value_changed.call(ImageTexture.create_from_image(image), parameter_name)

View file

@ -545,6 +545,8 @@ func _on_open_last_project_file_menu_option_pressed() -> void:
func _save_project_file() -> void: func _save_project_file() -> void:
if Global.current_project is ResourceProject:
Global.current_project.resource_updated.emit(Global.current_project)
var path: String = Global.current_project.save_path var path: String = Global.current_project.save_path
if path == "": if path == "":
Global.control.show_save_dialog() Global.control.show_save_dialog()