My latest (fun) side-project that consumed my scripting time these last couple days.
The main purpose of this was to create what I believe is "cuter" (and more flexible) GUI code.
Pretty much every function returns the object, or the object it created. Objects that are created are also joined to gui_builder which allows them access to the same functions. Which in practice allows me to write more "verbose" code. I.e:
PHP Code:
// assuming an object with the ID "Other" exists
createButton("New"). // Create Button with "New" as it's ID
position(). // Position it (Actually sets it position to 0,0 but below fixes the position)
below("Other"). // Below the "Other" object
offset(0, 16). // Offset it's position by 0 X and 16 Y
built(); // Button is now Built
When you're done creating and manipulating an gui_builder object you call the built() function to leave the class, and it returns the parent of the object which allows you to traverse your creation in the same function call.
You can use catch/bind to catch events like onAction to your own functions. I.e: bind("onAction", "onButtonClicked").
I've also added dimensions(width, height) which allows you to change the clientwidth and clientheight of the object. This is much better explained with code however.
Example:
PHP Code:
function onCreated() {
this.join("gui_builder");
}
//#CLIENTSIDE
function onCreated() {
// Create Window
// Calling it Test"Window" is kind of redundant since the builder automatically
// places _Window at the end of it's ID.
createWindow("TestWindow").
features().
canclose().
dimensions(300, 10 + 32 * 13).
text("Test Window").
center();
// Add Buttons
for (temp.button: {"Hello", "Test", "Winning"}) {
getWindow("TestWindow").
createButton(temp.button).
text(temp.button).
position(2, 2).
sizing("width", "").
dimensions(300 - 4, 32).
below(temp.last, 2).
bind("onAction", "onButtonClicked").
built();
temp.last = temp.button;
}
// Adding More Controls
getWindow("TestWindow").
// Add Text
createText("TestText").
profileMods().
profileMod("fontsize", 20).
profileMod("fontstyle", "b").
text("This is nifty!").
position().
below("Winning", 2).
center("x").
offset(-4, 0).
built().
// Add Text Edit
createTextEdit("TestTextEdit").
copy("Winning", "dimensions").
position().
below("TestText", 2).
copy("Winning", "x").
built();
// Add Checkboxes
for (temp.checkbox: {"A", "B", "C", "D", "E"}) {
getWindow("TestWindow").
createCheckBox(temp.checkbox).
dimensions(60, 16).
text(temp.checkbox).
position().
below("TestTextEdit", 2).
offset(16, 6).
rightOf(temp.last_check).
built();
temp.last_check = temp.checkbox;
}
// Add Radio Buttons
for (temp.radio: {"1", "2", "3", "4", "5"}) {
getWindow("TestWindow").
createRadioButton(temp.radio).
dimensions(60, 16).
text(temp.radio).
position().
below("A").
offset(0, 16).
rightOf(temp.last_radio).
built();
temp.last_radio = temp.radio;
}
// TextList
getWindow("TestWindow").
createScroll("TestScroll").
copy("Winning", "dimensions").
height(100).
position().
below("1", 4).
offset(-16, 0).
createTextList("List").
addRows({"Hello", player.account, "OMG!", "WTF?"}).
built().
built().
createScroll("TestMLScroll").
copy("TestScroll", "dimensions").
position().
below("TestScroll", 2).
createMLText("Description").
copy("TestScroll", "dimensions").
adjust("width", -4).
text("What a nifty way to create GUIs fp4! Test 123 Hello World super star!!!").
built().
built();
// Window Finished
getWindow("TestWindow").built();
}
Output:
Functions:
PHP Code:
// See Script for Documentation
// GUI Creation Functions
createWindow(window_id)
createBitmapBorder(border_id)
createButton(button_id)
createCheckBox(checkBox_id)
createControl(control_id)
createMLText(mltext_id)
createMLTextEdit(mltextedit_id)
createPopUpMenu(popUpMenu_id)
createPopUpEdit(popUpEdit_id)
createProgress(progress_id)
createRadioButton(radioButton_id)
createScroll(scroll_id)
createSlider(slider_id)
createText(text_id)
createTextEdit(textEdit_id)
createTextList(textlist_id)
// GUI Accessors
getWindow(window_id)
getBorder(border_id)
getButton(button_id)
getCheckBox(checkbox_id)
getControl(control_id)
getMLText(mltext_id)
getMLTextEdit(mltextedit_id)
getPopUpMenu(popupmenu_id)
getPopUpEdit(popupedit_id)
getProgress(progress_id)
getRadioButton(radiobutton_id)
getScroll(scroll_id)
getSlider(slider_id)
getText(text_id)
getTextEdit(textedit_id)
getTextList(textlist_id)
// Debugging
debug(msg)
// GUI Object Positioning
above(obj, space)
below(obj, space)
leftOf(obj, space)
rightOf(obj, space)
position(tx, ty)
center(center_pos)
// GUI Object Modifiers
adjust(a, v)
addRows(rows)
bind(a, b)
built()
canResize()
canClose()
canMinimize()
canMaximize()
catch(a, b)
clear()
copy(c, v)
dimensions(w, h)
features(v)
height(v)
offset(tx, ty)
profile(p)
profileMod(a, v)
profileMods(a, v)
set(a, v)
setValues(a, v)
setValue(a, v)
sizing(horiz, vert)
text(v)
width(v)