- Timestamp:
- Dec 27, 2024, 10:29:54 AM (4 weeks ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/FormGameSystem.pas
r344 r349 116 116 FGameSystem := AValue; 117 117 if Assigned(FGameSystem) then begin 118 FormUnitKinds.List := GameSystem.UnitKinds ;119 FormNations.List := GameSystem.Nations ;120 FormBuildingKinds.List := GameSystem.BuildingKinds ;118 FormUnitKinds.List := GameSystem.UnitKinds.BaseItemList; 119 FormNations.List := GameSystem.Nations.BaseItemList; 120 FormBuildingKinds.List := GameSystem.BuildingKinds.BaseItemList; 121 121 end; 122 122 end; -
trunk/Forms/FormItem.pas
r346 r349 80 80 J: Integer; 81 81 Control: TControl; 82 ReferenceList: IList<TItem>;82 ReferenceList: TBaseItemList; 83 83 ReferenceItem: TItem; 84 84 begin -
trunk/Forms/FormList.pas
r346 r349 47 47 Selected: Boolean); 48 48 private 49 FList: IList<TItem>;50 procedure SetList(AValue: IList<TItem>);49 FList: TBaseItemList; 50 procedure SetList(AValue: TBaseItemList); 51 51 procedure UpdateListViewColumns; 52 52 public … … 55 55 procedure UpdateInterface; 56 56 procedure UpdateList; 57 property List: IList<TItem>read FList write SetList;57 property List: TBaseItemList read FList write SetList; 58 58 end; 59 59 … … 84 84 if List.Count <= MinItemCount then Break; 85 85 ListView1.Items[I].Selected := False; 86 List.Remove(TItem(ListView1.Items[I].Data));86 FList.Remove(TItem(ListView1.Items[I].Data)); 87 87 end; 88 88 UpdateList; … … 99 99 if Assigned(ListView1.Selected) then 100 100 with TItem(ListView1.Selected.Data) do begin 101 TempEntry := List.CreateBaseItem;101 TempEntry := FList.CreateItem; 102 102 TempEntry.Assign(TItem(ListView1.Selected.Data)); 103 103 FormItem := TFormItem.Create(Self); … … 121 121 FormItem: TFormItem; 122 122 begin 123 if (MaxItemCount <> -1) and ( List.Count >= MaxItemCount) then Exit;124 125 TempEntry := List.CreateBaseItem;123 if (MaxItemCount <> -1) and (FList.Count >= MaxItemCount) then Exit; 124 125 TempEntry := FList.CreateItem; 126 126 FormItem := TFormItem.Create(Self); 127 127 try 128 TempEntry.Name := List.GetNextAvailableName(SNew + ' ' + LowerCase(List.GetName));128 TempEntry.Name := FList.GetNextAvailableName(SNew + ' ' + LowerCase(List.GetName)); 129 129 FormItem.Item := TempEntry; 130 130 if FormItem.ShowModal = mrOk then begin 131 List.Add(TempEntry);131 FList.Add(TempEntry); 132 132 TempEntry := nil; 133 133 UpdateList; … … 145 145 FormItem: TFormItem; 146 146 begin 147 if (MaxItemCount <> -1) and ( List.Count >= MaxItemCount) then Exit;148 149 TempEntry := List.CreateBaseItem;147 if (MaxItemCount <> -1) and (FList.Count >= MaxItemCount) then Exit; 148 149 TempEntry := FList.CreateItem; 150 150 TempEntry.Assign(TItem(ListView1.Selected.Data)); 151 151 FormItem := TFormItem.Create(Self); … … 154 154 FormItem.Item := TempEntry; 155 155 if FormItem.ShowModal = mrOk then begin 156 List.Add(TempEntry);156 FList.Add(TempEntry); 157 157 TempEntry := nil; 158 158 UpdateList; … … 222 222 begin 223 223 if Item.Index < ListView1.Items.Count then 224 with TItem(List[Item.Index])do begin224 with FList[Item.Index] do begin 225 225 //Item.Caption := GetName; 226 Item.Data := List[Item.Index];227 Fields := List.GetItemFields;226 Item.Data := FList[Item.Index]; 227 Fields := FList.GetItemFields; 228 228 try 229 229 for I := 0 to Fields.Count - 1 do begin … … 256 256 end; 257 257 258 procedure TFormList.SetList(AValue: IList<TItem>);258 procedure TFormList.SetList(AValue: TBaseItemList); 259 259 begin 260 260 if FList = AValue then Exit; … … 269 269 Fields: TItemFields; 270 270 begin 271 if not Assigned(FList) then begin 272 while ListView1.Columns.Count > 0 do 273 ListView1.Columns.Delete(ListView1.Columns.Count - 1); 274 Exit; 275 end; 271 276 Fields := List.GetItemFields; 272 277 ListView1.Columns.BeginUpdate; … … 297 302 procedure TFormList.UpdateList; 298 303 begin 299 if Assigned( List) then ListView1.Items.Count :=List.Count304 if Assigned(FList) then ListView1.Items.Count := FList.Count 300 305 else ListView1.Items.Count := 0; 301 306 ListView1.Refresh; -
trunk/Forms/FormNew.pas
r344 r349 371 371 if Assigned(FServer) then begin 372 372 Load(FServer); 373 FormPlayers.List := FServer.Game.Players ;373 FormPlayers.List := FServer.Game.Players.BaseItemList; 374 374 end else begin 375 375 FormPlayers.List := nil; … … 468 468 WinObjective: TWinObjective; 469 469 begin 470 471 470 ComboBoxGridType.Enabled := FServer.Game.GameSystem.PreferedMapType = mtNone; 472 471 if FServer.Game.GameSystem.PreferedMapType <> mtNone then -
trunk/ItemList.pas
r347 r349 36 36 end; 37 37 38 { IList } 39 40 IList<T> = interface 41 function GetName: string; 42 function GetCount: SizeInt; 43 function GetItem(Index: SizeInt): T; 44 function Remove(constref AValue: T): SizeInt; 45 function Add(constref AValue: T): SizeInt; 46 function CreateBaseItem(Name: string = ''): T; 47 function GetNextAvailableName(Name: string): string; 48 function GetItemFields: TItemFields; 49 procedure SetItem(Index: SizeInt; AValue: T); 50 property Count: SizeInt read GetCount; 51 property Items[Index: SizeInt]: T read GetItem write SetItem; default; 52 end; 38 TBaseItemList = class; 53 39 54 40 { TItem } … … 87 73 class function GetClassSysName: string; virtual; 88 74 class function GetClassName: string; virtual; 89 function GetReferenceList(Index: Integer): IList<TItem>; virtual;75 function GetReferenceList(Index: Integer): TBaseItemList; virtual; 90 76 constructor Create; virtual; 91 77 end; … … 93 79 TItemClass = class of TItem; 94 80 95 IItemList = interface(IList<TItem>) 96 end; 81 { TBaseItemList } 82 83 TBaseItemList = class 84 public 85 type 86 TAddEvent = function (constref AValue: TItem): SizeInt of object; 87 TGetCountEvent = function: SizeInt of object; 88 TSetItemEvent = procedure(Index: SizeInt; AValue: TItem) of object; 89 TGetNameEvent = function: string of object; 90 TGetItemEvent = function(Index: SizeInt): TItem of object; 91 TGetItemFieldsEvent = function: TItemFields of object; 92 TRemoveEvent = function(constref AValue: TItem): SizeInt of object; 93 TGetNextAvailableNameEvent = function(Name: string): string of object; 94 TCreateItemEvent = function(Name: string = ''): TItem of object; 95 private 96 FOnAdd: TAddEvent; 97 FOnCreateItem: TCreateItemEvent; 98 FOnGetCount: TGetCountEvent; 99 FOnGetItem: TGetItemEvent; 100 FOnGetItemFields: TGetItemFieldsEvent; 101 FOnGetName: TGetNameEvent; 102 FOnGetNextAvailableName: TGetNextAvailableNameEvent; 103 FOnRemove: TRemoveEvent; 104 FOnSetItem: TSetItemEvent; 105 procedure SetItem(Index: SizeInt; AValue: TItem); 106 function GetItem(Index: SizeInt): TItem; 107 public 108 function GetName: string; 109 function GetCount: SizeInt; 110 function Remove(constref AValue: TItem): SizeInt; 111 function Add(constref AValue: TItem): SizeInt; 112 function CreateItem(Name: string = ''): TItem; 113 function GetNextAvailableName(Name: string): string; 114 function GetItemFields: TItemFields; 115 property Count: SizeInt read GetCount; 116 property Items[Index: SizeInt]: TItem read GetItem write SetItem; default; 117 property OnAdd: TAddEvent read FOnAdd write FOnAdd; 118 property OnGetCount: TGetCountEvent read FOnGetCount write FOnGetCount; 119 property OnSetItem: TSetItemEvent read FOnSetItem write FOnSetItem; 120 property OnGetItem: TGetItemEvent read FOnGetItem write FOnGetItem; 121 property OnGetName: TGetNameEvent read FOnGetName write FOnGetName; 122 property OnRemove: TRemoveEvent read FOnRemove write FOnRemove; 123 property OnGetItemFields: TGetItemFieldsEvent read FOnGetItemFields write FOnGetItemFields; 124 property OnGetNextAvailableName: TGetNextAvailableNameEvent read 125 FOnGetNextAvailableName write FOnGetNextAvailableName; 126 property OnCreateItem: TCreateItemEvent read FOnCreateItem 127 write FOnCreateItem; 128 end; 97 129 98 130 { TItemList } 99 131 100 TItemList<T: TItem> = class(TObjectList<T> , IList<TItem>)132 TItemList<T: TItem> = class(TObjectList<T>) 101 133 private 134 FBaseItemList: TBaseItemList; 102 135 procedure RecalculateNewId(Reset: Boolean); 103 136 procedure RecalculateItemsId; 104 function GetItem(Index: SizeInt): TItem; 105 procedure SetItem(Index: SizeInt; AValue: TItem); 106 protected 107 function GetCount: SizeInt; override; 137 function BaseGetItem(Index: SizeInt): TItem; 138 procedure BaseSetItem(Index: SizeInt; AValue: TItem); 139 function BaseAdd(constref AValue: TItem): SizeInt; 140 function BaseGetCount: SizeInt; 141 function BaseGetName(A: string): string; 142 function BaseRemove(constref AValue: TItem): SizeInt; 143 function BaseGetItemFields: TItemFields; 144 function BaseCreateItem(Name: string = ''): TItem; 108 145 public 109 146 NewId: Integer; 110 function GetName: string;111 function GetItemFields: TItemFields;112 function Remove(constref AValue: TItem): SizeInt;113 function Add(constref AValue: TItem): SizeInt; overload;114 147 function CreateItem(Name: string = ''): T; virtual; 115 function CreateBaseItem(Name: string = ''): TItem;116 148 function IncrementName(Name: string): string; 117 149 function GetNextAvailableName(Name: string): string; … … 126 158 procedure SaveToNode(Node: TDOMNode); virtual; 127 159 constructor Create(FreeObjects: Boolean = True); 128 function QueryInterface({$IFDEF FPC_HAS_CONSTREF}constref{$ELSE}const{$ENDIF} iid : tguid;out obj) : longint;{$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF}; 129 function _AddRef: Longint;{$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF}; 130 function _Release: Longint;{$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF}; 160 destructor Destroy; override; 161 property BaseItemList: TBaseItemList read FBaseItemList; 131 162 end; 132 163 … … 210 241 end; 211 242 212 function TItemList<T>. CreateBaseItem(Name: string): TItem;243 function TItemList<T>.BaseCreateItem(Name: string): TItem; 213 244 begin 214 245 Result := TItem(CreateItem(Name)); … … 247 278 begin 248 279 inherited; 280 FBaseItemList := TBaseItemList.Create; 281 FBaseItemList.OnAdd := BaseAdd; 282 FBaseItemList.OnGetCount := BaseGetCount; 283 FBaseItemList.OnSetItem := BaseSetItem; 284 FBaseItemList.OnGetItem := BaseGetItem; 285 FBaseItemList.OnRemove := BaseRemove; 286 FBaseItemList.OnGetItemFields := BaseGetItemFields; 287 FBaseItemList.OnCreateItem := BaseCreateItem; 288 //FBaseItemList.OnGetNextAvailableName := GetNextAvailableName; 289 //FBaseItemList.OnGetName := BaseGetName; 249 290 NewId := 1; 250 291 end; 251 292 252 function TItemList<T>.QueryInterface({$IFDEF FPC_HAS_CONSTREF}constref{$ELSE}const{$ENDIF} iid: tguid; out obj): LongInt; 253 {$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF}; 254 begin 255 if GetInterface(IID, Obj) then Result := 0 256 else Result := E_NOINTERFACE; 257 end; 258 259 function TItemList<T>._AddRef: LongInt; {$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF}; 260 begin 261 Result := -1; 262 end; 263 264 function TItemList<T>._Release: LongInt; {$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF}; 265 begin 266 Result := -1; 267 end; 268 269 function TItemList<T>.GetCount: SizeInt; 293 destructor TItemList<T>.Destroy; 294 begin 295 FreeAndNil(FBaseItemList); 296 inherited; 297 end; 298 299 function TItemList<T>.BaseGetCount: SizeInt; 270 300 begin 271 301 Result := Count; 272 302 end; 273 303 274 function TItemList<T>. GetName: string;304 function TItemList<T>.BaseGetName(A: string): string; 275 305 begin 276 306 Result := T.GetClassName; 277 307 end; 278 308 279 function TItemList<T>. GetItemFields: TItemFields;309 function TItemList<T>.BaseGetItemFields: TItemFields; 280 310 begin 281 311 Result := T.GetFields; 282 312 end; 283 313 284 function TItemList<T>. Remove(constref AValue: TItem): SizeInt;314 function TItemList<T>.BaseRemove(constref AValue: TItem): SizeInt; 285 315 begin 286 316 Result := inherited Remove(T(AValue)); 287 317 end; 288 318 289 function TItemList<T>. Add(constref AValue: TItem): SizeInt;319 function TItemList<T>.BaseAdd(constref AValue: TItem): SizeInt; 290 320 begin 291 321 Result := inherited Add(T(AValue)); … … 312 342 end; 313 343 314 function TItemList<T>. GetItem(Index: SizeInt): TItem;344 function TItemList<T>.BaseGetItem(Index: SizeInt): TItem; 315 345 begin 316 346 Result := inherited GetItem(Index); 317 347 end; 318 348 319 procedure TItemList<T>. SetItem(Index: SizeInt; AValue: TItem);349 procedure TItemList<T>.BaseSetItem(Index: SizeInt; AValue: TItem); 320 350 begin 321 351 inherited SetItem(Index, T(AValue)); … … 452 482 var 453 483 ReadId: Integer; 454 ReferenceList: IList<TItem>;484 ReferenceList: TBaseItemList; 455 485 begin 456 486 if Field.DataType = dtString then begin … … 471 501 if Field.DataType = dtReference then begin 472 502 ReadId := ReadInteger(Node, Field.SysName, 0); 473 ReferenceList := IList<TItem>(GetReferenceList(Field.Index));503 ReferenceList := GetReferenceList(Field.Index); 474 504 if (ReadId > 0) and Assigned(ReferenceList) then 475 505 SetValueReference(Field.Index, TItem(ReferenceList[ReadId])); … … 714 744 end; 715 745 716 function TItem.GetReferenceList(Index: Integer): IList<TItem>;746 function TItem.GetReferenceList(Index: Integer): TBaseItemList; 717 747 begin 718 748 Result := nil; … … 723 753 end; 724 754 755 { TBaseItemList } 756 757 procedure TBaseItemList.SetItem(Index: SizeInt; AValue: TItem); 758 begin 759 if Assigned(FOnSetItem) then FOnSetItem(Index, AValue) 760 else Exception.Create('Undefined SetItem handler'); 761 end; 762 763 function TBaseItemList.GetName: string; 764 begin 765 if Assigned(FOnGetName) then Result := FOnGetName 766 else Exception.Create('Undefined GetName handler'); 767 end; 768 769 function TBaseItemList.GetCount: SizeInt; 770 begin 771 if Assigned(FOnGetCount) then Result := FOnGetCount 772 else Exception.Create('Undefined GetCount handler'); 773 end; 774 775 function TBaseItemList.GetItem(Index: SizeInt): TItem; 776 begin 777 if Assigned(FOnGetItem) then Result := FOnGetItem(Index) 778 else Exception.Create('Undefined GetItem handler'); 779 end; 780 781 function TBaseItemList.Remove(constref AValue: TItem): SizeInt; 782 begin 783 if Assigned(FOnRemove) then Result := FOnRemove(AValue) 784 else Exception.Create('Undefined Remove handler'); 785 end; 786 787 function TBaseItemList.Add(constref AValue: TItem): SizeInt; 788 begin 789 if Assigned(FOnAdd) then Result := FOnAdd(AValue) 790 else Exception.Create('Undefined Add handler'); 791 end; 792 793 function TBaseItemList.CreateItem(Name: string): TItem; 794 begin 795 if Assigned(FOnCreateItem) then Result := FOnCreateItem(Name) 796 else Exception.Create('Undefined CreateItem handler'); 797 end; 798 799 function TBaseItemList.GetNextAvailableName(Name: string): string; 800 begin 801 if Assigned(FOnGetNextAvailableName) then Result := FOnGetNextAvailableName(Name) 802 else Exception.Create('Undefined GetNextAvailableName handler'); 803 end; 804 805 function TBaseItemList.GetItemFields: TItemFields; 806 begin 807 if Assigned(FOnGetItemFields) then Result := FOnGetItemFields 808 else Exception.Create('Undefined GetItemFields handler'); 809 end; 810 725 811 end. 726 812 -
trunk/Player.pas
r346 r349 100 100 procedure GetValue(Index: Integer; out Value); override; 101 101 procedure SetValue(Index: Integer; var Value); override; 102 function GetReferenceList(Index: Integer): IList<TItem>; override;102 function GetReferenceList(Index: Integer): TBaseItemList; override; 103 103 class function GetClassSysName: string; override; 104 104 class function GetClassName: string; override; … … 1257 1257 end; 1258 1258 1259 function TPlayer.GetReferenceList(Index: Integer): IList<TItem>;1260 begin 1261 if Index = 2 then Result := TGame(Game).GameSystem.Nations 1259 function TPlayer.GetReferenceList(Index: Integer): TBaseItemList; 1260 begin 1261 if Index = 2 then Result := TGame(Game).GameSystem.Nations.BaseItemList 1262 1262 else Result := nil; 1263 1263 end;
Note:
See TracChangeset
for help on using the changeset viewer.