MrRobar35

Untitled

Feb 4th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.70 KB | None | 0 0
  1. local comp = require('component')
  2. local buffer = require("doubleBuffering")
  3. local GUI = require("GUI")
  4. local computer = require("computer")
  5. local event = require("event")
  6. local ship = require("libwarp")
  7. --Переменные, массивы, прочая хрень
  8.  
  9. buffer.setResolution(80,25)
  10.  
  11. local colors = {
  12. background = 0xFFFFFF,
  13. panel = 0x000000,
  14. window = 0xb3b3b3,
  15. textColor = 0x000000,
  16. textColor2 = 0xFFFFFF,
  17. button = 0x000082,
  18. buttonPressed = 0x00004d,
  19. buttonYes = 0x00FF00,
  20. buttonNo = 0xFF0000,
  21. }
  22.  
  23.  
  24. -----
  25. local mainContainer = GUI.fullScreenContainer()
  26. mainContainer:addChild(GUI.panel(1, 1, mainContainer.width, mainContainer.height, colors.background))
  27. local navContainer = mainContainer:addChild(GUI.container(18,3,62,21))
  28. local infoContainer = mainContainer:addChild(GUI.container(1,2,16,23))
  29. -----
  30. local function jumpHyper()
  31.  
  32. end
  33.  
  34. local function CoreScreenFix()
  35. comp.gpu.bind(comp.screen.address,true)
  36. buffer.setResolution(80,25)
  37. end
  38.  
  39. local function slept(timeout)
  40. checkArg(1, timeout, "number", "nil")
  41. local deadline = computer.uptime() + (timeout or 0)
  42. repeat
  43. computer.pullSignal(deadline - computer.uptime())
  44. until computer.uptime() >= deadline
  45. end
  46.  
  47. local function drawNav()
  48. local sx,sy,sz,planet = shipcon.position()
  49. local pos
  50. infoContainer:addChild(GUI.label(1,2,15,1,colors.textColor2,'Координаты:')):setAlignment(GUI.alignment.horizontal.center, GUI.alignment.vertical.center)
  51. infoContainer:addChild(GUI.label(1,3,15,1,colors.textColor2,'X: '..sx)):setAlignment(GUI.alignment.horizontal.center, GUI.alignment.vertical.center)
  52. infoContainer:addChild(GUI.label(1,4,15,1,colors.textColor2,'Y: '..sy)):setAlignment(GUI.alignment.horizontal.center, GUI.alignment.vertical.center)
  53. infoContainer:addChild(GUI.label(1,5,15,1,colors.textColor2,'Z: '..sz)):setAlignment(GUI.alignment.horizontal.center, GUI.alignment.vertical.center)
  54. infoContainer:addChild(GUI.label(1,7,15,1,colors.textColor2,'Пространство:')):setAlignment(GUI.alignment.horizontal.center, GUI.alignment.vertical.center)
  55. if shipcon.isInSpace() == true or planet == 'Asteroids' then
  56. pos = 'Космос'
  57. elseif shipcon.isInHyperspace() == true then
  58. pos = 'Гипер'
  59. else
  60. pos = 'Планета '..planet..''
  61. end
  62. infoContainer:addChild(GUI.label(1,8,15,2,colors.textColor2,pos)):setAlignment(GUI.alignment.horizontal.center, GUI.alignment.vertical.center)
  63. end
  64.  
  65. local function drawIRCSettrings()
  66. navContainer:addChild(GUI.panel(1, 1, navContainer.width, navContainer.height, colors.window))
  67. navContainer:addChild(GUI.label(1, 1, 61, 1, colors.button, "Настройки IRC")):setAlignment(GUI.alignment.horizontal.center, GUI.alignment.vertical.center)
  68. navContainer:addChild(GUI.label(2, 4, 8, 1, colors.textColor, 'Никнейм'))
  69. navContainer:addChild(GUI.input(2, 5, 30, 1, 0xEEEEEE, 0x555555, 0x999999, 0xFFFFFF, 0x2D2D2D, "", "nickname"))
  70. navContainer:addChild(GUI.label(2, 7, 12, 1, colors.textColor, 'Адрес сервера'))
  71. navContainer:addChild(GUI.input(2, 8, 30, 1, 0xEEEEEE, 0x555555, 0x999999, 0xFFFFFF, 0x2D2D2D, "", "irc.name.domain:port"))
  72. navContainer:addChild(GUI.label(2, 10, 5, 1, colors.textColor, 'Канал'))
  73. navContainer:addChild(GUI.input(2, 11, 30, 1, 0xEEEEEE, 0x555555, 0x999999, 0xFFFFFF, 0x2D2D2D, "", "#channel"))
  74. navContainer:addChild(GUI.switchAndLabel(2, 13, 25, 8, colors.button, 0x1D1D1D, 0xEEEEEE, 0x000000, "Отправлять в ЛС", false)).switch.onStateChanged = function(state)
  75. if state == true then
  76. navContainer:addChild(GUI.label(2, 14, 15, 1, colors.textColor, 'Кому отправлять'))
  77. navContainer:addChild(GUI.input(2, 15, 30, 1, 0xEEEEEE, 0x555555, 0x999999, 0xFFFFFF, 0x2D2D2D, "", "nickname"))
  78. else
  79. navContainer:addChild(GUI.panel(2, 14, 59, 7, colors.window))
  80. end
  81. end
  82. end
  83.  
  84. local function drawJump()
  85. local _,max = shipcon.getMaxJumpDistance()
  86. local jumpX = 0
  87. local jumpY = 0
  88. local jumpZ = 0
  89. local rot = 0
  90. local type
  91. navContainer:deleteChildren()
  92. navContainer:addChild(GUI.panel(1, 1, navContainer.width, navContainer.height, colors.window))
  93. navContainer:addChild(GUI.label(1, 1, 61, 1, colors.button, "Прыжок")):setAlignment(GUI.alignment.horizontal.center, GUI.alignment.vertical.center)
  94. navContainer:addChild(GUI.label(2, 3, 9, 1, 0x555555, 'Максимум: '..max))
  95. navContainer:addChild(GUI.label(2, 4, 8, 1, 0x555555, "Все значения выше максимума будут выравнены автоматически."))
  96. navContainer:addChild(GUI.label(2, 6, 16, 1, colors.textColor, 'Ось перед-зад'))
  97. navContainer:addChild(GUI.input(2, 7, 30, 1, 0xEEEEEE, 0x555555, 0x999999, 0xFFFFFF, 0x2D2D2D, "0", "X")).onInputFinished = function(navContainer, input, eventData, text)
  98. jumpX = tonumber(text)
  99. if not jumpX then input.text = "" input.placeholderText = "Введите число!" jumpX = 0 return end
  100. if jumpX >= max then jumpX = max input.text = jumpX return end
  101. if jumpX <= -max then jumpX = -max input.text = jumpX return end
  102. end
  103. navContainer:addChild(GUI.label(2, 9, 12, 1, colors.textColor, 'Ось верх-низ'))
  104. navContainer:addChild(GUI.input(2, 10, 30, 1, 0xEEEEEE, 0x555555, 0x999999, 0xFFFFFF, 0x2D2D2D, "0", "Y")).onInputFinished = function(navContainer, input, eventData, text)
  105. jumpY = tonumber(text)
  106. if not jumpY then input.text = "" input.placeholderText = "Введите число!" jumpY = 0 return end
  107. if jumpY >= max then jumpY = max input.text = jumpY return end
  108. if jumpY <= -max then jumpY = -max input.text = jumpY return end
  109. end
  110. navContainer:addChild(GUI.label(2, 12, 14, 1, colors.textColor, 'Ось лево-право'))
  111. navContainer:addChild(GUI.input(2, 13, 30, 1, 0xEEEEEE, 0x555555, 0x999999, 0xFFFFFF, 0x2D2D2D, "0", "Z")).onInputFinished = function(navContainer, input, eventData, text)
  112. jumpZ = tonumber(text)
  113. if not jumpZ then input.text = "" input.placeholderText = "Введите число!" jumpZ = 0 return end
  114. if jumpZ >= max then jumpZ = max input.text = jumpZ return end
  115. if jumpZ <= -max then jumpZ = -max input.text = jumpZ return end
  116. end
  117. navContainer:addChild(GUI.label(2, 15, 14, 1, colors.textColor, 'Разворот'))
  118. navContainer:addChild(GUI.input(2, 16, 30, 1, 0xEEEEEE, 0x555555, 0x999999, 0xFFFFFF, 0x2D2D2D, "0", "R")).onInputFinished = function(navContainer, input, eventData, text)
  119. rot = tonumber(text)
  120. if not rot then input.text = "" input.placeholderText = "Введите число!" rot = 0 return end
  121. if rot >= max then rot = max input.text = rot return end
  122. if rot <= -max then rot = -max input.text = rot return end
  123. end
  124. navContainer:addChild(GUI.button(2, 18, 29, 3, colors.button, colors.textColor2, colors.buttonPressed, colors.textColor2, "Совершить прыжок"))
  125. navContainer:addChild(GUI.button(33, 18, 29, 3, colors.button, colors.textColor2, colors.buttonPressed, colors.textColor2, "Совершить гипер-переход"))
  126. end
  127.  
  128. local function drawInfo()
  129. local size = shipcon.getShipSize()
  130. local assembly = shipcon.isAssemblyValid()
  131. local energy = shipcon.energy()
  132. local back,left,down = shipcon.dim_negative()
  133. local front,right,up = shipcon.dim_positive()
  134. local ass
  135. if assembly then ass = "правильная" else ass = "неправильная" end
  136. navContainer:addChild(GUI.panel(1, 1, navContainer.width, navContainer.height, colors.window))
  137. navContainer:addChild(GUI.label(1, 1, 61, 1, colors.button, "Информация о корабле")):setAlignment(GUI.alignment.horizontal.center, GUI.alignment.vertical.center)
  138. navContainer:addChild(GUI.label(2, 3, 61, 1, colors.textColor, "Масса корабля: "..size.." блоков"))
  139. navContainer:addChild(GUI.label(2, 5, 61, 1, colors.textColor, "Сборка корабля: "..ass))
  140. navContainer:addChild(GUI.label(2, 7, 61, 1, colors.textColor, "Накоплено энергии: "..energy.." EU"))
  141. navContainer:addChild(GUI.label(53, 3, 61, 1, colors.textColor, "Габариты: "))
  142. navContainer:addChild(GUI.label(53, 5, 61, 1, colors.textColor, "Зад: "..back))
  143. navContainer:addChild(GUI.label(53, 7, 61, 1, colors.textColor, "Лево: "..left))
  144. navContainer:addChild(GUI.label(53, 9, 61, 1, colors.textColor, "Низ: "..down))
  145. navContainer:addChild(GUI.label(53, 11, 61, 1, colors.textColor, "Перед: "..front))
  146. navContainer:addChild(GUI.label(53, 13, 61, 1, colors.textColor, "Право: "..right))
  147. navContainer:addChild(GUI.label(53, 15, 61, 1, colors.textColor, "Верх: "..up))
  148. end
  149.  
  150. local function drawRadar()
  151. if not comp.isAvailable("warpdriveRadar") then GUI.error("Для работы этой функции необходим варп-радар!") return end
  152. local max = 9999
  153. local radius = 1
  154. navContainer:addChild(GUI.panel(1, 1, navContainer.width, navContainer.height, colors.window))
  155. navContainer:addChild(GUI.label(1, 1, 61, 1, colors.button, "Варп-радар")):setAlignment(GUI.alignment.horizontal.center, GUI.alignment.vertical.center)
  156. local textBox = navContainer:addChild(GUI.textBox(2, 9, 60, 12, 0xEEEEEE, 0x2D2D2D, {}, 1, 1, 0))
  157. navContainer:addChild(GUI.label(2, 3, 9, 1, 0x555555, 'Максимум радиуса: '..max))
  158. navContainer:addChild(GUI.label(2, 4, 8, 1, 0x555555, "Все значения выше максимума будут выравнены автоматически."))
  159. navContainer:addChild(GUI.label(2, 6, 16, 1, colors.textColor, 'Радиус поиска '))
  160. navContainer:addChild(GUI.input(2, 7, 30, 1, 0xEEEEEE, 0x555555, 0x999999, 0xFFFFFF, 0x2D2D2D, "1", "Радиус")).onInputFinished = function(navContainer, input, eventData, text)
  161. radius = tonumber(text)
  162. if not radius then input.text = "" input.placeholderText = "Введите число!" radius = 0 return end
  163. if radius >= max then radius = max input.text = radius return end
  164. if radius < 1 then radius = 1 input.text = radius end
  165. end
  166. navContainer:addChild(GUI.button(33, 7, 29, 1, colors.button, colors.background, colors.buttonPressed, 0xFFFFFF, "Сканировать")).onTouch = function(navContainer, button, eventData, text)
  167. if comp.warpdriveRadar.getEnergyRequired(radius) > comp.warpdriveRadar.energy() then GUI.error("Ошибка: недостаточно энергии.\nНакоплено "..comp.warpdriveRadar.energy().." EU\nНеобходимо еще "..comp.warpdriveRadar.getEnergyRequired(radius) - comp.warpdriveRadar.energy().." EU") return end
  168. comp.warpdriveRadar.radius(radius)
  169. comp.warpdriveRadar.start()
  170. slept(0.5)
  171. button.text = "Сканирование ("..comp.warpdriveRadar.getScanDuration(radius).."s)"
  172. slept(comp.warpdriveRadar.getScanDuration(radius))
  173. button.text = "Сканировать"
  174. textBox.lines = {}
  175. local delay = 0
  176. local count
  177. repeat
  178. count = comp.warpdriveRadar.getResultsCount()
  179. slept(0.1)
  180. delay = delay + 1
  181. until (count ~= nil and count ~= -1) or delay > 10
  182. if count ~= nil and count > 0 then
  183. for i=0,count-1 do
  184. success, type, name, x, y, z = comp.warpdriveRadar.getResult(i)
  185. if success then
  186. table.insert(textBox.lines,type.." "..name.." ".." @ ("..x.." "..y.." "..z..")")
  187. end
  188. end
  189. else
  190. table.insert(textBox.lines,"Ничего не найдено.")
  191. end
  192. end
  193. end
  194. local function drawCrew()
  195. navContainer:addChild(GUI.panel(1, 1, navContainer.width, navContainer.height, colors.window))
  196. navContainer:addChild(GUI.label(1, 1, 61, 1, colors.button, "Экипаж")):setAlignment(GUI.alignment.horizontal.center, GUI.alignment.vertical.center)
  197. end
  198. -----------------------------------------------------------------------------
  199.  
  200. --верхняя панель
  201.  
  202. local menu = mainContainer:addChild(GUI.menu(1, 1, mainContainer.width, colors.panel, 0x666666, 0x3366CC, 0xFFFFFF, 0.7))
  203. menu:addItem("Interstellar", 0x0)
  204. local mSettings = menu:addItem("Настройки")
  205. local mAbout = menu:addItem("О программе")
  206. local mExit = menu:addItem("Выход")
  207. mSettings.onTouch = function(eventData)
  208. local contextMenu = GUI.contextMenu(mSettings.x, mSettings.y + 1)
  209. contextMenu:addItem("Общие")
  210. contextMenu:addItem("Корабль")
  211. contextMenu:addItem("IRC").onTouch = function()
  212. drawIRCSettrings()
  213. end
  214. contextMenu:show()
  215. end
  216. mExit.onTouch = function(eventData)
  217. mainContainer:stopEventHandling()
  218. os.execute('/bin/sh.lua')
  219. end
  220.  
  221. --панель с точками
  222.  
  223. infoContainer:addChild(GUI.panel(1,1,infoContainer.width,infoContainer.height,colors.button,0.1))
  224.  
  225. --кнопочки
  226.  
  227. mainContainer:addChild(GUI.button(18,25,8,1,colors.button,colors.background,colors.buttonPressed,colors.background,'Экипаж'))
  228. mainContainer:addChild(GUI.button(27,25,8,1,colors.button,colors.background,colors.buttonPressed,colors.background,'Прыжок')).onTouch = function()
  229. drawJump()
  230. end
  231. mainContainer:addChild(GUI.button(36,25,6,1,colors.button,colors.background,colors.buttonPressed,colors.background,'Инфо')).onTouch = function()
  232. drawInfo()
  233. end
  234. mainContainer:addChild(GUI.button(43,25,7,1,colors.button,colors.background,colors.buttonPressed,colors.background,'Радар')).onTouch = function()
  235. drawRadar()
  236. end
  237. mainContainer:addChild(GUI.button(51,25,12,1,colors.button,colors.background,colors.buttonPressed,colors.background,'Маскировка'))
  238. mainContainer:addChild(GUI.button(71,25,7,1,colors.button,colors.background,colors.buttonPressed,colors.background,'Карта')).onTouch = function()
  239.  
  240. end
  241. mainContainer:addChild(GUI.button(79,25,2,1,colors.button,colors.background,colors.button,colors.background,''))
  242. mainContainer:addChild(GUI.button(64,25,6,1,colors.button,colors.background,colors.button,colors.background,''))
  243. mainContainer:addChild(GUI.button(1,25,16,1,colors.button,colors.background,colors.button,colors.background,''))
  244. infoContainer:addChild(GUI.button(1,infoContainer.height,5,1,0xFFFFFF,0x000000,0xFFFFFF,0x000000,"upd")).onTouch = function()
  245. drawNav()
  246. end
  247. drawNav()
  248.  
  249. -----------------------------------------------------------------------------
  250. buffer.clear()
  251. mainContainer:draw()
  252. buffer.draw(true)
  253. mainContainer:startEventHandling()
Advertisement
Add Comment
Please, Sign In to add comment