Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
SimpleButtonComponent.c
Go to the documentation of this file.
1
// Simple button provides 4 states in which it can be:
2
// Default, focused, pressed and disabled.
3
// Hovering over the button will focus it instantly.
4
// Use it in places where you don't need onHover functionality.
5
6
// TODO:
7
// Need events OnDisable and onEnable to recolorize widgets
8
9
class
SimpleButtonComponent
:
ScriptedWidgetComponent
10
{
11
[
Attribute
(
"0 0 0 0.7"
,
UIWidgets
.ColorPicker,
""
)]
12
protected
ref
Color
m_ColorButtonDefault
;
13
14
[
Attribute
(
"1 1 1 0.25"
,
UIWidgets
.ColorPicker,
""
)]
15
protected
ref
Color
m_ColorButtonFocused
;
16
17
[
Attribute
(
"1 1 1 0.3"
,
UIWidgets
.ColorPicker,
""
)]
18
protected
ref
Color
m_ColorButtonPressed
;
19
20
[
Attribute
(
"0.8 0.8 0.8 0.1"
,
UIWidgets
.ColorPicker,
""
)]
21
protected
ref
Color
m_ColorButtonDisabled
;
22
23
[
Attribute
(
"false"
,
UIWidgets
.CheckBox,
""
)]
24
protected
bool
m_bColorizeChildren
;
25
26
[
Attribute
(
"1 1 1 1"
,
UIWidgets
.ColorPicker,
""
)]
27
protected
ref
Color
m_ColorChildDefault
;
28
29
[
Attribute
(
"0 0 0 1"
,
UIWidgets
.ColorPicker,
""
)]
30
protected
ref
Color
m_ColorChildFocused
;
31
32
[
Attribute
(
"0 0 0 1"
,
UIWidgets
.ColorPicker,
""
)]
33
protected
ref
Color
m_ColorChildPressed
;
34
35
[
Attribute
(
"1 1 1 0.6"
,
UIWidgets
.ColorPicker,
""
)]
36
protected
ref
Color
m_ColorChildDisabled
;
37
38
[
Attribute
(
"0.2"
,
UIWidgets
.EditBox,
""
)]
39
protected
float
m_fAnimationLength
;
40
41
[
Attribute
(
SCR_SoundEvent
.CLICK,
UIWidgets
.EditBox,
""
)]
42
protected
string
m_sSoundClicked
;
43
44
[
Attribute
(
SCR_SoundEvent
.FOCUS,
UIWidgets
.EditBox,
""
)]
45
protected
string
m_sSoundFocused
;
46
47
48
protected
Widget
m_wChild
;
49
protected
bool
m_bIsFocused
=
false
;
50
51
//------------------------------------------------------------------------------------------------
52
override
void
HandlerAttached
(
Widget
w)
53
{
54
m_wChild
= w.GetChildren();
55
m_fAnimationLength
= 1 /
m_fAnimationLength
;
56
57
if
(!w.IsEnabled())
58
{
59
w.SetColor(
m_ColorButtonDisabled
);
60
if
(
m_bColorizeChildren
&&
m_wChild
)
61
m_wChild
.SetColor(
m_ColorChildDisabled
);
62
}
63
else
64
{
65
w.SetColor(
m_ColorButtonDefault
);
66
if
(
m_bColorizeChildren
&&
m_wChild
)
67
m_wChild
.SetColor(
m_ColorChildDefault
);
68
}
69
}
70
71
//------------------------------------------------------------------------------------------------
72
override
bool
OnClick
(
Widget
w,
int
x,
int
y,
int
button)
73
{
74
SCR_UISoundEntity
.SoundEvent(
m_sSoundClicked
);
75
return
false
;
76
}
77
78
//------------------------------------------------------------------------------------------------
79
void
SetOnClickSound
(
string
newOnClickedSound)
80
{
81
m_sSoundClicked
= newOnClickedSound;
82
}
83
84
//------------------------------------------------------------------------------------------------
85
override
bool
OnMouseButtonDown
(
Widget
w,
int
x,
int
y,
int
button)
86
{
87
AnimateWidget
.
Color
(w,
m_ColorButtonPressed
,
m_fAnimationLength
);
88
if
(
m_bColorizeChildren
&&
m_wChild
)
89
AnimateWidget
.
Color
(
m_wChild
,
m_ColorChildPressed
,
m_fAnimationLength
);
90
91
return
false
;
92
}
93
94
//------------------------------------------------------------------------------------------------
95
override
bool
OnMouseButtonUp
(
Widget
w,
int
x,
int
y,
int
button)
96
{
97
if
(w.IsEnabled())
98
AnimateWidget
.
Color
(w,
m_ColorButtonFocused
,
m_fAnimationLength
);
99
else
100
AnimateWidget
.
Color
(w,
m_ColorButtonDisabled
,
m_fAnimationLength
);
101
102
if
(
m_bColorizeChildren
&&
m_wChild
)
103
{
104
if
(w.IsEnabled())
105
AnimateWidget
.
Color
(
m_wChild
,
m_ColorChildFocused
,
m_fAnimationLength
);
106
else
107
AnimateWidget
.
Color
(
m_wChild
,
m_ColorChildDisabled
,
m_fAnimationLength
);
108
}
109
110
return
false
;
111
}
112
113
//------------------------------------------------------------------------------------------------
114
override
bool
OnFocus
(
Widget
w,
int
x,
int
y)
115
{
116
m_bIsFocused
=
true
;
117
SCR_UISoundEntity
.SoundEvent(
m_sSoundFocused
);
118
119
if
(w.IsEnabled())
120
AnimateWidget
.
Color
(w,
m_ColorButtonFocused
,
m_fAnimationLength
);
121
else
122
AnimateWidget
.
Color
(w,
m_ColorButtonDisabled
,
m_fAnimationLength
);
123
124
if
(
m_bColorizeChildren
&&
m_wChild
)
125
{
126
if
(w.IsEnabled())
127
AnimateWidget
.
Color
(
m_wChild
,
m_ColorChildFocused
,
m_fAnimationLength
);
128
else
129
AnimateWidget
.
Color
(
m_wChild
,
m_ColorChildDisabled
,
m_fAnimationLength
);
130
}
131
132
return
false
;
133
}
134
135
//------------------------------------------------------------------------------------------------
136
override
bool
OnFocusLost
(
Widget
w,
int
x,
int
y)
137
{
138
m_bIsFocused
=
false
;
139
140
if
(w.IsEnabled())
141
AnimateWidget
.
Color
(w,
m_ColorButtonDefault
,
m_fAnimationLength
);
142
else
143
AnimateWidget
.
Color
(w,
m_ColorButtonDisabled
,
m_fAnimationLength
);
144
145
if
(
m_bColorizeChildren
&&
m_wChild
)
146
{
147
if
(w.IsEnabled())
148
AnimateWidget
.
Color
(
m_wChild
,
m_ColorChildDefault
,
m_fAnimationLength
);
149
else
150
AnimateWidget
.
Color
(
m_wChild
,
m_ColorChildDisabled
,
m_fAnimationLength
);
151
}
152
153
return
false
;
154
}
155
156
//------------------------------------------------------------------------------------------------
157
override
bool
OnMouseEnter
(
Widget
w,
int
x,
int
y)
158
{
159
if
(w.GetFlags() &
WidgetFlags
.NOFOCUS)
160
OnFocus
(w, x, y);
161
else
162
GetGame
().GetWorkspace().SetFocusedWidget(w);
163
164
return
false
;
165
}
166
167
//------------------------------------------------------------------------------------------------
168
override
bool
OnMouseLeave
(
Widget
w,
Widget
enterW,
int
x,
int
y)
169
{
170
if
(w.GetFlags() &
WidgetFlags
.NOFOCUS)
171
OnFocusLost
(w, x, y);
172
else
173
GetGame
().GetWorkspace().SetFocusedWidget(enterW);
174
175
return
false
;
176
}
177
};
GetGame
ArmaReforgerScripted GetGame()
Definition
game.c:1398
AnimateWidget
Definition
AnimateWidget.c:3
AnimateWidget::Color
static WidgetAnimationColor Color(Widget widget, Color color, float speed)
Definition
AnimateWidget.c:200
Color
Definition
Color.c:13
SCR_SoundEvent
Definition
SCR_SoundEvent.c:2
SCR_UISoundEntity
Definition
SCR_UISoundEntity.c:8
ScriptedWidgetComponent
Definition
ScriptedWidgetComponent.c:13
SimpleButtonComponent
Definition
SimpleButtonComponent.c:10
SimpleButtonComponent::m_bColorizeChildren
bool m_bColorizeChildren
Definition
SimpleButtonComponent.c:24
SimpleButtonComponent::m_ColorChildFocused
ref Color m_ColorChildFocused
Definition
SimpleButtonComponent.c:30
SimpleButtonComponent::m_sSoundFocused
string m_sSoundFocused
Definition
SimpleButtonComponent.c:45
SimpleButtonComponent::OnMouseLeave
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
Definition
SimpleButtonComponent.c:168
SimpleButtonComponent::m_wChild
Widget m_wChild
Definition
SimpleButtonComponent.c:48
SimpleButtonComponent::m_ColorButtonDisabled
ref Color m_ColorButtonDisabled
Definition
SimpleButtonComponent.c:21
SimpleButtonComponent::OnFocus
override bool OnFocus(Widget w, int x, int y)
Definition
SimpleButtonComponent.c:114
SimpleButtonComponent::SetOnClickSound
void SetOnClickSound(string newOnClickedSound)
Definition
SimpleButtonComponent.c:79
SimpleButtonComponent::HandlerAttached
override void HandlerAttached(Widget w)
Definition
SimpleButtonComponent.c:52
SimpleButtonComponent::m_bIsFocused
bool m_bIsFocused
Definition
SimpleButtonComponent.c:49
SimpleButtonComponent::m_fAnimationLength
float m_fAnimationLength
Definition
SimpleButtonComponent.c:39
SimpleButtonComponent::m_ColorButtonPressed
ref Color m_ColorButtonPressed
Definition
SimpleButtonComponent.c:18
SimpleButtonComponent::m_sSoundClicked
string m_sSoundClicked
Definition
SimpleButtonComponent.c:42
SimpleButtonComponent::m_ColorChildPressed
ref Color m_ColorChildPressed
Definition
SimpleButtonComponent.c:33
SimpleButtonComponent::m_ColorButtonDefault
ref Color m_ColorButtonDefault
Definition
SimpleButtonComponent.c:12
SimpleButtonComponent::OnClick
override bool OnClick(Widget w, int x, int y, int button)
Definition
SimpleButtonComponent.c:72
SimpleButtonComponent::OnMouseButtonUp
override bool OnMouseButtonUp(Widget w, int x, int y, int button)
Definition
SimpleButtonComponent.c:95
SimpleButtonComponent::m_ColorChildDisabled
ref Color m_ColorChildDisabled
Definition
SimpleButtonComponent.c:36
SimpleButtonComponent::OnFocusLost
override bool OnFocusLost(Widget w, int x, int y)
Definition
SimpleButtonComponent.c:136
SimpleButtonComponent::m_ColorChildDefault
ref Color m_ColorChildDefault
Definition
SimpleButtonComponent.c:27
SimpleButtonComponent::OnMouseButtonDown
override bool OnMouseButtonDown(Widget w, int x, int y, int button)
Definition
SimpleButtonComponent.c:85
SimpleButtonComponent::m_ColorButtonFocused
ref Color m_ColorButtonFocused
Definition
SimpleButtonComponent.c:15
SimpleButtonComponent::OnMouseEnter
override bool OnMouseEnter(Widget w, int x, int y)
Definition
SimpleButtonComponent.c:157
UIWidgets
Definition
attributes.c:40
Widget
Definition
Widget.c:13
Attribute
SCR_FieldOfViewSettings Attribute
Definition
SendGoalMessage.c:170
WidgetFlags
WidgetFlags
Widget flags. See enf::Widget::SetFlags().
Definition
WidgetFlags.c:14
scripts
Game
UI
Deprecated
SimpleButtonComponent.c
Generated by
1.17.0