From 2cb29ab2746c2c85780ce7d02f70ccbe8484105e Mon Sep 17 00:00:00 2001 From: Variable <77773850+Variable-ind@users.noreply.github.com> Date: Thu, 17 Oct 2024 21:51:45 +0500 Subject: [PATCH] somewhat fix transparency for floating window (#1116) * somewhat fix transparency * some formatting --- src/UI/Dialogs/WindowOpacityDialog.gd | 16 ++++++++++++---- src/UI/UI.gd | 22 +++++++++++++++++++--- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/UI/Dialogs/WindowOpacityDialog.gd b/src/UI/Dialogs/WindowOpacityDialog.gd index e8f0524a3..8ab8230cf 100644 --- a/src/UI/Dialogs/WindowOpacityDialog.gd +++ b/src/UI/Dialogs/WindowOpacityDialog.gd @@ -1,18 +1,22 @@ extends AcceptDialog +var main_canvas := Global.control.find_child("Main Canvas", true, false) + @onready var slider := $VBoxContainer/ValueSlider as ValueSlider @onready var fullscreen_warning := $VBoxContainer/FullscreenWarning as Label -@onready var main_canvas := Global.control.find_child("Main Canvas") as Control func _ready() -> void: + if main_canvas is FloatingWindow: ## If it's shifted to a window then get the content + main_canvas = main_canvas.window_content await get_tree().process_frame Global.control.main_ui.sort_children.connect(_recalculate_opacity) func _on_WindowOpacityDialog_about_to_show() -> void: - get_tree().root.transparent = true - get_tree().root.transparent_bg = true + var canvas_window = main_canvas.get_window() + canvas_window.transparent = true + canvas_window.transparent_bg = true slider.editable = not is_fullscreen() fullscreen_warning.visible = not slider.editable @@ -31,7 +35,11 @@ func set_window_opacity(value: float) -> void: if container is TabContainer: var center := container.get_rect().get_center() if main_canvas.get_rect().has_point(center): - container.self_modulate.a = value + if main_canvas.get_window() != get_tree().root: + ## In case we converted to window while trransparency was active + container.self_modulate.a = 1.0 + else: + container.self_modulate.a = value Global.transparent_checker.update_transparency(value) diff --git a/src/UI/UI.gd b/src/UI/UI.gd index 3cbc532b0..105e46511 100644 --- a/src/UI/UI.gd +++ b/src/UI/UI.gd @@ -1,12 +1,28 @@ extends Panel +var shader_disabled := false +var transparency_material: ShaderMaterial + @onready var main_canvas_container := find_child("Main Canvas") as Container func _ready() -> void: + transparency_material = material + main_canvas_container.property_list_changed.connect(_re_configure_shader) update_transparent_shader() +func _re_configure_shader(): + await get_tree().process_frame + if get_window() != main_canvas_container.get_window(): + material = null + shader_disabled = true + else: + if shader_disabled: + material = transparency_material + shader_disabled = false + + func _on_main_canvas_item_rect_changed() -> void: update_transparent_shader() @@ -20,6 +36,6 @@ func update_transparent_shader() -> void: return # Works independently of the transparency feature var canvas_size: Vector2 = (main_canvas_container.size - Vector2.DOWN * 2) * Global.shrink - material.set_shader_parameter("screen_resolution", get_viewport().size) - material.set_shader_parameter("position", main_canvas_container.global_position * Global.shrink) - material.set_shader_parameter("size", canvas_size) + transparency_material.set_shader_parameter("screen_resolution", get_viewport().size) + transparency_material.set_shader_parameter("position", main_canvas_container.global_position * Global.shrink) + transparency_material.set_shader_parameter("size", canvas_size)