-
Notifications
You must be signed in to change notification settings - Fork 3
/
JediAcademyLauncher.cpp
311 lines (283 loc) · 12.1 KB
/
JediAcademyLauncher.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/************************************************************************************
** The MIT License (MIT)
**
** Copyright (c) 2020 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 <ScrollView.h>
#include <StringView.h>
#include <StringList.h>
#include <ListView.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 "JediAcademyLauncher"
// Launcher Settings
#define TITLE "StarWars: Jedi Academy Launcher"
#define VERSION "1.0.0"
#define PACKAGE_DIR "JediAcademy"
#define SETTINGS_FILE "JediAcademyLauncher.set"
#define EXECUTABLE_FILE_SP "JediAcademy"
#define EXECUTABLE_FILE_MP "JediAcademyMP"
#define EXECUTABLE_FILE_TM "Terminal"
#define EXECUTABLE_FILE_DS "openjkded"
#define DATA_PATH_OPT "JEDI_ACADEMY_DATA"
// Globals
#define G_GAMES_LIST_HEIGHT 64.0f
#define G_SERVER_INFO_HEIGHT 64.0f
// Various Strings
#define L_ABOUT_STRING B_TRANSLATE("Community-maintained Star Wars Jedi Knight: Jedi Academy, story version\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("https://github.com/JACoders/OpenJK")
#define L_ABOUT_LINK_DESC B_TRANSLATE("Official site:")
#define L_ABOUT_OTH_LINK B_TRANSLATE("http://jkhub.org/forum/51-discussion/")
#define L_ABOUT_OTH_LINK_DESC B_TRANSLATE("OpenJK Discussion:")
#define L_DATA_LINK B_TRANSLATE("https://store.steampowered.com/app/6020")
#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/star_wars_jedi_knight_jedi_academy")
#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.")
#define L_GAME_LIST_LABEL B_TRANSLATE("Please select:")
#define L_GAME_LIST_SINGLEPLAYER_DESC B_TRANSLATE("Star Wars: Jedi Knight: Jedi Academy (Singleplayer)")
#define L_GAME_LIST_MULTIPLAYER_DESC B_TRANSLATE("Star Wars: Jedi Knight: Jedi Academy (Multiplayer)")
#define L_GAME_LIST_SERVER_DESC B_TRANSLATE("Dedicated Server")
#define L_GAMESP_INFORMATION B_TRANSLATE("In single-player mode, the player takes control of the \
character Jaden Korr, a new student at Luke Skywalker's Jedi Academy under the tutelage of Kyle Katarn.")
#define L_GAMEMP_INFORMATION B_TRANSLATE("In multiplayer mode, one can play online or via a local \
area network (LAN) with other players, as well as computer-controlled bots.")
#define L_SERVER_INFORMATION B_TRANSLATE("Jedi Academy dedicated server.")
// 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"
#define O_GAME_LIST_LABEL "gameListLabel"
#define O_VIEW_SCROLL "viewScroll"
#define O_SERVER_INFORMATION "serverInformation"
class JediAcademyAboutWindow : public BeAboutWindow
{
public:
explicit JediAcademyAboutWindow(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 JediAcademyLauncher : public BeLauncherBase
{
enum
{
MSG_LIST_ITEM_SELECTED = 'ssgl'
};
BListView *fGamesList;
BScrollView *fScrollView;
BTextView *fInformationView;
void
FillGamesList(void)
{
fGamesList->MakeEmpty();
fGamesList->AddItem(new BStringItem(L_GAME_LIST_SINGLEPLAYER_DESC));
fGamesList->AddItem(new BStringItem(L_GAME_LIST_MULTIPLAYER_DESC));
fGamesList->AddItem(new BStringItem(L_GAME_LIST_SERVER_DESC));
fGamesList->Select(0);
}
protected:
virtual void
MessageReceived(BMessage *msg)
{
switch (msg->what)
{
case MSG_LIST_ITEM_SELECTED:
{
int32 selection = fGamesList->CurrentSelection();
switch (selection)
{
case 0:
fInformationView->SetText(L_GAMESP_INFORMATION);
break;
case 1:
fInformationView->SetText(L_GAMEMP_INFORMATION);
break;
case 2:
fInformationView->SetText(L_SERVER_INFORMATION);
break;
default:
fInformationView->SetText("");
break;
}
break;
}
default:
{
BeLauncherBase::MessageReceived(msg);
break;
}
}
}
virtual bool
CheckCache(void)
{
BString path = BeLauncherBase::GetTextControl()->Text();
if(!path.EndsWith("/"))
{
path << "/";
}
// NOTE: Check some file in the game cache.
path << "base/assets0.pk3";
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("OPENJK_GAME_DATA", BeLauncherBase::GetTextControl()->Text(), 1);
if (fGamesList->CurrentSelection() == 0) {
BString executableFilePath = BeUtils::GetPathToExecutable(PACKAGE_DIR, EXECUTABLE_FILE_SP);
BeLauncherBase::SetExecutablePath(executableFilePath);
return BeLauncherBase::RunGameViaExecVe(true, false);
}
if (fGamesList->CurrentSelection() == 1) {
BString executableFilePath = BeUtils::GetPathToExecutable(PACKAGE_DIR, EXECUTABLE_FILE_MP);
BeLauncherBase::SetExecutablePath(executableFilePath);
return BeLauncherBase::RunGameViaExecVe(true, false);
}
if (fGamesList->CurrentSelection() == 2) {
BString executableFilePath = BeUtils::GetPathToExecutable("", EXECUTABLE_FILE_TM);
chdir(BeLauncherBase::GetTextControl()->Text());
executableFilePath << " " << EXECUTABLE_FILE_DS << " &";
system(executableFilePath.String());
return false;
}
return false;
}
virtual void
ShowAboutDialog(void)
{
JediAcademyAboutWindow *gameAboutWindow = new JediAcademyAboutWindow(Frame().InsetBySelf(BannerWidth(), -(Gap() * 3)),
TITLE, VERSION);
gameAboutWindow->Show();
}
public:
explicit JediAcademyLauncher(const char *startPath)
: BeLauncherBase(TITLE, PACKAGE_DIR, EXECUTABLE_FILE_SP, 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);
BStringView *gameListLabel = new BStringView(O_GAME_LIST_LABEL, L_GAME_LIST_LABEL);
fGamesList = new BListView();
fGamesList->SetExplicitMinSize(BSize(B_SIZE_UNSET, G_GAMES_LIST_HEIGHT));
fGamesList->SetSelectionMessage(new BMessage(MSG_LIST_ITEM_SELECTED));
fScrollView = new BScrollView(O_VIEW_SCROLL, fGamesList, B_WILL_DRAW | B_FRAME_EVENTS,
false, true, B_PLAIN_BORDER);
fInformationView = new BTextView(O_SERVER_INFORMATION);
fInformationView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
fInformationView->SetExplicitMinSize(BSize(B_SIZE_UNSET, G_SERVER_INFO_HEIGHT));
fInformationView->SetText(L_GAMESP_INFORMATION);
fInformationView->MakeEditable(false);
BGroupLayout *boxLayout = BLayoutBuilder::Group<>(B_VERTICAL, B_USE_HALF_ITEM_SPACING)
.AddGroup(B_HORIZONTAL, 0.0f)
.Add(gameListLabel)
.AddGlue()
.End()
.Add(fScrollView)
.AddGroup(B_HORIZONTAL, 0.0f)
.Add(urlDescString)
.Add(urlString)
.Add(orText)
.Add(urlStringGOG)
.Add(dotText)
.AddGlue()
.End()
.AddStrut(B_USE_SMALL_SPACING)
.Add(fInformationView);
BeLauncherBase::GetAdditionalBox()->AddChild(boxLayout->View());
FillGamesList();
}
};
int
main(void)
{
BeApp *beApp = new BeApp(SIGNATURE);
JediAcademyLauncher *jediAcademyLauncher = new JediAcademyLauncher(BeUtils::GetPathToHomeDir());
beApp->SetMainWindow(jediAcademyLauncher);
beApp->Run();
delete beApp;
beApp = NULL;
return 0;
}