Ignore:
Timestamp:
Jul 10, 2019, 5:35:15 PM (5 years ago)
Author:
chronos
Message:
  • Added: New item list type reference. Used in players for reference to selected nation.
  • Modified: New game players selection migrated to dynamic item/list forms.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormList.pas

    r290 r298  
    5151    procedure UpdateListViewColumns;
    5252  public
     53    MinItemCount: Integer;
     54    MaxItemCount: Integer;
    5355    procedure UpdateInterface;
    5456    procedure UpdateList;
     
    7072  SRemoveItems = 'Remove items';
    7173  SRemoveItemsQuery = 'Do you want to remove selected items?';
    72   SNewItem = 'New item';
     74  SNew = 'New';
    7375
    7476{ TFormList }
     
    8385      for I := ListView1.Items.Count - 1 downto 0 do
    8486        if ListView1.Items[I].Selected then begin
     87          if List.Count <= MinItemCount then Break;
    8588          ListView1.Items[I].Selected := False;
    8689          List.Remove(TItem(ListView1.Items[I].Data));
     
    99102  if Assigned(ListView1.Selected) then
    100103  with TItem(ListView1.Selected.Data) do begin
    101     TempEntry := List.GetItemClass.Create;
     104    TempEntry := List.CreateItem;
    102105    TempEntry.Assign(TItem(ListView1.Selected.Data));
    103106    FormItem := TFormItem.Create(Self);
     
    121124  FormItem: TFormItem;
    122125begin
    123   TempEntry := List.GetItemClass.Create;
     126  if (MaxItemCount <> -1) and (List.Count >= MaxItemCount) then Exit;
     127
     128  TempEntry := List.CreateItem;
    124129  FormItem := TFormItem.Create(Self);
    125130  try
    126     TempEntry.Name := SNewItem;
     131    TempEntry.Name := SNew + ' ' + LowerCase(List.GetItemClass.GetClassName);
    127132    FormItem.Item := TempEntry;
    128133    if FormItem.ShowModal = mrOk then begin
     
    143148  FormItem: TFormItem;
    144149begin
    145   TempEntry := List.GetItemClass.Create;
     150  if (MaxItemCount <> -1) and (List.Count >= MaxItemCount) then Exit;
     151
     152  TempEntry := List.CreateItem;
    146153  TempEntry.Assign(TItem(ListView1.Selected.Data));
    147154  FormItem := TFormItem.Create(Self);
     
    183190  for I := 0 to ToolBar1.ButtonCount - 1 do
    184191    ToolBar1.Buttons[I].Hint := ToolBar1.Buttons[I].Caption;
     192  MinItemCount := 0;
     193  MaxItemCount := -1;
    185194end;
    186195
     
    197206  var DefaultDraw: Boolean);
    198207var
     208  ItemFields: TItemFields;
    199209  ItemField: TItemField;
    200210begin
    201   ItemField := TItem(Item.Data).GetField(SubItem);
    202   if ItemField.DataType = dtColor then
    203   with ListView1.Canvas do begin
    204     Brush.Color := TItem(Item.Data).GetValueColor(ItemField.Index);
    205     Brush.Style := bsSolid;
    206     FillRect(Item.DisplayRectSubItem(1, drBounds));
    207   end;
    208   ItemField.Free;
     211  ItemFields := TItem(Item.Data).GetFields;
     212  try
     213    ItemField := ItemFields[SubItem];
     214    if ItemField.DataType = dtColor then
     215    with ListView1.Canvas do begin
     216      Brush.Color := TItem(Item.Data).GetValueColor(ItemField.Index);
     217      Brush.Style := bsSolid;
     218      FillRect(Item.DisplayRectSubItem(SubItem, drBounds));
     219    end;
     220  finally
     221    ItemFields.Free;
     222  end;
    209223end;
    210224
     
    272286procedure TFormList.UpdateInterface;
    273287begin
    274   ARemove.Enabled := Assigned(FList) and Assigned(ListView1.Selected);
     288  ARemove.Enabled := Assigned(FList) and Assigned(ListView1.Selected) and (List.Count > MinItemCount);
    275289  AModify.Enabled := Assigned(FList) and Assigned(ListView1.Selected);
    276   AAdd.Enabled := Assigned(FList);
     290  AAdd.Enabled := Assigned(FList) and ((MaxItemCount = -1) or ((MaxItemCount <> -1) and (List.Count < MaxItemCount)));
     291  AClone.Enabled := Assigned(FList) and ((MaxItemCount = -1) or ((MaxItemCount <> -1) and (List.Count < MaxItemCount)));
    277292  ASelectAll.Enabled := ListView1.Items.Count > 0;
    278293end;
Note: See TracChangeset for help on using the changeset viewer.