Rev 73 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | daniel-mar | 1 | unit LevSpeicherung; |
2 | |||
3 | interface |
||
4 | |||
5 | uses |
||
6 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, |
||
6 | daniel-mar | 7 | StdCtrls, ExtCtrls, Spin, ComCtrls{$IF CompilerVersion >= 23.0}, System.UITypes{$IFEND}; |
1 | daniel-mar | 8 | |
9 | type |
||
10 | TSpeicherungForm = class(TForm) |
||
11 | Bevel1: TBevel; |
||
12 | LadenBtn: TButton; |
||
13 | LoeschenBtn: TButton; |
||
14 | AktualisierenBtn: TButton; |
||
15 | SpeichernBtn: TButton; |
||
16 | AbbrechenBtn: TButton; |
||
17 | LevelListBox: TListBox; |
||
18 | Label2: TLabel; |
||
19 | Label3: TLabel; |
||
20 | Label1: TLabel; |
||
21 | ElPanel1: TPanel; |
||
22 | li3a: TLabel; |
||
23 | li1b: TLabel; |
||
24 | li1a: TLabel; |
||
25 | li2b: TLabel; |
||
26 | li2a: TLabel; |
||
27 | li3b: TLabel; |
||
43 | daniel-mar | 28 | li4: TLabel; |
1 | daniel-mar | 29 | liu: TLabel; |
30 | liw: TLabel; |
||
24 | daniel-mar | 31 | LevelNumber: TSpinEdit; |
1 | daniel-mar | 32 | procedure LoeschenBtnClick(Sender: TObject); |
33 | procedure LadenBtnClick(Sender: TObject); |
||
34 | procedure SpeichernBtnClick(Sender: TObject); |
||
35 | procedure LevelListBoxClick(Sender: TObject); |
||
36 | procedure Button4Click(Sender: TObject); |
||
37 | procedure FormShow(Sender: TObject); |
||
38 | procedure DsFancyButton2Click(Sender: TObject); |
||
39 | procedure AbbrechenBtnClick(Sender: TObject); |
||
40 | procedure LevelNameChange(Sender: TObject); |
||
41 | procedure FormHide(Sender: TObject); |
||
40 | daniel-mar | 42 | procedure FormCreate(Sender: TObject); |
51 | daniel-mar | 43 | private |
44 | function GetListBoxSelectedLevelNumber: integer; |
||
1 | daniel-mar | 45 | public |
46 | procedure SearchLevels; |
||
47 | end; |
||
48 | |||
49 | var |
||
50 | SpeicherungForm: TSpeicherungForm; |
||
51 | |||
52 | implementation |
||
53 | |||
54 | uses |
||
14 | daniel-mar | 55 | Global, LevMain, ComLevelReader; |
1 | daniel-mar | 56 | |
57 | {$R *.DFM} |
||
58 | |||
51 | daniel-mar | 59 | resourcestring |
60 | SLevelListBox = 'Level %d'; |
||
61 | daniel-mar | 61 | SSelbsterstellt = 'Selbsterstellt'; |
79 | daniel-mar | 62 | SLevelFileNotFound = 'Leveldatei nicht gefunden'; |
51 | daniel-mar | 63 | |
1 | daniel-mar | 64 | procedure TSpeicherungForm.SearchLevels; |
65 | var |
||
66 | i: integer; |
||
61 | daniel-mar | 67 | fil: TLevelFile; |
1 | daniel-mar | 68 | begin |
69 | //SpinEdit.Value := 1; |
||
70 | LevelListBox.items.clear; |
||
71 | li1a.visible := false; |
||
72 | li2a.visible := false; |
||
73 | li3a.visible := false; |
||
74 | li1b.visible := false; |
||
75 | li2b.visible := false; |
||
76 | li3b.visible := false; |
||
43 | daniel-mar | 77 | li4.visible := false; |
51 | daniel-mar | 78 | liu.Visible := false; |
1 | daniel-mar | 79 | liw.visible := true; |
80 | LadenBtn.enabled := false; |
||
81 | LoeschenBtn.enabled := false; |
||
40 | daniel-mar | 82 | for i := 1 to MaxPossibleLevels do |
1 | daniel-mar | 83 | begin |
51 | daniel-mar | 84 | fil := GetLevelFileName(i, false); |
61 | daniel-mar | 85 | if fil.found then |
86 | begin |
||
87 | if fil.isUser then |
||
88 | LevelListBox.items.Add(Format(SLevelListBox, [i])+' ('+SSelbsterstellt+')') |
||
89 | else |
||
90 | LevelListBox.items.Add(Format(SLevelListBox, [i])); |
||
91 | end; |
||
1 | daniel-mar | 92 | end; |
93 | end; |
||
94 | |||
95 | procedure TSpeicherungForm.LoeschenBtnClick(Sender: TObject); |
||
79 | daniel-mar | 96 | resourcestring |
97 | SReallyDeleteLevel = 'Dieses Level wirklich löschen?'; |
||
51 | daniel-mar | 98 | var |
61 | daniel-mar | 99 | fil: TLevelFile; |
1 | daniel-mar | 100 | begin |
28 | daniel-mar | 101 | if LevelListBox.ItemIndex = -1 then exit; |
102 | |||
79 | daniel-mar | 103 | if MessageDlg(SReallyDeleteLevel, mtConfirmation, mbYesNoCancel, 0) = mrYes then |
1 | daniel-mar | 104 | begin |
105 | li1a.visible := false; |
||
106 | li2a.visible := false; |
||
107 | li3a.visible := false; |
||
108 | li1b.visible := false; |
||
109 | li2b.visible := false; |
||
110 | li3b.visible := false; |
||
43 | daniel-mar | 111 | li4.visible := false; |
1 | daniel-mar | 112 | liu.visible := false; |
113 | liw.visible := true; |
||
114 | LadenBtn.enabled := false; |
||
115 | LoeschenBtn.enabled := false; |
||
51 | daniel-mar | 116 | fil := GetLevelFileName(GetListBoxSelectedLevelNumber,false); |
79 | daniel-mar | 117 | if not fil.found then raise Exception.Create(SLevelFileNotFound); |
61 | daniel-mar | 118 | deletefile(fil.fileLocation); |
1 | daniel-mar | 119 | SearchLevels; |
120 | end; |
||
121 | end; |
||
122 | |||
123 | procedure TSpeicherungForm.LadenBtnClick(Sender: TObject); |
||
79 | daniel-mar | 124 | resourcestring |
125 | SLoadNewLevelAndDiscardChanges = 'Neues Level laden und Änderungen verwerfen?'; |
||
51 | daniel-mar | 126 | var |
61 | daniel-mar | 127 | fil: TLevelFile; |
1 | daniel-mar | 128 | begin |
28 | daniel-mar | 129 | if LevelListBox.ItemIndex = -1 then exit; |
130 | |||
30 | daniel-mar | 131 | if MainForm.LevChanged and (MainForm.LevData.CountEnemies>0) then |
1 | daniel-mar | 132 | begin |
79 | daniel-mar | 133 | if MessageDlg(SLoadNewLevelAndDiscardChanges, mtConfirmation, mbYesNoCancel, 0) <> mrYes then exit; |
1 | daniel-mar | 134 | end; |
28 | daniel-mar | 135 | |
1 | daniel-mar | 136 | // Da Button bei ungültigen Level deaktiviert wird, ist das nicht mehr nötig. |
137 | {if liu.visible or (LevelListBox.items.count=0) then |
||
138 | exit;} |
||
30 | daniel-mar | 139 | |
1 | daniel-mar | 140 | MainForm.DestroyLevel; |
44 | daniel-mar | 141 | MainForm.LevData.RasterErzwingen := true; |
51 | daniel-mar | 142 | fil := GetLevelFileName(GetListBoxSelectedLevelNumber,false); |
79 | daniel-mar | 143 | if not fil.found then raise Exception.Create(SLevelFileNotFound); |
61 | daniel-mar | 144 | MainForm.LevData.LoadFromFile(fil.fileLocation); |
30 | daniel-mar | 145 | MainForm.RefreshFromLevData; |
146 | MainForm.LevChanged := false; |
||
1 | daniel-mar | 147 | MainForm.AnzeigeAct; |
148 | close; |
||
149 | end; |
||
150 | |||
151 | procedure TSpeicherungForm.SpeichernBtnClick(Sender: TObject); |
||
79 | daniel-mar | 152 | resourcestring |
153 | SLevelIsEmpty = 'Das Level ist leer!'; |
||
154 | SLevelAlreadyExists = 'Level ist bereits vorhanden. Ersetzen?'; |
||
155 | SNoValidLevelName = 'Dies ist kein gültiger Levelname!'; |
||
1 | daniel-mar | 156 | begin |
27 | daniel-mar | 157 | if MainForm.LevData.CountEnemies = 0 then |
1 | daniel-mar | 158 | begin |
79 | daniel-mar | 159 | MessageDlg(SLevelIsEmpty, mtError, [mbOK], 0); |
24 | daniel-mar | 160 | LevelNumber.SetFocus; |
1 | daniel-mar | 161 | exit; |
162 | end; |
||
66 | daniel-mar | 163 | {for i := 1 to length(LevelName.text) do |
1 | daniel-mar | 164 | begin |
165 | if (copy(LevelName.text, i, 1) = '\') or |
||
166 | (copy(LevelName.text, i, 1) = '/') or |
||
167 | (copy(LevelName.text, i, 1) = ':') or |
||
168 | (copy(LevelName.text, i, 1) = '*') or |
||
169 | (copy(LevelName.text, i, 1) = '?') or |
||
170 | (copy(LevelName.text, i, 1) = '"') or |
||
171 | (copy(LevelName.text, i, 1) = '<') or |
||
172 | (copy(LevelName.text, i, 1) = '>') or |
||
173 | (copy(LevelName.text, i, 1) = '|') then |
||
174 | begin |
||
79 | daniel-mar | 175 | MessageDlg(SNoValidLevelName, mtError, [mbOK], 0); |
1 | daniel-mar | 176 | LevelName.SetFocus; |
177 | exit; |
||
178 | end; |
||
179 | end;} |
||
73 | daniel-mar | 180 | if (LevelListBox.items.IndexOf(Format(SLevelListBox, [LevelNumber.Value])) > -1) or |
181 | (LevelListBox.items.IndexOf(Format(SLevelListBox, [LevelNumber.Value])+' ('+SSelbsterstellt+')') > -1) then |
||
1 | daniel-mar | 182 | begin |
79 | daniel-mar | 183 | if MessageDlg(SLevelAlreadyExists, mtConfirmation, mbYesNoCancel, 0) <> mrYes then |
1 | daniel-mar | 184 | exit; |
185 | end; |
||
15 | daniel-mar | 186 | |
1 | daniel-mar | 187 | // Speichern |
27 | daniel-mar | 188 | MainForm.LevData.LevelEditorLength := MainForm.ScrollBar.Max; |
61 | daniel-mar | 189 | MainForm.LevData.SaveToFile(GetLevelFileName(LevelNumber.Value,true).fileLocation); |
15 | daniel-mar | 190 | |
1 | daniel-mar | 191 | // Nacharbeiten |
192 | MainForm.LevChanged := false; |
||
193 | MainForm.AnzeigeAct; |
||
194 | SearchLevels; |
||
195 | end; |
||
196 | |||
197 | procedure TSpeicherungForm.LevelListBoxClick(Sender: TObject); |
||
79 | daniel-mar | 198 | resourcestring |
199 | SYes = 'Ja'; |
||
200 | SNo = 'Nein'; |
||
201 | SFields = '%d Felder'; |
||
202 | SXbyY = '%s von %s'; |
||
1 | daniel-mar | 203 | var |
14 | daniel-mar | 204 | LevelData: TLevelData; |
205 | boss: boolean; |
||
206 | i: Integer; |
||
207 | anzahlEinheiten: integer; |
||
61 | daniel-mar | 208 | fil: TLevelFile; |
1 | daniel-mar | 209 | begin |
210 | li1a.visible := false; |
||
211 | li2a.visible := false; |
||
212 | li3a.visible := false; |
||
213 | li1b.visible := false; |
||
214 | li2b.visible := false; |
||
215 | li3b.visible := false; |
||
43 | daniel-mar | 216 | li4.visible := false; |
1 | daniel-mar | 217 | liu.visible := false; |
218 | liw.visible := false; |
||
219 | if (LevelListBox.items.count=0) or (LevelListBox.itemindex = -1) then |
||
220 | begin |
||
221 | ladenbtn.enabled := false; |
||
222 | loeschenbtn.enabled := false; |
||
223 | liw.visible := true; |
||
224 | exit; |
||
225 | end; |
||
51 | daniel-mar | 226 | LevelNumber.Value := GetListBoxSelectedLevelNumber; |
14 | daniel-mar | 227 | |
228 | LevelData := TLevelData.Create; |
||
229 | try |
||
230 | try |
||
44 | daniel-mar | 231 | LevelData.RasterErzwingen := true; |
14 | daniel-mar | 232 | |
51 | daniel-mar | 233 | fil := GetLevelFileName(GetListBoxSelectedLevelNumber,false); |
79 | daniel-mar | 234 | if not fil.found then raise Exception.Create(SLevelFileNotFound); |
61 | daniel-mar | 235 | LevelData.LoadFromFile(fil.fileLocation); |
51 | daniel-mar | 236 | |
30 | daniel-mar | 237 | boss := false; |
238 | anzahlEinheiten := Length(LevelData.EnemyAdventTable); |
||
239 | for i := 0 to anzahlEinheiten - 1 do |
||
14 | daniel-mar | 240 | begin |
30 | daniel-mar | 241 | if LevelData.EnemyAdventTable[i].enemyType = etEnemyBoss then |
242 | begin |
||
243 | boss := true; |
||
244 | end; |
||
14 | daniel-mar | 245 | end; |
30 | daniel-mar | 246 | |
247 | li1a.visible := true; |
||
248 | li2a.visible := true; |
||
249 | li3a.visible := true; |
||
250 | li1b.visible := true; |
||
251 | li2b.visible := true; |
||
252 | li3b.visible := true; |
||
43 | daniel-mar | 253 | li4.visible := true; |
30 | daniel-mar | 254 | LadenBtn.enabled := true; |
255 | LoeschenBtn.enabled := true; |
||
256 | li1b.caption := inttostr(anzahlEinheiten); |
||
257 | if boss then |
||
79 | daniel-mar | 258 | li2b.caption := SYes |
30 | daniel-mar | 259 | else |
79 | daniel-mar | 260 | li2b.caption := SNo; |
261 | li3b.caption := Format(SFields, [LevelData.LevelEditorLength]); |
||
262 | li4.Caption := Trim(Format(SXbyY, [LevelData.LevelName, LevelData.LevelAuthor])); |
||
30 | daniel-mar | 263 | finally |
264 | FreeAndNil(LevelData); |
||
14 | daniel-mar | 265 | end; |
30 | daniel-mar | 266 | except |
267 | liu.visible := true; |
||
268 | LadenBtn.enabled := false; |
||
1 | daniel-mar | 269 | end; |
270 | end; |
||
271 | |||
272 | procedure TSpeicherungForm.Button4Click(Sender: TObject); |
||
273 | begin |
||
274 | close; |
||
275 | end; |
||
276 | |||
277 | procedure TSpeicherungForm.FormShow(Sender: TObject); |
||
278 | begin |
||
279 | mainform.dxtimer.enabled := false; |
||
280 | SearchLevels; |
||
281 | end; |
||
282 | |||
51 | daniel-mar | 283 | function TSpeicherungForm.GetListBoxSelectedLevelNumber: integer; |
284 | var |
||
285 | i: integer; |
||
286 | begin |
||
287 | result := -1; |
||
288 | if LevelListBox.itemindex = -1 then exit; |
||
289 | for i := 1 to MaxPossibleLevels do |
||
290 | begin |
||
61 | daniel-mar | 291 | if (LevelListBox.Items.strings[LevelListBox.itemindex] = Format(SLevelListBox, [i])) or |
292 | (LevelListBox.Items.strings[LevelListBox.itemindex] = Format(SLevelListBox, [i])+' ('+SSelbstErstellt+')') then |
||
51 | daniel-mar | 293 | begin |
294 | result := i; |
||
295 | exit; |
||
296 | end; |
||
297 | end; |
||
298 | end; |
||
299 | |||
1 | daniel-mar | 300 | procedure TSpeicherungForm.DsFancyButton2Click(Sender: TObject); |
301 | begin |
||
302 | SearchLevels; |
||
303 | end; |
||
304 | |||
305 | procedure TSpeicherungForm.AbbrechenBtnClick(Sender: TObject); |
||
306 | begin |
||
307 | close; |
||
308 | end; |
||
309 | |||
310 | procedure TSpeicherungForm.LevelNameChange(Sender: TObject); |
||
311 | begin |
||
312 | {...} |
||
313 | end; |
||
314 | |||
40 | daniel-mar | 315 | procedure TSpeicherungForm.FormCreate(Sender: TObject); |
316 | begin |
||
317 | LevelNumber.MinValue := 1; |
||
318 | LevelNumber.MaxValue := MaxPossibleLevels; |
||
319 | LevelNumber.Value := 1; |
||
320 | end; |
||
321 | |||
1 | daniel-mar | 322 | procedure TSpeicherungForm.FormHide(Sender: TObject); |
323 | begin |
||
324 | mainform.dxtimer.enabled := true; |
||
325 | end; |
||
326 | |||
327 | end. |
||
328 |