From 2b2f80907a863f7961cd89db7301a8cd64300013 Mon Sep 17 00:00:00 2001 From: chendian <-> Date: Thu, 27 Feb 2025 04:26:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=89=E9=94=AE=E6=98=A0=E5=B0=84=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project.godot | 12 ++- resource/ui/icon/input/input_map.png | Bin 2547 -> 2432 bytes scene/ui/hud_screen.tscn | 6 ++ script/_global/enum.gd | 1 + script/_global/global.gd | 1 + script/manager/input_manager.gd | 18 ++++- script/manager/signal_manager.gd | 2 + script/ui/hud/input_item.gd | 107 ++++++++++++++++++++++++++- 8 files changed, 141 insertions(+), 6 deletions(-) diff --git a/project.godot b/project.godot index 1c2f674..3cb45f8 100644 --- a/project.godot +++ b/project.godot @@ -156,13 +156,13 @@ jump={ flash={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194325,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) -, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":9,"pressure":0.0,"pressed":true,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":1,"pressure":0.0,"pressed":true,"script":null) ] } lock={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":76,"key_label":0,"unicode":108,"location":0,"echo":false,"script":null) -, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":5,"axis_value":1.0,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":4,"axis_value":1.0,"script":null) ] } weapon_pre={ @@ -173,7 +173,7 @@ weapon_pre={ weapon_next={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"location":0,"echo":false,"script":null) -, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":10,"pressure":0.0,"pressed":true,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":5,"axis_value":1.0,"script":null) ] } menu={ @@ -191,7 +191,7 @@ status={ switch={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194326,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) -, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":4,"axis_value":1.0,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":10,"pressure":0.0,"pressed":true,"script":null) ] } interact={ @@ -203,21 +203,25 @@ interact={ skill1={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":49,"key_label":0,"unicode":49,"location":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":11,"pressure":0.0,"pressed":true,"script":null) ] } skill2={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":50,"key_label":0,"unicode":50,"location":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":13,"pressure":0.0,"pressed":true,"script":null) ] } skill3={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":51,"key_label":0,"unicode":51,"location":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":12,"pressure":0.0,"pressed":true,"script":null) ] } skill4={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":52,"key_label":0,"unicode":52,"location":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":14,"pressure":0.0,"pressed":true,"script":null) ] } test_1={ diff --git a/resource/ui/icon/input/input_map.png b/resource/ui/icon/input/input_map.png index 98aaafe89fbc14a1edd3e145e55992503f8e7aea..4a0b84077865e4a0ee238eb267166ad5c1d0093f 100644 GIT binary patch delta 2405 zcmV-r37Yov6Mz$tG=DcqL_t(|ob8>@Y8*!p#%qP%K|!F`@GZU>T_WFnGYJCu;yi(Z zAqY(J1j$7LVdGnFu`i2n$xW|eF!oby4yHG~HPwHrt9NQ<=lg;2u4cZj-u^Q^v-{Ny z5daHj42r{OM^IYeRI1r32JmwkX{-?zXAvu0n7HV}7y&k0x?JEmpqSjz}{X%fU7g%{EhEdCb?3^Rxq z#Ajg`{QPyTp6J`44+B3;iW+@9@cH1c(Z>Uy4}M8sbAJRabp+oxr%io^6hT`XKi;oa z%iAD~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_top = 16.0 offset_right = -16.0 offset_bottom = -16.0 +grow_horizontal = 2 +grow_vertical = 2 [node name="Up" parent="HudPage/CoreItem/CoreItemInput" instance=ExtResource("18_1ymc1")] +input_action = "attack_heavy" [node name="Left" parent="HudPage/CoreItem/CoreItemInput" instance=ExtResource("18_1ymc1")] +input_action = "attack_light" [node name="Down" parent="HudPage/CoreItem/CoreItemInput" instance=ExtResource("18_1ymc1")] +input_action = "jump" [node name="Right" parent="HudPage/CoreItem/CoreItemInput" instance=ExtResource("18_1ymc1")] +input_action = "interact" [node name="HeadBarPage" type="Control" parent="."] layout_mode = 3 diff --git a/script/_global/enum.gd b/script/_global/enum.gd index 61ea629..72485ba 100644 --- a/script/_global/enum.gd +++ b/script/_global/enum.gd @@ -24,3 +24,4 @@ enum EAIRoleType {None, Saber, Assassin, Caster} enum ESkillWarnType {None, Normal, Mid, Heavy} enum EMaterial {None, Cloth, Steel} enum EPtType {HP, MP, Money} +enum EControllerType {Keyboard, Joypad} diff --git a/script/_global/global.gd b/script/_global/global.gd index 26f3d4f..19e7202 100644 --- a/script/_global/global.gd +++ b/script/_global/global.gd @@ -10,3 +10,4 @@ var effect_mgr: EffectManager #全局状态 var is_level_loading: bool var is_control_pause: bool +var controller_type: Enum.EControllerType = Enum.EControllerType.Joypad diff --git a/script/manager/input_manager.gd b/script/manager/input_manager.gd index 98cd24b..7d8ab07 100644 --- a/script/manager/input_manager.gd +++ b/script/manager/input_manager.gd @@ -2,6 +2,16 @@ extends Node3D func _input(event) -> void: if !event.is_action_type(): return + if event is InputEventKey: + if not Global.controller_type == Enum.EControllerType.Keyboard: + Global.controller_type = Enum.EControllerType.Keyboard + SignalManager.input_device_change.emit() + elif event is InputEventJoypadButton or event is InputEventJoypadMotion: + if not Global.controller_type == Enum.EControllerType.Joypad: + Global.controller_type = Enum.EControllerType.Joypad + SignalManager.input_device_change.emit() + else: + return for action_name in InputMap.get_actions(): if event.is_action_pressed(action_name): @@ -9,4 +19,10 @@ func _input(event) -> void: elif event.is_action_released(action_name): SignalManager.input_action_released.emit(action_name) var input_dir: Vector2 = Input.get_vector("move_left", "move_right", "move_up", "move_down") - SignalManager.input_action_move.emit(input_dir) + # 限定为8方向 + if input_dir.length() > 0: + # 计算角度并将其限制为45度的倍数 + var angle = input_dir.angle() + var snapped_angle = round(angle / (PI / 4)) * (PI / 4) + input_dir = Vector2(cos(snapped_angle), sin(snapped_angle)) + SignalManager.input_action_move.emit(input_dir) \ No newline at end of file diff --git a/script/manager/signal_manager.gd b/script/manager/signal_manager.gd index 343be47..7972eb0 100644 --- a/script/manager/signal_manager.gd +++ b/script/manager/signal_manager.gd @@ -21,3 +21,5 @@ signal level_size_change signal level_pos_change signal level_loading_start signal level_loading_end +#input +signal input_device_change diff --git a/script/ui/hud/input_item.gd b/script/ui/hud/input_item.gd index f60e874..1bc440f 100644 --- a/script/ui/hud/input_item.gd +++ b/script/ui/hud/input_item.gd @@ -2,8 +2,113 @@ extends Sprite2D class_name InputItem +@export var input_action: String: + set(value): + input_action = value + _on_input_action_set() @export var detail_rate: float: set(value): detail_rate = value - modulate.a = value \ No newline at end of file + modulate.a = value + +func _ready() -> void: + SignalManager.input_device_change.connect(_on_input_device_change) + +func _on_input_device_change() -> void: + _on_input_action_set() + +func _on_input_action_set(): + var actions = InputMap.get_actions() + for action in actions: + if not action == input_action: + continue + var events = InputMap.action_get_events(action) + for event in events: + if event is InputEventJoypadButton: + if not Global.controller_type == Enum.EControllerType.Joypad: + continue + match event.button_index: + JOY_BUTTON_A: frame = 1 + JOY_BUTTON_B: frame = 2 + JOY_BUTTON_X: frame = 3 + JOY_BUTTON_Y: frame = 4 + JOY_BUTTON_LEFT_STICK: frame = 5 + JOY_BUTTON_RIGHT_STICK: frame = 6 + JOY_BUTTON_LEFT_SHOULDER: frame = 7 + JOY_BUTTON_RIGHT_SHOULDER: frame = 8 + JOY_BUTTON_BACK: frame = 9 + JOY_BUTTON_START: frame = 10 + JOY_BUTTON_GUIDE: frame = 11 + _: continue + return + elif event is InputEventKey: + if not Global.controller_type == Enum.EControllerType.Keyboard: + continue + match event.physical_keycode: + KEY_F1: frame = 12 + KEY_F2: frame = 13 + KEY_F3: frame = 14 + KEY_F4: frame = 15 + KEY_F5: frame = 16 + KEY_F6: frame = 17 + KEY_F7: frame = 18 + KEY_F8: frame = 19 + KEY_F9: frame = 20 + KEY_F10: frame = 21 + KEY_F11: frame = 22 + KEY_F12: frame = 23 + KEY_QUOTELEFT: frame = 24 + KEY_1: frame = 25 + KEY_2: frame = 26 + KEY_3: frame = 27 + KEY_4: frame = 28 + KEY_5: frame = 29 + KEY_6: frame = 30 + KEY_7: frame = 31 + KEY_8: frame = 32 + KEY_9: frame = 33 + KEY_0: frame = 34 + KEY_TAB: frame = 36 + KEY_Q: frame = 37 + KEY_W: frame = 38 + KEY_E: frame = 39 + KEY_R: frame = 40 + KEY_T: frame = 41 + KEY_Y: frame = 42 + KEY_U: frame = 43 + KEY_I: frame = 44 + KEY_O: frame = 45 + KEY_P: frame = 46 + KEY_CAPSLOCK: frame = 48 + KEY_A: frame = 49 + KEY_S: frame = 50 + KEY_D: frame = 51 + KEY_F: frame = 52 + KEY_G: frame = 53 + KEY_H: frame = 54 + KEY_J: frame = 55 + KEY_K: frame = 56 + KEY_L: frame = 57 + KEY_SHIFT: frame = 60 + KEY_Z: frame = 61 + KEY_X: frame = 62 + KEY_C: frame = 63 + KEY_V: frame = 64 + KEY_B: frame = 65 + KEY_N: frame = 66 + KEY_M: frame = 67 + KEY_CTRL: frame = 72 + KEY_ALT: frame = 73 + KEY_SPACE: frame = 74 + KEY_UP: frame = 75 + KEY_DOWN: frame = 76 + KEY_LEFT: frame = 77 + KEY_RIGHT: frame = 78 + KEY_ESCAPE: frame = 79 + KEY_ENTER: frame = 80 + _: continue + return + else: + break + frame = 0 \ No newline at end of file