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 if platform == 'android': 66 appname = bui.appname() 67 if subplatform == 'google': 68 url = f'market://details?id=net.froemling.{appname}' 69 else: 70 url = f'market://details?id=net.froemling.{appname}cb' 71 else: 72 url = 'macappstore://itunes.apple.com/app/id416482767?ls=1&mt=12' 73 74 bui.open_url(url) 75 bui.containerwidget(edit=dlg, transition='out_left') 76 77 bui.buttonwidget( 78 parent=dlg, 79 position=(60, 20), 80 size=(200, 60), 81 label=bui.Lstr(resource='wellSureText'), 82 autoselect=True, 83 on_activate_call=do_rating, 84 ) 85 86 def close() -> None: 87 bui.containerwidget(edit=dlg, transition='out_left') 88 89 btn = bui.buttonwidget( 90 parent=dlg, 91 position=(width - 270, 20), 92 size=(200, 60), 93 label=bui.Lstr(resource='noThanksText'), 94 autoselect=True, 95 on_activate_call=close, 96 ) 97 bui.containerwidget(edit=dlg, cancel_button=btn, selected_child=btn) 98 return dlg