Ignore:
Timestamp:
Jan 7, 2023, 12:10:51 AM (23 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/Forms/UFormMain.pas

    r63 r64  
    3636    TimerDraw: TTimer;
    3737    TimerEngineTick: TTimer;
    38     XMLConfig1: TXMLConfig;
    3938    procedure AAboutExecute(Sender: TObject);
    4039    procedure AExitExecute(Sender: TObject);
     
    8382procedure TFormMain.TimerDrawTimer(Sender: TObject);
    8483begin
    85   Application.ProcessMessages;
    8684  if not Drawing then
    8785  try
     
    112110
    113111procedure TFormMain.LoadConfig;
    114 begin
    115   if not FileExists(XMLConfig1.Filename) then Exit;
    116 
    117   with XMLConfig1 do begin
    118     FullScreenEnabled := GetValue(DOMString('LanguageCode'), FullScreenEnabled);
    119   end;
    120 
    121   if Assigned(Engine) then Engine.LoadConfig(XMLConfig1, '');
     112var
     113  LangCode: string;
     114begin
     115  with TRegistryEx.Create do
     116  try
     117    CurrentContext := Core.ApplicationInfo.GetRegistryContext;
     118
     119    if ValueExists('LanguageCode') then begin
     120      LangCode := ReadStringWithDefault('LanguageCode', '');
     121      Core.Translator1.Language := Core.Translator1.Languages.SearchByCode(LangCode);
     122    end else Core.Translator1.Language := Core.Translator1.Languages.SearchByCode('');
     123    Engine.LoadFromRegistry(CurrentContext);
     124  finally
     125    Free;
     126  end;
    122127end;
    123128
    124129procedure TFormMain.SaveConfig;
    125130begin
    126   with XMLConfig1 do begin
    127     SetValue(DOMString('LanguageCode'), FullScreenEnabled);
    128   end;
    129   if Assigned(Engine) then Engine.SaveConfig(XMLConfig1, '');
    130   ForceDirectories(ExtractFileDir(XMLConfig1.Filename));
    131   XMLConfig1.Flush;
     131  with TRegistryEx.Create do
     132  try
     133    CurrentContext := Core.ApplicationInfo.GetRegistryContext;
     134
     135    if Assigned(Core.Translator1.Language) and (Core.Translator1.Language.Code <> '') then
     136      WriteString('LanguageCode', Core.Translator1.Language.Code)
     137      else DeleteValue('LanguageCode');
     138    Engine.SaveToRegistry(CurrentContext);
     139  finally
     140    Free;
     141  end;
    132142end;
    133143
     
    150160
    151161procedure TFormMain.FormCreate(Sender: TObject);
    152 begin
    153   XMLConfig1.Filename := GetAppConfigDir(False) + 'Config.xml';
     162const
     163  UnixLanguagesDir = '/usr/share/Tunneler/Languages';
     164begin
     165  {$IFDEF UNIX}
     166  // If installed in UNIX system then use installation directory for po files
     167  if not DirectoryExists(Core.Translator1.POFilesFolder) and DirectoryExists(UnixLanguagesDir) then
     168    Core.Translator1.POFilesFolder := UnixLanguagesDir;
     169  {$ENDIF}
     170
     171  Image1.ControlStyle := Image1.ControlStyle + [csOpaque];
    154172  FullScreenEnabled := True;
    155173
     
    162180  DoubleBuffered := False;
    163181  Engine := TEngine.Create(nil);
     182  LoadConfig;
     183  Engine.InitPlayerPool;
    164184  Engine.Bitmap := Image1.Picture.Bitmap;
    165   Core.Translator1.Language := Core.Translator1.Languages.SearchByCode('cs');
    166   LoadConfig;
    167185  Engine.NewGame;
     186  Image1Resize(Self);
    168187  Engine.Active := True;
    169   Image1Resize(Self);
    170   Image1.ControlStyle := Image1.ControlStyle + [csOpaque];
    171188end;
    172189
     
    178195procedure TFormMain.FormDestroy(Sender: TObject);
    179196begin
     197  SaveConfig;
    180198  TimerDraw.Enabled := False;
    181199  FreeAndNil(PersistentForm);
     
    218236begin
    219237  PersistentForm.Save(Self);
    220   SaveConfig;
    221238end;
    222239
     
    249266  PersistentForm.Load(Self, False, True);
    250267  FullScreenEnabled := PersistentForm.FormFullScreen;
    251   PersistentForm.SetFullScreen(FullScreenEnabled);
     268  //PersistentForm.SetFullScreen(FullScreenEnabled);
    252269  UpdateInterface;
    253270end;
Note: See TracChangeset for help on using the changeset viewer.