@quenty/buttonhighlightmodel 7.5.0 → 7.6.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 +2 -2
- package/src/Client/HandleHighlightModel.lua +116 -0
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
|
+
# [7.6.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/buttonhighlightmodel@7.5.0...@quenty/buttonhighlightmodel@7.6.0) (2022-12-06)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Add HandleHighlightModel ([94ca0bd](https://github.com/Quenty/NevermoreEngine/commit/94ca0bdf3e6fedbfc25b1a557b895d05823b95b7))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [7.5.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/buttonhighlightmodel@7.4.0...@quenty/buttonhighlightmodel@7.5.0) (2022-12-05)
|
|
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": "7.
|
|
3
|
+
"version": "7.6.0",
|
|
4
4
|
"description": "Contains model information for the current button",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "d9b0d10faa443cc42a6c2ac966f2f56d124bbde5"
|
|
41
41
|
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
--[=[
|
|
2
|
+
@class HandleHighlightModel
|
|
3
|
+
]=]
|
|
4
|
+
|
|
5
|
+
local require = require(script.Parent.loader).load(script)
|
|
6
|
+
|
|
7
|
+
local UserInputService = game:GetService("UserInputService")
|
|
8
|
+
|
|
9
|
+
local BaseObject = require("BaseObject")
|
|
10
|
+
local Maid = require("Maid")
|
|
11
|
+
local Blend = require("Blend")
|
|
12
|
+
local Rx = require("Rx")
|
|
13
|
+
|
|
14
|
+
local HandleHighlightModel = setmetatable({}, BaseObject)
|
|
15
|
+
HandleHighlightModel.ClassName = "HandleHighlightModel"
|
|
16
|
+
HandleHighlightModel.__index = HandleHighlightModel
|
|
17
|
+
|
|
18
|
+
function HandleHighlightModel.new()
|
|
19
|
+
local self = setmetatable(BaseObject.new(), HandleHighlightModel)
|
|
20
|
+
|
|
21
|
+
self.IsMouseOver = Instance.new("BoolValue")
|
|
22
|
+
self.IsMouseOver.Value = false
|
|
23
|
+
self._maid:GiveTask(self.IsMouseOver)
|
|
24
|
+
|
|
25
|
+
self.IsMouseDown = Instance.new("BoolValue")
|
|
26
|
+
self.IsMouseDown.Value = false
|
|
27
|
+
self._maid:GiveTask(self.IsMouseDown)
|
|
28
|
+
|
|
29
|
+
self.IsHighlighted = Instance.new("BoolValue")
|
|
30
|
+
self.IsHighlighted.Value = false
|
|
31
|
+
self._maid:GiveTask(self.IsHighlighted)
|
|
32
|
+
|
|
33
|
+
self._maid:GiveTask(self.IsMouseDown.Changed:Connect(function()
|
|
34
|
+
self:_updateHighlighted()
|
|
35
|
+
end))
|
|
36
|
+
self._maid:GiveTask(self.IsMouseOver.Changed:Connect(function()
|
|
37
|
+
self:_updateHighlighted()
|
|
38
|
+
end))
|
|
39
|
+
self:_updateHighlighted()
|
|
40
|
+
|
|
41
|
+
return self
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
--[=[
|
|
45
|
+
Sets the handle for the highlight model.
|
|
46
|
+
@param handle
|
|
47
|
+
]=]
|
|
48
|
+
function HandleHighlightModel:SetHandle(handle: Instance)
|
|
49
|
+
assert(typeof(handle) == "Instance" or handle == nil, "Bad handle")
|
|
50
|
+
|
|
51
|
+
local maid = Maid.new()
|
|
52
|
+
|
|
53
|
+
if handle then
|
|
54
|
+
maid:GiveTask(handle.MouseButton1Down:Connect(function()
|
|
55
|
+
self.IsMouseDown.Value = true
|
|
56
|
+
end))
|
|
57
|
+
maid:GiveTask(handle.MouseButton1Up:Connect(function()
|
|
58
|
+
self.IsMouseDown.Value = false
|
|
59
|
+
end))
|
|
60
|
+
maid:GiveTask(handle.MouseEnter:Connect(function()
|
|
61
|
+
self.IsMouseOver.Value = true
|
|
62
|
+
end))
|
|
63
|
+
maid:GiveTask(handle.MouseLeave:Connect(function()
|
|
64
|
+
self.IsMouseOver.Value = false
|
|
65
|
+
end))
|
|
66
|
+
|
|
67
|
+
maid:GiveTask(UserInputService.InputEnded:Connect(function(inputObject)
|
|
68
|
+
if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
|
|
69
|
+
self.IsMouseDown.Value = false
|
|
70
|
+
end
|
|
71
|
+
end))
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
self._maid._buttonMaid = maid
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
--[=[
|
|
79
|
+
Observes how pressed down the button is
|
|
80
|
+
@return Observable<number>
|
|
81
|
+
]=]
|
|
82
|
+
function HandleHighlightModel:ObservePercentPressed()
|
|
83
|
+
return Blend.AccelTween(Blend.toPropertyObservable(self.IsMouseDown)
|
|
84
|
+
:Pipe({
|
|
85
|
+
Rx.map(function(value)
|
|
86
|
+
return value and 1 or 0
|
|
87
|
+
end);
|
|
88
|
+
}), 200)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
--[=[
|
|
92
|
+
Observes how highlighted the button is
|
|
93
|
+
@return Observable<number>
|
|
94
|
+
]=]
|
|
95
|
+
function HandleHighlightModel:ObservePercentHighlighted()
|
|
96
|
+
return Blend.AccelTween(self:ObservePercentHighlightedTarget(), 200)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
--[=[
|
|
100
|
+
Observes target for how highlighted the button is
|
|
101
|
+
@return Observable<number>
|
|
102
|
+
]=]
|
|
103
|
+
function HandleHighlightModel:ObservePercentHighlightedTarget()
|
|
104
|
+
return Blend.toPropertyObservable(self.IsHighlighted)
|
|
105
|
+
:Pipe({
|
|
106
|
+
Rx.map(function(value)
|
|
107
|
+
return value and 1 or 0
|
|
108
|
+
end);
|
|
109
|
+
})
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
function HandleHighlightModel:_updateHighlighted()
|
|
113
|
+
self.IsHighlighted.Value = self.IsMouseOver.Value or self.IsMouseDown.Value
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
return HandleHighlightModel
|