Subversion Repositories spacemission

Compare Revisions

Regard whitespace Rev 1 → Rev HEAD

/LevSpeicherung.pas
4,7 → 4,7
 
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Spin, ComCtrls;
StdCtrls, ExtCtrls, Spin, ComCtrls{$IF CompilerVersion >= 23.0}, System.UITypes{$IFEND};
 
type
TSpeicherungForm = class(TForm)
25,10 → 25,10
li2b: TLabel;
li2a: TLabel;
li3b: TLabel;
li4: TLabel;
liu: TLabel;
liw: TLabel;
SpinEditEdt: TEdit;
SpinEdit: TUpDown;
LevelNumber: TSpinEdit;
procedure LoeschenBtnClick(Sender: TObject);
procedure LadenBtnClick(Sender: TObject);
procedure SpeichernBtnClick(Sender: TObject);
38,35 → 38,33
procedure DsFancyButton2Click(Sender: TObject);
procedure AbbrechenBtnClick(Sender: TObject);
procedure LevelNameChange(Sender: TObject);
procedure LevelListBoxDblClick(Sender: TObject);
procedure FormHide(Sender: TObject);
procedure SpinEditClick(Sender: TObject; Button: TUDBtnType);
procedure SpinEditEdtKeyPress(Sender: TObject; var Key: Char);
procedure SpinEditEdtChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
function GetListBoxSelectedLevelNumber: integer;
public
procedure SearchLevels;
function RightStr(str: string; count: integer): string;
function Filter(n: integer; s: string): string;
end;
 
var
SpeicherungForm: TSpeicherungForm;
 
const
FCompVersion = '1.0';
 
implementation
 
uses
LevMain;
Global, LevMain, ComLevelReader;
 
{$R *.DFM}
 
resourcestring
SLevelListBox = 'Level %d';
SSelbsterstellt = 'Selbsterstellt';
SLevelFileNotFound = 'Leveldatei nicht gefunden';
 
procedure TSpeicherungForm.SearchLevels;
var
{sr: TSearchRec;
res: integer;}
i: integer;
fil: TLevelFile;
begin
//SpinEdit.Value := 1;
LevelListBox.items.clear;
76,40 → 74,34
li1b.visible := false;
li2b.visible := false;
li3b.visible := false;
li4.visible := false;
liu.Visible := false;
liw.visible := true;
LadenBtn.enabled := false;
LoeschenBtn.enabled := false;
{res := FindFirst(mainform.fdirectory+'Levels\*.lev', 0, sr);
try
while (res = 0) do
for i := 1 to MaxPossibleLevels do
begin
if (sr.name <> '.') and (sr.name <> '..') then
LevelListBox.items.Add(copy(sr.Name, 0, length(sr.name)-4));
res := FindNext(sr);
end;
finally
FindClose(sr);
end;}
for i := 1 to 9999 do
fil := GetLevelFileName(i, false);
if fil.found then
begin
if fileexists(mainform.fdirectory+'Levels\Level '+inttostr(i)+'.lev') then
LevelListBox.items.Add('Level ' + inttostr(i));
if fil.isUser then
LevelListBox.items.Add(Format(SLevelListBox, [i])+' ('+SSelbsterstellt+')')
else
LevelListBox.items.Add(Format(SLevelListBox, [i]));
end;
end;
end;
 
procedure TSpeicherungForm.LoeschenBtnClick(Sender: TObject);
resourcestring
SReallyDeleteLevel = 'Dieses Level wirklich löschen?';
var
Markiert: boolean;
i: integer;
fil: TLevelFile;
begin
Markiert := false;
for i := 0 to LevelListBox.items.Count-1 do
if LevelListBox.ItemIndex = -1 then exit;
 
if MessageDlg(SReallyDeleteLevel, mtConfirmation, mbYesNoCancel, 0) = mrYes then
begin
if LevelListBox.Selected[i] then Markiert := true;
end;
if not Markiert then exit;
if MessageDlg('Dieses Level wirklich löschen?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then
begin
li1a.visible := false;
li2a.visible := false;
li3a.visible := false;
116,154 → 108,59
li1b.visible := false;
li2b.visible := false;
li3b.visible := false;
li4.visible := false;
liu.visible := false;
liw.visible := true;
LadenBtn.enabled := false;
LoeschenBtn.enabled := false;
deletefile(mainform.FDirectory+'Levels\'+
LevelListBox.Items.strings[LevelListBox.itemindex]+'.lev');
fil := GetLevelFileName(GetListBoxSelectedLevelNumber,false);
if not fil.found then raise Exception.Create(SLevelFileNotFound);
deletefile(fil.fileLocation);
SearchLevels;
end;
end;
 
procedure TSpeicherungForm.LadenBtnClick(Sender: TObject);
resourcestring
SLoadNewLevelAndDiscardChanges = 'Neues Level laden und Änderungen verwerfen?';
var
Markiert: boolean;
i, TempArtMain, TempLiveMain: integer;
SavGame: textfile;
Ergebnis: array[1..5] of string;
fil: TLevelFile;
begin
Markiert := false;
for i := 0 to LevelListBox.items.Count-1 do
if LevelListBox.ItemIndex = -1 then exit;
 
if MainForm.LevChanged and (MainForm.LevData.CountEnemies>0) then
begin
if LevelListBox.Selected[i] then Markiert := true;
if MessageDlg(SLoadNewLevelAndDiscardChanges, mtConfirmation, mbYesNoCancel, 0) <> mrYes then exit;
end;
if not Markiert then exit;
if LevelListBox.items.count = 0 then
begin
li1a.visible := false;
li2a.visible := false;
li3a.visible := false;
li1b.visible := false;
li2b.visible := false;
li3b.visible := false;
liw.visible := true;
LadenBtn.enabled := false;
LoeschenBtn.enabled := false;
end;
 
// Da Button bei ungültigen Level deaktiviert wird, ist das nicht mehr nötig.
{if liu.visible or (LevelListBox.items.count=0) then
exit;}
// Vorbereiten
 
MainForm.DestroyLevel;
MainForm.LevData.RasterErzwingen := true;
fil := GetLevelFileName(GetListBoxSelectedLevelNumber,false);
if not fil.found then raise Exception.Create(SLevelFileNotFound);
MainForm.LevData.LoadFromFile(fil.fileLocation);
MainForm.RefreshFromLevData;
MainForm.LevChanged := false;
// Öffnen
AssignFile(SavGame, mainform.FDirectory+'Levels\'+
LevelListBox.Items.strings[LevelListBox.itemindex]+'.lev');
Reset(SavGame);
// Laden
ReadLN(SavGame); // --> Copyrightinfo
ReadLN(SavGame); // --> Copyrightinfo
ReadLN(SavGame, Ergebnis[5]); // --> Länge der Karte
MainForm.ScrollBar.Max := strtoint(Ergebnis[5]);
MainForm.Enemys.Clear;
TempArtMain := MainForm.ArtChecked;
TempLiveMain := MainForm.LiveEdit;
while not seekEoF(SavGame) do
begin
ReadLN(SavGame, Ergebnis[3]);
ReadLN(SavGame, Ergebnis[1]);
ReadLN(SavGame, Ergebnis[2]);
ReadLN(SavGame, Ergebnis[4]);
MainForm.EnemyAdd(strtoint(Ergebnis[1]), strtoint(Ergebnis[2]), strtoint(Ergebnis[3]), strtoint(Ergebnis[4]));
MainForm.ArtChecked := strtoint(Ergebnis[3]);
MainForm.LiveEdit := strtoint(Ergebnis[4]);
MainForm.EnemyCreate(strtoint(Ergebnis[1]), strtoint(Ergebnis[2]));
inc(MainForm.NumEnemys);
if Ergebnis[3] = '7' then MainForm.Boss := true;
end;
MainForm.LiveEdit := TempLiveMain;
MainForm.ArtChecked := TempArtMain;
// Schließen
CloseFile(SavGame);
// Nacharbeiten
MainForm.AnzeigeAct;
close;
end;
 
function TSpeicherungForm.RightStr(str: string; count: integer): string;
begin
result := copy(str, length(str)-(count-1), count);
end;
 
function TSpeicherungForm.Filter(n: integer; s: string): string;
var
i, last: integer;
start, start2: boolean;
temp: string;
begin
last := 0;
start := false;
start2 := false;
temp := '';
if n = 1 then
begin
for i := 1 to length(s)+1 do
begin
if copy(s, i, 1) = '-' then
begin
last := i;
break;
end;
end;
temp := copy(s, 1, last-1);
end;
if n = 2 then
begin
for i := 1 to length(s)+1 do
begin
if start2 then start := true;
if copy(s, i, 1) = '-' then start2 := true;
if (copy(s, i, 1) = ':') and start then break;
if start then temp := temp + copy(s, i, 1)
end;
end;
if n = 3 then
begin
for i := 1 to length(s)+1 do
begin
if start2 then start := true;
if copy(s, i, 1) = ':' then start2 := true;
if (copy(s, i, 1) = '(') and start then break;
if start then temp := temp + copy(s, i, 1)
end;
end;
if n = 4 then
begin
for i := 1 to length(s)+1 do
begin
if start2 then start := true;
if copy(s, i, 1) = '(' then start2 := true;
if (copy(s, i, 1) = ')') and start then break;
if start then temp := temp + copy(s, i, 1)
end;
end;
result := temp;
end;
 
procedure TSpeicherungForm.SpeichernBtnClick(Sender: TObject);
var
SavGame: textfile;
i, j: integer;
puffer: string;
resourcestring
SLevelIsEmpty = 'Das Level ist leer!';
SLevelAlreadyExists = 'Level ist bereits vorhanden. Ersetzen?';
SNoValidLevelName = 'Dies ist kein gültiger Levelname!';
begin
if mainform.Enemys.count = 0 then
if MainForm.LevData.CountEnemies = 0 then
begin
MessageDlg('Das Level ist leer!', mtError, [mbOK], 0);
SpinEdit.SetFocus;
MessageDlg(SLevelIsEmpty, mtError, [mbOK], 0);
LevelNumber.SetFocus;
exit;
end;
{for i := 0 to length(LevelName.text) do
{for i := 1 to length(LevelName.text) do
begin
if (copy(LevelName.text, i, 1) = '\') or
(copy(LevelName.text, i, 1) = '/') or
275,45 → 172,22
(copy(LevelName.text, i, 1) = '>') or
(copy(LevelName.text, i, 1) = '|') then
begin
MessageDlg('Dies ist kein gültiger Levelname!', mtError, [mbOK], 0);
MessageDlg(SNoValidLevelName, mtError, [mbOK], 0);
LevelName.SetFocus;
exit;
end;
end;}
if LevelListBox.items.IndexOf('Level ' + inttostr(SpinEdit.Position)) > -1 then
if (LevelListBox.items.IndexOf(Format(SLevelListBox, [LevelNumber.Value])) > -1) or
(LevelListBox.items.IndexOf(Format(SLevelListBox, [LevelNumber.Value])+' ('+SSelbsterstellt+')') > -1) then
begin
if MessageDlg('Level ist bereits vorhanden. Ersetzen?', mtConfirmation, [mbYes, mbNo], 0) = mrNo then
if MessageDlg(SLevelAlreadyExists, mtConfirmation, mbYesNoCancel, 0) <> mrYes then
exit;
end;
// Öffnen oder erstellen
AssignFile(SavGame, mainform.FDirectory+'Levels\Level '+inttostr(SpinEdit.Position)+'.lev');
Rewrite(SavGame);
// Sortierung
for j := 0 to mainform.enemys.Count - 2 do
begin
for i := 0 to mainform.enemys.Count - 2 do
begin
if strtoint(filter(1, mainform.enemys.Strings[i])) > strtoint(filter(1, mainform.enemys.Strings[i + 1])) then
begin
puffer := mainform.enemys.Strings[i];
mainform.enemys.Strings[i] := mainform.enemys.Strings[i + 1];
mainform.enemys.Strings[i + 1] := puffer;
end;
end;
end;
 
// Speichern
WriteLN(SavGame, '; SpaceMission ' + FCompVersion);
WriteLN(SavGame, '; LEV-File');
WriteLN(SavGame, inttostr(MainForm.ScrollBar.Max)); // --> Länge der Karte
for i := 0 to mainform.enemys.count-1 do
begin
WriteLN(SavGame, filter(3, mainform.enemys.Strings[i]));
WriteLN(SavGame, filter(1, mainform.enemys.Strings[i]));
WriteLN(SavGame, filter(2, mainform.enemys.Strings[i]));
WriteLN(SavGame, filter(4, mainform.enemys.Strings[i]));
end;
// Schließen
CloseFile(SavGame);
MainForm.LevData.LevelEditorLength := MainForm.ScrollBar.Max;
MainForm.LevData.SaveToFile(GetLevelFileName(LevelNumber.Value,true).fileLocation);
 
// Nacharbeiten
MainForm.LevChanged := false;
MainForm.AnzeigeAct;
321,10 → 195,17
end;
 
procedure TSpeicherungForm.LevelListBoxClick(Sender: TObject);
resourcestring
SYes = 'Ja';
SNo = 'Nein';
SFields = '%d Felder';
SXbyY = '%s von %s';
var
Ergebnis, boss, l, temp: string;
SavGame: textfile;
x, a: integer;
LevelData: TLevelData;
boss: boolean;
i: Integer;
anzahlEinheiten: integer;
fil: TLevelFile;
begin
li1a.visible := false;
li2a.visible := false;
332,6 → 213,7
li1b.visible := false;
li2b.visible := false;
li3b.visible := false;
li4.visible := false;
liu.visible := false;
liw.visible := false;
if (LevelListBox.items.count=0) or (LevelListBox.itemindex = -1) then
341,47 → 223,27
liw.visible := true;
exit;
end;
temp := LevelListBox.Items.strings[LevelListBox.itemindex];
SpinEdit.Position := strtoint(RightStr(temp, length(temp)-6));
AssignFile(SavGame, mainform.FDirectory+'Levels\'+
LevelListBox.Items.strings[LevelListBox.itemindex]+'.lev');
Reset(SavGame);
ReadLN(SavGame, Ergebnis);
if Ergebnis <> '; SpaceMission '+FCompVersion then
LevelNumber.Value := GetListBoxSelectedLevelNumber;
 
LevelData := TLevelData.Create;
try
try
LevelData.RasterErzwingen := true;
 
fil := GetLevelFileName(GetListBoxSelectedLevelNumber,false);
if not fil.found then raise Exception.Create(SLevelFileNotFound);
LevelData.LoadFromFile(fil.fileLocation);
 
boss := false;
anzahlEinheiten := Length(LevelData.EnemyAdventTable);
for i := 0 to anzahlEinheiten - 1 do
begin
liu.visible := true;
LadenBtn.enabled := false;
CloseFile(SavGame);
exit;
end;
ReadLN(SavGame, Ergebnis);
if Ergebnis <> '; LEV-File' then
if LevelData.EnemyAdventTable[i].enemyType = etEnemyBoss then
begin
liu.visible := true;
LadenBtn.enabled := false;
CloseFile(SavGame);
exit;
boss := true;
end;
ReadLN(SavGame, l);
x := 0;
a := 0;
boss := 'Nein';
while not SeekEOF(SavGame) do
begin
ReadLN(SavGame, Ergebnis);
inc(a);
if a = 5 then a := 1;
if (a = 1) and (Ergebnis = '7') then boss := 'Ja';
inc(x);
end;
CloseFile(SavGame);
if a <> 4 then
begin
liu.visible := true;
LadenBtn.enabled := false;
end
else
begin
 
li1a.visible := true;
li2a.visible := true;
li3a.visible := true;
388,13 → 250,24
li1b.visible := true;
li2b.visible := true;
li3b.visible := true;
li4.visible := true;
LadenBtn.enabled := true;
LoeschenBtn.enabled := true;
li1b.caption := inttostr(trunc(x / 4));
li2b.caption := boss;
li3b.caption := l + ' Felder';
li1b.caption := inttostr(anzahlEinheiten);
if boss then
li2b.caption := SYes
else
li2b.caption := SNo;
li3b.caption := Format(SFields, [LevelData.LevelEditorLength]);
li4.Caption := Trim(Format(SXbyY, [LevelData.LevelName, LevelData.LevelAuthor]));
finally
FreeAndNil(LevelData);
end;
except
liu.visible := true;
LadenBtn.enabled := false;
end;
end;
 
procedure TSpeicherungForm.Button4Click(Sender: TObject);
begin
407,6 → 280,23
SearchLevels;
end;
 
function TSpeicherungForm.GetListBoxSelectedLevelNumber: integer;
var
i: integer;
begin
result := -1;
if LevelListBox.itemindex = -1 then exit;
for i := 1 to MaxPossibleLevels do
begin
if (LevelListBox.Items.strings[LevelListBox.itemindex] = Format(SLevelListBox, [i])) or
(LevelListBox.Items.strings[LevelListBox.itemindex] = Format(SLevelListBox, [i])+' ('+SSelbstErstellt+')') then
begin
result := i;
exit;
end;
end;
end;
 
procedure TSpeicherungForm.DsFancyButton2Click(Sender: TObject);
begin
SearchLevels;
422,9 → 312,11
{...}
end;
 
procedure TSpeicherungForm.LevelListBoxDblClick(Sender: TObject);
procedure TSpeicherungForm.FormCreate(Sender: TObject);
begin
LadenBtn.click;
LevelNumber.MinValue := 1;
LevelNumber.MaxValue := MaxPossibleLevels;
LevelNumber.Value := 1;
end;
 
procedure TSpeicherungForm.FormHide(Sender: TObject);
432,23 → 324,5
mainform.dxtimer.enabled := true;
end;
 
procedure TSpeicherungForm.SpinEditClick(Sender: TObject;
Button: TUDBtnType);
begin
SpinEditEdt.Text := inttostr(SpinEdit.position);
end;
 
procedure TSpeicherungForm.SpinEditEdtKeyPress(Sender: TObject;
var Key: Char);
begin
if not (Key in [#13, #08, '0'..'9']) then
Key := #0;
end;
 
procedure TSpeicherungForm.SpinEditEdtChange(Sender: TObject);
begin
SpinEdit.Position := strtoint(SpinEditEdt.text);
end;
 
end.