-
Notifications
You must be signed in to change notification settings - Fork 3
/
fHeroes2Launcher.cpp
180 lines (163 loc) · 7.82 KB
/
fHeroes2Launcher.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
/************************************************************************************
** 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 "fHeroes2Launcher"
// Launcher Settings
#define TITLE "fHeroes2 Launcher"
#define VERSION "1.0.0"
#define PACKAGE_DIR "fHeroes2"
#define SETTINGS_FILE "fHeroes2Launcher.set"
#define EXECUTABLE_FILE "fHeroes2"
#define DATA_PATH_OPT "FHEROES2_DATA"
// Various Strings
#define L_ABOUT_STRING B_TRANSLATE("Free implementation of Heroes of the Might and Magic II engine.\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://ihhub.github.io/fheroes2/")
#define L_ABOUT_LINK_DESC B_TRANSLATE("Official site:")
#define L_DATA_LINK_U B_TRANSLATE("https://store.ubi.com/ru/game?pid=5902fbba88a7e3f0618b4567")
#define L_DATA_TEXT_U B_TRANSLATE("Ubisoft")
#define L_DATA_FILES_LINK_D B_TRANSLATE("Buy game files on ")
#define L_DATA_LINK_G B_TRANSLATE("https://www.gog.com/game/heroes_of_might_and_magic_2_gold_edition")
#define L_DATA_TEXT_G B_TRANSLATE("GOG")
#define L_OR B_TRANSLATE("or ")
#define L_DOT B_TRANSLATE(".")
#define L_COMMA B_TRANSLATE(", ")
#define L_DATA_DEMO_TEXT_D B_TRANSLATE("archive.org")
#define L_DATA_DEMO_LINK_D B_TRANSLATE("https://archive.org/download/HeroesofMightandMagicIITheSuccessionWars_1020/h2demo.zip")
#define L_DATA_DEMO_TEXT_DESC B_TRANSLATE("download free demo version from ")
// Object Names
#define O_OR "orView"
#define O_DOT "dotView"
#define O_COMMA "commaView"
#define O_ABOUT_LINK "aboutLink"
#define O_ABOUT_LINK_DESC "aboutLinkDesc"
#define O_DATA_LINK_U "dataLink"
#define O_DATA_LINK_DESC_U "dataLinkDesc"
#define O_DATA_LINK_G "dataLinkG"
#define O_DATA_LINK_DESC_G "dataLinkDescG"
#define O_DATA_DEMO_LINK "dataDemoLink"
#define O_DATA_DEMO_LINK_DESC "dataDemoLinkDesc"
class fHeroes2AboutWindow : public BeAboutWindow
{
public:
explicit fHeroes2AboutWindow(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);
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();
BeAboutWindow::GetAdditionalBox()->AddChild(boxLayout->View());
}
};
class fHeroes2Launcher : public BeLauncherBase
{
protected:
virtual bool
RunGame(void)
{
return BeLauncherBase::RunGameViaRoster(true, true);
}
virtual void
ShowAboutDialog(void)
{
fHeroes2AboutWindow *gameAboutWindow = new fHeroes2AboutWindow(Frame().InsetBySelf(BannerWidth(), -(Gap() * 3)),
TITLE, VERSION);
gameAboutWindow->Show();
}
public:
explicit fHeroes2Launcher(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_U, L_DATA_FILES_LINK_D);
BeUrlStringView *urlStringUBI = new BeUrlStringView(O_DATA_LINK_U, L_DATA_TEXT_U, L_DATA_LINK_U);
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 *commaText = new BStringView(O_COMMA, L_COMMA);
BStringView *orText = new BStringView(O_OR, L_OR);
BStringView *demoDataDescString = new BStringView(O_DATA_DEMO_LINK_DESC, L_DATA_DEMO_TEXT_DESC);
BeUrlStringView *demoDataString = new BeUrlStringView(O_DATA_DEMO_LINK, L_DATA_DEMO_TEXT_D, L_DATA_DEMO_LINK_D);
BGroupLayout *boxLayout = BLayoutBuilder::Group<>(B_VERTICAL, B_USE_HALF_ITEM_SPACING)
.AddGroup(B_HORIZONTAL, 0.0f)
.Add(urlDescString)
.Add(urlStringUBI)
.Add(commaText)
.Add(urlStringGOG)
.AddGlue()
.End()
.AddGroup(B_HORIZONTAL, 0.0f)
.Add(orText)
.Add(demoDataDescString)
.Add(demoDataString)
.Add(dotText)
.AddGlue()
.End();
BeLauncherBase::GetAdditionalBox()->AddChild(boxLayout->View());
}
};
int
main(void)
{
BeApp *beApp = new BeApp(SIGNATURE);
fHeroes2Launcher *fheroes2launcher = new fHeroes2Launcher(BeUtils::GetPathToHomeDir());
beApp->SetMainWindow(fheroes2launcher);
beApp->Run();
delete beApp;
beApp = NULL;
return 0;
}