Advertisement
davedumas0

opencomputers robotControll_II_beta_0.2

Feb 19th, 2023
965
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 30.94 KB | None | 0 0
  1. -- Require necessary libraries
  2. local os = require("os")
  3. local computer = require("computer")
  4. local term = require("term")
  5. local filesystem = require("filesystem")
  6. local component = require("component")
  7. local keyboard = require("keyboard")
  8. local event = require("event")
  9. local serialization = require("serialization")
  10. local gpu = component.gpu
  11. local modem = component.modem
  12. local robotNavButtons = {}
  13. local robotActionsButtons = {}
  14.  
  15.  
  16. -- Minecraft colors
  17. colors_white = 0xffffff
  18. colors_orange = 0xff6600
  19. colors_magenta = 0xff00ff
  20. colors_lightblue = 0x0099ff
  21. colors_yellow = 0xffff00
  22. colors_lime = 0x00ff00
  23. colors_pink = 0xff3399
  24. colors_gray = 0x737373
  25. colors_lightgray = 0xa5a5a5
  26. colors_silver = 0xc0c0c0
  27. colors_cyan = 0x169c9d
  28. colors_purple = 0x8932b7
  29. colors_blue = 0x3c44a9
  30. colors_brown = 0x825432
  31. colors_green = 0x5d7c15
  32. colors_red = 0xb02e26
  33. colors_lightred = 0xffcccb
  34. colors_lightorange = 0xbd8817
  35. colors_black = 0x000000
  36.  
  37.  
  38. -- UUIDs for OpenComputers screens
  39. primaryScreen = "b20d3b1e-87ed-4f8a-941e-26dc440344f8"
  40. secondaryScreen = "2db16f67-86c1-404d-be3d-61894134f13d"
  41.  
  42.  
  43. leahBot = "933160e0-1a85-4cb0-a91d-d786fb02462f"
  44. -- Initial position of the robot in Minecraft world
  45. robotPos = {}
  46. robotPos.x = 0
  47. robotPos.y = 0
  48. robotPos.z = 0
  49.  
  50. -- Open the modem on channel 6 for communication
  51. modem.open(6)
  52.  
  53.  
  54.  
  55. -- ╔══════════════════════════════════════════╗ --
  56. -- ║      ╭─────╮  IU FUNCTIONS  ╭─────╮      ║ --
  57. -- ╚══════════════════════════════════════════╝ --
  58.  
  59.  
  60. -- Set the background color of the GPU
  61. function setBgColor (color)
  62.   gpu.setBackground(color)
  63. end
  64.  
  65. -- Set the foreground color of the GPU
  66. function setFgColor (color)
  67.   gpu.setForeground(color)
  68. end
  69.  
  70. -- Fill a specified rectangular area on the GPU with spaces
  71. function renderLine(posX, posY, sizeX, sizeY)
  72.   gpu.fill(posX, posY, sizeX, sizeY, " ")
  73. end
  74.  
  75. -- Set the position of the terminal cursor
  76. function setCursorPos (posX, posY)
  77.   term.setCursor(posX, posY)
  78. end
  79.  
  80. -- Write text to the terminal
  81. function renderText(text)
  82.   term.write(text)
  83. end
  84.  
  85. -- Print text to the console
  86. function testFunction (text)
  87.   print(text)
  88. end
  89.  
  90. -- Bind the GPU to a different screen
  91. function switchScreens(screen)
  92.   gpu.bind(screen, false)
  93. end
  94.  
  95.  
  96.  
  97.  
  98. -- Function that draws a progress bar on a terminal screen in OpenComputers
  99. function draw_ProgressBar(orientation, posX, posY, sizeX, sizeY, maxValue, value, bgColor, barColor, showValue)
  100.   -- Calculate the size of the bar based on the value and maxValue arguments
  101.   local barSize = orientation == 1 and sizeX * (value / maxValue) or sizeY * (value / maxValue)
  102.   -- String to display the value below the bar
  103.   local valueText = value .. "/" .. maxValue
  104.   -- Length of the valueText string
  105.   local valueTextLength = #valueText
  106.  
  107.   -- Set the background color to bgColor
  108.   setBgColor(bgColor)
  109.   -- Render a box around the bar
  110.   renderLine(posX - 1, posY - 1, sizeX + 2, sizeY + 2)
  111.  
  112.   if showValue then
  113.     -- Draw the bar inside a box
  114.     -- Set the background color of the box to colors_lightgray
  115.     setBgColor(colors_lightgray)
  116.     renderLine(posX, posY, sizeX, sizeY)
  117.     -- Set the bar color to barColor
  118.     setBgColor(barColor)
  119.     -- Render the bar based on orientation
  120.     if orientation == 1 then
  121.       renderLine(posX, posY, math.floor(barSize), sizeY)
  122.     else
  123.       renderLine(posX, posY + sizeY - math.floor(barSize), sizeX, math.floor(barSize))
  124.     end
  125.  
  126.     -- Display the value below the bar
  127.     -- Set the cursor position to center the valueText
  128.     setCursorPos(posX + (sizeX / 2) - valueTextLength / 2, posY + sizeY + 1)
  129.     -- Set the background color to bgColor
  130.     setBgColor(bgColor)
  131.     -- Set the text color to colors_lime
  132.     setFgColor(colors_lime)
  133.     renderText(valueText)
  134.   else
  135.     -- Draw the bar directly on the screen
  136.     setBgColor(barColor)
  137.     if orientation == 1 then
  138.       renderLine(posX, posY, math.floor(barSize), sizeY)
  139.     else
  140.       renderLine(posX, posY + sizeY - math.floor(barSize), sizeX, math.floor(barSize))
  141.     end
  142.   end
  143. end
  144.  
  145.  
  146. -- ╔══════════════════════════════════════════╗ --
  147. -- ║      ╰─────╯  IU FUNCTIONS  ╰─────╯      ║ --
  148. -- ╚══════════════════════════════════════════╝ --
  149.  
  150.  
  151.  
  152.  
  153. -- ╔══════════════════════════════════════════╗ --
  154. -- ║    ╭─────╮ BUTTON FUNCTIONS  ╭─────╮     ║ --
  155. -- ╚══════════════════════════════════════════╝ --
  156.  
  157.  
  158. -- Check for button presses
  159. function buttonCheck(posX, posY, buttonTable)
  160.   -- t is a flag to keep track of button presses
  161.   local t = false
  162.  
  163.   -- Loop through all buttons in the buttonTable
  164.   for i = 1, #buttonTable do
  165.     -- Check if the touch event is within the bounds of the button
  166.     local buttonPosX = posX >= buttonTable[i].posX and posX <= buttonTable[i].posX + buttonTable[i].sizeX
  167.     local buttonPosY = posY >= buttonTable[i].posY and posY <= buttonTable[i].posY + buttonTable[i].sizeY
  168.    
  169.     -- If the touch event is within the bounds of the button
  170.     if buttonPosX and buttonPosY then
  171.       -- If the flag t is not set
  172.       if not t then
  173.         -- Set the flag t to true
  174.         t = true
  175.        
  176.         -- Call the function stored in the button's `func` field and pass it the data stored in the `func_DATA` field
  177.         buttonTable[i].func(buttonTable[i].func_DATA)
  178.       end
  179.     else
  180.       -- If the touch event is not within the bounds of the button, set the flag t to false
  181.       t = false
  182.     end
  183.   end
  184. end
  185.  
  186.  
  187. -- function to draw buttons
  188. -- input: buttonTable - table containing all the button objects to be drawn
  189. function drawButtons(buttonTable)
  190.   for i = 1, #buttonTable do
  191.    local ghg = buttonTable[i].posX+buttonTable[i].sizeX/2-string.len(buttonTable[i].label)/2
  192.     -- check if the sizeOverride property is set to true
  193.     if buttonTable[i].sizeOverride then
  194.       -- set the background color of the button
  195.       setBgColor(buttonTable[i].buttonColor)
  196.       -- draw the button with the specified X, Y, sizeX, and sizeY values
  197.       renderLine(buttonTable[i].posX, buttonTable[i].posY, buttonTable[i].sizeX, buttonTable[i].sizeY)
  198.       -- set the cursor position within the button
  199.       if buttonTable[i].sizeY ==  1 then
  200.         setCursorPos(ghg, buttonTable[i].posY)
  201.       else
  202.         setCursorPos(ghg, buttonTable[i].posY+1)
  203.       end
  204.      
  205.       -- set the text color of the button label
  206.       setFgColor(buttonTable[i].textColor)
  207.       -- render the button label
  208.       renderText(buttonTable[i].label)
  209.     else
  210.       -- set the background color of the button
  211.       setBgColor(buttonTable[i].buttonColor)
  212.       -- draw the button with the specified X, Y, and length of the label + 2
  213.       renderLine(buttonTable[i].posX, buttonTable[i].posY, string.len(buttonTable[i].label)+2, 3)
  214.       -- set the cursor position within the button
  215.       setCursorPos(ghg, buttonTable[i].posY+1)
  216.       -- set the text color of the button label
  217.       setFgColor(buttonTable[i].textColor)
  218.       -- render the button label
  219.       renderText(buttonTable[i].label)
  220.     end
  221.   end
  222. end
  223.  
  224. -- This function creates a new button object with the specified properties and adds it to the specified button table.
  225. -- The button object will contain the label, position, size, color information, and functions that will be triggered
  226. -- when the button is clicked.
  227.  
  228. function newButton(label, posX, posY, sizeX, sizeY, SizeOverride, textColor, buttonColor, func, func_DATA, buttonTable)
  229.   -- Create a new button object
  230.   local button = {}
  231.    button.label = label -- Label to display on the button
  232.    button.posX = posX -- X position of the button on the screen
  233.    button.posY = posY -- Y position of the button on the screen
  234.    button.sizeX = sizeX -- Width of the button
  235.    button.sizeY = sizeY -- Height of the button
  236.    button.sizeOverride = SizeOverride -- Boolean to indicate whether the size of the button should be overridden
  237.                                       -- (if set to true, the size will be determined by the sizeX and sizeY properties)
  238.    button.textColor = textColor -- Color of the label text
  239.    button.buttonColor = buttonColor -- Color of the button background
  240.    button.func = func -- Function to call when the button is clicked
  241.    button.func_DATA = func_DATA -- Data to pass to the function when the button is clicked
  242.    button.clicked = false -- Boolean to track whether the button has been clicked
  243.    
  244.    -- Add the button to the specified button table
  245.    table.insert(buttonTable, button)
  246. end
  247.  
  248.  
  249. -- ╔══════════════════════════════════════════╗ --
  250. -- ║    ╰─────╯ BUTTON FUNCTIONS  ╰─────╯     ║ --
  251. -- ╚══════════════════════════════════════════╝ --
  252.  
  253.  
  254.  
  255. -- Send a message to the robot in Minecraft
  256. function sendMsgToRobot (msg)
  257.   -- Open channel 5 on the modem and set the strength to 255
  258.   modem.open(5)
  259.   modem.setStrength(255)
  260.  
  261.   -- Broadcast the message on channel 5
  262.  
  263.   modem.send(leahBot, 5, msg)
  264.  
  265.   -- Close channel 5 on the modem and update the console
  266.   modem.close(5)
  267.   updateConsole_01("sending command:"..msg)
  268. end
  269.  
  270.  
  271. -- Check for various events and handle them accordingly
  272. function checkForEvents()
  273.   -- Open channel 5 on the modem
  274.   modem.open(5)
  275.  
  276.   -- Wait for the next event to occur and store the event information in eventData
  277.   local eventData = {event.pull(0.1)}
  278.  
  279.   -- Check the type of event
  280.   if eventData[1] == "key_down" then
  281.     -- Handle keyboard events
  282.     -- eventData[2] will contain the ASCII value of the key that was pressed
  283.  
  284.   elseif eventData[1] == "touch" then
  285.     -- Handle touch events
  286.     -- eventData[3] and eventData[4] will contain the X and Y coordinates of the touch event, respectively
  287.  
  288.     if eventData[2] == primaryScreen then
  289.      
  290.       buttonCheck(eventData[3], eventData[4], robotNavButtons)
  291.        buttonCheck(eventData[3], eventData[4], robotActionsButtons)
  292.         buttonCheck(eventData[3], eventData[4], console_01_Buttons)
  293.          buttonCheck(eventData[3], eventData[4], console_02_Buttons)
  294.           buttonCheck(eventData[3], eventData[4], robotInventoryButtons)
  295.     end
  296.  
  297.   elseif eventData[1] == "modem_message" then
  298.     -- Handle modem message events
  299.     -- eventData[6] will contain the message sent over the modem
  300.     local message = serialization.unserialize(eventData[6])
  301.     if type(message) == "table" and inventoryToggle then
  302.       for iii = 1 , 16 do
  303.           --updateConsole_02("slot "..iii..": "..tostring(message[iii]))
  304.         table.insert(robotInventory, iii, message[iii])
  305.        
  306.       end
  307.  
  308.        
  309.     else
  310.       updateConsole_02(message)
  311.     end
  312.     --updateConsole_02(serialization.unserialize(eventData[6]))
  313.     -- Wait for 0.3 seconds
  314.     os.sleep(0.3)
  315.   end
  316.  
  317.   -- Close channel 5 on the modem
  318.   modem.close(5)
  319.  
  320.   -- Return true to continue checking for events
  321.   return true
  322. end
  323.  
  324.  
  325.  
  326. -- ╔══════════════════════════════════════════╗ --
  327. -- ║      ╭─────╮   CONSOLE_01   ╭─────╮      ║ --
  328. -- ╚══════════════════════════════════════════╝ --
  329.  
  330.  
  331.  
  332. -- Initialize the first console panel
  333. function init_Consol_01 ()
  334.   console_01_posX = 5
  335.   console_01_posY = 32
  336.   console_01_sizeX = 40
  337.   console_01_sizeY = 15
  338.   console_01_Buttons = {}
  339.   console_01_contents = {}
  340.  
  341. end
  342.  
  343.  
  344. -- Function to draw the first console UI
  345. function drawConsole_01()
  346.   -- Set the background color to gray
  347.   setBgColor(colors_gray)
  348.   -- Draw a line for the console using the specified position, size and color
  349.   renderLine(console_01_posX, console_01_posY, console_01_sizeX, console_01_sizeY)
  350.   -- Set the background color to black
  351.   setBgColor(colors_black)
  352.   -- Draw a line for the contents of the console using the specified position, size and color
  353.   renderLine(console_01_posX+1, console_01_posY+1, console_01_sizeX-2, console_01_sizeY-2)
  354.   -- Set the text color to white
  355.   setFgColor(colors_white)
  356.   -- Set the background color to gray
  357.   setBgColor(colors_gray)
  358.   -- Set the cursor position to the center of the top of the console
  359.   setCursorPos(console_01_posX+console_01_sizeX/2-string.len("console 01")/2, console_01_posY)
  360.   -- Write the label "console 01"
  361.   renderText("console 01")
  362.   -- Create a "clear" button for the console
  363.   newButton("clear", console_01_posX, console_01_posY+console_01_sizeY, string.len("clear")+2, 3, true, colors_white, colors_lightblue, clearConsole_01, _, console_01_Buttons)
  364.   -- Draw all buttons for the console
  365.   drawButtons(console_01_Buttons)
  366. end
  367.  
  368.  
  369. function updateConsole_01(text)
  370.   -- Check if the number of lines in the console is less than the maximum number of lines that can be displayed
  371.   if #console_01_contents < console_01_sizeY-4 then
  372.     -- If there are fewer lines than the maximum number of lines, add the new text to the console_01_contents table
  373.     table.insert(console_01_contents, text)
  374.     -- Clear the background of the console
  375.     setBgColor(colors_black)
  376.     renderLine(console_01_posX+1, console_01_posY+1, console_01_sizeX-2, console_01_sizeY-2)
  377.     -- Loop through the console_01_contents table and display each line of text
  378.     for i = 1, #console_01_contents do
  379.       setCursorPos(console_01_posX+1, console_01_posY+1+i)
  380.       renderText(console_01_contents[i])
  381.     end
  382.   elseif #console_01_contents >= console_01_sizeY-4 then
  383.     -- If there are more lines than the maximum number of lines, add the new text to the console_01_contents table
  384.     table.insert(console_01_contents, text)
  385.     -- Remove the first line in the table
  386.     table.remove(console_01_contents, 1)
  387.     -- Clear the background of the console
  388.     setBgColor(colors_black)
  389.     renderLine(console_01_posX+1, console_01_posY+1, console_01_sizeX-2, console_01_sizeY-2)
  390.     -- Loop through the console_01_contents table and display each line of text
  391.     for i = 1, #console_01_contents do
  392.       setCursorPos(console_01_posX+1, console_01_posY+1+i)
  393.       renderText(console_01_contents[i])
  394.     end
  395.   end
  396. end
  397.  
  398.  
  399.  
  400.  
  401. -- Function to clear the contents of console 01
  402. function clearConsole_01 ()
  403.   -- Reset the contents of the console
  404.   console_01_contents = {}
  405.  
  406.   -- Set the background color to black and draw a line to clear the console
  407.   setBgColor(colors_black)
  408.   renderLine(console_01_posX+1, console_01_posY+1, console_01_sizeX-2, console_01_sizeY-2)
  409. end
  410.  
  411.  
  412. -- ╔══════════════════════════════════════════╗ --
  413. -- ║      ╰─────╯   CONSOLE_01   ╰─────╯      ║ --
  414. -- ╚══════════════════════════════════════════╝ --
  415.  
  416.  
  417. -- ╔══════════════════════════════════════════╗ --
  418. -- ║      ╭─────╮   CONSOLE_02   ╭─────╮      ║ --
  419. -- ╚══════════════════════════════════════════╝ --
  420.  
  421.  
  422.  
  423. -- Initialize the properties for the second console
  424. function init_Consol_02 ()
  425.   console_02_posX = 5
  426.   console_02_posY = 5
  427.   console_02_sizeX = 40
  428.   console_02_sizeY = 15
  429.   console_02_Buttons = {}
  430.   console_02_contents = {}
  431. end
  432.  
  433.  
  434. -- Function to draw the second console UI
  435. function drawConsole_02()
  436.   -- Set the background color to gray
  437.   setBgColor(colors_gray)
  438.   -- Draw a line for the console using the specified position, size and color
  439.   renderLine(console_02_posX, console_02_posY, console_02_sizeX, console_02_sizeY)
  440.   -- Set the background color to black
  441.   setBgColor(colors_black)
  442.   -- Draw a line for the contents of the console using the specified position, size and color
  443.   renderLine(console_02_posX+1, console_02_posY+1, console_02_sizeX-2, console_02_sizeY-2)
  444.   -- Set the text color to white
  445.   setFgColor(colors_white)
  446.   -- Set the background color to gray
  447.   setBgColor(colors_gray)
  448.   -- Set the cursor position to the center of the top of the console
  449.   setCursorPos(console_02_posX+console_02_sizeX/2-string.len("console 02")/2, console_02_posY)
  450.   -- Write the label "console 02"
  451.   renderText("console 02")
  452.   -- Create a "clear" button for the console
  453.   newButton("clear", console_02_posX, console_02_posY+console_02_sizeY, string.len("clear")+2, 3, true, colors_white, colors_lightblue, clearConsole_02, _, console_02_Buttons)
  454.   -- Draw all buttons for the console
  455.   drawButtons(console_02_Buttons)
  456. end
  457.  
  458.  
  459. -- Function to update the contents of the second console
  460. function updateConsole_02(text)
  461.   -- If the number of contents in the console is less than the size of the console minus 4
  462.   if #console_02_contents < console_02_sizeY-4 then
  463.     -- Add the new text to the contents of the console
  464.     table.insert(console_02_contents, text)
  465.     -- Set the background color to black
  466.     setBgColor(colors_black)
  467.     -- Draw a line for the contents of the console using the specified position, size and color
  468.     renderLine(console_02_posX+1, console_02_posY+1, console_02_sizeX-2, console_02_sizeY-2)
  469.     -- Loop through all the contents of the console
  470.     for i = 1, #console_02_contents do
  471.       -- Set the cursor position to the specified position
  472.       setCursorPos(console_02_posX+1, console_02_posY+1+i)
  473.       -- Write the contents of the console
  474.       renderText(console_02_contents[i])
  475.     end
  476.   -- If the number of contents in the console is equal to or greater than the size of the console minus 4
  477.   elseif #console_02_contents >= console_02_sizeY-4 then
  478.     -- Add the new text to the contents of the console
  479.     table.insert(console_02_contents, text)
  480.     -- Remove the first content from the console
  481.     table.remove(console_02_contents, 1)
  482.     -- Set the background color to black
  483.     setBgColor(colors_black)
  484.     -- Draw a line for the contents of the console using the specified position, size and color
  485.     renderLine(console_02_posX+1, console_02_posY+1, console_02_sizeX-2, console_02_sizeY-2)
  486.     -- Loop through all the contents of the console
  487.     for i = 1, #console_02_contents do
  488.       -- Set the cursor position to the specified position
  489.       setCursorPos(console_02_posX+1, console_02_posY+1+i)
  490.       -- Write the contents of the console
  491.       renderText(console_02_contents[i])
  492.     end
  493.   end
  494. end
  495.  
  496. -- Function to clear the contents of the second console
  497. function clearConsole_02 ()
  498.   -- Reset the contents of the console to an empty table
  499.   console_02_contents = {}
  500.   -- Set the background color to black
  501.   setBgColor(colors_black)
  502.   -- Draw a line for the contents of the console using the specified position, size and color
  503.   renderLine(console_02_posX+1, console_02_posY+1, console_02_sizeX-2, console_02_sizeY-2)
  504. end
  505.  
  506. -- ╔══════════════════════════════════════════╗ --
  507. -- ║      ╰─────╯   CONSOLE_02   ╰─────╯      ║ --
  508. -- ╚══════════════════════════════════════════╝ --
  509.  
  510. -- ╔══════════════════════════════════════════╗ --
  511. -- ║   ╭─────╮   NAVIGATION_PANEL   ╭─────╮   ║ --
  512. -- ╚══════════════════════════════════════════╝ --
  513.  
  514. -- Draw the navigation panel for the robot in Minecraft
  515. function drawRobotNavPanel()
  516.   -- Variables for the panel's position, size, and background color
  517.   local panelX = 123
  518.   local panelY = 40
  519.   local panelSizeX = 31
  520.   local panelSizeY = 9
  521.   local panel_BGColor = colors_gray
  522.  
  523.   -- Set the background color of the panel and render a rectangular area on the GPU
  524.   setBgColor(panel_BGColor)
  525.   renderLine(panelX, panelY, panelSizeX, panelSizeY)
  526.  
  527.   -- Set the cursor position, background color, and foreground color and render text
  528.   setCursorPos(panelX + panelSizeX / 2 - string.len("navigation controls")/2, panelY - 1)
  529.   setBgColor(colors_black)
  530.   setFgColor(colors_orange)
  531.   renderText("navigation controls")
  532.  
  533.   -- Create several navigation buttons and add them to the robotNavButtons table
  534.   newButton("NAV_FWD", panelX + 11, panelY + 1, 9, 3, true, colors_lightblue, colors_white, sendMsgToRobot, "FWD", robotNavButtons)
  535.   newButton("NAV_LFT", panelX + 1, panelY + 1, 9, 3, true, colors_lightblue, colors_white, sendMsgToRobot, "LFT", robotNavButtons)
  536.   newButton("NAV_RHT", panelX + 21, panelY + 1, 9, 3, true, colors_lightblue, colors_white, sendMsgToRobot, "RHT", robotNavButtons)
  537.   newButton("NAV_UPW", panelX + 1, panelY + 5, 9, 3, true, colors_lightblue, colors_white, sendMsgToRobot, "UP", robotNavButtons)
  538.   newButton("NAV_DWN", panelX + 21, panelY + 5, 9, 3, true, colors_lightblue, colors_white, sendMsgToRobot, "DWN", robotNavButtons)
  539.   newButton("NAV_BWD", panelX + 11, panelY + 5, 9, 3, true, colors_lightblue, colors_white, sendMsgToRobot, "BWD", robotNavButtons)
  540.  
  541.   -- Render the navigation buttons on the GPU
  542.   drawButtons(robotNavButtons)
  543. end
  544.  
  545. -- ╔══════════════════════════════════════════╗ --
  546. -- ║   ╰─────╯   NAVIGATION_PANEL   ╰─────╯   ║ --
  547. -- ╚══════════════════════════════════════════╝ --
  548.  
  549. -- ╔══════════════════════════════════════════╗ --
  550. -- ║     ╭─────╮   ACTIONS_PANEL   ╭─────╮    ║ --
  551. -- ╚══════════════════════════════════════════╝ --
  552.  
  553.  
  554.  
  555. -- Draw the actions panel for the robot in Minecraft
  556. function drawRobotActionsPanel()
  557.   -- Variables for the panel's position, size, and background color
  558.   local panelX = 123
  559.   local panelY = 25
  560.   local panelSizeX = 22
  561.   local panelSizeY = 13
  562.   local panel_BGColor = colors_gray
  563.  
  564.   -- Set the background color of the panel and render a rectangular area on the GPU
  565.   setBgColor(panel_BGColor)
  566.   renderLine(panelX, panelY, panelSizeX, panelSizeY)
  567.  
  568.   -- Set the cursor position, background color, and foreground color and render text
  569.   setCursorPos(panelX + panelSizeX / 2 - string.len("action controls")/2, panelY - 1)
  570.   setBgColor(colors_black)
  571.   setFgColor(colors_orange)
  572.   renderText("action controls")
  573.  
  574.   -- Create several action buttons and add them to the robotActionsButtons table
  575.   newButton("DCT_UPW", panelX + 1, panelY + 1, string.len("DCT_UPW")+2, 3, true, colors_lightblue, colors_white, sendMsgToRobot, "DCT_UPW", robotActionsButtons)
  576.   newButton("DCT_FWD", panelX + 1, panelY + 5, string.len("DCT_FWD")+2, 3, true, colors_lightblue, colors_white, sendMsgToRobot, "DCT_FWD", robotActionsButtons)
  577.   newButton("DCT_DWD", panelX + 1, panelY + 5 + 4, (string.len("DCT_FWD")+2), 3, true, colors_lightblue, colors_white, sendMsgToRobot, "DCT_DWD", robotActionsButtons)
  578.   newButton("USE_FWD", panelX + 11, panelY + 5, (string.len("DCT_FWD")+2), 3, true, colors_lightblue, colors_white, sendMsgToRobot, "USE_FWD", robotActionsButtons)
  579.  
  580.   -- Render the action buttons on the GPU
  581.   drawButtons(robotActionsButtons)
  582. end
  583.  
  584. -- ╔══════════════════════════════════════════╗ --
  585. -- ║     ╰─────╯   ACTIONS_PANEL   ╰─────╯    ║ --
  586. -- ╚══════════════════════════════════════════╝ --
  587.  
  588.  
  589.  
  590. function drawInventoryPanel()
  591.   local panelX = 128
  592.   local panelY = 13
  593.   local panelSizeX = 17
  594.   local panelSizeY = 11
  595.   local panel_BGColor = colors_gray
  596.   robotInventoryButtons = {}
  597.   robotInventory = {}
  598.   inventoryToggle = false
  599.   robotInventorySlot = nil
  600.  
  601.  
  602.   setBgColor(panel_BGColor)
  603.   renderLine(panelX, panelY, panelSizeX, panelSizeY)
  604.  
  605.  
  606.  
  607.   setCursorPos(panelX + panelSizeX / 2 - string.len("inventory controls")/2, panelY - 1)
  608.   setBgColor(colors_black)
  609.   setFgColor(colors_orange)
  610.   renderText("inventory controls")
  611.  
  612.  
  613.   newButton("GET_INV", panelX + 1, panelY + 9, panelSizeX-2, 1, true, colors_lightblue, colors_white, getInventory, _, robotInventoryButtons)
  614.   newButton("1", panelX + 1, panelY + 1, 3, 1, true, colors_lightblue, colors_white, showInventorySlotInfo, 1, robotInventoryButtons)
  615.   newButton("2", panelX + 5, panelY + 1, 3, 1, true, colors_lightblue, colors_white, showInventorySlotInfo, 2, robotInventoryButtons)
  616.   newButton("3", panelX + 9, panelY + 1, 3, 1, true, colors_lightblue, colors_white, showInventorySlotInfo, 3, robotInventoryButtons)
  617.   newButton("4", panelX + 13, panelY + 1, 3, 1, true, colors_lightblue, colors_white, showInventorySlotInfo, 4, robotInventoryButtons)
  618.  
  619.   newButton("5", panelX + 1, panelY + 3, 3, 1, true, colors_lightblue, colors_white, showInventorySlotInfo, 5, robotInventoryButtons)
  620.   newButton("6", panelX + 5, panelY + 3, 3, 1, true, colors_lightblue, colors_white, showInventorySlotInfo, 6, robotInventoryButtons)
  621.   newButton("7", panelX + 9, panelY + 3, 3, 1, true, colors_lightblue, colors_white, showInventorySlotInfo, 7, robotInventoryButtons)
  622.   newButton("8", panelX + 13, panelY + 3, 3, 1, true, colors_lightblue, colors_white, showInventorySlotInfo, 8, robotInventoryButtons)
  623.  
  624.   newButton("9", panelX + 1, panelY + 5, 3, 1, true, colors_lightblue, colors_white, showInventorySlotInfo, 9, robotInventoryButtons)
  625.   newButton("10", panelX + 5, panelY + 5, 3, 1, true, colors_lightblue, colors_white, showInventorySlotInfo, 10, robotInventoryButtons)
  626.   newButton("11", panelX + 9, panelY + 5, 3, 1, true, colors_lightblue, colors_white, showInventorySlotInfo, 11, robotInventoryButtons)
  627.   newButton("12", panelX + 13, panelY + 5, 3, 1, true, colors_lightblue, colors_white, showInventorySlotInfo, 12, robotInventoryButtons)
  628.  
  629.   newButton("13", panelX + 1, panelY + 7, 3, 1, true, colors_lightblue, colors_white, showInventorySlotInfo, 13, robotInventoryButtons)
  630.   newButton("14", panelX + 5, panelY + 7, 3, 1, true, colors_lightblue, colors_white, showInventorySlotInfo, 14, robotInventoryButtons)
  631.   newButton("15", panelX + 9, panelY + 7, 3, 1, true, colors_lightblue, colors_white, showInventorySlotInfo, 15, robotInventoryButtons)
  632.   newButton("16", panelX + 13, panelY + 7, 3, 1, true, colors_lightblue, colors_white, showInventorySlotInfo, 16, robotInventoryButtons)
  633.  
  634.   drawButtons(robotInventoryButtons)
  635. end
  636.  
  637.  
  638. function getInventory()
  639.   inventoryToggle = true
  640.   sendMsgToRobot("GET_INV")
  641.  
  642. end
  643.  
  644. function showInventorySlotInfo(slot)
  645.   local panelX = 117
  646.   local panelY = 3
  647.   local panelSizeX = 43
  648.   local panelSizeY = 9
  649.   local panel_BGColor = colors_silver
  650.   checkInventory(slot)
  651.  
  652.   setBgColor(panel_BGColor)
  653.   renderLine(panelX, panelY, panelSizeX, panelSizeY)
  654.     setCursorPos(1, 1)
  655.     renderText(tostring(type(robotInventorySlot)))
  656.     if type(robotInventorySlot) == "table" then
  657.         ia = 0
  658.       for k , v in pairs(robotInventorySlot) do
  659.         ia = ia +1
  660.         setCursorPos(panelX+1, panelY+ia)
  661.         renderText(k..": "..tostring(v))
  662.       end
  663.     else
  664.       setCursorPos(panelX+1, panelY+1)
  665.       renderText(robotInventorySlot)
  666.     end
  667.      
  668. end
  669.  
  670. function checkInventory(slot)
  671.  
  672.  
  673.   robotInventorySlot = robotInventory[slot]
  674.  
  675. end
  676.  
  677.  
  678. function displayAspects()
  679.   local x = 2
  680.   local y = 2
  681.   local primalAspects = {
  682.     ["Aer"] = {aspect = "air", color = 0x87CEFA},
  683.     ["Terra"] = {aspect = "earth", color = 0x228B22},
  684.     ["Ignis"] = {aspect = "fire", color = 0xFF4500},
  685.     ["Aqua"] = {aspect = "water", color = 0x1E90FF},
  686.     ["Ordo"] = {aspect = "order", color = 0xF5DEB3},
  687.     ["Perditio"] = {aspect = "entropy", color = 0xA9A9A9}
  688.   }
  689.  
  690.   local compoundAspects = {
  691.     ["Alienis"] = {aspect = "strange", color = 0xFF00FF},
  692.     ["Arbor"] = {aspect = "tree", color = 0x228B22},
  693.     ["Bestia"] = {aspect = "beast", color = 0xA0522D},
  694.     ["Cognitio"] = {aspect = "knowledge", color = 0xFFD700},
  695.     ["Corpus"] = {aspect = "body", color = 0x8B008B},
  696.     ["Exanimis"] = {aspect = "dead", color = 0x696969},
  697.     ["Herba"] = {aspect = "plant", color = 0x228B22},
  698.     ["Humanus"] = {aspect = "man", color = 0xFF69B4},
  699.     ["Instrumentum"] = {aspect = "tool", color = 0xA9A9A9},
  700.     ["Lucrum"] = {aspect = "profit", color = 0xFFD700},
  701.     ["Machina"] = {aspect = "machine", color = 0xA9A9A9},
  702.     ["Metallum"] = {aspect = "Metal", color = 0xA9A9A9},
  703.     ["Mortuus"] = {aspect = "dead", color = 0x696969},
  704.     ["Praecantatio"] = {aspect = "magic", color = 0xFF00FF},
  705.     ["Sensus"] = {aspect = "sense", color = 0x00FF00},
  706.     ["Spiritus"] = {aspect = "spirit", color = 0x0000FF},
  707.     ["Vacuos"] = {aspect = "void", color = 0xA9A9A9},
  708.     ["Vitium"] = {aspect = "vice", color = 0x8B008B}
  709.   }
  710.     setBgColor(colors_lightgray)
  711.      renderLine(x, y, 158, 48)
  712.  
  713.     setBgColor(colors_black)
  714.      renderLine(x+1, y+1, 17, 6)
  715.  
  716.     setFgColor(colors_white)
  717.      setCursorPos(x+3, y)
  718.       renderText("Primal Aspects")
  719.  
  720.   for _, aspectData in pairs(primalAspects) do  
  721.     setFgColor(aspectData.color)
  722.      setCursorPos(x+3, y+1)
  723.       y = y + 1
  724.        renderText(aspectData.aspect)
  725.   end
  726. y = 10
  727.    setBgColor(colors_black)
  728.     renderLine(x+1, y, 19, 20)
  729.  
  730.  setFgColor(colors_white)
  731.   setCursorPos(x+3, y)
  732.    renderText("Compound Aspects")
  733.   for _, aspectData in pairs(compoundAspects) do
  734.     y = y+1
  735.       setFgColor(aspectData.color)
  736.        setCursorPos(x+3, y)
  737.         renderText(aspectData.aspect)
  738.    
  739.   end
  740. end
  741.  
  742.  
  743.  
  744.  
  745. switchScreens(primaryScreen)
  746. term.clear()
  747. -- Initialize the first console UI
  748. init_Consol_01 ()
  749. -- Initialize the second console UI
  750. init_Consol_02 ()
  751.  
  752. -- Draw the first console UI
  753. drawConsole_01()
  754. -- Draw the second console UI
  755. drawConsole_02()
  756.  
  757. -- Draw the navigation panel for the robot
  758. drawRobotNavPanel()
  759.  
  760. -- Draw the actions panel for the robot
  761. drawRobotActionsPanel()
  762.  
  763. drawInventoryPanel()
  764.  
  765. switchScreens(secondaryScreen)
  766. term.clear()
  767. displayAspects()
  768.  
  769. switchScreens(primaryScreen)
  770.  
  771.  
  772.  
  773.  
  774.  
  775. -- Continuously check for events
  776. while true do
  777.   -- Call the checkForEvents function to handle any incoming events
  778.   checkForEvents()
  779. end
  780.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement