DraRex368

Stargate Address Book

Jul 2nd, 2026 (edited)
42
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.67 KB | None | 0 0
  1. -- Pocket Computer Address Manager
  2. -- Full edit mode: name, address (grid), notes
  3. -- Address: 7 digits chosen from grid (0–38), no duplicates, undo supported
  4.  
  5. local addresses = {}
  6. local currentTab = "Home"
  7. local w, h = term.getSize()
  8.  
  9. local selectedIndex = nil
  10. local editMode = nil  -- "name", "address", "notes"
  11.  
  12. local function clear()
  13.     term.setBackgroundColor(colors.black)
  14.     term.clear()
  15.     term.setCursorPos(1,1)
  16. end
  17.  
  18. local function drawTabs()
  19.     term.setBackgroundColor(colors.gray)
  20.     term.setTextColor(colors.white)
  21.     term.setCursorPos(1,1) term.write("Home")
  22.     term.setCursorPos(7,1) term.write("List")
  23.     term.setCursorPos(12,1) term.write("Add")
  24. end
  25.  
  26. ----------------------------------------------------
  27. -- HOME TAB
  28. ----------------------------------------------------
  29. local function drawHome()
  30.     clear()
  31.     drawTabs()
  32.     term.setCursorPos(1,3) term.write("Address Manager")
  33.     term.setCursorPos(1,5) term.write("Tabs:")
  34.     term.setCursorPos(2,6) term.write("- Home")
  35.     term.setCursorPos(2,7) term.write("- List")
  36.     term.setCursorPos(2,8) term.write("- Add")
  37. end
  38.  
  39. ----------------------------------------------------
  40. -- LIST TAB (Clickable names)
  41. ----------------------------------------------------
  42. local function drawList()
  43.     clear()
  44.     drawTabs()
  45.     term.setCursorPos(1,3) term.write("Saved Addresses:")
  46.     local y = 5
  47.     for i, a in ipairs(addresses) do
  48.         term.setCursorPos(1,y)
  49.         term.write(i..": "..a.name)
  50.         y = y + 1
  51.     end
  52. end
  53.  
  54. local function handleListClick(mx,my)
  55.     local y = 5
  56.     for i,_ in ipairs(addresses) do
  57.         if my == y then
  58.             selectedIndex = i
  59.             currentTab = "Details"
  60.             editMode = nil
  61.             return
  62.         end
  63.         y = y + 1
  64.     end
  65. end
  66.  
  67. ----------------------------------------------------
  68. -- DETAILS SCREEN
  69. ----------------------------------------------------
  70. local function drawDetails()
  71.     clear()
  72.     drawTabs()
  73.  
  74.     local a = addresses[selectedIndex]
  75.     if not a then currentTab="List" return end
  76.  
  77.     term.setCursorPos(1,3)
  78.     term.write("Name: " .. a.name)
  79.  
  80.     term.setCursorPos(1,4)
  81.     term.write("Address: ")
  82.     for _,d in ipairs(a.addr) do term.write(d.." ") end
  83.  
  84.     term.setCursorPos(1,6)
  85.     term.write("Notes:")
  86.     term.setCursorPos(1,7)
  87.     term.write(a.notes or "")
  88.  
  89.     -- Buttons
  90.     term.setCursorPos(1,9)
  91.     term.setBackgroundColor(colors.blue)
  92.     term.write("Edit Name")
  93.     term.setBackgroundColor(colors.black)
  94.  
  95.     term.setCursorPos(1,11)
  96.     term.setBackgroundColor(colors.blue)
  97.     term.write("Edit Address")
  98.     term.setBackgroundColor(colors.black)
  99.  
  100.     term.setCursorPos(1,13)
  101.     term.setBackgroundColor(colors.blue)
  102.     term.write("Edit Notes")
  103.     term.setBackgroundColor(colors.black)
  104.  
  105.     term.setCursorPos(1,15)
  106.     term.setBackgroundColor(colors.red)
  107.     term.write("Delete")
  108.     term.setBackgroundColor(colors.black)
  109.  
  110.     term.setCursorPos(1,17)
  111.     term.setBackgroundColor(colors.gray)
  112.     term.write("Back")
  113.     term.setBackgroundColor(colors.black)
  114. end
  115.  
  116. local function handleDetailsClick(mx,my)
  117.     -- Edit Name
  118.     if my == 9 then
  119.         editMode = "name"
  120.         currentTab = "Edit"
  121.         return
  122.     end
  123.  
  124.     -- Edit Address
  125.     if my == 11 then
  126.         editMode = "address"
  127.         currentTab = "Edit"
  128.         return
  129.     end
  130.  
  131.     -- Edit Notes
  132.     if my == 13 then
  133.         editMode = "notes"
  134.         currentTab = "Edit"
  135.         return
  136.     end
  137.  
  138.     -- Delete
  139.     if my == 15 then
  140.         table.remove(addresses, selectedIndex)
  141.         selectedIndex = nil
  142.         currentTab = "List"
  143.         return
  144.     end
  145.  
  146.     -- Back
  147.     if my == 17 then
  148.         selectedIndex = nil
  149.         currentTab = "List"
  150.         return
  151.     end
  152. end
  153.  
  154. ----------------------------------------------------
  155. -- EDIT MODE SCREEN
  156. ----------------------------------------------------
  157. local editName = ""
  158. local editAddr = {}
  159. local editUsed = {}
  160. local editNotes = ""
  161.  
  162. local function drawEdit()
  163.     clear()
  164.     drawTabs()
  165.  
  166.     local a = addresses[selectedIndex]
  167.  
  168.     if editMode == "name" then
  169.         term.setCursorPos(1,3) term.write("Edit Name:")
  170.         term.setCursorPos(1,4) term.write("> "..editName)
  171.         term.setCursorPos(1,6)
  172.         term.setBackgroundColor(colors.green)
  173.         term.write("Save")
  174.         term.setBackgroundColor(colors.black)
  175.         term.setCursorPos(1,8)
  176.         term.setBackgroundColor(colors.gray)
  177.         term.write("Cancel")
  178.         term.setBackgroundColor(colors.black)
  179.  
  180.     elseif editMode == "notes" then
  181.         term.setCursorPos(1,3) term.write("Edit Notes:")
  182.         term.setCursorPos(1,5) term.write(editNotes)
  183.         term.setCursorPos(1,7)
  184.         term.setBackgroundColor(colors.green)
  185.         term.write("Save")
  186.         term.setBackgroundColor(colors.black)
  187.         term.setCursorPos(1,9)
  188.         term.setBackgroundColor(colors.gray)
  189.         term.write("Cancel")
  190.         term.setBackgroundColor(colors.black)
  191.  
  192.     elseif editMode == "address" then
  193.         term.setCursorPos(1,3) term.write("Edit Address:")
  194.         term.setCursorPos(1,4)
  195.         term.write("Addr: ")
  196.         for _,d in ipairs(editAddr) do term.write(d.." ") end
  197.  
  198.         -- Undo button
  199.         term.setCursorPos(1,5)
  200.         term.setBackgroundColor(colors.blue)
  201.         term.write("Undo")
  202.         term.setBackgroundColor(colors.black)
  203.  
  204.         -- Grid
  205.         local x,y = 1,7
  206.         for i=0,38 do
  207.             term.setCursorPos(x,y)
  208.             if editUsed[i] then
  209.                 term.setTextColor(colors.red)
  210.                 term.write("X")
  211.                 term.setTextColor(colors.white)
  212.             else
  213.                 term.write(i)
  214.             end
  215.             x = x + 3
  216.             if x > w-2 then x = 1 y = y + 1 end
  217.         end
  218.     end
  219. end
  220.  
  221. local function handleEditClick(mx,my)
  222.     local a = addresses[selectedIndex]
  223.  
  224.     if editMode == "name" then
  225.         if my == 6 then
  226.             a.name = editName
  227.             currentTab = "Details"
  228.             return
  229.         elseif my == 8 then
  230.             currentTab = "Details"
  231.             return
  232.         end
  233.  
  234.     elseif editMode == "notes" then
  235.         if my == 7 then
  236.             a.notes = editNotes
  237.             currentTab = "Details"
  238.             return
  239.         elseif my == 9 then
  240.             currentTab = "Details"
  241.             return
  242.         end
  243.  
  244.     elseif editMode == "address" then
  245.         -- Undo
  246.         if my == 5 and mx >= 1 and mx <= 4 then
  247.             if #editAddr > 0 then
  248.                 local last = editAddr[#editAddr]
  249.                 editUsed[last] = nil
  250.                 table.remove(editAddr)
  251.                 drawEdit()
  252.             end
  253.             return
  254.         end
  255.  
  256.         -- Grid
  257.         local x,y = 1,7
  258.         for i=0,38 do
  259.             if mx >= x and mx <= x+1 and my == y then
  260.  
  261.                 if editUsed[i] then
  262.                     term.setCursorPos(1,h)
  263.                     term.setTextColor(colors.red)
  264.                     term.write("Digit already used!")
  265.                     term.setTextColor(colors.white)
  266.                     return
  267.                 end
  268.  
  269.                 table.insert(editAddr, i)
  270.                 editUsed[i] = true
  271.                 drawEdit()
  272.  
  273.                 if #editAddr == 7 then
  274.                     a.addr = editAddr
  275.                     currentTab = "Details"
  276.                 end
  277.                 return
  278.             end
  279.  
  280.             x = x + 3
  281.             if x > w-2 then x = 1 y = y + 1 end
  282.         end
  283.     end
  284. end
  285.  
  286. ----------------------------------------------------
  287. -- ADD TAB (unchanged)
  288. ----------------------------------------------------
  289. local addState = "name"
  290. local newName = ""
  291. local newAddr = {}
  292. local usedDigits = {}
  293.  
  294. local function drawAdd()
  295.     clear()
  296.     drawTabs()
  297.  
  298.     if addState == "name" then
  299.         term.setCursorPos(1,3) term.write("Type Name:")
  300.         term.setCursorPos(1,4) term.write("> "..newName)
  301.         term.setCursorPos(1,6) term.write("[Enter to confirm]")
  302.  
  303.     elseif addState == "grid" then
  304.         term.setCursorPos(1,3)
  305.         term.write("Pick 7 digits:")
  306.         term.setCursorPos(1,4)
  307.         term.write("Addr: ")
  308.         for _,d in ipairs(newAddr) do term.write(d.." ") end
  309.  
  310.         term.setCursorPos(1,5)
  311.         term.setBackgroundColor(colors.blue)
  312.         term.write("Undo")
  313.         term.setBackgroundColor(colors.black)
  314.  
  315.         local x,y = 1,7
  316.         for i=0,38 do
  317.             term.setCursorPos(x,y)
  318.             if usedDigits[i] then
  319.                 term.setTextColor(colors.red)
  320.                 term.write("X")
  321.                 term.setTextColor(colors.white)
  322.             else
  323.                 term.write(i)
  324.             end
  325.             x = x + 3
  326.             if x > w-2 then x = 1 y = y + 1 end
  327.         end
  328.     end
  329. end
  330.  
  331. local function handleGridClick(mx,my)
  332.     if mx >= 1 and mx <= 4 and my == 5 then
  333.         if #newAddr > 0 then
  334.             local last = newAddr[#newAddr]
  335.             usedDigits[last] = nil
  336.             table.remove(newAddr)
  337.             drawAdd()
  338.         end
  339.         return
  340.     end
  341.  
  342.     local x,y = 1,7
  343.     for i=0,38 do
  344.         if mx >= x and mx <= x+1 and my == y then
  345.  
  346.             if usedDigits[i] then
  347.                 term.setCursorPos(1,h)
  348.                 term.setTextColor(colors.red)
  349.                 term.write("Digit already used!")
  350.                 term.setTextColor(colors.white)
  351.                 return
  352.             end
  353.  
  354.             table.insert(newAddr, i)
  355.             usedDigits[i] = true
  356.             drawAdd()
  357.  
  358.             if #newAddr == 7 then
  359.                 table.insert(addresses, {name=newName, addr=newAddr, notes=""})
  360.                 newName = ""
  361.                 newAddr = {}
  362.                 usedDigits = {}
  363.                 addState = "name"
  364.                 currentTab = "List"
  365.                 drawList()
  366.             end
  367.             return
  368.         end
  369.  
  370.         x = x + 3
  371.         if x > w-2 then x = 1 y = y + 1 end
  372.     end
  373. end
  374.  
  375. ----------------------------------------------------
  376. -- REDRAW
  377. ----------------------------------------------------
  378. local function redraw()
  379.     if currentTab=="Home" then drawHome()
  380.     elseif currentTab=="List" then drawList()
  381.     elseif currentTab=="Add" then drawAdd()
  382.     elseif currentTab=="Details" then drawDetails()
  383.     elseif currentTab=="Edit" then drawEdit()
  384.     end
  385. end
  386.  
  387. redraw()
  388.  
  389. ----------------------------------------------------
  390. -- MAIN LOOP
  391. ----------------------------------------------------
  392. while true do
  393.     local e, p1, p2, p3 = os.pullEvent()
  394.  
  395.     if e == "mouse_click" then
  396.         local mx,my = p2,p3
  397.  
  398.         if my == 1 then
  399.             if mx <= 4 then currentTab="Home"
  400.             elseif mx <= 10 then currentTab="List"
  401.             else currentTab="Add" end
  402.             redraw()
  403.  
  404.         elseif currentTab=="List" then
  405.             handleListClick(mx,my)
  406.  
  407.         elseif currentTab=="Details" then
  408.             handleDetailsClick(mx,my)
  409.             redraw()
  410.  
  411.         elseif currentTab=="Edit" then
  412.             handleEditClick(mx,my)
  413.             redraw()
  414.  
  415.         elseif currentTab=="Add" and addState=="grid" then
  416.             handleGridClick(mx,my)
  417.             redraw()
  418.         end
  419.  
  420.     elseif e == "char" then
  421.         if currentTab=="Add" and addState=="name" then
  422.             newName = newName .. p1
  423.             drawAdd()
  424.  
  425.         elseif currentTab=="Edit" and editMode=="name" then
  426.             editName = editName .. p1
  427.             drawEdit()
  428.  
  429.         elseif currentTab=="Edit" and editMode=="notes" then
  430.             editNotes = editNotes .. p1
  431.             drawEdit()
  432.         end
  433.  
  434.     elseif e == "key" then
  435.         if currentTab=="Add" and addState=="name" then
  436.             if p1 == keys.backspace then
  437.                 newName = newName:sub(1,-2)
  438.                 drawAdd()
  439.             elseif p1 == keys.enter then
  440.                 if #newName > 0 then
  441.                     addState = "grid"
  442.                     drawAdd()
  443.                 end
  444.             end
  445.  
  446.         elseif currentTab=="Edit" and editMode=="name" then
  447.             if p1 == keys.backspace then
  448.                 editName = editName:sub(1,-2)
  449.                 drawEdit()
  450.             elseif p1 == keys.enter then
  451.                 addresses[selectedIndex].name = editName
  452.                 currentTab = "Details"
  453.                 drawDetails()
  454.             end
  455.  
  456.         elseif currentTab=="Edit" and editMode=="notes" then
  457.             if p1 == keys.backspace then
  458.                 editNotes = editNotes:sub(1,-2)
  459.                 drawEdit()
  460.             elseif p1 == keys.enter then
  461.                 addresses[selectedIndex].notes = editNotes
  462.                 currentTab = "Details"
  463.                 drawDetails()
  464.             end
  465.         end
  466.     end
  467. end
  468.  
  469.  
  470.  
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment