bauiv1lib.resourcetypeinfo

Provides a window which shows info about resource types.

  1# Released under the MIT License. See LICENSE for details.
  2#
  3"""Provides a window which shows info about resource types."""
  4
  5from __future__ import annotations
  6
  7from typing import override, TYPE_CHECKING, assert_never
  8
  9from bauiv1lib.popup import PopupWindow
 10import bauiv1 as bui
 11
 12if TYPE_CHECKING:
 13    from typing import Literal
 14
 15
 16class ResourceTypeInfoWindow(PopupWindow):
 17    """Popup window providing info about resource types."""
 18
 19    def __init__(
 20        self,
 21        resource_type: Literal['tickets', 'tokens', 'trophies', 'xp'],
 22        origin_widget: bui.Widget,
 23    ):
 24        assert bui.app.classic is not None
 25        uiscale = bui.app.ui_v1.uiscale
 26        scale = (
 27            2.0
 28            if uiscale is bui.UIScale.SMALL
 29            else 1.3 if uiscale is bui.UIScale.MEDIUM else 0.7
 30        )
 31        self._transitioning_out = False
 32        self._width = 570
 33        self._height = 400
 34        self._get_tokens_button: bui.Widget | None = None
 35        bg_color = (0.5, 0.4, 0.6)
 36        super().__init__(
 37            size=(self._width, self._height),
 38            toolbar_visibility='inherit',
 39            scale=scale,
 40            bg_color=bg_color,
 41            position=origin_widget.get_screen_space_center(),
 42            edge_buffer_scale=4.0,
 43        )
 44        self._cancel_button = bui.buttonwidget(
 45            parent=self.root_widget,
 46            position=(40, self._height - 40),
 47            size=(50, 50),
 48            scale=0.7,
 49            label='',
 50            color=bg_color,
 51            on_activate_call=self._on_cancel_press,
 52            autoselect=True,
 53            icon=bui.gettexture('crossOut'),
 54            iconscale=1.2,
 55        )
 56
 57        yoffs = self._height - 145
 58
 59        max_rdesc_height = 160
 60
 61        if resource_type == 'tickets':
 62            yoffs -= 20
 63            rdesc = (
 64                'Tickets can be used to unlock characters,\n'
 65                'maps, minigames, and more in the store.\n'
 66                '\n'
 67                'Tickets can be found in chests won through\n'
 68                'campaigns, tournaments, and achievements.'
 69            )
 70            texname = 'tickets'
 71        elif resource_type == 'tokens':
 72            rdesc = (
 73                'Tokens are used to speed up chest unlocks\n'
 74                'and for other game and account features.\n'
 75                '\n'
 76                'You can win tokens in the game or buy them\n'
 77                'in packs. Or buy a Gold Pass for infinite\n'
 78                'tokens and never hear about them again.'
 79            )
 80            texname = 'coin'
 81            bwidth = 200
 82            bheight = 50
 83
 84            self._get_tokens_button = bui.buttonwidget(
 85                parent=self.root_widget,
 86                position=(
 87                    self._width * 0.5 - bwidth * 0.5,
 88                    yoffs - 15.0 - bheight - max_rdesc_height,
 89                ),
 90                color=bg_color,
 91                textcolor=(0.8, 0.8, 0.8),
 92                label=bui.Lstr(resource='tokens.getTokensText'),
 93                size=(bwidth, bheight),
 94                autoselect=True,
 95                on_activate_call=bui.WeakCall(self._on_get_tokens_press),
 96            )
 97
 98        elif resource_type == 'trophies':
 99            rdesc = 'TODO: Will show trophies & league rankings.'
