HUD Groups

by Forum_account
An easy way to manage screen objects. [More]
To download this library for your Linux/Mac installation, enter this on your command line:

DreamDownload byond://Forum_account.HudGroups##version=10

Emulator users, in the BYOND pager go to File | Open Location and enter this URL:


Version 10
Date added: Nov 14 2011
Last updated: Jul 7 2012
19 fans
This library provides you with objects you can use to create and manage screen objects. You don't have to compute, parse, or set values for the screen_loc var or manage the client.screen list. The library handles these details for you so you can focus on implementing a functional HUD without getting bogged down in the details.

Version 10 (posted 07-07-2012)
  • Added the ability to next HudGroups inside each other. Calling HudGroup1.add(HudGroup2) will make HudGroup2 a child of HudGroup1.
  • HudGroups have a list of their child HudGroups and a reference to their parent group. It's possible for either or both of those vars to be null.
  • HudGroups inherit visibility and position from their parent. If you call hide() for one group, hide() will be called for its child HudGroups (and recursively on their children). If you call pos() on a HudGroup it'll update the positions of all nested HudGroups and the HudObjects they contain.
Version 9 (posted 06-27-2012)
  • Added the HudGroup.add(HudObject) format. You could already remove HudObjects by calling HudGroup.remove(). This is handy for creating cursors or other objects that are part of the hud group but may be hidden and shown.
Version 8 (posted 04-21-2012)
  • Added support for maptext. You can call the HudObject.set_maptext(maptext, width, height) proc to set the screen object's maptext. The last two arguments are used to set maptext_width and maptext_height, which are both 32 by default. Each argument defaults to null and the values are only updated if the parameters aren't null.
  • Updated the party-demo to show how you can use maptext.
  • Updated the chat-demo to contain an implementation of an on-screen chat log that uses maptext.
  • Updated the text-demo to show how you can use maptext.
Version 7 (posted 02-26-12)
  • Made the HudInput control in the interface-demo play nice with the Keyboard library's NO_KEY_REPEAT flag.
  • Fixed a bug in the Font object's wrap_text() proc. Previously it hadn't been taking into account line breaks in the string you passed to the proc.
  • Added the minimap-demo which shows how to create a minimap that tracks and shows the positions of mobs.
Version 6 (posted 12-07-11)
  • Added the DragAndDrop() proc to the HudGroup object, which is called when a HudObject's MouseDrop() proc is called. You can override the group's DragAndDrop proc to create custom behavior for the group. The proc takes two arguments - the first is the HudObject you're dragging, the second is the object you dropped it on (which might not be a HudObject).
  • Added the "inventory-demo", which contains an on-screen inventory system. Walk over items to pick them up. Use the "toggle inventory" verb to hide or show your inventory, and drag items to move them, equip them, or unequip them.
  • Changed the px and py vars on the HudObject object to "sx" and "sy" so they don't conflict with other libraries of mine.
  • Changed the __px and __py vars of the HudGroup object to be called "sx" and "sy". These vars can be used to reference the group's current position but shouldn't be modified. To change the group's position use its pos() proc.
  • Made some internal changes to how HudGroups hide and show HudObjects, which makes use of the new __hide_object() and __show_object() procs.
  • Added the ability to type spaces to in interface-demo.
  • Added the #define statement to include the Keyboard library only if you have included in the interface-demo.
  • Added to interface-demo. This file defines the "game form" verb which brings up a game creation form. You can type a name, select a level, and click submit, which calls the form's submit() proc which prints out the values you selected.
Version 5 (posted 12-03-11)
  • Added the HudInput control to the interface-demo. This is an on-screen textbox that players can type in. The demo was updated to include one on screen text box whose value is output when you click the "ok" button. This demo now requires the Forum_account.Keyboard library which can be found here:
