bastd.ui.debug
UIs for debugging purposes.
1# Released under the MIT License. See LICENSE for details. 2# 3"""UIs for debugging purposes.""" 4 5from __future__ import annotations 6 7from typing import TYPE_CHECKING, cast 8 9import ba 10 11if TYPE_CHECKING: 12 pass 13 14 15class DebugWindow(ba.Window): 16 """Window for debugging internal values.""" 17 18 def __init__(self, transition: str | None = 'in_right'): 19 # pylint: disable=too-many-statements 20 # pylint: disable=cyclic-import 21 from bastd.ui import popup 22 23 ba.app.ui.set_main_menu_location('Benchmarks & Stress Tests') 24 uiscale = ba.app.ui.uiscale 25 self._width = width = 580 26 self._height = height = ( 27 350 28 if uiscale is ba.UIScale.SMALL 29 else 420 30 if uiscale is ba.UIScale.MEDIUM 31 else 520 32 ) 33 34 self._scroll_width = self._width - 100 35 self._scroll_height = self._height - 120 36 37 self._sub_width = self._scroll_width * 0.95 38 self._sub_height = 520 39 40 self._stress_test_game_type = 'Random' 41 self._stress_test_playlist = '__default__' 42 self._stress_test_player_count = 8 43 self._stress_test_round_duration = 30 44 45 self._r = 'debugWindow' 46 uiscale = ba.app.ui.uiscale 47 super().__init__( 48 root_widget=ba.containerwidget( 49 size=(width, height), 50 transition=transition, 51 scale=( 52 2.35 53 if uiscale is ba.UIScale.SMALL 54 else 1.55 55 if uiscale is ba.UIScale.MEDIUM 56 else 1.0 57 ), 58 stack_offset=(0, -30) 59 if uiscale is ba.UIScale.SMALL 60 else (0, 0), 61 ) 62 ) 63 64 self._done_button = btn = ba.buttonwidget( 65 parent=self._root_widget, 66 position=(40, height - 67), 67 size=(120, 60), 68 scale=0.8, 69 autoselect=True, 70 label=ba.Lstr(resource='doneText'), 71 on_activate_call=self._done, 72 ) 73 ba.containerwidget(edit=self._root_widget, cancel_button=btn) 74 ba.textwidget( 75 parent=self._root_widget, 76 position=(0, height - 60), 77 size=(width, 30), 78 text=ba.Lstr(resource=self._r + '.titleText'), 79 h_align='center', 80 color=ba.app.ui.title_color, 81 v_align='center', 82 maxwidth=260, 83 ) 84 85 self._scrollwidget = ba.scrollwidget( 86 parent=self._root_widget, 87 highlight=False, 88 size=(self._scroll_width, self._scroll_height), 89 position=((self._width - self._scroll_width) * 0.5, 50), 90 ) 91 ba.containerwidget(edit=self._scrollwidget, claims_left_right=True) 92 93 self._subcontainer = ba.containerwidget( 94 parent=self._scrollwidget, 95 size=(self._sub_width, self._sub_height), 96 background=False, 97 ) 98 99 v = self._sub_height - 70 100 button_width = 300 101 btn = ba.buttonwidget( 102 parent=self._subcontainer, 103 position=((self._sub_width - button_width) * 0.5, v), 104 size=(button_width, 60), 105 autoselect=True, 106 label=ba.Lstr(resource=self._r + '.runCPUBenchmarkText'), 107 on_activate_call=self._run_cpu_benchmark_pressed, 108 ) 109 ba.widget( 110 edit=btn, up_widget=self._done_button, left_widget=self._done_button 111 ) 112 v -= 60 113 114 ba.buttonwidget( 115 parent=self._subcontainer, 116 position=((self._sub_width - button_width) * 0.5, v), 117 size=(button_width, 60), 118 autoselect=True, 119 label=ba.Lstr(resource=self._r + '.runGPUBenchmarkText'), 120 on_activate_call=self._run_gpu_benchmark_pressed, 121 ) 122 v -= 60 123 124 ba.buttonwidget( 125 parent=self._subcontainer, 126 position=((self._sub_width - button_width) * 0.5, v), 127 size=(button_width, 60), 128 autoselect=True, 129 label=ba.Lstr(resource=self._r + '.runMediaReloadBenchmarkText'), 130 on_activate_call=self._run_media_reload_benchmark_pressed, 131 ) 132 v -= 60 133 134 ba.textwidget( 135 parent=self._subcontainer, 136 position=(self._sub_width * 0.5, v + 22), 137 size=(0, 0), 138 text=ba.Lstr(resource=self._r + '.stressTestTitleText'), 139 maxwidth=200, 140 color=ba.app.ui.heading_color, 141 scale=0.85, 142 h_align='center', 143 v_align='center', 144 ) 145 v -= 45 146 147 x_offs = 165 148 ba.textwidget( 149 parent=self._subcontainer, 150 position=(x_offs - 10, v + 22), 151 size=(0, 0), 152 text=ba.Lstr(resource=self._r + '.stressTestPlaylistTypeText'), 153 maxwidth=130, 154 color=ba.app.ui.heading_color, 155 scale=0.65, 156 h_align='right', 157 v_align='center', 158 ) 159 160 popup.PopupMenu( 161 parent=self._subcontainer, 162 position=(x_offs, v), 163 width=150, 164 choices=['Random', 'Teams', 'Free-For-All'], 165 choices_display=[ 166 ba.Lstr(resource=a) 167 for a in [ 168 'randomText', 169 'playModes.teamsText', 170 'playModes.freeForAllText', 171 ] 172 ], 173 current_choice='Auto', 174 on_value_change_call=self._stress_test_game_type_selected, 175 ) 176 177 v -= 46 178 ba.textwidget( 179 parent=self._subcontainer, 180 position=(x_offs - 10, v + 22), 181 size=(0, 0), 182 text=ba.Lstr(resource=self._r + '.stressTestPlaylistNameText'), 183 maxwidth=130, 184 color=ba.app.ui.heading_color, 185 scale=0.65, 186 h_align='right', 187 v_align='center', 188 ) 189 190 self._stress_test_playlist_name_field = ba.textwidget( 191 parent=self._subcontainer, 192 position=(x_offs + 5, v - 5), 193 size=(250, 46), 194 text=self._stress_test_playlist, 195 h_align='left', 196 v_align='center', 197 autoselect=True, 198 color=(0.9, 0.9, 0.9, 1.0), 199 description=ba.Lstr( 200 resource=self._r + '.stressTestPlaylistDescriptionText' 201 ), 202 editable=True, 203 padding=4, 204 ) 205 v -= 29 206 x_sub = 60 207 208 # Player count. 209 ba.textwidget( 210 parent=self._subcontainer, 211 position=(x_offs - 10, v), 212 size=(0, 0), 213 text=ba.Lstr(resource=self._r + '.stressTestPlayerCountText'), 214 color=(0.8, 0.8, 0.8, 1.0), 215 h_align='right', 216 v_align='center', 217 scale=0.65, 218 maxwidth=130, 219 ) 220 self._stress_test_player_count_text = ba.textwidget( 221 parent=self._subcontainer, 222 position=(246 - x_sub, v - 14), 223 size=(60, 28), 224 editable=False, 225 color=(0.3, 1.0, 0.3, 1.0), 226 h_align='right', 227 v_align='center', 228 text=str(self._stress_test_player_count), 229 padding=2, 230 ) 231 ba.buttonwidget( 232 parent=self._subcontainer, 233 position=(330 - x_sub, v - 11), 234 size=(28, 28), 235 label='-', 236 autoselect=True, 237 on_activate_call=ba.Call(self._stress_test_player_count_decrement), 238 repeat=True, 239 enable_sound=True, 240 ) 241 ba.buttonwidget( 242 parent=self._subcontainer, 243 position=(380 - x_sub, v - 11), 244 size=(28, 28), 245 label='+', 246 autoselect=True, 247 on_activate_call=ba.Call(self._stress_test_player_count_increment), 248 repeat=True, 249 enable_sound=True, 250 ) 251 v -= 42 252 253 # Round duration. 254 ba.textwidget( 255 parent=self._subcontainer, 256 position=(x_offs - 10, v), 257 size=(0, 0), 258 text=ba.Lstr(resource=self._r + '.stressTestRoundDurationText'), 259 color=(0.8, 0.8, 0.8, 1.0), 260 h_align='right', 261 v_align='center', 262 scale=0.65, 263 maxwidth=130, 264 ) 265 self._stress_test_round_duration_text = ba.textwidget( 266 parent=self._subcontainer, 267 position=(246 - x_sub, v - 14), 268 size=(60, 28), 269 editable=False, 270 color=(0.3, 1.0, 0.3, 1.0), 271 h_align='right', 272 v_align='center', 273 text=str(self._stress_test_round_duration), 274 padding=2, 275 ) 276 ba.buttonwidget( 277 parent=self._subcontainer, 278 position=(330 - x_sub, v - 11), 279 size=(28, 28), 280 label='-', 281 autoselect=True, 282 on_activate_call=ba.Call( 283 self._stress_test_round_duration_decrement 284 ), 285 repeat=True, 286 enable_sound=True, 287 ) 288 ba.buttonwidget( 289 parent=self._subcontainer, 290 position=(380 - x_sub, v - 11), 291 size=(28, 28), 292 label='+', 293 autoselect=True, 294 on_activate_call=ba.Call( 295 self._stress_test_round_duration_increment 296 ), 297 repeat=True, 298 enable_sound=True, 299 ) 300 v -= 82 301 btn = ba.buttonwidget( 302 parent=self._subcontainer, 303 position=((self._sub_width - button_width) * 0.5, v), 304 size=(button_width, 60), 305 autoselect=True, 306 label=ba.Lstr(resource=self._r + '.runStressTestText'), 307 on_activate_call=self._stress_test_pressed, 308 ) 309 ba.widget(btn, show_buffer_bottom=50) 310 311 def _stress_test_player_count_decrement(self) -> None: 312 self._stress_test_player_count = max( 313 1, self._stress_test_player_count - 1 314 ) 315 ba.textwidget( 316 edit=self._stress_test_player_count_text, 317 text=str(self._stress_test_player_count), 318 ) 319 320 def _stress_test_player_count_increment(self) -> None: 321 self._stress_test_player_count = self._stress_test_player_count + 1 322 ba.textwidget( 323 edit=self._stress_test_player_count_text, 324 text=str(self._stress_test_player_count), 325 ) 326 327 def _stress_test_round_duration_decrement(self) -> None: 328 self._stress_test_round_duration = max( 329 10, self._stress_test_round_duration - 10 330 ) 331 ba.textwidget( 332 edit=self._stress_test_round_duration_text, 333 text=str(self._stress_test_round_duration), 334 ) 335 336 def _stress_test_round_duration_increment(self) -> None: 337 self._stress_test_round_duration = self._stress_test_round_duration + 10 338 ba.textwidget( 339 edit=self._stress_test_round_duration_text, 340 text=str(self._stress_test_round_duration), 341 ) 342 343 def _stress_test_game_type_selected(self, game_type: str) -> None: 344 self._stress_test_game_type = game_type 345 346 def _run_cpu_benchmark_pressed(self) -> None: 347 from ba.internal import run_cpu_benchmark 348 349 run_cpu_benchmark() 350 351 def _run_gpu_benchmark_pressed(self) -> None: 352 from ba.internal import run_gpu_benchmark 353 354 run_gpu_benchmark() 355 356 def _run_media_reload_benchmark_pressed(self) -> None: 357 from ba.internal import run_media_reload_benchmark 358 359 run_media_reload_benchmark() 360 361 def _stress_test_pressed(self) -> None: 362 from ba.internal import run_stress_test 363 364 run_stress_test( 365 playlist_type=self._stress_test_game_type, 366 playlist_name=cast( 367 str, ba.textwidget(query=self._stress_test_playlist_name_field) 368 ), 369 player_count=self._stress_test_player_count, 370 round_duration=self._stress_test_round_duration, 371 ) 372 ba.containerwidget(edit=self._root_widget, transition='out_right') 373 374 def _done(self) -> None: 375 # pylint: disable=cyclic-import 376 from bastd.ui.settings.advanced import AdvancedSettingsWindow 377 378 ba.containerwidget(edit=self._root_widget, transition='out_right') 379 ba.app.ui.set_main_menu_window( 380 AdvancedSettingsWindow(transition='in_left').get_root_widget() 381 )
class
DebugWindow(ba.ui.Window):
16class DebugWindow(ba.Window): 17 """Window for debugging internal values.""" 18 19 def __init__(self, transition: str | None = 'in_right'): 20 # pylint: disable=too-many-statements 21 # pylint: disable=cyclic-import 22 from bastd.ui import popup 23 24 ba.app.ui.set_main_menu_location('Benchmarks & Stress Tests') 25 uiscale = ba.app.ui.uiscale 26 self._width = width = 580 27 self._height = height = ( 28 350 29 if uiscale is ba.UIScale.SMALL 30 else 420 31 if uiscale is ba.UIScale.MEDIUM 32 else 520 33 ) 34 35 self._scroll_width = self._width - 100 36 self._scroll_height = self._height - 120 37 38 self._sub_width = self._scroll_width * 0.95 39 self._sub_height = 520 40 41 self._stress_test_game_type = 'Random' 42 self._stress_test_playlist = '__default__' 43 self._stress_test_player_count = 8 44 self._stress_test_round_duration = 30 45 46 self._r = 'debugWindow' 47 uiscale = ba.app.ui.uiscale 48 super().__init__( 49 root_widget=ba.containerwidget( 50 size=(width, height), 51 transition=transition, 52 scale=( 53 2.35 54 if uiscale is ba.UIScale.SMALL 55 else 1.55 56 if uiscale is ba.UIScale.MEDIUM 57 else 1.0 58 ), 59 stack_offset=(0, -30) 60 if uiscale is ba.UIScale.SMALL 61 else (0, 0), 62 ) 63 ) 64 65 self._done_button = btn = ba.buttonwidget( 66 parent=self._root_widget, 67 position=(40, height - 67), 68 size=(120, 60), 69 scale=0.8, 70 autoselect=True, 71 label=ba.Lstr(resource='doneText'), 72 on_activate_call=self._done, 73 ) 74 ba.containerwidget(edit=self._root_widget, cancel_button=btn) 75 ba.textwidget( 76 parent=self._root_widget, 77 position=(0, height - 60), 78 size=(width, 30), 79 text=ba.Lstr(resource=self._r + '.titleText'), 80 h_align='center', 81 color=ba.app.ui.title_color, 82 v_align='center', 83 maxwidth=260, 84 ) 85 86 self._scrollwidget = ba.scrollwidget( 87 parent=self._root_widget, 88 highlight=False, 89 size=(self._scroll_width, self._scroll_height), 90 position=((self._width - self._scroll_width) * 0.5, 50), 91 ) 92 ba.containerwidget(edit=self._scrollwidget, claims_left_right=True) 93 94 self._subcontainer = ba.containerwidget( 95 parent=self._scrollwidget, 96 size=(self._sub_width, self._sub_height), 97 background=False, 98 ) 99 100 v = self._sub_height - 70 101 button_width = 300 102 btn = ba.buttonwidget( 103 parent=self._subcontainer, 104 position=((self._sub_width - button_width) * 0.5, v), 105 size=(button_width, 60), 106 autoselect=True, 107 label=ba.Lstr(resource=self._r + '.runCPUBenchmarkText'), 108 on_activate_call=self._run_cpu_benchmark_pressed, 109 ) 110 ba.widget( 111 edit=btn, up_widget=self._done_button, left_widget=self._done_button 112 ) 113 v -= 60 114 115 ba.buttonwidget( 116 parent=self._subcontainer, 117 position=((self._sub_width - button_width) * 0.5, v), 118 size=(button_width, 60), 119 autoselect=True, 120 label=ba.Lstr(resource=self._r + '.runGPUBenchmarkText'), 121 on_activate_call=self._run_gpu_benchmark_pressed, 122 ) 123 v -= 60 124 125 ba.buttonwidget( 126 parent=self._subcontainer, 127 position=((self._sub_width - button_width) * 0.5, v), 128 size=(button_width, 60), 129 autoselect=True, 130 label=ba.Lstr(resource=self._r + '.runMediaReloadBenchmarkText'), 131 on_activate_call=self._run_media_reload_benchmark_pressed, 132 ) 133 v -= 60 134 135 ba.textwidget( 136 parent=self._subcontainer, 137 position=(self._sub_width * 0.5, v + 22), 138 size=(0, 0), 139 text=ba.Lstr(resource=self._r + '.stressTestTitleText'), 140 maxwidth=200, 141 color=ba.app.ui.heading_color, 142 scale=0.85, 143 h_align='center', 144 v_align='center', 145 ) 146 v -= 45 147 148 x_offs = 165 149 ba.textwidget( 150 parent=self._subcontainer, 151 position=(x_offs - 10, v + 22), 152 size=(0, 0), 153 text=ba.Lstr(resource=self._r + '.stressTestPlaylistTypeText'), 154 maxwidth=130, 155 color=ba.app.ui.heading_color, 156 scale=0.65, 157 h_align='right', 158 v_align='center', 159 ) 160 161 popup.PopupMenu( 162 parent=self._subcontainer, 163 position=(x_offs, v), 164 width=150, 165 choices=['Random', 'Teams', 'Free-For-All'], 166 choices_display=[ 167 ba.Lstr(resource=a) 168 for a in [ 169 'randomText', 170 'playModes.teamsText', 171 'playModes.freeForAllText', 172 ] 173 ], 174 current_choice='Auto', 175 on_value_change_call=self._stress_test_game_type_selected, 176 ) 177 178 v -= 46 179 ba.textwidget( 180 parent=self._subcontainer, 181 position=(x_offs - 10, v + 22), 182 size=(0, 0), 183 text=ba.Lstr(resource=self._r + '.stressTestPlaylistNameText'), 184 maxwidth=130, 185 color=ba.app.ui.heading_color, 186 scale=0.65, 187 h_align='right', 188 v_align='center', 189 ) 190 191 self._stress_test_playlist_name_field = ba.textwidget( 192 parent=self._subcontainer, 193 position=(x_offs + 5, v - 5), 194 size=(250, 46), 195 text=self._stress_test_playlist, 196 h_align='left', 197 v_align='center', 198 autoselect=True, 199 color=(0.9, 0.9, 0.9, 1.0), 200 description=ba.Lstr( 201 resource=self._r + '.stressTestPlaylistDescriptionText' 202 ), 203 editable=True, 204 padding=4, 205 ) 206 v -= 29 207 x_sub = 60 208 209 # Player count. 210 ba.textwidget( 211 parent=self._subcontainer, 212 position=(x_offs - 10, v), 213 size=(0, 0), 214 text=ba.Lstr(resource=self._r + '.stressTestPlayerCountText'), 215 color=(0.8, 0.8, 0.8, 1.0), 216 h_align='right', 217 v_align='center', 218 scale=0.65, 219 maxwidth=130, 220 ) 221 self._stress_test_player_count_text = ba.textwidget( 222 parent=self._subcontainer, 223 position=(246 - x_sub, v - 14), 224 size=(60, 28), 225 editable=False, 226 color=(0.3, 1.0, 0.3, 1.0), 227 h_align='right', 228 v_align='center', 229 text=str(self._stress_test_player_count), 230 padding=2, 231 ) 232 ba.buttonwidget( 233 parent=self._subcontainer, 234 position=(330 - x_sub, v - 11), 235 size=(28, 28), 236 label='-', 237 autoselect=True, 238 on_activate_call=ba.Call(self._stress_test_player_count_decrement), 239 repeat=True, 240 enable_sound=True, 241 ) 242 ba.buttonwidget( 243 parent=self._subcontainer, 244 position=(380 - x_sub, v - 11), 245 size=(28, 28), 246 label='+', 247 autoselect=True, 248 on_activate_call=ba.Call(self._stress_test_player_count_increment), 249 repeat=True, 250 enable_sound=True, 251 ) 252 v -= 42 253 254 # Round duration. 255 ba.textwidget( 256 parent=self._subcontainer, 257 position=(x_offs - 10, v), 258 size=(0, 0), 259 text=ba.Lstr(resource=self._r + '.stressTestRoundDurationText'), 260 color=(0.8, 0.8, 0.8, 1.0), 261 h_align='right', 262 v_align='center', 263 scale=0.65, 264 maxwidth=130, 265 ) 266 self._stress_test_round_duration_text = ba.textwidget( 267 parent=self._subcontainer, 268 position=(246 - x_sub, v - 14), 269 size=(60, 28), 270 editable=False, 271 color=(0.3, 1.0, 0.3, 1.0), 272 h_align='right', 273 v_align='center', 274 text=str(self._stress_test_round_duration), 275 padding=2, 276 ) 277 ba.buttonwidget( 278 parent=self._subcontainer, 279 position=(330 - x_sub, v - 11), 280 size=(28, 28), 281 label='-', 282 autoselect=True, 283 on_activate_call=ba.Call( 284 self._stress_test_round_duration_decrement 285 ), 286 repeat=True, 287 enable_sound=True, 288 ) 289 ba.buttonwidget( 290 parent=self._subcontainer, 291 position=(380 - x_sub, v - 11), 292 size=(28, 28), 293 label='+', 294 autoselect=True, 295 on_activate_call=ba.Call( 296 self._stress_test_round_duration_increment 297 ), 298 repeat=True, 299 enable_sound=True, 300 ) 301 v -= 82 302 btn = ba.buttonwidget( 303 parent=self._subcontainer, 304 position=((self._sub_width - button_width) * 0.5, v), 305 size=(button_width, 60), 306 autoselect=True, 307 label=ba.Lstr(resource=self._r + '.runStressTestText'), 308 on_activate_call=self._stress_test_pressed, 309 ) 310 ba.widget(btn, show_buffer_bottom=50) 311 312 def _stress_test_player_count_decrement(self) -> None: 313 self._stress_test_player_count = max( 314 1, self._stress_test_player_count - 1 315 ) 316 ba.textwidget( 317 edit=self._stress_test_player_count_text, 318 text=str(self._stress_test_player_count), 319 ) 320 321 def _stress_test_player_count_increment(self) -> None: 322 self._stress_test_player_count = self._stress_test_player_count + 1 323 ba.textwidget( 324 edit=self._stress_test_player_count_text, 325 text=str(self._stress_test_player_count), 326 ) 327 328 def _stress_test_round_duration_decrement(self) -> None: 329 self._stress_test_round_duration = max( 330 10, self._stress_test_round_duration - 10 331 ) 332 ba.textwidget( 333 edit=self._stress_test_round_duration_text, 334 text=str(self._stress_test_round_duration), 335 ) 336 337 def _stress_test_round_duration_increment(self) -> None: 338 self._stress_test_round_duration = self._stress_test_round_duration + 10 339 ba.textwidget( 340 edit=self._stress_test_round_duration_text, 341 text=str(self._stress_test_round_duration), 342 ) 343 344 def _stress_test_game_type_selected(self, game_type: str) -> None: 345 self._stress_test_game_type = game_type 346 347 def _run_cpu_benchmark_pressed(self) -> None: 348 from ba.internal import run_cpu_benchmark 349 350 run_cpu_benchmark() 351 352 def _run_gpu_benchmark_pressed(self) -> None: 353 from ba.internal import run_gpu_benchmark 354 355 run_gpu_benchmark() 356 357 def _run_media_reload_benchmark_pressed(self) -> None: 358 from ba.internal import run_media_reload_benchmark 359 360 run_media_reload_benchmark() 361 362 def _stress_test_pressed(self) -> None: 363 from ba.internal import run_stress_test 364 365 run_stress_test( 366 playlist_type=self._stress_test_game_type, 367 playlist_name=cast( 368 str, ba.textwidget(query=self._stress_test_playlist_name_field) 369 ), 370 player_count=self._stress_test_player_count, 371 round_duration=self._stress_test_round_duration, 372 ) 373 ba.containerwidget(edit=self._root_widget, transition='out_right') 374 375 def _done(self) -> None: 376 # pylint: disable=cyclic-import 377 from bastd.ui.settings.advanced import AdvancedSettingsWindow 378 379 ba.containerwidget(edit=self._root_widget, transition='out_right') 380 ba.app.ui.set_main_menu_window( 381 AdvancedSettingsWindow(transition='in_left').get_root_widget() 382 )
Window for debugging internal values.
DebugWindow(transition: str | None = 'in_right')
19 def __init__(self, transition: str | None = 'in_right'): 20 # pylint: disable=too-many-statements 21 # pylint: disable=cyclic-import 22 from bastd.ui import popup 23 24 ba.app.ui.set_main_menu_location('Benchmarks & Stress Tests') 25 uiscale = ba.app.ui.uiscale 26 self._width = width = 580 27 self._height = height = ( 28 350 29 if uiscale is ba.UIScale.SMALL 30 else 420 31 if uiscale is ba.UIScale.MEDIUM 32 else 520 33 ) 34 35 self._scroll_width = self._width - 100 36 self._scroll_height = self._height - 120 37 38 self._sub_width = self._scroll_width * 0.95 39 self._sub_height = 520 40 41 self._stress_test_game_type = 'Random' 42 self._stress_test_playlist = '__default__' 43 self._stress_test_player_count = 8 44 self._stress_test_round_duration = 30 45 46 self._r = 'debugWindow' 47 uiscale = ba.app.ui.uiscale 48 super().__init__( 49 root_widget=ba.containerwidget( 50 size=(width, height), 51 transition=transition, 52 scale=( 53 2.35 54 if uiscale is ba.UIScale.SMALL 55 else 1.55 56 if uiscale is ba.UIScale.MEDIUM 57 else 1.0 58 ), 59 stack_offset=(0, -30) 60 if uiscale is ba.UIScale.SMALL 61 else (0, 0), 62 ) 63 ) 64 65 self._done_button = btn = ba.buttonwidget( 66 parent=self._root_widget, 67 position=(40, height - 67), 68 size=(120, 60), 69 scale=0.8, 70 autoselect=True, 71 label=ba.Lstr(resource='doneText'), 72 on_activate_call=self._done, 73 ) 74 ba.containerwidget(edit=self._root_widget, cancel_button=btn) 75 ba.textwidget( 76 parent=self._root_widget, 77 position=(0, height - 60), 78 size=(width, 30), 79 text=ba.Lstr(resource=self._r + '.titleText'), 80 h_align='center', 81 color=ba.app.ui.title_color, 82 v_align='center', 83 maxwidth=260, 84 ) 85 86 self._scrollwidget = ba.scrollwidget( 87 parent=self._root_widget, 88 highlight=False, 89 size=(self._scroll_width, self._scroll_height), 90 position=((self._width - self._scroll_width) * 0.5, 50), 91 ) 92 ba.containerwidget(edit=self._scrollwidget, claims_left_right=True) 93 94 self._subcontainer = ba.containerwidget( 95 parent=self._scrollwidget, 96 size=(self._sub_width, self._sub_height), 97 background=False, 98 ) 99 100 v = self._sub_height - 70 101 button_width = 300 102 btn = ba.buttonwidget( 103 parent=self._subcontainer, 104 position=((self._sub_width - button_width) * 0.5, v), 105 size=(button_width, 60), 106 autoselect=True, 107 label=ba.Lstr(resource=self._r + '.runCPUBenchmarkText'), 108 on_activate_call=self._run_cpu_benchmark_pressed, 109 ) 110 ba.widget( 111 edit=btn, up_widget=self._done_button, left_widget=self._done_button 112 ) 113 v -= 60 114 115 ba.buttonwidget( 116 parent=self._subcontainer, 117 position=((self._sub_width - button_width) * 0.5, v), 118 size=(button_width, 60), 119 autoselect=True, 120 label=ba.Lstr(resource=self._r + '.runGPUBenchmarkText'), 121 on_activate_call=self._run_gpu_benchmark_pressed, 122 ) 123 v -= 60 124 125 ba.buttonwidget( 126 parent=self._subcontainer, 127 position=((self._sub_width - button_width) * 0.5, v), 128 size=(button_width, 60), 129 autoselect=True, 130 label=ba.Lstr(resource=self._r + '.runMediaReloadBenchmarkText'), 131 on_activate_call=self._run_media_reload_benchmark_pressed, 132 ) 133 v -= 60 134 135 ba.textwidget( 136 parent=self._subcontainer, 137 position=(self._sub_width * 0.5, v + 22), 138 size=(0, 0), 139 text=ba.Lstr(resource=self._r + '.stressTestTitleText'), 140 maxwidth=200, 141 color=ba.app.ui.heading_color, 142 scale=0.85, 143 h_align='center', 144 v_align='center', 145 ) 146 v -= 45 147 148 x_offs = 165 149 ba.textwidget( 150 parent=self._subcontainer, 151 position=(x_offs - 10, v + 22), 152 size=(0, 0), 153 text=ba.Lstr(resource=self._r + '.stressTestPlaylistTypeText'), 154 maxwidth=130, 155 color=ba.app.ui.heading_color, 156 scale=0.65, 157 h_align='right', 158 v_align='center', 159 ) 160 161 popup.PopupMenu( 162 parent=self._subcontainer, 163 position=(x_offs, v), 164 width=150, 165 choices=['Random', 'Teams', 'Free-For-All'], 166 choices_display=[ 167 ba.Lstr(resource=a) 168 for a in [ 169 'randomText', 170 'playModes.teamsText', 171 'playModes.freeForAllText', 172 ] 173 ], 174 current_choice='Auto', 175 on_value_change_call=self._stress_test_game_type_selected, 176 ) 177 178 v -= 46 179 ba.textwidget( 180 parent=self._subcontainer, 181 position=(x_offs - 10, v + 22), 182 size=(0, 0), 183 text=ba.Lstr(resource=self._r + '.stressTestPlaylistNameText'), 184 maxwidth=130, 185 color=ba.app.ui.heading_color, 186 scale=0.65, 187 h_align='right', 188 v_align='center', 189 ) 190 191 self._stress_test_playlist_name_field = ba.textwidget( 192 parent=self._subcontainer, 193 position=(x_offs + 5, v - 5), 194 size=(250, 46), 195 text=self._stress_test_playlist, 196 h_align='left', 197 v_align='center', 198 autoselect=True, 199 color=(0.9, 0.9, 0.9, 1.0), 200 description=ba.Lstr( 201 resource=self._r + '.stressTestPlaylistDescriptionText' 202 ), 203 editable=True, 204 padding=4, 205 ) 206 v -= 29 207 x_sub = 60 208 209 # Player count. 210 ba.textwidget( 211 parent=self._subcontainer, 212 position=(x_offs - 10, v), 213 size=(0, 0), 214 text=ba.Lstr(resource=self._r + '.stressTestPlayerCountText'), 215 color=(0.8, 0.8, 0.8, 1.0), 216 h_align='right', 217 v_align='center', 218 scale=0.65, 219 maxwidth=130, 220 ) 221 self._stress_test_player_count_text = ba.textwidget( 222 parent=self._subcontainer, 223 position=(246 - x_sub, v - 14), 224 size=(60, 28), 225 editable=False, 226 color=(0.3, 1.0, 0.3, 1.0), 227 h_align='right', 228 v_align='center', 229 text=str(self._stress_test_player_count), 230 padding=2, 231 ) 232 ba.buttonwidget( 233 parent=self._subcontainer, 234 position=(330 - x_sub, v - 11), 235 size=(28, 28), 236 label='-', 237 autoselect=True, 238 on_activate_call=ba.Call(self._stress_test_player_count_decrement), 239 repeat=True, 240 enable_sound=True, 241 ) 242 ba.buttonwidget( 243 parent=self._subcontainer, 244 position=(380 - x_sub, v - 11), 245 size=(28, 28), 246 label='+', 247 autoselect=True, 248 on_activate_call=ba.Call(self._stress_test_player_count_increment), 249 repeat=True, 250 enable_sound=True, 251 ) 252 v -= 42 253 254 # Round duration. 255 ba.textwidget( 256 parent=self._subcontainer, 257 position=(x_offs - 10, v), 258 size=(0, 0), 259 text=ba.Lstr(resource=self._r + '.stressTestRoundDurationText'), 260 color=(0.8, 0.8, 0.8, 1.0), 261 h_align='right', 262 v_align='center', 263 scale=0.65, 264 maxwidth=130, 265 ) 266 self._stress_test_round_duration_text = ba.textwidget( 267 parent=self._subcontainer, 268 position=(246 - x_sub, v - 14), 269 size=(60, 28), 270 editable=False, 271 color=(0.3, 1.0, 0.3, 1.0), 272 h_align='right', 273 v_align='center', 274 text=str(self._stress_test_round_duration), 275 padding=2, 276 ) 277 ba.buttonwidget( 278 parent=self._subcontainer, 279 position=(330 - x_sub, v - 11), 280 size=(28, 28), 281 label='-', 282 autoselect=True, 283 on_activate_call=ba.Call( 284 self._stress_test_round_duration_decrement 285 ), 286 repeat=True, 287 enable_sound=True, 288 ) 289 ba.buttonwidget( 290 parent=self._subcontainer, 291 position=(380 - x_sub, v - 11), 292 size=(28, 28), 293 label='+', 294 autoselect=True, 295 on_activate_call=ba.Call( 296 self._stress_test_round_duration_increment 297 ), 298 repeat=True, 299 enable_sound=True, 300 ) 301 v -= 82 302 btn = ba.buttonwidget( 303 parent=self._subcontainer, 304 position=((self._sub_width - button_width) * 0.5, v), 305 size=(button_width, 60), 306 autoselect=True, 307 label=ba.Lstr(resource=self._r + '.runStressTestText'), 308 on_activate_call=self._stress_test_pressed, 309 ) 310 ba.widget(btn, show_buffer_bottom=50)
Inherited Members
- ba.ui.Window
- get_root_widget