2024-05-31 23:37:49 +00:00
|
|
|
local config = require "config"
|
2024-05-31 23:12:12 +00:00
|
|
|
|
2024-06-01 02:39:41 +00:00
|
|
|
-- index of current tab
|
2024-05-31 23:37:49 +00:00
|
|
|
local current_tab = config.initial_tab
|
2024-05-31 23:12:12 +00:00
|
|
|
-- 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
|
2024-06-01 02:39:41 +00:00
|
|
|
[1]=require "requests",
|
2024-05-31 23:12:12 +00:00
|
|
|
-- to display colony work orders
|
2024-06-01 02:39:41 +00:00
|
|
|
[2]=require "orders",
|
2024-05-31 23:12:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-06-01 02:39:41 +00:00
|
|
|
local function display()
|
2024-05-31 23:12:12 +00:00
|
|
|
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)
|
|
|
|
|
2024-06-01 02:39:41 +00:00
|
|
|
tabs[current_tab].display(page_start_idx)
|
2024-05-31 23:12:12 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2024-06-01 02:39:41 +00:00
|
|
|
local function page_down(th)
|
2024-05-31 23:12:12 +00:00
|
|
|
page_start_idx = page_start_idx+th-3
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2024-06-01 02:39:41 +00:00
|
|
|
local function page_up(th)
|
2024-05-31 23:12:12 +00:00
|
|
|
page_start_idx = math.max(1, page_start_idx-th+3)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2024-06-01 02:39:41 +00:00
|
|
|
local function on_touch(touch_x, touch_y)
|
2024-05-31 23:12:12 +00:00
|
|
|
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
|
2024-06-01 02:39:41 +00:00
|
|
|
-- reload button
|
2024-05-31 23:12:12 +00:00
|
|
|
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
|
2024-06-01 02:39:41 +00:00
|
|
|
elseif tabs[current_tab].on_touch(touch_x, touch_y) then
|
2024-05-31 23:12:12 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2024-06-01 02:39:41 +00:00
|
|
|
local function wait_for(time_secs)
|
2024-05-31 23:12:12 +00:00
|
|
|
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
|
2024-06-01 02:39:41 +00:00
|
|
|
os.cancelTimer(timer_id)
|
2024-05-31 23:12:12 +00:00
|
|
|
immediate_reload = false
|
|
|
|
break
|
|
|
|
end
|
|
|
|
elseif event_data[1] == "timer" then
|
|
|
|
if event_data[2] == timer_id then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2024-05-31 23:37:49 +00:00
|
|
|
if peripheral.isPresent(config.monitor_side) then
|
|
|
|
monitor = peripheral.wrap(config.monitor_side)
|
|
|
|
monitor.setTextScale(config.monitor_scale)
|
2024-05-31 23:12:12 +00:00
|
|
|
term.redirect(monitor)
|
|
|
|
end
|
|
|
|
|
|
|
|
while true do
|
|
|
|
currently_working = true
|
2024-06-01 02:39:41 +00:00
|
|
|
for i, tab in pairs(tabs) do
|
|
|
|
tab.fetch(wait_for)
|
|
|
|
end
|
2024-05-31 23:12:12 +00:00
|
|
|
currently_working = false
|
2024-05-31 23:37:49 +00:00
|
|
|
wait_for(config.round_sleep_time)
|
2024-05-31 23:12:12 +00:00
|
|
|
end
|