Version 4 (posted 11-30-11)
  • Added the width and height named parameters to the HudGroup's add proc. These specify the width and height of the screen object just like you would by calling the HudObject's size() proc.
  • Added the "chat-demo", which shows how to create and use an on-screen chat log.
  • Added some procs to the Font object which are just aliases of other procs. The original procs had misleaning names because the name said "word" but you didn't have to pass just one word to the proc, you could pass a multi-word string. The aliases say "text" instead, but the original procs are kept anyway.
    • Added the text_width() proc to the Font object which is just an alias of the word_width proc.
    • Added the cut_text() proc to the Font object which is just an alias of the cut_word() proc.
  • Added the "interface-demo", which contains HUD-based implementations of some interface controls. Each control is implemented as its own type of HudGroup, which means you just have to instantiate the object type to create the control and can use its pos() proc to move it. The demo currently contains:
    • Labels: labels can display text and capture click events, so they can also be used as buttons. You can set the background color, size, text alignment, action (the proc that's called when clicked), and position.
    • Buttons: they're a child type of the label object that have some different default values (ex: size, background color, border, etc.)
    • Option Groups: you can define a set of options and the selection mode. The selection mode determines if the list uses radio buttons (you select a single value) or check boxes (you select any combination of values).
Version 3 (posted 11-17-11)
  • Changed how objects are added to HudGroups. The HudGroup's add proc can be used in one of three forms. Parameters written in square brackets are optional named parameters you can set.
    • add(client/c) - adds a client to the list of players viewing the hud group. Returns 0 or 1.
    • add(mob/m) - adds the mob's client to the list of viewers. Returns 0 or 1.
    • add(x, y, ...) - creates a screen object at the specified location and returns the HudObject that was created. There are many named arguments you can also use to set properties of the new object: icon_state, text, layer, and value.
  • Changed how objects are removed from HudGroups. The HudGroup's remove() proc can now be used in one of five forms. All return 1 or 0 to indicate success or failure:
    • remove(client/c) - removes a client from the list of viewers
    • remove(mob/m) - removes the mob's client from the list of viewers
    • remove(HudObject/h) - removes the object from the group
    • remove(index) - removes the object at the specified index in the group's "objects" list from the group.
    • remove() - removes the last object in the group.
  • Added the cut_word() proc to the Font object. The proc takes a string and a width (in pixels) and returns the part of the string that fits inside that width. For example, calling cut_word("testing", 16) might return "test", because that's all that can fit inside 16 pixels.
  • Added the "border-demo" which shows how to create a border around the edge of the player's screen that can be updated as the player's screen size changes.
  • Added the "party-demo", which shows how to create an on-screen indicator of where your allies are located.
Version 2 (posted 11-16-11)
  • Added support for text - call the HudGroup's add_text() proc to create a screen object with text attached to it. You can also call the HudObject's set_text() proc to set or udpate its text.
  • Added support for fonts. Font objects are necessary for writing text on a screen object. They can also be used to make text that wraps to fit inside a specified width. See the Font object in for more details.
  • Added two new demos:
    • text-demo shows the bare minimum that's required to draw text on the screen using a font.
    • message-box-demo shows how to create an on-screen message box, the message is dynamically updated and the box is closed by clicking an "Ok" button.
Version 1 (posted 11-15-11)
  • Initial post.
  • Contains the HudGroup and HudObject objects.
  • Contains three demos: flyout-menu-demo, health-bar-demo,
    and menu-demo.


Forum_account: (Jan 11 2014, 5:59 am)
Killua - yugioh wrote:
Thank you forum_account. I found this quite useful to use. I would like to request adding show() and hide() for hud objects. Thanks again!

A little late on answering this, but, I think there were two reasons for leaving these procs out:

1. The HudGroup objects can be hidden and shown and I didn't want to deal with cases where you have a hidden HudObject inside a visible HudGroup (or a visible HudObject inside a hidden group). Having the entire group be visible or hidden keeps it simpler.

2. You can call group.remove(object) to hide a single object and group.add(object) to show it again.

Now that I think about it, you might be able to do something like this:



But I'm not sure if that'd always work. There might be some issues that come from changing a hud group while the object is removed, but calling hud_group.add() should update any properties to reflect changes made to the group while the object was removed.
Killua - yugioh: (Dec 28 2012, 10:38 am)
Thank you forum_account. I found this quite useful to use. I would like to request adding show() and hide() for hud objects. Thanks again!
Shellfisch: (Apr 29 2012, 12:06 am)
oh ok i try it with the lastest beta version :)
Edit: Working with latest version
Toddab503: (Apr 28 2012, 11:23 pm)
He did. I'm guessing you didn't read the documentation, because it looks like you're including more than one demo at a time which is the cause of your compile problems.

Make sure to read through things carefully, it'll help a lot.

Edit: Oh, and you also may need the latest beta version of BYOND.
Shellfisch: (Apr 28 2012, 11:05 pm)
Undefined vars D: make it newbie friendly please

C:\Users\usr\Documents\BYOND\lib\forum_account\hudgroups\hud maptext_width: undefined var
C:\Users\usr\Documents\BYOND\lib\forum_account\hudgroups\hud maptext_height: undefined var
C:\Users\usr\Documents\BYOND\lib\forum_account\hudgroups\men u-demo\ attack: duplicate definition
C:\Users\usr\Documents\BYOND\lib\forum_account\keyboard\simp le-demo\ attack: previous definition
C:\Users\usr\Documents\BYOND\lib\forum_account\hudgroups\men u-demo\ speak: duplicate definition
C:\Users\usr\Documents\BYOND\lib\forum_account\keyboard\simp le-demo\ speak: previous definition
C:\Users\usr\Documents\BYOND\lib\forum_account\hudgroups\hud src.maptext: undefined var
C:\Users\usr\Documents\BYOND\lib\forum_account\hudgroups\hud src.maptext_width: undefined var
C:\Users\usr\Documents\BYOND\lib\forum_account\hudgroups\hud src.maptext_height: undefined var

menu-demo.dmb - 9 errors, 0 warnings (double-click on an error to jump to it)