100            texname = 'crossOut'
101        elif resource_type == 'xp':
102            rdesc = 'TODO: Will describe xp/levels.'
103            texname = 'crossOut'
104        else:
105            assert_never(resource_type)
106
107        imgsize = 100.0
108        bui.imagewidget(
109            parent=self.root_widget,
110            position=(self._width * 0.5 - imgsize * 0.5, yoffs + 5.0),
111            size=(imgsize, imgsize),
112            texture=bui.gettexture(texname),
113        )
114
115        bui.textwidget(
116            parent=self.root_widget,
117            h_align='center',
118            v_align='top',
119            size=(0, 0),
120            maxwidth=self._width * 0.8,
121            max_height=max_rdesc_height,
122            position=(self._width * 0.5, yoffs - 5.0),
123            text=rdesc,
124            scale=0.8,
125        )
126
127    def _on_get_tokens_press(self) -> None:
128        from bauiv1lib.gettokens import show_get_tokens_window
129
130        self._transition_out()
131        show_get_tokens_window(
132            origin_widget=bui.existing(self._get_tokens_button)
133        )
134
135    def _on_cancel_press(self) -> None:
136        self._transition_out()
137
138    def _transition_out(self) -> None:
139        if not self._transitioning_out:
140            self._transitioning_out = True
141            bui.containerwidget(edit=self.root_widget, transition='out_scale')
142
143    @override
144    def on_popup_cancel(self) -> None:
145        bui.getsound('swish').play()
146        self._transition_out()
class ResourceTypeInfoWindow(bauiv1lib.popup.PopupWindow):
 17class ResourceTypeInfoWindow(PopupWindow):
 18    """Popup window providing info about resource types."""
 19
 20    def __init__(
 21        self,
 22        resource_type: Literal['tickets', 'tokens', 'trophies', 'xp'],
 23        origin_widget: bui.Widget,
 24    ):
 25        assert bui.app.classic is not None
 26        uiscale = bui.app.ui_v1.uiscale
 27        scale = (
 28            2.0
 29            if uiscale is bui.UIScale.SMALL
 30            else 1.3 if uiscale is bui.UIScale.MEDIUM else 0.7
 31        )
 32        self._transitioning_out = False
 33        self._width = 570
 34        self._height = 400
 35        self._get_tokens_button: bui.Widget | None = None
 36        bg_color = (0.5, 0.4, 0.6)
 37        super().__init__(
 38            size=(self._width, self._height),
 39            toolbar_visibility='inherit',
 40            scale=scale,
 41            bg_color=bg_color,
 42            position=origin_widget.get_screen_space_center(),
 43            edge_buffer_scale=4.0,
 44        )
 45        self._cancel_button = bui.buttonwidget(
 46            parent=self.root_widget,
 47            position=(40, self._height - 40),
 48            size=(50, 50),
 49            scale=0.7,
 50            label='',
 51            color=bg_color,
 52            on_activate_call=self._on_cancel_press,
 53            autoselect=True,
 54            icon=bui.gettexture('crossOut'),
 55            iconscale=1.2,
 56        )
 57
 58        yoffs = self._height - 145
 59
 60        max_rdesc_height = 160
 61
 62        if resource_type == 'tickets':
 63            yoffs -= 20
 64            rdesc = (
 65                'Tickets can be used to unlock characters,\n'
 66                'maps, minigames, and more in the store.\n'
 67                '\n'
 68                'Tickets can be found in chests won through\n'
 69                'campaigns, tournaments, and achievements.'
 70            )
 71            texname = 'tickets'
 72        elif resource_type == 'tokens':
 73            rdesc = (
 74                'Tokens are used to speed up chest unlocks\n'
 75                'and for other game and account features.\n'
 76                '\n'
 77                'You can win tokens in the game or buy them\n'
 78                'in packs. Or buy a Gold Pass for infinite\n'
 79                'tokens and never hear about them again.'
 80            )
 81            texname = 'coin'
 82            bwidth = 200
 83            bheight = 50
 84
 85            self._get_tokens_button = bui.buttonwidget(
 86                parent=self.root_widget,
 87                position=(
 88                    self._width * 0.5 - bwidth * 0.5,
 89                    yoffs - 15.0 - bheight - max_rdesc_height,
 90                ),
 91                color=bg_color,
 92                textcolor=(0.8, 0.8, 0.8),
 93                label=bui.Lstr(resource='tokens.getTokensText'),
 94                size=(bwidth, bheight),
 95                autoselect=True,
 96                on_activate_call=bui.WeakCall(self._on_get_tokens_press),
 97            )
 98
 99        elif resource_type == 'trophies':
100            rdesc = 'TODO: Will show trophies & league rankings.'
101            texname = 'crossOut'
102        elif resource_type == 'xp':
103            rdesc = 'TODO: Will describe xp/levels.'
104            texname = 'crossOut'
105        else:
106            assert_never(resource_type)
107
108        imgsize = 100.0
109        bui.imagewidget(
110            parent=self.root_widget,
111            position=(self._width * 0.5 - imgsize * 0.5, yoffs + 5.0),
112            size=(imgsize, imgsize),
113            texture=bui.gettexture(texname),
114        )
115
116        bui.textwidget(
117            parent=self.root_widget,
118            h_align='center',
119            v_align='top',
120            size=(0, 0),
121            maxwidth=self._width * 0.8,
122            max_height=max_rdesc_height,
123            position=(self._width * 0.5, yoffs - 5.0),
124            text=rdesc,
125            scale=0.8,
126        )
127
128    def _on_get_tokens_press(self) -> None:
129        from bauiv1lib.gettokens import show_get_tokens_window
130
131        self._transition_out()
132        show_get_tokens_window(
133            origin_widget=bui.existing(self._get_tokens_button)
134        )
135
136    def _on_cancel_press(self) -> None:
137        self._transition_out()
138
139    def _transition_out(self) -> None:
140        if not self._transitioning_out:
141            self._transitioning_out = True
142            bui.containerwidget(edit=self.root_widget, transition='out_scale')
143
144    @override
145    def on_popup_cancel(self) -> None:
146        bui.getsound('swish').play()
147        self._transition_out()

