popupbox
var/client/client // who can see this box right now?
var/mob/M // the mob that goes with client
var/list/items // items to be shown on screen
var/list/screenitems
var/list/backdrop // the background
var/x, y
var/width, height
New(mob/_M, list/_items, _x, _y)
if(!_M || !_M.client) del(src)
M = _M
client = _M.client
items = _items
var/viewx, viewy
if(isnum(client.view))
viewx = client.view * 2 + 1
viewy = viewx
else
var/index = findtext(client.view, "x")
viewx = text2num(copytext(client.view, 1, index))
viewy = text2num(copytext(client.view, index+1))
x = _x; y = _y
if(x < 0) x += viewx+1 // x==-1 means right edge
if(y < 0) y += viewy+1 // y==-1 means top edge
// round up from items.len/viewx
height = round((items.len + viewx - 1) / viewx)
// round up from items.len/width
width = round((items.len + height - 1) / height)
if(x + width - 1 > viewx) x = max(viewx - width + 1, 1)
if(y + height - 1 > viewy) y = max(viewy - height + 1, 1)
backdrop = list(new/obj/backdrop(src))
screenitems = new
var/n = 0
for(_y in y+height-1 to y step -1) // fill from the top down
for(_x in x to (x+width-1))
if(++n > items.len) break
screenitems += new/obj/popupitem(src, "[_x],[_y]", items[n])
//M.pbox = src
Del()
// if(M /*&& M.pbox == src*/) //M.pbox = null
if(backdrop)
if(client) client.screen -= backdrop
for(var/O in backdrop)
del(O)
if(screenitems)
if(client) client.screen -= screenitems
for(var/O in screenitems)
del(O)
..()
proc/Select(atom/item)
del(src)
obj/backdrop
var/popupbox/box
var/client/client
icon = 'popup.dmi'
icon_state = "backdrop"
layer = 20
New(popupbox/_box)
box = _box
client = box.client
screen_loc = "[box.x],[box.y] to \
[box.x+box.width-1],[box.y+box.height-1]"
if(client) client.screen += src
Del()
if(client) client.screen -= src
..()
Click()
box.Select(null)
obj/popupitem
var/popupbox/box
var/client/client
var/atom/item
layer = 21
New(popupbox/_box, newloc, atom/_item)
box = _box
client = box.client
screen_loc = newloc
item = _item
icon = item.icon
icon_state = item.icon_state
dir = item.dir
if(client) client.screen += src
Del()
if(client) client.screen -= src
..()
Click()
box.Select(item)
obj/item/weapon
Drop()
..()
if(usr.weapon == src) usr.weapon = null
Use()
..()
if(usr.weapon == src)
usr.weapon = null
usr << "You put away [src]."
else
usr.weapon = src
usr << "You arm yourself with [src]."
mob
var/obj/item/weapon/weapon
verb/Weapon() // choose a weapon
set src = usr
if(pbox) del(pbox)
var/list/L = list()
if(weapon) L += weapon // put the current weapon first
for(var/obj/item/weapon/w in contents)
if(w != weapon) L += w
if(L.len)
pbox=new/popupbox/inventory(usr, L, -1, 1)
else usr << "You are unarmed."
Errors:
Datum Testing.dm:117:error: pbox: undefined var
Datum Testing.dm:117:error: pbox: undefined var
Datum Testing.dm:123:error: pbox: undefined var
Datum Testing.dm:123:error: /popupbox/inventory: undefined type path
Datum Testing.dm:39:error: M.pbox: undefined var
Datum Testing.dm:42:error: M.pbox: undefined var
Datum Testing.dm:42:error: M.pbox: undefined var
Datum Testing.dm:100:error: Drop: undefined proc
Datum Testing.dm:103:error: Use: undefined proc
Datum Testing.dmb - 9 errors
I am not sure how I should define the pbox variable, how I should set up having a datum under a datum called inventory, and how I should go about defining the Drop and Use procs. Any help is appreciated, and thank-you!
Lummox JR