TerrainDlg.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. // TerrainDlg.cpp: Implementierungsdatei
  17. //
  18. #include "stdafx.h"
  19. #include "finalsun.h"
  20. #include "TerrainDlg.h"
  21. #include "TileSetBrowserFrame.h"
  22. #include "mapdata.h"
  23. #include "variables.h"
  24. #include "functions.h"
  25. #include "inlines.h"
  26. #include <string>
  27. extern ACTIONDATA AD;
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33. /////////////////////////////////////////////////////////////////////////////
  34. // Dialogfeld CTerrainDlg
  35. CTerrainDlg::CTerrainDlg(CWnd* pParent /*=NULL*/)
  36. : CDialogBar()
  37. {
  38. //{{AFX_DATA_INIT(CTerrainDlg)
  39. //}}AFX_DATA_INIT
  40. }
  41. void CTerrainDlg::DoDataExchange(CDataExchange* pDX)
  42. {
  43. CDialogBar::DoDataExchange(pDX);
  44. //{{AFX_DATA_MAP(CTerrainDlg)
  45. //}}AFX_DATA_MAP
  46. }
  47. BEGIN_MESSAGE_MAP(CTerrainDlg, CDialogBar)
  48. //{{AFX_MSG_MAP(CTerrainDlg)
  49. ON_CBN_SELCHANGE(IDC_TILESET, OnSelchangeTileset)
  50. ON_CBN_SELCHANGE(IDC_OVERLAY, OnSelchangeOverlay)
  51. //}}AFX_MSG_MAP
  52. END_MESSAGE_MAP()
  53. /////////////////////////////////////////////////////////////////////////////
  54. // Behandlungsroutinen für Nachrichten CTerrainDlg
  55. void CTerrainDlg::OnOK()
  56. {
  57. // stub
  58. }
  59. void CTerrainDlg::OnCancel()
  60. {
  61. DestroyWindow();
  62. }
  63. BOOL CTerrainDlg::OnInitDialog()
  64. {
  65. //CDialogBar::OnInitDialog();
  66. return FALSE;
  67. }
  68. void CTerrainDlg::PostNcDestroy()
  69. {
  70. //delete this;
  71. //CDialog::PostNcDestroy();
  72. }
  73. void CTerrainDlg::OnSelchangeTileset()
  74. {
  75. //while(m_Type.DeleteString(0)!=CB_ERR);
  76. CString currentTileSet;
  77. CComboBox* TileSet;
  78. TileSet = (CComboBox*)GetDlgItem(IDC_TILESET);
  79. TileSet->GetLBText(TileSet->GetCurSel(), currentTileSet);
  80. TruncSpace(currentTileSet);
  81. ((CTileSetBrowserFrame*)GetParentFrame())->m_view.SetTileSet(atoi(currentTileSet));
  82. }
  83. BOOL CTerrainDlg::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
  84. {
  85. return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
  86. }
  87. // needed to find out if pic exists
  88. extern PICDATA* ovrlpics[0xFF][max_ovrl_img];
  89. void CTerrainDlg::Update()
  90. {
  91. CComboBox* TileSet;
  92. TileSet = (CComboBox*)GetDlgItem(IDC_TILESET);
  93. while (TileSet->DeleteString(0) != CB_ERR);
  94. if (tiles)
  95. {
  96. int i;
  97. int tilecount = 0;
  98. for (i = 0;i < 10000;i++)
  99. {
  100. CString tset;
  101. char c[50];
  102. itoa(i, c, 10);
  103. int e;
  104. for (e = 0;e < 4 - strlen(c);e++)
  105. tset += "0";
  106. tset += c;
  107. CString sec = "TileSet";
  108. sec += tset;
  109. if (tiles->sections.find(sec) == tiles->sections.end())
  110. break;
  111. if (atoi(tiles->sections[sec].values["TilesInSet"]) == 0)
  112. continue;
  113. CString string;
  114. string = tset;
  115. string += " (";
  116. string += TranslateStringACP(tiles->sections[sec].values["SetName"]);
  117. string += ")";
  118. BOOL bForced = FALSE;
  119. BOOL bForcedNot = FALSE;
  120. // force yes
  121. CString datsec = (CString)"UseSet" + Map->GetTheater();
  122. auto tsetc = CString(std::to_string(atoi(tset)).c_str());
  123. if (g_data.sections[datsec].FindValue(tsetc) >= 0)
  124. bForced = TRUE;
  125. // force no
  126. datsec = (CString)"IgnoreSet" + Map->GetTheater();
  127. if (g_data.sections[datsec].FindValue(tsetc) >= 0)
  128. bForcedNot = TRUE;
  129. if (bForced || (!bForcedNot && (*tiledata)[tilecount].bAllowToPlace && !(*tiledata)[tilecount].bMarbleMadness))
  130. TileSet->SetItemData(TileSet->AddString(string), i);
  131. tilecount += atoi(tiles->sections[sec].values["TilesInSet"]);
  132. }
  133. TileSet->SetCurSel(0);
  134. OnSelchangeTileset();
  135. }
  136. CComboBox* Overlays;
  137. Overlays = (CComboBox*)GetDlgItem(IDC_OVERLAY);
  138. while (Overlays->DeleteString(0) != CB_ERR);
  139. int i;
  140. int e = 0;
  141. for (i = 0;i < rules.sections["OverlayTypes"].values.size();i++)
  142. {
  143. CString id = *rules.sections["OverlayTypes"].GetValue(i);
  144. id.TrimLeft();
  145. id.TrimRight();
  146. if (id.GetLength() > 0)
  147. {
  148. if (rules.sections.find(id) != rules.sections.end() && rules.sections[id].FindName("Name") >= 0)
  149. {
  150. int p;
  151. BOOL bListIt = TRUE;
  152. for (p = 0;p < max_ovrl_img;p++)
  153. if (ovrlpics[i][p] != NULL && ovrlpics[i][p]->pic != NULL)
  154. bListIt = TRUE;
  155. #ifdef RA2_MODE
  156. if ((i >= 39 && i <= 60) || (i >= 180 && i <= 201) || i == 239 || i == 178 || i == 167 || i == 126
  157. || (i >= 122 && i <= 125))
  158. bListIt = FALSE;
  159. #endif
  160. if (bListIt)
  161. {
  162. CString str;
  163. str = TranslateStringACP(rules.sections[(*rules.sections["OverlayTypes"].GetValue(i))].values["Name"]);
  164. Overlays->SetItemData(Overlays->AddString(str), e);
  165. }
  166. }
  167. e++;
  168. }
  169. }
  170. }
  171. DWORD CTerrainDlg::GetTileID(DWORD dwTileSet, int iTile)
  172. {
  173. int i, e;
  174. DWORD tilecount = 0;
  175. for (i = 0;i < 10000;i++)
  176. {
  177. CString tset;
  178. char c[50];
  179. itoa(i, c, 10);
  180. int e;
  181. for (e = 0;e < 4 - strlen(c);e++)
  182. tset += "0";
  183. tset += c;
  184. CString sec = "TileSet";
  185. sec += tset;
  186. if (tiles->sections.find(sec) == tiles->sections.end())
  187. return 0xFFFFFFFF;
  188. for (e = 0;e < atoi(tiles->sections[sec].values["TilesInSet"]);e++)
  189. {
  190. if (i == dwTileSet && e == iTile)
  191. return tilecount;
  192. tilecount++;
  193. }
  194. }
  195. return tilecount;
  196. }
  197. void CTerrainDlg::OnSelchangeOverlay()
  198. {
  199. CComboBox* Overlay;
  200. Overlay = (CComboBox*)GetDlgItem(IDC_OVERLAY);
  201. //TileSet->GetLBText(TileSet->GetCurSel(), currentTileSet);
  202. int n = Overlay->GetCurSel();
  203. if (n < 0) return;
  204. int sel = Overlay->GetItemData(n);
  205. ((CTileSetBrowserFrame*)GetParentFrame())->m_view.SetOverlay(sel);
  206. }