1 |
|
unit Tool_TxmpReplace; |
2 |
– |
|
2 |
|
interface |
4 |
– |
|
3 |
|
uses |
4 |
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
5 |
< |
Dialogs, ExtCtrls, StdCtrls, StrUtils, Code_Functions, Data, Code_OniImgClass; |
5 |
> |
Dialogs, Tool_Template, StdCtrls, ExtCtrls, |
6 |
> |
Code_Functions, Data, Code_OniImgClass, Menus; |
7 |
|
|
8 |
|
type |
9 |
< |
TForm_TxmpReplace = class(TForm) |
11 |
< |
panel_12: TPanel; |
12 |
< |
group_txmpselect: TGroupBox; |
13 |
< |
splitter_txmp: TSplitter; |
14 |
< |
list_txmp: TListBox; |
15 |
< |
Splitter1: TSplitter; |
16 |
< |
group_bmpselect: TGroupBox; |
17 |
< |
panel_load: TPanel; |
18 |
< |
btn_load: TButton; |
19 |
< |
image_bmppreview: TImage; |
20 |
< |
opend: TOpenDialog; |
9 |
> |
TForm_TxmpReplace = class(TForm_ToolTemplate) |
10 |
|
group_options: TGroupBox; |
11 |
|
btn_replace: TButton; |
12 |
|
check_transparency: TCheckBox; |
14 |
|
panel_txmppreview: TPanel; |
15 |
|
btn_save: TButton; |
16 |
|
image_txmppreview: TImage; |
17 |
< |
saved: TSaveDialog; |
17 |
> |
splitter_txmp: TSplitter; |
18 |
> |
group_bmpselect: TGroupBox; |
19 |
> |
image_bmppreview: TImage; |
20 |
> |
panel_load: TPanel; |
21 |
> |
btn_load: TButton; |
22 |
> |
opend: TOpenDialog; |
23 |
> |
saved: TSaveDialog; |
24 |
> |
procedure SelectFile(fileinfo: TFileInfo); |
25 |
|
procedure FormCreate(Sender: TObject); |
30 |
– |
procedure btn_saveClick(Sender: TObject); |
26 |
|
procedure FormClose(Sender: TObject; var Action: TCloseAction); |
27 |
< |
procedure btn_replaceClick(Sender: TObject); |
27 |
> |
procedure btn_saveClick(Sender: TObject); |
28 |
|
procedure btn_loadClick(Sender: TObject); |
29 |
< |
procedure list_txmpClick(Sender: TObject); |
35 |
< |
procedure Recreatelist; |
36 |
< |
procedure list_txmpMouseDown(Sender: TObject; Button: TMouseButton; |
37 |
< |
Shift: TShiftState; X, Y: Integer); |
29 |
> |
procedure btn_replaceClick(Sender: TObject); |
30 |
|
private |
31 |
|
OniImage_Old: TOniImage; |
32 |
|
OniImage_New: TOniImage; |
33 |
+ |
fileid: Integer; |
34 |
|
public |
35 |
|
end; |
36 |
|
|
38 |
|
Form_TxmpReplace: TForm_TxmpReplace; |
39 |
|
|
40 |
|
implementation |
48 |
– |
|
49 |
– |
uses Main, Code_OniDataClass; |
50 |
– |
|
41 |
|
{$R *.dfm} |
42 |
+ |
uses Main, Code_OniDataClass; |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
< |
procedure TForm_TxmpReplace.Recreatelist; |
56 |
< |
var |
57 |
< |
files: TStringArray; |
58 |
< |
i: LongWord; |
59 |
< |
begin |
60 |
< |
list_txmp.Items.Clear; |
61 |
< |
files := OniDataConnection.GetFilesList('TXMP', '', True); |
62 |
< |
if Length(files) > 0 then |
63 |
< |
for i := 0 to High(files) do |
64 |
< |
list_txmp.Items.Add(files[i]); |
65 |
< |
group_bmpselect.Enabled := False; |
66 |
< |
check_transparency.Checked := False; |
67 |
< |
check_fading.Checked := False; |
68 |
< |
end; |
69 |
< |
|
70 |
< |
|
71 |
< |
|
72 |
< |
|
73 |
< |
procedure TForm_TxmpReplace.list_txmpClick(Sender: TObject); |
46 |
> |
procedure TForm_TxmpReplace.SelectFile(fileinfo: TFileInfo); |
47 |
|
var |
75 |
– |
id: LongWord; |
48 |
|
Data: Tdata; |
49 |
|
mem: TMemoryStream; |
50 |
|
fadingbyte, depthbyte, storebyte: Byte; |
51 |
|
begin |
52 |
< |
id := OniDataConnection.ExtractFileID(list_txmp.Items.Strings[list_txmp.ItemIndex]); |
53 |
< |
OniDataConnection.LoadDatFilePart(id, $88, SizeOf(fadingbyte), @fadingbyte); |
54 |
< |
OniDataConnection.LoadDatFilePart(id, $89, SizeOf(depthbyte), @depthbyte); |
55 |
< |
OniDataConnection.LoadDatFilePart(id, $90, SizeOf(storebyte), @storebyte); |
52 |
> |
fileid := fileinfo.ID; |
53 |
> |
OniDataConnection.LoadDatFilePart(fileid, $88, SizeOf(fadingbyte), @fadingbyte); |
54 |
> |
OniDataConnection.LoadDatFilePart(fileid, $89, SizeOf(depthbyte), @depthbyte); |
55 |
> |
OniDataConnection.LoadDatFilePart(fileid, $90, SizeOf(storebyte), @storebyte); |
56 |
|
check_fading.Checked := (fadingbyte and $01) > 0; |
57 |
|
check_transparency.Checked := (depthbyte and $04) > 0; |
58 |
|
|
59 |
< |
OniImage_Old.LoadFromTXMP(id); |
59 |
> |
OniImage_Old.LoadFromTXMP(fileid); |
60 |
|
Data := OniImage_Old.GetAsBMP; |
61 |
|
mem := TMemoryStream.Create; |
62 |
|
mem.Write(Data[0], Length(Data)); |
68 |
|
end; |
69 |
|
|
70 |
|
|
99 |
– |
|
100 |
– |
|
101 |
– |
procedure TForm_TxmpReplace.list_txmpMouseDown(Sender: TObject; |
102 |
– |
Button: TMouseButton; Shift: TShiftState; X, Y: Integer); |
103 |
– |
var |
104 |
– |
pt: TPoint; |
105 |
– |
begin |
106 |
– |
pt.X := x; |
107 |
– |
pt.Y := y; |
108 |
– |
list_txmp.ItemIndex := list_txmp.ItemAtPos(pt, true); |
109 |
– |
if list_txmp.ItemIndex > -1 then |
110 |
– |
Self.list_txmpClick(Self); |
111 |
– |
end; |
112 |
– |
|
71 |
|
procedure TForm_TxmpReplace.btn_loadClick(Sender: TObject); |
72 |
|
var |
73 |
|
mem: TMemoryStream; |
91 |
|
|
92 |
|
procedure TForm_TxmpReplace.btn_replaceClick(Sender: TObject); |
93 |
|
var |
136 |
– |
id: LongWord; |
137 |
– |
|
94 |
|
oldsize, newsize: LongWord; |
95 |
|
old_rawaddr, new_rawaddr: LongWord; |
96 |
|
oldfading: Byte; |
98 |
|
|
99 |
|
datbyte: Word; |
100 |
|
begin |
101 |
< |
if list_txmp.ItemIndex >= 0 then |
101 |
> |
if filelist.ItemIndex >= 0 then |
102 |
|
begin |
103 |
< |
id := OniDataConnection.ExtractFileID(list_txmp.Items.Strings[list_txmp.ItemIndex]); |
148 |
< |
OniDataConnection.LoadDatFilePart(id, $88, 1, @oldfading); |
103 |
> |
OniDataConnection.LoadDatFilePart(fileid, $88, 1, @oldfading); |
104 |
|
if OniDataConnection.OSisMac then |
105 |
< |
OniDataConnection.UpdateDatFilePart(id, $A0, 4, @old_rawaddr) |
105 |
> |
OniDataConnection.UpdateDatFilePart(fileid, $A0, 4, @old_rawaddr) |
106 |
|
else |
107 |
< |
OniDataConnection.LoadDatFilePart(id, $9C, 4, @old_rawaddr); |
107 |
> |
OniDataConnection.LoadDatFilePart(fileid, $9C, 4, @old_rawaddr); |
108 |
|
|
109 |
|
if (OniImage_Old.Width <> OniImage_New.Width) or |
110 |
|
(OniImage_Old.Height <> OniImage_New.Height) then |
115 |
|
'x' + IntToStr(OniImage_Old.Height) + ' - New: ' + |
116 |
|
IntToStr(OniImage_New.Width) + 'x' + IntToStr(OniImage_New.Height) + ')' + CrLf + |
117 |
|
'Replace anyways?'), |
118 |
< |
PChar(list_txmp.Items.Strings[list_txmp.ItemIndex]), |
118 |
> |
PChar(filelist.Items.Strings[filelist.ItemIndex]), |
119 |
|
MB_YESNO) = idNo then |
120 |
|
Exit; |
121 |
|
end; |
144 |
|
else |
145 |
|
begin |
146 |
|
new_rawaddr := old_rawaddr; |
147 |
< |
OniDataConnection.UpdateRawFile(id, $9C, Length(tempd), tempd); |
147 |
> |
OniDataConnection.UpdateRawFile(fileid, $9C, Length(tempd), tempd); |
148 |
|
end; |
149 |
|
|
150 |
|
datbyte := $00; |
151 |
|
if check_fading.Checked then |
152 |
|
datbyte := datbyte or $01; |
153 |
< |
OniDataConnection.UpdateDatFilePart(id, $88, 1, @datbyte); |
153 |
> |
OniDataConnection.UpdateDatFilePart(fileid, $88, 1, @datbyte); |
154 |
|
datbyte := $10; |
155 |
|
if check_transparency.Checked then |
156 |
|
datbyte := datbyte or $04; |
157 |
< |
OniDataConnection.UpdateDatFilePart(id, $89, 1, @datbyte); |
158 |
< |
OniDataConnection.UpdateDatFilePart(id, $8C, 2, @OniImage_New.Width); |
159 |
< |
OniDataConnection.UpdateDatFilePart(id, $8E, 2, @OniImage_New.Height); |
157 |
> |
OniDataConnection.UpdateDatFilePart(fileid, $89, 1, @datbyte); |
158 |
> |
OniDataConnection.UpdateDatFilePart(fileid, $8C, 2, @OniImage_New.Width); |
159 |
> |
OniDataConnection.UpdateDatFilePart(fileid, $8E, 2, @OniImage_New.Height); |
160 |
|
datbyte := $08; |
161 |
< |
OniDataConnection.UpdateDatFilePart(id, $90, 1, @datbyte); |
161 |
> |
OniDataConnection.UpdateDatFilePart(fileid, $90, 1, @datbyte); |
162 |
|
if OniDataConnection.OSisMac then |
163 |
< |
OniDataConnection.UpdateDatFilePart(id, $A0, 4, @new_rawaddr) |
163 |
> |
OniDataConnection.UpdateDatFilePart(fileid, $A0, 4, @new_rawaddr) |
164 |
|
else |
165 |
< |
OniDataConnection.UpdateDatFilePart(id, $9C, 4, @new_rawaddr); |
165 |
> |
OniDataConnection.UpdateDatFilePart(fileid, $9C, 4, @new_rawaddr); |
166 |
|
|
167 |
|
ShowMessage('TXMP-image replaced'); |
168 |
|
end; |
175 |
|
begin |
176 |
|
OniImage_Old.Free; |
177 |
|
OniImage_New.Free; |
178 |
< |
Action := caFree; |
178 |
> |
inherited; |
179 |
|
end; |
180 |
|
|
181 |
|
|
183 |
|
|
184 |
|
procedure TForm_TxmpReplace.FormCreate(Sender: TObject); |
185 |
|
begin |
186 |
+ |
inherited; |
187 |
|
OniImage_Old := TOniImage.Create; |
188 |
|
OniImage_New := TOniImage.Create; |
189 |
+ |
Self.AllowedExts := 'TXMP'; |
190 |
+ |
Self.OnNewFileSelected := SelectFile; |
191 |
|
end; |
192 |
|
|
193 |
|
|
199 |
|
OniImage_Old.WriteToBMP(saved.FileName); |
200 |
|
end; |
201 |
|
|
202 |
+ |
begin |
203 |
+ |
AddToolListEntry('txmpreplace', 'TXMP Replacer', 'TXMP'); |
204 |
|
end. |