eventeditorunit.pas 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  1. unit eventeditorunit;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Buttons,
  6. ExtCtrls, ComCtrls, LCLTranslator, EditBtn, Spin, languagehelper,
  7. eclistframeunit, fpjson, tilesetgraphicsunit;
  8. const
  9. EVENT_ID_NEW = -1;
  10. type
  11. { TEventEditorForm }
  12. TEventEditorForm = class(TForm)
  13. ApplyBitBtn: TBitBtn;
  14. ButtonAvailabilityTimer: TTimer;
  15. EventECListFrame: TECListFrame;
  16. ImageButton: TButton;
  17. RouteButton: TButton;
  18. CancelBitBtn: TBitBtn;
  19. PriorityComboBox: TComboBox;
  20. TriggerComboBox: TComboBox;
  21. PriorityGroupBox: TGroupBox;
  22. PassThroughCheckBox: TCheckBox;
  23. DirFixCheckBox: TCheckBox;
  24. TriggerGroupBox: TGroupBox;
  25. StepAnimCheckBox: TCheckBox;
  26. WalkAnimCheckBox: TCheckBox;
  27. OptionsGroupBox: TGroupBox;
  28. MoveFreqLabel: TLabel;
  29. MoveFreqComboBox: TComboBox;
  30. MoveSpeedLabel: TLabel;
  31. MoveSpeedComboBox: TComboBox;
  32. MoveTypeComboBox: TComboBox;
  33. MoveTypeLabel: TLabel;
  34. MovementGroupBox: TGroupBox;
  35. ImageGroupBox: TGroupBox;
  36. ItemCheckBox: TCheckBox;
  37. ActorCheckBox: TCheckBox;
  38. SelfSwitchComboBox: TComboBox;
  39. SelfSwitchCheckBox: TCheckBox;
  40. ItemComboBox: TComboBox;
  41. ActorComboBox: TComboBox;
  42. ImageSpeedButton: TSpeedButton;
  43. SettingsEcsSplitter: TSplitter;
  44. VarValueLabel: TLabel;
  45. VarValueSpinEdit: TSpinEdit;
  46. Switch2CheckBox: TCheckBox;
  47. Switch1EditButton: TEditButton;
  48. Switch1CheckBox: TCheckBox;
  49. ConditionsGroupBox: TGroupBox;
  50. OkBitBtn: TBitBtn;
  51. Panel1: TPanel;
  52. SettingsScrollBox: TScrollBox;
  53. SettingsPanel: TPanel;
  54. ResultBevel: TBevel;
  55. ClearPageBitBtn: TBitBtn;
  56. CopyPageBitBtn: TBitBtn;
  57. DeletePageBitBtn: TBitBtn;
  58. NameEdit: TEdit;
  59. NameLabel: TLabel;
  60. NewPageBitBtn: TBitBtn;
  61. NoteEdit: TEdit;
  62. NoteLabel: TLabel;
  63. PastePageBitBtn: TBitBtn;
  64. VarCheckBox: TCheckBox;
  65. Switch2EditButton: TEditButton;
  66. VarEditButton: TEditButton;
  67. PagesTabControl: TTabControl;
  68. TopPanel: TPanel;
  69. ResultPanel: TPanel;
  70. procedure ActorCheckBoxChange(Sender: TObject);
  71. procedure ApplyBitBtnClick(Sender: TObject);
  72. procedure ButtonAvailabilityTimerTimer(Sender: TObject);
  73. procedure ClearPageBitBtnClick(Sender: TObject);
  74. procedure CopyPageBitBtnClick(Sender: TObject);
  75. procedure DeletePageBitBtnClick(Sender: TObject);
  76. procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
  77. procedure ImageButtonClick(Sender: TObject);
  78. procedure ItemCheckBoxChange(Sender: TObject);
  79. procedure MoveTypeComboBoxChange(Sender: TObject);
  80. procedure NewPageBitBtnClick(Sender: TObject);
  81. procedure OkBitBtnClick(Sender: TObject);
  82. procedure PagesTabControlChange(Sender: TObject);
  83. procedure PagesTabControlChanging(Sender: TObject; var AllowChange: Boolean
  84. );
  85. procedure PastePageBitBtnClick(Sender: TObject);
  86. procedure SelfSwitchCheckBoxChange(Sender: TObject);
  87. procedure Switch1CheckBoxChange(Sender: TObject);
  88. procedure Switch1EditButtonButtonClick(Sender: TObject);
  89. procedure Switch1EditButtonKeyPress(Sender: TObject; var Key: char);
  90. procedure Switch2CheckBoxChange(Sender: TObject);
  91. procedure Switch2EditButtonButtonClick(Sender: TObject);
  92. procedure Switch2EditButtonKeyPress(Sender: TObject; var Key: char);
  93. procedure VarCheckBoxChange(Sender: TObject);
  94. procedure UpdateButtonAvailability;
  95. procedure VarEditButtonButtonClick(Sender: TObject);
  96. procedure VarEditButtonKeyPress(Sender: TObject; var Key: char);
  97. private
  98. EventList: TJSONArray;
  99. EventId: Integer;
  100. Pages: TJSONArray;
  101. Switch1Id, Switch2Id, VarId: Integer;
  102. EventX, EventY: Integer;
  103. IsLoading: Boolean;
  104. TilesetGraphics: TTilesetGraphics;
  105. CharIndex, CharPattern, CharDir: Integer;
  106. CharFilename: String;
  107. TileId: Integer;
  108. public
  109. procedure EditEvent(AEventList: TJSONArray; AEventId: Integer; ATilesetGraphics: TTilesetGraphics = nil);
  110. procedure CreateNew(AEventList: TJSONArray; X, Y: Integer; ATilesetGraphics: TTilesetGraphics = nil); overload;
  111. procedure PresetPages;
  112. procedure SavePageChanges;
  113. procedure UpdatePage;
  114. function CreateEmptyPage: TJSONObject;
  115. procedure UpdateEditButtons;
  116. procedure PresetComboboxes;
  117. procedure LoadCharGraphics;
  118. procedure SaveEventData;
  119. end;
  120. var
  121. EventEditorForm: TEventEditorForm;
  122. implementation
  123. uses
  124. comboboxhelper, globals, imageselection, namedindexselection, clipboardhelper;
  125. resourcestring
  126. rsEventMovement_Fixed = 'Fixed';
  127. rsEventMovement_Random = 'Random';
  128. rsEventMovement_Approach = 'Approach';
  129. rsEventMovement_Custom = 'Custom';
  130. rsEventSpeed_1 = '1: 12.5%';
  131. rsEventSpeed_2 = '2: 25%';
  132. rsEventSpeed_3 = '3: 50%';
  133. rsEventSpeed_4 = '4: normal';
  134. rsEventSpeed_5 = '5: 200%';
  135. rsEventSpeed_6 = '6: 400%';
  136. rsEventFrequency_1 = '1: lowest';
  137. rsEventFrequency_2 = '2: low';
  138. rsEventFrequency_3 = '3: normal';
  139. rsEventFrequency_4 = '4: high';
  140. rsEventFrequency_5 = '5: highest';
  141. rsEventPriority_belowCharacters = 'Below char.';
  142. rsEventPriority_sameLevelAsCharacters = 'As char.';
  143. rsEventPriority_overCharacters = 'Over char.';
  144. rsEventTrigger_actionButton = 'Action button';
  145. rsEventTrigger_playerTouch = 'Player touch';
  146. rsEventTrigger_eventTouch = 'Event touch';
  147. rsEventTrigger_autorun = 'Autorun';
  148. rsEventTrigger_parallelProcess = 'Parallel';
  149. {$R *.lfm}
  150. { TEventEditorForm }
  151. procedure TEventEditorForm.PagesTabControlChange(Sender: TObject);
  152. begin
  153. UpdatePage;
  154. end;
  155. procedure TEventEditorForm.PagesTabControlChanging(Sender: TObject;
  156. var AllowChange: Boolean);
  157. begin
  158. if not IsLoading and (Pages <> nil) then
  159. SavePageChanges;
  160. end;
  161. procedure TEventEditorForm.PastePageBitBtnClick(Sender: TObject);
  162. var
  163. PastedObject: TJSONObject;
  164. TypeString: String;
  165. PlaceOfNewTab: Integer;
  166. begin
  167. TypeString := DataTypeStrings[DATA_TYPE_ID_MAP_EVENT_PAGE];
  168. if ClipboardHasData(TypeString) then begin
  169. PastedObject := GetJsonObjectFromClipboard(TypeString);
  170. if PastedObject <> nil then begin
  171. IsLoading := True;
  172. SavePageChanges;
  173. PlaceOfNewTab := PagesTabControl.TabIndex + 1;
  174. Pages.Insert(PlaceOfNewTab, PastedObject);
  175. PagesTabControl.Tabs.Add(IntToStr(PagesTabControl.Tabs.Count + 1));
  176. PagesTabControl.TabIndex := PlaceOfNewTab;
  177. UpdatePage;
  178. UpdateButtonAvailability;
  179. IsLoading := False;
  180. end;
  181. end;
  182. end;
  183. procedure TEventEditorForm.ItemCheckBoxChange(Sender: TObject);
  184. begin
  185. ItemComboBox.Enabled := ItemCheckBox.Checked;
  186. if ItemComboBox.Enabled then begin
  187. FillDbArrayComboBox(ItemComboBox, Game.Db.Items);
  188. if ItemComboBox.ItemIndex < 0 then
  189. ItemComboBox.ItemIndex := 0;
  190. end;
  191. end;
  192. procedure TEventEditorForm.MoveTypeComboBoxChange(Sender: TObject);
  193. begin
  194. RouteButton.Enabled := MoveTypeComboBox.ItemIndex = 3;
  195. end;
  196. procedure TEventEditorForm.NewPageBitBtnClick(Sender: TObject);
  197. var
  198. PlaceOfNewTab: Integer;
  199. begin
  200. IsLoading := True;
  201. SavePageChanges;
  202. PlaceOfNewTab := PagesTabControl.TabIndex + 1;
  203. Pages.Insert(PlaceOfNewTab, CreateEmptyPage);
  204. PagesTabControl.Tabs.Add(IntToStr(PagesTabControl.Tabs.Count + 1));
  205. PagesTabControl.TabIndex := PlaceOfNewTab;
  206. UpdatePage;
  207. UpdateButtonAvailability;
  208. IsLoading := False;
  209. end;
  210. procedure TEventEditorForm.OkBitBtnClick(Sender: TObject);
  211. begin
  212. SaveEventData
  213. end;
  214. procedure TEventEditorForm.ActorCheckBoxChange(Sender: TObject);
  215. begin
  216. ActorComboBox.Enabled := ActorCheckBox.Checked;
  217. if ActorComboBox.Enabled then begin
  218. FillDbArrayComboBox(ActorComboBox, Game.Db.Actors);
  219. if ActorComboBox.ItemIndex < 0 then
  220. ActorComboBox.ItemIndex := 0;
  221. end;
  222. end;
  223. procedure TEventEditorForm.ApplyBitBtnClick(Sender: TObject);
  224. begin
  225. SaveEventData;
  226. end;
  227. procedure TEventEditorForm.ButtonAvailabilityTimerTimer(Sender: TObject);
  228. begin
  229. if (Pages <> nil) then
  230. UpdateButtonAvailability;
  231. end;
  232. procedure TEventEditorForm.ClearPageBitBtnClick(Sender: TObject);
  233. begin
  234. IsLoading := True;
  235. Pages[PagesTabControl.TabIndex] := CreateEmptyPage;
  236. UpdatePage;
  237. UpdateButtonAvailability;
  238. IsLoading := False;
  239. end;
  240. procedure TEventEditorForm.CopyPageBitBtnClick(Sender: TObject);
  241. var
  242. Page: TJSONObject;
  243. begin
  244. SavePageChanges;
  245. Page := Pages.Objects[PagesTabControl.TabIndex];
  246. if (Page <> nil) then
  247. CopyDataToClipboard(DataTypeIds[DATA_TYPE_ID_MAP_EVENT_PAGE], Page);
  248. UpdateButtonAvailability
  249. end;
  250. procedure TEventEditorForm.DeletePageBitBtnClick(Sender: TObject);
  251. begin
  252. if Pages.Count < 2 then
  253. Exit;
  254. IsLoading := True;
  255. Pages.Delete(PagesTabControl.TabIndex);
  256. if PagesTabControl.TabIndex >= Pages.Count then
  257. PagesTabControl.TabIndex := Pages.Count - 1;
  258. PagesTabControl.Tabs.Delete(Pages.Count);
  259. UpdatePage;
  260. UpdateButtonAvailability;
  261. IsLoading := False;
  262. end;
  263. procedure TEventEditorForm.FormClose(Sender: TObject;
  264. var CloseAction: TCloseAction);
  265. begin
  266. ImageSpeedButton.Glyph.Clear;
  267. EventECListFrame.SetDatabase(nil);
  268. EventECListFrame.SetList(nil);
  269. end;
  270. procedure TEventEditorForm.ImageButtonClick(Sender: TObject);
  271. begin
  272. //TODO
  273. if ImageSelectionForm.ShowFullCharSelection(CharFilename, CharIndex,
  274. CharPattern,
  275. CharDir,
  276. TileId,
  277. TilesetGraphics)
  278. then begin
  279. CharFilename := ImageSelectionForm.SelectedFilename;
  280. CharIndex := ImageSelectionForm.Index;
  281. CharDir := ImageSelectionForm.Direction;
  282. CharPattern := ImageSelectionForm.Pattern;
  283. TileId := ImageSelectionForm.TileId;
  284. LoadCharGraphics;
  285. end;
  286. end;
  287. procedure TEventEditorForm.SelfSwitchCheckBoxChange(Sender: TObject);
  288. begin
  289. SelfSwitchComboBox.Enabled := SelfSwitchCheckBox.Checked;
  290. if SelfSwitchComboBox.Enabled then begin
  291. FillUserSelfSwitchNameCombobox(SelfSwitchComboBox);
  292. if SelfSwitchComboBox.ItemIndex < 0 then
  293. SelfSwitchComboBox.ItemIndex := 0;
  294. end;
  295. end;
  296. procedure TEventEditorForm.Switch1CheckBoxChange(Sender: TObject);
  297. begin
  298. Switch1EditButton.Enabled := Switch1CheckBox.Checked;
  299. end;
  300. procedure TEventEditorForm.Switch1EditButtonButtonClick(Sender: TObject);
  301. begin
  302. Switch1Id := NamedIndexSelectionForm.SelectSwitch(Switch1Id, Game.Db);
  303. UpdateEditButtons
  304. end;
  305. procedure TEventEditorForm.Switch1EditButtonKeyPress(Sender: TObject;
  306. var Key: char);
  307. begin
  308. Key := #0;
  309. Switch1EditButtonButtonClick(Sender);
  310. end;
  311. procedure TEventEditorForm.Switch2CheckBoxChange(Sender: TObject);
  312. begin
  313. Switch2EditButton.Enabled := Switch2CheckBox.Checked;
  314. end;
  315. procedure TEventEditorForm.Switch2EditButtonButtonClick(Sender: TObject);
  316. begin
  317. Switch2Id := NamedIndexSelectionForm.SelectSwitch(Switch2Id, Game.Db);
  318. UpdateEditButtons
  319. end;
  320. procedure TEventEditorForm.Switch2EditButtonKeyPress(Sender: TObject;
  321. var Key: char);
  322. begin
  323. Key := #0;
  324. Switch2EditButtonButtonClick(Sender);
  325. end;
  326. procedure TEventEditorForm.VarCheckBoxChange(Sender: TObject);
  327. begin
  328. VarEditButton.Enabled := VarCheckBox.Checked;
  329. VarValueSpinEdit.Enabled := VarCheckBox.Checked;
  330. end;
  331. procedure TEventEditorForm.UpdateButtonAvailability;
  332. begin
  333. if Pages = nil then
  334. Exit;
  335. DeletePageBitBtn.Enabled := Pages.Count > 1;
  336. PastePageBitBtn.Enabled := ClipboardHasData(DataTypeStrings[DATA_TYPE_ID_MAP_EVENT_PAGE]);
  337. end;
  338. procedure TEventEditorForm.VarEditButtonButtonClick(Sender: TObject);
  339. begin
  340. VarId := NamedIndexSelectionForm.SelectVariable(VarId, Game.Db);
  341. UpdateEditButtons
  342. end;
  343. procedure TEventEditorForm.VarEditButtonKeyPress(Sender: TObject; var Key: char
  344. );
  345. begin
  346. Key := #0;
  347. VarEditButtonButtonClick(Sender);
  348. end;
  349. procedure TEventEditorForm.EditEvent(AEventList: TJSONArray; AEventId: Integer;
  350. ATilesetGraphics: TTilesetGraphics);
  351. var
  352. Event: TJSONObject;
  353. procedure PresetFields;
  354. var
  355. NameJson, NoteJson: TJSONString;
  356. EventName: String = '';
  357. Note: String = '';
  358. begin
  359. if Event.Find('name', NameJson) then
  360. EventName := NameJson.AsString;
  361. if Event.Find('note', NoteJson) then
  362. Note := NoteJson.AsString;
  363. NameEdit.Text := EventName;
  364. NoteEdit.Text := Note;
  365. end;
  366. begin
  367. IsLoading := True;
  368. EventList := AEventList;
  369. EventId := AEventId;
  370. Event := EventList.Objects[EventId];
  371. EventX := Event.Integers['x'];
  372. EventY := Event.Integers['y'];
  373. TilesetGraphics := ATilesetGraphics;
  374. PresetComboboxes;
  375. PresetFields;
  376. if Pages <> nil then
  377. FreeAndNil(Pages);
  378. Pages := Event.Arrays['pages'].Clone as TJSONArray;
  379. PresetPages;
  380. UpdateButtonAvailability;
  381. PagesTabControl.TabIndex := 0;
  382. UpdatePage;
  383. IsLoading := False;
  384. ShowModal
  385. end;
  386. procedure TEventEditorForm.CreateNew(AEventList: TJSONArray; X, Y: Integer;
  387. ATilesetGraphics: TTilesetGraphics);
  388. begin
  389. IsLoading := True;
  390. EventList := AEventList;
  391. EventId := EventList.Count;
  392. EventX := X;
  393. EventY := Y;
  394. TilesetGraphics := ATilesetGraphics;
  395. NameEdit.Text := 'EV%.3d'.Format([EventList.Count]);
  396. NoteEdit.Text := '';
  397. PresetComboboxes;
  398. if Pages <> nil then
  399. FreeAndNil(Pages);
  400. Pages := TJSONArray.Create([
  401. CreateEmptyPage
  402. ]);
  403. PresetPages;
  404. UpdateButtonAvailability;
  405. PagesTabControl.TabIndex := 0;
  406. UpdatePage;
  407. MoveTypeComboBox.ItemHeight := 0;
  408. MoveSpeedComboBox.ItemHeight := 4;
  409. MoveFreqComboBox.ItemHeight := 4;
  410. PriorityComboBox.ItemHeight := 0;
  411. TriggerComboBox.ItemIndex := 0;
  412. IsLoading := False;
  413. ShowModal;
  414. end;
  415. procedure TEventEditorForm.PresetPages;
  416. var
  417. I: Integer;
  418. begin
  419. with PagesTabControl.Tabs do begin
  420. BeginUpdate;
  421. Clear;
  422. for I := 1 to Pages.Count do
  423. Add(IntToStr(I));
  424. EndUpdate;
  425. end;
  426. end;
  427. procedure TEventEditorForm.SavePageChanges;
  428. var
  429. Page: TJSONObject;
  430. procedure SaveConditions;
  431. var
  432. C: TJSONObject;
  433. begin
  434. C := Page.Objects['conditions'];
  435. C.Booleans['switch1Valid'] := Switch1CheckBox.Checked;
  436. C.Integers['switch1Id'] := Switch1Id;
  437. C.Booleans['switch2Valid'] := Switch2CheckBox.Checked;
  438. C.Integers['switch2Id'] := Switch2Id;
  439. C.Booleans['variableValid'] := VarCheckBox.Checked;
  440. C.Integers['variableId'] := VarId;
  441. C.Integers['variableValue'] := VarValueSpinEdit.Value;
  442. C.Booleans['selfSwitchValid'] := SelfSwitchCheckBox.Checked;
  443. C.Strings['selfSwitchCh'] := Chr(Ord('A') + SelfSwitchComboBox.ItemIndex);
  444. C.Booleans['itemValid'] := ItemCheckBox.Checked;
  445. C.Integers['itemId'] := ItemComboBox.ItemIndex + 1;
  446. C.Booleans['actorValid'] := ActorCheckBox.Checked;
  447. C.Integers['actorId'] := ActorComboBox.ItemIndex + 1;
  448. end;
  449. procedure SaveMoveSettings;
  450. begin
  451. Page.Integers['moveType'] := MoveTypeComboBox.ItemIndex;
  452. //TODO: movement route
  453. Page.Integers['moveSpeed'] := MoveSpeedComboBox.ItemIndex;
  454. Page.Integers['moveFrequency'] := MoveFreqComboBox.ItemIndex;
  455. end;
  456. procedure SaveOptions;
  457. begin
  458. Page.Booleans['walkAnime'] := WalkAnimCheckBox.Checked;
  459. Page.Booleans['stepAnime'] := StepAnimCheckBox.Checked;
  460. Page.Booleans['directionFix'] := DirFixCheckBox.Checked;
  461. Page.Booleans['through'] := PassThroughCheckBox.Checked;
  462. end;
  463. procedure SaveGraphics;
  464. var
  465. I: TJSONObject;
  466. begin
  467. I := Page.Objects['image'];
  468. I.Integers['characterIndex'] := CharIndex;
  469. I.Strings['characterName'] := CharFilename;
  470. I.Integers['direction'] := CharDir;
  471. I.Integers['pattern'] := CharPattern;
  472. I.Integers['tileId'] := TileId;
  473. end;
  474. begin
  475. Page := Pages.Objects[PagesTabControl.TabIndex];
  476. SaveConditions;
  477. SaveGraphics;
  478. SaveMoveSettings;
  479. SaveOptions;
  480. Page.Integers['priorityType'] := PriorityComboBox.ItemIndex;
  481. Page.Integers['trigger'] := TriggerComboBox.ItemIndex;
  482. end;
  483. procedure TEventEditorForm.UpdatePage;
  484. var
  485. Page: TJSONObject;
  486. procedure UpdateConditions;
  487. var
  488. C: TJSONObject;
  489. begin
  490. C := Page.Objects['conditions'];
  491. Switch1CheckBox.Checked := C.Booleans['switch1Valid'];
  492. Switch1Id := C.Integers['switch1Id'];
  493. Switch2CheckBox.Checked := C.Booleans['switch2Valid'];
  494. Switch2Id := C.Integers['switch2Id'];
  495. VarCheckBox.Checked := C.Booleans['variableValid'];
  496. VarId := C.Integers['variableId'];
  497. VarValueSpinEdit.Value := C.Integers['variableValue'];
  498. SelfSwitchCheckBox.Checked := C.Booleans['selfSwitchValid'];
  499. if C.Strings['selfSwitchCh'] <> '' then
  500. SelfSwitchComboBox.ItemIndex := Ord(C.Strings['selfSwitchCh'][1]) - Ord('A');
  501. ItemCheckBox.Checked := C.Booleans['itemValid'];
  502. ItemComboBox.ItemIndex := C.Integers['itemId'] - 1;
  503. ActorCheckBox.Checked := C.Booleans['actorValid'];
  504. ActorComboBox.ItemIndex := C.Integers['actorId'] - 1;
  505. UpdateEditButtons;
  506. {TODO: update names}
  507. end;
  508. procedure UpdateGraphics;
  509. var
  510. I: TJSONObject;
  511. begin
  512. I := Page.Objects['image'];
  513. CharIndex := I.Integers['characterIndex'];
  514. CharFilename := I.Strings['characterName'];
  515. CharDir := I.Integers['direction'];
  516. CharPattern := I.Integers['pattern'];
  517. TileId := I.Integers['tileId'];
  518. LoadCharGraphics;
  519. end;
  520. procedure UpdateMove;
  521. begin
  522. MoveTypeComboBox.ItemIndex := Page.Integers['moveType'];
  523. //TODO: movement route
  524. MoveSpeedComboBox.ItemIndex := Page.Integers['moveSpeed'];
  525. MoveFreqComboBox.ItemIndex := Page.Integers['moveFrequency'];
  526. end;
  527. procedure UpdateOptions;
  528. begin
  529. WalkAnimCheckBox.Checked := Page.Booleans['walkAnime'];
  530. StepAnimCheckBox.Checked := Page.Booleans['stepAnime'];
  531. DirFixCheckBox.Checked := Page.Booleans['directionFix'];
  532. PassThroughCheckBox.Checked := Page.Booleans['through'];
  533. end;
  534. begin
  535. if Pages = nil then
  536. Exit;
  537. Page := Pages.Objects[PagesTabControl.TabIndex];
  538. UpdateConditions;
  539. UpdateGraphics;
  540. UpdateMove;
  541. UpdateOptions;
  542. PriorityComboBox.ItemIndex := Page.Integers['priorityType'];
  543. TriggerComboBox.ItemIndex := Page.Integers['trigger'];
  544. EventECListFrame.SetDatabase(Game.Db);
  545. EventECListFrame.SetList(Page.Arrays['list']);
  546. {TODO: update event command list}
  547. end;
  548. function TEventEditorForm.CreateEmptyPage: TJSONObject;
  549. begin
  550. Result := TJSONObject.Create([
  551. 'conditions', TJSONObject.Create([
  552. 'actorId', 1,
  553. 'actorValid', false,
  554. 'itemId', 1,
  555. 'itemValid', false,
  556. 'selfSwitchCh', 'A',
  557. 'selfSwitchValid', false,
  558. 'switch1Id', 1,
  559. 'switch1Valid', false,
  560. 'switch2Id', 1,
  561. 'switch2Valid', false,
  562. 'variableId', 1,
  563. 'variableValid', false,
  564. 'variableValue', 0
  565. ]),
  566. 'directionFix', false,
  567. 'image', TJSONObject.Create([
  568. 'tileId', 0,
  569. 'characterName', '',
  570. 'direction', 4,
  571. 'pattern', 1,
  572. 'characterIndex', 0
  573. ]),
  574. 'list', TJSONArray.Create([
  575. TJSONObject.Create([
  576. 'code', 0,
  577. 'indent', 0,
  578. 'parameters', TJSONArray.Create()
  579. ])
  580. ]),
  581. 'moveFrequency', 3,
  582. 'moveRoute', TJSONObject.Create([
  583. 'list', TJSONArray.Create([
  584. TJSONObject.Create([
  585. 'code', 0,
  586. 'parameters', TJSONArray.Create()
  587. ])
  588. ]),
  589. 'repeat', True,
  590. 'skippable', False,
  591. 'wait', False
  592. ]),
  593. 'moveSpeed', 3,
  594. 'moveType', 0,
  595. 'priorityType', 1,
  596. 'stepAnime', False,
  597. 'through', False,
  598. 'trigger', 0,
  599. 'walkAnime', True
  600. ]);
  601. end;
  602. procedure TEventEditorForm.UpdateEditButtons;
  603. begin
  604. Switch1EditButton.Text := Game.Db.GetSwitchName(Switch1Id);
  605. Switch2EditButton.Text := Game.Db.GetSwitchName(Switch2Id);
  606. VarEditButton.Text := Game.Db.GetVariableName(VarId);
  607. end;
  608. procedure TEventEditorForm.PresetComboboxes;
  609. begin
  610. ItemComboBox.Items.Clear;
  611. ActorComboBox.Items.Clear;
  612. with MoveTypeComboBox.Items do begin
  613. BeginUpdate;
  614. Clear;
  615. Add(rsEventMovement_Fixed);
  616. Add(rsEventMovement_Random);
  617. Add(rsEventMovement_Approach);
  618. Add(rsEventMovement_Custom);
  619. EndUpdate;
  620. end;
  621. MoveTypeComboBox.ItemHeight := 0;
  622. with MoveSpeedComboBox.Items do begin
  623. BeginUpdate;
  624. Clear;
  625. Add(rsEventSpeed_1);
  626. Add(rsEventSpeed_2);
  627. Add(rsEventSpeed_3);
  628. Add(rsEventSpeed_4);
  629. Add(rsEventSpeed_5);
  630. Add(rsEventSpeed_6);
  631. EndUpdate;
  632. end;
  633. MoveSpeedComboBox.ItemHeight := 4;
  634. with MoveFreqComboBox.Items do begin
  635. BeginUpdate;
  636. Clear;
  637. Add(rsEventFrequency_1);
  638. Add(rsEventFrequency_2);
  639. Add(rsEventFrequency_3);
  640. Add(rsEventFrequency_4);
  641. Add(rsEventFrequency_5);
  642. EndUpdate;
  643. end;
  644. MoveFreqComboBox.ItemHeight := 4;
  645. with PriorityComboBox.Items do begin
  646. BeginUpdate;
  647. Clear;
  648. Add(rsEventPriority_belowCharacters);
  649. Add(rsEventPriority_sameLevelAsCharacters);
  650. Add(rsEventPriority_overCharacters);
  651. EndUpdate;
  652. end;
  653. PriorityComboBox.ItemHeight := 0;
  654. with TriggerComboBox.Items do begin
  655. BeginUpdate;
  656. Clear;
  657. Add(rsEventTrigger_actionButton);
  658. Add(rsEventTrigger_playerTouch);
  659. Add(rsEventTrigger_eventTouch);
  660. Add(rsEventTrigger_autorun);
  661. Add(rsEventTrigger_parallelProcess);
  662. EndUpdate;
  663. end;
  664. TriggerComboBox.ItemIndex := 0;
  665. end;
  666. procedure TEventEditorForm.LoadCharGraphics;
  667. var
  668. Png: TBitmap;
  669. begin
  670. ImageSpeedButton.Glyph.Clear;
  671. if CharFilename <> '' then begin
  672. Png := Game.GetCharacterGraphics(CharFilename, CharIndex, CharDir, CharPattern);
  673. ImageSpeedButton.Glyph.Assign(Png);
  674. Png.Free;
  675. end else if TilesetGraphics <> nil then begin
  676. Png := TilesetGraphics.GetUpperTile(TileId);
  677. if Png <> nil then begin
  678. ImageSpeedButton.Glyph.Assign(Png);
  679. Png.Free;
  680. end;
  681. end;
  682. {TODO: show tile graphics}
  683. end;
  684. procedure TEventEditorForm.SaveEventData;
  685. var
  686. NewEvent: TJSONObject;
  687. begin
  688. SavePageChanges;
  689. NewEvent := TJSONObject.Create([
  690. 'id', EventId,
  691. 'name', NameEdit.Text,
  692. 'note', NoteEdit.Text,
  693. 'pages', Pages.Clone as TJSONArray,
  694. 'x', EventX,
  695. 'y', EventY
  696. ]);
  697. if EventId >= EventList.Count then
  698. EventList.Add(NewEvent)
  699. else
  700. EventList.Objects[EventId] := NewEvent;
  701. Game.MapIsDirty := True;
  702. end;
  703. end.