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 98aaafe..4a0b840 100644 Binary files a/resource/ui/icon/input/input_map.png and b/resource/ui/icon/input/input_map.png differ diff --git a/scene/ui/hud_screen.tscn b/scene/ui/hud_screen.tscn index bc0576d..33abbdc 100644 --- a/scene/ui/hud_screen.tscn +++ b/scene/ui/hud_screen.tscn @@ -343,14 +343,20 @@ offset_left = 16.0 offset_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