MainWindow.cpp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. /*
  2. * This file is part of XDRE.
  3. *
  4. * XDRE is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * XDRE is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with XDRE. If not, see <http://www.gnu.org/licenses/>.
  16. *
  17. * Этот файл — часть XDRE.
  18. *
  19. * XDRE — свободная программа: вы можете перераспространять её и/или
  20. * изменять её на условиях Стандартной общественной лицензии GNU в том виде,
  21. * в каком она была опубликована Фондом свободного программного обеспечения;
  22. * либо версии 2 лицензии, либо (по вашему выбору) любой более поздней
  23. * версии.
  24. *
  25. * XDRE распространяется в надежде, что она будет полезной,
  26. * но БЕЗО ВСЯКИХ ГАРАНТИЙ; даже без неявной гарантии ТОВАРНОГО ВИДА
  27. * или ПРИГОДНОСТИ ДЛЯ ОПРЕДЕЛЕННЫХ ЦЕЛЕЙ. Подробнее см. в Стандартной
  28. * общественной лицензии GNU.
  29. *
  30. * Вы должны были получить копию Стандартной общественной лицензии GNU
  31. * вместе с этой программой. Если это не так, см.
  32. * <http://www.gnu.org/licenses/>.
  33. *
  34. * Description: main XDRE window (command line, traces etc.).
  35. */
  36. #include "MainWindow.hpp"
  37. #include <wx/intl.h>
  38. #include <wx/string.h>
  39. #include <wx/valnum.h>
  40. #include <wx/msgdlg.h>
  41. #include <wx/filedlg.h>
  42. #include <wx/ffile.h>
  43. #include <wx/tokenzr.h>
  44. #include "BruteDialog.hpp"
  45. #include "HeaderDialog.hpp"
  46. #include "KeysDialog.hpp"
  47. #include "xdre.hpp"
  48. #include "config.h"
  49. //for wxSscanf()
  50. #include <wx/crt.h>
  51. //for SDL_SetWindowPosition()
  52. #include "SDL.h"
  53. extern SDL_Window *sdl_window;
  54. const long MainWindow::ID_INPUTFIELD = wxNewId();
  55. const long MainWindow::ID_LINEDEFCONTROL = wxNewId();
  56. const long MainWindow::ID_LINEADD = wxNewId();
  57. const long MainWindow::ID_SECTORCONTROL = wxNewId();
  58. const long MainWindow::ID_SECTORADD = wxNewId();
  59. const long MainWindow::ID_THINGCONTROL = wxNewId();
  60. const long MainWindow::ID_THINGADD = wxNewId();
  61. const long MainWindow::ID_STYLECHOICE = wxNewId();
  62. const long MainWindow::ID_ANGLETYPE = wxNewId();
  63. const long MainWindow::IDM_LOAD = wxNewId();
  64. const long MainWindow::IDM_SAVE = wxNewId();
  65. const long MainWindow::IDM_EXIT = wxNewId();
  66. const long MainWindow::IDM_BRUTE = wxNewId();
  67. const long MainWindow::IDM_PALSTUFF = wxNewId();
  68. const long MainWindow::IDM_SETKEYS = wxNewId();
  69. const long MainWindow::IDM_HEADER = wxNewId();
  70. const long MainWindow::IDM_CLEARTRACES = wxNewId();
  71. BEGIN_EVENT_TABLE(MainWindow, wxFrame)
  72. END_EVENT_TABLE()
  73. MainWindow::MainWindow(wxWindow* parent, wxWindowID id, wxPoint const& pos, wxSize const& size) {
  74. SetKeys();
  75. Create(parent, id, PACKAGE_STRING, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE);
  76. SetClientSize(wxSize(640,520));
  77. int x, y;
  78. //"-1,-1" is wxDefaultPosition
  79. wxSscanf(config.Read("WindowPos", "-1,-1"), "%d,%d", &x, &y);
  80. Move(x, y);
  81. wxString str(config.Read("DoomWindowPos", "center"));
  82. if(str == "centre" || str == "center")
  83. SDL_SetWindowPosition(sdl_window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
  84. else {
  85. wxSscanf(str, "%d,%d", &x, &y);
  86. SDL_SetWindowPosition(sdl_window, x, y);
  87. }
  88. str = config.Read("SavepointMode", "1");
  89. str.ToLong((long*)&x);
  90. if(x < SP_NOSAVE && x > SP_AUTO) x = SP_START;
  91. xdre::setSavepointStyle(x);
  92. str.Clear();
  93. SetMinSize(wxSize(640,520));
  94. SetMaxSize(wxSize(640,520));
  95. p = new wxPanel(this);
  96. StaticText1 = new wxStaticText(p, wxID_ANY, _("(P)RNG index"), wxPoint(476,44));
  97. StaticText2 = new wxStaticText(p, wxID_ANY, _("Input"), wxPoint(526,12));
  98. StaticText3 = new wxStaticText(p, wxID_ANY, _("X"), wxPoint(236,76));
  99. StaticText4 = new wxStaticText(p, wxID_ANY, _("Y"), wxPoint(380,76));
  100. StaticText24 = new wxStaticText(p, wxID_ANY,_("Z"), wxPoint(524,76));
  101. StaticText22 = new wxStaticText(p, wxID_ANY, _("X dist."), wxPoint(236,108));
  102. StaticText23 = new wxStaticText(p, wxID_ANY, _("Y dist."), wxPoint(380,108));
  103. StaticText25 = new wxStaticText(p, wxID_ANY, _("Z dist."), wxPoint(524,108));
  104. StaticText5 = new wxStaticText(p, wxID_ANY, _("X mom."), wxPoint(236,140));
  105. StaticText6 = new wxStaticText(p, wxID_ANY, _("Y mom."), wxPoint(380,140));
  106. StaticText7 = new wxStaticText(p, wxID_ANY, _("Distance moved"), wxPoint(424,172));
  107. StaticText8 = new wxStaticText(p, wxID_ANY, _("Direction moved"),wxPoint(424,204));
  108. StaticText9 = new wxStaticText(p, wxID_ANY, _("Angle"), wxPoint(496,236));
  109. StaticText10 = new wxStaticText(p, wxID_ANY, _("Linedef"), wxPoint(472,300));
  110. StaticText11 = new wxStaticText(p, wxID_ANY, _("Hit special"), wxPoint(508,332));
  111. StaticText12 = new wxStaticText(p, wxID_ANY, _("X"), wxPoint(528,352));
  112. StaticText13 = new wxStaticText(p, wxID_ANY, _("Y"), wxPoint(584,352));
  113. StaticText14 = new wxStaticText(p, wxID_ANY, _("V. 1"), wxPoint(480,372));
  114. StaticText15 = new wxStaticText(p, wxID_ANY, _("V. 2"), wxPoint(480,396));
  115. StaticText16 = new wxStaticText(p, wxID_ANY, _("Dist. from line"), wxPoint(432,428));
  116. StaticText17 = new wxStaticText(p, wxID_ANY, _("Current tic"), wxPoint(64,428));
  117. StaticText18 = new wxStaticText(p, wxID_ANY, _("Used a line"), wxPoint(196,364));
  118. StaticText19 = new wxStaticText(p, wxID_ANY, _("Damage done"), wxPoint(184,396));
  119. StaticText20 = new wxStaticText(p, wxID_ANY, _("Time"), wxPoint(224,428));
  120. StaticText21 = new wxStaticText(p, wxID_ANY, _("Savepoint"), wxPoint(68,396));
  121. StaticText26 = new wxStaticText(p, wxID_ANY, _("Sector"), wxPoint(384,324));
  122. StaticText27 = new wxStaticText(p, wxID_ANY, _("Floor"), wxPoint(384,348));
  123. StaticText28 = new wxStaticText(p, wxID_ANY, _("Ceiling"), wxPoint(384,372));
  124. StaticText29 = new wxStaticText(p, wxID_ANY, _("Effect"), wxPoint(384,396));
  125. StaticText30 = new wxStaticText(p, wxID_ANY, _("Thing"), wxPoint(188,168));
  126. StaticText31 = new wxStaticText(p, wxID_ANY, _("X"), wxPoint(188,192));
  127. StaticText32 = new wxStaticText(p, wxID_ANY, _("Y"), wxPoint(188,216));
  128. StaticText33 = new wxStaticText(p, wxID_ANY, _("Z"), wxPoint(188,240));
  129. StaticText34 = new wxStaticText(p, wxID_ANY, _("Radius"), wxPoint(188,264));
  130. StaticText35 = new wxStaticText(p, wxID_ANY, _("Tics"), wxPoint(320,192));
  131. StaticText36 = new wxStaticText(p, wxID_ANY, _("Health"), wxPoint(320,216));
  132. StaticText37 = new wxStaticText(p, wxID_ANY, _("Reaction time"), wxPoint(320,240));
  133. StaticText38 = new wxStaticText(p, wxID_ANY, _("Threshold"), wxPoint(320,264));
  134. inputField = new wxTextCtrl(p, ID_INPUTFIELD, wxEmptyString, wxPoint(568,8), wxSize(52,21), wxTE_RIGHT);
  135. inputField->SetMaxLength(10);
  136. rngIndex = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(568,40), wxSize(52,21), wxTE_READONLY|wxTE_RIGHT);
  137. xPos = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(288,72), wxSize(84,21), wxTE_READONLY|wxTE_RIGHT);
  138. yPos = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(432,72), wxSize(84,21), wxTE_READONLY|wxTE_RIGHT);
  139. zPos = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(568,72), wxSize(52,21), wxTE_READONLY|wxTE_RIGHT);
  140. xMom = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(288,136), wxSize(84,21), wxTE_READONLY|wxTE_RIGHT);
  141. yMom = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(432,136), wxSize(84,21), wxTE_READONLY|wxTE_RIGHT);
  142. xDist = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(288,104), wxSize(84,21), wxTE_READONLY|wxTE_RIGHT);
  143. yDist = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(432,104), wxSize(84,21), wxTE_READONLY|wxTE_RIGHT);
  144. zDist = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(568,104), wxSize(52,21), wxTE_READONLY|wxTE_RIGHT);
  145. distanceMoved = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(536,168), wxSize(84,21), wxTE_READONLY|wxTE_RIGHT);
  146. directionMoved = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(536,200), wxSize(84,21), wxTE_READONLY|wxTE_RIGHT);
  147. playerAngle = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(536,232), wxSize(52,21), wxTE_READONLY|wxTE_RIGHT);
  148. AngleType = new wxChoice(p, ID_ANGLETYPE, wxPoint(508,264), wxSize(108,28), 0, 0, 0, wxDefaultValidator);
  149. AngleType->Append(_("longtics"));
  150. AngleType->Append(_("fine angles"));
  151. AngleType->Append(_("degrees"));
  152. AngleType->Append(_("byte angles"));
  153. AngleType->SetSelection(config.ReadLong("AngleType", 0));
  154. linedefInputField = new wxComboBox(p, ID_LINEDEFCONTROL, wxEmptyString, wxPoint(524,296), wxSize(60,28), 0, 0, 0, wxIntegerValidator<unsigned int>());
  155. linedefInputField->SetMaxLength(10);
  156. wxStringTokenizer tok(config.Read("LinedefNums", "0"), ",");
  157. while(tok.HasMoreTokens()) linedefInputField->Append(tok.GetNextToken());
  158. linedefInputField->SetSelection(0);
  159. linedefAdd = new wxButton(p, ID_LINEADD, _("Add"), wxPoint(588,296), wxSize(26,21), 0);
  160. crossed = new wxTextCtrl(p, wxID_ANY, _("false"), wxPoint(560,328), wxSize(52,21), wxTE_READONLY|wxTE_RIGHT);
  161. linedefXV1 = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(504,368), wxSize(52,21), wxTE_READONLY|wxTE_RIGHT);
  162. linedefYV1 = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(560,368), wxSize(52,21), wxTE_READONLY|wxTE_RIGHT);
  163. linedefXV2 = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(504,392), wxSize(52,21), wxTE_READONLY|wxTE_RIGHT);
  164. linedefYV2 = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(560,392), wxSize(52,21), wxTE_READONLY|wxTE_RIGHT);
  165. distanceFromLine = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(528,424), wxSize(84,21), wxTE_READONLY|wxTE_RIGHT);
  166. sectorInputField = new wxComboBox(p, ID_SECTORCONTROL, wxEmptyString, wxPoint(416,320), wxSize(60,21), 0, 0, 0, wxIntegerValidator<unsigned int>());
  167. sectorInputField->SetMaxLength(10);
  168. tok.SetString(config.Read("SectorNums", "0"), ",");
  169. while(tok.HasMoreTokens()) sectorInputField->Append(tok.GetNextToken());
  170. sectorInputField->SetSelection(0);
  171. sectorAdd = new wxButton(p, ID_SECTORADD, _("Add"), wxPoint(476,320), wxSize(26,21), 0);
  172. floorheight = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(420,344), wxSize(52,21), wxTE_READONLY|wxTE_RIGHT);
  173. ceilingheight = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(420,368), wxSize(52,21), wxTE_READONLY|wxTE_RIGHT);
  174. special = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(420,392), wxSize(52,21), wxTE_READONLY|wxTE_RIGHT);
  175. thingInputField = new wxComboBox(p, ID_THINGCONTROL, wxEmptyString, wxPoint(232,164), wxSize(60,21), 0, 0, 0, wxIntegerValidator<unsigned int>());
  176. thingInputField->SetMaxLength(10);
  177. tok.SetString(config.Read("ThingNums", "0"), ",");
  178. while(tok.HasMoreTokens()) thingInputField->Append(tok.GetNextToken());
  179. thingInputField->SetSelection(0);
  180. thingAdd = new wxButton(p, ID_THINGADD, _("Add"), wxPoint(296,164), wxSize(26,21), 0);
  181. thingX = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(232,188), wxSize(84,21), wxTE_READONLY|wxTE_RIGHT);
  182. thingY = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(232,212), wxSize(84,21), wxTE_READONLY|wxTE_RIGHT);
  183. thingZ = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(232,236), wxSize(52,21), wxTE_READONLY|wxTE_RIGHT);
  184. thingRadius = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(232,260), wxSize(52,21), wxTE_READONLY|wxTE_RIGHT);
  185. thingTics = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(388,188), wxSize(40,21), wxTE_READONLY|wxTE_RIGHT);
  186. thingHealth = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(388,212), wxSize(40,21), wxTE_READONLY|wxTE_RIGHT);
  187. thingReactionTime = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(388,236), wxSize(40,21), wxTE_READONLY|wxTE_RIGHT);
  188. thingThreshold = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(388,260), wxSize(40,21), wxTE_READONLY|wxTE_RIGHT);
  189. useSuccess = new wxTextCtrl(p, wxID_ANY, _("false"), wxPoint(260,360), wxSize(60,21), wxTE_READONLY|wxTE_RIGHT);
  190. damageDone = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(260,392), wxSize(60,21), wxTE_READONLY|wxTE_RIGHT);
  191. time = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(260,424), wxSize(60,21), wxTE_READONLY|wxTE_RIGHT);
  192. currentTic = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(120,424), wxSize(60,21), wxTE_READONLY|wxTE_RIGHT);
  193. ticlist = new TiclistCtrl(p, wxID_ANY, wxPoint(16,16), wxSize(170,368));
  194. savepointTic = new wxTextCtrl(p, wxID_ANY, _("0"), wxPoint(120,392), wxSize(60,21), wxTE_READONLY|wxTE_RIGHT);
  195. styleChoice = new wxChoice(p, ID_STYLECHOICE, wxPoint(16,392), wxSize(48,21), 0, 0, 0);
  196. styleChoice->Append(_("User"));
  197. styleChoice->Append(_("Start"));
  198. styleChoice->Append(_("Auto"));
  199. styleChoice->SetSelection(x);
  200. menuBar = new wxMenuBar();
  201. menuFile = new wxMenu();
  202. MenuItem1 = new wxMenuItem(menuFile, IDM_LOAD, _("Load"), wxEmptyString, wxITEM_NORMAL);
  203. MenuItem2 = new wxMenuItem(menuFile, IDM_SAVE, _("Save"), wxEmptyString, wxITEM_NORMAL);
  204. MenuItem3 = new wxMenuItem(menuFile, IDM_EXIT, _("Exit"), wxEmptyString, wxITEM_NORMAL);
  205. MenuItem4 = new wxMenuItem(menuTools, IDM_BRUTE, _("Brute force"), wxEmptyString, wxITEM_NORMAL);
  206. MenuItem5 = new wxMenuItem(menuOptions, IDM_SETKEYS, _("Set keys"), wxEmptyString, wxITEM_NORMAL);
  207. MenuItem6 = new wxMenuItem(menuTools, IDM_HEADER, _("Edit header"), wxEmptyString, wxITEM_NORMAL);
  208. menuTools = new wxMenu();
  209. menuOptions = new wxMenu();
  210. MenuItem7 = new wxMenuItem(menuOptions, IDM_PALSTUFF, _("Palette stuff"), wxEmptyString, wxITEM_CHECK);
  211. MenuItem8 = new wxMenuItem(menuOptions, IDM_CLEARTRACES, _("Clear all traces"), wxEmptyString, wxITEM_NORMAL);
  212. menuDemo = new wxMenu();
  213. SetMenuBar(menuBar);
  214. menuBar->Append(menuFile, _("File"));
  215. menuBar->Append(menuTools, _("Tools"));
  216. menuBar->Append(menuOptions, _("Options"));
  217. menuFile->Append(MenuItem1);
  218. menuFile->Append(MenuItem2);
  219. menuFile->Append(MenuItem3);
  220. menuTools->Append(MenuItem4);
  221. menuTools->Append(MenuItem6);
  222. menuOptions->Append(MenuItem5);
  223. menuOptions->Append(MenuItem7);
  224. menuOptions->Append(MenuItem8);
  225. MenuItem7->Check(true);
  226. Connect(ID_INPUTFIELD, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler(MainWindow::OnInputFieldText));
  227. Connect(ID_ANGLETYPE, wxEVT_CHOICE, wxCommandEventHandler(MainWindow::OnAngleType));
  228. Connect(ID_LINEDEFCONTROL, wxEVT_TEXT, wxCommandEventHandler(MainWindow::OnLinedefInput));
  229. Connect(ID_LINEDEFCONTROL, wxEVT_COMBOBOX, wxCommandEventHandler(MainWindow::OnLinedefInput));
  230. Connect(ID_LINEADD, wxEVT_BUTTON, wxCommandEventHandler(MainWindow::OnLineAdd));
  231. Connect(ID_SECTORCONTROL, wxEVT_TEXT, wxCommandEventHandler(MainWindow::OnSectorInput));
  232. Connect(ID_SECTORCONTROL, wxEVT_COMBOBOX, wxCommandEventHandler(MainWindow::OnSectorInput));
  233. Connect(ID_SECTORADD, wxEVT_BUTTON, wxCommandEventHandler(MainWindow::OnSectorAdd));
  234. Connect(ID_THINGCONTROL, wxEVT_TEXT, wxCommandEventHandler(MainWindow::OnThingInput));
  235. Connect(ID_THINGCONTROL, wxEVT_COMBOBOX, wxCommandEventHandler(MainWindow::OnThingInput));
  236. Connect(ID_THINGADD, wxEVT_BUTTON, wxCommandEventHandler(MainWindow::OnThingAdd));
  237. Connect(ID_STYLECHOICE, wxEVT_CHOICE, wxCommandEventHandler(MainWindow::OnStyleChoiceSelect));
  238. Connect(IDM_LOAD, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainWindow::OnMenuLoad));
  239. Connect(IDM_SAVE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainWindow::OnMenuSave));
  240. Connect(IDM_EXIT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainWindow::OnMenuExit));
  241. Connect(IDM_BRUTE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainWindow::OnMenuBrute));
  242. Connect(IDM_SETKEYS, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainWindow::OnMenuSetKeys));
  243. Connect(IDM_PALSTUFF, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainWindow::OnMenuPalStuff));
  244. Connect(IDM_HEADER, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainWindow::OnMenuHeader));
  245. Connect(IDM_CLEARTRACES, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainWindow::OnMenuClearTraces));
  246. Connect(wxID_ANY, wxEVT_CLOSE_WINDOW, wxCloseEventHandler(MainWindow::OnClose));
  247. Connect(wxID_ANY, wxEVT_IDLE, wxCommandEventHandler(MainWindow::OnIdle));
  248. xdre::setAngleType(AngleType->GetSelection());
  249. linedefXV1->ChangeValue(wxString::FromCDouble(xdre::getLinedefVertex(0, 0), 0));
  250. linedefYV1->ChangeValue(wxString::FromCDouble(xdre::getLinedefVertex(0, 1), 0));
  251. linedefXV2->ChangeValue(wxString::FromCDouble(xdre::getLinedefVertex(1, 0), 0));
  252. linedefYV2->ChangeValue(wxString::FromCDouble(xdre::getLinedefVertex(1, 1), 0));
  253. RS();
  254. }
  255. MainWindow::~MainWindow() {}
  256. void MainWindow::DoInput(XCmd cmd, unsigned int val) {
  257. switch(cmd) {
  258. case XCmd::Fire: xdre::toggleFire(); RS(); break;
  259. case XCmd::Use: xdre::toggleUse(); RS(); break;
  260. case XCmd::TurnStepLeft: xdre::turnStepLeft(); RS(); break;
  261. case XCmd::TurnStepRight: xdre::turnStepRight(); RS(); break;
  262. case XCmd::TurnStep: xdre::setTurnStep(val); break;
  263. case XCmd::PrevTic: xdre::seekDemo(-1); RS(); break;
  264. case XCmd::NextTic: xdre::seekDemo(1); RS(); break;
  265. case XCmd::CopyTic: xdre::copyTic(); RS(); break;
  266. case XCmd::CopyTicX: xdre::copyTicX(val); RS(); break;
  267. case XCmd::DeleteTic: xdre::deleteTic(); RS(); break;
  268. case XCmd::DeleteTicX: xdre::deleteTicX(val); RS(); break;
  269. case XCmd::NewTic: xdre::newTic(); RS(); break;
  270. case XCmd::ToggleBlood: xdre::toggleBlood();MenuItem7->Check(xdre::getBlood());break;
  271. case XCmd::SetSavepoint: xdre::setSavepoint(); RS(); break;
  272. case XCmd::UnsetSavepoint:xdre::unsetSavepoint(); RS(); break;
  273. case XCmd::Load: Load(); break;
  274. case XCmd::Save: Save(); break;
  275. case XCmd::Exit: Quit(); break;
  276. case XCmd::RunBwd: xdre::run(-val); RS(); break;
  277. case XCmd::RunFwd: xdre::run(val); RS(); break;
  278. case XCmd::StrafeLeft: xdre::strafe(-val); RS(); break;
  279. case XCmd::StrafeRight: xdre::strafe(val); RS(); break;
  280. case XCmd::TurnLeft: xdre::turn(val); RS(); break;
  281. case XCmd::TurnRight: xdre::turn(-val); RS(); break;
  282. case XCmd::Weapon: xdre::changeWeapon(val);RS(); break;
  283. case XCmd::TransposeLeft: xdre::transpose(0, val);RS(); break;
  284. case XCmd::TransposeRight:xdre::transpose(1, val);RS(); break;
  285. case XCmd::BackwardDemo: xdre::seekDemo(-val); RS(); break;
  286. case XCmd::ForwardDemo: xdre::seekDemo(val); RS(); break;
  287. case XCmd::ChangePlayer: xdre::changePlayerView(val);RS();break;
  288. default: break;
  289. }
  290. }
  291. void MainWindow::SetKeys() {
  292. configToStringMap.clear();
  293. configToStringMap["Fire"] = config.Read("Fire", "f");
  294. configToStringMap["Use"] = config.Read("Use", "u");
  295. configToStringMap["TurnStepLeft"] = config.Read("TurnStepLeft", "-");
  296. configToStringMap["TurnStepRight"] = config.Read("TurnStepRight", "+");
  297. configToStringMap["TurnStep"] = config.Read("TurnStep", "ts");
  298. configToStringMap["PrevTic"] = config.Read("PrevTic", "j");
  299. configToStringMap["NextTic"] = config.Read("NextTic", "i");
  300. configToStringMap["CopyTic"] = config.Read("CopyTic", "c");
  301. configToStringMap["DeleteTic"] = config.Read("DeleteTic", "x");;
  302. configToStringMap["NewTic"] = config.Read("NewTic", "n");
  303. configToStringMap["ToggleBlood"] = config.Read("ToggleBlood", "z");
  304. configToStringMap["SetSavepoint"] = config.Read("SetSavepoint", "ssp");
  305. configToStringMap["UnsetSavepoint"] = config.Read("UnsetSavepoint", "pss");
  306. configToStringMap["Load"] = config.Read("Load", "load");
  307. configToStringMap["Save"] = config.Read("Save", "save");
  308. configToStringMap["Exit"] = config.Read("Exit", "exit");
  309. configToStringMap["RunBwd"] = config.Read("RunBwd", "wq");
  310. configToStringMap["RunFwd"] = config.Read("RunFwd", "we");
  311. configToStringMap["StrafeLeft"] = config.Read("StrafeLeft", "sa");
  312. configToStringMap["StrafeRight"] = config.Read("StrafeRight", "sd");
  313. configToStringMap["TurnLeft"] = config.Read("TurnLeft", "re");
  314. configToStringMap["TurnRight"] = config.Read("TurnRight", "rt");
  315. configToStringMap["Weapon"] = config.Read("Weapon", "g");
  316. configToStringMap["TransposeLeft"] = config.Read("TransposeLeft", "tr");
  317. configToStringMap["TransposeRight"] = config.Read("TransposeRight", "ty");
  318. configToStringMap["CopyTicX"] = config.Read("CopyTicX", "tc");
  319. configToStringMap["DeleteTicX"] = config.Read("DeleteTicX", "tx");
  320. configToStringMap["BackwardDemo"] = config.Read("BackwardDemo", ",");
  321. configToStringMap["ForwardDemo"] = config.Read("ForwardDemo", ".");
  322. configToStringMap["ChangePlayer"] = config.Read("ChangePlayer", "v");
  323. stringToCommandMap.clear();
  324. stringToCommandMap[configToStringMap["Fire"]] = XCmd::Fire;
  325. stringToCommandMap[configToStringMap["Use"]] = XCmd::Use;
  326. stringToCommandMap[configToStringMap["TurnStepLeft"]] = XCmd::TurnStepLeft;
  327. stringToCommandMap[configToStringMap["TurnStepRight"]] = XCmd::TurnStepRight;
  328. stringToCommandMap[configToStringMap["TurnStep"]] = XCmd::TurnStep;
  329. stringToCommandMap[configToStringMap["PrevTic"]] = XCmd::PrevTic;
  330. stringToCommandMap[configToStringMap["NextTic"]] = XCmd::NextTic;
  331. stringToCommandMap[configToStringMap["CopyTic"]] = XCmd::CopyTic;
  332. stringToCommandMap[configToStringMap["DeleteTic"]] = XCmd::DeleteTic;
  333. stringToCommandMap[configToStringMap["NewTic"]] = XCmd::NewTic;
  334. stringToCommandMap[configToStringMap["ToggleBlood"]] = XCmd::ToggleBlood;
  335. stringToCommandMap[configToStringMap["SetSavepoint"]] = XCmd::SetSavepoint;
  336. stringToCommandMap[configToStringMap["UnsetSavepoint"]] = XCmd::UnsetSavepoint;
  337. stringToCommandMap[configToStringMap["Load"]] = XCmd::Load;
  338. stringToCommandMap[configToStringMap["Save"]] = XCmd::Save;
  339. stringToCommandMap[configToStringMap["Exit"]] = XCmd::Exit;
  340. stringToCommandMap[configToStringMap["RunBwd"]] = XCmd::RunBwd;
  341. stringToCommandMap[configToStringMap["RunFwd"]] = XCmd::RunFwd;
  342. stringToCommandMap[configToStringMap["StrafeLeft"]] = XCmd::StrafeLeft;
  343. stringToCommandMap[configToStringMap["StrafeRight"]] = XCmd::StrafeRight;
  344. stringToCommandMap[configToStringMap["TurnLeft"]] = XCmd::TurnLeft;
  345. stringToCommandMap[configToStringMap["TurnRight"]] = XCmd::TurnRight;
  346. stringToCommandMap[configToStringMap["Weapon"]] = XCmd::Weapon;
  347. stringToCommandMap[configToStringMap["TransposeLeft"]] = XCmd::TransposeLeft;
  348. stringToCommandMap[configToStringMap["TransposeRight"]] = XCmd::TransposeRight;
  349. stringToCommandMap[configToStringMap["CopyTicX"]] = XCmd::CopyTicX;
  350. stringToCommandMap[configToStringMap["DeleteTicX"]] = XCmd::DeleteTicX;
  351. stringToCommandMap[configToStringMap["BackwardDemo"]] = XCmd::BackwardDemo;
  352. stringToCommandMap[configToStringMap["ForwardDemo"]] = XCmd::ForwardDemo;
  353. stringToCommandMap[configToStringMap["ChangePlayer"]] = XCmd::ChangePlayer;
  354. }
  355. void MainWindow::RS() { //RefreshStuff
  356. rngIndex->ChangeValue(wxString::FromCDouble(xdre::getRngIndex()));
  357. xPos->ChangeValue(wxString::FromCDouble(xdre::getXPos(), 6));
  358. yPos->ChangeValue(wxString::FromCDouble(xdre::getYPos(), 6));
  359. zPos->ChangeValue(wxString::FromCDouble(xdre::getZPos(), 2)); //2 for slow stairs
  360. xMom->ChangeValue(wxString::FromCDouble(xdre::getXMom(), 6));
  361. yMom->ChangeValue(wxString::FromCDouble(xdre::getYMom(), 6));
  362. xDist->ChangeValue(wxString::FromCDouble(xdre::getXDist(), 6));
  363. yDist->ChangeValue(wxString::FromCDouble(xdre::getYDist(), 6));
  364. zDist->ChangeValue(wxString::FromCDouble(xdre::getZDist(), 2));
  365. distanceMoved->ChangeValue(wxString::FromCDouble(xdre::getDistanceMoved(), 6));
  366. directionMoved->ChangeValue(wxString::FromCDouble(xdre::getDirectionMoved(), 6));
  367. playerAngle->ChangeValue(wxString::FromCDouble(xdre::getAngle(0)));
  368. time->ChangeValue(wxString::FromCDouble(xdre::getTime(), 2));
  369. currentTic->ChangeValue(wxString::FromCDouble(xdre::getCurrentTic()));
  370. damageDone->ChangeValue(wxString::FromCDouble(xdre::getDoneDamage()));
  371. useSuccess->ChangeValue(xdre::getUseSuccess() ? "true" : "false");
  372. crossed->ChangeValue(xdre::getLinedefCrossed() ? "true" : "false");
  373. distanceFromLine->ChangeValue(wxString::FromCDouble(xdre::getDistanceFromLine(), 6));
  374. floorheight->ChangeValue(wxString::FromCDouble(xdre::getSectorInfo(0), 2));
  375. ceilingheight->ChangeValue(wxString::FromCDouble(xdre::getSectorInfo(1), 2));
  376. special->ChangeValue(wxString::FromCDouble(xdre::getSectorInfo(2)));
  377. thingX->ChangeValue(wxString::FromCDouble(xdre::getThingInfo(0), 6));
  378. thingY->ChangeValue(wxString::FromCDouble(xdre::getThingInfo(1), 6));
  379. thingZ->ChangeValue(wxString::FromCDouble(xdre::getThingInfo(2), 2));
  380. thingRadius->ChangeValue(wxString::FromCDouble(xdre::getThingInfo(3), 3));
  381. thingTics->ChangeValue(wxString::FromCDouble(xdre::getThingInfo(4), 0));
  382. thingHealth->ChangeValue(wxString::FromCDouble(xdre::getThingInfo(5), 0));
  383. thingReactionTime->ChangeValue(wxString::FromCDouble(xdre::getThingInfo(6), 0));
  384. thingThreshold->ChangeValue(wxString::FromCDouble(xdre::getThingInfo(7), 0));
  385. savepointTic->ChangeValue(wxString::FromCDouble(xdre::getSavepointTic()));
  386. styleChoice->SetSelection(xdre::getSavepointStyle());
  387. ticlist->SetItemCount(xdre::getTiclistSize());
  388. ticlist->SetItemState(xdre::getCurrentTic(), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
  389. ticlist->EnsureVisible(xdre::getCurrentTic());
  390. ticlist->Refresh();
  391. }
  392. void MainWindow::Save() {
  393. wxString filename = wxFileSelector(wxFileSelectorPromptStr,
  394. wxEmptyString,
  395. wxEmptyString,
  396. ".lmp",
  397. "LMP files (*.lmp)|*.lmp",
  398. wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
  399. if(!filename.empty()) {
  400. wxFFile file;
  401. if(file.Open(filename, "wb")) {
  402. if(!xdre::save(file.fp())) {
  403. wxMessageBox("Couldn't write demo. That's really weird and shouldn't happen.",
  404. "Couldn't write demo",
  405. wxOK | wxCENTRE | wxICON_ERROR,
  406. this);
  407. }
  408. } else {
  409. wxMessageBox("Couldn't open file for write: " + filename,
  410. "Couldn't open file",
  411. wxOK | wxCENTRE | wxICON_ERROR,
  412. this);
  413. }
  414. }
  415. }
  416. void MainWindow::Load() {
  417. wxString filename = wxFileSelector(wxFileSelectorPromptStr,
  418. wxEmptyString,
  419. wxEmptyString,
  420. ".lmp",
  421. "LMP files (*.lmp)|*.lmp",
  422. wxFD_OPEN | wxFD_FILE_MUST_EXIST);
  423. if(!filename.empty()) {
  424. wxFFile file;
  425. if(file.Open(filename, "rb")) {
  426. if(!xdre::load(file.fp())) {
  427. wxMessageBox("Couldn't load demo. Debug it yourself to see what went wrong.",
  428. "Couldn't load demo",
  429. wxOK | wxCENTRE | wxICON_ERROR,
  430. this);
  431. } else RS();
  432. } else {
  433. wxMessageBox("Couldn't open file for read: " + filename,
  434. "Couldn't open file",
  435. wxOK | wxCENTRE | wxICON_ERROR,
  436. this);
  437. }
  438. }
  439. }
  440. void MainWindow::Quit(bool canVeto) {
  441. if(canVeto) {
  442. int ync = wxMessageBox("Do you want to save before quit?", "Save before quit", wxYES_NO | wxCANCEL, this);
  443. if(ync == wxCANCEL) return;
  444. else if(ync == wxYES) Save();
  445. }
  446. WriteConfig();
  447. Destroy();
  448. }
  449. void MainWindow::WriteConfig() {
  450. for(auto& key : configToStringMap) config.Write(key.first, key.second);
  451. unsigned int i, j;
  452. wxString s(wxEmptyString);
  453. int x, y;
  454. MainWindow::GetScreenPosition(&x, &y);
  455. s << x; s << ","; s << y;
  456. config.Write("WindowPos", s);
  457. s.Clear();
  458. SDL_GetWindowPosition(sdl_window, &x, &y);
  459. s << x; s << ","; s << y;
  460. config.Write("DoomWindowPos", s);
  461. s.Clear();
  462. config.Write("AngleType", AngleType->GetSelection());
  463. config.Write("SavepointMode", styleChoice->GetSelection());
  464. j = linedefInputField->GetCount();
  465. for(i = 0; i != j; i++) {
  466. if(linedefInputField->GetString(i) == wxEmptyString) continue;
  467. s << linedefInputField->GetString(i);
  468. if(j-1 > i) s << ",";
  469. }
  470. if(s.IsEmpty()) s = "0";
  471. config.Write("LinedefNums", s);
  472. s.Clear();
  473. j = sectorInputField->GetCount();
  474. for(i = 0; i != j; i++) {
  475. if(sectorInputField->GetString(i) == wxEmptyString) continue;
  476. s << sectorInputField->GetString(i);
  477. if(j-1 > i) s << ",";
  478. }
  479. if(s.IsEmpty()) s = "0";
  480. config.Write("SectorNums", s);
  481. s.Clear();
  482. j = thingInputField->GetCount();
  483. for(i = 0; i != j; i++) {
  484. if(thingInputField->GetString(i) == wxEmptyString) continue;
  485. s << thingInputField->GetString(i);
  486. if(j-1 > i) s << ",";
  487. }
  488. if(s.IsEmpty()) s = "0";
  489. config.Write("ThingNums", s);
  490. s.Clear();
  491. }
  492. void MainWindow::OnIdle(wxCommandEvent& event) {xdre::doSdlEvents();}
  493. void MainWindow::OnClose(wxCloseEvent& event) {Quit(event.CanVeto());}
  494. void MainWindow::OnInputFieldText(wxCommandEvent& event) {
  495. wxString input = inputField->GetValue();
  496. if(input.length() < 1) return;
  497. wxString strCmd = input;
  498. unsigned long val = 0;
  499. int numDigits = 0;
  500. bool space = false;
  501. //plain cmd or with value?
  502. for(unsigned int i = 1; i < input.length(); ++i) {
  503. if(wxIsdigit(input[i])) {
  504. numDigits = input.Mid(i).First(" ");
  505. if(numDigits == wxNOT_FOUND) numDigits = 1;
  506. else space = true;
  507. //there should be digits only, is there?
  508. if(input.Mid(i, numDigits).ToULong(&val)) {
  509. strCmd = input.Mid(0, i);
  510. break; //yes
  511. } else return; //no
  512. }
  513. }
  514. auto keyvalue = stringToCommandMap.find(strCmd);
  515. if(keyvalue == stringToCommandMap.end()) return;
  516. // final checks D:
  517. if(keyvalue->second > XCmd::Exit && numDigits < 1) return;
  518. else if(keyvalue->second > XCmd::Weapon && !space) return;
  519. inputField->ChangeValue("");
  520. DoInput(keyvalue->second, val);
  521. }
  522. void MainWindow::OnAngleType(wxCommandEvent& event) {
  523. xdre::setAngleType(AngleType->GetSelection());
  524. playerAngle->ChangeValue(wxString::FromCDouble(xdre::getAngle(0)));
  525. }
  526. void MainWindow::OnLinedefInput(wxCommandEvent& event) {
  527. unsigned long val;
  528. if(linedefInputField->GetValue().ToULong(&val)) {
  529. xdre::setLinedefCheck(val);
  530. linedefXV1->ChangeValue(wxString::FromCDouble(xdre::getLinedefVertex(0, 0), 0));
  531. linedefYV1->ChangeValue(wxString::FromCDouble(xdre::getLinedefVertex(0, 1), 0));
  532. linedefXV2->ChangeValue(wxString::FromCDouble(xdre::getLinedefVertex(1, 0), 0));
  533. linedefYV2->ChangeValue(wxString::FromCDouble(xdre::getLinedefVertex(1, 1), 0));
  534. crossed->ChangeValue(xdre::getLinedefCrossed() ? "true" : "false");
  535. distanceFromLine->ChangeValue(wxString::FromCDouble(xdre::getDistanceFromLine(), 6));
  536. }
  537. }
  538. void MainWindow::OnLineAdd(wxCommandEvent& event) {
  539. if(linedefInputField->GetValue() != wxEmptyString)
  540. linedefInputField->Append(linedefInputField->GetValue());
  541. }
  542. void MainWindow::OnSectorInput(wxCommandEvent& event) {
  543. unsigned long val;
  544. if(sectorInputField->GetValue().ToULong(&val)) {
  545. xdre::setSectorCheck(val);
  546. floorheight->ChangeValue(wxString::FromCDouble(xdre::getSectorInfo(0), 2));
  547. ceilingheight->ChangeValue(wxString::FromCDouble(xdre::getSectorInfo(1), 2));
  548. special->ChangeValue(wxString::FromCDouble(xdre::getSectorInfo(2)));
  549. }
  550. }
  551. void MainWindow::OnSectorAdd(wxCommandEvent& event) {
  552. if(sectorInputField->GetValue() != wxEmptyString) sectorInputField->Append(sectorInputField->GetValue());
  553. }
  554. void MainWindow::OnThingInput(wxCommandEvent& event) {
  555. unsigned long val;
  556. if(thingInputField->GetValue().ToULong(&val)) {
  557. xdre::setThingCheck(val);
  558. thingX->ChangeValue(wxString::FromCDouble(xdre::getThingInfo(0), 6));
  559. thingY->ChangeValue(wxString::FromCDouble(xdre::getThingInfo(1), 6));
  560. thingZ->ChangeValue(wxString::FromCDouble(xdre::getThingInfo(2), 2));
  561. thingRadius->ChangeValue(wxString::FromCDouble(xdre::getThingInfo(3), 3));
  562. thingTics->ChangeValue(wxString::FromCDouble(xdre::getThingInfo(4), 0));
  563. thingHealth->ChangeValue(wxString::FromCDouble(xdre::getThingInfo(5), 0));
  564. thingReactionTime->ChangeValue(wxString::FromCDouble(xdre::getThingInfo(6), 0));
  565. thingThreshold->ChangeValue(wxString::FromCDouble(xdre::getThingInfo(7), 0));
  566. }
  567. }
  568. void MainWindow::OnThingAdd(wxCommandEvent& event) {
  569. if(thingInputField->GetValue() != wxEmptyString)
  570. thingInputField->Append(thingInputField->GetValue());
  571. }
  572. void MainWindow::OnMenuPalStuff(wxCommandEvent& event) {
  573. xdre::toggleBlood();
  574. MenuItem7->Check(xdre::getBlood());
  575. }
  576. void MainWindow::OnMenuExit(wxCommandEvent& event) {Quit();}
  577. void MainWindow::OnMenuLoad(wxCommandEvent& event) {Load();}
  578. void MainWindow::OnMenuSave(wxCommandEvent& event) {Save();}
  579. void MainWindow::OnMenuBrute(wxCommandEvent& event) {
  580. BruteDialog bruteDialog(this);
  581. bruteDialog.ShowModal();
  582. RS();
  583. }
  584. void MainWindow::OnMenuSetKeys(wxCommandEvent& event) {
  585. KeysDialog *keysDialog = new KeysDialog(this);
  586. keysDialog->Show(true);
  587. }
  588. void MainWindow::OnMenuHeader(wxCommandEvent& event) {
  589. HeaderDialog *headerDialog = new HeaderDialog(this);
  590. headerDialog->Show(true);
  591. }
  592. void MainWindow::OnMenuClearTraces(wxCommandEvent& event) {
  593. linedefInputField->Clear();
  594. sectorInputField->Clear();
  595. thingInputField->Clear();
  596. }
  597. void MainWindow::OnStyleChoiceSelect(wxCommandEvent& event) {
  598. xdre::setSavepointStyle(styleChoice->GetSelection());
  599. RS();
  600. }