bauiv1lib.settings.devtools

UI functionality for Modding Tools.

  1# Released under the MIT License. See LICENSE for details.
  2#
  3"""UI functionality for Modding Tools."""
  4
  5from __future__ import annotations
  6
  7import babase
  8import bauiv1 as bui
  9from bauiv1lib.popup import PopupMenu
 10from bauiv1lib.confirm import ConfirmWindow
 11from bauiv1lib.config import ConfigCheckBox
 12
 13
 14class DevToolsWindow(bui.Window):
 15    """Window for accessing modding tools."""
 16
 17    def __init__(
 18        self,
 19        transition: str = 'in_right',
 20        origin_widget: bui.Widget | None = None,
 21    ):
 22
 23        app = bui.app
 24        assert app.classic is not None
 25
 26        # If they provided an origin-widget, scale up from that.
 27        scale_origin: tuple[float, float] | None
 28        if origin_widget is not None:
 29            self._transition_out = 'out_scale'
 30            scale_origin = origin_widget.get_screen_space_center()
 31            transition = 'in_scale'
 32        else:
 33            self._transition_out = 'out_right'
 34            scale_origin = None
 35
 36        uiscale = app.ui_v1.uiscale
 37        self._width = 970.0 if uiscale is bui.UIScale.SMALL else 670.0
 38        x_inset = 150 if uiscale is bui.UIScale.SMALL else 0
 39        self._height = (
 40            390.0
 41            if uiscale is bui.UIScale.SMALL
 42            else 450.0 if uiscale is bui.UIScale.MEDIUM else 520.0
 43        )
 44
 45        self._spacing = 32
 46        top_extra = 10 if uiscale is bui.UIScale.SMALL else 0
 47
 48        self._scroll_width = self._width - (100 + 2 * x_inset)
 49        self._scroll_height = self._height - 115.0
 50        self._sub_width = self._scroll_width * 0.95
 51        self._sub_height = 350.0
 52
 53        super().__init__(
 54            root_widget=bui.containerwidget(
 55                size=(self._width, self._height + top_extra),
 56                transition=transition,
 57                toolbar_visibility='menu_minimal',
 58                scale_origin_stack_offset=scale_origin,
 59                scale=(
 60                    2.06
 61                    if uiscale is bui.UIScale.SMALL
 62                    else 1.4 if uiscale is bui.UIScale.MEDIUM else 1.0
 63                ),
 64                stack_offset=(
 65                    (0, -25) if uiscale is bui.UIScale.SMALL else (0, 0)
 66                ),
 67            )
 68        )
 69
 70        self._r = 'settingsDevTools'
 71
 72        if app.ui_v1.use_toolbars and uiscale is bui.UIScale.SMALL:
 73            bui.containerwidget(
 74                edit=self._root_widget, on_cancel_call=self._do_back
 75            )
 76            self._back_button = None
 77        else:
 78            self._back_button = bui.buttonwidget(
 79                parent=self._root_widget,
 80                position=(53 + x_inset, self._height - 60),
 81                size=(140, 60),
 82                scale=0.8,
 83                autoselect=True,
 84                label=bui.Lstr(resource='backText'),
 85                button_type='back',
 86                on_activate_call=self._do_back,
 87            )
 88            bui.containerwidget(
 89                edit=self._root_widget, cancel_button=self._back_button
 90            )
 91
 92        self._title_text = bui.textwidget(
 93            parent=self._root_widget,
 94            position=(self._width * 0.5, self._height - 48),
 95            size=(0, 25),
 96            maxwidth=self._width - 200,
 97            text=bui.Lstr(resource='settingsWindowAdvanced.devToolsText'),
 98            color=app.ui_v1.title_color,
 99            h_align='center',
100            v_align='center',
101        )
102
103        if self._back_button is not None:
104            bui.buttonwidget(
105                edit=self._back_button,
106                button_type='backSmall',
107                size=(60, 60),
108                label=bui.charstr(bui.SpecialChar.BACK),
109            )
110
111        self._scrollwidget = bui.scrollwidget(
112            parent=self._root_widget,
113            position=(50 + x_inset, 50),
114            simple_culling_v=20.0,
115            highlight=False,
116            size=(self._scroll_width, self._scroll_height),
117            selection_loops_to_parent=True,
118        )
119        bui.widget(edit=self._scrollwidget, right_widget=self._scrollwidget)
120        self._subcontainer = bui.containerwidget(
121            parent=self._scrollwidget,
122            size=(self._sub_width, self._sub_height),
123            background=False,
124            selection_loops_to_parent=True,
125        )
126
127        v = self._sub_height - 35
128        this_button_width = 410
129
130        v -= self._spacing * 2.5
131        self._show_dev_console_button_check_box = ConfigCheckBox(
132            parent=self._subcontainer,
133            position=(90, v + 40),
134            size=(self._sub_width - 100, 30),
135            configkey='Show Dev Console Button',
136            displayname=bui.Lstr(
137                resource='settingsWindowAdvanced.showDevConsoleButtonText'
138            ),
139            scale=1.0,
140            maxwidth=400,
141        )
142        if self._back_button is not None:
143            bui.widget(
144                edit=self._show_dev_console_button_check_box.widget,
145                up_widget=self._back_button,
146            )
147
148        v -= self._spacing * 1.2
149        self._create_user_system_scripts_button = bui.buttonwidget(
150            parent=self._subcontainer,
151            position=(self._sub_width / 2 - this_button_width / 2, v - 10),
152            size=(this_button_width, 60),
153            autoselect=True,
154            label=bui.Lstr(resource='userSystemScriptsCreateText'),
155            text_scale=1.0,
156            on_activate_call=babase.modutils.create_user_system_scripts,
157        )
158
159        v -= self._spacing * 2.5
160        self._delete_user_system_scripts_button = bui.buttonwidget(
161            parent=self._subcontainer,
162            position=(self._sub_width / 2 - this_button_width / 2, v - 10),
163            size=(this_button_width, 60),
164            autoselect=True,
165            label=bui.Lstr(resource='userSystemScriptsDeleteText'),
166            text_scale=1.0,
167            on_activate_call=lambda: ConfirmWindow(
168                action=babase.modutils.delete_user_system_scripts,
169            ),
170        )
171
172        v -= self._spacing * 2.5
173        bui.textwidget(
174            parent=self._subcontainer,
175            position=(170, v + 10),
176            size=(0, 0),
177            text=bui.Lstr(resource='uiScaleText'),
178            color=app.ui_v1.title_color,
179            h_align='center',
180            v_align='center',
181        )
182
183        PopupMenu(
184            parent=self._subcontainer,
185            position=(230, v - 20),
186            button_size=(200.0, 60.0),
187            width=100.0,
188            choices=[
189                'auto',
190                'small',
191                'medium',
192                'large',
193            ],
194            choices_display=[
195                bui.Lstr(resource='autoText'),
196                bui.Lstr(resource='sizeSmallText'),
197                bui.Lstr(resource='sizeMediumText'),
198                bui.Lstr(resource='sizeLargeText'),
199            ],
200            current_choice=app.config.get('UI Scale', 'auto'),
201            on_value_change_call=self._set_uiscale,
202        )
203
204    def _set_uiscale(self, val: str) -> None:
205        cfg = bui.app.config
206        cfg['UI Scale'] = val
207        cfg.apply_and_commit()
208        if bui.app.ui_v1.uiscale.name != val.upper():
209            bui.screenmessage(
210                bui.Lstr(resource='settingsWindowAdvanced.mustRestartText'),
211                color=(1.0, 0.5, 0.0),
212            )
213
214    def _do_back(self) -> None:
215        from bauiv1lib.settings.advanced import AdvancedSettingsWindow
216
217        # no-op if our underlying widget is dead or on its way out.
218        if not self._root_widget or self._root_widget.transitioning_out:
219            return
220
221        bui.containerwidget(
222            edit=self._root_widget, transition=self._transition_out
223        )
224        assert bui.app.classic is not None
225        bui.app.ui_v1.set_main_menu_window(
226            AdvancedSettingsWindow(transition='in_left').get_root_widget(),
227            from_window=self._root_widget,
228        )
class DevToolsWindow(bauiv1._uitypes.Window):
 15class DevToolsWindow(bui.Window):
 16    """Window for accessing modding tools."""
 17
 18    def __init__(
 19        self,
 20        transition: str = 'in_right',
 21        origin_widget: bui.Widget | None = None,
 22    ):
 23
 24        app = bui.app
 25        assert app.classic is not None
 26
 27        # If they provided an origin-widget, scale up from that.
 28        scale_origin: tuple[float, float] | None
 29        if origin_widget is not None:
 30            self._transition_out = 'out_scale'
 31            scale_origin = origin_widget.get_screen_space_center()
 32            transition = 'in_scale'
 33        else:
 34            self._transition_out = 'out_right'
 35            scale_origin = None
 36
 37        uiscale = app.ui_v1.uiscale
 38        self._width = 970.0 if uiscale is bui.UIScale.SMALL else 670.0
 39        x_inset = 150 if uiscale is bui.UIScale.SMALL else 0
 40        self._height = (
 41            390.0
 42            if uiscale is bui.UIScale.SMALL
 43            else 450.0 if uiscale is bui.UIScale.MEDIUM else 520.0
 44        )
 45
 46        self._spacing = 32
 47        top_extra = 10 if uiscale is bui.UIScale.SMALL else 0
 48
 49        self._scroll_width = self._width - (100 + 2 * x_inset)
 50        self._scroll_height = self._height - 115.0
 51        self._sub_width = self._scroll_width * 0.95
 52        self._sub_height = 350.0
 53
 54        super().__init__(
 55            root_widget=bui.containerwidget(
 56                size=(self._width, self._height + top_extra),
 57                transition=transition,
 58                toolbar_visibility='menu_minimal',
 59                scale_origin_stack_offset=scale_origin,
 60                scale=(
 61                    2.06
 62                    if uiscale is bui.UIScale.SMALL
 63                    else 1.4 if uiscale is bui.UIScale.MEDIUM else 1.0
 64                ),
 65                stack_offset=(
 66                    (0, -25) if uiscale is bui.UIScale.SMALL else (0, 0)
 67                ),
 68            )
 69        )
 70
 71        self._r = 'settingsDevTools'
 72
 73        if app.ui_v1.use_toolbars and uiscale is bui.UIScale.SMALL:
 74            bui.containerwidget(
 75                edit=self._root_widget, on_cancel_call=self._do_back
 76            )
 77            self._back_button = None
 78        else:
 79            self._back_button = bui.buttonwidget(
 80                parent=self._root_widget,
 81                position=(53 + x_inset, self._height - 60),
 82                size=(140, 60),
 83                scale=0.8,
 84                autoselect=True,
 85                label=bui.Lstr(resource='backText'),
 86                button_type='back',
 87                on_activate_call=self._do_back,
 88            )
 89            bui.containerwidget(
 90                edit=self._root_widget, cancel_button=self._back_button
 91            )
 92
 93        self._title_text = bui.textwidget(
 94            parent=self._root_widget,
 95            position=(self._width * 0.5, self._height - 48),
 96            size=(0, 25),
 97            maxwidth=self._width - 200,
 98            text=bui.Lstr(resource='settingsWindowAdvanced.devToolsText'),
 99            color=app.ui_v1.title_color,
100            h_align='center',
101            v_align='center',
102        )
103
104        if self._back_button is not None:
105            bui.buttonwidget(
106                edit=self._back_button,
107                button_type='backSmall',
108                size=(60, 60),
109                label=bui.charstr(bui.SpecialChar.BACK),
110            )
111
112        self._scrollwidget = bui.scrollwidget(
113            parent=self._root_widget,
114            position=(50 + x_inset, 50),
115            simple_culling_v=20.0,
116            highlight=False,
117            size=(self._scroll_width, self._scroll_height),
118            selection_loops_to_parent=True,
119        )
120        bui.widget(edit=self._scrollwidget, right_widget=self._scrollwidget)
121        self._subcontainer = bui.containerwidget(
122            parent=self._scrollwidget,
123            size=(self._sub_width, self._sub_height),
124            background=False,
125            selection_loops_to_parent=True,
126        )
127
128        v = self._sub_height - 35
129        this_button_width = 410
130
131        v -= self._spacing * 2.5
132        self._show_dev_console_button_check_box = ConfigCheckBox(
133            parent=self._subcontainer,
134            position=(90, v + 40),
135            size=(self._sub_width - 100, 30),
136            configkey='Show Dev Console Button',
137            displayname=bui.Lstr(
138                resource='settingsWindowAdvanced.showDevConsoleButtonText'
139            ),
140            scale=1.0,
141            maxwidth=400,
142        )
143        if self._back_button is not None:
144            bui.widget(
145                edit=self._show_dev_console_button_check_box.widget,
146                up_widget=self._back_button,
147            )
148
149        v -= self._spacing * 1.2
150        self._create_user_system_scripts_button = bui.buttonwidget(
151            parent=self._subcontainer,
152            position=(self._sub_width / 2 - this_button_width / 2, v - 10),
153            size=(this_button_width, 60),
154            autoselect=True,
155            label=bui.Lstr(resource='userSystemScriptsCreateText'),
156            text_scale=1.0,
157            on_activate_call=babase.modutils.create_user_system_scripts,
158        )
159
160        v -= self._spacing * 2.5
161        self._delete_user_system_scripts_button = bui.buttonwidget(
162            parent=self._subcontainer,
163            position=(self._sub_width / 2 - this_button_width / 2, v - 10),
164            size=(this_button_width, 60),
165            autoselect=True,
166            label=bui.Lstr(resource='userSystemScriptsDeleteText'),
167            text_scale=1.0,
168            on_activate_call=lambda: ConfirmWindow(
169                action=babase.modutils.delete_user_system_scripts,
170            ),
171        )
172
173        v -= self._spacing * 2.5
174        bui.textwidget(
175            parent=self._subcontainer,
176            position=(170, v + 10),
177            size=(0, 0),
178            text=bui.Lstr(resource='uiScaleText'),
179            color=app.ui_v1.title_color,
180            h_align='center',
181            v_align='center',
182        )
183
184        PopupMenu(
185            parent=self._subcontainer,
186            position=(230, v - 20),
187            button_size=(200.0, 60.0),
188            width=100.0,
189            choices=[
190                'auto',
191                'small',
192                'medium',
193                'large',
194            ],
195            choices_display=[
196                bui.Lstr(resource='autoText'),
197                bui.Lstr(resource='sizeSmallText'),
198                bui.Lstr(resource='sizeMediumText'),
199                bui.Lstr(resource='sizeLargeText'),
200            ],
201            current_choice=app.config.get('UI Scale', 'auto'),
202            on_value_change_call=self._set_uiscale,
203        )
204
205    def _set_uiscale(self, val: str) -> None:
206        cfg = bui.app.config
207        cfg['UI Scale'] = val
208        cfg.apply_and_commit()
209        if bui.app.ui_v1.uiscale.name != val.upper():
210            bui.screenmessage(
211                bui.Lstr(resource='settingsWindowAdvanced.mustRestartText'),
212                color=(1.0, 0.5, 0.0),
213            )
214
215    def _do_back(self) -> None:
216        from bauiv1lib.settings.advanced import AdvancedSettingsWindow
217
218        # no-op if our underlying widget is dead or on its way out.
219        if not self._root_widget or self._root_widget.transitioning_out:
220            return
221
222        bui.containerwidget(
223            edit=self._root_widget, transition=self._transition_out
224        )
225        assert bui.app.classic is not None
226        bui.app.ui_v1.set_main_menu_window(
227            AdvancedSettingsWindow(transition='in_left').get_root_widget(),
228            from_window=self._root_widget,
229        )

