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.4 if uiscale is bui.UIScale.MEDIUM else 0.8
 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        rdesc: bui.Lstr | str
 62
 63        if resource_type == 'tickets':
 64            yoffs -= 20
 65            rdesc = bui.Lstr(resource='ticketsDescriptionText')
 66            texname = 'tickets'
 67        elif resource_type == 'tokens':
 68            rdesc = bui.Lstr(resource='tokens.tokensDescriptionText')
 69            texname = 'coin'
 70            bwidth = 200
 71            bheight = 50
 72
 73            # Show 'Get Tokens' button if we don't have a gold pass
 74            # (in case a user doesn't notice the '+' button or we have
 75            # it disabled for some reason).
 76            if not bui.app.classic.gold_pass:
 77                self._get_tokens_button = bui.buttonwidget(
 78                    parent=self.root_widget,
 79                    position=(
 80                        self._width * 0.5 - bwidth * 0.5,
 81                        yoffs - 15.0 - bheight - max_rdesc_height,
 82                    ),
 83                    color=bg_color,
 84                    textcolor=(0.8, 0.8, 0.8),
 85                    label=bui.Lstr(resource='tokens.getTokensText'),
 86                    size=(bwidth, bheight),
 87                    autoselect=True,
 88                    on_activate_call=bui.WeakCall(self._on_get_tokens_press),
 89                )
 90
 91        elif resource_type == 'trophies':
 92            rdesc = 'TODO: Will show trophies & league rankings.'
 93            texname = 'crossOut'
 94        elif resource_type == 'xp':
 95            rdesc = 'TODO: Will describe xp/levels.'
 96            texname = 'crossOut'
 97        else:
 98            assert_never(resource_type)
 99
100        imgsize = 100.0
101        bui.imagewidget(
102            parent=self.root_widget,
103            position=(self._width * 0.5 - imgsize * 0.5, yoffs + 5.0),
104            size=(imgsize, imgsize),
105            texture=bui.gettexture(texname),
106        )
107
108        bui.textwidget(
109            parent=self.root_widget,
110            h_align='center',
111            v_align='top',
112            size=(0, 0),
113            maxwidth=self._width * 0.8,
114            max_height=max_rdesc_height,
115            position=(self._width * 0.5, yoffs - 5.0),
116            text=rdesc,
117            scale=0.8,
118        )
119
120    def _on_get_tokens_press(self) -> None:
121        from bauiv1lib.gettokens import show_get_tokens_window
122
123        self._transition_out()
124        show_get_tokens_window(
125            origin_widget=bui.existing(self._get_tokens_button)
126        )
127
128    def _on_cancel_press(self) -> None:
129        self._transition_out()
130
131    def _transition_out(self) -> None:
132        if not self._transitioning_out:
133            self._transitioning_out = True
134            bui.containerwidget(edit=self.root_widget, transition='out_scale')
135
136    @override
137    def on_popup_cancel(self) -> None:
138        bui.getsound('swish').play()
139        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.4 if uiscale is bui.UIScale.MEDIUM else 0.8
 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        rdesc: bui.Lstr | str
 63
 64        if resource_type == 'tickets':
 65            yoffs -= 20
 66            rdesc = bui.Lstr(resource='ticketsDescriptionText')
 67            texname = 'tickets'
 68        elif resource_type == 'tokens':
 69            rdesc = bui.Lstr(resource='tokens.tokensDescriptionText')
 70            texname = 'coin'
 71            bwidth = 200
 72            bheight = 50
 73
 74            # Show 'Get Tokens' button if we don't have a gold pass
 75            # (in case a user doesn't notice the '+' button or we have
 76            # it disabled for some reason).
 77            if not bui.app.classic.gold_pass:
 78                self._get_tokens_button = bui.buttonwidget(
 79                    parent=self.root_widget,
 80                    position=(
 81                        self._width * 0.5 - bwidth * 0.5,
 82                        yoffs - 15.0 - bheight - max_rdesc_height,
 83                    ),
 84                    color=bg_color,
 85                    textcolor=(0.8, 0.8, 0.8),
 86                    label=bui.Lstr(resource='tokens.getTokensText'),
 87                    size=(bwidth, bheight),
 88                    autoselect=True,
 89                    on_activate_call=bui.WeakCall(self._on_get_tokens_press),
 90                )
 91
 92        elif resource_type == 'trophies':
 93            rdesc = 'TODO: Will show trophies & league rankings.'
 94            texname = 'crossOut'
 95        elif resource_type == 'xp':
 96            rdesc = 'TODO: Will describe xp/levels.'
 97            texname = 'crossOut'
 98        else:
 99            assert_never(resource_type)
