- Timestamp:
- Mar 2, 2021, 10:45:43 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Integrated.lpi
r288 r292 333 333 </Unit40> 334 334 <Unit41> 335 <Filename Value=" UKeyBindings.pas"/>335 <Filename Value="LocalPlayer\UKeyBindings.pas"/> 336 336 <IsPartOfProject Value="True"/> 337 337 </Unit41> -
trunk/LocalPlayer/Term.pas
r291 r292 3403 3403 i, j: integer; 3404 3404 begin 3405 KeyBindings.LoadFromRegistry(HKEY_CURRENT_USER, AppRegistryKey + '\KeyBindings'); 3405 3406 UpdateKeyShortcuts; 3406 3407 … … 3507 3508 I: Integer; 3508 3509 begin 3510 KeyBindings.SaveToRegistry(HKEY_CURRENT_USER, AppRegistryKey + '\KeyBindings'); 3509 3511 MainFormKeyDown := nil; 3510 3512 FreeAndNil(sb); -
trunk/LocalPlayer/UKeyBindings.pas
r291 r292 6 6 7 7 uses 8 Classes, SysUtils, fgl, LCLProc, LCLType, Menus ;8 Classes, SysUtils, fgl, LCLProc, LCLType, Menus, Registry; 9 9 10 10 type … … 23 23 24 24 TKeyBindings = class(TFPGObjectList<TKeyBinding>) 25 public 25 26 function AddItem(const ShortName, FullName: string; ShortCut: TShortCut; ShortCut2: TShortCut = 0): TKeyBinding; overload; 26 27 function AddItem(const ShortName, FullName: string; ShortCutText: string; ShortCutText2: string = ''): TKeyBinding; overload; 27 28 function Search(ShortName: string): TKeyBinding; 28 procedure LoadFrom File(FileName: string);29 procedure SaveTo File(FileName: string);29 procedure LoadFromRegistry(RootKey: HKEY; Key: string); 30 procedure SaveToRegistry(RootKey: HKEY; Key: string); 30 31 end; 31 32 … … 151 152 end; 152 153 153 procedure TKeyBindings.LoadFromFile(FileName: string); 154 var 155 Lines: TStringList; 154 procedure TKeyBindings.LoadFromRegistry(RootKey: HKEY; Key: string); 155 var 156 156 I: Integer; 157 KeyBinding: TKeyBinding; 158 begin 159 Lines := TStringList.Create; 160 Lines.NameValueSeparator := '='; 157 Registry: TRegistry; 158 Text: string; 159 begin 160 Registry := TRegistry.Create; 161 Registry.RootKey := RootKey; 162 with Registry do 161 163 try 162 Lines.LoadFromFile(FileName); 163 for I := 0 to Lines.Count - 1 do begin 164 KeyBinding := Search(Lines.Names[I]); 165 if Assigned(KeyBinding) then begin 166 KeyBinding.ShortCut := TextToShortCut(Lines.ValueFromIndex[I]); 164 OpenKey(Key, True); 165 for I := 0 to Count - 1 do begin 166 Text := ''; 167 if ValueExists(Items[I].ShortName) then begin 168 Text := ReadString(Items[I].ShortName); 169 if Pos(',', Text) > 0 then begin 170 Items[I].ShortCut2 := TextToShortCut(Copy(Text, Pos(',', Text) + 1, MaxInt)); 171 Items[I].ShortCut := TextToShortCut(Copy(Text, 1, Pos(',', Text) - 1)); 172 end else begin 173 Items[I].ShortCut := TextToShortCut(Text); 174 Items[I].ShortCut2 := 0; 175 end; 176 end else begin 177 Text := ShortCutToText(Items[I].ShortCut); 178 if Items[I].ShortCut2 <> 0 then Text := Text + ',' + ShortCutToText(Items[I].ShortCut2); 179 WriteString(Items[I].ShortName, Text); 167 180 end; 168 181 end; 169 182 finally 170 FreeAndNil(Lines); 171 end; 172 end; 173 174 procedure TKeyBindings.SaveToFile(FileName: string); 175 var 176 Lines: TStringList; 183 Free; 184 end; 185 end; 186 187 procedure TKeyBindings.SaveToRegistry(RootKey: HKEY; Key: string); 188 var 177 189 I: Integer; 178 begin 179 Lines := TStringList.Create; 180 Lines.NameValueSeparator := '='; 190 Registry: TRegistry; 191 Text: string; 192 begin 193 Registry := TRegistry.Create; 194 Registry.RootKey := RootKey; 195 with Registry do 181 196 try 197 OpenKey(Key, True); 182 198 for I := 0 to Count - 1 do begin 183 Lines.Add(TKeyBinding(Items[I]).ShortName + '=' + ShortCutToText(TKeyBinding(Items[I]).ShortCut)); 199 Text := ShortCutToText(Items[I].ShortCut); 200 if Items[I].ShortCut2 <> 0 then Text := Text + ',' + ShortCutToText(Items[I].ShortCut2); 201 WriteString(Items[I].ShortName, Text); 184 202 end; 185 Lines.SaveToFile(FileName);186 203 finally 187 Free AndNil(Lines);204 Free; 188 205 end; 189 206 end; -
trunk/Start.pas
r290 r292 166 166 167 167 uses 168 Global, Directories, Direct, ScreenTools, Inp, Back, Settings, UPixelPointer, 169 UKeyBindings; 168 Global, Directories, Direct, ScreenTools, Inp, Back, Settings, UPixelPointer; 170 169 171 170 {$R *.lfm} … … 226 225 PlayerAutoDiff: array [1 .. 5] of integer = (1, 1, 2, 2, 3); 227 226 EnemyAutoDiff: array [1 .. 5] of integer = (4, 3, 2, 1, 1); 228 KeyBindingsFileName = 'KeyBindings.txt';229 227 230 228 { TMiniMap } … … 438 436 PlayerSlot: TPlayerSlot; 439 437 AIBrains: TBrains; 440 KeyBindingsAbsoluteFileName: string;441 438 begin 442 439 PlayerSlots := TPlayerSlots.Create; … … 449 446 LoadConfig; 450 447 LoadAssets; 451 KeyBindingsAbsoluteFileName := DataDir + DirectorySeparator + KeyBindingsFileName;452 if FileExists(KeyBindingsAbsoluteFileName) then KeyBindings.LoadFromFile(KeyBindingsAbsoluteFileName)453 else begin454 ForceDirectories(ExtractFileDir(KeyBindingsAbsoluteFileName));455 KeyBindings.SaveToFile(KeyBindingsAbsoluteFileName);456 end;457 448 458 449 ActionsOffered := [maConfig, maManual, maCredits, maWeb]; … … 1979 1970 Shift: TShiftState); 1980 1971 begin 1981 if KeyToShortCut(Key, Shift) = BHelp.ShortCutthen1972 if KeyToShortCut(Key, Shift) = VK_F1 then 1982 1973 DirectHelp(cStartHelp); 1983 1974 end;
Note:
See TracChangeset
for help on using the changeset viewer.