@@ -23,6 +23,10 @@ mentioned on this page because they are internal methods you shouldn't touch.
2323Do feel free to read the source code though if you so desire.
2424*)
2525 TMiscFormHelper = record
26+ LoginPanel, ClientPanel: TLazPanel;
27+ EmailEdit, PasswordEdit: TLazEdit;
28+ RecorderLength: TLazSpinEdit;
29+ RecorderLengthLbl1, RecorderLengthLbl2: TLazLabel;
2630 Config: TConfigJSON;
2731 end;
2832
@@ -31,6 +35,161 @@ begin
3135 Self.Config.Setup('misc' + PATH_SEP + ToStr(ProfileIndex));
3236end;
3337
38+
39+ procedure TMiscFormHelper.OnLogin(sender: TLazObject);
40+ begin
41+ WaspClient.Login(Self.EmailEdit.Text, Self.PasswordEdit.Text);
42+
43+ if WaspClient.LoggedIn then
44+ TLazButton(sender).Parent.Hide();
45+ end;
46+
47+ procedure TMiscFormHelper.OnLogout(sender: TLazObject);
48+ begin
49+ WaspClient.Login(Self.EmailEdit.Text, Self.PasswordEdit.Text);
50+
51+ if WaspClient.LoggedIn then
52+ TLazButton(sender).Parent.Hide();
53+ end;
54+
55+
56+ procedure TMiscFormHelper.SetupLoginPanel(parent: TLazComponent);
57+ var
58+ info: TLazLabel;
59+ btn: TLazButton;
60+ begin
61+ Self.LoginPanel := TLazPanel.CreateEx(parent, TLazTabSheet(parent).Width div 2 - 240, 20, 480, 220);
62+ Self.LoginPanel.BevelWidth := 0;
63+
64+ info := TLazLabel.CreateEx(Self.LoginPanel, '', '', 60, 20, 0, 90);
65+ info.Caption := 'You are currently not logged into WaspScripts.' + LINE_SEP + LINE_SEP +
66+ 'To submit stats you can either login below' + LINE_SEP +
67+ 'or relaunch the script from wasp-launcher.';
68+ info.Alignment := ELazAlignment.Center;
69+ info.Font.Name := 'Courier New';
70+
71+ Self.EmailEdit := TLazEdit.CreateEx(Self.LoginPanel, 'Email:', 'Username to login to WaspScripts', 20, info.Bottom + 20, 200);
72+ Self.PasswordEdit := TLazEdit.CreateEx(Self.LoginPanel, 'Password:', 'Password to login to WaspScripts', Self.EmailEdit.Right + 20, Self.EmailEdit.Top, 200);
73+ Self.PasswordEdit.PasswordChar := '*';
74+
75+ btn := TLazButton.CreateEx(Self.LoginPanel, 'Login', '', Self.LoginPanel.Width div 2 - 100, Self.EmailEdit.Bottom + 20, 200);
76+ btn.OnClick := @Self.OnLogin;
77+
78+ if WaspClient.LoggedIn then
79+ Self.LoginPanel.Hide();
80+ end;
81+
82+ procedure TMiscFormHelper.SetupClientPanel(parent: TLazComponent);
83+ var
84+ info: TLazLabel;
85+ btn: TLazButton;
86+ begin
87+ Self.ClientPanel := TLazPanel.CreateEx(parent, TLazTabSheet(parent).Width div 2 - 240, 20, 480, 220);
88+ Self.ClientPanel.BevelWidth := 0;
89+
90+ info := TLazLabel.CreateEx(Self.ClientPanel, 'You are logged in as ' + WaspClient.User.Username, '', 60, 20, 0, 90);
91+ info.Alignment := ELazAlignment.Center;
92+ info.Font.Name := 'Courier New';
93+
94+ btn := TLazButton.CreateEx(Self.LoginPanel, 'Login', '', Self.LoginPanel.Width div 2 - 100, Self.EmailEdit.Bottom + 20, 200);
95+ btn.OnClick := @Self.OnLogout;
96+
97+ if WaspClient.LoggedIn then
98+ Self.LoginPanel.Hide();
99+ end;
100+
101+
102+
103+ procedure TMiscFormHelper.OnRecorderEnabledChange(sender: TLazObject);
104+ begin
105+ if TLazCheckBox(sender).IsChecked() then
106+ begin
107+ SimbaRecorder.Enabled := True;
108+ Self.RecorderLengthLbl1.Enabled := True;
109+ Self.RecorderLength.Enabled := True;
110+ Self.RecorderLengthLbl2.Enabled := True;
111+ SimbaRecorder.BufferSeconds := Self.RecorderLength.Value;
112+ end
113+ else
114+ begin
115+ SimbaRecorder.Enabled := False;
116+ Self.RecorderLengthLbl1.Enabled := False;
117+ Self.RecorderLength.Enabled := False;
118+ Self.RecorderLengthLbl2.Enabled := False;
119+ end;
120+
121+ if Self.Config.Data.Has('recorder_enabled') then
122+ Self.Config.Data.Item['recorder_enabled'].AsBool := SimbaRecorder.Enabled
123+ else
124+ Self.Config.Data.AddBool('recorder_enabled', SimbaRecorder.Enabled);
125+ Self.Config.Save();
126+ end;
127+
128+ procedure TMiscFormHelper.OnRecorderLengthChange(sender: TLazObject);
129+ begin
130+ SimbaRecorder.BufferSeconds := TLazSpinEdit(sender).Value;
131+ if Self.Config.Data.Has('recorder_length') then
132+ Self.Config.Data.Item['recorder_length'].AsInt := SimbaRecorder.BufferSeconds
133+ else
134+ Self.Config.Data.AddInt('recorder_length', SimbaRecorder.BufferSeconds);
135+ Self.Config.Save();
136+ end;
137+
138+
139+ procedure TMiscFormHelper.SetupRecorderPanel(parent: TLazComponent);
140+ var
141+ panel: TLazPanel;
142+ check: TLazCheckBox;
143+ begin
144+ panel := TLazPanel.CreateEx(parent, TLazTabSheet(parent).Width div 2 - 120, 320, 240, 100);
145+ panel.BevelWidth := 0;
146+
147+ check := TLazCheckBox.CreateEx(panel, 'Record crashes', '', 20, 0);
148+ check.Hint := 'Simba recorder records the last X seconds of a script running.' + LINE_SEP +
149+ 'This is great to analyze crashes and issues that shut down scripts' + LINE_SEP +
150+ 'but uses a lot of RAM and will use more the longer the recording is.';
151+ check.ShowHint := True;
152+ check.OnChange := @Self.OnRecorderEnabledChange;
153+
154+ Self.RecorderLengthLbl1 := TLazLabel.CreateEx(panel, 'Record last', '', 20, 40);
155+ Self.RecorderLength := TLazSpinEdit.CreateEx(panel);
156+ Self.RecorderLength.AnchorHorizontally(Self.RecorderLengthLbl1, 10);
157+ Self.RecorderLength.Hint := check.Hint;
158+ Self.RecorderLength.ShowHint := True;
159+ Self.RecorderLength.Increment := 5;
160+ if Self.Config.Data.Has('recorder_length') then
161+ begin
162+ SimbaRecorder.BufferSeconds := Self.Config.Data.Item['recorder_length'].AsInt;
163+ Self.RecorderLength.Value := Self.Config.Data.Item['recorder_length'].AsInt;
164+ end
165+ else
166+ begin
167+ SimbaRecorder.BufferSeconds := 30;
168+ Self.RecorderLength.Value := 30;
169+ end;
170+ Self.RecorderLength.MinValue := 10;
171+ Self.RecorderLength.OnChange := @Self.OnRecorderLengthChange;
172+
173+ Self.RecorderLengthLbl2 := TLazLabel.CreateEx(panel, 'seconds');
174+ Self.RecorderLengthLbl2.AnchorHorizontally(Self.RecorderLength, 10);
175+
176+ if Self.Config.Data.Has('recorder_enabled') then
177+ begin
178+ check.SetChecked(Self.Config.Data.Item['recorder_enabled'].AsBool);
179+ Self.RecorderLengthLbl1.Enabled := Self.Config.Data.Item['recorder_enabled'].AsBool;
180+ Self.RecorderLength.Enabled := Self.Config.Data.Item['recorder_enabled'].AsBool;
181+ Self.RecorderLengthLbl2.Enabled := Self.Config.Data.Item['recorder_enabled'].AsBool;
182+ end
183+ else
184+ begin
185+ check.SetChecked(False);
186+ Self.RecorderLengthLbl1.Enabled := False;
187+ Self.RecorderLength.Enabled := False;
188+ Self.RecorderLengthLbl2.Enabled := False;
189+ end;
190+ end;
191+
192+
34193var
35194(*
36195## MiscForm variable
65224 Result := Self.CreateTab('Misc');
66225
67226 MiscForm.Setup();
227+ MiscForm.SetupLoginPanel(Result);
228+ MiscForm.SetupRecorderPanel(Result);
229+ MiscForm.Setup();
68230end;
0 commit comments