SRL Archive - Research & Development Lounge

Dg's Player Form


Dgby714

2011-09-06 23:25:18


I started this a few days ago and would like some input (suggestions). Or if anyone would like to help?

I know the script options form looks like total shit…..

  1. Finish Loading Stats/Player info.
  2. Beautify script options form.
  3. Clean up code. (Messy and Bloated)

{$IFNDEF IS_INCLUDE}
program PlayerForm;
{$I SRL\SRL.simba}
{$WARNING This is a include file. You shouldn't be running this file.}
{$ENDIF}

type
TPFMembers = (pfmEther, pfmMembersOnly);

TPFAddition = (pfaCustomTitle, pfaNick, pfaNoPin,
pfaNoMembers, pfaNoSaveLoad, pfaNotHidden,
pfaNoEncyrpt, pfaScriptKey, pfaNoSKWarn,
pfaNoScriptOpt, pfaScriptSalt, pfaScriptFile,
pfaAutoLoad, pfaClearPlayers, pfaMembersOnly,
pfaNoStats);
TPFAdditions = set of TPFAddition;

TPSFOption = record
Typ: (pfsoInt, pfsoStr, pfsoBool, pfsoExt);
Id: integer;
Name, Desc: string;
Value: Variant;
Visible, Enabled: boolean;
_Obj: TObject;
end;

TPFSOptions = array of TPSFOption;

TPFOptions = record
Title: string;

Additions: TPFAdditions;

ScriptKey: string;
ScriptSalt: string;
ScriptFile: string;
ScriptOptions: TPFSOptions;
end;

const
MENU_FILE = 0;
MENUITEM_SAVE = 1;
MENUITEM_LOAD = 2;
MENUITEM_EXIT = 4;

MENU_STATS = 5;
MENUITEM_LOGIN = 6;
MENUITEM_LOGOUT = 7;
MENUITEM_INFO = 8;

EDIT_USER = 0;
EDIT_PASS = 1;
EDIT_PIN = 2;

CHECKBOX_ACTIVE = 0;
CHECKBOX_MEMBER = 1;

BUTTON_GENERAL = 0;
BUTTON_REMOVE = 1;
BUTTON_START = 2;
BUTTON_SCRIPT = 3;

var
_Options: TPFOptions;
PForm, SForm: TForm;
Menu: TMainMenu;
MenuItems: array[0..8] of TMenuItem;
ListBox: TListBox;
Edits: array [0..2] of TEdit;
CheckBoxes: array [0..1] of TCheckbox;
Buttons: array[0..3] of TButton;
EditMode: boolean;

{ StatsForm }
StatsForm: TForm;
StatsEdits: array[0..1] of TEdit;
StatsButtons: array[0..1] of TButton;

function BoolToInt(const B: boolean): LongInt;
begin
Result := 0;
if (B) then
Result := 1;
end;

function StringToChars(const S: string): string;
var
L, I: LongInt;
begin
Result := '';
L := Length(S);
for I := 1 to L do
Result := Result + '#' + IntToStr(Ord(S[I]));
end;

procedure SavePlayers();
var
Data, Salt, Filename, _Data: string;
H, I, J, K, FileP: LongInt;
begin
Data := '';

if (pfaScriptKey in _Options.Additions) then
Data := Data + 'SK' + _Options.ScriptKey + #10;

if (pfaScriptSalt in _Options.Additions) then
begin
Salt := _Options.ScriptKey;
rc6_encrypt(_Options.ScriptSalt, htSHA512, Salt);
Data := Data + 'SS' + Base64Encode(Salt) + #10;
Salt := '';
end;

if (not (InputQuery('Saving Players...', 'Password: ', Salt))) then
Exit;

if (pfaScriptSalt in _Options.Additions) then
Salt := Salt + SHA512(_Options.ScriptSalt);


if (not (pfaNoStats in _Options.Additions)) then
begin
_Data := stats_UserName + ':' + stats_UserPass;
if (_Data <> ':') then
begin
rc6_encrypt(Salt, htSHA512, _Data);
Data := Data + 'SI' + Base64Encode(_Data) + #10;
end;
end;


H := High(Players);
for I := 0 to H do
with Players[I] do
begin
_Data := Format('%s:%s:%s:%s:%s:', [BoolToStr(Active), Name, Pass, Pin, BoolToStr(Member)]);

J := High(Booleans);
for K := 0 to J do
_Data := _Data + IntToStr(BoolToInt(Booleans[K]));
_Data := _Data + ':';

J := High(Integers);
for K := 0 to J do
begin
_Data := _Data + IntToStr(Integers[K]);
if (K < J) then
_Data := _Data + ',';
end;
_Data := _Data + ':';

J := High(Strings);
for K := 0 to J do
begin
_Data := _Data + StringToChars(Strings[K]);
if (K < J) then
_Data := _Data + ',';
end;
_Data := _Data + ':';

J := High(Extendeds);
for K := 0 to J do
begin
_Data := _Data + FloatToStr(Extendeds[K]);
if (K < J) then
_Data := _Data + ',';
end;

rc6_decrypt(Salt, htSHA512, _Data);
Data := Data + 'UI' + Base64Encode(_Data) + #10;
end;

while (not (InputQuery('Saving Players...', 'Filename: [players.dat]', Filename))) do;
if (Filename = '') then
Filename := 'players.dat';

FileP := RewriteFile(ScriptPath + Filename, False);
try
WriteFileString(FileP, Data);
finally
CloseFile(FileP);
end;
end;

procedure LoadPlayers();
begin
end;

procedure RemovePlayerArrI(const Index: Integer);
var
H, I: Integer;
begin
H := High(Players);
for I := Index to H - 1 do
Players[I] := Players[I + 1];
SetLength(Players, Length(Players) - 1);
end;

function FormatPlayerName(Player: TUser): string;
begin
Result := '[' + Copy(BoolToStr(Player.Active), 1, 1) + '] ' + Player.Name;
end;

procedure Click(Sender: TObject);
var
L, X1, X2, Y1, Y2, H, I, Client: integer;
Responce: string;
begin
case Sender of
ListBox: if (ListBox.Items.Count <> 0) then
begin
Buttons[BUTTON_GENERAL].Caption := 'Edit';
Buttons[BUTTON_GENERAL].Enabled := True;
Buttons[BUTTON_REMOVE].Enabled := True;
end;
MenuItems[MENUITEM_SAVE]: SavePlayers();
MenuItems[MENUITEM_LOAD]: ;
MenuItems[MENUITEM_EXIT]: PForm.Close;
MenuItems[MENUITEM_LOGIN]: begin
MenuItems[MENUITEM_LOGIN].Enabled := False;
StatsForm.Show;
end;
MenuItems[MENUITEM_LOGOUT]: begin
StatsEdits[0].Text := '';
StatsEdits[1].Text := '';
MenuItems[MENUITEM_LOGIN].Enabled := True;
MenuItems[MENUITEM_LOGOUT].Enabled := False;
MenuItems[MENUITEM_INFO].Enabled := False;
end;
MenuItems[MENUITEM_INFO]: MessageDlg('Stats Info', Format('You are currently logged in as %s!', [StatsEdits[0].Text]), mtInformation, [mbOK]);
Buttons[BUTTON_REMOVE]: begin
RemovePlayerArrI(ListBox.ItemIndex);
ListBox.Items.Delete(ListBox.ItemIndex);
Buttons[BUTTON_GENERAL].Enabled := False;
Buttons[BUTTON_REMOVE].Enabled := False;
end;
Buttons[BUTTON_SCRIPT]: begin
SetDesktopAsClient();
GetClientDimensions(X1, Y1);
GetMousePos(X2, Y2);

while (X2 + SForm.Width > X1 - 4) do
Dec(X2);
while (Y2 + SForm.Height > Y1 - 4) do
Dec(Y2);

SForm.Left := X2;
SForm.Top := Y2;

Buttons[BUTTON_SCRIPT].Enabled := False;
SForm.Show;
end;
Buttons[BUTTON_GENERAL]: begin
if (EditMode) then
begin
EditMode := False;
L := ListBox.ItemIndex;
ListBox.Items.Strings[L] := FormatPlayerName(Players[L]);
end else
begin
if (Buttons[BUTTON_GENERAL].Caption = 'Edit') then
begin
EditMode := True;
ListBox.Enabled := False;
Buttons[BUTTON_GENERAL].Caption := 'Save';
with Players[ListBox.ItemIndex] do
begin
Edits[EDIT_USER].Text := Name;
Edits[EDIT_PASS].Text := Pass;
Edits[EDIT_PASS].PasswordChar := '*';
Edits[EDIT_PIN].Text := Pin;
Edits[EDIT_PIN].PasswordChar := '*';
CheckBoxes[CHECKBOX_ACTIVE].Checked := Active;
CheckBoxes[CHECKBOX_MEMBER].Checked := Member;

H := High(_Options.ScriptOptions);
for I := 0 to H do
with _Options.ScriptOptions[I] do
case Typ of
pfsoBool: TCheckBox(_Obj).Checked := Booleans[Id];
pfsoExt: TEdit(_Obj).Text := FloatToStr(Extendeds[Id]);
pfsoInt: TEdit(_Obj).Text := IntToStr(Integers[Id]);
pfsoStr: TEdit(_Obj).Text := Strings[Id];
end;
end;
Buttons[BUTTON_GENERAL].Enabled := True;
Exit;
end;

L := ListBox.Items.Add('Temp Player ' + IntToStr(Random(500)));
if (Length(Players) < L + 1) then
SetLength(Players, L + 1);
end;

with Players[L] do
begin
Name := Edits[EDIT_USER].Text;
Pass := Edits[EDIT_PASS].Text;
if (not ((pfaNoPin in _Options.Additions) or (Edits[EDIT_PIN].Text = Edits[EDIT_PIN].Name))) then
Pin := Edits[EDIT_PIN].Text;
Active := CheckBoxes[CHECKBOX_ACTIVE].Checked;
Member := CheckBoxes[CHECKBOX_MEMBER].Checked;

SetLength(Strings, 100);
SetLength(Integers, 100);
SetLength(Booleans, 100);
SetLength(Extendeds, 100);
SetLength(Arrays, 100);

H := High(_Options.ScriptOptions);
for I := 0 to H do
with _Options.ScriptOptions[I] do
case Typ of
pfsoBool: Booleans[Id] := TCheckBox(_Obj).Checked;
pfsoExt: Extendeds[Id] := StrToFloatDef(TEdit(_Obj).Text, Extended(Value));
pfsoInt: Integers[Id] := StrToIntDef(TEdit(_Obj).Text, Integer(Value));
pfsoStr: Strings[Id] := TEdit(_Obj).Text;
end;
end;
ListBox.Items.Strings[L] := FormatPlayerName(Players[L]);

Edits[EDIT_USER].Text := Edits[EDIT_USER].Name;
Edits[EDIT_USER].Font.Color := clGray;
Edits[EDIT_USER].Font.Style := [fsItalic];
Edits[EDIT_PASS].Text := Edits[EDIT_PASS].Name;
Edits[EDIT_PASS].Font.Color := clGray;
Edits[EDIT_PASS].Font.Style := [fsItalic];
Edits[EDIT_PASS].PasswordChar := #0;
Edits[EDIT_PIN].Text := Edits[EDIT_PIN].Name;
Edits[EDIT_PIN].Font.Color := clGray;
Edits[EDIT_PIN].Font.Style := [fsItalic];
Edits[EDIT_PIN].PasswordChar := #0;
CheckBoxes[CHECKBOX_MEMBER].Checked := (pfaMembersOnly in _Options.Additions);
H := High(_Options.ScriptOptions);
for I := 0 to H do
with _Options.ScriptOptions[I] do
case Typ of
pfsoBool: TCheckBox(_Obj).Checked := Boolean(Value);
pfsoExt: TEdit(_Obj).Text := FloatToStr(Extended(Value));
pfsoInt: TEdit(_Obj).Text := IntToStr(Integer(Value));
pfsoStr: TEdit(_Obj).Text := String(Value);
end;
ListBox.Enabled := True;
end;
StatsButtons[0]: begin
MenuItems[MENUITEM_LOGIN].Enabled := True;
StatsForm.Hide;
end;
StatsButtons[1]: begin
Client := InitializeHTTPClientWrap(False);
AddPostVariable(Client, 'user', StatsEdits[0].Text);
AddPostVariable(Client, 'password', StatsEdits[1].Text);
Responce := PostHTTPPageEx(Client, 'http://stats.villavu.com/api/commit');
FreeHTTPClient(Client);

if (Responce = '120') then
begin
MenuItems[MENUITEM_LOGIN].Enabled := False;
MenuItems[MENUITEM_LOGOUT].Enabled := True;
MenuItems[MENUITEM_INFO].Enabled := True;
StatsForm.Hide;
stats_UserName := StatsEdits[0].Text;
stats_UserPass := StatsEdits[1].Text;
Exit;
end;

if (Responce = '110') then
begin
MessageDlg('Stats Login', 'Invalid User/Pass.', mtWarning, [mbOK]);
StatsButtons[1].Enabled := False;
Exit;
end;

if (Responce = '') then
begin
MessageDlg('Stats Login', 'No Responce from Server.'#13#10'Are you sure your connected to the internet?'#13#10'Is the server down?', mtError, [mbOK]);
Exit;
end;

DebugLn('Unknown Error Code "' + Responce + '"');
end;
end;

Buttons[BUTTON_START].Enabled := (ListBox.Items.Count > 0) and (not (EditMode));

if (not (Sender = Buttons[BUTTON_SCRIPT])) then
begin
SForm.Hide;
Buttons[BUTTON_SCRIPT].Enabled := (Length(_Options.ScriptOptions) > 0);
end;
end;

procedure _Enter(Sender: TObject);
begin
with TEdit(Sender) do
if (Text = Hint) then
begin
Text := '';
Font.Color := clBlack;
Font.Style := [];
if (Tag and $01 = $01) then
PasswordChar := '*';
end;

if (not (EditMode)) then
Buttons[BUTTON_GENERAL].Caption := 'Add';
Buttons[BUTTON_REMOVE].Enabled := False;
end;

procedure _Exit(Sender: TObject);
begin
with TEdit(Sender) do
if (Text = '') then
begin
Text := Hint;
Font.Color := clGray;
Font.Style := [fsItalic];
if (Tag and $01 = $01) then
PasswordChar := #0;
end;
end;

procedure RestrictNumbers(Sender: TObject);
begin
with TEdit(Sender) do
Text := ExtractFromStr(Text, Numbers);
end;

procedure Change(Sender: TObject);
var
oldSS: LongInt;
begin
Buttons[BUTTON_GENERAL].Enabled := ((Edits[EDIT_USER].Text <> Edits[EDIT_USER].Name) and
(Edits[EDIT_USER].Text <> '') and
(Edits[EDIT_PASS].Text <> Edits[EDIT_PASS].Name) and
(Edits[EDIT_PASS].Text <> '') and
((Edits[EDIT_PIN].Text <> '') or
(not (Edits[EDIT_PIN].Enabled))));

if (Sender = Edits[EDIT_PIN]) then
with Edits[EDIT_PIN] do
if (not ((Text = Name) or (Text = ''))) then
begin
oldSS := SelStart;
Text := ExtractFromStr(Text, Numbers);
SelStart := Min(Length(Text), oldSS);
end;

StatsButtons[1].Enabled := ((StatsEdits[0].Text <> '') and
(StatsEdits[0].Text <> StatsEdits[0].Hint) and
(StatsEdits[1].Text <> '') and
(StatsEdits[1].Text <> StatsEdits[1].Hint));
end;

procedure Outline(Sender: TObject);
begin
if (not (Sender is TForm)) then
Exit;

with TForm(Sender) do
with Canvas do
begin
Brush.Style := bsSolid;
Brush.Color := clDefault;
Rectangle(1, 1, Width - 1, Height - 1);
end;
end;

function _PlayerForm(const Options: TPFOptions): boolean;
var
H, I, J: integer;
begin
_Options := Options;

PForm := TForm.Create(nil);
try
with PForm do
begin
if (pfaCustomTitle in Options.Additions) then
Caption := Options.Title
else
Caption := 'Player Form';

SetBounds(0, 0, 350, 175);
Position := poScreenCenter;
BorderStyle := bsSingle;

OnActivate := @Click;
end;

Menu := TMainMenu.Create(PForm);

MenuItems[MENU_FILE] := TMenuItem.Create(Menu);
MenuItems[MENU_FILE].Caption := 'File';
Menu.Items.Add(MenuItems[MENU_FILE]);

MenuItems[MENUITEM_SAVE] := TMenuItem.Create(MenuItems[MENU_FILE]);
MenuItems[MENUITEM_SAVE].Caption := 'Save';
//MenuItems[MENUITEM_SAVE].Enabled := False;
MenuItems[MENUITEM_SAVE].OnClick := @Click;
MenuItems[MENUITEM_SAVE].Visible := (not (pfaNoSaveLoad in Options.Additions));
MenuItems[MENU_FILE].Add(MenuItems[MENUITEM_SAVE]);

MenuItems[MENUITEM_LOAD] := TMenuItem.Create(MenuItems[MENU_FILE]);
MenuItems[MENUITEM_LOAD].Caption := 'Load';
MenuItems[MENUITEM_LOAD].Enabled := False;
MenuItems[MENUITEM_LOAD].OnClick := @Click;
MenuItems[MENUITEM_LOAD].Visible := (not (pfaNoSaveLoad in Options.Additions));
MenuItems[MENU_FILE].Add(MenuItems[MENUITEM_LOAD]);

MenuItems[3] := TMenuItem.Create(MenuItems[MENU_FILE]);
MenuItems[3].Caption := '-';
MenuItems[3].Visible := (not (pfaNoSaveLoad in Options.Additions));
MenuItems[MENU_FILE].Add(MenuItems[3]);

MenuItems[MENUITEM_EXIT] := TMenuItem.Create(MenuItems[MENU_FILE]);
MenuItems[MENUITEM_EXIT].Caption := 'Exit';
MenuItems[MENUITEM_EXIT].OnClick := @Click;
MenuItems[MENU_FILE].Add(MenuItems[MENUITEM_EXIT]);

MenuItems[MENU_STATS] := TMenuItem.Create(Menu);
MenuItems[MENU_STATS].Caption := 'Stats';
Menu.Items.Add(MenuItems[MENU_STATS]);

MenuItems[MENUITEM_LOGIN] := TMenuItem.Create(MenuItems[MENU_STATS]);
MenuItems[MENUITEM_LOGIN].Caption := 'Login';
MenuItems[MENUITEM_LOGIN].OnClick := @Click;
MenuItems[MENU_STATS].Add(MenuItems[MENUITEM_LOGIN]);

MenuItems[MENUITEM_LOGOUT] := TMenuItem.Create(MenuItems[MENU_STATS]);
MenuItems[MENUITEM_LOGOUT].Caption := 'Logout';
MenuItems[MENUITEM_LOGOUT].OnClick := @Click;
MenuItems[MENUITEM_LOGOUT].Enabled := False;
MenuItems[MENU_STATS].Add(MenuItems[MENUITEM_LOGOUT]);

MenuItems[3] := TMenuItem.Create(MenuItems[MENU_STATS]);
MenuItems[3].Caption := '-';
MenuItems[MENU_STATS].Add(MenuItems[3]);

MenuItems[MENUITEM_INFO] := TMenuItem.Create(MenuItems[MENU_STATS]);
MenuItems[MENUITEM_INFO].Caption := 'Info';
MenuItems[MENUITEM_INFO].OnClick := @Click;
MenuItems[MENUITEM_INFO].Enabled := False;
MenuItems[MENU_STATS].Add(MenuItems[MENUITEM_INFO]);

ListBox := TListBox.Create(PForm);
with ListBox do
begin
Parent := PForm;
Caption := 'Accounts';

OnClick := @Click;

Top := 3;
Left := 3;
Width := 175;
Height := 148;

if (not (pfaClearPlayers in Options.Additions)) then
begin
H := High(Players);
for I := 0 to H do
Items.Add(Players[I].Name);
end else
SetLength(Players, 0);
end;

Edits[EDIT_USER] := TEdit.Create(PForm);
with Edits[EDIT_USER] do
begin
Parent := PForm;

Hint := 'Username';
Text := Hint;
MaxLength := 12;
Font.Style := [fsItalic];
Font.Color := clGray;
OnEnter := @_Enter;
OnExit := @_Exit;
OnChange := @Change;

Top := 3;
Left := 190;
Width := 150;
end;

Edits[EDIT_PASS] := TEdit.Create(PForm);
with Edits[EDIT_PASS] do
begin
Parent := PForm;

Hint := 'Password';
Text := Hint;
Tag := $01;
MaxLength := 32;
Font.Style := [fsItalic];
Font.Color := clGray;
OnEnter := @_Enter;
OnExit := @_Exit;
OnChange := @Change;

Top := 28;
Left := 190;
Width := 150;
end;

CheckBoxes[CHECKBOX_ACTIVE] := TCheckBox.Create(PForm);
with CheckBoxes[CHECKBOX_ACTIVE] do
begin
Parent := PForm;

Caption := 'Active';
Checked := True;

Top := 55;
Left := 190;
end;

CheckBoxes[CHECKBOX_MEMBER] := TCheckBox.Create(PForm);
with CheckBoxes[CHECKBOX_MEMBER] do
begin
Parent := PForm;

Caption := 'Member';

Top := 55;
Left := 245;

if (pfaMembersOnly in Options.Additions) then
begin
Checked := True;
Enabled := False;
Hint := 'This script requires membership to run.';
ShowHint := True;
end;

if (pfaNoMembers in Options.Additions) then
Visible := False;
end;

Edits[EDIT_PIN] := TEdit.Create(PForm);
with Edits[EDIT_PIN] do
begin
Parent := PForm;

Hint := 'Pin';
Text := Hint;
Tag := $01;
MaxLength := 4;
Font.Size := 7;
Font.Style := [fsItalic];
Font.Color := clGray;
OnEnter := @_Enter;
OnExit := @_Exit;
OnChange := @Change;

Top := 53;
Left := 310;
Width := 30;

if (pfaNoPin in Options.Additions) then
begin
Enabled := False;
Hint := 'This script doesn''t need your pin.';
ShowHint := True;
end;
end;

Buttons[BUTTON_GENERAL] := TButton.Create(PForm);
with Buttons[BUTTON_GENERAL] do
begin
Parent := PForm;

Caption := 'Add';
OnClick := @Click;
Enabled := False;

Top := 110;
Left := 190;
Width := 70;
Height := 20;
end;

Buttons[BUTTON_REMOVE] := TButton.Create(PForm);
with Buttons[BUTTON_REMOVE] do
begin
Parent := PForm;

Caption := 'Remove';
OnClick := @Click;
Enabled := False;

Top := 130;
Left := 190;
Width := 70;
Height := 20;
end;

Buttons[BUTTON_START] := TButton.Create(PForm);
with Buttons[BUTTON_START] do
begin
Parent := PForm;

Caption := 'Start';
OnClick := @Click;
ModalResult := mrOk;
Enabled := False;

Top := 130;
Left := 270;
Width := 70;
Height := 20;
end;

Buttons[BUTTON_SCRIPT] := TButton.Create(PForm);
with Buttons[BUTTON_SCRIPT] do
begin
Parent := PForm;

Caption := 'Script Options';
OnClick := @Click;

Top := 78;
Left := 220;
Width := 95;
Height := 25;

if (Length(Options.ScriptOptions) = 0) then
begin
Enabled := False;
Hint := 'This script doesn''t have any extra options.';
ShowHint := True;
end;

if (pfaNoScriptOpt in Options.Additions) then
Visible := False;
end;

SForm := TForm.Create(PForm);
with SForm do
begin
Caption := 'Script Options';

Width := 58;
if (Length(Options.ScriptOptions) > 0) then
Width:= 182;

Height := (24 * Length(Options.ScriptOptions)) + 8;
BorderStyle := bsNone;

OnPaint := @Outline;
end;


//TODO: Rewrite this shitty ScriptOptions
H := High(Options.ScriptOptions);
for I := 0 to H do
begin
if (Options.ScriptOptions[I]._Obj <> nil) then
Continue;

case Options.ScriptOptions[I].Typ of
pfsoInt, pfsoExt, pfsoStr: begin
J := 0;

with TLabel.Create(SForm) do
begin
Parent := SForm;
Name := 'ScriptOption_' + IntToStr(I) + '_L';
Caption := Options.ScriptOptions[I].Name;

Enabled := Options.ScriptOptions[I].Enabled;
Visible := Options.ScriptOptions[I].Visible;

Top := (I * 24) + 4;
Left := 4;

J := Width + 20; //Weird...

if (Options.ScriptOptions[I].Desc <> '') then
begin
Hint := Options.ScriptOptions[I].Desc;
ShowHint := True;
end;
end;

Options.ScriptOptions[I]._Obj := TEdit.Create(SForm);
with TEdit(Options.ScriptOptions[I]._Obj) do
begin
Parent := SForm;
Name := 'ScriptOption_' + IntToStr(I);
Text := Options.ScriptOptions[I].Value;

Enabled := Options.ScriptOptions[I].Enabled;
Visible := Options.ScriptOptions[I].Visible;

Width := 170 - J;
Top := (I * 24) + 2;
Left := J + 8;


if (Options.ScriptOptions[I].Typ = pfsoInt) then
OnChange := @RestrictNumbers;
end;
end;
pfsoBool: begin
Options.ScriptOptions[I]._Obj := TCheckBox.Create(SForm);
with TCheckBox(Options.ScriptOptions[I]._Obj) do
begin
Parent := SForm;
Name := 'ScriptOption_' + IntToStr(I);
Caption := Options.ScriptOptions[I].Name;

Enabled := Options.ScriptOptions[I].Enabled;
Visible := Options.ScriptOptions[I].Visible;
Checked := Boolean(Options.ScriptOptions[I].Value);

Top := (I * 24) + 4;
Left := 4;

if (Options.ScriptOptions[I].Desc <> '') then
begin
Hint := Options.ScriptOptions[I].Desc;
ShowHint := True;
end;
end;
end;
end;
end;

StatsForm := TForm.Create(PForm);
with StatsForm do
begin
Parent := PForm;
Caption := 'Stats';
BorderStyle := bsNone;

Top := 3;
Left := 185;
Width := 156;
Height := 148;

ShowHint := True;
end;

with TEdit.Create(StatsForm) do //Small Hack...
begin
Parent := StatsForm;

Width := 0;
Height := 0;

ReadOnly := True;
end;

StatsEdits[0] := TEdit.Create(StatsForm);
with StatsEdits[0] do
begin
Parent := StatsForm;

Top := 35;
Left := 3;
Width := 150;
Height := 20;

Hint := 'Username';
Text := Hint;
OnChange := @Change;
OnEnter := @_Enter;
OnExit := @_Exit;

Font.Color := clGray;
Font.Style := [fsItalic];
end;

StatsEdits[1] := TEdit.Create(StatsForm);
with StatsEdits[1] do
begin
Parent := StatsForm;

Top := 60;
Left := 3;
Width := 150;
Height := 20;

Hint := 'Password';
Tag := $01;
Text := Hint;
OnChange := @Change;
OnEnter := @_Enter;
OnExit := @_Exit;

Font.Color := clGray;
Font.Style := [fsItalic];
end;

StatsButtons[0] := TButton.Create(StatsForm);
with StatsButtons[0] do
begin
Parent := StatsForm;
Caption := 'Cancel';

Top := 90;
Left := 3;
Width := 75;
Height := 24;

OnClick := @Click;
end;

StatsButtons[1] := TButton.Create(StatsForm);
with StatsButtons[1] do
begin
Parent := StatsForm;
Caption := 'Login';
Enabled := False;

Top := 90;
Left := 78;
Width := 75;
Height := 24;

OnClick := @Click;
Default := True;
end;

PForm.ShowModal;
Result := (PForm.ModalResult = mrOk);
finally
PForm.Free;
end;
end;

var
_TempOptions: TPFOptions;
_TempResult: boolean;

procedure _PlayerFormWrap();
begin
_TempResult := _PlayerForm(_TempOptions);
end;

function PlayerForm(const Options: TPFOptions): boolean;
var
V: TVariantArray;
begin
_TempOptions := Options;
_TempResult := False;
ThreadSafeCall('_PlayerFormWrap', V);
Result := _TempResult;
end;

{$IFNDEF IS_INCLUDE}
var
Options: TPFOptions;

begin
SetupSRL;

with Options do
begin
Title := 'Example';
Additions := [pfaCustomTitle, pfaScriptKey, pfaNoPin, pfaMembersOnly, pfaScriptSalt];
ScriptKey := 'EmptyExample';
ScriptSalt := 'FUCK OFF!';

SetLength(ScriptOptions, 2);
with ScriptOptions[0] do
begin
Typ := pfsoInt;
Name := 'Ex. Int';
Desc := 'This is an example integer option.';
Value := 42;
Visible := True;
Enabled := True;
end;

with ScriptOptions[1] do
begin
Typ := pfsoBool;
Name := 'Ex. Bool';
Desc := 'This is an example boolean option.';
Value := True;
Visible := True;
Enabled := True;
end;
end;

WriteLn(PlayerForm(Options));
WriteLn(Players);
end.
{$ENDIF}

Coh3n

2011-09-07 00:04:38

Looking awesome. I like how you did a lot of things and I'm definitely going to use some techniques for the MSI form. :)

bevardis

2011-09-07 10:59:49

Why is the windowish look so blanky on this one? Or was it just the background?

Dgby714

2011-09-07 16:47:55

Updated.
- Added Stats Login Form.

mormonman

2011-09-07 17:55:53

Are you eventually going to save "Logins" between script starts?

Dgby714

2011-09-07 18:00:52

From: mormonman
Are you eventually going to save "Logins" between script starts?


"Logins"? For the stats thing? Yes!

And if you mean player information. Yes, I already have some functions started for it.

mormonman

2011-09-07 18:31:18

From: Dgby714
"Logins"? For the stats thing? Yes!

And if you mean player information. Yes, I already have some functions started for it.


Stats thing :)

What file format do you plan on using to save the player information?

Dgby714

2011-09-07 22:22:35

From: mormonman
Stats thing :)

What file format do you plan on using to save the player information?


Don't know yet… Tho I might just add an option into Simba to allow script to have global settings (Instead of per-script) and save the Stats info into Simbas settings. Player info will be flatfile or ini tho I like flatfile better.

Dgby714

2012-01-11 00:22:28

BACK FROM THE GRAVE!!!

I've started on this project again.

Added saving Player info and Stats info.
Encrypted with RC6.

Coh3n

2012-01-11 00:40:56

I wouldn't mind replacing SRL's player form with this when it's done. SRL's doesn't currently work properly, and I'm not about to be the one to look through and figure out why.