Changeset 64 for trunk/UEngine.pas


Ignore:
Timestamp:
Jan 7, 2023, 12:10:51 AM (17 months ago)
Author:
chronos
Message:
  • Modified: Store app settings in registry.
  • Fixed: Full screen initialization.
  • Fixed: Automatic language detection.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UEngine.pas

    r62 r64  
    44
    55uses
    6   Dialogs, Classes, SysUtils, Graphics, SpecializedMatrix,
     6  Dialogs, Classes, SysUtils, Graphics, SpecializedMatrix, URegistry,
    77  IntfGraphics, FPImage, LCLType, SpecializedBitmap, GraphType, Math, URectangle,
    88  Syncobjs, UThreading, Forms, DateUtils, UAudioSystem, XMLConf, DOM,
     
    143143    destructor Destroy; override;
    144144    procedure Assign(Source: TPlayer);
    145     procedure LoadConfig(Config: TXMLConfig; Path: string);
    146     procedure SaveConfig(Config: TXMLConfig; Path: string);
     145    procedure LoadFromRegistry(Context: TRegistryContext);
     146    procedure SaveToRegistry(Context: TRegistryContext);
    147147    property Exploded: Boolean read FExploded write SetExploded;
    148148  end;
     
    154154    function AddNew: TPlayer;
    155155    procedure Assign(Players: TPlayers);
    156     procedure LoadConfig(Config: TXMLConfig; Path: string);
    157     procedure SaveConfig(Config: TXMLConfig; Path: string);
     156    procedure LoadFromRegistry(Context: TRegistryContext);
     157    procedure SaveToRegistry(Context: TRegistryContext);
    158158    function GetAliveCount: Integer;
    159159    function GetWinner: TPlayer;
     
    210210    procedure Redraw;
    211211    function IsInsideHouses(Pos: TPoint): Boolean;
    212     procedure InitPlayerPool;
    213212    procedure InitPlayers;
    214213    procedure CheckGameEnd;
     
    243242    procedure NewGame;
    244243    procedure NewRound;
    245     procedure LoadConfig(Config: TXMLConfig; Path: string);
    246     procedure SaveConfig(Config: TXMLConfig; Path: string);
    247244    procedure KeyUp(Key: Word);
    248245    procedure KeyDown(Key: Word);
     246    procedure LoadFromRegistry(Context: TRegistryContext);
     247    procedure SaveToRegistry(Context: TRegistryContext);
     248    procedure InitPlayerPool;
    249249    property Bitmap: TBitmap read FBitmap write SetBitmap;
    250250    property Active: Boolean read FActive write SetActive;
     
    317317end;
    318318
    319 procedure TPlayers.SaveConfig(Config: TXMLConfig; Path: string);
    320 var
    321   I: Integer;
    322 begin
    323   Config.SetValue(DOMString(Path + '/Count'), Count);
    324   for I := 0 to Count - 1 do
    325     Items[I].SaveConfig(Config, Path + '/Player' + IntToStr(I));
     319procedure TPlayers.LoadFromRegistry(Context: TRegistryContext);
     320var
     321  Player: TPlayer;
     322begin
     323  for Player in Self do begin
     324    Player.LoadFromRegistry(TRegistryContext.Create(Context.RootKey, Context.Key + '\' + IntToStr(Player.Id)));
     325  end;
     326end;
     327
     328procedure TPlayers.SaveToRegistry(Context: TRegistryContext);
     329var
     330  Player: TPlayer;
     331begin
     332  for Player in Self do begin
     333    Player.SaveToRegistry(TRegistryContext.Create(Context.RootKey, Context.Key + '\' + IntToStr(Player.Id)));
     334  end;
    326335end;
    327336
     
    348357    TopScore := Score;
    349358    Result := Items[I];
    350   end;
    351 end;
    352 
    353 procedure TPlayers.LoadConfig(Config: TXMLConfig; Path: string);
    354 var
    355   I: Integer;
    356   NewCount: Integer;
    357 begin
    358   NewCount := Config.GetValue(DOMString(Path + '/Count'), 0);
    359   while Count > NewCount do Delete(Count - 1);
    360   while Count < NewCount do Add(TPlayer.Create);
    361   for I := 0 to Count - 1 do begin
    362     Items[I].Engine := Engine;
    363     Items[I].Id := I;
    364     Items[I].LoadConfig(Config, Path + '/Player' + IntToStr(I));
    365359  end;
    366360end;
     
    965959end;
    966960
    967 procedure TPlayer.LoadConfig(Config: TXMLConfig; Path: string);
    968 begin
    969   with Config do begin
    970     Self.Name := string(GetValue(DOMString(Path + '/Name'), UnicodeString(Name)));
    971     Color1 := GetValue(DOMString(Path + '/Color1'), Color1);
    972     Color2 := GetValue(DOMString(Path + '/Color2'), Color2);
    973     Enabled := GetValue(DOMString(Path + '/Enabled'), Enabled);
    974     Keys.Left := GetValue(DOMString(Path + '/Keys/Left'), Keys.Left);
    975     Keys.Right := GetValue(DOMString(Path + '/Keys/Right'), Keys.Right);
    976     Keys.Down := GetValue(DOMString(Path + '/Keys/Down'), Keys.Down);
    977     Keys.Up := GetValue(DOMString(Path + '/Keys/Up'), Keys.Up);
    978     Keys.Shoot := GetValue(DOMString(Path + '/Keys/Shoot'), Keys.Shoot);
    979   end;
    980   InitTanks;
    981 end;
    982 
    983 procedure TPlayer.SaveConfig(Config: TXMLConfig; Path: string);
    984 begin
    985   with Config do begin
    986     SetValue(DOMString(Path + '/Name'), DOMString(Self.Name));
    987     SetValue(DOMString(Path + '/Color1'), Color1);
    988     SetValue(DOMString(Path + '/Color2'), Color2);
    989     SetValue(DOMString(Path + '/Enabled'), Enabled);
    990     SetValue(DOMString(Path + '/Keys/Left'), Keys.Left);
    991     SetValue(DOMString(Path + '/Keys/Right'), Keys.Right);
    992     SetValue(DOMString(Path + '/Keys/Down'), Keys.Down);
    993     SetValue(DOMString(Path + '/Keys/Up'), Keys.Up);
    994     SetValue(DOMString(Path + '/Keys/Shoot'), Keys.Shoot);
     961procedure TPlayer.LoadFromRegistry(Context: TRegistryContext);
     962begin
     963  with TRegistryEx.Create do
     964  try
     965    CurrentContext := Context;
     966    Name := ReadStringWithDefault('Name', Name);
     967    Color1 := ReadIntegerWithDefault('Color1', Color1);
     968    Color2 := ReadIntegerWithDefault('Color2', Color2);
     969    Enabled := ReadBoolWithDefault('Enabled', Enabled);
     970    Keys.Left := ReadIntegerWithDefault('KeysLeft', Keys.Left);
     971    Keys.Right := ReadIntegerWithDefault('KeyRight', Keys.Right);
     972    Keys.Down := ReadIntegerWithDefault('KeyDown', Keys.Down);
     973    Keys.Up := ReadIntegerWithDefault('KeyUp', Keys.Up);
     974    Keys.Shoot := ReadIntegerWithDefault('KeyShoot', Keys.Shoot);
     975  finally
     976    Free;
     977  end;
     978end;
     979
     980procedure TPlayer.SaveToRegistry(Context: TRegistryContext);
     981begin
     982  with TRegistryEx.Create do
     983  try
     984    CurrentContext := Context;
     985    WriteString('Name', Name);
     986    WriteInteger('Color1', Color1);
     987    WriteInteger('Color2', Color2);
     988    WriteBool('Enabled', Enabled);
     989    WriteInteger('KeysLeft', Keys.Left);
     990    WriteInteger('KeyRight', Keys.Right);
     991    WriteInteger('KeyDown', Keys.Down);
     992    WriteInteger('KeyUp', Keys.Up);
     993    WriteInteger('KeyShoot', Keys.Shoot);
     994  finally
     995    Free;
    995996  end;
    996997end;
     
    17281729end;
    17291730
    1730 procedure TEngine.LoadConfig(Config: TXMLConfig; Path: string);
    1731 begin
    1732   PlayerPool.LoadConfig(Config, Path + '/Players');
    1733 end;
    1734 
    1735 procedure TEngine.SaveConfig(Config: TXMLConfig; Path: string);
    1736 begin
    1737   PlayerPool.SaveConfig(Config, Path + '/Players');
     1731procedure TEngine.LoadFromRegistry(Context: TRegistryContext);
     1732begin
     1733  with TRegistryEx.Create do
     1734  try
     1735    CurrentContext := Context;
     1736    PlayerPool.LoadFromRegistry(TRegistryContext.Create(Context.RootKey, Context.Key + '\Players'));
     1737  finally
     1738    Free;
     1739  end;
     1740end;
     1741
     1742procedure TEngine.SaveToRegistry(Context: TRegistryContext);
     1743begin
     1744  with TRegistryEx.Create do
     1745  try
     1746    CurrentContext := Context;
     1747
     1748    PlayerPool.SaveToRegistry(TRegistryContext.Create(Context.RootKey, Context.Key + '\Players'));
     1749  finally
     1750    Free;
     1751  end;
    17381752end;
    17391753
Note: See TracChangeset for help on using the changeset viewer.