ID:2383111
 
(See the best response by MisterPerson.)
Code:
obj/crhud
text_window
icon = HUD_ICON
layer = HUD_LAYER
maptext_width = 384
maptext_height = 288


top
icon_state = "Top"
screen_loc = "CENTER-6,CENTER+4 to CENTER+6,CENTER+4"
bottom
icon_state = "Bottom"
screen_loc = "CENTER-6,CENTER-4 to CENTER+6,CENTER-4"
right
icon_state = "Right"
screen_loc = "CENTER+7,CENTER-3 to CENTER+7,CENTER+3"
left
icon_state = "Left"
screen_loc = "CENTER-7,CENTER+3 to CENTER-7,CENTER-3"
top_right
icon_state = "Top Right"
screen_loc = "CENTER+7,CENTER+4"
bottom_right
icon_state = "Bottom Right"
screen_loc = "CENTER+7,CENTER-4"
top_left
icon_state = "Top Left"
screen_loc = "CENTER-7,CENTER+4"
bottom_left
icon_state = "Bottom Left"
screen_loc = "CENTER-7,CENTER+-4"
middle
icon_state = "BG"
screen_loc = "CENTER-6,CENTER-3 to CENTER+6,CENTER+3"


mob/proc/Demo()
Freeze()
src.client.crhud_add(/obj/crhud/text_window)


Problem description: I'm attempting to use Crispy's HeadsUp library to make my own HUDS, and I'm having trouble. I've gone through all of the libraries I could find and this one was the easiest for me to understand, but I'm aware it may not be the most efficient.

If I keep the libraries addatstart variable on, then it populates my text window just fine upon startup. But after toggling that off and then trying to call on the crhud_add() proc in the first step of my demo, it does nothing. Is there a better way to go about this? Any help would be appreciated.

/*************************************************************

Crispy.HeadsUp
VERSION 2

**************************************************************

An automated HUD library. Just define the HUD object under
/obj/crhud, give it a default screen_loc, and let the library
handle the rest. It's that simple!

Includes the optional ability to drag HUD objects around the
screen to customise the interface. This even optionally
supports pixel offsets!

This library has a standard prefix, crhud, which precedes all
vars and procs that it defines. This is done to avoid conflicts
with other libraries, and with any vars and procs you may have
defined.

Version 2 fixes some bugs caused by the changes to client.eye
that were made in BYOND versions 336, 338, 339 and 341.

See http://www.byond.com/people/Crispy for contact details.

INSTRUCTIONS:
Include this library in your project by ticking the checkbox
next to 'Crispy.HeadsUp' under the Lib entry on the left
panel. (Tick the checkbox while your project is open, NOT
this library!)

Define each HUD object you need as a separate type under
/obj/crhud. For each object, specify its screen_loc (where
it appears on the screen; look it up in the DM reference for
more information). If you want to use any of this library's
advanced capabilities for that HUD object (such as dragging
and pixel dragging), set the appropriate vars
(see "User-modifiable vars" below).

KNOWN BUGS:
- Pixel offset dragging is slightly buggy. It works fine,
except for a slight cosmetic bug - namely, if you drag a
HUD object a short distance (so that the centre of the new
position is over a part of the object in its old position),
that counts as a click on the HUD object rather than a drag
of it.

- If the player can see past the edge of the map,
they will not be able to move HUD objects to some areas of
their screen while they are near the edge. To work around
this, set client.perspective to EDGE_PERSPECTIVE (which
prevents the player from seeing past the edge of the map)
or make sure that the player can never get close enough to
the edge of a map to see past it.

USER-MODIFABLE VARS:
/obj/crhud/crhud_addatstart (default: true)
If this is true (default), HeadsUp will automatically
add this HUD object to the HUD of everyone who logs in.

/obj/crhud/crhud_draggable (default: false)
If this is true, players can drag this type of HUD object
around on their screen to customize their HUD layout.

/obj/crhud/crhud_dragpixel (default: false)
If this is true, players can drag this type of HUD object
to locations on the screen with pixel offsets. This var
has no effect if crhud_draggable is false.

ATOMS:
/obj/crhud
Used for all HUD objects managed by HeadsUp.

CLIENT PROCS:
crhud_add(hudtype)
Adds a HUD object of the specified type to the client's
HUD. hudtype can be any subtype of /atom/movable.

crhud_remove(hudtype)
Like crhud_add(), but removes all HUD objects of the
specified type from the client's HUD. Does not remove
subtypes of 'hudtype'.

*/


