DEADSOFTWARE

514cf5cdfa6e42c8f6ed9f3d535425d79801da33
[d2df-editor.git] / src / editor / f_addresource.pas
1 unit f_addresource;
3 {$INCLUDE ../shared/a_modes.inc}
5 interface
7 uses
8 LCLIntf, LCLType, LMessages, Messages, SysUtils, Variants, Classes,
9 Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls,
10 ExtDlgs, e_Log, e_textures, WADEDITOR;
12 type
13 TOKFunction = function: Boolean;
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;
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);
30 protected
31 FResourceName: String;
32 FFullResourceName: String;
33 FResourceSelected: Boolean;
34 FOKFunction: TOKFunction;
36 public
37 property ResourceName: String read FResourceName;
38 property FullResourceName: String read FFullResourceName;
39 property OKFunction: TOKFunction read FOKFunction write FOKFunction;
40 end;
42 var
43 AddResourceForm: TAddResourceForm;
45 implementation
47 uses
48 f_main, WADSTRUCT, g_language, utils;
50 {$R *.lfm}
52 const
53 STANDART_WAD = 'Standart.wad';
55 procedure TAddResourceForm.FormActivate(Sender: TObject);
56 var
57 SR: TSearchRec;
59 begin
60 cbWADList.Clear();
61 cbSectionsList.Clear();
62 lbResourcesList.Clear();
64 FResourceName := '';
65 FFullResourceName := '';
66 FResourceSelected := False;
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);
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;
82 // WAD карты:
83 if OpenedMap <> '' then
84 cbWADList.Items.Add(_lc[I_WAD_SPECIAL_MAP]);
85 end;
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;
96 if @FOKFunction <> nil then
97 begin
98 if FOKFunction() then
99 Close();
100 end
101 else
102 Close();
103 end;
105 procedure TAddResourceForm.cbWADListChange(Sender: TObject);
106 var
107 WAD: TWADEditor_1;
108 SectionList: SArray;
109 i: Integer;
110 FileName, fn, sn, rn: String;
112 begin
113 WAD := TWADEditor_1.Create();
115 // Внешний WAD:
116 if cbWADList.Text <> _lc[I_WAD_SPECIAL_MAP] then
117 FileName := EditorDir+'wads/'+utf2win(cbWADList.Text)
118 else // WAD карты:
119 begin
120 g_ProcessResourceStr(OpenedMap, fn, sn, rn);
121 FileName := fn;
122 end;
124 // Читаем секции:
125 WAD.ReadFile(FileName);
126 SectionList := WAD.GetSectionList();
127 WAD.Free();
129 cbSectionsList.Clear();
130 lbResourcesList.Clear();
132 if SectionList <> nil then
133 for i := 0 to High(SectionList) do
134 if SectionList[i] <> '' then
135 cbSectionsList.Items.Add(win2utf(SectionList[i]))
136 else
137 cbSectionsList.Items.Add('..');
138 end;
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;
147 begin
148 WAD := TWADEditor_1.Create();
150 // Внешний WAD:
151 if cbWADList.Text <> _lc[I_WAD_SPECIAL_MAP] then
152 FileName := EditorDir+'wads/'+utf2win(cbWADList.Text)
153 else // WAD карты:
154 begin
155 g_ProcessResourceStr(OpenedMap, fn, sn, rn);
156 FileName := fn;
157 end;
159 // Читаем WAD:
160 WAD.ReadFile(FileName);
162 if cbSectionsList.Text <> '..' then
163 SectionName := utf2win(cbSectionsList.Text)
164 else
165 SectionName := '';
167 // Читаем ресурсы выбранной секции:
168 ResourceList := WAD.GetResourcesList(SectionName);
170 WAD.Free();
172 lbResourcesList.Clear();
174 if ResourceList <> nil then
175 for i := 0 to High(ResourceList) do
176 lbResourcesList.Items.Add(win2utf(ResourceList[i]));
177 end;
179 procedure TAddResourceForm.lbResourcesListClick(Sender: TObject);
180 var
181 FileName, SectionName, fn: String;
183 begin
184 FResourceSelected := (lbResourcesList.SelCount > 0) or
185 (lbResourcesList.ItemIndex > -1);
187 if not FResourceSelected then
188 begin
189 FResourceName := '';
190 FFullResourceName := '';
191 Exit;
192 end;
194 if cbSectionsList.Text = '..' then
195 SectionName := ''
196 else
197 SectionName := utf2win(cbSectionsList.Text);
199 if cbWADList.Text[1] <> '<' then
200 FileName := utf2win(cbWADList.Text)
201 else
202 FileName := '';
204 FResourceName := FileName+':'+SectionName+'\'+utf2win(lbResourcesList.Items[lbResourcesList.ItemIndex]);
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;
215 end.