Advertisement
JustDoesGames

Basics

Aug 5th, 2022 (edited)
1,032
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Basics --
  2. -- KOGA --
  3.  
  4. local t,txt = term, textutils
  5.  
  6. local w,h = t.getSize()
  7.  
  8. local clr, cls, cp, st, sb, paint, m = t.clear, colors, t.setCursorPos, t.setTextColor, t.setBackgroundColor, paintutils, math
  9. local ser, unser = txt.serialize, txt.unserialize
  10. local ms = function(a,b) st(a) sb(b) end -- Multi-Set Text and Color
  11.  
  12. -- Functions --
  13.  
  14. local status_ref = {
  15.     {color = colors.green, icon = string.char(3)}, -- Status of 1 (Good)
  16.     {color = colors.yellow, icon = string.char(7)}, -- Status of 2 (Degrade)
  17.     {color = colors.red, icon = string.char(19)}, -- Status of 3 (Fail)
  18.     {color = colors.purple, icon = string.char(21)}, -- Status of 4 (Lost / Disconnected)
  19. }
  20.  
  21. local function connectBasics()
  22.     local list, connected = peripheral.getNames(), {}
  23.     for i=1, #list do
  24.         connected[#connected+1] = {term = peripheral.wrap(list[i]), name = peripheral.getType(list[i]), id = list[i], status = 1}
  25.     end
  26.     return connected
  27. end
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36. local connected = connectBasics()
  37.  
  38. local function drawMainMenu()
  39.     local sel, scroll = 1, 0
  40.     local item_display_max = 6
  41.     while true do
  42.         paint.drawBox(0,0,11,7,colors.gray) sb(colors.black)
  43.         cp(1,1)
  44.         for i=1, math.min(#connected, item_display_max) do
  45.             if sel == i+scroll then write(string.char(187)) else write(" ") end
  46.             st(status_ref[connected[i+scroll].status].color) write(status_ref[connected[i+scroll].status].icon)
  47.             st(colors.white) write("["..i+scroll.."] "..string.sub(connected[i+scroll].name,1,3).."\n")
  48.         end
  49.         a,b,x,y = os.pullEvent()
  50.         if a == "mouse_click" then
  51.             --
  52.         elseif a == "monitor_touch" then
  53.             --
  54.         elseif a == "key" then
  55.             if b == keys.w or b == keys.up then
  56.                 sel = sel-1 if sel < 1 then sel = #connected end
  57.             elseif b == keys.s or b == keys.down then
  58.                 sel = sel+1 if sel > #connected then sel = 1 end
  59.             elseif b == keys.enter or b == keys.e then
  60.                 --
  61.             elseif b == keys.q then
  62.                 break
  63.             elseif b == keys.delete then
  64.                 --
  65.             end
  66.         end
  67.         if sel > scroll+item_display_max then scroll = sel-item_display_max end
  68.         if sel <= scroll then scroll = math.max(0, sel-1) end
  69.     end
  70. end
  71.  
  72. clr()
  73. drawMainMenu()
  74.  
  75. sleep(.5)
Advertisement
RAW Paste Data Copied
Advertisement