Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/UI/IAPScreen.cpp
4776 views
1
// NOTE: This currently only used on iOS, to present the availablility of getting PPSSPP Gold through IAP.
2
3
#include "Common/System/System.h"
4
#include "Common/System/Request.h"
5
#include "Common/Data/Text/I18n.h"
6
#include "Common/System/OSD.h"
7
#include "Common/Render/DrawBuffer.h"
8
#include "UI/IAPScreen.h"
9
#include "UI/OnScreenDisplay.h"
10
#include "UI/MiscViews.h"
11
12
void IAPScreen::CreateViews() {
13
using namespace UI;
14
15
auto di = GetI18NCategory(I18NCat::DIALOG);
16
auto mm = GetI18NCategory(I18NCat::MAINMENU);
17
18
const bool portrait = GetDeviceOrientation() == DeviceOrientation::Portrait;
19
20
root_ = new LinearLayout(portrait ? ORIENT_VERTICAL : ORIENT_HORIZONTAL, new LayoutParams(FILL_PARENT, FILL_PARENT));
21
22
if (portrait) {
23
root_->Add(new TopBar(*screenManager()->getUIContext(), TopBarFlags::Default, di->T("PPSSPP Gold")));
24
root_->Add(new Spacer(20.0f));
25
}
26
const bool bought = System_GetPropertyBool(SYSPROP_APP_GOLD);
27
28
LinearLayout *leftColumnItems;
29
if (portrait) {
30
leftColumnItems = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT, UI::Margins(12, 12)));
31
root_->Add(leftColumnItems);
32
} else {
33
ViewGroup *leftColumnContainer = new AnchorLayout(new LinearLayoutParams(1.0f, UI::Gravity::G_HCENTER));
34
leftColumnItems = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(600, WRAP_CONTENT, NONE, 105, NONE, 12));
35
leftColumnContainer->Add(leftColumnItems);
36
root_->Add(leftColumnContainer);
37
}
38
39
ViewGroup *appTitle = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT));
40
appTitle->Add(new ShinyIcon(ImageID("I_ICON_GOLD"), new LinearLayoutParams(64, 64)));
41
appTitle->Add(new TextView("PPSSPP Gold", new LinearLayoutParams(1.0f, Gravity::G_VCENTER)));
42
43
leftColumnItems->Add(appTitle);
44
leftColumnItems->Add(new Spacer(30.0f));
45
if (!bought) {
46
leftColumnItems->Add(new Spacer(20.0f));
47
leftColumnItems->Add(new TextView(di->T("GoldOverview1", "Buy PPSSPP Gold to support development!")))->SetAlign(FLAG_WRAP_TEXT);
48
leftColumnItems->Add(new Spacer(10.0f));
49
leftColumnItems->Add(new TextView(di->T("GoldOverview2", "It helps sustain development!")))->SetAlign(FLAG_WRAP_TEXT);
50
} else {
51
leftColumnItems->Add(new TextView(di->T("GoldThankYou", "Thank you for supporting the PPSSPP project!")))->SetAlign(FLAG_WRAP_TEXT);
52
}
53
54
leftColumnItems->Add(new Spacer(20.0f));
55
leftColumnItems->Add(new TextView("Henrik Rydgård"));
56
leftColumnItems->Add(new TextView("(hrydgard)"));
57
58
float weight = 0.0f;
59
if (portrait)
60
weight = 1.0f; // hack to lift the buttons up.
61
62
ViewGroup *rightColumnItems = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(350, WRAP_CONTENT, weight, UI::Margins(12, 12)));
63
root_->Add(rightColumnItems);
64
65
if (!bought) {
66
ImageID image;
67
#if 1 || PPSSPP_PLATFORM(ANDROID)
68
image = ImageID("I_LOGO_PLAY_STORE");
69
#elif PPSSPP_PLATFORM(IOS)
70
image = ImageID("I_LOGO_APP_STORE");
71
#endif
72
Choice *buyButton = rightColumnItems->Add(new Choice(mm->T("Buy PPSSPP Gold"), image));
73
buyButton->SetIconRight(ImageID("I_ICON_GOLD"), 0.5f);
74
buyButton->SetShine(true);
75
const int requesterToken = GetRequesterToken();
76
buyButton->OnClick.Add([this, requesterToken](UI::EventParams &) {
77
INFO_LOG(Log::System, "Showing purchase UI...");
78
79
if (useIAP_) {
80
System_IAPMakePurchase(requesterToken, "org.ppsspp.gold", [this](const char *responseString, int intValue) {
81
INFO_LOG(Log::System, "PPSSPP Gold purchase successful!");
82
auto di = GetI18NCategory(I18NCat::DIALOG);
83
g_OSD.Show(OSDType::MESSAGE_SUCCESS, di->T("GoldThankYou", "Thank you for supporting the PPSSPP project!"), 3.0f);
84
RecreateViews();
85
}, []() {
86
WARN_LOG(Log::System, "Purchase failed or cancelled!");
87
});
88
} else {
89
#if PPSSPP_PLATFORM(ANDROID)
90
System_LaunchUrl(LaunchUrlType::BROWSER_URL, "market://details?id=org.ppsspp.ppssppgold");
91
#else
92
System_LaunchUrl(LaunchUrlType::BROWSER_URL, "https://www.ppsspp.org/buygold");
93
#endif
94
}
95
});
96
}
97
98
Choice *moreInfo = rightColumnItems->Add(new Choice(di->T("More info"), ImageID("I_LINK_OUT")));
99
moreInfo->OnClick.Add([](UI::EventParams &) {
100
System_LaunchUrl(LaunchUrlType::BROWSER_URL, "https://www.ppsspp.org/buygold_ios");
101
});
102
103
if (!portrait) {
104
Choice *backButton = rightColumnItems->Add(new Choice(di->T("Back"), ImageID("I_NAVIGATE_BACK")));
105
backButton->OnClick.Handle<UIScreen>(this, &UIScreen::OnBack);
106
}
107
108
if (useIAP_) {
109
// Put the restore purchases button in the bottom right corner in landscape. It's rarely useful, but needed.
110
if (!portrait) {
111
rightColumnItems->Add(new Spacer(new LinearLayoutParams(1.0f)));
112
}
113
Choice *restorePurchases = new Choice(di->T("Restore purchase"));
114
const int requesterToken = GetRequesterToken();
115
restorePurchases->OnClick.Add([this, requesterToken, restorePurchases](UI::EventParams &) {
116
restorePurchases->SetEnabled(false);
117
INFO_LOG(Log::System, "Requesting purchase restore");
118
System_IAPRestorePurchases(requesterToken, [this](const char *responseString, int) {
119
INFO_LOG(Log::System, "Successfully restored purchases!");
120
RecreateViews();
121
}, []() {
122
WARN_LOG(Log::System, "Failed restoring purchases");
123
});
124
});
125
rightColumnItems->Add(restorePurchases);
126
}
127
}
128
129