-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToolbar.lua
More file actions
77 lines (61 loc) · 1.73 KB
/
Toolbar.lua
File metadata and controls
77 lines (61 loc) · 1.73 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
-- Toolbar.lua
local globalData = require 'globalData'
local Tappy = require 'Tappy'
local Util = require 'Util'
local Tappies = {
{element='shuffle', label='Sh', subtitle='SHUFFLE', command=function() globalData.grid:shuffle() end},
{element='hint', label='Hi', subtitle='HINT', command=function() globalData.grid:hint() end},
{element='undo', label='Un', subtitle='UNDO', command=function() globalData.grid:undo() end},
{element='result', label='Wo', subtitle='WORDS', command=function() globalData.grid:showFoundWords() end},
}
local Toolbar = {}
Toolbar.__index = Toolbar
function Toolbar.new()
local o = {}
-- assert(self==Toolbar)
setmetatable(o, Toolbar)
local dim = globalData.dim
o.rect = display.newRect(globalData.uiGroup, dim.toolbarX, dim.toolbarY, dim.toolbarWidth, dim.toolbarHeight)
o.rect:setFillColor(0.1,0.1,0.1)
o.rect.alpha = 0.1
for i=1,#Tappies do
local tp = Tappies[i]
o[tp.element] = Tappy.new({
parent = globalData.uiGroup,
x = Util.mapValue(i, 1, #Tappies, dim.halfQ, display.actualContentWidth - dim.halfQ),
y = dim.toolbarY,
command = tp.command,
text = tp.label,
description = tp.subtitle
})
end
return o
end
--[[
function Toolbar:destroy()
display.remove(self.rect)
end
]]
function Toolbar:set(tappy, s)
if self[tappy] then
self[tappy]:setLabel(s)
end
end
function Toolbar:enable(tappy, enabled)
if self[tappy] then
self[tappy]:enable(enabled)
end
end
function Toolbar:suspendTouch()
for i=1,#Tappies do
local tp = Tappies[i]
self[tp.element]:removeTouchListener()
end
end
function Toolbar:resumeTouch()
for i=1,#Tappies do
local tp = Tappies[i]
self[tp.element]:addTouchListener()
end
end
return Toolbar