Spaceship/base/controls/toggle switch/toggle_switch.gd
2026-06-04 18:14:18 -07:00

39 lines
923 B
GDScript

extends Control
class_name ToggleSwitch
enum SwitchTypes {Standard, Covered}
@export var type : SwitchTypes = SwitchTypes.Standard
@onready var cover = $Cover
@onready var switch = $Switch
@onready var mount = $Mount
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
if type != SwitchTypes.Covered:
cover.hide()
mount.hide()
switch.position = Vector2(0,0)
custom_minimum_size = switch.size
if type == SwitchTypes.Covered:
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