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 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.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.set_touchscreen_editing(True) 29 30 uiscale = ba.app.ui.uiscale 31 super().__init__(root_widget=ba.containerwidget( 32 size=(self._width, self._height), 33 transition='in_right', 34 scale=(1.9 if uiscale is ba.UIScale.SMALL else 35 1.55 if uiscale is ba.UIScale.MEDIUM else 1.2))) 36 37 btn = ba.buttonwidget(parent=self._root_widget, 38 position=(55, self._height - 60), 39 size=(120, 60), 40 label=ba.Lstr(resource='backText'), 41 button_type='back', 42 scale=0.8, 43 on_activate_call=self._back) 44 ba.containerwidget(edit=self._root_widget, cancel_button=btn) 45 46 ba.textwidget(parent=self._root_widget, 47 position=(25, self._height - 50), 48 size=(self._width, 25), 49 text=ba.Lstr(resource=self._r + '.titleText'), 50 color=ba.app.ui.title_color, 51 maxwidth=280, 52 h_align='center', 53 v_align='center') 54 55 ba.buttonwidget(edit=btn, 56 button_type='backSmall', 57 size=(60, 60), 58 label=ba.charstr(ba.SpecialChar.BACK)) 59 60 self._scroll_width = self._width - 100 61 self._scroll_height = self._height - 110 62 self._sub_width = self._scroll_width - 20 63 self._sub_height = 360 64 65 self._scrollwidget = ba.scrollwidget( 66 parent=self._root_widget, 67 position=((self._width - self._scroll_width) * 0.5, 68 self._height - 65 - self._scroll_height), 69 size=(self._scroll_width, self._scroll_height), 70 claims_left_right=True, 71 claims_tab=True, 72 selection_loops_to_parent=True) 73 self._subcontainer = ba.containerwidget(parent=self._scrollwidget, 74 size=(self._sub_width, 75 self._sub_height), 76 background=False, 77 claims_left_right=True, 78 claims_tab=True, 79 selection_loops_to_parent=True) 80 self._build_gui() 81 82 def _build_gui(self) -> None: 83 from bastd.ui.config import ConfigNumberEdit, ConfigCheckBox 84 from bastd.ui.radiogroup import make_radio_group 85 86 # Clear anything already there. 87 children = self._subcontainer.get_children() 88 for child in children: 89 child.delete() 90 h = 30 91 v = self._sub_height - 85 92 clr = (0.8, 0.8, 0.8, 1.0) 93 clr2 = (0.8, 0.8, 0.8) 94 ba.textwidget(parent=self._subcontainer, 95 position=(-10, v + 43), 96 size=(self._sub_width, 25), 97 text=ba.Lstr(resource=self._r + '.swipeInfoText'), 98 flatness=1.0, 99 color=(0, 0.9, 0.1, 0.7), 100 maxwidth=self._sub_width * 0.9, 101 scale=0.55, 102 h_align='center', 103 v_align='center') 104 cur_val = ba.app.config.get('Touch Movement Control Type', 'swipe') 105 ba.textwidget(parent=self._subcontainer, 106 position=(h, v - 2), 107 size=(0, 30), 108 text=ba.Lstr(resource=self._r + '.movementText'), 109 maxwidth=190, 110 color=clr, 111 v_align='center') 112 cb1 = ba.checkboxwidget(parent=self._subcontainer, 113 position=(h + 220, v), 114 size=(170, 30), 115 text=ba.Lstr(resource=self._r + 116 '.joystickText'), 117 maxwidth=100, 118 textcolor=clr2, 119 scale=0.9) 120 cb2 = ba.checkboxwidget(parent=self._subcontainer, 121 position=(h + 357, v), 122 size=(170, 30), 123 text=ba.Lstr(resource=self._r + '.swipeText'), 124 maxwidth=100, 125 textcolor=clr2, 126 value=False, 127 scale=0.9) 128 make_radio_group((cb1, cb2), ('joystick', 'swipe'), cur_val, 129 self._movement_changed) 130 v -= 50 131 ConfigNumberEdit(parent=self._subcontainer, 132 position=(h, v), 133 xoffset=65, 134 configkey='Touch Controls Scale Movement', 135 displayname=ba.Lstr(resource=self._r + 136 '.movementControlScaleText'), 137 changesound=False, 138 minval=0.1, 139 maxval=4.0, 140 increment=0.1) 141 v -= 50 142 cur_val = ba.app.config.get('Touch Action Control Type', 'buttons') 143 ba.textwidget(parent=self._subcontainer, 144 position=(h, v - 2), 145 size=(0, 30), 146 text=ba.Lstr(resource=self._r + '.actionsText'), 147 maxwidth=190, 148 color=clr, 149 v_align='center') 150 cb1 = ba.checkboxwidget(parent=self._subcontainer, 151 position=(h + 220, v), 152 size=(170, 30), 153 text=ba.Lstr(resource=self._r + 154 '.buttonsText'), 155 maxwidth=100, 156 textcolor=clr2, 157 scale=0.9) 158 cb2 = ba.checkboxwidget(parent=self._subcontainer, 159 position=(h + 357, v), 160 size=(170, 30), 161 text=ba.Lstr(resource=self._r + '.swipeText'), 162 maxwidth=100, 163 textcolor=clr2, 164 scale=0.9) 165 make_radio_group((cb1, cb2), ('buttons', 'swipe'), cur_val, 166 self._actions_changed) 167 v -= 50 168 ConfigNumberEdit(parent=self._subcontainer, 169 position=(h, v), 170 xoffset=65, 171 configkey='Touch Controls Scale Actions', 172 displayname=ba.Lstr(resource=self._r + 173 '.actionControlScaleText'), 174 changesound=False, 175 minval=0.1, 176 maxval=4.0, 177 increment=0.1) 178 179 v -= 50 180 ConfigCheckBox(parent=self._subcontainer, 181 position=(h, v), 182 size=(400, 30), 183 maxwidth=400, 184 configkey='Touch Controls Swipe Hidden', 185 displayname=ba.Lstr(resource=self._r + 186 '.swipeControlsHiddenText')) 187 v -= 65 188 189 ba.buttonwidget(parent=self._subcontainer, 190 position=(self._sub_width * 0.5 - 70, v), 191 size=(170, 60), 192 label=ba.Lstr(resource=self._r + '.resetText'), 193 scale=0.75, 194 on_activate_call=self._reset) 195 196 ba.textwidget(parent=self._root_widget, 197 position=(self._width * 0.5, 38), 198 size=(0, 0), 199 h_align='center', 200 text=ba.Lstr(resource=self._r + '.dragControlsText'), 201 maxwidth=self._width * 0.8, 202 scale=0.65, 203 color=(1, 1, 1, 0.4)) 204 205 def _actions_changed(self, v: str) -> None: 206 cfg = ba.app.config 207 cfg['Touch Action Control Type'] = v 208 cfg.apply_and_commit() 209 210 def _movement_changed(self, v: str) -> None: 211 cfg = ba.app.config 212 cfg['Touch Movement Control Type'] = v 213 cfg.apply_and_commit() 214 215 def _reset(self) -> None: 216 cfg = ba.app.config 217 cfgkeys = [ 218 'Touch Movement Control Type', 'Touch Action Control Type', 219 'Touch Controls Scale', 'Touch Controls Scale Movement', 220 'Touch Controls Scale Actions', 'Touch Controls Swipe Hidden', 221 'Touch DPad X', 'Touch DPad Y', 'Touch Buttons X', 222 'Touch Buttons Y' 223 ] 224 for cfgkey in cfgkeys: 225 if cfgkey in cfg: 226 del cfg[cfgkey] 227 cfg.apply_and_commit() 228 ba.timer(0, self._build_gui, timetype=ba.TimeType.REAL) 229 230 def _back(self) -> None: 231 from bastd.ui.settings import controls 232 ba.containerwidget(edit=self._root_widget, transition='out_right') 233 ba.app.ui.set_main_menu_window( 234 controls.ControlsSettingsWindow( 235 transition='in_left').get_root_widget()) 236 _ba.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.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.set_touchscreen_editing(True) 30 31 uiscale = ba.app.ui.uiscale 32 super().__init__(root_widget=ba.containerwidget( 33 size=(self._width, self._height), 34 transition='in_right', 35 scale=(1.9 if uiscale is ba.UIScale.SMALL else 36 1.55 if uiscale is ba.UIScale.MEDIUM else 1.2))) 37 38 btn = ba.buttonwidget(parent=self._root_widget, 39 position=(55, self._height - 60), 40 size=(120, 60), 41 label=ba.Lstr(resource='backText'), 42 button_type='back', 43 scale=0.8, 44 on_activate_call=self._back) 45 ba.containerwidget(edit=self._root_widget, cancel_button=btn) 46 47 ba.textwidget(parent=self._root_widget, 48 position=(25, self._height - 50), 49 size=(self._width, 25), 50 text=ba.Lstr(resource=self._r + '.titleText'), 51 color=ba.app.ui.title_color, 52 maxwidth=280, 53 h_align='center', 54 v_align='center') 55 56 ba.buttonwidget(edit=btn, 57 button_type='backSmall', 58 size=(60, 60), 59 label=ba.charstr(ba.SpecialChar.BACK)) 60 61 self._scroll_width = self._width - 100 62 self._scroll_height = self._height - 110 63 self._sub_width = self._scroll_width - 20 64 self._sub_height = 360 65 66 self._scrollwidget = ba.scrollwidget( 67 parent=self._root_widget, 68 position=((self._width - self._scroll_width) * 0.5, 69 self._height - 65 - self._scroll_height), 70 size=(self._scroll_width, self._scroll_height), 71 claims_left_right=True, 72 claims_tab=True, 73 selection_loops_to_parent=True) 74 self._subcontainer = ba.containerwidget(parent=self._scrollwidget, 75 size=(self._sub_width, 76 self._sub_height), 77 background=False, 78 claims_left_right=True, 79 claims_tab=True, 80 selection_loops_to_parent=True) 81 self._build_gui() 82 83 def _build_gui(self) -> None: 84 from bastd.ui.config import ConfigNumberEdit, ConfigCheckBox 85 from bastd.ui.radiogroup import make_radio_group 86 87 # Clear anything already there. 88 children = self._subcontainer.get_children() 89 for child in children: 90 child.delete() 91 h = 30 92 v = self._sub_height - 85 93 clr = (0.8, 0.8, 0.8, 1.0) 94 clr2 = (0.8, 0.8, 0.8) 95 ba.textwidget(parent=self._subcontainer, 96 position=(-10, v + 43), 97 size=(self._sub_width, 25), 98 text=ba.Lstr(resource=self._r + '.swipeInfoText'), 99 flatness=1.0, 100 color=(0, 0.9, 0.1, 0.7), 101 maxwidth=self._sub_width * 0.9, 102 scale=0.55, 103 h_align='center', 104 v_align='center') 105 cur_val = ba.app.config.get('Touch Movement Control Type', 'swipe') 106 ba.textwidget(parent=self._subcontainer, 107 position=(h, v - 2), 108 size=(0, 30), 109 text=ba.Lstr(resource=self._r + '.movementText'), 110 maxwidth=190, 111 color=clr, 112 v_align='center') 113 cb1 = ba.checkboxwidget(parent=self._subcontainer, 114 position=(h + 220, v), 115 size=(170, 30), 116 text=ba.Lstr(resource=self._r + 117 '.joystickText'), 118 maxwidth=100, 119 textcolor=clr2, 120 scale=0.9) 121 cb2 = ba.checkboxwidget(parent=self._subcontainer, 122 position=(h + 357, v), 123 size=(170, 30), 124 text=ba.Lstr(resource=self._r + '.swipeText'), 125 maxwidth=100, 126 textcolor=clr2, 127 value=False, 128 scale=0.9) 129 make_radio_group((cb1, cb2), ('joystick', 'swipe'), cur_val, 130 self._movement_changed) 131 v -= 50 132 ConfigNumberEdit(parent=self._subcontainer, 133 position=(h, v), 134 xoffset=65, 135 configkey='Touch Controls Scale Movement', 136 displayname=ba.Lstr(resource=self._r + 137 '.movementControlScaleText'), 138 changesound=False, 139 minval=0.1, 140 maxval=4.0, 141 increment=0.1) 142 v -= 50 143 cur_val = ba.app.config.get('Touch Action Control Type', 'buttons') 144 ba.textwidget(parent=self._subcontainer, 145 position=(h, v - 2), 146 size=(0, 30), 147 text=ba.Lstr(resource=self._r + '.actionsText'), 148 maxwidth=190, 149 color=clr, 150 v_align='center') 151 cb1 = ba.checkboxwidget(parent=self._subcontainer, 152 position=(h + 220, v), 153 size=(170, 30), 154 text=ba.Lstr(resource=self._r + 155 '.buttonsText'), 156 maxwidth=100, 157 textcolor=clr2, 158 scale=0.9) 159 cb2 = ba.checkboxwidget(parent=self._subcontainer, 160 position=(h + 357, v), 161 size=(170, 30), 162 text=ba.Lstr(resource=self._r + '.swipeText'), 163 maxwidth=100, 164 textcolor=clr2, 165 scale=0.9) 166 make_radio_group((cb1, cb2), ('buttons', 'swipe'), cur_val, 167 self._actions_changed) 168 v -= 50 169 ConfigNumberEdit(parent=self._subcontainer, 170 position=(h, v), 171 xoffset=65, 172 configkey='Touch Controls Scale Actions', 173 displayname=ba.Lstr(resource=self._r + 174 '.actionControlScaleText'), 175 changesound=False, 176 minval=0.1, 177 maxval=4.0, 178 increment=0.1) 179 180 v -= 50 181 ConfigCheckBox(parent=self._subcontainer, 182 position=(h, v), 183 size=(400, 30), 184 maxwidth=400, 185 configkey='Touch Controls Swipe Hidden', 186 displayname=ba.Lstr(resource=self._r + 187 '.swipeControlsHiddenText')) 188 v -= 65 189 190 ba.buttonwidget(parent=self._subcontainer, 191 position=(self._sub_width * 0.5 - 70, v), 192 size=(170, 60), 193 label=ba.Lstr(resource=self._r + '.resetText'), 194 scale=0.75, 195 on_activate_call=self._reset) 196 197 ba.textwidget(parent=self._root_widget, 198 position=(self._width * 0.5, 38), 199 size=(0, 0), 200 h_align='center', 201 text=ba.Lstr(resource=self._r + '.dragControlsText'), 202 maxwidth=self._width * 0.8, 203 scale=0.65, 204 color=(1, 1, 1, 0.4)) 205 206 def _actions_changed(self, v: str) -> None: 207 cfg = ba.app.config 208 cfg['Touch Action Control Type'] = v 209 cfg.apply_and_commit() 210 211 def _movement_changed(self, v: str) -> None: 212 cfg = ba.app.config 213 cfg['Touch Movement Control Type'] = v 214 cfg.apply_and_commit() 215 216 def _reset(self) -> None: 217 cfg = ba.app.config 218 cfgkeys = [ 219 'Touch Movement Control Type', 'Touch Action Control Type', 220 'Touch Controls Scale', 'Touch Controls Scale Movement', 221 'Touch Controls Scale Actions', 'Touch Controls Swipe Hidden', 222 'Touch DPad X', 'Touch DPad Y', 'Touch Buttons X', 223 'Touch Buttons Y' 224 ] 225 for cfgkey in cfgkeys: 226 if cfgkey in cfg: 227 del cfg[cfgkey] 228 cfg.apply_and_commit() 229 ba.timer(0, self._build_gui, timetype=ba.TimeType.REAL) 230 231 def _back(self) -> None: 232 from bastd.ui.settings import controls 233 ba.containerwidget(edit=self._root_widget, transition='out_right') 234 ba.app.ui.set_main_menu_window( 235 controls.ControlsSettingsWindow( 236 transition='in_left').get_root_widget()) 237 _ba.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.set_touchscreen_editing(True) 30 31 uiscale = ba.app.ui.uiscale 32 super().__init__(root_widget=ba.containerwidget( 33 size=(self._width, self._height), 34 transition='in_right', 35 scale=(1.9 if uiscale is ba.UIScale.SMALL else 36 1.55 if uiscale is ba.UIScale.MEDIUM else 1.2))) 37 38 btn = ba.buttonwidget(parent=self._root_widget, 39 position=(55, self._height - 60), 40 size=(120, 60), 41 label=ba.Lstr(resource='backText'), 42 button_type='back', 43 scale=0.8, 44 on_activate_call=self._back) 45 ba.containerwidget(edit=self._root_widget, cancel_button=btn) 46 47 ba.textwidget(parent=self._root_widget, 48 position=(25, self._height - 50), 49 size=(self._width, 25), 50 text=ba.Lstr(resource=self._r + '.titleText'), 51 color=ba.app.ui.title_color, 52 maxwidth=280, 53 h_align='center', 54 v_align='center') 55 56 ba.buttonwidget(edit=btn, 57 button_type='backSmall', 58 size=(60, 60), 59 label=ba.charstr(ba.SpecialChar.BACK)) 60 61 self._scroll_width = self._width - 100 62 self._scroll_height = self._height - 110 63 self._sub_width = self._scroll_width - 20 64 self._sub_height = 360 65 66 self._scrollwidget = ba.scrollwidget( 67 parent=self._root_widget, 68 position=((self._width - self._scroll_width) * 0.5, 69 self._height - 65 - self._scroll_height), 70 size=(self._scroll_width, self._scroll_height), 71 claims_left_right=True, 72 claims_tab=True, 73 selection_loops_to_parent=True) 74 self._subcontainer = ba.containerwidget(parent=self._scrollwidget, 75 size=(self._sub_width, 76 self._sub_height), 77 background=False, 78 claims_left_right=True, 79 claims_tab=True, 80 selection_loops_to_parent=True) 81 self._build_gui()
Inherited Members
- ba.ui.Window
- get_root_widget