File GUIUtils.lua

Functions

PadHexNum (incString) Pads a hex number to ensure a minimum of 2 digits.
RGB2Hex (red, green, blue) Converts an RGB value into an HTML compliant(label usable) HEX number.
bg (colorName) Sets current background color to a named color.
cecho (...) Echo string with embedded color name information.
cinsertText (...) Inserts string with embedded color name information.
color_table () The color_table table holds definition of color names.
createConsole (consoleName, fontSize, charsPerLine, numberOfLines, Xpos, Ypos) Make a new console window with ease.
createGauge (gaugeName, width, height, Xpos, Ypos, gaugeText, color1, color2, color3) Make your very own customized gauge with this function.
decho (...) Echo string with embedded decimal color information.
deselect () Clears the current selection in the main window or miniConsole window.
dinsertText (...) Inserts string with embedded decimal color information.
fg (colorName) Sets current foreground color to a named color.
gagLine () Function will gag the whole line.
gaugesTable () The gaugesTable table.
getRGB (colorName) Get RGB component from color name.
handleWindowResizeEvent () Default resizeEvent handler function.
hecho (...) Echo string with embedded hex color information.
hinsertText (...) Inserts string with embedded hex color information.
moveGauge (gaugeName, newX, newY) Move a custom gauge.
prefix (what, func, fg, bg, window) Prefixes text at the beginning of the current line when used in a trigger.
replaceAll (word, what) Replaces all occurrences of what in the current line with with.
replaceLine (what) Replace the whole with a string you'd like.
replaceWildcard (what, replacement) Replaces the given wildcard (as a number) with the given text.
resizeGauge (gaugeName, width, height) TODO resizeGauge(gaugeName, width, height)
setGauge (gaugeName, currentValue, maxValue, gaugeText) Use this function when you want to change the gauges look according to your values.
setGaugeStyleSheet (gaugeName, css, cssback) TODO setGaugeStyleSheet(gaugeName, css, cssback)
setGaugeText (gaugeName, gaugeText, color1, color2, color3) Set the text on a custom gauge.
showColors (...) Prints out a formatted list of all available named colors, optional arg specifies number of columns to print in, defaults to 3
suffix (what, func, fg, bg, window) Suffixes text at the end of the current line when used in a trigger.
xEcho (style, insert, win, str) Generic color echo and insert function (allowing hecho, decho, cecho, hinsertText, dinsertText and cinsertText).


Functions

PadHexNum (incString)
Pads a hex number to ensure a minimum of 2 digits.
Parameters
  • incString:
Usage:
  • Following command will returns "F0".
        PadHexNum("F")
     
RGB2Hex (red, green, blue)
Converts an RGB value into an HTML compliant(label usable) HEX number. This function is colorNames aware and can take any defined global color as its first argument.
Parameters
  • red:
  • green:
  • blue:
Usage:
  • Both following commands will returns "FFFFFF".
        RGB2Hex(255,255,255)
        RGB2Hex("white")
     
See also:
  • MISSING LINK: 'showColor'
bg (colorName)
Sets current background color to a named color.
Parameters
  • colorName:
Usage:
  • Set background color to magenta.
        bg("magenta")
     
See also:
cecho (...)
Echo string with embedded color name information.
Parameters
  • ...:
Usage:
  • Consider following example:
        cecho("<green>green text <blue>blue text <red>red text")
     
See also:
cinsertText (...)
Inserts string with embedded color name information.
Parameters
  • ...:
See also:
color_table ()
The color_table table holds definition of color names. These are intended to be used in conjunction with fg() and bg() colorizer functions.
See also:
createConsole (consoleName, fontSize, charsPerLine, numberOfLines, Xpos, Ypos)
Make a new console window with ease. The default background is black and text color white. If you wish to change the color you can easily do this when updating your text or manually somewhere, using setFgColor() and setBackgroundColor().
Parameters
  • consoleName:
  • fontSize:
  • charsPerLine:
  • numberOfLines:
  • Xpos:
  • Ypos:
Usage:
  • This will create a miniconsole window that has a font size of 8pt, will display 80 characters in width, hold a maximum of 20 lines and be place at 200x400 of your Mudlet window.
        createConsole("myConsoleWindow", 8, 80, 20, 200, 400)
     
createGauge (gaugeName, width, height, Xpos, Ypos, gaugeText, color1, color2, color3)
Make your very own customized gauge with this function.
Parameters
  • gaugeName:
  • width:
  • height:
  • Xpos:
  • Ypos:
  • gaugeText:
  • color1:
  • color2:
  • color3:
Usage
  • This would make a gauge at that's 300px width, 20px in height, located at Xpos and Ypos and is green.
        createGauge("healthBar", 300, 20, 30, 300, nil, 0, 255, 0)
     
  • The second example is using the same names you'd use for something like fg() or bg().
        createGauge("healthBar", 300, 20, 30, 300, nil, "green")
     
  • Finally we'll add some text to our gauche.
        createGauge("healthBar", 300, 20, 30, 300, "Now with some text", "green")
     
decho (...)
Echo string with embedded decimal color information.

Color changes can be made using the format <FR,FG,FB:BR,BG,BB> where each field is a number from 0 to 255. The background portion can be omitted using <FR,FG,FB> or the foreground portion can be omitted using <:BR,BG,BB>.
Parameters
  • ...:
Usage:
  • Print red test on green background.
        decho("<255,0,0:0,255,0>test")
     
See also:
deselect ()
Clears the current selection in the main window or miniConsole window.
(Note: deselect(windowName) is implemented in Core Mudlet.)
Usage
  • Clear selection in main window.
        deselect()
     
  • Clear selection in myMiniConsole window.
        deselect("myMiniConsole")
     
