Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local button = require "button"
- local rect = require "rectangle"
- local component = require "component"
- local event = require "event"
- local ser = require "serialization"
- local unicode = require "unicode"
- local gpu = component.gpu
- local gameTimer = nil
- -- КОСТЫЛИ, НЕ ТРОГАТЬ --
- local update = nil
- local selectCategories = nil
- local drawStatistics = nil
- local drawTop = nil
- local xui = nil
- local xui2 = nil
- -- Автоматический сброс цветов при завершении программы --
- local exitListener = {}
- setmetatable(exitListener, {__gc = function()
- gpu.setBackground( 0x000000 )
- gpu.setForeground( 0xffffff )
- if (gameTimer) then event.cancel(gameTimer) end
- event.ignore("touch", xui)
- event.ignore("scroll", xui2)
- button.stop()
- package.loaded["button"] = nil
- package.loaded["rectangle"] = nil
- end})
- -- КОНСТАНТЫ --
- local bgColor = 0xffffff
- local fgColor = 0x000000
- local questionsFilepath = "questions.txt"
- local screenWidth, screenHeight = gpu.getResolution()
- local centerScreenX, centerScreenY = math.floor(screenWidth/2), math.floor(screenHeight/2)
- -- Информация о кнопках --
- local buttonMinWidth, buttonHeight = 10, 3
- local buttonMarginX, buttonMarginY = 1, 1
- local buttonsPosX, buttonsPosY = 0, 0
- local summaryButtonsWidth = 0
- local statistics, questions, buttons = nil
- local currentPlayer = nil
- local currentCategory = "Мемология"
- local currentQuestionId = 1
- local firstRun = true
- -- РАЗНОЕ --
- local function swap(array, index1, index2)
- array[index1], array[index2] = array[index2], array[index1]
- end
- local function shake(array)
- local counter = #array
- while counter > 1 do
- local index = math.random(counter)
- swap(array, index, counter)
- counter = counter - 1
- end
- end
- local function tableLen( array )
- local length = 0
- for _, _ in pairs(array) do
- length = length + 1
- end
- return length
- end
- local function shakeCategories(questions)
- for _, category in ipairs(questions) do
- shake(category)
- end
- end
- local function addMetaToCategoriesAndShake(questions)
- for name, category in pairs(questions) do
- -- Перемешать массив с вопросами--
- shake(category)
- -- Мета-информация --
- category.countQuestions = #category
- category.name = name
- end
- end
- -- КНОПКИ --
- --Данные о внешнем виде кнопок
- local buttonDesign_categories = {
- blink_time = 0.2,
- -- Вид кнопки в обычном состоянии --
- [0] = {
- bg = 0xBF2008,
- fg = 0xffffff,
- char = ' '
- },
- -- Вид кнопки в состоянии "недоступна" --
- [5] = {
- bg = 0xFF9696,
- fg = 0xffffff,
- char = ' '
- },
- -- Подсветка кнопки --
- [10] = {
- bg = 0xff0000,
- fg = 0xffffff,
- char = ' '
- }
- }
- local buttonDesign_incorrect = {
- blink_time = 0.2,
- -- Вид кнопки в обычном состоянии --
- [0] = {
- bg = 0xCCCCCC,
- fg = 0xffffff,
- char = ' '
- },
- -- Вид кнопки в состоянии "недоступна" --
- [5] = {
- bg = 0xffffff,
- fg = 0x000000,
- char = ' '
- },
- -- Подсветка кнопки --
- [10] = {
- bg = 0xBF2008,
- fg = 0xffffff,
- char = ' '
- }
- }
- local buttonDesign_incorrect = {
- blink_time = 0.2,
- -- Вид кнопки в обычном состоянии --
- [0] = {
- bg = 0xCCCCCC,
- fg = 0xffffff,
- char = ' '
- },
- -- Вид кнопки в состоянии "недоступна" --
- [5] = {
- bg = 0xffffff,
- fg = 0x000000,
- char = ' '
- },
- -- Подсветка кнопки --
- [10] = {
- bg = 0xBF2008,
- fg = 0xffffff,
- char = ' '
- }
- }
- local buttonDesign_correct = {
- blink_time = 0.2,
- -- Вид кнопки в обычном состоянии --
- [0] = {
- bg = 0xCCCCCC,
- fg = 0xffffff,
- char = ' '
- },
- -- Вид кнопки в состоянии "недоступна" --
- [5] = {
- bg = 0xffffff,
- fg = 0x000000,
- char = ' '
- },
- -- Подсветка кнопки --
- [10] = {
- bg = 0x00911B,
- fg = 0xffffff,
- char = ' '
- }
- }
- -- xxx --
- local function saveStatistics( statistics, statisticsFilepath )
- local file = assert( io.open(statisticsFilepath, "w"), "Can't open/create the file!" )
- file:write( ser.serialize( statistics ) )
- file:close()
- end
- local function loadStatistics( statisticsFilepath )
- local statistics = nil
- local file = assert( io.open(statisticsFilepath, "r"), "File not found!" )
- statistics = assert( ser.unserialize( file:read("*a") ), "Parse statistics file failed!" )
- file:close()
- return statistics
- end
- local function findPlayerStatistic( playerName )
- for i = 1, #statistics, 1 do
- if (statistics[i].player == playerName) then
- return statistics[i], i
- end
- end
- end
- local function addPlayerToStatistics( playerName )
- if ( not findPlayerStatistic(playerName) ) then
- table.insert(statistics,
- {
- player = playerName,
- totalPlayTime = 0,
- totalCorrectAnswers = 0,
- totalIncorrectAnswers = 0,
- totalAverageResponseTime = 0,
- totalLeave = 0,
- })
- end
- end
- local function editPlayerStatistic( playerName, key, value, opertion )
- for i = 1, #statistics, 1 do
- if (statistics[i].player == playerName) then
- if ( opertion == "add" or not opertion ) then
- statistics[i][key] = statistics[i][key] + value
- elseif ( opertion == "sub" ) then
- statistics[i][key] = statistics[i][key] - value
- end
- break
- end
- end
- end
- local function timer_gameTime()
- editPlayerStatistic(currentPlayer, "totalPlayTime", 1, "add")
- end
- local function hideAnimation()
- for i=0, screenWidth-1, 1 do
- gpu.copy(1-i, buttonsPosY, screenWidth+1, buttonHeight, -1, 0)
- coroutine.yield();
- end
- end
- local function showAnimation()
- local countAnswers = #questions[currentCategory][currentQuestionId].answers
- for j=screenWidth, buttonsPosX, -1 do
- gpu.setBackground(0xffffff)
- gpu.fill(j, buttonsPosY, summaryButtonsWidth+1, buttonHeight, ' ')
- for i = 1, #buttons, 1 do
- rect.MoveNXY( buttons[i].rectangle, buttons[i].rectangle.sx-1, buttonsPosY )
- buttons[i]:redraw()
- end
- coroutine.yield();
- end
- end
- -- Реакция на ответ --
- local function callback_returnToMenu()
- event.ignore( "touch", xui )
- event.ignore("scroll", xui2)
- button.destroyAllButtons()
- if (gameTimer) then event.cancel(gameTimer) end
- saveStatistics(statistics, "statistics.txt")
- -- Очистка экрана для следующего вывода --
- gpu.setBackground(bgColor)
- gpu.setForeground(fgColor)
- gpu.fill(1, 1, screenWidth, screenHeight, ' ')
- selectCategories(questions)
- firstRun = true
- end
- local function callback_runShoolTest(btn, catname)
- currentPlayer = btn.pressedPlayer
- addPlayerToStatistics(currentPlayer)
- gameTimer = event.timer(1, timer_gameTime, math.huge)
- currentCategory = catname
- currentQuestionId = 1
- button.destroyAllButtons()
- update( questions )
- firstRun = false
- end
- local function incorrectAnswer()
- editPlayerStatistic(currentPlayer, "totalIncorrectAnswers", 1, "add")
- end
- local function correctAnswer()
- editPlayerStatistic(currentPlayer, "totalCorrectAnswers", 1, "add")
- if ( currentQuestionId < questions[currentCategory].countQuestions) then
- currentQuestionId = currentQuestionId + 1
- else
- shakeCategories(questions)
- callback_returnToMenu()
- return nil
- end
- update(questions)
- end
- -- РАБОТА С МАССИВОМ ВОПРОСОВ --
- -- Получение массива вопросов из файла --
- local function readQuestions( filename )
- local questions = nil
- local file = assert( io.open(filename, "r"), "File not found!" )
- questions = assert( ser.unserialize( file:read("*a") ), "Parse questions file failed!" )
- file:close()
- -- Перемешать вопросы и добавить мета-информацию --
- addMetaToCategoriesAndShake(questions)
- return questions
- end
- local function repositionButtons( buttons )
- summaryButtonsWidth = 0
- -- Инициализировать кнопки --
- for i = 1, #buttons, 1 do
- buttons[i]:recalculateWidth( buttonMinWidth )
- summaryButtonsWidth = summaryButtonsWidth + buttons[i].rectangle.width + buttonMarginX
- end
- -- Рассчитать позиции кнопок --
- buttonsPosX = centerScreenX - math.floor(summaryButtonsWidth/2)
- buttonsPosY = centerScreenY - math.floor(buttonHeight/2) + buttonHeight - 2
- local currentButtonPosX = ( not firstRun ) and screenWidth or buttonsPosX
- for i = 1, #buttons, 1 do
- rect.MoveNXY( buttons[i].rectangle, currentButtonPosX, buttonsPosY )
- currentButtonPosX = currentButtonPosX + buttons[i].rectangle.width + buttonMarginX
- end
- end
- local function initButtons( questions )
- local buttons = {}
- local countAnswers = #questions[currentCategory][currentQuestionId].answers
- local currentQuestion = questions[currentCategory][currentQuestionId]
- -- Инициализировать кнопки --
- button.destroyAllButtons()
- for i = 1, countAnswers, 1 do
- local currentAction = (currentQuestion.correctAnswer == i) and correctAnswer or incorrectAnswer
- local currentDesign = (currentQuestion.correctAnswer == i) and buttonDesign_correct or buttonDesign_incorrect
- buttons[i] = button.createRubber( 1, 1, buttonMinWidth, buttonHeight, {currentQuestion.answers[i]}, currentAction, currentDesign )
- end
- repositionButtons( buttons )
- return buttons
- end
- -- XXX --
- local function drawProgressBar(currentValue, totalValue, xPos, yPos, width, progressColor, backgroundColor, char, notcenter)
- -- Отлов исключительных ситуаций --
- currentValue = (currentValue > totalValue) and totalValue or currentValue
- -- Вычисление текущего прогресса --
- local progress = ( width * (currentValue-1) ) / totalValue
- -- Смена точки привязки от начала к центру прогресс-бара --
- local centerPosX = xPos - math.floor(width/2)
- -- Отрисовка подложки --
- gpu.setForeground(backgroundColor)
- gpu.fill( notcenter and xPos or centerPosX, yPos, width, 1, char )
- -- Отрисовка прогресса --
- gpu.setForeground(progressColor)
- gpu.fill( notcenter and xPos or centerPosX, yPos, progress, 1, char )
- end
- local function drawDownVerticalProgressBar(currentValue, totalValue, xPos, yPos, height, progressColor, backgroundColor, char, notcenter)
- -- Отлов исключительных ситуаций --
- currentValue = (currentValue > totalValue) and totalValue or currentValue
- -- Вычисление текущего прогресса --
- local progress = ( height * (currentValue-1) ) / totalValue
- -- Смена точки привязки от начала к центру прогресс-бара --
- local centerPosY = yPos - math.floor(height/2)
- -- Отрисовка подложки --
- gpu.setForeground(backgroundColor)
- gpu.fill( xPos, notcenter and yPos or centerPosY, 1, height, char )
- -- Отрисовка прогресса --
- gpu.setForeground(progressColor)
- gpu.fill( xPos, notcenter and yPos or centerPosY, 1, progress, char )
- end
- local function drawUpVerticalProgressBar(currentValue, totalValue, xPos, yPos, height, progressColor, backgroundColor, char, notcenter)
- -- Отлов исключительных ситуаций --
- currentValue = (currentValue > totalValue) and totalValue or currentValue
- -- Вычисление текущего прогресса --
- local progress = ( height * (currentValue-1) ) / totalValue
- -- Смена точки привязки от начала к центру прогресс-бара --
- local centerPosY = yPos - math.floor(height/2)
- -- Отрисовка подложки --
- gpu.setForeground(backgroundColor)
- gpu.fill( xPos, (notcenter and yPos or centerPosY)-height, 1, height, char )
- -- Отрисовка прогресса --
- gpu.setForeground(progressColor)
- gpu.fill( xPos, (notcenter and yPos or centerPosY)-progress, 1, progress, char )
- end
- update = function(questions)
- local currentQuestion = questions[currentCategory][currentQuestionId]
- buttons = initButtons( questions )
- -- Анимации --
- local h = coroutine.create(hideAnimation)
- local s = coroutine.create(showAnimation)
- if ( not firstRun ) then
- while ( coroutine.status(h) ~= "dead" and coroutine.status(s) ~= "dead" ) do
- coroutine.resume(h)
- coroutine.resume(s)
- os.sleep(0)
- end
- end
- -- Очистка экрана для следующего вывода --
- gpu.setBackground(bgColor)
- gpu.setForeground(fgColor)
- gpu.fill(1, 1, screenWidth, screenHeight, ' ')
- -- Отрисовка всего --
- for i, btn in ipairs(buttons) do
- btn:redraw()
- end
- button.createXYWH(screenWidth-15-2, screenHeight-4-1, 15, 4, {"↩ Вернуться", "к категориям"}, callback_returnToMenu, buttonDesign_categories):redraw()
- -- Восстановление цветов после отрисовки предыдущих элементов --
- gpu.setBackground(bgColor)
- gpu.setForeground(fgColor)
- gpu.set( centerScreenX - math.floor(unicode.len(currentQuestion.question)/2), centerScreenY-2, currentQuestion.question )
- drawProgressBar(currentQuestionId, questions[currentCategory].countQuestions, centerScreenX, centerScreenY+8, screenWidth/1.2, 0xBF2008, 0xCCCCCC, '▂')
- end
- local function callback_drawStat(btn)
- currentPlayer = btn.pressedPlayer
- addPlayerToStatistics(currentPlayer)
- drawStatistics(statistics)
- end
- selectCategories = function(questions)
- local countOfCategories = tableLen(questions)
- local startDrawButtonsX = 8
- local startDrawButtonsY = 4
- local buttonMarginX = 2
- local buttonMarginY = 1
- local buttonWidth = 20
- local buttonHeight = 3
- local maxButtonsInRow = math.ceil( (screenWidth - startDrawButtonsX*2) / (buttonWidth + buttonMarginX) )
- local maxButtonsInColumn = math.ceil( (screenHeight - startDrawButtonsY*2) / (buttonHeight + buttonMarginY) )
- local statButton = button.createXYWH( screenWidth-centerScreenX+9, screenHeight-3, centerScreenX-10, 3, {"Общая статистика"}, callback_drawStat, buttonDesign_categories )
- local topButton = button.createXYWH( 3, screenHeight-3, centerScreenX-10, 3, {"Топ игроков"}, drawTop, buttonDesign_categories )
- local pages = math.ceil( countOfCategories/(maxButtonsInRow*maxButtonsInColumn) )
- --local buttonsInEndRow = countOfCategories % maxButtonsInRow
- --local rowCount = (buttonsInEndRow > 0) and math.floor(countOfCategories/2)+1 or math.floor(countOfCategories/2)
- local summaryButtonsWidth = (buttonWidth+buttonMarginX) * maxButtonsInRow
- local summaryButtonsHeight = (buttonWidth+buttonMarginX) * maxButtonsInColumn
- local text1 = "Пожайлуста, выберите одну любую категорию вопросов из предложенных ниже."
- gpu.set( centerScreenX - math.floor(unicode.len(text1)/2), 2, text1 )
- local buttons = {}
- local i, j = 1, 1
- for _, category in pairs(questions) do
- buttons[i] = button.createXYWH( startDrawButtonsX+(buttonWidth+1)*(i-1), startDrawButtonsY+(buttonHeight+1)*(j-1), buttonWidth, buttonHeight, {category.name}, callback_runShoolTest, buttonDesign_categories )
- buttons[i].args = category.name
- buttons[i]:redraw()
- i = (i % maxButtonsInRow) + 1
- j = (i == 1) and j+1 or j
- end
- statButton:redraw()
- topButton:redraw()
- end
- local playersInOnePage = 4
- local currentPage = 1
- local function callback_nextStatisticsPage()
- currentPage = currentPage + playersInOnePage
- drawStatistics(statistics)
- end
- local function callback_prevStatisticsPage()
- currentPage = currentPage - playersInOnePage
- drawStatistics(statistics)
- end
- drawStatistics = function(statistics)
- button.destroyAllButtons()
- gpu.setForeground(0)
- gpu.setBackground(0xFFFFFF)
- gpu.fill(1, 1, screenWidth, screenHeight, ' ')
- local nextListButton = button.createXYWH( screenWidth-centerScreenX+9, screenHeight-3, centerScreenX-10, 3, {"Следующий лист ►"}, callback_nextStatisticsPage, buttonDesign_categories, (currentPage >= #statistics-playersInOnePage+1) and 5 or 0 )
- local prevListButton = button.createXYWH( 3, screenHeight-3, centerScreenX-10, 3, {"◄ Предыдущий лист"}, callback_prevStatisticsPage, buttonDesign_categories, (currentPage <= 1) and 5 or 0 )
- local returnToMenu = button.createXYWH( centerScreenX-5, screenHeight-3, 12, 3, {"↩"}, callback_returnToMenu, buttonDesign_categories )
- gpu.setForeground(0)
- gpu.setBackground(0xffffff)
- local plr, iplr = findPlayerStatistic(currentPlayer)
- if ( plr and plr ~= statistics[1] ) then
- swap(statistics, 1, iplr)
- end
- local players = #statistics
- local columnMargin = 1
- local columnWidth = math.floor(screenWidth/playersInOnePage)
- local centerColumn = math.floor(columnWidth/2)
- for i = currentPage, currentPage+playersInOnePage, 1 do
- local bgcolor = (i%2 == 0) and 0xEEEEEE or 0xFFFFFF
- local centerText = math.floor(unicode.len(statistics[i].player)/2)
- gpu.setBackground(bgcolor)
- if ( i%2 == 0 ) then
- gpu.fill(1 + columnWidth * (i-currentPage), 1, columnWidth, screenHeight, ' ')
- end
- -- Отрисовать имя игрока
- gpu.set(1 + (centerColumn - centerText) + columnWidth * (i-currentPage), 2, statistics[i].player)
- centerText = math.floor(unicode.len("Отношение верных ответов к неверным:")/2)
- gpu.set(1 + (centerColumn - centerText) + columnWidth * (i-currentPage), 4,"Отношение верных ответов к неверным:")
- drawProgressBar(statistics[i].totalCorrectAnswers, statistics[i].totalIncorrectAnswers, centerColumn + columnWidth * (i-currentPage), 5, columnWidth-10, 0x7AFF93, 0xFF9696, '▄')
- gpu.setForeground(0)
- centerText = math.floor(unicode.len("Суммарное время прохождения:")/2)
- gpu.set(1 + (centerColumn - centerText) + columnWidth * (i-currentPage), 9, "Суммарное время прохождения:")
- drawProgressBar(statistics[i].totalPlayTime, columnWidth-10, centerColumn + columnWidth * (i-currentPage), 10, columnWidth-10, 0xFF9696, 0xCCCCCC, '▄')
- gpu.setForeground(0)
- centerText = math.floor(unicode.len("Количество прерываний теста:")/2)
- gpu.set(1 + (centerColumn - centerText) + columnWidth * (i-currentPage), 12, "Количество прерываний теста:")
- drawProgressBar(statistics[i].totalLeave, columnWidth-10, centerColumn + columnWidth * (i-currentPage), 13, columnWidth-10, 0xFF9696, 0xCCCCCC, '▄')
- gpu.setForeground(0)
- nextListButton:redraw()
- prevListButton:redraw()
- returnToMenu:redraw()
- gpu.setForeground(0)
- end
- end
- local function fixedString(str, len, char)
- if (#str < len) then
- return string.rep(char, len-#str) .. str
- end
- return str
- end
- local curpage = 1
- local prevSelected = nil
- local selected = 1
- local function callback_nextTopPage()
- local maxPlayerInOnePage = math.floor( (screenHeight-7)/3 )
- curpage = curpage + maxPlayerInOnePage
- selected = curpage
- prevSelected = curpage
- drawTop(true)
- end
- local function callback_prevTopPage()
- local maxPlayerInOnePage = math.floor( (screenHeight-7)/3 )
- curpage = curpage - maxPlayerInOnePage
- selected = curpage+maxPlayerInOnePage-1
- prevSelected = curpage+maxPlayerInOnePage-1
- drawTop(true)
- end
- xui = function( ... )
- local e = {...}
- if e[1] ~= "touch" then return end
- local playersInOnePage = 16
- local players = #statistics
- local maxPlayerInOnePage = math.floor( (screenHeight-7)/3 )
- for i = curpage, math.min(curpage+maxPlayerInOnePage-1, #statistics), 1 do
- if (rect.PointInRectFree(e[3], e[4], 1, 1+3+3*(i-curpage), screenWidth, 3+3+3*(i-curpage))) then
- if ( selected == i ) then
- event.ignore( "touch", xui )
- event.ignore("scroll", xui2)
- drawStatistics(statistics)
- break
- end
- prevSelected = selected
- selected = i
- drawTop()
- break
- end
- end
- end
- xui2 = function( ... )
- local e = {...}
- if e[1] ~= "scroll" then return end
- local playersInOnePage = 16
- local players = #statistics
- local maxPlayerInOnePage = math.floor( (screenHeight-7)/3 )
- if ( selected - e[5] > math.min(curpage+maxPlayerInOnePage-1, #statistics) ) then
- if ( math.min(curpage+maxPlayerInOnePage-1, #statistics) < #statistics ) then
- callback_nextTopPage()
- else
- selected = math.min(curpage+maxPlayerInOnePage-1, #statistics)
- end
- elseif ( selected - e[5] < curpage ) then
- if ( curpage > 1 ) then
- callback_prevTopPage()
- else
- selected = curpage
- end
- else
- prevSelected = selected
- selected = selected - e[5]
- end
- drawTop()
- end
- drawTop = function( redraw )
- if ( prevSelected and not redraw) then
- local i = prevSelected
- local bgcolor = (i%2 == 0) and 0xEEEEEE or 0xFFFFFF
- local bgcolorn = (i%2 == 0) and 0x5E5E5E or 0x424242
- gpu.setForeground(0xffffff)
- gpu.setBackground(bgcolor)
- gpu.fill(1, 1+3+3*(i-curpage), screenWidth, 3, ' ')
- gpu.setBackground(bgcolorn)
- gpu.fill(1, 1+3+3*(i-curpage), 6, 3, ' ')
- gpu.set(3, 2+3+3*(i-curpage), fixedString(tostring(i), 2, '0'))
- gpu.setBackground(bgcolor)
- gpu.setForeground(0)
- gpu.set(9, 2+3+3*(i-curpage), statistics[i].player)
- gpu.set(39, 2+3+3*(i-curpage), tostring(statistics[i].totalPlayTime))
- gpu.set(59, 2+3+3*(i-curpage), tostring(statistics[i].totalCorrectAnswers))
- gpu.set(79, 2+3+3*(i-curpage), tostring(statistics[i].totalIncorrectAnswers))
- i = selected
- bgcolor = 0xFF9696
- bgcolorn = 0xBF2008
- gpu.setForeground(0xffffff)
- gpu.setBackground(bgcolor)
- gpu.fill(1, 1+3+3*(i-curpage), screenWidth, 3, ' ')
- gpu.setBackground(bgcolorn)
- gpu.fill(1, 1+3+3*(i-curpage), 6, 3, ' ')
- gpu.set(3, 2+3+3*(i-curpage), fixedString(tostring(i), 2, '0'))
- gpu.setBackground(bgcolor)
- gpu.setForeground(0x424242)
- gpu.set(9, 2+3+3*(i-curpage), statistics[i].player)
- gpu.set(39, 2+3+3*(i-curpage), tostring(statistics[i].totalPlayTime))
- gpu.set(59, 2+3+3*(i-curpage), tostring(statistics[i].totalCorrectAnswers))
- gpu.set(79, 2+3+3*(i-curpage), tostring(statistics[i].totalIncorrectAnswers))
- return nil
- end
- button.destroyAllButtons()
- event.ignore( "touch", xui )
- event.ignore( "scroll", xui2 )
- event.listen( "touch", xui )
- event.listen( "scroll", xui2 )
- local playersInOnePage = 16
- local players = #statistics
- local maxPlayerInOnePage = math.floor( (screenHeight-7)/3 )
- local nextListButton = button.createXYWH( screenWidth-centerScreenX+9, screenHeight-3, centerScreenX-10, 3, {"Вниз ▼"}, callback_nextTopPage, buttonDesign_categories, (curpage >= #statistics-maxPlayerInOnePage+1) and 5 or 0 )
- local prevListButton = button.createXYWH( 3, screenHeight-3, centerScreenX-10, 3, {"▲ вверх"}, callback_prevTopPage, buttonDesign_categories, (curpage <= 1) and 5 or 0 )
- local returnToMenu = button.createXYWH( centerScreenX-5, screenHeight-3, 12, 3, {"↩"}, callback_returnToMenu, buttonDesign_categories )
- gpu.setBackground(0xFFFFFF)
- gpu.setForeground(0x000000)
- gpu.fill(1, 1, screenWidth, screenHeight, ' ')
- nextListButton:redraw()
- prevListButton:redraw()
- returnToMenu:redraw()
- -- Отрисовать заголовок --
- gpu.setForeground(0xFFFFFF)
- gpu.setBackground(0x5E5E5E)
- gpu.fill(1, 1, 6, 3, ' ')
- gpu.set(3, 2, '№')
- gpu.setBackground(0x424242)
- gpu.fill(7, 1, screenWidth, 3, ' ')
- gpu.set(9, 2, 'Никнейм')
- gpu.set(39, 2, 'Время игры')
- gpu.set(59, 2, 'Верных ответов')
- gpu.set(79, 2, 'Неверных ответов')
- for i = curpage, math.min(curpage+maxPlayerInOnePage-1, #statistics), 1 do
- local bgcolor = (i%2 == 0) and 0xEEEEEE or 0xFFFFFF
- local bgcolorn = (i%2 == 0) and 0x5E5E5E or 0x424242
- --button.create( 1, 1+3+3*(i-1), screenWidth, 3, {"000"}, a, buttonDesign_incorrect, 0, 5 ):redraw()
- if (i == selected) then
- bgcolor = 0xFF9696
- bgcolorn = 0xBF2008
- end
- gpu.setForeground(0xffffff)
- gpu.setBackground(bgcolor)
- gpu.fill(1, 1+3+3*(i-curpage), screenWidth, 3, ' ')
- gpu.setBackground(bgcolorn)
- gpu.fill(1, 1+3+3*(i-curpage), 6, 3, ' ')
- gpu.set(3, 2+3+3*(i-curpage), fixedString(tostring(i), 2, '0'))
- gpu.setBackground(bgcolor)
- gpu.setForeground(0x424242)
- gpu.set(9, 2+3+3*(i-curpage), statistics[i].player)
- gpu.set(39, 2+3+3*(i-curpage), tostring(statistics[i].totalPlayTime))
- gpu.set(59, 2+3+3*(i-curpage), tostring(statistics[i].totalCorrectAnswers))
- gpu.set(79, 2+3+3*(i-curpage), tostring(statistics[i].totalIncorrectAnswers))
- end
- end
- -- ИНИЦИАЛИЗАЦИЯ --
- gpu.setBackground(bgColor)
- gpu.setForeground(fgColor)
- gpu.fill(1, 1, screenWidth, screenHeight, ' ')
- questions = readQuestions( questionsFilepath )
- statistics = loadStatistics( "statistics.txt" )
- drawTop()
- --drawStatistics( statistics )
- --selectCategories(questions)
- --update(questions)
- button.start()
- -- Цикл-заглушка, чтобы прога сразу не завершалась --
- while (true) do
- os.sleep(100)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement