forked from lexbailey/YHSConsoleSim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spacehackcontrolsilluminatedtoggle.pas
97 lines (86 loc) · 1.99 KB
/
spacehackcontrolsilluminatedtoggle.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
unit spacehackcontrolsilluminatedtoggle;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils,
StdCtrls, controls, Graphics,
ExtCtrls, ComCtrls, Buttons, MQTTComponent, spacehackcontrols;
type
TSpacehackGameControlIlluminatedToggle = class(TSpacehackGameControl)
lightIsOn: boolean;
lblLight: TLabel;
btnOn, btnOff: TButton;
panelWidth: integer;
procedure initUI(thisPanel:TPanel) override;
procedure updateUI override;
procedure handleOnClick(Sender: TObject);
procedure handleOffClick(Sender: TObject);
end;
implementation
procedure TSpacehackGameControlIlluminatedToggle.initUI(thisPanel: TPanel);
begin;
inherited;
lblLight := TLabel.Create(thisPanel);
panelWidth := thisPanel.Width;
with lblLight do begin
top := 40;
left := 0;
AutoSize:=true;
Font.Size:=20;
Parent:= thisPanel;
Visible:=true;
end;
btnOn := TButton.Create(thisPanel);
with btnOn do begin
width := 100;
height := 50;
top := 90;
left := 50;
parent := thisPanel;
Visible:=true;
Caption:='On';
tag := 1;
OnClick:=@handleOnClick;
end;
btnOff := TButton.Create(thisPanel);
with btnOff do begin
width := 100;
height := 50;
top := 140;
left := 50;
parent := thisPanel;
Visible:=true;
Caption:='Off';
tag := 0;
OnClick:=@handleOffClick;
end;
updateUI;
end;
procedure TSpacehackGameControlIlluminatedToggle.handleOnClick(Sender: TObject);
begin;
lightIsOn:=true;
end;
procedure TSpacehackGameControlIlluminatedToggle.handleOffClick(Sender: TObject);
begin;
lightIsOn:=false;
end;
procedure TSpacehackGameControlIlluminatedToggle.updateUI;
begin
with lblLight do begin
if lightIsOn then
begin
Caption:= 'ON';
Color:=clGreen;
btnOff.Enabled:=true;
btnOn.Enabled:=false;
end else
begin
Caption:= 'OFF';
Color:=clRed;
btnoff.Enabled:=false;
btnOn.Enabled:=true;
end;
left := round((panelWidth/2) - (width/2));
end;
end;
end.