dinsertText (...)
Inserts string with embedded decimal color information.
Parameters
  • ...:
See also:
fg (colorName)
Sets current foreground color to a named color.
Parameters
  • colorName:
Usage:
  • Set foreground color to black.
        fg("black")
     
See also:
gagLine ()
Function will gag the whole line. Use deleteLine() instead.
gaugesTable ()
The gaugesTable table. First we need to make this table which will be used later to store important data in.
getRGB (colorName)
Get RGB component from color name.
Parameters
  • colorName:
Usage:
  • Following will display "0.255.0" on your screen.
        local red, green, blue = getRGB("green")
        echo(red .. "." .. green .. "." .. blue )
     
handleWindowResizeEvent ()
Default resizeEvent handler function. Overwrite this function to make a custom event handler if the main window is being resized.

The standard implementation of this function does nothing. However, this function gets called whenever the main window is being manually resized. You can overwrite this function in your own scripts to handle window resize events yourself and e.g. adjust the screen position and size of your mini console windows, labels or other relevant GUI elements in your scripts that depend on the size of the main Window. To override this function you can simply put a function with the same name in one of your scripts thus overwriting the original empty implementation of this function.
    function handleWindowResizeEvent()
       -- determine the size of your screen
       WindowWidth=0;
       WindowHeight=0;
       WindowWidth, WindowHeight = getMainWindowSize();
       -- move mini console "sys" to the far right side of the screen whenever the screen gets resized
       moveWindow("sys",WindowWidth-300,0)
    end
 

hecho (...)
Echo string with embedded hex color information.

Color changes can be made within the string using the format |cFRFGFB,BRBGBB where FR is the foreground red value, FG is the foreground green value, FB is the foreground blue value, BR is the background red value, etc., BRBGBB is optional. |r can be used within the string to reset the colors to default.
Parameters
  • ...:
See also:
hinsertText (...)
Inserts string with embedded hex color information.
Parameters
  • ...:
See also:
moveGauge (gaugeName, newX, newY)
Move a custom gauge.
Parameters
  • gaugeName:
  • newX:
  • newY:
Usage:
  • This would move the health bar gauge to the location 1200, 400.
        moveGauge("healthBar", 1200, 400)
     
See also:
prefix (what, func, fg, bg, window)
Prefixes text at the beginning of the current line when used in a trigger.
Parameters
  • what:
  • func:
  • fg:
  • bg:
  • window:
Usage:
  • Prefix the hours, minutes and seconds onto our prompt even though Mudlet has a button for that.
        prefix(os.date("%H:%M:%S "))
     
See also:
replaceAll (word, what)
Replaces all occurrences of what in the current line with with.
Parameters
  • word:
  • what:
Usage:
  • This will replace all occurrences of John with the word Doe.
        replaceAll("John", "Doe")
     
replaceLine (what)
Replace the whole with a string you'd like.
Parameters
  • what:
See also:
replaceWildcard (what, replacement)
Replaces the given wildcard (as a number) with the given text.
Parameters
  • what:
  • replacement:
Usage:
  • Replace "goodbye" with "hello" on a trigger of "^You wave (goodbye)\.$"
        replaceWildcard(2, "hello")
     
    Is equivalent to doing:
        selectString(matches[2], 1)
        replace("hello")
     
resizeGauge (gaugeName, width, height)
TODO resizeGauge(gaugeName, width, height)
Parameters
  • gaugeName:
  • width:
  • height:
setGauge (gaugeName, currentValue, maxValue, gaugeText)
Use this function when you want to change the gauges look according to your values. Typical usage would be in a prompt with your current health or whatever value, and throw in some variables instead of the numbers.
Parameters
  • gaugeName:
  • currentValue:
  • maxValue:
  • gaugeText:
Usage
  • In that example, we'd change the looks of the gauge named healthBar and make it fill to half of its capacity. The height is always remembered.
        setGauge("healthBar", 200, 400)
     
  • Change the text on your gauge.
        setGauge("healthBar", 200, 400, "some text")
     
setGaugeStyleSheet (gaugeName, css, cssback)
TODO setGaugeStyleSheet(gaugeName, css, cssback)
Parameters
  • gaugeName:
  • css:
  • cssback:
setGaugeText (gaugeName, gaugeText, color1, color2, color3)
Set the text on a custom gauge.
Parameters
  • gaugeName:
  • gaugeText: An empty gaugeText will clear the text entirely.
  • color1: Colors are optional and will default to 0,0,0(black) if not passed as args.
  • color2:
  • color3:
Usage
  •     setGaugeText("healthBar", "HP: 100%", 40, 40, 40)
     
  •     setGaugeText("healthBar", "HP: 100%", "red")
     
See also:
showColors (...)
Prints out a formatted list of all available named colors, optional arg specifies number of columns to print in, defaults to 3
Parameters
  • ...:
Usage
  • Print list in 3 columns by default.
        showColors()
     
  • Print list in 2 columns.
        showColors(2)
     
See also:
suffix (what, func, fg, bg, window)
Suffixes text at the end of the current line when used in a trigger.
Parameters
  • what:
  • func:
  • fg:
  • bg:
  • window:
See also:
xEcho (style, insert, win, str)
Generic color echo and insert function (allowing hecho, decho, cecho, hinsertText, dinsertText and cinsertText).
Parameters
  • style: Hex, Decimal or Color
  • insert: boolean flag to determine echo/insert behaviour
  • win: windowName optional
  • str: text with embedded color information
See also:

Valid XHTML 1.0!