NewMap.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /*
  2. FinalSun/FinalAlert 2 Mission Editor
  3. Copyright (C) 1999-2024 Electronic Arts, Inc.
  4. Authored by Matthias Wagner
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program 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. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. */
  16. // NewMap.cpp: Implementierungsdatei
  17. //
  18. #include "stdafx.h"
  19. #include "FinalSun.h"
  20. #include "NewMap.h"
  21. #include "MapOpenDialog.h"
  22. #include "resource.h"
  23. #include "mapdata.h"
  24. #include "variables.h"
  25. #include "functions.h"
  26. extern CFinalSunApp theApp;
  27. #ifdef _DEBUG
  28. #define new DEBUG_NEW
  29. #undef THIS_FILE
  30. static char THIS_FILE[] = __FILE__;
  31. #endif
  32. /////////////////////////////////////////////////////////////////////////////
  33. // Dialogfeld CNewMap
  34. CNewMap::CNewMap(CWnd* pParent /*=NULL*/)
  35. : CDialog(CNewMap::IDD, pParent)
  36. {
  37. //{{AFX_DATA_INIT(CNewMap)
  38. m_ImportOverlay = FALSE;
  39. m_ImportTrees = FALSE;
  40. m_ImportUnits = FALSE;
  41. m_Multiplayer = FALSE;
  42. m_House = _T("");
  43. m_PrepareHouses = FALSE;
  44. m_AutoProduction = FALSE;
  45. m_Height = 0;
  46. m_Width = 0;
  47. m_Import = -1;
  48. m_Theater = 0;
  49. m_GroundHeight = 2;
  50. //}}AFX_DATA_INIT
  51. }
  52. void CNewMap::DoDataExchange(CDataExchange* pDX)
  53. {
  54. CDialog::DoDataExchange(pDX);
  55. //{{AFX_DATA_MAP(CNewMap)
  56. DDX_Control(pDX, IDOK, m_OK);
  57. DDX_Check(pDX, IDC_IMPORTOVERLAY, m_ImportOverlay);
  58. DDX_Check(pDX, IDC_IMPORTTREES, m_ImportTrees);
  59. DDX_Check(pDX, IDC_IMPORTUNITS, m_ImportUnits);
  60. DDX_Check(pDX, IDC_MULTIPLAYER, m_Multiplayer);
  61. DDX_CBString(pDX, IDC_HOUSE, m_House);
  62. DDX_Check(pDX, IDC_PREPAREHOUSES, m_PrepareHouses);
  63. DDX_Check(pDX, IDC_AUTOPROD, m_AutoProduction);
  64. DDX_Text(pDX, IDC_HEIGHT, m_Height);
  65. DDV_MinMaxUInt(pDX, m_Height, 8, 255);
  66. DDX_Text(pDX, IDC_WIDTH, m_Width);
  67. DDV_MinMaxUInt(pDX, m_Width, 8, 255);
  68. DDX_Radio(pDX, IDC_IMPORT, m_Import);
  69. DDX_CBIndex(pDX, IDC_THEATER, m_Theater);
  70. DDX_CBIndex(pDX, IDC_GROUNDHEIGHT, m_GroundHeight);
  71. DDX_Control(pDX, IDC_IMPORTFILE, m_ImportFile);
  72. //}}AFX_DATA_MAP
  73. }
  74. BEGIN_MESSAGE_MAP(CNewMap, CDialog)
  75. //{{AFX_MSG_MAP(CNewMap)
  76. ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
  77. ON_BN_CLICKED(IDC_MULTIPLAYER, OnMultiplayer)
  78. ON_CBN_EDITCHANGE(IDC_IMPORTFILE, OnEditchangeImportfile)
  79. ON_BN_CLICKED(IDC_IMPORT, OnImport)
  80. ON_BN_CLICKED(IDC_NEW, OnNew)
  81. //}}AFX_MSG_MAP
  82. END_MESSAGE_MAP()
  83. /////////////////////////////////////////////////////////////////////////////
  84. // Behandlungsroutinen für Nachrichten CNewMap
  85. BOOL CNewMap::OnInitDialog()
  86. {
  87. CDialog::OnInitDialog();
  88. // preset some stuff
  89. m_ImportOverlay=TRUE;
  90. m_ImportUnits=TRUE;
  91. m_OK.EnableWindow(FALSE);
  92. m_ImportTrees=TRUE;
  93. m_PrepareHouses=TRUE;
  94. m_AutoProduction=TRUE;
  95. m_Theater=0;
  96. m_Import=1;
  97. m_Width=64;
  98. m_Height=64;
  99. CComboBox& house=*((CComboBox*)(GetDlgItem(IDC_HOUSE)));
  100. int i;
  101. for(i=0;i<rules.sections[HOUSES].values.size();i++)
  102. {
  103. house.AddString(*rules.sections[HOUSES].GetValue(i));
  104. }
  105. m_House=rules.sections[HOUSES].values["0"];
  106. CComboBox& theater=*((CComboBox*)GetDlgItem(IDC_THEATER));
  107. theater.AddString(THEATER0);
  108. theater.AddString(THEATER1);
  109. #ifdef RA2_MODE
  110. theater.AddString(THEATER2);
  111. #endif
  112. m_Theater=0;
  113. UpdateData(FALSE);
  114. UpdateStrings();
  115. // set cursor to wait
  116. SetCursor(LoadCursor(NULL,IDC_WAIT));
  117. CString maps=CString(u8AppDataPath.c_str())+"\\stdmaps\\*.mpr";
  118. CFileFind ff;
  119. if(ff.FindFile(maps))
  120. {
  121. BOOL bFileAvailable=TRUE;
  122. while(bFileAvailable) {
  123. bFileAvailable=ff.FindNextFile();
  124. CString file=ff.GetFileName();
  125. m_ImportFile.AddString(file);
  126. }
  127. m_ImportFile.SetCurSel(0);
  128. OnEditchangeImportfile();
  129. }
  130. m_OK.EnableWindow(TRUE);
  131. // set cursor to ready
  132. SetCursor(m_hArrowCursor);
  133. return TRUE;
  134. }
  135. void CNewMap::OnBrowse()
  136. {
  137. UpdateData();
  138. CMapOpenDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_FILEMUSTEXIST, "TS maps|*.mpr;*.map|TS multi maps|*.mpr|TS single maps|*.map|");
  139. char cuPath[MAX_PATH];
  140. GetCurrentDirectory(MAX_PATH, cuPath);
  141. dlg.m_ofn.lpstrInitialDir=cuPath;
  142. if(theApp.m_Options.TSExe.GetLength()) dlg.m_ofn.lpstrInitialDir=(char*)(LPCTSTR)theApp.m_Options.TSExe;
  143. if(dlg.DoModal()==IDCANCEL) return;
  144. m_ImportFile.SetWindowText(dlg.GetPathName());
  145. UpdateData(FALSE);
  146. OnEditchangeImportfile();
  147. }
  148. void CNewMap::OnOK()
  149. {
  150. UpdateData();
  151. CDialog::OnOK();
  152. }
  153. void CNewMap::OnMultiplayer()
  154. {
  155. UpdateData();
  156. CButton& ph=*((CButton*)(GetDlgItem(IDC_PREPAREHOUSES)));
  157. CButton& autoprod=*((CButton*)(GetDlgItem(IDC_AUTOPROD)));
  158. CComboBox& house=*((CComboBox*)(GetDlgItem(IDC_HOUSE)));
  159. if(m_Multiplayer)
  160. {
  161. ph.EnableWindow(FALSE);
  162. autoprod.EnableWindow(FALSE);
  163. m_AutoProduction=FALSE;
  164. house.EnableWindow(FALSE);
  165. m_PrepareHouses=FALSE;
  166. }
  167. else
  168. {
  169. autoprod.EnableWindow(TRUE);
  170. m_AutoProduction=TRUE;
  171. ph.EnableWindow(TRUE);
  172. house.EnableWindow(TRUE);
  173. m_PrepareHouses=TRUE;
  174. }
  175. UpdateData(FALSE);
  176. }
  177. void CNewMap::UpdateStrings()
  178. {
  179. SetDlgItemText(IDC_LDESC, GetLanguageStringACP("NewMapDesc"));
  180. SetDlgItemText(IDC_BROWSE, GetLanguageStringACP("NewMapBrowse"));
  181. SetDlgItemText(IDC_MULTIPLAYER, GetLanguageStringACP("NewMapMultiplayer"));
  182. SetDlgItemText(IDC_PREPAREHOUSES, GetLanguageStringACP("NewMapPrepareStandardHouses"));
  183. SetDlgItemText(IDC_AUTOPROD, GetLanguageStringACP("NewMapSetAutoProduction"));
  184. SetDlgItemText(IDC_LPLAYERHOUSE, GetLanguageStringACP("NewMapPlayerHouse"));
  185. SetDlgItemText(IDC_LIMPORTOPTIONS, GetLanguageStringACP("NewMapImportOptions"));
  186. SetDlgItemText(IDC_IMPORTTREES, GetLanguageStringACP("NewMapImportTrees"));
  187. SetDlgItemText(IDC_IMPORTOVERLAY, GetLanguageStringACP("NewMapImportOverlay"));
  188. SetDlgItemText(IDC_IMPORTUNITS, GetLanguageStringACP("NewMapImportUnits"));
  189. SetDlgItemText(IDOK, GetLanguageStringACP("OK"));
  190. SetDlgItemText(IDCANCEL, GetLanguageStringACP("Cancel"));
  191. SetWindowText(GetLanguageStringACP("NewMapCap"));
  192. }
  193. void CNewMap::OnEditchangeImportfile()
  194. {
  195. UpdateData();
  196. CIniFile cmap;
  197. CString file;
  198. m_ImportFile.GetWindowText(file);
  199. m_MapToImport=file;
  200. if(file.Find(":")<0)
  201. {
  202. m_MapToImport=CString(u8AppDataPath.c_str())+"\\stdmaps\\";
  203. m_MapToImport+=file;
  204. }
  205. cmap.InsertFile(m_MapToImport,"Map");
  206. if(cmap.sections.find("Map")==cmap.sections.end())
  207. {
  208. m_OK.EnableWindow(FALSE);
  209. return;
  210. }
  211. m_OK.EnableWindow(TRUE);
  212. }
  213. void CNewMap::OnImport()
  214. {
  215. m_OK.EnableWindow(FALSE);
  216. OnEditchangeImportfile();
  217. }
  218. void CNewMap::OnNew()
  219. {
  220. m_OK.EnableWindow(TRUE);
  221. }