Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   GUI Explorer (https://forums.graalonline.com/forums/showthread.php?t=134257984)

fowlplay4 02-12-2010 01:19 AM

GUI Explorer
 
2 Attachment(s)
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;
      
10;
      
extent "280,280";
      
hScrollBar "dynamic";
      
vScrollBar "dynamic";
      new 
GuiTreeViewCtrl("GUIExplorer_Tree") {
        
profile GuiBlueTreeViewProfile;
        
0;
        
fitparentwidth true;
        
clearnodes();
      }  
    }
    new 
GuiTextEditCtrl("GUIExplorer_Source") {
      
profile GuiBlueTextEditProfile;
      
10;
      
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;
      
10;
      
extent "570,550";
      
hScrollBar "dynamic";
      
vScrollBar "dynamic";
      new 
GuiMLTextCtrl("GUIExplorerDump_Text_" obj.name) {
        
profile GuiBlueMLTextProfile;
        
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_Treemakevar(obj.text));
}

// Recursively populates node with children.

function populateNode(parentNodeparentObj) {
  
// 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.childObjparentObj.controls) {
      
populateNode(temp.newNodetemp.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) {
    
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.0temp.temp.vars.size(); temp.++ )
    
temp.dump @= "  "temp.vars[i] @" = "getValobj.(@ temp.vars[i] ) ) @";\n";
  
temp.dump @= "};";
  return 
temp.dump;
}

// Credits to Novo for this function.
function getValval )
{
  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 0temp.count val.size(); temp.count ++ )
      {
        if ( 
count != )
          
temp.dump @= ", ";

        
temp.dump @= getValvaltemp.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.

DustyPorViva 02-12-2010 01:56 AM

Cool stuff :)

I like how you set up the tree system... does it take into consideration children of children? If it doesn't, I think that'd be a good set-up.

Also, while the dump is useful I think it's fairly messy. I think it should be better formatted. For one, use a fixed width font like courier new. Two, better divide the GUI's. Maybe a format like:

PHP Code:

NameOfGui (typeGUIWindowCtrl):
  var = 
[integer]
  
var2 "foo" [string]
  
var3 = {0,0} [array] 

As well as spacing between the GUI's, to quickly differentiate one GUI from the next.

fowlplay4 02-12-2010 02:09 AM

Quote:

Originally Posted by DustyPorViva (Post 1555731)
Cool stuff :)

I like how you set up the tree system... does it take into consideration children of children? If it doesn't, I think that'd be a good set-up.

Thanks, and yeah it recursively travels all the way down each branch until it can't find any child controls. So you'll be able to see all that GUIContainer offers.

Modified the script so people can write their own dumping functions.

cbk1994 02-12-2010 02:15 AM

Excellent, nice work :).

WhiteDragon 02-12-2010 02:16 AM

Sweet job, been thinking about something like this lately.

cbk1994 02-12-2010 02:42 AM

Just noticed, you should probably start with GUIContainer as the base GUI, not GraalControl.

fowlplay4 02-12-2010 02:53 AM

Quote:

Originally Posted by cbk1994 (Post 1555744)
Just noticed, you should probably start with GUIContainer as the base GUI, not GraalControl.

Noted, added a default GUI variable.

adam 02-28-2010 07:30 AM

Nice.


All times are GMT +2. The time now is 01:30 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.