-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scrollbar.lua
177 lines (149 loc) · 6.08 KB
/
Scrollbar.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
AK.Scroll = {
__call = function(I)
I:Call()
end
}
do
local Scroll = AK.Scroll
Scroll.__index = Scroll
function Scroll:New(gameObject,axe,container,coef,focus_model,fond_molette,molette_active)
return setmetatable( {
gameObject = gameObject,
active = false,
max = nil,
min = nil,
axe = axe,
scrollbar = nil,
scrollbar_model = false,
scrollbar_focus = focus_model or "Frameworks/Scroll/Bar_focus",
molette_active = molette_active,
container = container,
clicked = false,
flecheH = nil,
flecheB = nil,
fond_molette = fond_molette,
coef = coef or 100,
factor = 0
} , self )
end
function Scroll:Init()
local child = self.gameObject:GetChildren()
for k,v in pairs(child) do
local name = string.lower(v.Name)
if string.find(name,"max",1) == 1 then
self.max = self.axe and v.LocalPos.y or v.LocalPos.x
elseif string.find(name,"min",1) == 1 then
self.min = self.axe and v.LocalPos.y or v.LocalPos.x
elseif string.find(name,"scrollbar",1) == 1 then
self.scrollbar = v
self.scrollbar_model = CS.CheckModel( v , "Frameworks/Scroll/Bar" )
elseif string.find(name,"flecheh",1) == 1 then
self.flecheH = v
elseif string.find(name,"flecheb",1) == 1 then
self.flecheB = v
end
end
if self.scrollbar ~= nil and self.max ~= nil and self.min ~= nil then self.active = true else return false end
end
function Scroll:GoFactor()
local bar = self.scrollbar.LocalPos
self.factor = math.round( ( self.axe and bar.y - self.min or bar.x - self.min ) / ( self.max - (self.min) ) * self.coef)
if self.container ~= nil then
self.container:SendMessage("Move", { factor = self.factor , coef = self.coef, axe = self.axe } )
end
end
function Scroll:Move()
local warp = AK.UI.ray.position + AK.UI.ray.direction
local bar = self.scrollbar.LocalPos
warp = self.axe and warp.y - self.gameObject.Pos.y or warp.x - self.gameObject.Pos.x
if self.axe then
warp = (warp < self.min) and self.min or ( ( warp > self.max ) and self.max or warp )
else
warp = (warp > self.min) and self.min or ( ( warp < self.max ) and self.max or warp )
end
if self.axe then
self.scrollbar.transform:SetLocalPosition( Vector3:New( bar.x , warp , bar.z ) )
else
self.scrollbar.transform:SetLocalPosition( Vector3:New( warp , bar.y , bar.z ) )
end
self:GoFactor()
end
function Scroll:Molette(V)
if self.molette_active then
local bar = self.scrollbar.LocalPos
local axe = self.axe and bar.y or bar.x
axe = V and ( ( axe + 2 > self.max ) and self.max or axe + 2 ) or ( ( axe - 2 < self.min ) and self.min or axe - 2 )
if self.axe then
self.scrollbar.transform:SetLocalPosition( Vector3:New( bar.x , axe , bar.z ) )
else
self.scrollbar.transform:SetLocalPosition( Vector3:New( axe , bar.y , bar.z ) )
end
self:GoFactor()
end
end
function Scroll:Call()
local ray = AK.UI.ray
if self.active then
local molette = false
if self.clicked then
self:Move()
if CS.KeyReleased("SG") then
self.clicked = false
AK.OnDrag = true
self.scrollbar.modelRenderer:SetModel( self.scrollbar_model )
end
else
if ray:IntersectsModelRenderer( self.scrollbar.modelRenderer ) ~= nil then
if CS.KeyDown("SG") and AK.OnDrag then
self.clicked = true
AK.OnDrag = false
self.scrollbar.modelRenderer:SetModel( CS.FindAsset( self.scrollbar_focus , "Model" ) )
end
molette = true
elseif ray:IntersectsModelRenderer( self.gameObject.modelRenderer ) ~= nil then
if CS.KeyReleased("SG") then
self:Move()
end
molette = true
end
end
if self.fond_molette ~= nil then
if ray:IntersectsModelRenderer( self.fond_molette.modelRenderer ) ~= nil then
molette = true
end
end
if molette then
if CS.KeyPressed("SMH") then
self:Molette(false)
elseif CS.KeyPressed("SMB") then
self:Molette(true)
end
end
if CS.KeyReleased("SG") then
if self.flecheH ~= nil then
if ray:IntersectsModelRenderer( self.flecheH.modelRenderer ) ~= nil then
self:Molette(true)
end
end
if self.flecheB ~= nil then
if ray:IntersectsModelRenderer( self.flecheB.modelRenderer ) ~= nil then
self:Molette(false)
end
end
end
end
end
function Scroll:Set(V)
local coef_warp = 100 - (self.coef - V.coef)
local bar = self.scrollbar.LocalPos
if coef_warp >= 50 then
bar.x = (self.min / 50) * (coef_warp - 50)
else
bar.x = (self.max / 50) * (50 - coef_warp)
end
self.scrollbar.transform:SetLocalPosition( bar )
end
function Scroll:Get()
return self.factor
end
end