Popup window providing info about resource types.

ResourceTypeInfoWindow( resource_type: Literal['tickets', 'tokens', 'trophies', 'xp'], origin_widget: _bauiv1.Widget)
 20    def __init__(
 21        self,
 22        resource_type: Literal['tickets', 'tokens', 'trophies', 'xp'],
 23        origin_widget: bui.Widget,
 24    ):
 25        assert bui.app.classic is not None
 26        uiscale = bui.app.ui_v1.uiscale
 27        scale = (
 28            2.0
 29            if uiscale is bui.UIScale.SMALL
 30            else 1.3 if uiscale is bui.UIScale.MEDIUM else 0.7
 31        )
 32        self._transitioning_out = False
 33        self._width = 570
 34        self._height = 400
 35        self._get_tokens_button: bui.Widget | None = None
 36        bg_color = (0.5, 0.4, 0.6)
 37        super().__init__(
 38            size=(self._width, self._height),
 39            toolbar_visibility='inherit',
 40            scale=scale,
 41            bg_color=bg_color,
 42            position=origin_widget.get_screen_space_center(),
 43            edge_buffer_scale=4.0,
 44        )
 45        self._cancel_button = bui.buttonwidget(
 46            parent=self.root_widget,
 47            position=(40, self._height - 40),
 48            size=(50, 50),
 49            scale=0.7,
 50            label='',
 51            color=bg_color,
 52            on_activate_call=self._on_cancel_press,
 53            autoselect=True,
 54            icon=bui.gettexture('crossOut'),
 55            iconscale=1.2,
 56        )
 57
 58        yoffs = self._height - 145
 59
 60        max_rdesc_height = 160
 61
 62        if resource_type == 'tickets':
 63            yoffs -= 20
 64            rdesc = (
 65                'Tickets can be used to unlock characters,\n'
 66                'maps, minigames, and more in the store.\n'
 67                '\n'
 68                'Tickets can be found in chests won through\n'
 69                'campaigns, tournaments, and achievements.'
 70            )
 71            texname = 'tickets'
 72        elif resource_type == 'tokens':
 73            rdesc = (
 74                'Tokens are used to speed up chest unlocks\n'
 75                'and for other game and account features.\n'
 76                '\n'
 77                'You can win tokens in the game or buy them\n'
 78                'in packs. Or buy a Gold Pass for infinite\n'
 79                'tokens and never hear about them again.'
 80            )
 81            texname = 'coin'
 82            bwidth = 200
 83            bheight = 50
 84
 85            self._get_tokens_button = bui.buttonwidget(
 86                parent=self.root_widget,
 87                position=(
 88                    self._width * 0.5 - bwidth * 0.5,
 89                    yoffs - 15.0 - bheight - max_rdesc_height,
 90                ),
 91                color=bg_color,
 92                textcolor=(0.8, 0.8, 0.8),
 93                label=bui.Lstr(resource='tokens.getTokensText'),
 94                size=(bwidth, bheight),
 95                autoselect=True,
 96                on_activate_call=bui.WeakCall(self._on_get_tokens_press),
 97            )
 98
 99        elif resource_type == 'trophies':
100            rdesc = 'TODO: Will show trophies & league rankings.'
101            texname = 'crossOut'
102        elif resource_type == 'xp':
103            rdesc = 'TODO: Will describe xp/levels.'
104            texname = 'crossOut'
105        else:
106            assert_never(resource_type)
107
108        imgsize = 100.0
109        bui.imagewidget(
110            parent=self.root_widget,
111            position=(self._width * 0.5 - imgsize * 0.5, yoffs + 5.0),
112            size=(imgsize, imgsize),
113            texture=bui.gettexture(texname),
114        )
115
116        bui.textwidget(
117            parent=self.root_widget,
118            h_align='center',
119            v_align='top',
120            size=(0, 0),
121            maxwidth=self._width * 0.8,
122            max_height=max_rdesc_height,
123            position=(self._width * 0.5, yoffs - 5.0),
124            text=rdesc,
125            scale=0.8,
126        )
@override
def on_popup_cancel(self) -> None:
144    @override
145    def on_popup_cancel(self) -> None:
146        bui.getsound('swish').play()
147        self._transition_out()

Called when the popup is canceled.

Cancels can occur due to clicking outside the window, hitting escape, etc.