52 lines
1.2 KiB
GDScript
52 lines
1.2 KiB
GDScript
@tool
|
|
extends Control
|
|
|
|
class_name ToggleSwitch
|
|
|
|
@onready var cover = $Cover
|
|
@onready var switch = $Switch
|
|
@onready var mount = $Mount
|
|
|
|
enum SwitchTypes {Standard, Covered}
|
|
@export var type : SwitchTypes = SwitchTypes.Standard:
|
|
set(new_type):
|
|
type = new_type
|
|
if Engine.is_editor_hint():
|
|
update_type()
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
update_type()
|
|
|
|
func update_type():
|
|
match type:
|
|
SwitchTypes.Standard:
|
|
cover.hide()
|
|
#mount.hide()
|
|
switch.position = Vector2(0,0)
|
|
custom_minimum_size = switch.size
|
|
|
|
SwitchTypes.Covered:
|
|
cover.show()
|
|
#mount.show()
|
|
switch.position = Vector2(0,35)
|
|
custom_minimum_size = mount.size
|
|
if not Engine.is_editor_hint():
|
|
switch.reparent(cover)
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta: float) -> void:
|
|
pass
|
|
|
|
|
|
func _on_cover_flipped(flipped_down: bool) -> void:
|
|
switch.disabled = flipped_down
|
|
|
|
if flipped_down:
|
|
switch.button_pressed = false
|
|
switch.mouse_filter = MOUSE_FILTER_IGNORE
|
|
switch.show_behind_parent = true
|
|
else:
|
|
switch.mouse_filter = MOUSE_FILTER_PASS
|
|
switch.show_behind_parent = false
|