ec_condbranch.pas 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907
  1. unit ec_condbranch;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, Buttons,
  6. ComCtrls, StdCtrls, EditBtn, Spin, ec_base, Types, fpjson;
  7. type
  8. { TECCondBranchFrame }
  9. TECCondBranchFrame = class(TECBaseFrame)
  10. ActorArmourComboBox: TComboBox;
  11. ActorStateComboBox: TComboBox;
  12. ActorArmourRadioButton: TRadioButton;
  13. ActorClassComboBox: TComboBox;
  14. ActorClassRadioButton: TRadioButton;
  15. ActorInPartyRadioButton: TRadioButton;
  16. ActorNameEdit: TEdit;
  17. ActorNameRadioButton: TRadioButton;
  18. ActorSkillComboBox: TComboBox;
  19. ActorSkillRadioButton: TRadioButton;
  20. ActorStateRadioButton: TRadioButton;
  21. ActorWeaponComboBox: TComboBox;
  22. ActorWeaponRadioButton: TRadioButton;
  23. ArmourComboBox: TComboBox;
  24. CodeEdit: TEdit;
  25. DummyPage4RadioButton: TRadioButton;
  26. EnemyAppearedInBattleRadioButton: TRadioButton;
  27. EnemyStateComboBox: TComboBox;
  28. EnemyStateRadioButton: TRadioButton;
  29. KeyComboBox: TComboBox;
  30. KeyRadioButton: TRadioButton;
  31. CodeRadioButton: TRadioButton;
  32. ActorCheckPanel: TPanel;
  33. EnemyCheckPanel: TPanel;
  34. WeaponIncludeEquipmentCheckBox: TCheckBox;
  35. DummyPage3RadioButton: TRadioButton;
  36. DummyPage2RadioButton: TRadioButton;
  37. ItemComboBox: TComboBox;
  38. GoldOperatorComboBox: TComboBox;
  39. GoldRadioButton: TRadioButton;
  40. WeaponComboBox: TComboBox;
  41. ItemRadioButton: TRadioButton;
  42. GoldSpinEdit: TSpinEdit;
  43. ArmourIncludeEquipmentCheckBox: TCheckBox;
  44. WeaponRadioButton: TRadioButton;
  45. VehicleComboBox: TComboBox;
  46. MapObjectDirComboBox: TComboBox;
  47. MapObjectComboBox: TComboBox;
  48. EnemyComboBox: TComboBox;
  49. EnemyRadioButton: TRadioButton;
  50. ActorComboBox: TComboBox;
  51. ActorRadioButton: TRadioButton;
  52. MapObjectRadioButton: TRadioButton;
  53. VehicleRadioButton: TRadioButton;
  54. TimerMinutesLabel: TLabel;
  55. TimerSecondsLabel: TLabel;
  56. TimerMinutesSpinEdit: TSpinEdit;
  57. TimerSecondsSpinEdit: TSpinEdit;
  58. TimerRadioButton: TRadioButton;
  59. SelfSwitchComboBox: TComboBox;
  60. SelfSwitchRadioButton: TRadioButton;
  61. SelfSwitchStateComboBox: TComboBox;
  62. TimerOperationComboBox: TComboBox;
  63. VarVarOperandEditButton: TEditButton;
  64. VarVarOperandRadioButton: TRadioButton;
  65. VarConstOperandSpinEdit: TSpinEdit;
  66. VarConstOperandRadioButton: TRadioButton;
  67. VarOperandPanel: TPanel;
  68. VarEditButton: TEditButton;
  69. VarRadioButton: TRadioButton;
  70. SwitchStateComboBox: TComboBox;
  71. SwitchEditButton: TEditButton;
  72. ElseCheckBox: TCheckBox;
  73. CondPageControl: TPageControl;
  74. Page1TabSheet: TTabSheet;
  75. Page2TabSheet: TTabSheet;
  76. Page3TabSheet: TTabSheet;
  77. Page4TabSheet: TTabSheet;
  78. DummyPage1RadioButton: TRadioButton;
  79. SwitchRadioButton: TRadioButton;
  80. VarOperatorComboBox: TComboBox;
  81. ArmourRadioButton: TRadioButton;
  82. procedure ActorArmourRadioButtonChange(Sender: TObject);
  83. procedure ActorClassRadioButtonChange(Sender: TObject);
  84. procedure ActorNameRadioButtonChange(Sender: TObject);
  85. procedure ActorRadioButtonChange(Sender: TObject);
  86. procedure ActorSkillRadioButtonChange(Sender: TObject);
  87. procedure ActorStateRadioButtonChange(Sender: TObject);
  88. procedure ActorWeaponRadioButtonChange(Sender: TObject);
  89. procedure ArmourRadioButtonChange(Sender: TObject);
  90. procedure CodeRadioButtonChange(Sender: TObject);
  91. procedure EnemyRadioButtonChange(Sender: TObject);
  92. procedure EnemyStateRadioButtonChange(Sender: TObject);
  93. procedure FormCreate(Sender: TObject);
  94. procedure GoldRadioButtonChange(Sender: TObject);
  95. procedure ItemRadioButtonChange(Sender: TObject);
  96. procedure KeyRadioButtonChange(Sender: TObject);
  97. procedure MapObjectRadioButtonChange(Sender: TObject);
  98. procedure SelfSwitchRadioButtonChange(Sender: TObject);
  99. procedure SwitchEditButtonButtonClick(Sender: TObject);
  100. procedure SwitchEditButtonKeyPress(Sender: TObject; var Key: char);
  101. procedure SwitchRadioButtonChange(Sender: TObject);
  102. procedure TimerRadioButtonChange(Sender: TObject);
  103. procedure VarConstOperandRadioButtonChange(Sender: TObject);
  104. procedure VarEditButtonButtonClick(Sender: TObject);
  105. procedure VarRadioButtonChange(Sender: TObject);
  106. procedure VarVarOperandEditButtonButtonClick(Sender: TObject);
  107. procedure VarVarOperandRadioButtonChange(Sender: TObject);
  108. procedure VehicleRadioButtonChange(Sender: TObject);
  109. procedure WeaponRadioButtonChange(Sender: TObject);
  110. private
  111. SwitchId, VarId, VarVarOperandId: Integer;
  112. procedure RepositionDummyRadioButtons;
  113. procedure UnsetOptionsOnOtherPages(PageToKeep: Integer);
  114. procedure UpdateEditButtons;
  115. procedure InitialSetUp;
  116. function MakeCondition: TJSONArray;
  117. public
  118. procedure InitNew; override;
  119. procedure InitExisting; override;
  120. procedure MakeResultingCommand; override;
  121. function FindStartOfSubcommands(Index: Integer): Integer; override;
  122. end;
  123. var
  124. ECCondBranchFrame: TECCondBranchFrame;
  125. const
  126. KeyCodes: array [0..8] of String = (
  127. 'ok', 'cancel', 'shift',
  128. 'down', 'left', 'right', 'up',
  129. 'pageup', 'pagedown'
  130. );
  131. implementation
  132. {$R *.lfm}
  133. uses
  134. namedindexselection, globals, constants, comboboxhelper, namehelper;
  135. { TECCondBranchFrame }
  136. procedure TECCondBranchFrame.FormCreate(Sender: TObject);
  137. begin
  138. RepositionDummyRadioButtons;
  139. UnsetOptionsOnOtherPages(-1);
  140. end;
  141. procedure TECCondBranchFrame.GoldRadioButtonChange(Sender: TObject);
  142. begin
  143. if GoldRadioButton.Checked then
  144. UnsetOptionsOnOtherPages(4);
  145. GoldOperatorComboBox.Enabled := GoldRadioButton.Checked;
  146. GoldSpinEdit.Enabled := GoldRadioButton.Checked
  147. end;
  148. procedure TECCondBranchFrame.ItemRadioButtonChange(Sender: TObject);
  149. begin
  150. if ItemRadioButton.Checked then
  151. UnsetOptionsOnOtherPages(4);
  152. ItemComboBox.Enabled := ItemRadioButton.Checked
  153. end;
  154. procedure TECCondBranchFrame.KeyRadioButtonChange(Sender: TObject);
  155. begin
  156. if KeyRadioButton.Checked then
  157. UnsetOptionsOnOtherPages(4);
  158. KeyComboBox.Enabled := KeyRadioButton.Checked;
  159. end;
  160. procedure TECCondBranchFrame.MapObjectRadioButtonChange(Sender: TObject);
  161. begin
  162. if MapObjectRadioButton.Checked then
  163. UnsetOptionsOnOtherPages(3);
  164. MapObjectComboBox.Enabled := MapObjectRadioButton.Checked;
  165. MapObjectDirComboBox.Enabled := MapObjectRadioButton.Checked
  166. end;
  167. procedure TECCondBranchFrame.ActorRadioButtonChange(Sender: TObject);
  168. begin
  169. if ActorRadioButton.Checked then
  170. UnsetOptionsOnOtherPages(2);
  171. ActorInPartyRadioButton.Enabled := ActorRadioButton.Checked;
  172. ActorNameRadioButton.Enabled := ActorRadioButton.Checked;
  173. ActorNameEdit.Enabled := ActorNameRadioButton.Checked;
  174. ActorClassRadioButton.Enabled := ActorRadioButton.Checked;
  175. ActorClassComboBox.Enabled := ActorClassRadioButton.Checked;
  176. ActorSkillRadioButton.Enabled := ActorRadioButton.Checked;
  177. ActorSkillComboBox.Enabled := ActorSkillRadioButton.Checked;
  178. ActorWeaponRadioButton.Enabled := ActorRadioButton.Checked;
  179. ActorWeaponComboBox.Enabled := ActorWeaponRadioButton.Checked;
  180. ActorArmourRadioButton.Enabled := ActorRadioButton.Checked;
  181. ActorArmourComboBox.Enabled := ActorArmourRadioButton.Checked;
  182. ActorStateRadioButton.Enabled := ActorRadioButton.Checked;
  183. ActorStateComboBox.Enabled := ActorStateRadioButton.Checked;
  184. end;
  185. procedure TECCondBranchFrame.ActorSkillRadioButtonChange(Sender: TObject);
  186. begin
  187. ActorSkillComboBox.Enabled := ActorSkillRadioButton.Checked;
  188. end;
  189. procedure TECCondBranchFrame.ActorStateRadioButtonChange(Sender: TObject);
  190. begin
  191. ActorStateComboBox.Enabled := ActorStateRadioButton.Checked;
  192. end;
  193. procedure TECCondBranchFrame.ActorWeaponRadioButtonChange(Sender: TObject);
  194. begin
  195. ActorWeaponComboBox.Enabled := ActorWeaponRadioButton.Checked;
  196. end;
  197. procedure TECCondBranchFrame.ArmourRadioButtonChange(Sender: TObject);
  198. begin
  199. if ArmourRadioButton.Checked then
  200. UnsetOptionsOnOtherPages(4);
  201. ArmourComboBox.Enabled := ArmourRadioButton.Checked;
  202. ArmourIncludeEquipmentCheckBox.Enabled := ArmourRadioButton.Checked;
  203. end;
  204. procedure TECCondBranchFrame.CodeRadioButtonChange(Sender: TObject);
  205. begin
  206. if CodeRadioButton.Checked then
  207. UnsetOptionsOnOtherPages(4);
  208. CodeEdit.Enabled := CodeRadioButton.Checked
  209. end;
  210. procedure TECCondBranchFrame.EnemyRadioButtonChange(Sender: TObject);
  211. begin
  212. if EnemyRadioButton.Checked then
  213. UnsetOptionsOnOtherPages(3);
  214. EnemyComboBox.Enabled := EnemyRadioButton.Checked;
  215. EnemyAppearedInBattleRadioButton.Enabled := EnemyRadioButton.Checked;
  216. EnemyStateRadioButton.Enabled := EnemyRadioButton.Checked;
  217. EnemyStateComboBox.Enabled := EnemyStateRadioButton.Checked
  218. end;
  219. procedure TECCondBranchFrame.EnemyStateRadioButtonChange(Sender: TObject);
  220. begin
  221. EnemyStateComboBox.Enabled := EnemyStateRadioButton.Checked
  222. end;
  223. procedure TECCondBranchFrame.ActorNameRadioButtonChange(Sender: TObject);
  224. begin
  225. ActorNameEdit.Enabled := ActorNameRadioButton.Checked;
  226. end;
  227. procedure TECCondBranchFrame.ActorClassRadioButtonChange(Sender: TObject);
  228. begin
  229. ActorClassComboBox.Enabled := ActorClassRadioButton.Checked;
  230. end;
  231. procedure TECCondBranchFrame.ActorArmourRadioButtonChange(Sender: TObject);
  232. begin
  233. ActorArmourComboBox.Enabled := ActorArmourRadioButton.Checked;
  234. end;
  235. procedure TECCondBranchFrame.SelfSwitchRadioButtonChange(Sender: TObject);
  236. begin
  237. if SelfSwitchRadioButton.Checked then
  238. UnsetOptionsOnOtherPages(1);
  239. SelfSwitchComboBox.Enabled := SelfSwitchRadioButton.Checked;
  240. SelfSwitchStateComboBox.Enabled := SelfSwitchRadioButton.Checked;
  241. end;
  242. procedure TECCondBranchFrame.SwitchEditButtonButtonClick(Sender: TObject);
  243. begin
  244. SwitchId := NamedIndexSelectionForm.SelectSwitch(SwitchId, Game.Db);
  245. UpdateEditButtons
  246. end;
  247. procedure TECCondBranchFrame.SwitchEditButtonKeyPress(Sender: TObject;
  248. var Key: char);
  249. begin
  250. Key := #0;
  251. if (Sender is TEditButton)
  252. and ((Sender as TEditButton).OnButtonClick <> nil) then
  253. (Sender as TEditButton).OnButtonClick(Sender);
  254. end;
  255. procedure TECCondBranchFrame.SwitchRadioButtonChange(Sender: TObject);
  256. begin
  257. if SwitchRadioButton.Checked then
  258. UnsetOptionsOnOtherPages(1);
  259. SwitchEditButton.Enabled := SwitchRadioButton.Checked;
  260. SwitchStateComboBox.Enabled := SwitchRadioButton.Checked;
  261. end;
  262. procedure TECCondBranchFrame.TimerRadioButtonChange(Sender: TObject);
  263. begin
  264. if TimerRadioButton.Checked then
  265. UnsetOptionsOnOtherPages(1);
  266. TimerOperationComboBox.Enabled := TimerRadioButton.Checked;
  267. TimerMinutesSpinEdit.Enabled := TimerRadioButton.Checked;
  268. TimerSecondsSpinEdit.Enabled := TimerRadioButton.Checked
  269. end;
  270. procedure TECCondBranchFrame.VarConstOperandRadioButtonChange(Sender: TObject);
  271. begin
  272. VarConstOperandSpinEdit.Enabled := VarConstOperandRadioButton.Checked;
  273. end;
  274. procedure TECCondBranchFrame.VarEditButtonButtonClick(Sender: TObject);
  275. begin
  276. VarId := NamedIndexSelectionForm.SelectVariable(VarId, Game.Db);
  277. UpdateEditButtons
  278. end;
  279. procedure TECCondBranchFrame.VarRadioButtonChange(Sender: TObject);
  280. begin
  281. if VarRadioButton.Checked then
  282. UnsetOptionsOnOtherPages(1);
  283. VarEditButton.Enabled := VarRadioButton.Checked;
  284. VarOperatorComboBox.Enabled := VarRadioButton.Checked;
  285. VarConstOperandRadioButton.Enabled := VarRadioButton.Checked;
  286. VarConstOperandSpinEdit.Enabled := VarConstOperandRadioButton.Checked;
  287. VarVarOperandRadioButton.Enabled := VarRadioButton.Checked;
  288. VarVarOperandEditButton.Enabled := VarVarOperandRadioButton.Checked;
  289. UpdateEditButtons;
  290. end;
  291. procedure TECCondBranchFrame.VarVarOperandEditButtonButtonClick(Sender: TObject
  292. );
  293. begin
  294. VarVarOperandId := NamedIndexSelectionForm.SelectVariable(VarVarOperandId,
  295. Game.Db);
  296. UpdateEditButtons
  297. end;
  298. procedure TECCondBranchFrame.VarVarOperandRadioButtonChange(Sender: TObject);
  299. begin
  300. VarVarOperandEditButton.Enabled := VarVarOperandRadioButton.Checked;
  301. end;
  302. procedure TECCondBranchFrame.VehicleRadioButtonChange(Sender: TObject);
  303. begin
  304. if VehicleRadioButton.Checked then
  305. UnsetOptionsOnOtherPages(3);
  306. VehicleComboBox.Enabled := VehicleRadioButton.Checked
  307. end;
  308. procedure TECCondBranchFrame.WeaponRadioButtonChange(Sender: TObject);
  309. begin
  310. if WeaponRadioButton.Checked then
  311. UnsetOptionsOnOtherPages(4);
  312. WeaponComboBox.Enabled := WeaponRadioButton.Checked;
  313. WeaponIncludeEquipmentCheckBox.Enabled := WeaponRadioButton.Checked;
  314. end;
  315. procedure TECCondBranchFrame.RepositionDummyRadioButtons;
  316. begin
  317. (* It would be nice if we found a way to do without this, but I haven't found
  318. a better way to unselect all the radio buttons on a page. *)
  319. DummyPage1RadioButton.Left := -100;
  320. DummyPage2RadioButton.Left := -100;
  321. DummyPage3RadioButton.Left := -100;
  322. DummyPage4RadioButton.Left := -100;
  323. end;
  324. procedure TECCondBranchFrame.UnsetOptionsOnOtherPages(PageToKeep: Integer);
  325. begin
  326. if PageToKeep <> 1 then
  327. DummyPage1RadioButton.Checked := true;
  328. if PageToKeep <> 2 then
  329. DummyPage2RadioButton.Checked := true;
  330. if PageToKeep <> 3 then
  331. DummyPage3RadioButton.Checked := true;
  332. if PageToKeep <> 4 then
  333. DummyPage4RadioButton.Checked := true;
  334. end;
  335. procedure TECCondBranchFrame.UpdateEditButtons;
  336. begin
  337. SwitchEditButton.Text := Game.Db.GetSwitchName(SwitchId);
  338. VarEditButton.Text := Game.Db.GetVariableName(VarId);
  339. VarVarOperandEditButton.Text := Game.Db.GetVariableName(VarVarOperandId);
  340. end;
  341. procedure TECCondBranchFrame.InitialSetUp;
  342. procedure SetSwitchOptions(Box: TComboBox);
  343. begin
  344. with Box.Items do begin
  345. BeginUpdate;
  346. Clear;
  347. Add(rsConditionalBranch_isOn);
  348. Add(rsConditionalBranch_isOff);
  349. EndUpdate
  350. end;
  351. Box.ItemIndex := 0;
  352. end;
  353. procedure SetVariableOperations;
  354. begin
  355. with VarOperatorComboBox.Items do begin
  356. BeginUpdate;
  357. Clear;
  358. Add(rsEquals);
  359. Add(rsGreaterOrEqualThan);
  360. Add(rsLessOrEqualThan);
  361. Add(rsGreaterThan);
  362. Add(rsLessThan);
  363. Add(rsNotEqual);
  364. EndUpdate
  365. end;
  366. VarOperatorComboBox.ItemIndex := 0
  367. end;
  368. procedure SetTimerOptions;
  369. begin
  370. with TimerOperationComboBox.Items do begin
  371. BeginUpdate;
  372. Clear;
  373. Add(rsGreaterOrEqualThan);
  374. Add(rsLessOrEqualThan);
  375. EndUpdate
  376. end;
  377. TimerOperationComboBox.ItemIndex := 0;
  378. end;
  379. procedure FillEnemyList;
  380. var
  381. I: Integer;
  382. EnemyId: Integer;
  383. S: String;
  384. begin
  385. with EnemyComboBox.Items do begin
  386. BeginUpdate;
  387. Clear;
  388. for I := 0 to 7 do begin
  389. if (Troop <> nil) and (I < Troop.Arrays['members'].Count) then begin
  390. EnemyId := Troop.Arrays['members'].Objects[I].Integers['enemyId'];
  391. S := rsEnemyNumberName.Format([I+1, Db.Enemies.Objects[EnemyId].Strings['name']]);
  392. end else
  393. S := rsEnemyNumber.Format([I+1]);
  394. Add(S);
  395. end;
  396. EndUpdate;
  397. end;
  398. EnemyComboBox.ItemIndex := 0
  399. end;
  400. procedure FillMapObjectDirectionList;
  401. begin
  402. with MapObjectDirComboBox.Items do begin
  403. BeginUpdate;
  404. Clear;
  405. Add(rsConditionalBranch_charDownComboBox);
  406. Add(rsConditionalBranch_charLeftComboBox);
  407. Add(rsConditionalBranch_charRightComboBox);
  408. Add(rsConditionalBranch_charUpComboBox);
  409. EndUpdate;
  410. end;
  411. MapObjectDirComboBox.ItemIndex := 0
  412. end;
  413. procedure FillVehicleList;
  414. begin
  415. with VehicleComboBox.Items do begin
  416. BeginUpdate;
  417. Clear;
  418. Add(rsVehicleBoatComboBox);
  419. Add(rsVehicleShipComboBox);
  420. Add(rsVehicleAirshipComboBox);
  421. EndUpdate;
  422. end;
  423. VehicleComboBox.ItemIndex := 0;
  424. end;
  425. procedure SetGoldOperations;
  426. begin
  427. with GoldOperatorComboBox.Items do begin
  428. BeginUpdate;
  429. Clear;
  430. Add(rsGreaterOrEqualThan);
  431. Add(rsLessOrEqualThan);
  432. Add(rsLessThan);
  433. EndUpdate
  434. end;
  435. GoldOperatorComboBox.ItemIndex := 0
  436. end;
  437. procedure SetKeys;
  438. var
  439. I: Integer;
  440. begin
  441. with KeyComboBox.Items do begin
  442. BeginUpdate;
  443. Clear;
  444. for I := Low(KeyCodes) to High(KeyCodes) do
  445. Add(GetButtonName(KeyCodes[I]));
  446. EndUpdate
  447. end;
  448. KeyComboBox.ItemIndex := 0
  449. end;
  450. begin
  451. SetSwitchOptions(SwitchStateComboBox);
  452. SetVariableOperations;
  453. SetSwitchOptions(SelfSwitchStateComboBox);
  454. FillUserSelfSwitchNameCombobox(SelfSwitchComboBox);
  455. SelfSwitchComboBox.ItemIndex := 0;
  456. SetTimerOptions;
  457. FillDbArrayComboBox(ActorComboBox, Game.Db.Actors);
  458. FillDbArrayComboBox(ActorClassComboBox, Game.Db.Classes);
  459. FillDbArrayComboBox(ActorSkillComboBox, Game.Db.Skills);
  460. FillDbArrayComboBox(ActorWeaponComboBox, Game.Db.Weapons);
  461. FillDbArrayComboBox(ActorArmourComboBox, Game.Db.Armours);
  462. FillDbArrayComboBox(ActorStateComboBox, Game.Db.States);
  463. FillEnemyList;
  464. FillDbArrayComboBox(EnemyStateComboBox, Game.Db.States);
  465. FillMapCharacterComboBox(MapObjectComboBox, Game.Map);
  466. MapObjectComboBox.ItemIndex := 0;
  467. FillMapObjectDirectionList;
  468. FillVehicleList;
  469. SetGoldOperations;
  470. FillDbArrayComboBox(ItemComboBox, Game.Db.Items);
  471. FillDbArrayComboBox(WeaponComboBox, Game.Db.Weapons);
  472. FillDbArrayComboBox(ArmourComboBox, Game.Db.Armours);
  473. SetKeys;
  474. SwitchId := 1;
  475. VarId := 1;
  476. VarVarOperandId := 1;
  477. end;
  478. function TECCondBranchFrame.MakeCondition: TJSONArray;
  479. function MakeVarCondition: TJSONArray;
  480. var
  481. OpType, Operand: Integer;
  482. begin
  483. if VarConstOperandRadioButton.Checked then begin
  484. OpType := 0;
  485. Operand := VarConstOperandSpinEdit.Value
  486. end else begin
  487. OpType := 1;
  488. Operand := VarVarOperandId
  489. end;
  490. MakeVarCondition := TJSONArray.Create([
  491. 1, VarId, OpType, Operand, VarOperatorComboBox.ItemIndex
  492. ]);
  493. end;
  494. function MakeTimerCondition: TJSONArray;
  495. begin
  496. MakeTimerCondition := TJSONArray.Create([
  497. 3,
  498. TimerMinutesSpinEdit.Value * 60 + TimerSecondsSpinEdit.Value,
  499. TimerOperationComboBox.ItemIndex
  500. ]);
  501. end;
  502. function MakeActorCondition: TJSONArray;
  503. procedure AddWithItemIndex(CheckType: Integer; List: TComboBox);
  504. begin
  505. Result.Add(CheckType);
  506. Result.Add(List.ItemIndex + 1);
  507. end;
  508. begin
  509. Result := TJSONArray.Create([
  510. 4,
  511. ActorComboBox.ItemIndex + 1
  512. ]);
  513. if ActorInPartyRadioButton.Checked then
  514. Result.Add(0)
  515. else if ActorNameRadioButton.Checked then begin
  516. Result.Add(1);
  517. Result.Add(ActorNameEdit.Text);
  518. end else if ActorClassRadioButton.Checked then
  519. AddWithItemIndex(2, ActorClassComboBox)
  520. else if ActorSkillRadioButton.Checked then
  521. AddWithItemIndex(3, ActorSkillComboBox)
  522. else if ActorWeaponRadioButton.Checked then
  523. AddWithItemIndex(4, ActorWeaponComboBox)
  524. else if ActorArmourRadioButton.Checked then
  525. AddWithItemIndex(5, ActorArmourComboBox)
  526. else if ActorStateRadioButton.Checked then
  527. AddWithItemIndex(6, ActorStateComboBox);
  528. end;
  529. function MakeEnemyCondition: TJSONArray;
  530. begin
  531. Result := TJSONArray.Create([5, EnemyComboBox.ItemIndex]);
  532. if EnemyAppearedInBattleRadioButton.Checked then
  533. Result.Add(0)
  534. else begin
  535. Result.Add(1);
  536. Result.Add(EnemyStateComboBox.ItemIndex + 1);
  537. end;
  538. end;
  539. begin
  540. if SwitchRadioButton.Checked then
  541. MakeCondition := TJSONArray.Create([
  542. 0, SwitchId, SwitchStateComboBox.ItemIndex
  543. ])
  544. else if VarRadioButton.Checked then
  545. MakeCondition := MakeVarCondition
  546. else if SelfSwitchRadioButton.Checked then
  547. MakeCondition := TJSONArray.Create([
  548. 2,
  549. Chr(Ord('A') + SelfSwitchComboBox.ItemIndex),
  550. SelfSwitchStateComboBox.ItemIndex
  551. ])
  552. else if TimerRadioButton.Checked then
  553. MakeCondition := MakeTimerCondition
  554. else if ActorRadioButton.Checked then
  555. MakeCondition := MakeActorCondition
  556. else if EnemyRadioButton.Checked then
  557. MakeCondition := MakeEnemyCondition
  558. else if MapObjectRadioButton.Checked then
  559. MakeCondition := TJSONArray.Create([
  560. 6,
  561. MapObjectComboBox.ItemIndex - 1,
  562. (MapObjectDirComboBox.ItemIndex + 1) * 2
  563. ])
  564. else if VehicleRadioButton.Checked then
  565. MakeCondition := TJSONArray.Create([13, VehicleComboBox.ItemIndex])
  566. else if GoldRadioButton.Checked then
  567. MakeCondition := TJSONArray.Create([
  568. 7, GoldSpinEdit.Value, GoldOperatorComboBox.ItemIndex
  569. ])
  570. else if ItemRadioButton.Checked then
  571. MakeCondition := TJSONArray.Create([8, ItemComboBox.ItemIndex + 1])
  572. else if WeaponRadioButton.Checked then
  573. MakeCondition := TJSONArray.Create([
  574. 9, WeaponComboBox.ItemIndex + 1, WeaponIncludeEquipmentCheckBox.Checked
  575. ])
  576. else if ArmourRadioButton.Checked then
  577. MakeCondition := TJSONArray.Create([
  578. 10, ArmourComboBox.ItemIndex + 1, ArmourIncludeEquipmentCheckBox.Checked
  579. ])
  580. else if KeyRadioButton.Checked then
  581. MakeCondition := TJSONArray.Create([
  582. 11, KeyCodes[KeyComboBox.ItemIndex]
  583. ])
  584. else if CodeRadioButton.Checked then
  585. MakeCondition := TJSONArray.Create([
  586. 12, CodeEdit.Text
  587. ])
  588. end;
  589. procedure TECCondBranchFrame.InitNew;
  590. begin
  591. InitialSetUp;
  592. VarConstOperandRadioButton.Checked := True;
  593. UpdateEditButtons;
  594. end;
  595. procedure TECCondBranchFrame.InitExisting;
  596. var
  597. Params: TJSONArray;
  598. procedure InitSwitchCondition;
  599. begin
  600. CondPageControl.PageIndex := 0;
  601. SwitchRadioButton.Checked := True;
  602. SwitchId := Params.Integers[1];
  603. SwitchStateComboBox.ItemIndex := Params.Integers[2];
  604. UpdateEditButtons
  605. end;
  606. procedure InitVariableCondition;
  607. begin
  608. CondPageControl.PageIndex := 0;
  609. VarRadioButton.Checked := True;
  610. VarId := Params.Integers[1];
  611. if Params.Integers[2] = 0 then begin
  612. VarConstOperandRadioButton.Checked := True;
  613. VarConstOperandSpinEdit.Value := Params.Integers[3]
  614. end else begin
  615. VarVarOperandRadioButton.Checked := True;
  616. VarVarOperandId := Params.Integers[3]
  617. end;
  618. VarOperatorComboBox.ItemIndex := Params.Integers[4];
  619. UpdateEditButtons
  620. end;
  621. procedure InitSelfSwitchCondition;
  622. begin
  623. CondPageControl.PageIndex := 0;
  624. SelfSwitchRadioButton.Checked := True;
  625. SelfSwitchComboBox.ItemIndex := Ord(Params.Strings[1][1]) - Ord('A');
  626. SelfSwitchStateComboBox.ItemIndex := Params.Integers[2];
  627. end;
  628. procedure InitTimerCondition;
  629. begin
  630. CondPageControl.PageIndex := 0;
  631. TimerRadioButton.Checked := True;
  632. TimerMinutesSpinEdit.Value := Params.Integers[1] div 60;
  633. TimerSecondsSpinEdit.Value := Params.Integers[1] mod 60;
  634. TimerOperationComboBox.ItemIndex := Params.Integers[2];
  635. end;
  636. procedure InitActorCondition;
  637. procedure SetWithItemIndex(RadioButton: TRadioButton; List: TComboBox);
  638. begin
  639. RadioButton.Checked := True;
  640. List.ItemIndex := Params.Integers[3] - 1;
  641. end;
  642. begin
  643. CondPageControl.PageIndex := 1;
  644. ActorRadioButton.Checked := True;
  645. ActorComboBox.ItemIndex := Params.Integers[1] - 1;
  646. case Params.Integers[2] of
  647. 0: ActorInPartyRadioButton.Checked := True;
  648. 1: begin
  649. ActorNameRadioButton.Checked := True;
  650. ActorNameEdit.Text := Params.Strings[3];
  651. end;
  652. 2: SetWithItemIndex(ActorClassRadioButton, ActorClassComboBox);
  653. 3: SetWithItemIndex(ActorSkillRadioButton, ActorSkillComboBox);
  654. 4: SetWithItemIndex(ActorWeaponRadioButton, ActorWeaponComboBox);
  655. 5: SetWithItemIndex(ActorArmourRadioButton, ActorArmourComboBox);
  656. 6: SetWithItemIndex(ActorStateRadioButton, ActorStateComboBox);
  657. end;
  658. end;
  659. procedure InitEnemyCondition;
  660. begin
  661. CondPageControl.PageIndex := 2;
  662. EnemyRadioButton.Checked := True;
  663. EnemyComboBox.ItemIndex := Params.Integers[1];
  664. case Params.Integers[2] of
  665. 0: EnemyAppearedInBattleRadioButton.Checked := True;
  666. 1: begin
  667. EnemyStateRadioButton.Checked := True;
  668. EnemyStateComboBox.ItemIndex := Params.Integers[3] - 1;
  669. end;
  670. end;
  671. end;
  672. procedure InitMapObjectCondition;
  673. begin
  674. CondPageControl.PageIndex := 2;
  675. MapObjectRadioButton.Checked := True;
  676. MapObjectComboBox.ItemIndex := Params.Integers[1] + 1;
  677. MapObjectDirComboBox.ItemIndex := Params.Integers[2] div 2 - 1;
  678. end;
  679. procedure InitVehicleCondition;
  680. begin
  681. CondPageControl.PageIndex := 2;
  682. VehicleRadioButton.Checked := True;
  683. VehicleComboBox.ItemIndex := Params.Integers[1];
  684. end;
  685. procedure InitGoldCondition;
  686. begin
  687. CondPageControl.PageIndex := 3;
  688. GoldRadioButton.Checked := True;
  689. GoldSpinEdit.Value := Params.Integers[1];
  690. GoldOperatorComboBox.ItemIndex := Params.Integers[2];
  691. end;
  692. procedure InitPossessionCondition(ARadio: TRadioButton; AComboBox: TComboBox;
  693. ACheckBox: TCheckBox);
  694. begin
  695. CondPageControl.PageIndex := 3;
  696. ARadio.Checked := True;
  697. AComboBox.ItemIndex := Params.Integers[1] - 1;
  698. if ACheckBox <> nil then begin
  699. if Params[2].JSONType = jtBoolean then
  700. ACheckBox.Checked := Params.Booleans[2]
  701. else if Params[2].JSONType = jtNumber then
  702. ACheckBox.Checked := Params.Integers[2] <> 0
  703. end;
  704. end;
  705. procedure InitKeyCondition;
  706. var
  707. I: Integer;
  708. begin
  709. CondPageControl.PageIndex := 3;
  710. KeyRadioButton.Checked := True;
  711. for I := Low(KeyCodes) to High(KeyCodes) do
  712. if Params.Strings[1] = KeyCodes[I] then
  713. KeyComboBox.ItemIndex := I;
  714. end;
  715. procedure InitCodeCondition;
  716. begin
  717. CondPageControl.PageIndex := 3;
  718. CodeRadioButton.Checked := True;
  719. CodeEdit.Text := Params.Strings[1];
  720. end;
  721. begin
  722. InitialSetUp;
  723. Params := GetFirstParams;
  724. case Params.Integers[0] of
  725. 0: InitSwitchCondition;
  726. 1: InitVariableCondition;
  727. 2: InitSelfSwitchCondition;
  728. 3: InitTimerCondition;
  729. 4: InitActorCondition;
  730. 5: InitEnemyCondition;
  731. 6: InitMapObjectCondition;
  732. 7: InitGoldCondition;
  733. 8: InitPossessionCondition(ItemRadioButton, ItemComboBox, nil);
  734. 9: InitPossessionCondition(WeaponRadioButton, WeaponComboBox, WeaponIncludeEquipmentCheckBox);
  735. 10: InitPossessionCondition(ArmourRadioButton, ArmourComboBox, ArmourIncludeEquipmentCheckBox);
  736. 11: InitKeyCondition;
  737. 12: InitCodeCondition;
  738. 13: InitVehicleCondition;
  739. end;
  740. ElseCheckBox.Checked :=
  741. FindStartOfSubcommands(CONDITIONAL_BRANCH_ELSE_EC_CODE) > -1;
  742. end;
  743. procedure TECCondBranchFrame.MakeResultingCommand;
  744. begin
  745. ResultingCommand := TJSONArray.Create;
  746. ResultingCommand.Add(TJSONObject.Create([
  747. 'code', CONDITIONAL_BRANCH_IF_EC_CODE,
  748. 'indent', Indent,
  749. 'parameters', MakeCondition
  750. ]));
  751. AddExitingSubCommands(ResultingCommand, CONDITIONAL_BRANCH_IF_EC_CODE);
  752. if ElseCheckBox.Checked then begin
  753. ResultingCommand.Add(TJSONObject.Create([
  754. 'code', CONDITIONAL_BRANCH_ELSE_EC_CODE,
  755. 'indent', Indent,
  756. 'parameters', MakeCondition
  757. ]));
  758. AddExitingSubCommands(ResultingCommand, CONDITIONAL_BRANCH_ELSE_EC_CODE);
  759. end;
  760. ResultingCommand.Add(TJSONObject.Create([
  761. 'code', CONDITIONAL_BRANCH_END_EC_CODE,
  762. 'indent', Indent,
  763. 'parameters', TJSONArray.Create([])
  764. ]));
  765. end;
  766. function TECCondBranchFrame.FindStartOfSubcommands(Index: Integer): Integer;
  767. var
  768. Code: Integer;
  769. AIndent: Integer;
  770. begin
  771. Result := -1;
  772. if Index = CONDITIONAL_BRANCH_IF_EC_CODE then
  773. Result := ListIndex
  774. else if Index = CONDITIONAL_BRANCH_ELSE_EC_CODE then begin
  775. if (EcList = nil) or (EcList.JSONType <> jtArray) then
  776. Exit;
  777. Result := ListIndex + 1;
  778. while Result < EcList.Count do begin
  779. Code := EcList.Objects[Result].Integers['code'];
  780. AIndent := EcList.Objects[Result].Integers['indent'];
  781. if (Code = CONDITIONAL_BRANCH_ELSE_EC_CODE) and (AIndent = Indent) then
  782. Break;
  783. if (Code = CONDITIONAL_BRANCH_END_EC_CODE) and (AIndent = Indent) then
  784. begin
  785. Result := -1;
  786. Break
  787. end;
  788. Inc(Result)
  789. end
  790. end;
  791. end;
  792. end.