TGB/Level Builder/CustomCreateTab

From TDN


New Note: RC1 has made this article unneeded.

Note: The following was written for TGB beta 3. With the introduction of beta 4, descriptions for particle effects and frame numbers for static sprites were added. This makes the following somewhat unneeded, but if you wish to add custom information to the tooltips, perhaps this guide can help point you in the right direction.

Contents

Introduction


While TGB's Image Builder has a great option to change the background color while you are working on your ImageMap, unfortunetly the default for displayed images with alpha (transparency) in the Level Builder's create tab is a dark gray. For images or particles that are quite small or have lots of transparency in them, it can be quite hard to figure out what it is from just looking at the thumbnail button. This resource allows you to add a tooltip, which shows useful image or file name info, to certain sections of the create tab.

Image:TGB_CustomCreateTab_1.jpg Image:TGB_CustomCreateTab_2.jpg
Figure 1.1Figure 1.2


Note: The following involves editing Level Builder scripts. Do this at your own risk.

Adding Tooltips


Ready for some cut and paste? The first function we will change can be found in the default folder layout under games/tools/levelEditor/scripts/forms/objectLibrary. The script file is called objectLibraryBaseType.ed.cs. Open it up and if your script or text editor displays line numbers - find the function objectLibraryBaseType::AddT2DObject at line 118. Change that function to the following:

function ObjectLibraryBaseType::AddT2DObject( %this, %t2dObject, %datablockName, %toolType, %caption, %toolTip )
{
   // Validate Object (Should check to make sure it's a t2d object?)
   if( !isObject( %t2dObject ) )
   {
      error("ObjectBrowserDlg::AddT2DObject - Invalid Object!");
      return;
   }
   
   $LB::ObjectLibraryGroup.add( %t2dObject );
   
   if (isObject(%datablockName) && $ignoredDatablockSet.isMember(%datablockName))
      return;

   // Build T2D Object Container
   %t2dContainer = new guiT2DObjectCtrl()
   {
      class = "ObjectBrowserItem";
      Profile = ObjectBrowserThumbProfile;
      RenderMargin = 6;
      groupNum = 1337;
      datablockName = %datablockName;
      toolType = %toolType;
      tooltipprofile = "GuiToolTipProfile";
      ToolTip = %toolTip;
      hovertime = "100";
   };
   %t2dContainer.setSceneObject( %t2dObject );

   if( %caption !$= "" )
      %t2dContainer.setCaption( %caption );

   // Add to list.
   %this.add( %t2dContainer );
}

You might have noticed that a %toolTip variable gets passed to this function now. Let's edit some other scripts to give this variable some meaning.

Static Sprites


Ok, now we will have the tooltip for static sprites show the imageName (Figure 1.1). Find the file staticSprites.ed.cs in the games/tools/levelEditor/scripts/forms/objectLibrary. At line 44, find the function LBOTStaticSprite::refresh. Change that function to this:

function LBOTStaticSprite::refresh(%this)
{
   %this.destroy();
   
   %this.scenegraph = new t2dSceneGraph();
   
   
   $LB::ObjectLibraryGroup.add( %this.scenegraph );
   
   %datablockSet = getT2DDatablockSet();
   %datablockCount = %datablockSet.getCount();

   // Find objectList
   %objectList = %this.findObjectByInternalName("ObjectList");  
   
   for (%i = 0; %i < %datablockCount; %i++ )
   {
      %object = %datablockSet.getObject( %i );
      if( %object.getClassName() $= "t2dImageMapDatablock" )
      {
	      // Create Sprite Object
         %staticSprite = new t2dStaticSprite()  { scenegraph = %this.SceneGraph; };
         %staticSprite.setImageMap( %object.getName() );
         %staticSprite.setSize( %object.getFrameSize(0) );

         %caption = "";
         %toolTip = %object.getName();
         %imageMode = %object.getImageMapMode();
         if( (%imageMode $= "CELL") || (%imageMode $= "LINK") || (%imageMode $= "KEY") )
         {
            %totalFrames  = %object.getFrameCount();
            %caption = "1/" @ %totalFrames;
         }

         %objectList.AddT2DObject( %staticSprite, %object.getName(), "t2dStaticSprite", %caption, %toolTip );
      }
   }

}

If you wish to change the tooltip to something else, you can naturally do this by changing what %toolTip refers to.

Particle Effects


For particle effects, our tooltip will display the file name (Figure 1.2). Find particleEffects.ed.cs in the same objectLibrary folder as the previous two scripts. Go to line 45 and replace LBOTParticleEffect::refresh with this:

function LBOTParticleEffect::refresh( %this )
{
   %this.destroy();
   
   %this.scenegraph = new t2dSceneGraph();
   
   $LB::ObjectLibraryGroup.add( %this.scenegraph );
   
   // Find objectList
   %objectList = %this.findObjectByInternalName("ObjectList");
   
   %fileSpec = $currentProject @ "/data/particles/*.eff";
   for (%file = findFirstFile(%fileSpec); %file !$= ""; %file = findNextFile(%fileSpec))
   {

	   // Create Effect Object
      %particleEffect = new t2dParticleEffect()  { scenegraph = %this.SceneGraph; };
      %particleEffect.loadEffect( %file );
      %particleEffect.setSize( "15 15" );
      
      %particleEffect.moveEffectTo(2.0, 0.5);
         
      %particleEffect.setPaused(true);
      
      %caption = "";
      %toolTip = %file;

      %objectList.AddT2DObject( %particleEffect, %file, "t2dParticleEffect", %caption, %toolTip );
   }

}

Not only was %toolTip added, but also a blank %caption to keep the variables in order when AddT2DObject is run.

That's it for this resource! If you wish to add tooltips to the rest of your create tab sections, the objectLibrary folder we have been editing our scripts from contains the rest of the sections in individual script files.