-
Notifications
You must be signed in to change notification settings - Fork 3
/
AquariaLauncher.cpp
195 lines (177 loc) · 7.84 KB
/
AquariaLauncher.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/************************************************************************************
** The MIT License (MIT)
**
** Copyright (c) 2021 3dEyes**
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and associated documentation files (the "Software"), to deal
** in the Software without restriction, including without limitation the rights
** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
** copies of the Software, and to permit persons to whom the Software is
** furnished to do so, subject to the following conditions:
**
** The above copyright notice and this permission notice shall be included in all
** copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
** SOFTWARE.
************************************************************************************/
#include "BeApp.h"
#include "BeLauncherBase.h"
#include "BeAboutWindow.h"
#include "BeUrlStringView.h"
#include "BeUtils.h"
#include <Font.h>
#include <Rect.h>
#include <String.h>
#include <StringView.h>
#include <Entry.h>
#include <GroupLayout.h>
#include <LayoutBuilder.h>
#include <InterfaceDefs.h>
#include <Catalog.h>
#ifndef SIGNATURE
#error "Application SIGNATURE is not defined. Check your build system."
#endif // !SIGNATURE
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "AquariaLauncher"
// Launcher Settings
#define TITLE "Aquaria Launcher"
#define VERSION "1.1.3"
#define PACKAGE_DIR "Aquaria"
#define SETTINGS_FILE "AquariaLauncher.set"
#define EXECUTABLE_FILE "aquaria.sh"
#define DATA_PATH_OPT "AQUARIA_DATA"
// Various Strings
#define L_ABOUT_STRING B_TRANSLATE("A breath-taking underwater fantasy game. \n\n")
#define L_ABOUT_THANKS_STR_H B_TRANSLATE("Thanks to:\n\t")
#define L_ABOUT_THANKS_STR B_TRANSLATE("EXL\n\n")
#define L_ABOUT_PORT_STR_H B_TRANSLATE("Port to Haiku:\n\t")
#define L_ABOUT_PORT_STR B_TRANSLATE("3dEyes**\n")
#define L_ABOUT_LINK B_TRANSLATE("http://bit-blot.com/aquaria")
#define L_ABOUT_LINK_DESC B_TRANSLATE("Official site:")
#define L_ABOUT_OTH_LINK B_TRANSLATE("https://github.com/AquariaOSE/Aquaria")
#define L_ABOUT_OTH_LINK_DESC B_TRANSLATE("Aquaria OSE:")
#define L_DATA_LINK B_TRANSLATE("https://steamcommunity.com/app/24420")
#define L_DATA_TEXT B_TRANSLATE("Steam")
#define L_DATA_FILES_LINK_D B_TRANSLATE("Buy game files on ")
#define L_DATA_LINK_G B_TRANSLATE("https://www.gog.com/game/aquaria")
#define L_DATA_TEXT_G B_TRANSLATE("GOG")
#define L_OR B_TRANSLATE(" or ")
#define L_DOT B_TRANSLATE(".")
#define L_ERROR_NO_GAMEINFO_FILE B_TRANSLATE("Required data file %file% not found.")
// Object Names
#define O_OR "orView"
#define O_DOT "dotView"
#define O_ABOUT_LINK "aboutLink"
#define O_ABOUT_LINK_DESC "aboutLinkDesc"
#define O_DATA_LINK "dataLink"
#define O_DATA_LINK_DESC "dataLinkDesc"
#define O_DATA_LINK_G "dataLinkG"
#define O_DATA_LINK_DESC_G "dataLinkDescG"
class AquariaAboutWindow : public BeAboutWindow
{
public:
explicit AquariaAboutWindow(const BRect &frame, const char *title, const char *version)
: BeAboutWindow(frame, title, version)
{
BStringView *urlDescString = new BStringView(O_ABOUT_LINK_DESC, L_ABOUT_LINK_DESC);
BeUrlStringView *urlString = new BeUrlStringView(O_ABOUT_LINK, L_ABOUT_LINK);
BStringView *urlDescOthString = new BStringView(O_ABOUT_LINK_DESC, L_ABOUT_OTH_LINK_DESC);
BeUrlStringView *urlOthString = new BeUrlStringView(O_ABOUT_LINK, L_ABOUT_OTH_LINK);
BeAboutWindow::GetInformationView()->Insert(L_ABOUT_STRING);
BeAboutWindow::GetInformationView()->SetFontAndColor(be_bold_font);
BeAboutWindow::GetInformationView()->Insert(L_ABOUT_THANKS_STR_H);
BeAboutWindow::GetInformationView()->SetFontAndColor(be_plain_font);
BeAboutWindow::GetInformationView()->Insert(L_ABOUT_THANKS_STR);
BeAboutWindow::GetInformationView()->SetFontAndColor(be_bold_font);
BeAboutWindow::GetInformationView()->Insert(L_ABOUT_PORT_STR_H);
BeAboutWindow::GetInformationView()->SetFontAndColor(be_plain_font);
BeAboutWindow::GetInformationView()->Insert(L_ABOUT_PORT_STR);
BGroupLayout *boxLayout = BLayoutBuilder::Group<>(B_VERTICAL, 0.0f)
.AddGroup(B_HORIZONTAL, B_USE_HALF_ITEM_SPACING)
.Add(urlDescString)
.Add(urlString)
.AddGlue()
.End()
.AddGroup(B_HORIZONTAL, B_USE_HALF_ITEM_SPACING)
.Add(urlDescOthString)
.Add(urlOthString)
.AddGlue()
.End();
BeAboutWindow::GetAdditionalBox()->AddChild(boxLayout->View());
}
};
class AquariaLauncher : public BeLauncherBase
{
virtual bool
CheckCache(void)
{
BString path = BeLauncherBase::GetTextControl()->Text();
if(!path.EndsWith("/"))
{
path << "/";
}
// NOTE: Check some file in the game cache.
path << "data/worldmap.txt";
BEntry fileToCheck(path);
if(!fileToCheck.Exists())
{
BString errorMessage(L_ERROR_NO_GAMEINFO_FILE);
errorMessage.ReplaceAll("%file%", path);
SetStatusString(B_COLOR_RED, errorMessage);
return false;
}
return true;
}
virtual bool
RunGame(void)
{
setenv("AQUARIA_DATA_PATH", BeLauncherBase::GetTextControl()->Text(), 1);
return BeLauncherBase::RunGameViaExecVe(true, false);
}
virtual void
ShowAboutDialog(void)
{
AquariaAboutWindow *gameAboutWindow = new AquariaAboutWindow(Frame().InsetBySelf(BannerWidth(), -(Gap() * 3)),
TITLE, VERSION);
gameAboutWindow->Show();
}
public:
explicit AquariaLauncher(const char *startPath)
: BeLauncherBase(TITLE, PACKAGE_DIR, EXECUTABLE_FILE, SETTINGS_FILE, DATA_PATH_OPT,
startPath, true, true)
{
BStringView *urlDescString = new BStringView(O_DATA_LINK_DESC, L_DATA_FILES_LINK_D);
BeUrlStringView *urlString = new BeUrlStringView(O_DATA_LINK, L_DATA_TEXT, L_DATA_LINK);
BeUrlStringView *urlStringGOG = new BeUrlStringView(O_DATA_LINK_G, L_DATA_TEXT_G, L_DATA_LINK_G);
BStringView *dotText = new BStringView(O_DOT, L_DOT);
BStringView *orText = new BStringView(O_OR, L_OR);
BGroupLayout *boxLayout = BLayoutBuilder::Group<>(B_VERTICAL, B_USE_HALF_ITEM_SPACING)
.AddGroup(B_HORIZONTAL, 0.0f)
.Add(urlDescString)
.Add(urlString)
.Add(orText)
.Add(urlStringGOG)
.Add(dotText)
.AddGlue()
.End();
BeLauncherBase::GetAdditionalBox()->AddChild(boxLayout->View());
}
};
int
main(void)
{
BeApp *beApp = new BeApp(SIGNATURE);
AquariaLauncher *aquariaLauncher = new AquariaLauncher(BeUtils::GetPathToHomeDir());
beApp->SetMainWindow(aquariaLauncher);
beApp->Run();
delete beApp;
beApp = NULL;
return 0;
}