📄 main.pas
字号:
unit Main;
{****************************************************************************
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS"
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific language governing rights and limitations
under the License.
The Original Code is IsoEditMdi.
The Initial Developer of the Original Code is Crystal Software (Canada) Inc.
and Chris Bruner. Portions created by Chris Bruner are Copyright
(C) Crystal Software (Canada) Inc. All Rights Reserved.
Contributor(s): Chris Bruner of Crystal Software (Canada) Inc.
(sign your name here)
******************************************************************************}
interface
uses Windows, SysUtils, Classes, Graphics, Forms, Controls, Menus,
StdCtrls, Dialogs, Buttons, Messages, ExtCtrls, ComCtrls, StdActns,
ActnList, ToolWin, ImgList,IsoEngine,DXIsoengine,inifiles, DXClass,util,childwin,
DXDraws;
type
TMainForm = class(TForm)
MainMenu1: TMainMenu;
File1: TMenuItem;
FileNewItem: TMenuItem;
FileOpenItem: TMenuItem;
FileCloseItem: TMenuItem;
Window1: TMenuItem;
Help1: TMenuItem;
N1: TMenuItem;
FileExitItem: TMenuItem;
WindowCascadeItem: TMenuItem;
WindowTileItem: TMenuItem;
WindowArrangeItem: TMenuItem;
HelpAboutItem: TMenuItem;
OpenDialog: TOpenDialog;
FileSaveItem: TMenuItem;
FileSaveAsItem: TMenuItem;
Edit1: TMenuItem;
WindowMinimizeItem: TMenuItem;
StatusBar: TStatusBar;
ActionList1: TActionList;
EditCut1: TEditCut;
EditCopy1: TEditCopy;
EditPaste1: TEditPaste;
FileNew1: TAction;
FileSave1: TAction;
FileExit1: TAction;
FileOpen1: TAction;
FileSaveAs1: TAction;
WindowCascade1: TWindowCascade;
WindowTileHorizontal1: TWindowTileHorizontal;
WindowArrangeAll1: TWindowArrange;
WindowMinimizeAll1: TWindowMinimizeAll;
HelpAbout1: TAction;
FileClose1: TWindowClose;
WindowTileVertical1: TWindowTileVertical;
WindowTileItem2: TMenuItem;
ToolBar2: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
ToolButton4: TToolButton;
ToolButton5: TToolButton;
ToolButton6: TToolButton;
ToolButton9: TToolButton;
ToolButton7: TToolButton;
ToolButton8: TToolButton;
ToolButton10: TToolButton;
ToolButton11: TToolButton;
ImageList1: TImageList;
ToolButton12: TToolButton;
ToolButton13: TToolButton;
View1: TMenuItem;
OverView1: TMenuItem;
OpenImageList: TOpenDialog;
DXTimer1: TDXTimer;
opendialogmap: TOpenDialog;
OpenDialog1: TOpenDialog;
OpenDialog2: TOpenDialog;
OpenDialog3: TOpenDialog;
OpenDialog4: TOpenDialog;
Images1: TMenuItem;
SaveDialog1: TSaveDialog;
Draw: TToolButton;
SelSame: TToolButton;
Movexy: TToolButton;
MoveXZ: TToolButton;
EyeDropper: TToolButton;
Fill: TToolButton;
GridOnOff: TToolButton;
Select: TToolButton;
ToolButton16: TToolButton;
Layers1: TMenuItem;
ToolButton15: TToolButton;
ToolButton17: TToolButton;
ToolButton18: TToolButton;
Erase: TToolButton;
ToolButton14: TToolButton;
N3: TMenuItem;
Diagnostics1: TMenuItem;
Options1: TMenuItem;
LoadProjectOnStartup1: TMenuItem;
BlockUndoRedo1: TMenuItem;
History1: TMenuItem;
H11: TMenuItem;
H21: TMenuItem;
H31: TMenuItem;
H41: TMenuItem;
H51: TMenuItem;
H61: TMenuItem;
H71: TMenuItem;
H81: TMenuItem;
H91: TMenuItem;
h101: TMenuItem;
H01: TMenuItem;
ToolButton19: TToolButton;
N2: TMenuItem;
DirectXOptions1: TMenuItem;
FullScreen1: TMenuItem;
NoWindowChange1: TMenuItem;
AllowReboot1: TMenuItem;
WaitVBlank1: TMenuItem;
AllowPalett2561: TMenuItem;
SystemMemory1: TMenuItem;
Stretch1: TMenuItem;
Center1: TMenuItem;
Flip1: TMenuItem;
N3D1: TMenuItem;
DirectX7Mode1: TMenuItem;
RetainedMode1: TMenuItem;
Hardware1: TMenuItem;
Select1: TMenuItem;
ZBuffer1: TMenuItem;
procedure FileNew1Execute(Sender: TObject);
procedure FileOpen1Execute(Sender: TObject);
procedure HelpAbout1Execute(Sender: TObject);
procedure FileExit1Execute(Sender: TObject);
procedure ToolButton13Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure OverView1Click(Sender: TObject);
procedure LoadTileList1Click(Sender: TObject);
procedure DXTimer1Timer(Sender: TObject; LagCount: Integer);
procedure LoadOldMaps1Click(Sender: TObject);
procedure Images1Click(Sender: TObject);
procedure FileSaveItemClick(Sender: TObject);
procedure FileSaveAsItemClick(Sender: TObject);
procedure GridOnOffClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ToolButton16Click(Sender: TObject);
procedure Layers1Click(Sender: TObject);
procedure ToolButton15Click(Sender: TObject);
procedure Diagnostics1Click(Sender: TObject);
procedure LoadProjectOnStartup1Click(Sender: TObject);
procedure BlockUndoRedo1Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure HistoryClick(Sender: TObject);
procedure ToolButton19Click(Sender: TObject);
procedure SetDirectXOptions(Sender: TObject);
private
HeartBeat : Integer;
Loaded : Boolean;
FActiveChild : TMDIChild;
{ Private declarations }
procedure CreateMDIChild(const Name: string);
procedure LoadTiles(FileName : string);
procedure SetCoord(const Value: string);
procedure SetModified(const Value: Boolean);
procedure SetTilesLoaded(const Value: Boolean);
procedure SetOverViewOK(const Value: Boolean);
procedure SetActiveChild(const Value: TMDIChild);
procedure ReviseHistory(NewestProject : string);
public
AllowDrawing : Boolean;
InTimer : Boolean;
function GetDXOptions : TDXDrawOptions;
{ Public declarations }
property Modified : Boolean Write SetModified;
property StatusCoord : string Write SetCoord;
property TilesLoaded : Boolean Write SetTilesLoaded;
property OverViewOk : Boolean Write SetOverViewOK;
// property ActiveIso : TDXIsoMap read FActiveIso;
property ActiveChild : TMDIChild read FActiveChild Write SetActiveChild;
end;
var
g : Integer;
MainForm: TMainForm;
implementation
{$R *.DFM}
uses {ChildWin, }About, overview, imageinfo, diag, layerunit;
procedure TMainForm.CreateMDIChild(const Name: string);
var
i : integer;
Child: TMDIChild;
begin
{ create a new MDI child window }
ActiveChild := nil;
Child := TMDIChild.Create(Application);
Child.Width := 290;
Child.Height := 237;
Child.OK.Left := 192;
Child.OK.Top := 170;
Child.BitBtn2.Left := 59;
Child.BitBtn2.Top := 170;
Child.Caption := Name;
if FileExists(Name) then
begin
Child.IsoMap.LoadFromFile(Name);
Child.MapWidth.Text := IntToStr(Child.IsoMap.MapWidth);
Child.MapHeight.Text := IntToStr(Child.IsoMap.MapHeight);
Child.CellWidth.Text := IntToStr(Child.IsoMap.CellWidth);
Child.CellHeight.Text := IntToStr(Child.IsoMap.CellHeight);
Child.MapName := Child.IsoMap.MapName;
Child.Named := True;
Images.IG.RowCount := Child.IsoMap.FImageList.Items.Count + 1;
layers.LG.RowCount := Child.IsoMap.FIsoMap.LayerCount+1;
for i := 0 to layers.lg.rowcount+2 do
layers.LG.cells[0,i] := 'Y';
end
else
begin
Child.MapName := Name;
Child.Named := False;
end;
ActiveChild := Child;
end;
procedure TMainForm.FileNew1Execute(Sender: TObject);
begin { DONE : Add Code to select a tileset when creating a new map }
CreateMDIChild('NONAME' + IntToStr(MDIChildCount + 1));
FileSaveAsItem.enabled := true;
end;
procedure TMainForm.FileOpen1Execute(Sender: TObject);
begin
if OpenDialog.Execute then
begin
CreateMDIChild(OpenDialog.FileName);
ReviseHistory(OpenDialog.FileName);
SaveDialog1.filename := opendialog.filename;
FileSaveAsItem.enabled := true;
FileSaveItem.Enabled := true;
end;
end;
procedure TMainForm.HelpAbout1Execute(Sender: TObject);
begin
AboutBox.ShowModal;
end;
procedure TMainForm.FileExit1Execute(Sender: TObject);
begin
Close;
end;
procedure TMainForm.ToolButton13Click(Sender: TObject);
begin
if (ActiveChild<>nil) and (Activechild.IsoMap<>nil) then
begin
Activechild.IsoMap.DrawIsoMap;
if (_OverView<> nil) then
begin
if OverView1.Enabled then
begin
OverView1.Checked := True;
_OverView.Show;
end;
end;
end;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
_OverView := nil;
Loaded := False; // if the last project that we were working on is currently loaded
AllowDrawing := True;
end;
procedure TMainForm.OverView1Click(Sender: TObject);
begin
if (ActiveChild=nil) or (Activechild.IsoMap = nil) then
begin
OverView1.Checked := False;
OverView1.Enabled := False;
end
else
OverView1.Checked := not OverView1.Checked;
if (OverView1.Checked) then _OverView.Show
else _OverView.Hide;
end;
procedure TMainform.LoadTiles(FileName : string);
var f : TFileStream;
begin
f := TFileStream.Create(FileName,fmOpenRead);
try
Activechild.IsoMap.LoadImageListFromStream(f);
Images.IG.RowCount := Activechild.IsoMap.FImageList.Items.Count + 1;
TilesLoaded := True;
finally
f.free;
end
end;
procedure TMainForm.LoadTileList1Click(Sender: TObject);
var IniFile : TIniFile;
begin
if (ActiveChild <> nil) and (Activechild.IsoMap <>NIL) then
begin
IniFile := GetIniFile;
openImageList.filename := IniFile.ReadString('Defaults','ImagePath',openImageList.filename);
IniFile.Free;
if (OpenImageList.Execute) then
begin
IniFile := GetInifile;
IniFile.WriteString('Defaults','ImagePath',openImageLIst.filename);
IniFile.WriteString('Defaults','LastLoaded','ImagePath');
IniFile.Free; // we will be probably storing other stuff eventually but this will start us off
Loadtiles(OpenImageList.FileName);
end;
end;
end;
procedure TMainForm.DXTimer1Timer(Sender: TObject; LagCount: Integer);
begin
if (InTimer) then Exit;
InTimer := True;
try
diagnostics.AddDiagnostic('Enter Timer');
dec(Heartbeat);
if (Heartbeat<0) then
begin
Heartbeat := 1;
if (ActiveChild <> nil) and (Activechild.IsoMap<>nil) and (_OverView <> nil) then
begin
if (_OverView.Visible) then
begin
diagnostics.AddDiagnostic('Enter Overview paint');
if (_OverView.Visible) then
_OverView.Paint;
diagnostics.AddDiagnostic('Exit Overview paint');
end;
diagnostics.AddDiagnostic('Enter DrawIsoMap');
if (AllowDrawing and ActiveChild.Isomap.visible) then
Activechild.IsoMap.DrawIsoMap;
diagnostics.AddDiagnostic('Exit DrawIsoMap');
end;
end;
finally
diagnostics.AddDiagnostic('Exit Timer');
Intimer := False;
end;
end;
procedure TMainForm.LoadOldMaps1Click(Sender: TObject);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -