From 8abbe0a1cbb939dcc996bdfe1e1d66d4eef752c1 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas Date: Mon, 3 Oct 2022 14:43:08 +0300 Subject: [PATCH] Use a ValueSlider in the window opacity dialog More ValueSlider replacements coming next. --- src/UI/Dialogs/WindowOpacityDialog.gd | 23 ++++++++--------------- src/UI/Dialogs/WindowOpacityDialog.tscn | 23 ++++------------------- src/UI/Nodes/ValueSlider.gd | 2 +- src/UI/TransparentChecker.gd | 11 +++++------ 4 files changed, 18 insertions(+), 41 deletions(-) diff --git a/src/UI/Dialogs/WindowOpacityDialog.gd b/src/UI/Dialogs/WindowOpacityDialog.gd index 0cdd11d24..d4be081e3 100644 --- a/src/UI/Dialogs/WindowOpacityDialog.gd +++ b/src/UI/Dialogs/WindowOpacityDialog.gd @@ -1,7 +1,6 @@ extends AcceptDialog -onready var hslider: HSlider = $VBoxContainer/HBoxContainer/HSlider -onready var spinbox: SpinBox = $VBoxContainer/HBoxContainer/SpinBox +onready var slider: ValueSlider = $VBoxContainer/ValueSlider onready var fullscreen_warning: Label = $VBoxContainer/FullscreenWarning onready var main_canvas = Global.control.find_node("Main Canvas") @@ -13,34 +12,28 @@ func _ready() -> void: func _on_WindowOpacityDialog_about_to_show() -> void: OS.window_per_pixel_transparency_enabled = true - hslider.editable = !OS.window_fullscreen - spinbox.editable = hslider.editable - fullscreen_warning.visible = !spinbox.editable + slider.editable = !OS.window_fullscreen + fullscreen_warning.visible = !slider.editable -func _recalculate_opacity(): - set_window_opacity(hslider.value) - - -func _on_value_changed(value: float) -> void: - set_window_opacity(value) +func _recalculate_opacity() -> void: + set_window_opacity(slider.value) func set_window_opacity(value: float) -> void: if OS.window_fullscreen: value = 100.0 - hslider.value = value - spinbox.value = value + slider.value = value value = value / 100.0 for container in Global.control.ui._panel_container.get_children(): - if container.get_class() == "TabContainer": + if container is TabContainer: var point = container.get_rect().position + (container.get_rect().size / 2.0) if main_canvas.get_rect().has_point(point): container.self_modulate.a = value else: container.self_modulate.a = 1.0 - Global.transparent_checker.transparency(value) + Global.transparent_checker.update_transparency(value) func _on_WindowOpacityDialog_popup_hide() -> void: diff --git a/src/UI/Dialogs/WindowOpacityDialog.tscn b/src/UI/Dialogs/WindowOpacityDialog.tscn index 4f335f23b..ec71804d6 100644 --- a/src/UI/Dialogs/WindowOpacityDialog.tscn +++ b/src/UI/Dialogs/WindowOpacityDialog.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=3 format=2] [ext_resource path="res://src/UI/Dialogs/WindowOpacityDialog.gd" type="Script" id=1] +[ext_resource path="res://src/UI/Nodes/ValueSlider.tscn" type="PackedScene" id=2] [node name="WindowOpacityDialog" type="AcceptDialog"] margin_right = 204.0 @@ -21,24 +22,9 @@ margin_top = 8.0 margin_right = -8.0 margin_bottom = -36.0 -[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"] +[node name="ValueSlider" parent="VBoxContainer" instance=ExtResource( 2 )] margin_right = 327.0 margin_bottom = 24.0 - -[node name="HSlider" type="HSlider" parent="VBoxContainer/HBoxContainer"] -margin_top = 4.0 -margin_right = 249.0 -margin_bottom = 20.0 -mouse_default_cursor_shape = 2 -size_flags_horizontal = 3 -size_flags_vertical = 4 -value = 100.0 - -[node name="SpinBox" type="SpinBox" parent="VBoxContainer/HBoxContainer"] -margin_left = 253.0 -margin_right = 327.0 -margin_bottom = 24.0 -mouse_default_cursor_shape = 2 value = 100.0 [node name="FullscreenWarning" type="Label" parent="VBoxContainer"] @@ -50,5 +36,4 @@ text = "Window opacity does not work on fullscreen mode." [connection signal="about_to_show" from="." to="." method="_on_WindowOpacityDialog_about_to_show"] [connection signal="popup_hide" from="." to="." method="_on_WindowOpacityDialog_popup_hide"] -[connection signal="value_changed" from="VBoxContainer/HBoxContainer/HSlider" to="." method="_on_value_changed"] -[connection signal="value_changed" from="VBoxContainer/HBoxContainer/SpinBox" to="." method="_on_value_changed"] +[connection signal="value_changed" from="VBoxContainer/ValueSlider" to="." method="set_window_opacity"] diff --git a/src/UI/Nodes/ValueSlider.gd b/src/UI/Nodes/ValueSlider.gd index d23d56b8b..d2fdde1c4 100644 --- a/src/UI/Nodes/ValueSlider.gd +++ b/src/UI/Nodes/ValueSlider.gd @@ -1,4 +1,4 @@ -# Made by MrTriPie +# Initial version made by MrTriPie, has been modified tool class_name ValueSlider extends TextureProgress diff --git a/src/UI/TransparentChecker.gd b/src/UI/TransparentChecker.gd index e5f5508c0..c9264deea 100644 --- a/src/UI/TransparentChecker.gd +++ b/src/UI/TransparentChecker.gd @@ -32,15 +32,14 @@ func fit_rect(rect: Rect2) -> void: rect_size = rect.size -func transparency(value: float) -> void: - # first make viewport transparent then background and then viewport +func update_transparency(value: float) -> void: + # Change the transparency status of the parent viewport and the root viewport if value == 1.0: get_parent().transparent_bg = false - get_tree().get_root().set_transparent_background(false) + get_tree().get_root().transparent_bg = false else: get_parent().transparent_bg = true - get_tree().get_root().set_transparent_background(true) + get_tree().get_root().transparent_bg = true - # this controls opacity 0 for transparent, 1 or a greater value than 1 is opaque - # i have set a minimum amount for the fade (We would'nt want the canvas to dissapear now would we?) + # Set a minimum amount for the fade so the canvas won't disappear material.set("shader_param/alpha", clamp(value, 0.1, 1))