-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdxButton.lua
More file actions
131 lines (113 loc) · 4.1 KB
/
Copy pathdxButton.lua
File metadata and controls
131 lines (113 loc) · 4.1 KB
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
function dxCreateButton(x,y,w,h,text,btncolor,txtcolor, btnType, enabled, postgui)
if x and y and w and h then
local dxButtonElement = createElement("dxLibButton")
if isElement(dxButtonElement) then
dxbuttonData = {}
dxbuttonData.x = x
dxbuttonData.y = y
dxbuttonData.w = w
dxbuttonData.h = h
dxbuttonData.text = text or "Button"
dxbuttonData.btncolor = btncolor or {255,0,20}
dxbuttonData.txtcolor = txtcolor or {255,255,255}
dxbuttonData.hover = false
dxbuttonData.btnType = btnType or "normal"
dxbuttonData.target = dxCreateRenderTarget(w,h,true)
if enabled ~= nil and tostring(enabled) == "false" then
dxbuttonData.enabled = false
else
dxbuttonData.enabled = true
end
setElementData(dxButtonElement, "dxData", dxbuttonData, false)
return dxButtonElement
end
end
end
function dxDrawButton(dxButtonElement, x,y,w,h,text,btncolor,txtcolor, btnType, enabled, postgui)
if dxButtonElement then
d = getElementData(dxButtonElement, "dxData")
if d and type(d) == "table" then
d.x = x or d.x
d.y = y or d.y
d.w = w or d.w
d.h = h or d.h
d.text = text or d.text
d.btncolor = btncolor or d.btncolor
d.txtcolor = txtcolor or d.txtcolor
d.btnType = btnType or d.btnType
d.clicked = false
local x = d.x
local y = d.y
local w = d.w
local h = d.h
local text = d.text
local btnR, btnG, btnB = unpack(d.btncolor)
local textR,textG,textB = unpack(d.txtcolor)
local btnType = d.btnType
dh = d.target
if tostring(enabled) == "false" then
d.enabled = false
else
d.enabled = true
end
if btnType == "normal" then
btnAlpha = 255
circleR,circleG,circleB = 0,0,0
textR,textG,textB = 255,255,255
else
btnAlpha = 0
circleR,circleG,circleB = btnR, btnG, btnB
textR,textG,textB = btnR, btnG, btnB
end
if d.enabled and d.target then
dxDrawRoundedRectangle(x,y,w,h,tocolor(btnR, btnG, btnB,btnAlpha),15,postgui)
--dxDrawRectangle(x,y,w,h,tocolor(btnR, btnG, btnB,255), postgui)
dxDrawText(string.upper(text),x,y,x+w,y+h, tocolor(textR,textG,textB, 255), 1 ,dxFont, "center","center",false,false, postgui)
end
if d.enabled and isMawseInPosition(x, y, w, h) then
dxDrawRoundedRectangle(x,y,w,h,tocolor(50, 50, 50,50),10,postgui)
end
if clicked == true and d.enabled and d.target then
if progress >= 1 then
progress = 1
end
if clicked == true then
progress = progress + 0.02
end
alpha = interpolateBetween( 250,0,0, 0,0,0, progress, "Linear")
dxSetRenderTarget(d.target,true)
if isCursorShowing() then
theX = cursX*sX - x
theY = cursY*sY - y
aW , aH = interpolateBetween( 0,0,0, (x+w)*0.75,(y+h)*0.75,0, progress, "Linear")
nX , nY = interpolateBetween( theX,30,0, 200,200,0, progress, "Linear")
dxDrawImage(theX-aW/2,theY-aH/2, aW, aH,"img/circle.png", 0,0, 0,tocolor(circleR,circleG,circleB,alpha))
dxSetRenderTarget()
--
-- clicked = false
end
dxDrawImage(x,y,w,h, d.target, 0, 0, 0, tocolor(btnR, btnG, btnB,170))
end
-- progress = 0
setElementData(dxButtonElement, "dxData", d, false)
end
end
end
function dxLibClientClick(button,state)
if button == "left" and state == "up" then
for i, dxLibButton in pairs(getElementsByType("dxLibButton")) do
local dxData = getElementData(dxLibButton, "dxData")
if isMawseInPosition ( dxData.x , dxData.y , dxData.w , dxData.h ) then
if dxData.enabled then
clicked = true
cursX , cursY = getCursorPosition()
triggerEvent("onConolelClick", getRootElement(), dxLibButton)
progress = 0
setElementData(dxLibButton, "dxData", dxData, false)
-- outputChatBox("hehe")
end
end
end
end
end
addEventHandler("onClientClick", root, dxLibClientClick)