bastd.ui.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
  7from typing import TYPE_CHECKING
  8
  9import ba
 10import ba.internal
 11
 12if TYPE_CHECKING:
 13    pass
 14
 15
 16def ask_for_rating() -> ba.Widget | None:
 17    """(internal)"""
 18    app = ba.app
 19    platform = app.platform
 20    subplatform = app.subplatform
 21
 22    # FIXME: should whitelist platforms we *do* want this for.
 23    if ba.app.test_build:
 24        return None
 25    if not (
 26        platform == 'mac'
 27        or (platform == 'android' and subplatform in ['google', 'cardboard'])
 28    ):
 29        return None
 30    width = 700
 31    height = 400
 32    spacing = 40
 33    uiscale = ba.app.ui.uiscale
 34    dlg = ba.containerwidget(
 35        size=(width, height),
 36        transition='in_right',
 37        scale=(
 38            1.6
 39            if uiscale is ba.UIScale.SMALL
 40            else 1.35
 41            if uiscale is ba.UIScale.MEDIUM
 42            else 1.0
 43        ),
 44    )
 45    v = height - 50
 46    v -= spacing
 47    v -= 140
 48    ba.imagewidget(
 49        parent=dlg,
 50        position=(width / 2 - 100, v + 10),
 51        size=(200, 200),
 52        texture=ba.gettexture('cuteSpaz'),
 53    )
 54    ba.textwidget(
 55        parent=dlg,
 56        position=(15, v - 55),
 57        size=(width - 30, 30),
 58        color=ba.app.ui.infotextcolor,
 59        text=ba.Lstr(
 60            resource='pleaseRateText',
 61            subs=[('${APP_NAME}', ba.Lstr(resource='titleText'))],
 62        ),
 63        maxwidth=width * 0.95,
 64        max_height=130,
 65        scale=0.85,
 66        h_align='center',
 67        v_align='center',
 68    )
 69
 70    def do_rating() -> None:
 71        if platform == 'android':
 72            appname = ba.internal.appname()
 73            if subplatform == 'google':
 74                url = f'market://details?id=net.froemling.{appname}'
 75            else:
 76                url = f'market://details?id=net.froemling.{appname}cb'
 77        else:
 78            url = 'macappstore://itunes.apple.com/app/id416482767?ls=1&mt=12'
 79
 80        ba.open_url(url)
 81        ba.containerwidget(edit=dlg, transition='out_left')
 82
 83    ba.buttonwidget(
 84        parent=dlg,
 85        position=(60, 20),
 86        size=(200, 60),
 87        label=ba.Lstr(resource='wellSureText'),
 88        autoselect=True,
 89        on_activate_call=do_rating,
 90    )
 91
 92    def close() -> None:
 93        ba.containerwidget(edit=dlg, transition='out_left')
 94
 95    btn = ba.buttonwidget(
 96        parent=dlg,
 97        position=(width - 270, 20),
 98        size=(200, 60),
 99        label=ba.Lstr(resource='noThanksText'),
100        autoselect=True,
101        on_activate_call=close,
102    )
103    ba.containerwidget(edit=dlg, cancel_button=btn, selected_child=btn)
104    return dlg