Trees.cpp 5.4 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. // Trees.cpp: Implementierungsdatei
  17. //
  18. #include "stdafx.h"
  19. #include "TiberianSun Mission Editor.h"
  20. #include "Trees.h"
  21. #include "pos.h"
  22. #ifdef _DEBUG
  23. #define new DEBUG_NEW
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #endif
  27. /////////////////////////////////////////////////////////////////////////////
  28. // Eigenschaftenseite CTrees
  29. IMPLEMENT_DYNCREATE(CTrees, CPropertyPage)
  30. CTrees::CTrees() : CPropertyPage(CTrees::IDD)
  31. {
  32. //{{AFX_DATA_INIT(CTrees)
  33. // HINWEIS: Der Klassen-Assistent fügt hier Elementinitialisierung ein
  34. //}}AFX_DATA_INIT
  35. }
  36. CTrees::~CTrees()
  37. {
  38. }
  39. void CTrees::DoDataExchange(CDataExchange* pDX)
  40. {
  41. CPropertyPage::DoDataExchange(pDX);
  42. //{{AFX_DATA_MAP(CTrees)
  43. DDX_Control(pDX, IDC_POS, m_Pos);
  44. DDX_Control(pDX, IDC_TYPE, m_Type);
  45. DDX_Control(pDX, IDC_TREELIST, m_TreeList);
  46. //}}AFX_DATA_MAP
  47. }
  48. BEGIN_MESSAGE_MAP(CTrees, CPropertyPage)
  49. //{{AFX_MSG_MAP(CTrees)
  50. ON_LBN_SELCHANGE(IDC_TREELIST, OnSelchangeTreelist)
  51. ON_CBN_EDITCHANGE(IDC_TYPE, OnEditchangeType)
  52. ON_CBN_KILLFOCUS(IDC_TYPE, OnKillfocusType)
  53. ON_WM_KILLFOCUS()
  54. ON_WM_SHOWWINDOW()
  55. ON_BN_CLICKED(IDC_DELETE, OnDelete)
  56. ON_CBN_SELCHANGE(IDC_TYPE, OnEditchangeType)
  57. ON_BN_CLICKED(IDC_NEW, OnNew)
  58. //}}AFX_MSG_MAP
  59. END_MESSAGE_MAP()
  60. /////////////////////////////////////////////////////////////////////////////
  61. // Behandlungsroutinen für Nachrichten CTrees
  62. void CTrees::UpdateDialog()
  63. {
  64. m_TreeList.SetRedraw(FALSE);
  65. // first clear the list
  66. while(m_TreeList.DeleteString(0)!=LB_ERR);
  67. // okay add all trees
  68. int i;
  69. CIniFileSection& sec=ini.sections["Terrain"];
  70. for(i=0;i<sec.values.size();i++)
  71. {
  72. CString str;
  73. str=sec.GetValueName(i)->data();
  74. int pos=atoi(str);
  75. str+=(CString)" "+ sec.GetValue(i)->data();
  76. int x,y,z;
  77. GetXYPos((char*)sec.GetValueName(i)->data(), &x, &y);
  78. char c[50];
  79. itoa(x, c, 10);
  80. str+=" (";
  81. str+=c;
  82. str+="/";
  83. itoa(y, c, 10);
  84. str+=c;
  85. z=GetPos(x,y,0);
  86. itoa(z, c, 10);
  87. str+="/";
  88. str+=c;
  89. str+=")";
  90. m_TreeList.InsertString(-1, str);
  91. }
  92. m_TreeList.SetRedraw(TRUE);
  93. m_TreeList.RedrawWindow();
  94. }
  95. BOOL CTrees::OnInitDialog()
  96. {
  97. CPropertyPage::OnInitDialog();
  98. // TODO: Zusätzliche Initialisierung hier einfügen
  99. return TRUE; // return TRUE unless you set the focus to a control
  100. // EXCEPTION: OCX-Eigenschaftenseiten sollten FALSE zurückgeben
  101. }
  102. void CTrees::OnSelchangeTreelist()
  103. {
  104. int i=m_TreeList.GetCurSel();
  105. CString str;
  106. m_TreeList.GetText(i, str);
  107. str.SetAt(str.Find(" ", 0),0);
  108. m_Type.SetWindowText( ini.sections["Terrain"].values[ (char*)(LPCTSTR)str ].data() );
  109. string pos;
  110. int x,y,z;
  111. GetXYPos((char*)ini.sections["Terrain"].GetValueName(i)->data(), &x, &y);
  112. char c[50];
  113. itoa(x, c, 10);
  114. pos=c;
  115. pos+="/";
  116. itoa(y, c, 10);
  117. pos+=c;
  118. pos+="/";
  119. itoa(z, c, 10);
  120. pos+=c;
  121. m_Pos.SetWindowText(pos.data());
  122. }
  123. void CTrees::OnEditchangeType()
  124. {
  125. }
  126. void CTrees::OnKillfocusType()
  127. {
  128. int i=m_TreeList.GetCurSel();
  129. if(i==-1) return;
  130. m_TreeList.SetRedraw(FALSE);
  131. CString str;
  132. m_TreeList.GetText(i, str);
  133. str.SetAt(str.Find(" ", 0),0);
  134. CString type;
  135. m_Type.GetWindowText(type);
  136. if(ini.sections["Terrain"].values[(char*)(LPCTSTR)str]==(char*)(LPCTSTR)type) return;
  137. ini.sections["Terrain"].values[(char*)(LPCTSTR)str]=type;
  138. UpdateDialog();
  139. m_TreeList.SetCurSel(i);
  140. CTrees::OnSelchangeTreelist();
  141. /*String str_=str;
  142. //str_=ini.sections["Terrain"].GetValueName(i)->data();
  143. //int pos=atoi(str_);
  144. str_+=(CString)" "+ ini.sections["Terrain"].values[(char*)(LPCTSTR)str].data();
  145. int x,y;
  146. GetXYPos(atoi(str), x, y);
  147. char c[50];
  148. itoa(x, c, 10);
  149. str_+=" (";
  150. str_+=c;
  151. str_+="/";
  152. itoa(y, c, 10);
  153. str_+=c;
  154. str_+=")";
  155. m_TreeList.DeleteString(i);
  156. m_TreeList.InsertString(i, str_);*/
  157. m_TreeList.SetRedraw(TRUE);
  158. m_TreeList.RedrawWindow();
  159. m_TreeList.SetCurSel(i);
  160. }
  161. void CTrees::OnKillFocus(CWnd* pNewWnd)
  162. {
  163. CPropertyPage::OnKillFocus(pNewWnd);
  164. }
  165. void CTrees::OnShowWindow(BOOL bShow, UINT nStatus)
  166. {
  167. CPropertyPage::OnShowWindow(bShow, nStatus);
  168. OnKillfocusType();
  169. }
  170. void CTrees::OnDelete()
  171. {
  172. int pos=m_TreeList.GetCurSel();
  173. if(pos==-1) return;
  174. CString cutree;
  175. //m_TreeList.GetText(pos, cutree);
  176. cutree=ini.sections["Terrain"].GetValueName(pos)->data();
  177. ini.sections["Terrain"].values.erase((string)(char*)(LPCTSTR) cutree);
  178. //m_TreeList.SetRedraw(FALSE);
  179. UpdateDialog();
  180. m_TreeList.SetCurSel(pos);
  181. //m_TreeList.SetRedraw(TRUE);
  182. }
  183. void CTrees::OnNew()
  184. {
  185. int pos=m_TreeList.GetCurSel();
  186. CPos p;
  187. if(p.DoModal()==IDCANCEL) return;
  188. int h=GetPos(atoi(p.m_x), atoi(p.m_y), 0);
  189. char k[50];
  190. itoa(h, k, 10);
  191. ini.sections["Terrain"].values[k]="TREE01";
  192. UpdateDialog();
  193. m_TreeList.SetCurSel(pos);
  194. }