bastd.ui.play
Provides the top level play window.
1# Released under the MIT License. See LICENSE for details. 2# 3"""Provides the top level play window.""" 4 5from __future__ import annotations 6 7from typing import TYPE_CHECKING 8 9import _ba 10import ba 11 12if TYPE_CHECKING: 13 pass 14 15 16class PlayWindow(ba.Window): 17 """Window for selecting overall play type.""" 18 19 def __init__(self, 20 transition: str = 'in_right', 21 origin_widget: ba.Widget | None = None): 22 # pylint: disable=too-many-statements 23 # pylint: disable=too-many-locals 24 import threading 25 26 # Preload some modules we use in a background thread so we won't 27 # have a visual hitch when the user taps them. 28 threading.Thread(target=self._preload_modules).start() 29 30 # We can currently be used either for main menu duty or for selecting 31 # playlists (should make this more elegant/general). 32 self._is_main_menu = not ba.app.ui.selecting_private_party_playlist 33 34 uiscale = ba.app.ui.uiscale 35 width = 1000 if uiscale is ba.UIScale.SMALL else 800 36 x_offs = 100 if uiscale is ba.UIScale.SMALL else 0 37 height = 550 38 button_width = 400 39 40 scale_origin: tuple[float, float] | None 41 if origin_widget is not None: 42 self._transition_out = 'out_scale' 43 scale_origin = origin_widget.get_screen_space_center() 44 transition = 'in_scale' 45 else: 46 self._transition_out = 'out_right' 47 scale_origin = None 48 49 self._r = 'playWindow' 50 51 super().__init__(root_widget=ba.containerwidget( 52 size=(width, height), 53 transition=transition, 54 toolbar_visibility='menu_full', 55 scale_origin_stack_offset=scale_origin, 56 scale=(1.6 if uiscale is ba.UIScale.SMALL else 57 0.9 if uiscale is ba.UIScale.MEDIUM else 0.8), 58 stack_offset=(0, 0) if uiscale is ba.UIScale.SMALL else (0, 0))) 59 self._back_button = back_button = btn = ba.buttonwidget( 60 parent=self._root_widget, 61 position=(55 + x_offs, height - 132), 62 size=(120, 60), 63 scale=1.1, 64 text_res_scale=1.5, 65 text_scale=1.2, 66 autoselect=True, 67 label=ba.Lstr(resource='backText'), 68 button_type='back') 69 70 txt = ba.textwidget( 71 parent=self._root_widget, 72 position=(width * 0.5, height - 101), 73 # position=(width * 0.5, height - 74 # (101 if main_menu else 61)), 75 size=(0, 0), 76 text=ba.Lstr(resource=( 77 self._r + 78 '.titleText') if self._is_main_menu else 'playlistsText'), 79 scale=1.7, 80 res_scale=2.0, 81 maxwidth=400, 82 color=ba.app.ui.heading_color, 83 h_align='center', 84 v_align='center') 85 86 ba.buttonwidget(edit=btn, 87 button_type='backSmall', 88 size=(60, 60), 89 label=ba.charstr(ba.SpecialChar.BACK)) 90 if ba.app.ui.use_toolbars and uiscale is ba.UIScale.SMALL: 91 ba.textwidget(edit=txt, text='') 92 93 v = height - (110 if self._is_main_menu else 90) 94 v -= 100 95 clr = (0.6, 0.7, 0.6, 1.0) 96 v -= 280 if self._is_main_menu else 180 97 v += (30 98 if ba.app.ui.use_toolbars and uiscale is ba.UIScale.SMALL else 0) 99 hoffs = x_offs + 80 if self._is_main_menu else x_offs - 100 100 scl = 1.13 if self._is_main_menu else 0.68 101 102 self._lineup_tex = ba.gettexture('playerLineup') 103 angry_computer_transparent_model = ba.getmodel( 104 'angryComputerTransparent') 105 self._lineup_1_transparent_model = ba.getmodel( 106 'playerLineup1Transparent') 107 self._lineup_2_transparent_model = ba.getmodel( 108 'playerLineup2Transparent') 109 self._lineup_3_transparent_model = ba.getmodel( 110 'playerLineup3Transparent') 111 self._lineup_4_transparent_model = ba.getmodel( 112 'playerLineup4Transparent') 113 self._eyes_model = ba.getmodel('plasticEyesTransparent') 114 115 self._coop_button: ba.Widget | None = None 116 117 # Only show coop button in main-menu variant. 118 if self._is_main_menu: 119 self._coop_button = btn = ba.buttonwidget( 120 parent=self._root_widget, 121 position=(hoffs, v + (scl * 15 if self._is_main_menu else 0)), 122 size=(scl * button_width, 123 scl * (300 if self._is_main_menu else 360)), 124 extra_touch_border_scale=0.1, 125 autoselect=True, 126 label='', 127 button_type='square', 128 text_scale=1.13, 129 on_activate_call=self._coop) 130 131 if ba.app.ui.use_toolbars and uiscale is ba.UIScale.SMALL: 132 ba.widget(edit=btn, 133 left_widget=_ba.get_special_widget('back_button')) 134 ba.widget(edit=btn, 135 up_widget=_ba.get_special_widget('account_button')) 136 ba.widget( 137 edit=btn, 138 down_widget=_ba.get_special_widget('settings_button')) 139 140 self._draw_dude(0, 141 btn, 142 hoffs, 143 v, 144 scl, 145 position=(140, 30), 146 color=(0.72, 0.4, 1.0)) 147 self._draw_dude(1, 148 btn, 149 hoffs, 150 v, 151 scl, 152 position=(185, 53), 153 color=(0.71, 0.5, 1.0)) 154 self._draw_dude(2, 155 btn, 156 hoffs, 157 v, 158 scl, 159 position=(220, 27), 160 color=(0.67, 0.44, 1.0)) 161 self._draw_dude(3, 162 btn, 163 hoffs, 164 v, 165 scl, 166 position=(255, 57), 167 color=(0.7, 0.3, 1.0)) 168 ba.imagewidget(parent=self._root_widget, 169 draw_controller=btn, 170 position=(hoffs + scl * 230, v + scl * 153), 171 size=(scl * 115, scl * 115), 172 texture=self._lineup_tex, 173 model_transparent=angry_computer_transparent_model) 174 175 ba.textwidget(parent=self._root_widget, 176 draw_controller=btn, 177 position=(hoffs + scl * (-10), v + scl * 95), 178 size=(scl * button_width, scl * 50), 179 text=ba.Lstr( 180 resource='playModes.singlePlayerCoopText', 181 fallback_resource='playModes.coopText'), 182 maxwidth=scl * button_width * 0.7, 183 res_scale=1.5, 184 h_align='center', 185 v_align='center', 186 color=(0.7, 0.9, 0.7, 1.0), 187 scale=scl * 2.3) 188 189 ba.textwidget(parent=self._root_widget, 190 draw_controller=btn, 191 position=(hoffs + scl * (-10), v + (scl * 54)), 192 size=(scl * button_width, scl * 30), 193 text=ba.Lstr(resource=self._r + 194 '.oneToFourPlayersText'), 195 h_align='center', 196 v_align='center', 197 scale=0.83 * scl, 198 flatness=1.0, 199 maxwidth=scl * button_width * 0.7, 200 color=clr) 201 202 scl = 0.5 if self._is_main_menu else 0.68 203 hoffs += 440 if self._is_main_menu else 216 204 v += 180 if self._is_main_menu else -68 205 206 self._teams_button = btn = ba.buttonwidget( 207 parent=self._root_widget, 208 position=(hoffs, v + (scl * 15 if self._is_main_menu else 0)), 209 size=(scl * button_width, 210 scl * (300 if self._is_main_menu else 360)), 211 extra_touch_border_scale=0.1, 212 autoselect=True, 213 label='', 214 button_type='square', 215 text_scale=1.13, 216 on_activate_call=self._team_tourney) 217 218 if ba.app.ui.use_toolbars: 219 ba.widget(edit=btn, 220 up_widget=_ba.get_special_widget('tickets_plus_button'), 221 right_widget=_ba.get_special_widget('party_button')) 222 223 xxx = -14 224 self._draw_dude(2, 225 btn, 226 hoffs, 227 v, 228 scl, 229 position=(xxx + 148, 30), 230 color=(0.2, 0.4, 1.0)) 231 self._draw_dude(3, 232 btn, 233 hoffs, 234 v, 235 scl, 236 position=(xxx + 181, 53), 237 color=(0.3, 0.4, 1.0)) 238 self._draw_dude(1, 239 btn, 240 hoffs, 241 v, 242 scl, 243 position=(xxx + 216, 33), 244 color=(0.3, 0.5, 1.0)) 245 self._draw_dude(0, 246 btn, 247 hoffs, 248 v, 249 scl, 250 position=(xxx + 245, 57), 251 color=(0.3, 0.5, 1.0)) 252 253 xxx = 155 254 self._draw_dude(0, 255 btn, 256 hoffs, 257 v, 258 scl, 259 position=(xxx + 151, 30), 260 color=(1.0, 0.5, 0.4)) 261 self._draw_dude(1, 262 btn, 263 hoffs, 264 v, 265 scl, 266 position=(xxx + 189, 53), 267 color=(1.0, 0.58, 0.58)) 268 self._draw_dude(3, 269 btn, 270 hoffs, 271 v, 272 scl, 273 position=(xxx + 223, 27), 274 color=(1.0, 0.5, 0.5)) 275 self._draw_dude(2, 276 btn, 277 hoffs, 278 v, 279 scl, 280 position=(xxx + 257, 57), 281 color=(1.0, 0.5, 0.5)) 282 283 ba.textwidget(parent=self._root_widget, 284 draw_controller=btn, 285 position=(hoffs + scl * (-10), v + scl * 95), 286 size=(scl * button_width, scl * 50), 287 text=ba.Lstr(resource='playModes.teamsText', 288 fallback_resource='teamsText'), 289 res_scale=1.5, 290 maxwidth=scl * button_width * 0.7, 291 h_align='center', 292 v_align='center', 293 color=(0.7, 0.9, 0.7, 1.0), 294 scale=scl * 2.3) 295 ba.textwidget(parent=self._root_widget, 296 draw_controller=btn, 297 position=(hoffs + scl * (-10), v + (scl * 54)), 298 size=(scl * button_width, scl * 30), 299 text=ba.Lstr(resource=self._r + 300 '.twoToEightPlayersText'), 301 h_align='center', 302 v_align='center', 303 res_scale=1.5, 304 scale=0.9 * scl, 305 flatness=1.0, 306 maxwidth=scl * button_width * 0.7, 307 color=clr) 308 309 hoffs += 0 if self._is_main_menu else 300 310 v -= 155 if self._is_main_menu else 0 311 self._free_for_all_button = btn = ba.buttonwidget( 312 parent=self._root_widget, 313 position=(hoffs, v + (scl * 15 if self._is_main_menu else 0)), 314 size=(scl * button_width, 315 scl * (300 if self._is_main_menu else 360)), 316 extra_touch_border_scale=0.1, 317 autoselect=True, 318 label='', 319 button_type='square', 320 text_scale=1.13, 321 on_activate_call=self._free_for_all) 322 323 xxx = -5 324 self._draw_dude(0, 325 btn, 326 hoffs, 327 v, 328 scl, 329 position=(xxx + 140, 30), 330 color=(0.4, 1.0, 0.4)) 331 self._draw_dude(3, 332 btn, 333 hoffs, 334 v, 335 scl, 336 position=(xxx + 185, 53), 337 color=(1.0, 0.4, 0.5)) 338 self._draw_dude(1, 339 btn, 340 hoffs, 341 v, 342 scl, 343 position=(xxx + 220, 27), 344 color=(0.4, 0.5, 1.0)) 345 self._draw_dude(2, 346 btn, 347 hoffs, 348 v, 349 scl, 350 position=(xxx + 255, 57), 351 color=(0.5, 1.0, 0.4)) 352 xxx = 140 353 self._draw_dude(2, 354 btn, 355 hoffs, 356 v, 357 scl, 358 position=(xxx + 148, 30), 359 color=(1.0, 0.9, 0.4)) 360 self._draw_dude(0, 361 btn, 362 hoffs, 363 v, 364 scl, 365 position=(xxx + 182, 53), 366 color=(0.7, 1.0, 0.5)) 367 self._draw_dude(3, 368 btn, 369 hoffs, 370 v, 371 scl, 372 position=(xxx + 233, 27), 373 color=(0.7, 0.5, 0.9)) 374 self._draw_dude(1, 375 btn, 376 hoffs, 377 v, 378 scl, 379 position=(xxx + 266, 53), 380 color=(0.4, 0.5, 0.8)) 381 ba.textwidget(parent=self._root_widget, 382 draw_controller=btn, 383 position=(hoffs + scl * (-10), v + scl * 95), 384 size=(scl * button_width, scl * 50), 385 text=ba.Lstr(resource='playModes.freeForAllText', 386 fallback_resource='freeForAllText'), 387 maxwidth=scl * button_width * 0.7, 388 h_align='center', 389 v_align='center', 390 color=(0.7, 0.9, 0.7, 1.0), 391 scale=scl * 1.9) 392 ba.textwidget(parent=self._root_widget, 393 draw_controller=btn, 394 position=(hoffs + scl * (-10), v + (scl * 54)), 395 size=(scl * button_width, scl * 30), 396 text=ba.Lstr(resource=self._r + 397 '.twoToEightPlayersText'), 398 h_align='center', 399 v_align='center', 400 scale=0.9 * scl, 401 flatness=1.0, 402 maxwidth=scl * button_width * 0.7, 403 color=clr) 404 405 if ba.app.ui.use_toolbars and uiscale is ba.UIScale.SMALL: 406 back_button.delete() 407 ba.containerwidget(edit=self._root_widget, 408 on_cancel_call=self._back, 409 selected_child=self._coop_button 410 if self._is_main_menu else self._teams_button) 411 else: 412 ba.buttonwidget(edit=back_button, on_activate_call=self._back) 413 ba.containerwidget(edit=self._root_widget, 414 cancel_button=back_button, 415 selected_child=self._coop_button 416 if self._is_main_menu else self._teams_button) 417 418 self._restore_state() 419 420 # noinspection PyUnresolvedReferences 421 @staticmethod 422 def _preload_modules() -> None: 423 """Preload modules we use (called in bg thread).""" 424 import bastd.ui.mainmenu as _unused1 425 import bastd.ui.account as _unused2 426 import bastd.ui.coop.browser as _unused3 427 import bastd.ui.playlist.browser as _unused4 428 429 def _back(self) -> None: 430 # pylint: disable=cyclic-import 431 if self._is_main_menu: 432 from bastd.ui.mainmenu import MainMenuWindow 433 self._save_state() 434 ba.app.ui.set_main_menu_window( 435 MainMenuWindow(transition='in_left').get_root_widget()) 436 ba.containerwidget(edit=self._root_widget, 437 transition=self._transition_out) 438 else: 439 from bastd.ui.gather import GatherWindow 440 self._save_state() 441 ba.app.ui.set_main_menu_window( 442 GatherWindow(transition='in_left').get_root_widget()) 443 ba.containerwidget(edit=self._root_widget, 444 transition=self._transition_out) 445 446 def _coop(self) -> None: 447 # pylint: disable=cyclic-import 448 from bastd.ui.account import show_sign_in_prompt 449 from bastd.ui.coop.browser import CoopBrowserWindow 450 if _ba.get_v1_account_state() != 'signed_in': 451 show_sign_in_prompt() 452 return 453 self._save_state() 454 ba.containerwidget(edit=self._root_widget, transition='out_left') 455 ba.app.ui.set_main_menu_window( 456 CoopBrowserWindow( 457 origin_widget=self._coop_button).get_root_widget()) 458 459 def _team_tourney(self) -> None: 460 # pylint: disable=cyclic-import 461 from bastd.ui.playlist.browser import PlaylistBrowserWindow 462 self._save_state() 463 ba.containerwidget(edit=self._root_widget, transition='out_left') 464 ba.app.ui.set_main_menu_window( 465 PlaylistBrowserWindow( 466 origin_widget=self._teams_button, 467 sessiontype=ba.DualTeamSession).get_root_widget()) 468 469 def _free_for_all(self) -> None: 470 # pylint: disable=cyclic-import 471 from bastd.ui.playlist.browser import PlaylistBrowserWindow 472 self._save_state() 473 ba.containerwidget(edit=self._root_widget, transition='out_left') 474 ba.app.ui.set_main_menu_window( 475 PlaylistBrowserWindow( 476 origin_widget=self._free_for_all_button, 477 sessiontype=ba.FreeForAllSession).get_root_widget()) 478 479 def _draw_dude(self, i: int, btn: ba.Widget, hoffs: float, v: float, 480 scl: float, position: tuple[float, float], 481 color: tuple[float, float, float]) -> None: 482 h_extra = -100 483 v_extra = 130 484 eye_color = (0.7 * 1.0 + 0.3 * color[0], 0.7 * 1.0 + 0.3 * color[1], 485 0.7 * 1.0 + 0.3 * color[2]) 486 if i == 0: 487 ba.imagewidget(parent=self._root_widget, 488 draw_controller=btn, 489 position=(hoffs + scl * (h_extra + position[0]), 490 v + scl * (v_extra + position[1])), 491 size=(scl * 60, scl * 80), 492 color=color, 493 texture=self._lineup_tex, 494 model_transparent=self._lineup_1_transparent_model) 495 ba.imagewidget( 496 parent=self._root_widget, 497 draw_controller=btn, 498 position=(hoffs + scl * (h_extra + position[0] + 12), 499 v + scl * (v_extra + position[1] + 53)), 500 size=(scl * 36, scl * 18), 501 texture=self._lineup_tex, 502 color=eye_color, 503 model_transparent=self._eyes_model) 504 elif i == 1: 505 ba.imagewidget(parent=self._root_widget, 506 draw_controller=btn, 507 position=(hoffs + scl * (h_extra + position[0]), 508 v + scl * (v_extra + position[1])), 509 size=(scl * 45, scl * 90), 510 color=color, 511 texture=self._lineup_tex, 512 model_transparent=self._lineup_2_transparent_model) 513 ba.imagewidget(parent=self._root_widget, 514 draw_controller=btn, 515 position=(hoffs + scl * (h_extra + position[0] + 5), 516 v + scl * (v_extra + position[1] + 67)), 517 size=(scl * 32, scl * 16), 518 texture=self._lineup_tex, 519 color=eye_color, 520 model_transparent=self._eyes_model) 521 elif i == 2: 522 ba.imagewidget(parent=self._root_widget, 523 draw_controller=btn, 524 position=(hoffs + scl * (h_extra + position[0]), 525 v + scl * (v_extra + position[1])), 526 size=(scl * 45, scl * 90), 527 color=color, 528 texture=self._lineup_tex, 529 model_transparent=self._lineup_3_transparent_model) 530 ba.imagewidget(parent=self._root_widget, 531 draw_controller=btn, 532 position=(hoffs + scl * (h_extra + position[0] + 5), 533 v + scl * (v_extra + position[1] + 59)), 534 size=(scl * 34, scl * 17), 535 texture=self._lineup_tex, 536 color=eye_color, 537 model_transparent=self._eyes_model) 538 elif i == 3: 539 ba.imagewidget(parent=self._root_widget, 540 draw_controller=btn, 541 position=(hoffs + scl * (h_extra + position[0]), 542 v + scl * (v_extra + position[1])), 543 size=(scl * 48, scl * 96), 544 color=color, 545 texture=self._lineup_tex, 546 model_transparent=self._lineup_4_transparent_model) 547 ba.imagewidget(parent=self._root_widget, 548 draw_controller=btn, 549 position=(hoffs + scl * (h_extra + position[0] + 2), 550 v + scl * (v_extra + position[1] + 62)), 551 size=(scl * 38, scl * 19), 552 texture=self._lineup_tex, 553 color=eye_color, 554 model_transparent=self._eyes_model) 555 556 def _save_state(self) -> None: 557 try: 558 sel = self._root_widget.get_selected_child() 559 if sel == self._teams_button: 560 sel_name = 'Team Games' 561 elif self._coop_button is not None and sel == self._coop_button: 562 sel_name = 'Co-op Games' 563 elif sel == self._free_for_all_button: 564 sel_name = 'Free-for-All Games' 565 elif sel == self._back_button: 566 sel_name = 'Back' 567 else: 568 raise ValueError(f'unrecognized selection {sel}') 569 ba.app.ui.window_states[type(self)] = sel_name 570 except Exception: 571 ba.print_exception(f'Error saving state for {self}.') 572 573 def _restore_state(self) -> None: 574 try: 575 sel_name = ba.app.ui.window_states.get(type(self)) 576 if sel_name == 'Team Games': 577 sel = self._teams_button 578 elif sel_name == 'Co-op Games' and self._coop_button is not None: 579 sel = self._coop_button 580 elif sel_name == 'Free-for-All Games': 581 sel = self._free_for_all_button 582 elif sel_name == 'Back': 583 sel = self._back_button 584 else: 585 sel = (self._coop_button if self._coop_button is not None else 586 self._teams_button) 587 ba.containerwidget(edit=self._root_widget, selected_child=sel) 588 except Exception: 589 ba.print_exception(f'Error restoring state for {self}.')
class
PlayWindow(ba.ui.Window):
17class PlayWindow(ba.Window): 18 """Window for selecting overall play type.""" 19 20 def __init__(self, 21 transition: str = 'in_right', 22 origin_widget: ba.Widget | None = None): 23 # pylint: disable=too-many-statements 24 # pylint: disable=too-many-locals 25 import threading 26 27 # Preload some modules we use in a background thread so we won't 28 # have a visual hitch when the user taps them. 29 threading.Thread(target=self._preload_modules).start() 30 31 # We can currently be used either for main menu duty or for selecting 32 # playlists (should make this more elegant/general). 33 self._is_main_menu = not ba.app.ui.selecting_private_party_playlist 34 35 uiscale = ba.app.ui.uiscale 36 width = 1000 if uiscale is ba.UIScale.SMALL else 800 37 x_offs = 100 if uiscale is ba.UIScale.SMALL else 0 38 height = 550 39 button_width = 400 40 41 scale_origin: tuple[float, float] | None 42 if origin_widget is not None: 43 self._transition_out = 'out_scale' 44 scale_origin = origin_widget.get_screen_space_center() 45 transition = 'in_scale' 46 else: 47 self._transition_out = 'out_right' 48 scale_origin = None 49 50 self._r = 'playWindow' 51 52 super().__init__(root_widget=ba.containerwidget( 53 size=(width, height), 54 transition=transition, 55 toolbar_visibility='menu_full', 56 scale_origin_stack_offset=scale_origin, 57 scale=(1.6 if uiscale is ba.UIScale.SMALL else 58 0.9 if uiscale is ba.UIScale.MEDIUM else 0.8), 59 stack_offset=(0, 0) if uiscale is ba.UIScale.SMALL else (0, 0))) 60 self._back_button = back_button = btn = ba.buttonwidget( 61 parent=self._root_widget, 62 position=(55 + x_offs, height - 132), 63 size=(120, 60), 64 scale=1.1, 65 text_res_scale=1.5, 66 text_scale=1.2, 67 autoselect=True, 68 label=ba.Lstr(resource='backText'), 69 button_type='back') 70 71 txt = ba.textwidget( 72 parent=self._root_widget, 73 position=(width * 0.5, height - 101), 74 # position=(width * 0.5, height - 75 # (101 if main_menu else 61)), 76 size=(0, 0), 77 text=ba.Lstr(resource=( 78 self._r + 79 '.titleText') if self._is_main_menu else 'playlistsText'), 80 scale=1.7, 81 res_scale=2.0, 82 maxwidth=400, 83 color=ba.app.ui.heading_color, 84 h_align='center', 85 v_align='center') 86 87 ba.buttonwidget(edit=btn, 88 button_type='backSmall', 89 size=(60, 60), 90 label=ba.charstr(ba.SpecialChar.BACK)) 91 if ba.app.ui.use_toolbars and uiscale is ba.UIScale.SMALL: 92 ba.textwidget(edit=txt, text='') 93 94 v = height - (110 if self._is_main_menu else 90) 95 v -= 100 96 clr = (0.6, 0.7, 0.6, 1.0) 97 v -= 280 if self._is_main_menu else 180 98 v += (30 99 if ba.app.ui.use_toolbars and uiscale is ba.UIScale.SMALL else 0) 100 hoffs = x_offs + 80 if self._is_main_menu else x_offs - 100 101 scl = 1.13 if self._is_main_menu else 0.68 102 103 self._lineup_tex = ba.gettexture('playerLineup') 104 angry_computer_transparent_model = ba.getmodel( 105 'angryComputerTransparent') 106 self._lineup_1_transparent_model = ba.getmodel( 107 'playerLineup1Transparent') 108 self._lineup_2_transparent_model = ba.getmodel( 109 'playerLineup2Transparent') 110 self._lineup_3_transparent_model = ba.getmodel( 111 'playerLineup3Transparent') 112 self._lineup_4_transparent_model = ba.getmodel( 113 'playerLineup4Transparent') 114 self._eyes_model = ba.getmodel('plasticEyesTransparent') 115 116 self._coop_button: ba.Widget | None = None 117 118 # Only show coop button in main-menu variant. 119 if self._is_main_menu: 120 self._coop_button = btn = ba.buttonwidget( 121 parent=self._root_widget, 122 position=(hoffs, v + (scl * 15 if self._is_main_menu else 0)), 123 size=(scl * button_width, 124 scl * (300 if self._is_main_menu else 360)), 125 extra_touch_border_scale=0.1, 126 autoselect=True, 127 label='', 128 button_type='square', 129 text_scale=1.13, 130 on_activate_call=self._coop) 131 132 if ba.app.ui.use_toolbars and uiscale is ba.UIScale.SMALL: 133 ba.widget(edit=btn, 134 left_widget=_ba.get_special_widget('back_button')) 135 ba.widget(edit=btn, 136 up_widget=_ba.get_special_widget('account_button')) 137 ba.widget( 138 edit=btn, 139 down_widget=_ba.get_special_widget('settings_button')) 140 141 self._draw_dude(0, 142 btn, 143 hoffs, 144 v, 145 scl, 146 position=(140, 30), 147 color=(0.72, 0.4, 1.0)) 148 self._draw_dude(1, 149 btn, 150 hoffs, 151 v, 152 scl, 153 position=(185, 53), 154 color=(0.71, 0.5, 1.0)) 155 self._draw_dude(2, 156 btn, 157 hoffs, 158 v, 159 scl, 160 position=(220, 27), 161 color=(0.67, 0.44, 1.0)) 162 self._draw_dude(3, 163 btn, 164 hoffs, 165 v, 166 scl, 167 position=(255, 57), 168 color=(0.7, 0.3, 1.0)) 169 ba.imagewidget(parent=self._root_widget, 170 draw_controller=btn, 171 position=(hoffs + scl * 230, v + scl * 153), 172 size=(scl * 115, scl * 115), 173 texture=self._lineup_tex, 174 model_transparent=angry_computer_transparent_model) 175 176 ba.textwidget(parent=self._root_widget, 177 draw_controller=btn, 178 position=(hoffs + scl * (-10), v + scl * 95), 179 size=(scl * button_width, scl * 50), 180 text=ba.Lstr( 181 resource='playModes.singlePlayerCoopText', 182 fallback_resource='playModes.coopText'), 183 maxwidth=scl * button_width * 0.7, 184 res_scale=1.5, 185 h_align='center', 186 v_align='center', 187 color=(0.7, 0.9, 0.7, 1.0), 188 scale=scl * 2.3) 189 190 ba.textwidget(parent=self._root_widget, 191 draw_controller=btn, 192 position=(hoffs + scl * (-10), v + (scl * 54)), 193 size=(scl * button_width, scl * 30), 194 text=ba.Lstr(resource=self._r + 195 '.oneToFourPlayersText'), 196 h_align='center', 197 v_align='center', 198 scale=0.83 * scl, 199 flatness=1.0, 200 maxwidth=scl * button_width * 0.7, 201 color=clr) 202 203 scl = 0.5 if self._is_main_menu else 0.68 204 hoffs += 440 if self._is_main_menu else 216 205 v += 180 if self._is_main_menu else -68 206 207 self._teams_button = btn = ba.buttonwidget( 208 parent=self._root_widget, 209 position=(hoffs, v + (scl * 15 if self._is_main_menu else 0)), 210 size=(scl * button_width, 211 scl * (300 if self._is_main_menu else 360)), 212 extra_touch_border_scale=0.1, 213 autoselect=True, 214 label='', 215 button_type='square', 216 text_scale=1.13, 217 on_activate_call=self._team_tourney) 218 219 if ba.app.ui.use_toolbars: 220 ba.widget(edit=btn, 221 up_widget=_ba.get_special_widget('tickets_plus_button'), 222 right_widget=_ba.get_special_widget('party_button')) 223 224 xxx = -14 225 self._draw_dude(2, 226 btn, 227 hoffs, 228 v, 229 scl, 230 position=(xxx + 148, 30), 231 color=(0.2, 0.4, 1.0)) 232 self._draw_dude(3, 233 btn, 234 hoffs, 235 v, 236 scl, 237 position=(xxx + 181, 53), 238 color=(0.3, 0.4, 1.0)) 239 self._draw_dude(1, 240 btn, 241 hoffs, 242 v, 243 scl, 244 position=(xxx + 216, 33), 245 color=(0.3, 0.5, 1.0)) 246 self._draw_dude(0, 247 btn, 248 hoffs, 249 v, 250 scl, 251 position=(xxx + 245, 57), 252 color=(0.3, 0.5, 1.0)) 253 254 xxx = 155 255 self._draw_dude(0, 256 btn, 257 hoffs, 258 v, 259 scl, 260 position=(xxx + 151, 30), 261 color=(1.0, 0.5, 0.4)) 262 self._draw_dude(1, 263 btn, 264 hoffs, 265 v, 266 scl, 267 position=(xxx + 189, 53), 268 color=(1.0, 0.58, 0.58)) 269 self._draw_dude(3, 270 btn, 271 hoffs, 272 v, 273 scl, 274 position=(xxx + 223, 27), 275 color=(1.0, 0.5, 0.5)) 276 self._draw_dude(2, 277 btn, 278 hoffs, 279 v, 280 scl, 281 position=(xxx + 257, 57), 282 color=(1.0, 0.5, 0.5)) 283 284 ba.textwidget(parent=self._root_widget, 285 draw_controller=btn, 286 position=(hoffs + scl * (-10), v + scl * 95), 287 size=(scl * button_width, scl * 50), 288 text=ba.Lstr(resource='playModes.teamsText', 289 fallback_resource='teamsText'), 290 res_scale=1.5, 291 maxwidth=scl * button_width * 0.7, 292 h_align='center', 293 v_align='center', 294 color=(0.7, 0.9, 0.7, 1.0), 295 scale=scl * 2.3) 296 ba.textwidget(parent=self._root_widget, 297 draw_controller=btn, 298 position=(hoffs + scl * (-10), v + (scl * 54)), 299 size=(scl * button_width, scl * 30), 300 text=ba.Lstr(resource=self._r + 301 '.twoToEightPlayersText'), 302 h_align='center', 303 v_align='center', 304 res_scale=1.5, 305 scale=0.9 * scl, 306 flatness=1.0, 307 maxwidth=scl * button_width * 0.7, 308 color=clr) 309 310 hoffs += 0 if self._is_main_menu else 300 311 v -= 155 if self._is_main_menu else 0 312 self._free_for_all_button = btn = ba.buttonwidget( 313 parent=self._root_widget, 314 position=(hoffs, v + (scl * 15 if self._is_main_menu else 0)), 315 size=(scl * button_width, 316 scl * (300 if self._is_main_menu else 360)), 317 extra_touch_border_scale=0.1, 318 autoselect=True, 319 label='', 320 button_type='square', 321 text_scale=1.13, 322 on_activate_call=self._free_for_all) 323 324 xxx = -5 325 self._draw_dude(0, 326 btn, 327 hoffs, 328 v, 329 scl, 330 position=(xxx + 140, 30), 331 color=(0.4, 1.0, 0.4)) 332 self._draw_dude(3, 333 btn, 334 hoffs, 335 v, 336 scl, 337 position=(xxx + 185, 53), 338 color=(1.0, 0.4, 0.5)) 339 self._draw_dude(1, 340 btn, 341 hoffs, 342 v, 343 scl, 344 position=(xxx + 220, 27), 345 color=(0.4, 0.5, 1.0)) 346 self._draw_dude(2, 347 btn, 348 hoffs, 349 v, 350 scl, 351 position=(xxx + 255, 57), 352 color=(0.5, 1.0, 0.4)) 353 xxx = 140 354 self._draw_dude(2, 355 btn, 356 hoffs, 357 v, 358 scl, 359 position=(xxx + 148, 30), 360 color=(1.0, 0.9, 0.4)) 361 self._draw_dude(0, 362 btn, 363 hoffs, 364 v, 365 scl, 366 position=(xxx + 182, 53), 367 color=(0.7, 1.0, 0.5)) 368 self._draw_dude(3, 369 btn, 370 hoffs, 371 v, 372 scl, 373 position=(xxx + 233, 27), 374 color=(0.7, 0.5, 0.9)) 375 self._draw_dude(1, 376 btn, 377 hoffs, 378 v, 379 scl, 380 position=(xxx + 266, 53), 381 color=(0.4, 0.5, 0.8)) 382 ba.textwidget(parent=self._root_widget, 383 draw_controller=btn, 384 position=(hoffs + scl * (-10), v + scl * 95), 385 size=(scl * button_width, scl * 50), 386 text=ba.Lstr(resource='playModes.freeForAllText', 387 fallback_resource='freeForAllText'), 388 maxwidth=scl * button_width * 0.7, 389 h_align='center', 390 v_align='center', 391 color=(0.7, 0.9, 0.7, 1.0), 392 scale=scl * 1.9) 393 ba.textwidget(parent=self._root_widget, 394 draw_controller=btn, 395 position=(hoffs + scl * (-10), v + (scl * 54)), 396 size=(scl * button_width, scl * 30), 397 text=ba.Lstr(resource=self._r + 398 '.twoToEightPlayersText'), 399 h_align='center', 400 v_align='center', 401 scale=0.9 * scl, 402 flatness=1.0, 403 maxwidth=scl * button_width * 0.7, 404 color=clr) 405 406 if ba.app.ui.use_toolbars and uiscale is ba.UIScale.SMALL: 407 back_button.delete() 408 ba.containerwidget(edit=self._root_widget, 409 on_cancel_call=self._back, 410 selected_child=self._coop_button 411 if self._is_main_menu else self._teams_button) 412 else: 413 ba.buttonwidget(edit=back_button, on_activate_call=self._back) 414 ba.containerwidget(edit=self._root_widget, 415 cancel_button=back_button, 416 selected_child=self._coop_button 417 if self._is_main_menu else self._teams_button) 418 419 self._restore_state() 420 421 # noinspection PyUnresolvedReferences 422 @staticmethod 423 def _preload_modules() -> None: 424 """Preload modules we use (called in bg thread).""" 425 import bastd.ui.mainmenu as _unused1 426 import bastd.ui.account as _unused2 427 import bastd.ui.coop.browser as _unused3 428 import bastd.ui.playlist.browser as _unused4 429 430 def _back(self) -> None: 431 # pylint: disable=cyclic-import 432 if self._is_main_menu: 433 from bastd.ui.mainmenu import MainMenuWindow 434 self._save_state() 435 ba.app.ui.set_main_menu_window( 436 MainMenuWindow(transition='in_left').get_root_widget()) 437 ba.containerwidget(edit=self._root_widget, 438 transition=self._transition_out) 439 else: 440 from bastd.ui.gather import GatherWindow 441 self._save_state() 442 ba.app.ui.set_main_menu_window( 443 GatherWindow(transition='in_left').get_root_widget()) 444 ba.containerwidget(edit=self._root_widget, 445 transition=self._transition_out) 446 447 def _coop(self) -> None: 448 # pylint: disable=cyclic-import 449 from bastd.ui.account import show_sign_in_prompt 450 from bastd.ui.coop.browser import CoopBrowserWindow 451 if _ba.get_v1_account_state() != 'signed_in': 452 show_sign_in_prompt() 453 return 454 self._save_state() 455 ba.containerwidget(edit=self._root_widget, transition='out_left') 456 ba.app.ui.set_main_menu_window( 457 CoopBrowserWindow( 458 origin_widget=self._coop_button).get_root_widget()) 459 460 def _team_tourney(self) -> None: 461 # pylint: disable=cyclic-import 462 from bastd.ui.playlist.browser import PlaylistBrowserWindow 463 self._save_state() 464 ba.containerwidget(edit=self._root_widget, transition='out_left') 465 ba.app.ui.set_main_menu_window( 466 PlaylistBrowserWindow( 467 origin_widget=self._teams_button, 468 sessiontype=ba.DualTeamSession).get_root_widget()) 469 470 def _free_for_all(self) -> None: 471 # pylint: disable=cyclic-import 472 from bastd.ui.playlist.browser import PlaylistBrowserWindow 473 self._save_state() 474 ba.containerwidget(edit=self._root_widget, transition='out_left') 475 ba.app.ui.set_main_menu_window( 476 PlaylistBrowserWindow( 477 origin_widget=self._free_for_all_button, 478 sessiontype=ba.FreeForAllSession).get_root_widget()) 479 480 def _draw_dude(self, i: int, btn: ba.Widget, hoffs: float, v: float, 481 scl: float, position: tuple[float, float], 482 color: tuple[float, float, float]) -> None: 483 h_extra = -100 484 v_extra = 130 485 eye_color = (0.7 * 1.0 + 0.3 * color[0], 0.7 * 1.0 + 0.3 * color[1], 486 0.7 * 1.0 + 0.3 * color[2]) 487 if i == 0: 488 ba.imagewidget(parent=self._root_widget, 489 draw_controller=btn, 490 position=(hoffs + scl * (h_extra + position[0]), 491 v + scl * (v_extra + position[1])), 492 size=(scl * 60, scl * 80), 493 color=color, 494 texture=self._lineup_tex, 495 model_transparent=self._lineup_1_transparent_model) 496 ba.imagewidget( 497 parent=self._root_widget, 498 draw_controller=btn, 499 position=(hoffs + scl * (h_extra + position[0] + 12), 500 v + scl * (v_extra + position[1] + 53)), 501 size=(scl * 36, scl * 18), 502 texture=self._lineup_tex, 503 color=eye_color, 504 model_transparent=self._eyes_model) 505 elif i == 1: 506 ba.imagewidget(parent=self._root_widget, 507 draw_controller=btn, 508 position=(hoffs + scl * (h_extra + position[0]), 509 v + scl * (v_extra + position[1])), 510 size=(scl * 45, scl * 90), 511 color=color, 512 texture=self._lineup_tex, 513 model_transparent=self._lineup_2_transparent_model) 514 ba.imagewidget(parent=self._root_widget, 515 draw_controller=btn, 516 position=(hoffs + scl * (h_extra + position[0] + 5), 517 v + scl * (v_extra + position[1] + 67)), 518 size=(scl * 32, scl * 16), 519 texture=self._lineup_tex, 520 color=eye_color, 521 model_transparent=self._eyes_model) 522 elif i == 2: 523 ba.imagewidget(parent=self._root_widget, 524 draw_controller=btn, 525 position=(hoffs + scl * (h_extra + position[0]), 526 v + scl * (v_extra + position[1])), 527 size=(scl * 45, scl * 90), 528 color=color, 529 texture=self._lineup_tex, 530 model_transparent=self._lineup_3_transparent_model) 531 ba.imagewidget(parent=self._root_widget, 532 draw_controller=btn, 533 position=(hoffs + scl * (h_extra + position[0] + 5), 534 v + scl * (v_extra + position[1] + 59)), 535 size=(scl * 34, scl * 17), 536 texture=self._lineup_tex, 537 color=eye_color, 538 model_transparent=self._eyes_model) 539 elif i == 3: 540 ba.imagewidget(parent=self._root_widget, 541 draw_controller=btn, 542 position=(hoffs + scl * (h_extra + position[0]), 543 v + scl * (v_extra + position[1])), 544 size=(scl * 48, scl * 96), 545 color=color, 546 texture=self._lineup_tex, 547 model_transparent=self._lineup_4_transparent_model) 548 ba.imagewidget(parent=self._root_widget, 549 draw_controller=btn, 550 position=(hoffs + scl * (h_extra + position[0] + 2), 551 v + scl * (v_extra + position[1] + 62)), 552 size=(scl * 38, scl * 19), 553 texture=self._lineup_tex, 554 color=eye_color, 555 model_transparent=self._eyes_model) 556 557 def _save_state(self) -> None: 558 try: 559 sel = self._root_widget.get_selected_child() 560 if sel == self._teams_button: 561 sel_name = 'Team Games' 562 elif self._coop_button is not None and sel == self._coop_button: 563 sel_name = 'Co-op Games' 564 elif sel == self._free_for_all_button: 565 sel_name = 'Free-for-All Games' 566 elif sel == self._back_button: 567 sel_name = 'Back' 568 else: 569 raise ValueError(f'unrecognized selection {sel}') 570 ba.app.ui.window_states[type(self)] = sel_name 571 except Exception: 572 ba.print_exception(f'Error saving state for {self}.') 573 574 def _restore_state(self) -> None: 575 try: 576 sel_name = ba.app.ui.window_states.get(type(self)) 577 if sel_name == 'Team Games': 578 sel = self._teams_button 579 elif sel_name == 'Co-op Games' and self._coop_button is not None: 580 sel = self._coop_button 581 elif sel_name == 'Free-for-All Games': 582 sel = self._free_for_all_button 583 elif sel_name == 'Back': 584 sel = self._back_button 585 else: 586 sel = (self._coop_button if self._coop_button is not None else 587 self._teams_button) 588 ba.containerwidget(edit=self._root_widget, selected_child=sel) 589 except Exception: 590 ba.print_exception(f'Error restoring state for {self}.')
Window for selecting overall play type.
PlayWindow( transition: str = 'in_right', origin_widget: _ba.Widget | None = None)
20 def __init__(self, 21 transition: str = 'in_right', 22 origin_widget: ba.Widget | None = None): 23 # pylint: disable=too-many-statements 24 # pylint: disable=too-many-locals 25 import threading 26 27 # Preload some modules we use in a background thread so we won't 28 # have a visual hitch when the user taps them. 29 threading.Thread(target=self._preload_modules).start() 30 31 # We can currently be used either for main menu duty or for selecting 32 # playlists (should make this more elegant/general). 33 self._is_main_menu = not ba.app.ui.selecting_private_party_playlist 34 35 uiscale = ba.app.ui.uiscale 36 width = 1000 if uiscale is ba.UIScale.SMALL else 800 37 x_offs = 100 if uiscale is ba.UIScale.SMALL else 0 38 height = 550 39 button_width = 400 40 41 scale_origin: tuple[float, float] | None 42 if origin_widget is not None: 43 self._transition_out = 'out_scale' 44 scale_origin = origin_widget.get_screen_space_center() 45 transition = 'in_scale' 46 else: 47 self._transition_out = 'out_right' 48 scale_origin = None 49 50 self._r = 'playWindow' 51 52 super().__init__(root_widget=ba.containerwidget( 53 size=(width, height), 54 transition=transition, 55 toolbar_visibility='menu_full', 56 scale_origin_stack_offset=scale_origin, 57 scale=(1.6 if uiscale is ba.UIScale.SMALL else 58 0.9 if uiscale is ba.UIScale.MEDIUM else 0.8), 59 stack_offset=(0, 0) if uiscale is ba.UIScale.SMALL else (0, 0))) 60 self._back_button = back_button = btn = ba.buttonwidget( 61 parent=self._root_widget, 62 position=(55 + x_offs, height - 132), 63 size=(120, 60), 64 scale=1.1, 65 text_res_scale=1.5, 66 text_scale=1.2, 67 autoselect=True, 68 label=ba.Lstr(resource='backText'), 69 button_type='back') 70 71 txt = ba.textwidget( 72 parent=self._root_widget, 73 position=(width * 0.5, height - 101), 74 # position=(width * 0.5, height - 75 # (101 if main_menu else 61)), 76 size=(0, 0), 77 text=ba.Lstr(resource=( 78 self._r + 79 '.titleText') if self._is_main_menu else 'playlistsText'), 80 scale=1.7, 81 res_scale=2.0, 82 maxwidth=400, 83 color=ba.app.ui.heading_color, 84 h_align='center', 85 v_align='center') 86 87 ba.buttonwidget(edit=btn, 88 button_type='backSmall', 89 size=(60, 60), 90 label=ba.charstr(ba.SpecialChar.BACK)) 91 if ba.app.ui.use_toolbars and uiscale is ba.UIScale.SMALL: 92 ba.textwidget(edit=txt, text='') 93 94 v = height - (110 if self._is_main_menu else 90) 95 v -= 100 96 clr = (0.6, 0.7, 0.6, 1.0) 97 v -= 280 if self._is_main_menu else 180 98 v += (30 99 if ba.app.ui.use_toolbars and uiscale is ba.UIScale.SMALL else 0) 100 hoffs = x_offs + 80 if self._is_main_menu else x_offs - 100 101 scl = 1.13 if self._is_main_menu else 0.68 102 103 self._lineup_tex = ba.gettexture('playerLineup') 104 angry_computer_transparent_model = ba.getmodel( 105 'angryComputerTransparent') 106 self._lineup_1_transparent_model = ba.getmodel( 107 'playerLineup1Transparent') 108 self._lineup_2_transparent_model = ba.getmodel( 109 'playerLineup2Transparent') 110 self._lineup_3_transparent_model = ba.getmodel( 111 'playerLineup3Transparent') 112 self._lineup_4_transparent_model = ba.getmodel( 113 'playerLineup4Transparent') 114 self._eyes_model = ba.getmodel('plasticEyesTransparent') 115 116 self._coop_button: ba.Widget | None = None 117 118 # Only show coop button in main-menu variant. 119 if self._is_main_menu: 120 self._coop_button = btn = ba.buttonwidget( 121 parent=self._root_widget, 122 position=(hoffs, v + (scl * 15 if self._is_main_menu else 0)), 123 size=(scl * button_width, 124 scl * (300 if self._is_main_menu else 360)), 125 extra_touch_border_scale=0.1, 126 autoselect=True, 127 label='', 128 button_type='square', 129 text_scale=1.13, 130 on_activate_call=self._coop) 131 132 if ba.app.ui.use_toolbars and uiscale is ba.UIScale.SMALL: 133 ba.widget(edit=btn, 134 left_widget=_ba.get_special_widget('back_button')) 135 ba.widget(edit=btn, 136 up_widget=_ba.get_special_widget('account_button')) 137 ba.widget( 138 edit=btn, 139 down_widget=_ba.get_special_widget('settings_button')) 140 141 self._draw_dude(0, 142 btn, 143 hoffs, 144 v, 145 scl, 146 position=(140, 30), 147 color=(0.72, 0.4, 1.0)) 148 self._draw_dude(1, 149 btn, 150 hoffs, 151 v, 152 scl, 153 position=(185, 53), 154 color=(0.71, 0.5, 1.0)) 155 self._draw_dude(2, 156 btn, 157 hoffs, 158 v, 159 scl, 160 position=(220, 27), 161 color=(0.67, 0.44, 1.0)) 162 self._draw_dude(3, 163 btn, 164 hoffs, 165 v, 166 scl, 167 position=(255, 57), 168 color=(0.7, 0.3, 1.0)) 169 ba.imagewidget(parent=self._root_widget, 170 draw_controller=btn, 171 position=(hoffs + scl * 230, v + scl * 153), 172 size=(scl * 115, scl * 115), 173 texture=self._lineup_tex, 174 model_transparent=angry_computer_transparent_model) 175 176 ba.textwidget(parent=self._root_widget, 177 draw_controller=btn, 178 position=(hoffs + scl * (-10), v + scl * 95), 179 size=(scl * button_width, scl * 50), 180 text=ba.Lstr( 181 resource='playModes.singlePlayerCoopText', 182 fallback_resource='playModes.coopText'), 183 maxwidth=scl * button_width * 0.7, 184 res_scale=1.5, 185 h_align='center', 186 v_align='center', 187 color=(0.7, 0.9, 0.7, 1.0), 188 scale=scl * 2.3) 189 190 ba.textwidget(parent=self._root_widget, 191 draw_controller=btn, 192 position=(hoffs + scl * (-10), v + (scl * 54)), 193 size=(scl * button_width, scl * 30), 194 text=ba.Lstr(resource=self._r + 195 '.oneToFourPlayersText'), 196 h_align='center', 197 v_align='center', 198 scale=0.83 * scl, 199 flatness=1.0, 200 maxwidth=scl * button_width * 0.7, 201 color=clr) 202 203 scl = 0.5 if self._is_main_menu else 0.68 204 hoffs += 440 if self._is_main_menu else 216 205 v += 180 if self._is_main_menu else -68 206 207 self._teams_button = btn = ba.buttonwidget( 208 parent=self._root_widget, 209 position=(hoffs, v + (scl * 15 if self._is_main_menu else 0)), 210 size=(scl * button_width, 211 scl * (300 if self._is_main_menu else 360)), 212 extra_touch_border_scale=0.1, 213 autoselect=True, 214 label='', 215 button_type='square', 216 text_scale=1.13, 217 on_activate_call=self._team_tourney) 218 219 if ba.app.ui.use_toolbars: 220 ba.widget(edit=btn, 221 up_widget=_ba.get_special_widget('tickets_plus_button'), 222 right_widget=_ba.get_special_widget('party_button')) 223 224 xxx = -14 225 self._draw_dude(2, 226 btn, 227 hoffs, 228 v, 229 scl, 230 position=(xxx + 148, 30), 231 color=(0.2, 0.4, 1.0)) 232 self._draw_dude(3, 233 btn, 234 hoffs, 235 v, 236 scl, 237 position=(xxx + 181, 53), 238 color=(0.3, 0.4, 1.0)) 239 self._draw_dude(1, 240 btn, 241 hoffs, 242 v, 243 scl, 244 position=(xxx + 216, 33), 245 color=(0.3, 0.5, 1.0)) 246 self._draw_dude(0, 247 btn, 248 hoffs, 249 v, 250 scl, 251 position=(xxx + 245, 57), 252 color=(0.3, 0.5, 1.0)) 253 254 xxx = 155 255 self._draw_dude(0, 256 btn, 257 hoffs, 258 v, 259 scl, 260 position=(xxx + 151, 30), 261 color=(1.0, 0.5, 0.4)) 262 self._draw_dude(1, 263 btn, 264 hoffs, 265 v, 266 scl, 267 position=(xxx + 189, 53), 268 color=(1.0, 0.58, 0.58)) 269 self._draw_dude(3, 270 btn, 271 hoffs, 272 v, 273 scl, 274 position=(xxx + 223, 27), 275 color=(1.0, 0.5, 0.5)) 276 self._draw_dude(2, 277 btn, 278 hoffs, 279 v, 280 scl, 281 position=(xxx + 257, 57), 282 color=(1.0, 0.5, 0.5)) 283 284 ba.textwidget(parent=self._root_widget, 285 draw_controller=btn, 286 position=(hoffs + scl * (-10), v + scl * 95), 287 size=(scl * button_width, scl * 50), 288 text=ba.Lstr(resource='playModes.teamsText', 289 fallback_resource='teamsText'), 290 res_scale=1.5, 291 maxwidth=scl * button_width * 0.7, 292 h_align='center', 293 v_align='center', 294 color=(0.7, 0.9, 0.7, 1.0), 295 scale=scl * 2.3) 296 ba.textwidget(parent=self._root_widget, 297 draw_controller=btn, 298 position=(hoffs + scl * (-10), v + (scl * 54)), 299 size=(scl * button_width, scl * 30), 300 text=ba.Lstr(resource=self._r + 301 '.twoToEightPlayersText'), 302 h_align='center', 303 v_align='center', 304 res_scale=1.5, 305 scale=0.9 * scl, 306 flatness=1.0, 307 maxwidth=scl * button_width * 0.7, 308 color=clr) 309 310 hoffs += 0 if self._is_main_menu else 300 311 v -= 155 if self._is_main_menu else 0 312 self._free_for_all_button = btn = ba.buttonwidget( 313 parent=self._root_widget, 314 position=(hoffs, v + (scl * 15 if self._is_main_menu else 0)), 315 size=(scl * button_width, 316 scl * (300 if self._is_main_menu else 360)), 317 extra_touch_border_scale=0.1, 318 autoselect=True, 319 label='', 320 button_type='square', 321 text_scale=1.13, 322 on_activate_call=self._free_for_all) 323 324 xxx = -5 325 self._draw_dude(0, 326 btn, 327 hoffs, 328 v, 329 scl, 330 position=(xxx + 140, 30), 331 color=(0.4, 1.0, 0.4)) 332 self._draw_dude(3, 333 btn, 334 hoffs, 335 v, 336 scl, 337 position=(xxx + 185, 53), 338 color=(1.0, 0.4, 0.5)) 339 self._draw_dude(1, 340 btn, 341 hoffs, 342 v, 343 scl, 344 position=(xxx + 220, 27), 345 color=(0.4, 0.5, 1.0)) 346 self._draw_dude(2, 347 btn, 348 hoffs, 349 v, 350 scl, 351 position=(xxx + 255, 57), 352 color=(0.5, 1.0, 0.4)) 353 xxx = 140 354 self._draw_dude(2, 355 btn, 356 hoffs, 357 v, 358 scl, 359 position=(xxx + 148, 30), 360 color=(1.0, 0.9, 0.4)) 361 self._draw_dude(0, 362 btn, 363 hoffs, 364 v, 365 scl, 366 position=(xxx + 182, 53), 367 color=(0.7, 1.0, 0.5)) 368 self._draw_dude(3, 369 btn, 370 hoffs, 371 v, 372 scl, 373 position=(xxx + 233, 27), 374 color=(0.7, 0.5, 0.9)) 375 self._draw_dude(1, 376 btn, 377 hoffs, 378 v, 379 scl, 380 position=(xxx + 266, 53), 381 color=(0.4, 0.5, 0.8)) 382 ba.textwidget(parent=self._root_widget, 383 draw_controller=btn, 384 position=(hoffs + scl * (-10), v + scl * 95), 385 size=(scl * button_width, scl * 50), 386 text=ba.Lstr(resource='playModes.freeForAllText', 387 fallback_resource='freeForAllText'), 388 maxwidth=scl * button_width * 0.7, 389 h_align='center', 390 v_align='center', 391 color=(0.7, 0.9, 0.7, 1.0), 392 scale=scl * 1.9) 393 ba.textwidget(parent=self._root_widget, 394 draw_controller=btn, 395 position=(hoffs + scl * (-10), v + (scl * 54)), 396 size=(scl * button_width, scl * 30), 397 text=ba.Lstr(resource=self._r + 398 '.twoToEightPlayersText'), 399 h_align='center', 400 v_align='center', 401 scale=0.9 * scl, 402 flatness=1.0, 403 maxwidth=scl * button_width * 0.7, 404 color=clr) 405 406 if ba.app.ui.use_toolbars and uiscale is ba.UIScale.SMALL: 407 back_button.delete() 408 ba.containerwidget(edit=self._root_widget, 409 on_cancel_call=self._back, 410 selected_child=self._coop_button 411 if self._is_main_menu else self._teams_button) 412 else: 413 ba.buttonwidget(edit=back_button, on_activate_call=self._back) 414 ba.containerwidget(edit=self._root_widget, 415 cancel_button=back_button, 416 selected_child=self._coop_button 417 if self._is_main_menu else self._teams_button) 418 419 self._restore_state()
Inherited Members
- ba.ui.Window
- get_root_widget