Rev 18 | Rev 22 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 18 | Rev 21 | ||
---|---|---|---|
Line 2... | Line 2... | ||
2 | 2 | ||
3 | interface |
3 | interface |
4 | 4 | ||
5 | uses |
5 | uses |
6 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, |
6 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, |
7 | Dialogs, StdCtrls, ImgList, ComCtrls, Menus, ExtCtrls, System.ImageList; |
7 | Dialogs, StdCtrls, ImgList, ComCtrls, Menus, ExtCtrls, System.ImageList, LevelFunctions; |
8 | 8 | ||
9 | type |
9 | type |
10 | TLevelChoice = class(TForm) |
10 | TLevelChoice = class(TForm) |
11 | PlayBtn: TButton; |
11 | PlayBtn: TButton; |
12 | CancelBtn: TButton; |
12 | CancelBtn: TButton; |
Line 20... | Line 20... | ||
20 | LevelList: TListView; |
20 | LevelList: TListView; |
21 | procedure PlayBtnClick(Sender: TObject); |
21 | procedure PlayBtnClick(Sender: TObject); |
22 | procedure CancelBtnClick(Sender: TObject); |
22 | procedure CancelBtnClick(Sender: TObject); |
23 | procedure FormShow(Sender: TObject); |
23 | procedure FormShow(Sender: TObject); |
24 | procedure LevelListClick(Sender: TObject); |
24 | procedure LevelListClick(Sender: TObject); |
25 | procedure LevelListChange(Sender: TObject; Item: TListItem; |
25 | procedure LevelListChange(Sender: TObject; Item: TListItem; Change: TItemChange); |
26 | Change: TItemChange); |
- | |
27 | procedure PRefreshListClick(Sender: TObject); |
26 | procedure PRefreshListClick(Sender: TObject); |
28 | procedure FormResize(Sender: TObject); |
- | |
29 | procedure FormCreate(Sender: TObject); |
27 | procedure FormCreate(Sender: TObject); |
30 | private |
28 | private |
31 | procedure RefreshList; |
29 | procedure RefreshList; |
- | 30 | procedure DrawLevelPreview(Level: TLevel); |
|
32 | public |
31 | public |
33 | function SelectedLevel: string; |
32 | function SelectedLevel: string; |
34 | end; |
33 | end; |
35 | 34 | ||
36 | var |
35 | var |
Line 39... | Line 38... | ||
39 | implementation |
38 | implementation |
40 | 39 | ||
41 | {$R *.dfm} |
40 | {$R *.dfm} |
42 | 41 | ||
43 | uses |
42 | uses |
44 | Functions, LevelFunctions, Constants; |
43 | Functions, Constants; |
- | 44 | ||
- | 45 | procedure TLevelChoice.DrawLevelPreview(Level: TLevel); |
|
- | 46 | var |
|
- | 47 | LevelArray: TLevelArray; |
|
- | 48 | y, x: integer; |
|
- | 49 | t: TFieldType; |
|
- | 50 | indent: Integer; |
|
- | 51 | Image: TImage; |
|
- | 52 | BackgroundColor: TColor; |
|
- | 53 | const |
|
- | 54 | PREVIEW_BLOCK_SIZE = 10; // Enthält Field und Abstand |
|
- | 55 | PREVIEW_TAB_SIZE = PREVIEW_BLOCK_SIZE div 2; // 5 |
|
- | 56 | begin |
|
- | 57 | Image := PreviewImage; |
|
- | 58 | BackgroundColor := Self.Color; |
|
- | 59 | ||
- | 60 | LevelArray := nil; |
|
- | 61 | ||
- | 62 | ClearImage(Image, BackgroundColor); |
|
- | 63 | ||
- | 64 | LevelArray := Level.LevelStringToLevelArray(false); |
|
- | 65 | ||
- | 66 | for y := Low(LevelArray) to High(LevelArray) do |
|
- | 67 | begin |
|
- | 68 | for x := Low(LevelArray[y].Fields) to High(LevelArray[y].Fields) do |
|
- | 69 | begin |
|
- | 70 | t := LevelArray[y].Fields[x].Typ; |
|
- | 71 | indent := LevelArray[y].Indent; |
|
- | 72 | ||
- | 73 | case t of |
|
- | 74 | ftFullSpace: Image.Canvas.Brush.Color := BackgroundColor; |
|
- | 75 | ftEmpty: Image.Canvas.Brush.Color := clWhite; |
|
- | 76 | ftGreen: Image.Canvas.Brush.Color := clLime; |
|
- | 77 | ftYellow: Image.Canvas.Brush.Color := clYellow; |
|
- | 78 | ftRed: Image.Canvas.Brush.Color := clRed; |
|
- | 79 | end; |
|
- | 80 | ||
- | 81 | if LevelArray[y].Fields[x].Goal then |
|
- | 82 | Image.Canvas.Pen.Color := clBlack |
|
- | 83 | else |
|
- | 84 | Image.Canvas.Pen.Color := BackgroundColor; |
|
- | 85 | ||
- | 86 | Image.Canvas.Rectangle(x*PREVIEW_BLOCK_SIZE + indent*PREVIEW_TAB_SIZE, |
|
- | 87 | y*PREVIEW_BLOCK_SIZE, |
|
- | 88 | x*PREVIEW_BLOCK_SIZE + indent*PREVIEW_TAB_SIZE + PREVIEW_BLOCK_SIZE, |
|
- | 89 | y*PREVIEW_BLOCK_SIZE + PREVIEW_BLOCK_SIZE); |
|
- | 90 | end; |
|
- | 91 | end; |
|
- | 92 | end; |
|
45 | 93 | ||
46 | function TLevelChoice.SelectedLevel: string; |
94 | function TLevelChoice.SelectedLevel: string; |
47 | begin |
95 | begin |
48 | result := Format(LVL_FILE, [LevelList.Selected.Caption]); |
96 | result := Format(LVL_FILE, [LevelList.Selected.Caption]); |
49 | end; |
97 | end; |
Line 91... | Line 139... | ||
91 | if Assigned(LevelList.Selected) then |
139 | if Assigned(LevelList.Selected) then |
92 | begin |
140 | begin |
93 | LevelFile := Format(LVL_FILE, [LevelList.Selected.Caption]); |
141 | LevelFile := Format(LVL_FILE, [LevelList.Selected.Caption]); |
94 | Level := TLevel.Create(LevelFile); |
142 | Level := TLevel.Create(LevelFile); |
95 | try |
143 | try |
96 | DrawLevelPreview(Level, PreviewImage, Color); |
144 | DrawLevelPreview(Level); |
97 | finally |
145 | finally |
98 | FreeAndNil(Level); |
146 | FreeAndNil(Level); |
99 | end; |
147 | end; |
100 | end |
148 | end |
101 | else |
149 | else |
Line 142... | Line 190... | ||
142 | until FindNext(s) <> 0; |
190 | until FindNext(s) <> 0; |
143 | FindClose(s); |
191 | FindClose(s); |
144 | end; |
192 | end; |
145 | end; |
193 | end; |
146 | 194 | ||
147 | procedure TLevelChoice.FormResize(Sender: TObject); |
- | |
148 | var |
- | |
149 | p: integer; |
- | |
150 | begin |
- | |
151 | // WIDTH |
- | |
152 | p := ClientWidth - 3*LevelGrp.Left; // 100% useable |
- | |
153 | LevelGrp.Width := Round((1-MET_PREVIEW_SIZE_RATIO) * p); |
- | |
154 | PreviewGrp.Width := Round(MET_PREVIEW_SIZE_RATIO * p); |
- | |
155 | PreviewGrp.Left := 2*LevelGrp.Left + LevelGrp.Width; |
- | |
156 | LevelList.Width := LevelGrp.Width - 2*LevelList.Left; |
- | |
157 | PreviewImage.Width := PreviewGrp.Width - 2*PreviewImage.Left; |
- | |
158 | PlayBtn.Left := (LevelGrp.Left + LevelGrp.Width) - PlayBtn.Width; |
- | |
159 | - | ||
160 | // HEIGHT |
- | |
161 | LevelGrp.Height := ClientHeight - 3*LevelGrp.Top - PlayBtn.Height; |
- | |
162 | PreviewGrp.Height := LevelGrp.Height; |
- | |
163 | PlayBtn.Top := 2*LevelGrp.Top + LevelGrp.Height; |
- | |
164 | CancelBtn.Top := PlayBtn.Top; |
- | |
165 | LevelList.Height := LevelGrp.Height - 2*LevelList.Top; |
- | |
166 | PreviewImage.Height := PreviewGrp.Height - 2*PreviewImage.Top; |
- | |
167 | - | ||
168 | // TODO: Icons rearrangieren |
- | |
169 | end; |
- | |
170 | - | ||
171 | procedure TLevelChoice.FormCreate(Sender: TObject); |
195 | procedure TLevelChoice.FormCreate(Sender: TObject); |
172 | begin |
196 | begin |
173 | if not ForceDirectories(ExtractFilePath(Application.ExeName) + LVL_PATH) then |
197 | if not ForceDirectories(ExtractFilePath(Application.ExeName) + LVL_PATH) then |
174 | begin |
198 | begin |
175 | MessageDlg(Format(LNG_COULD_NOT_CREATE_DIR, [LVL_PATH]), mtError, [mbOK], 0); |
199 | MessageDlg(Format(LNG_COULD_NOT_CREATE_DIR, [LVL_PATH]), mtError, [mbOK], 0); |