forked from OTAcademy/RME
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.cpp
More file actions
698 lines (587 loc) · 19.2 KB
/
application.cpp
File metadata and controls
698 lines (587 loc) · 19.2 KB
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
//////////////////////////////////////////////////////////////////////
// This file is part of Remere's Map Editor
//////////////////////////////////////////////////////////////////////
// Remere's Map Editor is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Remere's Map Editor is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//////////////////////////////////////////////////////////////////////
#include "main.h"
#include "application.h"
#include "sprites.h"
#include "editor.h"
#include "common_windows.h"
#include "palette_window.h"
#include "preferences.h"
#include "result_window.h"
#include "minimap_window.h"
#include "about_window.h"
#include "main_menubar.h"
#include "updater.h"
#include "artprovider.h"
#include "materials.h"
#include "map.h"
#include "complexitem.h"
#include "creature.h"
#include "lua/lua_script_manager.h"
#include "lua/lua_scripts_window.h"
#include <wx/snglinst.h>
#if defined(__LINUX__) || defined(__WINDOWS__)
#include <GL/glut.h>
#endif
#include "../brushes/icon/editor_icon.xpm"
BEGIN_EVENT_TABLE(MainFrame, wxFrame)
EVT_CLOSE(MainFrame::OnExit)
// Update check complete
#ifdef _USE_UPDATER_
EVT_ON_UPDATE_CHECK_FINISHED(wxID_ANY, MainFrame::OnUpdateReceived)
#endif
EVT_ON_UPDATE_MENUS(wxID_ANY, MainFrame::OnUpdateMenus)
// Idle event handler
EVT_IDLE(MainFrame::OnIdle)
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(MapWindow, wxPanel)
EVT_SIZE(MapWindow::OnSize)
EVT_COMMAND_SCROLL_TOP(MAP_WINDOW_HSCROLL, MapWindow::OnScroll)
EVT_COMMAND_SCROLL_BOTTOM(MAP_WINDOW_HSCROLL, MapWindow::OnScroll)
EVT_COMMAND_SCROLL_THUMBTRACK(MAP_WINDOW_HSCROLL, MapWindow::OnScroll)
EVT_COMMAND_SCROLL_LINEUP(MAP_WINDOW_HSCROLL, MapWindow::OnScrollLineUp)
EVT_COMMAND_SCROLL_LINEDOWN(MAP_WINDOW_HSCROLL, MapWindow::OnScrollLineDown)
EVT_COMMAND_SCROLL_PAGEUP(MAP_WINDOW_HSCROLL, MapWindow::OnScrollPageUp)
EVT_COMMAND_SCROLL_PAGEDOWN(MAP_WINDOW_HSCROLL, MapWindow::OnScrollPageDown)
EVT_COMMAND_SCROLL_TOP(MAP_WINDOW_VSCROLL, MapWindow::OnScroll)
EVT_COMMAND_SCROLL_BOTTOM(MAP_WINDOW_VSCROLL, MapWindow::OnScroll)
EVT_COMMAND_SCROLL_THUMBTRACK(MAP_WINDOW_VSCROLL, MapWindow::OnScroll)
EVT_COMMAND_SCROLL_LINEUP(MAP_WINDOW_VSCROLL, MapWindow::OnScrollLineUp)
EVT_COMMAND_SCROLL_LINEDOWN(MAP_WINDOW_VSCROLL, MapWindow::OnScrollLineDown)
EVT_COMMAND_SCROLL_PAGEUP(MAP_WINDOW_VSCROLL, MapWindow::OnScrollPageUp)
EVT_COMMAND_SCROLL_PAGEDOWN(MAP_WINDOW_VSCROLL, MapWindow::OnScrollPageDown)
EVT_BUTTON(MAP_WINDOW_GEM, MapWindow::OnGem)
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(MapScrollBar, wxScrollBar)
EVT_KEY_DOWN(MapScrollBar::OnKey)
EVT_KEY_UP(MapScrollBar::OnKey)
EVT_CHAR(MapScrollBar::OnKey)
EVT_SET_FOCUS(MapScrollBar::OnFocus)
EVT_MOUSEWHEEL(MapScrollBar::OnWheel)
END_EVENT_TABLE()
wxIMPLEMENT_APP(Application);
Application::~Application() {
// Destroy
}
bool Application::OnInit() {
#if defined __DEBUG_MODE__ && defined __WINDOWS__
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
std::cout << "This is free software: you are free to change and redistribute it." << std::endl;
std::cout << "There is NO WARRANTY, to the extent permitted by law." << std::endl;
std::cout << "Review COPYING in RME distribution for details." << std::endl;
mt_seed(time(nullptr));
srand(time(nullptr));
// Discover data directory
g_gui.discoverDataDirectory("clients.xml");
// Tell that we are the real thing
wxAppConsole::SetInstance(this);
wxArtProvider::Push(new ArtProvider());
#if defined(__LINUX__) || defined(__WINDOWS__)
int argc = 1;
char* argv[1] = { wxString(this->argv[0]).char_str() };
glutInit(&argc, argv);
#endif
// Load some internal stuff
g_settings.load();
FixVersionDiscrapencies();
g_gui.LoadHotkeys();
ClientVersion::loadVersions();
#ifdef _USE_PROCESS_COM
m_single_instance_checker = newd wxSingleInstanceChecker; // Instance checker has to stay alive throughout the applications lifetime
if (g_settings.getInteger(Config::ONLY_ONE_INSTANCE) && m_single_instance_checker->IsAnotherRunning()) {
RMEProcessClient client;
wxConnectionBase* connection = client.MakeConnection("localhost", "rme_host", "rme_talk");
if (connection) {
wxString fileName;
if (ParseCommandLineMap(fileName)) {
wxLogNull nolog; // We might get a timeout message if the file fails to open on the running instance. Let's not show that message.
connection->Execute(fileName);
}
connection->Disconnect();
wxDELETE(connection);
}
wxDELETE(m_single_instance_checker);
return false; // Since we return false - OnExit is never called
}
// We act as server then
m_proc_server = newd RMEProcessServer();
if (!m_proc_server->Create("rme_host")) {
wxLogWarning("Could not register IPC service!");
}
#endif
// Image handlers
// wxImage::AddHandler(newd wxBMPHandler);
wxImage::AddHandler(newd wxPNGHandler);
wxImage::AddHandler(newd wxJPEGHandler);
wxImage::AddHandler(newd wxTGAHandler);
g_gui.gfx.loadEditorSprites();
#ifndef __DEBUG_MODE__
// wxHandleFatalExceptions(true);
#endif
// Load all the dependency files
std::string error;
StringVector warnings;
m_file_to_open = wxEmptyString;
ParseCommandLineMap(m_file_to_open);
g_gui.root = newd MainFrame(__W_RME_APPLICATION_NAME__, wxDefaultPosition, wxSize(700, 500));
SetTopWindow(g_gui.root);
g_gui.SetTitle("");
g_gui.root->LoadRecentFiles();
// Load palette
g_gui.LoadPerspective();
// Initialize Lua scripting system
if (!g_luaScripts.initialize()) {
wxLogWarning("Failed to initialize Lua scripting: %s", g_luaScripts.getLastError());
} else if (g_gui.root && g_gui.root->menu_bar) {
g_gui.root->menu_bar->LoadScriptsMenu();
}
wxIcon icon(editor_icon);
g_gui.root->SetIcon(icon);
if (g_settings.getInteger(Config::WELCOME_DIALOG) == 1 && m_file_to_open == wxEmptyString) {
g_gui.ShowWelcomeDialog(icon);
} else {
g_gui.root->Show();
}
// Set idle event handling mode
wxIdleEvent::SetMode(wxIDLE_PROCESS_SPECIFIED);
// Goto RME website?
if (g_settings.getInteger(Config::GOTO_WEBSITE_ON_BOOT) == 1) {
::wxLaunchDefaultBrowser(__SITE_URL__, wxBROWSER_NEW_WINDOW);
g_settings.setInteger(Config::GOTO_WEBSITE_ON_BOOT, 0);
}
// Check for updates
#ifdef _USE_UPDATER_
if (g_settings.getInteger(Config::USE_UPDATER) == -1) {
int ret = g_gui.PopupDialog(
"Notice",
"Do you want the editor to automatically check for updates?\n"
"It will connect to the internet if you choose yes.\n"
"You can change this setting in the preferences later.",
wxYES | wxNO
);
if (ret == wxID_YES) {
g_settings.setInteger(Config::USE_UPDATER, 1);
} else {
g_settings.setInteger(Config::USE_UPDATER, 0);
}
}
if (g_settings.getInteger(Config::USE_UPDATER) == 1) {
UpdateChecker updater;
updater.connect(g_gui.root);
}
#endif
FileName save_failed_file = GUI::GetLocalDataDirectory();
save_failed_file.SetName(".saving.txt");
if (save_failed_file.FileExists()) {
std::ifstream f(nstr(save_failed_file.GetFullPath()).c_str(), std::ios::in);
std::string backup_otbm, backup_house, backup_spawn;
getline(f, backup_otbm);
getline(f, backup_house);
getline(f, backup_spawn);
// Remove the file
f.close();
std::remove(nstr(save_failed_file.GetFullPath()).c_str());
// Query file retrieval if possible
if (!backup_otbm.empty()) {
long ret = g_gui.PopupDialog(
"Editor Crashed",
wxString(
"IMPORTANT! THE EDITOR CRASHED WHILE SAVING!\n\n"
"Do you want to recover the lost map? (it will be opened immediately):\n"
) << wxstr(backup_otbm)
<< "\n"
<< wxstr(backup_house) << "\n"
<< wxstr(backup_spawn) << "\n",
wxYES | wxNO
);
if (ret == wxID_YES) {
// Recover if the user so wishes
std::remove(backup_otbm.substr(0, backup_otbm.size() - 1).c_str());
std::rename(backup_otbm.c_str(), backup_otbm.substr(0, backup_otbm.size() - 1).c_str());
if (!backup_house.empty()) {
std::remove(backup_house.substr(0, backup_house.size() - 1).c_str());
std::rename(backup_house.c_str(), backup_house.substr(0, backup_house.size() - 1).c_str());
}
if (!backup_spawn.empty()) {
std::remove(backup_spawn.substr(0, backup_spawn.size() - 1).c_str());
std::rename(backup_spawn.c_str(), backup_spawn.substr(0, backup_spawn.size() - 1).c_str());
}
// Load the map
g_gui.LoadMap(wxstr(backup_otbm.substr(0, backup_otbm.size() - 1)));
return true;
}
}
}
// Keep track of first event loop entry
m_startup = true;
return true;
}
void Application::OnEventLoopEnter(wxEventLoopBase* loop) {
// First startup?
if (!m_startup) {
return;
}
m_startup = false;
// Don't try to create a map if we didn't load the client map.
if (ClientVersion::getLatestVersion() == nullptr) {
return;
}
// Open a map.
if (m_file_to_open != wxEmptyString) {
g_gui.LoadMap(FileName(m_file_to_open));
} else if (!g_gui.IsWelcomeDialogShown() && g_gui.NewMap()) { // Open a new empty map
// You generally don't want to save this map...
g_gui.GetCurrentEditor()->map.clearChanges();
}
}
void Application::MacOpenFiles(const wxArrayString& fileNames) {
if (!fileNames.IsEmpty()) {
g_gui.LoadMap(FileName(fileNames.Item(0)));
}
}
void Application::FixVersionDiscrapencies() {
// Here the registry should be fixed, if the version has been changed
if (g_settings.getInteger(Config::VERSION_ID) < MAKE_VERSION_ID(1, 0, 5)) {
g_settings.setInteger(Config::USE_MEMCACHED_SPRITES_TO_SAVE, 0);
}
if (g_settings.getInteger(Config::VERSION_ID) < __RME_VERSION_ID__ && ClientVersion::getLatestVersion() != nullptr) {
g_settings.setInteger(Config::DEFAULT_CLIENT_VERSION, ClientVersion::getLatestVersion()->getID());
}
wxString ss = wxstr(g_settings.getString(Config::SCREENSHOT_DIRECTORY));
if (ss.empty()) {
ss = wxStandardPaths::Get().GetDocumentsDir();
#ifdef __WINDOWS__
ss += "/My Pictures/RME/";
#endif
}
g_settings.setString(Config::SCREENSHOT_DIRECTORY, nstr(ss));
// Set registry to newest version
g_settings.setInteger(Config::VERSION_ID, __RME_VERSION_ID__);
}
void Application::Unload() {
g_gui.CloseAllEditors();
g_gui.UnloadVersion();
g_gui.SaveHotkeys();
g_gui.SavePerspective();
g_gui.root->SaveRecentFiles();
ClientVersion::saveVersions();
ClientVersion::unloadVersions();
g_settings.save(true);
g_gui.root = nullptr;
}
int Application::OnExit() {
// Shutdown Lua scripting system
g_luaScripts.shutdown();
#ifdef _USE_PROCESS_COM
wxDELETE(m_proc_server);
wxDELETE(m_single_instance_checker);
#endif
return 1;
}
void Application::OnFatalException() {
////
}
bool Application::ParseCommandLineMap(wxString& fileName) {
if (argc == 2) {
fileName = wxString(argv[1]);
return true;
} else if (argc == 3) {
if (argv[1] == "-ws") {
g_settings.setInteger(Config::WELCOME_DIALOG, argv[2] == "1" ? 1 : 0);
}
}
return false;
}
MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size) :
wxFrame((wxFrame*)nullptr, -1, title, pos, size, wxDEFAULT_FRAME_STYLE) {
// Receive idle events
SetExtraStyle(wxWS_EX_PROCESS_IDLE);
#if wxCHECK_VERSION(3, 1, 0) // 3.1.0 or higher
// Make sure ShowFullScreen() uses the full screen API on macOS
EnableFullScreenView(true);
#endif
// Creates the file-dropdown menu
menu_bar = newd MainMenuBar(this);
wxArrayString warnings;
wxString error;
wxFileName filename;
filename.Assign(g_gui.getFoundDataDirectory() + "menubar.xml");
if (!filename.FileExists()) {
filename = FileName(GUI::GetDataDirectory() + "menubar.xml");
}
if (!menu_bar->Load(filename, warnings, error)) {
wxLogError(wxString() + "Could not load menubar.xml, editor will NOT be able to show its menu.\n");
}
wxStatusBar* statusbar = CreateStatusBar();
statusbar->SetFieldsCount(4);
SetStatusText(wxString("Welcome to ") << __W_RME_APPLICATION_NAME__ << " " << __W_RME_VERSION__);
// Le sizer
g_gui.aui_manager = newd wxAuiManager(this);
g_gui.tabbook = newd MapTabbook(this, wxID_ANY);
tool_bar = newd MainToolBar(this, g_gui.aui_manager);
g_gui.aui_manager->AddPane(g_gui.tabbook, wxAuiPaneInfo().CenterPane().Floatable(false).CloseButton(false).PaneBorder(false));
// Create Script Manager panel (dockable)
LuaScriptsWindow* scriptsWindow = newd LuaScriptsWindow(this);
LuaScriptsWindow::SetInstance(scriptsWindow);
g_gui.aui_manager->AddPane(scriptsWindow, wxAuiPaneInfo().Name("ScriptManager").Caption("Script Manager").Right().CloseButton(true).MaximizeButton(false).MinimizeButton(false).Floatable(true).BestSize(450, 350).MinSize(300, 200).Hide() // Hidden by default, show from menu
);
g_gui.aui_manager->Update();
UpdateMenubar();
}
MainFrame::~MainFrame() = default;
void MainFrame::OnIdle(wxIdleEvent& event) {
////
}
#ifdef _USE_UPDATER_
void MainFrame::OnUpdateReceived(wxCommandEvent& event) {
std::string data = *(std::string*)event.GetClientData();
delete (std::string*)event.GetClientData();
try {
json::mValue val;
if (!json::read(data, val)) {
return;
}
json::mObject& obj = val.get_obj();
if (obj.count("tag_name") == 0) {
return;
}
std::string tag = obj["tag_name"].get_str();
if (!tag.empty() && (tag[0] == 'v' || tag[0] == 'V')) {
tag = tag.substr(1);
}
// Parse version
int major = 0, minor = 0, patch = 0;
sscanf(tag.c_str(), "%d.%d.%d", &major, &minor, &patch);
int remoteVersion = MAKE_VERSION_ID(major, minor, patch);
int localVersion = __RME_VERSION_ID__;
if (remoteVersion > localVersion) {
std::string url = obj["html_url"].get_str();
std::string name = obj["name"].get_str();
int ret = g_gui.PopupDialog(
"Update Notice",
wxString("There is a new update available (") << wxstr(name) << "). Do you want to go to the download page?",
wxYES | wxNO,
"I don't want any update notices",
Config::AUTOCHECK_FOR_UPDATES
);
if (ret == wxID_YES) {
::wxLaunchDefaultBrowser(wxstr(url), wxBROWSER_NEW_WINDOW);
}
}
} catch (...) {
// Error parsing JSON, silently ignore
}
}
#endif
void MainFrame::OnUpdateMenus(wxCommandEvent&) {
UpdateMenubar();
g_gui.UpdateMinimap(true);
g_gui.UpdateTitle();
}
#ifdef __WINDOWS__
bool MainFrame::MSWTranslateMessage(WXMSG* msg) {
if (g_gui.AreHotkeysEnabled()) {
if (wxFrame::MSWTranslateMessage(msg)) {
return true;
}
} else {
if (wxWindow::MSWTranslateMessage(msg)) {
return true;
}
}
return false;
}
#endif
void MainFrame::UpdateMenubar() {
menu_bar->Update();
tool_bar->UpdateButtons();
}
bool MainFrame::DoQueryClose() {
Editor* editor = g_gui.GetCurrentEditor();
if (editor) {
if (editor->IsLive()) {
long ret = g_gui.PopupDialog(
"Must Close Server",
wxString("You are currently connected to a live server, to close this map the connection must be severed."),
wxOK | wxCANCEL
);
if (ret == wxID_OK) {
editor->CloseLiveServer();
} else {
return false;
}
}
}
return true;
}
bool MainFrame::DoQuerySaveTileset(bool doclose) {
if (!g_materials.needSave()) {
// skip dialog when there is nothing to save
return true;
}
long ret = g_gui.PopupDialog(
"Export tileset",
"Do you want to export your tileset changes before exiting?",
wxYES | wxNO | wxCANCEL
);
if (ret == wxID_NO) {
// "no" - exit without saving
return true;
} else if (ret == wxID_CANCEL) {
// "cancel" - just close the dialog
return false;
}
// "yes" button was pressed, open tileset exporting dialog
if (g_gui.GetCurrentEditor()) {
ExportTilesetsWindow dlg(this, *g_gui.GetCurrentEditor());
dlg.ShowModal();
dlg.Destroy();
}
return !g_materials.needSave();
}
bool MainFrame::DoQuerySave(bool doclose) {
if (!g_gui.IsEditorOpen()) {
return true;
}
if (!DoQuerySaveTileset()) {
return false;
}
Editor& editor = *g_gui.GetCurrentEditor();
if (editor.IsLiveClient()) {
long ret = g_gui.PopupDialog(
"Disconnect",
"Do you want to disconnect?",
wxYES | wxNO
);
if (ret != wxID_YES) {
return false;
}
editor.CloseLiveServer();
return DoQuerySave(doclose);
} else if (editor.IsLiveServer()) {
long ret = g_gui.PopupDialog(
"Shutdown",
"Do you want to shut down the server? (any clients will be disconnected)",
wxYES | wxNO
);
if (ret != wxID_YES) {
return false;
}
editor.CloseLiveServer();
return DoQuerySave(doclose);
} else if (g_gui.ShouldSave()) {
long ret = g_gui.PopupDialog(
"Save changes",
"Do you want to save your changes to \"" + wxstr(g_gui.GetCurrentMap().getName()) + "\"?",
wxYES | wxNO | wxCANCEL
);
if (ret == wxID_YES) {
if (g_gui.GetCurrentMap().hasFile()) {
g_gui.SaveCurrentMap(true);
} else {
wxFileDialog file(this, "Save...", "", "", "*.otbm", wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
int32_t result = file.ShowModal();
if (result == wxID_OK) {
g_gui.SaveCurrentMap(file.GetPath(), true);
} else {
return false;
}
}
} else if (ret == wxID_CANCEL) {
return false;
}
}
if (doclose) {
UnnamedRenderingLock();
g_gui.CloseCurrentEditor();
}
return true;
}
bool MainFrame::DoQueryImportCreatures() {
if (g_creatures.hasMissing()) {
long ret = g_gui.PopupDialog("Missing creatures", "There are missing creatures and/or NPC in the editor, do you want to load them from an OT monster/npc file?", wxYES | wxNO);
if (ret == wxID_YES) {
do {
wxFileDialog dlg(g_gui.root, "Import monster/npc file", "", "", "*.xml", wxFD_OPEN | wxFD_MULTIPLE | wxFD_FILE_MUST_EXIST);
if (dlg.ShowModal() == wxID_OK) {
wxArrayString paths;
dlg.GetPaths(paths);
for (uint32_t i = 0; i < paths.GetCount(); ++i) {
wxString error;
wxArrayString warnings;
bool ok = g_creatures.importXMLFromOT(FileName(paths[i]), error, warnings);
if (ok) {
g_gui.ListDialog("Monster loader errors", warnings);
} else {
wxMessageBox("Error OT data file \"" + paths[i] + "\".\n" + error, "Error", wxOK | wxICON_INFORMATION, g_gui.root);
}
}
} else {
break;
}
} while (g_creatures.hasMissing());
}
}
g_gui.RefreshPalettes();
return true;
}
void MainFrame::UpdateFloorMenu() {
menu_bar->UpdateFloorMenu();
}
bool MainFrame::LoadMap(FileName name) {
return g_gui.LoadMap(name);
}
void MainFrame::OnExit(wxCloseEvent& event) {
// clicking 'x' button
// do you want to save map changes?
while (g_gui.IsEditorOpen()) {
if (!DoQuerySave()) {
if (event.CanVeto()) {
event.Veto();
return;
} else {
break;
}
}
}
g_gui.aui_manager->UnInit();
((Application&)wxGetApp()).Unload();
#ifdef __RELEASE__
// Hack, "crash" gracefully in release builds, let OS handle cleanup of windows
exit(0);
#endif
Destroy();
}
void MainFrame::AddRecentFile(const FileName& file) {
menu_bar->AddRecentFile(file);
}
void MainFrame::LoadRecentFiles() {
menu_bar->LoadRecentFiles();
}
void MainFrame::SaveRecentFiles() {
menu_bar->SaveRecentFiles();
}
std::vector<wxString> MainFrame::GetRecentFiles() {
return menu_bar->GetRecentFiles();
}
void MainFrame::PrepareDC(wxDC& dc) {
dc.SetLogicalOrigin(0, 0);
dc.SetAxisOrientation(1, 0);
dc.SetUserScale(1.0, 1.0);
dc.SetMapMode(wxMM_TEXT);
}