Changeset 391


Ignore:
Timestamp:
Jan 5, 2025, 9:08:52 PM (3 days ago)
Author:
chronos
Message:
  • Fixed: Add new players with different colors.
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/Forms/FormList.pas

    r373 r391  
    7272  SRemoveItems = 'Remove items';
    7373  SRemoveItemsQuery = 'Do you want to remove selected items?';
    74   SNew = 'New';
    7574
    7675{ TFormList }
     
    129128  FormItem := TFormItem.Create(Self);
    130129  try
    131     TempEntry.Name := FList.GetNextAvailableName(SNew + ' ' + LowerCase(List.GetName));
     130    TempEntry.Name := FList.GetNextAvailableName(List.GetName);
    132131    FormItem.Item := TempEntry;
    133132    if FormItem.ShowModal = mrOk then begin
  • trunk/Packages/Common/ItemList.pas

    r359 r391  
    368368  NewName: string);
    369369begin
    370   NewName := Name;
     370  NewName := Name + ' 1';
    371371  while Assigned(FindByName(NewName)) do
    372372    NewName := IncrementName(NewName);
  • trunk/Packages/Common/Languages/FormList.cs.po

    r364 r391  
    1212"X-Generator: Poedit 3.5\n"
    1313
    14 #: formlist.snew
    15 msgid "New"
    16 msgstr "Nová"
    17 
    1814#: formlist.sremoveitems
    1915msgid "Remove items"
  • trunk/Packages/Common/Languages/FormList.pot

    r355 r391  
    11msgid ""
    22msgstr "Content-Type: text/plain; charset=UTF-8"
    3 
    4 #: formlist.snew
    5 msgid "New"
    6 msgstr ""
    73
    84#: formlist.sremoveitems
  • trunk/Player.pas

    r349 r391  
    137137  public
    138138    Game: TObject; //TGame;
     139    function GetPlayerByColor(Color: TColor): TPlayer;
     140    function GetUnusedColor: TColor;
    139141    procedure Assign(Source: TItemList<TPlayer>); override;
    140142    procedure New(Name: string; Color: TColor; Mode: TPlayerMode);
     
    206208  SDefensive = 'Defensive';
    207209
     210const
     211  PlayerColors: array[0..11] of TColor = (clBlue, clRed, clGreen, clYellow,
     212    clFuchsia, clAqua, clOlive, clMaroon, clNavy, clPurple, clTeal, clGray);
     213
    208214function ComparePointer(constref Item1, Item2: Integer): Integer;
    209215begin
     
    502508end;
    503509
     510function TPlayers.GetPlayerByColor(Color: TColor): TPlayer;
     511var
     512  I: Integer;
     513begin
     514  I := 0;
     515  while (I < Count) do begin
     516    if Assigned(Items[I]) and (Items[I].Color = Color) then Break;
     517    Inc(I);
     518  end;
     519  if I < Count then Result := Items[I]
     520    else Result := nil;
     521end;
     522
     523function TPlayers.GetUnusedColor: TColor;
     524var
     525  I: Integer;
     526begin
     527  Result := clBlack;
     528  for I := 0 to Length(PlayerColors) - 1 do
     529    if not Assigned(GetPlayerByColor(PlayerColors[I])) then begin
     530      Result := PlayerColors[I];
     531      Exit;
     532    end;
     533end;
     534
    504535procedure TPlayers.Assign(Source: TItemList<TPlayer>);
    505536var
     
    526557  Result := inherited;
    527558  Result.Game := Game;
     559  Result.Color := GetUnusedColor;
    528560end;
    529561
Note: See TracChangeset for help on using the changeset viewer.