-
Notifications
You must be signed in to change notification settings - Fork 1
/
ueditor.pas
156 lines (136 loc) · 4.61 KB
/
ueditor.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
unit ueditor;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
Grids, Buttons, StdCtrls, Spin, ugameutils;
type
{ TEditorForm }
TEditorForm = class(TForm)
ClearBitBtn: TBitBtn;
OpenDialog1: TOpenDialog;
SaveBitBtn: TBitBtn;
SaveAsBitBtn: TBitBtn;
OpenBitBtn: TBitBtn;
CloseBitBtn: TBitBtn;
GroupBox1: TGroupBox;
GroupBox2: TPanel;
HeightSpinEdit: TSpinEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
SaveDialog1: TSaveDialog;
SkladDrawGrid: TDrawGrid;
Panel1: TPanel;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton4: TSpeedButton;
SpeedButton5: TSpeedButton;
SpeedButton6: TSpeedButton;
LevelNumSpinEdit: TSpinEdit;
WidthSpinEdit: TSpinEdit;
procedure ClearBitBtnClick(Sender: TObject);
procedure CloseBitBtnClick(Sender: TObject);
procedure OpenBitBtnClick(Sender: TObject);
procedure SaveAsBitBtnClick(Sender: TObject);
procedure SaveBitBtnClick(Sender: TObject);
procedure SkladDrawGridDrawCell(Sender: TObject; aCol, aRow: Integer;
aRect: TRect; aState: TGridDrawState);
procedure SkladDrawGridSelectCell(Sender: TObject; aCol, aRow: Integer;
var CanSelect: Boolean);
procedure SpeedButton1Click(Sender: TObject);
procedure WidthSpinEditChange(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
EditorForm: TEditorForm;
CellData : Char; //символ для встановлення в матрицю рівня
implementation
uses umain, ulogger;
{$R *.lfm}
{ TEditorForm }
procedure TEditorForm.ClearBitBtnClick(Sender: TObject);
var x,y : Integer;
begin
//заповнюємо динамічний масив пробілами (підлога)
for x:=0 to High(Sklad) do
for y:=0 to High(Sklad[x]) do Sklad[x,y]:=' ';
SkladDrawGrid.Repaint; //перемальовуємо ігрове поле
end;
procedure TEditorForm.CloseBitBtnClick(Sender: TObject);
begin
Close;
end;
procedure TEditorForm.OpenBitBtnClick(Sender: TObject);
begin
if OpenDialog1.Execute then begin
LoadLevel(OpenDialog1.FileName,Sklad);
SkladDrawGrid.ColCount:=High(Sklad[0])+1; //стовбці
SkladDrawGrid.RowCount:=High(Sklad)+1; //рядки
WidthSpinEdit.Value:=EditorForm.SkladDrawGrid.ColCount-1;
HeightSpinEdit.Value:=EditorForm.SkladDrawGrid.RowCount-1;
//розміри форми підігнати під розміри рівня
Width:=(High(Sklad[0])+1)*EditorForm.SkladDrawGrid.DefaultColWidth+EditorForm.Panel1.Width+5;
Height:=(High(Sklad)+1)*EditorForm.SkladDrawGrid.DefaultRowHeight+5;
end;
end;
procedure TEditorForm.SaveAsBitBtnClick(Sender: TObject);
begin
if SaveDialog1.Execute then begin
SaveLevel(SaveDialog1.FileName);
end;
end;
procedure TEditorForm.SaveBitBtnClick(Sender: TObject);
begin
SaveLevel(ProgramDirectory+DirectorySeparator+'data'+DirectorySeparator+LevelNumSpinEdit.Text+'.xsb');
end;
procedure TEditorForm.SkladDrawGridDrawCell(Sender: TObject; aCol, aRow: Integer;
aRect: TRect; aState: TGridDrawState);
begin
{$I drawsklad.inc}
end;
procedure TEditorForm.SkladDrawGridSelectCell(Sender: TObject; aCol,
aRow: Integer; var CanSelect: Boolean);
begin
if CurrSymbol='' then Exit;
if CurrSymbol='@' then begin
Player.x:=aCol;
Player.y:=aRow;
if Sklad[aRow,aCol]='.' then Sklad[aRow,aCol]:='+'
else Sklad[aRow,aCol]:=CurrSymbol[1];
end else Sklad[aRow,aCol]:=CurrSymbol[1];
SkladDrawGrid.Repaint;
end;
procedure TEditorForm.SpeedButton1Click(Sender: TObject);
begin
case CurrSymbol of
'$':SpeedButton1.Down:=false;
' ':SpeedButton2.Down:=false;
'*':SpeedButton3.Down:=false;
'@':SpeedButton4.Down:=false;
'#':SpeedButton5.Down:=false;
'.':SpeedButton6.Down:=false;
end;
CurrSymbol:=(Sender as TSpeedButton).Hint;
(Sender as TSpeedbutton).Down:=true;
end;
procedure TEditorForm.WidthSpinEditChange(Sender: TObject);
begin
CanDraw:=false;
Case (Sender as TSpinEdit).Tag of
1:ChangeMatrixWidth((Sender as TSpinEdit).Value); //ширина
2:ChangeMatrixHeight((Sender as TSpinEdit).Value); //висота
end;
SkladDrawGrid.ColCount:=High(Sklad[0])+1; //стовбці
SkladDrawGrid.RowCount:=High(Sklad)+1; //рядки
//розміри форми підігнати під розміри рівня
Width:=SkladDrawGrid.ColCount*SkladDrawGrid.DefaultColWidth+Panel1.Width+5;
Height:=SkladDrawGrid.RowCount*SkladDrawGrid.DefaultRowHeight+5;
CanDraw:=true;
SkladDrawGrid.Repaint;//перемальовуємо поле редактора
end;
end.