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

Change tilemask loading (#731)

* Load tilemask from current frame...

...instead of selecting from FileDialog

* Delete the FileDialog

* Added the reset button

every good loader needs a reset button, Cheers!!!
This commit is contained in:
Variable 2022-08-03 02:42:54 +05:00 committed by GitHub
parent 8803acd105
commit 57387f3530
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 71 deletions

View file

@ -7,6 +7,7 @@ onready var y_basis_y_spinbox: SpinBox = $VBoxContainer/HBoxContainer/OptionsCon
onready var preview_rect: Control = $VBoxContainer/AspectRatioContainer/Preview onready var preview_rect: Control = $VBoxContainer/AspectRatioContainer/Preview
onready var tile_mode: Node2D = $VBoxContainer/AspectRatioContainer/Preview/TileMode onready var tile_mode: Node2D = $VBoxContainer/AspectRatioContainer/Preview/TileMode
onready var load_button: Button = $VBoxContainer/HBoxContainer/Mask/LoadMask onready var load_button: Button = $VBoxContainer/HBoxContainer/Mask/LoadMask
onready var reset_mask: Button = $VBoxContainer/HBoxContainer/Mask/ResetMask
onready var mask_hint: TextureRect = $VBoxContainer/HBoxContainer/Mask/MaskHint onready var mask_hint: TextureRect = $VBoxContainer/HBoxContainer/Mask/MaskHint
@ -37,12 +38,10 @@ func _on_TileModeOffsetsDialog_about_to_show() -> void:
$VBoxContainer/HBoxContainer/OptionsContainer/XBasisXLabel.visible = false $VBoxContainer/HBoxContainer/OptionsContainer/XBasisXLabel.visible = false
$VBoxContainer/HBoxContainer/OptionsContainer/XBasisYLabel.visible = false $VBoxContainer/HBoxContainer/OptionsContainer/XBasisYLabel.visible = false
load_button.text = "Load Mask" reset_mask.disabled = true
if Global.current_project.tiles.has_mask: if Global.current_project.tiles.has_mask:
load_button.text = "Loaded" reset_mask.disabled = false
var tex := ImageTexture.new()
tex.create_from_image(Global.current_project.tiles.tile_mask)
mask_hint.texture = tex
update_preview() update_preview()
@ -98,6 +97,11 @@ func update_preview() -> void:
tile_mode.update() tile_mode.update()
preview_rect.get_node("TransparentChecker").rect_size = preview_rect.rect_size preview_rect.get_node("TransparentChecker").rect_size = preview_rect.rect_size
# Also update the tile_mask preview
var tex := ImageTexture.new()
tex.create_from_image(Global.current_project.tiles.tile_mask)
mask_hint.texture = tex
func _on_TileModeOffsetsDialog_popup_hide() -> void: func _on_TileModeOffsetsDialog_popup_hide() -> void:
Global.dialog_open(false) Global.dialog_open(false)
@ -120,44 +124,28 @@ func _on_Reset_pressed():
func _on_LoadMask_pressed() -> void: func _on_LoadMask_pressed() -> void:
if OS.get_name() == "HTML5": var frame_idx = Global.current_project.current_frame
Html5FileExchange.connect("image_loaded", self, "_on_html_image_loaded") var current_frame = Global.current_project.frames[frame_idx]
Html5FileExchange.load_image(false) var tiles = Global.current_project.tiles
else: var size = tiles.tile_size
$FileDialog.current_dir = Global.current_project.directory_path
$FileDialog.popup_centered()
func _on_html_image_loaded(image_info: Dictionary):
if image_info.has("image"):
load_mask(image_info.image)
Html5FileExchange.disconnect("image_loaded", self, "_on_html_image_loaded")
func _on_FileDialog_file_selected(path: String) -> void:
var image := Image.new() var image := Image.new()
var err := image.load(path) image.create(size.x, size.y, false, Image.FORMAT_RGBA8)
if err != OK: # An error occured Export.blend_layers(image, current_frame)
var file_name: String = path.get_file() if image.get_used_rect().size == Vector2.ZERO:
Global.error_dialog.set_text( reset_mask.disabled = true
tr("Can't load file '%s'.\nError code: %s") % [file_name, str(err)] tiles.reset_mask()
) else:
Global.error_dialog.popup_centered() load_mask(image)
Global.dialog_open(true) update_preview()
return
if image.get_size() != Global.current_project.size:
Global.error_dialog.set_text(tr("The mask must have the same size as the project"))
Global.error_dialog.popup_centered()
Global.dialog_open(true)
return
load_mask(image)
func load_mask(image: Image): func load_mask(image: Image):
load_button.text = "Loaded" reset_mask.disabled = false
Global.current_project.tiles.tile_mask = image Global.current_project.tiles.tile_mask = image
Global.current_project.tiles.has_mask = true Global.current_project.tiles.has_mask = true
var tex := ImageTexture.new()
tex.create_from_image(Global.current_project.tiles.tile_mask)
mask_hint.texture = tex func _on_ResetMask_pressed() -> void:
reset_mask.disabled = true
Global.current_project.tiles.reset_mask()
update_preview()

View file

@ -8,9 +8,10 @@
blend_mode = 4 blend_mode = 4
[node name="TileModeOffsetsDialog" type="ConfirmationDialog"] [node name="TileModeOffsetsDialog" type="ConfirmationDialog"]
margin_right = 216.0 visible = true
margin_bottom = 374.0 margin_right = 301.0
rect_min_size = Vector2( 172, 60.2 ) margin_bottom = 422.0
rect_min_size = Vector2( 172, 422 )
window_title = "Tile Mode Offsets" window_title = "Tile Mode Offsets"
resizable = true resizable = true
script = ExtResource( 3 ) script = ExtResource( 3 )
@ -19,7 +20,7 @@ script = ExtResource( 3 )
margin_left = 8.0 margin_left = 8.0
margin_top = 8.0 margin_top = 8.0
margin_right = 293.0 margin_right = 293.0
margin_bottom = 362.0 margin_bottom = 386.0
[node name="TileModeOffsets" type="Label" parent="VBoxContainer"] [node name="TileModeOffsets" type="Label" parent="VBoxContainer"]
margin_right = 285.0 margin_right = 285.0
@ -29,11 +30,11 @@ text = "Tile Mode Offsets"
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"] [node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
margin_top = 18.0 margin_top = 18.0
margin_right = 285.0 margin_right = 285.0
margin_bottom = 150.0 margin_bottom = 174.0
[node name="OptionsContainer" type="GridContainer" parent="VBoxContainer/HBoxContainer"] [node name="OptionsContainer" type="GridContainer" parent="VBoxContainer/HBoxContainer"]
margin_right = 137.0 margin_right = 137.0
margin_bottom = 132.0 margin_bottom = 156.0
custom_constants/vseparation = 4 custom_constants/vseparation = 4
custom_constants/hseparation = 2 custom_constants/hseparation = 2
columns = 2 columns = 2
@ -110,12 +111,12 @@ text = "Reset"
[node name="VSeparator" type="VSeparator" parent="VBoxContainer/HBoxContainer"] [node name="VSeparator" type="VSeparator" parent="VBoxContainer/HBoxContainer"]
margin_left = 141.0 margin_left = 141.0
margin_right = 145.0 margin_right = 145.0
margin_bottom = 132.0 margin_bottom = 156.0
[node name="Mask" type="VBoxContainer" parent="VBoxContainer/HBoxContainer"] [node name="Mask" type="VBoxContainer" parent="VBoxContainer/HBoxContainer"]
margin_left = 149.0 margin_left = 149.0
margin_right = 285.0 margin_right = 285.0
margin_bottom = 132.0 margin_bottom = 156.0
size_flags_horizontal = 3 size_flags_horizontal = 3
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer/Mask"] [node name="Label" type="Label" parent="VBoxContainer/HBoxContainer/Mask"]
@ -134,6 +135,8 @@ margin_top = 26.0
margin_right = 136.0 margin_right = 136.0
margin_bottom = 100.0 margin_bottom = 100.0
rect_min_size = Vector2( 136, 74 ) rect_min_size = Vector2( 136, 74 )
hint_tooltip = "Mask will only allow the drawing to remain within it's bounds
(Used for custom tiles)"
size_flags_vertical = 3 size_flags_vertical = 3
expand = true expand = true
stretch_mode = 6 stretch_mode = 6
@ -148,15 +151,24 @@ margin_top = 112.0
margin_right = 136.0 margin_right = 136.0
margin_bottom = 132.0 margin_bottom = 132.0
rect_min_size = Vector2( 100, 0 ) rect_min_size = Vector2( 100, 0 )
hint_tooltip = "Mask will only allow the drawing to remain within it's bounds hint_tooltip = "Create the Tile Mask from Current Frame"
(Used for custom tiles)" text = "Current Frame?"
text = "Load Mask" clip_text = true
[node name="ResetMask" type="Button" parent="VBoxContainer/HBoxContainer/Mask"]
margin_top = 136.0
margin_right = 136.0
margin_bottom = 156.0
rect_min_size = Vector2( 100, 0 )
hint_tooltip = "Create the Tile Mask from Current Frame"
disabled = true
text = "Reset Mask"
clip_text = true clip_text = true
[node name="AspectRatioContainer" type="AspectRatioContainer" parent="VBoxContainer"] [node name="AspectRatioContainer" type="AspectRatioContainer" parent="VBoxContainer"]
margin_top = 154.0 margin_top = 178.0
margin_right = 285.0 margin_right = 285.0
margin_bottom = 354.0 margin_bottom = 378.0
size_flags_vertical = 3 size_flags_vertical = 3
[node name="Preview" type="Control" parent="VBoxContainer/AspectRatioContainer"] [node name="Preview" type="Control" parent="VBoxContainer/AspectRatioContainer"]
@ -176,23 +188,6 @@ anchor_bottom = 1.0
margin_right = 0.0 margin_right = 0.0
margin_bottom = 0.0 margin_bottom = 0.0
[node name="FileDialog" type="FileDialog" parent="."]
margin_left = 8.0
margin_top = 8.0
margin_right = 293.0
margin_bottom = 362.0
rect_min_size = Vector2( 172, 60.2 )
window_title = "Open a File"
resizable = true
mode = 0
access = 2
filters = PoolStringArray( "*.png ; PNG Image" )
current_dir = "/home/variable/Documents/Godot/Godot projects/Pixelorama-Tile-mode-Fixes"
current_path = "/home/variable/Documents/Godot/Godot projects/Pixelorama-Tile-mode-Fixes/"
__meta__ = {
"_editor_description_": ""
}
[connection signal="about_to_show" from="." to="." method="_on_TileModeOffsetsDialog_about_to_show"] [connection signal="about_to_show" from="." to="." method="_on_TileModeOffsetsDialog_about_to_show"]
[connection signal="confirmed" from="." to="." method="_on_TileModeOffsetsDialog_confirmed"] [connection signal="confirmed" from="." to="." method="_on_TileModeOffsetsDialog_confirmed"]
[connection signal="item_rect_changed" from="." to="." method="_on_TileModeOffsetsDialog_item_rect_changed"] [connection signal="item_rect_changed" from="." to="." method="_on_TileModeOffsetsDialog_item_rect_changed"]
@ -203,4 +198,4 @@ __meta__ = {
[connection signal="value_changed" from="VBoxContainer/HBoxContainer/OptionsContainer/YBasisY" to="." method="_on_YBasisY_value_changed"] [connection signal="value_changed" from="VBoxContainer/HBoxContainer/OptionsContainer/YBasisY" to="." method="_on_YBasisY_value_changed"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer/OptionsContainer/Reset" to="." method="_on_Reset_pressed"] [connection signal="pressed" from="VBoxContainer/HBoxContainer/OptionsContainer/Reset" to="." method="_on_Reset_pressed"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer/Mask/LoadMask" to="." method="_on_LoadMask_pressed"] [connection signal="pressed" from="VBoxContainer/HBoxContainer/Mask/LoadMask" to="." method="_on_LoadMask_pressed"]
[connection signal="file_selected" from="FileDialog" to="." method="_on_FileDialog_file_selected"] [connection signal="pressed" from="VBoxContainer/HBoxContainer/Mask/ResetMask" to="." method="_on_ResetMask_pressed"]