Advertisement
PandaDoddo72Rus

Trader

Jul 19th, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 29.18 KB | None | 0 0
  1. -- Trader new version
  2. local cmp = require('component')
  3. local event = require('event')
  4. local serialization = require('serialization')
  5. local gpu=cmp.gpu
  6. local filesystem=require('filesystem')
  7. local term =require('term')
  8. local computer = require('computer')
  9. local unicode = require('unicode')
  10. local tunnel = cmp.tunnel
  11. local function saveTbl(tbl, fl) file = io.open(fl, 'w') file:write(serialization.serialize(tbl)) file:close() end
  12. local function loadTbl(fl) file = io.open(fl, 'r') if not file then file = io.open(fl, 'w') file:write('{}') return {} else return serialization.unserialize(file:read('*a')) end file:close() end
  13. local OldResX,OldResY=gpu.getResolution()
  14. local A,B=120,40
  15. local CONGFIG_FILE = 'config.cfg'
  16. local TRANSPOSER_FILE
  17. local ITEM_FILE = 'items.list' -- структура {{display_name,id,raw_name,max_size,qty,кол-во в системе,общее кол-во,условная цена ,не активный цвет текста , цвет текста при выделении}}
  18. gpu.setResolution(A,B) C=gpu.getBackground() D=gpu.getForeground() gpu.setForeground(0xFFFFFF)
  19. buttons={{1,1,60,3,'Trade',27,2,0x505050,0xFFFFFF,123123,0xFFFFFF},{61,1,60,3,'Orders',87,2,0x505050,0xFFFFFF,123123,0xFFFFFF},{45,9,4,3}, --[[-1]]{39,9,5,3}, --[[-10]]{71,9,4,3}, --[[+1]]{76,9,5,3}, --[[+10]]{32,9,6,3},  --[[-100]]{82,9,6,3},  --[[+100]]{46,13,4,3}, --[[<selector#1>]]{53,13,4,3},{59,13,4,3},{65,13,4,3},{71,13,4,3}, --[[</selector#1>]]{46,20,4,3}, --[[<selector#2>]]{53,20,4,3},{59,20,4,3},{65,20,4,3},
  20. {71,20,4,3}, --[[</selector#2>]]
  21. {30,29,28,5}, -- OK
  22. {53,20,1,1}, --<settings>
  23. {54,20,1,1},
  24. {55,20,1,1},
  25. {56,20,1,1},
  26. {57,20,1,1},
  27. {58,20,1,1},
  28. {53,22,1,1},
  29. {54,22,1,1},
  30. {55,22,1,1},
  31. {56,22,1,1},
  32. {57,22,1,1},
  33. {58,22,1,1},
  34. {64,21,20,3}, --</settings>
  35. {54,18,10,3}  -- Settings owner
  36. }
  37. color={back=0x000000,top=0x505050}
  38. frames={
  39. {1,2}, -- main
  40. {3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19}, -- addMenuItem
  41. {20,21,22,23,24,25,26,27,28,29,30,31,32}, -- setting
  42. {33} -- owner
  43. }
  44. function drawErr(text,mode,SleepTime)
  45.   drawField(30,13,60,9,' ',0x505050,0x505050)
  46.   if mode == 1 then
  47.     errColor=0xFFFFFF
  48.   elseif mode == 2 then
  49.     errColor = 0xAA0000
  50.   elseif mode == 3 then
  51.     errColor = 0xFFAA00
  52.   end
  53.   drawClound('┌','┐','└','┘','│','─',30,13,60,9,0x505050,errColor)
  54.   drawText(32,17,56,text,0x505050,0xFFFFFF)
  55.   if SleepTime ~= 0 then
  56.   os.sleep(SleepTime)
  57.   drawEmptyField(1,2)
  58.   end
  59. end
  60. function getRawEvent(arr)
  61.   local N = nil
  62.   local key,_,x,y,clickMouse,name=event.pull()
  63.   if key ~= 'scroll' then
  64.   for i=1,#arr-2 do
  65.  --   print(i,#arr)
  66.     if x > arr[i][1]-1 and x < arr[i][1]+arr[i][3]+1 and y > arr[i][2]-1 and y < arr[i][2]+arr[i][4]+1 then
  67.     N=i
  68.     break
  69.   end
  70.   end
  71.   elseif key == 'scroll' then
  72.    for i=37,38 do
  73.  --   print(i,#arr)
  74.     if x > arr[i][1]-1 and x < arr[i][1]+arr[i][3]+1 and y > arr[i][2]-1 and y < arr[i][2]+arr[i][4]+1 then
  75.     N=i
  76.     break
  77.   end
  78.   end
  79.   end
  80.   if N == nil then
  81.     N = 0
  82.   end
  83.   return key,N,clickMouse,name  
  84. end
  85. function drawField(x,y,w,h,s,c1,c2)     oldBack=gpu.getBackground() oldFore=gpu.getForeground() gpu.setBackground(c1) gpu.setForeground(c2) gpu.fill(x,y,w,h,s) gpu.setBackground(oldBack) gpu.setForeground(oldFore) end
  86. function drawButton(N)
  87.     oldFore=gpu.getForeground() oldBack=gpu.getBackground() if pos== N then --[[gpu.setBackground(buttons[N][10]) gpu.setForeground(0x505050) gpu.set(buttons[N][1],buttons[N][2],'▀') gpu.set(buttons[N][1]+buttons[N][3]-1,buttons[N][2],'▀')]] gpu.setForeground(buttons[N][11]) gpu.setBackground(buttons[N][10]) else --[[gpu.setForeground(0x505050) gpu.setBackground(buttons[N][8]) gpu.set(buttons[N][1],buttons[N][2],'▀') gpu.set(buttons[N][1]+buttons[N][3]-1,buttons[N][2],'▀')]] gpu.setForeground(buttons[N][9]) gpu.setBackground(buttons[N][8]) end
  88.     gpu.fill(buttons[N][1],buttons[N][2],buttons[N][3],buttons[N][4],' ') gpu.setForeground(buttons[N][9]) gpu.set(buttons[N][6],buttons[N][7],buttons[N][5]) gpu.setForeground(oldFore) gpu.setBackground(oldBack)
  89. end
  90.  
  91. function getMessage(mess)
  92. tunnel.send(mess)
  93. _,_,_,_,_,message = event.pull('modem_message')
  94. return message
  95. end
  96.  
  97. function buttonsCatch(N,mode)
  98.   if pos~=nil then oldPos=pos end
  99.   pos = nil
  100.   local _,_,p1,p2,_,nick=event.pull('touch')
  101.   for i=1,#frames[N] do
  102.     if p1 > buttons[frames[N][i]][1]-1 and p1 < buttons[frames[N][i]][1]+buttons[frames[N][i]][3]+1 and p2 > buttons[frames[N][i]][2]-1 and p2 < buttons[frames[N][i]][2]+buttons[frames[N][i]][4]+1 then    
  103.    pos=i break
  104.     end
  105.   end
  106.   if mode == 1 then
  107.     if pos==nil then pos=oldPos end
  108.   elseif mode == 2 then
  109.     if pos==nil then pos=0 end
  110.   end
  111.   return pos,nick
  112. end
  113.  
  114. function drawFrame(N)     gpu.setBackground(color.top) gpu.fill(1,1,A,1,' ') for i=1,#frames[N] do drawButton(frames[N][i]) end end
  115. gpu.setBackground(color.back) term.clear() --drawClound('╔','╗','╚','╝','║','═',x,y,w,h)
  116. function drawClound(s,s2,s3,s4,s5,s6,x,y,w,h,c1,c2)    oldFore=gpu.getForeground() oldBack=gpu.getBackground() gpu.setBackground(c1) gpu.setForeground(c2) gpu.set(x,y,s) gpu.fill(x+1,y,w-1,1,s6) gpu.set(x,y+h-1,s3) gpu.fill(x,y+1,1,h-2,s5) gpu.fill(x+w-1,y+1,1,h-2,s5) gpu.set(x+w-1,y,s2) gpu.fill(x+1,y+h-1,w-2,1,s6) gpu.set(x+w-1,y+h-1,s4) gpu.setBackground(oldBack) gpu.setForeground(oldFore) end
  117. function Exit() gpu.setBackground(C) gpu.setForeground(D) gpu.setResolution(OldResX,OldResY) term.clear() os.exit() end
  118. function drawEmptyField(frame,mode)
  119. gpu.setBackground(0x505050)
  120.  if mode == 1 then
  121.    drawFrame(frame)
  122.  elseif mode == 2 then
  123.   drawField(1,1,120,1,' ',0x505050,0x505050)
  124.   drawField(1,2,120,1,'▀',0xDCDCDC,0x505050)
  125.   drawField(1,3,120,37,' ',0xDCDCDC,0x505050)
  126.  end
  127.  drawField(1,4,120,38,' ',0xDCDCDC,0x505050)
  128.  drawField(1,40,120,1,' ',0x505050,0x505050)
  129.  drawField(1,39,120,1,'▄',0xDCDCDC,0x505050)
  130.  gpu.set(3,40,'OpenTrader v0.1')
  131.  gpu.set(90,40,'Autor: PandaDoddo72Rus (vah)')
  132. end
  133. drawEmptyField(1,2)
  134.  
  135. function drawText(x,y,leght,txt,col_back,col_fore)
  136.     local oldB=gpu.getBackground()
  137.   local oldF=gpu.getForeground()
  138.   local txt = tostring(txt)
  139.   gpu.setBackground(col_back)
  140.   gpu.setForeground(col_fore)
  141.   if unicode.len(txt) > leght then
  142.     txt=unicode.sub(txt,0,leght)
  143.   end
  144.     gpu.set(x+math.floor((leght-unicode.len(txt))/2),y,txt)
  145.   gpu.setBackground(oldB)
  146.   gpu.setForeground(oldF)
  147. end
  148. --transArr={address,1s,2s,3s,4s,5s,6s}
  149. function checkTransposers()
  150.   if filesystem.exists(TRANSPOSER_FILE) == false then
  151.     file=io.open(TRANSPOSER_FILE,'w')
  152.     file:write('{}')
  153.     file:close()
  154.     local wordsArr={'drop','client_drop','in_system','client_inventory','system_out'}
  155.     local transposers = cmp.list('transposer')
  156.     for i , val in pairs(transposers) do
  157.       for j=0,5 do
  158.         if cmp.proxy(i).getInventorySize(j) > 9 then
  159.         local itemInChest=cmp.proxy(i).getStackInSlot(j,1)
  160.         for t=1,#wordsArr do
  161.           if itemInChest.label == wordsArr[t] then
  162.             TFile[#TFile+1]={i,wordsArr[t],j}
  163.         saveTbl(TFile,TRANSPOSER_FILE)
  164.           end
  165.         end
  166.       end
  167.     end
  168.     end
  169.   elseif filesystem.exists(TRANSPOSER_FILE) == true then
  170.     TFile=loadTbl(TRANSPOSER_FILE)
  171.   itemsTransposer={}
  172.   for i=1,#TFile do
  173.     if TFile[i][2] == 'system_out' then
  174.       itemsTransposer={TFile[i][1],TFile[i][2],TFile[i][3]}
  175.     end
  176.   end
  177.   end
  178. end
  179.  
  180. function selectPosListYou(pYou,name,nameItem,mode)
  181.   if mode == 1 then
  182.   youTrade={}
  183.   for i=1,#items do
  184.     for j=1,#youTrade do
  185.     if items[i][1] == name then
  186.     Nitem = i
  187.     break
  188.   end
  189.   end
  190.     if math.floor(items[i][8]*items[i][4]/2) >= math.floor(items[Nitem][8]*2) then
  191.     youTrade[#youTrade+1]=i
  192.   end
  193.   end
  194.   end
  195.   if pos==nil then
  196.     pos = oldName
  197.   end
  198.   l=1+pYou
  199.   j=l+17
  200.   NInListYou=1
  201. --  drawField(6,7,43,18,' ',0x505050,0x505050)
  202.   for k=l,j do
  203.   if youTrade[k] ~= nil then
  204.     if items[youTrade[k]][1] == nameItem then
  205.     gpu.setBackground(config[1])
  206.     gpu.setForeground(items[youTrade[k]][9])
  207.     gpu.fill(6,6+NInListYou,43,1,' ')
  208.     gpu.set(8,6+NInListYou,unicode.sub(nameItem,1,39))
  209.     gpu.setForeground(0xFFFFFF)
  210.     gpu.setBackground(0x505050)
  211.   NInListYou=NInListYou+1
  212.   else
  213.     gpu.setBackground(0x505050)
  214.       gpu.setForeground(items[youTrade[k]][10])
  215.     gpu.fill(6,6+NInListYou,43,1,' ')
  216.     gpu.set(8,6+NInListYou,unicode.sub(items[youTrade[k]][1],1,39))
  217.     gpu.setForeground(0xFFFFFF)
  218.     gpu.setBackground(0x505050)
  219.   NInListYou=NInListYou+1
  220.   end
  221.   end
  222.   if youTrade[k] == nil and NInListYou<19 then
  223.     gpu.setBackground(0x505050)
  224.     gpu.fill(6,6+NInListYou,43,1,' ')  end
  225.     NInListYou=NInListYou+1
  226.   if name ~= nil then
  227.     oldName=name
  228.   end
  229.   end
  230. end
  231.  
  232. function selectPosListTrades(page,name)
  233.   for i=1,#items do
  234.     if items[i][1] == name then
  235.     Nitem=i
  236.     break
  237.   end
  238.   end
  239.   if name==nil then
  240.     name = oldName
  241.   end
  242.   l=1+page
  243.   j=l+17
  244. NInList=1
  245.   for k=l,j do
  246.   if items[k] ~= nil then
  247.     if items[k][1] == name then
  248.     gpu.setBackground(config[1])
  249.     gpu.setForeground(items[Nitem][9])
  250.     gpu.fill(71,6+NInList,43,1,' ')
  251.     gpu.set(73,6+NInList,unicode.sub(name,1,39))
  252.     gpu.setForeground(0xFFFFFF)
  253.     gpu.setBackground(0x505050)
  254. NInList=NInList+1
  255.   else
  256.     gpu.setBackground(0x505050)
  257.     gpu.setForeground(items[k][10])
  258.     gpu.fill(71,6+NInList,43,1,' ')
  259.     gpu.set(73,6+NInList,unicode.sub(items[k][1],1,39))
  260.     gpu.setForeground(0xFFFFFF)
  261.     gpu.setBackground(0x505050)
  262. NInList=NInList+1
  263.   end
  264.   end
  265.   if name ~= nil then
  266.     oldName=name
  267.   end
  268.   end
  269. end
  270.  
  271. function tradeItemFrame()
  272.   TFile=loadTbl(TRANSPOSER_FILE)
  273.   drawEmptyField(1,2)
  274.   drawField(6,7,43,20,' ',0x505050,0x505050)
  275.   drawClound('┌','┐','└','┘','│','─',5,6,45,22,0x505050,0xFFFFFF)
  276.   drawClound('┌','┐','└','┘','│','─',5,25,45,3,0x505050,0xFFFFFF)
  277.   drawText(5,25,45,'[YOU_INVENTORY]',0x505050,0xFFFFFF)
  278.   for i=1,#TFile do
  279.     if TFile[i][2] == 'client_inventory' then
  280.     clientInv={}
  281.     for j=1,cmp.proxy(TFile[i][1]).getInventorySize(TFile[i][3]) do
  282.       itemInSlotChest=cmp.proxy(TFile[i][1]).getStackInSlot(TFile[i][3],j)
  283.     if itemInSlotChest.hasTag == false then
  284.           for t=1,#clientInv do
  285.             if clientInv[t][1]==itemInSlotChest.label then
  286.         N=t
  287.         break
  288.       end
  289.           end    
  290.           if clientInv[N][1]==itemInSlotChest.label then
  291.         clientInv[N][2]=clientInv[N][2]+itemInSlotChest.size
  292.       else
  293.         clientInv[#clientInv+1]={itemInSlotChest.label,itemInSlotChest.size}
  294.       end
  295.         end  
  296.     end
  297.   end
  298.   end
  299.   --
  300.   l=1+pageYouInv
  301.   j=l+18
  302.   for k=l,j do
  303.   if clientInv[k] ~= nil then
  304.     if items[youTrade[k]][1] == nameItem then
  305.     gpu.setBackground(config[1])
  306.     gpu.setForeground(items[Nitem][9])
  307.     gpu.fill(6,6+k,43,1,' ')
  308.     gpu.set(8,6+k,nameItem)
  309.     gpu.setForeground(0xFFFFFF)
  310.     gpu.setBackground(0x505050)
  311.   else
  312.     gpu.setBackground(0x505050)
  313.     gpu.setForeground(items[youTrade[k]][10])
  314.     gpu.fill(6,6+k,43,1,' ')
  315.     gpu.set(8,6+k,unicode.sub(items[youTrade[k]][1]),1,40)
  316.     gpu.setForeground(0xFFFFFF)
  317.     gpu.setBackground(0x505050)
  318.   end
  319.   end
  320.   if youTrade[k] == nil then
  321.     gpu.setBackground(0x505050)
  322.     gpu.fill(6,6+k,43,1,' ')
  323.   end
  324.   if name ~= nil then
  325.     oldName=name
  326.   end
  327.   end
  328.   --
  329. end
  330.  
  331. function traders()
  332. youTrade={}
  333. drawTraderPer=0
  334. tradersButtons={
  335. {73,6,39,1},
  336. {73,7,39,1},
  337. {73,8,39,1},
  338. {73,9,39,1},
  339. {73,10,39,1},
  340. {73,11,39,1},
  341. {73,12,39,1},
  342. {73,13,39,1},
  343. {73,14,39,1},
  344. {73,15,39,1},
  345. {73,16,39,1},
  346. {73,17,39,1},
  347. {73,18,39,1},
  348. {73,19,39,1},
  349. {73,20,39,1},
  350. {73,21,39,1},
  351. {73,22,39,1},
  352. {73,23,39,1},
  353. {8,6,39,1}, -- <youList>
  354. {8,7,39,1},
  355. {8,8,39,1},
  356. {8,9,39,1},
  357. {8,10,39,1},
  358. {8,11,39,1},
  359. {8,12,39,1},
  360. {8,13,39,1},
  361. {8,14,39,1},
  362. {8,15,39,1},
  363. {8,16,39,1},
  364. {8,17,39,1},
  365. {8,18,39,1},
  366. {8,19,39,1},
  367. {8,20,39,1},
  368. {8,21,39,1},
  369. {8,22,39,1},
  370. {8,23,39,1}, --</youList>
  371. {5,7,45,20},-- YOU SCROLL
  372. {70,6,45,20} -- TRADE SCROLL
  373. }
  374. --
  375. page=0
  376. pageYou=0
  377. --price,newActiveFore,newNonActiveFore
  378. --{inSlot.display_name 1,inSlot.id 2,inSlot.raw_name 3,maxSize 4,inSlot.qty 5,itemsInNetwork 6,itemsInNetwork+inSlot.qty 7,price 8,activeColor 9 ,nonActiveColor10}
  379.  
  380. while true do
  381. drawsItems=0
  382. if drawTraderPer== 0 then
  383. drawEmptyField(1,1)  
  384. drawField(6,7,43,20,' ',0x505050,0x505050)
  385. drawClound('┌','┐','└','┘','│','─',5,6,45,22,0x505050,0xFFFFFF)
  386. drawClound('┌','┐','└','┘','│','─',5,25,45,3,0x505050,0xFFFFFF)
  387. gpu.set(23,6,'[YOU]')
  388. drawField(A-49,7,43,20,' ',0x505050,0x505050)
  389. drawClound('┌','┐','└','┘','│','─',A-50,6,45,22,0x505050,0xFFFFFF)
  390. drawClound('┌','┐','└','┘','│','─',A-50,25,45,3,0x505050,0xFFFFFF)
  391. gpu.set(A-31,6,"[Trader]")
  392. gpu.setBackground(0xFFAA00)
  393. gpu.set(57,11,'      ')
  394. gpu.set(55,12,'          ')
  395. gpu.set(55,14,'          ')
  396. gpu.set(57,15,'      ')
  397. gpu.set(55,13,'          ')
  398. gpu.setBackground(0x0044FF)
  399. gpu.fill(57,12,6,3,' ')
  400. gpu.set(59,13,'OK')
  401. gpu.setForeground(0xFFAA00)
  402. gpu.setBackground(0xDCDCDC)
  403. gpu.set(56,11,'▄')
  404. gpu.set(63,11,'▄')
  405. gpu.set(56,15,'▀')
  406. gpu.set(63,15,'▀')
  407. gpu.setForeground(0xFFFFFF)
  408. gpu.setBackground(0x505050)
  409. -- вывод YOU
  410. items=loadTbl(ITEM_FILE)
  411. --вывод traders
  412. selectPosListTrades(page)
  413. else
  414.  
  415. end
  416. drawTraderPer=1
  417.     local key,posTraderList,clickMouse,nick=getRawEvent(tradersButtons)
  418.   if key == 'touch' then
  419.   if posTraderList~= 0 or posTraderList ~= nil then
  420.     if clickMouse == 1 and clickMouse~= nil and nick == config[2] and posTraderList < 19 then
  421.         if items[posTraderList+page] ~= nil then
  422.     local NewPriceTraderList,NewActiveForeTraderList,NewNonActiveForeTraderList=addMenuItem(items[posTraderList+page][1])
  423.     items[posTraderList+page][8]=NewPriceTraderList
  424.     items[posTraderList+page][9]=NewActiveForeTraderList
  425.     items[posTraderList+page][10]=NewNonActiveForeTraderList
  426.     saveTbl(items,ITEM_FILE)
  427.         drawTraderPer=0
  428.     end
  429.     elseif clickMouse == 0 and clickMouse~= nil then
  430.     if posTraderList > 18 then
  431.       if youTrade[1] ~= nil and NameItemInTrade~=nil and items[youTrade[posTraderList+page-18]]~=nil  then
  432.         ItemSelectInYouList=items[youTrade[posTraderList+pageYou-18]][1]
  433.         selectPosListYou(pageYou,NameItemInTrade,items[youTrade[posTraderList+pageYou-18]][1],0)        
  434.       end
  435.     end
  436.     if items[posTraderList+page] ~= nil and posTraderList<19 then
  437.       NameItemInTrade=items[posTraderList+page][1]
  438.       selectPosListTrades(page,NameItemInTrade)
  439.       selectPosListYou(pageYou,NameItemInTrade,ItemSelectInYouList,1)
  440.     end
  441.       end
  442.   end
  443.  elseif key == 'scroll' then
  444.     if posTraderList > 36 and posTraderList < 39 then
  445.     if posTraderList == 37 then
  446.       pageYou=pageYou-(clickMouse)
  447.       if youTrade ~= nil then
  448.         if pageYou < 0 then
  449.         pageYou = 0
  450.         elseif pageYou>math.ceil(#youTrade-18) then
  451.             pageYou = math.ceil(#youTrade-18)
  452.         end
  453.       if youTrade[1]~= nil then
  454.   selectPosListYou(pageYou,NameItemInTrade,ItemSelectInYouList,0)
  455. end
  456.   end
  457.     elseif posTraderList == 38 then
  458.       page=page-(clickMouse)
  459.       if page < 0 then
  460.         page = 0
  461.       elseif page > math.ceil(#items-18) then
  462.         page = math.ceil(#items-18)
  463.       end
  464.     selectPosListTrades(page,NameItemInTrade)
  465.     end
  466.   end
  467.   end
  468.   end
  469. end
  470. -- формула one*условная_цена/2| one*условная_цена*2 [При условии что может стакаться]
  471. --   Алмаз(100)[1*100/2] {50} | Камень(10)
  472. --   Камень(10)[1*10/2] (5) | Камень(10*2) 4к1
  473. --   Алмаз(1000) [1*1000/2] (500) | Камень(10*2)
  474. --   Алмаз(1000) [1*1000/2] (500) {32000} | Гибридка(250000*2)
  475. --   Гибридка(250000) [1*250000/2] (175000) | 4к1
  476. local function drawColorSelectorAddMenu(arr,i,n)
  477.     if oldN1 == nil then
  478.     oldN1 = 1
  479.   end
  480.   if oldN2 == nil then
  481.     oldN2 = 6
  482.   end
  483.     drawField(arr[i][1],arr[i][2],arr[i][3],1,' ',arr[i][4],arr[i][5])
  484.     if n == 0 then
  485.     drawClound('┌','┐','└','┘','│','─',arr[i][1]-1,arr[i][2]-1,4,3,0x505050,arr[i][5])
  486.   elseif n == 1 then
  487.     drawClound('┌','┐','└','┘','│','─',arr[i][1]-1,arr[i][2]-1,4,3,0x505050,arr[i][6])
  488.   end
  489.   if i > 5 and oldN2 ~= i then
  490.     drawField(arr[oldN2][1],arr[i][2],arr[oldN2][3],1,' ',arr[oldN2][4],arr[oldN2][5])
  491.     drawClound('┌','┐','└','┘','│','─',arr[oldN2][1]-1,arr[oldN2][2]-1,4,3,0x505050,arr[oldN2][5])
  492.   elseif i < 6 and oldN1 ~= i then
  493.       drawField(arr[oldN1][1],arr[i][2],arr[oldN1][3],1,' ',arr[oldN1][4],arr[oldN1][5])
  494.     drawClound('┌','┐','└','┘','│','─',arr[oldN1][1]-1,arr[oldN1][2]-1,4,3,0x505050,arr[oldN1][5])
  495.   end
  496.   if i > 5 and n == 1 then
  497.     oldN2=i
  498.   elseif i < 6 and n == 1 then
  499.     oldN1=i
  500.   end
  501. end
  502.  
  503. local function drawButtonAddMenu(arr,i)
  504.     drawField(arr[i][1],arr[i][2],arr[i][3],1,'▄',arr[i][4],arr[i][5])
  505.     drawField(arr[i][1],arr[i][2]+1,arr[i][3],1,' ',arr[i][5],arr[i][5])
  506.     drawField(arr[i][1],arr[i][2]+2,arr[i][3],1,'▄',arr[i][5],arr[i][4])
  507. end
  508.  
  509. function checkExport()
  510.   local items = loadTbl(ITEM_FILE)
  511.   local meControllers = cmp.list('me_interface')
  512.   for i , val in pairs(meControllers) do
  513.     local inNetwork=cmp.proxy(i).getItemsInNetwork()
  514.   for l=1,9 do
  515.     local inSlot = cmp.proxy(i).getStackInSlot(l)
  516.       if #items == 0 or #items == nil then
  517.     if inSlot~= nil then
  518.       if inSlot.id ~= nil then
  519.         price,activeColor,nonActiveColor=addMenuItem(inSlot.display_name)
  520.         for h=1,#inNetwork do
  521.         if inNetwork[h].name == inSlot.id or inNetwork[h].name == inSlot.raw_name then
  522.           itemsInNetwork=inNetwork[h].size
  523.         break
  524.         else
  525.                 itemsInNetwork=0
  526.           end
  527.         if itemsInNetwork == nil then
  528.           itemsInNetwork = 0
  529.         end
  530.       end
  531.       maxSize=inSlot.max_size
  532.       items[#items+1]={inSlot.display_name,inSlot.id,inSlot.raw_name,maxSize,inSlot.qty,itemsInNetwork,itemsInNetwork+inSlot.qty,price,activeColor,nonActiveColor}
  533.       saveTbl(items,'/'..ITEM_FILE)
  534.       end
  535.       end  
  536.     else
  537.     if inSlot~= nil then
  538.       if inSlot.id ~= nil then
  539.       foundItem=0
  540.       for j=1,#items do
  541.         if items[j][2] == inSlot.id and items[j][3] == inSlot.raw_name then
  542.           foundItem=1
  543.           break
  544.         end
  545.       end
  546.       if foundItem == 0 then
  547.           price,activeColor,nonActiveColor=addMenuItem(inSlot.display_name)
  548.           for h=1,#inNetwork do
  549.           if inNetwork[h].name == inSlot.id or inNetwork[h].name == inSlot.raw_name then
  550.             itemsInNetwork=inNetwork[h].size
  551.           break
  552.                 else
  553.                   itemsInNetwork=0
  554.                 end
  555.         if itemsInNetwork == nil then
  556.             itemsInNetwork = 0
  557.         end
  558.         end
  559.         maxSize=inSlot.max_size
  560.         items[#items+1]={inSlot.display_name,inSlot.id,inSlot.raw_name,maxSize,inSlot.qty,itemsInNetwork,itemsInNetwork+inSlot.qty,price,activeColor,nonActiveColor}
  561.         saveTbl(items,'/'..ITEM_FILE)
  562.       end
  563.         end
  564.     end
  565.     end
  566.   end
  567.   end
  568. end
  569.  
  570. function addMenuItem(item)
  571.   local price = 0
  572.   local buttonsAddMenuItem={ -- структура {x,y,w,color_back,color_fore}
  573.     {50,9,20,0x505050,0,0xFFFFFF},-- черное поле
  574.     {45,9,4,0x505050,0xFFAA00,0xFFFFFF}, -- [-1]
  575.     {39,9,5,0x505050,0xFFAA00,0xFFFFFF}, -- [-10]
  576.     {71,9,4,0x505050,0xFFAA00,0xFFFFFF}, -- [+1]
  577.     {76,9,5,0x505050,0xFFAA00,0xFFFFFF},  -- [+10]
  578.   {32,9,6,0x505050,0xFFAA00,0xFFFFFF},  -- [-100]
  579.   {82,9,6,0x505050,0xFFAA00,0xFFFFFF}  -- [+100]
  580.   }
  581.   local colorFrameToSelect={    {47,14,2,0xFFFFFF,0xFFFFFF,0xFFAA00}, {53,14,2,0x00AA00,0xFFFFFF,0xFFAA00}, {59,14,2,0xFFFF00,0xFFFFFF,0xFFAA00}, {65,14,2,0x00FFFF,0xFFFFFF,0xFFAA00}, {71,14,2,0xFF00FF,0xFFFFFF,0xFFAA00},    {47,21,2,0xFFFFFF,0xFFFFFF,0xFFAA00},  {53,21,2,0x00AA00,0xFFFFFF,0xFFAA00}, {59,21,2,0xFFFF00,0xFFFFFF,0xFFAA00}, {65,21,2,0x00FFFF,0xFFFFFF,0xFFAA00}, {71,21,2,0xFF00FF,0xFFFFFF,0xFFAA00}  
  582.   }
  583.   while true do
  584.   if drawsItems == 1 then
  585.     gpu.setBackground(config[1])
  586.     gpu.fill(43,24,34,1,' ')
  587.     drawText(43,24,34,item,config[1],newActiveFore)
  588.   gpu.setBackground(0x505050)
  589.   gpu.fill(43,17,34,1,' ')
  590.   drawText(43,17,34,item,0x505050,newNonActiveFore)
  591.   gpu.setBackground(0)
  592.   gpu.fill(50,10,20,1,' ')
  593.     drawText(51,10,18,price,0,0xFFFFFF)
  594.   else
  595.     drawField(30,7,60,20,' ',0x505050,0x505050)
  596.     drawClound('┌','┐','└','┘','│','─',30,7,60,20,0x505050,0xFFFFFF)
  597.   for i=1,#buttonsAddMenuItem do
  598.     drawButtonAddMenu(buttonsAddMenuItem,i)
  599.   end
  600.   for i=1,#colorFrameToSelect do
  601.     drawColorSelectorAddMenu(colorFrameToSelect,i,0)
  602.   end
  603.     drawField(30,29,28,5,' ',0x898989,0x505050)
  604.     drawClound('┌','┐','└','┘','│','─',30,29,28,5,0x898989,0xFFFFFF)
  605.     gpu.set(53,8,'Условная цена:')
  606.     gpu.set(48,12,'Цвет неактивного текста:')
  607.     gpu.set(49,19,'Цвет активного текста:')
  608.     gpu.setBackground(0xFFAA00)
  609.     gpu.set(46,10,'-1')
  610.     gpu.set(40,10,'-10')
  611.     gpu.set(72,10,'+1')
  612.     gpu.set(77,10,'+10')
  613.     gpu.set(33,10,'-100')
  614.     gpu.set(83,10,'+100')
  615.     gpu.setBackground(0x505050)
  616.     gpu.set(35,17,'Example:')
  617.     drawText(43,17,34,item,0x505050,0xFFFFFF)
  618.     gpu.set(35,24,'Example:')
  619.     gpu.setBackground(config[1])
  620.     gpu.fill(43,24,34,1,' ')
  621.     drawText(43,24,34,item,config[1],0xFFFFFF)
  622.     gpu.setBackground(0x505050)
  623.     drawText(51,10,18,price,0,0xFFFFFF)
  624.     drawColorSelectorAddMenu(colorFrameToSelect,1,1)
  625.     drawColorSelectorAddMenu(colorFrameToSelect,6,1)
  626.     newActiveFore=0xFFFFFF
  627.     newNonActiveFore=0xFFFFFF
  628.   drawsItems = 1
  629.   end
  630.     local posButtonAddMenu,_ = buttonsCatch(2,2)
  631.   if posButtonAddMenu > 0 and posButtonAddMenu < 7 then
  632.     if posButtonAddMenu == 1 then
  633.         price = price - 1
  634.     elseif posButtonAddMenu == 2 then
  635.       price = price - 10
  636.     elseif posButtonAddMenu == 3 then
  637.       price = price + 1
  638.     elseif posButtonAddMenu == 4 then
  639.       price = price + 10
  640.     elseif posButtonAddMenu == 5 then
  641.       price = price - 100
  642.     elseif posButtonAddMenu == 6 then
  643.       price = price + 100
  644.     end
  645.     if price < 0 then
  646.       price = 0
  647.       elseif price > 999999999999999999 then
  648.       price = 999999999999999999
  649.     end
  650.     drawButtonAddMenu(buttonsAddMenuItem,1)
  651.     drawText(51,10,18,price,0,0xFFFFFF)
  652.     end
  653.   if posButtonAddMenu > 6 and posButtonAddMenu < 12 then
  654.     if posButtonAddMenu == 7 then
  655.       newNonActiveFore=colorFrameToSelect[1][4]
  656.     drawColorSelectorAddMenu(colorFrameToSelect,1,1)
  657.     elseif posButtonAddMenu == 8 then
  658.       newNonActiveFore=colorFrameToSelect[2][4]
  659.     drawColorSelectorAddMenu(colorFrameToSelect,2,1)
  660.     elseif posButtonAddMenu == 9 then
  661.       newNonActiveFore=colorFrameToSelect[3][4]
  662.     drawColorSelectorAddMenu(colorFrameToSelect,3,1)
  663.     elseif posButtonAddMenu == 10 then
  664.       newNonActiveFore=colorFrameToSelect[4][4]
  665.     drawColorSelectorAddMenu(colorFrameToSelect,4,1)
  666.     elseif posButtonAddMenu == 11 then
  667.       newNonActiveFore=colorFrameToSelect[5][4]
  668.     drawColorSelectorAddMenu(colorFrameToSelect,5,1)
  669.     end
  670.     drawText(43,17,34,item,0x505050,newNonActiveFore)
  671.   end
  672.   if posButtonAddMenu > 11 and posButtonAddMenu < 17 then
  673.     if posButtonAddMenu == 12 then
  674.       newActiveFore=colorFrameToSelect[6][4]
  675.     drawColorSelectorAddMenu(colorFrameToSelect,6,1)
  676.       elseif posButtonAddMenu == 13 then
  677.       newActiveFore=colorFrameToSelect[7][4]
  678.     drawColorSelectorAddMenu(colorFrameToSelect,7,1)
  679.     elseif posButtonAddMenu == 14 then
  680.       newActiveFore=colorFrameToSelect[8][4]
  681.     drawColorSelectorAddMenu(colorFrameToSelect,8,1)
  682.     elseif posButtonAddMenu == 15 then
  683.       newActiveFore=colorFrameToSelect[9][4]
  684.     drawColorSelectorAddMenu(colorFrameToSelect,9,1)
  685.     elseif posButtonAddMenu == 16 then
  686.       newActiveFore=colorFrameToSelect[10][4]
  687.     drawColorSelectorAddMenu(colorFrameToSelect,10,1)
  688.     end
  689.   gpu.setBackground(config[1])
  690.     gpu.fill(43,24,34,1,' ')
  691.     drawText(43,24,34,item,config[1],newActiveFore)
  692.     gpu.setBackground(0x505050)
  693.   end
  694.   if posButtonAddMenu == 17 then
  695.     break
  696.   end
  697.   end
  698.   return price,newActiveFore,newNonActiveFore
  699. end
  700. -- Выберете цвет для выделения товаров:
  701. function colorSelector(txt)
  702.   local colorPos1 = 0
  703.   local colorPos2 = 0
  704.   local colorPos3 = 0
  705.   local colorPos4 = 0
  706.   local colorPos5 = 0
  707.   local colorPos6 = 0
  708.   local function F16(n)
  709.     N=nil
  710.     if n > 9 then
  711.     if n==10 then
  712.       N = 'A'
  713.     elseif n == 11 then
  714.       N = 'B'
  715.     elseif n == 12 then
  716.       N = 'C'
  717.     elseif n == 13 then
  718.       N = 'D'
  719.     elseif n == 14 then
  720.       N = 'E'
  721.     elseif n == 15 then
  722.       N = 'F'
  723.     else N = n
  724.     end
  725.   end
  726.   if N == nil then N=n end
  727.     return N
  728.   end
  729.   local buttonsSettings={{60,20,10,0x505050,0,0xFFFFFF}}
  730.   drawEmptyField(1,2)
  731.   drawField(30,15,60,11,' ',0x505050,0x505050)
  732.   drawClound('┌','┐','└','┘','│','─',30,15,60,11,0x505050,0xFFFFFF)
  733.   drawText(40,17,40,txt,0x505050,0xFFFFFF)
  734.   gpu.setBackground(0)
  735.   gpu.set(52,21,'0x')
  736.   gpu.set(54,21,'000000')
  737.   drawField(47,21,2,1,' ',0,0x505050)
  738.   drawClound('┌','┐','└','┘','│','─',46,20,4,3,0x505050,0xFFFFFF)
  739.   gpu.setBackground(0x505050)
  740.   gpu.setForeground(0xFFAA00)
  741.   gpu.set(54,20,'▲▲▲▲▲▲')
  742.   gpu.set(54,22,'▼▼▼▼▼▼')
  743.   gpu.setForeground(0xFFFFFF)
  744.   gpu.setBackground(0x898989)
  745.   gpu.fill(64,20,20,3,' ')
  746.   gpu.set(73,21,'OK')
  747.   gpu.setBackground(0x505050)
  748.   newColor=0
  749. while true do
  750.   local posSettingMenu,_ = buttonsCatch(3,2)
  751.   if posSettingMenu > 0 and posSettingMenu < 13 then
  752.     if posSettingMenu == 1 then
  753.       colorPos1 = colorPos1+1
  754.     elseif posSettingMenu == 2 then
  755.       colorPos2 = colorPos2+1
  756.     elseif posSettingMenu == 3 then
  757.       colorPos3 = colorPos3 + 1
  758.     elseif posSettingMenu == 4 then
  759.       colorPos4 = colorPos4 + 1
  760.     elseif posSettingMenu == 5 then
  761.       colorPos5 = colorPos5 + 1
  762.     elseif posSettingMenu == 6 then
  763.       colorPos6 = colorPos6 + 1
  764.     elseif posSettingMenu == 7 then
  765.       colorPos1 = colorPos1-1
  766.     elseif posSettingMenu == 8 then
  767.       colorPos2 = colorPos2-1
  768.     elseif posSettingMenu == 9 then
  769.       colorPos3 = colorPos3 - 1
  770.     elseif posSettingMenu == 10 then
  771.       colorPos4 = colorPos4 - 1
  772.     elseif posSettingMenu == 11 then
  773.       colorPos5 = colorPos5 - 1
  774.     elseif posSettingMenu == 12 then
  775.       colorPos6 = colorPos6 - 1
  776.     end
  777.     if colorPos1 > 15 then
  778.       colorPos1 = 15
  779.     elseif colorPos2 > 15 then
  780.       colorPos2 = 15
  781.     elseif colorPos3 > 15 then
  782.       colorPos3 = 15
  783.     elseif colorPos4 > 15 then
  784.       colorPos4 = 15
  785.     elseif colorPos5 > 15 then
  786.      colorPos5 = 15
  787.     elseif colorPos6 > 15 then
  788.       colorPos6 = 15
  789.     end
  790.     if colorPos1 < 0 then
  791.       colorPos1 = 0
  792.     elseif colorPos2 < 0 then
  793.       colorPos2 = 0
  794.     elseif colorPos3 < 0 then
  795.       colorPos3 = 0
  796.     elseif colorPos4 < 0 then
  797.       colorPos4 = 0
  798.     elseif colorPos5 < 0 then
  799.       colorPos5 = 0
  800.     elseif colorPos6 < 0 then
  801.       colorPos6 = 0
  802.     end
  803.     local F1=F16(colorPos1)
  804.     local F2=F16(colorPos2)
  805.     local F3=F16(colorPos3)
  806.     local F4=F16(colorPos4)
  807.     local F5=F16(colorPos5)
  808.     local F6=F16(colorPos6)
  809.     gpu.setBackground(0)
  810.     gpu.set(54,21,tostring(F1..F2..F3..F4..F5..F6))
  811.     newColor=tonumber('0x'..F1..F2..F3..F4..F5..F6)
  812.     drawField(47,21,2,1,' ',newColor,0x505050)
  813.     drawClound('┌','┐','└','┘','│','─',40,46,4,3,0x505050,0xFFFFFF)
  814.     gpu.setBackground(0x505050)
  815.     end
  816.   if posSettingMenu == 13 then
  817.     drawEmptyField(1,2)
  818.     break
  819.   end
  820.   end
  821.   return newColor
  822. end
  823. function getOwner(col)
  824.       drawErr('Кто владелец?',3,0)
  825.     getOwnerButtons={{54,18,10,0x505050,0x00AA00,0xFFFFFF}}
  826.   drawButtonAddMenu(getOwnerButtons,1)
  827.     gpu.setBackground(0x00AA00)
  828.     gpu.set(56,19,'click!')
  829.     gpu.setBackground(0x505050)
  830.   while true do
  831.     local posOwnerMenu,owner=buttonsCatch(4)
  832.     if posOwnerMenu == 1 then
  833.         configs=loadTbl(CONGFIG_FILE)
  834.         newConfig={col,owner}
  835.     saveTbl(newConfig,CONGFIG_FILE)
  836.     break
  837.   end
  838.   end
  839.   gpu.setBackground(0x505050)
  840. end
  841.  --░▒▓ ►◄▼▲ 123123
  842. function start()
  843.   drawEmptyField(1,2)
  844.   drawErr('Добро пожаловать!',1,2)
  845.   if filesystem.exists(ITEM_FILE) == false then
  846.     file=io.open(ITEM_FILE,'w')
  847.     file:write('{}')
  848.     file:close()
  849.   end
  850.   if filesystem.exists(CONGFIG_FILE) == false then
  851.     file=io.open(CONGFIG_FILE,'w')
  852.     file:write('{}')
  853.     file:close()
  854.   end
  855.   config=loadTbl(CONGFIG_FILE)
  856.   if filesystem.exists(CONGFIG_FILE) == false or config[1] == nil or config[2] == nil then
  857.   file=io.open(CONGFIG_FILE,'w')
  858.     file:write('{}')
  859.     file:close()
  860.     drawErr('Настройка системы...',1,2)
  861.   colorSelect=colorSelector('Выберете цвет для выделения товаров:')
  862.   getOwner(colorSelect)
  863.   config=loadTbl(CONGFIG_FILE)
  864.   else
  865.     config=loadTbl(CONGFIG_FILE)
  866.   end
  867. end
  868.  
  869. start()
  870. checkExport()
  871. traders()
  872. while true do
  873.   if pos == nil then
  874.     pos = 1
  875.     drawEmptyField(1,1)
  876.   else
  877.     pos=buttonsCatch(1)
  878.   end
  879.   if pos == 1 then
  880.     drawEmptyField(1,1)
  881.   traders()
  882.   elseif pos == 2 then
  883.     drawEmptyField(1,1)
  884.   end
  885. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement