UiMode enum

This commit is contained in:
Nordup 2024-03-26 09:24:16 +04:00
parent 7ab7255140
commit f821952b9a
5 changed files with 20 additions and 13 deletions

View file

@ -1,14 +1,20 @@
extends Resource
class_name UiEvents
signal ui_visibility_changed(visible: bool)
signal ui_mode_changed(mode: UiMode)
signal ui_size_changed(size: Vector2)
enum UiMode
{
INITIAL,
FULL_SCREEN
}
var current_ui_size: Vector2
func ui_visibility_changed_emit(visible: bool) -> void:
ui_visibility_changed.emit(visible)
func ui_mode_changed_emit(mode: UiMode) -> void:
ui_mode_changed.emit(mode)
func ui_size_changed_emit(size: Vector2) -> void:

View file

@ -13,7 +13,7 @@ var should_send := false
func _ready() -> void:
gate_events.gate_entered.connect(start_server)
ui_events.ui_visibility_changed.connect(on_ui_visibility_changed)
ui_events.ui_mode_changed.connect(on_ui_mode_changed)
scale_width = float(render_result.width) / ui_events.current_ui_size.x
scale_height = float(render_result.height) / ui_events.current_ui_size.y
@ -25,8 +25,8 @@ func start_server() -> void:
input_sync.bind()
func on_ui_visibility_changed(visible: bool) -> void:
should_send = not visible
func on_ui_mode_changed(mode: UiEvents.UiMode) -> void:
should_send = mode == UiEvents.UiMode.FULL_SCREEN
func _input(event: InputEvent) -> void:

View file

@ -11,15 +11,15 @@ var fullscreen := false
func _ready() -> void:
ui_events.ui_visibility_changed.connect(on_ui_visibility_changed)
gate_events.open_gate.connect(func(_url): on_ui_visibility_changed(true))
ui_events.ui_mode_changed.connect(on_ui_mode_changed)
gate_events.open_gate.connect(func(_url): on_ui_mode_changed(UiEvents.UiMode.INITIAL))
func on_ui_visibility_changed(visible: bool) -> void:
if visible and fullscreen:
func on_ui_mode_changed(mode: UiEvents.UiMode) -> void:
if mode == UiEvents.UiMode.INITIAL and fullscreen:
fullscreen = false
play(INITIAL)
if not visible and not fullscreen:
if mode == UiEvents.UiMode.FULL_SCREEN and not fullscreen:
fullscreen = true
play(FULLSCREEN)

View file

@ -9,4 +9,5 @@ func _ready() -> void:
func on_resized() -> void:
Debug.logclr("Ui resized: %dx%d" % [size.x, size.y], Debug.SILENT_CLR)
ui_events.ui_size_changed_emit(size)

View file

@ -31,7 +31,7 @@ func show_ui() -> void:
_visible = true
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
ui_events.ui_visibility_changed_emit(true)
ui_events.ui_mode_changed_emit(UiEvents.UiMode.INITIAL)
func hide_ui() -> void:
@ -39,4 +39,4 @@ func hide_ui() -> void:
_visible = false
Input.set_mouse_mode(mouse_mode)
ui_events.ui_visibility_changed_emit(false)
ui_events.ui_mode_changed_emit(UiEvents.UiMode.FULL_SCREEN)