diff --git a/src/builtin/locale/en.json b/src/builtin/locale/en.json index 436e674..44dd374 100644 --- a/src/builtin/locale/en.json +++ b/src/builtin/locale/en.json @@ -114,6 +114,8 @@ "soundtrack": "Soundtrack: {soundtrack}" }, + "controls": "Controls...", + "language": "Language...", "behavior": "Behavior...", @@ -125,6 +127,38 @@ }, "pause_on_focus_loss": "Pause on focus loss:" } + }, + + "controls_menu": { + "select_player": { + "entry": "Select player:", + "player_1": "Player 1", + "player_2": "Player 2" + }, + "controller": { + "entry": "Controller:", + "keyboard": "Keyboard" + }, + "rebind": "Rebind...", + "rebind_menu": { + "up": "Up", + "down": "Down", + "left": "Left", + "right": "Right", + "jump": "Jump", + "shoot": "Shoot", + "prev_weapon": "Previous weapon", + "next_weapon": "Next weapon", + "inventory": "Inventory", + "map": "Map system", + "skip": "Skip", + "strafe": "Strafe" + }, + + "rebind_confirm_menu": { + "title": "Press button for \"{control}\"", + "cancel": "(Esc to cancel)" + } } }, diff --git a/src/builtin/locale/jp.json b/src/builtin/locale/jp.json index c09947e..471065d 100644 --- a/src/builtin/locale/jp.json +++ b/src/builtin/locale/jp.json @@ -106,6 +106,8 @@ "soundtrack": "サウンドトラック: {soundtrack}" }, + "controls": "ボタン変更", + "language": "言語", "behavior": "動作", @@ -117,8 +119,41 @@ }, "pause_on_focus_loss": "フォーカスが外れた時のポーズ:" } + }, + + "controls_menu": { + "select_player": { + "entry": "プレイヤーを選択:", + "player_1": "プレーヤー 1", + "player_2": "プレーヤー 2" + }, + "controller": { + "entry": "コントローラ:", + "keyboard": "キーボード" + }, + "rebind": "再バインド", + "rebind_menu": { + "up": "うえ", + "down": "した", + "left": "ひだり", + "right": "みぎ", + "jump": "ジャンプ", + "shoot": "ショット", + "prev_weapon": "前の武器", + "next_weapon": "次の武器", + "inventory": "在庫", + "map": "マップシステム", + "skip": "スキップ", + "strafe": "ストレイフ" + }, + + "rebind_confirm_menu": { + "title": "新しい「ジャンプ」ボタンを押す", + "cancel": "(Escキーを押してキャンセル)" + } } }, + "soundtrack": { "organya": "オルガーニャ", "remastered": "リマスター", diff --git a/src/framework/gamepad.rs b/src/framework/gamepad.rs index 7822568..058a819 100644 --- a/src/framework/gamepad.rs +++ b/src/framework/gamepad.rs @@ -33,6 +33,26 @@ pub enum AxisDirection { } impl AxisDirection { + pub fn from_axis_data(axis: Axis, value: f64) -> Self { + match axis { + Axis::LeftX | Axis::RightX => { + if value < 0.0 { + AxisDirection::Left + } else { + AxisDirection::Right + } + } + Axis::LeftY | Axis::RightY => { + if value < 0.0 { + AxisDirection::Up + } else { + AxisDirection::Down + } + } + Axis::TriggerLeft | Axis::TriggerRight => AxisDirection::Either, + } + } + pub fn compare(&self, value: f64, axis_sensitivity: f64) -> bool { match self { AxisDirection::None => false, @@ -143,6 +163,26 @@ impl GamepadData { 1 } + + pub fn get_gamepad_name(&self) -> String { + let name = if let Some(controller_type) = self.controller_type { + match controller_type { + sdl2_sys::SDL_GameControllerType::SDL_CONTROLLER_TYPE_PS3 + | sdl2_sys::SDL_GameControllerType::SDL_CONTROLLER_TYPE_PS4 + | sdl2_sys::SDL_GameControllerType::SDL_CONTROLLER_TYPE_PS5 => "PlayStation Controller".to_string(), + sdl2_sys::SDL_GameControllerType::SDL_CONTROLLER_TYPE_XBOX360 + | sdl2_sys::SDL_GameControllerType::SDL_CONTROLLER_TYPE_XBOXONE => "Xbox Controller".to_string(), + sdl2_sys::SDL_GameControllerType::SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO => { + "Nintendo Switch Controller".to_string() + } + _ => "Unknown Controller".to_string(), + } + } else { + "Unknown controller".to_string() + }; + + name + } } pub struct GamepadContext { @@ -258,6 +298,28 @@ impl GamepadContext { } } } + + pub(crate) fn get_gamepads(&self) -> &Vec { + &self.gamepads + } + + pub(crate) fn pressed_buttons(&self, gamepad_index: u32) -> HashSet