DEADSOFTWARE

changed some backslashes to forward slashes
[d2df-editor.git] / src / editor / f_addresource.pas
1 unit f_addresource;
2
3 {$MODE Delphi}
4
5 interface
6
7 uses
8 LCLIntf, LCLType, LMessages, Messages, SysUtils, Variants, Classes,
9 Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls,
10 ExtDlgs, e_Log, e_textures, WADEDITOR;
11
12 type
13 TOKFunction = function: Boolean;
14
15 TAddResourceForm = class (TForm)
16 LabelWADs: TLabel;
17 cbWADList: TComboBox;
18 LabelSections: TLabel;
19 cbSectionsList: TComboBox;
20 lbResourcesList: TListBox;
21 bOK: TButton;
22 bCancel: TButton;
23
24 procedure FormActivate(Sender: TObject);
25 procedure bOKClick(Sender: TObject);
26 procedure cbWADListChange(Sender: TObject);
27 procedure cbSectionsListChange(Sender: TObject);
28 procedure lbResourcesListClick(Sender: TObject);
29
30 protected
31 FResourceName: String;
32 FFullResourceName: String;
33 FResourceSelected: Boolean;
34 FOKFunction: TOKFunction;
35
36 public
37 property ResourceName: String read FResourceName;
38 property FullResourceName: String read FFullResourceName;
39 property OKFunction: TOKFunction read FOKFunction write FOKFunction;
40 end;
41
42 var
43 AddResourceForm: TAddResourceForm;
44
45 implementation
46
47 uses
48 f_main, WADSTRUCT, g_language;
49
50 {$R *.lfm}
51
52 const
53 STANDART_WAD = 'Standart.wad';
54
55 procedure TAddResourceForm.FormActivate(Sender: TObject);
56 var
57 SR: TSearchRec;
58
59 begin
60 cbWADList.Clear();
61 cbSectionsList.Clear();
62 lbResourcesList.Clear();
63
64 FResourceName := '';
65 FFullResourceName := '';
66 FResourceSelected := False;
67
68 ChDir(EditorDir);
69 if FindFirst(EditorDir+'wads/*.wad', faAnyFile, SR) = 0 then
70 repeat
71 cbWADList.Items.Add(SR.Name);
72 until FindNext(SR) <> 0;
73 FindClose(SR);
74
75 // "Standart.wad" в начало списка:
76 if cbWADList.Items.IndexOf(STANDART_WAD) > 0 then
77 begin
78 cbWADList.Items.Delete(cbWADList.Items.IndexOf(STANDART_WAD));
79 cbWADList.Items.Insert(0, STANDART_WAD);
80 end;
81
82 // WAD карты:
83 if OpenedMap <> '' then
84 cbWADList.Items.Add(_lc[I_WAD_SPECIAL_MAP]);
85 end;
86
87 procedure TAddResourceForm.bOKClick(Sender: TObject);
88 begin
89 if FResourceName = '' then
90 begin
91 MessageBox(0, PChar(_lc[I_MSG_CHOOSE_RES]),
92 PChar(_lc[I_MSG_ERROR]), MB_OK + MB_ICONERROR);
93 Exit;
94 end;
95
96 if @FOKFunction <> nil then
97 begin
98 if FOKFunction() then
99 Close();
100 end
101 else
102 Close();
103 end;
104
105 procedure TAddResourceForm.cbWADListChange(Sender: TObject);
106 var
107 WAD: TWADEditor_1;
108 SectionList: SArray;
109 i: Integer;
110 FileName, fn, sn, rn: String;
111
112 begin
113 WAD := TWADEditor_1.Create();
114
115 // Внешний WAD:
116 if cbWADList.Text <> _lc[I_WAD_SPECIAL_MAP] then
117 FileName := EditorDir+'wads/'+cbWADList.Text
118 else // WAD карты:
119 begin
120 g_ProcessResourceStr(OpenedMap, fn, sn, rn);
121 FileName := fn;
122 end;
123
124 // Читаем секции:
125 WAD.ReadFile(FileName);
126 SectionList := WAD.GetSectionList();
127 WAD.Free();
128
129 cbSectionsList.Clear();
130 lbResourcesList.Clear();
131
132 if SectionList <> nil then
133 for i := 0 to High(SectionList) do
134 if SectionList[i] <> '' then
135 cbSectionsList.Items.Add(SectionList[i])
136 else
137 cbSectionsList.Items.Add('..');
138 end;
139
140 procedure TAddResourceForm.cbSectionsListChange(Sender: TObject);
141 var
142 ResourceList: SArray;
143 WAD: TWADEditor_1;
144 i: DWORD;
145 FileName, SectionName, fn, sn, rn: String;
146
147 begin
148 WAD := TWADEditor_1.Create();
149
150 // Внешний WAD:
151 if cbWADList.Text <> _lc[I_WAD_SPECIAL_MAP] then
152 FileName := EditorDir+'wads/'+cbWADList.Text
153 else // WAD карты:
154 begin
155 g_ProcessResourceStr(OpenedMap, fn, sn, rn);
156 FileName := fn;
157 end;
158
159 // Читаем WAD:
160 WAD.ReadFile(FileName);
161
162 if cbSectionsList.Text <> '..' then
163 SectionName := cbSectionsList.Text
164 else
165 SectionName := '';
166
167 // Читаем ресурсы выбранной секции:
168 ResourceList := WAD.GetResourcesList(SectionName);
169
170 WAD.Free();
171
172 lbResourcesList.Clear();
173
174 if ResourceList <> nil then
175 for i := 0 to High(ResourceList) do
176 lbResourcesList.Items.Add(ResourceList[i]);
177 end;
178
179 procedure TAddResourceForm.lbResourcesListClick(Sender: TObject);
180 var
181 FileName, SectionName, fn: String;
182
183 begin
184 FResourceSelected := (lbResourcesList.SelCount > 0) or
185 (lbResourcesList.ItemIndex > -1);
186
187 if not FResourceSelected then
188 begin
189 FResourceName := '';
190 FFullResourceName := '';
191 Exit;
192 end;
193
194 if cbSectionsList.Text = '..' then
195 SectionName := ''
196 else
197 SectionName := cbSectionsList.Text;
198
199 if cbWADList.Text[1] <> '<' then
200 FileName := cbWADList.Text
201 else
202 FileName := '';
203
204 FResourceName := FileName+':'+SectionName+'\'+lbResourcesList.Items[lbResourcesList.ItemIndex];
205
206 if FileName <> '' then
207 FFullResourceName := EditorDir+'wads/'+FResourceName
208 else
209 begin
210 g_ProcessResourceStr(OpenedMap, @fn, nil, nil);
211 FFullResourceName := fn+FResourceName;
212 end;
213 end;
214
215 end.