This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Neywiny's profile picture

openperipharals add text over icon

Started by Neywiny, 14 December 2014 - 03:39 PM
Neywiny #1
Posted 14 December 2014 - 04:39 PM
Hey all, I'm having trouble with openperipheral glasses.

I need to draw text over an icon, but whenever I addText it goes behind the addIcon. It is drawn after the icon, as seen with the code, but it draws behind the icon.

b = peripheral.wrap("right")
s = peripheral.wrap("left")
--print(s.listMethods())
posx = {2,23,40,57,74,91,108,125,142,159}
posy = {1,18,35,52}
tpos = {{2,4},{3,4},{4,4},{5,4},{6,4},{7,4},{8,4},{9,4},{10,4},{2,1},{3,1},{4,1},{5,1},{6,1},{7,1},{8,1},{9,1},{10,1},{2,2},{3,2},{4,2},{5,2},{6,2},{7,2},{8,2},{9,2},{10,2},{2,3},{3,3},{4,3},{5,3},{6,3},{7,3},{8,3},{9,3},{10,3},{1,4},{1,3},{1,2},{1,1}}
x = s.getPlayerNames()
player = x[1]
data = s.getPlayerData(player)
b.clear()
b.addBox(0,0,177,70,0xc6c6c6)
for i = 1,4 do
  b.addBox(2,(i*17)-16,16,16,0x8b8b8b)
end
for z = 1,9 do
  for i = 1,4 do
    b.addBox((z*17)+6,(i*17)-16,16,16,0x8b8b8b)
  end
end
for f = 1,4 do
  for i = 1,10 do
    --b.addIcon(posx[i],posy[f],1,0)
  end
end
b.addBox(23,51,152,1,0x3f3f3f)
for k,v in pairs(data.inventory) do
  if v.qty ~= 0 then
    --print(textutils.serialize(v))
    b.addIcon(posx[tpos[k][1]],posy[tpos[k][2]],v.id,v.dmg)
    if v.qty ~= 1 then
   x = string.sub(v.qty,string.find(v.qty,"."))
	  b.addText((posx[tpos[k][1]]+20)-9*#x,posy[tpos[k][2]]+9,x)
    end
  end
end
its a short code, but does a good job of what I want. feel free to run it if you want, but I'd prefer to take credit for my work if anybody wants to use it.
for those who didn't run it, as seen when the computer draws the GUI, it draws the box in the back, the text in the middle, and the icon in the front.
Neywiny #2
Posted 14 December 2014 - 04:48 PM
I have just tried drawing the icon after the text. no luck.
Lyqyd #3
Posted 14 December 2014 - 08:19 PM
There's supposed to be a setZindex method or something, which would allow you to manually adjust the draw order.
AgentE382 #4
Posted 14 December 2014 - 09:41 PM
I think Lyqyd's right. You should try listing the methods of the wrapped bridge to see what's there. Also, the various addXXX methods might return a handle that you can use to modify the added element. Try assigning that to a variable and listing the methods on it.

I'm away from my PC for the next few days, but I think that's true.
Edited on 14 December 2014 - 08:41 PM
Neywiny #5
Posted 14 December 2014 - 10:11 PM
I'll try it out when I have time. thanks for the response.
Neywiny #6
Posted 14 December 2014 - 11:30 PM
alright. there is a set z function, it works. thanks.