@@ -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,163 @@ 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+ panel: TLazPanel;
59+ info: TLazLabel;
60+ btn: TLazButton;
61+ begin
62+ Self.LoginPanel := TLazPanel.CreateEx(parent, TLazTabSheet(parent).Width div 2 - 240, 20, 480, 220);
63+ Self.LoginPanel.BevelWidth := 0;
64+
65+ info := TLazLabel.CreateEx(Self.LoginPanel, '', '', 60, 20, 0, 90);
66+ info.Caption := 'You are currently not logged into WaspScripts.' + LINE_SEP + LINE_SEP +
67+ 'To submit stats you can either login below' + LINE_SEP +
68+ 'or relaunch the script from wasp-launcher.';
69+ info.Alignment := ELazAlignment.Center;
70+ info.Font.Name := 'Courier New';
71+
72+ Self.EmailEdit := TLazEdit.CreateEx(Self.LoginPanel, 'Email:', 'Username to login to WaspScripts', 20, info.Bottom + 20, 200);
73+ Self.PasswordEdit := TLazEdit.CreateEx(Self.LoginPanel, 'Password:', 'Password to login to WaspScripts', Self.EmailEdit.Right + 20, Self.EmailEdit.Top, 200);
74+ Self.PasswordEdit.PasswordChar := '*';
75+
76+ btn := TLazButton.CreateEx(Self.LoginPanel, 'Login', '', Self.LoginPanel.Width div 2 - 100, Self.EmailEdit.Bottom + 20, 200);
77+ btn.OnClick := @Self.OnLogin;
78+
79+ if WaspClient.LoggedIn then
80+ Self.LoginPanel.Hide();
81+ end;
82+
83+ procedure TMiscFormHelper.SetupClientPanel(parent: TLazComponent);
84+ var
85+ panel: TLazPanel;
86+ info: TLazLabel;
87+ btn: TLazButton;
88+ begin
89+ Self.ClientPanel := TLazPanel.CreateEx(parent, TLazTabSheet(parent).Width div 2 - 240, 20, 480, 220);
90+ Self.ClientPanel.BevelWidth := 0;
91+
92+ info := TLazLabel.CreateEx(Self.ClientPanel, 'You are logged in as ' + WaspClient.User.Username, '', 60, 20, 0, 90);
93+ info.Alignment := ELazAlignment.Center;
94+ info.Font.Name := 'Courier New';
95+
96+ btn := TLazButton.CreateEx(Self.LoginPanel, 'Login', '', Self.LoginPanel.Width div 2 - 100, Self.EmailEdit.Bottom + 20, 200);
97+ btn.OnClick := @Self.OnLogout;
98+
99+ if WaspClient.LoggedIn then
100+ Self.LoginPanel.Hide();
101+ end;
102+
103+
104+
105+ procedure TMiscFormHelper.OnRecorderEnabledChange(sender: TLazObject);
106+ begin
107+ if TLazCheckBox(sender).IsChecked() then
108+ begin
109+ SimbaRecorder.Enabled := True;
110+ Self.RecorderLengthLbl1.Enabled := True;
111+ Self.RecorderLength.Enabled := True;
112+ Self.RecorderLengthLbl2.Enabled := True;
113+ SimbaRecorder.BufferSeconds := Self.RecorderLength.Value;
114+ end
115+ else
116+ begin
117+ SimbaRecorder.Enabled := False;
118+ Self.RecorderLengthLbl1.Enabled := False;
119+ Self.RecorderLength.Enabled := False;
120+ Self.RecorderLengthLbl2.Enabled := False;
121+ end;
122+
123+ if Self.Config.Data.Has('recorder_enabled') then
124+ Self.Config.Data.Item['recorder_enabled'].AsBool := SimbaRecorder.Enabled
125+ else
126+ Self.Config.Data.AddBool('recorder_enabled', SimbaRecorder.Enabled);
127+ Self.Config.Save();
128+ end;
129+
130+ procedure TMiscFormHelper.OnRecorderLengthChange(sender: TLazObject);
131+ begin
132+ SimbaRecorder.BufferSeconds := TLazSpinEdit(sender).Value;
133+ if Self.Config.Data.Has('recorder_length') then
134+ Self.Config.Data.Item['recorder_length'].AsInt := SimbaRecorder.BufferSeconds
135+ else
136+ Self.Config.Data.AddInt('recorder_length', SimbaRecorder.BufferSeconds);
137+ Self.Config.Save();
138+ end;
139+
140+
141+ procedure TMiscFormHelper.SetupRecorderPanel(parent: TLazComponent);
142+ var
143+ panel: TLazPanel;
144+ check: TLazCheckBox;
145+ begin
146+ panel := TLazPanel.CreateEx(parent, TLazTabSheet(parent).Width div 2 - 120, 320, 240, 100);
147+ panel.BevelWidth := 0;
148+
149+ check := TLazCheckBox.CreateEx(panel, 'Record crashes', '', 20, 0);
150+ check.Hint := 'Simba recorder records the last X seconds of a script running.' + LINE_SEP +
151+ 'This is great to analyze crashes and issues that shut down scripts' + LINE_SEP +
152+ 'but uses a lot of RAM and will use more the longer the recording is.';
153+ check.ShowHint := True;
154+ check.OnChange := @Self.OnRecorderEnabledChange;
155+
156+ Self.RecorderLengthLbl1 := TLazLabel.CreateEx(panel, 'Record last', '', 20, 40);
157+ Self.RecorderLength := TLazSpinEdit.CreateEx(panel);
158+ Self.RecorderLength.AnchorHorizontally(Self.RecorderLengthLbl1, 10);
159+ Self.RecorderLength.Hint := check.Hint;
160+ Self.RecorderLength.ShowHint := True;
161+ Self.RecorderLength.Increment := 5;
162+ if Self.Config.Data.Has('recorder_length') then
163+ begin
164+ SimbaRecorder.BufferSeconds := Self.Config.Data.Item['recorder_length'].AsInt;
165+ Self.RecorderLength.Value := Self.Config.Data.Item['recorder_length'].AsInt;
166+ end
167+ else
168+ begin
169+ SimbaRecorder.BufferSeconds := 30;
170+ Self.RecorderLength.Value := 30;
171+ end;
172+ Self.RecorderLength.MinValue := 10;
173+ Self.RecorderLength.OnChange := @Self.OnRecorderLengthChange;
174+
175+ Self.RecorderLengthLbl2 := TLazLabel.CreateEx(panel, 'seconds');
176+ Self.RecorderLengthLbl2.AnchorHorizontally(Self.RecorderLength, 10);
177+
178+ if Self.Config.Data.Has('recorder_enabled') then
179+ begin
180+ check.SetChecked(Self.Config.Data.Item['recorder_enabled'].AsBool);
181+ Self.RecorderLengthLbl1.Enabled := Self.Config.Data.Item['recorder_enabled'].AsBool;
182+ Self.RecorderLength.Enabled := Self.Config.Data.Item['recorder_enabled'].AsBool;
183+ Self.RecorderLengthLbl2.Enabled := Self.Config.Data.Item['recorder_enabled'].AsBool;
184+ end
185+ else
186+ begin
187+ check.SetChecked(False);
188+ Self.RecorderLengthLbl1.Enabled := False;
189+ Self.RecorderLength.Enabled := False;
190+ Self.RecorderLengthLbl2.Enabled := False;
191+ end;
192+ end;
193+
194+
34195var
35196(*
36197## MiscForm variable
65226 Result := Self.CreateTab('Misc');
66227
67228 MiscForm.Setup();
229+ MiscForm.SetupLoginPanel(Result);
230+ MiscForm.SetupRecorderPanel(Result);
231+ MiscForm.Setup();
68232end;
0 commit comments