@quenty/buttondragmodel 1.15.2-canary.547.ba47c62.0 → 1.15.3-canary.550.afa1b3b.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 +9 -1
- package/LICENSE.md +1 -1
- package/package.json +8 -8
- package/src/Client/ButtonDragModel.lua +50 -26
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,15 @@
|
|
|
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
|
-
## [1.15.
|
|
6
|
+
## [1.15.3-canary.550.afa1b3b.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/buttondragmodel@1.15.2...@quenty/buttondragmodel@1.15.3-canary.550.afa1b3b.0) (2025-04-10)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @quenty/buttondragmodel
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [1.15.2](https://github.com/Quenty/NevermoreEngine/compare/@quenty/buttondragmodel@1.15.0...@quenty/buttondragmodel@1.15.2) (2025-04-07)
|
|
7
15
|
|
|
8
16
|
|
|
9
17
|
### Bug Fixes
|
package/LICENSE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2014-
|
|
3
|
+
Copyright (c) 2014-2025 James Onnen (Quenty)
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/buttondragmodel",
|
|
3
|
-
"version": "1.15.
|
|
3
|
+
"version": "1.15.3-canary.550.afa1b3b.0",
|
|
4
4
|
"description": "Model for dragging buttons around",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -25,15 +25,15 @@
|
|
|
25
25
|
"Quenty"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@quenty/baseobject": "10.8.
|
|
29
|
-
"@quenty/inputobjectutils": "4.18.
|
|
30
|
-
"@quenty/loader": "10.8.
|
|
31
|
-
"@quenty/maid": "3.4.
|
|
32
|
-
"@quenty/rx": "13.17.
|
|
33
|
-
"@quenty/valueobject": "13.17.
|
|
28
|
+
"@quenty/baseobject": "10.8.3-canary.550.afa1b3b.0",
|
|
29
|
+
"@quenty/inputobjectutils": "4.18.3-canary.550.afa1b3b.0",
|
|
30
|
+
"@quenty/loader": "10.8.3-canary.550.afa1b3b.0",
|
|
31
|
+
"@quenty/maid": "3.4.3-canary.550.afa1b3b.0",
|
|
32
|
+
"@quenty/rx": "13.17.3-canary.550.afa1b3b.0",
|
|
33
|
+
"@quenty/valueobject": "13.17.3-canary.550.afa1b3b.0"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "afa1b3b99b862698c3ab46009497bd507150867c"
|
|
39
39
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
--!strict
|
|
1
2
|
--[=[
|
|
2
3
|
Computes the position of a user dragging a button around
|
|
3
4
|
|
|
@@ -14,19 +15,37 @@ local InputObjectUtils = require("InputObjectUtils")
|
|
|
14
15
|
local ValueObject = require("ValueObject")
|
|
15
16
|
local _Observable = require("Observable")
|
|
16
17
|
local _Brio = require("Brio")
|
|
18
|
+
local _Signal = require("Signal")
|
|
17
19
|
|
|
18
20
|
local ButtonDragModel = setmetatable({}, BaseObject)
|
|
19
21
|
ButtonDragModel.ClassName = "ButtonDragModel"
|
|
20
22
|
ButtonDragModel.__index = ButtonDragModel
|
|
21
23
|
|
|
24
|
+
export type ButtonDragModel = typeof(setmetatable(
|
|
25
|
+
{} :: {
|
|
26
|
+
_dragPosition: ValueObject.ValueObject<Vector2?>,
|
|
27
|
+
_dragDelta: ValueObject.ValueObject<Vector2?>,
|
|
28
|
+
_isMouseDown: ValueObject.ValueObject<boolean>,
|
|
29
|
+
_button: ValueObject.ValueObject<GuiButton?>,
|
|
30
|
+
_absoluteSize: ValueObject.ValueObject<Vector2>,
|
|
31
|
+
_isPressed: ValueObject.ValueObject<boolean>,
|
|
32
|
+
_clampWithinButton: ValueObject.ValueObject<boolean>,
|
|
33
|
+
_activePositions: { [InputObject | string]: Vector2? },
|
|
34
|
+
|
|
35
|
+
DragPositionChanged: _Signal.Signal<Vector2>,
|
|
36
|
+
IsDraggingChanged: _Signal.Signal<boolean>,
|
|
37
|
+
},
|
|
38
|
+
{} :: typeof({ __index = ButtonDragModel })
|
|
39
|
+
)) & BaseObject.BaseObject
|
|
40
|
+
|
|
22
41
|
--[=[
|
|
23
42
|
Construst a new drag model for the button
|
|
24
43
|
|
|
25
44
|
@param initialButton GuiButton? -- Optional
|
|
26
45
|
@return ButtonDragModel
|
|
27
46
|
]=]
|
|
28
|
-
function ButtonDragModel.new(initialButton: GuiButton?)
|
|
29
|
-
local self = setmetatable(BaseObject.new(), ButtonDragModel)
|
|
47
|
+
function ButtonDragModel.new(initialButton: GuiButton?): ButtonDragModel
|
|
48
|
+
local self: ButtonDragModel = setmetatable(BaseObject.new() :: any, ButtonDragModel)
|
|
30
49
|
|
|
31
50
|
self._isMouseDown = self._maid:Add(ValueObject.new(false, "boolean"))
|
|
32
51
|
self._dragPosition = self._maid:Add(ValueObject.new(nil))
|
|
@@ -44,14 +63,14 @@ function ButtonDragModel.new(initialButton: GuiButton?)
|
|
|
44
63
|
end))
|
|
45
64
|
|
|
46
65
|
self.DragPositionChanged = self._dragPosition.Changed
|
|
47
|
-
self.IsDraggingChanged = self._isPressed.Changed
|
|
66
|
+
self.IsDraggingChanged = self._isPressed.Changed :: any
|
|
48
67
|
|
|
49
68
|
if initialButton then
|
|
50
69
|
self:SetButton(initialButton)
|
|
51
70
|
end
|
|
52
71
|
|
|
53
72
|
self._maid:GiveTask(self._button
|
|
54
|
-
:ObserveBrio(function(button)
|
|
73
|
+
:ObserveBrio(function(button: GuiButton?)
|
|
55
74
|
return button ~= nil
|
|
56
75
|
end)
|
|
57
76
|
:Subscribe(function(brio)
|
|
@@ -59,7 +78,7 @@ function ButtonDragModel.new(initialButton: GuiButton?)
|
|
|
59
78
|
return
|
|
60
79
|
end
|
|
61
80
|
|
|
62
|
-
local maid, button = brio:ToMaidAndValue()
|
|
81
|
+
local maid, button: any = brio:ToMaidAndValue()
|
|
63
82
|
self:_setupDragging(maid, button)
|
|
64
83
|
end))
|
|
65
84
|
|
|
@@ -71,7 +90,7 @@ end
|
|
|
71
90
|
|
|
72
91
|
@return boolean
|
|
73
92
|
]=]
|
|
74
|
-
function ButtonDragModel
|
|
93
|
+
function ButtonDragModel.IsPressed(self: ButtonDragModel): boolean
|
|
75
94
|
return self._isPressed.Value
|
|
76
95
|
end
|
|
77
96
|
|
|
@@ -80,30 +99,30 @@ end
|
|
|
80
99
|
|
|
81
100
|
@return Observable<boolean>
|
|
82
101
|
]=]
|
|
83
|
-
function ButtonDragModel
|
|
102
|
+
function ButtonDragModel.ObserveIsPressed(self: ButtonDragModel): _Observable.Observable<boolean>
|
|
84
103
|
return self._isPressed:Observe()
|
|
85
104
|
end
|
|
86
105
|
|
|
87
106
|
--[=[
|
|
88
107
|
@return Observable<Brio<true>>
|
|
89
108
|
]=]
|
|
90
|
-
function ButtonDragModel
|
|
109
|
+
function ButtonDragModel.ObserveIsPressedBrio(self: ButtonDragModel): _Observable.Observable<_Brio.Brio<boolean>>
|
|
91
110
|
return self._isPressed:ObserveBrio(function(value)
|
|
92
|
-
return value
|
|
93
|
-
end)
|
|
111
|
+
return value :: any
|
|
112
|
+
end) :: any
|
|
94
113
|
end
|
|
95
114
|
|
|
96
115
|
--[=[
|
|
97
116
|
@return Observable<Vector2?>
|
|
98
117
|
]=]
|
|
99
|
-
function ButtonDragModel
|
|
118
|
+
function ButtonDragModel.ObserveDragDelta(self: ButtonDragModel): _Observable.Observable<Vector2?>
|
|
100
119
|
return self._dragDelta:Observe()
|
|
101
120
|
end
|
|
102
121
|
|
|
103
122
|
--[=[
|
|
104
123
|
@return Vector2?
|
|
105
124
|
]=]
|
|
106
|
-
function ButtonDragModel
|
|
125
|
+
function ButtonDragModel.GetDragDelta(self: ButtonDragModel): Vector2?
|
|
107
126
|
return self._dragDelta.Value
|
|
108
127
|
end
|
|
109
128
|
|
|
@@ -114,7 +133,7 @@ end
|
|
|
114
133
|
|
|
115
134
|
@return Vector2?
|
|
116
135
|
]=]
|
|
117
|
-
function ButtonDragModel
|
|
136
|
+
function ButtonDragModel.GetDragPosition(self: ButtonDragModel): Vector2?
|
|
118
137
|
return self._dragPosition.Value
|
|
119
138
|
end
|
|
120
139
|
|
|
@@ -125,7 +144,7 @@ end
|
|
|
125
144
|
|
|
126
145
|
@return Observable<Vector2?>
|
|
127
146
|
]=]
|
|
128
|
-
function ButtonDragModel
|
|
147
|
+
function ButtonDragModel.ObserveDragPosition(self: ButtonDragModel): _Observable.Observable<Vector2?>
|
|
129
148
|
return self._dragPosition:Observe()
|
|
130
149
|
end
|
|
131
150
|
|
|
@@ -133,7 +152,7 @@ end
|
|
|
133
152
|
Sets whether to clamp the results within the button bounds
|
|
134
153
|
@param clampWithinButton boolean
|
|
135
154
|
]=]
|
|
136
|
-
function ButtonDragModel
|
|
155
|
+
function ButtonDragModel.SetClampWithinButton(self: ButtonDragModel, clampWithinButton: boolean)
|
|
137
156
|
self._clampWithinButton.Value = clampWithinButton
|
|
138
157
|
end
|
|
139
158
|
|
|
@@ -143,7 +162,7 @@ end
|
|
|
143
162
|
@param button GuiButton
|
|
144
163
|
@return () -> () -- Cleanup function
|
|
145
164
|
]=]
|
|
146
|
-
function ButtonDragModel
|
|
165
|
+
function ButtonDragModel.SetButton(self: ButtonDragModel, button: GuiButton): () -> ()
|
|
147
166
|
assert(typeof(button) == "Instance" or button == nil, "Bad button")
|
|
148
167
|
|
|
149
168
|
self._button.Value = button
|
|
@@ -155,7 +174,7 @@ function ButtonDragModel:SetButton(button: GuiButton): () -> ()
|
|
|
155
174
|
end
|
|
156
175
|
end
|
|
157
176
|
|
|
158
|
-
function ButtonDragModel
|
|
177
|
+
function ButtonDragModel._setupDragging(self: ButtonDragModel, maid: Maid.Maid, button: GuiButton)
|
|
159
178
|
maid:GiveTask(self._clampWithinButton.Changed:Connect(function()
|
|
160
179
|
self:_updateCurrentPosition()
|
|
161
180
|
end))
|
|
@@ -204,7 +223,7 @@ function ButtonDragModel:_setupDragging(maid: Maid.Maid, button: GuiButton)
|
|
|
204
223
|
end))
|
|
205
224
|
end
|
|
206
225
|
|
|
207
|
-
function ButtonDragModel
|
|
226
|
+
function ButtonDragModel._updateMouseTracking(self: ButtonDragModel, button: GuiButton)
|
|
208
227
|
local maid = Maid.new()
|
|
209
228
|
|
|
210
229
|
local lastMousePosition: Vector3? = nil
|
|
@@ -260,7 +279,12 @@ function ButtonDragModel:_updateMouseTracking(button: GuiButton)
|
|
|
260
279
|
return maid
|
|
261
280
|
end
|
|
262
281
|
|
|
263
|
-
function ButtonDragModel
|
|
282
|
+
function ButtonDragModel._trackTouch(
|
|
283
|
+
self: ButtonDragModel,
|
|
284
|
+
buttonMaid: Maid.Maid,
|
|
285
|
+
button: GuiButton,
|
|
286
|
+
inputObject: InputObject
|
|
287
|
+
)
|
|
264
288
|
buttonMaid[inputObject] = nil
|
|
265
289
|
|
|
266
290
|
if inputObject.UserInputState == Enum.UserInputState.End then
|
|
@@ -296,23 +320,23 @@ function ButtonDragModel:_trackTouch(buttonMaid: Maid.Maid, button: GuiButton, i
|
|
|
296
320
|
maid[inputObject] = maid
|
|
297
321
|
end
|
|
298
322
|
|
|
299
|
-
function ButtonDragModel
|
|
323
|
+
function ButtonDragModel._stopTouchTrack(_self: ButtonDragModel, buttonMaid: Maid.Maid, inputObject: InputObject)
|
|
300
324
|
-- Clears the input tracking as we slide off the button
|
|
301
325
|
buttonMaid[inputObject] = nil
|
|
302
326
|
end
|
|
303
327
|
|
|
304
|
-
function ButtonDragModel
|
|
328
|
+
function ButtonDragModel._toButtonSpace(_self: ButtonDragModel, button: GuiButton, position: Vector3): Vector2
|
|
305
329
|
local pos = button.AbsolutePosition
|
|
306
330
|
local size = button.AbsoluteSize
|
|
307
331
|
|
|
308
332
|
return (Vector2.new(position.X, position.Y) - pos) / size
|
|
309
333
|
end
|
|
310
334
|
|
|
311
|
-
function ButtonDragModel
|
|
312
|
-
local current = Vector2.zero
|
|
335
|
+
function ButtonDragModel._updateCurrentPosition(self: ButtonDragModel): ()
|
|
336
|
+
local current: Vector2 = Vector2.zero
|
|
313
337
|
local count = 0
|
|
314
|
-
for _, item in self._activePositions do
|
|
315
|
-
current
|
|
338
|
+
for _, item: any in self._activePositions do
|
|
339
|
+
current += item
|
|
316
340
|
count = count + 1
|
|
317
341
|
end
|
|
318
342
|
if count == 0 then
|
|
@@ -338,7 +362,7 @@ function ButtonDragModel:_updateCurrentPosition()
|
|
|
338
362
|
end
|
|
339
363
|
end
|
|
340
364
|
|
|
341
|
-
function ButtonDragModel
|
|
365
|
+
function ButtonDragModel._incrementDragDelta(self: ButtonDragModel, delta: Vector3)
|
|
342
366
|
local current: Vector2 = self._dragDelta.Value or Vector2.zero
|
|
343
367
|
self._dragDelta.Value = current + Vector2.new(delta.X, delta.Y)
|
|
344
368
|
end
|