Ignore:
Timestamp:
May 7, 2020, 12:46:55 AM (5 years ago)
Author:
chronos
Message:
  • Added: New Global unit with global constants.
  • Modified: Multiple occurence of string constants used for subdirectories replaced by functions.
Location:
trunk/Packages/CevoComponents
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/CevoComponents/Directories.pas

    r169 r189  
    1010
    1111function LocalizedFilePath(const Path: string): string;
    12 procedure InitUnit;
     12procedure UnitInit;
    1313function GetSavedDir(Home: Boolean = False): string;
    1414function GetMapsDir(Home: Boolean = False): string;
     15function GetGraphicsDir: string;
     16function GetSoundsDir: string;
    1517
    1618
     
    3032
    3133  if Lang = '' then begin
    32       for i := 1 to Paramcount - 1 do
    33         if (ParamStrUTF8(i) = '--LANG') or (ParamStrUTF8(i) = '-l') or
    34           (ParamStrUTF8(i) = '--lang') then
     34    for i := 1 to Paramcount - 1 do
     35      if (ParamStrUTF8(i) = '--LANG') or (ParamStrUTF8(i) = '-l') or
     36        (ParamStrUTF8(i) = '--lang') then
    3537          Lang := ParamStrUTF8(i + 1);
    3638  end;
     
    5961end;
    6062
    61 procedure InitUnit;
     63procedure UnitInit;
    6264var
    6365  AppDataDir: string;
     
    113115end;
    114116
     117function GetGraphicsDir: string;
     118begin
     119  Result := HomeDir + 'Graphics';
     120end;
     121
     122function GetSoundsDir: string;
     123begin
     124  Result := HomeDir + 'Sounds';
     125end;
     126
    115127end.
  • trunk/Packages/CevoComponents/DrawDlg.pas

    r174 r189  
    176176  // ButtonDownSound, ButtonUpSound: string;
    177177begin
    178   // ButtonDownSound:=Sounds.Lookup('BUTTON_DOWN');
    179   // ButtonUpSound:=Sounds.Lookup('BUTTON_UP');
     178  // ButtonDownSound := Sounds.Lookup('BUTTON_DOWN');
     179  // ButtonUpSound := Sounds.Lookup('BUTTON_UP');
    180180  for cix := 0 to ComponentCount - 1 do
    181181    if Components[cix] is TButtonBase then
    182182    begin
    183183      TButtonBase(Components[cix]).Graphic := GrExt[HGrSystem].Data;
    184       // if ButtonDownSound<>'*' then
    185       // DownSound:=HomeDir+'Sounds' + DirectorySeparator + ButtonDownSound + '.wav';
    186       // if ButtonUpSound<>'*' then
    187       // UpSound:=HomeDir+'Sounds' + DirectorySeparator + ButtonUpSound + '.wav';
     184      // if ButtonDownSound <> '*' then
     185      // DownSound := GetSoundsDir + DirectorySeparator + ButtonDownSound + '.wav';
     186      // if ButtonUpSound <> '*' then
     187      // UpSound := GetSoundsDir + DirectorySeparator + ButtonUpSound + '.wav';
    188188      if Components[cix] is TButtonA then
    189189        TButtonA(Components[cix]).Font := UniFont[ftButton];
  • trunk/Packages/CevoComponents/ScreenTools.pas

    r188 r189  
    188188
    189189  UniFont: array [TFontType] of TFont;
    190   AppRegistryKey: string = '\SOFTWARE\C-evo';
     190  Gamma: Integer; // global gamma correction (cent)
    191191
    192192procedure UnitInit;
    193193procedure UnitDone;
     194procedure InitGammaLookupTable;
     195
    194196
    195197implementation
     
    204206  {$ENDIF}
    205207
    206   Gamma: Integer; // global gamma correction (cent)
    207   GammaLookupTable: array [0 .. 255] of Byte;
     208  GammaLookupTable: array [0..255] of Byte;
    208209
    209210{$IFDEF WINDOWS}
     
    468469    Source := TBitmap.Create;
    469470    Source.PixelFormat := pf24bit;
    470     FileName := HomeDir + 'Graphics' + DirectorySeparator + Name;
     471    FileName := GetGraphicsDir + DirectorySeparator + Name;
    471472    if not LoadGraphicFile(Source, FileName) then begin
    472473      Result := -1;
     
    13521353    with MainTexture do begin
    13531354      MainTextureAge := Age;
    1354       LoadGraphicFile(Image, HomeDir + 'Graphics' + DirectorySeparator +
     1355      LoadGraphicFile(Image, GetGraphicsDir + DirectorySeparator +
    13551356        'Texture' + IntToStr(Age + 1) + '.jpg');
    13561357      clBevelLight := Colors.Canvas.Pixels[clkAge0 + Age, cliBevelLight];
     
    13911392
    13921393  if Sounds = nil then Sounds := TStringTable.Create;
    1393   if not Sounds.LoadFromFile(HomeDir + 'Sounds' + DirectorySeparator + 'sound.txt') then
     1394  if not Sounds.LoadFromFile(GetSoundsDir + DirectorySeparator + 'sound.txt') then
    13941395  begin
    13951396    FreeAndNil(Sounds);
     
    14701471
    14711472procedure UnitInit;
    1472 var
    1473   Reg: TRegistry;
    1474 begin
    1475   Reg := TRegistry.Create;
    1476   with Reg do
    1477     try
    1478       OpenKey(AppRegistryKey, True);
    1479       if ValueExists('Gamma') then
    1480         Gamma := ReadInteger('Gamma')
    1481       else
    1482       begin
    1483         Gamma := 100;
    1484         WriteInteger('Gamma', Gamma);
    1485       end;
    1486       if ValueExists('Locale') then
    1487         LocaleCode := ReadString('Locale')
    1488       else
    1489         LocaleCode := '';
    1490     finally
    1491       Free;
    1492     end;
    1493 
    1494   if Gamma <> 100 then InitGammaLookupTable;
     1473begin
     1474  Gamma := 100;
     1475  InitGammaLookupTable;
    14951476
    14961477  {$IFDEF WINDOWS}
     
    15121493  Templates := TBitmap.Create;
    15131494  Templates.PixelFormat := pf24bit;
    1514   LoadGraphicFile(Templates, HomeDir + 'Graphics' + DirectorySeparator +
     1495  LoadGraphicFile(Templates, GetGraphicsDir + DirectorySeparator +
    15151496    'Templates.png', gfNoGamma);
    15161497  Colors := TBitmap.Create;
    15171498  Colors.PixelFormat := pf24bit;
    1518   LoadGraphicFile(Colors, HomeDir + 'Graphics' + DirectorySeparator + 'Colors.png');
     1499  LoadGraphicFile(Colors, GetGraphicsDir + DirectorySeparator + 'Colors.png');
    15191500  Paper := TBitmap.Create;
    15201501  Paper.PixelFormat := pf24bit;
    1521   LoadGraphicFile(Paper, HomeDir + 'Graphics' + DirectorySeparator + 'Paper.jpg');
     1502  LoadGraphicFile(Paper, GetGraphicsDir + DirectorySeparator + 'Paper.jpg');
    15221503  BigImp := TBitmap.Create;
    15231504  BigImp.PixelFormat := pf24bit;
    1524   LoadGraphicFile(BigImp, HomeDir + 'Graphics' + DirectorySeparator + 'Icons.png');
     1505  LoadGraphicFile(BigImp, GetGraphicsDir + DirectorySeparator + 'Icons.png');
    15251506  MainTexture.Image := TBitmap.Create;
    15261507  MainTextureAge := -2;
     
    15321513procedure UnitDone;
    15331514var
    1534   Reg: TRegistry;
    15351515  I: integer;
    15361516begin
    1537   Reg := TRegistry.Create;
    1538   with Reg do
    1539     try
    1540       OpenKey(AppRegistryKey, True);
    1541       WriteString('Locale', LocaleCode);
    1542       WriteInteger('Gamma', Gamma);
    1543       if FullScreen then WriteInteger('ScreenMode', 1)
    1544         else WriteInteger('ScreenMode', 0);
    1545     finally
    1546       Free;
    1547     end;
    1548 
    15491517  RestoreResolution;
    15501518  for I := 0 to nGrExt - 1 do begin
  • trunk/Packages/CevoComponents/Sound.pas

    r174 r189  
    290290  Result := (WavFileName <> '') and (WavFileName[1] <> '[') and (WavFileName <> '*');
    291291  if Result then
    292     // SndPlaySound(pchar(HomeDir+'Sounds' +DirectorySeparator+WavFileName+'.wav'),SND_ASYNC)
    293     PlaySound(HomeDir + 'Sounds' + DirectorySeparator + WavFileName);
     292    // SndPlaySound(pchar(GetSoundsDir + DirectorySeparator + WavFileName + '.wav'), SND_ASYNC)
     293    PlaySound(GetSoundsDir + DirectorySeparator + WavFileName);
    294294{$ENDIF}
    295295end;
     
    307307  Assert(WavFileName[1] <> '[');
    308308  if (WavFileName <> '') and (WavFileName[1] <> '[') and (WavFileName <> '*') then
    309     PrepareSound(HomeDir + 'Sounds' + DirectorySeparator + WavFileName);
     309    PrepareSound(GetSoundsDir + DirectorySeparator + WavFileName);
    310310{$ENDIF}
    311311end;
Note: See TracChangeset for help on using the changeset viewer.