From 1759e0763cf07713c6101e4a7d77f13f6937e2d6 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 8 Dec 2009 22:17:39 +0100 Subject: [PATCH] - Fixed typo in UMulManager - Added array initialization to TAnimDataProvider - Adjusted frmLogin - Some code cleanups --- Client/UGameResources.pas | 6 +- Client/UdmNetwork.lfm | 2 +- Client/UdmNetwork.pas | 47 +++-- Client/UfrmLogin.lfm | 307 ++++++++++++++++++++++-------- Client/UfrmLogin.pas | 15 +- MulProvider/UAnimDataProvider.pas | 19 ++ MulProvider/UMulManager.pas | 2 +- UOLib/UAnimData.pas | 8 +- 8 files changed, 288 insertions(+), 118 deletions(-) diff --git a/Client/UGameResources.pas b/Client/UGameResources.pas index 2b8863b..7b6ab05 100644 --- a/Client/UGameResources.pas +++ b/Client/UGameResources.pas @@ -31,7 +31,7 @@ interface uses Classes, SysUtils, UArtProvider, UTileDataProvider, UTexmapProvider, - ULandscape, UHueProvider; + ULandscape, UHueProvider, UAnimDataProvider; type @@ -45,6 +45,7 @@ type FDataDir: string; FArtProvider: TArtProvider; FTiledataProvider: TTiledataProvider; + FAnimdataProvider: TAnimdataProvider; FTexmapProvider: TTexmapProvider; FHueProvider: THueProvider; FLandscape: TLandscape; @@ -54,6 +55,7 @@ type property Hue: THueProvider read FHueProvider; property Landscape: TLandscape read FLandscape; property Tiledata: TTiledataProvider read FTiledataProvider; + property Animdata: TAnimDataProvider read FAnimdataProvider; property Texmaps: TTexmapProvider read FTexmapProvider; { Methods } @@ -84,6 +86,7 @@ begin FArtProvider := TArtProvider.Create(GetFile('art.mul'), GetFile('artidx.mul'), True); FTiledataProvider := TTiledataProvider.Create(GetFile('tiledata.mul'), True); + FAnimdataProvider := TAnimDataProvider.Create(GetFile('animdata.mul'), True); FTexmapProvider := TTexmapProvider.Create(GetFile('texmaps.mul'), GetFile('texidx.mul'), True); FHueProvider := THueProvider.Create(GetFile('hues.mul'), True); end; @@ -92,6 +95,7 @@ destructor TGameResourceManager.Destroy; begin FreeAndNil(FArtProvider); FreeAndNil(FTiledataProvider); + FreeAndNil(FAnimdataProvider); FreeAndNil(FTexmapProvider); FreeAndNil(FHueProvider); FreeAndNil(FLandscape); diff --git a/Client/UdmNetwork.lfm b/Client/UdmNetwork.lfm index fd42dc9..e80b362 100644 --- a/Client/UdmNetwork.lfm +++ b/Client/UdmNetwork.lfm @@ -22,7 +22,7 @@ object dmNetwork: TdmNetwork Interval = 30000 OnTimer = tmNoOpTimer OnStartTimer = tmNoOpStartTimer - left = 72 + left = 112 top = 24 end end diff --git a/Client/UdmNetwork.pas b/Client/UdmNetwork.pas index b01fbfa..a58b02b 100644 --- a/Client/UdmNetwork.pas +++ b/Client/UdmNetwork.pas @@ -21,7 +21,7 @@ * CDDL HEADER END * * - * Portions Copyright 2007 Andreas Schneider + * Portions Copyright 2009 Andreas Schneider *) unit UdmNetwork; @@ -95,9 +95,9 @@ end; procedure TdmNetwork.DataModuleDestroy(Sender: TObject); begin - if FSendQueue <> nil then FreeAndNil(FSendQueue); - if FReceiveQueue <> nil then FreeAndNil(FReceiveQueue); - if PacketHandlers[$02] <> nil then FreeAndNil(PacketHandlers[$02]); + FreeAndNil(FSendQueue); + FreeAndNil(FReceiveQueue); + FreeAndNil(PacketHandlers[$02]); end; procedure TdmNetwork.TCPClientConnect(aSocket: TLSocket); @@ -290,28 +290,33 @@ procedure TdmNetwork.DoLogin; begin tmNoOp.Enabled := False; frmLogin := TfrmLogin.Create(dmNetwork); - if frmInitialize = nil then frmInitialize := TfrmInitialize.Create(dmNetwork); - if frmTileInfo <> nil then FreeAndNil(frmTileInfo); - if frmEditAccount <> nil then FreeAndNil(frmEditAccount); - if frmAccountControl <> nil then FreeAndNil(frmAccountControl); - if frmConfirmation <> nil then FreeAndNil(frmConfirmation); - if frmDrawSettings <> nil then FreeAndNil(frmDrawSettings); - if frmMoveSettings <> nil then FreeAndNil(frmMoveSettings); - if frmElevateSettings <> nil then FreeAndNil(frmElevateSettings); - if frmHueSettings <> nil then FreeAndNil(frmHueSettings); - if frmBoundaries <> nil then FreeAndNil(frmBoundaries); - if frmFilter <> nil then FreeAndNil(frmFilter); - if frmVirtualLayer <> nil then FreeAndNil(frmVirtualLayer); - if frmAbout <> nil then FreeAndNil(frmAbout); - if frmRegionControl <> nil then FreeAndNil(frmRegionControl); - if frmLargeScaleCommand <> nil then FreeAndNil(frmLargeScaleCommand); - if frmRadarMap <> nil then FreeAndNil(frmRadarMap); + if frmInitialize = nil then + frmInitialize := TfrmInitialize.Create(dmNetwork); + + FreeAndNil(frmTileInfo); + FreeAndNil(frmEditAccount); + FreeAndNil(frmAccountControl); + FreeAndNil(frmConfirmation); + FreeAndNil(frmDrawSettings); + FreeAndNil(frmMoveSettings); + FreeAndNil(frmElevateSettings); + FreeAndNil(frmHueSettings); + FreeAndNil(frmBoundaries); + FreeAndNil(frmFilter); + FreeAndNil(frmVirtualLayer); + FreeAndNil(frmAbout); + FreeAndNil(frmRegionControl); + FreeAndNil(frmLargeScaleCommand); + FreeAndNil(frmRadarMap); + if frmMain <> nil then begin frmMain.ApplicationProperties1.OnIdle := nil; FreeAndNil(frmMain); end; - if GameResourceManager <> nil then FreeAndNil(GameResourceManager); + + FreeAndNil(GameResourceManager); + frmInitialize.Hide; while frmLogin.ShowModal = mrOK do begin diff --git a/Client/UfrmLogin.lfm b/Client/UfrmLogin.lfm index 2f83edf..a65294e 100644 --- a/Client/UfrmLogin.lfm +++ b/Client/UfrmLogin.lfm @@ -1,14 +1,14 @@ object frmLogin: TfrmLogin Left = 290 - Height = 265 + Height = 246 Top = 171 - Width = 489 - ActiveControl = edHost + Width = 481 + ActiveControl = btnOK BorderIcons = [biSystemMenu] BorderStyle = bsDialog Caption = 'UO CentrED' - ClientHeight = 265 - ClientWidth = 489 + ClientHeight = 246 + ClientWidth = 481 Font.Height = -11 OnClose = FormClose OnCreate = FormCreate @@ -16,53 +16,85 @@ object frmLogin: TfrmLogin ShowInTaskBar = stAlways LCLVersion = '0.9.29' object lblCopyright: TLabel + AnchorSideLeft.Control = Owner + AnchorSideRight.Control = Owner + AnchorSideRight.Side = asrBottom + AnchorSideBottom.Control = Owner + AnchorSideBottom.Side = asrBottom Left = 0 - Height = 14 - Top = 251 - Width = 489 - Align = alBottom + Height = 15 + Top = 231 + Width = 481 Alignment = taCenter + Anchors = [akLeft, akRight, akBottom] ParentColor = False end object gbConnection: TGroupBox + AnchorSideLeft.Control = Owner + AnchorSideTop.Control = Owner + AnchorSideRight.Control = gbActions + AnchorSideBottom.Side = asrCenter Left = 8 Height = 128 - Top = 8 - Width = 321 + Top = 4 + Width = 314 + Anchors = [akTop, akLeft, akRight] + AutoSize = True + BorderSpacing.Left = 8 + BorderSpacing.Top = 4 Caption = 'Connection' - ClientHeight = 110 - ClientWidth = 317 + ClientHeight = 114 + ClientWidth = 312 TabOrder = 0 object lblHost: TLabel - Left = 30 + AnchorSideLeft.Control = imgHost + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = edHost + AnchorSideTop.Side = asrCenter + Left = 32 Height = 14 - Top = 9 + Top = 10 Width = 28 + BorderSpacing.Left = 8 Caption = 'Host:' ParentColor = False end object lblUsername: TLabel - Left = 30 + AnchorSideLeft.Control = imgUsername + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = edUsername + AnchorSideTop.Side = asrCenter + Left = 32 Height = 14 - Top = 43 - Width = 55 + Top = 46 + Width = 58 + BorderSpacing.Left = 8 Caption = 'Username:' ParentColor = False end object lblPassword: TLabel - Left = 30 + AnchorSideLeft.Control = imgPassword + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = edPassword + AnchorSideTop.Side = asrCenter + Left = 32 Height = 14 - Top = 77 - Width = 53 + Top = 81 + Width = 54 + BorderSpacing.Left = 8 Caption = 'Password:' ParentColor = False end object imgHost: TImage - Left = 6 + AnchorSideLeft.Control = gbConnection + AnchorSideTop.Control = lblHost + AnchorSideTop.Side = asrCenter + Left = 8 Height = 16 Top = 9 Width = 16 AutoSize = True + BorderSpacing.Left = 8 Picture.Data = { 07545069786D61702E0A00002F2A2058504D202A2F0A73746174696320636861 72202A64756D6D795B5D3D7B0A223136203136203132342032222C0A22517420 @@ -150,9 +182,12 @@ object frmLogin: TfrmLogin Transparent = True end object imgUsername: TImage - Left = 6 + AnchorSideLeft.Control = imgHost + AnchorSideTop.Control = lblUsername + AnchorSideTop.Side = asrCenter + Left = 8 Height = 16 - Top = 43 + Top = 45 Width = 16 AutoSize = True Picture.Data = { @@ -242,9 +277,12 @@ object frmLogin: TfrmLogin Transparent = True end object imgPassword: TImage - Left = 6 + AnchorSideLeft.Control = imgUsername + AnchorSideTop.Control = lblPassword + AnchorSideTop.Side = asrCenter + Left = 8 Height = 16 - Top = 77 + Top = 80 Width = 16 AutoSize = True Picture.Data = { @@ -324,34 +362,66 @@ object frmLogin: TfrmLogin Transparent = True end object edHost: TEdit - Left = 101 - Height = 21 - Top = 5 - Width = 137 + AnchorSideLeft.Control = lblUsername + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = gbConnection + AnchorSideRight.Control = edPort + Left = 98 + Height = 19 + Top = 8 + Width = 143 + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Left = 8 + BorderSpacing.Top = 8 TabOrder = 0 Text = 'localhost' end object edUsername: TEdit - Left = 101 - Height = 21 - Top = 39 - Width = 201 + AnchorSideLeft.Control = edHost + AnchorSideTop.Control = edHost + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = edPort + AnchorSideRight.Side = asrBottom + Left = 98 + Height = 19 + Top = 44 + Width = 206 + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Top = 17 TabOrder = 2 end object edPassword: TEdit - Left = 101 - Height = 21 - Top = 73 - Width = 201 + AnchorSideLeft.Control = edUsername + AnchorSideTop.Control = edUsername + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = edUsername + AnchorSideRight.Side = asrBottom + Left = 98 + Height = 19 + Top = 79 + Width = 206 + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Top = 16 + BorderSpacing.Bottom = 16 EchoMode = emPassword PasswordChar = '*' TabOrder = 3 end object edPort: TSpinEdit - Left = 246 - Height = 21 - Top = 5 - Width = 56 + AnchorSideLeft.Control = edHost + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = edHost + AnchorSideRight.Control = gbConnection + AnchorSideRight.Side = asrBottom + AnchorSideBottom.Control = edHost + AnchorSideBottom.Side = asrBottom + Left = 249 + Height = 19 + Top = 8 + Width = 55 + Anchors = [akTop, akRight, akBottom] + BorderSpacing.Left = 8 + BorderSpacing.Right = 8 MaxValue = 65565 MinValue = 1024 TabOrder = 1 @@ -359,18 +429,33 @@ object frmLogin: TfrmLogin end end object gbActions: TGroupBox - Left = 336 - Height = 96 - Top = 8 - Width = 145 - ClientHeight = 78 + AnchorSideLeft.Control = gbConnection + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = gbConnection + AnchorSideRight.Control = Owner + AnchorSideRight.Side = asrBottom + Left = 330 + Height = 76 + Top = 12 + Width = 143 + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Left = 8 + BorderSpacing.Top = 8 + BorderSpacing.Right = 8 + ClientHeight = 74 ClientWidth = 141 TabOrder = 2 object btnOK: TButton - Left = 6 + AnchorSideLeft.Control = gbActions + AnchorSideTop.Control = gbActions + AnchorSideRight.Control = gbActions + AnchorSideRight.Side = asrBottom + Left = 8 Height = 25 - Top = 5 - Width = 128 + Top = 8 + Width = 125 + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Around = 8 BorderSpacing.InnerBorder = 4 Caption = '&OK' Default = True @@ -378,10 +463,17 @@ object frmLogin: TfrmLogin TabOrder = 0 end object btnCancel: TButton - Left = 6 + AnchorSideLeft.Control = btnOK + AnchorSideTop.Control = btnOK + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = btnOK + AnchorSideRight.Side = asrBottom + Left = 8 Height = 25 - Top = 39 - Width = 128 + Top = 41 + Width = 125 + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Bottom = 8 BorderSpacing.InnerBorder = 4 Caption = '&Cancel' ModalResult = 2 @@ -390,51 +482,83 @@ object frmLogin: TfrmLogin end end object gbData: TGroupBox + AnchorSideLeft.Control = gbConnection + AnchorSideTop.Control = gbConnection + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = gbConnection + AnchorSideRight.Side = asrBottom Left = 8 - Height = 97 - Top = 144 - Width = 321 + Height = 95 + Top = 136 + Width = 314 + Anchors = [akTop, akLeft, akRight] + AutoSize = True + BorderSpacing.Top = 4 Caption = 'Data files' - ClientHeight = 79 - ClientWidth = 317 + ClientHeight = 81 + ClientWidth = 312 TabOrder = 1 object lblData: TLabel - Left = 7 - Height = 32 - Top = 8 - Width = 304 - AutoSize = False - Caption = 'Select the directory containing art.mul, artidx.mul, hues.mul, tiledata.mul, texmaps.mul and texidx.mul.' + AnchorSideLeft.Control = gbData + AnchorSideTop.Control = gbData + AnchorSideRight.Control = gbData + AnchorSideRight.Side = asrBottom + Left = 8 + Height = 46 + Top = 4 + Width = 296 + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Left = 8 + BorderSpacing.Top = 4 + BorderSpacing.Right = 8 + Caption = 'Select the directory containing art.mul, artidx.mul, hues.mul, tiledata.mul, animdata.mul, texmaps.mul and texidx.mul.' ParentColor = False WordWrap = True end object edData: TDirectoryEdit - Left = 7 - Height = 21 - Top = 48 - Width = 280 + AnchorSideLeft.Control = lblData + AnchorSideTop.Control = lblData + AnchorSideTop.Side = asrBottom + Left = 8 + Height = 19 + Top = 54 + Width = 272 ShowHidden = False ButtonWidth = 23 NumGlyphs = 1 + BorderSpacing.Top = 4 + BorderSpacing.Bottom = 8 MaxLength = 0 TabOrder = 0 end end - object GroupBox1: TGroupBox - Left = 336 - Height = 88 - Top = 112 - Width = 145 + object gbProfiles: TGroupBox + AnchorSideLeft.Control = gbActions + AnchorSideTop.Control = gbActions + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = gbActions + AnchorSideRight.Side = asrBottom + Left = 330 + Height = 85 + Top = 96 + Width = 143 + Anchors = [akTop, akLeft, akRight] + AutoSize = True + BorderSpacing.Top = 8 Caption = 'Profiles' - ClientHeight = 70 + ClientHeight = 71 ClientWidth = 141 TabOrder = 3 object btnSaveProfile: TSpeedButton - Left = 86 + AnchorSideTop.Control = btnDeleteProfile + AnchorSideRight.Control = btnDeleteProfile + Left = 81 Height = 22 Hint = 'Save profile' - Top = 40 - Width = 23 + Top = 41 + Width = 22 + Anchors = [akTop, akRight] + BorderSpacing.Right = 8 Color = clBtnFace Glyph.Data = { 36040000424D3604000000000000360000002800000010000000100000000100 @@ -479,11 +603,18 @@ object frmLogin: TfrmLogin ParentShowHint = False end object btnDeleteProfile: TSpeedButton + AnchorSideTop.Control = cbProfile + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = cbProfile + AnchorSideRight.Side = asrBottom Left = 111 Height = 22 Hint = 'Delete profile' - Top = 40 - Width = 23 + Top = 41 + Width = 22 + Anchors = [akTop, akRight] + BorderSpacing.Top = 8 + BorderSpacing.Bottom = 8 Color = clBtnFace Glyph.Data = { 36040000424D3604000000000000360000002800000010000000100000000100 @@ -528,11 +659,19 @@ object frmLogin: TfrmLogin ParentShowHint = False end object cbProfile: TComboBox - Left = 6 - Height = 21 - Top = 8 - Width = 128 - ItemHeight = 13 + AnchorSideLeft.Control = gbProfiles + AnchorSideTop.Control = gbProfiles + AnchorSideRight.Control = gbProfiles + AnchorSideRight.Side = asrBottom + Left = 8 + Height = 29 + Top = 4 + Width = 125 + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Left = 8 + BorderSpacing.Top = 4 + BorderSpacing.Right = 8 + ItemHeight = 0 OnChange = cbProfileChange Style = csDropDownList TabOrder = 0 diff --git a/Client/UfrmLogin.pas b/Client/UfrmLogin.pas index b46ca3a..7bd9791 100644 --- a/Client/UfrmLogin.pas +++ b/Client/UfrmLogin.pas @@ -21,7 +21,7 @@ * CDDL HEADER END * * - * Portions Copyright 2007 Andreas Schneider + * Portions Copyright 2009 Andreas Schneider *) unit UfrmLogin; @@ -48,7 +48,7 @@ type gbConnection: TGroupBox; gbData: TGroupBox; gbActions: TGroupBox; - GroupBox1: TGroupBox; + gbProfiles: TGroupBox; imgHost: TImage; imgUsername: TImage; imgPassword: TImage; @@ -108,12 +108,13 @@ begin (not FileExists(path + 'artidx.mul')) or (not FileExists(path + 'hues.mul')) or (not FileExists(path + 'tiledata.mul')) or + (not FileExists(path + 'animdata.mul')) or (not FileExists(path + 'texmaps.mul')) or (not FileExists(path + 'texidx.mul')) then begin - MessageDlg('Incorrect directory', 'The data path you specified does not seem to be correct.', mtWarning, [mbOK], 0); + MessageDlg('Incorrect directory', 'The data path you specified does not ' + + 'seem to be correct.', mtWarning, [mbOK], 0); edData.SetFocus; - Exit; end else ModalResult := mrOK; end; @@ -168,9 +169,11 @@ procedure TfrmLogin.FormCreate(Sender: TObject); var searchRec: TSearchRec; begin - lblCopyright.Caption := Format('UO CentrED Client Version %s (c) %s', [ProductVersion, Copyright]); + lblCopyright.Caption := Format('UO CentrED Client Version %s (c) %s', + [ProductVersion, Copyright]); - FProfilePath := IncludeTrailingPathDelimiter(ExtractFilePath(Application.ExeName)) + 'Profiles' + PathDelim; + FProfilePath := IncludeTrailingPathDelimiter(ExtractFilePath(Application.ExeName)) + + 'Profiles' + PathDelim; ForceDirectories(FProfilePath); if FindFirst(FProfilePath + '*.ini', faAnyFile, searchRec) = 0 then begin diff --git a/MulProvider/UAnimDataProvider.pas b/MulProvider/UAnimDataProvider.pas index 6d6307e..f7d4980 100644 --- a/MulProvider/UAnimDataProvider.pas +++ b/MulProvider/UAnimDataProvider.pas @@ -48,6 +48,7 @@ type FAnimData: TAnimDataArray; function CalculateOffset(AID: Integer): Integer; override; function GetData(AID, AOffset: Integer): TAnimData; override; + procedure InitArray; procedure SetData(AID, AOffset: Integer; ABlock: TMulBlock); override; public property AnimData: TAnimDataArray read FAnimData; @@ -61,15 +62,22 @@ implementation constructor TAnimDataProvider.Create(AData: TStream; AReadOnly: Boolean); begin inherited Create(AData, AReadOnly); + InitArray; end; constructor TAnimDataProvider.Create(AData: string; AReadOnly: Boolean); begin inherited Create(AData, AReadOnly); + InitArray; end; destructor TAnimDataProvider.Destroy; +var + i: Integer; begin + for i := 0 to Length(FAnimData) - 1 do + FreeAndNil(FAnimData[i]); + inherited Destroy; end; @@ -83,6 +91,17 @@ begin Result := FAnimData[AID]; end; +procedure TAnimDataProvider.InitArray; +var + i: Integer; +begin + for i := 0 to Length(FAnimData) - 1 do + begin + FData.Position := GetAnimDataOffset(i); + FAnimData[i] := TAnimData.Create(FData); + end; +end; + procedure TAnimDataProvider.SetData(AID, AOffset: Integer; ABlock: TMulBlock); begin FreeAndNil(FAnimData[AID]); diff --git a/MulProvider/UMulManager.pas b/MulProvider/UMulManager.pas index 34d0116..eba90cd 100644 --- a/MulProvider/UMulManager.pas +++ b/MulProvider/UMulManager.pas @@ -123,7 +123,7 @@ procedure TMulManager.RegisterAnimDataProvider( AAnimDataProvider: TAnimDataProvider); begin FreeAndNil(FAnimDataProvider); - FTileDataProvider := AAnimDataProvider; + FAnimDataProvider := AAnimDataProvider; end; end. diff --git a/UOLib/UAnimData.pas b/UOLib/UAnimData.pas index ff05916..08e19a5 100644 --- a/UOLib/UAnimData.pas +++ b/UOLib/UAnimData.pas @@ -69,16 +69,16 @@ type property Unknown: LongInt read FUnknown write FUnknown; end; -function GetAnimDataOffset(Block: Integer): Integer; +function GetAnimDataOffset(AID: Integer): Integer; implementation -function GetAnimDataOffset(Block: Integer): Integer; +function GetAnimDataOffset(AID: Integer): Integer; var group, tile: Integer; begin - group := Block div 8; - tile := Block mod 8; + group := AID div 8; + tile := AID mod 8; Result := group * AnimDataGroupSize + 4 + tile * AnimDataSize; end;