Changeset 405 for branches/highdpi/LocalPlayer/UKeyBindings.pas
- Timestamp:
- Nov 3, 2021, 11:22:02 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/highdpi/LocalPlayer/UKeyBindings.pas
r303 r405 17 17 ShortCut: TShortCut; 18 18 ShortCut2: TShortCut; 19 DefaultShortCut: TShortCut; 20 DefaultShortCut2: TShortCut; 19 21 function Test(AShortCut: TShortCut): Boolean; 22 procedure Assign(Source: TKeyBinding); 23 procedure SetDefault; 20 24 end; 21 25 … … 23 27 24 28 TKeyBindings = class(TFPGObjectList<TKeyBinding>) 29 private 25 30 public 26 31 function AddItem(const ShortName, FullName: string; ShortCut: TShortCut; ShortCut2: TShortCut = 0): TKeyBinding; overload; … … 29 34 procedure LoadFromRegistry(RootKey: HKEY; Key: string); 30 35 procedure SaveToRegistry(RootKey: HKEY; Key: string); 36 procedure LoadToStrings(Strings: TStrings); 37 procedure Assign(Source: TKeyBindings); 38 procedure ResetToDefault; 39 procedure RemoveShortCut(ShortCut: TShortCut); 31 40 end; 32 41 … … 52 61 BStay: TKeyBinding; 53 62 BNoOrders: TKeyBinding; 63 BPrevUnit: TKeyBinding; 64 BNextUnit: TKeyBinding; 54 65 BCancel: TKeyBinding; 55 66 BPillage: TKeyBinding; … … 123 134 end; 124 135 136 procedure TKeyBinding.Assign(Source: TKeyBinding); 137 begin 138 ShortName := Source.ShortName; 139 FullName := Source.FullName; 140 ShortCut := Source.ShortCut; 141 ShortCut2 := Source.ShortCut2; 142 DefaultShortCut := Source.DefaultShortCut; 143 DefaultShortCut2 := Source.DefaultShortCut2; 144 end; 145 146 procedure TKeyBinding.SetDefault; 147 begin 148 ShortCut := DefaultShortCut; 149 ShortCut2 := DefaultShortCut2; 150 end; 151 125 152 { TKeyBindings } 126 153 … … 133 160 Result.ShortCut := ShortCut; 134 161 Result.ShortCut2 := ShortCut2; 162 Result.DefaultShortCut := ShortCut; 163 Result.DefaultShortCut2 := ShortCut2; 135 164 Add(Result); 136 165 end; … … 207 236 end; 208 237 238 procedure TKeyBindings.LoadToStrings(Strings: TStrings); 239 var 240 I: Integer; 241 Text: string; 242 begin 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; 256 end; 257 258 procedure TKeyBindings.Assign(Source: TKeyBindings); 259 var 260 I: Integer; 261 begin 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]); 268 end; 269 270 procedure TKeyBindings.ResetToDefault; 271 var 272 I: Integer; 273 begin 274 for I := 0 to Count - 1 do 275 Items[I].SetDefault; 276 end; 277 278 procedure TKeyBindings.RemoveShortCut(ShortCut: TShortCut); 279 var 280 I: Integer; 281 begin 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; 286 end; 287 209 288 210 289 initialization … … 231 310 BStay := AddItem('Stay', 'Stay', 'S'); 232 311 BNoOrders := AddItem('NoOrders', 'No orders', 'Space'); 312 BPrevUnit := AddItem('PrevUnit', 'Previous unit', 'Del'); 313 BNextUnit := AddItem('NextUnit', 'Next unit', 'Ins'); 233 314 BCancel := AddItem('Cancel', 'Cancel', 'Ctrl+C'); 234 315 BPillage := AddItem('Pillage', 'Pillage', 'Ctrl+P');
Note:
See TracChangeset
for help on using the changeset viewer.