Well I was needing a way to navigate throughout GUI Objects, to see what kind of things I could find. An hour later, I finished this tool to do so.
Weapon script:
PHP Code:
//#CLIENTSIDE
// Variables
function onCreated() {
this.defaultGUI = "GUIContainer";
}
// Allows opening of GUIExplorer with
// Chat command: /guiexplorer
function ChatBar.onAction() {
if (ChatBar.text == "/guiexplorer") {
ChatBar.text = "";
createGUI();
}
}
// Create Main GUIExplorer
function createGUI() {
new GuiWindowCtrl("GUIExplorer") {
profile = GuiBlueWindowProfile;
isexternal = true;
clientextent = true;
extent = "600,600";
canresize = false;
destroyonhide = true;
text = "GUI Explorer";
new GuiScrollCtrl("GUIExplorer_Scroll") {
profile = GuiBlueScrollProfile;
x = y = 10;
extent = "280,280";
hScrollBar = "dynamic";
vScrollBar = "dynamic";
new GuiTreeViewCtrl("GUIExplorer_Tree") {
profile = GuiBlueTreeViewProfile;
x = y = 0;
fitparentwidth = true;
clearnodes();
}
}
new GuiTextEditCtrl("GUIExplorer_Source") {
profile = GuiBlueTextEditProfile;
x = 10;
y = GUIExplorer.height - 56;
height = 20;
width = GUIExplorer.width - 32;
text = "";
thiso.catchevent(this.name, "onAction", "onLoadSource");
}
}
onLoadSource(GUIExplorer_Source);
setTimer(0.05);
}
// Create Object Dump GUI
function createObjectDump(obj) {
new GuiWindowCtrl("GUIExplorerDump_" @ obj.name) {
profile = GuiBlueWindowProfile;
isexternal = true;
clientextent = true;
extent = "600,600";
canresize = false;
destroyonhide = true;
text = "GUI Object Dump";
new GuiScrollCtrl("GUIExplorerDump_Scroll_" @ obj.name) {
profile = GuiBlueScrollProfile;
x = y = 10;
extent = "570,550";
hScrollBar = "dynamic";
vScrollBar = "dynamic";
new GuiMLTextCtrl("GUIExplorerDump_Text_" @ obj.name) {
profile = GuiBlueMLTextProfile;
x = y = 0;
width = 540;
height = 540;
text = "";
temp.textobj = this;
}
}
}
// Display Object Dump
temp.textobj.text = getDump(obj);
}
// Sets Root Node and Repopulates Tree.
function onLoadSource(obj) {
// Trim text
obj.text = obj.text.trim();
// Default Text
if (obj.text == "") obj.text = this.defaultGUI;
// Populate Tree
GUIExplorer_Tree.clearnodes();
populateNode(GUIExplorer_Tree, makevar(obj.text));
}
// Recursively populates node with children.
function populateNode(parentNode, parentObj) {
// Idiot Protection
if (parentObj.name == "GUIExplorer_Tree") return;
// Check if parentObj is Object
if (parentObj.type() == 0) {
temp.node = parentNode.addNode("Could not locate object!");
with (temp.node) {
image = selectedimage = 2;
}
return;
}
// Add Node
temp.newNode = parentNode.addNode(parentObj.name);
// Populate Children Data
if (parentObj.controls.size() > 0) {
// Children found
for (temp.childObj: parentObj.controls) {
populateNode(temp.newNode, temp.childObj);
}
} else {
// Does not have Children
with (temp.newNode) {
image = selectedimage = 2;
}
}
}
// Opens Object Dump when a Node is Double-clicked.
function GUIExplorer_Tree.onDblClick(node) {
// Avoid Error Node
if (node == "Could not locate object!") return;
// Display Dump
createObjectDump(makevar(node));
}
// Resizes Appropriately
function GUIExplorer.onResize() {
with (GUIExplorer_Scroll) {
width = GUIExplorer.width - 20;
height = GUIExplorer.height - 40;
}
with (GUIExplorer_Source) {
y = GUIExplorer.height - 26;
width = GUIExplorer.width - 20;
}
}
// Dump Functions
function getDump(obj) {
temp.dump = getVal(obj);
temp.dump @= " {\n";
temp.vars = obj.getvarnames();
for ( temp.i = 0; temp.i < temp.vars.size(); temp.i ++ )
temp.dump @= " "@ temp.vars[i] @" = "@ getVal( obj.(@ temp.vars[i] ) ) @";\n";
temp.dump @= "};";
return temp.dump;
}
// Credits to Novo for this function.
function getVal( val )
{
switch ( val.type() )
{
case 0: case 1:
return "\""@ val @"\"";
break;
case 2:
return val.objecttype() @"("@ val.name @")";
break;
case 3:
temp.dump = "{";
temp.count = 0;
for ( temp.count = 0; temp.count < val.size(); temp.count ++ )
{
if ( count != 0 )
temp.dump @= ", ";
temp.dump @= getVal( val[ temp.count ] );
}
temp.dump @= "}";
return temp.dump;
break;
}
return "\"\"";
}
You can get an object dump by double-clicking a node in the tree.
To change the root object, just type it in to the text-box and press enter.
Possible Future Features:
- Live Editing of Values
- Improved Tree Navigation (See parent, etc.)
See attachments for imagery.
Enjoy, and happy GUI exploring.