mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-01-28 01:43:22 +08:00
Plugin Settings
This commit is contained in:
parent
0cbaf28aae
commit
198a782660
@ -48,13 +48,14 @@ class PluginSubsystem:
|
||||
available=True,
|
||||
)
|
||||
)
|
||||
if class_path not in plugstates:
|
||||
# Go ahead and enable new plugins by default, but we'll
|
||||
# inform the user that they need to restart to pick them up.
|
||||
# they can also disable them in settings so they never load.
|
||||
plugstates[class_path] = {'enabled': True}
|
||||
config_changed = True
|
||||
found_new = True
|
||||
if _ba.app.config['Auto Enable New Plugins'] is True:
|
||||
if class_path not in plugstates:
|
||||
# Go ahead and enable new plugins by default, but we'll
|
||||
# inform the user that they need to restart to pick them up.
|
||||
# they can also disable them in settings so they never load.
|
||||
plugstates[class_path] = {'enabled': True}
|
||||
config_changed = True
|
||||
found_new = True
|
||||
|
||||
plugs.potential_plugins.sort(key=lambda p: p.class_path)
|
||||
|
||||
|
||||
@ -667,12 +667,12 @@ class AdvancedSettingsWindow(ba.Window):
|
||||
appinvite.handle_app_invites_press()
|
||||
|
||||
def _on_plugins_button_press(self) -> None:
|
||||
from bastd.ui.settings.plugins import PluginSettingsWindow
|
||||
from bastd.ui.settings.plugins import PluginWindow
|
||||
|
||||
self._save_state()
|
||||
ba.containerwidget(edit=self._root_widget, transition='out_left')
|
||||
ba.app.ui.set_main_menu_window(
|
||||
PluginSettingsWindow(
|
||||
PluginWindow(
|
||||
origin_widget=self._plugins_button
|
||||
).get_root_widget()
|
||||
)
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
# Released under the MIT License. See LICENSE for details.
|
||||
#
|
||||
"""Plugin settings UI."""
|
||||
"""Plugin Window UI."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@ -12,7 +12,7 @@ if TYPE_CHECKING:
|
||||
pass
|
||||
|
||||
|
||||
class PluginSettingsWindow(ba.Window):
|
||||
class PluginWindow(ba.Window):
|
||||
"""Window for configuring plugins."""
|
||||
|
||||
def __init__(
|
||||
@ -106,6 +106,21 @@ class PluginSettingsWindow(ba.Window):
|
||||
size=(60, 60),
|
||||
label=ba.charstr(ba.SpecialChar.BACK),
|
||||
)
|
||||
settings_button_x = 670 if uiscale is ba.UIScale.SMALL else 570
|
||||
self._settings_button = ba.buttonwidget(
|
||||
parent=self._root_widget,
|
||||
position=(settings_button_x, self._height - 60),
|
||||
size=(40, 40),
|
||||
label='',
|
||||
on_activate_call=self._open_settings,
|
||||
)
|
||||
|
||||
ba.imagewidget(
|
||||
parent=self._root_widget,
|
||||
position=(settings_button_x + 5, self._height - 60),
|
||||
size=(35, 35),
|
||||
texture=ba.gettexture('settingsIcon'),
|
||||
)
|
||||
|
||||
self._scrollwidget = ba.scrollwidget(
|
||||
parent=self._root_widget,
|
||||
@ -212,6 +227,17 @@ class PluginSettingsWindow(ba.Window):
|
||||
plugstate['enabled'] = value
|
||||
ba.app.config.commit()
|
||||
|
||||
def _open_settings(self) -> None:
|
||||
from bastd.ui.settings.pluginsettings import PluginSettingsWindow
|
||||
ba.playsound(ba.getsound('swish'))
|
||||
|
||||
ba.containerwidget(
|
||||
edit=self._root_widget,transition='out_left'
|
||||
)
|
||||
ba.app.ui.set_main_menu_window(
|
||||
PluginSettingsWindow(transition='in_right').get_root_widget()
|
||||
)
|
||||
|
||||
def _save_state(self) -> None:
|
||||
pass
|
||||
|
||||
|
||||
151
assets/src/ba_data/python/bastd/ui/settings/pluginsettings.py
Normal file
151
assets/src/ba_data/python/bastd/ui/settings/pluginsettings.py
Normal file
@ -0,0 +1,151 @@
|
||||
# Released under the MIT License. See LICENSE for details.
|
||||
#
|
||||
"""Plugin Settings UI."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import ba
|
||||
|
||||
if TYPE_CHECKING:
|
||||
pass
|
||||
|
||||
class PluginSettingsWindow(ba.Window):
|
||||
"""Plugin Settings Window"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
transition: str = 'in_right'
|
||||
):
|
||||
|
||||
scale_origin: tuple[float, float] | None
|
||||
self._transition_out = 'out_right'
|
||||
scale_origin = None
|
||||
|
||||
uiscale = ba.app.ui.uiscale
|
||||
width = 470.0 if uiscale is ba.UIScale.SMALL else 470.0
|
||||
height = (
|
||||
365.0
|
||||
if uiscale is ba.UIScale.SMALL
|
||||
else 300.0
|
||||
if uiscale is ba.UIScale.MEDIUM
|
||||
else 370.0
|
||||
)
|
||||
top_extra = 10 if uiscale is ba.UIScale.SMALL else 0
|
||||
|
||||
super().__init__(
|
||||
root_widget=ba.containerwidget(
|
||||
size=(width, height + top_extra),
|
||||
transition=transition,
|
||||
toolbar_visibility='menu_minimal',
|
||||
scale_origin_stack_offset=scale_origin,
|
||||
scale=(
|
||||
2.06
|
||||
if uiscale is ba.UIScale.SMALL
|
||||
else 1.4
|
||||
if uiscale is ba.UIScale.MEDIUM
|
||||
else 1.0
|
||||
),
|
||||
stack_offset=(0, -25)
|
||||
if uiscale is ba.UIScale.SMALL
|
||||
else (0, 0),
|
||||
)
|
||||
)
|
||||
|
||||
self._back_button = ba.buttonwidget(
|
||||
parent=self._root_widget,
|
||||
position=(53, height - 60),
|
||||
size=(60, 60),
|
||||
scale=0.8,
|
||||
autoselect=True,
|
||||
label=ba.charstr(ba.SpecialChar.BACK),
|
||||
button_type='backSmall',
|
||||
on_activate_call=self._do_back
|
||||
)
|
||||
ba.containerwidget(
|
||||
edit=self._root_widget, cancel_button=self._back_button
|
||||
)
|
||||
|
||||
self._title_text = ba.textwidget(
|
||||
parent=self._root_widget,
|
||||
position=(0, height - 52),
|
||||
size=(width, 25),
|
||||
text='Plugin Settings',
|
||||
color=ba.app.ui.title_color,
|
||||
h_align='center',
|
||||
v_align='top'
|
||||
)
|
||||
|
||||
self._y_position = 170 if uiscale is ba.UIScale.MEDIUM else 205
|
||||
self._plugins_button = ba.buttonwidget(
|
||||
parent=self._root_widget,
|
||||
position=(65,self._y_position),
|
||||
size=(350, 60),
|
||||
autoselect=True,
|
||||
label='Enable All Plugins',
|
||||
text_scale=1.0,
|
||||
on_activate_call=self._enable_all_plugins,
|
||||
)
|
||||
|
||||
self._y_position -= 70
|
||||
self._plugins_button = ba.buttonwidget(
|
||||
parent=self._root_widget,
|
||||
position=(65,self._y_position),
|
||||
size=(350, 60),
|
||||
autoselect=True,
|
||||
label='Disable All Plugins',
|
||||
text_scale=1.0,
|
||||
on_activate_call=self._disable_all_plugins,
|
||||
)
|
||||
|
||||
self._y_position -= 70
|
||||
self._enable_new_plugins_check_box = ba.checkboxwidget(
|
||||
parent=self._root_widget,
|
||||
position=(65, self._y_position),
|
||||
size=(350, 60),
|
||||
value=ba.app.config['Auto Enable New Plugins'],
|
||||
text='Auto Enable New Plugins',
|
||||
scale=1.0,
|
||||
maxwidth=430,
|
||||
on_value_change_call=self._update_value
|
||||
)
|
||||
|
||||
def _enable_all_plugins(self) -> None:
|
||||
cfg = ba.app.config
|
||||
plugs = cfg['Plugins']
|
||||
for plug in plugs:
|
||||
plugs[plug]['enabled'] = True
|
||||
cfg.apply_and_commit()
|
||||
|
||||
ba.screenmessage(
|
||||
ba.Lstr(resource='settingsWindowAdvanced.mustRestartText'),
|
||||
color=(1.0, 0.5, 0.0),
|
||||
)
|
||||
|
||||
def _disable_all_plugins(self) -> None:
|
||||
cfg = ba.app.config
|
||||
plugs = cfg['Plugins']
|
||||
for plug in plugs:
|
||||
plugs[plug]['enabled'] = False
|
||||
cfg.apply_and_commit()
|
||||
|
||||
ba.screenmessage(
|
||||
ba.Lstr(resource='settingsWindowAdvanced.mustRestartText'),
|
||||
color=(1.0, 0.5, 0.0),
|
||||
)
|
||||
|
||||
def _update_value(self, val: bool) -> None:
|
||||
cfg = ba.app.config
|
||||
cfg['Auto Enable New Plugins'] = val
|
||||
cfg.apply_and_commit()
|
||||
|
||||
def _do_back(self) -> None:
|
||||
from bastd.ui.settings.plugins import PluginWindow
|
||||
|
||||
ba.containerwidget(
|
||||
edit=self._root_widget, transition=self._transition_out
|
||||
)
|
||||
ba.app.ui.set_main_menu_window(
|
||||
PluginWindow(transition='in_left').get_root_widget()
|
||||
)
|
||||
Loading…
x
Reference in New Issue
Block a user