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