Ignore:
Timestamp:
Jul 10, 2019, 10:46:20 PM (5 years ago)
Author:
chronos
Message:
  • Added: Hide player options applicatble only for computer player.
  • Modified: Better selection of player and nation colors.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormItem.pas

    r298 r300  
    2424    FItem: TItem;
    2525    DataControls: TFPGObjectList<TControl>;
     26    DataLabels: TFPGObjectList<TLabel>;
     27    procedure ControlChangeExecute(Sender: TObject);
    2628    procedure SetItem(AValue: TItem);
    2729    procedure LoadData(Item: TItem); virtual;
     
    2931    procedure InitControls;
    3032  public
     33    procedure UpdateInterface;
    3134    property Item: TItem read FItem write SetItem;
    3235  end;
     
    6063  Core.ThemeManager1.UseTheme(Self);
    6164  DataControls := TFPGObjectList<TControl>.Create;
     65  DataLabels := TFPGObjectList<TLabel>.Create;
    6266end;
    6367
    6468procedure TFormItem.FormDestroy(Sender: TObject);
    6569begin
     70  DataLabels.Free;
    6671  DataControls.Free;
    6772end;
     
    7075begin
    7176  Core.PersistentForm.Load(Self);
     77end;
     78
     79procedure TFormItem.ControlChangeExecute(Sender: TObject);
     80begin
     81  UpdateInterface;
    7282end;
    7383
     
    130140  end;
    131141  Fields.Free;
     142  UpdateInterface;
    132143end;
    133144
     
    165176  Y: Integer;
    166177begin
    167   Y := 8;
     178  DataControls.Clear;
     179  DataLabels.Clear;
     180  Y := Scale96ToScreen(8);
    168181  Fields := Item.GetFields;
    169182  for I := 0 to Fields.Count - 1 do
    170183  with TItemField(Fields[I]) do begin
    171184    NewLabel := TLabel.Create(Self);
    172     NewLabel.Left := 8;
     185    NewLabel.Left := Scale96ToScreen(8);
    173186    NewLabel.Top := Y;
    174187    NewLabel.Parent := Self;
    175188    NewLabel.Caption := Name + ':';
    176189    NewLabel.Visible := True;
     190    DataLabels.Add(NewLabel);
    177191
    178192    if DataType = dtInteger then begin
    179193      NewControl := TSpinEdit.Create(nil);
    180       NewControl.Width := 100;
     194      NewControl.Width := Scale96ToScreen(100);
    181195      TSpinEdit(NewControl).MaxValue := High(Integer);
    182196    end else
    183197    if DataType = dtString then begin
    184198      NewControl := TEdit.Create(nil);
    185       NewControl.Width := 300;
     199      NewControl.Width := Scale96ToScreen(300);
    186200    end else
    187201    if DataType = dtColor then begin
    188202      NewControl := TColorBox.Create(nil);
    189       NewControl.Width := 200;
     203      NewControl.Width := Scale96ToScreen(200);
     204      TColorBox(NewControl).Style := [cbStandardColors, cbExtendedColors,
     205        cbCustomColor, cbPrettyNames];
    190206    end else
    191207    if DataType = dtEnumeration then begin
    192208      NewControl := TComboBox.Create(nil);
    193       NewControl.Width := 200;
     209      NewControl.Width := Scale96ToScreen(200);
    194210      TComboBox(NewControl).Style := csDropDownList;
     211      TComboBox(NewControl).OnChange := ControlChangeExecute;
    195212    end else
    196213    if DataType = dtReference then begin
    197214      NewControl := TComboBox.Create(nil);
    198       NewControl.Width := 200;
     215      NewControl.Width := Scale96ToScreen(200);
    199216      TComboBox(NewControl).Style := csDropDownList;
    200217    end else
     
    203220    end else
    204221      raise Exception.Create(Format(SUnsupportedDataType, [DataTypeStr[DataType]]));
    205     NewControl.Left := 150;
     222    NewControl.Left := Scale96ToScreen(150);
    206223    NewControl.Top := Y;
    207224    NewControl.Parent := Self;
     
    210227    NewControl.Visible := True;
    211228    DataControls.Add(NewControl);
    212     Y := Y + 40;
     229    Y := Y + Scale96ToScreen(30);
    213230  end;
    214231  Fields.Free;
    215232end;
    216233
     234procedure TFormItem.UpdateInterface;
     235var
     236  I: Integer;
     237  Fields: TItemFields;
     238  Condition: Boolean;
     239begin
     240  Fields := Item.GetFields;
     241  try
     242    for I := 0 to Fields.Count - 1 do
     243    with TItemField(Fields[I]) do begin
     244      if VisibleIfIndex > 0 then begin
     245        if TItemField(Fields[VisibleIfIndex]).DataType = dtEnumeration then begin
     246          Condition := TComboBox(DataControls[VisibleIfIndex]).ItemIndex > 0;
     247        end else Condition := False;
     248      end;
     249      DataControls[I].Visible := (VisibleIfIndex = 0) or ((VisibleIfIndex > 0) and Condition);
     250      DataLabels[I].Visible := DataControls[I].Visible;
     251    end;
     252  finally
     253    Fields.Free;
     254  end;
     255end;
     256
    217257end.
    218258
Note: See TracChangeset for help on using the changeset viewer.