Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 02-12-2010, 01:19 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
GUI Explorer

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.
Attached Thumbnails
Click image for larger version

Name:	guiexplorer1.png
Views:	752
Size:	83.6 KB
ID:	50396   Click image for larger version

Name:	guiexplorer2.png
Views:	680
Size:	94.7 KB
ID:	50397  
__________________
Quote:

Last edited by fowlplay4; 02-12-2010 at 02:51 AM..
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 04:22 PM.


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