local set_timer_page = { start_time = {hours='0', minutes='10', seconds='0'}, increment = {minutes='0', seconds='10'}, } function set_timer_page_run_loop(h) local dt = love.timer.step() while true do love.event.pump() for name, a,b,c,d,e,f in love.event.poll() do if name == 'quit' then os.exit(0) end if set_timer_page[name] then set_timer_page[name](a,b,c,d,e,f) end end love.graphics.clear{0.9,0.9,0.9} set_timer_page.draw() love.graphics.present() love.timer.sleep(0.001) end end local w = utils.width('88') function numeric_input(tab, k, x,y) local w, h = w+15, love.graphics.getFont():getHeight()+10 local result = {} result.draw = function() love.graphics.setColor(0.5,0.5,0.5) love.graphics.rectangle('line', x,y, w,h) love.graphics.setColor(0.2,0.2,0.2) love.graphics.print(tab[k], x+5, y+5) if set_timer_page.focus == result then love.graphics.print('|', x+5+utils.width(tab[k]), y+5) end end local within = function(x, lo, hi) return lo <= x and x < hi end result.ispressed = function(x2,y2) return within(x2, x, x+w) and within(y2, y, y+h) end result.press = function() set_timer_page.focus = result love.keyboard.setTextInput(true) end result.keypressed = function(key) if key == 'backspace' then local len = #tab[k] tab[k] = tab[k]:sub(1, len-1) end end result.textinput = function(t) if #tab[k] < 2 then tab[k] = tab[k]..t end end return result end function submit_button(msg, x,y) local w, h = utils.width(msg)+10, love.graphics.getFont():getHeight()+10 local result = {} result.draw = function() love.graphics.setColor(0.7,0.7,0.7) love.graphics.rectangle('fill', x,y, w,h) love.graphics.setColor(0.2,0.2,0.2) love.graphics.print(msg, x+5, y+5) end local within = function(x, lo, hi) return lo <= x and x < hi end result.ispressed = function(x2,y2) return within(x2, x, x+w) and within(y2, y, y+h) end result.press = function() love.keyboard.setTextInput(false) local sh = tonumber(set_timer_page.start_time.hours) or 0 start_time = sh local sm = tonumber(set_timer_page.start_time.minutes) or 2 start_time = start_time*60 + sm local ss = tonumber(set_timer_page.start_time.seconds) or 0 start_time = start_time*60 + ss time = {white=start_time, black=start_time} local im = tonumber(set_timer_page.increment.minutes) or 0 increment = im local is = tonumber(set_timer_page.increment.seconds) or 0 increment = increment*60 + is draw_board_and_run_loop(play_game) end return result end local msg1, msg2 = 'start time', 'increment' local x = 30 + utils.width(msg1) + 10 local x2 = x + (w+15)*3 + 10 + utils.width(msg2) + 10 local set_timer_widgets = { hours = numeric_input(set_timer_page.start_time, 'hours', x, 30), minutes = numeric_input(set_timer_page.start_time, 'minutes', x+w+15, 30), seconds = numeric_input(set_timer_page.start_time, 'seconds', x+w+15+w+15, 30), increment_minutes = numeric_input(set_timer_page.increment, 'minutes', x2, 30), increment_seconds = numeric_input(set_timer_page.increment, 'seconds', x2+w+15, 30), submit_button = submit_button('start game', x2+w+15+w+15+10, 30), } function set_timer_page.draw() x, y = 30, 30 love.graphics.setColor(0.2,0.2,0.2) love.graphics.print(msg1, x, y+5) x = x + utils.width(msg1) + 10 + (w+15)*3 + 10 love.graphics.print(msg2, x, y+5) x = x + utils.width(msg2) + 10 for _,widget in pairs(set_timer_widgets) do widget.draw() end end function set_timer_page.mousepressed(x,y) for _,widget in pairs(set_timer_widgets) do if widget.ispressed(x,y) then widget.press() end end end function set_timer_page.keypressed(key) if set_timer_page.focus then set_timer_page.focus.keypressed(key) end end function set_timer_page.textinput(t) if set_timer_page.focus then set_timer_page.focus.textinput(t) end end set_timer_page_run_loop()