DEADSOFTWARE

i10n: use resourcestring and gettext for localization
[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, sfs, g_options;
50 {$R *.lfm}
52 const
53 STANDART_WAD = 'standart.wad';
55 procedure TAddResourceForm.FormActivate(Sender: TObject);
56 var
57 SR: TSearchRec;
58 begin
59 cbWADList.Clear();
60 cbSectionsList.Clear();
61 lbResourcesList.Clear();
63 FResourceName := '';
64 FFullResourceName := '';
65 FResourceSelected := False;
67 if FindFirst(WadsDir + DirectorySeparator + '*.*', faAnyFile, SR) = 0 then
68 repeat
69 if (SR.name <> '.') and (SR.name <> '..') then
70 cbWADList.Items.Add(SR.Name);
71 until FindNext(SR) <> 0;
72 FindClose(SR);
74 // "standart.wad" в начало списка:
75 if cbWADList.Items.IndexOf(STANDART_WAD) > 0 then
76 begin
77 cbWADList.Items.Delete(cbWADList.Items.IndexOf(STANDART_WAD));
78 cbWADList.Items.Insert(0, STANDART_WAD);
79 end;
81 // WAD карты:
82 if OpenedMap <> '' then
83 cbWADList.Items.Add(MsgWadSpecialMap);
84 end;
86 procedure TAddResourceForm.bOKClick(Sender: TObject);
87 begin
88 if FResourceName = '' then
89 begin
90 Application.MessageBox(PChar(MsgMsgChooseRes),
91 PChar(MsgMsgError), MB_OK + MB_ICONERROR);
92 Exit;
93 end;
95 if @FOKFunction <> nil then
96 begin
97 if FOKFunction() then
98 Close();
99 end
100 else
101 Close();
102 end;
104 procedure TAddResourceForm.cbWADListChange(Sender: TObject);
105 var
106 wad: TSFSFileList;
107 i: Integer;
108 FileName, Section, sn, rn: String;
109 begin
110 if cbWADList.Text <> MsgWadSpecialMap then
111 FileName := WadsDir + DirectorySeparator + cbWADList.Text (* Resource wad *)
112 else
113 g_ProcessResourceStr(OpenedMap, FileName, sn, rn); (* Map wad *)
115 cbSectionsList.Clear();
116 lbResourcesList.Clear();
118 wad := SFSFileList(FileName);
119 if wad <> nil then
120 begin
121 for i := 0 to wad.Count - 1 do
122 begin
123 Section := win2utf(Copy(wad.Files[i].path, 1, Length(wad.Files[i].path) - 1));
124 if cbSectionsList.Items.IndexOf(Section) = -1 then
125 cbSectionsList.Items.Add(Section)
126 end;
127 wad.Destroy
128 end;
130 (* Update resource list (see below) *)
131 cbSectionsListChange(Sender)
132 end;
134 procedure TAddResourceForm.cbSectionsListChange(Sender: TObject);
135 var
136 wad: TSFSFileList;
137 i: Integer;
138 FileName, Section, SectionName, sn, rn: String;
139 begin
140 if cbWADList.Text <> MsgWadSpecialMap then
141 FileName := WadsDir + DirectorySeparator + cbWADList.Text (* Resource wad *)
142 else
143 g_ProcessResourceStr(OpenedMap, FileName, sn, rn); (* Map wad *)
145 SectionName := cbSectionsList.Text;
146 lbResourcesList.Clear();
148 wad := SFSFileList(FileName);
149 if wad <> nil then
150 begin
151 for i := 0 to wad.Count - 1 do
152 begin
153 Section := win2utf(Copy(wad.Files[i].path, 1, Length(wad.Files[i].path) - 1));
154 if Section = SectionName then
155 lbResourcesList.Items.Add(win2utf(wad.Files[i].name))
156 end;
157 wad.Destroy
158 end;
159 end;
161 procedure TAddResourceForm.lbResourcesListClick(Sender: TObject);
162 var
163 FileName, fn: String;
164 begin
165 FResourceSelected := (lbResourcesList.SelCount > 0) or (lbResourcesList.ItemIndex > -1);
166 if not FResourceSelected then
167 begin
168 FResourceName := '';
169 FFullResourceName := '';
170 Exit;
171 end;
173 if cbWADList.Text[1] <> '<' then
174 FileName := cbWADList.Text
175 else
176 FileName := '';
178 FResourceName := FileName + ':' + cbSectionsList.Text + '\' + lbResourcesList.Items[lbResourcesList.ItemIndex];
180 g_ProcessResourceStr(OpenedMap, @fn, nil, nil);
181 if FileName <> '' then
182 FFullResourceName := WadsDir + DirectorySeparator + FResourceName
183 else
184 FFullResourceName := fn + FResourceName
185 end;
187 end.