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 7from typing import override 8 9import babase 10import bauiv1 as bui 11from bauiv1lib.popup import PopupMenu 12from bauiv1lib.confirm import ConfirmWindow 13from bauiv1lib.config import ConfigCheckBox 14 15 16class DevToolsWindow(bui.MainWindow): 17 """Window for accessing modding tools.""" 18 19 def __init__( 20 self, 21 transition: str | None = 'in_right', 22 origin_widget: bui.Widget | None = None, 23 ): 24 25 app = bui.app 26 assert app.classic is not None 27 28 uiscale = app.ui_v1.uiscale 29 self._width = 1000.0 if uiscale is bui.UIScale.SMALL else 670.0 30 x_inset = 150 if uiscale is bui.UIScale.SMALL else 0 31 self._height = ( 32 370.0 33 if uiscale is bui.UIScale.SMALL 34 else 450.0 if uiscale is bui.UIScale.MEDIUM else 520.0 35 ) 36 37 self._spacing = 32 38 top_extra = 10 if uiscale is bui.UIScale.SMALL else 0 39 40 self._scroll_width = self._width - (100 + 2 * x_inset) 41 self._scroll_height = self._height - 115.0 42 self._sub_width = self._scroll_width * 0.95 43 self._sub_height = 300.0 44 45 super().__init__( 46 root_widget=bui.containerwidget( 47 size=(self._width, self._height + top_extra), 48 toolbar_visibility=( 49 'menu_minimal' 50 if uiscale is bui.UIScale.SMALL 51 else 'menu_full' 52 ), 53 scale=( 54 2.13 55 if uiscale is bui.UIScale.SMALL 56 else 1.4 if uiscale is bui.UIScale.MEDIUM else 1.0 57 ), 58 stack_offset=( 59 (0, 0) if uiscale is bui.UIScale.SMALL else (0, 0) 60 ), 61 ), 62 transition=transition, 63 origin_widget=origin_widget, 64 ) 65 66 self._r = 'settingsDevTools' 67 68 if uiscale is bui.UIScale.SMALL: 69 bui.containerwidget( 70 edit=self._root_widget, on_cancel_call=self.main_window_back 71 ) 72 self._back_button = None 73 else: 74 self._back_button = bui.buttonwidget( 75 parent=self._root_widget, 76 position=(53 + x_inset, self._height - 60), 77 size=(140, 60), 78 scale=0.8, 79 autoselect=True, 80 label=bui.Lstr(resource='backText'), 81 button_type='back', 82 on_activate_call=self.main_window_back, 83 ) 84 bui.containerwidget( 85 edit=self._root_widget, cancel_button=self._back_button 86 ) 87 88 self._title_text = bui.textwidget( 89 parent=self._root_widget, 90 position=( 91 self._width * 0.5, 92 self._height - (64 if uiscale is bui.UIScale.SMALL else 48), 93 ), 94 size=(0, 25), 95 scale=(0.8 if uiscale is bui.UIScale.SMALL else 1.0), 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 # Currently this is not wired up. The current official way to test 173 # UIScales is either to use the switcher in the dev-console or to 174 # set the BA_UI_SCALE env var. 175 if bool(False): 176 v -= self._spacing * 2.5 177 bui.textwidget( 178 parent=self._subcontainer, 179 position=(170, v + 10), 180 size=(0, 0), 181 text=bui.Lstr(resource='uiScaleText'), 182 color=app.ui_v1.title_color, 183 h_align='center', 184 v_align='center', 185 ) 186 187 PopupMenu( 188 parent=self._subcontainer, 189 position=(230, v - 20), 190 button_size=(200.0, 60.0), 191 width=100.0, 192 choices=[ 193 'auto', 194 'small', 195 'medium', 196 'large', 197 ], 198 choices_display=[ 199 bui.Lstr(resource='autoText'), 200 bui.Lstr(resource='sizeSmallText'), 201 bui.Lstr(resource='sizeMediumText'), 202 bui.Lstr(resource='sizeLargeText'), 203 ], 204 current_choice=app.config.get('UI Scale', 'auto'), 205 on_value_change_call=self._set_uiscale, 206 ) 207 208 @override 209 def get_main_window_state(self) -> bui.MainWindowState: 210 # Support recreating our window for back/refresh purposes. 211 cls = type(self) 212 return bui.BasicMainWindowState( 213 create_call=lambda transition, origin_widget: cls( 214 transition=transition, origin_widget=origin_widget 215 ) 216 ) 217 218 def _set_uiscale(self, val: str) -> None: 219 cfg = bui.app.config 220 cfg['UI Scale'] = val 221 cfg.apply_and_commit() 222 if bui.app.ui_v1.uiscale.name != val.upper(): 223 bui.screenmessage( 224 bui.Lstr(resource='settingsWindowAdvanced.mustRestartText'), 225 color=(1.0, 0.5, 0.0), 226 )
class
DevToolsWindow(bauiv1._uitypes.MainWindow):
17class DevToolsWindow(bui.MainWindow): 18 """Window for accessing modding tools.""" 19 20 def __init__( 21 self, 22 transition: str | None = 'in_right', 23 origin_widget: bui.Widget | None = None, 24 ): 25 26 app = bui.app 27 assert app.classic is not None 28 29 uiscale = app.ui_v1.uiscale 30 self._width = 1000.0 if uiscale is bui.UIScale.SMALL else 670.0 31 x_inset = 150 if uiscale is bui.UIScale.SMALL else 0 32 self._height = ( 33 370.0 34 if uiscale is bui.UIScale.SMALL 35 else 450.0 if uiscale is bui.UIScale.MEDIUM else 520.0 36 ) 37 38 self._spacing = 32 39 top_extra = 10 if uiscale is bui.UIScale.SMALL else 0 40 41 self._scroll_width = self._width - (100 + 2 * x_inset) 42 self._scroll_height = self._height - 115.0 43 self._sub_width = self._scroll_width * 0.95 44 self._sub_height = 300.0 45 46 super().__init__( 47 root_widget=bui.containerwidget( 48 size=(self._width, self._height + top_extra), 49 toolbar_visibility=( 50 'menu_minimal' 51 if uiscale is bui.UIScale.SMALL 52 else 'menu_full' 53 ), 54 scale=( 55 2.13 56 if uiscale is bui.UIScale.SMALL 57 else 1.4 if uiscale is bui.UIScale.MEDIUM else 1.0 58 ), 59 stack_offset=( 60 (0, 0) if uiscale is bui.UIScale.SMALL else (0, 0) 61 ), 62 ), 63 transition=transition, 64 origin_widget=origin_widget, 65 ) 66 67 self._r = 'settingsDevTools' 68 69 if uiscale is bui.UIScale.SMALL: 70 bui.containerwidget( 71 edit=self._root_widget, on_cancel_call=self.main_window_back 72 ) 73 self._back_button = None 74 else: 75 self._back_button = bui.buttonwidget( 76 parent=self._root_widget, 77 position=(53 + x_inset, self._height - 60), 78 size=(140, 60), 79 scale=0.8, 80 autoselect=True, 81 label=bui.Lstr(resource='backText'), 82 button_type='back', 83 on_activate_call=self.main_window_back, 84 ) 85 bui.containerwidget( 86 edit=self._root_widget, cancel_button=self._back_button 87 ) 88 89 self._title_text = bui.textwidget( 90 parent=self._root_widget, 91 position=( 92 self._width * 0.5, 93 self._height - (64 if uiscale is bui.UIScale.SMALL else 48), 94 ), 95 size=(0, 25), 96 scale=(0.8 if uiscale is bui.UIScale.SMALL else 1.0), 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 # Currently this is not wired up. The current official way to test 174 # UIScales is either to use the switcher in the dev-console or to 175 # set the BA_UI_SCALE env var. 176 if bool(False): 177 v -= self._spacing * 2.5 178 bui.textwidget( 179 parent=self._subcontainer, 180 position=(170, v + 10), 181 size=(0, 0), 182 text=bui.Lstr(resource='uiScaleText'), 183 color=app.ui_v1.title_color, 184 h_align='center', 185 v_align='center', 186 ) 187 188 PopupMenu( 189 parent=self._subcontainer, 190 position=(230, v - 20), 191 button_size=(200.0, 60.0), 192 width=100.0, 193 choices=[ 194 'auto', 195 'small', 196 'medium', 197 'large', 198 ], 199 choices_display=[ 200 bui.Lstr(resource='autoText'), 201 bui.Lstr(resource='sizeSmallText'), 202 bui.Lstr(resource='sizeMediumText'), 203 bui.Lstr(resource='sizeLargeText'), 204 ], 205 current_choice=app.config.get('UI Scale', 'auto'), 206 on_value_change_call=self._set_uiscale, 207 ) 208 209 @override 210 def get_main_window_state(self) -> bui.MainWindowState: 211 # Support recreating our window for back/refresh purposes. 212 cls = type(self) 213 return bui.BasicMainWindowState( 214 create_call=lambda transition, origin_widget: cls( 215 transition=transition, origin_widget=origin_widget 216 ) 217 ) 218 219 def _set_uiscale(self, val: str) -> None: 220 cfg = bui.app.config 221 cfg['UI Scale'] = val 222 cfg.apply_and_commit() 223 if bui.app.ui_v1.uiscale.name != val.upper(): 224 bui.screenmessage( 225 bui.Lstr(resource='settingsWindowAdvanced.mustRestartText'), 226 color=(1.0, 0.5, 0.0), 227 )
Window for accessing modding tools.
DevToolsWindow( transition: str | None = 'in_right', origin_widget: _bauiv1.Widget | None = None)
20 def __init__( 21 self, 22 transition: str | None = 'in_right', 23 origin_widget: bui.Widget | None = None, 24 ): 25 26 app = bui.app 27 assert app.classic is not None 28 29 uiscale = app.ui_v1.uiscale 30 self._width = 1000.0 if uiscale is bui.UIScale.SMALL else 670.0 31 x_inset = 150 if uiscale is bui.UIScale.SMALL else 0 32 self._height = ( 33 370.0 34 if uiscale is bui.UIScale.SMALL 35 else 450.0 if uiscale is bui.UIScale.MEDIUM else 520.0 36 ) 37 38 self._spacing = 32 39 top_extra = 10 if uiscale is bui.UIScale.SMALL else 0 40 41 self._scroll_width = self._width - (100 + 2 * x_inset) 42 self._scroll_height = self._height - 115.0 43 self._sub_width = self._scroll_width * 0.95 44 self._sub_height = 300.0 45 46 super().__init__( 47 root_widget=bui.containerwidget( 48 size=(self._width, self._height + top_extra), 49 toolbar_visibility=( 50 'menu_minimal' 51 if uiscale is bui.UIScale.SMALL 52 else 'menu_full' 53 ), 54 scale=( 55 2.13 56 if uiscale is bui.UIScale.SMALL 57 else 1.4 if uiscale is bui.UIScale.MEDIUM else 1.0 58 ), 59 stack_offset=( 60 (0, 0) if uiscale is bui.UIScale.SMALL else (0, 0) 61 ), 62 ), 63 transition=transition, 64 origin_widget=origin_widget, 65 ) 66 67 self._r = 'settingsDevTools' 68 69 if uiscale is bui.UIScale.SMALL: 70 bui.containerwidget( 71 edit=self._root_widget, on_cancel_call=self.main_window_back 72 ) 73 self._back_button = None 74 else: 75 self._back_button = bui.buttonwidget( 76 parent=self._root_widget, 77 position=(53 + x_inset, self._height - 60), 78 size=(140, 60), 79 scale=0.8, 80 autoselect=True, 81 label=bui.Lstr(resource='backText'), 82 button_type='back', 83 on_activate_call=self.main_window_back, 84 ) 85 bui.containerwidget( 86 edit=self._root_widget, cancel_button=self._back_button 87 ) 88 89 self._title_text = bui.textwidget( 90 parent=self._root_widget, 91 position=( 92 self._width * 0.5, 93 self._height - (64 if uiscale is bui.UIScale.SMALL else 48), 94 ), 95 size=(0, 25), 96 scale=(0.8 if uiscale is bui.UIScale.SMALL else 1.0), 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 # Currently this is not wired up. The current official way to test 174 # UIScales is either to use the switcher in the dev-console or to 175 # set the BA_UI_SCALE env var. 176 if bool(False): 177 v -= self._spacing * 2.5 178 bui.textwidget( 179 parent=self._subcontainer, 180 position=(170, v + 10), 181 size=(0, 0), 182 text=bui.Lstr(resource='uiScaleText'), 183 color=app.ui_v1.title_color, 184 h_align='center', 185 v_align='center', 186 ) 187 188 PopupMenu( 189 parent=self._subcontainer, 190 position=(230, v - 20), 191 button_size=(200.0, 60.0), 192 width=100.0, 193 choices=[ 194 'auto', 195 'small', 196 'medium', 197 'large', 198 ], 199 choices_display=[ 200 bui.Lstr(resource='autoText'), 201 bui.Lstr(resource='sizeSmallText'), 202 bui.Lstr(resource='sizeMediumText'), 203 bui.Lstr(resource='sizeLargeText'), 204 ], 205 current_choice=app.config.get('UI Scale', 'auto'), 206 on_value_change_call=self._set_uiscale, 207 )
Create a MainWindow given a root widget and transition info.
Automatically handles in and out transitions on the provided widget, so there is no need to set transitions when creating it.
209 @override 210 def get_main_window_state(self) -> bui.MainWindowState: 211 # Support recreating our window for back/refresh purposes. 212 cls = type(self) 213 return bui.BasicMainWindowState( 214 create_call=lambda transition, origin_widget: cls( 215 transition=transition, origin_widget=origin_widget 216 ) 217 )
Return a WindowState to recreate this window, if supported.