unit uGameDetails;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  StdCtrls, ExtCtrls, ComCtrls, IniFiles, ToolWin, Buttons, GR32_Image;

type
  TFormGameDetails = class(TForm)
    PageControlGameInfo: TPageControl;
    TabSheetGameInfo: TTabSheet;
    LabelManufacturer: TLabel;
    Manufacturer: TLabel;
    LabelYear: TLabel;
    Year: TLabel;
    LabelAudioChannels: TLabel;
    AudioChannels: TLabel;
    LabelAudioSamples: TLabel;
    AudioSamples: TLabel;
    LabelDriverStatus: TLabel;
    LabelSoundStatus: TLabel;
    LabelColorStatus: TLabel;
    DriverStatus: TLabel;
    SoundStatus: TLabel;
    ColorStatus: TLabel;
    LabelCategory: TLabel;
    Category: TLabel;
    LabelMerged: TLabel;
    Merged: TLabel;
    LabelName: TLabel;
    Name: TLabel;
    LabelCloneOf: TLabel;
    CloneOf: TLabel;
    LabelVersionAdded: TLabel;
    VersionAdded: TLabel;
    LabelDriverName: TLabel;
    DriverName: TLabel;
    LabelGameSize: TLabel;
    GameSize: TLabel;
    LabelPlayed: TLabel;
    Played: TLabel;
    LabelPlayTime: TLabel;
    PlayTime: TLabel;
    LabelMediaType: TLabel;
    MediaType: TLabel;
    LabelSamplesFile: TLabel;
    SamplesFile: TLabel;
    TabSheetGameFiles: TTabSheet;
    GameROMsList: TListView;
    LabelNumberPlayers: TLabel;
    NumberPlayers: TLabel;
    LabelSaveState: TLabel;
    SaveState: TLabel;
    LabelDescription: TLabel;
    ImageGameIcon: TImage;
    ButtonClose: TButton;
    TopImage: TImage32;
    LabelBios: TLabel;
    Bios: TLabel;
    LabelEmulationStatus: TLabel;
    EmulationStatus: TLabel;
    GraphicStatus: TLabel;
    LabelGraphicStatus: TLabel;
    CocktailStatus: TLabel;
    LabelCocktailStatus: TLabel;
    ProtectionStatus: TLabel;
    LabelProtectionStatus: TLabel;
    Screen1GroupBox: TGroupBox;
    LabelScreenType1: TLabel;
    ScreenType1: TLabel;
    LabelRotation1: TLabel;
    Rotation1: TLabel;
    Resolution1: TLabel;
    LabelResolution1: TLabel;
    LabelRefreshRate1: TLabel;
    RefreshRate1: TLabel;
    ControlTypeGroupBox: TGroupBox;
    ControlTypes: TLabel;
    Screen2GroupBox: TGroupBox;
    LabelScreenType2: TLabel;
    ScreenType2: TLabel;
    LabelRotation2: TLabel;
    Rotation2: TLabel;
    Resolution2: TLabel;
    LabelResolution2: TLabel;
    LabelRefreshRate2: TLabel;
    RefreshRate2: TLabel;
    Screen3GroupBox: TGroupBox;
    LabelScreenType3: TLabel;
    ScreenType3: TLabel;
    LabelRotation3: TLabel;
    Rotation3: TLabel;
    Resolution3: TLabel;
    LabelResolution3: TLabel;
    LabelRefreshRate3: TLabel;
    RefreshRate3: TLabel;
    Screen4GroupBox: TGroupBox;
    LabelScreenType4: TLabel;
    ScreenType4: TLabel;
    LabelRotation4: TLabel;
    Rotation4: TLabel;
    Resolution4: TLabel;
    LabelResolution4: TLabel;
    LabelRefreshRate4: TLabel;
    RefreshRate4: TLabel;
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure FormShow(Sender: TObject);
    procedure ButtonCloseClick(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    GetROMsFiles: Boolean;
  end;

var
  FormGameDetails: TFormGameDetails;

implementation

uses uMain, uFilesUtil, uCommon;

{$R *.DFM}

procedure TFormGameDetails.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if ((Key = #27) or (Key = #13)) then
     Close;
end;

procedure TFormGameDetails.FormShow(Sender: TObject);

  function FillBlank(const InfoString: String): String;
  begin
    if InfoString <> '' then
       Result:= InfoString
    else
       Result:= '-';
  end;

  function CheckRotation(const RotationData: SmallInt): String;
  begin
    case RotationData of
      -1: Result:= '-';
       1: Result:= aOrientation[RotationData];
    else
      Result:= IntToStr(RotationData);
    end;
  end;

begin
  FormMain.LoadTopBar(TopImage, 'games.png');
  FormMain.GetGameIcon(FormMain.IL_StandardIconsLarge, FormMain.IL_StandardIconsStandard, FormMain.IL_StandardIconsSmall, FormMain.GameInfoData.eImageIndex, ImageGameIcon.Picture.Icon);

  LabelMediaType.Font.Style:= [fsBold];
  LabelYear.Font.Style:= [fsBold];
  LabelManufacturer.Font.Style:= [fsBold];
  LabelSaveState.Font.Style:= [fsBold];

  LabelCategory.Font.Style:= [fsBold];
  LabelVersionAdded.Font.Style:= [fsBold];
  LabelAudioChannels.Font.Style:= [fsBold];
  LabelAudioSamples.Font.Style:= [fsBold];
  LabelSamplesFile.Font.Style:= [fsBold];

  LabelScreenType1.Font.Style:= [fsBold];
  LabelRotation1.Font.Style:= [fsBold];
  LabelResolution1.Font.Style:= [fsBold];
  LabelRefreshRate1.Font.Style:= [fsBold];

  LabelScreenType2.Font.Style:= [fsBold];
  LabelRotation2.Font.Style:= [fsBold];
  LabelResolution2.Font.Style:= [fsBold];
  LabelRefreshRate2.Font.Style:= [fsBold];

  LabelScreenType3.Font.Style:= [fsBold];
  LabelRotation3.Font.Style:= [fsBold];
  LabelResolution3.Font.Style:= [fsBold];
  LabelRefreshRate3.Font.Style:= [fsBold];

  LabelScreenType4.Font.Style:= [fsBold];
  LabelRotation4.Font.Style:= [fsBold];
  LabelResolution4.Font.Style:= [fsBold];
  LabelRefreshRate4.Font.Style:= [fsBold];

  LabelDriverStatus.Font.Style:= [fsBold];
  LabelEmulationStatus.Font.Style:= [fsBold];
  LabelColorStatus.Font.Style:= [fsBold];
  LabelSoundStatus.Font.Style:= [fsBold];
  LabelGraphicStatus.Font.Style:= [fsBold];
  LabelCocktailStatus.Font.Style:= [fsBold];
  LabelProtectionStatus.Font.Style:= [fsBold];

  LabelName.Font.Style:= [fsBold];
  LabelCloneOf.Font.Style:= [fsBold];
  LabelDriverName.Font.Style:= [fsBold];
  LabelBios.Font.Style:= [fsBold];
  LabelMerged.Font.Style:= [fsBold];

  LabelGameSize.Font.Style:= [fsBold];
  LabelPlayTime.Font.Style:= [fsBold];
  LabelPlayed.Font.Style:= [fsBold];
  LabelNumberPlayers.Font.Style:= [fsBold];

  if FormMain.SystemID_Number = 2 then
     LabelMerged.Caption:= 'Game Index'; // for ZiNc

  MediaType.Caption:= 'ROMs';
  case FormMain.GameInfoData.eMediaType of
    1: MediaType.Caption:= MediaType.Caption+'+CHD';
    2: MediaType.Caption:= MediaType.Caption+'+LD';
  end;
  Year.Caption:= FillBlank(FormMain.GameInfoData.eYear);
  Manufacturer.Caption:= FillBlank(FormMain.GameInfoData.eManufacturer);
  SaveState.Caption:= FillBlank(aSaveState[FormMain.GameInfoData.eSaveState]);

  Category.Caption:= FillBlank(FormMain.GameInfoData.eCategory);
  VersionAdded.Caption:= FillBlank(FormMain.GameInfoData.eVersionAdded);

  AudioChannels.Caption:= FillBlank(aAudioChannels[FormMain.GameInfoData.eAudioChannels]);
  AudioSamples.Caption:= FillBlank(aAudioSamples[FormMain.GameInfoData.eAudioSamples]);
  SamplesFile.Caption:= FillBlank(FormMain.GameInfoData.eAudioSampleName);

  ScreenType1.Caption:= FillBlank(aScreenType[FormMain.GameInfoData.eScreenType1]);
  Rotation1.Caption:= CheckRotation(FormMain.GameInfoData.eScreenRotation1);
  Resolution1.Caption:= FillBlank(FormMain.MountResolution(FormMain.GameInfoData.eResolutionWidth1, FormMain.GameInfoData.eResolutionHeight1, FormMain.GameInfoData.eScreenRotation1, False));
  RefreshRate1.Caption:= FillBlank(FormMain.GameInfoData.eRefreshRate1);
  if RefreshRate1.Caption <> '-' then
     RefreshRate1.Caption:= RefreshRate1.Caption+' Hz';

  ScreenType2.Caption:= FillBlank(aScreenType[FormMain.GameInfoData.eScreenType2]);
  Rotation2.Caption:= CheckRotation(FormMain.GameInfoData.eScreenRotation2);
  Resolution2.Caption:= FillBlank(FormMain.MountResolution(FormMain.GameInfoData.eResolutionWidth2, FormMain.GameInfoData.eResolutionHeight2, FormMain.GameInfoData.eScreenRotation2, False));
  RefreshRate2.Caption:= FillBlank(FormMain.GameInfoData.eRefreshRate2);
  if RefreshRate2.Caption <> '-' then
     RefreshRate2.Caption:= RefreshRate2.Caption+' Hz';

  ScreenType3.Caption:= FillBlank(aScreenType[FormMain.GameInfoData.eScreenType3]);
  Rotation3.Caption:= CheckRotation(FormMain.GameInfoData.eScreenRotation3);
  Resolution3.Caption:= FillBlank(FormMain.MountResolution(FormMain.GameInfoData.eResolutionWidth3, FormMain.GameInfoData.eResolutionHeight3, FormMain.GameInfoData.eScreenRotation3, False));
  RefreshRate3.Caption:= FillBlank(FormMain.GameInfoData.eRefreshRate3);
  if RefreshRate3.Caption <> '-' then
     RefreshRate3.Caption:= RefreshRate3.Caption+' Hz';

  ScreenType4.Caption:= FillBlank(aScreenType[FormMain.GameInfoData.eScreenType4]);
  Rotation4.Caption:= CheckRotation(FormMain.GameInfoData.eScreenRotation4);
  Resolution4.Caption:= FillBlank(FormMain.MountResolution(FormMain.GameInfoData.eResolutionWidth4, FormMain.GameInfoData.eResolutionHeight4, FormMain.GameInfoData.eScreenRotation4, False));
  RefreshRate4.Caption:= FillBlank(FormMain.GameInfoData.eRefreshRate4);
  if RefreshRate4.Caption <> '-' then
     RefreshRate4.Caption:= RefreshRate4.Caption+' Hz';

  DriverStatus.Caption:= FillBlank(aStatus[FormMain.GameInfoData.eDriverStatus]);
  EmulationStatus.Caption:= FillBlank(aStatus[FormMain.GameInfoData.eDriverStatus]);
  ColorStatus.Caption:= FillBlank(aStatus[FormMain.GameInfoData.eColorStatus]);
  SoundStatus.Caption:= FillBlank(aStatus[FormMain.GameInfoData.eSoundStatus]);
  GraphicStatus.Caption:= FillBlank(aStatus[FormMain.GameInfoData.eGraphicStatus]);
  CocktailStatus.Caption:= FillBlank(aStatus[FormMain.GameInfoData.eCocktailStatus]);
  ProtectionStatus.Caption:= FillBlank(aStatus[FormMain.GameInfoData.eProtectionStatus]);

  Name.Caption:= FormMain.GameInfoData.eName;
  CloneOf.Caption:= FillBlank(FormMain.GameInfoData.eClone);
  DriverName.Caption:= FillBlank(FormMain.GameInfoData.eDriverName);
  Bios.Caption:= FillBlank(FormMain.GameInfoData.eBiosName);
  Merged.Caption:= FillBlank(FormMain.GameInfoData.eMerged);

  GameSize.Caption:= FormMain.UpdateGameSize;
  PlayTime.Caption:= FillBlank(FormMain.GameInfoData.ePlayTime);
  if FormMain.GameInfoData.ePlayed = 0 then
     Played.Caption:= '-'
  else
     Played.Caption:= IntToStr(FormMain.GameInfoData.ePlayed)+'x';
  NumberPlayers.Caption:= FillBlank(FormMain.GameInfoData.eNumberPlayers);

  ControlTypes.Caption:= FormMain.MountControlTypesList(FormMain.GameInfoData.eControls, nil);
  
  LabelDescription.Caption:= FormMain.GameInfoData.eDescription+#13+'System: '+
                FormMain.GetEmuFullDescription(FormMain.SystemID_Number);
end;

procedure TFormGameDetails.ButtonCloseClick(Sender: TObject);
begin
  Close;
end;

procedure TFormGameDetails.FormActivate(Sender: TObject);
var
  gIndex: Integer;
  chdFile, romsFile: String;
  gameFilesList: THashedStringList;
  roms: TMemIniFile;
begin
  Application.ProcessMessages;
  if FormMain.SystemID_Number in [1, 4, 5, 6] then
     romsFile:= GetSystemROMFileName(FormMain.SystemID_Number);

  if romsFile <> '' then
     begin
       roms:= TMemIniFile.Create(FormMain.FrontendPath+GetMachineTypeGamesFolder+romsFile);
       gameFilesList:= THashedStringList.Create;
       roms.ReadSectionValues(FormMain.GameInfoData.eName, gameFilesList);
       FreeAndNil(roms);
       FormMain.ListROMsName:= THashedStringList.Create;
       FormMain.ListROMsSize:= THashedStringList.Create;
       FormMain.ListROMsCRC:= THashedStringList.Create;
       FormMain.ListROMsName.BeginUpdate;
       FormMain.ListROMsSize.BeginUpdate;
       FormMain.ListROMsCRC.BeginUpdate;
       FormMain.GetGameROMs(gameFilesList, False);
       FormMain.ListROMsName.EndUpdate;
       FormMain.ListROMsSize.EndUpdate;
       FormMain.ListROMsCRC.EndUpdate;
       FreeAndNil(gameFilesList);
     end;

  if Assigned(FormMain.ListROMsName) and (FormMain.ListROMsName.Count > 0) then
     begin
       GameROMsList.Items.BeginUpdate;
       gIndex:= 0;
       repeat
         if Pos('.chd', LowerCase(FormMain.ListROMsName[gIndex])) <> 0 then
            begin
              chdFile:= FormMain.SearchCHDFolder(FormMain.ListROMsName[gIndex], False, FormMain.SystemID_Number);
              if chdFile <> '' then
                 FormMain.ListROMsSize[gIndex]:= IntToStr(GetFileSize(chdFile));
           end;
         with GameROMsList.Items.Add do
         begin
           ImageIndex:= 65;
           Caption:= FormMain.ListROMsName[gIndex];
           SubItems.Add(Format('%.0n', [StrToFloat(FormMain.ListROMsSize[gIndex])]));
           SubItems.Add(FormMain.ListROMsCRC[gIndex]);
         end;
         Inc(gIndex);
       until gIndex = FormMain.ListROMsName.Count;
       GameROMsList.Items.EndUpdate;
     end;
  FreeAndNil(FormMain.ListROMsName);
  FreeAndNil(FormMain.ListROMsSize);
  FreeAndNil(FormMain.ListROMsCRC);
end;

end.
