-
Notifications
You must be signed in to change notification settings - Fork 0
/
Statusbar.lua
116 lines (97 loc) · 3.21 KB
/
Statusbar.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
-- Statusbar.lua
local composer = require 'composer'
local widget = require 'widget'
local const = require 'constants'
local globalData = require 'globalData'
local Util = require 'Util'
local Statusbar = {}
Statusbar.__index = Statusbar
function Statusbar.new()
local o = {}
setmetatable(o, Statusbar)
local dim = globalData.dim
local fontSize = dim.Q / 3
local halfFontSize = fontSize / 2
o.rect = display.newRect(globalData.uiGroup, dim.statusbarX, dim.statusbarY, dim.statusbarWidth, dim.statusbarHeight)
o.rect:setFillColor(unpack(const.COLORS.uibackground))
-- o.left = display.newText(globalData.uiGroup, '🦝', halfFontSize, dim.statusbarY, const.FONTS.ACME, fontSize)
-- o.left:setFillColor(unpack(const.COLORS.uiforeground))
-- o.left.anchorX = 0
o.left = widget.newButton({
x = halfFontSize,
y = dim.statusbarY,
onRelease = function()
Util.sound('ui')
if #globalData.grid.humanFoundWords == 0 then
globalData.grid:cancelGame()
composer.gotoScene('ModeMenu', {effect='slideRight'})
else
Util.showAlert('Are you sure', 'Abandon this game?', {'Yes','No'}, function(event)
if event.index == 1 then
globalData.grid:cancelGame()
composer.gotoScene('ModeMenu', {effect='slideRight'})
end
end)
end
end,
label = '☰',
labelColor = { default=globalData.colorTile, over=globalData.colorSelected },
labelAlign = 'left',
font = const.FONTS.ACME,
fontSize = fontSize,
textOnly = true,
})
o.left.anchorX = 0
globalData.uiGroup:insert(o.left)
-- could maybe make this a button, tap shows FoundWords scene
-- const.FONTS.ROBOTO_BOLD didn't display raccoon glyph on phone
o.center = display.newText(globalData.uiGroup, '🦝', dim.statusbarX, dim.statusbarY, const.FONTS.ACME, fontSize)
o.center:setFillColor(unpack(const.COLORS.uiforeground))
o.center.anchorX = 0.5
o.right = display.newText(globalData.uiGroup, '🦝', dim.statusbarWidth - halfFontSize, dim.statusbarY, const.FONTS.ACME, fontSize)
o.right:setFillColor(unpack(const.COLORS.uiforeground))
o.right.anchorX = 1
-- o.right = widget.newButton({
-- x = dim.statusbarWidth - halfFontSize,
-- y = dim.statusbarY,
-- onRelease = function()
-- Util.sound('ui')
-- Public.showLeaderboard()
-- end,
-- label = '...', -- raccoon looks clunky on Chromebook '🦝'
-- labelColor = { default=const.COLORS.uiforeground, over=const.COLORS.uicontrol },
-- labelAlign = 'right',
-- font = const.FONTS.ACME,
-- fontSize = fontSize,
-- textOnly = true,
-- })
-- o.right.anchorX = 1
-- globalData.uiGroup:insert(o.right)
return o
end
--[[
function Toolbar:destroy()
display.remove(self.rect)
display.remove(self.left)
display.remove(self.center)
display.remove(self.right)
end
]]
function Statusbar:set(pos, s)
if self[pos] and self[pos].text then -- may have timed out and been deleted
self[pos].text = s or ''
end
end
function Statusbar:setLeft(s)
-- self:set('left', s)
if self.left then
self.left:setLabel(s)
end
end
function Statusbar:setCenter(s)
self:set('center', s)
end
function Statusbar:setRight(s)
self:set('right', s)
end
return Statusbar