Subversion Repositories spacemission

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. unit SplSpeicherung;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, ExtCtrls, Spin;
  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);
  43.   public
  44.     procedure SearchSaves;
  45.   end;
  46.  
  47. var
  48.   SpeicherungForm: TSpeicherungForm;
  49.  
  50. const
  51.   FCompVersion = '1.0';
  52.  
  53. implementation
  54.  
  55. uses
  56.   SplMain;
  57.  
  58. {$R *.DFM}
  59.  
  60. procedure TSpeicherungForm.SearchSaves;
  61. var
  62.   sr: TSearchRec;
  63.   res: integer;
  64. begin
  65.   LevelName.text := '';
  66.   LevelListBox.items.clear;
  67.   li1.visible := false;
  68.   li2a.visible := false;
  69.   li2b.visible := false;
  70.   li3a.visible := false;
  71.   li3b.visible := false;
  72.   li4a.visible := false;
  73.   li4b.visible := false;
  74.   liu.visible := false;
  75.   liw.visible := true;
  76.   li1.caption := 'n/a';
  77.   li2b.caption := 'n/a';
  78.   li3b.caption := 'n/a';
  79.   li4b.caption := 'n/a';
  80.   LadenBtn.enabled := false;
  81.   LoeschenBtn.enabled := false;
  82.   res := FindFirst(mainform.fdirectory+'Spielstände\*.sav', 0, sr);
  83.   try
  84.     while (res = 0) do
  85.     begin
  86.       if (sr.name <> '.') and (sr.name <> '..') then
  87.         LevelListBox.items.Add(copy(sr.Name, 0, length(sr.name)-4));
  88.       res := FindNext(sr);
  89.     end;
  90.   finally
  91.     FindClose(sr);
  92.   end;
  93. end;
  94.  
  95. procedure TSpeicherungForm.LoeschenBtnClick(Sender: TObject);
  96. var
  97.   Markiert: boolean;
  98.   i: integer;
  99. begin
  100.   Markiert := false;
  101.   for i := 0 to LevelListBox.items.Count-1 do
  102.   begin
  103.     if LevelListBox.Selected[i] then Markiert := true;
  104.   end;
  105.   if not Markiert then exit;
  106.   if MessageDlg('Diesen Spielstand wirklich löschen?',
  107.     mtConfirmation, [mbYes, mbNo], 0) = mrYes then
  108.   begin
  109.     li1.visible := false;
  110.     li2a.visible := false;
  111.     li2b.visible := false;
  112.     li3a.visible := false;
  113.     li3b.visible := false;
  114.     li4a.visible := false;
  115.     li4b.visible := false;
  116.     liu.visible := false;
  117.     liw.visible := false;
  118.     li1.caption := 'n/a';
  119.     li2b.caption := 'n/a';
  120.     li3b.caption := 'n/a';
  121.     li4b.caption := 'n/a';
  122.     LadenBtn.enabled := false;
  123.     LoeschenBtn.enabled := false;
  124.     deletefile(mainform.FDirectory+'Spielstände\'+LevelListBox.Items.strings[LevelListBox.itemindex]+'.sav');
  125.     searchsaves;
  126.   end;
  127. end;
  128.  
  129. procedure TSpeicherungForm.LadenBtnClick(Sender: TObject);
  130. var
  131.   Markiert: boolean;
  132.   i: integer;
  133.   SavGame: textfile;
  134. begin
  135.   Markiert := false;
  136.   for i := 0 to LevelListBox.items.Count-1 do
  137.   begin
  138.     if LevelListBox.Selected[i] then Markiert := true;
  139.   end;
  140.   if not Markiert then exit;
  141.   if LevelListBox.items.count = 0 then
  142.   begin
  143.     li1.visible := false;
  144.     li2a.visible := false;
  145.     li2b.visible := false;
  146.     li3a.visible := false;
  147.     li3b.visible := false;
  148.     li4a.visible := false;
  149.     li4b.visible := false;
  150.     liu.visible := false;
  151.     liw.visible := false;
  152.     li1.caption := 'n/a';
  153.     li2b.caption := 'n/a';
  154.     li3b.caption := 'n/a';
  155.     li4b.caption := 'n/a';
  156.     LadenBtn.enabled := false;
  157.     LoeschenBtn.enabled := false;
  158.   end;
  159.   {if liu.visible or (LevelListBox.items.count=0) then
  160.     exit;}
  161.   AssignFile(SavGame, mainform.FDirectory+'Spielstände\'+LevelListBox.Items.strings[LevelListBox.itemindex]+'.sav');
  162.   Reset(SavGame);
  163.   ReadLN(SavGame);
  164.   ReadLN(SavGame);
  165.   ReadLN(SavGame, mainform.FScore);
  166.   ReadLN(SavGame, mainform.FLife);
  167.   ReadLN(SavGame, mainform.Flevel);
  168.   ReadLN(SavGame, mainform.FMenuItem);
  169.   CloseFile(SavGame);
  170.   mainform.playsound('SceneMov', false);
  171.   mainform.FNextScene := gsNewLevel;
  172.   mainform.FCheat := false;
  173.   close;
  174. end;
  175.  
  176. procedure TSpeicherungForm.SpeichernBtnClick(Sender: TObject);
  177. var
  178.   SavGame: textfile;
  179.   i: integer;
  180. begin
  181.   if Levelname.text = '' then
  182.   begin
  183.     MessageDlg('Dies ist kein gültiger Spielstandname!', mtError, [mbOK], 0);
  184.     LevelName.setfocus;
  185.     exit;
  186.   end;
  187.   for i := 0 to length(LevelName.text) do
  188.   begin
  189.     if (copy(LevelName.text, i, 1) = '\') or
  190.       (copy(LevelName.text, i, 1) = '/') or
  191.       (copy(LevelName.text, i, 1) = ':') or
  192.       (copy(LevelName.text, i, 1) = '*') or
  193.       (copy(LevelName.text, i, 1) = '?') or
  194.       (copy(LevelName.text, i, 1) = '"') or
  195.       (copy(LevelName.text, i, 1) = '<') or
  196.       (copy(LevelName.text, i, 1) = '>') or
  197.       (copy(LevelName.text, i, 1) = '|') then
  198.     begin
  199.       MessageDlg('Dies ist kein gültiger Spielstandname!', mtError, [mbOK], 0);
  200.       LevelName.setfocus;
  201.       exit;
  202.     end;
  203.   end;
  204.   if LevelListBox.items.IndexOf(LevelName.text) > -1 then
  205.   begin
  206.     if MessageDlg('Spielstand ist bereits vorhanden. Ersetzen?', mtConfirmation, [mbYes, mbNo], 0) = mrNo then
  207.       exit;
  208.   end;
  209.   AssignFile(SavGame, mainform.FDirectory+'Spielstände\'+LevelName.text+'.sav');
  210.   Rewrite(SavGame);
  211.   WriteLN(SavGame, '; SpaceMission '+FCompVersion);
  212.   WriteLN(SavGame, '; SAV-File');
  213.   WriteLN(SavGame, mainform.FScore);
  214.   WriteLN(SavGame, mainform.FLife);
  215.   WriteLN(SavGame, mainform.FLevel);
  216.   WriteLN(SavGame, mainform.FMenuItem);
  217.   CloseFile(SavGame);
  218.   SearchSaves;
  219. end;
  220.  
  221. procedure TSpeicherungForm.LevelListBoxClick(Sender: TObject);
  222. var
  223.   Ergebniss: String;
  224.   SavGame: textfile;
  225.   Punkte, Leben, Level, Art: integer;
  226. begin
  227.   ladenbtn.enabled := true;
  228.   loeschenbtn.enabled := true;
  229.   li1.visible := false;
  230.   li2a.visible := false;
  231.   li2b.visible := false;
  232.   li3a.visible := false;
  233.   li3b.visible := false;
  234.   li4a.visible := false;
  235.   li4b.visible := false;
  236.   liu.visible := false;
  237.   liw.visible := false;
  238.   li1.caption := 'n/a';
  239.   li2b.caption := 'n/a';
  240.   li3b.caption := 'n/a';
  241.   li4b.caption := 'n/a';
  242.   if (LevelListBox.items.count=0) or (LevelListBox.itemindex = -1) then
  243.   begin
  244.     ladenbtn.enabled := false;
  245.     loeschenbtn.enabled := false;
  246.     liw.visible := true;
  247.     exit;
  248.   end;
  249.   LevelName.Text := LevelListBox.Items.strings[LevelListBox.itemindex];
  250.   AssignFile(SavGame, mainform.FDirectory+'Spielstände\'+LevelListBox.Items.strings[LevelListBox.itemindex]+'.sav');
  251.   Reset(SavGame);
  252.   ReadLN(SavGame, Ergebniss);
  253.   if Ergebniss <> '; SpaceMission '+FCompVersion then
  254.   begin
  255.     liu.visible := true;
  256.     ladenbtn.enabled := false;
  257.     CloseFile(SavGame);
  258.     exit;
  259.   end;
  260.   ReadLN(SavGame, Ergebniss);
  261.   if Ergebniss <> '; SAV-File' then
  262.   begin
  263.     liu.visible := true;
  264.     ladenbtn.enabled := false;
  265.     CloseFile(SavGame);
  266.     exit;
  267.   end;
  268.   ReadLN(SavGame, Punkte);
  269.   ReadLN(SavGame, Leben);
  270.   ReadLN(SavGame, Level);
  271.   ReadLN(SavGame, Art);
  272.   CloseFile(SavGame);
  273.   li1.visible := true;
  274.   li2a.visible := true;
  275.   li2b.visible := true;
  276.   li3a.visible := true;
  277.   li3b.visible := true;
  278.   li4a.visible := true;
  279.   li4b.visible := true;
  280.   if Art = 1 then
  281.     li1.caption := 'Das Level ist ein normales Level.'
  282.   else
  283.     li1.caption := 'Das Level ist ein Zufallslevel.';
  284.   li3b.caption := inttostr(Level);
  285.   li4b.caption := inttostr(Leben);
  286.   li2b.caption := inttostr(Punkte);
  287. end;
  288.  
  289. procedure TSpeicherungForm.LevelNameChange(Sender: TObject);
  290. begin
  291.   //listbox1.Items.indexof('Level '+spinedit1.text);
  292. end;
  293.  
  294. procedure TSpeicherungForm.Button4Click(Sender: TObject);
  295. begin
  296.   mainform.dxtimer.enabled := not mainform.gamepause.checked;
  297.   close;
  298. end;
  299.  
  300. procedure TSpeicherungForm.FormShow(Sender: TObject);
  301. begin
  302.   mainform.dxtimer.enabled := false;
  303.   SearchSaves;
  304.   if mainform.FNotSave then
  305.   begin
  306.     label1.enabled := false;
  307.     LevelName.enabled := false;
  308.     SpeichernBtn.enabled := false;
  309.   end
  310.   else
  311.   begin
  312.     label1.enabled := true;
  313.     LevelName.enabled := true;
  314.     SpeichernBtn.enabled := true;
  315.   end;
  316. end;
  317.  
  318. procedure TSpeicherungForm.DsFancyButton2Click(Sender: TObject);
  319. begin
  320.   SearchSaves;
  321. end;
  322.  
  323. procedure TSpeicherungForm.AbbrechenBtnClick(Sender: TObject);
  324. begin
  325.   close;
  326. end;
  327.  
  328. procedure TSpeicherungForm.FormHide(Sender: TObject);
  329. begin
  330.   if not mainform.gamepause.checked then mainform.dxtimer.enabled := true;
  331. end;
  332.  
  333. procedure TSpeicherungForm.LevelListBoxDblClick(Sender: TObject);
  334. begin
  335.   LadenBtn.click;
  336. end;
  337.  
  338. end.
  339.  
  340.