Advertisement
Guest User

tmpshop.lua

a guest
Dec 14th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.59 KB | None | 0 0
  1. --Функции обработки
  2.  
  3.  
  4. function explode(div,str)
  5.   if (div=='') then return false end
  6.   local pos,arr = 0,{}
  7.  
  8.   for st,sp in function() return string.find(str,div,pos,true) end do
  9.     table.insert(arr,string.sub(str,pos,st-1))
  10.     pos = sp + 1
  11.   end
  12.   table.insert(arr,string.sub(str,pos))
  13.   return arr
  14. end
  15.  
  16. function rgb2hex(r, g, b)
  17.     return r*65536+g*256+b
  18. end
  19.  
  20. --Цвета
  21.  
  22. local colorPage = rgb2hex(211,211,211)
  23. local white = rgb2hex(255,255,255)
  24. local black = rgb2hex(0,0,0)
  25. local ocean = rgb2hex(123,124,233)
  26. local fiol = rgb2hex(160,37,136)
  27. local red = rgb2hex(211,8,12)
  28. local pink = rgb2hex(255,0,255)
  29. local lime = rgb2hex(150,222,111)
  30. local blue = rgb2hex(0,0,222)
  31. local green = rgb2hex(0,128,0)
  32. local yellow = rgb2hex(255,215,0)
  33. local darkorange = rgb2hex(255,140,0)
  34.  
  35. --Округление числа после запятой до определенного знака floor_to_step(42346.12345678,0.01) -> 42346.12
  36. function floor_to_step(what,step)
  37.     return math.floor(what/step) * step
  38. end
  39. --Наследование классов
  40. function extended (child, parent)
  41.     setmetatable(child,{__index = parent})
  42. end
  43.  
  44. local component = require('component')
  45. local event = require("event")
  46. local side = require("sides")
  47. local term = require("term")
  48. local computer = require("computer")
  49. local serial = require("serialization")
  50. local modem = component.modem
  51. local g = component.gpu
  52. --local chat = component.chat_box
  53. local buffer = require("doubleBuffering")
  54. local image = require("image")
  55. local GUI = require("GUI")
  56. local shell = require("shell")
  57. local unicode = require("unicode")
  58.  
  59.  
  60.  
  61. local LSR = {}
  62.  
  63. -- Глобальный класс для управления МЕ системой
  64. function LSR:new()
  65.  
  66.     -- свойства
  67.     local obj= {}
  68.         -- obj.firstName = fName
  69.         -- obj.lastName = lName
  70.     --obj.distance = chat.getDistance()
  71.     obj.Name = "Skynet"
  72.     obj.colorName = "red"
  73.     obj.prefix = "SmartHome"
  74.     obj.colors = {
  75.         -- Символ § - ALT + 0,1,6,7
  76.         ["black"] = "§0",
  77.         ["blue"] = "§1",
  78.         ["green"] = "§2",
  79.         ["ocean"] = "§3",
  80.         ["red"] = "§4",
  81.         ["fiol"] = "§5",
  82.         ["yellow"] = "§6",
  83.         ["gray"] = "§7",
  84.         ["darkgray"] = "§8",
  85.         ["lightblue"] = "§9",
  86.         ["default"] = "§3"
  87.     }
  88.    
  89.    
  90.     -- Установить свойство
  91.     function obj:setVar(key,val)
  92.         self[key] = val
  93.         return self[key]
  94.     end
  95.    
  96.     -- Отправить сообщение
  97.     -- function obj:say(msg)
  98.         -- local m = chat.say(self.colors[self.colorName]..self.Name..self.colors["gray"]..": "..msg,self.distance)
  99.         -- return m
  100.     -- end
  101.    
  102.     --Возвращаем объект МЕ со всеми методами и свойствами! использование в коде local me = ME:new()
  103.     setmetatable(obj, self)
  104.     self.__index = self
  105.     return obj
  106. end
  107.  
  108. --Переменные
  109. local mainContainer = GUI.fullScreenContainer()
  110. local content
  111. local window
  112. local header
  113. local page
  114. local modal
  115. local dateInput
  116. local nickInput
  117. local Filters = {}
  118. local F = {
  119.     count = 600
  120. }
  121. local text
  122.  
  123. local button_logs
  124. local button_ls
  125. local button_chat
  126. local button_command
  127. local button_filters
  128. local logs = ""
  129. --Константы
  130. local TERMINALS = {["a87ed872-c777-4544-9a28-0733767bbfb8"] = 1, ["ecdf5459-2f7a-4a5e-afd6-ed618c34f549"] = 1, ["e97d829b-67ce-4b2c-9db0-04ed15443749"] = 1}
  131.  
  132.  
  133. -- function event.shouldInterrupt()
  134.     -- return false
  135. -- end
  136. -- if event.interruptingEnabled then
  137.     -- event.interruptingEnabled = false
  138. -- end
  139.  
  140.  
  141.  
  142. ----------------------
  143.  
  144. -----Функцианал-----
  145.  
  146. function waiting(message,func)
  147.  
  148.     loading = mainContainer:addChild(GUI.container(20,9,40,1))
  149.     loading:addChild(GUI.panel(1,1,loading.width,loading.height,rgb2hex(255,255,255)))
  150.     local textBox = loading:addChild(GUI.textBox(1, 1, loading.width, loading.height,rgb2hex(255,255,255), rgb2hex(0,0,0), {}, 1, 1, 0))
  151.     table.insert(textBox.lines, {text = message, color = 0x880000})
  152.     textBox:setAlignment(GUI.ALIGNMENT_HORIZONTAL_CENTER,GUI.ALIGNMENT_VERTICAL_CENTER)
  153.        
  154.    
  155.     loading:drawOnScreen(true)
  156.    
  157.     func()
  158.    
  159.     loading:remove()
  160.     mainContainer:drawOnScreen(true)
  161.    
  162. end
  163. function getLogs()
  164.  
  165.     local res = ""
  166.     pcall(function() for chunk in require("internet").request('http://minecraft.graycode.ru/app/lsreader/server/getLogs.php',Filters) do res = res..chunk end end)
  167.     return table.fromString(res)
  168.  
  169. end
  170. function getRawLogs()
  171.  
  172.     local res = ""
  173.     pcall(function() for chunk in require("internet").request('http://minecraft.graycode.ru/app/lsreader/server/getLogs.php',Filters) do res = res..chunk end end)
  174.     return res
  175.  
  176. end
  177. function floor_to_step(what,step)
  178.     return math.floor(what/step) * step
  179. end
  180.  
  181. function clearContent()
  182.    
  183.     content:removeChildren()
  184.     content:addChild(GUI.panel(1,1,content.width,content.height,black))
  185.    
  186. end
  187.  
  188. function getTab(n)
  189.    
  190.    
  191.     clearContent()
  192.    
  193.     if n == 1 then
  194.         Filters.chat = nil
  195.         Filters.commands = nil
  196.         Filters.ls = nil
  197.        
  198.         waiting("Загрузка...", function() logs = getLogs() end);
  199.        
  200.        
  201.         drawTextBox()
  202.        
  203.         for i = 1, #logs do
  204.             table.insert(text.lines, logs[i][6])
  205.         end
  206.        
  207.         button_logs.pressed = true
  208.         button_ls.pressed = false
  209.         button_chat.pressed = false
  210.         button_command.pressed = false
  211.        
  212.        
  213.        
  214.     elseif n == 2 then
  215.         Filters.ls = true
  216.         Filters.chat = nil
  217.         Filters.commands = nil
  218.        
  219.         --GUI.alert(Filters)
  220.        
  221.         waiting("Загрузка...", function() logs = getLogs() end);
  222.        
  223.         drawTextBox()
  224.        
  225.        
  226.         for i = 1, #logs do
  227.             table.insert(text.lines, logs[i][1].." "..logs[i][2].." /"..logs[i][3].." "..logs[i][4])
  228.         end
  229.        
  230.         button_logs.pressed = false
  231.         button_ls.pressed = true
  232.         button_chat.pressed = false
  233.         button_command.pressed = false
  234.        
  235.        
  236.     elseif n == 3 then
  237.         Filters.chat = true
  238.         Filters.commands = nil
  239.         Filters.ls = nil
  240.         waiting("Загрузка...", function() logs = getLogs() end);
  241.        
  242.         drawTextBox()
  243.        
  244.        
  245.         for i = 1, #logs do
  246.             if logs[i][3] == "l" then
  247.                 table.insert(text.lines, logs[i][1].." ".."[Мод.чат]".." "..logs[i][2]..": "..logs[i][4])
  248.             else
  249.                 table.insert(text.lines, logs[i][1].." "..logs[i][3].." "..logs[i][2]..": "..logs[i][4])
  250.             end
  251.            
  252.         end
  253.        
  254.         button_logs.pressed = false
  255.         button_ls.pressed = false
  256.         button_chat.pressed = true
  257.         button_command.pressed = false
  258.        
  259.        
  260.     elseif n == 4 then
  261.         Filters.commands = true
  262.         Filters.chat = nil
  263.         Filters.ls = nil
  264.         waiting("Загрузка...", function() logs = getLogs() end);
  265.        
  266.         drawTextBox()
  267.        
  268.        
  269.         for i = 1, #logs do
  270.             table.insert(text.lines, logs[i][1].." "..logs[i][2].." /"..logs[i][3].." "..logs[i][4])
  271.         end
  272.        
  273.         button_logs.pressed = false
  274.         button_ls.pressed = false
  275.         button_chat.pressed = false
  276.         button_command.pressed = true
  277.        
  278.     else
  279.        
  280.     end
  281.    
  282.    
  283.    
  284.  
  285. end
  286.  
  287.  
  288. -----Draw функции-----
  289. function drawTextBox()
  290.     text = nil
  291.     text = content:addChild(GUI.textBox(1,2,content.width,content.height,black, white, {}, 1, 2,0))
  292.     text.scrollBarEnabled = true
  293. end
  294.  
  295. function drawModal()
  296.    
  297.     if modal then
  298.         modal = nil
  299.     end
  300.    
  301.     if g.getResolution() > 80 then
  302.         modal = mainContainer:addChild(GUI.container(mainContainer.width/2-15,mainContainer.height/2-10,30,20))
  303.     else
  304.         modal = mainContainer:addChild(GUI.container(25,5,30,20))
  305.     end
  306.    
  307.     modal:addChild(GUI.panel(1,1,modal.width,modal.height, fiol))
  308.    
  309.     if Filters.date then
  310.         dateInput = modal:addChild(GUI.input( 1, 2, 30, 3, white, black, colorPage, white, black, nil, Filters.date))
  311.     else
  312.         dateInput = modal:addChild(GUI.input( 1, 2, 30, 3, white, black, colorPage, white, black, nil, "дд-мм-гггг"))
  313.     end
  314.    
  315.     if Filters.nick then
  316.         nickInput = modal:addChild(GUI.input( 1, 6, 30, 3, white, black, colorPage, white, black, nil, Filters.nick))
  317.     else
  318.         nickInput = modal:addChild(GUI.input( 1, 6, 30, 3, white, black, colorPage, white, black, nil, "Ник"))
  319.     end
  320.    
  321.     local reset = modal:addChild(GUI.button(1,modal.height-5, 30, 3, blue, white, white,blue, "Сбросить"))
  322.     reset.onTouch = function()
  323.    
  324.         Filters.date = nil
  325.         Filters.nick = nil
  326.        
  327.         modal:remove()
  328.     end
  329.    
  330.     local button = modal:addChild(GUI.button(1,modal.height-2, 30, 3, blue, white, white,blue, "ОК"))
  331.     button.onTouch = function()
  332.    
  333.        
  334.         if #dateInput.text >0 then
  335.             Filters.date = dateInput.text
  336.         end
  337.         if #nickInput.text >0 then
  338.             Filters.nick = nickInput.text
  339.         end
  340.        
  341.         modal:remove()
  342.     end
  343.    
  344. end
  345.  
  346. function init()
  347.  
  348. LSR = LSR:new() -- инициализация чат модуля
  349. --LSR:say("Модуль чата активирован.")
  350.  
  351. mainContainer:addChild(GUI.panel(1, 1, mainContainer.width, mainContainer.height, colorPage))
  352.  
  353.  
  354. local menu = mainContainer:addChild(GUI.container(1,1,mainContainer.width,3))
  355. button_logs = menu:addChild(GUI.button(1,1, 20, 3, white, black, black,white, "ЛОГИ"))
  356. button_logs.switchMode = true
  357. button_logs.onTouch = function()
  358.    
  359.     getTab(1)
  360.    
  361. end
  362.  
  363. button_ls = menu:addChild(GUI.button(21,1, 20, 3, white, black, black,white, "ЛС"))
  364. button_ls.switchMode = true
  365. button_ls.onTouch = function()
  366.    
  367.     getTab(2)
  368.    
  369. end
  370.  
  371. button_chat = menu:addChild(GUI.button(41,1, 20, 3, white, black, black,white, "Чат"))
  372. button_chat.switchMode = true
  373. button_chat.onTouch = function()
  374.    
  375.     getTab(3)
  376.    
  377. end
  378. button_command = menu:addChild(GUI.button(60,1, 20, 3, white, black, black,white, "КОМАНДЫ"))
  379. button_command.switchMode = true
  380. button_command.onTouch = function()
  381.    
  382.     getTab(4)
  383.    
  384. end
  385. if g.getResolution() > 80 then
  386.     button_filters = menu:addChild(GUI.button(menu.width-19,1, 20, 3, white, ocean, ocean,white, "Фильтры"))
  387. else
  388.     button_filters = menu:addChild(GUI.button(menu.width-2,1, 3, 3, white, ocean, ocean,white, "Ф"))
  389. end
  390. button_filters.onTouch = function()
  391.    
  392.     drawModal()
  393.     --waiting("Загрузка...", function() logs = getRawLogs() end);
  394.     --GUI.alert(logs)
  395. end
  396.  
  397.  
  398.  
  399. content = mainContainer:addChild(GUI.container(1,4,mainContainer.width,mainContainer.height-3))
  400. content:addChild(GUI.panel(1,1,content.width,content.height,black))
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412. -- local exitButton = mainContainer:addChild(GUI.button( 2, mainContainer.height-3, 15, 3, rgb2hex(255,255,255), black, rgb2hex(0,0,0), white, "Выйти в Shell" ))
  413.     -- exitButton.onTouch = function()
  414.         -- g.setBackground(0x000000)
  415.         -- term.clear()
  416.         -- g.setForeground(0xffffff)
  417.         -- g.set(1, 1, "")
  418.         -- error("Закрылись", 0)
  419. -- end
  420.  
  421.  
  422. end
  423.  
  424. ----------------------
  425.  
  426.  
  427. --[[ Проверка терминала ]]--
  428.  
  429. if not TERMINALS[modem.address] then
  430.     Oops()
  431. end
  432.  
  433. --[[********************]]--
  434.  
  435. init()
  436.  
  437.  
  438. mainContainer:drawOnScreen(true)
  439. mainContainer:startEventHandling()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement