File GUIUtils.lua
-- GUI Utils -- --
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 (window, text) | cecho(window,text). |
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 (window, text) | decho(window, text) |
deselect () | deselect() |
fg (colorName) | Sets current foreground color to a named color. |
gagLine () | Function will gag the whole line. |
getRGB (colorName) | Get RGB component from color name. |
handleResizeEvent () | TODO - is this correct? what about handleWindowResizeEvent Default resizeEvent handler function. |
hecho (...) | TODO put some doc for each func |
moveGauge (gaugeName, newX, newY) | Move a custom gauge built by createGauge(...) |
prefix (what, func, fg, bg, window) | Echo something before your line |
replaceAll (word, what) | Replace all words on the current line by your choice |
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) | 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) | setGaugeStyleSheet(gaugeName, css, cssback) |
setGaugeText (gaugeName, gaugeText, color1, color2, color3) | Set the text on a custom gauge built by createGauge(...). |
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) | Echo something after your line |
xEcho (style, insert, win, str) | xEcho(style, insert, win, str) |
Functions
- PadHexNum (incString)
-
Pads a hex number to ensure a minimum of 2 digits.
Parameters
- incString:
Usage:
- PadHexNum("F") returns "F0"
- 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 arg
Parameters
- red:
- green:
- blue:
Usage
- RGB2Hex(255,255,255) returns "FFFFFF"
- RGB2Hex("white") returns "FFFFFF"
- bg (colorName)
-
Sets current background color to a named color.
Parameters
- colorName:
Usage:
- bg("magenta")
See also:
- cecho (window, text)
-
cecho(window,text). TODO
HEIKO: using this as a replacement until the problems of the real function are fixed. function cecho(window, text) local win = text and window local s = text or window local reset if win then reset = function() resetFormat(win) end else reset = function() resetFormat() end end reset() for color, text in s:gmatch("<([a-zA-Z_:]+)>([^<>]+)") do if color == "reset" then reset() if win then echo(win, text) else echo(text) end else local colist = string.split(color..":", "%s*:%s*") local fgcol = colist[1] ~= "" and colist[1] or "white" local bgcol = colist[2] ~= "" and colist[2] or "black" local FGrgb = color_table[fgcol] local BGrgb = color_table[bgcol] if win then setFgColor(win, FGrgb[1], FGrgb[2], FGrgb[3]) setBgColor(win, BGrgb[1], BGrgb[2], BGrgb[3]) echo(win,text) else setFgColor(FGrgb[1], FGrgb[2], FGrgb[3]) setBgColor(BGrgb[1], BGrgb[2], BGrgb[3]) echo(text) end end end reset() end
Parameters
- window:
- text:
- 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:
- createConsole("myConsoleWindow", 8, 80, 20, 200, 400)
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.
- 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
- createGauge("healthBar", 300, 20, 30, 300, nil, 0, 255, 0)
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, "green")
The second example is using the same names you'd use for something like fg() or bg(). - createGauge("healthBar", 300, 20, 30, 300, "Now with some text", 0, 255, 0)
- createGauge("healthBar", 300, 20, 30, 300, "Now with some text", "green")
- decho (window, text)
-
decho(window, text)
Parameters
- window:
- text:
- deselect ()
- deselect()
- fg (colorName)
-
Sets current foreground color to a named color.
Parameters
- colorName:
Usage:
- fg("black")
See also:
- gagLine ()
- Function will gag the whole line. Use deleteLine() instead.
- 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 )
- handleResizeEvent ()
- TODO - is this correct? what about handleWindowResizeEvent Default resizeEvent handler function. Overwrite this function to make a custom event handler if the main window is being resized.
- hecho (...)
-
TODO put some doc for each func
Parameters
- ...:
- moveGauge (gaugeName, newX, newY)
-
Move a custom gauge built by createGauge(...)
Parameters
- gaugeName:
- newX:
- newY:
Usage:
- moveGauge("healthBar", 1200, 400)
This would move the health bar gauge to the location 1200, 400
- prefix (what, func, fg, bg, window)
-
Echo something before your line
Parameters
- what:
- func:
- fg:
- bg:
- window:
- replaceAll (word, what)
-
Replace all words on the current line by your choice
Parameters
- word:
- what:
Usage:
- replaceAll("John", "Doe")
This will replace the word John with the word Doe, everytime the word John occurs on the current line.
- replaceLine (what)
-
Replace the whole with a string you'd like.
Parameters
- what:
- replaceWildcard (what, replacement)
-
Replaces the given wildcard (as a number) with the given text.
Parameters
- what:
- replacement:
Usage:
- replaceWildcard(1, "hello")
on a trigger of `^You wave (goodbye)\.$`
- resizeGauge (gaugeName, width, height)
-
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
- setGauge("healthBar", 200, 400)
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, "some text")
change the text on your gauge
- setGaugeStyleSheet (gaugeName, css, cssback)
-
setGaugeStyleSheet(gaugeName, css, cssback)
Parameters
- gaugeName:
- css:
- cssback:
- setGaugeText (gaugeName, gaugeText, color1, color2, color3)
-
Set the text on a custom gauge built by createGauge(...).
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
- showColors()
- showColors(2)
Print list in 2 columns.
- suffix (what, func, fg, bg, window)
-
Echo something after your line
Parameters
- what:
- func:
- fg:
- bg:
- window:
- xEcho (style, insert, win, str)
-
xEcho(style, insert, win, str)
Parameters
- style:
- insert:
- win:
- str: