Rev 45 | Rev 66 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 45 | Rev 51 | ||
---|---|---|---|
1 | unit GamSpeicherung; |
1 | unit GamSpeicherung; |
2 | 2 | ||
3 | interface |
3 | interface |
4 | 4 | ||
5 | uses |
5 | uses |
6 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, |
6 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, |
7 | StdCtrls, ExtCtrls, Spin{$IF CompilerVersion >= 23.0}, System.UITypes{$IFEND}; |
7 | StdCtrls, ExtCtrls, Spin{$IF CompilerVersion >= 23.0}, System.UITypes{$IFEND}; |
8 | 8 | ||
9 | type |
9 | type |
10 | TSpeicherungForm = class(TForm) |
10 | TSpeicherungForm = class(TForm) |
11 | Bevel1: TBevel; |
11 | Bevel1: TBevel; |
12 | LadenBtn: TButton; |
12 | LadenBtn: TButton; |
13 | LoeschenBtn: TButton; |
13 | LoeschenBtn: TButton; |
14 | AktualisierenBtn: TButton; |
14 | AktualisierenBtn: TButton; |
15 | SpeichernBtn: TButton; |
15 | SpeichernBtn: TButton; |
16 | AbbrechenBtn: TButton; |
16 | AbbrechenBtn: TButton; |
17 | LevelListBox: TListBox; |
17 | LevelListBox: TListBox; |
18 | Label2: TLabel; |
18 | Label2: TLabel; |
19 | Label3: TLabel; |
19 | Label3: TLabel; |
20 | Label1: TLabel; |
20 | Label1: TLabel; |
21 | LevelName: TEdit; |
21 | LevelName: TEdit; |
22 | ElPanel1: TPanel; |
22 | ElPanel1: TPanel; |
23 | li4a: TLabel; |
23 | li4a: TLabel; |
24 | li1: TLabel; |
24 | li1: TLabel; |
25 | li3b: TLabel; |
25 | li3b: TLabel; |
26 | li3a: TLabel; |
26 | li3a: TLabel; |
27 | li4b: TLabel; |
27 | li4b: TLabel; |
28 | liu: TLabel; |
28 | liu: TLabel; |
29 | liw: TLabel; |
29 | liw: TLabel; |
30 | li2a: TLabel; |
30 | li2a: TLabel; |
31 | li2b: TLabel; |
31 | li2b: TLabel; |
32 | procedure LoeschenBtnClick(Sender: TObject); |
32 | procedure LoeschenBtnClick(Sender: TObject); |
33 | procedure LadenBtnClick(Sender: TObject); |
33 | procedure LadenBtnClick(Sender: TObject); |
34 | procedure SpeichernBtnClick(Sender: TObject); |
34 | procedure SpeichernBtnClick(Sender: TObject); |
35 | procedure LevelListBoxClick(Sender: TObject); |
35 | procedure LevelListBoxClick(Sender: TObject); |
36 | procedure LevelNameChange(Sender: TObject); |
36 | procedure LevelNameChange(Sender: TObject); |
37 | procedure Button4Click(Sender: TObject); |
37 | procedure Button4Click(Sender: TObject); |
38 | procedure FormShow(Sender: TObject); |
38 | procedure FormShow(Sender: TObject); |
39 | procedure DsFancyButton2Click(Sender: TObject); |
39 | procedure DsFancyButton2Click(Sender: TObject); |
40 | procedure AbbrechenBtnClick(Sender: TObject); |
40 | procedure AbbrechenBtnClick(Sender: TObject); |
41 | procedure FormHide(Sender: TObject); |
41 | procedure FormHide(Sender: TObject); |
42 | procedure LevelListBoxDblClick(Sender: TObject); |
42 | procedure LevelListBoxDblClick(Sender: TObject); |
43 | private |
43 | private |
- | 44 | function GetSpielstandVerzeichnisSystem: string; |
|
44 | function GetSpielstandVerzeichnis: string; |
45 | function GetSpielstandVerzeichnisUser: string; |
- | 46 | function GetSaveGameFileName(SpielstandName: string; forceuserdir: boolean): string; |
|
45 | public |
47 | public |
46 | procedure SearchSaves; |
48 | procedure SearchSaves; |
47 | end; |
49 | end; |
48 | 50 | ||
49 | var |
51 | var |
50 | SpeicherungForm: TSpeicherungForm; |
52 | SpeicherungForm: TSpeicherungForm; |
51 | 53 | ||
52 | implementation |
54 | implementation |
53 | 55 | ||
54 | uses |
56 | uses |
55 | Global, GamMain, ComLevelReader, ActiveX, ShlObj; |
57 | Global, GamMain, ComLevelReader; |
56 | 58 | ||
57 | {$R *.DFM} |
59 | {$R *.DFM} |
58 | 60 | ||
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 } |
61 | { TSpeicherungForm } |
85 | 62 | ||
86 | procedure TSpeicherungForm.SearchSaves; |
63 | procedure TSpeicherungForm.SearchSaves; |
87 | var |
64 | var |
88 | sr: TSearchRec; |
65 | sr: TSearchRec; |
89 | res: integer; |
66 | res: integer; |
90 | begin |
67 | begin |
91 | LevelName.text := ''; |
68 | LevelName.text := ''; |
92 | LevelListBox.items.clear; |
69 | LevelListBox.items.clear; |
93 | li1.visible := false; |
70 | li1.visible := false; |
94 | li2a.visible := false; |
71 | li2a.visible := false; |
95 | li2b.visible := false; |
72 | li2b.visible := false; |
96 | li3a.visible := false; |
73 | li3a.visible := false; |
97 | li3b.visible := false; |
74 | li3b.visible := false; |
98 | li4a.visible := false; |
75 | li4a.visible := false; |
99 | li4b.visible := false; |
76 | li4b.visible := false; |
100 | liu.visible := false; |
77 | liu.visible := false; |
101 | liw.visible := true; |
78 | liw.visible := true; |
102 | li1.caption := 'n/a'; |
79 | li1.caption := 'n/a'; |
103 | li2b.caption := 'n/a'; |
80 | li2b.caption := 'n/a'; |
104 | li3b.caption := 'n/a'; |
81 | li3b.caption := 'n/a'; |
105 | li4b.caption := 'n/a'; |
82 | li4b.caption := 'n/a'; |
106 | LadenBtn.enabled := false; |
83 | LadenBtn.enabled := false; |
107 | LoeschenBtn.enabled := false; |
84 | LoeschenBtn.enabled := false; |
108 | res := FindFirst(IncludeTrailingPathDelimiter(GetSpielstandVerzeichnis)+'*.sav', 0, sr); |
85 | res := FindFirst(IncludeTrailingPathDelimiter(GetSpielstandVerzeichnisSystem)+'*.sav', 0, sr); |
109 | try |
86 | try |
110 | while (res = 0) do |
87 | while (res = 0) do |
111 | begin |
88 | begin |
112 | if (sr.name <> '.') and (sr.name <> '..') then |
89 | if (sr.name <> '.') and (sr.name <> '..') then |
113 | LevelListBox.items.Add(ChangeFileExt(sr.Name, '')); |
90 | LevelListBox.items.Add(ChangeFileExt(sr.Name, '')); |
114 | res := FindNext(sr); |
91 | res := FindNext(sr); |
115 | end; |
92 | end; |
116 | finally |
93 | finally |
117 | FindClose(sr); |
94 | FindClose(sr); |
118 | end; |
95 | end; |
- | 96 | res := FindFirst(IncludeTrailingPathDelimiter(GetSpielstandVerzeichnisUser)+'*.sav', 0, sr); |
|
- | 97 | try |
|
- | 98 | while (res = 0) do |
|
- | 99 | begin |
|
- | 100 | // Anmerkung: Contains() ist nicht case-sensitive |
|
- | 101 | if (sr.name <> '.') and (sr.name <> '..') and not LevelListBox.Items.Contains(ChangeFileExt(sr.Name, '')) then |
|
- | 102 | LevelListBox.items.Add(ChangeFileExt(sr.Name, '')); |
|
- | 103 | res := FindNext(sr); |
|
- | 104 | end; |
|
- | 105 | finally |
|
- | 106 | FindClose(sr); |
|
- | 107 | end; |
|
- | 108 | LevelListBox.Sorted := true; |
|
119 | end; |
109 | end; |
120 | 110 | ||
121 | procedure TSpeicherungForm.LoeschenBtnClick(Sender: TObject); |
111 | procedure TSpeicherungForm.LoeschenBtnClick(Sender: TObject); |
- | 112 | var |
|
- | 113 | fil: string; |
|
122 | begin |
114 | begin |
123 | if LevelListBox.ItemIndex = -1 then exit; |
115 | if LevelListBox.ItemIndex = -1 then exit; |
124 | 116 | ||
125 | if MessageDlg('Diesen Spielstand wirklich löschen?', mtConfirmation, mbYesNoCancel, 0) = mrYes then |
117 | if MessageDlg('Diesen Spielstand wirklich löschen?', mtConfirmation, mbYesNoCancel, 0) = mrYes then |
126 | begin |
118 | begin |
127 | li1.visible := false; |
119 | li1.visible := false; |
128 | li2a.visible := false; |
120 | li2a.visible := false; |
129 | li2b.visible := false; |
121 | li2b.visible := false; |
130 | li3a.visible := false; |
122 | li3a.visible := false; |
131 | li3b.visible := false; |
123 | li3b.visible := false; |
132 | li4a.visible := false; |
124 | li4a.visible := false; |
133 | li4b.visible := false; |
125 | li4b.visible := false; |
134 | liu.visible := false; |
126 | liu.visible := false; |
135 | liw.visible := false; |
127 | liw.visible := false; |
136 | li1.caption := 'n/a'; |
128 | li1.caption := 'n/a'; |
137 | li2b.caption := 'n/a'; |
129 | li2b.caption := 'n/a'; |
138 | li3b.caption := 'n/a'; |
130 | li3b.caption := 'n/a'; |
139 | li4b.caption := 'n/a'; |
131 | li4b.caption := 'n/a'; |
140 | LadenBtn.enabled := false; |
132 | LadenBtn.enabled := false; |
141 | LoeschenBtn.enabled := false; |
133 | LoeschenBtn.enabled := false; |
142 | deletefile(IncludeTrailingPathDelimiter(GetSpielstandVerzeichnis)+LevelListBox.Items.strings[LevelListBox.itemindex]+'.sav'); |
134 | fil := GetSaveGameFileName(LevelListBox.Items.strings[LevelListBox.itemindex], false); |
- | 135 | if not fileexists(fil) then raise Exception.Create('Spielstandsdatei nicht gefunden'); |
|
- | 136 | deletefile(fil); |
|
143 | searchsaves; |
137 | searchsaves; |
144 | end; |
138 | end; |
145 | end; |
139 | end; |
146 | 140 | ||
- | 141 | function TSpeicherungForm.GetSaveGameFileName(SpielstandName: string; forceuserdir: boolean): string; |
|
- | 142 | var |
|
- | 143 | usr, sys: string; |
|
- | 144 | begin |
|
- | 145 | usr := IncludeTrailingPathDelimiter(GetSpielstandVerzeichnisUser) + SpielstandName + '.sav'; // ab SpaceMission 1.2+ |
|
- | 146 | sys := IncludeTrailingPathDelimiter(GetSpielstandVerzeichnisSystem) + SpielstandName + '.sav'; // alte Versionen von SpaceMission <1.2 |
|
- | 147 | if fileexists(usr) or forceuserdir then exit(usr); |
|
- | 148 | if fileexists(sys) then exit(sys); |
|
- | 149 | exit(usr); |
|
- | 150 | end; |
|
- | 151 | ||
147 | procedure TSpeicherungForm.LadenBtnClick(Sender: TObject); |
152 | procedure TSpeicherungForm.LadenBtnClick(Sender: TObject); |
148 | var |
153 | var |
149 | SavGame: TSaveData; |
154 | SavGame: TSaveData; |
- | 155 | fil: string; |
|
150 | begin |
156 | begin |
151 | if LevelListBox.ItemIndex = -1 then exit; |
157 | if LevelListBox.ItemIndex = -1 then exit; |
152 | 158 | ||
153 | if LevelListBox.items.count = 0 then |
159 | if LevelListBox.items.count = 0 then |
154 | begin |
160 | begin |
155 | li1.visible := false; |
161 | li1.visible := false; |
156 | li2a.visible := false; |
162 | li2a.visible := false; |
157 | li2b.visible := false; |
163 | li2b.visible := false; |
158 | li3a.visible := false; |
164 | li3a.visible := false; |
159 | li3b.visible := false; |
165 | li3b.visible := false; |
160 | li4a.visible := false; |
166 | li4a.visible := false; |
161 | li4b.visible := false; |
167 | li4b.visible := false; |
162 | liu.visible := false; |
168 | liu.visible := false; |
163 | liw.visible := false; |
169 | liw.visible := false; |
164 | li1.caption := 'n/a'; |
170 | li1.caption := 'n/a'; |
165 | li2b.caption := 'n/a'; |
171 | li2b.caption := 'n/a'; |
166 | li3b.caption := 'n/a'; |
172 | li3b.caption := 'n/a'; |
167 | li4b.caption := 'n/a'; |
173 | li4b.caption := 'n/a'; |
168 | LadenBtn.enabled := false; |
174 | LadenBtn.enabled := false; |
169 | LoeschenBtn.enabled := false; |
175 | LoeschenBtn.enabled := false; |
170 | end; |
176 | end; |
171 | {if liu.visible or (LevelListBox.items.count=0) then |
177 | {if liu.visible or (LevelListBox.items.count=0) then |
172 | exit;} |
178 | exit;} |
173 | SavGame := TSaveData.Create; |
179 | SavGame := TSaveData.Create; |
174 | try |
180 | try |
175 | SavGame.LoadFromFile(IncludeTrailingPathDelimiter(GetSpielstandVerzeichnis)+LevelListBox.Items.strings[LevelListBox.itemindex]+'.sav'); |
181 | fil := GetSaveGameFileName(LevelListBox.Items.strings[LevelListBox.itemindex], false); |
- | 182 | if not fileexists(fil) then raise Exception.Create('Spielstandsdatei nicht gefunden'); |
|
- | 183 | SavGame.LoadFromFile(fil); |
|
176 | mainform.FScore := SavGame.Score; |
184 | mainform.FScore := SavGame.Score; |
177 | mainform.FLife := SavGame.Life; |
185 | mainform.FLife := SavGame.Life; |
178 | mainform.FLevel := SavGame.Level; |
186 | mainform.FLevel := SavGame.Level; |
179 | mainform.FGameMode := SavGame.GameMode; |
187 | mainform.FGameMode := SavGame.GameMode; |
180 | MainForm.FLevelDataAlreadyLoaded := true; // do not call NewLevel() in StartSceneMain |
188 | MainForm.FLevelDataAlreadyLoaded := true; // do not call NewLevel() in StartSceneMain |
181 | if Assigned(SavGame.LevelData) then |
189 | if Assigned(SavGame.LevelData) then |
182 | begin |
190 | begin |
183 | MainForm.LevelData.Assign(SavGame.LevelData); |
191 | MainForm.LevelData.Assign(SavGame.LevelData); |
184 | end; |
192 | end; |
185 | finally |
193 | finally |
186 | FreeAndNil(SavGame); |
194 | FreeAndNil(SavGame); |
187 | end; |
195 | end; |
188 | mainform.playsound(smsSceneMov, false); |
196 | mainform.playsound(smsSceneMov, false); |
189 | mainform.FNextScene := gsNewLevel; |
197 | mainform.FNextScene := gsNewLevel; |
190 | mainform.FCheat := false; |
198 | mainform.FCheat := false; |
191 | close; |
199 | close; |
192 | end; |
200 | end; |
193 | 201 | ||
194 | procedure TSpeicherungForm.SpeichernBtnClick(Sender: TObject); |
202 | procedure TSpeicherungForm.SpeichernBtnClick(Sender: TObject); |
195 | var |
203 | var |
196 | SavGame: TSaveData; |
204 | SavGame: TSaveData; |
197 | i: integer; |
205 | i: integer; |
198 | begin |
206 | begin |
199 | if Levelname.text = '' then |
207 | if Levelname.text = '' then |
200 | begin |
208 | begin |
201 | MessageDlg('Dies ist kein gültiger Spielstandname!', mtError, [mbOK], 0); |
209 | MessageDlg('Dies ist kein gültiger Spielstandname!', mtError, [mbOK], 0); |
202 | LevelName.setfocus; |
210 | LevelName.setfocus; |
203 | exit; |
211 | exit; |
204 | end; |
212 | end; |
205 | for i := 0 to length(LevelName.text) do |
213 | for i := 0 to length(LevelName.text) do |
206 | begin |
214 | begin |
207 | if (copy(LevelName.text, i, 1) = '\') or |
215 | if (copy(LevelName.text, i, 1) = '\') or |
208 | (copy(LevelName.text, i, 1) = '/') or |
216 | (copy(LevelName.text, i, 1) = '/') or |
209 | (copy(LevelName.text, i, 1) = ':') or |
217 | (copy(LevelName.text, i, 1) = ':') or |
210 | (copy(LevelName.text, i, 1) = '*') or |
218 | (copy(LevelName.text, i, 1) = '*') or |
211 | (copy(LevelName.text, i, 1) = '?') or |
219 | (copy(LevelName.text, i, 1) = '?') or |
212 | (copy(LevelName.text, i, 1) = '"') or |
220 | (copy(LevelName.text, i, 1) = '"') or |
213 | (copy(LevelName.text, i, 1) = '<') or |
221 | (copy(LevelName.text, i, 1) = '<') or |
214 | (copy(LevelName.text, i, 1) = '>') or |
222 | (copy(LevelName.text, i, 1) = '>') or |
215 | (copy(LevelName.text, i, 1) = '|') then |
223 | (copy(LevelName.text, i, 1) = '|') then |
216 | begin |
224 | begin |
217 | MessageDlg('Dies ist kein gültiger Spielstandname!', mtError, [mbOK], 0); |
225 | MessageDlg('Dies ist kein gültiger Spielstandname!', mtError, [mbOK], 0); |
218 | LevelName.setfocus; |
226 | LevelName.setfocus; |
219 | exit; |
227 | exit; |
220 | end; |
228 | end; |
221 | end; |
229 | end; |
222 | if LevelListBox.items.IndexOf(LevelName.text) > -1 then |
230 | if LevelListBox.items.IndexOf(LevelName.text) > -1 then |
223 | begin |
231 | begin |
224 | if MessageDlg('Spielstand ist bereits vorhanden. Ersetzen?', mtConfirmation, mbYesNoCancel, 0) <> mrYes then |
232 | if MessageDlg('Spielstand ist bereits vorhanden. Ersetzen?', mtConfirmation, mbYesNoCancel, 0) <> mrYes then |
225 | exit; |
233 | exit; |
226 | end; |
234 | end; |
227 | 235 | ||
228 | SavGame := TSaveData.Create; |
236 | SavGame := TSaveData.Create; |
229 | try |
237 | try |
230 | SavGame.Score := mainform.FScoreAtLevelStart;//mainform.FScore; |
238 | SavGame.Score := mainform.FScoreAtLevelStart;//mainform.FScore; |
231 | SavGame.Life := mainform.FLifeAtLevelStart;//mainform.FLife; |
239 | SavGame.Life := mainform.FLifeAtLevelStart;//mainform.FLife; |
232 | SavGame.Level := mainform.FLevel; |
240 | SavGame.Level := mainform.FLevel; |
233 | SavGame.GameMode := mainform.FGameMode; |
241 | SavGame.GameMode := mainform.FGameMode; |
234 | if not Assigned(SavGame.LevelData) then SavGame.LevelData := TLevelData.Create; |
242 | if not Assigned(SavGame.LevelData) then SavGame.LevelData := TLevelData.Create; |
235 | SavGame.LevelData.Assign(mainForm.LevelData); |
243 | SavGame.LevelData.Assign(mainForm.LevelData); |
236 | SavGame.SaveToFile(IncludeTrailingPathDelimiter(GetSpielstandVerzeichnis)+LevelName.text+'.sav'); |
244 | SavGame.SaveToFile(GetSaveGameFileName(LevelName.text, true)); |
237 | finally |
245 | finally |
238 | FreeAndNil(SavGame); |
246 | FreeAndNil(SavGame); |
239 | end; |
247 | end; |
240 | 248 | ||
241 | SearchSaves; |
249 | SearchSaves; |
242 | end; |
250 | end; |
243 | 251 | ||
244 | procedure TSpeicherungForm.LevelListBoxClick(Sender: TObject); |
252 | procedure TSpeicherungForm.LevelListBoxClick(Sender: TObject); |
245 | var |
253 | var |
246 | SavGame: TSaveData; |
254 | SavGame: TSaveData; |
247 | Punkte, Leben, Level: integer; |
255 | Punkte, Leben, Level: integer; |
248 | BeinhaltetLevelDaten: boolean; |
256 | BeinhaltetLevelDaten: boolean; |
249 | Art: TGameMode; |
257 | Art: TGameMode; |
- | 258 | fil: string; |
|
250 | begin |
259 | begin |
251 | ladenbtn.enabled := true; |
260 | ladenbtn.enabled := true; |
252 | loeschenbtn.enabled := true; |
261 | loeschenbtn.enabled := true; |
253 | li1.visible := false; |
262 | li1.visible := false; |
254 | li2a.visible := false; |
263 | li2a.visible := false; |
255 | li2b.visible := false; |
264 | li2b.visible := false; |
256 | li3a.visible := false; |
265 | li3a.visible := false; |
257 | li3b.visible := false; |
266 | li3b.visible := false; |
258 | li4a.visible := false; |
267 | li4a.visible := false; |
259 | li4b.visible := false; |
268 | li4b.visible := false; |
260 | liu.visible := false; |
269 | liu.visible := false; |
261 | liw.visible := false; |
270 | liw.visible := false; |
262 | li1.caption := 'n/a'; |
271 | li1.caption := 'n/a'; |
263 | li2b.caption := 'n/a'; |
272 | li2b.caption := 'n/a'; |
264 | li3b.caption := 'n/a'; |
273 | li3b.caption := 'n/a'; |
265 | li4b.caption := 'n/a'; |
274 | li4b.caption := 'n/a'; |
266 | if (LevelListBox.items.count=0) or (LevelListBox.itemindex = -1) then |
275 | if (LevelListBox.items.count=0) or (LevelListBox.itemindex = -1) then |
267 | begin |
276 | begin |
268 | ladenbtn.enabled := false; |
277 | ladenbtn.enabled := false; |
269 | loeschenbtn.enabled := false; |
278 | loeschenbtn.enabled := false; |
270 | liw.visible := true; |
279 | liw.visible := true; |
271 | exit; |
280 | exit; |
272 | end; |
281 | end; |
273 | LevelName.Text := LevelListBox.Items.strings[LevelListBox.itemindex]; |
282 | LevelName.Text := LevelListBox.Items.strings[LevelListBox.itemindex]; |
274 | 283 | ||
275 | SavGame := TSaveData.Create; |
284 | SavGame := TSaveData.Create; |
276 | try |
285 | try |
277 | try |
286 | try |
278 | SavGame.LoadFromFile(IncludeTrailingPathDelimiter(GetSpielstandVerzeichnis)+LevelListBox.Items.strings[LevelListBox.itemindex]+'.sav'); |
287 | fil := GetSaveGameFileName(LevelListBox.Items.strings[LevelListBox.itemindex], false); |
- | 288 | if not fileexists(fil) then raise Exception.Create('Spielstandsdatei nicht gefunden'); |
|
- | 289 | SavGame.LoadFromFile(fil); |
|
279 | Punkte := SavGame.Score; |
290 | Punkte := SavGame.Score; |
280 | Leben := SavGame.Life; |
291 | Leben := SavGame.Life; |
281 | Level := SavGame.Level; |
292 | Level := SavGame.Level; |
282 | Art := SavGame.GameMode; |
293 | Art := SavGame.GameMode; |
283 | BeinhaltetLevelDaten := Assigned(SavGame.LevelData); |
294 | BeinhaltetLevelDaten := Assigned(SavGame.LevelData); |
284 | except |
295 | except |
285 | liu.visible := true; |
296 | liu.visible := true; |
286 | ladenbtn.enabled := false; |
297 | ladenbtn.enabled := false; |
287 | exit; |
298 | exit; |
288 | end; |
299 | end; |
289 | finally |
300 | finally |
290 | FreeAndNil(SavGame); |
301 | FreeAndNil(SavGame); |
291 | end; |
302 | end; |
292 | li1.visible := true; |
303 | li1.visible := true; |
293 | li2a.visible := true; |
304 | li2a.visible := true; |
294 | li2b.visible := true; |
305 | li2b.visible := true; |
295 | li3a.visible := true; |
306 | li3a.visible := true; |
296 | li3b.visible := true; |
307 | li3b.visible := true; |
297 | li4a.visible := true; |
308 | li4a.visible := true; |
298 | li4b.visible := true; |
309 | li4b.visible := true; |
299 | if Art = gmLevels then |
310 | if Art = gmLevels then |
300 | li1.caption := 'Das Level ist ein norm. Level' |
311 | li1.caption := 'Das Level ist ein norm. Level' |
301 | else |
312 | else |
302 | li1.caption := 'Das Level ist ein Zufallslevel'; |
313 | li1.caption := 'Das Level ist ein Zufallslevel'; |
303 | if BeinhaltetLevelDaten then |
314 | if BeinhaltetLevelDaten then |
304 | li1.Caption := li1.Caption + ' mit Karte'; |
315 | li1.Caption := li1.Caption + ' mit Karte'; |
305 | li3b.caption := inttostr(Level); |
316 | li3b.caption := inttostr(Level); |
306 | li4b.caption := inttostr(Leben); |
317 | li4b.caption := inttostr(Leben); |
307 | li2b.caption := inttostr(Punkte); |
318 | li2b.caption := inttostr(Punkte); |
308 | end; |
319 | end; |
309 | 320 | ||
310 | procedure TSpeicherungForm.LevelNameChange(Sender: TObject); |
321 | procedure TSpeicherungForm.LevelNameChange(Sender: TObject); |
311 | begin |
322 | begin |
312 | //listbox1.Items.indexof('Level '+spinedit1.text); |
323 | //listbox1.Items.indexof('Level '+spinedit1.text); |
313 | end; |
324 | end; |
314 | 325 | ||
315 | procedure TSpeicherungForm.Button4Click(Sender: TObject); |
326 | procedure TSpeicherungForm.Button4Click(Sender: TObject); |
316 | begin |
327 | begin |
317 | mainform.dxtimer.enabled := not mainform.gamepause.checked; |
328 | mainform.dxtimer.enabled := not mainform.gamepause.checked; |
318 | close; |
329 | close; |
319 | end; |
330 | end; |
320 | 331 | ||
321 | procedure TSpeicherungForm.FormShow(Sender: TObject); |
332 | procedure TSpeicherungForm.FormShow(Sender: TObject); |
322 | begin |
333 | begin |
323 | mainform.dxtimer.enabled := false; |
334 | mainform.dxtimer.enabled := false; |
324 | SearchSaves; |
335 | SearchSaves; |
325 | if mainform.FNotSave then |
336 | if mainform.FNotSave then |
326 | begin |
337 | begin |
327 | label1.enabled := false; |
338 | label1.enabled := false; |
328 | LevelName.enabled := false; |
339 | LevelName.enabled := false; |
329 | SpeichernBtn.enabled := false; |
340 | SpeichernBtn.enabled := false; |
330 | end |
341 | end |
331 | else |
342 | else |
332 | begin |
343 | begin |
333 | label1.enabled := true; |
344 | label1.enabled := true; |
334 | LevelName.enabled := true; |
345 | LevelName.enabled := true; |
335 | SpeichernBtn.enabled := true; |
346 | SpeichernBtn.enabled := true; |
336 | end; |
347 | end; |
337 | end; |
348 | end; |
338 | 349 | ||
- | 350 | function TSpeicherungForm.GetSpielstandVerzeichnisSystem: string; |
|
- | 351 | begin |
|
- | 352 | // nicht mehr verwendet seit version 1.2 |
|
- | 353 | result := OwnDirectory + 'Spielstände'; |
|
- | 354 | end; |
|
- | 355 | ||
339 | function TSpeicherungForm.GetSpielstandVerzeichnis: string; |
356 | function TSpeicherungForm.GetSpielstandVerzeichnisUser: string; |
340 | begin |
357 | begin |
341 | try |
358 | try |
342 | result := GetKnownFolderPath(FOLDERID_SavedGames); |
359 | result := GetKnownFolderPath(FOLDERID_SavedGames); |
343 | except |
360 | except |
344 | result := ''; |
361 | result := ''; |
345 | end; |
362 | end; |
346 | if result = '' then |
363 | if result = '' then |
347 | begin |
364 | begin |
348 | // Pre Vista |
365 | // Pre Vista |
349 | result := OwnDirectory + 'Spielstände'; |
366 | result := OwnDirectory + 'Spielstände'; |
350 | end |
367 | end |
351 | else |
368 | else |
352 | begin |
369 | begin |
353 | result := IncludeTrailingPathDelimiter(result); |
370 | result := IncludeTrailingPathDelimiter(result); |
354 | result := result + 'SpaceMission'; |
371 | result := result + 'SpaceMission'; |
355 | end; |
372 | end; |
356 | result := IncludeTrailingPathDelimiter(result); |
373 | result := IncludeTrailingPathDelimiter(result); |
357 | ForceDirectories(result); |
374 | ForceDirectories(result); |
358 | end; |
375 | end; |
359 | 376 | ||
360 | procedure TSpeicherungForm.DsFancyButton2Click(Sender: TObject); |
377 | procedure TSpeicherungForm.DsFancyButton2Click(Sender: TObject); |
361 | begin |
378 | begin |
362 | SearchSaves; |
379 | SearchSaves; |
363 | end; |
380 | end; |
364 | 381 | ||
365 | procedure TSpeicherungForm.AbbrechenBtnClick(Sender: TObject); |
382 | procedure TSpeicherungForm.AbbrechenBtnClick(Sender: TObject); |
366 | begin |
383 | begin |
367 | close; |
384 | close; |
368 | end; |
385 | end; |
369 | 386 | ||
370 | procedure TSpeicherungForm.FormHide(Sender: TObject); |
387 | procedure TSpeicherungForm.FormHide(Sender: TObject); |
371 | begin |
388 | begin |
372 | if not mainform.gamepause.checked then mainform.dxtimer.enabled := true; |
389 | if not mainform.gamepause.checked then mainform.dxtimer.enabled := true; |
373 | end; |
390 | end; |
374 | 391 | ||
375 | procedure TSpeicherungForm.LevelListBoxDblClick(Sender: TObject); |
392 | procedure TSpeicherungForm.LevelListBoxDblClick(Sender: TObject); |
376 | begin |
393 | begin |
377 | LadenBtn.click; |
394 | LadenBtn.click; |
378 | end; |
395 | end; |
379 | 396 | ||
380 | end. |
397 | end. |
381 | 398 | ||
382 | 399 |