From 0eda5b758da603a3e574613b616f0d3cbf5a1356 Mon Sep 17 00:00:00 2001 From: Nordup Date: Mon, 22 May 2023 05:11:19 +0300 Subject: [PATCH] gd: set_mouse_mode --- project/the_gates/scenes/world.tscn | 1 + project/the_gates/scripts/resources/command_events.gd | 5 +++++ project/the_gates/scripts/sandbox/command_sync.gd | 11 +++++++---- project/the_gates/scripts/ui/world/world_ui.gd | 7 +++++++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/project/the_gates/scenes/world.tscn b/project/the_gates/scenes/world.tscn index 5682185..57e7145 100644 --- a/project/the_gates/scenes/world.tscn +++ b/project/the_gates/scenes/world.tscn @@ -171,6 +171,7 @@ grow_horizontal = 2 grow_vertical = 2 script = ExtResource("4_xatjs") ui_events = ExtResource("22_ryq4n") +command_events = ExtResource("22_lfk5j") [node name="Blur" type="Panel" parent="UICanvas/UI"] material = SubResource("ShaderMaterial_kc7rv") diff --git a/project/the_gates/scripts/resources/command_events.gd b/project/the_gates/scripts/resources/command_events.gd index 98f0f71..4cfd738 100644 --- a/project/the_gates/scripts/resources/command_events.gd +++ b/project/the_gates/scripts/resources/command_events.gd @@ -2,7 +2,12 @@ extends Resource class_name CommandEvents signal send_fd +signal set_mouse_mode(mode: int) func send_fd_emit() -> void: send_fd.emit() + + +func set_mouse_mode_emit(mode: int) -> void: + set_mouse_mode.emit(mode) diff --git a/project/the_gates/scripts/sandbox/command_sync.gd b/project/the_gates/scripts/sandbox/command_sync.gd index 3006d53..061787a 100644 --- a/project/the_gates/scripts/sandbox/command_sync.gd +++ b/project/the_gates/scripts/sandbox/command_sync.gd @@ -13,11 +13,14 @@ func _physics_process(delta: float) -> void: receive_commands() -func _execute_function(command: String) -> String: - print("Recieved command: " + command) - match command: +func _execute_function(command: Command) -> Variant: + print("Recieved command: " + command.name) + match command.name: "send_fd": command_events.send_fd_emit() + "set_mouse_mode": + if command.args.size() != 1: push_error("Arg count should be 1"); return "" + command_events.set_mouse_mode_emit(command.args[0]) _: - print("Command %s not implemented" % [command]) + print("Command %s not implemented" % [command.name]) return "" diff --git a/project/the_gates/scripts/ui/world/world_ui.gd b/project/the_gates/scripts/ui/world/world_ui.gd index 1f670da..60bf2b4 100644 --- a/project/the_gates/scripts/ui/world/world_ui.gd +++ b/project/the_gates/scripts/ui/world/world_ui.gd @@ -1,6 +1,7 @@ extends Control @export var ui_events: UiEvents +@export var command_events: CommandEvents var mouse_mode: int = Input.MOUSE_MODE_VISIBLE @@ -8,6 +9,12 @@ var mouse_mode: int = Input.MOUSE_MODE_VISIBLE func _ready() -> void: Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) hide_ui() + + command_events.set_mouse_mode.connect(set_mouse_mode) + + +func set_mouse_mode(mode: int) -> void: + if not visible: Input.set_mouse_mode(mode) func _input(event: InputEvent) -> void: