Gintarus

ls

Jul 1st, 2026 (edited)
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.44 KB | None | 0 0
  1. local component = require("component")
  2. local event = require("event")
  3. local computer = require("computer")
  4. local keyboard = require("keyboard")
  5. local unicode = require("unicode")
  6. local gpu = component.gpu
  7.  
  8. local function get(...)
  9. for _, n in ipairs({...}) do
  10. local a = component.list(n)()
  11. if a then return component.proxy(a) end
  12. end
  13. return nil
  14. end
  15.  
  16. local rf = get("draconic_rf_storage")
  17. local gate = get("flux_gate")
  18. local me = get("me_interface", "ae2_interface")
  19. local chat = get("chat_box")
  20. local opb = get("openperipheral_bridge", "terminal_glasses_bridge", "terminal")
  21. local sensor = get("sensor", "radar")
  22.  
  23. if chat then chat.setName("§3[PRISMA CORE]§r") end
  24. local w, h = gpu.getResolution()
  25. local col1_w, col4_w, col3_w = 28, 32, 30
  26. local col2_w = w - col1_w - col3_w - col4_w - 3
  27.  
  28. local cfg = {
  29. target = 200 * 10^9,
  30. maxDiff = 25000, step = 10000, flowMin = 1000, flowMax = 40000000,
  31. ar_chat_enabled = true, ar_radar_enabled = true, ar_me_enabled = true,
  32. hudX = 2, hudY = 2,
  33. hudW = 260,
  34. ar_chat_width = 35,
  35. me_name = "dwcity:Vis_materia",
  36. me_label = "Вис Материя",
  37. playerConfig = {
  38. ignore = {"GintaRus"},
  39. prefixes = { ["123"] = "[Чорт]", ["Noney"] = "[Girl]" }
  40. }
  41. }
  42.  
  43. local lastE, filVal, currentFlow = 0, 0, 0
  44. local chatLog, arChatLog, nearbyPlayers, buttons = {}, {}, {}, {}
  45. local showFlowMenu, showIgnoreMenu, needFullRedraw, chatUpdated = false, false, true, true
  46. local ar_error = nil
  47. local matter_current, matter_last, matter_rate, me_timer = 0, 0, 0, 0
  48. local tick_counter = 0
  49.  
  50. local C = {
  51. BG = 0x02060D, FRAME = 0x1A4059, FRAME_DIM = 0x0C1F2E,
  52. TEXT_MAIN = 0x00E5FF, TEXT_DIM = 0x4A7B9C, TEXT_WHITE = 0xE0F7FA,
  53. ALERT = 0xFF2A2A, OK = 0x00FF9D, BTN_OFF = 0x0B1B26, BTN_ON = 0x004D40
  54. }
  55.  
  56. local mc_colors = {
  57. ["0"]=0x000000, ["1"]=0x0000AA, ["2"]=0x00AA00, ["3"]=0x00AAAA,
  58. ["4"]=0xAA0000, ["5"]=0xAA00AA, ["6"]=0xFFAA00, ["7"]=0xAAAAAA,
  59. ["8"]=0x555555, ["9"]=0x5555FF, ["a"]=0x55FF55, ["b"]=0x55FFFF,
  60. ["c"]=0xFF5555, ["d"]=0xFF55FF, ["e"]=0xFFFF55, ["f"]=0xFFFFFF, ["r"]=C.TEXT_WHITE
  61. }
  62.  
  63. local function clamp(v, a, b) if v < a then return a end; if v > b then return b end; return v end
  64. local function formatNum(n)
  65. if type(n) ~= "number" or n ~= n then return "0" end
  66. local absN = math.abs(n)
  67. if absN >= 10^9 then return string.format("%.2fG", n / 10^9) end
  68. if absN >= 10^6 then return string.format("%.2fM", n / 10^6) end
  69. if absN >= 10^3 then return string.format("%.1fk", n / 10^3) end
  70. return tostring(math.floor(n))
  71. end
  72.  
  73. local function text(x, y, s, fg, bg)
  74. if fg then gpu.setForeground(fg) end
  75. if bg then gpu.setBackground(bg) else gpu.setBackground(C.BG) end
  76. gpu.set(x, y, s)
  77. end
  78.  
  79. local function drawTechFrame(x, y, bw, bh, title)
  80. gpu.setBackground(C.BG); gpu.setForeground(C.FRAME)
  81. gpu.set(x, y, "┌" .. string.rep("─", bw - 2) .. "┐")
  82. for i = 1, bh - 2 do gpu.set(x, y + i, "│"); gpu.set(x + bw - 1, y + i, "│") end
  83. gpu.set(x, y + bh - 1, "└" .. string.rep("─", bw - 2) .. "┘")
  84. if title then text(x + 2, y, "┤ " .. title .. " ├", C.TEXT_MAIN, C.BG) end
  85. end
  86.  
  87. local function drawButton(id, x, y, bw, bh, label, bg, fg)
  88. buttons[id] = {x = x, y = y, w = bw, h = bh}
  89. gpu.setBackground(bg); gpu.setForeground(fg)
  90. gpu.fill(x, y, bw, bh, " ")
  91. local lx = x + math.floor((bw - unicode.wlen(label)) / 2)
  92. local ly = y + math.floor(bh / 2)
  93. gpu.set(lx, ly, label); gpu.setBackground(C.BG)
  94. end
  95.  
  96. local function drawColoredText(x, y, textLine, defaultColor)
  97. gpu.setBackground(C.BG)
  98. local cx, currentColor = x, defaultColor or C.TEXT_WHITE
  99. local safeText = textLine:gsub("§", "&")
  100. local lastIdx = 1
  101. while lastIdx <= #safeText do
  102. local idx = safeText:find("&", lastIdx, true)
  103. if not idx then
  104. gpu.setForeground(currentColor); gpu.set(cx, y, safeText:sub(lastIdx)); break
  105. end
  106. if idx > lastIdx then
  107. local chunk = safeText:sub(lastIdx, idx - 1)
  108. gpu.setForeground(currentColor); gpu.set(cx, y, chunk)
  109. cx = cx + unicode.wlen(chunk)
  110. end
  111. local colorCode = safeText:sub(idx + 1, idx + 1):lower()
  112. if mc_colors[colorCode] then currentColor = mc_colors[colorCode]; lastIdx = idx + 2
  113. else gpu.setForeground(currentColor); gpu.set(cx, y, "&"); cx = cx + 1; lastIdx = idx + 1 end
  114. end
  115. end
  116.  
  117. local function fetchMatterAmount()
  118. if not me then return 0 end
  119. local amount = 0
  120. pcall(function()
  121. local items = nil
  122. if me.getItemsInNetwork then items = me.getItemsInNetwork()
  123. elseif me.getAvailableItems then items = me.getAvailableItems() end
  124. if type(items) == "table" then
  125. for i = 1, #items do
  126. local v = items[i]
  127. if v and (v.name == cfg.me_name or v.label == cfg.me_label) then
  128. amount = v.size or v.amount or 0
  129. break
  130. end
  131. end
  132. end
  133. end)
  134. return amount
  135. end
  136.  
  137. local function wrapText(textStr, maxW)
  138. local lines = {}
  139. local currentLine = ""
  140. for word in textStr:gmatch("%S+") do
  141. if unicode.wlen(currentLine) + unicode.wlen(word) + 1 > maxW then
  142. if currentLine ~= "" then table.insert(lines, currentLine) end
  143. currentLine = word
  144. while unicode.wlen(currentLine) > maxW do
  145. table.insert(lines, unicode.sub(currentLine, 1, maxW))
  146. currentLine = unicode.sub(currentLine, maxW + 1)
  147. end
  148. else
  149. currentLine = currentLine == "" and word or (currentLine .. " " .. word)
  150. end
  151. end
  152. if currentLine ~= "" then table.insert(lines, currentLine) end
  153. return lines
  154. end
  155.  
  156. local function updateAR()
  157. if not opb then return end
  158. local success, err = pcall(function()
  159. opb.clear()
  160. local leftColH = 8
  161. if cfg.ar_radar_enabled then leftColH = leftColH + 12 + (#nearbyPlayers > 0 and #nearbyPlayers * 8 or 8) end
  162. if cfg.ar_me_enabled then leftColH = leftColH + 30 end
  163. local rightColH = 8
  164. if cfg.ar_chat_enabled then rightColH = rightColH + 8 + (#arChatLog * 8) end
  165. local totalH = math.max(leftColH, rightColH) + 10
  166. if totalH < 25 then totalH = 25 end
  167. local bx, by, bw = cfg.hudX, cfg.hudY, cfg.hudW
  168. opb.addBox(bx, by, bw, totalH, 0x050F1A, 0.4)
  169. opb.addBox(bx, by, bw, 1, 0x00E5FF, 0.5)
  170. opb.addBox(bx, by + totalH - 1, bw, 1, 0x00E5FF, 0.5)
  171. local divX = bx + 95
  172. opb.addBox(divX, by + 2, 1, totalH - 4, 0x1A4059, 0.5)
  173. local leftX = bx + 5
  174. local rightX = divX + 5
  175. local curY = by + 3
  176. if cfg.ar_radar_enabled then
  177. opb.addText(leftX, curY, "CONTACTS IN RANGE", 0xFF2A2A).setScale(0.7)
  178. curY = curY + 11
  179. if #nearbyPlayers == 0 then
  180. opb.addText(leftX, curY, "NO CONTACTS", 0x4A7B9C).setScale(0.7)
  181. curY = curY + 9
  182. else
  183. for _, pName in ipairs(nearbyPlayers) do
  184. opb.addText(leftX, curY, pName, 0xFF7A7A).setScale(0.7)
  185. curY = curY + 9
  186. end
  187. end
  188. curY = curY + 4
  189. end
  190. if cfg.ar_me_enabled then
  191. opb.addText(leftX, curY, "TRACKING: VIS", 0x00FF9D).setScale(0.7)
  192. curY = curY + 10
  193. opb.addText(leftX, curY, "Храниться: " .. formatNum(matter_current), 0xE0F7FA).setScale(0.7)
  194. curY = curY + 8
  195. local rateSign = matter_rate >= 0 and "+" or ""
  196. opb.addText(leftX, curY, string.format("STATUS: %s%s/min", rateSign, formatNum(matter_rate)), 0x00E5FF).setScale(0.7)
  197. end
  198. if cfg.ar_chat_enabled then
  199. local chatY = by + 3
  200. for _, item in ipairs(arChatLog) do
  201. if item.type == "name" then opb.addText(rightX, chatY, item.text, 0x00E5FF).setScale(0.7)
  202. else local cleanMsg = item.text:gsub("^> ", ""); opb.addText(rightX, chatY, cleanMsg, 0xE0F7FA).setScale(0.7) end
  203. chatY = chatY + 9
  204. end
  205. end
  206. opb.sync()
  207. end)
  208. if not success then ar_error = tostring(err) else ar_error = nil end
  209. end
  210.  
  211. local function addChatMessage(name, msg)
  212. if msg:sub(1,1) == "!" then return end
  213. local pc_max_w = col2_w - 6
  214. local prefixLen = unicode.wlen(name) + 4
  215. local wrappedPC = wrapText(msg, pc_max_w - prefixLen)
  216. for i, line in ipairs(wrappedPC) do
  217. if i == 1 then table.insert(chatLog, string.format("&8> &b%s&8:&f %s", name, line))
  218. else table.insert(chatLog, "&f " .. line) end
  219. end
  220. local maxChatLines = h - 7
  221. while #chatLog > maxChatLines do table.remove(chatLog, 1) end
  222. table.insert(arChatLog, {type = "name", text = name})
  223. local wrappedAR = wrapText(msg, cfg.ar_chat_width)
  224. for _, line in ipairs(wrappedAR) do table.insert(arChatLog, {type = "msg", text = "> " .. line}) end
  225. while #arChatLog > 12 do table.remove(arChatLog, 1) end
  226. chatUpdated = true; updateAR()
  227. end
  228.  
  229. local function scanEnvironment()
  230. nearbyPlayers = {}
  231. if sensor then
  232. pcall(function()
  233. local result = sensor.getPlayers()
  234. if type(result) == "table" then
  235. for k, v in pairs(result) do
  236. local pName = "Unknown"
  237. if type(v) == "table" and v.name then pName = v.name
  238. elseif type(v) == "string" then pName = v
  239. elseif type(k) == "string" then pName = k end
  240. if pName ~= "Unknown" then
  241. local isIgnored = false
  242. for _, ignoredName in ipairs(cfg.playerConfig.ignore) do if pName:lower() == ignoredName:lower() then isIgnored = true break end end
  243. if not isIgnored then
  244. local displayName = pName
  245. if cfg.playerConfig.prefixes[pName] then displayName = cfg.playerConfig.prefixes[pName] .. pName end
  246. table.insert(nearbyPlayers, displayName)
  247. end
  248. end
  249. end
  250. end
  251. end)
  252. end
  253. updateAR()
  254. end
  255.  
  256. local function drawStaticUI()
  257. gpu.setBackground(C.BG); gpu.fill(1, 1, w, h, " ")
  258. text(2, 1, "PRISMA NEURAL CORE v3.2 // SECURE UPLINK", C.TEXT_MAIN)
  259. text(w - 25, 1, "STATUS: INTEGRITY OK", C.OK)
  260. gpu.setForeground(C.FRAME); gpu.set(1, 2, string.rep("─", w))
  261. drawTechFrame(1, 3, col1_w, h - 3, "PWR MATRIX")
  262. drawTechFrame(col1_w + 2, 3, col2_w, h - 3, "TTY // COMMS")
  263. drawTechFrame(col1_w + col2_w + 3, 3, col3_w, math.floor(h/2) - 1, "RADAR TOPOGRAPHY")
  264. drawTechFrame(col1_w + col2_w + 3, math.floor(h/2) + 3, col3_w, h - math.floor(h/2) - 3, "ASSETS // ME")
  265. drawTechFrame(w - col4_w + 1, 3, col4_w, h - 3, "SYS CONTROLS")
  266. text(3, 5, "PWR LVL:", C.TEXT_DIM); text(3, 6, "TGT LVL:", C.TEXT_DIM); text(3, 7, "NET FLW:", C.TEXT_DIM)
  267. local by = h - 6
  268. drawButton("tplus", 3, by, 9, 1, "[+1G]", C.BTN_ON, C.OK); drawButton("tmid", 13, by, 3, 1, "%", C.BTN_OFF, C.TEXT_WHITE); drawButton("tminus", 17, by, 9, 1, "[-1G]", C.BTN_ON, C.ALERT)
  269. drawButton("flowcfg", 3, by + 2, col1_w - 4, 1, "OVERRIDE LIMITS", C.BTN_OFF, C.TEXT_MAIN)
  270. local barX, barY, barH = col1_w - 3, 9, h - 17
  271. for i = 0, 5 do local p = 100 - (i * 20); text(barX - 4, barY + math.floor((i/5)*(barH-1)), string.format("%3d", p), C.TEXT_DIM) end
  272. needFullRedraw = false; chatUpdated = true
  273. end
  274.  
  275. local function updateDynamicUI(flow)
  276. text(12, 5, string.format("%-9s", formatNum(lastE)), C.TEXT_WHITE)
  277. text(12, 6, string.format("%-9s", formatNum(cfg.target)), C.TEXT_MAIN)
  278. text(12, 7, string.format("%-9s", formatNum(flow or currentFlow)), (flow or 0) >= 0 and C.OK or C.ALERT)
  279.  
  280. local maxE = (rf and rf.getMaxEnergyStored and rf.getMaxEnergyStored()) or 1
  281. local pct = clamp(maxE > 0 and (lastE / maxE) or 0, 0, 1)
  282. local barX, barY, barH = col1_w - 3, 9, h - 17
  283. gpu.setBackground(C.FRAME_DIM)
  284. gpu.fill(barX, barY, 1, barH, " ")
  285. local filled = math.floor(pct * barH)
  286. for i = 0, filled - 1 do
  287. text(barX, barY + barH - 1 - i, "█", C.OK)
  288. end
  289. text(3, 9, string.format("LOAD: %5.1f%%", pct * 100), C.TEXT_WHITE)
  290. text(3, 10, "DIFF: " .. formatNum(lastE - cfg.target), math.abs(lastE - cfg.target) <= cfg.maxDiff and C.OK or C.ALERT)
  291. text(3, 11, "SMTH: " .. formatNum(filVal) .. "/t", C.TEXT_DIM)
  292.  
  293. if chatUpdated then
  294. local cx = col1_w + 4
  295. gpu.setBackground(C.BG)
  296. gpu.fill(cx, 4, col2_w - 4, h - 5, " ")
  297. for i, line in ipairs(chatLog) do
  298. if 3 + i < h then drawColoredText(cx, 3 + i, line, C.TEXT_WHITE) end
  299. end
  300. chatUpdated = false
  301. end
  302.  
  303. local rx = col1_w + col2_w + 5
  304. local ry = 5
  305. text(rx, ry, "SCAN COMPLETE.", C.TEXT_DIM)
  306. text(rx, ry + 2, "CONTACTS IN RANGE: " .. #nearbyPlayers, C.TEXT_WHITE)
  307. for i = 1, 5 do
  308. local yy = ry + 3 + i
  309. gpu.setBackground(C.BG)
  310. gpu.fill(rx, yy, col3_w - 4, 1, " ")
  311. if nearbyPlayers[i] then
  312. text(rx, yy, "> " .. unicode.sub(nearbyPlayers[i], 1, 24), C.ALERT)
  313. else
  314. text(rx, yy, string.rep(" ", col3_w - 5), C.TEXT_DIM)
  315. end
  316. end
  317.  
  318. local my = math.floor(h / 2) + 5
  319. local meStatus = me and "LINKED" or "OFFLINE"
  320. text(rx, my, "ADAPTER: " .. meStatus, me and C.OK or C.ALERT)
  321. text(rx, my + 2, cfg.me_label .. ": " .. formatNum(matter_current), C.TEXT_WHITE)
  322. local rateSign = matter_rate >= 0 and "+" or ""
  323. text(rx, my + 3, "RATE: " .. rateSign .. formatNum(matter_rate) .. "/min", matter_rate >= 0 and C.OK or C.ALERT)
  324. text(rx, my + 5, "ITEM: " .. unicode.sub(cfg.me_name, 1, 20), C.TEXT_DIM)
  325.  
  326. local sx = w - col4_w + 3
  327. local bridgeStatus = ar_error and "API ERROR" or (opb and "LINKED" or "OFFLINE")
  328. text(sx, 5, "AR BRIDGE: " .. bridgeStatus, ar_error and C.ALERT or (opb and C.OK or C.ALERT))
  329. drawButton("tog_chat", sx, 7, 12, 1, cfg.ar_chat_enabled and "[CHT:ON]" or "[CHT:OFF]", cfg.ar_chat_enabled and C.BTN_ON or C.BTN_OFF, cfg.ar_chat_enabled and C.OK or C.TEXT_DIM)
  330. drawButton("tog_radar", sx + 14, 7, 12, 1, cfg.ar_radar_enabled and "[RDR:ON]" or "[RDR:OFF]", cfg.ar_radar_enabled and C.BTN_ON or C.BTN_OFF, cfg.ar_radar_enabled and C.OK or C.TEXT_DIM)
  331. drawButton("tog_me", sx, 9, 12, 1, cfg.ar_me_enabled and "[ ME:ON]" or "[ ME:OFF]", cfg.ar_me_enabled and C.BTN_ON or C.BTN_OFF, cfg.ar_me_enabled and C.OK or C.TEXT_DIM)
  332.  
  333. drawButton("btn_ignore", sx, 11, 26, 1, "[MANAGE IGNORE LIST]", C.BTN_OFF, C.TEXT_WHITE)
  334. drawButton("btn_prefix", sx, 13, 26, 1, "[SET PLAYER PREFIX]", C.BTN_OFF, C.TEXT_MAIN)
  335.  
  336. if ar_error then
  337. text(sx, h - 5, unicode.sub("ERR: " .. tostring(ar_error), 1, col4_w - 6), C.ALERT)
  338. end
  339. if tick_counter % 2 == 0 then
  340. text(sx, h - 4, "SYS TICK: " .. string.format("%04X-%04X", math.random(0, 65535), math.random(0, 65535)), C.TEXT_DIM)
  341. text(sx, h - 3, "UPTIME: " .. formatNum(computer.uptime()) .. "s", C.TEXT_DIM)
  342. end
  343. end
  344.  
  345. local function drawFlowMenu()
  346. local mw, mh = 42, 8; local mx, my = math.floor((w - mw) / 2), math.floor((h - mh) / 2); gpu.setBackground(C.FRAME_DIM); gpu.fill(mx, my, mw, mh, " ")
  347. gpu.setForeground(C.TEXT_MAIN)
  348. gpu.set(mx + 2, my + 1, "/// OVERRIDE CONFIGURATION")
  349. gpu.setForeground(C.TEXT_WHITE)
  350. gpu.set(mx + 2, my + 3, string.format("FLOW MAX: %s RF/t", formatNum(cfg.flowMax)))
  351. drawButton("f_minus10m", mx + 2, my + 5, 8, 1, "-10M", 0x471C1C, C.ALERT)
  352. drawButton("f_minus1m", mx + 11, my + 5, 8, 1, "-1M", 0x471C1C, C.TEXT_WHITE)
  353. drawButton("f_plus1m", mx + 20, my + 5, 8, 1, "+1M", C.BTN_ON, C.TEXT_WHITE)
  354. drawButton("f_plus10m", mx + 29, my + 5, 8, 1, "+10M", C.BTN_ON, C.OK)
  355. drawButton("f_close", mx + 13, my + 6, 16, 1, "[ CLOSE ]", C.BTN_OFF, C.TEXT_WHITE)
  356. end
  357.  
  358. local function drawIgnoreMenu()
  359. local mw, mh = 46, 14
  360. local mx, my = math.floor((w - mw) / 2), math.floor((h - mh) / 2)
  361. gpu.setBackground(C.FRAME_DIM); gpu.fill(mx, my, mw, mh, " ")
  362. drawTechFrame(mx, my, mw, mh, "MANAGE IGNORE LIST")
  363.  
  364. local startY = my + 2
  365. if #cfg.playerConfig.ignore == 0 then
  366. text(mx + 4, startY + 2, "Ignore list is completely empty.", C.TEXT_DIM, C.FRAME_DIM)
  367. for i = 1, 6 do buttons["unig_" .. i] = nil end
  368. else
  369. for i = 1, 6 do
  370. local name = cfg.playerConfig.ignore[i]
  371. if name then
  372. text(mx + 3, startY + i - 1, string.format("%d. %-18s", i, name), C.TEXT_WHITE, C.FRAME_DIM)
  373. drawButton("unig_" .. i, mx + 30, startY + i - 1, 12, 1, "[REMOVE]", 0x471C1C, C.ALERT)
  374. else
  375. gpu.setBackground(C.FRAME_DIM); gpu.fill(mx + 3, startY + i - 1, mw - 6, 1, " ")
  376. buttons["unig_" .. i] = nil
  377. end
  378. end
  379. end
  380.  
  381. drawButton("ig_add", mx + 3, my + mh - 3, 16, 1, "[+ ADD PLAYER]", C.BTN_ON, C.OK)
  382. drawButton("ig_close", mx + mw - 15, my + mh - 3, 12, 1, "[CLOSE]", C.BTN_OFF, C.TEXT_WHITE)
  383. end
  384.  
  385. -- ИСПРАВЛЕНО: Прямое чтение Юникода из key_down и защита от фризов фокуса экрана
  386. local function readInput(title, promptText)
  387. while event.pull(0) do end -- Полная очистка буфера событий
  388.  
  389. local mw, mh = 54, 8
  390. local mx, my = math.floor((w - mw) / 2), math.floor((h - mh) / 2)
  391.  
  392. local textStr = ""
  393. local inputX = mx + 2 + unicode.wlen(promptText) + 2
  394. local maxInputW = mw - (inputX - mx) - 4
  395.  
  396. local needRedraw = true
  397.  
  398. while true do
  399. if needRedraw then
  400. gpu.setBackground(C.FRAME_DIM)
  401. gpu.fill(mx, my, mw, mh, " ")
  402. drawTechFrame(mx, my, mw, mh, title)
  403. text(mx + 2, my + 3, promptText .. ": ", C.TEXT_WHITE, C.FRAME_DIM)
  404.  
  405. gpu.setBackground(C.BTN_OFF)
  406. gpu.fill(inputX, my + 3, maxInputW, 1, " ")
  407. gpu.setForeground(C.TEXT_MAIN)
  408.  
  409. local displayText = textStr .. "|"
  410. gpu.set(inputX, my + 3, unicode.sub(displayText, -maxInputW + 1))
  411.  
  412. drawButton("inp_ok", mx + 6, my + 5, 16, 1, "[ OK ]", C.BTN_ON, C.OK)
  413. drawButton("inp_cancel", mx + 32, my + 5, 16, 1, "[ CANCEL ]", 0x471C1C, C.ALERT)
  414. needRedraw = false
  415. end
  416.  
  417. local ev, _, a1, a2, a3 = event.pull()
  418. if ev == "key_down" then
  419. if a2 == 28 then -- Enter
  420. break
  421. elseif a2 == 14 then -- Backspace
  422. if unicode.wlen(textStr) > 0 then
  423. textStr = unicode.sub(textStr, 1, -2)
  424. needRedraw = true
  425. end
  426. elseif a2 == 1 then -- Esc
  427. textStr = nil; break
  428. elseif a1 >= 32 then -- Любой печатный символ (буквы, цифры, русская/ENG раскладка)
  429. if unicode.wlen(textStr) < 25 then
  430. local ok, ch = pcall(unicode.char, a1)
  431. if ok and ch then
  432. textStr = textStr .. ch
  433. needRedraw = true
  434. end
  435. end
  436. end
  437. elseif ev == "touch" then
  438. local tx, ty = a1, a2
  439. if tx >= mx + 6 and tx < mx + 22 and ty == my + 5 then -- Клик по OK
  440. break
  441. elseif tx >= mx + 32 and tx < mx + 48 and ty == my + 5 then -- Клик по CANCEL
  442. textStr = nil; break
  443. end
  444. end
  445. end
  446.  
  447. buttons["inp_ok"] = nil
  448. buttons["inp_cancel"] = nil
  449. needFullRedraw = true
  450. return textStr
  451. end
  452.  
  453. local lastStats, lastScan = 0, 0; gpu.setResolution(w, h); gpu.setBackground(C.BG); gpu.fill(1, 1, w, h, " ")
  454. while true do
  455. local ev, addr, arg1, arg2, arg3, arg4 = event.pull(0.5)
  456. if ev == "chat_message" then addChatMessage(arg1, arg2)
  457. elseif ev == "touch" then
  458. local x, y = arg1, arg2
  459. if showFlowMenu then
  460. local b = buttons
  461. if b["f_close"] and x >= b["f_close"].x and x < b["f_close"].x + b["f_close"].w and y == b["f_close"].y then
  462. showFlowMenu = false
  463. needFullRedraw = true
  464. elseif b["f_minus10m"] and x >= b["f_minus10m"].x and x < b["f_minus10m"].x + b["f_minus10m"].w and y == b["f_minus10m"].y then
  465. cfg.flowMax = clamp(cfg.flowMax - 10000000, cfg.flowMin, 40000000)
  466. elseif b["f_minus1m"] and x >= b["f_minus1m"].x and x < b["f_minus1m"].x + b["f_minus1m"].w and y == b["f_minus1m"].y then
  467. cfg.flowMax = clamp(cfg.flowMax - 1000000, cfg.flowMin, 40000000)
  468. elseif b["f_plus1m"] and x >= b["f_plus1m"].x and x < b["f_plus1m"].x + b["f_plus1m"].w and y == b["f_plus1m"].y then
  469. cfg.flowMax = clamp(cfg.flowMax + 1000000, cfg.flowMin, 40000000)
  470. elseif b["f_plus10m"] and x >= b["f_plus10m"].x and x < b["f_plus10m"].x + b["f_plus10m"].w and y == b["f_plus10m"].y then
  471. cfg.flowMax = clamp(cfg.flowMax + 10000000, cfg.flowMin, 40000000)
  472. end
  473. if showFlowMenu then drawFlowMenu() end
  474.  
  475. elseif showIgnoreMenu then
  476. local b = buttons
  477. if b["ig_close"] and x >= b["ig_close"].x and x < b["ig_close"].x + b["ig_close"].w and y == b["ig_close"].y then
  478. showIgnoreMenu = false
  479. buttons["ig_close"] = nil; buttons["ig_add"] = nil
  480. for i = 1, 6 do buttons["unig_" .. i] = nil end
  481. needFullRedraw = true
  482. elseif b["ig_add"] and x >= b["ig_add"].x and x < b["ig_add"].x + b["ig_add"].w and y == b["ig_add"].y then
  483. local pName = readInput("ADD TO IGNORE", "Nickname")
  484. if pName and pName ~= "" then
  485. local found = false
  486. for _, name in ipairs(cfg.playerConfig.ignore) do
  487. if name:lower() == pName:lower() then found = true; break end
  488. end
  489. if not found then table.insert(cfg.playerConfig.ignore, pName) end
  490. scanEnvironment()
  491. end
  492. needFullRedraw = true
  493. else
  494. for i = 1, 6 do
  495. local id = "unig_" .. i
  496. if b[id] and x >= b[id].x and x < b[id].x + b[id].w and y == b[id].y then
  497. table.remove(cfg.playerConfig.ignore, i)
  498. buttons[id] = nil
  499. scanEnvironment()
  500. needFullRedraw = true
  501. break
  502. end
  503. end
  504. end
  505. if showIgnoreMenu then drawIgnoreMenu() end
  506.  
  507. else
  508. local b = buttons
  509. if b["tplus"] and x >= b["tplus"].x and x < b["tplus"].x + b["tplus"].w and y == b["tplus"].y then
  510. cfg.target = cfg.target + (keyboard.isShiftDown() and 10 * 10^9 or 1 * 10^9)
  511. elseif b["tminus"] and x >= b["tminus"].x and x < b["tminus"].x + b["tminus"].w and y == b["tminus"].y then
  512. cfg.target = math.max(0, cfg.target - (keyboard.isShiftDown() and 10 * 10^9 or 1 * 10^9))
  513. elseif b["flowcfg"] and x >= b["flowcfg"].x and x < b["flowcfg"].x + b["flowcfg"].w and y == b["flowcfg"].y then
  514. showFlowMenu = true
  515. drawFlowMenu()
  516. elseif b["tog_chat"] and x >= b["tog_chat"].x and x < b["tog_chat"].x + b["tog_chat"].w and y == b["tog_chat"].y then
  517. cfg.ar_chat_enabled = not cfg.ar_chat_enabled
  518. updateAR()
  519. elseif b["tog_radar"] and x >= b["tog_radar"].x and x < b["tog_radar"].x + b["tog_radar"].w and y == b["tog_radar"].y then
  520. cfg.ar_radar_enabled = not cfg.ar_radar_enabled
  521. updateAR()
  522. elseif b["tog_me"] and x >= b["tog_me"].x and x < b["tog_me"].x + b["tog_me"].w and y == b["tog_me"].y then
  523. cfg.ar_me_enabled = not cfg.ar_me_enabled
  524. updateAR()
  525. elseif b["btn_ignore"] and x >= b["btn_ignore"].x and x < b["btn_ignore"].x + b["btn_ignore"].w and y == b["btn_ignore"].y then
  526. showIgnoreMenu = true
  527. drawIgnoreMenu()
  528. elseif b["btn_prefix"] and x >= b["btn_prefix"].x and x < b["btn_prefix"].x + b["btn_prefix"].w and y == b["btn_prefix"].y then
  529. local pName = readInput("PREFIX CONFIG", "Player Nick")
  530. if pName and pName ~= "" then
  531. local pPref = readInput("PREFIX CONFIG", "Prefix (or leave empty)")
  532. if pPref then
  533. if pPref == "" then cfg.playerConfig.prefixes[pName] = nil
  534. else cfg.playerConfig.prefixes[pName] = pPref end
  535. scanEnvironment()
  536. end
  537. end
  538. end
  539. end
  540. lastStats = 0
  541. end
  542. local now = computer.uptime()
  543. if now - lastScan >= 2 then scanEnvironment(); lastScan = now end
  544. if now - lastStats >= 1 then
  545. tick_counter = tick_counter + 1
  546. if rf and gate then
  547. pcall(function()
  548. local cur = rf.getEnergyStored()
  549. currentFlow = (gate.getFlow and gate.getFlow()) or currentFlow or 0
  550. filVal = filVal + ((cur - lastE) - filVal) * 0.3
  551. local diff = cfg.target - cur
  552. local desired = currentFlow
  553. if math.abs(diff) > cfg.maxDiff then
  554. desired = clamp(currentFlow + math.floor(diff / cfg.step), cfg.flowMin, cfg.flowMax)
  555. end
  556. if gate.setFlow then gate.setFlow(desired) end
  557. currentFlow = desired
  558. lastE = cur
  559. end)
  560. end
  561.  
  562. matter_current = fetchMatterAmount()
  563. if now - me_timer >= 10 then
  564. if me_timer > 0 then
  565. matter_rate = (matter_current - matter_last) * (60 / math.max(1, now - me_timer))
  566. end
  567. matter_last = matter_current
  568. me_timer = now
  569. end
  570.  
  571. if needFullRedraw then drawStaticUI() end
  572. if showFlowMenu then
  573. drawFlowMenu()
  574. elseif showIgnoreMenu then
  575. drawIgnoreMenu()
  576. else
  577. updateDynamicUI(currentFlow)
  578. end
  579. lastStats = now
  580. end
  581. end
  582.  
Advertisement
Add Comment
Please, Sign In to add comment