- Types on every parameter, return value and variable, and snake_case names (the player name limit is the constant MAX_NAME_LENGTH). - Spelling fixes: *_triggered, character_selected, separator, caught_errors. The server's catched_errors key stays as the server sends it. - Signals are connected with signal.connect() instead of by name. - Code is ordered signals, constants, exported vars, vars, @onready vars, functions, with @onready on one line and two blank lines between functions. - Every script starts with a ## description. Template comments, old LOC notes and commented-out code are gone, apart from the local play code. - Lines are at most 100 characters, apart from the local play path. - The screenshot tour turns off the blinking text cursor so pictures match.
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()
|