effectselector.pas 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. unit effectselector;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, StdCtrls,
  6. Spin, ExtCtrls, ButtonPanel, database, LCLTranslator;
  7. type
  8. { TEffectSelectorForm }
  9. TEffectSelectorForm = class(TForm)
  10. AddStateComboBox: TComboBox;
  11. AddBuffComboBox: TComboBox;
  12. AddDebuffComboBox: TComboBox;
  13. AddDebuffRadioButton: TRadioButton;
  14. AddDebuffTurnsLabel: TLabel;
  15. CommonEventComboBox: TComboBox;
  16. LearnSkillComboBox: TComboBox;
  17. IncreaseParamComboBox: TComboBox;
  18. IncreaseParameterRadioButton: TRadioButton;
  19. LearnSkillRadioButton: TRadioButton;
  20. CommonEventRadioButton: TRadioButton;
  21. DummyBuffsDebuffsRadioButton: TRadioButton;
  22. DummyOtherRadioButton: TRadioButton;
  23. SpecialEscapeRadioButton: TRadioButton;
  24. RemoveDebuffComboBox: TComboBox;
  25. RemoveDebuffRadioButton: TRadioButton;
  26. RemoveBuffRadioButton: TRadioButton;
  27. RemoveBuffComboBox: TComboBox;
  28. ResultButtonPanel: TButtonPanel;
  29. DummyHpMpTpRadioButton: TRadioButton;
  30. DummyStateRadioButton: TRadioButton;
  31. AddBuffRadioButton: TRadioButton;
  32. AddBuffTurnsLabel: TLabel;
  33. RemoveStatePercentLabel: TLabel;
  34. RemoveStateRadioButton: TRadioButton;
  35. RemoveStateComboBox: TComboBox;
  36. EffectPageControl: TPageControl;
  37. GainTpRadioButton: TRadioButton;
  38. AddStateRadioButton: TRadioButton;
  39. AddStatePercentLabel: TLabel;
  40. RecoverHpPlusLabel: TLabel;
  41. RecoverMpPlusLabel: TLabel;
  42. RecoverMpConstSpinEdit: TSpinEdit;
  43. RecoverMpRadioButton: TRadioButton;
  44. RecoverMpPercentageSpinEdit: TSpinEdit;
  45. RecoverHpPercentLabel: TLabel;
  46. RecoverMpPercentLabel: TLabel;
  47. RecoverHpRadioButton: TRadioButton;
  48. HpMpTpTabSheet: TTabSheet;
  49. RecoverHpPercentageSpinEdit: TSpinEdit;
  50. RecoverHpConstSpinEdit: TSpinEdit;
  51. GainTpSpinEdit: TSpinEdit;
  52. AddStateRateSpinEdit: TSpinEdit;
  53. RemoveStateRateSpinEdit: TSpinEdit;
  54. AddBuffTurnsSpinEdit: TSpinEdit;
  55. AddDebuffTurnsSpinEdit: TSpinEdit;
  56. IncreaseParamSpinEdit: TSpinEdit;
  57. StateTabSheet: TTabSheet;
  58. ParamTabSheet: TTabSheet;
  59. OtherTabSheet: TTabSheet;
  60. procedure AddBuffRadioButtonChange(Sender: TObject);
  61. procedure AddDebuffRadioButtonChange(Sender: TObject);
  62. procedure AddStateRadioButtonChange(Sender: TObject);
  63. procedure CancelButtonClick(Sender: TObject);
  64. procedure CommonEventRadioButtonChange(Sender: TObject);
  65. procedure FormCreate(Sender: TObject);
  66. procedure FormHide(Sender: TObject);
  67. procedure GainTpRadioButtonChange(Sender: TObject);
  68. procedure IncreaseParameterRadioButtonChange(Sender: TObject);
  69. procedure LearnSkillRadioButtonChange(Sender: TObject);
  70. procedure OKButtonClick(Sender: TObject);
  71. procedure RecoverHpRadioButtonChange(Sender: TObject);
  72. procedure RecoverMpRadioButtonChange(Sender: TObject);
  73. procedure RemoveBuffRadioButtonChange(Sender: TObject);
  74. procedure RemoveDebuffRadioButtonChange(Sender: TObject);
  75. procedure RemoveStateRadioButtonChange(Sender: TObject);
  76. procedure SpecialEscapeRadioButtonChange(Sender: TObject);
  77. private
  78. Db: TDatabase;
  79. ResultWasAccepted: Boolean;
  80. procedure PresetValues(EffectCode: Integer = -1; DataId: Integer = 0; Value1: Double = 0.0; Value2: Double = 0.0);
  81. procedure RepositionDummyRatioButtons;
  82. procedure UnsetOptionsOnOtherPages(PageToKeep: Integer);
  83. function GetSelectedEffectCode: Integer;
  84. function GetDataId(EffectCode: Integer): Integer;
  85. function GetValue1(EffectCode: Integer): Double;
  86. function GetValue2(EffectCode: Integer): Double;
  87. procedure SetSelectedValues;
  88. procedure UnsetOptionsOnUnselectedPages;
  89. public
  90. SelectedCode: Integer;
  91. SelectedDataId: Integer;
  92. SelectedValue1: Double;
  93. SelectedValue2: Double;
  94. function ShowEffectSelection(ADb: TDatabase; EffectCode: Integer = -1; DataId: Integer = 0; Value1: Double = 0.0; Value2: Double = 0.0): Boolean;
  95. end;
  96. const
  97. EFFECT_PAGE_HPMPTP = 0;
  98. EFFECT_PAGE_STATE = 1;
  99. EFFECT_PAGE_BUFF_DEBUFF = 2;
  100. EFFECT_PAGE_OTHER = 3;
  101. var
  102. EffectSelectorForm: TEffectSelectorForm;
  103. implementation
  104. uses
  105. comboboxhelper;
  106. {$R *.lfm}
  107. { TEffectSelectorForm }
  108. procedure TEffectSelectorForm.FormHide(Sender: TObject);
  109. begin
  110. SetSelectedValues;
  111. UnsetOptionsOnOtherPages(-1);
  112. AddStateComboBox.Items.Clear;
  113. RemoveStateComboBox.Items.Clear;
  114. AddBuffComboBox.Items.Clear;
  115. AddDebuffComboBox.Items.Clear;
  116. RemoveBuffComboBox.Items.Clear;
  117. RemoveDebuffComboBox.Items.Clear;
  118. IncreaseParamComboBox.Items.Clear;
  119. LearnSkillComboBox.Items.Clear;
  120. CommonEventComboBox.Items.Clear;
  121. end;
  122. procedure TEffectSelectorForm.AddStateRadioButtonChange(Sender: TObject);
  123. begin
  124. UnsetOptionsOnUnselectedPages;
  125. FillStateComboBox(AddStateComboBox, Db, True);
  126. AddStateComboBox.Enabled := AddStateRadioButton.Checked;
  127. AddStateRateSpinEdit.Enabled := AddStateRadioButton.Checked;
  128. end;
  129. procedure TEffectSelectorForm.CancelButtonClick(Sender: TObject);
  130. begin
  131. ResultWasAccepted := False;
  132. Close
  133. end;
  134. procedure TEffectSelectorForm.CommonEventRadioButtonChange(Sender: TObject);
  135. begin
  136. UnsetOptionsOnUnselectedPages;
  137. FillCommonEventComboBox(CommonEventComboBox, Db);
  138. CommonEventComboBox.Enabled := CommonEventRadioButton.Checked;
  139. end;
  140. procedure TEffectSelectorForm.FormCreate(Sender: TObject);
  141. begin
  142. RepositionDummyRatioButtons;
  143. UnsetOptionsOnOtherPages(-1);
  144. end;
  145. procedure TEffectSelectorForm.AddBuffRadioButtonChange(Sender: TObject);
  146. begin
  147. UnsetOptionsOnUnselectedPages;
  148. FillParameterComboBox(AddBuffComboBox, Db);
  149. AddBuffComboBox.Enabled := AddBuffRadioButton.Checked;
  150. AddBuffTurnsSpinEdit.Enabled := AddBuffRadioButton.Checked;
  151. end;
  152. procedure TEffectSelectorForm.AddDebuffRadioButtonChange(Sender: TObject);
  153. begin
  154. UnsetOptionsOnUnselectedPages;
  155. FillParameterComboBox(AddDebuffComboBox, Db);
  156. AddDebuffComboBox.Enabled := AddDebuffRadioButton.Checked;
  157. AddDebuffTurnsSpinEdit.Enabled := AddDebuffRadioButton.Checked;
  158. end;
  159. procedure TEffectSelectorForm.GainTpRadioButtonChange(Sender: TObject);
  160. begin
  161. UnsetOptionsOnUnselectedPages;
  162. GainTpSpinEdit.Enabled := GainTpRadioButton.Checked;
  163. end;
  164. procedure TEffectSelectorForm.IncreaseParameterRadioButtonChange(Sender: TObject
  165. );
  166. begin
  167. UnsetOptionsOnUnselectedPages;
  168. FillParameterComboBox(IncreaseParamComboBox, Db);
  169. IncreaseParamComboBox.Enabled := IncreaseParameterRadioButton.Checked;
  170. IncreaseParamSpinEdit.Enabled := IncreaseParameterRadioButton.Checked;
  171. end;
  172. procedure TEffectSelectorForm.LearnSkillRadioButtonChange(Sender: TObject);
  173. begin
  174. UnsetOptionsOnUnselectedPages;
  175. FillSkillComboBox(LearnSkillComboBox, Db);
  176. LearnSkillComboBox.Enabled := LearnSkillRadioButton.Checked;
  177. end;
  178. procedure TEffectSelectorForm.OKButtonClick(Sender: TObject);
  179. begin
  180. ResultWasAccepted := True;
  181. Close
  182. end;
  183. procedure TEffectSelectorForm.RecoverHpRadioButtonChange(Sender: TObject);
  184. begin
  185. UnsetOptionsOnUnselectedPages;
  186. RecoverHpConstSpinEdit.Enabled := RecoverHpRadioButton.Checked;
  187. RecoverHpPercentageSpinEdit.Enabled := RecoverHpRadioButton.Checked;
  188. end;
  189. procedure TEffectSelectorForm.RecoverMpRadioButtonChange(Sender: TObject);
  190. begin
  191. UnsetOptionsOnUnselectedPages;
  192. RecoverMpConstSpinEdit.Enabled := RecoverMpRadioButton.Checked;
  193. RecoverMpPercentageSpinEdit.Enabled := RecoverMpRadioButton.Checked;
  194. end;
  195. procedure TEffectSelectorForm.RemoveBuffRadioButtonChange(Sender: TObject);
  196. begin
  197. UnsetOptionsOnUnselectedPages;
  198. FillParameterComboBox(RemoveBuffComboBox, Db);
  199. RemoveBuffComboBox.Enabled := RemoveBuffRadioButton.Checked;
  200. end;
  201. procedure TEffectSelectorForm.RemoveDebuffRadioButtonChange(Sender: TObject);
  202. begin
  203. UnsetOptionsOnUnselectedPages;
  204. FillParameterComboBox(RemoveDebuffComboBox, Db);
  205. RemoveDebuffComboBox.Enabled := RemoveDebuffRadioButton.Checked;
  206. end;
  207. procedure TEffectSelectorForm.RemoveStateRadioButtonChange(Sender: TObject);
  208. begin
  209. UnsetOptionsOnUnselectedPages;
  210. FillStateComboBox(RemoveStateComboBox, Db);
  211. RemoveStateComboBox.Enabled := RemoveStateRadioButton.Checked;
  212. RemoveStateRateSpinEdit.Enabled := RemoveStateRadioButton.Checked;
  213. end;
  214. procedure TEffectSelectorForm.SpecialEscapeRadioButtonChange(Sender: TObject);
  215. begin
  216. UnsetOptionsOnUnselectedPages;
  217. end;
  218. procedure TEffectSelectorForm.PresetValues(EffectCode: Integer;
  219. DataId: Integer; Value1: Double; Value2: Double);
  220. begin
  221. case EffectCode of
  222. EFFECT_RECOVER_HP: begin
  223. EffectPageControl.ActivePageIndex := EFFECT_PAGE_HPMPTP;
  224. RecoverHpRadioButton.Checked := True;
  225. RecoverHpPercentageSpinEdit.Value := Round(Value1 * 100);
  226. RecoverHpConstSpinEdit.Value := Round(Value2);
  227. end;
  228. EFFECT_RECOVER_MP: begin
  229. EffectPageControl.ActivePageIndex := EFFECT_PAGE_HPMPTP;
  230. RecoverMpRadioButton.Checked := True;
  231. RecoverMpPercentageSpinEdit.Value := Round(Value1 * 100);
  232. RecoverMpConstSpinEdit.Value := Round(Value2);
  233. end;
  234. EFFECT_GAIN_TP: begin
  235. EffectPageControl.ActivePageIndex := EFFECT_PAGE_HPMPTP;
  236. GainTpRadioButton.Checked := True;
  237. GainTpSpinEdit.Value := Round(Value1);
  238. end;
  239. EFFECT_ADD_STATE: begin
  240. EffectPageControl.ActivePageIndex := EFFECT_PAGE_STATE;
  241. AddStateRadioButton.Checked := True;
  242. AddStateComboBox.ItemIndex := DataId;
  243. AddStateRateSpinEdit.Value := Round(Value1 * 100);
  244. end;
  245. EFFECT_REMOVE_STATE: begin
  246. EffectPageControl.ActivePageIndex := EFFECT_PAGE_STATE;
  247. RemoveStateRadioButton.Checked := True;
  248. RemoveStateComboBox.ItemIndex := DataId - 1;
  249. RemoveStateRateSpinEdit.Value := Round(Value1 * 100);
  250. end;
  251. EFFECT_ADD_BUFF: begin
  252. EffectPageControl.ActivePageIndex := EFFECT_PAGE_BUFF_DEBUFF;
  253. AddBuffRadioButton.Checked := True;
  254. AddBuffComboBox.ItemIndex := DataId;
  255. AddBuffTurnsSpinEdit.Value := Round(Value1);
  256. end;
  257. EFFECT_ADD_DEBUFF: begin
  258. EffectPageControl.ActivePageIndex := EFFECT_PAGE_BUFF_DEBUFF;
  259. AddDebuffRadioButton.Checked := True;
  260. AddDebuffComboBox.ItemIndex := DataId;
  261. AddDebuffTurnsSpinEdit.Value := Round(Value1);
  262. end;
  263. EFFECT_REMOVE_BUFF: begin
  264. EffectPageControl.ActivePageIndex := EFFECT_PAGE_BUFF_DEBUFF;
  265. RemoveBuffRadioButton.Checked := True;
  266. RemoveBuffComboBox.ItemIndex := DataId;
  267. end;
  268. EFFECT_REMOVE_DEBUFF: begin
  269. EffectPageControl.ActivePageIndex := EFFECT_PAGE_BUFF_DEBUFF;
  270. RemoveDebuffRadioButton.Checked := True;
  271. RemoveDebuffComboBox.ItemIndex := DataId;
  272. end;
  273. EFFECT_SPECIAL: begin
  274. EffectPageControl.ActivePageIndex := EFFECT_PAGE_OTHER;
  275. SpecialEscapeRadioButton.Checked := True;
  276. end;
  277. EFFECT_GROW: begin
  278. EffectPageControl.ActivePageIndex := EFFECT_PAGE_OTHER;
  279. IncreaseParameterRadioButton.Checked := True;
  280. IncreaseParamComboBox.ItemIndex := DataId;
  281. IncreaseParamSpinEdit.Value := Round(Value1);
  282. end;
  283. EFFECT_LEARN_SKILL: begin
  284. EffectPageControl.ActivePageIndex := EFFECT_PAGE_OTHER;
  285. LearnSkillRadioButton.Checked := True;
  286. LearnSkillComboBox.ItemIndex := DataId - 1;
  287. end;
  288. EFFECT_COMMON_EVENT: begin
  289. EffectPageControl.ActivePageIndex := EFFECT_PAGE_OTHER;
  290. CommonEventRadioButton.Checked := True;
  291. CommonEventComboBox.ItemIndex := DataId - 1;
  292. end;
  293. //TODO: preset data for remaining effects
  294. end;
  295. end;
  296. procedure TEffectSelectorForm.RepositionDummyRatioButtons;
  297. begin
  298. // I haven't found a better way to unselect all radio buttons, so this will do
  299. DummyHpMpTpRadioButton.Left := -100;
  300. DummyStateRadioButton.Left := -100;
  301. DummyBuffsDebuffsRadioButton.Left := -100;
  302. DummyOtherRadioButton.Left := -100;
  303. end;
  304. procedure TEffectSelectorForm.UnsetOptionsOnOtherPages(PageToKeep: Integer);
  305. begin
  306. if PageToKeep <> EFFECT_PAGE_HPMPTP then
  307. DummyHpMpTpRadioButton.Checked := True;
  308. if PageToKeep <> EFFECT_PAGE_STATE then
  309. DummyStateRadioButton.Checked := True;
  310. if PageToKeep <> EFFECT_PAGE_BUFF_DEBUFF then
  311. DummyBuffsDebuffsRadioButton.Checked := True;
  312. if PageToKeep <> EFFECT_PAGE_OTHER then
  313. DummyOtherRadioButton.Checked := True;
  314. end;
  315. function TEffectSelectorForm.GetSelectedEffectCode: Integer;
  316. begin
  317. if RecoverHpRadioButton.Checked then
  318. GetSelectedEffectCode := EFFECT_RECOVER_HP
  319. else if RecoverMpRadioButton.Checked then
  320. GetSelectedEffectCode := EFFECT_RECOVER_MP
  321. else if GainTpRadioButton.Checked then
  322. GetSelectedEffectCode := EFFECT_GAIN_TP
  323. else if AddStateRadioButton.Checked then
  324. GetSelectedEffectCode := EFFECT_ADD_STATE
  325. else if RemoveStateRadioButton.Checked then
  326. GetSelectedEffectCode := EFFECT_REMOVE_STATE
  327. else if AddBuffRadioButton.Checked then
  328. GetSelectedEffectCode := EFFECT_ADD_BUFF
  329. else if AddDebuffRadioButton.Checked then
  330. GetSelectedEffectCode := EFFECT_ADD_DEBUFF
  331. else if RemoveBuffRadioButton.Checked then
  332. GetSelectedEffectCode := EFFECT_REMOVE_BUFF
  333. else if RemoveDebuffRadioButton.Checked then
  334. GetSelectedEffectCode := EFFECT_REMOVE_DEBUFF
  335. else if SpecialEscapeRadioButton.Checked then
  336. GetSelectedEffectCode := EFFECT_SPECIAL
  337. else if IncreaseParameterRadioButton.Checked then
  338. GetSelectedEffectCode := EFFECT_GROW
  339. else if LearnSkillRadioButton.Checked then
  340. GetSelectedEffectCode := EFFECT_LEARN_SKILL
  341. else if CommonEventRadioButton.Checked then
  342. GetSelectedEffectCode := EFFECT_COMMON_EVENT
  343. else
  344. GetSelectedEffectCode := 0
  345. end;
  346. function TEffectSelectorForm.GetDataId(EffectCode: Integer): Integer;
  347. begin
  348. case EffectCode of
  349. EFFECT_ADD_STATE: GetDataId := AddStateComboBox.ItemIndex;
  350. EFFECT_REMOVE_STATE: GetDataId := RemoveStateComboBox.ItemIndex + 1;
  351. EFFECT_ADD_BUFF: GetDataId := AddBuffComboBox.ItemIndex;
  352. EFFECT_ADD_DEBUFF: GetDataId := AddDebuffComboBox.ItemIndex;
  353. EFFECT_REMOVE_BUFF: GetDataId := RemoveBuffComboBox.ItemIndex;
  354. EFFECT_REMOVE_DEBUFF: GetDataId := RemoveDebuffComboBox.ItemIndex;
  355. EFFECT_SPECIAL: GetDataId := SPECIAL_EFFECT_ESCAPE;
  356. EFFECT_GROW: GetDataId := IncreaseParamComboBox.ItemIndex;
  357. EFFECT_LEARN_SKILL: GetDataId := LearnSkillComboBox.ItemIndex + 1;
  358. EFFECT_COMMON_EVENT: GetDataId := CommonEventComboBox.ItemIndex + 1;
  359. else
  360. GetDataId := 0;
  361. end;
  362. end;
  363. function TEffectSelectorForm.GetValue1(EffectCode: Integer): Double;
  364. begin
  365. case EffectCode of
  366. EFFECT_RECOVER_HP: GetValue1 := RecoverHpPercentageSpinEdit.Value / 100.0;
  367. EFFECT_RECOVER_MP: GetValue1 := RecoverMpPercentageSpinEdit.Value / 100.0;
  368. EFFECT_GAIN_TP: GetValue1 := GainTpSpinEdit.Value;
  369. EFFECT_ADD_STATE: GetValue1 := AddStateRateSpinEdit.Value / 100.0;
  370. EFFECT_REMOVE_STATE: GetValue1 := RemoveStateRateSpinEdit.Value / 100.0;
  371. EFFECT_ADD_BUFF: GetValue1 := AddBuffTurnsSpinEdit.Value;
  372. EFFECT_ADD_DEBUFF: GetValue1 := AddDebuffTurnsSpinEdit.Value;
  373. EFFECT_GROW: GetValue1 := IncreaseParamSpinEdit.Value;
  374. else
  375. GetValue1 := 0;
  376. end;
  377. end;
  378. function TEffectSelectorForm.GetValue2(EffectCode: Integer): Double;
  379. begin
  380. case EffectCode of
  381. EFFECT_RECOVER_HP: GetValue2 := RecoverHpConstSpinEdit.Value;
  382. EFFECT_RECOVER_MP: GetValue2 := RecoverMpConstSpinEdit.Value;
  383. else
  384. GetValue2 := 0;
  385. end;
  386. end;
  387. procedure TEffectSelectorForm.SetSelectedValues;
  388. begin
  389. SelectedCode := GetSelectedEffectCode;
  390. SelectedDataId := GetDataId(SelectedCode);
  391. SelectedValue1 := GetValue1(SelectedCode);
  392. SelectedValue2 := GetValue2(SelectedCode);
  393. end;
  394. procedure TEffectSelectorForm.UnsetOptionsOnUnselectedPages;
  395. begin
  396. UnsetOptionsOnOtherPages(EffectPageControl.ActivePageIndex);
  397. end;
  398. function TEffectSelectorForm.ShowEffectSelection(ADb: TDatabase;
  399. EffectCode: Integer; DataId: Integer; Value1: Double; Value2: Double
  400. ): Boolean;
  401. begin
  402. ResultWasAccepted := False;
  403. Db := ADb;
  404. //TODO
  405. PresetValues(EffectCode, DataId, Value1, Value2);
  406. ShowModal;
  407. ShowEffectSelection := ResultWasAccepted;
  408. end;
  409. end.