GlobalsDlg.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. // GlobalsDlg.cpp: Implementierungsdatei
  17. //
  18. #include "stdafx.h"
  19. #include "finalsun.h"
  20. #include "GlobalsDlg.h"
  21. #include "mapdata.h"
  22. #include "variables.h"
  23. #include "inlines.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. /////////////////////////////////////////////////////////////////////////////
  30. // Dialogfeld CGlobalsDlg
  31. CGlobalsDlg::CGlobalsDlg(CWnd* pParent /*=NULL*/)
  32. : CDialog(CGlobalsDlg::IDD, pParent)
  33. {
  34. //{{AFX_DATA_INIT(CGlobalsDlg)
  35. m_Description = _T("");
  36. //}}AFX_DATA_INIT
  37. }
  38. void CGlobalsDlg::DoDataExchange(CDataExchange* pDX)
  39. {
  40. CDialog::DoDataExchange(pDX);
  41. //{{AFX_DATA_MAP(CGlobalsDlg)
  42. DDX_Control(pDX, IDC_VALUE, m_Value);
  43. DDX_Control(pDX, IDC_GLOBAL, m_Global);
  44. DDX_Text(pDX, IDC_DESCRIPTION, m_Description);
  45. //}}AFX_DATA_MAP
  46. }
  47. BEGIN_MESSAGE_MAP(CGlobalsDlg, CDialog)
  48. //{{AFX_MSG_MAP(CGlobalsDlg)
  49. ON_EN_CHANGE(IDC_DESCRIPTION, OnChangeDescription)
  50. ON_CBN_SELCHANGE(IDC_GLOBAL, OnSelchangeGlobal)
  51. ON_CBN_SELCHANGE(IDC_VALUE, OnSelchangeValue)
  52. ON_CBN_EDITCHANGE(IDC_VALUE, OnEditchangeValue)
  53. //}}AFX_MSG_MAP
  54. END_MESSAGE_MAP()
  55. /////////////////////////////////////////////////////////////////////////////
  56. // Behandlungsroutinen für Nachrichten CGlobalsDlg
  57. void CGlobalsDlg::OnOK()
  58. {
  59. // CDialog::OnOK();
  60. }
  61. void CGlobalsDlg::OnCancel()
  62. {
  63. // TODO: Zusätzlichen Bereinigungscode hier einfügen
  64. CDialog::OnCancel();
  65. }
  66. void CGlobalsDlg::UpdateDialog()
  67. {
  68. int oldsel=m_Global.GetCurSel();
  69. if(oldsel<0) oldsel=0;
  70. while(m_Global.DeleteString(0)!=CB_ERR);
  71. int i;
  72. BOOL bFailFind=FALSE;
  73. CIniFile& ini=Map->GetIniFile();
  74. for(i=0;i<100;i++)
  75. {
  76. char c[50];
  77. itoa(i,c,10);
  78. CString added=c;
  79. added+=" ";
  80. if(ini.sections["VariableNames"].FindName(c)>=0)
  81. {
  82. added+=ini.sections["VariableNames"].values[c];
  83. }
  84. else
  85. {
  86. bFailFind=TRUE;
  87. added+=" No name";
  88. }
  89. m_Global.SetItemData(m_Global.AddString(added),i);
  90. if(bFailFind) break;
  91. }
  92. m_Global.SetCurSel(oldsel);
  93. OnSelchangeGlobal();
  94. }
  95. void CGlobalsDlg::OnChangeDescription()
  96. {
  97. CIniFile& ini=Map->GetIniFile();
  98. int cursel=m_Global.GetCurSel();
  99. if(cursel<0) return;
  100. int curglob=m_Global.GetItemData(cursel);
  101. char c[50];
  102. itoa(curglob, c, 10);
  103. UpdateData(TRUE);
  104. if(m_Description.Find(",")>=0) m_Description.SetAt(m_Description.Find(","), 0);
  105. if(ini.sections["VariableNames"].values[c].GetLength()==0) ini.sections["VariableNames"].values[c]="text,0";
  106. ini.sections["VariableNames"].values[c]=SetParam(ini.sections["VariableNames"].values[c], 0, m_Description);
  107. // do not remove, Tiberian Sun seems to don´t like probably unused global numbers
  108. //if(m_Description.GetLength()==0)
  109. // ini.sections["VariableNames"].values.erase(c);
  110. UpdateDialog();
  111. }
  112. void CGlobalsDlg::OnSelchangeGlobal()
  113. {
  114. CIniFile& ini=Map->GetIniFile();
  115. int cursel=m_Global.GetCurSel();
  116. if(cursel<0) return;
  117. int curglob=m_Global.GetItemData(cursel);
  118. char c[50];
  119. itoa(curglob, c, 10);
  120. if(ini.sections["VariableNames"].FindName(c)>=0)
  121. {
  122. m_Description=GetParam(ini.sections["VariableNames"].values[c],0);
  123. m_Value.SetWindowText(GetParam(ini.sections["VariableNames"].values[c],1));
  124. }
  125. else
  126. m_Description="";
  127. UpdateData(FALSE);
  128. }
  129. BOOL CGlobalsDlg::OnInitDialog()
  130. {
  131. CDialog::OnInitDialog();
  132. UpdateDialog();
  133. return TRUE; // return TRUE unless you set the focus to a control
  134. // EXCEPTION: OCX-Eigenschaftenseiten sollten FALSE zurückgeben
  135. }
  136. void CGlobalsDlg::OnSelchangeValue()
  137. {
  138. }
  139. void CGlobalsDlg::OnEditchangeValue()
  140. {
  141. CIniFile& ini=Map->GetIniFile();
  142. CString str;
  143. m_Value.GetWindowText(str);
  144. if(str.GetLength()==0) return;
  145. int cursel=m_Global.GetCurSel();
  146. if(cursel<0) return;
  147. int curglob=m_Global.GetItemData(cursel);
  148. char c[50];
  149. itoa(curglob, c, 10);
  150. if(ini.sections["VariableNames"].FindName(c)<0) return;
  151. UpdateData(TRUE);
  152. str=GetParam(str, 0);
  153. TruncSpace(str);
  154. ini.sections["VariableNames"].values[c]=SetParam(ini.sections["VariableNames"].values[c], 1, str);
  155. UpdateDialog();
  156. }