bastd.ui.settings.touchscreen
UI settings functionality related to touchscreens.
1# Released under the MIT License. See LICENSE for details. 2# 3"""UI settings functionality related to touchscreens.""" 4from __future__ import annotations 5 6import ba 7import ba.internal 8 9 10class TouchscreenSettingsWindow(ba.Window): 11 """Settings window for touchscreens.""" 12 13 def __del__(self) -> None: 14 # Note - this happens in 'back' too; 15 # we just do it here too in case the window is closed by other means. 16 17 # FIXME: Could switch to a UI destroy callback now that those are a 18 # thing that exists. 19 ba.internal.set_touchscreen_editing(False) 20 21 def __init__(self) -> None: 22 23 self._width = 650 24 self._height = 380 25 self._spacing = 40 26 self._r = 'configTouchscreenWindow' 27 28 ba.internal.set_touchscreen_editing(True) 29 30 uiscale = ba.app.ui.uiscale 31 super().__init__( 32 root_widget=ba.containerwidget( 33 size=(self._width, self._height), 34 transition='in_right', 35 scale=( 36 1.9 37 if uiscale is ba.UIScale.SMALL 38 else 1.55 39 if uiscale is ba.UIScale.MEDIUM 40 else 1.2 41 ), 42 ) 43 ) 44 45 btn = ba.buttonwidget( 46 parent=self._root_widget, 47 position=(55, self._height - 60), 48 size=(120, 60), 49 label=ba.Lstr(resource='backText'), 50 button_type='back', 51 scale=0.8, 52 on_activate_call=self._back, 53 ) 54 ba.containerwidget(edit=self._root_widget, cancel_button=btn) 55 56 ba.textwidget( 57 parent=self._root_widget, 58 position=(25, self._height - 50), 59 size=(self._width, 25), 60 text=ba.Lstr(resource=self._r + '.titleText'), 61 color=ba.app.ui.title_color, 62 maxwidth=280, 63 h_align='center', 64 v_align='center', 65 ) 66 67 ba.buttonwidget( 68 edit=btn, 69 button_type='backSmall', 70 size=(60, 60), 71 label=ba.charstr(ba.SpecialChar.BACK), 72 ) 73 74 self._scroll_width = self._width - 100 75 self._scroll_height = self._height - 110 76 self._sub_width = self._scroll_width - 20 77 self._sub_height = 360 78 79 self._scrollwidget = ba.scrollwidget( 80 parent=self._root_widget, 81 position=( 82 (self._width - self._scroll_width) * 0.5, 83 self._height - 65 - self._scroll_height, 84 ), 85 size=(self._scroll_width, self._scroll_height), 86 claims_left_right=True, 87 claims_tab=True, 88 selection_loops_to_parent=True, 89 ) 90 self._subcontainer = ba.containerwidget( 91 parent=self._scrollwidget, 92 size=(self._sub_width, self._sub_height), 93 background=False, 94 claims_left_right=True, 95 claims_tab=True, 96 selection_loops_to_parent=True, 97 ) 98 self._build_gui() 99 100 def _build_gui(self) -> None: 101 from bastd.ui.config import ConfigNumberEdit, ConfigCheckBox 102 from bastd.ui.radiogroup import make_radio_group 103 104 # Clear anything already there. 105 children = self._subcontainer.get_children() 106 for child in children: 107 child.delete() 108 h = 30 109 v = self._sub_height - 85 110 clr = (0.8, 0.8, 0.8, 1.0) 111 clr2 = (0.8, 0.8, 0.8) 112 ba.textwidget( 113 parent=self._subcontainer, 114 position=(-10, v + 43), 115 size=(self._sub_width, 25), 116 text=ba.Lstr(resource=self._r + '.swipeInfoText'), 117 flatness=1.0, 118 color=(0, 0.9, 0.1, 0.7), 119 maxwidth=self._sub_width * 0.9, 120 scale=0.55, 121 h_align='center', 122 v_align='center', 123 ) 124 cur_val = ba.app.config.get('Touch Movement Control Type', 'swipe') 125 ba.textwidget( 126 parent=self._subcontainer, 127 position=(h, v - 2), 128 size=(0, 30), 129 text=ba.Lstr(resource=self._r + '.movementText'), 130 maxwidth=190, 131 color=clr, 132 v_align='center', 133 ) 134 cb1 = ba.checkboxwidget( 135 parent=self._subcontainer, 136 position=(h + 220, v), 137 size=(170, 30), 138 text=ba.Lstr(resource=self._r + '.joystickText'), 139 maxwidth=100, 140 textcolor=clr2, 141 scale=0.9, 142 ) 143 cb2 = ba.checkboxwidget( 144 parent=self._subcontainer, 145 position=(h + 357, v), 146 size=(170, 30), 147 text=ba.Lstr(resource=self._r + '.swipeText'), 148 maxwidth=100, 149 textcolor=clr2, 150 value=False, 151 scale=0.9, 152 ) 153 make_radio_group( 154 (cb1, cb2), ('joystick', 'swipe'), cur_val, self._movement_changed 155 ) 156 v -= 50 157 ConfigNumberEdit( 158 parent=self._subcontainer, 159 position=(h, v), 160 xoffset=65, 161 configkey='Touch Controls Scale Movement', 162 displayname=ba.Lstr(resource=self._r + '.movementControlScaleText'), 163 changesound=False, 164 minval=0.1, 165 maxval=4.0, 166 increment=0.1, 167 ) 168 v -= 50 169 cur_val = ba.app.config.get('Touch Action Control Type', 'buttons') 170 ba.textwidget( 171 parent=self._subcontainer, 172 position=(h, v - 2), 173 size=(0, 30), 174 text=ba.Lstr(resource=self._r + '.actionsText'), 175 maxwidth=190, 176 color=clr, 177 v_align='center', 178 ) 179 cb1 = ba.checkboxwidget( 180 parent=self._subcontainer, 181 position=(h + 220, v), 182 size=(170, 30), 183 text=ba.Lstr(resource=self._r + '.buttonsText'), 184 maxwidth=100, 185 textcolor=clr2, 186 scale=0.9, 187 ) 188 cb2 = ba.checkboxwidget( 189 parent=self._subcontainer, 190 position=(h + 357, v), 191 size=(170, 30), 192 text=ba.Lstr(resource=self._r + '.swipeText'), 193 maxwidth=100, 194 textcolor=clr2, 195 scale=0.9, 196 ) 197 make_radio_group( 198 (cb1, cb2), ('buttons', 'swipe'), cur_val, self._actions_changed 199 ) 200 v -= 50 201 ConfigNumberEdit( 202 parent=self._subcontainer, 203 position=(h, v), 204 xoffset=65, 205 configkey='Touch Controls Scale Actions', 206 displayname=ba.Lstr(resource=self._r + '.actionControlScaleText'), 207 changesound=False, 208 minval=0.1, 209 maxval=4.0, 210 increment=0.1, 211 ) 212 213 v -= 50 214 ConfigCheckBox( 215 parent=self._subcontainer, 216 position=(h, v), 217 size=(400, 30), 218 maxwidth=400, 219 configkey='Touch Controls Swipe Hidden', 220 displayname=ba.Lstr(resource=self._r + '.swipeControlsHiddenText'), 221 ) 222 v -= 65 223 224 ba.buttonwidget( 225 parent=self._subcontainer, 226 position=(self._sub_width * 0.5 - 70, v), 227 size=(170, 60), 228 label=ba.Lstr(resource=self._r + '.resetText'), 229 scale=0.75, 230 on_activate_call=self._reset, 231 ) 232 233 ba.textwidget( 234 parent=self._root_widget, 235 position=(self._width * 0.5, 38), 236 size=(0, 0), 237 h_align='center', 238 text=ba.Lstr(resource=self._r + '.dragControlsText'), 239 maxwidth=self._width * 0.8, 240 scale=0.65, 241 color=(1, 1, 1, 0.4), 242 ) 243 244 def _actions_changed(self, v: str) -> None: 245 cfg = ba.app.config 246 cfg['Touch Action Control Type'] = v 247 cfg.apply_and_commit() 248 249 def _movement_changed(self, v: str) -> None: 250 cfg = ba.app.config 251 cfg['Touch Movement Control Type'] = v 252 cfg.apply_and_commit() 253 254 def _reset(self) -> None: 255 cfg = ba.app.config 256 cfgkeys = [ 257 'Touch Movement Control Type', 258 'Touch Action Control Type', 259 'Touch Controls Scale', 260 'Touch Controls Scale Movement', 261 'Touch Controls Scale Actions', 262 'Touch Controls Swipe Hidden', 263 'Touch DPad X', 264 'Touch DPad Y', 265 'Touch Buttons X', 266 'Touch Buttons Y', 267 ] 268 for cfgkey in cfgkeys: 269 if cfgkey in cfg: 270 del cfg[cfgkey] 271 cfg.apply_and_commit() 272 ba.timer(0, self._build_gui, timetype=ba.TimeType.REAL) 273 274 def _back(self) -> None: 275 from bastd.ui.settings import controls 276 277 ba.containerwidget(edit=self._root_widget, transition='out_right') 278 ba.app.ui.set_main_menu_window( 279 controls.ControlsSettingsWindow( 280 transition='in_left' 281 ).get_root_widget() 282 ) 283 ba.internal.set_touchscreen_editing(False)
class
TouchscreenSettingsWindow(ba.ui.Window):
11class TouchscreenSettingsWindow(ba.Window): 12 """Settings window for touchscreens.""" 13 14 def __del__(self) -> None: 15 # Note - this happens in 'back' too; 16 # we just do it here too in case the window is closed by other means. 17 18 # FIXME: Could switch to a UI destroy callback now that those are a 19 # thing that exists. 20 ba.internal.set_touchscreen_editing(False) 21 22 def __init__(self) -> None: 23 24 self._width = 650 25 self._height = 380 26 self._spacing = 40 27 self._r = 'configTouchscreenWindow' 28 29 ba.internal.set_touchscreen_editing(True) 30 31 uiscale = ba.app.ui.uiscale 32 super().__init__( 33 root_widget=ba.containerwidget( 34 size=(self._width, self._height), 35 transition='in_right', 36 scale=( 37 1.9 38 if uiscale is ba.UIScale.SMALL 39 else 1.55 40 if uiscale is ba.UIScale.MEDIUM 41 else 1.2 42 ), 43 ) 44 ) 45 46 btn = ba.buttonwidget( 47 parent=self._root_widget, 48 position=(55, self._height - 60), 49 size=(120, 60), 50 label=ba.Lstr(resource='backText'), 51 button_type='back', 52 scale=0.8, 53 on_activate_call=self._back, 54 ) 55 ba.containerwidget(edit=self._root_widget, cancel_button=btn) 56 57 ba.textwidget( 58 parent=self._root_widget, 59 position=(25, self._height - 50), 60 size=(self._width, 25), 61 text=ba.Lstr(resource=self._r + '.titleText'), 62 color=ba.app.ui.title_color, 63 maxwidth=280, 64 h_align='center', 65 v_align='center', 66 ) 67 68 ba.buttonwidget( 69 edit=btn, 70 button_type='backSmall', 71 size=(60, 60), 72 label=ba.charstr(ba.SpecialChar.BACK), 73 ) 74 75 self._scroll_width = self._width - 100 76 self._scroll_height = self._height - 110 77 self._sub_width = self._scroll_width - 20 78 self._sub_height = 360 79 80 self._scrollwidget = ba.scrollwidget( 81 parent=self._root_widget, 82 position=( 83 (self._width - self._scroll_width) * 0.5, 84 self._height - 65 - self._scroll_height, 85 ), 86 size=(self._scroll_width, self._scroll_height), 87 claims_left_right=True, 88 claims_tab=True, 89 selection_loops_to_parent=True, 90 ) 91 self._subcontainer = ba.containerwidget( 92 parent=self._scrollwidget, 93 size=(self._sub_width, self._sub_height), 94 background=False, 95 claims_left_right=True, 96 claims_tab=True, 97 selection_loops_to_parent=True, 98 ) 99 self._build_gui() 100 101 def _build_gui(self) -> None: 102 from bastd.ui.config import ConfigNumberEdit, ConfigCheckBox 103 from bastd.ui.radiogroup import make_radio_group 104 105 # Clear anything already there. 106 children = self._subcontainer.get_children() 107 for child in children: 108 child.delete() 109 h = 30 110 v = self._sub_height - 85 111 clr = (0.8, 0.8, 0.8, 1.0) 112 clr2 = (0.8, 0.8, 0.8) 113 ba.textwidget( 114 parent=self._subcontainer, 115 position=(-10, v + 43), 116 size=(self._sub_width, 25), 117 text=ba.Lstr(resource=self._r + '.swipeInfoText'), 118 flatness=1.0, 119 color=(0, 0.9, 0.1, 0.7), 120 maxwidth=self._sub_width * 0.9, 121 scale=0.55, 122 h_align='center', 123 v_align='center', 124 ) 125 cur_val = ba.app.config.get('Touch Movement Control Type', 'swipe') 126 ba.textwidget( 127 parent=self._subcontainer, 128 position=(h, v - 2), 129 size=(0, 30), 130 text=ba.Lstr(resource=self._r + '.movementText'), 131 maxwidth=190, 132 color=clr, 133 v_align='center', 134 ) 135 cb1 = ba.checkboxwidget( 136 parent=self._subcontainer, 137 position=(h + 220, v), 138 size=(170, 30), 139 text=ba.Lstr(resource=self._r + '.joystickText'), 140 maxwidth=100, 141 textcolor=clr2, 142 scale=0.9, 143 ) 144 cb2 = ba.checkboxwidget( 145 parent=self._subcontainer, 146 position=(h + 357, v), 147 size=(170, 30), 148 text=ba.Lstr(resource=self._r + '.swipeText'), 149 maxwidth=100, 150 textcolor=clr2, 151 value=False, 152 scale=0.9, 153 ) 154 make_radio_group( 155 (cb1, cb2), ('joystick', 'swipe'), cur_val, self._movement_changed 156 ) 157 v -= 50 158 ConfigNumberEdit( 159 parent=self._subcontainer, 160 position=(h, v), 161 xoffset=65, 162 configkey='Touch Controls Scale Movement', 163 displayname=ba.Lstr(resource=self._r + '.movementControlScaleText'), 164 changesound=False, 165 minval=0.1, 166 maxval=4.0, 167 increment=0.1, 168 ) 169 v -= 50 170 cur_val = ba.app.config.get('Touch Action Control Type', 'buttons') 171 ba.textwidget( 172 parent=self._subcontainer, 173 position=(h, v - 2), 174 size=(0, 30), 175 text=ba.Lstr(resource=self._r + '.actionsText'), 176 maxwidth=190, 177 color=clr, 178 v_align='center', 179 ) 180 cb1 = ba.checkboxwidget( 181 parent=self._subcontainer, 182 position=(h + 220, v), 183 size=(170, 30), 184 text=ba.Lstr(resource=self._r + '.buttonsText'), 185 maxwidth=100, 186 textcolor=clr2, 187 scale=0.9, 188 ) 189 cb2 = ba.checkboxwidget( 190 parent=self._subcontainer, 191 position=(h + 357, v), 192 size=(170, 30), 193 text=ba.Lstr(resource=self._r + '.swipeText'), 194 maxwidth=100, 195 textcolor=clr2, 196 scale=0.9, 197 ) 198 make_radio_group( 199 (cb1, cb2), ('buttons', 'swipe'), cur_val, self._actions_changed 200 ) 201 v -= 50 202 ConfigNumberEdit( 203 parent=self._subcontainer, 204 position=(h, v), 205 xoffset=65, 206 configkey='Touch Controls Scale Actions', 207 displayname=ba.Lstr(resource=self._r + '.actionControlScaleText'), 208 changesound=False, 209 minval=0.1, 210 maxval=4.0, 211 increment=0.1, 212 ) 213 214 v -= 50 215 ConfigCheckBox( 216 parent=self._subcontainer, 217 position=(h, v), 218 size=(400, 30), 219 maxwidth=400, 220 configkey='Touch Controls Swipe Hidden', 221 displayname=ba.Lstr(resource=self._r + '.swipeControlsHiddenText'), 222 ) 223 v -= 65 224 225 ba.buttonwidget( 226 parent=self._subcontainer, 227 position=(self._sub_width * 0.5 - 70, v), 228 size=(170, 60), 229 label=ba.Lstr(resource=self._r + '.resetText'), 230 scale=0.75, 231 on_activate_call=self._reset, 232 ) 233 234 ba.textwidget( 235 parent=self._root_widget, 236 position=(self._width * 0.5, 38), 237 size=(0, 0), 238 h_align='center', 239 text=ba.Lstr(resource=self._r + '.dragControlsText'), 240 maxwidth=self._width * 0.8, 241 scale=0.65, 242 color=(1, 1, 1, 0.4), 243 ) 244 245 def _actions_changed(self, v: str) -> None: 246 cfg = ba.app.config 247 cfg['Touch Action Control Type'] = v 248 cfg.apply_and_commit() 249 250 def _movement_changed(self, v: str) -> None: 251 cfg = ba.app.config 252 cfg['Touch Movement Control Type'] = v 253 cfg.apply_and_commit() 254 255 def _reset(self) -> None: 256 cfg = ba.app.config 257 cfgkeys = [ 258 'Touch Movement Control Type', 259 'Touch Action Control Type', 260 'Touch Controls Scale', 261 'Touch Controls Scale Movement', 262 'Touch Controls Scale Actions', 263 'Touch Controls Swipe Hidden', 264 'Touch DPad X', 265 'Touch DPad Y', 266 'Touch Buttons X', 267 'Touch Buttons Y', 268 ] 269 for cfgkey in cfgkeys: 270 if cfgkey in cfg: 271 del cfg[cfgkey] 272 cfg.apply_and_commit() 273 ba.timer(0, self._build_gui, timetype=ba.TimeType.REAL) 274 275 def _back(self) -> None: 276 from bastd.ui.settings import controls 277 278 ba.containerwidget(edit=self._root_widget, transition='out_right') 279 ba.app.ui.set_main_menu_window( 280 controls.ControlsSettingsWindow( 281 transition='in_left' 282 ).get_root_widget() 283 ) 284 ba.internal.set_touchscreen_editing(False)
Settings window for touchscreens.
TouchscreenSettingsWindow()
22 def __init__(self) -> None: 23 24 self._width = 650 25 self._height = 380 26 self._spacing = 40 27 self._r = 'configTouchscreenWindow' 28 29 ba.internal.set_touchscreen_editing(True) 30 31 uiscale = ba.app.ui.uiscale 32 super().__init__( 33 root_widget=ba.containerwidget( 34 size=(self._width, self._height), 35 transition='in_right', 36 scale=( 37 1.9 38 if uiscale is ba.UIScale.SMALL 39 else 1.55 40 if uiscale is ba.UIScale.MEDIUM 41 else 1.2 42 ), 43 ) 44 ) 45 46 btn = ba.buttonwidget( 47 parent=self._root_widget, 48 position=(55, self._height - 60), 49 size=(120, 60), 50 label=ba.Lstr(resource='backText'), 51 button_type='back', 52 scale=0.8, 53 on_activate_call=self._back, 54 ) 55 ba.containerwidget(edit=self._root_widget, cancel_button=btn) 56 57 ba.textwidget( 58 parent=self._root_widget, 59 position=(25, self._height - 50), 60 size=(self._width, 25), 61 text=ba.Lstr(resource=self._r + '.titleText'), 62 color=ba.app.ui.title_color, 63 maxwidth=280, 64 h_align='center', 65 v_align='center', 66 ) 67 68 ba.buttonwidget( 69 edit=btn, 70 button_type='backSmall', 71 size=(60, 60), 72 label=ba.charstr(ba.SpecialChar.BACK), 73 ) 74 75 self._scroll_width = self._width - 100 76 self._scroll_height = self._height - 110 77 self._sub_width = self._scroll_width - 20 78 self._sub_height = 360 79 80 self._scrollwidget = ba.scrollwidget( 81 parent=self._root_widget, 82 position=( 83 (self._width - self._scroll_width) * 0.5, 84 self._height - 65 - self._scroll_height, 85 ), 86 size=(self._scroll_width, self._scroll_height), 87 claims_left_right=True, 88 claims_tab=True, 89 selection_loops_to_parent=True, 90 ) 91 self._subcontainer = ba.containerwidget( 92 parent=self._scrollwidget, 93 size=(self._sub_width, self._sub_height), 94 background=False, 95 claims_left_right=True, 96 claims_tab=True, 97 selection_loops_to_parent=True, 98 ) 99 self._build_gui()
Inherited Members
- ba.ui.Window
- get_root_widget