bauiv1lib.promocode
UI functionality for entering promo codes.
1# Released under the MIT License. See LICENSE for details. 2# 3"""UI functionality for entering promo codes.""" 4 5from __future__ import annotations 6 7import time 8 9import bauiv1 as bui 10 11 12class PromoCodeWindow(bui.Window): 13 """Window for entering promo codes.""" 14 15 def __init__( 16 self, modal: bool = False, origin_widget: bui.Widget | None = None 17 ): 18 scale_origin: tuple[float, float] | None 19 if origin_widget is not None: 20 self._transition_out = 'out_scale' 21 scale_origin = origin_widget.get_screen_space_center() 22 transition = 'in_scale' 23 else: 24 self._transition_out = 'out_right' 25 scale_origin = None 26 transition = 'in_right' 27 28 width = 450 29 height = 230 30 31 self._modal = modal 32 self._r = 'promoCodeWindow' 33 34 assert bui.app.classic is not None 35 uiscale = bui.app.ui_v1.uiscale 36 super().__init__( 37 root_widget=bui.containerwidget( 38 size=(width, height), 39 transition=transition, 40 toolbar_visibility='menu_minimal_no_back', 41 scale_origin_stack_offset=scale_origin, 42 scale=( 43 2.0 44 if uiscale is bui.UIScale.SMALL 45 else 1.5 46 if uiscale is bui.UIScale.MEDIUM 47 else 1.0 48 ), 49 ) 50 ) 51 52 btn = bui.buttonwidget( 53 parent=self._root_widget, 54 scale=0.5, 55 position=(40, height - 40), 56 size=(60, 60), 57 label='', 58 on_activate_call=self._do_back, 59 autoselect=True, 60 color=(0.55, 0.5, 0.6), 61 icon=bui.gettexture('crossOut'), 62 iconscale=1.2, 63 ) 64 65 bui.textwidget( 66 parent=self._root_widget, 67 text=bui.Lstr(resource=self._r + '.codeText'), 68 position=(22, height - 113), 69 color=(0.8, 0.8, 0.8, 1.0), 70 size=(90, 30), 71 h_align='right', 72 ) 73 self._text_field = bui.textwidget( 74 parent=self._root_widget, 75 position=(125, height - 121), 76 size=(280, 46), 77 text='', 78 h_align='left', 79 v_align='center', 80 max_chars=64, 81 color=(0.9, 0.9, 0.9, 1.0), 82 description=bui.Lstr(resource=self._r + '.codeText'), 83 editable=True, 84 padding=4, 85 on_return_press_call=self._activate_enter_button, 86 ) 87 bui.widget(edit=btn, down_widget=self._text_field) 88 89 b_width = 200 90 self._enter_button = btn2 = bui.buttonwidget( 91 parent=self._root_widget, 92 position=(width * 0.5 - b_width * 0.5, height - 200), 93 size=(b_width, 60), 94 scale=1.0, 95 label=bui.Lstr( 96 resource='submitText', fallback_resource=self._r + '.enterText' 97 ), 98 on_activate_call=self._do_enter, 99 ) 100 bui.containerwidget( 101 edit=self._root_widget, 102 cancel_button=btn, 103 start_button=btn2, 104 selected_child=self._text_field, 105 ) 106 107 def _do_back(self) -> None: 108 # pylint: disable=cyclic-import 109 from bauiv1lib.settings.advanced import AdvancedSettingsWindow 110 111 bui.containerwidget( 112 edit=self._root_widget, transition=self._transition_out 113 ) 114 if not self._modal: 115 assert bui.app.classic is not None 116 bui.app.ui_v1.set_main_menu_window( 117 AdvancedSettingsWindow(transition='in_left').get_root_widget() 118 ) 119 120 def _activate_enter_button(self) -> None: 121 self._enter_button.activate() 122 123 def _do_enter(self) -> None: 124 # pylint: disable=cyclic-import 125 from bauiv1lib.settings.advanced import AdvancedSettingsWindow 126 127 plus = bui.app.plus 128 assert plus is not None 129 130 bui.containerwidget( 131 edit=self._root_widget, transition=self._transition_out 132 ) 133 if not self._modal: 134 assert bui.app.classic is not None 135 bui.app.ui_v1.set_main_menu_window( 136 AdvancedSettingsWindow(transition='in_left').get_root_widget() 137 ) 138 plus.add_v1_account_transaction( 139 { 140 'type': 'PROMO_CODE', 141 'expire_time': time.time() + 5, 142 'code': bui.textwidget(query=self._text_field), 143 } 144 ) 145 plus.run_v1_account_transactions()
class
PromoCodeWindow(bauiv1._uitypes.Window):
13class PromoCodeWindow(bui.Window): 14 """Window for entering promo codes.""" 15 16 def __init__( 17 self, modal: bool = False, origin_widget: bui.Widget | None = None 18 ): 19 scale_origin: tuple[float, float] | None 20 if origin_widget is not None: 21 self._transition_out = 'out_scale' 22 scale_origin = origin_widget.get_screen_space_center() 23 transition = 'in_scale' 24 else: 25 self._transition_out = 'out_right' 26 scale_origin = None 27 transition = 'in_right' 28 29 width = 450 30 height = 230 31 32 self._modal = modal 33 self._r = 'promoCodeWindow' 34 35 assert bui.app.classic is not None 36 uiscale = bui.app.ui_v1.uiscale 37 super().__init__( 38 root_widget=bui.containerwidget( 39 size=(width, height), 40 transition=transition, 41 toolbar_visibility='menu_minimal_no_back', 42 scale_origin_stack_offset=scale_origin, 43 scale=( 44 2.0 45 if uiscale is bui.UIScale.SMALL 46 else 1.5 47 if uiscale is bui.UIScale.MEDIUM 48 else 1.0 49 ), 50 ) 51 ) 52 53 btn = bui.buttonwidget( 54 parent=self._root_widget, 55 scale=0.5, 56 position=(40, height - 40), 57 size=(60, 60), 58 label='', 59 on_activate_call=self._do_back, 60 autoselect=True, 61 color=(0.55, 0.5, 0.6), 62 icon=bui.gettexture('crossOut'), 63 iconscale=1.2, 64 ) 65 66 bui.textwidget( 67 parent=self._root_widget, 68 text=bui.Lstr(resource=self._r + '.codeText'), 69 position=(22, height - 113), 70 color=(0.8, 0.8, 0.8, 1.0), 71 size=(90, 30), 72 h_align='right', 73 ) 74 self._text_field = bui.textwidget( 75 parent=self._root_widget, 76 position=(125, height - 121), 77 size=(280, 46), 78 text='', 79 h_align='left', 80 v_align='center', 81 max_chars=64, 82 color=(0.9, 0.9, 0.9, 1.0), 83 description=bui.Lstr(resource=self._r + '.codeText'), 84 editable=True, 85 padding=4, 86 on_return_press_call=self._activate_enter_button, 87 ) 88 bui.widget(edit=btn, down_widget=self._text_field) 89 90 b_width = 200 91 self._enter_button = btn2 = bui.buttonwidget( 92 parent=self._root_widget, 93 position=(width * 0.5 - b_width * 0.5, height - 200), 94 size=(b_width, 60), 95 scale=1.0, 96 label=bui.Lstr( 97 resource='submitText', fallback_resource=self._r + '.enterText' 98 ), 99 on_activate_call=self._do_enter, 100 ) 101 bui.containerwidget( 102 edit=self._root_widget, 103 cancel_button=btn, 104 start_button=btn2, 105 selected_child=self._text_field, 106 ) 107 108 def _do_back(self) -> None: 109 # pylint: disable=cyclic-import 110 from bauiv1lib.settings.advanced import AdvancedSettingsWindow 111 112 bui.containerwidget( 113 edit=self._root_widget, transition=self._transition_out 114 ) 115 if not self._modal: 116 assert bui.app.classic is not None 117 bui.app.ui_v1.set_main_menu_window( 118 AdvancedSettingsWindow(transition='in_left').get_root_widget() 119 ) 120 121 def _activate_enter_button(self) -> None: 122 self._enter_button.activate() 123 124 def _do_enter(self) -> None: 125 # pylint: disable=cyclic-import 126 from bauiv1lib.settings.advanced import AdvancedSettingsWindow 127 128 plus = bui.app.plus 129 assert plus is not None 130 131 bui.containerwidget( 132 edit=self._root_widget, transition=self._transition_out 133 ) 134 if not self._modal: 135 assert bui.app.classic is not None 136 bui.app.ui_v1.set_main_menu_window( 137 AdvancedSettingsWindow(transition='in_left').get_root_widget() 138 ) 139 plus.add_v1_account_transaction( 140 { 141 'type': 'PROMO_CODE', 142 'expire_time': time.time() + 5, 143 'code': bui.textwidget(query=self._text_field), 144 } 145 ) 146 plus.run_v1_account_transactions()
Window for entering promo codes.
PromoCodeWindow(modal: bool = False, origin_widget: _bauiv1.Widget | None = None)
16 def __init__( 17 self, modal: bool = False, origin_widget: bui.Widget | None = None 18 ): 19 scale_origin: tuple[float, float] | None 20 if origin_widget is not None: 21 self._transition_out = 'out_scale' 22 scale_origin = origin_widget.get_screen_space_center() 23 transition = 'in_scale' 24 else: 25 self._transition_out = 'out_right' 26 scale_origin = None 27 transition = 'in_right' 28 29 width = 450 30 height = 230 31 32 self._modal = modal 33 self._r = 'promoCodeWindow' 34 35 assert bui.app.classic is not None 36 uiscale = bui.app.ui_v1.uiscale 37 super().__init__( 38 root_widget=bui.containerwidget( 39 size=(width, height), 40 transition=transition, 41 toolbar_visibility='menu_minimal_no_back', 42 scale_origin_stack_offset=scale_origin, 43 scale=( 44 2.0 45 if uiscale is bui.UIScale.SMALL 46 else 1.5 47 if uiscale is bui.UIScale.MEDIUM 48 else 1.0 49 ), 50 ) 51 ) 52 53 btn = bui.buttonwidget( 54 parent=self._root_widget, 55 scale=0.5, 56 position=(40, height - 40), 57 size=(60, 60), 58 label='', 59 on_activate_call=self._do_back, 60 autoselect=True, 61 color=(0.55, 0.5, 0.6), 62 icon=bui.gettexture('crossOut'), 63 iconscale=1.2, 64 ) 65 66 bui.textwidget( 67 parent=self._root_widget, 68 text=bui.Lstr(resource=self._r + '.codeText'), 69 position=(22, height - 113), 70 color=(0.8, 0.8, 0.8, 1.0), 71 size=(90, 30), 72 h_align='right', 73 ) 74 self._text_field = bui.textwidget( 75 parent=self._root_widget, 76 position=(125, height - 121), 77 size=(280, 46), 78 text='', 79 h_align='left', 80 v_align='center', 81 max_chars=64, 82 color=(0.9, 0.9, 0.9, 1.0), 83 description=bui.Lstr(resource=self._r + '.codeText'), 84 editable=True, 85 padding=4, 86 on_return_press_call=self._activate_enter_button, 87 ) 88 bui.widget(edit=btn, down_widget=self._text_field) 89 90 b_width = 200 91 self._enter_button = btn2 = bui.buttonwidget( 92 parent=self._root_widget, 93 position=(width * 0.5 - b_width * 0.5, height - 200), 94 size=(b_width, 60), 95 scale=1.0, 96 label=bui.Lstr( 97 resource='submitText', fallback_resource=self._r + '.enterText' 98 ), 99 on_activate_call=self._do_enter, 100 ) 101 bui.containerwidget( 102 edit=self._root_widget, 103 cancel_button=btn, 104 start_button=btn2, 105 selected_child=self._text_field, 106 )
Inherited Members
- bauiv1._uitypes.Window
- get_root_widget