All.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. // All1.cpp: Implementierungsdatei
  17. //
  18. #include "stdafx.h"
  19. #include "FinalSun.h"
  20. #include "All.h"
  21. #include "mapdata.h"
  22. #include "variables.h"
  23. #ifdef _DEBUG
  24. #define new DEBUG_NEW
  25. #undef THIS_FILE
  26. static char THIS_FILE[] = __FILE__;
  27. #endif
  28. extern CFinalSunApp theApp;
  29. #include "ImportIni.h"
  30. /////////////////////////////////////////////////////////////////////////////
  31. // Dialogfeld CAll
  32. CAll::CAll(CWnd* pParent /*=NULL*/)
  33. : CDialog(CAll::IDD, pParent)
  34. {
  35. //{{AFX_DATA_INIT(CAll)
  36. // HINWEIS: Der Klassen-Assistent fügt hier Elementinitialisierung ein
  37. //}}AFX_DATA_INIT
  38. }
  39. void CAll::DoDataExchange(CDataExchange* pDX)
  40. {
  41. CDialog::DoDataExchange(pDX);
  42. //{{AFX_DATA_MAP(CAll)
  43. DDX_Control(pDX, IDC_VALUE, m_Value);
  44. DDX_Control(pDX, IDC_KEYS, m_Keys);
  45. DDX_Control(pDX, IDC_INISECTION, m_IniSection);
  46. DDX_Control(pDX, IDC_DELETESECTION, m_DeleteSection);
  47. DDX_Control(pDX, IDC_DELETEKEY, m_DeleteKey);
  48. DDX_Control(pDX, IDC_ADDSECTION, m_AddSection);
  49. DDX_Control(pDX, IDC_ADDKEY, m_AddKey);
  50. DDX_Control(pDX, IDC_SECTIONS, m_Sections);
  51. //}}AFX_DATA_MAP
  52. }
  53. BEGIN_MESSAGE_MAP(CAll, CDialog)
  54. //{{AFX_MSG_MAP(CAll)
  55. ON_CBN_SELCHANGE(IDC_SECTIONS, OnSelchangeSections)
  56. ON_EN_CHANGE(IDC_VALUE, OnChangeValue)
  57. ON_LBN_SELCHANGE(IDC_KEYS, OnSelchangeKeys)
  58. ON_EN_UPDATE(IDC_VALUE, OnUpdateValue)
  59. ON_BN_CLICKED(IDC_ADDSECTION, OnAddsection)
  60. ON_BN_CLICKED(IDC_DELETESECTION, OnDeletesection)
  61. ON_BN_CLICKED(IDC_DELETEKEY, OnDeletekey)
  62. ON_BN_CLICKED(IDC_ADDKEY, OnAddkey)
  63. ON_BN_CLICKED(IDC_INISECTION, OnInisection)
  64. //}}AFX_MSG_MAP
  65. END_MESSAGE_MAP()
  66. /////////////////////////////////////////////////////////////////////////////
  67. // Behandlungsroutinen für Nachrichten CAll
  68. void CAll::UpdateDialog()
  69. {
  70. //m_Sections.Clear();
  71. while(m_Sections.DeleteString(0)!=-1);
  72. while(m_Keys.DeleteString(0)!=-1);
  73. CIniFile& ini=Map->GetIniFile();
  74. m_Value.SetWindowText("");
  75. int i;
  76. for(i=ini.sections.size()-1;i>=0;i--)
  77. {
  78. const CString* name=ini.GetSectionName(i);
  79. if(!Map->IsMapSection(*name))
  80. m_Sections.InsertString(0, *name);
  81. }
  82. m_Sections.SetCurSel(1);
  83. OnSelchangeSections();
  84. }
  85. void CAll::OnSelchangeSections()
  86. {
  87. while(m_Keys.DeleteString(0)!=CB_ERR);
  88. CIniFile& ini=Map->GetIniFile();
  89. CString cuSection;
  90. m_Sections.GetWindowText(cuSection);
  91. if(cuSection.GetLength())
  92. {
  93. int i;
  94. m_Keys.SetRedraw(FALSE);
  95. SetCursor(LoadCursor(0,IDC_WAIT));
  96. for(i=0;i<ini.sections[cuSection].values.size();i++)
  97. {
  98. const CString* name=ini.sections[cuSection].GetValueName(i);
  99. m_Keys.InsertString(-1, *name);
  100. }
  101. SetCursor(m_hArrowCursor);
  102. m_Keys.SetRedraw(TRUE);
  103. m_Keys.RedrawWindow();
  104. }
  105. }
  106. void CAll::OnChangeValue()
  107. {
  108. CIniFile& ini=Map->GetIniFile();
  109. CString t;
  110. m_Value.GetWindowText(t);
  111. CString cuSection;
  112. m_Sections.GetWindowText(cuSection);
  113. CString cuKey;
  114. if(m_Keys.GetCurSel()>=0)m_Keys.GetText(m_Keys.GetCurSel(), cuKey) ;
  115. ini.sections[cuSection].values[cuKey]=t;
  116. }
  117. void CAll::OnSelchangeKeys()
  118. {
  119. CIniFile& ini=Map->GetIniFile();
  120. CString cuSection;
  121. m_Sections.GetWindowText(cuSection);
  122. CString cuKey;
  123. m_Keys.GetText(m_Keys.GetCurSel(), cuKey) ;
  124. m_Value.SetWindowText(ini.sections[cuSection].values[cuKey]);
  125. }
  126. void CAll::OnUpdateValue()
  127. {
  128. }
  129. void CAll::OnAddsection()
  130. {
  131. CString name=InputBox("Please set the name of the new section (the section may already exist)", "Insert Section");
  132. CIniFile& ini=Map->GetIniFile();
  133. CIniFileSection stub=ini.sections[(LPCTSTR)name];
  134. UpdateDialog();
  135. }
  136. void CAll::OnDeletesection()
  137. {
  138. CIniFile& ini=Map->GetIniFile();
  139. int cusection;
  140. cusection=m_Sections.GetCurSel();
  141. if(cusection==-1) {
  142. MessageBox("You cannot delete a section without choosing one.");
  143. return;
  144. }
  145. CString str;
  146. m_Sections.GetLBText(cusection, str);
  147. if(MessageBox(CString((CString)"Are you sure you want to delete " + str + "? You should be really careful, you may not be able to use the map afterwards."), "Delete section", MB_YESNO)==IDNO) return;
  148. ini.sections.erase(str);
  149. UpdateDialog();
  150. }
  151. void CAll::OnDeletekey()
  152. {
  153. CIniFile& ini=Map->GetIniFile();
  154. int cukey;
  155. if(m_Sections.GetCurSel()<0) return;
  156. cukey=m_Keys.GetCurSel();
  157. if(cukey==-1) {
  158. MessageBox("You cannot delete a key without choosing one.");
  159. return;
  160. }
  161. CString str;
  162. CString sec;
  163. int cuSection=m_Sections.GetCurSel();
  164. m_Sections.GetLBText(cuSection, sec);
  165. m_Keys.GetText(cukey, str);
  166. if(MessageBox(CString((CString)"Are you sure you want to delete " + str + "? You should be really careful, you may not be able to use the map afterwards."), "Delete key", MB_YESNO)==IDNO) return;
  167. ini.sections[sec].values.erase(str);
  168. UpdateDialog();
  169. m_Sections.SetCurSel(cuSection);
  170. OnSelchangeSections();
  171. }
  172. void CAll::OnAddkey()
  173. {
  174. CIniFile& ini=Map->GetIniFile();
  175. int cusection;
  176. cusection=m_Sections.GetCurSel();
  177. if(cusection==-1) {
  178. MessageBox("You need to specify a section first.");
  179. return;
  180. }
  181. CString sec;
  182. m_Sections.GetLBText(cusection, sec);
  183. CString key, value;
  184. key=InputBox("Please set the name and value for the current key here: (for example, setting a new key ""Strength"" with the value 200 can be written as ""Strength=200"". You don´t need to specify a value.)", "Create key");
  185. if(key.Find("=")!=-1)
  186. {
  187. // value specified
  188. // MW BUGFIX
  189. value=key.Right(key.GetLength()-key.Find("=")-1);
  190. key=key.Left(key.Find("="));
  191. }
  192. ini.sections[sec].values[key]=value;
  193. UpdateDialog();
  194. m_Sections.SetCurSel(cusection);
  195. OnSelchangeSections();
  196. }
  197. void CAll::OnInisection()
  198. {
  199. CFileDialog dlg(FALSE, ".ini", "*.ini", OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, "INI files|*.ini|");
  200. char cuPath[MAX_PATH];
  201. BOOL hidePreview=FALSE;
  202. BOOL previewPrinted=FALSE;
  203. GetCurrentDirectory(MAX_PATH, cuPath);
  204. dlg.m_ofn.lpstrInitialDir=cuPath;
  205. if(theApp.m_Options.TSExe.GetLength()) dlg.m_ofn.lpstrInitialDir=(char*)(LPCTSTR)theApp.m_Options.TSExe;
  206. if(dlg.DoModal()!=IDCANCEL)
  207. {
  208. CImportINI impini;
  209. impini.m_FileName=dlg.GetPathName();
  210. if(impini.DoModal()!=IDCANCEL)
  211. {
  212. UpdateDialog();
  213. }
  214. }
  215. }