100
101        imgsize = 100.0
102        bui.imagewidget(
103            parent=self.root_widget,
104            position=(self._width * 0.5 - imgsize * 0.5, yoffs + 5.0),
105            size=(imgsize, imgsize),
106            texture=bui.gettexture(texname),
107        )
108
109        bui.textwidget(
110            parent=self.root_widget,
111            h_align='center',
112            v_align='top',
113            size=(0, 0),
114            maxwidth=self._width * 0.8,
115            max_height=max_rdesc_height,
116            position=(self._width * 0.5, yoffs - 5.0),
117            text=rdesc,
118            scale=0.8,
119        )
120
121    def _on_get_tokens_press(self) -> None:
122        from bauiv1lib.gettokens import show_get_tokens_window
123
124        self._transition_out()
125        show_get_tokens_window(
126            origin_widget=bui.existing(self._get_tokens_button)
127        )
128
129    def _on_cancel_press(self) -> None:
130        self._transition_out()
131
132    def _transition_out(self) -> None:
133        if not self._transitioning_out:
134            self._transitioning_out = True
135            bui.containerwidget(edit=self.root_widget, transition='out_scale')
136
137    @override
138    def on_popup_cancel(self) -> None:
139        bui.getsound('swish').play()
140        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.4 if uiscale is bui.UIScale.MEDIUM else 0.8
 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        rdesc: bui.Lstr | str
 63
 64        if resource_type == 'tickets':
 65            yoffs -= 20
 66            rdesc = bui.Lstr(resource='ticketsDescriptionText')
 67            texname = 'tickets'
 68        elif resource_type == 'tokens':
 69            rdesc = bui.Lstr(resource='tokens.tokensDescriptionText')
 70            texname = 'coin'
 71            bwidth = 200
 72            bheight = 50
 73
 74            # Show 'Get Tokens' button if we don't have a gold pass
 75            # (in case a user doesn't notice the '+' button or we have
 76            # it disabled for some reason).
 77            if not bui.app.classic.gold_pass:
 78                self._get_tokens_button = bui.buttonwidget(
 79                    parent=self.root_widget,
 80                    position=(
 81                        self._width * 0.5 - bwidth * 0.5,
 82                        yoffs - 15.0 - bheight - max_rdesc_height,
 83                    ),
 84                    color=bg_color,
 85                    textcolor=(0.8, 0.8, 0.8),
 86                    label=bui.Lstr(resource='tokens.getTokensText'),
 87                    size=(bwidth, bheight),
 88                    autoselect=True,
 89                    on_activate_call=bui.WeakCall(self._on_get_tokens_press),
 90                )
 91
 92        elif resource_type == 'trophies':
 93            rdesc = 'TODO: Will show trophies & league rankings.'
 94            texname = 'crossOut'
 95        elif resource_type == 'xp':
 96            rdesc = 'TODO: Will describe xp/levels.'
 97            texname = 'crossOut'
 98        else:
 99            assert_never(resource_type)
100
101        imgsize = 100.0
102        bui.imagewidget(
103            parent=self.root_widget,
104            position=(self._width * 0.5 - imgsize * 0.5, yoffs + 5.0),
105            size=(imgsize, imgsize),
106            texture=bui.gettexture(texname),
107        )
108
109        bui.textwidget(
110            parent=self.root_widget,
111            h_align='center',
112            v_align='top',
113            size=(0, 0),
114            maxwidth=self._width * 0.8,
115            max_height=max_rdesc_height,
116            position=(self._width * 0.5, yoffs - 5.0),
117            text=rdesc,
118            scale=0.8,
119        )
@override
def on_popup_cancel(self) -> None:
137    @override
138    def on_popup_cancel(self) -> None:
139        bui.getsound('swish').play()
140        self._transition_out()

Called when the popup is canceled.

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