Changeset 346


Ignore:
Timestamp:
Dec 25, 2024, 11:04:56 AM (16 hours ago)
Author:
chronos
Message:
  • Fixed: Build on Linux.
  • Modified: Improved internal code structure.
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/FormItem.pas

    r344 r346  
    8080  J: Integer;
    8181  Control: TControl;
    82   ReferenceList: TItemList<TItem>;
     82  ReferenceList: IList<TItem>;
    8383  ReferenceItem: TItem;
    8484begin
     
    106106      try
    107107        TComboBox(Control).Items.Clear;
    108         ReferenceList := TItemList<TItem>(Item.GetReferenceList(Index));
     108        ReferenceList := Item.GetReferenceList(Index);
    109109        if Assigned(ReferenceList) then
    110110          for J := 0 to ReferenceList.Count - 1 do
  • trunk/Forms/FormList.lfm

    r320 r346  
    11object FormList: TFormList
    22  Left = 1040
    3   Height = 360
     3  Height = 312
    44  Top = 540
    5   Width = 480
     5  Width = 417
    66  Caption = 'List'
    7   ClientHeight = 360
    8   ClientWidth = 480
    9   DesignTimePPI = 144
     7  ClientHeight = 312
     8  ClientWidth = 417
     9  DesignTimePPI = 125
    1010  OnCreate = FormCreate
     11  OnDestroy = FormDestroy
    1112  OnShow = FormShow
    12   LCLVersion = '3.4.0.0'
     13  LCLVersion = '3.6.0.0'
    1314  object ListView1: TListView
    1415    Left = 0
    15     Height = 322
     16    Height = 279
    1617    Top = 0
    17     Width = 480
     18    Width = 417
    1819    Align = alClient
    1920    Columns = <   
    2021      item
    2122        Caption = 'Name'
    22         Width = 466
     23        Width = 405
    2324      end>
    2425    MultiSelect = True
     
    3940  object ToolBar1: TToolBar
    4041    Left = 0
    41     Height = 38
    42     Top = 322
    43     Width = 480
     42    Height = 33
     43    Top = 279
     44    Width = 417
    4445    Align = alBottom
    4546    Images = Core.ImageListSmall
     
    5455    end
    5556    object ToolButton2: TToolButton
    56       Left = 36
     57      Left = 31
    5758      Top = 2
    5859      Action = AModify
    5960    end
    6061    object ToolButton3: TToolButton
    61       Left = 71
     62      Left = 61
    6263      Top = 2
    6364      Action = ARemove
    6465    end
    6566    object ToolButton4: TToolButton
    66       Left = 106
     67      Left = 91
    6768      Top = 2
    6869      Action = AClone
     
    7172  object ActionList1: TActionList
    7273    Images = Core.ImageListSmall
    73     Left = 208
    74     Top = 163
     74    Left = 181
     75    Top = 141
    7576    object AAdd: TAction
    7677      Caption = 'Add'
     
    101102  object PopupMenu1: TPopupMenu
    102103    Images = Core.ImageListSmall
    103     Left = 352
    104     Top = 160
     104    Left = 306
     105    Top = 139
    105106    object MenuItem1: TMenuItem
    106107      Action = AAdd
  • trunk/Forms/FormList.pas

    r344 r346  
    3535    procedure ASelectAllExecute(Sender: TObject);
    3636    procedure FormCreate(Sender: TObject);
     37    procedure FormDestroy(Sender: TObject);
    3738    procedure FormShow(Sender: TObject);
    3839    procedure ListView1CustomDrawSubItem(Sender: TCustomListView;
     
    182183end;
    183184
     185procedure TFormList.FormDestroy(Sender: TObject);
     186begin
     187  List := nil;
     188end;
     189
    184190procedure TFormList.FormShow(Sender: TObject);
    185191begin
     
    254260  if FList = AValue then Exit;
    255261  FList := AValue;
     262  UpdateInterface;
     263  UpdateList;
    256264end;
    257265
  • trunk/ItemList.pas

    r345 r346  
    184184  while Count < Source.Count do AddItem('');
    185185  for I := 0 to Count - 1 do
    186     TItem(Items[I]).Assign(Source.Items[I]);
     186    Items[I].Assign(Source.Items[I]);
    187187end;
    188188
     
    201201function TItemList<T>.AddItem(Name: string): T;
    202202begin
    203   Result := T.Create;
    204   Result.Name := Name;
     203  Result := CreateItem(Name);
    205204  Result.Id := GetNewId;
    206205  Add(Result);
     
    253252end;
    254253
    255 function TItemList<T>.QueryInterface(constref iid: tguid; out obj): LongInt;
    256   stdcall;
     254function TItemList<T>.QueryInterface({$IFDEF FPC_HAS_CONSTREF}constref{$ELSE}const{$ENDIF} iid: tguid; out obj): LongInt;
     255  {$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF};
    257256begin
    258257  Result := 0;
    259258end;
    260259
    261 function TItemList<T>._AddRef: LongInt; stdcall;
     260function TItemList<T>._AddRef: LongInt; {$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF};
    262261begin
    263262  Result := 0;
    264263end;
    265264
    266 function TItemList<T>._Release: LongInt; stdcall;
     265function TItemList<T>._Release: LongInt; {$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF};
    267266begin
    268267  Result := 0;
  • trunk/Player.pas

    r344 r346  
    137137  public
    138138    Game: TObject; //TGame;
     139    procedure Assign(Source: TItemList<TPlayer>); override;
    139140    procedure New(Name: string; Color: TColor; Mode: TPlayerMode);
    140141    function CreateItem(Name: string = ''): TPlayer; override;
     
    160161    CountOnce: Integer;
    161162    CountRepeat: Integer;
     163    procedure Assign(Source: TUnitMove);
    162164    procedure LoadFromNode(Node: TDOMNode);
    163165    procedure SaveToNode(Node: TDOMNode);
     
    173175    Game: TObject; //TGame;
    174176    Player: TPlayer;
     177    procedure Assign(Source: TUnitMoves);
    175178    function SearchByFromTo(CellFrom, CellTo: TPlayerCell): TUnitMove;
    176179    procedure LoadFromNode(Node: TDOMNode);
     
    416419begin
    417420  for I := 0 to Cells.Count - 1 do
    418   with TPlayerCell(Cells[I]) do begin
     421  with Cells[I] do begin
    419422    for J := Neighbors.Count - 1 downto 0 do
    420423      DisconnectFrom(Neighbors[J]);
     
    440443  with TPlayerCell(Cells[I]) do begin
    441444    for J := 0 to MapCell.Neighbors.Count - 1 do
    442       ConnectTo(TPlayerCell(TCell(MapCell.Neighbors[J]).PlayerCell));
     445      ConnectTo(TPlayerCell(MapCell.Neighbors[J].PlayerCell));
    443446  end;
    444447end;
     
    499502end;
    500503
     504procedure TPlayers.Assign(Source: TItemList<TPlayer>);
     505var
     506  I: Integer;
     507begin
     508  inherited;
     509  for I := 0 to Count - 1 do
     510    Items[I].Game := Game;
     511end;
     512
    501513procedure TPlayers.New(Name: string; Color: TColor; Mode: TPlayerMode);
    502 begin
    503   AddItem(Name);
    504   Last.Color := Color;
    505   Last.Mode := Mode;
     514var
     515  NewPlayer: TPlayer;
     516begin
     517  NewPlayer := AddItem(Name);
     518  NewPlayer.Color := Color;
     519  NewPlayer.Mode := Mode;
    506520  if Mode = pmComputer then
    507     Last.Agressivity := caMedium;
     521    NewPlayer.Agressivity := caMedium;
    508522end;
    509523
     
    583597{ TUnitMoves }
    584598
     599procedure TUnitMoves.Assign(Source: TUnitMoves);
     600var
     601  I: Integer;
     602begin
     603  while Count > Source.Count do
     604    Delete(Count - 1);
     605  while Count < Source.Count do
     606    Add(TUnitMove.Create);
     607  for I := 0 to Count - 1 do begin
     608    Items[I].Assign(Source.Items[I]);
     609  end;
     610end;
     611
    585612function TUnitMoves.SearchByFromTo(CellFrom, CellTo: TPlayerCell): TUnitMove;
    586613var
     
    663690      else raise Exception.Create('Unit move already exists');
    664691  end else
     692end;
     693
     694procedure TUnitMove.Assign(Source: TUnitMove);
     695begin
     696  CountOnce := Source.CountOnce;
     697  CountRepeat := Source.CountRepeat;
     698  CellFrom.MapCell.Id := Source.CellFrom.MapCell.Id;
     699  CellTo.MapCell.Id := Source.CellTo.MapCell.Id;
    665700end;
    666701
     
    801836begin
    802837  inherited;
    803   //Game := TPlayer(Source).Game;
    804838  TotalCells := TPlayer(Source).TotalCells;
    805839  TotalUnits := TPlayer(Source).TotalUnits;
     
    809843  StartCell := TPlayer(Source).StartCell;
    810844  Color := TPlayer(Source).Color;
    811   //Units.Assign(TPlayer(Source).Units);
     845  Units.Assign(TPlayer(Source).Units);
     846  Moves.Assign(TPlayer(Source).Moves);
    812847  Nation := TPlayer(Source).Nation;
    813848end;
  • trunk/ServerList.pas

    r317 r346  
    2323  end;
    2424
     25  { TServerInfos }
     26
    2527  TServerInfos = class(TObjectList<TServerInfo>)
     28    procedure Assign(Source: TServerInfos);
    2629  end;
    2730
     
    6467end;
    6568
     69{ TServerInfos }
     70
     71procedure TServerInfos.Assign(Source: TServerInfos);
     72var
     73  I: Integer;
     74begin
     75  while Count > Source.Count do
     76    Delete(Count - 1);
     77  while Count < Source.Count do
     78    Add(TServerInfo.Create);
     79  for I := 0 to Count - 1 do begin
     80    Items[I].Assign(Source.Items[I]);
     81  end;
     82end;
     83
    6684{ TServerList }
    6785
    6886procedure TServerList.Assign(Source: TServerList);
    69 var
    70   I: Integer;
    7187begin
    72   while Items.Count > Source.Items.Count do
    73     Items.Delete(Items.Count - 1);
    74   while Items.Count < Source.Items.Count do
    75     Items.Add(TServerInfo.Create);
    76   for I := 0 to Items.Count - 1 do begin
    77     Items[I].Assign(Source.Items[I]);
    78   end;
     88  Name := Source.Name;
     89  Address := Source.Address;
     90  Items.Assign(Source.Items);
    7991end;
    8092
  • trunk/Units.pas

    r344 r346  
    138138  for I := 0 to Count - 1 do begin
    139139    Items[I].Assign(Source[I]);
     140    Items[I].Game := Game;
    140141  end;
    141142  NewId := Source.NewId;
Note: See TracChangeset for help on using the changeset viewer.