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