From 7949510e69eb09869b89941223c35921e6ca4e4f Mon Sep 17 00:00:00 2001 From: AleaJactaEst Date: Fri, 15 Apr 2022 16:37:38 +0200 Subject: [PATCH] activate reverse mouse mouvement --- player/player.gd | 24 ++++----- scenes/controls/controls.gd | 43 +++++++++++++--- scenes/controls/controls.tscn | 46 +++++++++-------- scripts/common.gd | 97 +++++++++++++++++++++++++++++++++++ 4 files changed, 171 insertions(+), 39 deletions(-) diff --git a/player/player.gd b/player/player.gd index 0d146b1..8b37d4c 100644 --- a/player/player.gd +++ b/player/player.gd @@ -407,16 +407,10 @@ func get_distance_vector(obj1: Vector3, obj2: Vector3) -> float: func is_mouse_button_pressed(action): var pressed:bool = true var ext = String(action) + "_PLUS" - Common.msg_debug("action:" + action) if InputMap.has_action(ext): if InputMap.action_get_events(ext).size() > 0: - for a in InputMap.action_get_events(ext): - Common.msg_debug(str(a)) - Common.msg_debug("Size:" + str(InputMap.action_get_events(ext).size())) pressed = Input.is_action_pressed(ext) var res = Input.is_action_pressed(action) and pressed - - Common.msg_debug("action:" + action + " -> " + str(res) + " / " + str(Input.is_action_pressed(action)) + " / " +str(pressed)) return res @@ -428,22 +422,18 @@ func _input(event): restore_position_camera() if event is InputEventMouseButton: - Common.msg_debug("----------") if is_mouse_button_pressed("INPUT_VIEW_CAMERA_MOVE_PLAYER_FOLLOW_MOUSE"): input_view_camera_move_player_follow_mouse = true - Common.msg_debug("input_view_camera_move_player_follow_mouse") else: input_view_camera_move_player_follow_mouse = false if is_mouse_button_pressed("INPUT_VIEW_CAMERA_MOVE_ONLY_MOUSE"): input_view_camera_move_only_mouse = true - Common.msg_debug("input_view_camera_move_only_mouse") else: input_view_camera_move_only_mouse = false if is_mouse_button_pressed("INPUT_ACTION_CAMERA_MOVE_PLAYER_MOUSE"): input_action_camera_move_player_mouse = true - Common.msg_debug("input_action_camera_move_player_mouse") else: input_action_camera_move_player_mouse = false @@ -460,9 +450,17 @@ func _input(event): camera_zoom_out() if Input.is_action_just_pressed("INPUT_VIEW_CAMERA_FPS_TPS", true): switch_camera_fps() - if input_view_camera_move_player_follow_mouse or input_view_camera_move_only_mouse or input_action_camera_move_player_mouse: - if event is InputEventMouseMotion: - move_camera(event.relative.y * 0.01 , - event.relative.x *0.01) + if event is InputEventMouseMotion: + if input_action_camera_move_player_mouse: + Common.msg_debug("Move " + str(Common.get_mul_mouse_camera_player_move_reverse_horizontal()) + " / " + str(Common.get_mul_mouse_camera_player_move_reverse_vertical())) + move_camera( Common.get_mul_mouse_camera_player_move_reverse_vertical() * event.relative.y * 0.01 , Common.get_mul_mouse_camera_player_move_reverse_horizontal() * event.relative.x *0.01) + elif input_view_camera_move_player_follow_mouse: + move_camera( Common.get_mul_mouse_camera_player_reverse_vertical() * event.relative.y * 0.01 , Common.get_mul_mouse_camera_player_reverse_horizontal() * event.relative.x *0.01) + #move_camera(event.relative.y * 0.01 , - event.relative.x *0.01) + elif input_view_camera_move_only_mouse: + # move_camera(event.relative.y * 0.01 , - event.relative.x *0.01) + Common.msg_debug("Move " + str(Common.get_mul_mouse_camera_only_reverse_vertical()) + " / " + str(Common.get_mul_mouse_camera_only_reverse_horizontal())) + move_camera( Common.get_mul_mouse_camera_only_reverse_vertical() * event.relative.y * 0.01 , Common.get_mul_mouse_camera_only_reverse_horizontal() * event.relative.x *0.01) if input_view_camera_move_player_follow_mouse or input_action_camera_move_player_mouse: reconciliate_rotate_camera_player = true Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) diff --git a/scenes/controls/controls.gd b/scenes/controls/controls.gd index e9923fa..bbcec75 100644 --- a/scenes/controls/controls.gd +++ b/scenes/controls/controls.gd @@ -14,6 +14,13 @@ func _ready(): $SelectType.connect("cancel_define_input", show_windows.bind() ) $DefineInput.connect("refresh_control_define_input", define_mouse_camera_move.bind() ) $DefineInput.connect("cancel_define_input", show_windows.bind()) + $Window/v/Tab/MOUSE/v/CameraPlayer/h2/ReverseHorizontal.set_pressed(Common.get_mouse_camera_player_reverse_horizontal()) + $Window/v/Tab/MOUSE/v/CameraPlayer/h2/ReverseVertical.set_pressed(Common.get_mouse_camera_player_reverse_vertical()) + $Window/v/Tab/MOUSE/v/CameraOnly/h2/ReverseHorizontal.set_pressed(Common.get_mouse_camera_only_reverse_horizontal()) + $Window/v/Tab/MOUSE/v/CameraOnly/h2/ReverseVertical.set_pressed(Common.get_mouse_camera_only_reverse_vertical()) + $Window/v/Tab/MOUSE/v/CameraPlayerMove/h2/ReverseHorizontal.set_pressed(Common.get_mouse_camera_player_move_reverse_horizontal()) + $Window/v/Tab/MOUSE/v/CameraPlayerMove/h2/ReverseVertical.set_pressed(Common.get_mouse_camera_player_move_reverse_vertical()) + func refresh(): configure_control() @@ -137,10 +144,10 @@ func load_current_control(): func update_mouse_button_move_camera(): $Window/v/Tab/MOUSE/v/CameraPlayer/h1/SelectButton.set_text(Common.get_input_plus("INPUT_VIEW_CAMERA_MOVE_PLAYER_FOLLOW_MOUSE")) $Window/v/Tab/MOUSE/v/CameraOnly/h1/SelectButton.set_text(Common.get_input_plus("INPUT_VIEW_CAMERA_MOVE_ONLY_MOUSE")) - $Window/v/Tab/MOUSE/v/CameraPlayerWalk/h1/SelectButton.set_text(Common.get_input_plus("INPUT_ACTION_CAMERA_MOVE_PLAYER_MOUSE")) + $Window/v/Tab/MOUSE/v/CameraPlayerMove/h1/SelectButton.set_text(Common.get_input_plus("INPUT_ACTION_CAMERA_MOVE_PLAYER_MOUSE")) $Window/v/Tab/JOYPAD/v/CameraPlayer/h1/SelectButton.set_text(Common.get_input_plus("INPUT_VIEW_CAMERA_MOVE_PLAYER_FOLLOW_JOYPAD")) $Window/v/Tab/JOYPAD/v/CameraOnly/h1/SelectButton.set_text(Common.get_input_plus("INPUT_VIEW_CAMERA_MOVE_ONLY_JOYPAD")) - $Window/v/Tab/JOYPAD/v/CameraPlayerWalk/h1/SelectButton.set_text(Common.get_input_plus("INPUT_ACTION_CAMERA_MOVE_PLAYER_JOYPAD")) + $Window/v/Tab/JOYPAD/v/CameraPlayerMove/h1/SelectButton.set_text(Common.get_input_plus("INPUT_ACTION_CAMERA_MOVE_PLAYER_JOYPAD")) func configure_control(): @@ -399,9 +406,9 @@ func _on_select_mouse_button_camera_only_pressed(): $DefineInput/Window.visible = true -func _on_select_mouse_button_camera_player_walk_pressed(): +func _on_select_mouse_button_camera_player_move_pressed(): $Window.visible = false - $DefineInput.set_param(2, "INPUT_VIEW_CAMERA_PLAYER_WALK_MOUSE") + $DefineInput.set_param(2, "INPUT_ACTION_CAMERA_MOVE_PLAYER_MOUSE") $DefineInput/Window.popup_centered() $DefineInput/Window.visible = true @@ -420,8 +427,32 @@ func _on_select_joypad_button_camera_only_pressed(): $DefineInput/Window.visible = true -func _on_joypad_camera_player_walk_button_pressed(): +func _on_joypad_camera_player_move_button_pressed(): $Window.visible = false - $DefineInput.set_param(4, "INPUT_VIEW_CAMERA_PLAYER_WALK_JOYPAD") + $DefineInput.set_param(4, "INPUT_ACTION_CAMERA_MOVE_PLAYER_JOYPAD") $DefineInput/Window.popup_centered() $DefineInput/Window.visible = true + + +func _on_camera_player_reverse_horizontal_toggled(button_pressed): + Common.set_mouse_camera_player_reverse_horizontal(button_pressed) + + +func _on_camera_player_reverse_vertical_toggled(button_pressed): + Common.set_mouse_camera_player_reverse_vertical(button_pressed) + + +func _on_camera_only_reverse_horizontal_toggled(button_pressed): + Common.set_mouse_camera_only_reverse_horizontal(button_pressed) + + +func _on_camera_only_reverse_vertical_toggled(button_pressed): + Common.set_mouse_camera_only_reverse_vertical(button_pressed) + + +func _on_camera_player_move_reverse_horizontal_toggled(button_pressed): + Common.set_mouse_camera_player_move_reverse_horizontal(button_pressed) + + +func _on_camera_player_move_reverse_vertical_toggled(button_pressed): + Common.set_mouse_camera_player_move_reverse_vertical(button_pressed) diff --git a/scenes/controls/controls.tscn b/scenes/controls/controls.tscn index e1b343f..419e7d9 100644 --- a/scenes/controls/controls.tscn +++ b/scenes/controls/controls.tscn @@ -196,44 +196,44 @@ text = "EDIT_CONTROL/MOVE_CAMERA_REVERSE_VERTICAL" offset_right = 40.0 offset_bottom = 4.0 -[node name="CameraPlayerWalk" type="VBoxContainer" parent="Window/v/Tab/MOUSE/v"] +[node name="CameraPlayerMove" type="VBoxContainer" parent="Window/v/Tab/MOUSE/v"] offset_right = 40.0 offset_bottom = 40.0 -[node name="Label" type="Label" parent="Window/v/Tab/MOUSE/v/CameraPlayerWalk"] +[node name="Label" type="Label" parent="Window/v/Tab/MOUSE/v/CameraPlayerMove"] offset_right = 40.0 offset_bottom = 23.0 text = "INPUT_ACTION_CAMERA_MOVE_PLAYER" -[node name="h1" type="HBoxContainer" parent="Window/v/Tab/MOUSE/v/CameraPlayerWalk"] +[node name="h1" type="HBoxContainer" parent="Window/v/Tab/MOUSE/v/CameraPlayerMove"] offset_right = 40.0 offset_bottom = 40.0 -[node name="space" type="Label" parent="Window/v/Tab/MOUSE/v/CameraPlayerWalk/h1"] +[node name="space" type="Label" parent="Window/v/Tab/MOUSE/v/CameraPlayerMove/h1"] minimum_size = Vector2(50, 0) offset_right = 40.0 offset_bottom = 23.0 -[node name="SelectButton" type="Button" parent="Window/v/Tab/MOUSE/v/CameraPlayerWalk/h1"] +[node name="SelectButton" type="Button" parent="Window/v/Tab/MOUSE/v/CameraPlayerMove/h1"] offset_right = 8.0 offset_bottom = 31.0 text = "SELECT" -[node name="h2" type="HBoxContainer" parent="Window/v/Tab/MOUSE/v/CameraPlayerWalk"] +[node name="h2" type="HBoxContainer" parent="Window/v/Tab/MOUSE/v/CameraPlayerMove"] offset_right = 40.0 offset_bottom = 40.0 -[node name="space" type="Label" parent="Window/v/Tab/MOUSE/v/CameraPlayerWalk/h2"] +[node name="space" type="Label" parent="Window/v/Tab/MOUSE/v/CameraPlayerMove/h2"] minimum_size = Vector2(50, 0) offset_right = 40.0 offset_bottom = 23.0 -[node name="ReverseHorizontal" type="CheckBox" parent="Window/v/Tab/MOUSE/v/CameraPlayerWalk/h2"] +[node name="ReverseHorizontal" type="CheckBox" parent="Window/v/Tab/MOUSE/v/CameraPlayerMove/h2"] offset_right = 24.0 offset_bottom = 31.0 text = "EDIT_CONTROL/MOVE_CAMERA_REVERSE_HORIZONTAL" -[node name="ReverseVertical" type="CheckBox" parent="Window/v/Tab/MOUSE/v/CameraPlayerWalk/h2"] +[node name="ReverseVertical" type="CheckBox" parent="Window/v/Tab/MOUSE/v/CameraPlayerMove/h2"] offset_right = 24.0 offset_bottom = 31.0 text = "EDIT_CONTROL/MOVE_CAMERA_REVERSE_VERTICAL" @@ -341,44 +341,44 @@ text = "EDIT_CONTROL/MOVE_CAMERA_REVERSE_VERTICAL" offset_right = 40.0 offset_bottom = 4.0 -[node name="CameraPlayerWalk" type="VBoxContainer" parent="Window/v/Tab/JOYPAD/v"] +[node name="CameraPlayerMove" type="VBoxContainer" parent="Window/v/Tab/JOYPAD/v"] offset_right = 40.0 offset_bottom = 40.0 -[node name="Label" type="Label" parent="Window/v/Tab/JOYPAD/v/CameraPlayerWalk"] +[node name="Label" type="Label" parent="Window/v/Tab/JOYPAD/v/CameraPlayerMove"] offset_right = 40.0 offset_bottom = 23.0 text = "INPUT_ACTION_CAMERA_MOVE_PLAYER" -[node name="h1" type="HBoxContainer" parent="Window/v/Tab/JOYPAD/v/CameraPlayerWalk"] +[node name="h1" type="HBoxContainer" parent="Window/v/Tab/JOYPAD/v/CameraPlayerMove"] offset_right = 40.0 offset_bottom = 40.0 -[node name="space" type="Label" parent="Window/v/Tab/JOYPAD/v/CameraPlayerWalk/h1"] +[node name="space" type="Label" parent="Window/v/Tab/JOYPAD/v/CameraPlayerMove/h1"] minimum_size = Vector2(50, 0) offset_right = 40.0 offset_bottom = 23.0 -[node name="SelectButton" type="Button" parent="Window/v/Tab/JOYPAD/v/CameraPlayerWalk/h1"] +[node name="SelectButton" type="Button" parent="Window/v/Tab/JOYPAD/v/CameraPlayerMove/h1"] offset_right = 8.0 offset_bottom = 31.0 text = "SELECT" -[node name="h2" type="HBoxContainer" parent="Window/v/Tab/JOYPAD/v/CameraPlayerWalk"] +[node name="h2" type="HBoxContainer" parent="Window/v/Tab/JOYPAD/v/CameraPlayerMove"] offset_right = 40.0 offset_bottom = 40.0 -[node name="space" type="Label" parent="Window/v/Tab/JOYPAD/v/CameraPlayerWalk/h2"] +[node name="space" type="Label" parent="Window/v/Tab/JOYPAD/v/CameraPlayerMove/h2"] minimum_size = Vector2(50, 0) offset_right = 40.0 offset_bottom = 23.0 -[node name="ReverseHorizontal" type="CheckBox" parent="Window/v/Tab/JOYPAD/v/CameraPlayerWalk/h2"] +[node name="ReverseHorizontal" type="CheckBox" parent="Window/v/Tab/JOYPAD/v/CameraPlayerMove/h2"] offset_right = 24.0 offset_bottom = 31.0 text = "EDIT_CONTROL/MOVE_CAMERA_REVERSE_HORIZONTAL" -[node name="ReverseVertical" type="CheckBox" parent="Window/v/Tab/JOYPAD/v/CameraPlayerWalk/h2"] +[node name="ReverseVertical" type="CheckBox" parent="Window/v/Tab/JOYPAD/v/CameraPlayerMove/h2"] offset_right = 24.0 offset_bottom = 31.0 text = "EDIT_CONTROL/MOVE_CAMERA_REVERSE_VERTICAL" @@ -409,9 +409,15 @@ metadata/_edit_use_custom_anchors = false [connection signal="pressed" from="Window/v/Tab/CONTROL/Menu/Reload" to="." method="reload_control_system"] [connection signal="button_pressed" from="Window/v/Tab/CONTROL/Tree" to="." method="_on_tree_button_pressed"] [connection signal="pressed" from="Window/v/Tab/MOUSE/v/CameraPlayer/h1/SelectButton" to="." method="_on_select_mouse_button_camera_player_pressed"] +[connection signal="toggled" from="Window/v/Tab/MOUSE/v/CameraPlayer/h2/ReverseHorizontal" to="." method="_on_camera_player_reverse_horizontal_toggled"] +[connection signal="toggled" from="Window/v/Tab/MOUSE/v/CameraPlayer/h2/ReverseVertical" to="." method="_on_camera_player_reverse_vertical_toggled"] [connection signal="pressed" from="Window/v/Tab/MOUSE/v/CameraOnly/h1/SelectButton" to="." method="_on_select_mouse_button_camera_only_pressed"] -[connection signal="pressed" from="Window/v/Tab/MOUSE/v/CameraPlayerWalk/h1/SelectButton" to="." method="_on_select_mouse_button_camera_player_walk_pressed"] +[connection signal="toggled" from="Window/v/Tab/MOUSE/v/CameraOnly/h2/ReverseHorizontal" to="." method="_on_camera_only_reverse_horizontal_toggled"] +[connection signal="toggled" from="Window/v/Tab/MOUSE/v/CameraOnly/h2/ReverseVertical" to="." method="_on_camera_only_reverse_vertical_toggled"] +[connection signal="pressed" from="Window/v/Tab/MOUSE/v/CameraPlayerMove/h1/SelectButton" to="." method="_on_select_mouse_button_camera_player_move_pressed"] +[connection signal="toggled" from="Window/v/Tab/MOUSE/v/CameraPlayerMove/h2/ReverseHorizontal" to="." method="_on_camera_player_move_reverse_horizontal_toggled"] +[connection signal="toggled" from="Window/v/Tab/MOUSE/v/CameraPlayerMove/h2/ReverseVertical" to="." method="_on_camera_player_move_reverse_vertical_toggled"] [connection signal="pressed" from="Window/v/Tab/JOYPAD/v/CameraPlayer/h1/SelectButton" to="." method="_on_select_joypad_button_camera_player_pressed"] [connection signal="pressed" from="Window/v/Tab/JOYPAD/v/CameraOnly/h1/SelectButton" to="." method="_on_select_joypad_button_camera_only_pressed"] -[connection signal="pressed" from="Window/v/Tab/JOYPAD/v/CameraPlayerWalk/h1/SelectButton" to="." method="_on_joypad_camera_player_walk_button_pressed"] +[connection signal="pressed" from="Window/v/Tab/JOYPAD/v/CameraPlayerMove/h1/SelectButton" to="." method="_on_joypad_camera_player_move_button_pressed"] [connection signal="pressed" from="Window/v/Quit" to="." method="_on_quit_pressed"] diff --git a/scripts/common.gd b/scripts/common.gd index 3dafbde..c2e2383 100644 --- a/scripts/common.gd +++ b/scripts/common.gd @@ -3,6 +3,13 @@ extends Node var debug:bool = true +var mouse_camera_player_reverse_horizontal:bool = false +var mouse_camera_player_reverse_vertical:bool = false +var mouse_camera_only_reverse_horizontal:bool = false +var mouse_camera_only_reverse_vertical:bool = false +var mouse_camera_player_move_reverse_horizontal:bool = false +var mouse_camera_player_move_reverse_vertical:bool = false + func _ready(): randomize() @@ -187,3 +194,93 @@ func set_input(action:String, event, origin, eraselast:bool): func set_input_plus(action:String, event, eventplus, eraselast:bool): set_input(action, event, event, eraselast) set_input(action + "_PLUS", eventplus, event, eraselast) + + +func set_mouse_camera_player_reverse_horizontal(value:bool): + mouse_camera_player_reverse_horizontal = value + + +func set_mouse_camera_player_reverse_vertical(value:bool): + mouse_camera_player_reverse_vertical = value + + +func set_mouse_camera_only_reverse_horizontal(value:bool): + mouse_camera_only_reverse_horizontal = value + + +func set_mouse_camera_only_reverse_vertical(value:bool): + mouse_camera_only_reverse_vertical = value + + +func set_mouse_camera_player_move_reverse_horizontal(value:bool): + mouse_camera_player_move_reverse_horizontal = value + + +func set_mouse_camera_player_move_reverse_vertical(value:bool): + mouse_camera_player_move_reverse_vertical = value + + +func get_mouse_camera_player_reverse_horizontal() -> bool: + return mouse_camera_player_reverse_horizontal + + +func get_mouse_camera_player_reverse_vertical() -> bool: + return mouse_camera_player_reverse_vertical + + +func get_mouse_camera_only_reverse_horizontal() -> bool: + return mouse_camera_only_reverse_horizontal + + +func get_mouse_camera_only_reverse_vertical() -> bool: + return mouse_camera_only_reverse_vertical + + +func get_mouse_camera_player_move_reverse_horizontal() -> bool: + return mouse_camera_player_move_reverse_horizontal + + +func get_mouse_camera_player_move_reverse_vertical() -> bool: + return mouse_camera_player_move_reverse_vertical + + +func get_mul_mouse_camera_player_reverse_horizontal() -> float: + if mouse_camera_player_reverse_horizontal: + return -1.0 + else: + return 1.0 + + +func get_mul_mouse_camera_player_reverse_vertical() -> float: + if mouse_camera_player_reverse_vertical: + return -1.0 + else: + return 1.0 + + +func get_mul_mouse_camera_only_reverse_horizontal() -> float: + if mouse_camera_only_reverse_horizontal: + return -1.0 + else: + return 1.0 + + +func get_mul_mouse_camera_only_reverse_vertical() -> float: + if mouse_camera_only_reverse_vertical: + return -1.0 + else: + return 1.0 + + +func get_mul_mouse_camera_player_move_reverse_horizontal() -> float: + if mouse_camera_player_move_reverse_horizontal: + return -1.0 + else: + return 1.0 + + +func get_mul_mouse_camera_player_move_reverse_vertical() -> float: + if mouse_camera_player_move_reverse_vertical: + return -1.0 + else: + return 1.0