Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/UI/IAPScreen.cpp
3185 views
1
// NOTE: This currently only used on iOS, to present the availablility of getting PPSSPP Gold through IAP.
2
3
#include "UI/IAPScreen.h"
4
#include "UI/OnScreenDisplay.h"
5
#include "UI/MiscScreens.h"
6
#include "Common/System/System.h"
7
#include "Common/Data/Text/I18n.h"
8
#include "Common/System/OSD.h"
9
10
void IAPScreen::CreateViews() {
11
using namespace UI;
12
13
auto di = GetI18NCategory(I18NCat::DIALOG);
14
auto mm = GetI18NCategory(I18NCat::MAINMENU);
15
16
const bool vertical = UseVerticalLayout();
17
18
root_ = new LinearLayout(vertical ? ORIENT_VERTICAL : ORIENT_HORIZONTAL, new LayoutParams(FILL_PARENT, FILL_PARENT));
19
20
const bool bought = System_GetPropertyBool(SYSPROP_APP_GOLD);
21
22
// TODO: Support vertical layout!
23
AnchorLayout *leftColumnContainer = new AnchorLayout(new LinearLayoutParams(1.0f, UI::Gravity::G_HCENTER));
24
25
LinearLayout *leftColumnItems = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(600, WRAP_CONTENT, NONE, 105, NONE, 15));
26
leftColumnContainer->Add(leftColumnItems);
27
root_->Add(leftColumnContainer);
28
29
ViewGroup *appTitle = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT));
30
appTitle->Add(new ShinyIcon(ImageID("I_ICONGOLD"), new LinearLayoutParams(64, 64)));
31
appTitle->Add(new TextView("PPSSPP Gold", new LinearLayoutParams(1.0f, G_VCENTER)));
32
33
leftColumnItems->Add(appTitle);
34
if (!bought) {
35
leftColumnItems->Add(new Spacer(20.0f));
36
leftColumnItems->Add(new TextView(di->T("GoldOverview1", "Buy PPSSPP Gold to support development!")))->SetAlign(FLAG_WRAP_TEXT);
37
leftColumnItems->Add(new Spacer(10.0f));
38
leftColumnItems->Add(new TextView(di->T("GoldOverview2", "It helps sustain development!")))->SetAlign(FLAG_WRAP_TEXT);
39
} else {
40
leftColumnItems->Add(new TextView(di->T("GoldThankYou", "Thank you for supporting the PPSSPP project!")))->SetAlign(FLAG_WRAP_TEXT);
41
}
42
43
leftColumnItems->Add(new Spacer(20.0f));
44
leftColumnItems->Add(new TextView("Henrik Rydgård"));
45
leftColumnItems->Add(new TextView("(hrydgard)"));
46
47
ViewGroup *rightColumnItems = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(300, WRAP_CONTENT, UI::Margins(15,15)));
48
root_->Add(rightColumnItems);
49
50
if (!bought) {
51
Choice *buyButton = rightColumnItems->Add(new Choice(mm->T("Buy PPSSPP Gold")));
52
buyButton->SetIcon(ImageID("I_ICONGOLD"), 0.5f);
53
buyButton->SetShine(true);
54
const int requesterToken = GetRequesterToken();
55
buyButton->OnClick.Add([this, requesterToken](UI::EventParams &) {
56
INFO_LOG(Log::System, "Showing purchase UI...");
57
System_IAPMakePurchase(requesterToken, "org.ppsspp.gold", [this](const char *responseString, int intValue) {
58
INFO_LOG(Log::System, "PPSSPP Gold purchase successful!");
59
auto di = GetI18NCategory(I18NCat::DIALOG);
60
g_OSD.Show(OSDType::MESSAGE_SUCCESS, di->T("GoldThankYou", "Thank you for supporting the PPSSPP project!"), 3.0f);
61
RecreateViews();
62
}, []() {
63
WARN_LOG(Log::System, "Purchase failed or cancelled!");
64
});
65
// TODO: What do we do here?
66
return UI::EVENT_DONE;
67
});
68
}
69
70
Choice *moreInfo = rightColumnItems->Add(new Choice(di->T("More info")));
71
moreInfo->OnClick.Add([](UI::EventParams &) {
72
System_LaunchUrl(LaunchUrlType::BROWSER_URL, "https://www.ppsspp.org/buygold_ios");
73
return UI::EVENT_DONE;
74
});
75
76
Choice *backButton = rightColumnItems->Add(new Choice(di->T("Back")));
77
backButton->OnClick.Handle<UIScreen>(this, &UIScreen::OnBack);
78
79
// Put the restore purchases button in the bottom right corner. It's rarely useful, but needed.
80
rightColumnItems->Add(new Spacer(new LinearLayoutParams(1.0f)));
81
Choice *restorePurchases = new Choice(di->T("Restore purchase"));
82
const int requesterToken = GetRequesterToken();
83
restorePurchases->OnClick.Add([this, requesterToken, restorePurchases](UI::EventParams &) {
84
restorePurchases->SetEnabled(false);
85
INFO_LOG(Log::System, "Requesting purchase restore");
86
System_IAPRestorePurchases(requesterToken, [this](const char *responseString, int) {
87
INFO_LOG(Log::System, "Successfully restored purchases!");
88
RecreateViews();
89
}, []() {
90
WARN_LOG(Log::System, "Failed restoring purchases");
91
});
92
return UI::EVENT_DONE;
93
});
94
rightColumnItems->Add(restorePurchases);
95
}
96
97