@quenty/buttonhighlightmodel 3.6.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/package.json +6 -6
- package/src/Client/ButtonHighlightModel.lua +98 -42
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [4.0.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/buttonhighlightmodel@3.6.0...@quenty/buttonhighlightmodel@4.0.0) (2022-03-06)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* ButtonHighlightModel can assign the button at any point which allows for use in Blend ([7010810](https://github.com/Quenty/NevermoreEngine/commit/701081083ddb40e9cb82df984594187386ab85df))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [3.6.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/buttonhighlightmodel@3.5.1...@quenty/buttonhighlightmodel@3.6.0) (2022-01-17)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @quenty/buttonhighlightmodel
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/buttonhighlightmodel",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Contains model information for the current button",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -27,15 +27,15 @@
|
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@quenty/acceltween": "^2.1.0",
|
|
30
|
-
"@quenty/baseobject": "^
|
|
31
|
-
"@quenty/blend": "^
|
|
32
|
-
"@quenty/loader": "^
|
|
30
|
+
"@quenty/baseobject": "^4.0.0",
|
|
31
|
+
"@quenty/blend": "^3.0.0",
|
|
32
|
+
"@quenty/loader": "^4.0.0",
|
|
33
33
|
"@quenty/maid": "^2.1.0",
|
|
34
|
-
"@quenty/rx": "^
|
|
34
|
+
"@quenty/rx": "^4.0.0",
|
|
35
35
|
"@quenty/steputils": "^3.0.1"
|
|
36
36
|
},
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "dd428cab58282c975a4c082957dc8f58e3186905"
|
|
41
41
|
}
|
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
--[=[
|
|
2
|
-
Contains model information for the current button
|
|
2
|
+
Contains model information for the current button.
|
|
3
|
+
|
|
4
|
+
Usage with Blend!
|
|
5
|
+
|
|
6
|
+
```lua
|
|
7
|
+
function Button.new()
|
|
8
|
+
local self = setmetatable(BaseObject.new(), Button)
|
|
9
|
+
|
|
10
|
+
-- Store the button model in the actual button so we can ensure it cleans up
|
|
11
|
+
-- this assumes only one render. We can also construct it in the Button.Render
|
|
12
|
+
|
|
13
|
+
self._buttonModel = ButtonHighlightModel.new()
|
|
14
|
+
self._maid:GiveTask(self._buttonModel)
|
|
15
|
+
|
|
16
|
+
return self
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
function Button:Render()
|
|
20
|
+
...
|
|
21
|
+
return Blend.New "ImageButton" {
|
|
22
|
+
...
|
|
23
|
+
[Blend.Instance] = function(button)
|
|
24
|
+
self._buttonModel:SetButton(button)
|
|
25
|
+
end;
|
|
26
|
+
BackgroundTransparency = Blend.Computed(self._buttonModel:ObservePercentPressed(), function(pressed)
|
|
27
|
+
return 1 - pressed
|
|
28
|
+
end);
|
|
29
|
+
}
|
|
30
|
+
end
|
|
31
|
+
```
|
|
32
|
+
|
|
3
33
|
@class ButtonHighlightModel
|
|
4
34
|
]=]
|
|
5
35
|
|
|
@@ -18,12 +48,12 @@ ButtonHighlightModel.__index = ButtonHighlightModel
|
|
|
18
48
|
|
|
19
49
|
--[=[
|
|
20
50
|
A model that dictates the current state of a button.
|
|
21
|
-
@param button GuiBase
|
|
51
|
+
@param button? GuiBase
|
|
22
52
|
@param onUpdate function?
|
|
23
53
|
@return ButtonHighlightModel
|
|
24
54
|
]=]
|
|
25
55
|
function ButtonHighlightModel.new(button, onUpdate)
|
|
26
|
-
local self = setmetatable(BaseObject.new(
|
|
56
|
+
local self = setmetatable(BaseObject.new(), ButtonHighlightModel)
|
|
27
57
|
|
|
28
58
|
self._onUpdate = onUpdate
|
|
29
59
|
|
|
@@ -97,42 +127,6 @@ function ButtonHighlightModel.new(button, onUpdate)
|
|
|
97
127
|
self.IsPressed.Value = false
|
|
98
128
|
self._maid:GiveTask(self.IsPressed)
|
|
99
129
|
|
|
100
|
-
self._maid:GiveTask(self._obj.InputEnded:Connect(function(inputObject)
|
|
101
|
-
if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
|
|
102
|
-
self._isMouseOver.Value = false
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
|
|
106
|
-
self._isMouseDown.Value = false
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
if inputObject.UserInputType == Enum.UserInputType.Touch then
|
|
110
|
-
self:_stopTouchTrack(inputObject)
|
|
111
|
-
end
|
|
112
|
-
end))
|
|
113
|
-
|
|
114
|
-
self._maid:GiveTask(self._obj.SelectionGained:Connect(function()
|
|
115
|
-
self.IsSelected.Value = true
|
|
116
|
-
end))
|
|
117
|
-
|
|
118
|
-
self._maid:GiveTask(self._obj.SelectionLost:Connect(function()
|
|
119
|
-
self.IsSelected.Value = false
|
|
120
|
-
end))
|
|
121
|
-
|
|
122
|
-
self._maid:GiveTask(self._obj.InputBegan:Connect(function(inputObject)
|
|
123
|
-
if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
|
|
124
|
-
self._isMouseOver.Value = true
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
|
|
128
|
-
self._isMouseDown.Value = true
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
if inputObject.UserInputType == Enum.UserInputType.Touch then
|
|
132
|
-
self:_trackTouch(inputObject)
|
|
133
|
-
end
|
|
134
|
-
end))
|
|
135
|
-
|
|
136
130
|
-- Legacy update stepping mode
|
|
137
131
|
if self._onUpdate then
|
|
138
132
|
self._percentHighlightedAccelTween = AccelTween.new(200)
|
|
@@ -190,9 +184,63 @@ function ButtonHighlightModel.new(button, onUpdate)
|
|
|
190
184
|
end))
|
|
191
185
|
self:_updateTargets()
|
|
192
186
|
|
|
187
|
+
if button then
|
|
188
|
+
self:SetButton(button)
|
|
189
|
+
end
|
|
190
|
+
|
|
193
191
|
return self
|
|
194
192
|
end
|
|
195
193
|
|
|
194
|
+
--[=[
|
|
195
|
+
Sets the button for the highlight model.
|
|
196
|
+
@param button
|
|
197
|
+
]=]
|
|
198
|
+
function ButtonHighlightModel:SetButton(button: Instance)
|
|
199
|
+
assert(typeof(button) == "Instance" or button == nil, "Bad button")
|
|
200
|
+
|
|
201
|
+
local maid = Maid.new()
|
|
202
|
+
|
|
203
|
+
if button then
|
|
204
|
+
maid:GiveTask(button.InputEnded:Connect(function(inputObject)
|
|
205
|
+
if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
|
|
206
|
+
self._isMouseOver.Value = false
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
|
|
210
|
+
self._isMouseDown.Value = false
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
if inputObject.UserInputType == Enum.UserInputType.Touch then
|
|
214
|
+
self:_stopTouchTrack(inputObject)
|
|
215
|
+
end
|
|
216
|
+
end))
|
|
217
|
+
|
|
218
|
+
maid:GiveTask(button.SelectionGained:Connect(function()
|
|
219
|
+
self.IsSelected.Value = true
|
|
220
|
+
end))
|
|
221
|
+
|
|
222
|
+
maid:GiveTask(button.SelectionLost:Connect(function()
|
|
223
|
+
self.IsSelected.Value = false
|
|
224
|
+
end))
|
|
225
|
+
|
|
226
|
+
maid:GiveTask(button.InputBegan:Connect(function(inputObject)
|
|
227
|
+
if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
|
|
228
|
+
self._isMouseOver.Value = true
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
|
|
232
|
+
self._isMouseDown.Value = true
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
if inputObject.UserInputType == Enum.UserInputType.Touch then
|
|
236
|
+
self:_trackTouch(inputObject)
|
|
237
|
+
end
|
|
238
|
+
end))
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
self._maid._buttonMaid = maid
|
|
242
|
+
end
|
|
243
|
+
|
|
196
244
|
--[=[
|
|
197
245
|
Observes how pressed down the button is
|
|
198
246
|
@return Observable<number>
|
|
@@ -210,13 +258,21 @@ end
|
|
|
210
258
|
Observes how highlighted the button is
|
|
211
259
|
@return Observable<number>
|
|
212
260
|
]=]
|
|
213
|
-
function ButtonHighlightModel:
|
|
214
|
-
return Blend.AccelTween(
|
|
261
|
+
function ButtonHighlightModel:ObservePercentHighlighted()
|
|
262
|
+
return Blend.AccelTween(self:ObservePercentHighlightedTarget(), 200)
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
--[=[
|
|
266
|
+
Observes target for how highlighted the button is
|
|
267
|
+
@return Observable<number>
|
|
268
|
+
]=]
|
|
269
|
+
function ButtonHighlightModel:ObservePercentHighlightedTarget()
|
|
270
|
+
return Blend.toPropertyObservable(self.IsHighlighted)
|
|
215
271
|
:Pipe({
|
|
216
272
|
Rx.map(function(value)
|
|
217
273
|
return value and 1 or 0
|
|
218
274
|
end);
|
|
219
|
-
})
|
|
275
|
+
})
|
|
220
276
|
end
|
|
221
277
|
|
|
222
278
|
--[=[
|