bastd.ui.playlist.addgame
Provides a window for selecting a game type to add to a playlist.
1# Released under the MIT License. See LICENSE for details. 2# 3"""Provides a window for selecting a game type to add to a playlist.""" 4 5from __future__ import annotations 6 7from typing import TYPE_CHECKING 8 9import _ba 10import ba 11 12if TYPE_CHECKING: 13 from bastd.ui.playlist.editcontroller import PlaylistEditController 14 15 16class PlaylistAddGameWindow(ba.Window): 17 """Window for selecting a game type to add to a playlist.""" 18 19 def __init__(self, 20 editcontroller: PlaylistEditController, 21 transition: str = 'in_right'): 22 self._editcontroller = editcontroller 23 self._r = 'addGameWindow' 24 uiscale = ba.app.ui.uiscale 25 self._width = 750 if uiscale is ba.UIScale.SMALL else 650 26 x_inset = 50 if uiscale is ba.UIScale.SMALL else 0 27 self._height = (346 if uiscale is ba.UIScale.SMALL else 28 380 if uiscale is ba.UIScale.MEDIUM else 440) 29 top_extra = 30 if uiscale is ba.UIScale.SMALL else 20 30 self._scroll_width = 210 31 32 super().__init__(root_widget=ba.containerwidget( 33 size=(self._width, self._height + top_extra), 34 transition=transition, 35 scale=(2.17 if uiscale is ba.UIScale.SMALL else 36 1.5 if uiscale is ba.UIScale.MEDIUM else 1.0), 37 stack_offset=(0, 1) if uiscale is ba.UIScale.SMALL else (0, 0))) 38 39 self._back_button = ba.buttonwidget(parent=self._root_widget, 40 position=(58 + x_inset, 41 self._height - 53), 42 size=(165, 70), 43 scale=0.75, 44 text_scale=1.2, 45 label=ba.Lstr(resource='backText'), 46 autoselect=True, 47 button_type='back', 48 on_activate_call=self._back) 49 self._select_button = select_button = ba.buttonwidget( 50 parent=self._root_widget, 51 position=(self._width - (172 + x_inset), self._height - 50), 52 autoselect=True, 53 size=(160, 60), 54 scale=0.75, 55 text_scale=1.2, 56 label=ba.Lstr(resource='selectText'), 57 on_activate_call=self._add) 58 59 if ba.app.ui.use_toolbars: 60 ba.widget(edit=select_button, 61 right_widget=_ba.get_special_widget('party_button')) 62 63 ba.textwidget(parent=self._root_widget, 64 position=(self._width * 0.5, self._height - 28), 65 size=(0, 0), 66 scale=1.0, 67 text=ba.Lstr(resource=self._r + '.titleText'), 68 h_align='center', 69 color=ba.app.ui.title_color, 70 maxwidth=250, 71 v_align='center') 72 v = self._height - 64 73 74 self._selected_title_text = ba.textwidget( 75 parent=self._root_widget, 76 position=(x_inset + self._scroll_width + 50 + 30, v - 15), 77 size=(0, 0), 78 scale=1.0, 79 color=(0.7, 1.0, 0.7, 1.0), 80 maxwidth=self._width - self._scroll_width - 150 - x_inset * 2, 81 h_align='left', 82 v_align='center') 83 v -= 30 84 85 self._selected_description_text = ba.textwidget( 86 parent=self._root_widget, 87 position=(x_inset + self._scroll_width + 50 + 30, v), 88 size=(0, 0), 89 scale=0.7, 90 color=(0.5, 0.8, 0.5, 1.0), 91 maxwidth=self._width - self._scroll_width - 150 - x_inset * 2, 92 h_align='left') 93 94 scroll_height = self._height - 100 95 96 v = self._height - 60 97 98 self._scrollwidget = ba.scrollwidget(parent=self._root_widget, 99 position=(x_inset + 61, 100 v - scroll_height), 101 size=(self._scroll_width, 102 scroll_height), 103 highlight=False) 104 ba.widget(edit=self._scrollwidget, 105 up_widget=self._back_button, 106 left_widget=self._back_button, 107 right_widget=select_button) 108 self._column: ba.Widget | None = None 109 110 v -= 35 111 ba.containerwidget(edit=self._root_widget, 112 cancel_button=self._back_button, 113 start_button=select_button) 114 self._selected_game_type: type[ba.GameActivity] | None = None 115 116 ba.containerwidget(edit=self._root_widget, 117 selected_child=self._scrollwidget) 118 119 self._refresh() 120 121 def _refresh(self, select_get_more_games_button: bool = False) -> None: 122 from ba.internal import get_game_types 123 124 if self._column is not None: 125 self._column.delete() 126 127 self._column = ba.columnwidget(parent=self._scrollwidget, 128 border=2, 129 margin=0) 130 131 gametypes = [ 132 gt for gt in get_game_types() if gt.supports_session_type( 133 self._editcontroller.get_session_type()) 134 ] 135 136 # Sort in the current language. 137 gametypes.sort(key=lambda g: g.get_display_string().evaluate()) 138 139 for i, gametype in enumerate(gametypes): 140 141 def _doit() -> None: 142 if self._select_button: 143 ba.timer(0.1, 144 self._select_button.activate, 145 timetype=ba.TimeType.REAL) 146 147 txt = ba.textwidget(parent=self._column, 148 position=(0, 0), 149 size=(self._width - 88, 24), 150 text=gametype.get_display_string(), 151 h_align='left', 152 v_align='center', 153 color=(0.8, 0.8, 0.8, 1.0), 154 maxwidth=self._scroll_width * 0.8, 155 on_select_call=ba.Call( 156 self._set_selected_game_type, gametype), 157 always_highlight=True, 158 selectable=True, 159 on_activate_call=_doit) 160 if i == 0: 161 ba.widget(edit=txt, up_widget=self._back_button) 162 163 self._get_more_games_button = ba.buttonwidget( 164 parent=self._column, 165 autoselect=True, 166 label=ba.Lstr(resource=self._r + '.getMoreGamesText'), 167 color=(0.54, 0.52, 0.67), 168 textcolor=(0.7, 0.65, 0.7), 169 on_activate_call=self._on_get_more_games_press, 170 size=(178, 50)) 171 if select_get_more_games_button: 172 ba.containerwidget(edit=self._column, 173 selected_child=self._get_more_games_button, 174 visible_child=self._get_more_games_button) 175 176 def _on_get_more_games_press(self) -> None: 177 from bastd.ui.account import show_sign_in_prompt 178 from bastd.ui.store.browser import StoreBrowserWindow 179 if _ba.get_v1_account_state() != 'signed_in': 180 show_sign_in_prompt() 181 return 182 StoreBrowserWindow(modal=True, 183 show_tab=StoreBrowserWindow.TabID.MINIGAMES, 184 on_close_call=self._on_store_close, 185 origin_widget=self._get_more_games_button) 186 187 def _on_store_close(self) -> None: 188 self._refresh(select_get_more_games_button=True) 189 190 def _add(self) -> None: 191 _ba.lock_all_input() # Make sure no more commands happen. 192 ba.timer(0.1, _ba.unlock_all_input, timetype=ba.TimeType.REAL) 193 assert self._selected_game_type is not None 194 self._editcontroller.add_game_type_selected(self._selected_game_type) 195 196 def _set_selected_game_type(self, gametype: type[ba.GameActivity]) -> None: 197 self._selected_game_type = gametype 198 ba.textwidget(edit=self._selected_title_text, 199 text=gametype.get_display_string()) 200 ba.textwidget(edit=self._selected_description_text, 201 text=gametype.get_description_display_string( 202 self._editcontroller.get_session_type())) 203 204 def _back(self) -> None: 205 self._editcontroller.add_game_cancelled()
class
PlaylistAddGameWindow(ba.ui.Window):
17class PlaylistAddGameWindow(ba.Window): 18 """Window for selecting a game type to add to a playlist.""" 19 20 def __init__(self, 21 editcontroller: PlaylistEditController, 22 transition: str = 'in_right'): 23 self._editcontroller = editcontroller 24 self._r = 'addGameWindow' 25 uiscale = ba.app.ui.uiscale 26 self._width = 750 if uiscale is ba.UIScale.SMALL else 650 27 x_inset = 50 if uiscale is ba.UIScale.SMALL else 0 28 self._height = (346 if uiscale is ba.UIScale.SMALL else 29 380 if uiscale is ba.UIScale.MEDIUM else 440) 30 top_extra = 30 if uiscale is ba.UIScale.SMALL else 20 31 self._scroll_width = 210 32 33 super().__init__(root_widget=ba.containerwidget( 34 size=(self._width, self._height + top_extra), 35 transition=transition, 36 scale=(2.17 if uiscale is ba.UIScale.SMALL else 37 1.5 if uiscale is ba.UIScale.MEDIUM else 1.0), 38 stack_offset=(0, 1) if uiscale is ba.UIScale.SMALL else (0, 0))) 39 40 self._back_button = ba.buttonwidget(parent=self._root_widget, 41 position=(58 + x_inset, 42 self._height - 53), 43 size=(165, 70), 44 scale=0.75, 45 text_scale=1.2, 46 label=ba.Lstr(resource='backText'), 47 autoselect=True, 48 button_type='back', 49 on_activate_call=self._back) 50 self._select_button = select_button = ba.buttonwidget( 51 parent=self._root_widget, 52 position=(self._width - (172 + x_inset), self._height - 50), 53 autoselect=True, 54 size=(160, 60), 55 scale=0.75, 56 text_scale=1.2, 57 label=ba.Lstr(resource='selectText'), 58 on_activate_call=self._add) 59 60 if ba.app.ui.use_toolbars: 61 ba.widget(edit=select_button, 62 right_widget=_ba.get_special_widget('party_button')) 63 64 ba.textwidget(parent=self._root_widget, 65 position=(self._width * 0.5, self._height - 28), 66 size=(0, 0), 67 scale=1.0, 68 text=ba.Lstr(resource=self._r + '.titleText'), 69 h_align='center', 70 color=ba.app.ui.title_color, 71 maxwidth=250, 72 v_align='center') 73 v = self._height - 64 74 75 self._selected_title_text = ba.textwidget( 76 parent=self._root_widget, 77 position=(x_inset + self._scroll_width + 50 + 30, v - 15), 78 size=(0, 0), 79 scale=1.0, 80 color=(0.7, 1.0, 0.7, 1.0), 81 maxwidth=self._width - self._scroll_width - 150 - x_inset * 2, 82 h_align='left', 83 v_align='center') 84 v -= 30 85 86 self._selected_description_text = ba.textwidget( 87 parent=self._root_widget, 88 position=(x_inset + self._scroll_width + 50 + 30, v), 89 size=(0, 0), 90 scale=0.7, 91 color=(0.5, 0.8, 0.5, 1.0), 92 maxwidth=self._width - self._scroll_width - 150 - x_inset * 2, 93 h_align='left') 94 95 scroll_height = self._height - 100 96 97 v = self._height - 60 98 99 self._scrollwidget = ba.scrollwidget(parent=self._root_widget, 100 position=(x_inset + 61, 101 v - scroll_height), 102 size=(self._scroll_width, 103 scroll_height), 104 highlight=False) 105 ba.widget(edit=self._scrollwidget, 106 up_widget=self._back_button, 107 left_widget=self._back_button, 108 right_widget=select_button) 109 self._column: ba.Widget | None = None 110 111 v -= 35 112 ba.containerwidget(edit=self._root_widget, 113 cancel_button=self._back_button, 114 start_button=select_button) 115 self._selected_game_type: type[ba.GameActivity] | None = None 116 117 ba.containerwidget(edit=self._root_widget, 118 selected_child=self._scrollwidget) 119 120 self._refresh() 121 122 def _refresh(self, select_get_more_games_button: bool = False) -> None: 123 from ba.internal import get_game_types 124 125 if self._column is not None: 126 self._column.delete() 127 128 self._column = ba.columnwidget(parent=self._scrollwidget, 129 border=2, 130 margin=0) 131 132 gametypes = [ 133 gt for gt in get_game_types() if gt.supports_session_type( 134 self._editcontroller.get_session_type()) 135 ] 136 137 # Sort in the current language. 138 gametypes.sort(key=lambda g: g.get_display_string().evaluate()) 139 140 for i, gametype in enumerate(gametypes): 141 142 def _doit() -> None: 143 if self._select_button: 144 ba.timer(0.1, 145 self._select_button.activate, 146 timetype=ba.TimeType.REAL) 147 148 txt = ba.textwidget(parent=self._column, 149 position=(0, 0), 150 size=(self._width - 88, 24), 151 text=gametype.get_display_string(), 152 h_align='left', 153 v_align='center', 154 color=(0.8, 0.8, 0.8, 1.0), 155 maxwidth=self._scroll_width * 0.8, 156 on_select_call=ba.Call( 157 self._set_selected_game_type, gametype), 158 always_highlight=True, 159 selectable=True, 160 on_activate_call=_doit) 161 if i == 0: 162 ba.widget(edit=txt, up_widget=self._back_button) 163 164 self._get_more_games_button = ba.buttonwidget( 165 parent=self._column, 166 autoselect=True, 167 label=ba.Lstr(resource=self._r + '.getMoreGamesText'), 168 color=(0.54, 0.52, 0.67), 169 textcolor=(0.7, 0.65, 0.7), 170 on_activate_call=self._on_get_more_games_press, 171 size=(178, 50)) 172 if select_get_more_games_button: 173 ba.containerwidget(edit=self._column, 174 selected_child=self._get_more_games_button, 175 visible_child=self._get_more_games_button) 176 177 def _on_get_more_games_press(self) -> None: 178 from bastd.ui.account import show_sign_in_prompt 179 from bastd.ui.store.browser import StoreBrowserWindow 180 if _ba.get_v1_account_state() != 'signed_in': 181 show_sign_in_prompt() 182 return 183 StoreBrowserWindow(modal=True, 184 show_tab=StoreBrowserWindow.TabID.MINIGAMES, 185 on_close_call=self._on_store_close, 186 origin_widget=self._get_more_games_button) 187 188 def _on_store_close(self) -> None: 189 self._refresh(select_get_more_games_button=True) 190 191 def _add(self) -> None: 192 _ba.lock_all_input() # Make sure no more commands happen. 193 ba.timer(0.1, _ba.unlock_all_input, timetype=ba.TimeType.REAL) 194 assert self._selected_game_type is not None 195 self._editcontroller.add_game_type_selected(self._selected_game_type) 196 197 def _set_selected_game_type(self, gametype: type[ba.GameActivity]) -> None: 198 self._selected_game_type = gametype 199 ba.textwidget(edit=self._selected_title_text, 200 text=gametype.get_display_string()) 201 ba.textwidget(edit=self._selected_description_text, 202 text=gametype.get_description_display_string( 203 self._editcontroller.get_session_type())) 204 205 def _back(self) -> None: 206 self._editcontroller.add_game_cancelled()
Window for selecting a game type to add to a playlist.
PlaylistAddGameWindow( editcontroller: bastd.ui.playlist.editcontroller.PlaylistEditController, transition: str = 'in_right')
20 def __init__(self, 21 editcontroller: PlaylistEditController, 22 transition: str = 'in_right'): 23 self._editcontroller = editcontroller 24 self._r = 'addGameWindow' 25 uiscale = ba.app.ui.uiscale 26 self._width = 750 if uiscale is ba.UIScale.SMALL else 650 27 x_inset = 50 if uiscale is ba.UIScale.SMALL else 0 28 self._height = (346 if uiscale is ba.UIScale.SMALL else 29 380 if uiscale is ba.UIScale.MEDIUM else 440) 30 top_extra = 30 if uiscale is ba.UIScale.SMALL else 20 31 self._scroll_width = 210 32 33 super().__init__(root_widget=ba.containerwidget( 34 size=(self._width, self._height + top_extra), 35 transition=transition, 36 scale=(2.17 if uiscale is ba.UIScale.SMALL else 37 1.5 if uiscale is ba.UIScale.MEDIUM else 1.0), 38 stack_offset=(0, 1) if uiscale is ba.UIScale.SMALL else (0, 0))) 39 40 self._back_button = ba.buttonwidget(parent=self._root_widget, 41 position=(58 + x_inset, 42 self._height - 53), 43 size=(165, 70), 44 scale=0.75, 45 text_scale=1.2, 46 label=ba.Lstr(resource='backText'), 47 autoselect=True, 48 button_type='back', 49 on_activate_call=self._back) 50 self._select_button = select_button = ba.buttonwidget( 51 parent=self._root_widget, 52 position=(self._width - (172 + x_inset), self._height - 50), 53 autoselect=True, 54 size=(160, 60), 55 scale=0.75, 56 text_scale=1.2, 57 label=ba.Lstr(resource='selectText'), 58 on_activate_call=self._add) 59 60 if ba.app.ui.use_toolbars: 61 ba.widget(edit=select_button, 62 right_widget=_ba.get_special_widget('party_button')) 63 64 ba.textwidget(parent=self._root_widget, 65 position=(self._width * 0.5, self._height - 28), 66 size=(0, 0), 67 scale=1.0, 68 text=ba.Lstr(resource=self._r + '.titleText'), 69 h_align='center', 70 color=ba.app.ui.title_color, 71 maxwidth=250, 72 v_align='center') 73 v = self._height - 64 74 75 self._selected_title_text = ba.textwidget( 76 parent=self._root_widget, 77 position=(x_inset + self._scroll_width + 50 + 30, v - 15), 78 size=(0, 0), 79 scale=1.0, 80 color=(0.7, 1.0, 0.7, 1.0), 81 maxwidth=self._width - self._scroll_width - 150 - x_inset * 2, 82 h_align='left', 83 v_align='center') 84 v -= 30 85 86 self._selected_description_text = ba.textwidget( 87 parent=self._root_widget, 88 position=(x_inset + self._scroll_width + 50 + 30, v), 89 size=(0, 0), 90 scale=0.7, 91 color=(0.5, 0.8, 0.5, 1.0), 92 maxwidth=self._width - self._scroll_width - 150 - x_inset * 2, 93 h_align='left') 94 95 scroll_height = self._height - 100 96 97 v = self._height - 60 98 99 self._scrollwidget = ba.scrollwidget(parent=self._root_widget, 100 position=(x_inset + 61, 101 v - scroll_height), 102 size=(self._scroll_width, 103 scroll_height), 104 highlight=False) 105 ba.widget(edit=self._scrollwidget, 106 up_widget=self._back_button, 107 left_widget=self._back_button, 108 right_widget=select_button) 109 self._column: ba.Widget | None = None 110 111 v -= 35 112 ba.containerwidget(edit=self._root_widget, 113 cancel_button=self._back_button, 114 start_button=select_button) 115 self._selected_game_type: type[ba.GameActivity] | None = None 116 117 ba.containerwidget(edit=self._root_widget, 118 selected_child=self._scrollwidget) 119 120 self._refresh()
Inherited Members
- ba.ui.Window
- get_root_widget