-
Notifications
You must be signed in to change notification settings - Fork 3
/
BasedGameLauncher.cpp
228 lines (202 loc) · 7.87 KB
/
BasedGameLauncher.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
/************************************************************************************
** The MIT License (MIT)
**
** Copyright (c) 2018 EXL
**
** 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 <Rect.h>
#include <String.h>
#include <StringView.h>
#include <CheckBox.h>
#include <Font.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 "BasedGameLauncher"
// Launcher Settings
#define TITLE "Game Launcher"
#define VERSION "1.0.0"
#define PACKAGE_DIR "Game"
#define SETTINGS_FILE "GameLauncher.set"
#define EXECUTABLE_FILE "engine/Game"
#define DATA_PATH_OPT "DATA_DIR"
// Various Strings
#define L_ABOUT_STRING B_TRANSLATE("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do " \
"eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim " \
"veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea " \
"commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit " \
"esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat " \
"cupidatat non proident, sunt in culpa qui officia deserunt mollit anim " \
"id est laborum.\n\n")
#define L_ABOUT_THANKS_STR_H B_TRANSLATE("Thanks to:\n\t")
#define L_ABOUT_THANKS_STR B_TRANSLATE("- my gf")
#define L_ABOUT_LINK B_TRANSLATE("http://exlmoto.ru")
#define L_ABOUT_LINK_DESC B_TRANSLATE("Some useful link: ")
#define L_DATA_LINK B_TRANSLATE("https://store.steampowered.com/")
#define L_DATA_FILES_LINK_D B_TRANSLATE("Buy data files: ")
// Additional option
#define S_CHECKBOX_OPTION "GAME_OPTION"
#define L_CHECKBOX_OPTION B_TRANSLATE("Game option")
#define L_CHECKBOX_OPTION_TOOLTIP B_TRANSLATE("Check to activate game option.")
#define L_CHECKBOX_SAVED_OPTION B_TRANSLATE("Saved option: ")
#define O_CHECKBOX_OPTION "checkBoxOption"
#define O_ABOUT_LINK "aboutLink"
#define O_ABOUT_LINK_DESC "aboutLinkDesc"
#define O_DATA_LINK "dataLink"
#define O_DATA_LINK_DESC "dataLinkDesc"
class GameAboutWindow : public BeAboutWindow
{
public:
explicit
GameAboutWindow(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);
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);
BGroupLayout *boxLayout = BLayoutBuilder::Group<>(B_HORIZONTAL)
.Add(urlDescString)
.Add(urlString)
.AddGlue();
BeAboutWindow::GetAdditionalBox()->AddChild(boxLayout->View());
}
};
class BasedGameLauncher : public BeLauncherBase
{
enum
{
MSG_CHECKBOX_STATE_CHANGED = 'chks'
};
BCheckBox *fCheckBoxOption;
protected:
virtual void
MessageReceived(BMessage *msg)
{
switch (msg->what)
{
case MSG_CHECKBOX_STATE_CHANGED:
{
BCheckBox *checkBox = dynamic_cast<BCheckBox *>(FindView(O_CHECKBOX_OPTION));
if(checkBox != NULL)
{
SetStatusString(B_COLOR_BLACK, BString(L_CHECKBOX_OPTION) << ": " << checkBox->Value());
}
break;
}
default:
{
BeLauncherBase::MessageReceived(msg);
break;
}
}
}
virtual bool
CheckCache(void)
{
return true;
}
virtual bool
RunGame(void)
{
return BeLauncherBase::RunGameViaRoster(true, false);
}
virtual bool
ReadSettings(void)
{
if(!BeLauncherBase::ReadSettings())
{
BeDebug("[Info]: First run, set default values.\n");
fCheckBoxOption->SetValue(B_CONTROL_ON);
}
else
{
const char *str = BeLauncherBase::GetSettings()->GetSettingsString(S_CHECKBOX_OPTION);
int ASCII_MAGIC = 48;
int value = static_cast<int>(str[0] - ASCII_MAGIC);
SetStatusString(B_COLOR_BLACK, BString(L_CHECKBOX_SAVED_OPTION) << value);
fCheckBoxOption->SetValue(value);
}
return true;
}
virtual void
SaveSettings(bool def)
{
BString value;
value << fCheckBoxOption->Value();
BeLauncherBase::GetSettings()->SetSettingsString(S_CHECKBOX_OPTION, value);
BeLauncherBase::SaveSettings(def);
}
virtual void
ShowAboutDialog(void)
{
GameAboutWindow *gameAboutWindow = new GameAboutWindow(Frame().InsetBySelf(BannerWidth(), -(Gap() * 3)),
TITLE, VERSION);
gameAboutWindow->Show();
}
public:
explicit
BasedGameLauncher(const char *startPath)
: BeLauncherBase(TITLE, PACKAGE_DIR, EXECUTABLE_FILE, SETTINGS_FILE, DATA_PATH_OPT,
startPath, true, false)
{
fCheckBoxOption = new BCheckBox(O_CHECKBOX_OPTION, L_CHECKBOX_OPTION, new BMessage(MSG_CHECKBOX_STATE_CHANGED));
fCheckBoxOption->SetToolTip(L_CHECKBOX_OPTION_TOOLTIP);
BStringView *urlDescString = new BStringView(O_DATA_LINK_DESC, L_DATA_FILES_LINK_D);
BeUrlStringView *urlString = new BeUrlStringView(O_DATA_LINK, L_DATA_LINK);
BGroupLayout *boxLayout = BLayoutBuilder::Group<>(B_VERTICAL, B_USE_HALF_ITEM_SPACING)
.AddGroup(B_HORIZONTAL, 0.0f)
.Add(fCheckBoxOption)
.AddGlue()
.End()
.AddGroup(B_HORIZONTAL, 0.0f)
.Add(urlDescString)
.Add(urlString)
.AddGlue()
.End();
BeLauncherBase::GetAdditionalBox()->AddChild(boxLayout->View());
// NOTE: Be sure to call read settings function.
ReadSettings();
}
};
int
main(void)
{
BeApp *beApp = new BeApp(SIGNATURE);
BasedGameLauncher *basedGameLauncher = new BasedGameLauncher(BeUtils::GetPathToHomeDir());
beApp->SetMainWindow(basedGameLauncher);
beApp->Run();
delete beApp;
beApp = NULL;
return 0;
}