implemented daily double, adding/removing players, fixed font sizes, completed multiple choice
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
local label
|
||||
local imageHolder
|
||||
local imageHolder2
|
||||
local plusLabel
|
||||
|
||||
local function index(window, q, callback)
|
||||
frame = window:newFrame(0,0,0,-200,0,.2,1,.8)
|
||||
frame.visibility = 0
|
||||
label = window:newTextLabel(" " ..q.title.. " ",0,0,0,0,0,0,1,.2)
|
||||
label.align = ALIGN_CENTER
|
||||
label.textColor = color.white
|
||||
label.color = color.new("#060ce9")
|
||||
label.borderColor = color.new("#060ce9")
|
||||
|
||||
if not q.imageA or q.imageA == "" then
|
||||
error("Missing 'imageA' field for question!")
|
||||
end
|
||||
|
||||
if not q.imageB or q.imageB == "" then
|
||||
error("Missing 'imageB' field for question!")
|
||||
end
|
||||
|
||||
-- Left image: takes up 0.0 to 0.42 of width
|
||||
imageHolder = frame:newImageLabel(q.imageA)
|
||||
imageHolder:setAspectSize(imageHolder.imageWidth, imageHolder.imageHeight)
|
||||
imageHolder:setDualDim(0, 0, 0, 0, 0, 0, .4, 1)
|
||||
|
||||
-- Plus sign: centered between images at 0.42 to 0.58
|
||||
plusLabel = frame:newImageLabel("assets/plus.png", 0, 0, 0, 0, .4125, .4, .175)
|
||||
plusLabel.square = "w"
|
||||
plusLabel.align = ALIGN_CENTER
|
||||
plusLabel.textColor = color.white
|
||||
-- plusLabel.visibility=0
|
||||
|
||||
-- Right image: takes up 0.58 to 1.0 of width
|
||||
imageHolder2 = frame:newImageLabel(q.imageB)
|
||||
imageHolder2:setAspectSize(imageHolder2.imageWidth, imageHolder2.imageHeight)
|
||||
imageHolder2:setDualDim(0, 0, 0, 0, .6, 0, .4, 1)
|
||||
|
||||
local correct = window:newTextButton("Correct",0,-200,0,100,0,1,.5)
|
||||
correct.color = color.new("#52b11b")
|
||||
local wrong = window:newTextButton("Wrong",0,-200,0,100,.5,1,.5)
|
||||
wrong.color = color.new("#bd2626")
|
||||
local skip = window:newTextButton("Skip",0,-100,0,100,.25,1,.5)
|
||||
skip.color = color.new("#5d5d5d")
|
||||
|
||||
window.apply({
|
||||
centerY = {true},
|
||||
}, imageHolder, plusLabel, imageHolder2)
|
||||
|
||||
window.apply({
|
||||
fitFont={},
|
||||
align=window.ALIGN_CENTER,
|
||||
OnReleased=function(self)
|
||||
if self.text == "Skip" then
|
||||
callback()
|
||||
return
|
||||
end
|
||||
callback(self.text == "Correct")
|
||||
end,
|
||||
}, correct, wrong, skip)
|
||||
end
|
||||
|
||||
local function update(dt)
|
||||
label:fitFont()
|
||||
end
|
||||
|
||||
return {
|
||||
index = index,
|
||||
update = update
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
--[[ Constants
|
||||
* (all lua builtins that don't allow io/executing code)
|
||||
color (interface)
|
||||
gui (interface)
|
||||
multi (interface bound to a processor) no thread module
|
||||
|
||||
callback true/false confirm/wrong
|
||||
]]
|
||||
local label
|
||||
|
||||
local function noOf(sx,sy,sw,sh)
|
||||
return 0,0,0,0,sx,sy,sw,sh
|
||||
end
|
||||
|
||||
local choiceList = {}
|
||||
local allBoxes = {}
|
||||
local confirm
|
||||
local selected
|
||||
|
||||
local function index(window, q, callback)
|
||||
label = window:newTextLabel(" " ..q.title.. " ",noOf(0,0,1,.3))
|
||||
label.align = ALIGN_CENTER
|
||||
label.textColor = color.white
|
||||
label.color = color.new("#060ce9")
|
||||
label:setFont(50)
|
||||
choices = window:newFrame(noOf(0,.3,1,.7))
|
||||
choices.color = color.new("#060ce9")
|
||||
|
||||
function choices:newChoice(choice, i)
|
||||
local c = choices:newFrame(noOf(.25,(i-1)/#q.choices,.5,1/#q.choices))
|
||||
c.visibility = 0
|
||||
local box = c:newImageButton("assets/unchecked.png",noOf(.024*(#q.choices/4),.1,0,.8))
|
||||
box.checked = false
|
||||
box:OnReleased(function()
|
||||
if box.checked then
|
||||
box:setImage("assets/unchecked.png")
|
||||
else
|
||||
for _, other in pairs(allBoxes) do
|
||||
other.checked = false
|
||||
other:setImage("assets/unchecked.png")
|
||||
end
|
||||
box:setImage("assets/checked.png")
|
||||
selected = i
|
||||
end
|
||||
box.checked = not checked
|
||||
end)
|
||||
|
||||
box.square = "h"
|
||||
c.drawBorder = false
|
||||
local choiceText = c:newTextLabel(choice,noOf(.3,0,1,1))
|
||||
choiceText.visibility = 0
|
||||
choiceText.textColor = color.white
|
||||
-- choiceText.align = window.ALIGN_CENTER
|
||||
choiceText:setFont(40)
|
||||
table.insert(choiceList,choiceText)
|
||||
table.insert(allBoxes,box)
|
||||
|
||||
end
|
||||
|
||||
for i,choice in pairs(q.choices) do
|
||||
choices:newChoice(choice, i)
|
||||
end
|
||||
|
||||
local correct, wrong, netural = color.new("#52b11b"), color.new("#bd2626"), color.new("#5d5d5d")
|
||||
confirm = choices:newTextButton("Confirm",0,0,0,0,.01,1-(1/#q.choices),.24,.9/#q.choices)
|
||||
confirm.color = netural
|
||||
gui.apply({
|
||||
align=gui.ALIGN_CENTER,
|
||||
OnReleased=function(self)
|
||||
if selected == q.answer then
|
||||
confirm.color = correct
|
||||
timer(1,function()
|
||||
callback(true)
|
||||
end)
|
||||
else
|
||||
confirm.color = wrong
|
||||
timer(1,function()
|
||||
confirm.color = netural
|
||||
callback(false)
|
||||
end)
|
||||
end
|
||||
end,
|
||||
},confirm)
|
||||
end
|
||||
|
||||
local function update(dt) -- time in seconds that has passed since
|
||||
-- label:fitFont()
|
||||
label:centerFont()
|
||||
for _, obj in pairs(choiceList) do
|
||||
obj:centerFont()
|
||||
-- obj:fitFont(nil, nil, {scale = 2/3})
|
||||
end
|
||||
confirm:fitFont(nil, nil, {scale = 2/3})
|
||||
confirm:centerFont()
|
||||
-- print(box.parent:getAbsolutes())
|
||||
-- print(box:getAbsolutes())
|
||||
end
|
||||
|
||||
return {
|
||||
index = index,
|
||||
update = update
|
||||
}
|
||||
@@ -9,7 +9,7 @@
|
||||
local label
|
||||
|
||||
local function index(window, q, callback)
|
||||
label = window:newTextLabel(" " ..q.title.. " ")
|
||||
label = window:newTextLabel(q.title)
|
||||
label.align = ALIGN_CENTER
|
||||
label:fullFrame()
|
||||
label.textColor = color.white
|
||||
@@ -31,11 +31,11 @@ local function index(window, q, callback)
|
||||
callback(self.text == "Correct")
|
||||
end,
|
||||
},correct,wrong,skip)
|
||||
label:setFont(60)
|
||||
end
|
||||
|
||||
local function update(dt) -- time in seconds that has passed since
|
||||
-- label:centerFont()
|
||||
label:fitFont()
|
||||
label:centerFont()
|
||||
end
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user