imageselection.pas 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. unit imageselection;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
  6. ButtonPanel, fpjson, fgl, LCLTranslator, ComCtrls, Spin, BGRABitmap,
  7. BGRABitmapTypes, imghelper, tilesetgraphicsunit;
  8. type
  9. TImageSelectionType = (istImage, istFace, istSimpleCharset, istFullCharset);
  10. { TImageSelectionForm }
  11. TImageSelectionForm = class(TForm)
  12. DecisionButtonPanel: TButtonPanel;
  13. FilesListBox: TListBox;
  14. FilesSplitter: TSplitter;
  15. HueGroupBox: TGroupBox;
  16. PreviewPaintBox: TPaintBox;
  17. PreviewScrollBox: TScrollBox;
  18. SelectedPanel: TPanel;
  19. HueTrackBar: TTrackBar;
  20. HueSpinEdit: TSpinEdit;
  21. procedure CancelButtonClick(Sender: TObject);
  22. procedure FilesListBoxSelectionChange(Sender: TObject; User: boolean);
  23. procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
  24. procedure HueSpinEditChange(Sender: TObject);
  25. procedure HueTrackBarChange(Sender: TObject);
  26. procedure OKButtonClick(Sender: TObject);
  27. procedure PreviewPaintBoxDblClick(Sender: TObject);
  28. procedure PreviewPaintBoxMouseUp(Sender: TObject; Button: TMouseButton;
  29. Shift: TShiftState; X, Y: Integer);
  30. procedure PreviewPaintBoxPaint(Sender: TObject);
  31. procedure PreviewScrollBoxResize(Sender: TObject);
  32. private
  33. SelectionType: TImageSelectionType;
  34. Path: String; (* full path, with folder name *)
  35. HasNone: Boolean;
  36. HasTilesetItem: Boolean;
  37. UpdatingHueTrackBar: Boolean;
  38. ResultWasAccepted: Boolean;
  39. CurrentImage, RecolouredImage: TBGRABitmap;
  40. ResizedImage: TBGRACustomBitmap;
  41. TilesetGraphics: TTilesetGraphics;
  42. procedure FillFileList;
  43. procedure UpdatePreview;
  44. procedure UpdateResizedPreview;
  45. procedure FillSelectionResults;
  46. function IsNoneSelected: Boolean;
  47. function IsTilesetSelected: Boolean;
  48. function GetCellData(var AWidth, AHeight, PerLine: Integer): Boolean;
  49. function CountTilesetItems: Integer;
  50. function GetSelectedTilesetPart: Integer;
  51. public
  52. Index, Pattern, Direction, TileId, SelectedTilesetPart: Integer;
  53. TilesetItemSelected: Boolean;
  54. SelectedHue: Integer;
  55. SelectedFilename: String;
  56. function ShowFaceSelection(AFace: String; AIndex: Integer): Boolean;
  57. function ShowSimpleCharSelection(AChar: String; AIndex: Integer): Boolean;
  58. function ShowFullCharSelection(AChar: String; AIndex, APattern, ADir, ATileId: Integer; ATilesetGraphics: TTilesetGraphics): Boolean;
  59. function ShowSvBattlerSelection(ABattler: String): Boolean;
  60. function ShowEnemySelection(AEnemy: String; Hue: Integer; IsSv: Boolean): Boolean;
  61. function ShowTilesetImageSelection(OldFile: String): Boolean;
  62. end;
  63. var
  64. ImageSelectionForm: TImageSelectionForm;
  65. implementation
  66. uses Math, globals, gameproject, filehelper;
  67. {$R *.lfm}
  68. procedure TImageSelectionForm.CancelButtonClick(Sender: TObject);
  69. begin
  70. ResultWasAccepted := False;
  71. Close;
  72. end;
  73. procedure TImageSelectionForm.FilesListBoxSelectionChange(Sender: TObject;
  74. User: boolean);
  75. begin
  76. UpdatePreview;
  77. Refresh;
  78. end;
  79. procedure TImageSelectionForm.FormClose(Sender: TObject;
  80. var CloseAction: TCloseAction);
  81. begin
  82. FillSelectionResults;
  83. FilesListBox.Items.Clear;
  84. if ResizedImage <> nil then
  85. ResizedImage.Free;
  86. ResizedImage := nil;
  87. if CurrentImage <> nil then
  88. CurrentImage.Free;
  89. CurrentImage := nil;
  90. end;
  91. procedure TImageSelectionForm.HueSpinEditChange(Sender: TObject);
  92. begin
  93. SelectedHue := HueSpinEdit.Value;
  94. UpdatingHueTrackBar := True;
  95. HueTrackBar.Position := SelectedHue;
  96. UpdatingHueTrackBar := False;
  97. if CurrentImage = nil then
  98. Exit;
  99. if RecolouredImage <> nil then begin
  100. RecolouredImage.Free;
  101. RecolouredImage := nil;
  102. end;
  103. if (HueSpinEdit.Value <> 0) and (HueSpinEdit.Value <> 360) then
  104. RecolouredImage := ChangeHue(CurrentImage, HueSpinEdit.Value);
  105. UpdateResizedPreview;
  106. Refresh
  107. end;
  108. procedure TImageSelectionForm.HueTrackBarChange(Sender: TObject);
  109. begin
  110. if not UpdatingHueTrackBar then
  111. HueSpinEdit.Value := HueTrackBar.Position;
  112. end;
  113. procedure TImageSelectionForm.FillSelectionResults;
  114. begin
  115. if IsNoneSelected then begin
  116. TilesetItemSelected := False;
  117. SelectedFilename := '';
  118. Index := 0;
  119. end
  120. else if IsTilesetSelected then begin
  121. TilesetItemSelected := True;
  122. SelectedFilename := '';
  123. end
  124. else begin
  125. TilesetItemSelected := False;
  126. SelectedFilename := FilesListBox.Items[FilesListBox.ItemIndex];
  127. if TGameProject.IsDollarName(SelectedFilename) then
  128. Index := 0;
  129. end;
  130. end;
  131. function TImageSelectionForm.IsNoneSelected: Boolean;
  132. begin
  133. if HasNone then
  134. IsNoneSelected := FilesListBox.ItemIndex = 0
  135. else
  136. IsNoneSelected := False;
  137. end;
  138. function TImageSelectionForm.IsTilesetSelected: Boolean;
  139. begin
  140. if HasTilesetItem then begin
  141. IsTilesetSelected := FilesListBox.ItemIndex >= FilesListBox.Count - CountTilesetItems; //TODO: preselect the correct tileset
  142. end
  143. else
  144. IsTilesetSelected := False;
  145. end;
  146. procedure TImageSelectionForm.OKButtonClick(Sender: TObject);
  147. begin
  148. ResultWasAccepted := True;
  149. Close;
  150. end;
  151. procedure TImageSelectionForm.PreviewPaintBoxDblClick(Sender: TObject);
  152. begin
  153. (* This causes problems on Windows: if you close the window by double-click,
  154. subsequent calls to show ImageSelectionForm will not show anything.
  155. I don't know what causes this, so let's keep it commented out for a while. *)
  156. {$IF not Defined(LCLWin32)}
  157. //TODO: check that this doesn't happen in other widgetsets
  158. ResultWasAccepted := True;
  159. Close;
  160. {$ENDIF}
  161. end;
  162. procedure TImageSelectionForm.PreviewPaintBoxMouseUp(Sender: TObject;
  163. Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  164. var
  165. XIndex, YIndex: Integer;
  166. CellWidth: Integer = 0;
  167. CellHeight: Integer = 0;
  168. CellsPerLine: Integer = 0;
  169. ResizedCellWidth, ResizedCellHeight: Integer;
  170. begin
  171. if GetCellData(CellWidth, CellHeight, CellsPerLine) then begin
  172. //TODO: move this our into a separate routine?
  173. ResizedCellWidth := CellWidth * ResizedImage.Width div CurrentImage.Width;
  174. ResizedCellHeight:=CellHeight*ResizedImage.Height div CurrentImage.Height;
  175. XIndex := X div ResizedCellWidth;
  176. YIndex := Y div ResizedCellHeight;
  177. Index := YIndex*CellsPerLine + XIndex;
  178. Refresh;
  179. end;
  180. end;
  181. procedure TImageSelectionForm.PreviewPaintBoxPaint(Sender: TObject);
  182. var
  183. Dst, SelectionRect: TRect;
  184. CellWidth: Integer = 0;
  185. CellHeight: Integer = 0;
  186. CellsPerLine: Integer = 0;
  187. ResizedCellWidth, ResizedCellHeight: Double;
  188. begin
  189. if (ResizedImage <> nil) and (CurrentImage <> nil) then begin
  190. Dst :=Rect(0, 0, PreviewPaintBox.ClientWidth, PreviewPaintBox.ClientHeight);
  191. //PreviewPaintBox.Canvas.StretchDraw(Dst, ResizedImage);
  192. ResizedImage.Draw(PreviewPaintBox.Canvas, Dst, False);
  193. if GetCellData(CellWidth, CellHeight, CellsPerLine) then begin
  194. //TODO: draw index
  195. ResizedCellWidth := CellWidth * ResizedImage.Width / CurrentImage.Width;
  196. ResizedCellHeight:=CellHeight*ResizedImage.Height / CurrentImage.Height;
  197. SelectionRect.Left := Floor((Index mod CellsPerLine) * ResizedCellWidth);
  198. SelectionRect.Top := Floor((Index div CellsPerLine) * ResizedCellHeight);
  199. SelectionRect.Right := Ceil(SelectionRect.Left + ResizedCellWidth);
  200. SelectionRect.Bottom := Ceil(SelectionRect.Top + ResizedCellHeight);
  201. PreviewPaintBox.Canvas.Brush.Style := bsClear;
  202. PreviewPaintBox.Canvas.Pen.Color := clWhite;
  203. PreviewPaintBox.Canvas.Pen.Width := 2;
  204. PreviewPaintBox.Canvas.Rectangle(SelectionRect);
  205. PreviewPaintBox.Canvas.Pen.Color := clBlack;
  206. SelectionRect.Inflate(-2, -2, -2, -2);
  207. PreviewPaintBox.Canvas.Rectangle(SelectionRect);
  208. PreviewPaintBox.Canvas.Pen.Color := clWhite;
  209. SelectionRect.Inflate(-2, -2, -2, -2);
  210. PreviewPaintBox.Canvas.Rectangle(SelectionRect);
  211. //ResizedCellHeight
  212. end;
  213. end;
  214. end;
  215. function TImageSelectionForm.GetCellData(var AWidth, AHeight, PerLine: Integer): Boolean;
  216. begin
  217. if IsTilesetSelected then begin
  218. AWidth := 48; //TODO: adapt for other tile sizes
  219. AHeight := 48; //TODO: adapt for other tile sizes
  220. PerLine := 8;
  221. GetCellData := True;
  222. end
  223. else if IsNoneSelected then begin
  224. GetCellData := False;
  225. end
  226. else if CurrentImage <> nil then begin
  227. if SelectionType = istFace then begin
  228. AWidth := 144;
  229. AHeight := 144;
  230. PerLine := 4;
  231. GetCellData := True;
  232. end
  233. else if SelectionType = istSimpleCharset then begin
  234. if TGameProject.IsDollarName(FilesListBox.Items[FilesListBox.ItemIndex]) then begin
  235. AWidth := CurrentImage.Width;
  236. AHeight := CurrentImage.Height;
  237. PerLine := 1;
  238. GetCellData := True;
  239. end
  240. else begin
  241. AWidth := CurrentImage.Width div 4;
  242. AHeight := CurrentImage.Height div 2;
  243. PerLine := 4;
  244. GetCellData := True;
  245. end;
  246. end
  247. else if SelectionType = istFullCharset then begin
  248. if TGameProject.IsDollarName(FilesListBox.Items[FilesListBox.ItemIndex]) then begin
  249. AWidth := CurrentImage.Width div 3;
  250. AHeight := CurrentImage.Height div 4;
  251. PerLine := 3;
  252. GetCellData := True;
  253. end
  254. else begin
  255. AWidth := CurrentImage.Width div (3*4);
  256. AHeight := CurrentImage.Height div (4*2);
  257. PerLine := 3*4;
  258. GetCellData := True;
  259. end;
  260. end
  261. else begin
  262. GetCellData := False;
  263. end;
  264. end;
  265. end;
  266. function TImageSelectionForm.CountTilesetItems: Integer;
  267. var
  268. I: Integer;
  269. begin
  270. CountTilesetItems := 0;
  271. if HasTilesetItem and (TilesetGraphics <> nil) then
  272. for I := 5 to High(TilesetGraphics.Bitmaps) do
  273. if TilesetGraphics.HasSet(I) then
  274. Inc(CountTilesetItems);
  275. end;
  276. function TImageSelectionForm.GetSelectedTilesetPart: Integer;
  277. var
  278. I, StartIndex, StartListItem: Integer;
  279. begin
  280. GetSelectedTilesetPart := 0;
  281. if not HasTilesetItem or (TilesetGraphics = nil) then begin
  282. Exit;
  283. end;
  284. StartIndex := 8;
  285. StartListItem := FilesListBox.Count -1;
  286. repeat
  287. if TilesetGraphics.HasSet(StartIndex) then
  288. if StartListItem = FilesListBox.ItemIndex then begin
  289. GetSelectedTilesetPart := StartIndex;
  290. Exit
  291. end else
  292. Dec(StartListItem);
  293. Dec(StartIndex);
  294. until StartIndex <= 4;
  295. end;
  296. procedure TImageSelectionForm.PreviewScrollBoxResize(Sender: TObject);
  297. begin
  298. UpdateResizedPreview;
  299. end;
  300. procedure TImageSelectionForm.FillFileList;
  301. var
  302. PreselectedIndex: Integer = -1;
  303. I: Integer;
  304. FileNames: TFilenameList;
  305. function GetAvailableTilesetId: Integer;
  306. var
  307. CurrentNumber, SetIndex: Integer;
  308. begin
  309. Result := 0;
  310. CurrentNumber := 0;
  311. for SetIndex := 5 to 8 do
  312. if TilesetGraphics <> nil then
  313. if TilesetGraphics.HasSet(SetIndex) then
  314. if SelectedTilesetPart = SetIndex - 5 then begin
  315. Result := CurrentNumber;
  316. Exit;
  317. end else
  318. Inc(CurrentNumber);
  319. end;
  320. procedure AddTilesetItems;
  321. begin
  322. if (TilesetGraphics <> nil) then begin
  323. if TilesetGraphics.HasSet(5) then
  324. FilesListBox.Items.Add(TilesBFilename);
  325. if TilesetGraphics.HasSet(6) then
  326. FilesListBox.Items.Add(TilesCFilename);
  327. if TilesetGraphics.HasSet(7) then
  328. FilesListBox.Items.Add(TilesDFilename);
  329. if TilesetGraphics.HasSet(8) then
  330. FilesListBox.Items.Add(TilesEFilename);
  331. end;
  332. if TilesetItemSelected then begin
  333. PreselectedIndex := FilesListBox.Items.Count
  334. - CountTilesetItems + GetAvailableTilesetId;
  335. end;
  336. end;
  337. begin
  338. FilesListBox.Items.BeginUpdate;
  339. FilesListBox.Items.Clear;
  340. if HasNone then begin
  341. FilesListBox.Items.Add(NoneFilename);
  342. if (SelectedFilename = '') and not TilesetItemSelected then begin
  343. PreselectedIndex := FilesListBox.Items.Count - 1;
  344. end;
  345. end;
  346. //TODO: show files in subfolders???
  347. //TODO: make sure FilesListBox doesn't mess with our filenames (what about names w/ line feed in them? do we even need this brain damage?)
  348. FileNames := FillFilenameList(Path);
  349. for I := 0 to FileNames.Count - 1 do begin
  350. FilesListBox.Items.Add(FileNames[I]);
  351. if SelectedFilename = FileNames[I] then begin
  352. PreselectedIndex := FilesListBox.Items.Count - 1;
  353. end;
  354. end;
  355. FileNames.Free;
  356. AddTilesetItems;
  357. FilesListBox.Items.EndUpdate;
  358. if PreselectedIndex > -1 then
  359. FilesListBox.ItemIndex := PreselectedIndex;
  360. end;
  361. procedure TImageSelectionForm.UpdatePreview;
  362. var
  363. Filename: String = '';
  364. NewImage: TBGRABitmap = nil;
  365. BitmapToCopy: TBGRABitmap = nil;
  366. begin
  367. if CurrentImage <> nil then begin
  368. CurrentImage.Free;
  369. CurrentImage := nil;
  370. end;
  371. if RecolouredImage <> nil then begin
  372. RecolouredImage.Free;
  373. RecolouredImage := nil;
  374. end;
  375. if IsNoneSelected then begin
  376. //TODO: (None) item handling
  377. end
  378. else if IsTilesetSelected then begin
  379. BitmapToCopy := TilesetGraphics.Bitmaps[GetSelectedTilesetPart];
  380. NewImage := TBGRABitmap.Create(BitmapToCopy.Width div 2, BitmapToCopy.Height * 2, BGRAWhite);
  381. NewImage.CanvasBGRA.CopyRect(0, 0, BitmapToCopy, Rect(
  382. 0,
  383. 0,
  384. BitmapToCopy.Width div 2,
  385. BitmapToCopy.Height));
  386. NewImage.CanvasBGRA.CopyRect(0, BitmapToCopy.Height, BitmapToCopy,
  387. Rect(
  388. BitmapToCopy.Width div 2,
  389. 0,
  390. BitmapToCopy.Width,
  391. BitmapToCopy.Height));
  392. SelectedTilesetPart := GetSelectedTilesetPart - 5;
  393. CurrentImage := NewImage;
  394. //TODO: (Tiles) item handling
  395. end
  396. else begin
  397. try
  398. if (FilesListBox.ItemIndex >= 0) and (FilesListBox.ItemIndex < FilesListBox.Count) then
  399. Filename := Path + DirectorySeparator
  400. + FilesListBox.Items[FilesListBox.ItemIndex]
  401. + '.png';
  402. if FileExists(Filename) then
  403. NewImage := TBGRABitmap.Create(Filename);
  404. except
  405. if NewImage <> nil then
  406. NewImage.Free;
  407. end;
  408. CurrentImage := NewImage;
  409. if (CurrentImage <> nil) and (HueSpinEdit.Value <> 0) and (HueSpinEdit.Value <> 360) then
  410. RecolouredImage := ChangeHue(CurrentImage, HueSpinEdit.Value);
  411. end;
  412. UpdateResizedPreview;
  413. end;
  414. procedure TImageSelectionForm.UpdateResizedPreview;
  415. var
  416. ResizedWidth, ResizedHeight: Integer;
  417. ImgToResize: TBGRABitmap;
  418. begin
  419. if (CurrentImage <> nil) and (PreviewScrollBox.ClientWidth > 20) then begin
  420. if ResizedImage <> nil then begin
  421. ResizedImage.Free;
  422. ResizedImage := nil;
  423. end;
  424. if RecolouredImage <> nil then
  425. ImgToResize := RecolouredImage
  426. else
  427. ImgToResize := CurrentImage;
  428. (* Using PreviewScrollBox.ClientWidth causes an infinite loop here, so
  429. let's do this hack and hope scrollbar is around 20px. (If it's not,
  430. a small edge of the image will be hidden, which is acceptable.) *)
  431. ResizedWidth := PreviewScrollBox.Width - 20;
  432. ResizedHeight := ImgToResize.Height
  433. * ResizedWidth
  434. div Max(ImgToResize.Width, 1);
  435. PreviewPaintBox.ClientWidth := ResizedWidth;
  436. PreviewPaintBox.ClientHeight := ResizedHeight;
  437. (* Left can be changed when flipping for RTL, so ensure it's correct *)
  438. PreviewPaintBox.Left := 0;
  439. ResizedImage := ImgToResize.Resample(ResizedWidth, ResizedHeight, rmSimpleStretch);
  440. end;
  441. end;
  442. function TImageSelectionForm.ShowFaceSelection(AFace: String; AIndex: Integer): Boolean;
  443. begin
  444. ResultWasAccepted := False;
  445. SelectionType := istFace;
  446. SelectedFilename := AFace;
  447. HasTilesetItem := False;
  448. TilesetItemSelected := False;
  449. Index := AIndex;
  450. Path := Game.GetImageSubfolderPath('faces');
  451. HueGroupBox.Hide;
  452. HueSpinEdit.Value := 0;
  453. HasNone := True;
  454. FillFileList;
  455. UpdatePreview;
  456. ShowModal;
  457. ShowFaceSelection := ResultWasAccepted;
  458. end;
  459. function TImageSelectionForm.ShowSimpleCharSelection(AChar: String; AIndex: Integer): Boolean;
  460. begin
  461. ResultWasAccepted := False;
  462. SelectionType := istSimpleCharset;
  463. SelectedFilename := AChar;
  464. TilesetItemSelected := False;
  465. HasTilesetItem := False;
  466. Index := AIndex;
  467. Path := Game.GetImageSubfolderPath('characters');
  468. HueGroupBox.Hide;
  469. HueSpinEdit.Value := 0;
  470. HasNone := True;
  471. FillFileList;
  472. UpdatePreview;
  473. ShowModal;
  474. ShowSimpleCharSelection := ResultWasAccepted;
  475. end;
  476. function TImageSelectionForm.ShowFullCharSelection(AChar: String; AIndex,
  477. APattern, ADir, ATileId: Integer; ATilesetGraphics: TTilesetGraphics): Boolean;
  478. var
  479. CharsPerLine: Integer = 4;
  480. CharOffset: Integer = 0;
  481. begin
  482. ResultWasAccepted := False;
  483. SelectionType := istFullCharset;
  484. SelectedFilename := AChar;
  485. TilesetItemSelected := False;
  486. if TGameProject.IsDollarName(AChar) then
  487. CharsPerLine := 1;
  488. if AIndex > 3 then
  489. CharOffset := 48 + ((AIndex - 4) * 3)
  490. else
  491. CharOffset := (AIndex * 3);
  492. Index := CharOffset + ((ADir div 2 - 1) * (CharsPerLine * 3)) + APattern;
  493. Path := Game.GetImageSubfolderPath('characters');
  494. HueGroupBox.Hide;
  495. HueSpinEdit.Value := 0;
  496. HasNone := True;
  497. HasTilesetItem := True;
  498. TilesetGraphics := ATilesetGraphics;
  499. TileId := ATileId;
  500. SelectedTilesetPart := TileId div 256;
  501. TilesetItemSelected := SelectedFilename = '';
  502. if TilesetItemSelected then
  503. Index := TileId mod 256;
  504. FillFileList;
  505. UpdatePreview;
  506. ShowModal;
  507. if TilesetItemSelected then begin
  508. SelectedFilename := '';
  509. TileId := Index + (SelectedTilesetPart * 256); //TODO: preset SelectedTilesetPart
  510. end else begin
  511. if TGameProject.IsDollarName(SelectedFilename) then
  512. CharsPerLine := 1
  513. else
  514. CharsPerLine := 4;
  515. Direction := (((Index div (CharsPerLine * 3)) mod 4) + 1) * 2;
  516. Pattern := Index mod 3;
  517. if Index < 48 then
  518. Index := (Index mod (CharsPerLine * 3)) div 3
  519. else
  520. Index := 4 + (Index mod (CharsPerLine * 3)) div 3
  521. end;
  522. ShowFullCharSelection := ResultWasAccepted;
  523. end;
  524. function TImageSelectionForm.ShowSvBattlerSelection(ABattler: String): Boolean;
  525. begin
  526. ResultWasAccepted := False;
  527. SelectionType := istImage;
  528. SelectedFilename := ABattler;
  529. TilesetItemSelected := False;
  530. HasTilesetItem := False;
  531. Path := Game.GetImageSubfolderPath('sv_actors');
  532. HueGroupBox.Hide;
  533. HueSpinEdit.Value := 0;
  534. HasNone := True;
  535. FillFileList;
  536. UpdatePreview;
  537. ShowModal;
  538. ShowSvBattlerSelection := ResultWasAccepted;
  539. end;
  540. function TImageSelectionForm.ShowEnemySelection(AEnemy: String; Hue: Integer;
  541. IsSv: Boolean): Boolean;
  542. begin
  543. ResultWasAccepted := False;
  544. SelectionType := istImage;
  545. SelectedFilename := AEnemy;
  546. TilesetItemSelected := False;
  547. HasTilesetItem := False;
  548. if IsSv then
  549. Path := Game.GetImageSubfolderPath('sv_enemies')
  550. else
  551. Path := Game.GetImageSubfolderPath('enemies');
  552. HueGroupBox.Show;
  553. HueSpinEdit.Value := Hue;
  554. HueTrackBar.Position := Hue;
  555. HasNone := True;
  556. FillFileList;
  557. UpdatePreview;
  558. ShowModal;
  559. ShowEnemySelection := ResultWasAccepted;
  560. end;
  561. function TImageSelectionForm.ShowTilesetImageSelection(OldFile: String
  562. ): Boolean;
  563. begin
  564. ResultWasAccepted := False;
  565. SelectionType := istImage;
  566. SelectedFilename := OldFile;
  567. TilesetItemSelected := False;
  568. HasTilesetItem := False;
  569. Path := Game.GetImageSubfolderPath('tilesets');
  570. HueGroupBox.Hide;
  571. HasNone := True;
  572. FillFileList;
  573. UpdatePreview;
  574. ShowModal;
  575. ShowTilesetImageSelection := ResultWasAccepted;
  576. end;
  577. end.