Skip to content

Commit

Permalink
Fixed Switchs
Browse files Browse the repository at this point in the history
  • Loading branch information
not-my-username committed Dec 21, 2023
1 parent 441d7a9 commit fdcd2f0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
3 changes: 1 addition & 2 deletions Widgets/Button/Button.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
7 changes: 1 addition & 6 deletions Widgets/Button/Button.tscn
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -48,5 +45,3 @@ disabled = true
toggle_mode = true
text = "Button"
text_overrun_behavior = 3

[connection signal="resized" from="." to="." method="_on_resized"]
20 changes: 15 additions & 5 deletions Widgets/Switch/Switch.gd
Original file line number Diff line number Diff line change
@@ -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()

Expand All @@ -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
21 changes: 15 additions & 6 deletions Widgets/Switch/Switch.tscn
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"]
Expand All @@ -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
Expand Down Expand Up @@ -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"]

0 comments on commit fdcd2f0

Please sign in to comment.