@quenty/buttonhighlightmodel 7.5.0 → 7.6.1

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 CHANGED
@@ -3,6 +3,25 @@
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.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/buttonhighlightmodel@7.6.0...@quenty/buttonhighlightmodel@7.6.1) (2022-12-27)
7
+
8
+ **Note:** Version bump only for package @quenty/buttonhighlightmodel
9
+
10
+
11
+
12
+
13
+
14
+ # [7.6.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/buttonhighlightmodel@7.5.0...@quenty/buttonhighlightmodel@7.6.0) (2022-12-06)
15
+
16
+
17
+ ### Features
18
+
19
+ * Add HandleHighlightModel ([94ca0bd](https://github.com/Quenty/NevermoreEngine/commit/94ca0bdf3e6fedbfc25b1a557b895d05823b95b7))
20
+
21
+
22
+
23
+
24
+
6
25
  # [7.5.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/buttonhighlightmodel@7.4.0...@quenty/buttonhighlightmodel@7.5.0) (2022-12-05)
7
26
 
8
27
  **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.5.0",
3
+ "version": "7.6.1",
4
4
  "description": "Contains model information for the current button",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -28,14 +28,14 @@
28
28
  "dependencies": {
29
29
  "@quenty/acceltween": "^2.2.1",
30
30
  "@quenty/baseobject": "^6.0.1",
31
- "@quenty/blend": "^6.5.0",
31
+ "@quenty/blend": "^6.5.1",
32
32
  "@quenty/loader": "^6.0.1",
33
33
  "@quenty/maid": "^2.4.0",
34
- "@quenty/rx": "^7.2.0",
34
+ "@quenty/rx": "^7.2.1",
35
35
  "@quenty/steputils": "^3.2.0"
36
36
  },
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
- "gitHead": "3040397f5f4601886ca7a1f664be7019b3941618"
40
+ "gitHead": "ff0c0732eca3400949945c58c1d3cb8a479c9789"
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