unit uPreferences;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls, ComCtrls, Menus, ImgList, IniFiles, GR32_RangeBars,
  Buttons, CheckLst, VirtualTrees;

type
  TFormPreferences = class(TForm)
    PageControlPreferences: TPageControl;
    TabSheetGeneral: TTabSheet;
    PageControlGeneralOptions: TPageControl;
    TabSheetMiscellaneous: TTabSheet;
    TabSheetGames: TTabSheet;
    TabSheetPictures: TTabSheet;
    NewDescriptionFormat: TCheckBox;
    TabSheetMultimedia: TTabSheet;
    PlayAudio: TCheckBox;
    AudioVideoLoop: TCheckBox;
    AudioVideoUseParent: TCheckBox;
    AudioVolume: TGaugeBar;
    LabelAudioVolumeValue: TLabel;
    LabelAudioVolume: TLabel;
    LabelAutomaticGameInformation: TGroupBox;
    LabelAutomaticGameInformation1: TLabel;
    LabelAutomaticGameInformation2: TLabel;
    LabelAutomaticGameInformation3: TLabel;
    LabelAutomaticGameInformation4: TLabel;
    AutomaticGameInformation1: TComboBox;
    AutomaticGameInformation2: TComboBox;
    AutomaticGameInformation3: TComboBox;
    AutomaticGameInformation4: TComboBox;
    TabSheetAppearance: TTabSheet;
    ShowZipErrorMessages: TCheckBox;
    AutomaticGameInformationOpenWindow: TCheckBox;
    LabelRandomGamePreview: TGroupBox;
    LabelGamePreviewRunningTime: TLabel;
    LabelPauseBetweenGames: TLabel;
    LabelPauseBetweenGamesValue: TLabel;
    PauseBetweenGames: TGaugeBar;
    LabelUseAvailableGamesOnly: TLabel;
    LabelUseAvailableGamesOnlyValue: TLabel;
    UseAvailableGamesOnly: TGaugeBar;
    PauseBeforeEmulatorStarts: TGaugeBar;
    LabelPauseBeforeEmulatorStartsValue: TLabel;
    LabelPauseBeforeEmulatorStarts: TLabel;
    RestoreSelectedGame: TCheckBox;
    LabelNumberGamesToRun: TLabel;
    NumberGamesToRun: TGaugeBar;
    LabelNumberGamesToRunValue: TLabel;
    WarningPanelAnimation: TCheckBox;
    LabelBlendPreviewWindowFactor: TLabel;
    BlendPreviewWindowFactor: TGaugeBar;
    LabelBlendPreviewWindowFactorValue: TLabel;
    GamePreviewRunningTime: TGaugeBar;
    LabelGamePreviewRunningTimeValue: TLabel;
    PageControlImages: TPageControl;
    TabSheetImagesTypeSettings: TTabSheet;
    TabSheetImagesGeneral: TTabSheet;
    CycleImageTypes: TCheckBox;
    PageControlAppearance: TPageControl;
    TabSheetAppearanceGeneral: TTabSheet;
    LabelAppearanceGameDocuments: TLabel;
    GameDocumentsBackgroundColor: TColorBox;
    ButtonGameDocumentsFont: TButton;
    ButtonGameDocumentsDefault: TButton;
    IL_Preferences: TImageList;
    RunCustomGameSettingsByDefault: TCheckBox;
    TabSheetEmulators: TTabSheet;
    TabSheetFoldersZipFiles: TTabSheet;
    PageControlFoldersFiles: TPageControl;
    TabSheetFoldersGeneral: TTabSheet;
    LabelMAMu_Icons: TLabel;
    ZipIconsButtonSelect: TButton;
    ZipIconsButtonSelect2: TButton;
    LabelrGamesFAQFolder: TLabel;
    FolderGamesFAQButtonSelect: TButton;
    MAMu_Icons: TEdit;
    FolderGamesFAQ: TEdit;
    TabSheetFoldersImages: TTabSheet;
    LabelZipTitleSnapshots: TLabel;
    ZipTitleSnapshotsButtonSelect: TButton;
    ZipTitleSnapshotsButtonSelect2: TButton;
    LabelZipGameSnapshots: TLabel;
    ZipGameSnapshotsButtonSelect: TButton;
    ZipGameSnapshotsButtonSelect2: TButton;
    ZipGameSnapshotsButtonUpdate: TButton;
    LabelZipMarquees: TLabel;
    ZipMarqueesButtonSelect: TButton;
    ZipMarqueesButtonSelect2: TButton;
    LabelZipFlyers: TLabel;
    ZipFlyersButtonSelect: TButton;
    ZipFlyersButtonSelect2: TButton;
    LabelZipCabinets: TLabel;
    ZipCabinetsButtonSelect: TButton;
    ZipCabinetsButtonSelect2: TButton;
    LabelZipControlPanels: TLabel;
    ZipControlPanelsButtonSelect: TButton;
    ZipControlPanelsButtonSelect2: TButton;
    LabelZipControlPanelLayouts: TLabel;
    ZipControlPanelLayoutsButtonSelect: TButton;
    ZipControlPanelLayoutsButtonSelect2: TButton;
    LabelZipSelect: TLabel;
    ZipSelectButtonSelect: TButton;
    ZipSelectButtonSelect2: TButton;
    LabelZipVersus: TLabel;
    ZipVersusButtonSelect: TButton;
    ZipVersusButtonSelect2: TButton;
    LabelZipWallpapers: TLabel;
    ZipWallpapersButtonSelect: TButton;
    ZipWallpapersButtonSelect2: TButton;
    LabelZipHardware: TLabel;
    ZipHardwareButtonSelect: TButton;
    ZipHardwareButtonSelect2: TButton;
    LabelZipCustomImage: TLabel;
    ZipCustomImageButtonSelect: TButton;
    ZipCustomImageButtonSelect2: TButton;
    ZipTitleSnapshots: TEdit;
    ZipGameSnapshots: TEdit;
    ZipMarquees: TEdit;
    ZipFlyers: TEdit;
    ZipCabinets: TEdit;
    ZipControlPanels: TEdit;
    ZipControlPanelLayouts: TEdit;
    ZipSelect: TEdit;
    ZipVersus: TEdit;
    ZipWallpapers: TEdit;
    ZipHardware: TEdit;
    ZipCustomImage: TEdit;
    ButtonFolderZipFileClearAllImageTypes: TButton;
    imgType_TitleSnapshots: TImage;
    imgType_GameSnapshots: TImage;
    imgType_Marquees: TImage;
    imgType_Flyers: TImage;
    imgType_Cabinets: TImage;
    imgType_ControlPanels: TImage;
    imgType_ControlPanelLayouts: TImage;
    imgType_Select: TImage;
    imgType_Versus: TImage;
    imgType_Wallpapers: TImage;
    imgType_Hardware: TImage;
    imgType_Custom: TImage;
    ButtonDefaultDescriptionTitleSnapshots: TButton;
    ButtonDefaultDescriptionGameSnapshots: TButton;
    ButtonDefaultDescriptionMarquees: TButton;
    ButtonDefaultDescriptionFlyers: TButton;
    ButtonDefaultDescriptionCabinets: TButton;
    ButtonDefaultDescriptionControlPanels: TButton;
    ButtonDefaultDescriptionControlPanelLayouts: TButton;
    ButtonDefaultDescriptionSelect: TButton;
    ButtonDefaultDescriptionVersus: TButton;
    ButtonDefaultDescriptionWallpapers: TButton;
    ButtonDefaultDescriptionHardware: TButton;
    ButtonDefaultDescriptionCustomImage: TButton;
    DescriptionTitleSnapshots: TEdit;
    EnableTitleSnapshots: TCheckBox;
    DescriptionGameSnapshots: TEdit;
    EnableGameSnapshots: TCheckBox;
    DescriptionMarquees: TEdit;
    EnableMarquees: TCheckBox;
    DescriptionFlyers: TEdit;
    EnableFlyers: TCheckBox;
    DescriptionCabinets: TEdit;
    EnableCabinets: TCheckBox;
    DescriptionControlPanels: TEdit;
    EnableControlPanels: TCheckBox;
    DescriptionControlPanelLayouts: TEdit;
    EnableControlPanelLayouts: TCheckBox;
    EnableSelect: TCheckBox;
    DescriptionSelect: TEdit;
    EnableVersus: TCheckBox;
    DescriptionVersus: TEdit;
    EnableWallpapers: TCheckBox;
    DescriptionWallpapers: TEdit;
    EnableHardware: TCheckBox;
    DescriptionHardware: TEdit;
    EnableCustomImage: TCheckBox;
    DescriptionCustomImage: TEdit;
    ImagesFolderZipSelector: TComboBoxEx;
    GamesListBox: TGroupBox;
    LabelGamesBackgroundColor: TLabel;
    GamesBackgroundColor: TColorBox;
    LabelSortedColumnColor: TLabel;
    SortedColumnColor: TColorBox;
    ButtonMasterGameFont: TButton;
    ButtonCloneGameFont: TButton;
    ButtonPreliminaryGameFont: TButton;
    ButtonGameFontDefault: TButton;
    TabSheet3: TTabSheet;
    StartupGamesListNotFound: TRadioGroup;
    StartupNewBinaryFound: TRadioGroup;
    RunEmulatorStartup: TCheckBox;
    TabSheetAdvancedUser: TTabSheet;
    AdvancedUserBox: TGroupBox;
    LabelExtractEmulatorDataDOSBox: TLabel;
    LabelRunEmulatorDOSBox: TLabel;
    ExtractEmulatorDataDOSBox: TComboBox;
    RunEmulatorDOSBox: TComboBox;
    ReadOnlyMessage: TCheckBox;
    SmoothScroll: TCheckBox;
    LabelAudioBox: TGroupBox;
    AudioFolder: TEdit;
    AudioFolderSelect: TButton;
    AudioSystemSelector: TComboBoxEx;
    BiosSetWarning: TCheckBox;
    PlayMNG: TCheckBox;
    GroupBox2: TGroupBox;
    MNGFolderSelect: TButton;
    VideoFolder: TEdit;
    MNGSystemSelector: TComboBoxEx;
    ArcadeControllersGUI: TGroupBox;
    Devastator2: TCheckBox;
    HotRodSE: TCheckBox;
    SlikStik: TCheckBox;
    SlikStikSwap2ndPlayerStick: TCheckBox;
    XArcade: TCheckBox;
    TitleSnapshotsBackgroundColor: TColorBox;
    GameSnapshotsBackgroundColor: TColorBox;
    MarqueesBackgroundColor: TColorBox;
    FlyersBackgroundColor: TColorBox;
    CabinetsBackgroundColor: TColorBox;
    ControlPanelsBackgroundColor: TColorBox;
    ControlPanelLayoutsBackgroundColor: TColorBox;
    SelectBackgroundColor: TColorBox;
    VersusBackgroundColor: TColorBox;
    WallpapersBackgroundColor: TColorBox;
    HardwareBackgroundColor: TColorBox;
    CustomImageBackgroundColor: TColorBox;
    LabelSplashLogo: TLabel;
    SplashLogo: TEdit;
    SplashLogoButtonSelect: TButton;
    FMODSettings: TGroupBox;
    LabelOutputDevice: TLabel;
    OutputDevice: TComboBox;
    LabelMixerType: TLabel;
    MixerType: TComboBox;
    LabelOutputRate: TLabel;
    OutputRate: TComboBox;
    LabelAudioFormats: TGroupBox;
    AudioFormatMP3: TCheckBox;
    AudioFormatWAV: TCheckBox;
    AudioFormatOGG: TCheckBox;
    TreeViewGroupBox: TGroupBox;
    TreeViewTreeLines: TCheckBox;
    TreeViewHorizontalGridLines: TCheckBox;
    TreeViewVerticalGridLines: TCheckBox;
    TreeViewTreeRoot: TCheckBox;
    Windows9xGroupBox: TGroupBox;
    LabelTreeViewButtonFillMode: TLabel;
    LabelTreeViewButtonStyle: TLabel;
    TreeViewWinXPStyle: TCheckBox;
    TreeViewButtonFillMode: TComboBox;
    TreeViewButtonStyle: TComboBox;
    TreeViewHintsGroupBox: TGroupBox;
    LabelTreeViewHintAnimation: TLabel;
    LabelTreeViewHintMode: TLabel;
    TreeViewHintAnimation: TComboBox;
    TreeViewHintMode: TComboBox;
    ShowEmuVersionSystemDescription: TCheckBox;
    SelectedGameBoldFont: TCheckBox;
    EmuZiNcSettingsBox: TGroupBox;
    ZiNc_BreakSettingsCFG: TCheckBox;
    ZiNcUseMAMEGamesInfo: TCheckBox;
    EmuDaphneSettingsBox: TGroupBox;
    Daphne_NoLog: TCheckBox;
    LabelAutomaticGameInformation5: TLabel;
    AutomaticGameInformation5: TComboBox;
    ButtonResetAutoGameInfoOrder: TButton;
    EnableGamePlayTime_Played: TCheckBox;
    MinimizeFrontendToRunGames: TCheckBox;
    LabelGamesSelectionAlphaBlend: TGroupBox;
    GameSelectionAlphaBlendEnable: TCheckBox;
    GameSelectionAlphaBlend: TGaugeBar;
    LabelGameSelectionAlphaBlendValue: TLabel;
    LabelGamesBackgroundImage: TGroupBox;
    GamesBackgroundImageEnable: TCheckBox;
    GamesBackgroundImage: TEdit;
    GamesBackgroundImageButtonSelect: TButton;
    GamesBackgroundImageButtonUpdate: TButton;
    GamesTileBackGround: TCheckBox;
    procedure ImagesFolderZipSelectorSelect(Sender: TObject);
    procedure NewDescriptionFormatClick(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure HotRodSEClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure XArcadeClick(Sender: TObject);
    procedure SlikStikClick(Sender: TObject);
    procedure GamesBackgroundColorSelect(Sender: TObject);
    procedure TitleSnapshotsBackgroundColorSelect(Sender: TObject);
    procedure ButtonMasterGameFontClick(Sender: TObject);
    procedure ButtonGameFontDefaultClick(Sender: TObject);
    procedure ButtonGameDocumentsFontClick(Sender: TObject);
    procedure GameDocumentsBackgroundColorSelect(
      Sender: TObject);
    procedure ButtonGameDocumentsDefaultClick(Sender: TObject);
    procedure SplashLogoChange(Sender: TObject);
    procedure FolderGamesFAQButtonSelectClick(Sender: TObject);
    procedure CycleImageTypesClick(Sender: TObject);
    procedure PlayAudioClick(Sender: TObject);
    procedure OutputDeviceSelect(Sender: TObject);
    procedure OutputTypeSelect(Sender: TObject);
    procedure MixerTypeSelect(Sender: TObject);
    procedure OutputRateSelect(Sender: TObject);
    procedure AudioVolumeChange(Sender: TObject);
    procedure ZipTitleSnapshotsButtonSelectClick(Sender: TObject);
    procedure ZipGameSnapshotsButtonSelectClick(Sender: TObject);
    procedure ZipMarqueesButtonSelectClick(Sender: TObject);
    procedure ZipFlyersButtonSelectClick(Sender: TObject);
    procedure ZipCabinetsButtonSelectClick(Sender: TObject);
    procedure ZipControlPanelsButtonSelectClick(Sender: TObject);
    procedure ZipControlPanelLayoutsButtonSelectClick(Sender: TObject);
    procedure ZipIconsButtonSelectClick(Sender: TObject);
    procedure Devastator2Click(Sender: TObject);
    procedure ShowZipErrorMessagesClick(Sender: TObject);
    procedure AutomaticGameInformationOpenWindowClick(Sender: TObject);
    procedure ZipMarqueesButtonSelect2Click(Sender: TObject);
    procedure ZipFlyersButtonSelect2Click(Sender: TObject);
    procedure ZipCabinetsButtonSelect2Click(Sender: TObject);
    procedure ZipControlPanelsButtonSelect2Click(Sender: TObject);
    procedure ZipControlPanelLayoutsButtonSelect2Click(Sender: TObject);
    procedure ZipIconsButtonSelect2Click(Sender: TObject);
    procedure ZipGameSnapshotsButtonSelect2Click(Sender: TObject);
    procedure ZipGameSnapshotsButtonUpdateClick(Sender: TObject);
    procedure ButtonCloneGameFontClick(Sender: TObject);
    procedure ButtonPreliminaryGameFontClick(Sender: TObject);
    procedure GamesBackgroundImageButtonSelectClick(Sender: TObject);
    procedure GamesBackgroundImageButtonUpdateClick(Sender: TObject);
    procedure GamesBackgroundImageEnableClick(Sender: TObject);
    procedure PauseBetweenGamesChange(Sender: TObject);
    procedure UseAvailableGamesOnlyChange(Sender: TObject);
    procedure PauseBeforeEmulatorStartsChange(Sender: TObject);
    procedure NumberGamesToRunChange(Sender: TObject);
    procedure BlendPreviewWindowFactorChange(Sender: TObject);
    procedure GamePreviewRunningTimeChange(Sender: TObject);
    procedure ButtonDefaultDescriptionTitleSnapshotsClick(Sender: TObject);
    procedure EnableTitleSnapshotsClick(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure ZipSelectButtonSelectClick(Sender: TObject);
    procedure ZipVersusButtonSelectClick(Sender: TObject);
    procedure ZipWallpapersButtonSelectClick(Sender: TObject);
    procedure ZipHardwareButtonSelectClick(Sender: TObject);
    procedure ZipCustomImageButtonSelectClick(Sender: TObject);
    procedure ZipSelectButtonSelect2Click(Sender: TObject);
    procedure ZipVersusButtonSelect2Click(Sender: TObject);
    procedure ZipWallpapersButtonSelect2Click(Sender: TObject);
    procedure ZipHardwareButtonSelect2Click(Sender: TObject);
    procedure ZipCustomImageButtonSelect2Click(Sender: TObject);
    procedure TreeViewWinXPStyleClick(Sender: TObject);
    procedure SplashLogoButtonSelectClick(Sender: TObject);
    procedure SortedColumnColorSelect(Sender: TObject);
    procedure TreeViewButtonFillModeChange(Sender: TObject);
    procedure TreeViewButtonStyleChange(Sender: TObject);
    procedure TreeViewHintAnimationChange(Sender: TObject);
    procedure TreeViewHintModeChange(Sender: TObject);
    procedure TreeViewTreeLinesClick(Sender: TObject);
    procedure GamesTileBackGroundClick(Sender: TObject);
    procedure TreeViewHorizontalGridLinesClick(Sender: TObject);
    procedure TreeViewVerticalGridLinesClick(Sender: TObject);
    procedure TreeViewTreeRootClick(Sender: TObject);
    procedure SmoothScrollClick(Sender: TObject);
    procedure GameSelectionAlphaBlendChange(Sender: TObject);
    procedure GameSelectionAlphaBlendEnableClick(Sender: TObject);
    procedure ButtonFolderZipFileClearAllImageTypesClick(Sender: TObject);
    procedure ZipTitleSnapshotsChange(Sender: TObject);
    procedure AudioSystemSelectorSelect(Sender: TObject);
    procedure AudioFolderChange(Sender: TObject);
    procedure AudioFolderSelectClick(Sender: TObject);
    procedure MNGFolderSelectClick(Sender: TObject);
    procedure MNGSystemSelectorSelect(Sender: TObject);
    procedure VideoFolderChange(Sender: TObject);
    procedure TabSheetFoldersImagesShow(Sender: TObject);
    procedure ShowEmuVersionSystemDescriptionClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ButtonResetAutoGameInfoOrderClick(Sender: TObject);
    procedure EnableGamePlayTime_PlayedClick(Sender: TObject);
  private
    { Private declarations }
    procedure RestartFMOD;
    procedure SetDefaultColorBox(ColorHolder: TColorBox);
    procedure SetImagesZipFolders(sysID: Integer);
    procedure SetIncrementalSearch(ModeEnabled: Boolean);
  public
    { Public declarations }
    procedure UpdatePictureTypesDescriptions;
  end;

var
  FormPreferences: TFormPreferences;

implementation

uses uMain, uStatus, uCommon, uFilesUtil;

{$R *.DFM}

// procedures
procedure TFormPreferences.RestartFMOD;
begin
  if PlayAudio.Checked then
     begin
       FormMain.InitDeInitFMOD(False, False, False);
       FormMain.InitDeInitFMOD(True, False, False);
     end;
end;

procedure TFormPreferences.SetDefaultColorBox(ColorHolder: TColorBox);
begin
  ColorHolder.Selected:= ColorHolder.DefaultColorColor;
  ColorHolder.OnSelect(ColorHolder);
end;

procedure TFormPreferences.UpdatePictureTypesDescriptions;

  procedure ValidateString(StringHolder: TEdit; TypeIndex: Integer);
  begin
    if StringHolder.Text = '' then
       StringHolder.Text:= ImageTypeArray[TypeIndex, 0];
  end;

  procedure SetDescriptions(LabelHolder: TLabel; ImageTypeHolder: TImage;
                            MenuItemHolder: TMenuItem;
                            DescriptionHolder: TEdit);
  begin
    LabelHolder.Caption:= DescriptionHolder.Text;
    ImageTypeHolder.Hint:= DescriptionHolder.Text;
    MenuItemHolder.Caption:= DescriptionHolder.Text;
  end;

begin
  ValidateString(DescriptionTitleSnapshots, 0);
  SetDescriptions(LabelZipTitleSnapshots, imgType_TitleSnapshots,
                  FormMain.ButtonShowTitleSnapshots,
                  DescriptionTitleSnapshots);

  ValidateString(DescriptionMarquees, 2);
  SetDescriptions(LabelZipMarquees, imgType_Marquees,
                  FormMain.ButtonShowMarquees,
                  DescriptionMarquees);

  ValidateString(DescriptionFlyers, 3);
  SetDescriptions(LabelZipFlyers, imgType_Flyers,
                  FormMain.ButtonShowFlyers,
                  DescriptionFlyers);

  ValidateString(DescriptionCabinets, 4);
  SetDescriptions(LabelZipCabinets, imgType_Cabinets,
                  FormMain.ButtonShowCabinets,
                  DescriptionCabinets);

  ValidateString(DescriptionControlPanels, 5);
  SetDescriptions(LabelZipControlPanels, imgType_ControlPanels,
                  FormMain.ButtonShowControlPanels,
                  DescriptionControlPanels);

  ValidateString(DescriptionControlPanelLayouts, 6);
  SetDescriptions(LabelZipControlPanelLayouts, imgType_ControlPanelLayouts,
                  FormMain.ButtonShowControlPanelLayouts,
                  DescriptionControlPanelLayouts);

  ValidateString(DescriptionSelect, 7);
  SetDescriptions(LabelZipSelect, imgType_Select,
                  FormMain.ButtonShowSelect,
                  DescriptionSelect);

  ValidateString(DescriptionVersus, 8);
  SetDescriptions(LabelZipVersus, imgType_Versus,
                  FormMain.ButtonShowVersus,
                  DescriptionVersus);

  ValidateString(DescriptionWallpapers, 9);
  SetDescriptions(LabelZipWallpapers, imgType_Wallpapers,
                  FormMain.ButtonShowWallpapers,
                  DescriptionWallpapers);

  ValidateString(DescriptionHardware, 10);
  SetDescriptions(LabelZipHardware, imgType_Hardware,
                  FormMain.ButtonShowHardware,
                  DescriptionHardware);

  ValidateString(DescriptionCustomImage, 11);
  SetDescriptions(LabelZipCustomImage, imgType_Custom,
                  FormMain.ButtonShowCustomImage,
                  DescriptionCustomImage);
end;

// end of procedures

procedure TFormPreferences.NewDescriptionFormatClick(Sender: TObject);
begin
  FormMain.SetDescriptionFormat;
end;

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

procedure TFormPreferences.SetIncrementalSearch(ModeEnabled: Boolean);
begin
  FormMain.GamesTreeView.BeginUpdate;
  case ModeEnabled of
    True:
      begin
        if FormMain.GamesTreeView.IncrementalSearch <> isVisibleOnly then
           FormMain.GamesTreeView.IncrementalSearch:= isVisibleOnly;
      end;
    False:
      begin
        if FormMain.GamesTreeView.IncrementalSearch <> isNone then
           FormMain.GamesTreeView.IncrementalSearch:= isNone;
      end;
  end;
  FormMain.GamesTreeView.EndUpdate;
end;

procedure TFormPreferences.FormShow(Sender: TObject);
begin
  if Application.Terminated then
     begin
       PostMessage(Handle, wm_Close, 0, 0);
       Exit;
     end;

  SetComboBoxEx(ImagesFolderZipSelector, 0);
  SetComboBoxEx(AudioSystemSelector, 0);
  SetComboBoxEx(MNGSystemSelector, 0);
end;

procedure TFormPreferences.XArcadeClick(Sender: TObject);
begin
  if XArcade.Checked then
     begin
       HotRodSE.Checked:= False;
       SlikStik.Checked:= False;
       Devastator2.Checked:= False;
     end;
  SetIncrementalSearch(not(XArcade.Checked));
end;

procedure TFormPreferences.HotRodSEClick(Sender: TObject);
begin
  if HotRodSE.Checked then
     begin
       XArcade.Checked:= False;
       SlikStik.Checked:= False;
       Devastator2.Checked:= False;
     end;
  SetIncrementalSearch(not(HotRodSE.Checked));
end;

procedure TFormPreferences.SlikStikClick(Sender: TObject);
begin
  if SlikStik.Checked then
     begin
       HotRodSE.Checked:= False;
       XArcade.Checked:= False;
       Devastator2.Checked:= False;
     end;
  SetIncrementalSearch(not(SlikStik.Checked));
end;

procedure TFormPreferences.Devastator2Click(Sender: TObject);
begin
  if XArcade.Checked then
     begin
       HotRodSE.Checked:= False;
       SlikStik.Checked:= False;
       XArcade.Checked:= False;
     end;
  SetIncrementalSearch(not(Devastator2.Checked));
end;

procedure TFormPreferences.GamesBackgroundColorSelect(Sender: TObject);
begin
  FormMain.GamesTreeView.Color:= GamesBackgroundColor.Selected;
end;

procedure TFormPreferences.TitleSnapshotsBackgroundColorSelect(
  Sender: TObject);
begin
  if FormMain.ButtonImagesViewMode.Tag = TColorBox(Sender).Tag then
     FormMain.Images.Color:= TColorBox(Sender).Selected;
end;

procedure TFormPreferences.ButtonGameFontDefaultClick(Sender: TObject);
begin
  with FormMain.MasterFont.Font do
  begin
    Color:= clBlack;
    Name:= 'Segoe UI';
    Size:= 9;
    Style:= [];
  end;
  with FormMain.CloneFont.Font do
  begin
    Color:= clBlack;
    Name:= 'Segoe UI';
    Size:= 9;
    Style:= [];
  end;
  with FormMain.PreliminaryFont.Font do
  begin
    Color:= clGray;
    Name:= 'Segoe UI';
    Size:= 9;
    Style:= [fsStrikeOut];
  end;
  SetDefaultColorBox(GamesBackgroundColor);
  SetDefaultColorBox(SortedColumnColor); // sorted column color
  GameSelectionAlphaBlend.Position:= 128;
  GameSelectionAlphaBlendEnable.Checked:= False;
  FormMain.GamesTreeView.Refresh;
end;

procedure TFormPreferences.ButtonGameDocumentsFontClick(
  Sender: TObject);
begin
  FormMain.FontDialog.Font:= FormMain.MAMEInfoTextHolder.Font;
  if FormMain.FontDialog.Execute then
     FormMain.MAMEInfoTextHolder.Font:= FormMain.FontDialog.Font;
end;

procedure TFormPreferences.GameDocumentsBackgroundColorSelect(
  Sender: TObject);
begin
  FormMain.MAMEInfoTextHolder.Color:= GameDocumentsBackgroundColor.Selected;
end;

procedure TFormPreferences.ButtonGameDocumentsDefaultClick(Sender: TObject);
begin
  FormMain.MAMEInfoTextHolder.Font.Color:= clBlack;
  FormMain.MAMEInfoTextHolder.Font.Name:= 'Segoe UI';
  FormMain.MAMEInfoTextHolder.Font.Size:= 9;
  FormMain.MAMEInfoTextHolder.Font.Style:= [];
  GameDocumentsBackgroundColor.Selected:= GameDocumentsBackgroundColor.DefaultColorColor;
  GameDocumentsBackgroundColor.OnSelect(Self);
end;

procedure TFormPreferences.SplashLogoChange(Sender: TObject);
begin
  FormMain.LogoFileName:= SplashLogo.Text;
end;

procedure TFormPreferences.FolderGamesFAQButtonSelectClick(
  Sender: TObject);
begin
  FormMain.DialogSelectFolder(FolderGamesFAQ, False);
end;

procedure TFormPreferences.CycleImageTypesClick(Sender: TObject);
begin
  case CycleImageTypes.Checked of
    True:
      begin
        FormMain.ButtonPreviousImage.ImageIndex:= 45;
        FormMain.ButtonNextImage.ImageIndex:= 46;
      end;
    False:
      begin
        FormMain.ButtonPreviousImage.ImageIndex:= 47;
        FormMain.ButtonNextImage.ImageIndex:= 48;
      end;
  end;
  FormMain.UpdateLabelImages;
end;

procedure TFormPreferences.PlayAudioClick(Sender: TObject);
begin
  FormMain.InitDeInitFMOD(PlayAudio.Checked, True, False);
  if PlayAudio.Checked then
     begin
       FormMain.PopulateDevices; // Get all sound devices present on the system
       if OutputDevice.Items.Count > 0 then
          if OutputDevice.Tag > OutputDevice.Items.Count then
             OutputDevice.ItemIndex:= 0
          else
             OutputDevice.ItemIndex:= OutputDevice.Tag;
     end;
end;

procedure TFormPreferences.OutputDeviceSelect(Sender: TObject);
begin
  RestartFMOD;
end;

procedure TFormPreferences.OutputTypeSelect(Sender: TObject);
begin
  RestartFMOD;
  if PlayAudio.Checked then
     begin
       if OutputDevice.ItemIndex <> -1 then
          OutputDevice.Tag:= OutputDevice.ItemIndex;
       OutputDevice.Items.Clear;
       FormMain.PopulateDevices;
       if OutputDevice.Tag > OutputDevice.Items.Count then
          OutputDevice.ItemIndex:= 0
       else
          OutputDevice.ItemIndex:= OutputDevice.Tag;
     end;
end;

procedure TFormPreferences.MixerTypeSelect(Sender: TObject);
begin
  RestartFMOD;
end;

procedure TFormPreferences.OutputRateSelect(Sender: TObject);
begin
  RestartFMOD;
end;

procedure TFormPreferences.AudioVolumeChange(Sender: TObject);
begin
  FormMain.SetVolume(AudioVolume.Position);
end;

procedure TFormPreferences.ZipTitleSnapshotsButtonSelectClick(
  Sender: TObject);
begin
  case TSpeedButton(Sender).Tag of
    0: FormMain.DialogOpenFile(7, LabelZipTitleSnapshots.Caption, ZipTitleSnapshots, False, False);
    1: FormMain.DialogSelectFolder(ZipTitleSnapshots, False);
  end;
end;

procedure TFormPreferences.ZipGameSnapshotsButtonSelectClick(
  Sender: TObject);
begin
  FormMain.DialogOpenFile(7, LabelZipGameSnapshots.Caption, ZipGameSnapshots, False, False);
end;

procedure TFormPreferences.ZipMarqueesButtonSelectClick(Sender: TObject);
begin
  FormMain.DialogOpenFile(7, LabelZipMarquees.Caption, ZipMarquees, False, False);
end;

procedure TFormPreferences.ZipFlyersButtonSelectClick(Sender: TObject);
begin
  FormMain.DialogOpenFile(7, LabelZipFlyers.Caption, ZipFlyers, False, False);
end;

procedure TFormPreferences.ZipCabinetsButtonSelectClick(Sender: TObject);
begin
  FormMain.DialogOpenFile(7, LabelZipCabinets.Caption, ZipCabinets, False, False);
end;

procedure TFormPreferences.ZipControlPanelsButtonSelectClick(
  Sender: TObject);
begin
  FormMain.DialogOpenFile(7, LabelZipControlPanels.Caption, ZipControlPanels, False, False);
end;

procedure TFormPreferences.ZipControlPanelLayoutsButtonSelectClick(
  Sender: TObject);
begin
  FormMain.DialogOpenFile(7, LabelZipControlPanelLayouts.Caption, ZipControlPanelLayouts, False, False);
end;

procedure TFormPreferences.ZipSelectButtonSelectClick(Sender: TObject);
begin
  FormMain.DialogOpenFile(7, LabelZipSelect.Caption, ZipSelect, False, False);
end;

procedure TFormPreferences.ZipVersusButtonSelectClick(Sender: TObject);
begin
  FormMain.DialogOpenFile(7, LabelZipVersus.Caption, ZipVersus, False, False);
end;

procedure TFormPreferences.ZipWallpapersButtonSelectClick(Sender: TObject);
begin
  FormMain.DialogOpenFile(7, LabelZipWallpapers.Caption, ZipWallpapers, False, False);
end;

procedure TFormPreferences.ZipHardwareButtonSelectClick(Sender: TObject);
begin
  FormMain.DialogOpenFile(7, LabelZipHardware.Caption, ZipHardware, False, False);
end;

procedure TFormPreferences.ZipCustomImageButtonSelectClick(Sender: TObject);
begin
  FormMain.DialogOpenFile(7, LabelZipCustomImage.Caption, ZipCustomImage, False, False);
end;

procedure TFormPreferences.ZipIconsButtonSelectClick(Sender: TObject);
begin
  FormMain.DialogOpenFile(7, LabelMAMu_Icons.Caption, MAMu_Icons, False, False);
end;

procedure TFormPreferences.ShowZipErrorMessagesClick(Sender: TObject);
begin
  if not ShowZipErrorMessages.Checked then
     FreeAndNil(FormMain.ZipErrors);
end;

procedure TFormPreferences.AutomaticGameInformationOpenWindowClick(
  Sender: TObject);
begin
  if FormMain.PopupAutomaticGameInformation.Checked then
     FormMain.PopupAutomaticGameInformation.Click;
end;

procedure TFormPreferences.ZipMarqueesButtonSelect2Click(Sender: TObject);
begin
  FormMain.DialogSelectFolder(ZipMarquees, False);
end;

procedure TFormPreferences.ZipFlyersButtonSelect2Click(Sender: TObject);
begin
  FormMain.DialogSelectFolder(ZipFlyers, False);
end;

procedure TFormPreferences.ZipCabinetsButtonSelect2Click(Sender: TObject);
begin
  FormMain.DialogSelectFolder(ZipCabinets, False);
end;

procedure TFormPreferences.ZipControlPanelsButtonSelect2Click(
  Sender: TObject);
begin
  FormMain.DialogSelectFolder(ZipControlPanels, False);
end;

procedure TFormPreferences.ZipControlPanelLayoutsButtonSelect2Click(
  Sender: TObject);
begin
  FormMain.DialogSelectFolder(ZipControlPanelLayouts, False);
end;

procedure TFormPreferences.ZipSelectButtonSelect2Click(Sender: TObject);
begin
  FormMain.DialogSelectFolder(ZipSelect, False);
end;

procedure TFormPreferences.ZipVersusButtonSelect2Click(Sender: TObject);
begin
  FormMain.DialogSelectFolder(ZipVersus, False);
end;

procedure TFormPreferences.ZipWallpapersButtonSelect2Click(
  Sender: TObject);
begin
  FormMain.DialogSelectFolder(ZipWallpapers, False);
end;

procedure TFormPreferences.ZipHardwareButtonSelect2Click(Sender: TObject);
begin
  FormMain.DialogSelectFolder(ZipHardware, False);
end;

procedure TFormPreferences.ZipCustomImageButtonSelect2Click(Sender: TObject);
begin
  FormMain.DialogSelectFolder(ZipCustomImage, False);
end;

procedure TFormPreferences.ZipIconsButtonSelect2Click(Sender: TObject);
begin
  FormMain.DialogSelectFolder(MAMu_Icons, False);
end;

procedure TFormPreferences.ZipGameSnapshotsButtonSelect2Click(
  Sender: TObject);
begin
  FormMain.DialogSelectFolder(ZipGameSnapshots, False);
end;

procedure TFormPreferences.ZipGameSnapshotsButtonUpdateClick(
  Sender: TObject);
begin
  FormMain.UpdateMAMEsnapDir(FormMain.imgFolderZipFile[ImagesFolderZipSelector.Tag, 1],
                             ImagesFolderZipSelector.Tag);
end;

procedure TFormPreferences.ButtonMasterGameFontClick(Sender: TObject);
begin
  if FormMain.MasterFont.Execute then
     FormMain.GamesTreeView.Refresh;
end;

procedure TFormPreferences.ButtonCloneGameFontClick(Sender: TObject);
begin
  if FormMain.CloneFont.Execute then
     FormMain.GamesTreeView.Refresh;
end;

procedure TFormPreferences.ButtonPreliminaryGameFontClick(Sender: TObject);
begin
  if FormMain.PreliminaryFont.Execute then
     FormMain.GamesTreeView.Refresh;
end;

procedure TFormPreferences.GamesBackgroundImageButtonSelectClick(
  Sender: TObject);
begin
  FormMain.DialogOpenFile(5, GamesBackgroundImageEnable.Caption, GamesBackgroundImage, False, True);
  GamesBackgroundImageButtonUpdate.Click;
end;

procedure TFormPreferences.GamesBackgroundImageButtonUpdateClick(
  Sender: TObject);
begin
  if FileExists(GamesBackgroundImage.Text) and (GamesBackgroundImage.Text <> '') and
     (GamesBackgroundImageEnable.Checked) then
     begin
       try
         FormMain.GamesTreeView.Background.LoadFromFile(GamesBackgroundImage.Text);
       except
         FormMain.GamesTreeView.Background:= nil;
       end;
     end
  else
     FormMain.GamesTreeView.Background:= nil;
end;

procedure TFormPreferences.GamesBackgroundImageEnableClick(
  Sender: TObject);
begin
  case GamesBackgroundImageEnable.Checked of
    True :
      begin

        FormMain.GamesTreeView.Header.Columns[FormMain.ColumnsSort[FormMain.ButtonGameFilterArcade.Tag, 0]].Options:= FormMain.GamesTreeView.Header.Columns[FormMain.ColumnsSort[FormMain.ButtonGameFilterArcade.Tag, 0]].Options + [coParentColor];
        GamesBackgroundImageButtonUpdate.Click;
      end;
    False:
      begin
        FormMain.GamesTreeView.Background:= nil;
        FormMain.GamesTreeView.Header.Columns[FormMain.ColumnsSort[FormMain.ButtonGameFilterArcade.Tag, 0]].Color:= SortedColumnColor.Selected; // }$F7F7F7;
      end;
  end;
end;

procedure TFormPreferences.PauseBetweenGamesChange(Sender: TObject);
begin
  LabelPauseBetweenGamesValue.Caption:= GetPlayTime(PauseBetweenGames.Position, False, False);
end;

procedure TFormPreferences.UseAvailableGamesOnlyChange(Sender: TObject);
begin
  LabelUseAvailableGamesOnlyValue.Caption:= Format('%.2d Retries', [UseAvailableGamesOnly.Position]);
end;

procedure TFormPreferences.PauseBeforeEmulatorStartsChange(Sender: TObject);
begin
  LabelPauseBeforeEmulatorStartsValue.Caption:= GetPlayTime(PauseBeforeEmulatorStarts.Position, False, False);
end;

procedure TFormPreferences.NumberGamesToRunChange(Sender: TObject);
begin
  if NumberGamesToRun.Position > 2 then
     LabelNumberGamesToRunValue.Caption:= Format('%.4u Games', [NumberGamesToRun.Position])
  else
     LabelNumberGamesToRunValue.Caption:= 'No Limit';
end;

procedure TFormPreferences.BlendPreviewWindowFactorChange(Sender: TObject);
begin
  LabelBlendPreviewWindowFactorValue.Caption:= IntToStr(BlendPreviewWindowFactor.Position);
  FormMain.BlendWindow(0, BlendPreviewWindowFactor.Position);
end;

procedure TFormPreferences.GamePreviewRunningTimeChange(Sender: TObject);
begin
  LabelGamePreviewRunningTimeValue.Caption:= GetPlayTime(GamePreviewRunningTime.Position, False, False);
end;

procedure TFormPreferences.ButtonDefaultDescriptionTitleSnapshotsClick(
  Sender: TObject);
begin
  case TSpeedButton(Sender).Tag of
     0: SetDefaultColorBox(TitleSnapshotsBackgroundColor);
     1: SetDefaultColorBox(GameSnapshotsBackgroundColor);
     2: begin
          DescriptionMarquees.Text:= 'Marquees';
          SetDefaultColorBox(MarqueesBackgroundColor);
        end;
     3: begin
          DescriptionFlyers.Text:= 'Flyers';
          SetDefaultColorBox(FlyersBackgroundColor);
        end;
     4: begin
          DescriptionCabinets.Text:= 'Cabinets';
          SetDefaultColorBox(CabinetsBackgroundColor);
        end;  
     5: begin
          DescriptionControlPanels.Text:= 'Control Panels';
          SetDefaultColorBox(ControlPanelsBackgroundColor);
        end;
     6: begin
          DescriptionControlPanelLayouts.Text:= 'Control Panel Layouts';
          SetDefaultColorBox(ControlPanelLayoutsBackgroundColor);
        end;
     7: SetDefaultColorBox(SelectBackgroundColor);
     8: SetDefaultColorBox(VersusBackgroundColor);
     9: begin
          DescriptionWallpapers.Text:= 'Wallpapers';
          SetDefaultColorBox(WallpapersBackgroundColor);
        end;
    10: begin
          DescriptionHardware.Text:= 'Hardware';
          SetDefaultColorBox(HardwareBackgroundColor);
        end;
    11: begin
          DescriptionCustomImage.Text:= 'Custom';
          SetDefaultColorBox(CustomImageBackgroundColor);
        end;
  end;
end;

procedure TFormPreferences.EnableTitleSnapshotsClick(Sender: TObject);
begin
  FormMain.PopupMenuImageTypes.Items[TCheckBox(Sender).Tag].Visible:= TCheckBox(Sender).Checked;
end;

procedure TFormPreferences.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
  if CanClose then
     UpdatePictureTypesDescriptions;
end;

procedure TFormPreferences.TreeViewWinXPStyleClick(Sender: TObject);
begin
  if FormMain.IsThemesEnabled then
     Exit;
  case TreeViewWinXPStyle.Checked of
    True:
      begin
        FormMain.GamesTreeView.TreeOptions.PaintOptions:= FormMain.GamesTreeView.TreeOptions.PaintOptions+[toThemeAware];
        FormMain.GamesTreeView.Header.Style:= hsXPStyle;
      end;
    False:
      begin
        FormMain.GamesTreeView.TreeOptions.PaintOptions:= FormMain.GamesTreeView.TreeOptions.PaintOptions-[toThemeAware];
        FormMain.GamesTreeView.Header.Style:= hsThickButtons;
      end;
  end;
end;

procedure TFormPreferences.SplashLogoButtonSelectClick(Sender: TObject);
begin
  FormMain.DialogOpenFile(2, 'Select a file for splash screen', SplashLogo, False, True);
end;

procedure TFormPreferences.SortedColumnColorSelect(Sender: TObject);
begin
  case GamesBackgroundImageEnable.Checked of
    True : FormMain.GamesTreeView.Header.Columns[FormMain.ColumnsSort[FormMain.ButtonGameFilterArcade.Tag, 0]].Options:= FormMain.GamesTreeView.Header.Columns[FormMain.ColumnsSort[FormMain.ButtonGameFilterArcade.Tag, 0]].Options + [coParentColor];
    False: FormMain.GamesTreeView.Header.Columns[FormMain.ColumnsSort[FormMain.ButtonGameFilterArcade.Tag, 0]].Color:= SortedColumnColor.Selected; // }$F7F7F7;
  end;
end;

procedure TFormPreferences.TreeViewButtonFillModeChange(Sender: TObject);
begin
  if not FormMain.IsThemesEnabled then
     FormMain.GamesTreeView.ButtonFillMode:= TVTButtonFillMode(TreeViewButtonFillMode.ItemIndex);
end;

procedure TFormPreferences.TreeViewButtonStyleChange(Sender: TObject);
begin
  if not FormMain.IsThemesEnabled then
     FormMain.GamesTreeView.ButtonStyle:= TVTButtonStyle(TreeViewButtonStyle.ItemIndex);
end;

procedure TFormPreferences.TreeViewHintAnimationChange(Sender: TObject);
begin
  FormMain.GamesTreeView.HintAnimation:= THintAnimationType(TreeViewHintAnimation.ItemIndex);
end;

procedure TFormPreferences.TreeViewHintModeChange(Sender: TObject);
begin
  FormMain.GamesTreeView.HintMode:= TVTHintMode(TreeViewHintMode.ItemIndex);
end;

procedure TFormPreferences.TreeViewTreeLinesClick(Sender: TObject);
begin
  case TreeViewTreeLines.Checked of
    True : FormMain.GamesTreeView.TreeOptions.PaintOptions:= FormMain.GamesTreeView.TreeOptions.PaintOptions + [toShowTreeLines];
    False: FormMain.GamesTreeView.TreeOptions.PaintOptions:= FormMain.GamesTreeView.TreeOptions.PaintOptions - [toShowTreeLines];
  end;
end;

procedure TFormPreferences.GamesTileBackGroundClick(Sender: TObject);
begin
  case GamesTileBackGround.Checked of
    True : FormMain.GamesTreeView.TreeOptions.PaintOptions:= FormMain.GamesTreeView.TreeOptions.PaintOptions - [toStaticBackground];
    False: FormMain.GamesTreeView.TreeOptions.PaintOptions:= FormMain.GamesTreeView.TreeOptions.PaintOptions + [toStaticBackground];
  end;
end;

procedure TFormPreferences.TreeViewHorizontalGridLinesClick(
  Sender: TObject);
begin
  case TreeViewHorizontalGridLines.Checked of
    True : FormMain.GamesTreeView.TreeOptions.PaintOptions:= FormMain.GamesTreeView.TreeOptions.PaintOptions + [toShowHorzGridLines];
    False: FormMain.GamesTreeView.TreeOptions.PaintOptions:= FormMain.GamesTreeView.TreeOptions.PaintOptions - [toShowHorzGridLines];
  end;
end;

procedure TFormPreferences.TreeViewVerticalGridLinesClick(Sender: TObject);
begin
  case TreeViewVerticalGridLines.Checked of
    True : FormMain.GamesTreeView.TreeOptions.PaintOptions:= FormMain.GamesTreeView.TreeOptions.PaintOptions + [toShowVertGridLines];
    False: FormMain.GamesTreeView.TreeOptions.PaintOptions:= FormMain.GamesTreeView.TreeOptions.PaintOptions - [toShowVertGridLines];
  end;
end;

procedure TFormPreferences.TreeViewTreeRootClick(Sender: TObject);
begin
  if FormMain.ButtonViewModeStandard.Tag <> 0 then
     begin
       case TreeViewTreeRoot.Checked of
         True : FormMain.GamesTreeView.TreeOptions.PaintOptions:= FormMain.GamesTreeView.TreeOptions.PaintOptions + [toShowRoot];
         False: FormMain.GamesTreeView.TreeOptions.PaintOptions:= FormMain.GamesTreeView.TreeOptions.PaintOptions - [toShowRoot];
       end;
     end;
end;

procedure TFormPreferences.SmoothScrollClick(Sender: TObject);
begin
  FormMain.GamesTreeView.DoubleBuffered:= SmoothScroll.Checked;
end;

procedure TFormPreferences.GameSelectionAlphaBlendChange(Sender: TObject);
begin
  LabelGameSelectionAlphaBlendValue.Caption:= IntToStr(GameSelectionAlphaBlend.Position);
  FormMain.GamesTreeView.SelectionBlendFactor:= GameSelectionAlphaBlend.Position;
end;

procedure TFormPreferences.GameSelectionAlphaBlendEnableClick(
  Sender: TObject);
begin
  case GameSelectionAlphaBlendEnable.Checked of
    True : FormMain.GamesTreeView.TreeOptions.PaintOptions:= FormMain.GamesTreeView.TreeOptions.PaintOptions + [toUseBlendedSelection];
    False: FormMain.GamesTreeView.TreeOptions.PaintOptions:= FormMain.GamesTreeView.TreeOptions.PaintOptions - [toUseBlendedSelection];
  end;
end;

procedure TFormPreferences.ButtonFolderZipFileClearAllImageTypesClick(
  Sender: TObject);
begin
  if (ImagesFolderZipSelector.Tag = -1) then
     Exit;

  ZipTitleSnapshots.Text:= '';
  ZipGameSnapshots.Text:= '';
  ZipMarquees.Text:= '';
  ZipFlyers.Text:= '';
  ZipCabinets.Text:= '';
  ZipControlPanels.Text:= '';
  ZipControlPanelLayouts.Text:= '';
  ZipSelect.Text:= '';
  ZipVersus.Text:= '';
  ZipWallpapers.Text:= '';
  ZipHardware.Text:= '';
  ZipCustomImage.Text:= '';
end;

procedure TFormPreferences.ZipTitleSnapshotsChange(Sender: TObject);
begin
  if FormMain.imgFolderZipFile[ImagesFolderZipSelector.Tag, TEdit(Sender).Tag] <> TEdit(Sender).Text then
     FormMain.imgFolderZipFile[ImagesFolderZipSelector.Tag, TEdit(Sender).Tag]:= TEdit(Sender).Text;
end;

procedure TFormPreferences.SetImagesZipFolders(sysID: Integer);
begin
  ZipTitleSnapshots.Text:= FormMain.imgFolderZipFile[sysID, 0];
  ZipGameSnapshots.Text:= FormMain.imgFolderZipFile[sysID, 1];
  ZipMarquees.Text:= FormMain.imgFolderZipFile[sysID, 2];
  ZipFlyers.Text:= FormMain.imgFolderZipFile[sysID, 3];
  ZipCabinets.Text:= FormMain.imgFolderZipFile[sysID, 4];
  ZipControlPanels.Text:= FormMain.imgFolderZipFile[sysID, 5];
  ZipControlPanelLayouts.Text:= FormMain.imgFolderZipFile[sysID, 6];
  ZipSelect.Text:= FormMain.imgFolderZipFile[sysID, 7];
  ZipVersus.Text:= FormMain.imgFolderZipFile[sysID, 8];
  ZipWallpapers.Text:= FormMain.imgFolderZipFile[sysID, 9];
  ZipHardware.Text:= FormMain.imgFolderZipFile[sysID, 10];
  ZipCustomImage.Text:= FormMain.imgFolderZipFile[sysID, 11];
  ZipGameSnapshotsButtonUpdate.Enabled:= (sysID in [1, 4, 5, 6]);
end;

procedure TFormPreferences.ImagesFolderZipSelectorSelect(Sender: TObject);
begin
  ImagesFolderZipSelector.Tag:= ImagesFolderZipSelector.ItemsEx[ImagesFolderZipSelector.ItemIndex].ImageIndex;
  SetImagesZipFolders(ImagesFolderZipSelector.Tag);
end;

procedure TFormPreferences.AudioSystemSelectorSelect(Sender: TObject);
begin
  AudioSystemSelector.Tag:= AudioSystemSelector.ItemsEx[AudioSystemSelector.ItemIndex].ImageIndex;
  AudioFolder.Text:= FormMain.AudioFolders[AudioSystemSelector.Tag];
end;

procedure TFormPreferences.AudioFolderChange(Sender: TObject);
begin
  if FormMain.AudioFolders[AudioSystemSelector.Tag] <> AudioFolder.Text then
     FormMain.AudioFolders[AudioSystemSelector.Tag]:= AudioFolder.Text;
end;

procedure TFormPreferences.AudioFolderSelectClick(Sender: TObject);
begin
  FormMain.DialogSelectFolder(AudioFolder, False);
end;

procedure TFormPreferences.MNGFolderSelectClick(Sender: TObject);
begin
  FormMain.DialogSelectFolder(VideoFolder, False);
end;

procedure TFormPreferences.MNGSystemSelectorSelect(Sender: TObject);
begin
  MNGSystemSelector.Tag:= MNGSystemSelector.ItemsEx[MNGSystemSelector.ItemIndex].ImageIndex;
  VideoFolder.Text:= FormMain.MNGFolders[MNGSystemSelector.Tag];
end;

procedure TFormPreferences.VideoFolderChange(Sender: TObject);
begin
  if FormMain.MNGFolders[MNGSystemSelector.Tag] <> VideoFolder.Text then
     FormMain.MNGFolders[MNGSystemSelector.Tag]:= VideoFolder.Text;
end;

procedure TFormPreferences.TabSheetFoldersImagesShow(Sender: TObject);
begin
  UpdatePictureTypesDescriptions;
end;

procedure TFormPreferences.ShowEmuVersionSystemDescriptionClick(
  Sender: TObject);
var
  Node: PVirtualNode;
  Data: pGameInfo;
begin
  if (not FormMain.CheckTotal(FormMain.GamesTreeView)) then
     Exit;

  FormMain.GetSystemID(Data.eROMIdentification);
  if not FormMain.ButtonViewModeStandard.Tag in [2, 3] then
     Exit;

  FormMain.GamesTreeView.BeginUpdate;
  Node:= FormMain.GamesTreeView.GetFirst;
  repeat
    Data:= FormMain.GamesTreeView.GetNodeData(Node);
    case ShowEmuVersionSystemDescription.Checked of
      True:
        begin
          if FormMain.IsSystemEntry(Data.eDriverName) and (FormMain.SystemID_Number <> -1) then
             begin
               if FormMain.EmulatorVersion[FormMain.SystemID_Number] <> '' then
                  Data.eDescription:= FormMain.EmulatorVersion[FormMain.SystemID_Number];
             end;
        end;
      False:
        begin
          if FormMain.IsSystemEntry(Data.eDriverName) then
             Data.eDescription:= FormMain.GetEmuFullDescription(Data.eROMIdentification);
        end;
    end;
    Node:= FormMain.GamesTreeView.GetNext(Node);
  until (not Assigned(Node));
  FormMain.GamesTreeView.EndUpdate;
end;

procedure TFormPreferences.FormCreate(Sender: TObject);
begin
  RunEmulatorStartup.Enabled:= Win32Platform in [0, 1];
  RunEmulatorStartup.Checked:= RunEmulatorStartup.Enabled;
  FormMain.FillEmuDescriptionsSelector(ImagesFolderZipSelector);
  FormMain.FillEmuDescriptionsSelector(AudioSystemSelector);
  FormMain.FillEmuDescriptionsSelector(MNGSystemSelector);
end;

procedure TFormPreferences.ButtonResetAutoGameInfoOrderClick(
  Sender: TObject);
begin
  AutomaticGameInformation1.ItemIndex:= 1;
  AutomaticGameInformation2.ItemIndex:= 2;
  AutomaticGameInformation3.ItemIndex:= 3;
  AutomaticGameInformation4.ItemIndex:= 4;
  AutomaticGameInformation5.ItemIndex:= 5;
end;

procedure TFormPreferences.EnableGamePlayTime_PlayedClick(Sender: TObject);
begin
  FormMain.SetGamePlayTime_Played;
end;

end.

