TriggerActionsDlg.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  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. // TriggerActionsDlg.cpp: Implementierungsdatei
  17. //
  18. #include "stdafx.h"
  19. #include "finalsun.h"
  20. #include "TriggerActionsDlg.h"
  21. #include "mapdata.h"
  22. #include "variables.h"
  23. #include "functions.h"
  24. #include "inlines.h"
  25. CString GetWaypoint(int n);
  26. int GetWaypoint(const char* c);
  27. #ifdef _DEBUG
  28. #define new DEBUG_NEW
  29. #undef THIS_FILE
  30. static char THIS_FILE[] = __FILE__;
  31. #endif
  32. BOOL IsWaypointFormat(CString s)
  33. {
  34. if(s.GetLength()==0) return TRUE;
  35. if(s[0]>='A' && s[0]<='Z')
  36. return TRUE;
  37. return FALSE;
  38. }
  39. /////////////////////////////////////////////////////////////////////////////
  40. // Dialogfeld CTriggerActionsDlg
  41. CTriggerActionsDlg::CTriggerActionsDlg(CWnd* pParent /*=NULL*/)
  42. : CDialog(CTriggerActionsDlg::IDD, pParent)
  43. {
  44. //{{AFX_DATA_INIT(CTriggerActionsDlg)
  45. // HINWEIS: Der Klassen-Assistent fügt hier Elementinitialisierung ein
  46. //}}AFX_DATA_INIT
  47. }
  48. void CTriggerActionsDlg::DoDataExchange(CDataExchange* pDX)
  49. {
  50. CDialog::DoDataExchange(pDX);
  51. //{{AFX_DATA_MAP(CTriggerActionsDlg)
  52. DDX_Control(pDX, IDC_PARAMVALUE, m_ParamValue);
  53. DDX_Control(pDX, IDC_PARAMETER, m_Parameter);
  54. DDX_Control(pDX, IDC_ACTIONTYPE, m_ActionType);
  55. DDX_Control(pDX, IDC_ACTIONDESCRIPTION, m_ActionDescription);
  56. DDX_Control(pDX, IDC_ACTION, m_Action);
  57. //}}AFX_DATA_MAP
  58. }
  59. BEGIN_MESSAGE_MAP(CTriggerActionsDlg, CDialog)
  60. //{{AFX_MSG_MAP(CTriggerActionsDlg)
  61. ON_CBN_SELCHANGE(IDC_ACTION, OnSelchangeAction)
  62. ON_CBN_EDITCHANGE(IDC_ACTIONTYPE, OnEditchangeActiontype)
  63. ON_LBN_SELCHANGE(IDC_PARAMETER, OnSelchangeParameter)
  64. ON_CBN_EDITCHANGE(IDC_PARAMVALUE, OnEditchangeParamvalue)
  65. ON_BN_CLICKED(IDC_NEWACTION, OnNewaction)
  66. ON_BN_CLICKED(IDC_DELETEACTION, OnDeleteaction)
  67. //}}AFX_MSG_MAP
  68. END_MESSAGE_MAP()
  69. /////////////////////////////////////////////////////////////////////////////
  70. // Behandlungsroutinen für Nachrichten CTriggerActionsDlg
  71. void CTriggerActionsDlg::OnSelchangeAction()
  72. {
  73. CIniFile& ini=Map->GetIniFile();
  74. if(m_currentTrigger.GetLength()==0) return;
  75. int selev=m_Action.GetCurSel();
  76. if(selev<0) return;
  77. int curev=m_Action.GetItemData(selev);
  78. int i;
  79. CString ActionData;
  80. ActionData=ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger];
  81. int startpos=1+curev*8;
  82. CString ActionType=GetParam(ActionData,startpos);
  83. m_ActionType.SetWindowText(ActionType);
  84. for(i=0;i<m_ActionType.GetCount();i++)
  85. {
  86. CString tmp;
  87. m_ActionType.GetLBText(i,tmp);
  88. TruncSpace(tmp);
  89. if(tmp==ActionType)
  90. m_ActionType.SetCurSel(i);
  91. }
  92. OnEditchangeActiontype();
  93. }
  94. void CTriggerActionsDlg::OnEditchangeActiontype()
  95. {
  96. CIniFile& ini=Map->GetIniFile();
  97. if(m_currentTrigger.GetLength()==0) return;
  98. int selev=m_Action.GetCurSel();
  99. if(selev<0) return;
  100. int curev=m_Action.GetItemData(selev);
  101. CString e1,e2;
  102. while(m_Parameter.DeleteString(0)!=CB_ERR);
  103. CString eventtype,eventdata;
  104. m_ActionType.GetWindowText(eventtype);
  105. TruncSpace(eventtype);
  106. if(eventtype.GetLength()==0)
  107. {
  108. eventtype="0";
  109. m_ActionType.SetWindowText(eventtype);
  110. }
  111. CString acsec="Actions";
  112. #ifdef RA2_MODE
  113. acsec="ActionsRA2";
  114. #endif
  115. int pos=1+8*curev;
  116. ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger]=SetParam(ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger], pos, (LPCTSTR)eventtype);
  117. if(g_data.sections[acsec].FindName(eventtype)<0) return;
  118. eventdata=g_data.sections[acsec].values[eventtype];
  119. #ifdef RA2_MODE
  120. if(g_data.sections["ActionsRA2"].FindName(eventtype)>=0)
  121. eventdata=g_data.sections["ActionsRA2"].values[eventtype];
  122. #endif
  123. CString desc=GetParam(eventdata,10);
  124. desc.Replace("%1",",");
  125. m_ActionDescription.SetWindowText(desc);
  126. CString ptype[6];
  127. ptype[0]=GetParam(eventdata,1);
  128. ptype[1]=GetParam(eventdata,2);
  129. ptype[2]=GetParam(eventdata,3);
  130. ptype[3]=GetParam(eventdata,4);
  131. ptype[4]=GetParam(eventdata,5);
  132. ptype[5]=GetParam(eventdata,6);
  133. int pListType[6];
  134. memset(pListType, 0, 6*sizeof(int));
  135. if(atoi(ptype[0])>=0) pListType[0]=atoi(GetParam(g_data.sections["ParamTypes"].values[ptype[0]], 1));
  136. if(atoi(ptype[1])>=0) pListType[1]=atoi(GetParam(g_data.sections["ParamTypes"].values[ptype[1]], 1));
  137. if(atoi(ptype[2])>=0) pListType[2]=atoi(GetParam(g_data.sections["ParamTypes"].values[ptype[2]], 1));
  138. if(atoi(ptype[3])>=0) pListType[3]=atoi(GetParam(g_data.sections["ParamTypes"].values[ptype[3]], 1));
  139. if(atoi(ptype[4])>=0) pListType[4]=atoi(GetParam(g_data.sections["ParamTypes"].values[ptype[4]], 1));
  140. if(atoi(ptype[5])>=0) pListType[5]=atoi(GetParam(g_data.sections["ParamTypes"].values[ptype[5]], 1));
  141. int i;
  142. for(i=0;i<6;i++)
  143. {
  144. if(atoi(ptype[i])>0)
  145. {
  146. CString paramname=GetParam(g_data.sections["ParamTypes"].values[ptype[i]], 0);
  147. m_Parameter.SetItemData(m_Parameter.AddString(paramname), i);
  148. }
  149. else if(atoi(ptype[i])<0)
  150. {
  151. char c[50];
  152. itoa(-atoi(ptype[i]),c,10);
  153. ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger]=SetParam(ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger], pos+i+1,c );
  154. }
  155. else
  156. {
  157. ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger]=SetParam(ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger], pos+i+1, "0");
  158. }
  159. }
  160. // MW fix for waypoint/number issue
  161. CString code;
  162. BOOL bNoWP=FALSE;
  163. code=GetParam(ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger], pos+1);
  164. if(g_data.sections["DontSaveAsWP"].FindValue(code)>=0) bNoWP=TRUE;
  165. // conversion below:
  166. if(IsWaypointFormat(GetParam(ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger], pos+1+6)) && bNoWP)
  167. {
  168. int number=GetWaypoint(GetParam(ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger], pos+1+6));
  169. char c[50];
  170. itoa(number, c, 10);
  171. ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger]=SetParam(ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger], pos+1+6, c);
  172. }
  173. else if(!IsWaypointFormat(GetParam(ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger], pos+1+6)) && !bNoWP)
  174. {
  175. int wp=atoi(GetParam(ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger], pos+1+6));
  176. CString s=GetWaypoint(wp);
  177. ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger]=SetParam(ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger], pos+1+6, s);
  178. }
  179. if(atoi(GetParam(eventdata, 7))==1)
  180. {
  181. if(bNoWP)
  182. m_Parameter.SetItemData(m_Parameter.AddString(TranslateStringACP("Number")), -1);
  183. else
  184. m_Parameter.SetItemData(m_Parameter.AddString(TranslateStringACP("Waypoint")), -1);
  185. }
  186. m_ParamValue.SetWindowText("");
  187. if(m_Parameter.GetCount()>0) {
  188. m_Parameter.SetCurSel(0);
  189. OnSelchangeParameter();
  190. }
  191. }
  192. void CTriggerActionsDlg::OnSelchangeParameter()
  193. {
  194. CIniFile& ini=Map->GetIniFile();
  195. if(m_currentTrigger.GetLength()==0) return;
  196. int selev=m_Action.GetCurSel();
  197. if(selev<0) return;
  198. int curev=m_Action.GetItemData(selev);
  199. int curselparam=m_Parameter.GetCurSel();
  200. if(curselparam<0)
  201. {
  202. m_ParamValue.SetWindowText("");
  203. return;
  204. }
  205. int curparam=m_Parameter.GetItemData(curselparam);
  206. CString ActionData;
  207. ActionData=ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger];
  208. int startpos=1+curev*8;
  209. CString code;
  210. BOOL bNoWP=FALSE;
  211. code=GetParam(ActionData, startpos+1);
  212. if(g_data.sections["DontSaveAsWP"].FindValue(code)>=0) bNoWP=TRUE;
  213. if(curparam>=0 && curparam<6)
  214. {
  215. CString ParamType=GetParam(g_data.sections["Actions"].values[GetParam(ActionData,startpos)],1+curparam);
  216. #ifdef RA2_MODE
  217. if(g_data.sections["ActionsRA2"].FindName(GetParam(ActionData, startpos))>=0)
  218. {
  219. ParamType=GetParam(g_data.sections["ActionsRA2"].values[GetParam(ActionData,startpos)],1+curparam);
  220. }
  221. #endif
  222. if(atoi(ParamType)<0)
  223. {
  224. }
  225. else
  226. {
  227. CString ListType=GetParam(g_data.sections["ParamTypes"].values[ParamType],1);
  228. HandleParamList(m_ParamValue, atoi(ListType));
  229. m_ParamValue.SetWindowText(GetParam(ActionData,startpos+1+curparam));
  230. int i;
  231. BOOL bFound=FALSE;
  232. for(i=0;i<m_ParamValue.GetCount();i++)
  233. {
  234. CString tmp;
  235. m_ParamValue.GetLBText(i,tmp);
  236. TruncSpace(tmp);
  237. if(tmp==GetParam(ActionData,startpos+1+curparam))
  238. {
  239. m_ParamValue.SetCurSel(i);
  240. bFound=TRUE;
  241. break;
  242. }
  243. }
  244. /*if(!bFound)
  245. {
  246. // not found, change it...
  247. if(m_ParamValue.GetCount()) {
  248. m_ParamValue.SetCurSel(0);
  249. OnEditchangeParamvalue();
  250. }
  251. else
  252. {
  253. // not numeric value?
  254. CString p=GetParam(ActionData,startpos+1+curparam);
  255. char c[50];
  256. itoa(atoi(p), c, 10);
  257. if(c!=p) {
  258. m_ParamValue.SetWindowText("0");
  259. OnEditchangeParamvalue();
  260. }
  261. }
  262. }*/
  263. }
  264. }
  265. else if(curparam==-1)
  266. {
  267. char wayp[50];
  268. if(!bNoWP)
  269. {
  270. ListWaypoints(m_ParamValue);
  271. int iWayp=GetWaypoint(GetParam(ActionData,startpos+1+6));
  272. itoa(iWayp, wayp, 10);
  273. }
  274. else
  275. {
  276. strcpy(wayp, GetParam(ActionData, startpos+1+6));
  277. HandleParamList(m_ParamValue, 0);
  278. }
  279. m_ParamValue.SetWindowText(wayp);
  280. }
  281. }
  282. void CTriggerActionsDlg::OnEditchangeParamvalue()
  283. {
  284. CIniFile& ini=Map->GetIniFile();
  285. if(m_currentTrigger.GetLength()==0) return;
  286. int selev=m_Action.GetCurSel();
  287. if(selev<0) return;
  288. int curev=m_Action.GetItemData(selev);
  289. int curselparam=m_Parameter.GetCurSel();
  290. if(curselparam<0)
  291. {
  292. m_ParamValue.SetWindowText("");
  293. return;
  294. }
  295. int curparam=m_Parameter.GetItemData(curselparam);
  296. CString ActionData;
  297. ActionData=ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger];
  298. int startpos=1+curev*8;
  299. CString code;
  300. BOOL bNoWP=FALSE;
  301. code=GetParam(ActionData, startpos+1);
  302. if(g_data.sections["DontSaveAsWP"].FindValue(code)>=0) bNoWP=TRUE;
  303. CString newVal;
  304. m_ParamValue.GetWindowText(newVal);
  305. TruncSpace(newVal);
  306. newVal.TrimLeft();
  307. if(newVal.Find(",",0)>=0) newVal.SetAt(newVal.Find(",",0), 0);
  308. if(curparam>=0)
  309. {
  310. ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger]=SetParam(ActionData, startpos+1+curparam, newVal);
  311. }
  312. else if(curparam==-1) // waypoint FIX MW: OR NUMBER!!!
  313. {
  314. int pos=1+8*curev+7;
  315. CString waypoint=newVal;
  316. if(!bNoWP) waypoint=GetWaypoint(atoi(newVal));
  317. ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger]=SetParam(ini.sections["Actions"].values[(LPCTSTR)m_currentTrigger], pos, (LPCTSTR)waypoint);
  318. }
  319. }
  320. void CTriggerActionsDlg::OnNewaction()
  321. {
  322. CIniFile& ini=Map->GetIniFile();
  323. if(m_currentTrigger.GetLength()==0) return;
  324. CIniFileSection& sec=ini.sections["Actions"];
  325. int cval=atoi(GetParam(sec.values[(LPCTSTR)m_currentTrigger],0));
  326. cval++;
  327. char c[50];
  328. itoa(cval,c,10);
  329. sec.values[(LPCTSTR)m_currentTrigger]=SetParam(sec.values[(LPCTSTR)m_currentTrigger],0,c);
  330. sec.values[(LPCTSTR)m_currentTrigger]+=",0,0,0,0,0,0,0,A";
  331. UpdateDialog();
  332. m_Action.SetCurSel(cval-1);
  333. OnSelchangeAction();
  334. }
  335. void CTriggerActionsDlg::OnDeleteaction()
  336. {
  337. CIniFile& ini=Map->GetIniFile();
  338. if(m_currentTrigger.GetLength()==0) return;
  339. int sel2=m_Action.GetCurSel();
  340. if(sel2<0) return;
  341. int curev=m_Action.GetItemData(sel2);
  342. if(MessageBox("Do you really want to delete this action?","Delete action", MB_YESNO)==IDNO) return;
  343. CIniFileSection& sec=ini.sections["Actions"];
  344. CString data;
  345. data=sec.values[(LPCTSTR)m_currentTrigger];
  346. int v=atoi(GetParam(data,0));
  347. char c[50];
  348. v--;
  349. itoa(v,c,10);
  350. data=SetParam(data,0, c);
  351. int pos=1+curev*8;
  352. int posc=1+v*8;
  353. int i;
  354. for(i=0;i<8;i++)
  355. data=SetParam(data,pos+i, GetParam(data,posc+i));
  356. // MW April 17th, 2002:
  357. // fixed: (char*)(LPCTSTR)data should not be modified directly,
  358. // Instead, moving to a buffer
  359. char* str_act=new(char[data.GetLength()+1]);
  360. strcpy(str_act, (LPCSTR) data);
  361. char* cupos=str_act;//(char*)(LPCTSTR)data;
  362. for(i=0;i<posc;i++)
  363. {
  364. cupos=strchr(cupos+1, ',');
  365. if(i==posc-1)
  366. {
  367. cupos[0]=0;
  368. break;
  369. }
  370. }
  371. //MessageBox(str_act);
  372. sec.values[(LPCTSTR)m_currentTrigger]=str_act;
  373. delete[] str_act;
  374. UpdateDialog();
  375. }
  376. void CTriggerActionsDlg::UpdateDialog()
  377. {
  378. // MW 07/20/01
  379. Clear();
  380. if(m_currentTrigger.GetLength()==0)
  381. {
  382. while(m_Action.DeleteString(0)!=CB_ERR);
  383. return;
  384. }
  385. CIniFile& ini=Map->GetIniFile();
  386. // 9.3.2001: Only support specified section
  387. #ifndef RA2_MODE
  388. CString sec="Actions";
  389. #else
  390. CString sec="ActionsRA2";
  391. #endif
  392. while(m_ActionType.DeleteString(0)!=CB_ERR);
  393. int i;
  394. for(i=0;i<g_data.sections[sec].values.size();i++)
  395. {
  396. CString eventid=*g_data.sections[sec].GetValueName(i); //GetParam(*g_data.sections["Actions"].GetValue(i),13);
  397. CString eventdata=*g_data.sections[sec].GetValue(i);
  398. /*#ifdef RA2_MODE
  399. if(g_data.sections["ActionsRA2"].FindName(eventid)>=0)
  400. eventdata=g_data.sections["ActionsRA2"].values[eventid];
  401. #endif*/
  402. CString text=eventid+" "+GetParam(eventdata,0);
  403. text.Replace("%1",",");
  404. #ifdef RA2_MODE
  405. if(GetParam(eventdata,12)=="1" && (yuri_mode || !isTrue(GetParam(eventdata, 14))))
  406. {
  407. #else
  408. if(GetParam(eventdata,11)=="1")
  409. {
  410. #endif
  411. m_ActionType.AddString(text);
  412. }
  413. }
  414. int cur_sel=m_Action.GetCurSel();
  415. while(m_Action.DeleteString(0)!=CB_ERR);
  416. CString Data=ini.sections["Actions"].values[m_currentTrigger];
  417. int count=atoi(GetParam(Data,0));
  418. for(i=0;i<count;i++)
  419. {
  420. char c[50];
  421. itoa(i,c,10);
  422. CString s=TranslateStringACP("Action");
  423. s+=" ";
  424. s+=c;
  425. m_Action.SetItemData(m_Action.AddString(s), i);
  426. }
  427. if(cur_sel<0) cur_sel=0;
  428. if(cur_sel>=count) cur_sel=count-1;
  429. m_Action.SetCurSel(cur_sel);
  430. OnSelchangeAction();
  431. }
  432. // MW 07/20/01
  433. void CTriggerActionsDlg::Clear()
  434. {
  435. m_ActionType.SetWindowText("");
  436. while(m_Parameter.DeleteString(0)!=LB_ERR);
  437. m_ParamValue.SetWindowText("");
  438. m_ActionDescription.SetWindowText("");
  439. }