Rev 28 | Rev 40 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3 | daniel-mar | 1 | unit GamSpeicherung; |
2 | |||
3 | interface |
||
4 | |||
5 | uses |
||
6 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, |
||
6 | daniel-mar | 7 | StdCtrls, ExtCtrls, Spin{$IF CompilerVersion >= 23.0}, System.UITypes{$IFEND}; |
3 | 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 | LevelName: TEdit; |
||
22 | ElPanel1: TPanel; |
||
23 | li4a: TLabel; |
||
24 | li1: TLabel; |
||
25 | li3b: TLabel; |
||
26 | li3a: TLabel; |
||
27 | li4b: TLabel; |
||
28 | liu: TLabel; |
||
29 | liw: TLabel; |
||
30 | li2a: TLabel; |
||
31 | li2b: TLabel; |
||
32 | procedure LoeschenBtnClick(Sender: TObject); |
||
33 | procedure LadenBtnClick(Sender: TObject); |
||
34 | procedure SpeichernBtnClick(Sender: TObject); |
||
35 | procedure LevelListBoxClick(Sender: TObject); |
||
36 | procedure LevelNameChange(Sender: TObject); |
||
37 | procedure Button4Click(Sender: TObject); |
||
38 | procedure FormShow(Sender: TObject); |
||
39 | procedure DsFancyButton2Click(Sender: TObject); |
||
40 | procedure AbbrechenBtnClick(Sender: TObject); |
||
41 | procedure FormHide(Sender: TObject); |
||
42 | procedure LevelListBoxDblClick(Sender: TObject); |
||
26 | daniel-mar | 43 | private |
44 | function GetSpielstandVerzeichnis: string; |
||
3 | daniel-mar | 45 | public |
46 | procedure SearchSaves; |
||
47 | end; |
||
48 | |||
49 | var |
||
50 | SpeicherungForm: TSpeicherungForm; |
||
51 | |||
52 | implementation |
||
53 | |||
54 | uses |
||
26 | daniel-mar | 55 | Global, GamMain, ComSaveGameReader, ActiveX, ShlObj; |
3 | daniel-mar | 56 | |
57 | {$R *.DFM} |
||
58 | |||
26 | daniel-mar | 59 | const |
60 | FOLDERID_SavedGames: TGuid = '{4C5C32FF-BB9D-43b0-B5B4-2D72E54EAAA4}'; |
||
61 | |||
62 | function GetKnownFolderPath(const rfid: TGUID): string; |
||
63 | var |
||
64 | OutPath: PWideChar; |
||
65 | begin |
||
66 | // https://www.delphipraxis.net/135471-unit-zur-verwendung-von-shgetknownfolderpath.html |
||
67 | if ShGetKnownFolderPath(rfid, 0, 0, OutPath) {>= 0} = S_OK then |
||
68 | begin |
||
69 | Result := OutPath; |
||
70 | // From MSDN |
||
71 | // ppszPath [out] |
||
72 | // Type: PWSTR* |
||
73 | // When this method returns, contains the address of a pointer to a null-terminated Unicode string that specifies the path of the known folder |
||
74 | // The calling process is responsible for freeing this resource once it is no longer needed by calling CoTaskMemFree. |
||
75 | // The returned path does not include a trailing backslash. For example, "C:\Users" is returned rather than "C:\Users\". |
||
76 | CoTaskMemFree(OutPath); |
||
77 | end |
||
78 | else |
||
79 | begin |
||
80 | Result := ''; |
||
81 | end; |
||
82 | end; |
||
83 | |||
84 | { TSpeicherungForm } |
||
85 | |||
3 | daniel-mar | 86 | procedure TSpeicherungForm.SearchSaves; |
87 | var |
||
88 | sr: TSearchRec; |
||
89 | res: integer; |
||
90 | begin |
||
91 | LevelName.text := ''; |
||
92 | LevelListBox.items.clear; |
||
93 | li1.visible := false; |
||
94 | li2a.visible := false; |
||
95 | li2b.visible := false; |
||
96 | li3a.visible := false; |
||
97 | li3b.visible := false; |
||
98 | li4a.visible := false; |
||
99 | li4b.visible := false; |
||
100 | liu.visible := false; |
||
101 | liw.visible := true; |
||
102 | li1.caption := 'n/a'; |
||
103 | li2b.caption := 'n/a'; |
||
104 | li3b.caption := 'n/a'; |
||
105 | li4b.caption := 'n/a'; |
||
106 | LadenBtn.enabled := false; |
||
107 | LoeschenBtn.enabled := false; |
||
26 | daniel-mar | 108 | res := FindFirst(IncludeTrailingPathDelimiter(GetSpielstandVerzeichnis)+'*.sav', 0, sr); |
3 | daniel-mar | 109 | try |
110 | while (res = 0) do |
||
111 | begin |
||
112 | if (sr.name <> '.') and (sr.name <> '..') then |
||
24 | daniel-mar | 113 | LevelListBox.items.Add(ChangeFileExt(sr.Name, '')); |
3 | daniel-mar | 114 | res := FindNext(sr); |
115 | end; |
||
116 | finally |
||
117 | FindClose(sr); |
||
118 | end; |
||
119 | end; |
||
120 | |||
121 | procedure TSpeicherungForm.LoeschenBtnClick(Sender: TObject); |
||
122 | begin |
||
28 | daniel-mar | 123 | if LevelListBox.ItemIndex = -1 then exit; |
124 | |||
125 | if MessageDlg('Diesen Spielstand wirklich löschen?', mtConfirmation, mbYesNoCancel, 0) = mrYes then |
||
3 | daniel-mar | 126 | begin |
127 | li1.visible := false; |
||
128 | li2a.visible := false; |
||
129 | li2b.visible := false; |
||
130 | li3a.visible := false; |
||
131 | li3b.visible := false; |
||
132 | li4a.visible := false; |
||
133 | li4b.visible := false; |
||
134 | liu.visible := false; |
||
135 | liw.visible := false; |
||
136 | li1.caption := 'n/a'; |
||
137 | li2b.caption := 'n/a'; |
||
138 | li3b.caption := 'n/a'; |
||
139 | li4b.caption := 'n/a'; |
||
140 | LadenBtn.enabled := false; |
||
141 | LoeschenBtn.enabled := false; |
||
26 | daniel-mar | 142 | deletefile(IncludeTrailingPathDelimiter(GetSpielstandVerzeichnis)+LevelListBox.Items.strings[LevelListBox.itemindex]+'.sav'); |
3 | daniel-mar | 143 | searchsaves; |
144 | end; |
||
145 | end; |
||
146 | |||
147 | procedure TSpeicherungForm.LadenBtnClick(Sender: TObject); |
||
148 | var |
||
15 | daniel-mar | 149 | SavGame: TSaveData; |
3 | daniel-mar | 150 | begin |
28 | daniel-mar | 151 | if LevelListBox.ItemIndex = -1 then exit; |
152 | |||
3 | daniel-mar | 153 | if LevelListBox.items.count = 0 then |
154 | begin |
||
155 | li1.visible := false; |
||
156 | li2a.visible := false; |
||
157 | li2b.visible := false; |
||
158 | li3a.visible := false; |
||
159 | li3b.visible := false; |
||
160 | li4a.visible := false; |
||
161 | li4b.visible := false; |
||
162 | liu.visible := false; |
||
163 | liw.visible := false; |
||
164 | li1.caption := 'n/a'; |
||
165 | li2b.caption := 'n/a'; |
||
166 | li3b.caption := 'n/a'; |
||
167 | li4b.caption := 'n/a'; |
||
168 | LadenBtn.enabled := false; |
||
169 | LoeschenBtn.enabled := false; |
||
170 | end; |
||
171 | {if liu.visible or (LevelListBox.items.count=0) then |
||
172 | exit;} |
||
15 | daniel-mar | 173 | SavGame := TSaveData.Create; |
174 | try |
||
26 | daniel-mar | 175 | SavGame.Load(IncludeTrailingPathDelimiter(GetSpielstandVerzeichnis)+LevelListBox.Items.strings[LevelListBox.itemindex]+'.sav'); |
15 | daniel-mar | 176 | mainform.FScore := SavGame.FScore; |
177 | mainform.FLife := SavGame.FLife; |
||
178 | mainform.FLevel := SavGame.FLevel; |
||
179 | mainform.FGameMode := SavGame.FGameMode; |
||
180 | finally |
||
181 | FreeAndNil(SavGame); |
||
182 | end; |
||
31 | daniel-mar | 183 | mainform.playsound(smsSceneMov, false); |
3 | daniel-mar | 184 | mainform.FNextScene := gsNewLevel; |
185 | mainform.FCheat := false; |
||
186 | close; |
||
187 | end; |
||
188 | |||
189 | procedure TSpeicherungForm.SpeichernBtnClick(Sender: TObject); |
||
190 | var |
||
15 | daniel-mar | 191 | SavGame: TSaveData; |
3 | daniel-mar | 192 | i: integer; |
193 | begin |
||
194 | if Levelname.text = '' then |
||
195 | begin |
||
196 | MessageDlg('Dies ist kein gültiger Spielstandname!', mtError, [mbOK], 0); |
||
197 | LevelName.setfocus; |
||
198 | exit; |
||
199 | end; |
||
200 | for i := 0 to length(LevelName.text) do |
||
201 | begin |
||
202 | if (copy(LevelName.text, i, 1) = '\') or |
||
203 | (copy(LevelName.text, i, 1) = '/') or |
||
204 | (copy(LevelName.text, i, 1) = ':') or |
||
205 | (copy(LevelName.text, i, 1) = '*') or |
||
206 | (copy(LevelName.text, i, 1) = '?') or |
||
207 | (copy(LevelName.text, i, 1) = '"') or |
||
208 | (copy(LevelName.text, i, 1) = '<') or |
||
209 | (copy(LevelName.text, i, 1) = '>') or |
||
210 | (copy(LevelName.text, i, 1) = '|') then |
||
211 | begin |
||
212 | MessageDlg('Dies ist kein gültiger Spielstandname!', mtError, [mbOK], 0); |
||
213 | LevelName.setfocus; |
||
214 | exit; |
||
215 | end; |
||
216 | end; |
||
217 | if LevelListBox.items.IndexOf(LevelName.text) > -1 then |
||
218 | begin |
||
28 | daniel-mar | 219 | if MessageDlg('Spielstand ist bereits vorhanden. Ersetzen?', mtConfirmation, mbYesNoCancel, 0) <> mrYes then |
3 | daniel-mar | 220 | exit; |
221 | end; |
||
15 | daniel-mar | 222 | |
223 | SavGame := TSaveData.Create; |
||
224 | try |
||
225 | SavGame.FScore := mainform.FScore; |
||
226 | SavGame.FLife := mainform.FLife; |
||
227 | SavGame.FLevel := mainform.FLevel; |
||
228 | SavGame.FGameMode := mainform.FGameMode; |
||
26 | daniel-mar | 229 | SavGame.Save(IncludeTrailingPathDelimiter(GetSpielstandVerzeichnis)+LevelName.text+'.sav'); |
15 | daniel-mar | 230 | finally |
231 | FreeAndNil(SavGame); |
||
232 | end; |
||
233 | |||
3 | daniel-mar | 234 | SearchSaves; |
235 | end; |
||
236 | |||
237 | procedure TSpeicherungForm.LevelListBoxClick(Sender: TObject); |
||
238 | var |
||
15 | daniel-mar | 239 | SavGame: TSaveData; |
240 | Punkte, Leben, Level: integer; |
||
241 | Art: TGameMode; |
||
3 | daniel-mar | 242 | begin |
243 | ladenbtn.enabled := true; |
||
244 | loeschenbtn.enabled := true; |
||
245 | li1.visible := false; |
||
246 | li2a.visible := false; |
||
247 | li2b.visible := false; |
||
248 | li3a.visible := false; |
||
249 | li3b.visible := false; |
||
250 | li4a.visible := false; |
||
251 | li4b.visible := false; |
||
252 | liu.visible := false; |
||
253 | liw.visible := false; |
||
254 | li1.caption := 'n/a'; |
||
255 | li2b.caption := 'n/a'; |
||
256 | li3b.caption := 'n/a'; |
||
257 | li4b.caption := 'n/a'; |
||
258 | if (LevelListBox.items.count=0) or (LevelListBox.itemindex = -1) then |
||
259 | begin |
||
260 | ladenbtn.enabled := false; |
||
261 | loeschenbtn.enabled := false; |
||
262 | liw.visible := true; |
||
263 | exit; |
||
264 | end; |
||
265 | LevelName.Text := LevelListBox.Items.strings[LevelListBox.itemindex]; |
||
15 | daniel-mar | 266 | |
267 | SavGame := TSaveData.Create; |
||
268 | try |
||
269 | try |
||
26 | daniel-mar | 270 | SavGame.Load(IncludeTrailingPathDelimiter(GetSpielstandVerzeichnis)+LevelListBox.Items.strings[LevelListBox.itemindex]+'.sav'); |
15 | daniel-mar | 271 | Punkte := SavGame.FScore; |
272 | Leben := SavGame.FLife; |
||
273 | Level := SavGame.FLevel; |
||
274 | Art := SavGame.FGameMode; |
||
275 | except |
||
276 | liu.visible := true; |
||
277 | ladenbtn.enabled := false; |
||
278 | exit; |
||
279 | end; |
||
280 | finally |
||
281 | FreeAndNil(SavGame); |
||
3 | daniel-mar | 282 | end; |
283 | li1.visible := true; |
||
284 | li2a.visible := true; |
||
285 | li2b.visible := true; |
||
286 | li3a.visible := true; |
||
287 | li3b.visible := true; |
||
288 | li4a.visible := true; |
||
289 | li4b.visible := true; |
||
15 | daniel-mar | 290 | if Art = gmLevels then |
3 | daniel-mar | 291 | li1.caption := 'Das Level ist ein normales Level.' |
292 | else |
||
293 | li1.caption := 'Das Level ist ein Zufallslevel.'; |
||
294 | li3b.caption := inttostr(Level); |
||
295 | li4b.caption := inttostr(Leben); |
||
296 | li2b.caption := inttostr(Punkte); |
||
297 | end; |
||
298 | |||
299 | procedure TSpeicherungForm.LevelNameChange(Sender: TObject); |
||
300 | begin |
||
301 | //listbox1.Items.indexof('Level '+spinedit1.text); |
||
302 | end; |
||
303 | |||
304 | procedure TSpeicherungForm.Button4Click(Sender: TObject); |
||
305 | begin |
||
306 | mainform.dxtimer.enabled := not mainform.gamepause.checked; |
||
307 | close; |
||
308 | end; |
||
309 | |||
310 | procedure TSpeicherungForm.FormShow(Sender: TObject); |
||
311 | begin |
||
312 | mainform.dxtimer.enabled := false; |
||
313 | SearchSaves; |
||
314 | if mainform.FNotSave then |
||
315 | begin |
||
316 | label1.enabled := false; |
||
317 | LevelName.enabled := false; |
||
318 | SpeichernBtn.enabled := false; |
||
319 | end |
||
320 | else |
||
321 | begin |
||
322 | label1.enabled := true; |
||
323 | LevelName.enabled := true; |
||
324 | SpeichernBtn.enabled := true; |
||
325 | end; |
||
326 | end; |
||
327 | |||
26 | daniel-mar | 328 | function TSpeicherungForm.GetSpielstandVerzeichnis: string; |
329 | begin |
||
330 | try |
||
331 | result := GetKnownFolderPath(FOLDERID_SavedGames); |
||
332 | except |
||
333 | result := ''; |
||
334 | end; |
||
335 | if result = '' then |
||
336 | begin |
||
337 | // Pre Vista |
||
31 | daniel-mar | 338 | result := OwnDirectory + 'Spielstände'; |
26 | daniel-mar | 339 | end |
340 | else |
||
341 | begin |
||
342 | result := IncludeTrailingPathDelimiter(result); |
||
343 | result := result + 'SpaceMission'; |
||
344 | end; |
||
345 | result := IncludeTrailingPathDelimiter(result); |
||
346 | ForceDirectories(result); |
||
347 | end; |
||
348 | |||
3 | daniel-mar | 349 | procedure TSpeicherungForm.DsFancyButton2Click(Sender: TObject); |
350 | begin |
||
351 | SearchSaves; |
||
352 | end; |
||
353 | |||
354 | procedure TSpeicherungForm.AbbrechenBtnClick(Sender: TObject); |
||
355 | begin |
||
356 | close; |
||
357 | end; |
||
358 | |||
359 | procedure TSpeicherungForm.FormHide(Sender: TObject); |
||
360 | begin |
||
361 | if not mainform.gamepause.checked then mainform.dxtimer.enabled := true; |
||
362 | end; |
||
363 | |||
364 | procedure TSpeicherungForm.LevelListBoxDblClick(Sender: TObject); |
||
365 | begin |
||
366 | LadenBtn.click; |
||
367 | end; |
||
368 | |||
369 | end. |
||
370 |