forked from ruilov/CargoBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPopover.lua
112 lines (98 loc) · 2.75 KB
/
Popover.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
Popover = class()
function Popover:init(x,y,w,h)
self.x = x
self.y = y
self.w = w
self.h = h
self.visible = false
self.icons = {}
end
-- if dir is "left" or "right", coord is height of the arrow from the bottom of the popover
-- if dir is "up" or "down", coord is dist of the arrow from the left edge of the popover
function Popover:arrow(dir,coord)
self.arrowData = {dir=dir,coord=coord}
end
function Popover:show()
self.visible = true
end
function Popover:hide()
self.visible = false
end
function Popover:setText(text,fontSize)
self.text = text
self.fontSize = fontSize
end
function Popover:pack()
if self.text then
pushStyle()
font("Futura-CondensedExtraBold")
textWrapWidth(500)
fontSize(self.fontSize)
local w,h = textSize(self.text)
self.w,self.h = w + 20, h + 12
popStyle()
end
end
function Popover:addIcon(imgName,x,y,w,h)
table.insert(self.icons,{imgName=imgName,x=x,y=y,w=w,h=h})
end
function Popover:draw()
if not self.visible then return nil end
pushMatrix()
pushStyle()
translate(self.x,self.y)
rectMode(CORNER)
stroke(0, 0, 0, 255)
fill(0, 138, 255, 255)
strokeWidth(5)
rect(0,0,self.w,self.h)
if self.arrowData then
spriteMode(CORNER)
local arrw,arrh = 22,25
local arrx,arry,arrang,shax
if self.arrowData.dir == "right" then
arrx = self.w-6
shax = arrx+1
arry = self.arrowData.coord
arrang = 0
elseif self.arrowData.dir == "left" then
arrx = -6
shax = arrx+2
arry = self.arrowData.coord - arrh
arrang = 180
elseif self.arrowData.dir == "up" then
arrx = self.h-6
shax = arrx+1
arry = -self.arrowData.coord - arrh
arrang = 90
elseif self.arrowData.dir == "down" then
arrx = -6
shax = arrx+1
arry = self.arrowData.coord
arrang = -90
end
pushMatrix()
rotate(arrang)
tint(0, 0, 0, 255)
sprite("Cargo Bot:Play Solution Icon",shax,arry-3,arrw+5,arrh+6)
tint(0,138,255,255)
sprite("Cargo Bot:Play Solution Icon",arrx,arry,arrw,arrh)
popMatrix()
end
if self.text then
fill(255, 255, 255, 255)
font("Futura-CondensedExtraBold")
textWrapWidth(self.w-15)
textMode(CORNER)
fontSize(self.fontSize)
local w,h = textSize(self.text)
text(self.text,10,self.h - h - 5)
end
noTint()
spriteMode(CORNER)
for _,icon in ipairs(self.icons) do
sprite(icon.imgName,icon.x,icon.y,icon.w,icon.h)
end
popStyle()
popMatrix()
end