Changeset 89 for trunk/Game.pas


Ignore:
Timestamp:
Jun 7, 2024, 4:35:46 PM (3 months ago)
Author:
chronos
Message:
  • Added: Allow to select color palette in new game dialog.
  • Fixed: Use scrollboxes in options dialogs.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Game.pas

    r86 r89  
    1111  TMoveDirection = (drNone, drLeft, drUp, drRight, drDown);
    1212  TTileAction = (taNone, taMove, taMerge, taAppear);
     13  TColorPalette = (cpOrangeYellow, cpGreenYellow, cpPinkBlue, cpBlueCyan,
     14    cpGreenCyan, cpPinkRed);
    1315
    1416  { TTile }
     
    109111    FCanUndo: Boolean;
    110112    FBoardUndo: TBoard;
     113    FColorPalette: TColorPalette;
    111114    FSkin: TTileSkin;
    112115    function GetTileColor(Value: Integer): TColor;
     
    117120    procedure RenderTile(Canvas: TCanvas; Tile: TTile; TileRect: TRect; WithText: Boolean);
    118121    procedure GameOver;
     122    procedure SetColorPalette(AValue: TColorPalette);
    119123    procedure SetSkin(AValue: TTileSkin);
    120124    procedure Win;
     
    162166    property RecordHistory: Boolean read FRecordHistory write SetRecordHistory;
    163167    property Skin: TTileSkin read FSkin write SetSkin;
     168    property ColorPalette: TColorPalette read FColorPalette write SetColorPalette;
    164169  end;
    165170
     
    169174var
    170175  SkinText: array[TTileSkin] of string;
     176  ColorPaletteText: array[TColorPalette] of string;
    171177
    172178const
     
    187193  STileShouldBeEmpty = 'Tile should be empty';
    188194
     195  // Color palette
     196  SOrangeYellow = 'Orange - yellow';
     197  SGreenYellow = 'Green - yellow';
     198  SPinkBlue = 'Pink - blue';
     199  SBlueCyan = 'Blue - cyan';
     200  SGreenCyan = 'Green - cyan';
     201  SPinkRed = 'Pink - red';
    189202
    190203procedure Translate;
     
    194207
    195208uses
    196   Core, MetaCanvas;
     209  Core, MetaCanvas, PixelPointer;
    197210
    198211procedure Translate;
     
    203216  SkinText[tsRoman] := SSkinRoman;
    204217  SkinText[tsBinary] := SSkinBinary;
     218
     219  ColorPaletteText[cpOrangeYellow] := SOrangeYellow;
     220  ColorPaletteText[cpGreenYellow] := SGreenYellow;
     221  ColorPaletteText[cpPinkBlue] := SPinkBlue;
     222  ColorPaletteText[cpBlueCyan] := SBlueCyan;
     223  ColorPaletteText[cpGreenCyan] := SGreenCyan;
     224  ColorPaletteText[cpPinkRed] := SPinkRed;
    205225end;
    206226
     
    267287  GameStep.Board.Clear;
    268288  GameStep.Skin := Game.Skin;
     289  GameStep.ColorPalette := Game.ColorPalette;
    269290  GameStep.Score := 0;
    270291  for I := 0 to Length(InitialTiles) - 1 do
     
    293314begin
    294315  FreeAndNil(Moves);
    295   inherited Destroy;
     316  inherited;
    296317end;
    297318
     
    442463begin
    443464  Size := Point(0, 0);
    444   inherited Destroy;
     465  inherited;
    445466end;
    446467
     
    519540  if Running and Assigned(FOnGameOver) then FOnGameOver(Self);
    520541  Running := False;
     542end;
     543
     544procedure TGame.SetColorPalette(AValue: TColorPalette);
     545begin
     546  if FColorPalette = AValue then Exit;
     547  FColorPalette := AValue;
     548  DoPaint;
    521549end;
    522550
     
    579607  FRunning := Source.FRunning;
    580608  Skin := Source.Skin;
     609  ColorPalette := Source.ColorPalette;
    581610end;
    582611
     
    11741203    WriteBool('RecordHistory', RecordHistory);
    11751204    WriteInteger('Skin', Integer(Skin));
     1205    WriteInteger('ColorPalette', Integer(ColorPalette));
    11761206    FBoardUndo.SaveToRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\BoardUndo'));
    11771207    Board.SaveToRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\Board'));
     
    11981228    RecordHistory := ReadBoolWithDefault('RecordHistory', False);
    11991229    Skin := TTileSkin(ReadIntegerWithDefault('Skin', Integer(tsPowerOfTwo)));
     1230    ColorPalette := TColorPalette(ReadIntegerWithDefault('ColorPalette', Integer(cpOrangeYellow)));
    12001231    FBoardUndo.LoadFromRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\BoardUndo'));
    12011232    Board.LoadFromRegistry(Reg, TRegistryContext.Create(RegContext.RootKey, RegContext.Key + '\Board'));
     
    12291260
    12301261function TGame.GetTileColor(Value: Integer): TColor;
     1262var
     1263  Color: TPixel32;
    12311264begin
    12321265  if Core.Core.ThemeManager1.Theme.Name = 'Dark' then begin
     
    12631296    end;
    12641297  end;
     1298
     1299  Color.RGB := Result;
     1300  case ColorPalette of
     1301    cpOrangeYellow: Result := TColor(TPixel32.CreateRGB(Color.R, Color.G, Color.B));
     1302    cpGreenYellow: Result := TColor(TPixel32.CreateRGB(Color.R, Color.B, Color.G));
     1303    cpPinkBlue: Result := TColor(TPixel32.CreateRGB(Color.B, Color.R, Color.G));
     1304    cpBlueCyan: Result := TColor(TPixel32.CreateRGB(Color.B, Color.G, Color.R));
     1305    cpGreenCyan: Result := TColor(TPixel32.CreateRGB(Color.G, Color.B, Color.R));
     1306    cpPinkRed: Result := TColor(TPixel32.CreateRGB(Color.G, Color.R, Color.B));
     1307  end;
    12651308end;
    12661309
Note: See TracChangeset for help on using the changeset viewer.