mirror of
https://github.com/thegatesbrowser/godot-multiplayer.git
synced 2025-08-02 12:38:16 -04:00
copy from thegates-jam repo
This commit is contained in:
parent
c1a7ad74e1
commit
1a335de566
523 changed files with 22408 additions and 0 deletions
39
ui/mouse_mode.gd
Normal file
39
ui/mouse_mode.gd
Normal file
|
@ -0,0 +1,39 @@
|
|||
extends Control
|
||||
|
||||
var is_in_game: bool
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
visibility_changed.connect(on_visibility_changed)
|
||||
on_visibility_changed()
|
||||
|
||||
|
||||
func _input(_event: InputEvent) -> void:
|
||||
if not is_in_game: return
|
||||
|
||||
if Input.is_action_just_pressed("show_mouse"): set_captured(false)
|
||||
if Input.is_action_just_released("show_mouse"): set_captured(true)
|
||||
|
||||
|
||||
func on_visibility_changed() -> void:
|
||||
if is_visible_in_tree():
|
||||
set_captured(true)
|
||||
is_in_game = true
|
||||
else:
|
||||
set_captured(false)
|
||||
is_in_game = false
|
||||
|
||||
|
||||
func _notification(what: int) -> void:
|
||||
match what:
|
||||
MainLoop.NOTIFICATION_APPLICATION_FOCUS_IN:
|
||||
if is_visible_in_tree(): set_captured(true)
|
||||
MainLoop.NOTIFICATION_APPLICATION_FOCUS_OUT:
|
||||
pass
|
||||
|
||||
|
||||
func set_captured(captured: bool) -> void:
|
||||
if captured:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||
else:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
Loading…
Add table
Add a link
Reference in a new issue