local config = require "config" -- index of current tab local current_tab = config.initial_tab -- display working state local currently_working = true -- current start index to view requests local page_start_idx = 1 -- schedule immediate reload local immediate_reload = false local tabs = { -- to display requests and answer with an ME interface [1]=require "requests", -- to display colony work orders [2]=require "orders", } local function display() local tw,th = term.getSize() term.setCursorBlink(false) term.setBackgroundColor(colors.black) term.clear() term.setCursorPos(1,1) term.setBackgroundColor(colors.yellow) term.setTextColor(colors.black) term.clearLine() term.write(" " .. string.upper(tabs[current_tab].name) .. " ") if currently_working == false then term.setCursorPos(tw-8,1) term.write(" R ") end term.setCursorPos(tw-5,1) term.write(" ^ v ") term.setBackgroundColor(colors.black) tabs[current_tab].display(page_start_idx) if currently_working then local cx,cy = term.getCursorPos() term.setCursorPos(1,cy+2) term.setCursorBlink(true) term.setTextColor(colors.gray) term.write("Working... ") end end local function page_down(th) page_start_idx = page_start_idx+th-3 end local function page_up(th) page_start_idx = math.max(1, page_start_idx-th+3) end local function on_touch(touch_x, touch_y) local tw,th = term.getSize() if touch_y == 1 then if touch_x < (#tabs[current_tab].name + 2) then current_tab = current_tab + 1 if current_tab > #tabs then current_tab = 1 end return true elseif currently_working == false and touch_x > tw-9 and touch_x < tw-5 then -- reload button immediate_reload = true return true elseif touch_x > tw-6 and touch_x < tw-2 then page_up(th) return true elseif touch_x > tw-3 and touch_x <= tw then page_down(th) return true end elseif tabs[current_tab].on_touch(touch_x, touch_y) then return true end return false end local function wait_for(time_secs) display() local timer_id = os.startTimer(time_secs) while true do local event_data = {os.pullEvent()} if event_data[1] == "monitor_touch" or (event_data[1] == "mouse_click" and event_data[2] == 1) then if on_touch(event_data[3], event_data[4]) then display() end if immediate_reload == true then os.cancelTimer(timer_id) immediate_reload = false break end elseif event_data[1] == "timer" then if event_data[2] == timer_id then break end end end end if peripheral.isPresent(config.monitor_side) then monitor = peripheral.wrap(config.monitor_side) monitor.setTextScale(config.monitor_scale) term.redirect(monitor) end while true do currently_working = true for i, tab in pairs(tabs) do tab.fetch(wait_for) end currently_working = false wait_for(config.round_sleep_time) end