PDA

View Full Version : SRL Stats form



Chris
07-27-2012, 04:31 PM
After I saw this thread yesterday: villavu.com/forum/showthread.php?t=87140, I decided to make something like that to practise my form-skills :p
Here is what came out:

http://i50.tinypic.com/19pijl.png

You could open and run it with Simba to see how it works, it is also fairly simple to add into a script:
program new;
//{$i srl/srl.simba}

var
StatsForm: TForm;
EditArray: Array [0..1] of TEdit;
Done: Boolean;

procedure Stats(Username, Password: string);
begin
Done := True;
//SetupSRLStats(ScriptID, Username, Password); // Change ScriptID to the ID of your SRL Stats script.
end;

procedure CloseStatsForm(Sender: TObject; var Action: TCloseAction);
begin
end;

procedure PassCharEdit2(Sender: TObject);
begin
EditArray[1].PasswordChar := '*';
end;

procedure AClick(Sender: TObject);
var
a, b: string;
begin
case ToStr(Sender) of
'TEdit':
case (Sender as TEdit).Tag of
0:
if EditArray[0].Text = 'SRL Stats Username' then
EditArray[0].CLEAR;
1:
begin
if EditArray[1].Text = 'SRL Stats Password' then
EditArray[1].CLEAR;
EditArray[1].PasswordChar := '*';
end;
end;
'TButton':
case (Sender as TButton).Tag of
0:
begin
a := EditArray[0].Text;
b := EditArray[1].Text;
StatsForm.Close();
Writeln('SRL Stats: Setting up.. Welcome ' + a + '.');
Stats(a, b);
end;
1:
begin
StatsForm.Close();
writeln('SRL Stats: Setting up as Anonymous.');
Stats('Anonymous', 'anon1337');
end;
end;
end;
end;

procedure CreateStatsForm;
var
AButton: TButton;
ALabel: TLabel;
I: Integer;
Captions: TStringArray;
begin
StatsForm := TForm.Create(nil);
StatsForm.SetBounds(50, 50, 240, 150);
StatsForm.Position := poMainFormCenter;
StatsForm.BorderStyle := bsDialog;
StatsForm.Caption := 'SRL Stats';
StatsForm.OnClose := @CloseStatsForm;

Captions := ['Username:', 'Password:'];
for I := 0 to High(Captions) do
begin
ALabel := TLabel.Create(StatsForm);
ALabel.Parent := StatsForm;
ALabel.Top := 25 + (I * 37);
ALabel.Left := 30;
ALabel.Caption := Captions[I];
ALabel.Font.Size := 10;
ALabel.Font.Name := 'Comic Sans MS';
end;

Captions := ['Set up', 'Cancel'];
for I := 0 to High(Captions) do
begin
AButton := TButton.Create(StatsForm);
AButton.Left := 35 + (I * 100);
AButton.Top := 105;
AButton.Width := 70;
AButton.Height := 25;
AButton.CAPTION := Captions[I];
AButton.Tag := I;
AButton.ONCLICK := @AClick;
AButton.Parent := StatsForm;
end;

Captions := ['SRL Stats Username', 'SRL Stats Password'];
for i := 0 to 1 do
begin
EditArray[I] := TEdit.Create(StatsForm);
EditArray[I].Parent := StatsForm;
EditArray[I].Top := 25 + (I * 37);
EditArray[I].Left := 105;
EditArray[I].Width := 120;
EditArray[I].Height := 75;
EditArray[I].MaxLength := 32;
EditArray[I].Tag := I;
EditArray[I].Text := Captions[I];
EditArray[I].OnClick := @AClick;
end;
EditArray[1].OnChange := @PassCharEdit2;

StatsForm.ShowModal;
StatsForm.Free;
end;

procedure PromptSetupSRLStats;
var
V: TVariantArray;
begin
SetLength(V, 0);
ThreadSafeCall('CreateStatsForm', V);
if not(Done) then
begin
Writeln('SRL Stats: Window closed, setting up as Anonymous.');
Stats('Anonymous', 'anon1337');
end;
end;

begin
PromptSetupSRLStats;
end.

If you see me doing something which could be done simpler, please tell me :)

putonajonny
07-27-2012, 05:42 PM
I don't think you need PassCharEdit2 but looks good, you could just have one OnClick procedure btw

Kyle Undefined
07-27-2012, 06:02 PM
There's already a stats form included in SRL, it just needs to be edited to allow a user to type in their Stats credentials if they forgot to.

putonajonny
07-27-2012, 07:03 PM
There's already a stats form included in SRL, it just needs to be edited to allow a user to type in their Stats credentials if they forgot to.

I think he made this just to practice... (Snippets not suggestions)

Chris
07-27-2012, 08:39 PM
Yup, and this is how I would do something like this, wondering if there are things which could be done better. It could also be used to ask the RS username and password or something.
Hmm.. I'll have a look at using just one buttonclick procedure tomorrow, will probably need a global var or record for that though.
Why is PassCharEdit2 not needed, because there's no need to hide the password when someone types it in?
Thanks :)

putonajonny
07-27-2012, 10:42 PM
You already set the password char to '*' in ClearEdit2 :)

Chris
07-28-2012, 07:01 AM
You already set the password char to '*' in ClearEdit2 :)

Aha yes, That happens OnClick. PassCharEdit2 is called OnChange, because I usually fill in my username, then tab, and fill in my password, I never really click on the second Edit. When I tab to it, it selects the text and once I type in my pass, OnChange will be called. :)

litoris
07-28-2012, 09:46 AM
Awesome, I just wish stats was working properly.

Chris
07-28-2012, 07:22 PM
I don't think you need PassCharEdit2 but looks good, you could just have one OnClick procedure btw

I have been playing a bit with it and this is how I'm doing it now:

procedure AClick(Sender: TObject);
var
a, b: string;
begin
case ToStr(Sender) of
'TEdit':
case (Sender as TEdit).Tag of
0:
if EditArray[0].Text = 'SRL Stats Username' then
EditArray[0].CLEAR;
1:
begin
if EditArray[1].Text = 'SRL Stats Password' then
EditArray[1].CLEAR;
EditArray[1].PasswordChar := '*';
end;
end;
'TButton':
case (Sender as TButton).Tag of
0:
begin
a := EditArray[0].Text;
b := EditArray[1].Text;
StatsForm.Close();
Writeln('SRL Stats: Setting up.. Welcome ' + a + '.');
Stats(a, b);
end;
1:
begin
StatsForm.Close();
writeln('SRL Stats: Setting up as Anonymous.');
Stats('Anonymous', 'anon1337');
end;
end;
end;
end;

Updating OP :p

Daniel
07-28-2012, 11:06 PM
Aha yes, That happens OnClick. PassCharEdit2 is called OnChange, because I usually fill in my username, then tab, and fill in my password, I never really click on the second Edit. When I tab to it, it selects the text and once I type in my pass, OnChange will be called. :)

Change OnChange to OnExit (or OnEnter) ;)

Chris
07-29-2012, 01:33 PM
Change OnChange to OnExit (or OnEnter) ;)

Aah thanks!
I didn't know about OnEnter, but it's perfect! :)