From 878665391e7e8b78e2c73d7b49fc5c1f952350e3 Mon Sep 17 00:00:00 2001 From: TrialTemp Date: Tue, 9 Jan 2024 18:54:00 -0600 Subject: [PATCH 01/10] The reset. --- src/assets/ba_data/python/baclassic/_input.py | 7 +- .../ba_data/python/baclassic/_subsystem.py | 4 +- .../python/bauiv1lib/settings/gamepad.py | 210 +++++++++++------- .../python/bauiv1lib/settings/keyboard.py | 79 +++++-- 4 files changed, 192 insertions(+), 108 deletions(-) diff --git a/src/assets/ba_data/python/baclassic/_input.py b/src/assets/ba_data/python/baclassic/_input.py index 5c934c32..7c813401 100644 --- a/src/assets/ba_data/python/baclassic/_input.py +++ b/src/assets/ba_data/python/baclassic/_input.py @@ -13,7 +13,7 @@ if TYPE_CHECKING: def get_input_device_mapped_value( - devicename: str, unique_id: str, name: str + devicename: str, unique_id: str, name: str, default: bool = False, ) -> Any: """Returns a mapped value for an input device. @@ -30,8 +30,9 @@ def get_input_device_mapped_value( subplatform = app.classic.subplatform appconfig = babase.app.config - # If there's an entry in our config for this controller, use it. - if 'Controllers' in appconfig: + # If there's an entry in our config for this controller and + # we're not looking for our default mappings, use it. + if 'Controllers' in appconfig and not default: ccfgs = appconfig['Controllers'] if devicename in ccfgs: mapping = None diff --git a/src/assets/ba_data/python/baclassic/_subsystem.py b/src/assets/ba_data/python/baclassic/_subsystem.py index 755c4dd8..38f35d1d 100644 --- a/src/assets/ba_data/python/baclassic/_subsystem.py +++ b/src/assets/ba_data/python/baclassic/_subsystem.py @@ -570,7 +570,7 @@ class ClassicSubsystem(babase.AppSubsystem): ) def get_input_device_mapped_value( - self, device: bascenev1.InputDevice, name: str + self, device: bascenev1.InputDevice, name: str, default: bool = False, ) -> Any: """Returns a mapped value for an input device. @@ -578,7 +578,7 @@ class ClassicSubsystem(babase.AppSubsystem): where available. """ return _input.get_input_device_mapped_value( - device.name, device.unique_identifier, name + device.name, device.unique_identifier, name, default ) def get_input_device_map_hash( diff --git a/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py b/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py index a63847d4..cc9fba7e 100644 --- a/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py +++ b/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py @@ -43,7 +43,7 @@ class GamepadSettingsWindow(bui.Window): self._is_main_menu = is_main_menu self._displayname = self._name self._width = 700 if self._is_secondary else 730 - self._height = 440 if self._is_secondary else 450 + self._height = 440 if self._is_secondary else 490 self._spacing = 40 assert bui.app.classic is not None uiscale = bui.app.ui_v1.uiscale @@ -64,10 +64,79 @@ class GamepadSettingsWindow(bui.Window): ) ) + self._settings: dict[str, int] = {} + if not self._is_secondary: + self._get_config_mapping() # Don't ask to config joysticks while we're in here. self._rebuild_ui() - def _rebuild_ui(self) -> None: + def _get_config_mapping(self, default: bool = False) -> None: + for button in [ + 'buttonJump', + 'buttonJump_B', + 'buttonPunch', + 'buttonPunch_B', + 'buttonBomb', + 'buttonBomb_B', + 'buttonPickUp', + 'buttonPickUp_B', + 'buttonStart', + 'buttonStart_B', + 'buttonStart2', + 'buttonStart2_B', + 'buttonUp', + 'buttonUp_B', + 'buttonDown', + 'buttonDown_B', + 'buttonLeft', + 'buttonLeft_B', + 'buttonRight', + 'buttonRight_B', + 'buttonRun1', + 'buttonRun1_B', + 'buttonRun2', + 'buttonRun2_B', + 'triggerRun1', + 'triggerRun1_B', + 'triggerRun2', + 'triggerRun2_B', + 'buttonIgnored', + 'buttonIgnored_B', + 'buttonIgnored2', + 'buttonIgnored2_B', + 'buttonIgnored3', + 'buttonIgnored3_B', + 'buttonIgnored4', + 'buttonIgnored4_B', + 'buttonVRReorient', + 'buttonVRReorient_B', + 'analogStickDeadZone', + 'analogStickDeadZone_B', + 'dpad', + 'dpad_B', + 'unassignedButtonsRun', + 'unassignedButtonsRun_B', + 'startButtonActivatesDefaultWidget', + 'startButtonActivatesDefaultWidget_B', + 'uiOnly', + 'uiOnly_B', + 'ignoreCompletely', + 'ignoreCompletely_B', + 'autoRecalibrateAnalogStick', + 'autoRecalibrateAnalogStick_B', + 'analogStickLR', + 'analogStickLR_B', + 'analogStickUD', + 'analogStickUD_B', + 'enableSecondary', + ]: + val = bui.app.classic.get_input_device_mapped_value( + self._input, button, default + ) + if val != -1: + self._settings[button] = val + + def _rebuild_ui(self, reset: bool = False) -> None: # pylint: disable=too-many-statements # pylint: disable=too-many-locals @@ -79,77 +148,6 @@ class GamepadSettingsWindow(bui.Window): self._textwidgets: dict[str, bui.Widget] = {} - # If we were supplied with settings, we're a secondary joystick and - # just operate on that. in the other (normal) case we make our own. - if not self._is_secondary: - # Fill our temp config with present values (for our primary and - # secondary controls). - self._settings = {} - for skey in [ - 'buttonJump', - 'buttonJump_B', - 'buttonPunch', - 'buttonPunch_B', - 'buttonBomb', - 'buttonBomb_B', - 'buttonPickUp', - 'buttonPickUp_B', - 'buttonStart', - 'buttonStart_B', - 'buttonStart2', - 'buttonStart2_B', - 'buttonUp', - 'buttonUp_B', - 'buttonDown', - 'buttonDown_B', - 'buttonLeft', - 'buttonLeft_B', - 'buttonRight', - 'buttonRight_B', - 'buttonRun1', - 'buttonRun1_B', - 'buttonRun2', - 'buttonRun2_B', - 'triggerRun1', - 'triggerRun1_B', - 'triggerRun2', - 'triggerRun2_B', - 'buttonIgnored', - 'buttonIgnored_B', - 'buttonIgnored2', - 'buttonIgnored2_B', - 'buttonIgnored3', - 'buttonIgnored3_B', - 'buttonIgnored4', - 'buttonIgnored4_B', - 'buttonVRReorient', - 'buttonVRReorient_B', - 'analogStickDeadZone', - 'analogStickDeadZone_B', - 'dpad', - 'dpad_B', - 'unassignedButtonsRun', - 'unassignedButtonsRun_B', - 'startButtonActivatesDefaultWidget', - 'startButtonActivatesDefaultWidget_B', - 'uiOnly', - 'uiOnly_B', - 'ignoreCompletely', - 'ignoreCompletely_B', - 'autoRecalibrateAnalogStick', - 'autoRecalibrateAnalogStick_B', - 'analogStickLR', - 'analogStickLR_B', - 'analogStickUD', - 'analogStickUD_B', - 'enableSecondary', - ]: - val = bui.app.classic.get_input_device_mapped_value( - self._input, skey - ) - if val != -1: - self._settings[skey] = val - back_button: bui.Widget | None if self._is_secondary: @@ -171,7 +169,7 @@ class GamepadSettingsWindow(bui.Window): else: cancel_button = bui.buttonwidget( parent=self._root_widget, - position=(51, self._height - 65), + position=(51, self._height - 115), autoselect=True, size=(160, 60), label=bui.Lstr(resource='cancelText'), @@ -181,12 +179,27 @@ class GamepadSettingsWindow(bui.Window): bui.containerwidget( edit=self._root_widget, cancel_button=cancel_button ) - + reset_button: bui.Widget | None + if not self._is_secondary: + reset_button = bui.buttonwidget( + parent=self._root_widget, + autoselect=True, + position=((self._width / 2) - 80, self._height - 115), + size=(180, 60), + label=bui.Lstr(resource='settingsWindowAdvanced.resetText'), + scale=0.9, + text_scale=0.9, + color=(0.4, 0.4, 0.9), + textcolor=(1.0, 1.0, 1.0), + on_activate_call=self._reset, + ) + if reset: + bui.containerwidget(edit=self._root_widget, selected_child=reset_button) save_button: bui.Widget | None if not self._is_secondary: save_button = bui.buttonwidget( parent=self._root_widget, - position=(self._width - 195, self._height - 65), + position=(self._width - 195, self._height - 115), size=(180, 60), autoselect=True, label=bui.Lstr(resource='saveText'), @@ -203,7 +216,7 @@ class GamepadSettingsWindow(bui.Window): v = self._height - 59 bui.textwidget( parent=self._root_widget, - position=(0, v + 5), + position=(0, v + 10), size=(self._width, 25), text=bui.Lstr(resource=self._r + '.titleText'), color=bui.app.ui_v1.title_color, @@ -211,11 +224,11 @@ class GamepadSettingsWindow(bui.Window): h_align='center', v_align='center', ) - v -= 48 + v -= 95 bui.textwidget( parent=self._root_widget, - position=(0, v + 3), + position=(0, v - 5), size=(self._width, 25), text=self._name, color=bui.app.ui_v1.infotextcolor, @@ -227,7 +240,7 @@ class GamepadSettingsWindow(bui.Window): bui.textwidget( parent=self._root_widget, - position=(50, v + 10), + position=(50, v + 5), size=(self._width - 100, 30), text=bui.Lstr(resource=self._r + '.appliesToAllText'), maxwidth=330, @@ -382,9 +395,19 @@ class GamepadSettingsWindow(bui.Window): ) try: - if cancel_button is not None and save_button is not None: - bui.widget(edit=cancel_button, right_widget=save_button) - bui.widget(edit=save_button, left_widget=cancel_button) + bui.widget( + edit=cancel_button, + right_widget=reset_button if reset_button else save_button if save_button else None + ) + bui.widget( + edit=reset_button, + left_widget=cancel_button if cancel_button else None, + right_widget=save_button if save_button else None, + ) + bui.widget( + edit=save_button, + left_widget=reset_button if reset_button else cancel_button if cancel_button else None + ) except Exception: logging.exception('Error wiring up gamepad config window.') @@ -808,6 +831,27 @@ class GamepadSettingsWindow(bui.Window): ControlsSettingsWindow(transition='in_left').get_root_widget(), from_window=self._root_widget, ) + + def _reset(self) -> None: + from bauiv1lib.confirm import ConfirmWindow + + assert bui.app.classic is not None + ConfirmWindow( + # TODO: Implement a translation string for this! + 'Are you sure you want to reset your button mapping?\n' + '(This will include your advanced settings)', + self._do_reset, + width=480, + height=110, + ) + + def _do_reset(self) -> None: + """Resets the input's mapping settings.""" + self._settings: dict[str, int] = {} + self._get_config_mapping(default=True) + self._rebuild_ui(reset=True) + bui.getsound('gunCocking').play() + def _save(self) -> None: classic = bui.app.classic diff --git a/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py b/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py index 1e564378..130576db 100644 --- a/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py +++ b/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py @@ -27,9 +27,10 @@ class ConfigKeyboardWindow(bui.Window): self._displayname = bui.Lstr(translate=('inputDeviceNames', dname_raw)) self._width = 700 if self._unique_id != '#1': - self._height = 480 + self._height = 490 else: self._height = 375 + self._height += 45 self._spacing = 40 assert bui.app.classic is not None uiscale = bui.app.ui_v1.uiscale @@ -47,17 +48,13 @@ class ConfigKeyboardWindow(bui.Window): transition=transition, ) ) - + + self._settings: dict[str, int] = {} + self._get_config_mapping() + self._rebuild_ui() - def _rebuild_ui(self) -> None: - assert bui.app.classic is not None - - for widget in self._root_widget.get_children(): - widget.delete() - - # Fill our temp config with present values. - self._settings: dict[str, int] = {} + def _get_config_mapping(self, default: bool = False): for button in [ 'buttonJump', 'buttonPunch', @@ -73,22 +70,43 @@ class ConfigKeyboardWindow(bui.Window): self._settings[ button ] = bui.app.classic.get_input_device_mapped_value( - self._input, button + self._input, button, default ) + def _rebuild_ui(self, reset: bool = False) -> None: + assert bui.app.classic is not None + + for widget in self._root_widget.get_children(): + widget.delete() + + b_off = 0 if self._unique_id != '#1' else 9 cancel_button = bui.buttonwidget( parent=self._root_widget, autoselect=True, - position=(38, self._height - 85), + position=(38, self._height - 115 - b_off), size=(170, 60), label=bui.Lstr(resource='cancelText'), scale=0.9, on_activate_call=self._cancel, ) + reset_button = bui.buttonwidget( + parent=self._root_widget, + autoselect=True, + position=((self._width / 2) - 80, self._height - 115 - b_off), + size=(180, 60), + label=bui.Lstr(resource='settingsWindowAdvanced.resetText'), + scale=0.9, + text_scale=0.9, + color=(0.4, 0.4, 0.9), + textcolor=(1.0, 1.0, 1.0), + on_activate_call=self._reset, + ) + if reset: + bui.containerwidget(edit=self._root_widget, selected_child=reset_button) save_button = bui.buttonwidget( parent=self._root_widget, autoselect=True, - position=(self._width - 190, self._height - 85), + position=(self._width - 190, self._height - 115 - b_off), size=(180, 60), label=bui.Lstr(resource='saveText'), scale=0.9, @@ -101,13 +119,15 @@ class ConfigKeyboardWindow(bui.Window): start_button=save_button, ) - bui.widget(edit=cancel_button, right_widget=save_button) - bui.widget(edit=save_button, left_widget=cancel_button) + bui.widget(edit=cancel_button, right_widget=reset_button) + bui.widget(edit=reset_button, left_widget=cancel_button, right_widget=save_button) + bui.widget(edit=save_button, left_widget=reset_button) v = self._height - 74.0 + t_off = 0 if self._unique_id != '#1' else -10 bui.textwidget( parent=self._root_widget, - position=(self._width * 0.5, v + 15), + position=(self._width * 0.5, v + 41 + t_off), size=(0, 0), text=bui.Lstr( resource=self._r + '.configuringText', @@ -117,12 +137,12 @@ class ConfigKeyboardWindow(bui.Window): h_align='center', v_align='center', maxwidth=270, - scale=0.83, + scale=0.99, ) v -= 20 if self._unique_id != '#1': - v -= 20 + v -= 60 v -= self._spacing bui.textwidget( parent=self._root_widget, @@ -140,9 +160,9 @@ class ConfigKeyboardWindow(bui.Window): v -= 10 v -= self._spacing * 2.2 v += 25 - v -= 42 + v -= 45 if self._unique_id != '#1' else 86 h_offs = 160 - dist = 70 + dist = 68 d_color = (0.4, 0.4, 0.8) self._capture_button( pos=(h_offs, v + 0.95 * dist), @@ -282,6 +302,25 @@ class ConfigKeyboardWindow(bui.Window): from_window=self._root_widget, ) + def _reset(self) -> None: + from bauiv1lib.confirm import ConfirmWindow + + assert bui.app.classic is not None + ConfirmWindow( + # TODO: Implement a translation string for this! + 'Are you sure you want to reset your button mapping?', + self._do_reset, + width=480, + height=95, + ) + + def _do_reset(self) -> None: + """Resets the input's mapping settings.""" + self._settings: dict[str, int] = {} + self._get_config_mapping(default=True) + self._rebuild_ui(reset=True) + bui.getsound('gunCocking').play() + def _save(self) -> None: from bauiv1lib.settings.controls import ControlsSettingsWindow From 64743e26020b9d6c5ef7f5f3a40668f15bd41d90 Mon Sep 17 00:00:00 2001 From: TrialTemp Date: Tue, 9 Jan 2024 18:56:37 -0600 Subject: [PATCH 02/10] preflight.jpeg --- src/assets/ba_data/python/baclassic/_input.py | 5 +++- .../ba_data/python/baclassic/_subsystem.py | 5 +++- .../python/bauiv1lib/settings/gamepad.py | 23 +++++++++++++------ .../python/bauiv1lib/settings/keyboard.py | 16 +++++++++---- 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/assets/ba_data/python/baclassic/_input.py b/src/assets/ba_data/python/baclassic/_input.py index 7c813401..0effcb5b 100644 --- a/src/assets/ba_data/python/baclassic/_input.py +++ b/src/assets/ba_data/python/baclassic/_input.py @@ -13,7 +13,10 @@ if TYPE_CHECKING: def get_input_device_mapped_value( - devicename: str, unique_id: str, name: str, default: bool = False, + devicename: str, + unique_id: str, + name: str, + default: bool = False, ) -> Any: """Returns a mapped value for an input device. diff --git a/src/assets/ba_data/python/baclassic/_subsystem.py b/src/assets/ba_data/python/baclassic/_subsystem.py index 38f35d1d..c9a4cda8 100644 --- a/src/assets/ba_data/python/baclassic/_subsystem.py +++ b/src/assets/ba_data/python/baclassic/_subsystem.py @@ -570,7 +570,10 @@ class ClassicSubsystem(babase.AppSubsystem): ) def get_input_device_mapped_value( - self, device: bascenev1.InputDevice, name: str, default: bool = False, + self, + device: bascenev1.InputDevice, + name: str, + default: bool = False, ) -> Any: """Returns a mapped value for an input device. diff --git a/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py b/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py index cc9fba7e..95b0247e 100644 --- a/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py +++ b/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py @@ -194,7 +194,9 @@ class GamepadSettingsWindow(bui.Window): on_activate_call=self._reset, ) if reset: - bui.containerwidget(edit=self._root_widget, selected_child=reset_button) + bui.containerwidget( + edit=self._root_widget, selected_child=reset_button + ) save_button: bui.Widget | None if not self._is_secondary: save_button = bui.buttonwidget( @@ -397,8 +399,12 @@ class GamepadSettingsWindow(bui.Window): try: bui.widget( edit=cancel_button, - right_widget=reset_button if reset_button else save_button if save_button else None - ) + right_widget=reset_button + if reset_button + else save_button + if save_button + else None, + ) bui.widget( edit=reset_button, left_widget=cancel_button if cancel_button else None, @@ -406,7 +412,11 @@ class GamepadSettingsWindow(bui.Window): ) bui.widget( edit=save_button, - left_widget=reset_button if reset_button else cancel_button if cancel_button else None + left_widget=reset_button + if reset_button + else cancel_button + if cancel_button + else None, ) except Exception: logging.exception('Error wiring up gamepad config window.') @@ -831,7 +841,7 @@ class GamepadSettingsWindow(bui.Window): ControlsSettingsWindow(transition='in_left').get_root_widget(), from_window=self._root_widget, ) - + def _reset(self) -> None: from bauiv1lib.confirm import ConfirmWindow @@ -844,7 +854,7 @@ class GamepadSettingsWindow(bui.Window): width=480, height=110, ) - + def _do_reset(self) -> None: """Resets the input's mapping settings.""" self._settings: dict[str, int] = {} @@ -852,7 +862,6 @@ class GamepadSettingsWindow(bui.Window): self._rebuild_ui(reset=True) bui.getsound('gunCocking').play() - def _save(self) -> None: classic = bui.app.classic assert classic is not None diff --git a/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py b/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py index 130576db..7b237d5e 100644 --- a/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py +++ b/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py @@ -48,10 +48,10 @@ class ConfigKeyboardWindow(bui.Window): transition=transition, ) ) - + self._settings: dict[str, int] = {} self._get_config_mapping() - + self._rebuild_ui() def _get_config_mapping(self, default: bool = False): @@ -102,7 +102,9 @@ class ConfigKeyboardWindow(bui.Window): on_activate_call=self._reset, ) if reset: - bui.containerwidget(edit=self._root_widget, selected_child=reset_button) + bui.containerwidget( + edit=self._root_widget, selected_child=reset_button + ) save_button = bui.buttonwidget( parent=self._root_widget, autoselect=True, @@ -120,7 +122,11 @@ class ConfigKeyboardWindow(bui.Window): ) bui.widget(edit=cancel_button, right_widget=reset_button) - bui.widget(edit=reset_button, left_widget=cancel_button, right_widget=save_button) + bui.widget( + edit=reset_button, + left_widget=cancel_button, + right_widget=save_button, + ) bui.widget(edit=save_button, left_widget=reset_button) v = self._height - 74.0 @@ -313,7 +319,7 @@ class ConfigKeyboardWindow(bui.Window): width=480, height=95, ) - + def _do_reset(self) -> None: """Resets the input's mapping settings.""" self._settings: dict[str, int] = {} From f115c580ae84e411a785063cc59ade2831a5e4f3 Mon Sep 17 00:00:00 2001 From: TrialTemp Date: Tue, 9 Jan 2024 18:59:37 -0600 Subject: [PATCH 03/10] How many temps do you need to change a log --- CONTRIBUTORS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 8fccc544..7510d1dc 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -50,3 +50,6 @@ ### Rikko - Created the original "reject_recently_left_players" plugin + +### 3alTemp +- Bug Fixer & Modder \ No newline at end of file From 2655165296add4bac85a58d664b2869c23f6ba86 Mon Sep 17 00:00:00 2001 From: TrialTemp Date: Tue, 9 Jan 2024 19:22:01 -0600 Subject: [PATCH 04/10] =?UTF-8?q?log=20changed=20=F0=9F=8C=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1480580..d07555b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - Players now get points for killing bots with their own bombs by catching it and throwing it back at them. This is actually old logic but was disabled due to a logic flaw, but should be fixed now. (Thanks VinniTR!) +- Added a reset button in the input mapping menu. (Thanks Temp!) ### 1.7.32 (build 21741, api 8, 2023-12-20) - Fixed a screen message that no one will ever see (Thanks vishal332008?...) From 954364ee6fdf164efd66df3b817c9af514f117ac Mon Sep 17 00:00:00 2001 From: TrialTemp Date: Wed, 10 Jan 2024 14:36:25 -0600 Subject: [PATCH 05/10] made changelog consistent --- CONTRIBUTORS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 7510d1dc..626648a1 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -51,5 +51,5 @@ ### Rikko - Created the original "reject_recently_left_players" plugin -### 3alTemp -- Bug Fixer & Modder \ No newline at end of file +### Temp (3alTemp) +- Modder & Bug Fixer \ No newline at end of file From 4d6dc231c780f667811ef502f3f1305f84655179 Mon Sep 17 00:00:00 2001 From: 3alTemp Date: Fri, 1 Mar 2024 23:15:58 -0600 Subject: [PATCH 06/10] ... button --- .../python/bauiv1lib/settings/gamepad.py | 137 +++++++++++------- .../python/bauiv1lib/settings/keyboard.py | 106 +++++++++----- 2 files changed, 151 insertions(+), 92 deletions(-) diff --git a/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py b/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py index 95b0247e..c60a1bd0 100644 --- a/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py +++ b/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py @@ -1,5 +1,6 @@ # Released under the MIT License. See LICENSE for details. # +# pylint: disable=too-many-lines """Settings UI functionality related to gamepads.""" from __future__ import annotations @@ -12,7 +13,9 @@ import bauiv1 as bui if TYPE_CHECKING: from typing import Any, Callable + from bauiv1lib.popup import PopupWindow +from bauiv1lib.popup import PopupMenuWindow class GamepadSettingsWindow(bui.Window): """Window for configuring a gamepad.""" @@ -43,7 +46,7 @@ class GamepadSettingsWindow(bui.Window): self._is_main_menu = is_main_menu self._displayname = self._name self._width = 700 if self._is_secondary else 730 - self._height = 440 if self._is_secondary else 490 + self._height = 440 if self._is_secondary else 450 self._spacing = 40 assert bui.app.classic is not None uiscale = bui.app.ui_v1.uiscale @@ -136,7 +139,7 @@ class GamepadSettingsWindow(bui.Window): if val != -1: self._settings[button] = val - def _rebuild_ui(self, reset: bool = False) -> None: + def _rebuild_ui(self, is_reset: bool = False) -> None: # pylint: disable=too-many-statements # pylint: disable=too-many-locals @@ -169,7 +172,7 @@ class GamepadSettingsWindow(bui.Window): else: cancel_button = bui.buttonwidget( parent=self._root_widget, - position=(51, self._height - 115), + position=(51, self._height - 65), autoselect=True, size=(160, 60), label=bui.Lstr(resource='cancelText'), @@ -179,29 +182,12 @@ class GamepadSettingsWindow(bui.Window): bui.containerwidget( edit=self._root_widget, cancel_button=cancel_button ) - reset_button: bui.Widget | None - if not self._is_secondary: - reset_button = bui.buttonwidget( - parent=self._root_widget, - autoselect=True, - position=((self._width / 2) - 80, self._height - 115), - size=(180, 60), - label=bui.Lstr(resource='settingsWindowAdvanced.resetText'), - scale=0.9, - text_scale=0.9, - color=(0.4, 0.4, 0.9), - textcolor=(1.0, 1.0, 1.0), - on_activate_call=self._reset, - ) - if reset: - bui.containerwidget( - edit=self._root_widget, selected_child=reset_button - ) + save_button: bui.Widget | None if not self._is_secondary: save_button = bui.buttonwidget( parent=self._root_widget, - position=(self._width - 195, self._height - 115), + position=(self._width - 195, self._height - 65), size=(180, 60), autoselect=True, label=bui.Lstr(resource='saveText'), @@ -218,7 +204,7 @@ class GamepadSettingsWindow(bui.Window): v = self._height - 59 bui.textwidget( parent=self._root_widget, - position=(0, v + 10), + position=(0, v + 5), size=(self._width, 25), text=bui.Lstr(resource=self._r + '.titleText'), color=bui.app.ui_v1.title_color, @@ -226,11 +212,11 @@ class GamepadSettingsWindow(bui.Window): h_align='center', v_align='center', ) - v -= 95 + v -= 48 bui.textwidget( parent=self._root_widget, - position=(0, v - 5), + position=(0, v + 3), size=(self._width, 25), text=self._name, color=bui.app.ui_v1.infotextcolor, @@ -242,7 +228,7 @@ class GamepadSettingsWindow(bui.Window): bui.textwidget( parent=self._root_widget, - position=(50, v + 5), + position=(50, v + 10), size=(self._width - 100, 30), text=bui.Lstr(resource=self._r + '.appliesToAllText'), maxwidth=330, @@ -384,40 +370,27 @@ class GamepadSettingsWindow(bui.Window): scale=1.0, ) - self._advanced_button = bui.buttonwidget( + self._more_button = bui.buttonwidget( parent=self._root_widget, autoselect=True, - label=bui.Lstr(resource=self._r + '.advancedText'), + label='...', text_scale=0.9, color=(0.45, 0.4, 0.5), textcolor=(0.65, 0.6, 0.7), position=(self._width - 300, 30), size=(130, 40), - on_activate_call=self._do_advanced, + on_activate_call=self._do_more, ) try: - bui.widget( - edit=cancel_button, - right_widget=reset_button - if reset_button - else save_button - if save_button - else None, - ) - bui.widget( - edit=reset_button, - left_widget=cancel_button if cancel_button else None, - right_widget=save_button if save_button else None, - ) - bui.widget( - edit=save_button, - left_widget=reset_button - if reset_button - else cancel_button - if cancel_button - else None, - ) + if cancel_button is not None and save_button is not None: + bui.widget(edit=cancel_button, right_widget=save_button) + bui.widget(edit=save_button, left_widget=cancel_button) + if is_reset: + bui.containerwidget( + edit=self._root_widget, + selected_child=self._more_button, + ) except Exception: logging.exception('Error wiring up gamepad config window.') @@ -427,7 +400,7 @@ class GamepadSettingsWindow(bui.Window): def get_advanced_button(self) -> bui.Widget: """(internal)""" - return self._advanced_button + return self._more_button def get_is_secondary(self) -> bool: """(internal)""" @@ -849,19 +822,71 @@ class GamepadSettingsWindow(bui.Window): ConfirmWindow( # TODO: Implement a translation string for this! 'Are you sure you want to reset your button mapping?\n' - '(This will include your advanced settings)', + 'This will also reset your advanced mappings\n' + 'and secondary controller button mappings.', self._do_reset, - width=480, - height=110, + width=490, + height=150, ) def _do_reset(self) -> None: """Resets the input's mapping settings.""" + from babase import InputDeviceNotFoundError self._settings: dict[str, int] = {} - self._get_config_mapping(default=True) - self._rebuild_ui(reset=True) + # Unplugging the controller while performing a + # mapping reset makes things go bonkers a little. + try: + self._get_config_mapping(default=True) + except InputDeviceNotFoundError: + pass + + self._rebuild_ui(is_reset=True) bui.getsound('gunCocking').play() + def _do_more(self) -> None: + """Show a burger menu with extra settings.""" + # pylint: disable=cyclic-import + choices: list[str] = [ + 'advanced', + 'reset', + ] + choices_display: list[bui.Lstr] = [ + bui.Lstr(resource=self._r + '.advancedText'), + bui.Lstr(resource='settingsWindowAdvanced.resetText'), + ] + + uiscale = bui.app.ui_v1.uiscale + PopupMenuWindow( + position=self._more_button.get_screen_space_center(), + scale=( + 2.3 + if uiscale is bui.UIScale.SMALL + else 1.65 + if uiscale is bui.UIScale.MEDIUM + else 1.23 + ), + width=150, + choices=choices, + choices_display=choices_display, + current_choice='advanced', + delegate=self, + ) + + def popup_menu_selected_choice( + self, popup_window: PopupMenuWindow, choice: str + ) -> None: + """Called when a choice is selected in the popup.""" + del popup_window # unused + if choice == 'reset': + self._reset() + elif choice == 'advanced': + self._do_advanced() + else: + print(f'invalid choice: {choice}') + + def popup_menu_closing(self, popup_window: PopupWindow) -> None: + """Called when the popup is closing.""" + def _save(self) -> None: classic = bui.app.classic assert classic is not None diff --git a/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py b/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py index 7b237d5e..5126fe87 100644 --- a/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py +++ b/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py @@ -11,7 +11,9 @@ import bascenev1 as bs if TYPE_CHECKING: from typing import Any + from bauiv1lib.popup import PopupWindow +from bauiv1lib.popup import PopupMenuWindow class ConfigKeyboardWindow(bui.Window): """Window for configuring keyboards.""" @@ -27,10 +29,9 @@ class ConfigKeyboardWindow(bui.Window): self._displayname = bui.Lstr(translate=('inputDeviceNames', dname_raw)) self._width = 700 if self._unique_id != '#1': - self._height = 490 + self._height = 480 else: self._height = 375 - self._height += 45 self._spacing = 40 assert bui.app.classic is not None uiscale = bui.app.ui_v1.uiscale @@ -73,7 +74,7 @@ class ConfigKeyboardWindow(bui.Window): self._input, button, default ) - def _rebuild_ui(self, reset: bool = False) -> None: + def _rebuild_ui(self, is_reset: bool = False) -> None: assert bui.app.classic is not None for widget in self._root_widget.get_children(): @@ -83,32 +84,16 @@ class ConfigKeyboardWindow(bui.Window): cancel_button = bui.buttonwidget( parent=self._root_widget, autoselect=True, - position=(38, self._height - 115 - b_off), + position=(38, self._height - 85), size=(170, 60), label=bui.Lstr(resource='cancelText'), scale=0.9, on_activate_call=self._cancel, ) - reset_button = bui.buttonwidget( - parent=self._root_widget, - autoselect=True, - position=((self._width / 2) - 80, self._height - 115 - b_off), - size=(180, 60), - label=bui.Lstr(resource='settingsWindowAdvanced.resetText'), - scale=0.9, - text_scale=0.9, - color=(0.4, 0.4, 0.9), - textcolor=(1.0, 1.0, 1.0), - on_activate_call=self._reset, - ) - if reset: - bui.containerwidget( - edit=self._root_widget, selected_child=reset_button - ) save_button = bui.buttonwidget( parent=self._root_widget, autoselect=True, - position=(self._width - 190, self._height - 115 - b_off), + position=(self._width - 190, self._height - 85), size=(180, 60), label=bui.Lstr(resource='saveText'), scale=0.9, @@ -121,19 +106,10 @@ class ConfigKeyboardWindow(bui.Window): start_button=save_button, ) - bui.widget(edit=cancel_button, right_widget=reset_button) - bui.widget( - edit=reset_button, - left_widget=cancel_button, - right_widget=save_button, - ) - bui.widget(edit=save_button, left_widget=reset_button) - v = self._height - 74.0 - t_off = 0 if self._unique_id != '#1' else -10 bui.textwidget( parent=self._root_widget, - position=(self._width * 0.5, v + 41 + t_off), + position=(self._width * 0.5, v + 15), size=(0, 0), text=bui.Lstr( resource=self._r + '.configuringText', @@ -143,12 +119,12 @@ class ConfigKeyboardWindow(bui.Window): h_align='center', v_align='center', maxwidth=270, - scale=0.99, + scale=0.83, ) v -= 20 if self._unique_id != '#1': - v -= 60 + v -= 20 v -= self._spacing bui.textwidget( parent=self._root_widget, @@ -166,9 +142,9 @@ class ConfigKeyboardWindow(bui.Window): v -= 10 v -= self._spacing * 2.2 v += 25 - v -= 45 if self._unique_id != '#1' else 86 + v -= 42 h_offs = 160 - dist = 68 + dist = 70 d_color = (0.4, 0.4, 0.8) self._capture_button( pos=(h_offs, v + 0.95 * dist), @@ -239,6 +215,24 @@ class ConfigKeyboardWindow(bui.Window): scale=1.0, ) + self._more_button = bui.buttonwidget( + parent=self._root_widget, + autoselect=True, + label='...', + text_scale=0.9, + color=(0.45, 0.4, 0.5), + textcolor=(0.65, 0.6, 0.7), + position=(self._width * 0.5 - 65, 30), + size=(130, 40), + on_activate_call=self._do_more, + ) + + if is_reset: + bui.containerwidget( + edit=self._root_widget, + selected_child=self._more_button, + ) + def _pretty_button_name(self, button_name: str) -> bui.Lstr: button_id = self._settings[button_name] if button_id == -1: @@ -324,9 +318,49 @@ class ConfigKeyboardWindow(bui.Window): """Resets the input's mapping settings.""" self._settings: dict[str, int] = {} self._get_config_mapping(default=True) - self._rebuild_ui(reset=True) + self._rebuild_ui(is_reset=True) bui.getsound('gunCocking').play() + def _do_more(self) -> None: + """Show a burger menu with extra settings.""" + # pylint: disable=cyclic-import + choices: list[str] = [ + 'reset', + ] + choices_display: list[bui.Lstr] = [ + bui.Lstr(resource='settingsWindowAdvanced.resetText'), + ] + + uiscale = bui.app.ui_v1.uiscale + PopupMenuWindow( + position=self._more_button.get_screen_space_center(), + scale=( + 2.3 + if uiscale is bui.UIScale.SMALL + else 1.65 + if uiscale is bui.UIScale.MEDIUM + else 1.23 + ), + width=150, + choices=choices, + choices_display=choices_display, + current_choice='reset', + delegate=self, + ) + + def popup_menu_selected_choice( + self, popup_window: PopupMenuWindow, choice: str + ) -> None: + """Called when a choice is selected in the popup.""" + del popup_window # unused + if choice == 'reset': + self._reset() + else: + print(f'invalid choice: {choice}') + + def popup_menu_closing(self, popup_window: PopupWindow) -> None: + """Called when the popup is closing.""" + def _save(self) -> None: from bauiv1lib.settings.controls import ControlsSettingsWindow From cf78c23af95b84718891b517d4bcdee53505f7e0 Mon Sep 17 00:00:00 2001 From: 3alTemp Date: Fri, 1 Mar 2024 23:26:57 -0600 Subject: [PATCH 07/10] ci --- src/assets/ba_data/python/bauiv1lib/settings/gamepad.py | 4 ++-- src/assets/ba_data/python/bauiv1lib/settings/keyboard.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py b/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py index c60a1bd0..c6b0327b 100644 --- a/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py +++ b/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py @@ -8,6 +8,7 @@ from __future__ import annotations import logging from typing import TYPE_CHECKING +from bauiv1lib.popup import PopupMenuWindow import bascenev1 as bs import bauiv1 as bui @@ -15,10 +16,10 @@ if TYPE_CHECKING: from typing import Any, Callable from bauiv1lib.popup import PopupWindow -from bauiv1lib.popup import PopupMenuWindow class GamepadSettingsWindow(bui.Window): """Window for configuring a gamepad.""" + # pylint: disable=too-many-public-methods def __init__( self, @@ -141,7 +142,6 @@ class GamepadSettingsWindow(bui.Window): def _rebuild_ui(self, is_reset: bool = False) -> None: # pylint: disable=too-many-statements - # pylint: disable=too-many-locals assert bui.app.classic is not None diff --git a/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py b/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py index 5126fe87..8a9d59ce 100644 --- a/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py +++ b/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py @@ -6,6 +6,7 @@ from __future__ import annotations from typing import TYPE_CHECKING +from bauiv1lib.popup import PopupMenuWindow import bauiv1 as bui import bascenev1 as bs @@ -13,7 +14,6 @@ if TYPE_CHECKING: from typing import Any from bauiv1lib.popup import PopupWindow -from bauiv1lib.popup import PopupMenuWindow class ConfigKeyboardWindow(bui.Window): """Window for configuring keyboards.""" @@ -80,7 +80,7 @@ class ConfigKeyboardWindow(bui.Window): for widget in self._root_widget.get_children(): widget.delete() - b_off = 0 if self._unique_id != '#1' else 9 + #b_off = 0 if self._unique_id != '#1' else 9 cancel_button = bui.buttonwidget( parent=self._root_widget, autoselect=True, From 6d466ddf84f4302ff298252c0d0583662d35d4da Mon Sep 17 00:00:00 2001 From: 3alTemp Date: Fri, 1 Mar 2024 23:45:37 -0600 Subject: [PATCH 08/10] =?UTF-8?q?n=C2=B01=20ci=20hater?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/assets/ba_data/python/bauiv1lib/settings/gamepad.py | 2 +- src/assets/ba_data/python/bauiv1lib/settings/keyboard.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py b/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py index c6b0327b..b3979a79 100644 --- a/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py +++ b/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py @@ -832,7 +832,7 @@ class GamepadSettingsWindow(bui.Window): def _do_reset(self) -> None: """Resets the input's mapping settings.""" from babase import InputDeviceNotFoundError - self._settings: dict[str, int] = {} + self._settings = {} # Unplugging the controller while performing a # mapping reset makes things go bonkers a little. try: diff --git a/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py b/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py index 8a9d59ce..1fc1cd3c 100644 --- a/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py +++ b/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py @@ -316,7 +316,7 @@ class ConfigKeyboardWindow(bui.Window): def _do_reset(self) -> None: """Resets the input's mapping settings.""" - self._settings: dict[str, int] = {} + self._settings = {} self._get_config_mapping(default=True) self._rebuild_ui(is_reset=True) bui.getsound('gunCocking').play() From 6980c6669cdd03a70828510c99e8319f94902071 Mon Sep 17 00:00:00 2001 From: 3alTemp Date: Tue, 5 Mar 2024 03:04:08 -0600 Subject: [PATCH 09/10] cleanup --- src/assets/ba_data/python/bauiv1lib/settings/gamepad.py | 1 - src/assets/ba_data/python/bauiv1lib/settings/keyboard.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py b/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py index b3979a79..2aba46a9 100644 --- a/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py +++ b/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py @@ -38,7 +38,6 @@ class GamepadSettingsWindow(bui.Window): self._name = self._input.name self._r = 'configGamepadWindow' - self._settings = settings self._transition_out = transition_out # We're a secondary gamepad if supplied with settings. diff --git a/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py b/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py index 1fc1cd3c..11e5a1d7 100644 --- a/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py +++ b/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py @@ -55,7 +55,7 @@ class ConfigKeyboardWindow(bui.Window): self._rebuild_ui() - def _get_config_mapping(self, default: bool = False): + def _get_config_mapping(self, default: bool = False) -> None: for button in [ 'buttonJump', 'buttonPunch', From 7a954af5d06f8e1d7d7a31a86fba1594ace08203 Mon Sep 17 00:00:00 2001 From: 3alTemp Date: Tue, 5 Mar 2024 03:09:49 -0600 Subject: [PATCH 10/10] fixo --- src/assets/ba_data/python/baclassic/_subsystem.py | 2 +- src/assets/ba_data/python/bauiv1lib/settings/gamepad.py | 1 + src/assets/ba_data/python/bauiv1lib/settings/keyboard.py | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/assets/ba_data/python/baclassic/_subsystem.py b/src/assets/ba_data/python/baclassic/_subsystem.py index f5847c71..0889b7de 100644 --- a/src/assets/ba_data/python/baclassic/_subsystem.py +++ b/src/assets/ba_data/python/baclassic/_subsystem.py @@ -580,7 +580,7 @@ class ClassicSubsystem(babase.AppSubsystem): name: str, default: bool = False, ) -> Any: - """Returns a mapped value for an input device. + """Return a mapped value for an input device. This checks the user config and falls back to default values where available. diff --git a/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py b/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py index 2aba46a9..a4f193a4 100644 --- a/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py +++ b/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py @@ -133,6 +133,7 @@ class GamepadSettingsWindow(bui.Window): 'analogStickUD_B', 'enableSecondary', ]: + assert bui.app.classic is not None val = bui.app.classic.get_input_device_mapped_value( self._input, button, default ) diff --git a/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py b/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py index 11e5a1d7..3f445460 100644 --- a/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py +++ b/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py @@ -68,6 +68,7 @@ class ConfigKeyboardWindow(bui.Window): 'buttonLeft', 'buttonRight', ]: + assert bui.app.classic is not None self._settings[ button ] = bui.app.classic.get_input_device_mapped_value(