-
Notifications
You must be signed in to change notification settings - Fork 12
/
Settings.cpp
322 lines (267 loc) · 9.69 KB
/
Settings.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
312
313
314
315
316
317
318
319
320
321
322
#include "Settings.h"
#include "Courseplay_EditorMain.h"
#include "version.h"
#define LayoutUpdateMajor 0
#define LayoutUpdateMinor 0
#define LayoutUpdateBuild 718
Settings::Settings()
: Locale(this)
{
setLocaleSearchPath(wxT("Langs"));
setLocaleConfigPath(wxT("General"));
loadDefaultLocaleIfExists();
parent = NULL;
defaultLayout = wxEmptyString;
savegameHasChanges = false;
loadLastSavegame = false;
backupSavegame = false;
savegameId = 0;
saveVersion = false;
major = 0;
minor = 0;
build = 0;
configFrame = NULL;
}
Settings::Settings(Courseplay_EditorFrame *frame, wxAuiManager *m_mgr)
: Locale(this)
{
setLocaleSearchPath(wxT("Langs"));
setLocaleConfigPath(wxT("General"));
parent = frame;
defaultLayout = m_mgr->SavePerspective();
savegameHasChanges = true;
saveVersion = true;
Read(wxT("/General/Major"), &major, EditorVersion::MAJOR);
Read(wxT("/General/Minor"), &minor, EditorVersion::MINOR);
Read(wxT("/General/Build"), &build, EditorVersion::BUILD);
Read(wxT("/General/SelectedGame"), &selectedGameId, FS2013);
Read(wxT("/General/LoadLastSavegame"), &loadLastSavegame, false);
Read(wxT("/General/BackupSavegame"), &backupSavegame, true);
if (loadLastSavegame)
Read(wxT("/General/SavegameId"), &savegameId, 0);
else
savegameId = 0;
for (int i = 0; i < NumOfFSGames; i++)
{
Read(wxString::Format(wxT("/%s/Enabled"), gameLocations[i].game.c_str()), &gameIsEnabled[i], false);
Read(wxString::Format(wxT("/%s/InstallLocation"), gameLocations[i].game.c_str()), &installPath[i], wxEmptyString);
Read(wxString::Format(wxT("/%s/SavegameLocation"), gameLocations[i].game.c_str()), &savegamePath[i], wxEmptyString);
}
configFrame = new SettingsFrame(this, m_mgr, (wxWindow*) parent);
}
Settings::~Settings()
{
// Here for destructing things if needed.
if (configFrame)
delete configFrame;
if (saveVersion)
{
Write(_T("/General/Major"), EditorVersion::MAJOR);
Write(_T("/General/Minor"), EditorVersion::MINOR);
Write(_T("/General/Build"), EditorVersion::BUILD);
}
}
bool Settings::isFirstTimeSetup()
{
bool doneFirstTimeSetup;
Read(_T("/General/DoneFirstTimeSetup"), &doneFirstTimeSetup, false);
return !doneFirstTimeSetup;
}
void Settings::doFirstTimeSetup()
{
// Ask user for Language
askUserForLanguage(_("Select language to use."), _("Language Select"));
saveLocale();
// Ask to auto detect locations
wxString msg = wxEmptyString;
msg += _("Do you want Courseplay Editor to try to auto detect where Farming Simulator(s) install and savegame locations are?\n\n");
msg += _("If you select (No) you can set the install and savegame locations under Edit->Settings");
int answer = wxMessageBox(msg, _("First Time Setup"), wxYES_NO | wxICON_QUESTION, parent);
if (answer == wxYES)
{
bool fs2011FoundInstallPath = findInstallPath (FS2011);
bool fs2011FoundSavePath = findSavegamePath(FS2011);
bool fs2013FoundInstallPath = findInstallPath (FS2013);
bool fs2013FoundSavePath = findSavegamePath(FS2013);
// Enable game if both path is found.
enableGameIfFound(FS2011, false);
enableGameIfFound(FS2013, false);
// Show result of auto detect.
if (fs2011FoundInstallPath || fs2011FoundSavePath ||
fs2013FoundInstallPath || fs2013FoundSavePath)
{
bool addExtraDescription = false;
msg = wxEmptyString;
if (fs2011FoundInstallPath && fs2011FoundSavePath)
msg += _("Found all Farming Simulator 2011 Locations\n");
else if (fs2011FoundInstallPath && !fs2011FoundSavePath)
{
msg += _("Found Farming Simulator 2011 install location, but did not find the savegame location\n");
addExtraDescription = true;
}
else if (!fs2011FoundInstallPath && fs2011FoundSavePath)
{
msg += _("Found Farming Simulator 2011 savegame location but did not find the install location\n");
addExtraDescription = true;
}
if (fs2013FoundInstallPath && fs2013FoundSavePath)
msg += _("Found all Farming Simulator 2013 Locations\n");
else if (fs2013FoundInstallPath && !fs2013FoundSavePath)
{
msg += _("Found Farming Simulator 2013 install location, but did not find the savegame location\n");
addExtraDescription = true;
}
else if (!fs2013FoundInstallPath && fs2013FoundSavePath)
{
msg += _("Found Farming Simulator 2013 savegame location but did not find the install location\n");
addExtraDescription = true;
}
if (addExtraDescription)
msg += _("\nYou can manually select the install and savegame location under Edit->Settings menu if you have one of the game installed.");
}
else
{
msg = wxEmptyString;
msg += _("Courseplay Editor did not find any Farming Simulator games.\n");
msg += _("\nYou can manually select the install and savegame location under Edit->Settings menu if you have one of the game installed.");
}
wxMessageBox(msg, _("Courseplay Editor Auto Detect Result"), wxOK, parent);
}
Write(_T("/General/DoneFirstTimeSetup"), true);
}
void Settings::showSettings()
{
//(SettingsFrame*)configFrame->up
configFrame->updateTapPanels();
configFrame->Show();
configFrame->SetFocus();
}
void Settings::saveDefaultLayout(wxString layout)
{
defaultLayout = layout;
}
void Settings::saveLayout(wxString layout)
{
Write(_T("GUI/layout"), layout);
}
wxString Settings::getSavedLayout()
{
if (
major < LayoutUpdateMajor ||
(major <= LayoutUpdateMajor && minor < LayoutUpdateMinor) ||
(major <= LayoutUpdateMajor && minor <= LayoutUpdateMinor && build < LayoutUpdateBuild)
)
{
wxString msg = _("The layout have changed since last version.\n\nThe layout will be reset.");
wxMessageBox(msg, _("New Layout!"), wxOK | wxCENTER | wxICON_INFORMATION);
saveLayout(defaultLayout);
return defaultLayout;
}
else
return Read(_T("GUI/layout"), defaultLayout);
}
bool Settings::findInstallPath(FSGames gameId)
{
installPath[gameId] = doFindInstallPath(gameId);
return (installPath[gameId] != wxEmptyString);
}
bool Settings::findSavegamePath(FSGames gameId)
{
savegamePath[gameId] = doFindSavegamePath(gameId);
return (savegamePath[gameId] != wxEmptyString);
}
void Settings::enableGame(FSGames gameId, bool enable, bool updateToolbar)
{
Write(wxString::Format(_T("/%s/Enabled"), gameLocations[gameId].game.c_str()), enable);
if (updateToolbar)
{
gameIsEnabled[gameId] = enable;
updateGameSelect();
}
}
void Settings::enableGameIfFound(FSGames gameId, bool updateToolbar)
{
// Set values
wxString gameName = gameLocations[gameId].game;
if (installPath[gameId] != wxEmptyString && savegamePath[gameId] != wxEmptyString &&
wxDirExists(installPath[gameId]) && wxDirExists(savegamePath[gameId]))
enableGame(gameId, true, updateToolbar);
else
enableGame(gameId, false, updateToolbar);
}
void Settings::setInstallPath(FSGames gameId, wxString path)
{
Write(wxString::Format(wxT("/%s/InstallLocation"), gameLocations[gameId].game.c_str()), path);
installPath[gameId] = path;
}
void Settings::setSavegamePath(FSGames gameId, wxString path)
{
Write(wxString::Format(wxT("/%s/SavegameLocation"), gameLocations[gameId].game.c_str()), path);
savegamePath[gameId] = path;
}
bool Settings::setGameId(FSGames gameId)
{
if (gameId >= 0 && gameId < NumOfFSGames)
{
selectedGameId = gameId;
return Write(wxT("/General/SelectedGame"), selectedGameId);
}
return false;
}
void Settings::updateGameSelect()
{
bool noGameActive = true;
//parent->selectedGameId;
// TODO: Update Game Select.
if (selectedGameId < 0 || (selectedGameId >= 0 && !gameIsEnabled[selectedGameId]))
{
for (int i = 0; i < NumOfFSGames; i++)
{
if (gameIsEnabled[i])
{
noGameActive = false;
selectedGameId = i;
break;
}
}
if (noGameActive)
selectedGameId = -1;
Write(wxT("/General/SelectedGame"), selectedGameId);
parent->updateToolbar2();
}
}
void Settings::updateSavegameList()
{
parent->updateSavegameList();
}
wxString Settings::getSavegamePath()
{
if (selectedGameId >= 0)
return savegamePath[selectedGameId];
return wxEmptyString;
}
wxString Settings::getInstallPath()
{
if (selectedGameId >= 0)
return installPath[selectedGameId];
return wxEmptyString;
}
void Settings::setSavegameHasChanges(bool val)
{
savegameHasChanges = val;
}
void Settings::setLoadLastSavegame(bool val)
{
loadLastSavegame = val;
Write(wxT("/General/LoadLastSavegame"), loadLastSavegame);
}
void Settings::setBackupSavegame(bool val)
{
backupSavegame = val;
Write(wxT("/General/BackupSavegame"), backupSavegame);
}
void Settings::setSavegameId(long val)
{
savegameId = val;
Write(wxT("/General/SavegameId"), savegameId);
}