View difference between Paste ID: hS5SfdyR and FLG2SKe6
SHOW: | | - or go back to the newest paste.
1
local version = "Dev" --(26/06 2020)
2
os.loadAPI("/spawner/f") -- a monitor API made by myself, it makes my life easier
3
os.loadAPI("/spawner/lib/API") -- search_bar
4
os.loadAPI("/spawner/lib/APIjson")
5
local list_items,items = {},{}
6
local a,b,c,chestSize = 1,1,1,100
7
local Pcheck = false
8
9-
b = {}
9+
10-
function addButton(m,x1,y1,x2,y2,name)
10+
11-
  b[name] = {win = window.create(m,x1,y1,x2,y2)}
11+
12-
  b[name]["pos"] = {b[name].win.getPosition()} b[name]["size"] = {b[name].win.getSize()}
12+
13-
  b[name]["isClicked"] =
13+
14-
  function(x,y)
14+
15-
    local l = {x1,y1,x2+x1,y2+y1)
15+
16-
    return f.box(x,y,l[1],l[2],l[3],l[4])
16+
17
18
function addWin(m,x1,y1,x2,y2,name)
19
  local b = window.create(m,x1,y1,x2,y2)
20
  b.pos = {b.getPosition()}
21
  b.size = {b.getSize()}
22
  b.name = name
23
  function b:getName() return b.name end
24
  function b:isClicked(x,y) return f.itrv(x,b.pos[1],b.pos[1]+b.size[1]) and f.itrv(y,b.pos[2],b.pos[2]+b.size[2]-1) end
25
  return b
26
end
27-
  bg = window.create(m,1,1,w,h)
27+
28-
  list = window.create(m,1,2,w*3/5-1,chestSize)
28+
function setWindows()
29-
  up_bar = window.create(m,1,1,w,1)
29+
  bg = addWin(m,1,1,w,h) bg.reset = {bg_color="black"}
30-
  down_bar = window.create(m,1,h,w,h)
30+
  list = addWin(m,1,2,w*3/5-1,chestSize) list.reset = {bg_color="black"}
31-
  scroll_bar = window.create(m,w*(3/5),2,1,h-1)
31+
  up_bar = addWin(m,1,1,w,1) up_bar.reset = {bg_color="lightGray"}
32-
  bg2 = window.create(m,w*0.6+1,2,w*0.4+1,h-1)
32+
  down_bar = addWin(m,1,h,w,h) down_bar.reset = {bg_color="lightGray",printText = function()
33-
  pbg2 = {bg2.getPosition()} sbg2 = {bg2.getSize()}
33+
    f.centerTextRight(down_bar,1,"v"..version,"black","lightGray") end}
34-
  addButton(bg2,2,13,sbg2[1]-2,3,"button1")
34+
  scroll_bar = addWin(m,w*(3/5),2,1,h-1) scroll_bar.reset = {bg_color="lightGray",printText = function()
35-
  addButton(bg2,2,9,5,3,"button2")
35+
    f.cprint(scroll_bar,1,1,"^","black","gray")
36-
  addButton(bg2,2,3,5,3,"spawner1") addButton(bg2,10,3,5,3,"spawner2") addButton(bg2,18,3,5,3,"spawner3")
36+
    f.cprint(scroll_bar,1,h-2,"v","black","gray") end}
37-
  for q=1,3 do bq = b["spawner"..q]
37+
  bg2 = addWin(m,w*0.6+1,2,w*0.4+1,h-1) bg2.reset = {bg_color="gray",printText = function()
38-
  b["spawner"..q].reset = function() b["spawner"..q].win.setBackgroundColor(colors.black) b["spawner"..q].win.clear() 
38+
    f.cprint(bg2,2,1,"Mob: ","white","gray")
39-
  f.cprint(b["spawner"..q].win,3,2,q,"lightGray","black") end
39+
    f.cprint(bg2,8,10,"Status: ","white","gray") end}
40-
  b["spawner"..q].selected = function() b["spawner"..q].win.setBackgroundColor(colors.magenta) 
40+
  b1 = addWin(m,2,13,bg2.size[1]-2,3,"button1") b1.reset = {bg_color="red",printText = function()
41-
  b["spawner"..q].win.clear() f.cprint(b["spawner"..q].win,3,2,q,"black","magenta") end
41+
    f.centerText(b1,2,"i/o","black","red") end}
42-
  b["spawner"..q].reset()
42+
  b2 = addWin(m,2,9,5,3,"button2") b2.reset = {bg_color="red",printText = function()
43
    f.centerText(b2,"Rafraichir","black","purple") end}
