-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.lua
95 lines (88 loc) · 1.88 KB
/
menu.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
-- vim:et
class "Menu"
function Menu:initialize(o)
self.items={}
self.obj=o
end
function Menu:add(s,v)
if type(v)=="table" then
self.items[#self.items+1]={str=s,menu=v}
v.parent=self
else
self.items[#self.items+1]={str=s,func=v}
end
end
function Menu:draw()
local x,y=(self.obj.x+eye.vx)*eye.s+eye.cx,(self.obj.y+eye.vy)*eye.s+eye.cy
x=x+(self.obj.r+8)*eye.s
y=y-(#self.items*9)
graph.setLine(1,"rough")
local ml=0
for _,v in pairs(self.items) do
local l=v.str:len()
if ml<l then
ml=l
end
end
ml=ml*10
for _,v in pairs(self.items) do
if msx>x and msx<x+ml-2 and msy>y and msy<y+17 then
graph.setColor(219,159,223)
graph.rectangle("fill",x,y,ml-1,18)
graph.setColor(255,255,255)
graph.rectangle("line",x,y,ml,19)
graph.setColor(0,0,0)
graph.print(v.str,x+3,y+2)
else
graph.setColor(0,0,0)
graph.rectangle("fill",x,y,ml-1,18)
graph.setColor(255,255,255)
graph.rectangle("line",x,y,ml,19)
graph.setColor(255,255,255)
graph.print(v.str,x+3,y+2)
end
y=y+19
end
end
function Menu:switch(fs,ts)
for _,v in pairs(self.items) do
if v.str==fs then
v.str=ts
return
end
end
end
function Menu:cleanup()
for k,v in pairs(self.items) do
if v.str=="UNLINK" then
v.str="Unlink"
break
end
end
end
function Menu:click(mx,my)
local x,y=(self.obj.x+eye.vx)*eye.s+eye.cx,(self.obj.y+eye.vy)*eye.s+eye.cy
x=x+(self.obj.r+8)*eye.s
y=y-(#self.items*9)
local ml=0
for _,v in pairs(self.items) do
local l=v.str:len()
if ml<l then
ml=l
end
end
ml=ml*10
for _,v in pairs(self.items) do
if mx>x and mx<x+ml-2 and my>y and my<y+17 then
if v.str=="Unlink" then
v.str="UNLINK"
return self
end
v.func(self.obj)
break
end
y=y+19
end
self:cleanup()
return nil
end