-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurTWEventBubble.lua
148 lines (125 loc) · 3.4 KB
/
urTWEventBubble.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
-- ================
-- = Event Bubble =
-- ================
-- event notification bubble, should later be turn into a draggable menu
-- singleton class, or not really a class, just a table, always on top region
STAY_TIME = 2
bubbleView = {}
menu = {}
function bubbleView:Init()
self.r = Region('region', 'event', UIParent)
self.r:SetLayer("TOOLTIP")
self.r:SetAnchor('CENTER',ScreenWidth()/2,ScreenHeight()-25)
self.r.t = self.r:Texture("texture/tw_bubble.png")
self.r.t:SetBlendMode("BLEND")
self.r.tl = self.r:TextLabel()
self.r.tl:SetFontHeight(20)
self.r.tl:SetFont("Avenir Next Condensed")
self.r.tl:SetColor(255,255,255,255)
self.r.tl:SetShadowColor(0,0,0,0)
self.r.tl:SetHorizontalAlign("CENTER")
-- self.r.tl:SetVerticalAlign("MIDDLE")
self.r.timer = 0
self.r.region=NULL
self.r.o = self
self.r.sizeChangeSpeed = 0
self.r.w = 120
self.r.h = 120
self.r:Handle("OnTouchDown", bubbleView.OnTouchDown)
self.r:Handle("OnTouchUp", bubbleView.OnTouchUp)
end
function bubbleView:ShowEvent(text, region, menu)
self.showMenu = menu
if self.r:IsVisible() and region == self.r.region then
self.r.tl:SetLabel(text)
self.r:SetAlpha(1)
self.r.timer = STAY_TIME
return
end
self.r:SetAnchor('BOTTOM', region,'TOP')
self.r.region = region
self.r:SetWidth(10)
self.r:SetHeight(10)
self.r.sizeChangeSpeed = 15
self.r:SetAlpha(1)
self.r.tl:SetLabel(text)
self.r.timer = STAY_TIME
self.r:Handle("OnUpdate", bubbleUpdate)
self.r:EnableInput(true)
self.r:MoveToTop()
self.r:Show()
end
function bubbleView:Dismiss()
if self.r:IsVisible() then
self.r:EnableInput(false)
self.r.timer = 0
self.r:Handle("OnUpdate", bubbleUpdate)
end
end
function bubbleUpdate(self, e)
-- FIXME add spring physics
if self:Height() < self.h then
local curH = self:Height()
local curW = self:Width()
curH = curH + e*(self.h-curH)*self.sizeChangeSpeed
curW = curW + e*(self.w-curW)*self.sizeChangeSpeed
self:SetHeight(curH)
self:SetWidth(curW)
self.tl:SetHorizontalAlign("JUSTIFY")
self.tl:SetVerticalAlign("MIDDLE")
end
if self.timer > 0 then
self.timer = math.max(self.timer - e, 0)
return
end
if self:Alpha() > 0 then
if self:Alpha() < EPSILON then -- just set if it's close enough
self:SetAlpha(0)
self:Hide()
self:EnableInput(false)
self:Handle("OnUpdate", nil)
else
self:SetAlpha(self:Alpha() - self:Alpha() * e/FADEINTIME)
if self:Alpha()< 0.4 then
self:EnableInput(false)
end
end
end
end
function bubbleView:OnTouchDown()
-- if self:IsVisible() then
-- self:SetAlpha(1)
-- self.timer = STAY_TIME
--
-- cmdlist = {{'Move',nil, nil},
-- {'Touch', nil, nil},
-- {'More...', nil, nil}}
-- menu = loadGestureMenu(cmdlist, 'select events')
-- menu:present(self:Center())
--
-- end
end
function bubbleView:OnTouchUp()
if self:IsVisible() and self.o.showMenu then
self:SetAlpha(1)
self.timer = STAY_TIME
if self.region.canBeMoved then
cmdname = 'Restrict Movement'
else
cmdname = 'Free Movement'
end
cmdlist = {{cmdname, toggleMoveRetriction, self.region},
{'Remove from group', self.region.RemoveFromGroup, self.region},
{'Cancel', nil, nil}}
menu = loadSimpleMenu(cmdlist, 'Restrict '..self.region:Name()..' within group?')
menu:present(self:Center())
end
end
function toggleMoveRetriction(r)
menu:dismiss()
-- menu=nil
if r~= nil then
r:ToggleMovement()
r:SetAnchor('CENTER', r.group.r, 'CENTER', 0, 0)
end
end