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
 37            if uiscale is bui.UIScale.MEDIUM
 38            else 1.0
 39        ),
 40    )
 41    v = height - 50
 42    v -= spacing
 43    v -= 140
 44    bui.imagewidget(
 45        parent=dlg,
 46        position=(width / 2 - 100, v + 10),
 47        size=(200, 200),
 48        texture=bui.gettexture('cuteSpaz'),
 49    )
 50    bui.textwidget(
 51        parent=dlg,
 52        position=(15, v - 55),
 53        size=(width - 30, 30),
 54        color=bui.app.ui_v1.infotextcolor,
 55        text=bui.Lstr(
 56            resource='pleaseRateText',
 57            subs=[('${APP_NAME}', bui.Lstr(resource='titleText'))],
 58        ),
 59        maxwidth=width * 0.95,
 60        max_height=130,
 61        scale=0.85,
 62        h_align='center',
 63        v_align='center',
 64    )
 65
 66    def do_rating() -> None:
 67        if platform == 'android':
 68            appname = bui.appname()
 69            if subplatform == 'google':
 70                url = f'market://details?id=net.froemling.{appname}'
 71            else:
 72                url = f'market://details?id=net.froemling.{appname}cb'
 73        else:
 74            url = 'macappstore://itunes.apple.com/app/id416482767?ls=1&mt=12'
 75
 76        bui.open_url(url)
 77        bui.containerwidget(edit=dlg, transition='out_left')
 78
 79    bui.buttonwidget(
 80        parent=dlg,
 81        position=(60, 20),
 82        size=(200, 60),
 83        label=bui.Lstr(resource='wellSureText'),
 84        autoselect=True,
 85        on_activate_call=do_rating,
 86    )
 87
 88    def close() -> None:
 89        bui.containerwidget(edit=dlg, transition='out_left')
 90
 91    btn = bui.buttonwidget(
 92        parent=dlg,
 93        position=(width - 270, 20),
 94        size=(200, 60),
 95        label=bui.Lstr(resource='noThanksText'),
 96        autoselect=True,
 97        on_activate_call=close,
 98    )
 99    bui.containerwidget(edit=dlg, cancel_button=btn, selected_child=btn)
100    return dlg