Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Trader new version
- local cmp = require('component')
- local event = require('event')
- local serialization = require('serialization')
- local gpu=cmp.gpu
- local filesystem=require('filesystem')
- local term =require('term')
- local computer = require('computer')
- local unicode = require('unicode')
- local tunnel = cmp.tunnel
- local function saveTbl(tbl, fl) file = io.open(fl, 'w') file:write(serialization.serialize(tbl)) file:close() end
- 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
- local OldResX,OldResY=gpu.getResolution()
- local A,B=120,40
- local CONGFIG_FILE = 'config.cfg'
- local TRANSPOSER_FILE
- local ITEM_FILE = 'items.list' -- структура {{display_name,id,raw_name,max_size,qty,кол-во в системе,общее кол-во,условная цена ,не активный цвет текста , цвет текста при выделении}}
- gpu.setResolution(A,B) C=gpu.getBackground() D=gpu.getForeground() gpu.setForeground(0xFFFFFF)
- 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},
- {71,20,4,3}, --[[</selector#2>]]
- {30,29,28,5}, -- OK
- {53,20,1,1}, --<settings>
- {54,20,1,1},
- {55,20,1,1},
- {56,20,1,1},
- {57,20,1,1},
- {58,20,1,1},
- {53,22,1,1},
- {54,22,1,1},
- {55,22,1,1},
- {56,22,1,1},
- {57,22,1,1},
- {58,22,1,1},
- {64,21,20,3}, --</settings>
- {54,18,10,3} -- Settings owner
- }
- color={back=0x000000,top=0x505050}
- frames={
- {1,2}, -- main
- {3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19}, -- addMenuItem
- {20,21,22,23,24,25,26,27,28,29,30,31,32}, -- setting
- {33} -- owner
- }
- function drawErr(text,mode,SleepTime)
- drawField(30,13,60,9,' ',0x505050,0x505050)
- if mode == 1 then
- errColor=0xFFFFFF
- elseif mode == 2 then
- errColor = 0xAA0000
- elseif mode == 3 then
- errColor = 0xFFAA00
- end
- drawClound('┌','┐','└','┘','│','─',30,13,60,9,0x505050,errColor)
- drawText(32,17,56,text,0x505050,0xFFFFFF)
- if SleepTime ~= 0 then
- os.sleep(SleepTime)
- drawEmptyField(1,2)
- end
- end
- function getRawEvent(arr)
- local N = nil
- local key,_,x,y,clickMouse,name=event.pull()
- if key ~= 'scroll' then
- for i=1,#arr-2 do
- -- print(i,#arr)
- 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
- N=i
- break
- end
- end
- elseif key == 'scroll' then
- for i=37,38 do
- -- print(i,#arr)
- 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
- N=i
- break
- end
- end
- end
- if N == nil then
- N = 0
- end
- return key,N,clickMouse,name
- end
- 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
- function drawButton(N)
- 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
- 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)
- end
- function getMessage(mess)
- tunnel.send(mess)
- _,_,_,_,_,message = event.pull('modem_message')
- return message
- end
- function buttonsCatch(N,mode)
- if pos~=nil then oldPos=pos end
- pos = nil
- local _,_,p1,p2,_,nick=event.pull('touch')
- for i=1,#frames[N] do
- 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
- pos=i break
- end
- end
- if mode == 1 then
- if pos==nil then pos=oldPos end
- elseif mode == 2 then
- if pos==nil then pos=0 end
- end
- return pos,nick
- end
- 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
- gpu.setBackground(color.back) term.clear() --drawClound('╔','╗','╚','╝','║','═',x,y,w,h)
- 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
- function Exit() gpu.setBackground(C) gpu.setForeground(D) gpu.setResolution(OldResX,OldResY) term.clear() os.exit() end
- function drawEmptyField(frame,mode)
- gpu.setBackground(0x505050)
- if mode == 1 then
- drawFrame(frame)
- elseif mode == 2 then
- drawField(1,1,120,1,' ',0x505050,0x505050)
- drawField(1,2,120,1,'▀',0xDCDCDC,0x505050)
- drawField(1,3,120,37,' ',0xDCDCDC,0x505050)
- end
- drawField(1,4,120,38,' ',0xDCDCDC,0x505050)
- drawField(1,40,120,1,' ',0x505050,0x505050)
- drawField(1,39,120,1,'▄',0xDCDCDC,0x505050)
- gpu.set(3,40,'OpenTrader v0.1')
- gpu.set(90,40,'Autor: PandaDoddo72Rus (vah)')
- end
- drawEmptyField(1,2)
- function drawText(x,y,leght,txt,col_back,col_fore)
- local oldB=gpu.getBackground()
- local oldF=gpu.getForeground()
- local txt = tostring(txt)
- gpu.setBackground(col_back)
- gpu.setForeground(col_fore)
- if unicode.len(txt) > leght then
- txt=unicode.sub(txt,0,leght)
- end
- gpu.set(x+math.floor((leght-unicode.len(txt))/2),y,txt)
- gpu.setBackground(oldB)
- gpu.setForeground(oldF)
- end
- --transArr={address,1s,2s,3s,4s,5s,6s}
- function checkTransposers()
- if filesystem.exists(TRANSPOSER_FILE) == false then
- file=io.open(TRANSPOSER_FILE,'w')
- file:write('{}')
- file:close()
- local wordsArr={'drop','client_drop','in_system','client_inventory','system_out'}
- local transposers = cmp.list('transposer')
- for i , val in pairs(transposers) do
- for j=0,5 do
- if cmp.proxy(i).getInventorySize(j) > 9 then
- local itemInChest=cmp.proxy(i).getStackInSlot(j,1)
- for t=1,#wordsArr do
- if itemInChest.label == wordsArr[t] then
- TFile[#TFile+1]={i,wordsArr[t],j}
- saveTbl(TFile,TRANSPOSER_FILE)
- end
- end
- end
- end
- end
- elseif filesystem.exists(TRANSPOSER_FILE) == true then
- TFile=loadTbl(TRANSPOSER_FILE)
- itemsTransposer={}
- for i=1,#TFile do
- if TFile[i][2] == 'system_out' then
- itemsTransposer={TFile[i][1],TFile[i][2],TFile[i][3]}
- end
- end
- end
- end
- function selectPosListYou(pYou,name,nameItem,mode)
- if mode == 1 then
- youTrade={}
- for i=1,#items do
- for j=1,#youTrade do
- if items[i][1] == name then
- Nitem = i
- break
- end
- end
- if math.floor(items[i][8]*items[i][4]/2) >= math.floor(items[Nitem][8]*2) then
- youTrade[#youTrade+1]=i
- end
- end
- end
- if pos==nil then
- pos = oldName
- end
- l=1+pYou
- j=l+17
- NInListYou=1
- -- drawField(6,7,43,18,' ',0x505050,0x505050)
- for k=l,j do
- if youTrade[k] ~= nil then
- if items[youTrade[k]][1] == nameItem then
- gpu.setBackground(config[1])
- gpu.setForeground(items[youTrade[k]][9])
- gpu.fill(6,6+NInListYou,43,1,' ')
- gpu.set(8,6+NInListYou,unicode.sub(nameItem,1,39))
- gpu.setForeground(0xFFFFFF)
- gpu.setBackground(0x505050)
- NInListYou=NInListYou+1
- else
- gpu.setBackground(0x505050)
- gpu.setForeground(items[youTrade[k]][10])
- gpu.fill(6,6+NInListYou,43,1,' ')
- gpu.set(8,6+NInListYou,unicode.sub(items[youTrade[k]][1],1,39))
- gpu.setForeground(0xFFFFFF)
- gpu.setBackground(0x505050)
- NInListYou=NInListYou+1
- end
- end
- if youTrade[k] == nil and NInListYou<19 then
- gpu.setBackground(0x505050)
- gpu.fill(6,6+NInListYou,43,1,' ') end
- NInListYou=NInListYou+1
- if name ~= nil then
- oldName=name
- end
- end
- end
- function selectPosListTrades(page,name)
- for i=1,#items do
- if items[i][1] == name then
- Nitem=i
- break
- end
- end
- if name==nil then
- name = oldName
- end
- l=1+page
- j=l+17
- NInList=1
- for k=l,j do
- if items[k] ~= nil then
- if items[k][1] == name then
- gpu.setBackground(config[1])
- gpu.setForeground(items[Nitem][9])
- gpu.fill(71,6+NInList,43,1,' ')
- gpu.set(73,6+NInList,unicode.sub(name,1,39))
- gpu.setForeground(0xFFFFFF)
- gpu.setBackground(0x505050)
- NInList=NInList+1
- else
- gpu.setBackground(0x505050)
- gpu.setForeground(items[k][10])
- gpu.fill(71,6+NInList,43,1,' ')
- gpu.set(73,6+NInList,unicode.sub(items[k][1],1,39))
- gpu.setForeground(0xFFFFFF)
- gpu.setBackground(0x505050)
- NInList=NInList+1
- end
- end
- if name ~= nil then
- oldName=name
- end
- end
- end
- function tradeItemFrame()
- TFile=loadTbl(TRANSPOSER_FILE)
- drawEmptyField(1,2)
- drawField(6,7,43,20,' ',0x505050,0x505050)
- drawClound('┌','┐','└','┘','│','─',5,6,45,22,0x505050,0xFFFFFF)
- drawClound('┌','┐','└','┘','│','─',5,25,45,3,0x505050,0xFFFFFF)
- drawText(5,25,45,'[YOU_INVENTORY]',0x505050,0xFFFFFF)
- for i=1,#TFile do
- if TFile[i][2] == 'client_inventory' then
- clientInv={}
- for j=1,cmp.proxy(TFile[i][1]).getInventorySize(TFile[i][3]) do
- itemInSlotChest=cmp.proxy(TFile[i][1]).getStackInSlot(TFile[i][3],j)
- if itemInSlotChest.hasTag == false then
- for t=1,#clientInv do
- if clientInv[t][1]==itemInSlotChest.label then
- N=t
- break
- end
- end
- if clientInv[N][1]==itemInSlotChest.label then
- clientInv[N][2]=clientInv[N][2]+itemInSlotChest.size
- else
- clientInv[#clientInv+1]={itemInSlotChest.label,itemInSlotChest.size}
- end
- end
- end
- end
- end
- --
- l=1+pageYouInv
- j=l+18
- for k=l,j do
- if clientInv[k] ~= nil then
- if items[youTrade[k]][1] == nameItem then
- gpu.setBackground(config[1])
- gpu.setForeground(items[Nitem][9])
- gpu.fill(6,6+k,43,1,' ')
- gpu.set(8,6+k,nameItem)
- gpu.setForeground(0xFFFFFF)
- gpu.setBackground(0x505050)
- else
- gpu.setBackground(0x505050)
- gpu.setForeground(items[youTrade[k]][10])
- gpu.fill(6,6+k,43,1,' ')
- gpu.set(8,6+k,unicode.sub(items[youTrade[k]][1]),1,40)
- gpu.setForeground(0xFFFFFF)
- gpu.setBackground(0x505050)
- end
- end
- if youTrade[k] == nil then
- gpu.setBackground(0x505050)
- gpu.fill(6,6+k,43,1,' ')
- end
- if name ~= nil then
- oldName=name
- end
- end
- --
- end
- function traders()
- youTrade={}
- drawTraderPer=0
- tradersButtons={
- {73,6,39,1},
- {73,7,39,1},
- {73,8,39,1},
- {73,9,39,1},
- {73,10,39,1},
- {73,11,39,1},
- {73,12,39,1},
- {73,13,39,1},
- {73,14,39,1},
- {73,15,39,1},
- {73,16,39,1},
- {73,17,39,1},
- {73,18,39,1},
- {73,19,39,1},
- {73,20,39,1},
- {73,21,39,1},
- {73,22,39,1},
- {73,23,39,1},
- {8,6,39,1}, -- <youList>
- {8,7,39,1},
- {8,8,39,1},
- {8,9,39,1},
- {8,10,39,1},
- {8,11,39,1},
- {8,12,39,1},
- {8,13,39,1},
- {8,14,39,1},
- {8,15,39,1},
- {8,16,39,1},
- {8,17,39,1},
- {8,18,39,1},
- {8,19,39,1},
- {8,20,39,1},
- {8,21,39,1},
- {8,22,39,1},
- {8,23,39,1}, --</youList>
- {5,7,45,20},-- YOU SCROLL
- {70,6,45,20} -- TRADE SCROLL
- }
- --
- page=0
- pageYou=0
- --price,newActiveFore,newNonActiveFore
- --{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}
- while true do
- drawsItems=0
- if drawTraderPer== 0 then
- drawEmptyField(1,1)
- drawField(6,7,43,20,' ',0x505050,0x505050)
- drawClound('┌','┐','└','┘','│','─',5,6,45,22,0x505050,0xFFFFFF)
- drawClound('┌','┐','└','┘','│','─',5,25,45,3,0x505050,0xFFFFFF)
- gpu.set(23,6,'[YOU]')
- drawField(A-49,7,43,20,' ',0x505050,0x505050)
- drawClound('┌','┐','└','┘','│','─',A-50,6,45,22,0x505050,0xFFFFFF)
- drawClound('┌','┐','└','┘','│','─',A-50,25,45,3,0x505050,0xFFFFFF)
- gpu.set(A-31,6,"[Trader]")
- gpu.setBackground(0xFFAA00)
- gpu.set(57,11,' ')
- gpu.set(55,12,' ')
- gpu.set(55,14,' ')
- gpu.set(57,15,' ')
- gpu.set(55,13,' ')
- gpu.setBackground(0x0044FF)
- gpu.fill(57,12,6,3,' ')
- gpu.set(59,13,'OK')
- gpu.setForeground(0xFFAA00)
- gpu.setBackground(0xDCDCDC)
- gpu.set(56,11,'▄')
- gpu.set(63,11,'▄')
- gpu.set(56,15,'▀')
- gpu.set(63,15,'▀')
- gpu.setForeground(0xFFFFFF)
- gpu.setBackground(0x505050)
- -- вывод YOU
- items=loadTbl(ITEM_FILE)
- --вывод traders
- selectPosListTrades(page)
- else
- end
- drawTraderPer=1
- local key,posTraderList,clickMouse,nick=getRawEvent(tradersButtons)
- if key == 'touch' then
- if posTraderList~= 0 or posTraderList ~= nil then
- if clickMouse == 1 and clickMouse~= nil and nick == config[2] and posTraderList < 19 then
- if items[posTraderList+page] ~= nil then
- local NewPriceTraderList,NewActiveForeTraderList,NewNonActiveForeTraderList=addMenuItem(items[posTraderList+page][1])
- items[posTraderList+page][8]=NewPriceTraderList
- items[posTraderList+page][9]=NewActiveForeTraderList
- items[posTraderList+page][10]=NewNonActiveForeTraderList
- saveTbl(items,ITEM_FILE)
- drawTraderPer=0
- end
- elseif clickMouse == 0 and clickMouse~= nil then
- if posTraderList > 18 then
- if youTrade[1] ~= nil and NameItemInTrade~=nil and items[youTrade[posTraderList+page-18]]~=nil then
- ItemSelectInYouList=items[youTrade[posTraderList+pageYou-18]][1]
- selectPosListYou(pageYou,NameItemInTrade,items[youTrade[posTraderList+pageYou-18]][1],0)
- end
- end
- if items[posTraderList+page] ~= nil and posTraderList<19 then
- NameItemInTrade=items[posTraderList+page][1]
- selectPosListTrades(page,NameItemInTrade)
- selectPosListYou(pageYou,NameItemInTrade,ItemSelectInYouList,1)
- end
- end
- end
- elseif key == 'scroll' then
- if posTraderList > 36 and posTraderList < 39 then
- if posTraderList == 37 then
- pageYou=pageYou-(clickMouse)
- if youTrade ~= nil then
- if pageYou < 0 then
- pageYou = 0
- elseif pageYou>math.ceil(#youTrade-18) then
- pageYou = math.ceil(#youTrade-18)
- end
- if youTrade[1]~= nil then
- selectPosListYou(pageYou,NameItemInTrade,ItemSelectInYouList,0)
- end
- end
- elseif posTraderList == 38 then
- page=page-(clickMouse)
- if page < 0 then
- page = 0
- elseif page > math.ceil(#items-18) then
- page = math.ceil(#items-18)
- end
- selectPosListTrades(page,NameItemInTrade)
- end
- end
- end
- end
- end
- -- формула one*условная_цена/2| one*условная_цена*2 [При условии что может стакаться]
- -- Алмаз(100)[1*100/2] {50} | Камень(10)
- -- Камень(10)[1*10/2] (5) | Камень(10*2) 4к1
- -- Алмаз(1000) [1*1000/2] (500) | Камень(10*2)
- -- Алмаз(1000) [1*1000/2] (500) {32000} | Гибридка(250000*2)
- -- Гибридка(250000) [1*250000/2] (175000) | 4к1
- local function drawColorSelectorAddMenu(arr,i,n)
- if oldN1 == nil then
- oldN1 = 1
- end
- if oldN2 == nil then
- oldN2 = 6
- end
- drawField(arr[i][1],arr[i][2],arr[i][3],1,' ',arr[i][4],arr[i][5])
- if n == 0 then
- drawClound('┌','┐','└','┘','│','─',arr[i][1]-1,arr[i][2]-1,4,3,0x505050,arr[i][5])
- elseif n == 1 then
- drawClound('┌','┐','└','┘','│','─',arr[i][1]-1,arr[i][2]-1,4,3,0x505050,arr[i][6])
- end
- if i > 5 and oldN2 ~= i then
- drawField(arr[oldN2][1],arr[i][2],arr[oldN2][3],1,' ',arr[oldN2][4],arr[oldN2][5])
- drawClound('┌','┐','└','┘','│','─',arr[oldN2][1]-1,arr[oldN2][2]-1,4,3,0x505050,arr[oldN2][5])
- elseif i < 6 and oldN1 ~= i then
- drawField(arr[oldN1][1],arr[i][2],arr[oldN1][3],1,' ',arr[oldN1][4],arr[oldN1][5])
- drawClound('┌','┐','└','┘','│','─',arr[oldN1][1]-1,arr[oldN1][2]-1,4,3,0x505050,arr[oldN1][5])
- end
- if i > 5 and n == 1 then
- oldN2=i
- elseif i < 6 and n == 1 then
- oldN1=i
- end
- end
- local function drawButtonAddMenu(arr,i)
- drawField(arr[i][1],arr[i][2],arr[i][3],1,'▄',arr[i][4],arr[i][5])
- drawField(arr[i][1],arr[i][2]+1,arr[i][3],1,' ',arr[i][5],arr[i][5])
- drawField(arr[i][1],arr[i][2]+2,arr[i][3],1,'▄',arr[i][5],arr[i][4])
- end
- function checkExport()
- local items = loadTbl(ITEM_FILE)
- local meControllers = cmp.list('me_interface')
- for i , val in pairs(meControllers) do
- local inNetwork=cmp.proxy(i).getItemsInNetwork()
- for l=1,9 do
- local inSlot = cmp.proxy(i).getStackInSlot(l)
- if #items == 0 or #items == nil then
- if inSlot~= nil then
- if inSlot.id ~= nil then
- price,activeColor,nonActiveColor=addMenuItem(inSlot.display_name)
- for h=1,#inNetwork do
- if inNetwork[h].name == inSlot.id or inNetwork[h].name == inSlot.raw_name then
- itemsInNetwork=inNetwork[h].size
- break
- else
- itemsInNetwork=0
- end
- if itemsInNetwork == nil then
- itemsInNetwork = 0
- end
- end
- maxSize=inSlot.max_size
- items[#items+1]={inSlot.display_name,inSlot.id,inSlot.raw_name,maxSize,inSlot.qty,itemsInNetwork,itemsInNetwork+inSlot.qty,price,activeColor,nonActiveColor}
- saveTbl(items,'/'..ITEM_FILE)
- end
- end
- else
- if inSlot~= nil then
- if inSlot.id ~= nil then
- foundItem=0
- for j=1,#items do
- if items[j][2] == inSlot.id and items[j][3] == inSlot.raw_name then
- foundItem=1
- break
- end
- end
- if foundItem == 0 then
- price,activeColor,nonActiveColor=addMenuItem(inSlot.display_name)
- for h=1,#inNetwork do
- if inNetwork[h].name == inSlot.id or inNetwork[h].name == inSlot.raw_name then
- itemsInNetwork=inNetwork[h].size
- break
- else
- itemsInNetwork=0
- end
- if itemsInNetwork == nil then
- itemsInNetwork = 0
- end
- end
- maxSize=inSlot.max_size
- items[#items+1]={inSlot.display_name,inSlot.id,inSlot.raw_name,maxSize,inSlot.qty,itemsInNetwork,itemsInNetwork+inSlot.qty,price,activeColor,nonActiveColor}
- saveTbl(items,'/'..ITEM_FILE)
- end
- end
- end
- end
- end
- end
- end
- function addMenuItem(item)
- local price = 0
- local buttonsAddMenuItem={ -- структура {x,y,w,color_back,color_fore}
- {50,9,20,0x505050,0,0xFFFFFF},-- черное поле
- {45,9,4,0x505050,0xFFAA00,0xFFFFFF}, -- [-1]
- {39,9,5,0x505050,0xFFAA00,0xFFFFFF}, -- [-10]
- {71,9,4,0x505050,0xFFAA00,0xFFFFFF}, -- [+1]
- {76,9,5,0x505050,0xFFAA00,0xFFFFFF}, -- [+10]
- {32,9,6,0x505050,0xFFAA00,0xFFFFFF}, -- [-100]
- {82,9,6,0x505050,0xFFAA00,0xFFFFFF} -- [+100]
- }
- 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}
- }
- while true do
- if drawsItems == 1 then
- gpu.setBackground(config[1])
- gpu.fill(43,24,34,1,' ')
- drawText(43,24,34,item,config[1],newActiveFore)
- gpu.setBackground(0x505050)
- gpu.fill(43,17,34,1,' ')
- drawText(43,17,34,item,0x505050,newNonActiveFore)
- gpu.setBackground(0)
- gpu.fill(50,10,20,1,' ')
- drawText(51,10,18,price,0,0xFFFFFF)
- else
- drawField(30,7,60,20,' ',0x505050,0x505050)
- drawClound('┌','┐','└','┘','│','─',30,7,60,20,0x505050,0xFFFFFF)
- for i=1,#buttonsAddMenuItem do
- drawButtonAddMenu(buttonsAddMenuItem,i)
- end
- for i=1,#colorFrameToSelect do
- drawColorSelectorAddMenu(colorFrameToSelect,i,0)
- end
- drawField(30,29,28,5,' ',0x898989,0x505050)
- drawClound('┌','┐','└','┘','│','─',30,29,28,5,0x898989,0xFFFFFF)
- gpu.set(53,8,'Условная цена:')
- gpu.set(48,12,'Цвет неактивного текста:')
- gpu.set(49,19,'Цвет активного текста:')
- gpu.setBackground(0xFFAA00)
- gpu.set(46,10,'-1')
- gpu.set(40,10,'-10')
- gpu.set(72,10,'+1')
- gpu.set(77,10,'+10')
- gpu.set(33,10,'-100')
- gpu.set(83,10,'+100')
- gpu.setBackground(0x505050)
- gpu.set(35,17,'Example:')
- drawText(43,17,34,item,0x505050,0xFFFFFF)
- gpu.set(35,24,'Example:')
- gpu.setBackground(config[1])
- gpu.fill(43,24,34,1,' ')
- drawText(43,24,34,item,config[1],0xFFFFFF)
- gpu.setBackground(0x505050)
- drawText(51,10,18,price,0,0xFFFFFF)
- drawColorSelectorAddMenu(colorFrameToSelect,1,1)
- drawColorSelectorAddMenu(colorFrameToSelect,6,1)
- newActiveFore=0xFFFFFF
- newNonActiveFore=0xFFFFFF
- drawsItems = 1
- end
- local posButtonAddMenu,_ = buttonsCatch(2,2)
- if posButtonAddMenu > 0 and posButtonAddMenu < 7 then
- if posButtonAddMenu == 1 then
- price = price - 1
- elseif posButtonAddMenu == 2 then
- price = price - 10
- elseif posButtonAddMenu == 3 then
- price = price + 1
- elseif posButtonAddMenu == 4 then
- price = price + 10
- elseif posButtonAddMenu == 5 then
- price = price - 100
- elseif posButtonAddMenu == 6 then
- price = price + 100
- end
- if price < 0 then
- price = 0
- elseif price > 999999999999999999 then
- price = 999999999999999999
- end
- drawButtonAddMenu(buttonsAddMenuItem,1)
- drawText(51,10,18,price,0,0xFFFFFF)
- end
- if posButtonAddMenu > 6 and posButtonAddMenu < 12 then
- if posButtonAddMenu == 7 then
- newNonActiveFore=colorFrameToSelect[1][4]
- drawColorSelectorAddMenu(colorFrameToSelect,1,1)
- elseif posButtonAddMenu == 8 then
- newNonActiveFore=colorFrameToSelect[2][4]
- drawColorSelectorAddMenu(colorFrameToSelect,2,1)
- elseif posButtonAddMenu == 9 then
- newNonActiveFore=colorFrameToSelect[3][4]
- drawColorSelectorAddMenu(colorFrameToSelect,3,1)
- elseif posButtonAddMenu == 10 then
- newNonActiveFore=colorFrameToSelect[4][4]
- drawColorSelectorAddMenu(colorFrameToSelect,4,1)
- elseif posButtonAddMenu == 11 then
- newNonActiveFore=colorFrameToSelect[5][4]
- drawColorSelectorAddMenu(colorFrameToSelect,5,1)
- end
- drawText(43,17,34,item,0x505050,newNonActiveFore)
- end
- if posButtonAddMenu > 11 and posButtonAddMenu < 17 then
- if posButtonAddMenu == 12 then
- newActiveFore=colorFrameToSelect[6][4]
- drawColorSelectorAddMenu(colorFrameToSelect,6,1)
- elseif posButtonAddMenu == 13 then
- newActiveFore=colorFrameToSelect[7][4]
- drawColorSelectorAddMenu(colorFrameToSelect,7,1)
- elseif posButtonAddMenu == 14 then
- newActiveFore=colorFrameToSelect[8][4]
- drawColorSelectorAddMenu(colorFrameToSelect,8,1)
- elseif posButtonAddMenu == 15 then
- newActiveFore=colorFrameToSelect[9][4]
- drawColorSelectorAddMenu(colorFrameToSelect,9,1)
- elseif posButtonAddMenu == 16 then
- newActiveFore=colorFrameToSelect[10][4]
- drawColorSelectorAddMenu(colorFrameToSelect,10,1)
- end
- gpu.setBackground(config[1])
- gpu.fill(43,24,34,1,' ')
- drawText(43,24,34,item,config[1],newActiveFore)
- gpu.setBackground(0x505050)
- end
- if posButtonAddMenu == 17 then
- break
- end
- end
- return price,newActiveFore,newNonActiveFore
- end
- -- Выберете цвет для выделения товаров:
- function colorSelector(txt)
- local colorPos1 = 0
- local colorPos2 = 0
- local colorPos3 = 0
- local colorPos4 = 0
- local colorPos5 = 0
- local colorPos6 = 0
- local function F16(n)
- N=nil
- if n > 9 then
- if n==10 then
- N = 'A'
- elseif n == 11 then
- N = 'B'
- elseif n == 12 then
- N = 'C'
- elseif n == 13 then
- N = 'D'
- elseif n == 14 then
- N = 'E'
- elseif n == 15 then
- N = 'F'
- else N = n
- end
- end
- if N == nil then N=n end
- return N
- end
- local buttonsSettings={{60,20,10,0x505050,0,0xFFFFFF}}
- drawEmptyField(1,2)
- drawField(30,15,60,11,' ',0x505050,0x505050)
- drawClound('┌','┐','└','┘','│','─',30,15,60,11,0x505050,0xFFFFFF)
- drawText(40,17,40,txt,0x505050,0xFFFFFF)
- gpu.setBackground(0)
- gpu.set(52,21,'0x')
- gpu.set(54,21,'000000')
- drawField(47,21,2,1,' ',0,0x505050)
- drawClound('┌','┐','└','┘','│','─',46,20,4,3,0x505050,0xFFFFFF)
- gpu.setBackground(0x505050)
- gpu.setForeground(0xFFAA00)
- gpu.set(54,20,'▲▲▲▲▲▲')
- gpu.set(54,22,'▼▼▼▼▼▼')
- gpu.setForeground(0xFFFFFF)
- gpu.setBackground(0x898989)
- gpu.fill(64,20,20,3,' ')
- gpu.set(73,21,'OK')
- gpu.setBackground(0x505050)
- newColor=0
- while true do
- local posSettingMenu,_ = buttonsCatch(3,2)
- if posSettingMenu > 0 and posSettingMenu < 13 then
- if posSettingMenu == 1 then
- colorPos1 = colorPos1+1
- elseif posSettingMenu == 2 then
- colorPos2 = colorPos2+1
- elseif posSettingMenu == 3 then
- colorPos3 = colorPos3 + 1
- elseif posSettingMenu == 4 then
- colorPos4 = colorPos4 + 1
- elseif posSettingMenu == 5 then
- colorPos5 = colorPos5 + 1
- elseif posSettingMenu == 6 then
- colorPos6 = colorPos6 + 1
- elseif posSettingMenu == 7 then
- colorPos1 = colorPos1-1
- elseif posSettingMenu == 8 then
- colorPos2 = colorPos2-1
- elseif posSettingMenu == 9 then
- colorPos3 = colorPos3 - 1
- elseif posSettingMenu == 10 then
- colorPos4 = colorPos4 - 1
- elseif posSettingMenu == 11 then
- colorPos5 = colorPos5 - 1
- elseif posSettingMenu == 12 then
- colorPos6 = colorPos6 - 1
- end
- if colorPos1 > 15 then
- colorPos1 = 15
- elseif colorPos2 > 15 then
- colorPos2 = 15
- elseif colorPos3 > 15 then
- colorPos3 = 15
- elseif colorPos4 > 15 then
- colorPos4 = 15
- elseif colorPos5 > 15 then
- colorPos5 = 15
- elseif colorPos6 > 15 then
- colorPos6 = 15
- end
- if colorPos1 < 0 then
- colorPos1 = 0
- elseif colorPos2 < 0 then
- colorPos2 = 0
- elseif colorPos3 < 0 then
- colorPos3 = 0
- elseif colorPos4 < 0 then
- colorPos4 = 0
- elseif colorPos5 < 0 then
- colorPos5 = 0
- elseif colorPos6 < 0 then
- colorPos6 = 0
- end
- local F1=F16(colorPos1)
- local F2=F16(colorPos2)
- local F3=F16(colorPos3)
- local F4=F16(colorPos4)
- local F5=F16(colorPos5)
- local F6=F16(colorPos6)
- gpu.setBackground(0)
- gpu.set(54,21,tostring(F1..F2..F3..F4..F5..F6))
- newColor=tonumber('0x'..F1..F2..F3..F4..F5..F6)
- drawField(47,21,2,1,' ',newColor,0x505050)
- drawClound('┌','┐','└','┘','│','─',40,46,4,3,0x505050,0xFFFFFF)
- gpu.setBackground(0x505050)
- end
- if posSettingMenu == 13 then
- drawEmptyField(1,2)
- break
- end
- end
- return newColor
- end
- function getOwner(col)
- drawErr('Кто владелец?',3,0)
- getOwnerButtons={{54,18,10,0x505050,0x00AA00,0xFFFFFF}}
- drawButtonAddMenu(getOwnerButtons,1)
- gpu.setBackground(0x00AA00)
- gpu.set(56,19,'click!')
- gpu.setBackground(0x505050)
- while true do
- local posOwnerMenu,owner=buttonsCatch(4)
- if posOwnerMenu == 1 then
- configs=loadTbl(CONGFIG_FILE)
- newConfig={col,owner}
- saveTbl(newConfig,CONGFIG_FILE)
- break
- end
- end
- gpu.setBackground(0x505050)
- end
- --░▒▓ ►◄▼▲ 123123
- function start()
- drawEmptyField(1,2)
- drawErr('Добро пожаловать!',1,2)
- if filesystem.exists(ITEM_FILE) == false then
- file=io.open(ITEM_FILE,'w')
- file:write('{}')
- file:close()
- end
- if filesystem.exists(CONGFIG_FILE) == false then
- file=io.open(CONGFIG_FILE,'w')
- file:write('{}')
- file:close()
- end
- config=loadTbl(CONGFIG_FILE)
- if filesystem.exists(CONGFIG_FILE) == false or config[1] == nil or config[2] == nil then
- file=io.open(CONGFIG_FILE,'w')
- file:write('{}')
- file:close()
- drawErr('Настройка системы...',1,2)
- colorSelect=colorSelector('Выберете цвет для выделения товаров:')
- getOwner(colorSelect)
- config=loadTbl(CONGFIG_FILE)
- else
- config=loadTbl(CONGFIG_FILE)
- end
- end
- start()
- checkExport()
- traders()
- while true do
- if pos == nil then
- pos = 1
- drawEmptyField(1,1)
- else
- pos=buttonsCatch(1)
- end
- if pos == 1 then
- drawEmptyField(1,1)
- traders()
- elseif pos == 2 then
- drawEmptyField(1,1)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement