bastd.ui.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
 7import ba
 8from bastd.ui import popup
 9
10
11class ResourceTypeInfoWindow(popup.PopupWindow):
12    """Popup window providing info about resource types."""
13
14    def __init__(self, origin_widget: ba.Widget):
15        uiscale = ba.app.ui.uiscale
16        scale = (2.3 if uiscale is ba.UIScale.SMALL else
17                 1.65 if uiscale is ba.UIScale.MEDIUM else 1.23)
18        self._transitioning_out = False
19        self._width = 570
20        self._height = 350
21        bg_color = (0.5, 0.4, 0.6)
22        popup.PopupWindow.__init__(
23            self,
24            size=(self._width, self._height),
25            toolbar_visibility='inherit',
26            scale=scale,
27            bg_color=bg_color,
28            position=origin_widget.get_screen_space_center())
29        self._cancel_button = ba.buttonwidget(
30            parent=self.root_widget,
31            position=(50, self._height - 30),
32            size=(50, 50),
33            scale=0.5,
34            label='',
35            color=bg_color,
36            on_activate_call=self._on_cancel_press,
37            autoselect=True,
38            icon=ba.gettexture('crossOut'),
39            iconscale=1.2)
40
41    def _on_cancel_press(self) -> None:
42        self._transition_out()
43
44    def _transition_out(self) -> None:
45        if not self._transitioning_out:
46            self._transitioning_out = True
47            ba.containerwidget(edit=self.root_widget, transition='out_scale')
48
49    def on_popup_cancel(self) -> None:
50        ba.playsound(ba.getsound('swish'))
51        self._transition_out()
class ResourceTypeInfoWindow(bastd.ui.popup.PopupWindow):
12class ResourceTypeInfoWindow(popup.PopupWindow):
13    """Popup window providing info about resource types."""
14
15    def __init__(self, origin_widget: ba.Widget):
16        uiscale = ba.app.ui.uiscale
17        scale = (2.3 if uiscale is ba.UIScale.SMALL else
18                 1.65 if uiscale is ba.UIScale.MEDIUM else 1.23)
19        self._transitioning_out = False
20        self._width = 570
21        self._height = 350
22        bg_color = (0.5, 0.4, 0.6)
23        popup.PopupWindow.__init__(
24            self,
25            size=(self._width, self._height),
26            toolbar_visibility='inherit',
27            scale=scale,
28            bg_color=bg_color,
29            position=origin_widget.get_screen_space_center())
30        self._cancel_button = ba.buttonwidget(
31            parent=self.root_widget,
32            position=(50, self._height - 30),
33            size=(50, 50),
34            scale=0.5,
35            label='',
36            color=bg_color,
37            on_activate_call=self._on_cancel_press,
38            autoselect=True,
39            icon=ba.gettexture('crossOut'),
40            iconscale=1.2)
41
42    def _on_cancel_press(self) -> None:
43        self._transition_out()
44
45    def _transition_out(self) -> None:
46        if not self._transitioning_out:
47            self._transitioning_out = True
48            ba.containerwidget(edit=self.root_widget, transition='out_scale')
49
50    def on_popup_cancel(self) -> None:
51        ba.playsound(ba.getsound('swish'))
52        self._transition_out()

Popup window providing info about resource types.

ResourceTypeInfoWindow(origin_widget: _ba.Widget)
15    def __init__(self, origin_widget: ba.Widget):
16        uiscale = ba.app.ui.uiscale
17        scale = (2.3 if uiscale is ba.UIScale.SMALL else
18                 1.65 if uiscale is ba.UIScale.MEDIUM else 1.23)
19        self._transitioning_out = False
20        self._width = 570
21        self._height = 350
22        bg_color = (0.5, 0.4, 0.6)
23        popup.PopupWindow.__init__(
24            self,
25            size=(self._width, self._height),
26            toolbar_visibility='inherit',
27            scale=scale,
28            bg_color=bg_color,
29            position=origin_widget.get_screen_space_center())
30        self._cancel_button = ba.buttonwidget(
31            parent=self.root_widget,
32            position=(50, self._height - 30),
33            size=(50, 50),
34            scale=0.5,
35            label='',
36            color=bg_color,
37            on_activate_call=self._on_cancel_press,
38            autoselect=True,
39            icon=ba.gettexture('crossOut'),
40            iconscale=1.2)
def on_popup_cancel(self) -> None:
50    def on_popup_cancel(self) -> None:
51        ba.playsound(ba.getsound('swish'))
52        self._transition_out()

Called when the popup is canceled.

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