Subversion Repositories AndroidProjects

Rev

Blame | Last modification | View Log | RSS feed

unit app_main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, XPMan, ComCtrls, IniFiles;

type
  TFormMain = class(TForm)
    PageControl: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    TabSheet3: TTabSheet;
    TabSheet4: TTabSheet;
    TabSheet5: TTabSheet;
    XPManifest: TXPManifest;
    BtnSaveAndQuit: TButton;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    EWidth: TEdit;
    EHeight: TEdit;
    Label2: TLabel;
    Label3: TLabel;
    EHz: TEdit;
    LHz: TLabel;
    CBFullScreen: TCheckBox;
    GroupBox2: TGroupBox;
    TabSheet6: TTabSheet;
    LVSync: TLabel;
    CBVSync: TCheckBox;
    LGamma: TLabel;
    EGamma: TEdit;
    GroupBox3: TGroupBox;
    Label9: TLabel;
    Label10: TLabel;
    EVolume: TEdit;
    CBBackgroundMusic: TCheckBox;
    Label4: TLabel;
    GroupBox4: TGroupBox;
    Label5: TLabel;
    Label7: TLabel;
    EPlayer1Joypad: TEdit;
    Label6: TLabel;
    EPlayer1Up: TEdit;
    Label8: TLabel;
    EPlayer1Down: TEdit;
    GroupBox5: TGroupBox;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    EPlayer2Joypad: TEdit;
    EPlayer2Up: TEdit;
    EPlayer2Down: TEdit;
    GroupBox6: TGroupBox;
    Label17: TLabel;
    Label18: TLabel;
    EMenuAccept: TEdit;
    EMenuCancel: TEdit;
    TabSheet7: TTabSheet;
    GroupBox7: TGroupBox;
    Label15: TLabel;
    EPlayer1PlayerName: TEdit;
    Label16: TLabel;
    EPlayer1CPUName: TEdit;
    Label19: TLabel;
    EPlayer1TextToEnterGame: TEdit;
    GroupBox8: TGroupBox;
    Label20: TLabel;
    Label21: TLabel;
    Label22: TLabel;
    EPlayer2PlayerName: TEdit;
    EPlayer2CPUName: TEdit;
    EPlayer2TextToEnterGame: TEdit;
    GroupBox9: TGroupBox;
    Label23: TLabel;
    CBCanDisplayMenu: TCheckBox;
    Label24: TLabel;
    CBCanQuit: TCheckBox;
    GroupBox10: TGroupBox;
    Label25: TLabel;
    LStoredFrames: TLabel;
    EStoredFrames: TEdit;
    CBMotionBlur: TCheckBox;
    GroupBox11: TGroupBox;
    Label29: TLabel;
    EPingkRed: TEdit;
    EPingkGreen: TEdit;
    Label28: TLabel;
    EPingkBlue: TEdit;
    Label30: TLabel;
    StaticText1: TStaticText;
    StaticText2: TStaticText;
    LMotionBlurRAM: TLabel;
    PageControl1: TPageControl;
    TabSheet8: TTabSheet;
    TabSheet9: TTabSheet;
    TabSheet10: TTabSheet;
    TabSheet11: TTabSheet;
    GroupBox12: TGroupBox;
    Label27: TLabel;
    EMaxPaddleSpeed: TEdit;
    GroupBox13: TGroupBox;
    Label26: TLabel;
    EInertiaMultiplier: TEdit;
    Label31: TLabel;
    EInertiaDecrease: TEdit;
    GroupBox14: TGroupBox;
    Label32: TLabel;
    EBallStartSpeed: TEdit;
    Label33: TLabel;
    EBallSpeedUpTimer: TEdit;
    Label34: TLabel;
    EBallSpeedUpIncrease: TEdit;
    GroupBox15: TGroupBox;
    Label35: TLabel;
    Label36: TLabel;
    EBallMaximumAngularSpeed: TEdit;
    EBallAngularSpeedDecrease: TEdit;
    GroupBox16: TGroupBox;
    Label38: TLabel;
    ETopSpinIntensity: TEdit;
    Label39: TLabel;
    EAngleDeviation: TEdit;
    GroupBox17: TGroupBox;
    Label37: TLabel;
    Label40: TLabel;
    EPowerUpAppearanceTime: TEdit;
    EPowerUpSimultaneousPowerUps: TEdit;
    GroupBox18: TGroupBox;
    Label41: TLabel;
    Label42: TLabel;
    ESpawnBombOnCrystals: TEdit;
    ERandomCrystal: TEdit;
    ERandomConcave: TEdit;
    Label43: TLabel;
    ERandomPixel: TEdit;
    Label44: TLabel;
    ERandomFlowers: TEdit;
    Label45: TLabel;
    ERandomSlowMotion: TEdit;
    Label46: TLabel;
    ERandomBomb: TEdit;
    Label47: TLabel;
    GroupBox19: TGroupBox;
    Label48: TLabel;
    EPlayerTimeout: TEdit;
    Label49: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure CBFullScreenClick(Sender: TObject);
    procedure BtnSaveAndQuitClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure loadInt(const ini: TIniFile; const section, itemname: string; const edit: TEdit; const defaultvalue: integer);
    procedure loadBool(const ini: TIniFile; const section, itemname: string; const checkbox: TCheckBox; const defaultvalue: boolean);
    procedure loadFloat(const ini: TIniFile; const section, itemname: string; const edit: TEdit; const defaultvalue: single);
    procedure loadString(const ini: TIniFile; const section, itemname: string; const edit: TEdit; const defaultvalue: string);

    procedure saveInt(const ini: TIniFile; const section, itemname: string; const edit: TEdit; const defaultvalue: integer);
    procedure saveBool(const ini: TIniFile; const section, itemname: string; const checkbox: TCheckBox; const defaultvalue: boolean);
    procedure saveFloat(const ini: TIniFile; const section, itemname: string; const edit: TEdit; const defaultvalue: single);
    procedure saveString(const ini: TIniFile; const section, itemname: string; const edit: TEdit; const defaultvalue: string);

    procedure loadSettings;
    procedure saveSettings;
    procedure updateForm;
  end;

var
  FormMain: TFormMain;

implementation


{$R *.dfm}


procedure TFormMain.FormCreate(Sender: TObject);
begin
  DecimalSeparator := '.';

  loadSettings;
end;




procedure TFormMain.loadInt(const ini: TIniFile; const section, itemname: string; const edit: TEdit; const defaultvalue: integer);
var value: integer;
begin
  value := ini.ReadInteger(section, itemname, defaultvalue);
  edit.Text := IntToStr(value);
end;


procedure TFormMain.loadBool(const ini: TIniFile; const section, itemname: string; const checkbox: TCheckBox; const defaultvalue: boolean);
var value: boolean;
begin
  value := ini.ReadBool(section, itemname, defaultvalue);
  if (value) then checkbox.Checked := true else checkbox.Checked := false;
end;


procedure TFormMain.loadFloat(const ini: TIniFile; const section, itemname: string; const edit: TEdit; const defaultvalue: single);
var value: single;
begin
  value := ini.ReadFloat(section, itemname, defaultvalue);
  edit.Text := FloatToStrF(value, ffFixed, 10, 2);
end;


procedure TFormMain.loadString(const ini: TIniFile; const section, itemname: string; const edit: TEdit; const defaultvalue: string);
var value: string;
begin
  value := ini.ReadString(section, itemname, defaultvalue);
  edit.Text := value;
end;




procedure TFormMain.saveInt(const ini: TIniFile; const section, itemname: string; const edit: TEdit; const defaultvalue: integer);
var value: integer;
begin
  value := StrToIntDef(edit.Text, 0);
  ini.WriteInteger(section, itemname, value);
end;


procedure TFormMain.saveBool(const ini: TIniFile; const section, itemname: string; const checkbox: TCheckBox; const defaultvalue: boolean);
var value: boolean;
begin
  value := checkbox.Checked;
  ini.WriteBool(section, itemname, value);
end;


procedure TFormMain.saveFloat(const ini: TIniFile; const section, itemname: string; const edit: TEdit; const defaultvalue: single);
var value: single;
    valuestr: string;
begin
  value := StrToFloatDef(edit.Text, 0);
  valuestr := FloatToStrF(value, ffFixed, 10, 2);
  ini.WriteString(section, itemname, valuestr);
end;


procedure TFormMain.saveString(const ini: TIniFile; const section, itemname: string; const edit: TEdit; const defaultvalue: string);
var value: string;
begin
  value := edit.Text;
  ini.WriteString(section, itemname, value);
end;