obj/crhud
layer=200

var/crhud_addatstart=0
var/crhud_draggable=0
var/crhud_dragpixel=0

proc/crhud_add(client/C)
if (istype(C)) C.screen+=src

proc/crhud_remove(client/C)
if (istype(C)) C.screen-=src

MouseDrop(atom/over_object)
.=..()
if (!crhud_draggable || !usr.client) return
if (!over_object || !istype(over_object)) return

//Are we dragging it to another HUD object?
if (over_object!=src && (over_object in usr.client.screen))
//Can't drag to another HUD object
return

var{scrx;scry;viewx;viewy}

if ((!over_object.loc || (over_object in usr.client.screen)) && istype(over_object,/atom/movable))
////// Dragged to HUD object
var/atom/movable/O=over_object
scrx=text2num(O.screen_loc)
scry=text2num(copytext(screen_loc,findtext(screen_loc,",")+1))
else
////// Dragged to object in the world
////Compare location of over_object to the location of client.virtual_eye
var/atom/eyeloc=usr.client.virtual_eye
if (!eyeloc) eyeloc=usr
var/atom/objloc=locate(over_object.x,over_object.y,over_object.z)

if (!objloc) return

////Get screen_loc
scrx=objloc.x-eyeloc.x+1
scry=objloc.y-eyeloc.y+1

//Get size of client.view
var/viewsize=usr.client.view
if (isnum(viewsize))
viewx=viewsize
viewy=viewsize
else
//Extract viewx and viewy from text string
viewx=round(text2num(viewsize)/2)
viewy=round(text2num(copytext(viewsize,findtext(viewsize,"x")+1))/2)

//Work out screen_loc position
scrx+=viewx
scry+=viewy
if (crhud_dragpixel)
screen_loc="[scrx]:[usr.crhud_mousepixelx-16],[scry]:[usr.crhud_mousepixely-16]"
else
screen_loc="[scrx],[scry]"

New()
//Set drag pointer
if (crhud_draggable && !mouse_drag_pointer) mouse_drag_pointer=icon(icon,icon_state,dir)
.=..()

client/New()
//Add HUD objects
for (var/X in typesof(/obj/crhud)-/obj/crhud)
var/obj/crhud/O=new X()
if (O.crhud_addatstart && O.screen_loc) O.crhud_add(src)
else del O

.=..()

client/proc/crhud_add(X)
////X is the type of hud object to add to this client's HUD

//Get HUD object
var/atom/movable/HudObj=new(X)

//Add to HUD
screen+=HudObj

client/proc/crhud_remove(X)
////X is the type of hud object to remove from this client's HUD
for (var/obj/crhud/H in screen) if (H.type==X) screen-=H

//Keep track of the pixel offset of the user's mouse (for pixel dragging purposes)
atom/MouseUp(location,iconx,icony)
..()
usr.crhud_mousepixelx=iconx
usr.crhud_mousepixely=icony

mob/var
crhud_mousepixelx=16
crhud_mousepixely=16


For reference, here is the meat of the library.
Best response
You're just adding the base object /obj/hud/text_window. Try adding all the typesof(/obj/hud/text_window) - /obj/hud/text_window instead.
In response to MisterPerson
MisterPerson wrote:
You're just adding the base object /obj/hud/text_window. Try adding all the typesof(/obj/hud/text_window) - /obj/hud/text_window instead.

So do I need to re-write his proc with a for(typesof())? Or am I just calling his proc wrongly?
Still need clarification. Tried adding that to the arguments. Tried modifying the proc in the library itself. Nothing seems to work.