Skip to content

GUI FML

arikel edited this page Nov 22, 2011 · 3 revisions

GUI FML

The in-game Heads Up Display (HUD) is programmable using an FML API. This API is detailed on this page.

Details

To define a GUI, place a file under data/gui. Each file details one type of GUI. If you put your GUI in data/gui/xxx.cfg then in your level, add gui="xxx" to tell the user to use that GUI. Each level can use exactly one GUI.

The GUI .cfg file should contain a document in a [gui] element. This document may contain the following elements:

- any number of [animation] tags. These animation tags contain animation definitions which are identical to the animation definitions inside objects. - on_process and on_draw attributes which contain formulas.

The on_process and on_draw formulas are executed every cycle. These formulas get access to the following variables:

- level: the level object. In particular, level.player is very important to access. - object: the GUI has an object associated with it. This object is of type dummy_gui_object. The object does not exist in the level, but is useful for storing variables in associated with the GUI.

The on_process formula is run every cycle, and has access to the normal object manipulation API. It can be used to update any variables inside the GUI object, which will modify how the GUI is displayed.

The on_draw formula is run every cycle during drawing. The on_draw formula does NOT have access to the normal object manipulation API and functions. Instead it gets access to an API specially designed for drawing on the screen:

- draw_animation(animation_id, x, y[, time_in_animation]):

This function will draw the animation that is defined in the GUI, with the given animation_id at position (x, y) on the screen. time_in_animation specifies the number of cycles into the animation drawn. If omitted, the animation will be made to continuously cycle.

- draw_animation(object_id, animation_id, x, y[, time_in_animation]):

This is a variation of the above draw_animation that draws the animation found in the object given by 'object_id', rather than in the GUI's list of animations.

- draw_number(number, places, x, y):

This function will draw a number using a "slot machine" type number. The number drawn will be number/100, with number%100 indicating how far the lowest digit is scrolled along to the next digit. For instance, 8650 indicates to draw the number 86, with the 6 halfway scrolled to a 7. 'places' indicates how many digits to show in the display.

The on_draw formula should inspect the level and object, and draw all of the elements of the GUI using the above commands.

Clone this wiki locally