Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function main()
- --Data that gets saved to a file.
- local legend = {
- color = {},
- pattern = {},
- name = {},
- vendor = {},
- blurb = {}
- }
- --Data that is constant, never changes.
- local m = peripheral.wrap("left") -- Monitor Controller
- local p = peripheral.wrap("right") -- Printer Controller
- local t = term.current() -- Terminal Controller
- local mx, my = m.getSize() -- Size of Monitor
- local tx, ty = t.getSize() -- Size of Terminal
- local color = {
- [0] = "White", [1] = "Orange", [2] = "Magenta", [3] = "Light Blue", [4] = "Yellow", [5] = "Lime", [6] = "Pink", [7] = "Gray",
- [8] = "Light Gray", [9] = "Cyan", [10] = "Purple", [11] = "Blue", [12] = "Brown", [13] = "Green", [14] = "Red", [15] = "Black"
- }
- local pattern = {[0] = "Solid", [1] = "Horizontal Stripe", [2] = "Vertical Stripe", [3] = "Checkerboard"}
- --Data that is variable, changes based on user input.
- local termScroll = 0
- local monScroll = 0
- local monScreen = 0
- local editing = 0
- local editMode = "nil"
- local editLegend = {
- color = {0,0},
- pattern = 0,
- name = "",
- vendor = "",
- blurb = ""
- }
- local xPos, yPos = 0, 0
- local deleting = 0
- local sel = 0
- local printerError = 0
- local pCoolDown = 10
- local coolDownTimer = os.startTimer(10)
- local helper = 0
- if fs.exists("mapLegend.sav") then -- Loads the legend data from the save file if it exists.
- local file = fs.open("mapLegend.sav","r")
- legend = textutils.unserialize(file.readAll())
- file.close()
- end
- while true do
- -- Terminal Display
- if editing > 0 then xPos, yPos = editItem(editLegend, t, color, pattern, editMode)
- else
- if helper > 0 then helpScreen(helper, t)
- else
- drawTerm(termScroll, legend, t, sel)
- if deleting > 0 and deleting-termScroll >= 1 and deleting-termScroll <= ty-1 then
- term.setCursorPos(tx-6,deleting-termScroll)
- term.blit("Delete","000000","eeeeee")
- end
- end
- end
- -- Monitor Display
- if monScreen > 0 then
- if printerError > 0 then drawPrintError(printerError, m)
- else drawSub(monScreen, legend, m, pCoolDown) end
- else drawMain(monScroll, legend, m) end
- local event = {os.pullEvent()} -- Catches system events such as timers or user input
- if event[1] == "mouse_up" and event[2] == 1 then -- Releasing left mouse click
- if editing > 0 then
- if event[4] == 2 then
- editMode = "nil"
- if event[3] == 16 then
- editLegend.color[1] = editLegend.color[1] - 1
- if editLegend.color[1] < 0 then editLegend.color[1] = 15 end
- elseif event[3] == 34 then
- editLegend.color[1] = editLegend.color[1] + 1
- if editLegend.color[1] > 15 then editLegend.color[1] = 0 end
- end
- elseif event[4] == 3 and editLegend.pattern > 0 then
- editMode = "nil"
- if event[3] == 16 then
- editLegend.color[2] = editLegend.color[2] - 1
- if editLegend.color[2] < 0 then editLegend.color[2] = 15 end
- elseif event[3] == 34 then
- editLegend.color[2] = editLegend.color[2] + 1
- if editLegend.color[2] > 15 then editLegend.color[2] = 0 end
- end
- elseif event[4] == 4 then
- editMode = "nil"
- if event[3] == 16 then
- editLegend.pattern = editLegend.pattern - 1
- if editLegend.pattern < 0 then editLegend.pattern = #pattern end
- elseif event[3] == 34 then
- editLegend.pattern = editLegend.pattern + 1
- if editLegend.pattern > #pattern then editLegend.pattern = 0 end
- end
- elseif event[4] >= 8 and event[4] <= 9 and event[3] >= 2 and event[3] <= 14 then editMode = "name"
- elseif event[4] >= 12 and event[4] <= 13 and event[3] >= 2 and event[3] <= 14 then editMode = "vendor"
- elseif event[4] >= 8 and event[4] <= 13 and event[3] >= 17 and event[3] <= 34 then editMode = "blurb"
- elseif event[4] == 15 then
- editMode = "nil"
- if event[3] >= 2 and event[3] <= 5 then legend, editing = doneEdit(legend, editLegend, editing)
- elseif event[3] >= 9 and event[3] <= 14 then
- editing = 0
- term.setCursorBlink(false)
- end
- else editMode = "nil"
- end
- else
- if not (event[3] >= tx-6 and event[3] <= tx-1 and event[4] == deleting-termScroll) then deleting = 0 end
- if helper > 0 then
- if event[3] >= 2 and event[3] <= 10 and event[4] == 11 and helper == 1 then helper = 2
- elseif event[3] >= 2 and event[3] <= 16 and event[4] == 13 and helper == 1 then helper = 3
- elseif event[3] >= 2 and event[3] <= 8 and event[4] == 15 and helper == 1 then helper = 4
- elseif event[3] >= 1 and event[3] <= 6 and event[4] == ty then
- if helper > 1 then helper = 1
- else helper = 0 end
- end
- else
- if sel > 0 then sel = 0
- else
- if event[4] < ty then
- if event[3] >= tx-11 and event[3] <= tx-8 and event[4]+termScroll <= #legend.color then
- editing = event[4]+termScroll
- editLegend = {
- color = {0,0},
- pattern = legend.pattern[editing],
- name = legend.name[editing],
- blurb = legend.blurb[editing],
- vendor = legend.vendor[editing]
- }
- editLegend.color = convertColors(legend.color[editing], editLegend.color)
- elseif event[3] >= tx-6 and event[3] <= tx-1 then
- if deleting > 0 then
- if event[4] == deleting-termScroll then
- table.remove(legend.color,deleting)
- table.remove(legend.pattern,deleting)
- table.remove(legend.name,deleting)
- table.remove(legend.vendor,deleting)
- table.remove(legend.blurb,deleting)
- saveData(legend)
- if monScreen == deleting then monScreen = 0 end
- end
- deleting = 0
- elseif event[4]+termScroll <= #legend.color then
- deleting = event[4] + termScroll
- end
- end
- else
- if event[3] >= 2 and event[3] <= 5 then
- t.clear()
- t.setCursorPos(1,1)
- m.clear()
- m.setCursorPos(1,1)
- error()
- elseif event[3] >= 7 and event[3] <= 12 then
- os.reboot()
- elseif event[3] >= math.floor(tx/2)-3 and event[3] <= math.floor(tx/2)-1 and termScroll > 0 then
- termScroll = termScroll - ty + 1
- if termScroll < 0 then termScroll = 0 end
- elseif event[3] >= math.floor(tx/2)+1 and event[3] <= math.floor(tx/2)+3 and termScroll+ty-1 < #legend.color then
- termScroll = termScroll + ty - 1
- if termScroll+ty-1 > #legend.color then termScroll = #legend.color - ty + 1 end
- elseif event[3] >= tx-11 and event[3] <= tx-8 then helper = 1
- elseif event[3] >= tx-6 and event[3] <= tx-1 then
- editing = #legend.color+1
- editLegend = {
- color = {0,0},
- pattern = 0,
- name = "",
- blurb = "",
- vendor = ""
- }
- end
- end
- end
- end
- end
- elseif event[1] == "mouse_click" and event[2] == 1 and event[3] < tx-11 and event[4] < ty then sel = event[4]+termScroll -- Pressing left mouse click
- elseif event[1] == "mouse_drag" and event[2] == 1 and event[4] < ty and editing == 0 and sel > 0 and event[4]+termScroll > 0 and event[4]+termScroll <= #legend.color then
- -- Dragging left mouse click
- if event[4]+termScroll > sel then
- table.insert(legend.color,event[4]+termScroll+1,legend.color[sel])
- table.insert(legend.pattern,event[4]+termScroll+1,legend.pattern[sel])
- table.insert(legend.name,event[4]+termScroll+1,legend.name[sel])
- table.insert(legend.vendor,event[4]+termScroll+1,legend.vendor[sel])
- table.insert(legend.blurb,event[4]+termScroll+1,legend.blurb[sel])
- table.remove(legend.color,sel)
- table.remove(legend.pattern,sel)
- table.remove(legend.name,sel)
- table.remove(legend.vendor,sel)
- table.remove(legend.blurb,sel)
- elseif event[4]+termScroll < sel then
- table.insert(legend.color,event[4]+termScroll,legend.color[sel])
- table.insert(legend.pattern,event[4]+termScroll,legend.pattern[sel])
- table.insert(legend.name,event[4]+termScroll,legend.name[sel])
- table.insert(legend.vendor,event[4]+termScroll,legend.vendor[sel])
- table.insert(legend.blurb,event[4]+termScroll,legend.blurb[sel])
- table.remove(legend.color,sel+1)
- table.remove(legend.pattern,sel+1)
- table.remove(legend.name,sel+1)
- table.remove(legend.vendor,sel+1)
- table.remove(legend.blurb,sel+1)
- end
- if monScreen > 0 then
- if monScreen > sel and monScreen <= event[4]+termScroll then monScreen = monScreen - 1
- elseif monScreen >= event[4]+termScroll and monScreen < sel then monScreen = monScreen + 1
- elseif monScreen == sel then monScreen = event[4]+termScroll end
- end
- sel = event[4]+termScroll
- saveData(legend)
- elseif event[1] == "mouse_scroll" and editing == 0 and ((event[2] == 1 and termScroll+ty-1 < #legend.color) or (event[2] == -1 and termScroll > 0)) then
- -- Scroll Wheel
- termScroll = termScroll + event[2]
- elseif event[1] == "monitor_touch" and event[2] == "left" then -- Left monitor user touch
- if monScreen > 0 then
- if printerError > 0 and event[3] >= mx-3 and event[3] <= mx and event[4] == my then printerError = 0
- else
- if event[4] == my then
- if event[3] >= 1 and event[3] <= 3 then monScreen = 0
- elseif event[3] >= 5 and event[3] <= 7 and monScreen > 1 then
- monScreen = monScreen - 1
- if monScreen < monScroll+1 then monScroll = monScroll - my + 1 end
- elseif event[3] >= 9 and event[3] <= 11 and monScreen < #legend.color then
- monScreen = monScreen + 1
- if monScreen > monScroll+my-1 then monScroll = monScroll + my - 1 end
- elseif event[3] >= mx-4 and event[3] <= mx then
- if p.getPaperLevel() == 0 then
- if p.getInkLevel() == 0 then printerError = 3
- else printerError = 1 end
- elseif p.getInkLevel() == 0 then printerError = 2
- elseif pCoolDown == 0 then
- local colorIndex = convertColors(legend.color[monScreen],{0,0})
- local colorPattern = ""
- p.newPage()
- local xSize,ySize = p.getPageSize()
- p.setPageTitle(legend.name[monScreen].." Info Sheet")
- pPrint(legend.name[monScreen].." Info Sheet",1,1,xSize,ySize,p)
- colorPattern = color[colorIndex[1] ]
- if legend.pattern[monScreen] > 0 then colorPattern = colorPattern.." & "..color[colorIndex[2] ] end
- colorPattern = colorPattern.." "..pattern[legend.pattern[monScreen]].." Roof"
- pPrint(colorPattern,1,4,xSize,ySize,p)
- p.setCursorPos(1,7)
- p.write("Vendor:")
- pPrint(legend.vendor[monScreen],1,8,xSize,ySize,p)
- p.setCursorPos(1,11)
- p.write("Description:")
- pPrint(legend.blurb[monScreen],1,12,xSize,ySize,p)
- p.endPage()
- printerError = 4
- pCoolDown = 10
- coolDownTimer = os.startTimer(10)
- end
- end
- end
- end
- else
- if event[4] < my and event[4]+monScroll <= #legend.color then monScreen = event[4] + monScroll
- elseif event[4] == my then
- if event[3] >= 5 and event[3] <= 7 and monScroll > 0 then monScroll = monScroll - my + 1
- elseif event[3] >= 9 and event[3] <= 11 and monScroll+my-1 < #legend.color then monScroll = monScroll + my -1
- end
- end
- end
- elseif event[1] == "char" and editing > 0 then -- Character input from keyboard
- if editMode == "name" and not (xPos == 14 and yPos == 9) then editLegend.name = editLegend.name..event[2]
- elseif editMode == "vendor" and not (xPos == 14 and yPos == 13) then editLegend.vendor = editLegend.vendor..event[2]
- elseif editMode == "blurb" and not (xPos == 34 and yPos == 13) then editLegend.blurb = editLegend.blurb..event[2]
- end
- elseif event[1] == "key" then -- Non-character input from keyboard
- if editing > 0 then
- if event[2] == keys.backspace then
- if editMode == "name" then editLegend.name = string.sub(editLegend.name,1,string.len(editLegend.name)-1)
- elseif editMode == "vendor" then editLegend.vendor = string.sub(editLegend.vendor,1,string.len(editLegend.vendor)-1)
- elseif editMode == "blurb" then editLegend.blurb = string.sub(editLegend.blurb,1,string.len(editLegend.blurb)-1)
- end
- elseif event[2] == keys.tab then
- if editMode == "name" then editMode = "vendor"
- elseif editMode == "vendor" then editMode = "blurb"
- elseif editMode == "blurb" then editMode = "nil"
- elseif editMode == "nil" then editMode = "name"
- end
- elseif event[2] == keys.enter then legend, editing = doneEdit(legend, editLegend, editing)
- end
- else
- if event[2] == keys.pageUp then
- termScroll = termScroll - ty + 1
- if termScroll < 0 then termScroll = 0 end
- elseif event[2] == keys.pageDown then
- termScroll = termScroll + ty - 1
- if termScroll+ty-1 > #legend.color then termScroll = #legend.color - ty + 1 end
- end
- end
- elseif event[1] == "timer" and event[2] == coolDownTimer then pCoolDown = 0 -- Printer cooldown timer
- elseif event[1] == "term_resize" or event[1] == "monitor_resize" then -- Retrieves the size of the monitor and terminal if the size of either changes
- mx, my = m.getSize()
- tx, ty = t.getSize()
- end
- end
- end
- function drawTerm(scrollPos, legend, t, sel) -- Draws the main menu on the terminal
- local oldTerm = term.redirect(t)
- local xSize, ySize = term.getSize()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- for a = 1, ySize-1 do
- term.setCursorPos(1,a)
- if a+scrollPos <= #legend.color then
- local hexCol = "f"
- if sel == a+scrollPos then
- term.setBackgroundColor(colors.blue)
- term.clearLine()
- hexCol = "b"
- else term.setBackgroundColor(colors.black) end
- drawSymbol(legend.color[a+scrollPos], legend.pattern[a+scrollPos])
- write(" "..legend.name[a+scrollPos])
- term.setCursorPos(xSize-11,a)
- term.blit("Edit Delete","fffffffffff","8888"..hexCol.."888888")
- end
- end
- term.setCursorPos(2,ySize)
- term.blit("Exit Reboot","fffffffffff","8888f888888")
- term.setCursorPos(math.floor(xSize/2)-3,ySize)
- if scrollPos == 0 then term.blit(" \30 ","888f","777f")
- else term.blit(" \30 ","ffff","888f") end
- if scrollPos+ySize-1 >= #legend.color then term.blit(" \31 ","888","777")
- else term.blit(" \31 ","fff","888") end
- term.setCursorPos(xSize-11,ySize)
- term.blit("Help New...","fffffffffff","8888f888888")
- term.redirect(oldTerm)
- end
- function editItem(legend, t, color, pattern, editMode) -- Draws the new/edit screen on the teriminal
- local oldTerm = term.redirect(t)
- local mainTerm = term.current()
- local xSize, ySize = term.getSize()
- local xPos, yPos = 0, 0
- local name = window.create(term.current(),2,8,13,2)
- local vendor = window.create(term.current(),2,12,13,2)
- local blurb = window.create(term.current(),17,8,18,6)
- term.setCursorBlink(false)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- name.setBackgroundColor(colors.white)
- name.setTextColor(colors.black)
- name.clear()
- vendor.setBackgroundColor(colors.white)
- vendor.setTextColor(colors.black)
- vendor.clear()
- blurb.setBackgroundColor(colors.white)
- blurb.setTextColor(colors.black)
- blurb.clear()
- drawPattern({2^legend.color[1], 2^legend.color[2]}, legend.pattern, 2, 2)
- for a = 1, 2 do
- if a == 1 or (a == 2 and legend.pattern > 0) then
- term.setCursorPos(7,a+1)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- write("Color "..a..": ")
- paintutils.drawLine(17, a+1, 33, a+1, colors.white)
- term.setCursorPos(16, a+1)
- term.blit("\17","f","8")
- term.setTextColor(colors.black)
- write(color[legend.color[a] ])
- term.setCursorPos(34, a+1)
- term.blit("\16","f","8")
- end
- end
- term.setCursorPos(7,4)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- write("Pattern: ")
- paintutils.drawLine(17, 4, 33, 4, colors.white)
- term.setCursorPos(16, 4)
- term.blit("\17","f","8")
- term.setTextColor(colors.black)
- write(pattern[legend.pattern ])
- term.setCursorPos(34, 4)
- term.blit("\16","f","8")
- term.setCursorPos(7,5)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- write("Symbol: ")
- drawSymbol({2^legend.color[1], 2^legend.color[2]}, legend.pattern)
- term.setCursorPos(2,7)
- write("Name:")
- term.setCursorPos(2,11)
- write("Vendor:")
- term.setCursorPos(17,7)
- write("Description:")
- term.setCursorPos(2,15)
- term.blit("Save Cancel","fffffffffffff","8888fff888888")
- term.redirect(name)
- term.setCursorPos(1,1)
- write(legend.name)
- if editMode == "name" then xPos, yPos = t.getCursorPos() end
- term.redirect(vendor)
- term.setCursorPos(1,1)
- write(legend.vendor)
- if editMode == "vendor" then xPos, yPos = t.getCursorPos() end
- term.redirect(blurb)
- term.setCursorPos(1,1)
- write(legend.blurb)
- if editMode == "blurb" then xPos, yPos = t.getCursorPos() end
- if xPos > 0 and yPos > 0 then
- t.setCursorPos(xPos, yPos)
- t.setCursorBlink(true)
- t.setTextColor(colors.black)
- end
- term.redirect(oldTerm)
- return xPos, yPos
- end
- function helpScreen(h, t) -- Draws the help screens on the terminal
- local oldTerm = term.redirect(t)
- local xSize,ySize = term.getSize()
- term.setCursorPos(1,1)
- term.setBackgroundColor(colors.black)
- term.clear()
- if h == 1 then
- term.setTextColor(colors.white)
- print("This is mapLegend.lua, a program made by Raiu for Drako that displays an interactive legend for the town map with info about each location.\n")
- print("This section is for the adiministrator to look up how to use this program, as there are some features less obvious than others.\n")
- print("Click any of the buttons below to get started.")
- term.setCursorPos(1,11)
- term.blit(" Main Menu","ffffffffff","f888888888")
- print("\n")
- term.blit(" New/Edit Screen","ffffffffffffffff","f888888888888888")
- print("\n")
- term.blit(" Monitor","ffffffff","f8888888")
- elseif h == 2 then
- term.setTextColor(colors.cyan)
- print("Terminal: Main Menu Guide\n")
- term.setTextColor(colors.white)
- print("Click the 'New...' button to add a new item.")
- term.setTextColor(colors.yellow)
- print("Click the 'Edit' button next to any item in the menu to edit its properties.")
- term.setTextColor(colors.white)
- print("Click the 'Delete' button to mark an item for deletion. Click it again to confirm.")
- term.setTextColor(colors.yellow)
- print("Click the up and down arrow buttons or press the 'Page Up' or 'Page Down' keys to scroll through the menu in pages.")
- term.setTextColor(colors.white)
- print("Alternatively, you can use the scroll wheel to scroll one item at a time.")
- term.setTextColor(colors.yellow)
- print("Click the 'Exit' button to exit and restart the program or run a different program.")
- term.setTextColor(colors.white)
- print("Click the 'Reboot' button to reboot the computer.")
- elseif h == 3 then
- term.setTextColor(colors.cyan)
- print("Terminal: New/Edit Guide\n")
- term.setTextColor(colors.white)
- print("Use the left and right arrow buttons to cycle through the color and pattern options. The 2nd color option will be taken way while the pattern option is set to 'Solid'.")
- term.setTextColor(colors.yellow)
- print("Click on the text box for 'Name', 'Vendor' or 'Description' to start editing them. Use can use the 'Tab' key to cycle through the text boxes.")
- term.setTextColor(colors.white)
- print("Click the 'Save' button or press the 'Enter' or 'Return' key to save the information to the legend and return to the main menu.")
- term.setTextColor(colors.yellow)
- print("Click the 'Cancel' button to discard all information and return to the main menu.")
- elseif h == 4 then
- term.setTextColor(colors.cyan)
- print("Monitor: Legend Guide")
- term.setTextColor(colors.white)
- print("Tap on any item in the legend to view its info.")
- term.setTextColor(colors.yellow)
- print("If there are more items than can be shown, up and down arrow buttons will appear at the bottom of the screen. Tap those to scroll through the pages.")
- term.setTextColor(colors.cyan)
- print("\nMonitor: Location Info Guide")
- term.setTextColor(colors.white)
- print("Tap the left arrow button to return to the legend.")
- term.setTextColor(colors.yellow)
- print("When there is more than 1 item in the legend, up and down arrow buttons will appear at the bottom of the screen. Tap those to scroll through each location.")
- term.setTextColor(colors.white)
- print("Tap the 'Print' button to print a page with info about the currently viewed location. The page will be in the storage crate under the monitor.")
- end
- term.setCursorPos(1,ySize)
- term.blit("\27 Back","ffffff","888888")
- term.redirect(oldTerm)
- end
- function drawMain(scrollPos, legend, m) -- Draws the Legend on the monitor
- local oldTerm = term.redirect(m)
- local xSize, ySize = term.getSize()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- for a = 1, ySize-1 do
- term.setCursorPos(1,a)
- if a+scrollPos <= #legend.color then
- drawSymbol(legend.color[a+scrollPos], legend.pattern[a+scrollPos])
- write(" "..legend.name[a+scrollPos])
- end
- end
- if #legend.color > ySize-1 then
- term.setCursorPos(5,ySize)
- if scrollPos == 0 then term.blit(" \30 ","888f","777f")
- else term.blit(" \30 ","ffff","888f") end
- if scrollPos+ySize-1 > #legend.color then term.blit(" \31 ","888","777")
- else term.blit(" \31 ","fff","888") end
- end
- term.redirect(oldTerm)
- end
- function drawSub(shop, legend, m, coolDown) -- Draws the location info on the monitor
- local oldTerm = term.redirect(m)
- local xSize, ySize = term.getSize()
- local title = window.create(term.current(),6,1,xSize-6,4)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- drawPattern(legend.color[shop], legend.pattern[shop], 1, 1)
- term.setCursorPos(1, 6)
- write(legend.blurb[shop])
- term.setCursorPos(1,ySize)
- term.blit(" \27 ","fff","888")
- if #legend.color > 1 then
- term.setCursorPos(5,ySize)
- if shop == 1 then term.blit(" \30 ","888f","777f")
- else term.blit(" \30 ","ffff","888f") end
- if shop == #legend.color then term.blit(" \31 ","888","777")
- else term.blit(" \31 ","fff","888") end
- end
- term.setCursorPos(xSize-4,ySize)
- if coolDown > 0 then term.blit("Print","88888","77777")
- else term.blit("Print","fffff","88888") end
- term.redirect(title)
- term.setCursorPos(1,1)
- term.setTextColor(colors.white)
- write(legend.name[shop])
- term.setCursorPos(1,3)
- term.setTextColor(colors.yellow)
- write(legend.vendor[shop])
- term.setTextColor(colors.white)
- term.redirect(oldTerm)
- end
- function drawPrintError(printerError, m) -- Draws the printer info on the monitor
- local oldTerm = term.redirect(m)
- local xSize, ySize = term.getSize()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- if printerError == 1 then write("The printer is out of paper.\n\n\n\n\nPlease contact an administrator.")
- elseif printerError == 2 then write("The printer is out of ink.\n\n\n\n\nPlease contact an administrator.")
- elseif printerError == 3 then write("The printer is out of paper.\n\nThe printer is also out of ink.\n\nPlease contact an administrator.")
- elseif printerError == 4 then print("Your document has been printed. Check the storage crate below the monitor.\n\nIf it did not print, please contact an administrator.")
- end
- write("")
- term.setCursorPos(xSize-3, ySize)
- term.blit("Okay","ffff","8888")
- term.redirect(oldTerm)
- end
- function drawSymbol(color, pattern) -- Writes the symbol for a location
- local symbols = {[0] = " ", [1] = "\140", [2] = "\149", [3] = "\153"}
- local oldBack, oldText = term.getBackgroundColor(), term.getTextColor()
- term.setBackgroundColor(color[1])
- term.setTextColor(color[2])
- write(symbols[pattern])
- term.setBackgroundColor(oldBack)
- term.setTextColor(oldText)
- end
- function drawPattern(color, pattern, xPos, yPos) -- Draws the pattern for a location
- local oldBack = term.getBackgroundColor()
- if pattern == 0 then -- Solid
- paintutils.drawFilledBox(xPos, yPos, xPos+3, yPos+3, color[1])
- elseif pattern == 1 then -- Horizontal Stripe
- for a = 0, 3, 2 do
- paintutils.drawLine(xPos, yPos+a, xPos+3, yPos+a, color[1])
- paintutils.drawLine(xPos, yPos+a+1, xPos+3, yPos+a+1, color[2])
- end
- elseif pattern == 2 then -- Vertical Stripe
- for a = 0, 3, 2 do
- paintutils.drawLine(xPos+a, yPos, xPos+a, yPos+3, color[1])
- paintutils.drawLine(xPos+a+1, yPos, xPos+a+1, yPos+3, color[2])
- end
- elseif pattern == 3 then -- Checkerboard
- for a = 0, 3 do
- for b = 0, 3 do
- paintutils.drawPixel(xPos+a, yPos+b, color[(a+b)%2+1])
- end
- end
- end
- term.setBackgroundColor(oldBack)
- end
- function doneEdit(legend, editLegend, editing) -- Applies the edit to an item in the legend
- legend.color[editing] = {}
- legend.color[editing][1] = 2 ^ editLegend.color[1]
- legend.color[editing][2] = 2 ^ editLegend.color[2]
- legend.pattern[editing] = editLegend.pattern
- legend.name[editing] = editLegend.name
- legend.vendor[editing] = editLegend.vendor
- legend.blurb[editing] = editLegend.blurb
- editing = 0
- term.setCursorBlink(false)
- saveData(legend)
- return legend, editing
- end
- function convertColors(value, index) -- Conversion of color data for dynamic use
- for a = 1, 2 do
- for b = 0, 15 do
- if 2^b == value[a] then index[a] = b end
- end
- end
- return index
- end
- function pPrint(text, xPos, yPos, xSize, ySize,p) -- Text wrapper for printer paper
- local line, space, start = 0, 0, 1
- for a = 1, string.len(text) do
- if string.sub(text,a+1,a+1) == " " or a+1 > string.len(text) then space = a+1 end
- p.setCursorPos(xPos,yPos+line)
- if a%(xSize+1)+1 == xSize+1 then
- if start >= space+1 then
- p.write(string.sub(text,start,a))
- start = a + 1
- else
- p.write(string.sub(text,start,space-1))
- start = space + 1
- end
- line = line + 1
- elseif a == string.len(text) then
- p.write(string.sub(text,start,a))
- end
- end
- end
- function saveData(legend) -- Saves legend data to a file
- local file = fs.open("mapLegend.sav","w")
- file.write(textutils.serialize(legend))
- file.close()
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement