HeaderDialog.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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: demo header editor.
  35. */
  36. #include "HeaderDialog.hpp"
  37. #include <wx/intl.h>
  38. #include <wx/string.h>
  39. #include <wx/valnum.h>
  40. #include <wx/valtext.h>
  41. #include <wx/msgdlg.h>
  42. const long HeaderDialog::ID_CHANGE = wxNewId();
  43. const long HeaderDialog::ID_CLOSE = wxNewId();
  44. const long HeaderDialog::ID_HELP = wxNewId();
  45. BEGIN_EVENT_TABLE(HeaderDialog,wxDialog)
  46. END_EVENT_TABLE()
  47. class HeaderException : public std::exception {
  48. public:
  49. HeaderException(const char* str) : str{str} {}
  50. virtual const char* what() const noexcept {return str;}
  51. const char* str;
  52. };
  53. int options[28];
  54. HeaderDialog::HeaderDialog(wxWindow* parent,wxWindowID id,const wxPoint& pos,const wxSize& size) {
  55. wxDialog::Create(parent, wxID_ANY, _("Header editor"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE);
  56. SetClientSize(wxSize(384,352));
  57. SetMinSize(wxSize(384,352));
  58. SetMaxSize(wxSize(384,-1));
  59. p = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(400,440), wxTAB_TRAVERSAL);
  60. change = new wxButton(p, ID_CHANGE, _("Apply"), wxPoint(32,320), wxDefaultSize, 0, wxDefaultValidator);
  61. close = new wxButton(p, ID_CLOSE, _("Close"), wxPoint(292,320), wxDefaultSize, 0, wxDefaultValidator);
  62. help = new wxButton(p, ID_HELP, _("Help"), wxPoint(160,320), wxDefaultSize, 0, wxDefaultValidator);
  63. StaticText1 = new wxStaticText(p, wxID_ANY, _("Complevel"), wxPoint(8,8), wxDefaultSize, 0);
  64. StaticText2 = new wxStaticText(p, wxID_ANY, _("Skill"), wxPoint(8,40), wxDefaultSize, 0);
  65. StaticText3 = new wxStaticText(p, wxID_ANY, _("Episode"), wxPoint(8,72), wxDefaultSize, 0);
  66. StaticText4 = new wxStaticText(p, wxID_ANY, _("Map"), wxPoint(8,104), wxDefaultSize, 0);
  67. StaticText5 = new wxStaticText(p, wxID_ANY, _("Deathmatch"), wxPoint(8,136), wxDefaultSize, 0);
  68. StaticText6 = new wxStaticText(p, wxID_ANY, _("-respawn"), wxPoint(8,168), wxDefaultSize, 0);
  69. StaticText7 = new wxStaticText(p, wxID_ANY, _("-fast"), wxPoint(8,200), wxDefaultSize, 0);
  70. StaticText8 = new wxStaticText(p, wxID_ANY, _("-nomonsters"), wxPoint(8,232), wxDefaultSize, 0);
  71. StaticText9 = new wxStaticText(p, wxID_ANY, _("Consoleplayer"), wxPoint(8,264), wxDefaultSize, 0);
  72. StaticText10 = new wxStaticText(p, wxID_ANY, _("Players"), wxPoint(8,296), wxDefaultSize, 0);
  73. StaticText11 = new wxStaticText(p, wxID_ANY, _("Monsters \nremember targets"), wxPoint(114,4), wxDefaultSize, 0);
  74. StaticText12 = new wxStaticText(p, wxID_ANY, _("Variable friction"), wxPoint(114,40), wxDefaultSize, 0);
  75. StaticText13 = new wxStaticText(p, wxID_ANY, _("Weapon recoil"), wxPoint(114,72), wxDefaultSize, 0);
  76. StaticText14 = new wxStaticText(p, wxID_ANY, _("Allow pushers"), wxPoint(114,104), wxDefaultSize, 0);
  77. StaticText15 = new wxStaticText(p, wxID_ANY, _("Player bobbing"), wxPoint(114,136), wxDefaultSize, 0);
  78. StaticText16 = new wxStaticText(p, wxID_ANY, _("Demo insurance"), wxPoint(114,168), wxDefaultSize, 0);
  79. StaticText17 = new wxStaticText(p, wxID_ANY, _("(P)RNG seed"), wxPoint(114,200), wxDefaultSize, 0);
  80. StaticText18 = new wxStaticText(p, wxID_ANY, _("Monster infighting"), wxPoint(114,232), wxDefaultSize, 0);
  81. StaticText19 = new wxStaticText(p, wxID_ANY, _("Dogs (0-3)"), wxPoint(240,8), wxDefaultSize, 0);
  82. StaticText20 = new wxStaticText(p, wxID_ANY, _("Friend distance"), wxPoint(240,40), wxDefaultSize, 0);
  83. StaticText21 = new wxStaticText(p, wxID_ANY, _("Monsters can \ngo backwards"), wxPoint(240,68), wxDefaultSize, 0);
  84. StaticText22 = new wxStaticText(p, wxID_ANY, _("Monsters avoid\n hazards"), wxPoint(240,100), wxDefaultSize, 0);
  85. StaticText23 = new wxStaticText(p, wxID_ANY, _("Friction applies\n to monsters"), wxPoint(240,132), wxDefaultSize, 0);
  86. StaticText24 = new wxStaticText(p, wxID_ANY, _("Monsters help friends"), wxPoint(240,168), wxDefaultSize, 0);
  87. StaticText25 = new wxStaticText(p, wxID_ANY, _("Dogs can jump down"), wxPoint(240,200), wxDefaultSize, 0);
  88. StaticText26 = new wxStaticText(p, wxID_ANY, _("Climb steep stairs"), wxPoint(240,232), wxDefaultSize, 0);
  89. StaticText27 = new wxStaticText(p, wxID_ANY, _("Compatflags"), wxPoint(176,264), wxDefaultSize, 0);
  90. StaticText28 = new wxStaticText(p, wxID_ANY, _("Longtics"), wxPoint(176,296), wxDefaultSize, 0);
  91. complevel = new wxTextCtrl(p, wxID_ANY, _(""), wxPoint(80,4), wxSize(32,21), wxTE_RIGHT, wxIntegerValidator<signed int>());
  92. skill = new wxTextCtrl(p, wxID_ANY, _(""), wxPoint(80,36), wxSize(32,21), wxTE_RIGHT, wxIntegerValidator<unsigned int>());
  93. episode = new wxTextCtrl(p, wxID_ANY, _(""), wxPoint(80,68), wxSize(32,21), wxTE_RIGHT, wxIntegerValidator<unsigned int>());
  94. map = new wxTextCtrl(p, wxID_ANY, _(""), wxPoint(80,100), wxSize(32,21), wxTE_RIGHT, wxIntegerValidator<unsigned int>());
  95. deathmatch = new wxTextCtrl(p, wxID_ANY, _(""), wxPoint(80,132), wxSize(32,21), wxTE_RIGHT, wxIntegerValidator<unsigned int>());
  96. respawn = new wxTextCtrl(p, wxID_ANY, _(""), wxPoint(80,164), wxSize(32,21), wxTE_RIGHT, wxIntegerValidator<unsigned int>());
  97. fast = new wxTextCtrl(p, wxID_ANY, _(""), wxPoint(80,196), wxSize(32,21), wxTE_RIGHT, wxIntegerValidator<unsigned int>());
  98. nomonsters = new wxTextCtrl(p, wxID_ANY, _(""), wxPoint(80,228), wxSize(32,21), wxTE_RIGHT, wxIntegerValidator<unsigned int>());
  99. consoleplayer = new wxTextCtrl(p, wxID_ANY, _(""), wxPoint(80,260), wxSize(32,21), wxTE_RIGHT, wxIntegerValidator<unsigned int>());
  100. players = new wxTextCtrl(p, wxID_ANY, _(""), wxPoint(80,292), wxSize(32,21), wxTE_RIGHT, wxIntegerValidator<unsigned int>());
  101. monsters_remember = new wxTextCtrl(p, wxID_ANY, _(""), wxPoint(204,4), wxSize(32,21), wxTE_RIGHT, wxIntegerValidator<unsigned int>());
  102. variable_friction = new wxTextCtrl(p, wxID_ANY, _(""), wxPoint(204,36), wxSize(32,21), wxTE_RIGHT, wxIntegerValidator<unsigned int>());
  103. weapon_recoil = new wxTextCtrl(p, wxID_ANY, _(""), wxPoint(204,68), wxSize(32,21), wxTE_RIGHT, wxIntegerValidator<unsigned int>());
  104. allow_pushers = new wxTextCtrl(p, wxID_ANY, _(""), wxPoint(204,100), wxSize(32,21), wxTE_RIGHT, wxIntegerValidator<unsigned int>());
  105. player_bobbing = new wxTextCtrl(p, wxID_ANY, _(""), wxPoint(204,132), wxSize(32,21), wxTE_RIGHT, wxIntegerValidator<unsigned int>());
  106. demo_insurance = new wxTextCtrl(p, wxID_ANY, _(""), wxPoint(204,164), wxSize(32,21), wxTE_RIGHT, wxIntegerValidator<unsigned int>());
  107. rngseed = new wxTextCtrl(p, wxID_ANY, _(""), wxPoint(196,196), wxSize(40,21), wxTE_RIGHT, wxIntegerValidator<unsigned int>());
  108. monster_infighting= new wxTextCtrl(p, wxID_ANY, _(""), wxPoint(204,228), wxSize(32,21), wxTE_RIGHT, wxIntegerValidator<unsigned int>());
  109. dogs = new wxTextCtrl(p, wxID_ANY, _(""), wxPoint(346,4), wxSize(32,21), wxTE_RIGHT, wxIntegerValidator<unsigned int>());
  110. distfriend = new wxTextCtrl(p, wxID_ANY, _(""), wxPoint(338,36), wxSize(40,21), wxTE_RIGHT, wxIntegerValidator<unsigned int>());
  111. monster_backing = new wxTextCtrl(p, wxID_ANY, _(""), wxPoint(346,68), wxSize(32,21), wxTE_RIGHT, wxIntegerValidator<unsigned int>());
  112. monster_avoid_hazards=new wxTextCtrl(p,wxID_ANY,_(""), wxPoint(346,100), wxSize(32,21), wxTE_RIGHT, wxIntegerValidator<unsigned int>());
  113. monster_friction = new wxTextCtrl(p, wxID_ANY, _(""), wxPoint(346,132), wxSize(32,21), wxTE_RIGHT, wxIntegerValidator<unsigned int>());
  114. help_friends = new wxTextCtrl(p, wxID_ANY, _(""), wxPoint(346,164), wxSize(32,21), wxTE_RIGHT, wxIntegerValidator<unsigned int>());
  115. dog_jumping = new wxTextCtrl(p, wxID_ANY, _(""), wxPoint(346,196), wxSize(32,21), wxTE_RIGHT, wxIntegerValidator<unsigned int>());
  116. monkeys = new wxTextCtrl(p, wxID_ANY, _(""), wxPoint(346,228), wxSize(32,21), wxTE_RIGHT, wxIntegerValidator<unsigned int>());
  117. compatflags = new wxTextCtrl(p, wxID_ANY, _(""), wxPoint(240,260), wxSize(64,21), wxTE_RIGHT, wxIntegerValidator<unsigned int>());
  118. longtics = new wxTextCtrl(p, wxID_ANY, _(""), wxPoint(240,292), wxSize(32,21), wxTE_RIGHT, wxIntegerValidator<unsigned int>());
  119. xdre::getOptions(options);
  120. complevel->ChangeValue(wxString::FromCDouble(options[0], 0));
  121. skill->ChangeValue(wxString::FromCDouble(options[1], 0));
  122. episode->ChangeValue(wxString::FromCDouble(options[2], 0));
  123. map->ChangeValue(wxString::FromCDouble(options[3], 0));
  124. deathmatch->ChangeValue(wxString::FromCDouble(options[4], 0));
  125. respawn->ChangeValue(wxString::FromCDouble(options[5], 0));
  126. fast->ChangeValue(wxString::FromCDouble(options[6], 0));
  127. nomonsters->ChangeValue(wxString::FromCDouble(options[7], 0));
  128. consoleplayer->ChangeValue(wxString::FromCDouble(options[8], 0));
  129. players->ChangeValue(wxString::FromCDouble(options[9], 0));
  130. monsters_remember->ChangeValue(wxString::FromCDouble(options[10], 0));
  131. variable_friction->ChangeValue(wxString::FromCDouble(options[11], 0));
  132. weapon_recoil->ChangeValue(wxString::FromCDouble(options[12], 0));
  133. allow_pushers->ChangeValue(wxString::FromCDouble(options[13], 0));
  134. player_bobbing->ChangeValue(wxString::FromCDouble(options[14], 0));
  135. demo_insurance->ChangeValue(wxString::FromCDouble(options[15], 0));
  136. rngseed->ChangeValue(wxString::FromCDouble(options[16], 0));
  137. monster_infighting->ChangeValue(wxString::FromCDouble(options[17], 0));
  138. dogs->ChangeValue(wxString::FromCDouble(options[18], 0));
  139. distfriend->ChangeValue(wxString::FromCDouble(options[19], 0));
  140. monster_backing->ChangeValue(wxString::FromCDouble(options[20], 0));
  141. monster_avoid_hazards->ChangeValue(wxString::FromCDouble(options[21], 0));
  142. monster_friction->ChangeValue(wxString::FromCDouble(options[22], 0));
  143. help_friends->ChangeValue(wxString::FromCDouble(options[23], 0));
  144. dog_jumping->ChangeValue(wxString::FromCDouble(options[24], 0));
  145. monkeys->ChangeValue(wxString::FromCDouble(options[25], 0));
  146. compatflags->ChangeValue(wxString::FromCDouble(options[26], 0));
  147. longtics->ChangeValue(wxString::FromCDouble(options[27], 0));
  148. Connect(wxID_ANY, wxEVT_CLOSE_WINDOW, wxCloseEventHandler(HeaderDialog::OnClose));
  149. Connect(ID_CLOSE, wxEVT_BUTTON, wxCloseEventHandler(HeaderDialog::OnClose));
  150. Connect(ID_CHANGE, wxEVT_BUTTON, wxCommandEventHandler(HeaderDialog::OnApply));
  151. Connect(ID_HELP, wxEVT_BUTTON, wxCommandEventHandler(HeaderDialog::OnHelp));
  152. }
  153. HeaderDialog::~HeaderDialog() {}
  154. void HeaderDialog::OnClose(wxCloseEvent& event) {Destroy();}
  155. void HeaderDialog::OnApply(wxCommandEvent& event) {
  156. try {
  157. signed long i;
  158. if(complevel->GetValue().ToCLong(&i)) options[0] = i;
  159. if(options[0] < -1 || options[0] > 17 || options[0] == 10 || options[0] == 12)
  160. throw HeaderException("Invalid complevel.");
  161. if(skill->GetValue().ToCLong(&i)) options[1] = i;
  162. if(episode->GetValue().ToCLong(&i)) options[2] = i;
  163. if(map->GetValue().ToCLong(&i)) options[3] = i;
  164. if(deathmatch->GetValue().ToCLong(&i)) options[4] = i;
  165. if(respawn->GetValue().ToCLong(&i)) options[5] = i;
  166. if(fast->GetValue().ToCLong(&i)) options[6] = i;
  167. if(nomonsters->GetValue().ToCLong(&i)) options[7] = i;
  168. //consoleplayer will change in x_changeOptions() if it's invalid
  169. if(consoleplayer->GetValue().ToCLong(&i)) options[8] = i;
  170. if(options[8] > 3) throw HeaderException("Invalid consoleplayer.");
  171. if(players->GetValue().ToCLong(&i)) options[9] = i;
  172. if(options[9] > 15 || !options[9])
  173. throw HeaderException("Invalid players.");
  174. if(monsters_remember->GetValue().ToCLong(&i)) options[10] = i;
  175. if(variable_friction->GetValue().ToCLong(&i)) options[11] = i;
  176. if(weapon_recoil->GetValue().ToCLong(&i)) options[12] = i;
  177. if(allow_pushers->GetValue().ToCLong(&i)) options[13] = i;
  178. if(player_bobbing->GetValue().ToCLong(&i)) options[14] = i;
  179. if(demo_insurance->GetValue().ToCLong(&i)) options[15] = i;
  180. if(rngseed->GetValue().ToCLong(&i)) options[16] = i;
  181. if(monster_infighting->GetValue().ToCLong(&i))options[17] = i;
  182. if(dogs->GetValue().ToCLong(&i)) options[18] = i;
  183. if(distfriend->GetValue().ToCLong(&i)) options[19] = i;
  184. if(monster_backing->GetValue().ToCLong(&i)) options[20] = i;
  185. if(monster_avoid_hazards->GetValue().ToCLong(&i))options[21] = i;
  186. if(monster_friction->GetValue().ToCLong(&i)) options[22] = i;
  187. if(help_friends->GetValue().ToCLong(&i)) options[23] = i;
  188. if(dog_jumping->GetValue().ToCLong(&i)) options[24] = i;
  189. if(monkeys->GetValue().ToCLong(&i)) options[25] = i;
  190. if(compatflags->GetValue().ToCLong(&i)) options[26] = i;
  191. if(longtics->GetValue().ToCLong(&i)) options[27] = i;
  192. xdre::changeOptions(options);
  193. }
  194. catch(HeaderException& e) {
  195. wxMessageBox(e.what(), "Invalid value(s)",
  196. wxOK|wxCENTRE|wxICON_ERROR, this);
  197. }
  198. }
  199. void HeaderDialog::OnHelp(wxCommandEvent& event) {
  200. wxMessageBox(
  201. "Complevel is compatibility level (from -1 to 17, but 10 and 12 don't work).\n"
  202. "Skill level goes from 1 to 5 (like -skill parameter).\n"
  203. "Episode matters only in Doom 1.\n"
  204. "Deathmatch is multiplayer mode: 1 means -deathmatch, 2 means -altdeath, 0 means singleplayer or co-op.\n"
  205. "RNG seed only exists in Boom, MBF and PrBoom+ demo headers. Changing it with complevels 0-7 does nothing.\n"
  206. "Point of view is zero-indexed (0 is player 1).\n"
  207. "Players field is a bit more complicated, it uses bit flags. 1 is player 1, 2 is player 2, 4 is player 3, "
  208. "8 is player 4. For example, 15 would be all 4 players.",
  209. "Help",
  210. wxOK|wxICON_INFORMATION, this);
  211. }