-
Notifications
You must be signed in to change notification settings - Fork 2
/
animations.lua
217 lines (201 loc) · 9.25 KB
/
animations.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
-------------------------------------------------
------------ EDITED BY Beyonder#0711 ------------
-------------------------------------------------
-------------- metascripts.org-------------------
-------------------------------------------------
-------------------------
-- İmportant Functions
-------------------------
local sx,sy = guiGetScreenSize()
function debug(msg,type,r,g,b)
outputDebugString(getResourceName(getThisResource()).." : - "..msg,type,r,g,b)
end
function relativeto(x1,x2)
return sx *x1, sy*x2
end
function torelative(x1,x2)
return x1/sx,x2/sy
end
function hex2rgb(hex) --Hex to R,G,B
hex = hex:gsub("#","")
return tonumber("0x"..hex:sub(1,2)), tonumber("0x"..hex:sub(3,4)), tonumber("0x"..hex:sub(5,6))
end
-------------------------------------------
--GUI Animations
-------------------------------------------
local animations = {}
local anim_timers = {}
--Gui moving animation
function guiMoveTo(elm,movex,movey,relative,easing,duration,waiting)
local x,y = guiGetPosition(elm,relative)
local tick = getTickCount()
if waiting then
table.insert(anim_timers,{
elm = elm,
timer = setTimer(function(elm,startx,starty,movex,movey,relative,easing,duration)
table.insert(animations,{anim_type="moving",elm=elm,startx=x,starty=y,movex=movex,movey=movey,relative=relative,oldTick=tick,easing=easing,duration=duration})
end,waiting,1,elm,x,y,movex,movey,relative,easing,duration)
})
else
table.insert(animations,{anim_type="moving",elm=elm,startx=x,starty=y,movex=movex,movey=movey,relative=relative,oldTick=tick,easing=easing,duration=duration})
end
end
--Gui Alpha animation
function guiAlphaTo(elm,movealpha,easing,duration,waiting)
local startalpha = guiGetAlpha(elm)
local tick = getTickCount()
if waiting then
table.insert(anim_timers,{
elm = elm,
timer = setTimer(function(elm,startalpha,movealpha,easing,duration)
table.insert(animations,{anim_type="alpha",elm=elm,startalpha=startalpha,movealpha=movealpha,oldTick=tick,easing=easing,duration=duration})
end,waiting,1,elm,startalpha,movealpha,easing,duration)
})
else
table.insert(animations,{anim_type="alpha",elm=elm,startalpha=startalpha,movealpha=movealpha,oldTick=tick,easing=easing,duration=duration})
end
end
--Gui sizing animation
function guiSizeTo(elm,sizew,sizeh,relative,easing,duration,waiting)
local w,h = guiGetSize(elm,relative)
local tick = getTickCount()
if waiting then
table.insert(anim_timers,{
elm = elm,
timer = setTimer(function(elm,w,h,sizew,sizeh,relative,easing,duration)
table.insert(animations,{anim_type="sizing",elm=elm,startw=w,starth=h,sizew=sizew,sizeh=sizeh,relative=relative,oldTick=tick,easing=easing,duration=duration})
end,waiting,1,elm,w,h,sizew,sizeh,relative,easing,duration)
})
else
table.insert(animations,{anim_type="sizing",elm=elm,startw=w,starth=h,sizew=sizew,sizeh=sizeh,relative=relative,oldTick=tick,easing=easing,duration=duration})
end
end
function guiStopAniming(elm)
for k,v in ipairs(anim_timers) do
if v.elm == elm then
if isTimer(v.timer) then
killTimer(v.timer)
end
table.remove(anim_timers,k)
end
end
for index,animt in ipairs(animations) do
if animt.elm == elm then
table.remove(animations,index)
end
end
end
function setAnimRender()
local nowTick = getTickCount()
for index,animt in ipairs(animations) do
if animt.anim_type == "moving" then
if animt.relative then
local startx,starty = relativeto(animt.startx,animt.starty)
local movex,movey = relativeto(animt.movex,animt.movey)
movex,movey = interpolateBetween(startx,starty,0,movex,movey,0,(nowTick-animt.oldTick)/animt.duration,animt.easing)
movex,movey = torelative(movex,movey)
guiSetPosition(animt.elm,movex,movey,animt.relative)
if nowTick-animt.oldTick > animt.duration then table.remove(animations,index) end
else
local movex,movey = interpolateBetween(animt.startx,animt.starty,0,animt.movex,animt.movey,0,(nowTick-animt.oldTick)/animt.duration,animt.easing)
guiSetPosition(animt.elm,movex,movey,animt.relative)
if nowTick-animt.oldTick > animt.duration then table.remove(animations,index) end
end
end
if animt.anim_type == "alpha" then
local movealpha= interpolateBetween(animt.startalpha,0,0,animt.movealpha,0,0,(nowTick-animt.oldTick)/animt.duration,animt.easing)
guiSetAlpha(animt.elm,movealpha)
if nowTick-animt.oldTick > animt.duration then table.remove(animations,index) end
end
if animt.anim_type == "sizing" then
if animt.relative then
local startw,starth = relativeto(animt.startw,animt.starth)
local sizew,sizeh = relativeto(animt.sizew,animt.sizeh)
sizew,sizeh = interpolateBetween(startw,starth,0,sizew,sizeh,0,(nowTick-animt.oldTick)/animt.duration,animt.easing)
sizew,sizeh = torelative(sizew,sizeh)
guiSetSize(animt.elm,sizew,sizeh,animt.relative)
if nowTick-animt.oldTick > animt.duration then table.remove(animations,index) end
else
local movew,moveh = interpolateBetween(animt.startw,animt.starth,0,animt.sizew,animt.sizeh,0,(nowTick-animt.oldTick)/animt.duration,animt.easing)
guiSetSize(animt.elm,movew,moveh,animt.relative)
if nowTick-animt.oldTick > animt.duration then table.remove(animations,index) end
end
end
end
end
addEventHandler("onClientRender",root,setAnimRender)
---Custom Anims
--------------------------------------------------
--gui Alert Animation ( - gui uyarı animasyonu - )
---------------------------------------------------
function guiAlertAnim(element,relative)
if not element then return end
local elm_x,elm_y = guiGetPosition(element,relative)
local elm_w,elm_h = guiGetSize(element,relative)
local move_result = 0
if relative then
move_result = 0.01
else
move_result = 10
end
guiMoveTo(element,elm_x-move_result,elm_y,relative,"SineCurve",500)
guiMoveTo(element,elm_x+move_result,elm_y,relative,"SineCurve",500,50)
guiMoveTo(element,elm_x-move_result,elm_y,relative,"SineCurve",500,100)
guiMoveTo(element,elm_x+move_result,elm_y,relative,"SineCurve",500,150)
guiMoveTo(element,elm_x-move_result,elm_y,relative,"SineCurve",500,200)
guiMoveTo(element,elm_x+move_result,elm_y,relative,"SineCurve",500,250)
guiMoveTo(element,elm_x-move_result,elm_y,relative,"SineCurve",500,300)
guiMoveTo(element,elm_x+move_result,elm_y,relative,"SineCurve",500,350)
guiMoveTo(element,elm_x-move_result,elm_y,relative,"SineCurve",500,400)
guiMoveTo(element,elm_x,elm_y,relative,"SineCurve",500,450)
setTimer(function(element,elm_x,elm_y,relative,elm_w,elm_h)
guiStopAniming(element)
guiSetPosition(element,elm_x,elm_y,relative)
guiSetSize(element,elm_w,elm_h,relative)
end,650,2,element,elm_x,elm_y,relative,elm_w,elm_h)
end
----------------------------------
--Elements Tooltip
-----------------------------------
local tooltip_elements = {}
background = guiCreateGridList(0,0,190,100,false)
local label = guiCreateLabel(0,20,190,100,"asdasd",false,background)
--guiSetEnabled(label,false)
guiSetProperty(label,"DisabledTextColour","FFFFFFFF")
-- guiSetProperty(background,"AlwaysOnTop","True")
guiSetProperty(label,"AlwaysOnTop","True")
guiLabelSetHorizontalAlign(label,"left")
guiLabelSetVerticalAlign(label,"top")
status_tooltip = false
guiSetVisible(background,false)
addEventHandler( "onClientMouseEnter",root, function(aX, aY)
if tooltip_elements[source] then
if not status_tooltip then
local aX,aY = getCursorPosition()
aX,aY = relativeto(aX,aY)
guiBringToFront(background)
guiSetText(label,tooltip_elements[source][1])
guiSetVisible(background,true)
local _,piece = string.gsub(tooltip_elements[source][1], "\n", "")
if tooltip_elements[source][2] then
guiLabelSetColor(label,hex2rgb(tooltip_elements[source][2]))
end
guiSetSize(label,190,(15+(piece*15)),false)
guiSetSize(background,140,(55+(piece*7.2)),false)
guiSetPosition(background,aX+45,aY-50,false)
guiSetPosition(label,10,10,false)
status_tooltip = true
end
end
end)
addEventHandler( "onClientMouseLeave", root, function()
if status_tooltip then
guiSetText(label,"")
guiLabelSetColor(label,255,255,255)
status_tooltip = false
guiSetVisible(background,false)
end
end)
function guiAddTooltip(elm,text,color)
tooltip_elements[elm] = {text,color or false}
end