procedure TFormMain.loadSettings;
var ini: TIniFile;
begin
  ini := TIniFile.Create(ExtractFilePath(application.ExeName) + 'pingk.ini');

  loadInt(ini, 'DISPLAY', 'Width', FormMain.EWidth, 640);
  loadInt(ini, 'DISPLAY', 'Height', FormMain.EHeight, 480);
  loadBool(ini, 'DISPLAY', 'Fullscreen', FormMain.CBFullScreen, true);
  loadInt(ini, 'DISPLAY', 'Hz', FormMain.EHz, 60);
  loadBool(ini, 'DISPLAY', 'VSync', FormMain.CBVSync, true);
  loadFloat(ini, 'DISPLAY', 'Gamma', FormMain.EGamma, 1);

  loadFloat(ini, 'SOUND', 'Volume', FormMain.EVolume, 1);
  loadBool(ini, 'SOUND', 'BackgroundMusic', FormMain.CBBackgroundMusic, true);

  loadInt(ini, 'PLAYER1', 'Joypad', FormMain.EPlayer1Joypad, 0);
  loadInt(ini, 'PLAYER1', 'KeyUp', FormMain.EPlayer1Up, 0);
  loadInt(ini, 'PLAYER1', 'KeyDown', FormMain.EPlayer1Down, 0);
  loadInt(ini, 'PLAYER2', 'Joypad', FormMain.EPlayer2Joypad, 0);
  loadInt(ini, 'PLAYER2', 'KeyUp', FormMain.EPlayer2Up, 0);
  loadInt(ini, 'PLAYER2', 'KeyDown', FormMain.EPlayer2Down, 0);
  loadInt(ini, 'CONTROLS', 'Accept', FormMain.EMenuAccept, 0);
  loadInt(ini, 'CONTROLS', 'Cancel', FormMain.EMenuCancel, 0);

  loadString(ini, 'PLAYER1', 'PlayerName', FormMain.EPlayer1PlayerName, 'Player 1');
  loadString(ini, 'PLAYER1', 'CPUName', FormMain.EPlayer1CPUName, 'CPU 1');
  loadString(ini, 'PLAYER1', 'TextToEnterGame', FormMain.EPlayer1TextToEnterGame, 'Move joystick to enter game');
  loadString(ini, 'PLAYER2', 'PlayerName', FormMain.EPlayer2PlayerName, 'Player 2');
  loadString(ini, 'PLAYER2', 'CPUName', FormMain.EPlayer2CPUName, 'CPU 2');
  loadString(ini, 'PLAYER2', 'TextToEnterGame', FormMain.EPlayer2TextToEnterGame, 'Move joystick to enter game');

  loadFloat(ini, 'GAMEPLAY', 'MaxPaddleSpeed', FormMain.EMaxPaddleSpeed, 300);
  loadFloat(ini, 'GAMEPLAY', 'PaddleInertiaIncreaseMultiplier', FormMain.EInertiaMultiplier, 3.5);
  loadFloat(ini, 'GAMEPLAY', 'PaddleInertiaDecrease', FormMain.EInertiaDecrease, 300);
  loadFloat(ini, 'GAMEPLAY', 'TopSpinIntensity', FormMain.ETopSpinIntensity, 0.18);
  loadFloat(ini, 'GAMEPLAY', 'HitZoneAngleDeviation', FormMain.EAngleDeviation, 0.4);
  loadFloat(ini, 'GAMEPLAY', 'BallStartSpeed', FormMain.EBallStartSpeed, 400);
  loadFloat(ini, 'GAMEPLAY', 'BallSpeedUpTimer', FormMain.EBallSpeedUpTimer, 1);
  loadFloat(ini, 'GAMEPLAY', 'BallSpeedUpIncrease', FormMain.EBallSpeedUpIncrease, 12);
  loadFloat(ini, 'GAMEPLAY', 'BallMaximumAngularSpeed', FormMain.EBallMaximumAngularSpeed, 500);
  loadFloat(ini, 'GAMEPLAY', 'BallAngularSpeedDecrease', FormMain.EBallAngularSpeedDecrease, 10);

  loadFloat(ini, 'GAMEPLAY', 'PowerUpTimer', FormMain.EPowerUpAppearanceTime, 13);
  loadInt(ini, 'GAMEPLAY', 'MaximumPowerUpsPresent', FormMain.EPowerUpSimultaneousPowerUps, 3);
  loadInt(ini, 'GAMEPLAY', 'SpawnPowerUpBombOnCrystals', FormMain.ESpawnBombOnCrystals, 10);
  loadInt(ini, 'GAMEPLAY', 'PowerUpRandomCrystal', FormMain.ERandomCrystal, 2);
  loadInt(ini, 'GAMEPLAY', 'PowerUpRandomConcave', FormMain.ERandomConcave, 2);
  loadInt(ini, 'GAMEPLAY', 'PowerUpRandomPixel', FormMain.ERandomPixel, 2);
  loadInt(ini, 'GAMEPLAY', 'PowerUpRandomFlowers', FormMain.ERandomFlowers, 2);
  loadInt(ini, 'GAMEPLAY', 'PowerUpRandomSlowMotion', FormMain.ERandomSlowMotion, 1);
  loadInt(ini, 'GAMEPLAY', 'PowerUpRandomBomb', FormMain.ERandomBomb, 1);
  loadFloat(ini, 'GAMEPLAY', 'PlayerTimeOutDuration', FormMain.EPlayerTimeout, 15);

  loadBool(ini, 'MENU', 'CanDisplayMenu', FormMain.CBCanDisplayMenu, true);
  loadBool(ini, 'MENU', 'CanQuit', FormMain.CBCanQuit, true);

  loadBool(ini, 'DISPLAY', 'MotionBlur', FormMain.CBMotionBlur, true);
  loadInt(ini, 'DISPLAY', 'MotionBlurFrames', FormMain.EStoredFrames, 10);
  loadFloat(ini, 'PINGK', 'ColorR', FormMain.EPingkRed, 1.0);
  loadFloat(ini, 'PINGK', 'ColorG', FormMain.EPingkGreen, 0.0);
  loadFloat(ini, 'PINGK', 'ColorB', FormMain.EPingkBlue, 0.6);

  ini.Free;

  updateForm;
