bastd.ui.coop.level

Bits of utility functionality related to co-op levels.

 1# Released under the MIT License. See LICENSE for details.
 2#
 3"""Bits of utility functionality related to co-op levels."""
 4
 5from __future__ import annotations
 6
 7import ba
 8
 9
10class CoopLevelLockedWindow(ba.Window):
11    """Window showing that a level is locked."""
12
13    def __init__(self, name: ba.Lstr, dep_name: ba.Lstr):
14        width = 550.0
15        height = 250.0
16        lock_tex = ba.gettexture('lock')
17        uiscale = ba.app.ui.uiscale
18        super().__init__(
19            root_widget=ba.containerwidget(
20                size=(width, height),
21                transition='in_right',
22                scale=(
23                    1.7
24                    if uiscale is ba.UIScale.SMALL
25                    else 1.3
26                    if uiscale is ba.UIScale.MEDIUM
27                    else 1.0
28                ),
29            )
30        )
31        ba.textwidget(
32            parent=self._root_widget,
33            position=(150 - 20, height * 0.63),
34            size=(0, 0),
35            h_align='left',
36            v_align='center',
37            text=ba.Lstr(
38                resource='levelIsLockedText', subs=[('${LEVEL}', name)]
39            ),
40            maxwidth=400,
41            color=(1, 0.8, 0.3, 1),
42            scale=1.1,
43        )
44        ba.textwidget(
45            parent=self._root_widget,
46            position=(150 - 20, height * 0.48),
47            size=(0, 0),
48            h_align='left',
49            v_align='center',
50            text=ba.Lstr(
51                resource='levelMustBeCompletedFirstText',
52                subs=[('${LEVEL}', dep_name)],
53            ),
54            maxwidth=400,
55            color=ba.app.ui.infotextcolor,
56            scale=0.8,
57        )
58        ba.imagewidget(
59            parent=self._root_widget,
60            position=(56 - 20, height * 0.39),
61            size=(80, 80),
62            texture=lock_tex,
63            opacity=1.0,
64        )
65        btn = ba.buttonwidget(
66            parent=self._root_widget,
67            position=((width - 140) / 2, 30),
68            size=(140, 50),
69            label=ba.Lstr(resource='okText'),
70            on_activate_call=self._ok,
71        )
72        ba.containerwidget(
73            edit=self._root_widget, selected_child=btn, start_button=btn
74        )
75        ba.playsound(ba.getsound('error'))
76
77    def _ok(self) -> None:
78        ba.containerwidget(edit=self._root_widget, transition='out_left')
class CoopLevelLockedWindow(ba.ui.Window):
11class CoopLevelLockedWindow(ba.Window):
12    """Window showing that a level is locked."""
13
14    def __init__(self, name: ba.Lstr, dep_name: ba.Lstr):
15        width = 550.0
16        height = 250.0
17        lock_tex = ba.gettexture('lock')
18        uiscale = ba.app.ui.uiscale
19        super().__init__(
20            root_widget=ba.containerwidget(
21                size=(width, height),
22                transition='in_right',
23                scale=(
24                    1.7
25                    if uiscale is ba.UIScale.SMALL
26                    else 1.3
27                    if uiscale is ba.UIScale.MEDIUM
28                    else 1.0
29                ),
30            )
31        )
32        ba.textwidget(
33            parent=self._root_widget,
34            position=(150 - 20, height * 0.63),
35            size=(0, 0),
36            h_align='left',
37            v_align='center',
38            text=ba.Lstr(
39                resource='levelIsLockedText', subs=[('${LEVEL}', name)]
40            ),
41            maxwidth=400,
42            color=(1, 0.8, 0.3, 1),
43            scale=1.1,
44        )
45        ba.textwidget(
46            parent=self._root_widget,
47            position=(150 - 20, height * 0.48),
48            size=(0, 0),
49            h_align='left',
50            v_align='center',
51            text=ba.Lstr(
52                resource='levelMustBeCompletedFirstText',
53                subs=[('${LEVEL}', dep_name)],
54            ),
55            maxwidth=400,
56            color=ba.app.ui.infotextcolor,
57            scale=0.8,
58        )
59        ba.imagewidget(
60            parent=self._root_widget,
61            position=(56 - 20, height * 0.39),
62            size=(80, 80),
63            texture=lock_tex,
64            opacity=1.0,
65        )
66        btn = ba.buttonwidget(
67            parent=self._root_widget,
68            position=((width - 140) / 2, 30),
69            size=(140, 50),
70            label=ba.Lstr(resource='okText'),
71            on_activate_call=self._ok,
72        )
73        ba.containerwidget(
74            edit=self._root_widget, selected_child=btn, start_button=btn
75        )
76        ba.playsound(ba.getsound('error'))
77
78    def _ok(self) -> None:
79        ba.containerwidget(edit=self._root_widget, transition='out_left')

Window showing that a level is locked.

CoopLevelLockedWindow(name: ba._language.Lstr, dep_name: ba._language.Lstr)
14    def __init__(self, name: ba.Lstr, dep_name: ba.Lstr):
15        width = 550.0
16        height = 250.0
17        lock_tex = ba.gettexture('lock')
18        uiscale = ba.app.ui.uiscale
19        super().__init__(
20            root_widget=ba.containerwidget(
21                size=(width, height),
22                transition='in_right',
23                scale=(
24                    1.7
25                    if uiscale is ba.UIScale.SMALL
26                    else 1.3
27                    if uiscale is ba.UIScale.MEDIUM
28                    else 1.0
29                ),
30            )
31        )
32        ba.textwidget(
33            parent=self._root_widget,
34            position=(150 - 20, height * 0.63),
35            size=(0, 0),
36            h_align='left',
37            v_align='center',
38            text=ba.Lstr(
39                resource='levelIsLockedText', subs=[('${LEVEL}', name)]
40            ),
41            maxwidth=400,
42            color=(1, 0.8, 0.3, 1),
43            scale=1.1,
44        )
45        ba.textwidget(
46            parent=self._root_widget,
47            position=(150 - 20, height * 0.48),
48            size=(0, 0),
49            h_align='left',
50            v_align='center',
51            text=ba.Lstr(
52                resource='levelMustBeCompletedFirstText',
53                subs=[('${LEVEL}', dep_name)],
54            ),
55            maxwidth=400,
56            color=ba.app.ui.infotextcolor,
57            scale=0.8,
58        )
59        ba.imagewidget(
60            parent=self._root_widget,
61            position=(56 - 20, height * 0.39),
62            size=(80, 80),
63            texture=lock_tex,
64            opacity=1.0,
65        )
66        btn = ba.buttonwidget(
67            parent=self._root_widget,
68            position=((width - 140) / 2, 30),
69            size=(140, 50),
70            label=ba.Lstr(resource='okText'),
71            on_activate_call=self._ok,
72        )
73        ba.containerwidget(
74            edit=self._root_widget, selected_child=btn, start_button=btn
75        )
76        ba.playsound(ba.getsound('error'))
Inherited Members
ba.ui.Window
get_root_widget