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.5 if uiscale is bui.UIScale.MEDIUM else 1.0
30        )
31        self._transitioning_out = False
32        self._width = 570
33        self._height = 350
34        bg_color = (0.5, 0.4, 0.6)
35        super().__init__(
36            size=(self._width, self._height),
37            toolbar_visibility='inherit',
38            scale=scale,
39            bg_color=bg_color,
40            position=origin_widget.get_screen_space_center(),
41            edge_buffer_scale=4.0,
42        )
43        self._cancel_button = bui.buttonwidget(
44            parent=self.root_widget,
45            position=(40, self._height - 40),
46            size=(50, 50),
47            scale=0.7,
48            label='',
49            color=bg_color,
50            on_activate_call=self._on_cancel_press,
51            autoselect=True,
52            icon=bui.gettexture('crossOut'),
53            iconscale=1.2,
54        )
55
56        if resource_type == 'tickets':
57            rdesc = 'Will describe tickets.'
58        elif resource_type == 'tokens':
59            rdesc = 'Will describe tokens.'
60        elif resource_type == 'trophies':
61            rdesc = 'Will show trophies & league rankings.'
62        elif resource_type == 'xp':
63            rdesc = 'Will describe xp/levels.'
64        else:
65            assert_never(resource_type)
66
67        bui.textwidget(
68            parent=self.root_widget,
69            h_align='center',
70            v_align='center',
71            size=(0, 0),
72            position=(self._width * 0.5, self._height * 0.5),
73            text=(f'UNDER CONSTRUCTION.\n({rdesc})'),
74        )
75
76    def _on_cancel_press(self) -> None:
77        self._transition_out()
78
79    def _transition_out(self) -> None:
80        if not self._transitioning_out:
81            self._transitioning_out = True
82            bui.containerwidget(edit=self.root_widget, transition='out_scale')
83
84    @override
85    def on_popup_cancel(self) -> None:
86        bui.getsound('swish').play()
87        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.5 if uiscale is bui.UIScale.MEDIUM else 1.0
31        )
32        self._transitioning_out = False
33        self._width = 570
34        self._height = 350
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        if resource_type == 'tickets':
58            rdesc = 'Will describe tickets.'
59        elif resource_type == 'tokens':
60            rdesc = 'Will describe tokens.'
61        elif resource_type == 'trophies':
62            rdesc = 'Will show trophies & league rankings.'
63        elif resource_type == 'xp':
64            rdesc = 'Will describe xp/levels.'
65        else:
66            assert_never(resource_type)
67
68        bui.textwidget(
69            parent=self.root_widget,
70            h_align='center',
71            v_align='center',
72            size=(0, 0),
73            position=(self._width * 0.5, self._height * 0.5),
74            text=(f'UNDER CONSTRUCTION.\n({rdesc})'),
75        )
76
77    def _on_cancel_press(self) -> None:
78        self._transition_out()
79
80    def _transition_out(self) -> None:
81        if not self._transitioning_out:
82            self._transitioning_out = True
83            bui.containerwidget(edit=self.root_widget, transition='out_scale')
84
85    @override
86    def on_popup_cancel(self) -> None:
87        bui.getsound('swish').play()
88        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.5 if uiscale is bui.UIScale.MEDIUM else 1.0
31        )
32        self._transitioning_out = False
33        self._width = 570
34        self._height = 350
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        if resource_type == 'tickets':
58            rdesc = 'Will describe tickets.'
59        elif resource_type == 'tokens':
60            rdesc = 'Will describe tokens.'
61        elif resource_type == 'trophies':
62            rdesc = 'Will show trophies & league rankings.'
63        elif resource_type == 'xp':
64            rdesc = 'Will describe xp/levels.'
65        else:
66            assert_never(resource_type)
67
68        bui.textwidget(
69            parent=self.root_widget,
70            h_align='center',
71            v_align='center',
72            size=(0, 0),
73            position=(self._width * 0.5, self._height * 0.5),
74            text=(f'UNDER CONSTRUCTION.\n({rdesc})'),
75        )
@override
def on_popup_cancel(self) -> None:
85    @override
86    def on_popup_cancel(self) -> None:
87        bui.getsound('swish').play()
88        self._transition_out()

Called when the popup is canceled.

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