Subversion Repositories spacemission

Rev

Rev 66 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

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