Window for accessing modding tools.

DevToolsWindow( transition: str = 'in_right', origin_widget: _bauiv1.Widget | None = None)
 18    def __init__(
 19        self,
 20        transition: str = 'in_right',
 21        origin_widget: bui.Widget | None = None,
 22    ):
 23
 24        app = bui.app
 25        assert app.classic is not None
 26
 27        # If they provided an origin-widget, scale up from that.
 28        scale_origin: tuple[float, float] | None
 29        if origin_widget is not None:
 30            self._transition_out = 'out_scale'
 31            scale_origin = origin_widget.get_screen_space_center()
 32            transition = 'in_scale'
 33        else:
 34            self._transition_out = 'out_right'
 35            scale_origin = None
 36
 37        uiscale = app.ui_v1.uiscale
 38        self._width = 970.0 if uiscale is bui.UIScale.SMALL else 670.0
 39        x_inset = 150 if uiscale is bui.UIScale.SMALL else 0
 40        self._height = (
 41            390.0
 42            if uiscale is bui.UIScale.SMALL
 43            else 450.0 if uiscale is bui.UIScale.MEDIUM else 520.0
 44        )
 45
 46        self._spacing = 32
 47        top_extra = 10 if uiscale is bui.UIScale.SMALL else 0
 48
 49        self._scroll_width = self._width - (100 + 2 * x_inset)
 50        self._scroll_height = self._height - 115.0
 51        self._sub_width = self._scroll_width * 0.95
 52        self._sub_height = 350.0
 53
 54        super().__init__(
 55            root_widget=bui.containerwidget(
 56                size=(self._width, self._height + top_extra),
 57                transition=transition,
 58                toolbar_visibility='menu_minimal',
 59                scale_origin_stack_offset=scale_origin,
 60                scale=(
 61                    2.06
 62                    if uiscale is bui.UIScale.SMALL
 63                    else 1.4 if uiscale is bui.UIScale.MEDIUM else 1.0
 64                ),
 65                stack_offset=(
 66                    (0, -25) if uiscale is bui.UIScale.SMALL else (0, 0)
 67                ),
 68            )
 69        )
 70
 71        self._r = 'settingsDevTools'
 72
 73        if app.ui_v1.use_toolbars and uiscale is bui.UIScale.SMALL:
 74            bui.containerwidget(
 75                edit=self._root_widget, on_cancel_call=self._do_back
 76            )
 77            self._back_button = None
 78        else:
 79            self._back_button = bui.buttonwidget(
 80                parent=self._root_widget,
 81                position=(53 + x_inset, self._height - 60),
 82                size=(140, 60),
 83                scale=0.8,
 84                autoselect=True,
 85                label=bui.Lstr(resource='backText'),
 86                button_type='back',
 87                on_activate_call=self._do_back,
 88            )
 89            bui.containerwidget(
 90                edit=self._root_widget, cancel_button=self._back_button
 91            )
 92
 93        self._title_text = bui.textwidget(
 94            parent=self._root_widget,
 95            position=(self._width * 0.5, self._height - 48),
 96            size=(0, 25),
 97            maxwidth=self._width - 200,
 98            text=bui.Lstr(resource='settingsWindowAdvanced.devToolsText'),
 99            color=app.ui_v1.title_color,
100            h_align='center',
101            v_align='center',
102        )
103
104        if self._back_button is not None:
105            bui.buttonwidget(
106                edit=self._back_button,
107                button_type='backSmall',
108                size=(60, 60),
109                label=bui.charstr(bui.SpecialChar.BACK),
110            )
111
112        self._scrollwidget = bui.scrollwidget(
113            parent=self._root_widget,
114            position=(50 + x_inset, 50),
115            simple_culling_v=20.0,
116            highlight=False,
117            size=(self._scroll_width, self._scroll_height),
118            selection_loops_to_parent=True,
119        )
120        bui.widget(edit=self._scrollwidget, right_widget=self._scrollwidget)
121        self._subcontainer = bui.containerwidget(
122            parent=self._scrollwidget,
123            size=(self._sub_width, self._sub_height),
124            background=False,
125            selection_loops_to_parent=True,
126        )
127
128        v = self._sub_height - 35
129        this_button_width = 410
130
131        v -= self._spacing * 2.5
132        self._show_dev_console_button_check_box = ConfigCheckBox(
133            parent=self._subcontainer,
134            position=(90, v + 40),
135            size=(self._sub_width - 100, 30),
136            configkey='Show Dev Console Button',
137            displayname=bui.Lstr(
138                resource='settingsWindowAdvanced.showDevConsoleButtonText'
139            ),
140            scale=1.0,
141            maxwidth=400,
142        )
143        if self._back_button is not None:
144            bui.widget(
145                edit=self._show_dev_console_button_check_box.widget,
146                up_widget=self._back_button,
147            )
148
149        v -= self._spacing * 1.2
150        self._create_user_system_scripts_button = bui.buttonwidget(
151            parent=self._subcontainer,
152            position=(self._sub_width / 2 - this_button_width / 2, v - 10),
153            size=(this_button_width, 60),
154            autoselect=True,
155            label=bui.Lstr(resource='userSystemScriptsCreateText'),
156            text_scale=1.0,
157            on_activate_call=babase.modutils.create_user_system_scripts,
158        )
159
160        v -= self._spacing * 2.5
161        self._delete_user_system_scripts_button = bui.buttonwidget(
162            parent=self._subcontainer,
163            position=(self._sub_width / 2 - this_button_width / 2, v - 10),
164            size=(this_button_width, 60),
165            autoselect=True,
166            label=bui.Lstr(resource='userSystemScriptsDeleteText'),
167            text_scale=1.0,
168            on_activate_call=lambda: ConfirmWindow(
169                action=babase.modutils.delete_user_system_scripts,
170            ),
171        )
172
173        v -= self._spacing * 2.5
174        bui.textwidget(
175            parent=self._subcontainer,
176            position=(170, v + 10),
177            size=(0, 0),
178            text=bui.Lstr(resource='uiScaleText'),
179            color=app.ui_v1.title_color,
180            h_align='center',
181            v_align='center',
182        )
183
184        PopupMenu(
185            parent=self._subcontainer,
186            position=(230, v - 20),
187            button_size=(200.0, 60.0),
188            width=100.0,
189            choices=[
190                'auto',
191                'small',
192                'medium',
193                'large',
194            ],
195            choices_display=[
196                bui.Lstr(resource='autoText'),
197                bui.Lstr(resource='sizeSmallText'),
198                bui.Lstr(resource='sizeMediumText'),
199                bui.Lstr(resource='sizeLargeText'),
200            ],
201            current_choice=app.config.get('UI Scale', 'auto'),
202            on_value_change_call=self._set_uiscale,
203        )
Inherited Members
bauiv1._uitypes.Window
get_root_widget