main/ holds the main window and top bar, quiz/ the quiz and its parts, player/ the music player, popups/ every popup and what they share, data/ the songs, players, playlist and settings, server/ the MusicServer client, common/ the list row and GameLog, and themes/ the themes and style boxes.
39 lines
997 B
GDScript
39 lines
997 B
GDScript
class_name BasePopup
|
|
extends Control
|
|
## A window shown on top of the main window, such as Settings or About.
|
|
##
|
|
## Clicking outside [member panel] closes it. Popups that need to prepare or clean up
|
|
## override [method open] or [method close] and call [code]super()[/code].
|
|
|
|
## The visible part of the popup. Clicks outside it close the popup.
|
|
|
|
@export var panel: Control
|
|
|
|
|
|
## Shows the popup.
|
|
func open() -> void:
|
|
visible = true
|
|
|
|
|
|
## Hides the popup.
|
|
func close() -> void:
|
|
visible = false
|
|
|
|
|
|
## Opens the popup if it is closed and closes it if it is open.
|
|
func toggle() -> void:
|
|
if visible:
|
|
close()
|
|
else:
|
|
open()
|
|
|
|
|
|
func _input(event: InputEvent) -> void:
|
|
if !visible || !(event is InputEventMouseButton) || !event.pressed:
|
|
return
|
|
var click: InputEventMouseButton = panel.make_input_local(event)
|
|
if !Rect2(Vector2.ZERO, panel.size).has_point(click.position):
|
|
close()
|
|
# The click only closes the popup; it must not also press what is behind it
|
|
get_viewport().set_input_as_handled()
|