Changeset 298 for trunk/Forms


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.
Location:
trunk/Forms
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormItem.pas

    r296 r298  
    9191  J: Integer;
    9292  Control: TControl;
     93  ReferenceList: TItemList;
     94  ReferenceItem: TItem;
    9395begin
    9496  Fields := Item.GetFields;
     
    111113      end;
    112114    end
     115    else if DataType = dtReference then begin
     116      TComboBox(Control).Items.BeginUpdate;
     117      try
     118        TComboBox(Control).Items.Clear;
     119        ReferenceList := Item.GetReferenceList(Index);
     120        if Assigned(ReferenceList) then
     121          for J := 0 to ReferenceList.Count - 1 do
     122            TComboBox(Control).Items.AddObject(TItem(ReferenceList[J]).Name, ReferenceList[J]);
     123        ReferenceItem := TItem(Item.GetValueReference(Index));
     124        TComboBox(Control).ItemIndex := TComboBox(Control).Items.IndexOfObject(ReferenceItem);
     125      finally
     126        TComboBox(Control).Items.EndUpdate;
     127      end;
     128    end
    113129    else raise Exception.Create(Format(SUnsupportedDataType, [DataTypeStr[DataType]]));
    114130  end;
     
    131147    else if DataType = dtBoolean then Item.SetValueBoolean(Index, TCheckBox(Control).Checked)
    132148    else if DataType = dtEnumeration then Item.SetValueEnumeration(Index, TUndefinedEnum(TComboBox(Control).ItemIndex))
     149    else if DataType = dtReference then begin
     150      if TComboBox(Control).ItemIndex <> -1 then
     151        Item.SetValueReference(Index, TItem(TComboBox(Control).Items.Objects[TComboBox(Control).ItemIndex]))
     152        else Item.SetValueReference(Index, nil);
     153    end
    133154    else raise Exception.Create(Format(SUnsupportedDataType, [DataTypeStr[DataType]]));
    134155  end;
     
    173194      TComboBox(NewControl).Style := csDropDownList;
    174195    end else
     196    if DataType = dtReference then begin
     197      NewControl := TComboBox.Create(nil);
     198      NewControl.Width := 200;
     199      TComboBox(NewControl).Style := csDropDownList;
     200    end else
    175201    if DataType = dtBoolean then begin
    176202      NewControl := TCheckBox.Create(nil);
  • trunk/Forms/UFormList.lfm

    r295 r298  
    1111  OnCreate = FormCreate
    1212  OnShow = FormShow
    13   LCLVersion = '2.0.0.4'
     13  LCLVersion = '2.0.2.0'
    1414  object ListView1: TListView
    1515    Left = 0
  • 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;
  • trunk/Forms/UFormNew.pas

    r288 r298  
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    99  ComCtrls, Spin, ExtCtrls, ActnList, ExtDlgs, Menus, UGame, UGeometry, UPlayer,
    10   UGameServer, UServerList, UMap, UFormPlayers, UGameSystem;
     10  UGameServer, UServerList, UMap, UGameSystem, UFormList;
    1111
    1212type
     
    144144    MapPreviewRedrawPending: Boolean;
    145145    NewRandSeed: Cardinal;
    146     FormPlayers: TFormPlayers;
     146    FormPlayers: TFormList;
    147147    procedure LoadGame(Game: TGame);
    148148    procedure SaveGame(Game: TGame);
     
    385385  if Assigned(FServer) then begin
    386386    Load(FServer);
    387     FormPlayers.Players := FServer.Game.Players;
     387    FormPlayers.List := FServer.Game.Players;
    388388  end else begin
    389     FormPlayers.Players := nil;
     389    FormPlayers.List := nil;
    390390  end;
    391391end;
     
    402402  GamePreview.GeneratePlayers := False;
    403403  GamePreview.New;
    404   GamePreview.CurrentPlayer := GamePreview.Players.First;
     404  GamePreview.CurrentPlayer := TPlayer(GamePreview.Players.First);
    405405  Bitmap := Image1.Picture.Bitmap;
    406406  Bitmap.SetSize(Image1.Width, Image1.Height);
     
    534534  FormChat.Align := alClient;
    535535  FormChat.Show;
    536   FormPlayers := TFormPlayers.Create(nil);
     536  FormPlayers := TFormList.Create(nil);
    537537  FormPlayers.MinItemCount := MinPlayerCount;
    538538  FormPlayers.MaxItemCount := MaxPlayerCount;
  • trunk/Forms/UFormPlayer.lfm

    r295 r298  
    11object FormPlayer: TFormPlayer
    2   Left = 470
     2  Left = 1304
    33  Height = 338
    4   Top = 157
     4  Top = 318
    55  Width = 543
    66  Caption = 'Player'
     
    1414  OnShow = FormShow
    1515  Position = poMainFormCenter
    16   LCLVersion = '2.0.0.4'
     16  LCLVersion = '2.0.2.0'
    1717  object Label1: TLabel
    1818    Left = 20
Note: See TracChangeset for help on using the changeset viewer.