bauiv1lib.feedback

UI functionality related to users rating the game.

 1# Released under the MIT License. See LICENSE for details.
 2#
 3"""UI functionality related to users rating the game."""
 4
 5from __future__ import annotations
 6
 7import bauiv1 as bui
 8
 9
10def ask_for_rating() -> bui.Widget | None:
11    """(internal)"""
12    app = bui.app
13    assert app.classic is not None
14    platform = app.classic.platform
15    subplatform = app.classic.subplatform
16
17    # FIXME: should whitelist platforms we *do* want this for.
18    if bui.app.env.test:
19        return None
20    if not (
21        platform == 'mac'
22        or (platform == 'android' and subplatform in ['google', 'cardboard'])
23    ):
24        return None
25    width = 700
26    height = 400
27    spacing = 40
28    assert bui.app.classic is not None
29    uiscale = bui.app.ui_v1.uiscale
30    dlg = bui.containerwidget(
31        size=(width, height),
32        transition='in_right',
33        scale=(
34            1.6
35            if uiscale is bui.UIScale.SMALL
36            else 1.35 if uiscale is bui.UIScale.MEDIUM else 1.0
37        ),
38    )
39    v = height - 50
40    v -= spacing
41    v -= 140
42    bui.imagewidget(
43        parent=dlg,
44        position=(width / 2 - 100, v + 10),
45        size=(200, 200),
46        texture=bui.gettexture('cuteSpaz'),
47    )
48    bui.textwidget(
49        parent=dlg,
50        position=(15, v - 55),
51        size=(width - 30, 30),
52        color=bui.app.ui_v1.infotextcolor,
53        text=bui.Lstr(
54            resource='pleaseRateText',
55            subs=[('${APP_NAME}', bui.Lstr(resource='titleText'))],
56        ),
57        maxwidth=width * 0.95,
58        max_height=130,
59        scale=0.85,
60        h_align='center',
61        v_align='center',
62    )
63
64    def do_rating() -> None:
65        # This is not currently in use anywhere.
66        bui.screenmessage(bui.Lstr(resource='error'))
67        # bui.open_url(url)
68        bui.containerwidget(edit=dlg, transition='out_left')
69
70    bui.buttonwidget(
71        parent=dlg,
72        position=(60, 20),
73        size=(200, 60),
74        label=bui.Lstr(resource='wellSureText'),
75        autoselect=True,
76        on_activate_call=do_rating,
77    )
78
79    def close() -> None:
80        bui.containerwidget(edit=dlg, transition='out_left')
81
82    btn = bui.buttonwidget(
83        parent=dlg,
84        position=(width - 270, 20),
85        size=(200, 60),
86        label=bui.Lstr(resource='noThanksText'),
87        autoselect=True,
88        on_activate_call=close,
89    )
90    bui.containerwidget(edit=dlg, cancel_button=btn, selected_child=btn)
91    return dlg