end;


procedure TFormMain.saveSettings;
var ini: TIniFile;
begin
  ini := TIniFile.Create(ExtractFilePath(application.ExeName) + 'pingk.ini');

  saveInt(ini, 'DISPLAY', 'Width', FormMain.EWidth, 640);
  saveInt(ini, 'DISPLAY', 'Height', FormMain.EHeight, 480);
  saveBool(ini, 'DISPLAY', 'Fullscreen', FormMain.CBFullScreen, true);
  saveInt(ini, 'DISPLAY', 'Hz', FormMain.EHz, 60);
  saveBool(ini, 'DISPLAY', 'VSync', FormMain.CBVSync, true);
  saveFloat(ini, 'DISPLAY', 'Gamma', FormMain.EGamma, 1);

  saveFloat(ini, 'SOUND', 'Volume', FormMain.EVolume, 1);
  saveBool(ini, 'SOUND', 'BackgroundMusic', FormMain.CBBackgroundMusic, true);

  saveInt(ini, 'PLAYER1', 'Joypad', FormMain.EPlayer1Joypad, 0);
  saveInt(ini, 'PLAYER1', 'KeyUp', FormMain.EPlayer1Up, 0);
  saveInt(ini, 'PLAYER1', 'KeyDown', FormMain.EPlayer1Down, 0);
  saveInt(ini, 'PLAYER2', 'Joypad', FormMain.EPlayer2Joypad, 0);
  saveInt(ini, 'PLAYER2', 'KeyUp', FormMain.EPlayer2Up, 0);
  saveInt(ini, 'PLAYER2', 'KeyDown', FormMain.EPlayer2Down, 0);
  saveInt(ini, 'CONTROLS', 'Accept', FormMain.EMenuAccept, 0);
  saveInt(ini, 'CONTROLS', 'Cancel', FormMain.EMenuCancel, 0);

  saveString(ini, 'PLAYER1', 'PlayerName', FormMain.EPlayer1PlayerName, 'Player 1');
  saveString(ini, 'PLAYER1', 'CPUName', FormMain.EPlayer1CPUName, 'CPU 1');
  saveString(ini, 'PLAYER1', 'TextToEnterGame', FormMain.EPlayer1TextToEnterGame, 'Move joystick to enter game');
  saveString(ini, 'PLAYER2', 'PlayerName', FormMain.EPlayer2PlayerName, 'Player 2');
  saveString(ini, 'PLAYER2', 'CPUName', FormMain.EPlayer2CPUName, 'CPU 2');
  saveString(ini, 'PLAYER2', 'TextToEnterGame', FormMain.EPlayer2TextToEnterGame, 'Move joystick to enter game');

  saveFloat(ini, 'GAMEPLAY', 'MaxPaddleSpeed', FormMain.EMaxPaddleSpeed, 300);
  saveFloat(ini, 'GAMEPLAY', 'PaddleInertiaIncreaseMultiplier', FormMain.EInertiaMultiplier, 3.5);
  saveFloat(ini, 'GAMEPLAY', 'PaddleInertiaDecrease', FormMain.EInertiaDecrease, 300);
  saveFloat(ini, 'GAMEPLAY', 'TopSpinIntensity', FormMain.ETopSpinIntensity, 0.18);
  saveFloat(ini, 'GAMEPLAY', 'HitZoneAngleDeviation', FormMain.EAngleDeviation, 0.4);
  saveFloat(ini, 'GAMEPLAY', 'BallStartSpeed', FormMain.EBallStartSpeed, 400);
  saveFloat(ini, 'GAMEPLAY', 'BallSpeedUpTimer', FormMain.EBallSpeedUpTimer, 1);
  saveFloat(ini, 'GAMEPLAY', 'BallSpeedUpIncrease', FormMain.EBallSpeedUpIncrease, 12);
  saveFloat(ini, 'GAMEPLAY', 'BallMaximumAngularSpeed', FormMain.EBallMaximumAngularSpeed, 500);
  saveFloat(ini, 'GAMEPLAY', 'BallAngularSpeedDecrease', FormMain.EBallAngularSpeedDecrease, 10);

  saveFloat(ini, 'GAMEPLAY', 'PowerUpTimer', FormMain.EPowerUpAppearanceTime, 13);
  saveInt(ini, 'GAMEPLAY', 'MaximumPowerUpsPresent', FormMain.EPowerUpSimultaneousPowerUps, 3);
  saveInt(ini, 'GAMEPLAY', 'SpawnPowerUpBombOnCrystals', FormMain.ESpawnBombOnCrystals, 10);
  saveInt(ini, 'GAMEPLAY', 'PowerUpRandomCrystal', FormMain.ERandomCrystal, 2);
  saveInt(ini, 'GAMEPLAY', 'PowerUpRandomConcave', FormMain.ERandomConcave, 2);
  saveInt(ini, 'GAMEPLAY', 'PowerUpRandomPixel', FormMain.ERandomPixel, 2);
  saveInt(ini, 'GAMEPLAY', 'PowerUpRandomFlowers', FormMain.ERandomFlowers, 2);
  saveInt(ini, 'GAMEPLAY', 'PowerUpRandomSlowMotion', FormMain.ERandomSlowMotion, 1);
  saveInt(ini, 'GAMEPLAY', 'PowerUpRandomBomb', FormMain.ERandomBomb, 1);
  saveFloat(ini, 'GAMEPLAY', 'PlayerTimeOutDuration', FormMain.EPlayerTimeout, 15);

  saveBool(ini, 'MENU', 'CanDisplayMenu', FormMain.CBCanDisplayMenu, true);
  saveBool(ini, 'MENU', 'CanQuit', FormMain.CBCanQuit, true);

  saveBool(ini, 'DISPLAY', 'MotionBlur', FormMain.CBMotionBlur, true);
  saveInt(ini, 'DISPLAY', 'MotionBlurFrames', FormMain.EStoredFrames, 10);
  saveFloat(ini, 'PINGK', 'ColorR', FormMain.EPingkRed, 1.0);
  saveFloat(ini, 'PINGK', 'ColorG', FormMain.EPingkGreen, 0.0);
  saveFloat(ini, 'PINGK', 'ColorB', FormMain.EPingkBlue, 0.6);

  ini.Free;
end;


procedure TFormMain.updateForm;
var width, height, storedframes: integer;
begin
  FormMain.LHz.Enabled := FormMain.CBFullScreen.Checked;
  FormMain.EHz.Enabled := FormMain.CBFullScreen.Checked;
  FormMain.LStoredFrames.Enabled := FormMain.CBMotionBlur.Checked;
  FormMain.EStoredFrames.Enabled := FormMain.CBMotionBlur.Checked;

  if (FormMain.CBMotionBlur.Checked) then
  begin
    try
      width := StrToIntDef(FormMain.EWidth.Text, 0);
      height := StrToIntDef(FormMain.EHeight.Text, 0);
      storedframes := StrToIntDef(FormMain.EStoredFrames.Text, 0);
      FormMain.LMotionBlurRAM.Caption := IntToStr(width * height * storedframes * 4) + ' Byte';
    except
    end;
  end else FormMain.LMotionBlurRAM.Caption := '0 Byte';
end;


procedure TFormMain.CBFullScreenClick(Sender: TObject);
begin
  updateForm;
end;


procedure TFormMain.BtnSaveAndQuitClick(Sender: TObject);
begin
  saveSettings;
  Close;
end;

end.