- Changed profile, preset, locations and radar cache path to the user directory (fixes #50)
This commit is contained in:
parent
1759e0763c
commit
3df7b446f5
|
@ -31,6 +31,7 @@ uses
|
|||
{$IFDEF UNIX}{$IFDEF UseCThreads}
|
||||
cthreads,
|
||||
{$ENDIF}{$ENDIF}
|
||||
SysUtils,
|
||||
Interfaces, // this includes the LCL widgetset
|
||||
Forms, LResources, lnetvisual, LazOpenGLContext, UdmNetwork, UfrmMain,
|
||||
UfrmLogin, UfrmInitialize, UfrmAccountControl, virtualtreeview_package,
|
||||
|
@ -45,8 +46,14 @@ uses
|
|||
|
||||
{$IFDEF WINDOWS}{$R CentrED.rc}{$ENDIF}
|
||||
|
||||
function GetApplicationName: String;
|
||||
begin
|
||||
Result := 'CentrED';
|
||||
end;
|
||||
|
||||
begin
|
||||
{$I CentrED.lrs}
|
||||
OnGetApplicationName := @GetApplicationName;
|
||||
Application.Initialize;
|
||||
Application.CreateForm(TdmNetwork, dmNetwork);
|
||||
Application.Run;
|
||||
|
|
|
@ -22,8 +22,8 @@ object frmLogin: TfrmLogin
|
|||
AnchorSideBottom.Control = Owner
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 0
|
||||
Height = 15
|
||||
Top = 231
|
||||
Height = 16
|
||||
Top = 230
|
||||
Width = 481
|
||||
Alignment = taCenter
|
||||
Anchors = [akLeft, akRight, akBottom]
|
||||
|
|
|
@ -172,8 +172,7 @@ begin
|
|||
lblCopyright.Caption := Format('UO CentrED Client Version %s (c) %s',
|
||||
[ProductVersion, Copyright]);
|
||||
|
||||
FProfilePath := IncludeTrailingPathDelimiter(ExtractFilePath(Application.ExeName))
|
||||
+ 'Profiles' + PathDelim;
|
||||
FProfilePath := GetAppConfigDir(False) + 'Profiles' + PathDelim;
|
||||
ForceDirectories(FProfilePath);
|
||||
if FindFirst(FProfilePath + '*.ini', faAnyFile, searchRec) = 0 then
|
||||
begin
|
||||
|
|
|
@ -275,6 +275,7 @@ type
|
|||
protected
|
||||
{ Members }
|
||||
FAppDir: String;
|
||||
FConfigDir: String;
|
||||
FX: Integer;
|
||||
FY: Integer;
|
||||
FDrawDistance: Integer;
|
||||
|
@ -821,6 +822,8 @@ var
|
|||
searchRec: TSearchRec;
|
||||
begin
|
||||
FAppDir := IncludeTrailingPathDelimiter(ExtractFilePath(Application.ExeName));
|
||||
FConfigDir := GetAppConfigDir(False);
|
||||
ForceDirectories(FConfigDir);
|
||||
|
||||
FLandscape := ResMan.Landscape;
|
||||
FLandscape.OnChange := @OnLandscapeChanged;
|
||||
|
@ -850,7 +853,7 @@ begin
|
|||
vstChat.NodeDataSize := SizeOf(TChatInfo);
|
||||
pnlChatHeader.AnchorSide[akBottom].Control := pnlBottom;
|
||||
|
||||
FLocationsFile := FAppDir + 'Locations.dat';
|
||||
FLocationsFile := FConfigDir + 'Locations.dat';
|
||||
vstLocations.NodeDataSize := SizeOf(TLocationInfo);
|
||||
try
|
||||
if FileExists(FLocationsFile) then
|
||||
|
@ -879,7 +882,7 @@ begin
|
|||
FVirtualTiles := TWorldItemList.Create(True);
|
||||
FUndoList := TPacketList.Create(True);
|
||||
|
||||
FRandomPresetLocation := FAppDir + 'RandomPresets' + PathDelim;
|
||||
FRandomPresetLocation := FConfigDir + 'RandomPresets' + PathDelim;
|
||||
if not DirectoryExists(FRandomPresetLocation) then
|
||||
CreateDir(FRandomPresetLocation);
|
||||
|
||||
|
|
|
@ -1,54 +1,60 @@
|
|||
object frmRadarMap: TfrmRadarMap
|
||||
Left = 290
|
||||
Height = 360
|
||||
Top = 171
|
||||
Width = 479
|
||||
HorzScrollBar.Page = 478
|
||||
VertScrollBar.Page = 359
|
||||
Caption = 'Radar Map (1:8)'
|
||||
ClientHeight = 360
|
||||
ClientWidth = 479
|
||||
OnClose = FormClose
|
||||
OnCreate = FormCreate
|
||||
OnDestroy = FormDestroy
|
||||
OnResize = FormResize
|
||||
Position = poOwnerFormCenter
|
||||
ShowInTaskBar = stAlways
|
||||
object pnlBottom: TPanel
|
||||
Height = 21
|
||||
Top = 339
|
||||
Width = 479
|
||||
Align = alBottom
|
||||
BevelOuter = bvNone
|
||||
ClientHeight = 21
|
||||
ClientWidth = 479
|
||||
TabOrder = 0
|
||||
object lblPosition: TLabel
|
||||
Left = 8
|
||||
Height = 21
|
||||
Width = 38
|
||||
Align = alLeft
|
||||
BorderSpacing.Left = 8
|
||||
Layout = tlCenter
|
||||
ParentColor = False
|
||||
end
|
||||
end
|
||||
object sbMain: TScrollBox
|
||||
Height = 339
|
||||
Width = 479
|
||||
HorzScrollBar.Page = 474
|
||||
HorzScrollBar.Range = 292
|
||||
VertScrollBar.Page = 334
|
||||
VertScrollBar.Range = 202
|
||||
Align = alClient
|
||||
TabOrder = 1
|
||||
object pbRadar: TPaintBox
|
||||
Height = 202
|
||||
Width = 292
|
||||
OnMouseDown = pbRadarMouseDown
|
||||
OnMouseMove = pbRadarMouseMove
|
||||
OnMouseLeave = pbRadarMouseLeave
|
||||
OnPaint = pbRadarPaint
|
||||
end
|
||||
end
|
||||
end
|
||||
object frmRadarMap: TfrmRadarMap
|
||||
Left = 290
|
||||
Height = 360
|
||||
Top = 171
|
||||
Width = 479
|
||||
HorzScrollBar.Page = 478
|
||||
VertScrollBar.Page = 359
|
||||
ActiveControl = sbMain
|
||||
Caption = 'Radar Map (1:8)'
|
||||
ClientHeight = 360
|
||||
ClientWidth = 479
|
||||
OnClose = FormClose
|
||||
OnCreate = FormCreate
|
||||
OnDestroy = FormDestroy
|
||||
OnResize = FormResize
|
||||
Position = poOwnerFormCenter
|
||||
ShowInTaskBar = stAlways
|
||||
LCLVersion = '0.9.29'
|
||||
object pnlBottom: TPanel
|
||||
Left = 0
|
||||
Height = 21
|
||||
Top = 339
|
||||
Width = 479
|
||||
Align = alBottom
|
||||
BevelOuter = bvNone
|
||||
ClientHeight = 21
|
||||
ClientWidth = 479
|
||||
TabOrder = 0
|
||||
object lblPosition: TLabel
|
||||
Left = 8
|
||||
Height = 21
|
||||
Top = 0
|
||||
Width = 39
|
||||
Align = alLeft
|
||||
BorderSpacing.Left = 8
|
||||
Layout = tlCenter
|
||||
ParentColor = False
|
||||
end
|
||||
end
|
||||
object sbMain: TScrollBox
|
||||
Left = 0
|
||||
Height = 339
|
||||
Top = 0
|
||||
Width = 479
|
||||
Align = alClient
|
||||
ClientHeight = 335
|
||||
ClientWidth = 475
|
||||
TabOrder = 1
|
||||
object pbRadar: TPaintBox
|
||||
Left = 0
|
||||
Height = 202
|
||||
Top = 0
|
||||
Width = 292
|
||||
OnMouseDown = pbRadarMouseDown
|
||||
OnMouseMove = pbRadarMouseMove
|
||||
OnMouseLeave = pbRadarMouseLeave
|
||||
OnPaint = pbRadarPaint
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,246 +1,245 @@
|
|||
(*
|
||||
* CDDL HEADER START
|
||||
*
|
||||
* The contents of this file are subject to the terms of the
|
||||
* Common Development and Distribution License, Version 1.0 only
|
||||
* (the "License"). You may not use this file except in compliance
|
||||
* with the License.
|
||||
*
|
||||
* You can obtain a copy of the license at
|
||||
* http://www.opensource.org/licenses/cddl1.php.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
*
|
||||
* When distributing Covered Code, include this CDDL HEADER in each
|
||||
* file and include the License file at
|
||||
* http://www.opensource.org/licenses/cddl1.php. If applicable,
|
||||
* add the following below this CDDL HEADER, with the fields enclosed
|
||||
* by brackets "[]" replaced with your own identifying * information:
|
||||
* Portions Copyright [yyyy] [name of copyright owner]
|
||||
*
|
||||
* CDDL HEADER END
|
||||
*
|
||||
*
|
||||
* Portions Copyright 2007 Andreas Schneider
|
||||
*)
|
||||
unit UfrmRadar;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls,
|
||||
ImagingClasses, ImagingComponents, ImagingTypes, UEnhancedMemoryStream, crc,
|
||||
StdCtrls;
|
||||
|
||||
type
|
||||
|
||||
TRadarColorMap = array of Word;
|
||||
|
||||
{ TfrmRadarMap }
|
||||
|
||||
TfrmRadarMap = class(TForm)
|
||||
lblPosition: TLabel;
|
||||
pbRadar: TPaintBox;
|
||||
pnlBottom: TPanel;
|
||||
sbMain: TScrollBox;
|
||||
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure FormDestroy(Sender: TObject);
|
||||
procedure FormResize(Sender: TObject);
|
||||
procedure pbRadarMouseDown(Sender: TObject; Button: TMouseButton;
|
||||
Shift: TShiftState; X, Y: Integer);
|
||||
procedure pbRadarMouseLeave(Sender: TObject);
|
||||
procedure pbRadarMouseMove(Sender: TObject; Shift: TShiftState; X,
|
||||
Y: Integer);
|
||||
procedure pbRadarPaint(Sender: TObject);
|
||||
protected
|
||||
FRadar: TSingleImage;
|
||||
FRadarDependencies: TList;
|
||||
procedure OnRadarHandlingPacket(ABuffer: TEnhancedMemoryStream);
|
||||
procedure RefreshRadar(ARadarMap: TRadarColorMap);
|
||||
procedure RepaintRadar;
|
||||
public
|
||||
property Radar: TSingleImage read FRadar;
|
||||
property Dependencies: TList read FRadarDependencies;
|
||||
end;
|
||||
|
||||
var
|
||||
frmRadarMap: TfrmRadarMap;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
UdmNetwork, UGameResources, UPacketHandlers, UPackets, UfrmInitialize,
|
||||
UfrmMain, UGraphicHelper;
|
||||
|
||||
{ TfrmRadarMap }
|
||||
|
||||
procedure TfrmRadarMap.FormCreate(Sender: TObject);
|
||||
begin
|
||||
FRadar := TSingleImage.CreateFromParams(ResMan.Landscape.Width,
|
||||
ResMan.Landscape.Height, ifA8R8G8B8);
|
||||
pbRadar.Width := FRadar.Width;
|
||||
pbRadar.Height := FRadar.Height;
|
||||
sbMain.ClientWidth := FRadar.Width;
|
||||
sbMain.ClientHeight := FRadar.Height;
|
||||
ClientWidth := sbMain.Width + sbMain.VertScrollBar.Size;
|
||||
ClientHeight := sbMain.Height + sbMain.HorzScrollBar.Size + pnlBottom.Height;
|
||||
Constraints.MaxWidth := Width;
|
||||
Constraints.MaxHeight := Height;
|
||||
|
||||
FRadarDependencies := TList.Create;
|
||||
|
||||
RegisterPacketHandler($0D, TPacketHandler.Create(0, @OnRadarHandlingPacket));
|
||||
|
||||
dmNetwork.Send(TRequestRadarChecksumPacket.Create);
|
||||
end;
|
||||
|
||||
procedure TfrmRadarMap.FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
||||
begin
|
||||
CloseAction := caHide;
|
||||
end;
|
||||
|
||||
procedure TfrmRadarMap.FormDestroy(Sender: TObject);
|
||||
var
|
||||
radarMap: TRadarColorMap;
|
||||
x, y: Integer;
|
||||
radarMapFile: TFileStream;
|
||||
begin
|
||||
RegisterPacketHandler($0D, nil);
|
||||
|
||||
SetLength(radarMap, FRadar.Width * FRadar.Height);
|
||||
for x := 0 to FRadar.Width - 1 do
|
||||
for y := 0 to FRadar.Height - 1 do
|
||||
radarMap[x * FRadar.Height + y] := EncodeUOColor(PInteger(FRadar.PixelPointers[x, y])^);
|
||||
|
||||
radarMapFile := TFileStream.Create(IncludeTrailingPathDelimiter(
|
||||
ExtractFilePath(Application.ExeName)) + 'RadarMap.cache', fmCreate);
|
||||
radarMapFile.Write(radarMap[0], Length(radarMap) * SizeOf(Word));
|
||||
radarMapFile.Free;
|
||||
|
||||
if FRadarDependencies <> nil then FreeAndNil(FRadarDependencies);
|
||||
if FRadar <> nil then FreeAndNil(FRadar);
|
||||
end;
|
||||
|
||||
procedure TfrmRadarMap.FormResize(Sender: TObject);
|
||||
begin
|
||||
sbMain.AutoScroll := (Width < Constraints.MaxWidth) or (Height < Constraints.MaxHeight);
|
||||
end;
|
||||
|
||||
procedure TfrmRadarMap.pbRadarMouseDown(Sender: TObject; Button: TMouseButton;
|
||||
Shift: TShiftState; X, Y: Integer);
|
||||
begin
|
||||
frmMain.SetPos(X * 8, Y * 8);
|
||||
end;
|
||||
|
||||
procedure TfrmRadarMap.pbRadarMouseLeave(Sender: TObject);
|
||||
begin
|
||||
lblPosition.Caption := '';
|
||||
end;
|
||||
|
||||
procedure TfrmRadarMap.pbRadarMouseMove(Sender: TObject; Shift: TShiftState; X,
|
||||
Y: Integer);
|
||||
begin
|
||||
lblPosition.Caption := Format('X: %d, Y: %d', [X * 8, Y * 8]);
|
||||
end;
|
||||
|
||||
procedure TfrmRadarMap.pbRadarPaint(Sender: TObject);
|
||||
var
|
||||
posX, posY: Word;
|
||||
begin
|
||||
DisplayImage(pbRadar.Canvas, 0, 0, FRadar);
|
||||
posX := frmMain.X div 8;
|
||||
posY := frmMain.Y div 8;
|
||||
pbRadar.Canvas.Pen.Color := clBlack;
|
||||
pbRadar.Canvas.Pen.Style := psSolid;
|
||||
pbRadar.Canvas.Brush.Color := clRed;
|
||||
pbRadar.Canvas.Brush.Style := bsSolid;
|
||||
pbRadar.Canvas.Ellipse(posX - 3, posY - 3, posX + 3, posY + 3);
|
||||
{pbRadar.Canvas.Pen.Color := clRed;
|
||||
pbRadar.Canvas.Pen.Style := psDash;
|
||||
pbRadar.Canvas.Line(0, posY, pbRadar.Width, posY);
|
||||
pbRadar.Canvas.Line(posX, 0, posX, pbRadar.Height);}
|
||||
end;
|
||||
|
||||
procedure TfrmRadarMap.OnRadarHandlingPacket(ABuffer: TEnhancedMemoryStream);
|
||||
var
|
||||
subID: Byte;
|
||||
checksum, realChecksum: Cardinal;
|
||||
radarMapFile: TFileStream;
|
||||
radarMapFileName: string;
|
||||
radarMap: TRadarColorMap;
|
||||
x, y: Integer;
|
||||
begin
|
||||
subID := ABuffer.ReadByte;
|
||||
case subID of
|
||||
$01: //checksum
|
||||
begin
|
||||
checksum := ABuffer.ReadCardinal;
|
||||
realChecksum := crc32(0, nil, 0);
|
||||
radarMapFileName := IncludeTrailingPathDelimiter(ExtractFilePath(
|
||||
Application.ExeName)) + 'RadarMap.cache';
|
||||
if FileExists(radarMapFileName) then
|
||||
begin
|
||||
radarMapFile := TFileStream.Create(radarMapFileName, fmOpenRead);
|
||||
SetLength(radarMap, radarMapFile.Size div SizeOf(Word));
|
||||
radarMapFile.Read(radarMap[0], radarMapFile.Size);
|
||||
radarMapFile.Free;
|
||||
|
||||
realChecksum := crc32(realChecksum, @radarMap[0], Length(radarMap) * SizeOf(Word));
|
||||
end;
|
||||
|
||||
if checksum <> realChecksum then
|
||||
begin
|
||||
frmInitialize.lblStatus.Caption := 'Updating Radar Map';
|
||||
frmInitialize.Show;
|
||||
frmInitialize.SetModal;
|
||||
//frmMain.Enabled := False;
|
||||
dmNetwork.Send(TRequestRadarMapPacket.Create);
|
||||
end else
|
||||
RefreshRadar(radarMap);
|
||||
end;
|
||||
$02: //radar map
|
||||
begin
|
||||
SetLength(radarMap, (ABuffer.Size - ABuffer.Position) div SizeOf(Word));
|
||||
ABuffer.Read(radarMap[0], Length(radarMap) * SizeOf(Word));
|
||||
RefreshRadar(radarMap);
|
||||
//frmMain.Enabled := True;
|
||||
frmInitialize.UnsetModal;
|
||||
frmInitialize.Hide;
|
||||
end;
|
||||
$03: //update radar
|
||||
begin
|
||||
x := ABuffer.ReadWord;
|
||||
y := ABuffer.ReadWord;
|
||||
PInteger(FRadar.PixelPointers[x, y])^ := DecodeUOColor(ABuffer.ReadWord);
|
||||
RepaintRadar;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TfrmRadarMap.RefreshRadar(ARadarMap: TRadarColorMap);
|
||||
var
|
||||
x, y: Integer;
|
||||
begin
|
||||
for x := 0 to FRadar.Width - 1 do
|
||||
for y := 0 to FRadar.Height - 1 do
|
||||
PInteger(FRadar.PixelPointers[x, y])^ := DecodeUOColor(ARadarMap[x * FRadar.Height + y]);
|
||||
RepaintRadar;
|
||||
end;
|
||||
|
||||
procedure TfrmRadarMap.RepaintRadar;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
pbRadar.Repaint;
|
||||
for i := 0 to FRadarDependencies.Count - 1 do
|
||||
TWinControl(FRadarDependencies.Items[i]).Repaint;
|
||||
end;
|
||||
|
||||
initialization
|
||||
{$I UfrmRadar.lrs}
|
||||
|
||||
end.
|
||||
|
||||
(*
|
||||
* CDDL HEADER START
|
||||
*
|
||||
* The contents of this file are subject to the terms of the
|
||||
* Common Development and Distribution License, Version 1.0 only
|
||||
* (the "License"). You may not use this file except in compliance
|
||||
* with the License.
|
||||
*
|
||||
* You can obtain a copy of the license at
|
||||
* http://www.opensource.org/licenses/cddl1.php.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
*
|
||||
* When distributing Covered Code, include this CDDL HEADER in each
|
||||
* file and include the License file at
|
||||
* http://www.opensource.org/licenses/cddl1.php. If applicable,
|
||||
* add the following below this CDDL HEADER, with the fields enclosed
|
||||
* by brackets "[]" replaced with your own identifying * information:
|
||||
* Portions Copyright [yyyy] [name of copyright owner]
|
||||
*
|
||||
* CDDL HEADER END
|
||||
*
|
||||
*
|
||||
* Portions Copyright 2009 Andreas Schneider
|
||||
*)
|
||||
unit UfrmRadar;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls,
|
||||
ImagingClasses, ImagingComponents, ImagingTypes, UEnhancedMemoryStream, crc,
|
||||
StdCtrls;
|
||||
|
||||
type
|
||||
|
||||
TRadarColorMap = array of Word;
|
||||
|
||||
{ TfrmRadarMap }
|
||||
|
||||
TfrmRadarMap = class(TForm)
|
||||
lblPosition: TLabel;
|
||||
pbRadar: TPaintBox;
|
||||
pnlBottom: TPanel;
|
||||
sbMain: TScrollBox;
|
||||
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure FormDestroy(Sender: TObject);
|
||||
procedure FormResize(Sender: TObject);
|
||||
procedure pbRadarMouseDown(Sender: TObject; Button: TMouseButton;
|
||||
Shift: TShiftState; X, Y: Integer);
|
||||
procedure pbRadarMouseLeave(Sender: TObject);
|
||||
procedure pbRadarMouseMove(Sender: TObject; Shift: TShiftState; X,
|
||||
Y: Integer);
|
||||
procedure pbRadarPaint(Sender: TObject);
|
||||
protected
|
||||
FRadar: TSingleImage;
|
||||
FRadarDependencies: TList;
|
||||
procedure OnRadarHandlingPacket(ABuffer: TEnhancedMemoryStream);
|
||||
procedure RefreshRadar(ARadarMap: TRadarColorMap);
|
||||
procedure RepaintRadar;
|
||||
public
|
||||
property Radar: TSingleImage read FRadar;
|
||||
property Dependencies: TList read FRadarDependencies;
|
||||
end;
|
||||
|
||||
var
|
||||
frmRadarMap: TfrmRadarMap;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
UdmNetwork, UGameResources, UPacketHandlers, UPackets, UfrmInitialize,
|
||||
UfrmMain, UGraphicHelper;
|
||||
|
||||
{ TfrmRadarMap }
|
||||
|
||||
procedure TfrmRadarMap.FormCreate(Sender: TObject);
|
||||
begin
|
||||
FRadar := TSingleImage.CreateFromParams(ResMan.Landscape.Width,
|
||||
ResMan.Landscape.Height, ifA8R8G8B8);
|
||||
pbRadar.Width := FRadar.Width;
|
||||
pbRadar.Height := FRadar.Height;
|
||||
sbMain.ClientWidth := FRadar.Width;
|
||||
sbMain.ClientHeight := FRadar.Height;
|
||||
ClientWidth := sbMain.Width + sbMain.VertScrollBar.Size;
|
||||
ClientHeight := sbMain.Height + sbMain.HorzScrollBar.Size + pnlBottom.Height;
|
||||
Constraints.MaxWidth := Width;
|
||||
Constraints.MaxHeight := Height;
|
||||
|
||||
FRadarDependencies := TList.Create;
|
||||
|
||||
RegisterPacketHandler($0D, TPacketHandler.Create(0, @OnRadarHandlingPacket));
|
||||
|
||||
dmNetwork.Send(TRequestRadarChecksumPacket.Create);
|
||||
end;
|
||||
|
||||
procedure TfrmRadarMap.FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
||||
begin
|
||||
CloseAction := caHide;
|
||||
end;
|
||||
|
||||
procedure TfrmRadarMap.FormDestroy(Sender: TObject);
|
||||
var
|
||||
radarMap: TRadarColorMap;
|
||||
x, y: Integer;
|
||||
radarMapFile: TFileStream;
|
||||
begin
|
||||
RegisterPacketHandler($0D, nil);
|
||||
|
||||
SetLength(radarMap, FRadar.Width * FRadar.Height);
|
||||
for x := 0 to FRadar.Width - 1 do
|
||||
for y := 0 to FRadar.Height - 1 do
|
||||
radarMap[x * FRadar.Height + y] := EncodeUOColor(PInteger(FRadar.PixelPointers[x, y])^);
|
||||
|
||||
radarMapFile := TFileStream.Create(IncludeTrailingPathDelimiter(
|
||||
ExtractFilePath(Application.ExeName)) + 'RadarMap.cache', fmCreate);
|
||||
radarMapFile.Write(radarMap[0], Length(radarMap) * SizeOf(Word));
|
||||
radarMapFile.Free;
|
||||
|
||||
if FRadarDependencies <> nil then FreeAndNil(FRadarDependencies);
|
||||
if FRadar <> nil then FreeAndNil(FRadar);
|
||||
end;
|
||||
|
||||
procedure TfrmRadarMap.FormResize(Sender: TObject);
|
||||
begin
|
||||
sbMain.AutoScroll := (Width < Constraints.MaxWidth) or (Height < Constraints.MaxHeight);
|
||||
end;
|
||||
|
||||
procedure TfrmRadarMap.pbRadarMouseDown(Sender: TObject; Button: TMouseButton;
|
||||
Shift: TShiftState; X, Y: Integer);
|
||||
begin
|
||||
frmMain.SetPos(X * 8, Y * 8);
|
||||
end;
|
||||
|
||||
procedure TfrmRadarMap.pbRadarMouseLeave(Sender: TObject);
|
||||
begin
|
||||
lblPosition.Caption := '';
|
||||
end;
|
||||
|
||||
procedure TfrmRadarMap.pbRadarMouseMove(Sender: TObject; Shift: TShiftState; X,
|
||||
Y: Integer);
|
||||
begin
|
||||
lblPosition.Caption := Format('X: %d, Y: %d', [X * 8, Y * 8]);
|
||||
end;
|
||||
|
||||
procedure TfrmRadarMap.pbRadarPaint(Sender: TObject);
|
||||
var
|
||||
posX, posY: Word;
|
||||
begin
|
||||
DisplayImage(pbRadar.Canvas, 0, 0, FRadar);
|
||||
posX := frmMain.X div 8;
|
||||
posY := frmMain.Y div 8;
|
||||
pbRadar.Canvas.Pen.Color := clBlack;
|
||||
pbRadar.Canvas.Pen.Style := psSolid;
|
||||
pbRadar.Canvas.Brush.Color := clRed;
|
||||
pbRadar.Canvas.Brush.Style := bsSolid;
|
||||
pbRadar.Canvas.Ellipse(posX - 3, posY - 3, posX + 3, posY + 3);
|
||||
{pbRadar.Canvas.Pen.Color := clRed;
|
||||
pbRadar.Canvas.Pen.Style := psDash;
|
||||
pbRadar.Canvas.Line(0, posY, pbRadar.Width, posY);
|
||||
pbRadar.Canvas.Line(posX, 0, posX, pbRadar.Height);}
|
||||
end;
|
||||
|
||||
procedure TfrmRadarMap.OnRadarHandlingPacket(ABuffer: TEnhancedMemoryStream);
|
||||
var
|
||||
subID: Byte;
|
||||
checksum, realChecksum: Cardinal;
|
||||
radarMapFile: TFileStream;
|
||||
radarMapFileName: string;
|
||||
radarMap: TRadarColorMap;
|
||||
x, y: Integer;
|
||||
begin
|
||||
subID := ABuffer.ReadByte;
|
||||
case subID of
|
||||
$01: //checksum
|
||||
begin
|
||||
checksum := ABuffer.ReadCardinal;
|
||||
realChecksum := crc32(0, nil, 0);
|
||||
radarMapFileName := GetAppConfigDir(False) + 'RadarMap.cache';
|
||||
if FileExists(radarMapFileName) then
|
||||
begin
|
||||
radarMapFile := TFileStream.Create(radarMapFileName, fmOpenRead);
|
||||
SetLength(radarMap, radarMapFile.Size div SizeOf(Word));
|
||||
radarMapFile.Read(radarMap[0], radarMapFile.Size);
|
||||
radarMapFile.Free;
|
||||
|
||||
realChecksum := crc32(realChecksum, @radarMap[0], Length(radarMap) * SizeOf(Word));
|
||||
end;
|
||||
|
||||
if checksum <> realChecksum then
|
||||
begin
|
||||
frmInitialize.lblStatus.Caption := 'Updating Radar Map';
|
||||
frmInitialize.Show;
|
||||
frmInitialize.SetModal;
|
||||
//frmMain.Enabled := False;
|
||||
dmNetwork.Send(TRequestRadarMapPacket.Create);
|
||||
end else
|
||||
RefreshRadar(radarMap);
|
||||
end;
|
||||
$02: //radar map
|
||||
begin
|
||||
SetLength(radarMap, (ABuffer.Size - ABuffer.Position) div SizeOf(Word));
|
||||
ABuffer.Read(radarMap[0], Length(radarMap) * SizeOf(Word));
|
||||
RefreshRadar(radarMap);
|
||||
//frmMain.Enabled := True;
|
||||
frmInitialize.UnsetModal;
|
||||
frmInitialize.Hide;
|
||||
end;
|
||||
$03: //update radar
|
||||
begin
|
||||
x := ABuffer.ReadWord;
|
||||
y := ABuffer.ReadWord;
|
||||
PInteger(FRadar.PixelPointers[x, y])^ := DecodeUOColor(ABuffer.ReadWord);
|
||||
RepaintRadar;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TfrmRadarMap.RefreshRadar(ARadarMap: TRadarColorMap);
|
||||
var
|
||||
x, y: Integer;
|
||||
begin
|
||||
for x := 0 to FRadar.Width - 1 do
|
||||
for y := 0 to FRadar.Height - 1 do
|
||||
PInteger(FRadar.PixelPointers[x, y])^ := DecodeUOColor(ARadarMap[x * FRadar.Height + y]);
|
||||
RepaintRadar;
|
||||
end;
|
||||
|
||||
procedure TfrmRadarMap.RepaintRadar;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
pbRadar.Repaint;
|
||||
for i := 0 to FRadarDependencies.Count - 1 do
|
||||
TWinControl(FRadarDependencies.Items[i]).Repaint;
|
||||
end;
|
||||
|
||||
initialization
|
||||
{$I UfrmRadar.lrs}
|
||||
|
||||
end.
|
||||
|
||||
|
|
Loading…
Reference in New Issue