44
  b = {}
45-
getPeriphs()
45+
  b[1] = addWin(m,2,3,5,3) b[2] = addWin(m,10,3,5,3) b[3] = addWin(m,18,3,5,3)
46
  for i=1,3 do
47
    b[i]["notSelected"]={bg_color="black",printText=function() f.cprint(b[i],3,2,i,"lightGray","black") end}
48
    b[i]["selected"] = {bg_color="magenta",printText=function() f.cprint(b[i],3,2,i,"black","magenta") end}
49
  end
50
end
51
52
function apply(obj,name)
53
  if f.vn(obj[name]) then
54
    local metatable = {__Index = obj[name]}
55
    setmetatable(index, metatable)
56
    obj.setBackgroundColor(index.bg_color)
57
    obj.clear()
58
  else error("object not found") end
59
end
60
61
local default = {
62
  spawner1={side="east",curr_item=""},
63
  spawner2={side="north",curr_item=""},
64-
local VIP = {"TheBaslez","SesameChocolat","Jaguar","LeChikito","jungleis26","Ertupop","Veine","annelaure1912","Gaetann18",
64+
65-
"GohuSan","boucherreb","Ciliste"}
65+
66-
local GUIDES = {"zorinova","DaikiKaminari","maxou684"}
66+
67
  player_name="MarkFergus",
68
  server="infinity.mineaurion.com",
69-
  bg.setBackgroundColor(colors.black) bg.clear()
69+
70-
  list.setBackgroundColor(colors.black) list.clear()
70+
71-
  up_bar.setBackgroundColor(colors.lightGray) up_bar.clear()
71+
72-
  down_bar.setBackgroundColor(colors.lightGray) down_bar.clear()
72+
73-
  scroll_bar.setBackgroundColor(colors.lightGray) scroll_bar.clear()
73+
74-
  bg2.setBackgroundColor(colors.gray) bg2.clear()
74+
75-
  b["button1"].win.setBackgroundColor(colors.purple) b["button1"].win.clear()
75+
76-
  b["button2"].win.setBackgroundColor(colors.red) b["button2"].win.clear()
76+
77-
  f.centerTextRight(down_bar,1,"v"..version,"black","lightGray")
77+
78-
  if fxd~=nil then f.cprint(down_bar,1,1,fxd.getMaxEnergyStored()-fxd.getEnergyStored().." RF","red","lightGray") end
78+
79-
  f.cprint(scroll_bar,1,1,"^","black","gray")
79+
  apply(bg,"reset") apply(bg2,"reset") apply(list,"reset")
80-
  f.cprint(scroll_bar,1,h-2,"v","black","gray")
80+
  apply(up_bar,"reset") apply(down_bar,"reset") apply(scroll_bar,"reset")
81-
  f.cprint(bg2,2,1,"Mob: ","white","gray")
81+
  apply(b1,"reset")  apply(b2,"reset")
82
  --for i=1,3 do 
83-
  f.cprint(bg2,8,10,"Status: ","white","gray")
83+
  --  if rubrique == i then b[i].apply("selected") f.cprint(bb[i],3,2,i,"black","magenta")
84-
  if index.enable == true then f.cprint(bg2,16,10,"actif  ","lime","gray") else f.cprint(bg2,16,10,"inactif","purple","gray") end
84+
  --  else b[i].apply("notSelected") end
85-
  f.centerText(b["button1"].win,2,"Rafraichir","black","purple")
85+
  --end
86-
  f.centerText(b["button2"].win,2,"i/o","black","red")
86+
  if f.vn(fxd) then f.cprint(down_bar,1,1,fxd.getMaxEnergyStored()-fxd.getEnergyStored().." RF","red","lightGray") end
87
  f.cprint(bg2,7,1,index["spawner"..rubrique].curr_item,"purple","gray")
88-
  if rubrique == 1 then b["spawner1"].selected() f.centerText(up_bar,1,"config. spawner 1","black","lightGray")
88+
  if index.enable then f.cprint(bg2,16,10,"actif  ","lime","gray") else 
89-
  else b["spawner1"].reset() end
89+
  f.cprint(bg2,16,10,"inactif","purple","gray") end
90-
  if rubrique == 2 then b["spawner2"].selected() f.centerText(up_bar,1,"config. spawner 2","black","lightGray")
90+
91-
  else b["spawner2"].reset() end
91+
92-
  if rubrique == 3 then b["spawner3"].selected() f.centerText(up_bar,1,"config. spawner 3","black","lightGray")
92+
93-
  else b["spawner3"].reset() end
93+
94
  if check1 == true then
95
  b = 1
96
  items = {}
97
  if chestSize ~= nil then
98-
  local b = 1
98+
99
      item = p.getStackInSlot(a)
100
      if item ~= nil and item.name == "mobSoul" then
101
        items[b] = {}
102
        items[b][1] = a
103
        for ab=1,#nbt_index do
104
          if item.nbt_hash == nbt_index[ab].nbt_hash then items[b][2] = nbt_index[ab].name end
105
        end
106
        items[b]["qty"] = item.qty
107
        b = b + 1
108
      end
109
    end
110
  end
111
  if display == nil then display = items end
112
  end
113
end
114
115
function list_display(check1)
116
  if check1 == true then
117
  for c=1,#display do
118
    if c == selected then
119
      f.drawLine(list,1,c,w,"lightBlue")
120
      f.centerTextRight(list,c,tostring(items[c].qty),"black")
121
    else
122
      list.setBackgroundColor(colors.black)
123
    end
124
    if display[c][3] == nil then
125
      f.centerText(list,c,display[c][2],"purple")
126
    end
127
  end
128
  else f.centerText(list,1,"No chest found","red","black") end
129
end
130
131
function scroll(direction)
132
  local x,y = list.getPosition()
133
  if direction == "up" and y <=1 then
134
    list.reposition(1,y+2)
135
  elseif direction == "down" and y+#items > h-1 then
136
    list.reposition(1,y-2)
137
  end
138
end
139
  
140
function checkPlist()
141
  str = APIjson.decode(http.get("http://api.mineaurion.com/v1/serveurs/"..index.server).readAll())
142
  local Pcheck = false
143
  for i,v in pairs(str.joueurs) do
144
    if v == index.player_name then Pcheck = true end
145
  end
146
  if (Pcheck==true and index.enable==true) then rs.setAnalogOutput(index.rside,15) else rs.setAnalogOutput(index.rside,0) end
147
end
148
149
function updateIndex()
150
  shell.run("rm","/spawner/config")
151
  index.rubrique = rubrique index.selected = selected
152
  f3 = fs.open("/spawner/config","w") f3.write(textutils.serialise(index)) f3.close()
153
end
154
155
 getPeriphs() setWindows()
156
157
while true do
158
  reset() getItems(isChest) list_display(isChest)
159-
  reset()
159+
  down_bar.redraw() up_bar.redraw()
160-
  getItems(isChest)
160+
  checkPlist() updateIndex()
161-
  list_display(isChest)
161+
162-
  down_bar.redraw()
162+
163-
  up_bar.redraw()
163+
  if event[1] == "peripheral_detach" or event[1] == "peripheral" then getPeriphs() setWindows() end
164-
  checkPlist()
164+
165-
  updateIndex()
165+
166-
  xl,yl = list.getPosition()
166+
167-
  j,k = scroll_bar.getPosition()
167+
    if y-list.pos[1]+1 == selected and display[selected] ~= nil and x < scroll_bar.pos[1]-1 then
168
      up_bar.clear()
169
      f.centerText(up_bar,1,"reconfiguration...","black")
170-
  if event[1] == "peripheral_detach" or event[1] == "peripheral" then getPeriphs() end
170+
171
      p.pushItem(index["spawner"..rubrique].side,display[selected][1],1)
172
      index["spawner"..rubrique].curr_item = display[selected][2]
173
      getItems(isChest)
174-
    if y-yl+1 == selected and display[selected] ~= nil and x < j-1 then
174+
    elseif y > 1 and x < scroll_bar.pos[1]-1 then
175
      selected = y-yl+1
176
    elseif y == 2 and x == scroll_bar.pos[1] then
177
      scroll("up")
178
    elseif list.pos[2] == h-1 and event[3] == scroll_bar.pos[1] then
179
      scroll("down")
180
    elseif bg2.isClicked(x,y) then
181-
    elseif y > 1 and x < j-1 then
181+
182
      for i=1,3 do if b[i].isClicked(xc,yc) then rubrique = i end end
183-
    elseif y == 2 and x == j then
183+
      if b1.isClicked(xc,yc) then
184
        if index.enable == true then index.enable = not index.enable end
185-
    elseif yl == h-1 and event[3] == j then
185+
186
      if b2.isClicked(xc,yc) then
187-
    elseif f.itrv(x,pbg2[1],pbg2[1]+sbg2[1]) and f.itrv(y,pbg2[2],pbg2[2]+sbg2[2]) then
187+
188
        sleep(0.4)
189-
      if b["button1"].isClicked(xc,yc) then
189+
190
    end
191
  end
192
end