From fdcd2f06194e80a6ff40c7c3067fa82757aedac2 Mon Sep 17 00:00:00 2001 From: Liam <95655127+not-my-username@users.noreply.github.com> Date: Thu, 21 Dec 2023 22:28:51 +0000 Subject: [PATCH] Fixed Switchs --- Widgets/Button/Button.gd | 3 +-- Widgets/Button/Button.tscn | 7 +------ Widgets/Switch/Switch.gd | 20 +++++++++++++++----- Widgets/Switch/Switch.tscn | 21 +++++++++++++++------ 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/Widgets/Button/Button.gd b/Widgets/Button/Button.gd index 57adb06..f4aa42d 100644 --- a/Widgets/Button/Button.gd +++ b/Widgets/Button/Button.gd @@ -2,6 +2,7 @@ extends Node func _ready(): Globals.subscribe("edit_mode", self.toggle_edit_mode) + self.resized.connect(_on_resized) func close_request(): queue_free() @@ -12,8 +13,6 @@ func _on_resized(): self.size = Vector2(round(new_minsize.x / snap_size) * snap_size, round(new_minsize.y / snap_size) * snap_size) func toggle_edit_mode(edit_mode): - - print(edit_mode) if edit_mode: get_node("Button").disabled = true get_node("Button").mouse_filter = 1 diff --git a/Widgets/Button/Button.tscn b/Widgets/Button/Button.tscn index c79eab7..5c8f90b 100644 --- a/Widgets/Button/Button.tscn +++ b/Widgets/Button/Button.tscn @@ -1,6 +1,4 @@ -[gd_scene load_steps=5 format=3 uid="uid://d13q5meef75lt"] - -[ext_resource type="Script" path="res://Widgets/Button/Button.gd" id="1_bjehy"] +[gd_scene load_steps=4 format=3 uid="uid://d13q5meef75lt"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_1meh7"] bg_color = Color(0.137255, 0.137255, 0.137255, 1) @@ -32,7 +30,6 @@ corner_radius_bottom_left = 10 offset_right = 80.0 offset_bottom = 80.0 resizable = true -script = ExtResource("1_bjehy") [node name="Button" type="Button" parent="."] use_parent_material = true @@ -48,5 +45,3 @@ disabled = true toggle_mode = true text = "Button" text_overrun_behavior = 3 - -[connection signal="resized" from="." to="." method="_on_resized"] diff --git a/Widgets/Switch/Switch.gd b/Widgets/Switch/Switch.gd index e5accef..9e279a7 100644 --- a/Widgets/Switch/Switch.gd +++ b/Widgets/Switch/Switch.gd @@ -1,9 +1,12 @@ - extends Node var connection var value = 0 +func _ready(): + self.resized.connect(_on_resized) + $Switch.toggled.connect(_on_switch_toggled) + Globals.subscribe("edit_mode", self.toggle_edit_mode) func close_request(): queue_free() @@ -14,9 +17,16 @@ func _on_resized(): func _on_switch_toggled(toggled_on): if toggled_on: - get_node("Toggle Button/Container/False").visible = false - get_node("Toggle Button/Container/True").visible = true + get_node("Switch/Container/False").visible = false + get_node("Switch/Container/True").visible = true else: - get_node("Toggle Button/Container/False").visible = true - get_node("Toggle Button/Container/True").visible = false + get_node("Switch/Container/False").visible = true + get_node("Switch/Container/True").visible = false +func toggle_edit_mode(edit_mode): + if edit_mode: + get_node("Switch").disabled = true + get_node("Switch").mouse_filter = 1 + else: + get_node("Switch").disabled = false + get_node("Switch").mouse_filter = 0 diff --git a/Widgets/Switch/Switch.tscn b/Widgets/Switch/Switch.tscn index 58996ce..397148c 100644 --- a/Widgets/Switch/Switch.tscn +++ b/Widgets/Switch/Switch.tscn @@ -1,7 +1,5 @@ [gd_scene load_steps=7 format=3 uid="uid://d2b3q73a48sny"] -[ext_resource type="Script" path="res://Widgets/Button/Button.gd" id="1_56i8r"] - [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_1c4f0"] bg_color = Color(0.235294, 0.137255, 0.137255, 1) border_width_left = 4 @@ -26,6 +24,18 @@ corner_radius_top_right = 10 corner_radius_bottom_right = 10 corner_radius_bottom_left = 10 +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_j28fo"] +bg_color = Color(0.137255, 0.137255, 0.137255, 1) +border_width_left = 4 +border_width_top = 4 +border_width_right = 4 +border_width_bottom = 4 +border_color = Color(0.27451, 0.27451, 0.27451, 1) +corner_radius_top_left = 10 +corner_radius_top_right = 10 +corner_radius_bottom_right = 10 +corner_radius_bottom_left = 10 + [sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_vo6nq"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_3ccxs"] @@ -46,15 +56,16 @@ corner_radius_bottom_left = 7 offset_right = 140.0 offset_bottom = 140.0 resizable = true -script = ExtResource("1_56i8r") [node name="Switch" type="Button" parent="."] +use_parent_material = true custom_minimum_size = Vector2(70, 70) layout_mode = 2 mouse_filter = 1 theme_override_styles/normal = SubResource("StyleBoxFlat_1c4f0") theme_override_styles/hover = SubResource("StyleBoxFlat_1c4f0") theme_override_styles/pressed = SubResource("StyleBoxFlat_cwlsm") +theme_override_styles/disabled = SubResource("StyleBoxFlat_j28fo") theme_override_styles/focus = SubResource("StyleBoxEmpty_vo6nq") disabled = true toggle_mode = true @@ -82,11 +93,9 @@ mouse_filter = 1 theme_override_styles/panel = SubResource("StyleBoxFlat_3ccxs") [node name="True" type="Panel" parent="Switch/Container"] +visible = false custom_minimum_size = Vector2(41.34, 0) layout_mode = 2 size_flags_horizontal = 10 mouse_filter = 1 theme_override_styles/panel = SubResource("StyleBoxFlat_au1w3") - -[connection signal="resized" from="." to="." method="_on_resized"] -[connection signal="toggled" from="Switch" to="." method="_on_switch_toggled"]