traitselector.pas 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. unit traitselector;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, StdCtrls,
  6. Spin, ButtonPanel, database, fpjson, LCLTranslator;
  7. const
  8. TRAIT_PAGE_RATES = 0;
  9. TRAIT_PAGE_STATS = 1;
  10. TRAIT_PAGE_ATTACK = 2;
  11. TRAIT_PAGE_SKILL = 3;
  12. TRAIT_PAGE_EQUIP = 4;
  13. TRAIT_PAGE_OTHER = 5;
  14. type
  15. { TTraitSelectorForm }
  16. TTraitSelectorForm = class(TForm)
  17. ActionTimesRadioButton: TRadioButton;
  18. ActionTimesFloatSpinEdit: TFloatSpinEdit;
  19. AttackStatePercentLabel1: TLabel;
  20. KnockoutEffectRadioButton: TRadioButton;
  21. KnockoutEffectComboBox: TComboBox;
  22. PartyAbilityComboBox: TComboBox;
  23. PartyAbilityRadioButton: TRadioButton;
  24. SpecialFlagRadioButton: TRadioButton;
  25. SpecialFlagComboBox: TComboBox;
  26. LockEquipComboBox: TComboBox;
  27. LockEquipRadioButton: TRadioButton;
  28. EquipWeaponComboBox: TComboBox;
  29. AddSkillTypeRadioButton: TRadioButton;
  30. EquipWeaponRadioButton: TRadioButton;
  31. SealEquipComboBox: TComboBox;
  32. SlotTypeComboBox: TComboBox;
  33. SealEquipRadioButton: TRadioButton;
  34. SlotTypeRadioButton: TRadioButton;
  35. SealSkillTypeComboBox: TComboBox;
  36. AddSkillComboBox: TComboBox;
  37. SealSkillComboBox: TComboBox;
  38. EquipArmourComboBox: TComboBox;
  39. SealSkillTypeRadioButton: TRadioButton;
  40. AddSkillTypeComboBox: TComboBox;
  41. AttackSpeedFloatSpinEdit: TFloatSpinEdit;
  42. AttacksPerTurnPlusFloatSpinEdit: TFloatSpinEdit;
  43. AttackSpeedRadioButton: TRadioButton;
  44. AttacksPerTurnPlusRadioButton: TRadioButton;
  45. AttackStateRadioButton: TRadioButton;
  46. DummyOtherRadioButton: TRadioButton;
  47. DummyEquipRadioButton: TRadioButton;
  48. DummySkillRadioButton: TRadioButton;
  49. DummyRatesRadioButton: TRadioButton;
  50. DummyAttackRadioButton: TRadioButton;
  51. DummyStatsRadioButton: TRadioButton;
  52. ExParamComboBox: TComboBox;
  53. AttackElementRadioButton: TRadioButton;
  54. AttackStateComboBox: TComboBox;
  55. AttackStateFloatSpinEdit: TFloatSpinEdit;
  56. AttackStatePlusSignLabel: TLabel;
  57. AttackStatePercentLabel: TLabel;
  58. ResultButtonPanel: TButtonPanel;
  59. AddSkillRadioButton: TRadioButton;
  60. SealSkillRadioButton: TRadioButton;
  61. EquipArmourRadioButton: TRadioButton;
  62. SpParamComboBox: TComboBox;
  63. ExParamFloatSpinEdit: TFloatSpinEdit;
  64. SpParamFloatSpinEdit: TFloatSpinEdit;
  65. ExParamPlusSignLabel: TLabel;
  66. SpParamMultiplySignLabel: TLabel;
  67. ExParamPercentLabel: TLabel;
  68. SpParamPercentLabel: TLabel;
  69. ParamRadioButton: TRadioButton;
  70. ParamComboBox: TComboBox;
  71. ParamFloatSpinEdit: TFloatSpinEdit;
  72. ParamMultiplySignLabel: TLabel;
  73. ParamPercentLabel: TLabel;
  74. ExParamRadioButton: TRadioButton;
  75. SpParamRadioButton: TRadioButton;
  76. StateRateRadioButton: TRadioButton;
  77. ElemRateElemComboBox: TComboBox;
  78. ElementRateRadioButton: TRadioButton;
  79. DebuffRateRadioButton: TRadioButton;
  80. DebuffRateParamComboBox: TComboBox;
  81. StateResistRadioButton: TRadioButton;
  82. StateRateStateComboBox: TComboBox;
  83. ElemRateFloatSpinEdit: TFloatSpinEdit;
  84. DebuffRateFloatSpinEdit: TFloatSpinEdit;
  85. StateRateFloatSpinEdit: TFloatSpinEdit;
  86. ElemRateMultiplySignLabel: TLabel;
  87. DebuffRateMultiplySignLabel: TLabel;
  88. StateRateMultiplySignLabel: TLabel;
  89. ElemRatePercentLabel: TLabel;
  90. DebuffRatePercentLabel: TLabel;
  91. StateRatePercentLabel: TLabel;
  92. RatesTabSheet: TTabSheet;
  93. StateResistStateComboBox: TComboBox;
  94. AttackElementComboBox: TComboBox;
  95. StatsTabSheet: TTabSheet;
  96. AttackTabSheet: TTabSheet;
  97. SkillTabSheet: TTabSheet;
  98. EquipTabSheet: TTabSheet;
  99. OtherTabSheet: TTabSheet;
  100. TraitSelectorPageControl: TPageControl;
  101. procedure ActionTimesRadioButtonChange(Sender: TObject);
  102. procedure AddSkillRadioButtonChange(Sender: TObject);
  103. procedure AddSkillTypeRadioButtonChange(Sender: TObject);
  104. procedure AttackElementRadioButtonChange(Sender: TObject);
  105. procedure AttackSpeedRadioButtonChange(Sender: TObject);
  106. procedure AttackStateRadioButtonChange(Sender: TObject);
  107. procedure AttacksPerTurnPlusRadioButtonChange(Sender: TObject);
  108. procedure CancelButtonClick(Sender: TObject);
  109. procedure KnockoutEffectRadioButtonChange(Sender: TObject);
  110. procedure DebuffRateRadioButtonChange(Sender: TObject);
  111. procedure ElementRateRadioButtonChange(Sender: TObject);
  112. procedure EquipArmourRadioButtonChange(Sender: TObject);
  113. procedure EquipWeaponRadioButtonChange(Sender: TObject);
  114. procedure ExParamRadioButtonChange(Sender: TObject);
  115. procedure FormCreate(Sender: TObject);
  116. procedure FormHide(Sender: TObject);
  117. procedure LockEquipRadioButtonChange(Sender: TObject);
  118. procedure OKButtonClick(Sender: TObject);
  119. procedure ParamRadioButtonChange(Sender: TObject);
  120. procedure PartyAbilityRadioButtonChange(Sender: TObject);
  121. procedure SealEquipRadioButtonChange(Sender: TObject);
  122. procedure SealSkillRadioButtonChange(Sender: TObject);
  123. procedure SealSkillTypeRadioButtonChange(Sender: TObject);
  124. procedure SlotTypeRadioButtonChange(Sender: TObject);
  125. procedure SpecialFlagRadioButtonChange(Sender: TObject);
  126. procedure SpParamRadioButtonChange(Sender: TObject);
  127. procedure StateRateRadioButtonChange(Sender: TObject);
  128. procedure StateResistRadioButtonChange(Sender: TObject);
  129. private
  130. ResultWasAccepted: Boolean;
  131. Db: TDatabase;
  132. { Move dummy radio buttons out of view without hiding, because I haven't
  133. found another way to unselect all the radio buttons :(( }
  134. procedure RepositionDummyRatioButtons;
  135. { Makes radio buttons unset on all pages except the page with the index
  136. passed (pass -1 to uncheck all pages). }
  137. procedure UnsetOptionsOnOtherPages(PageToKeep: Integer);
  138. procedure UnsetOptionsOnUnselectedPages;
  139. function GetSelectedTraitCode: Integer;
  140. function GetDataId(TraitCode: Integer): Integer;
  141. function GetValue(TraitCode: Integer): Double;
  142. procedure PresetValues(TraitCode: Integer; DataId: Integer; Value: Double);
  143. public
  144. SelectedCode: Integer;
  145. SelectedDataId: Integer;
  146. SelectedValue: Double;
  147. function ShowTraitSelection(ADb: TDatabase; TraitCode: Integer = -1; DataId: Integer = 0; Value: Double = 0): Boolean;
  148. end;
  149. var
  150. TraitSelectorForm: TTraitSelectorForm;
  151. implementation
  152. uses
  153. comboboxhelper;
  154. {$R *.lfm}
  155. { TTraitSelectorForm }
  156. procedure TTraitSelectorForm.FormCreate(Sender: TObject);
  157. begin
  158. RepositionDummyRatioButtons;
  159. UnsetOptionsOnOtherPages(-1);
  160. end;
  161. procedure TTraitSelectorForm.FormHide(Sender: TObject);
  162. begin
  163. UnsetOptionsOnOtherPages(-1);
  164. (* We clear the combobox values because they can be changed next time when
  165. the form is called (e.g. if user changes skill names, param names et al.),
  166. so we ensure they will be reloaded *)
  167. ElemRateElemComboBox.Items.Clear;
  168. DebuffRateParamComboBox.Items.Clear;
  169. StateRateStateComboBox.Items.Clear;
  170. StateResistStateComboBox.Items.Clear;
  171. ParamComboBox.Items.Clear;
  172. { Ex-Params and Sp-Params are not reloaded because users can't change them }
  173. //TODO: refresh params if language was changed?
  174. AttackElementComboBox.Items.Clear;
  175. AttackStateComboBox.Items.Clear;
  176. AddSkillTypeComboBox.Items.Clear;
  177. SealSkillTypeComboBox.Items.Clear;
  178. AddSkillComboBox.Items.Clear;
  179. SealSkillComboBox.Items.Clear;
  180. EquipWeaponComboBox.Items.Clear;
  181. EquipArmourComboBox.Items.Clear;
  182. LockEquipComboBox.Items.Clear;
  183. SealEquipComboBox.Items.Clear;
  184. { Slot type is not cleared because its options can't be changed}
  185. { Special flag, knockout effect and party ability are not cleared either }
  186. end;
  187. procedure TTraitSelectorForm.LockEquipRadioButtonChange(Sender: TObject);
  188. begin
  189. UnsetOptionsOnUnselectedPages;
  190. FillEquipTypeComboBox(LockEquipComboBox, Db);
  191. LockEquipComboBox.Enabled := LockEquipRadioButton.Checked;
  192. end;
  193. procedure TTraitSelectorForm.OKButtonClick(Sender: TObject);
  194. begin
  195. SelectedCode := GetSelectedTraitCode;
  196. SelectedDataId := GetDataId(SelectedCode);
  197. SelectedValue := GetValue(SelectedCode);
  198. ResultWasAccepted := True;
  199. Close;
  200. end;
  201. procedure TTraitSelectorForm.ParamRadioButtonChange(Sender: TObject);
  202. begin
  203. UnsetOptionsOnUnselectedPages;
  204. FillParameterComboBox(ParamComboBox, Db);
  205. ParamComboBox.Enabled := ParamRadioButton.Checked;
  206. ParamFloatSpinEdit.Enabled := ParamRadioButton.Checked;
  207. end;
  208. procedure TTraitSelectorForm.PartyAbilityRadioButtonChange(Sender: TObject);
  209. begin
  210. UnsetOptionsOnUnselectedPages;
  211. FillPartyFlagComboBox(PartyAbilityComboBox);
  212. PartyAbilityComboBox.Enabled := PartyAbilityRadioButton.Checked;
  213. end;
  214. procedure TTraitSelectorForm.SealEquipRadioButtonChange(Sender: TObject);
  215. begin
  216. UnsetOptionsOnUnselectedPages;
  217. FillEquipTypeComboBox(SealEquipComboBox, Db);
  218. SealEquipComboBox.Enabled := SealEquipRadioButton.Checked;
  219. end;
  220. procedure TTraitSelectorForm.SealSkillRadioButtonChange(Sender: TObject);
  221. begin
  222. UnsetOptionsOnUnselectedPages;
  223. FillSkillComboBox(SealSkillComboBox, Db);
  224. SealSkillComboBox.Enabled := SealSkillRadioButton.Checked;
  225. end;
  226. procedure TTraitSelectorForm.SealSkillTypeRadioButtonChange(Sender: TObject);
  227. begin
  228. UnsetOptionsOnUnselectedPages;
  229. FillSkillTypeComboBox(SealSkillTypeComboBox, Db);
  230. SealSkillTypeComboBox.Enabled := SealSkillTypeRadioButton.Checked;
  231. end;
  232. procedure TTraitSelectorForm.SlotTypeRadioButtonChange(Sender: TObject);
  233. begin
  234. UnsetOptionsOnUnselectedPages;
  235. if SlotTypeComboBox.Items.Count = 0 then begin
  236. SlotTypeComboBox.Items.BeginUpdate;
  237. SlotTypeComboBox.Items.Add('Normal slots');
  238. SlotTypeComboBox.Items.Add('Two weapons');
  239. SlotTypeComboBox.Items.EndUpdate;
  240. SlotTypeComboBox.ItemIndex := 0;
  241. end;
  242. SlotTypeComboBox.Enabled := SlotTypeRadioButton.Checked;
  243. end;
  244. procedure TTraitSelectorForm.SpecialFlagRadioButtonChange(Sender: TObject);
  245. begin
  246. UnsetOptionsOnUnselectedPages;
  247. FillSpecialFlagComboBox(SpecialFlagComboBox);
  248. SpecialFlagComboBox.Enabled := SpecialFlagRadioButton.Checked;
  249. end;
  250. procedure TTraitSelectorForm.SpParamRadioButtonChange(Sender: TObject);
  251. begin
  252. UnsetOptionsOnUnselectedPages;
  253. FillSpParameterComboBox(SpParamComboBox);
  254. SpParamComboBox.Enabled := SpParamRadioButton.Checked;
  255. SpParamFloatSpinEdit.Enabled := SpParamRadioButton.Checked;
  256. end;
  257. procedure TTraitSelectorForm.StateRateRadioButtonChange(Sender: TObject);
  258. begin
  259. UnsetOptionsOnUnselectedPages;
  260. FillStateComboBox(StateRateStateComboBox, Db);
  261. StateRateStateComboBox.Enabled := StateRateRadioButton.Checked;
  262. StateRateFloatSpinEdit.Enabled := StateRateRadioButton.Checked;
  263. end;
  264. procedure TTraitSelectorForm.StateResistRadioButtonChange(Sender: TObject);
  265. begin
  266. UnsetOptionsOnUnselectedPages;
  267. FillStateComboBox(StateResistStateComboBox, Db);
  268. StateResistStateComboBox.Enabled := StateResistRadioButton.Checked;
  269. end;
  270. procedure TTraitSelectorForm.RepositionDummyRatioButtons;
  271. begin
  272. // I hate this. But I haven't found a better way to unselect all radio buttons
  273. DummyRatesRadioButton.Left := -100;
  274. DummyStatsRadioButton.Left := -100;
  275. DummyAttackRadioButton.Left := -100;
  276. DummySkillRadioButton.Left := -100;
  277. DummyEquipRadioButton.Left := -100;
  278. DummyOtherRadioButton.Left := -100;
  279. end;
  280. procedure TTraitSelectorForm.ElementRateRadioButtonChange(Sender: TObject);
  281. begin
  282. UnsetOptionsOnUnselectedPages;
  283. FillElementComboBox(ElemRateElemComboBox, Db);
  284. ElemRateElemComboBox.Enabled := ElementRateRadioButton.Checked;
  285. ElemRateFloatSpinEdit.Enabled := ElementRateRadioButton.Checked;
  286. end;
  287. procedure TTraitSelectorForm.EquipArmourRadioButtonChange(Sender: TObject);
  288. begin
  289. UnsetOptionsOnUnselectedPages;
  290. FillArmourTypeComboBox(EquipArmourComboBox, Db);
  291. EquipArmourComboBox.Enabled := EquipArmourRadioButton.Checked;
  292. end;
  293. procedure TTraitSelectorForm.EquipWeaponRadioButtonChange(Sender: TObject);
  294. begin
  295. UnsetOptionsOnUnselectedPages;
  296. FillWeaponTypeComboBox(EquipWeaponComboBox, Db);
  297. EquipWeaponComboBox.Enabled := EquipWeaponRadioButton.Checked;
  298. end;
  299. procedure TTraitSelectorForm.ExParamRadioButtonChange(Sender: TObject);
  300. begin
  301. UnsetOptionsOnUnselectedPages;
  302. FillExParameterComboBox(ExParamComboBox);
  303. ExParamComboBox.Enabled := ExParamRadioButton.Checked;
  304. ExParamFloatSpinEdit.Enabled := ExParamRadioButton.Checked;
  305. end;
  306. procedure TTraitSelectorForm.DebuffRateRadioButtonChange(Sender: TObject);
  307. begin
  308. UnsetOptionsOnUnselectedPages;
  309. FillParameterComboBox(DebuffRateParamComboBox, Db);
  310. DebuffRateFloatSpinEdit.Enabled := DebuffRateRadioButton.Checked;
  311. DebuffRateParamComboBox.Enabled := DebuffRateRadioButton.Checked;
  312. end;
  313. procedure TTraitSelectorForm.AttackElementRadioButtonChange(Sender: TObject);
  314. begin
  315. UnsetOptionsOnUnselectedPages;
  316. FillElementComboBox(AttackElementComboBox, Db);
  317. AttackElementComboBox.Enabled := AttackElementRadioButton.Checked;
  318. end;
  319. procedure TTraitSelectorForm.AddSkillTypeRadioButtonChange(Sender: TObject);
  320. begin
  321. UnsetOptionsOnUnselectedPages;
  322. FillSkillTypeComboBox(AddSkillTypeComboBox, Db);
  323. AddSkillTypeComboBox.Enabled := AddSkillTypeRadioButton.Checked;
  324. end;
  325. procedure TTraitSelectorForm.AddSkillRadioButtonChange(Sender: TObject);
  326. begin
  327. UnsetOptionsOnUnselectedPages;
  328. FillSkillComboBox(AddSkillComboBox, Db);
  329. AddSkillComboBox.Enabled := AddSkillRadioButton.Checked;
  330. end;
  331. procedure TTraitSelectorForm.ActionTimesRadioButtonChange(Sender: TObject);
  332. begin
  333. UnsetOptionsOnUnselectedPages;
  334. ActionTimesFloatSpinEdit.Enabled := ActionTimesRadioButton.Checked;
  335. end;
  336. procedure TTraitSelectorForm.AttackSpeedRadioButtonChange(Sender: TObject);
  337. begin
  338. UnsetOptionsOnUnselectedPages;
  339. AttackSpeedFloatSpinEdit.Enabled := AttackSpeedRadioButton.Checked;
  340. end;
  341. procedure TTraitSelectorForm.AttackStateRadioButtonChange(Sender: TObject);
  342. begin
  343. UnsetOptionsOnUnselectedPages;
  344. FillStateComboBox(AttackStateComboBox, Db);
  345. AttackStateComboBox.Enabled := AttackStateRadioButton.Checked;
  346. AttackStateFloatSpinEdit.Enabled := AttackStateRadioButton.Checked;
  347. end;
  348. procedure TTraitSelectorForm.AttacksPerTurnPlusRadioButtonChange(Sender: TObject);
  349. begin
  350. UnsetOptionsOnUnselectedPages;
  351. AttacksPerTurnPlusFloatSpinEdit.Enabled := AttacksPerTurnPlusRadioButton.Checked;
  352. end;
  353. procedure TTraitSelectorForm.CancelButtonClick(Sender: TObject);
  354. begin
  355. ResultWasAccepted := False;
  356. end;
  357. procedure TTraitSelectorForm.KnockoutEffectRadioButtonChange(Sender: TObject);
  358. begin
  359. UnsetOptionsOnUnselectedPages;
  360. FillKnockoutEffectComboBox(KnockoutEffectComboBox);
  361. KnockoutEffectComboBox.Enabled := KnockoutEffectRadioButton.Checked;
  362. end;
  363. procedure TTraitSelectorForm.UnsetOptionsOnOtherPages(PageToKeep: Integer);
  364. begin
  365. if PageToKeep <> TRAIT_PAGE_RATES then
  366. DummyRatesRadioButton.Checked := True;
  367. if PageToKeep <> TRAIT_PAGE_STATS then
  368. DummyStatsRadioButton.Checked := True;
  369. if PageToKeep <> TRAIT_PAGE_ATTACK then
  370. DummyAttackRadioButton.Checked := True;
  371. if PageToKeep <> TRAIT_PAGE_SKILL then
  372. DummySkillRadioButton.Checked := True;
  373. if PageToKeep <> TRAIT_PAGE_EQUIP then
  374. DummyEquipRadioButton.Checked := True;
  375. if PageToKeep <> TRAIT_PAGE_OTHER then
  376. DummyOtherRadioButton.Checked := True;
  377. end;
  378. procedure TTraitSelectorForm.UnsetOptionsOnUnselectedPages;
  379. begin
  380. UnsetOptionsOnOtherPages(TraitSelectorPageControl.ActivePageIndex);
  381. end;
  382. function TTraitSelectorForm.GetSelectedTraitCode: Integer;
  383. begin
  384. if ElementRateRadioButton.Checked then
  385. GetSelectedTraitCode := TRAIT_ELEMENT_RATE
  386. else if DebuffRateRadioButton.Checked then
  387. GetSelectedTraitCode := TRAIT_DEBUFF_RATE
  388. else if StateRateRadioButton.Checked then
  389. GetSelectedTraitCode := TRAIT_STATE_RATE
  390. else if StateResistRadioButton.Checked then
  391. GetSelectedTraitCode := TRAIT_STATE_RESIST
  392. else if ParamRadioButton.Checked then
  393. GetSelectedTraitCode := TRAIT_PARAM
  394. else if ExParamRadioButton.Checked then
  395. GetSelectedTraitCode := TRAIT_XPARAM
  396. else if SpParamRadioButton.Checked then
  397. GetSelectedTraitCode := TRAIT_SPARAM
  398. else if AttackElementRadioButton.Checked then
  399. GetSelectedTraitCode := TRAIT_ATTACK_ELEMENT
  400. else if AttackStateRadioButton.Checked then
  401. GetSelectedTraitCode := TRAIT_ATTACK_STATE
  402. else if AttackSpeedRadioButton.Checked then
  403. GetSelectedTraitCode := TRAIT_ATTACK_SPEED
  404. else if AttacksPerTurnPlusRadioButton.Checked then
  405. GetSelectedTraitCode := TRAIT_ATTACK_TIMES
  406. else if AddSkillTypeRadioButton.Checked then
  407. GetSelectedTraitCode := TRAIT_STYPE_ADD
  408. else if SealSkillTypeRadioButton.Checked then
  409. GetSelectedTraitCode := TRAIT_STYPE_SEAL
  410. else if AddSkillRadioButton.Checked then
  411. GetSelectedTraitCode := TRAIT_SKILL_ADD
  412. else if SealSkillRadioButton.Checked then
  413. GetSelectedTraitCode := TRAIT_SKILL_SEAL
  414. else if EquipWeaponRadioButton.Checked then
  415. GetSelectedTraitCode := TRAIT_EQUIP_WTYPE
  416. else if EquipArmourRadioButton.Checked then
  417. GetSelectedTraitCode := TRAIT_EQUIP_ATYPE
  418. else if LockEquipRadioButton.Checked then
  419. GetSelectedTraitCode := TRAIT_EQUIP_LOCK
  420. else if SealEquipRadioButton.Checked then
  421. GetSelectedTraitCode := TRAIT_EQUIP_SEAL
  422. else if SlotTypeRadioButton.Checked then
  423. GetSelectedTraitCode := TRAIT_SLOT_TYPE
  424. else if ActionTimesRadioButton.Checked then
  425. GetSelectedTraitCode := TRAIT_ACTION_PLUS
  426. else if SpecialFlagRadioButton.Checked then
  427. GetSelectedTraitCode := TRAIT_SPECIAL_FLAG
  428. else if KnockoutEffectRadioButton.Checked then
  429. GetSelectedTraitCode := TRAIT_COLLAPSE_TYPE
  430. else if PartyAbilityRadioButton.Checked then
  431. GetSelectedTraitCode := TRAIT_PARTY_ABILITY
  432. end;
  433. function TTraitSelectorForm.GetDataId(TraitCode: Integer): Integer;
  434. begin
  435. case TraitCode of
  436. TRAIT_ELEMENT_RATE:
  437. GetDataId := ElemRateElemComboBox.ItemIndex + 1;
  438. TRAIT_DEBUFF_RATE:
  439. GetDataId := DebuffRateParamComboBox.ItemIndex;
  440. TRAIT_STATE_RATE:
  441. GetDataId := StateRateStateComboBox.ItemIndex + 1;
  442. TRAIT_STATE_RESIST:
  443. GetDataId := StateResistStateComboBox.ItemIndex + 1;
  444. TRAIT_PARAM:
  445. GetDataId := ParamComboBox.ItemIndex;
  446. TRAIT_XPARAM:
  447. GetDataId := ExParamComboBox.ItemIndex;
  448. TRAIT_SPARAM:
  449. GetDataId := SpParamComboBox.ItemIndex;
  450. TRAIT_ATTACK_ELEMENT:
  451. GetDataId := AttackElementComboBox.ItemIndex + 1;
  452. TRAIT_ATTACK_STATE:
  453. GetDataId := AttackStateComboBox.ItemIndex + 1;
  454. TRAIT_STYPE_ADD:
  455. GetDataId := AddSkillTypeComboBox.ItemIndex + 1;
  456. TRAIT_STYPE_SEAL:
  457. GetDataId := SealSkillTypeComboBox.ItemIndex + 1;
  458. TRAIT_SKILL_ADD:
  459. GetDataId := AddSkillComboBox.ItemIndex + 1;
  460. TRAIT_SKILL_SEAL:
  461. GetDataId := SealSkillComboBox.ItemIndex + 1;
  462. TRAIT_EQUIP_WTYPE:
  463. GetDataId := EquipWeaponComboBox.ItemIndex + 1;
  464. TRAIT_EQUIP_ATYPE:
  465. GetDataId := EquipArmourComboBox.ItemIndex + 1;
  466. TRAIT_EQUIP_LOCK:
  467. GetDataId := LockEquipComboBox.ItemIndex + 1;
  468. TRAIT_EQUIP_SEAL:
  469. GetDataId := SealEquipComboBox.ItemIndex + 1;
  470. TRAIT_SPECIAL_FLAG:
  471. GetDataId := SpecialFlagComboBox.ItemIndex;
  472. TRAIT_COLLAPSE_TYPE:
  473. GetDataId := KnockoutEffectComboBox.ItemIndex;
  474. TRAIT_PARTY_ABILITY:
  475. GetDataId := PartyAbilityComboBox.ItemIndex;
  476. else
  477. GetDataId := 0
  478. end;
  479. end;
  480. function TTraitSelectorForm.GetValue(TraitCode: Integer): Double;
  481. begin
  482. case TraitCode of
  483. TRAIT_ELEMENT_RATE:
  484. GetValue := ElemRateFloatSpinEdit.Value / 100.0;
  485. TRAIT_DEBUFF_RATE:
  486. GetValue := DebuffRateFloatSpinEdit.Value / 100.0;
  487. TRAIT_STATE_RATE:
  488. GetValue := StateRateFloatSpinEdit.Value / 100.0;
  489. TRAIT_PARAM:
  490. GetValue := ParamFloatSpinEdit.Value / 100.0;
  491. TRAIT_XPARAM:
  492. GetValue := ExParamFloatSpinEdit.Value / 100.0;
  493. TRAIT_SPARAM:
  494. GetValue := SpParamFloatSpinEdit.Value / 100.0;
  495. TRAIT_ATTACK_STATE:
  496. GetValue := AttackStateFloatSpinEdit.Value / 100.0;
  497. TRAIT_ATTACK_SPEED:
  498. GetValue := AttackSpeedFloatSpinEdit.Value;
  499. TRAIT_ATTACK_TIMES:
  500. GetValue := AttacksPerTurnPlusFloatSpinEdit.Value;
  501. TRAIT_SLOT_TYPE:
  502. GetValue := SlotTypeComboBox.ItemIndex;
  503. TRAIT_ACTION_PLUS:
  504. GetValue := ActionTimesFloatSpinEdit.Value / 100.0;
  505. else
  506. GetValue := 0
  507. end;
  508. end;
  509. function TTraitSelectorForm.ShowTraitSelection(ADb: TDatabase; TraitCode: Integer = -1; DataId: Integer = 0; Value: Double = 0): Boolean;
  510. begin
  511. Db := ADb;
  512. ResultWasAccepted := False;
  513. PresetValues(TraitCode, DataId, Value);
  514. ShowModal;
  515. ShowTraitSelection := ResultWasAccepted;
  516. end;
  517. procedure TTraitSelectorForm.PresetValues(TraitCode: Integer; DataId: Integer; Value: Double);
  518. begin
  519. case TraitCode of
  520. TRAIT_ELEMENT_RATE: begin
  521. TraitSelectorPageControl.ActivePageIndex := TRAIT_PAGE_RATES;
  522. ElementRateRadioButton.Checked := True;
  523. ElemRateElemComboBox.ItemIndex := DataId - 1;
  524. ElemRateFloatSpinEdit.Value := Value * 100.0;
  525. end;
  526. TRAIT_DEBUFF_RATE: begin
  527. TraitSelectorPageControl.ActivePageIndex := TRAIT_PAGE_RATES;
  528. DebuffRateRadioButton.Checked := True;
  529. DebuffRateParamComboBox.ItemIndex := DataId;
  530. DebuffRateFloatSpinEdit.Value := Value * 100.0;
  531. end;
  532. TRAIT_STATE_RATE: begin
  533. TraitSelectorPageControl.ActivePageIndex := TRAIT_PAGE_RATES;
  534. StateRateRadioButton.Checked := True;
  535. StateRateStateComboBox.ItemIndex := DataId - 1;
  536. StateRateFloatSpinEdit.Value := Value * 100.0;
  537. end;
  538. TRAIT_STATE_RESIST: begin
  539. TraitSelectorPageControl.ActivePageIndex := TRAIT_PAGE_RATES;
  540. StateResistRadioButton.Checked := True;
  541. StateResistStateComboBox.ItemIndex := DataId - 1;
  542. end;
  543. TRAIT_PARAM: begin
  544. TraitSelectorPageControl.ActivePageIndex := TRAIT_PAGE_STATS;
  545. ParamRadioButton.Checked := True;
  546. ParamComboBox.ItemIndex := DataId;
  547. ParamFloatSpinEdit.Value := Value * 100.0;
  548. end;
  549. TRAIT_XPARAM: begin
  550. TraitSelectorPageControl.ActivePageIndex := TRAIT_PAGE_STATS;
  551. ExParamRadioButton.Checked := True;
  552. ExParamComboBox.ItemIndex := DataId;
  553. ExParamFloatSpinEdit.Value := Value * 100.0;
  554. end;
  555. TRAIT_SPARAM: begin
  556. TraitSelectorPageControl.ActivePageIndex := TRAIT_PAGE_STATS;
  557. SpParamRadioButton.Checked := True;
  558. SpParamComboBox.ItemIndex := DataId;
  559. SpParamFloatSpinEdit.Value := Value * 100.0;
  560. end;
  561. TRAIT_ATTACK_ELEMENT: begin
  562. TraitSelectorPageControl.ActivePageIndex := TRAIT_PAGE_ATTACK;
  563. AttackElementRadioButton.Checked := True;
  564. AttackElementComboBox.ItemIndex := DataId - 1;
  565. end;
  566. TRAIT_ATTACK_STATE: begin
  567. TraitSelectorPageControl.ActivePageIndex := TRAIT_PAGE_ATTACK;
  568. AttackStateRadioButton.Checked := True;
  569. AttackStateFloatSpinEdit.Value := Value * 100.0;
  570. end;
  571. TRAIT_ATTACK_SPEED: begin
  572. TraitSelectorPageControl.ActivePageIndex := TRAIT_PAGE_ATTACK;
  573. AttackSpeedRadioButton.Checked := True;
  574. AttackStateFloatSpinEdit.Value := Value;
  575. end;
  576. TRAIT_ATTACK_TIMES: begin
  577. TraitSelectorPageControl.ActivePageIndex := TRAIT_PAGE_ATTACK;
  578. AttacksPerTurnPlusRadioButton.Checked := True;
  579. AttacksPerTurnPlusFloatSpinEdit.Value := Value;
  580. end;
  581. TRAIT_STYPE_ADD: begin
  582. TraitSelectorPageControl.ActivePageIndex:= TRAIT_PAGE_SKILL;
  583. AddSkillTypeRadioButton.Checked := True;
  584. AddSkillTypeComboBox.ItemIndex := DataId - 1;
  585. end;
  586. TRAIT_STYPE_SEAL: begin
  587. TraitSelectorPageControl.ActivePageIndex:= TRAIT_PAGE_SKILL;
  588. SealSkillTypeRadioButton.Checked := True;
  589. SealSkillTypeComboBox.ItemIndex := DataId - 1;
  590. end;
  591. TRAIT_SKILL_ADD: begin
  592. TraitSelectorPageControl.ActivePageIndex:= TRAIT_PAGE_SKILL;
  593. AddSkillRadioButton.Checked := True;
  594. AddSkillComboBox.ItemIndex := DataId - 1;
  595. end;
  596. TRAIT_SKILL_SEAL: begin
  597. TraitSelectorPageControl.ActivePageIndex:= TRAIT_PAGE_SKILL;
  598. SealSkillRadioButton.Checked := True;
  599. SealSkillComboBox.ItemIndex := DataId - 1;
  600. end;
  601. TRAIT_EQUIP_WTYPE: begin
  602. TraitSelectorPageControl.ActivePageIndex:= TRAIT_PAGE_EQUIP;
  603. EquipWeaponRadioButton.Checked := True;
  604. EquipWeaponComboBox.ItemIndex := DataId - 1;
  605. end;
  606. TRAIT_EQUIP_ATYPE: begin
  607. TraitSelectorPageControl.ActivePageIndex:= TRAIT_PAGE_EQUIP;
  608. EquipArmourRadioButton.Checked := True;
  609. EquipArmourComboBox.ItemIndex := DataId - 1;
  610. end;
  611. TRAIT_EQUIP_LOCK: begin
  612. TraitSelectorPageControl.ActivePageIndex:= TRAIT_PAGE_EQUIP;
  613. LockEquipRadioButton.Checked := True;
  614. LockEquipComboBox.ItemIndex := DataId - 1;
  615. end;
  616. TRAIT_EQUIP_SEAL: begin
  617. TraitSelectorPageControl.ActivePageIndex:= TRAIT_PAGE_EQUIP;
  618. SealEquipRadioButton.Checked := True;
  619. SealEquipComboBox.ItemIndex := DataId - 1;
  620. end;
  621. TRAIT_SLOT_TYPE: begin
  622. TraitSelectorPageControl.ActivePageIndex := TRAIT_PAGE_EQUIP;
  623. SlotTypeRadioButton.Checked := True;
  624. SlotTypeComboBox.ItemIndex := Round(Value) - 1;
  625. end;
  626. TRAIT_ACTION_PLUS: begin
  627. TraitSelectorPageControl.ActivePageIndex := TRAIT_PAGE_OTHER;
  628. ActionTimesRadioButton.Checked := True;
  629. ActionTimesFloatSpinEdit.Value := Value * 100;
  630. end;
  631. TRAIT_SPECIAL_FLAG: begin
  632. TraitSelectorPageControl.ActivePageIndex := TRAIT_PAGE_OTHER;
  633. SpecialFlagRadioButton.Checked := True;
  634. SpecialFlagComboBox.ItemIndex := DataId;
  635. end;
  636. TRAIT_COLLAPSE_TYPE: begin
  637. TraitSelectorPageControl.ActivePageIndex := TRAIT_PAGE_OTHER;
  638. KnockoutEffectRadioButton.Checked := True;
  639. KnockoutEffectComboBox.ItemIndex := DataId;
  640. end;
  641. TRAIT_PARTY_ABILITY: begin
  642. TraitSelectorPageControl.ActivePageIndex := TRAIT_PAGE_OTHER;
  643. PartyAbilityRadioButton.Checked := True;
  644. PartyAbilityComboBox.ItemIndex := DataId;
  645. end;
  646. else
  647. UnsetOptionsOnOtherPages(-1);
  648. end;
  649. end;
  650. end.