Ignore:
Timestamp:
Nov 3, 2021, 11:22:02 AM (3 years ago)
Author:
chronos
Message:
  • Modified: Merged changes from trunk r404.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/highdpi/LocalPlayer/UKeyBindings.pas

    r303 r405  
    1717    ShortCut: TShortCut;
    1818    ShortCut2: TShortCut;
     19    DefaultShortCut: TShortCut;
     20    DefaultShortCut2: TShortCut;
    1921    function Test(AShortCut: TShortCut): Boolean;
     22    procedure Assign(Source: TKeyBinding);
     23    procedure SetDefault;
    2024  end;
    2125
     
    2327
    2428  TKeyBindings = class(TFPGObjectList<TKeyBinding>)
     29  private
    2530  public
    2631    function AddItem(const ShortName, FullName: string; ShortCut: TShortCut; ShortCut2: TShortCut = 0): TKeyBinding; overload;
     
    2934    procedure LoadFromRegistry(RootKey: HKEY; Key: string);
    3035    procedure SaveToRegistry(RootKey: HKEY; Key: string);
     36    procedure LoadToStrings(Strings: TStrings);
     37    procedure Assign(Source: TKeyBindings);
     38    procedure ResetToDefault;
     39    procedure RemoveShortCut(ShortCut: TShortCut);
    3140  end;
    3241
     
    5261  BStay: TKeyBinding;
    5362  BNoOrders: TKeyBinding;
     63  BPrevUnit: TKeyBinding;
     64  BNextUnit: TKeyBinding;
    5465  BCancel: TKeyBinding;
    5566  BPillage: TKeyBinding;
     
    123134end;
    124135
     136procedure TKeyBinding.Assign(Source: TKeyBinding);
     137begin
     138  ShortName := Source.ShortName;
     139  FullName := Source.FullName;
     140  ShortCut := Source.ShortCut;
     141  ShortCut2 := Source.ShortCut2;
     142  DefaultShortCut := Source.DefaultShortCut;
     143  DefaultShortCut2 := Source.DefaultShortCut2;
     144end;
     145
     146procedure TKeyBinding.SetDefault;
     147begin
     148  ShortCut := DefaultShortCut;
     149  ShortCut2 := DefaultShortCut2;
     150end;
     151
    125152{ TKeyBindings }
    126153
     
    133160  Result.ShortCut := ShortCut;
    134161  Result.ShortCut2 := ShortCut2;
     162  Result.DefaultShortCut := ShortCut;
     163  Result.DefaultShortCut2 := ShortCut2;
    135164  Add(Result);
    136165end;
     
    207236end;
    208237
     238procedure TKeyBindings.LoadToStrings(Strings: TStrings);
     239var
     240  I: Integer;
     241  Text: string;
     242begin
     243  Strings.Clear;
     244  for I := 0 to Count - 1 do begin
     245    Text:= '';
     246    if Items[I].ShortCut <> 0 then
     247      Text:= Text + ShortCutToText(Items[I].ShortCut);
     248    if Items[I].ShortCut2 <> 0 then begin
     249      if Text <> '' then Text := Text + ', ';
     250      Text:= Text + ShortCutToText(Items[I].ShortCut2);
     251    end;
     252    if Text <> '' then Text := Items[I].FullName + ' (' + Text + ')'
     253      else Text := Items[I].FullName;
     254    Strings.Add(Text);
     255  end;
     256end;
     257
     258procedure TKeyBindings.Assign(Source: TKeyBindings);
     259var
     260  I: Integer;
     261begin
     262  while Count < Source.Count do
     263    Add(TKeyBinding.Create);
     264  while Count > Source.Count do
     265    Delete(Count - 1);
     266  for I := 0 to Count - 1 do
     267    Items[I].Assign(Source.Items[I]);
     268end;
     269
     270procedure TKeyBindings.ResetToDefault;
     271var
     272  I: Integer;
     273begin
     274  for I := 0 to Count - 1 do
     275    Items[I].SetDefault;
     276end;
     277
     278procedure TKeyBindings.RemoveShortCut(ShortCut: TShortCut);
     279var
     280  I: Integer;
     281begin
     282  for I := 0 to Count - 1 do begin
     283    if Items[I].ShortCut = ShortCut then Items[I].ShortCut := 0;
     284    if Items[I].ShortCut2 = ShortCut then Items[I].ShortCut2 := 0;
     285  end;
     286end;
     287
    209288
    210289initialization
     
    231310  BStay := AddItem('Stay', 'Stay', 'S');
    232311  BNoOrders := AddItem('NoOrders', 'No orders', 'Space');
     312  BPrevUnit := AddItem('PrevUnit', 'Previous unit', 'Del');
     313  BNextUnit := AddItem('NextUnit', 'Next unit', 'Ins');
    233314  BCancel := AddItem('Cancel', 'Cancel', 'Ctrl+C');
    234315  BPillage := AddItem('Pillage', 'Pillage', 'Ctrl+P');
Note: See TracChangeset for help on using the changeset viewer.