Jump to content

GuiControl group calls system


Mud-H

Recommended Posts

I have build a simple system to allow updates of multiple GuiControl at same time that are part of the same group. It works by setting a guiGroup properties to any GuiControl that represent a group of GuiControls that share the same functions. For example, if you have multiple GuiPopUpMenuCtrl that share the same listed items, you can update them all by setting a common GuiGroup field. Here's a sample of how it work to add all Datablocks to multiple menus:

//Clear all the controls with field GuiGroup setted to AllDatablocksMenu
doGuiGroupAction("AllDatablocksMenu","clear()"); 

%i = 0;
foreach(%data in DatablockSet){

//Call add action for all GuiControls with GuiGroup AllDatablocksMenu
doGuiGroupAction("AllDatablocksMenu","add(\""@%data.getName()@"\",\""@%i@"\")"); 

%i++;
}
doGuiGroupAction("AllDatablocksMenu","setSelected(\""@%i @"\")"); 

 

I'm wondering if there's a built-in way to do something similar with T3D. I'd prefer to not use a custom field (guiGroup in this case) so it can be set easily in the Editor. If not, I will simply re-add the guiGroup field to my code.

Anyway, the system work quite good and can be very usefull in some case. For examples, I used it in Boost! to hide all the admin related GuiControls for non-admin, instead of having to keep track of all those, I simply set the guiGroup to "AdminControl" and then "doGuiGroupAction("AdminControls","setVisible(false)");


If you want to have a try, here's the script. It will be part of a Collection of Scripts helpers I'm planning to release once it have been cleaned.

//==============================================================================
// Called each time a GuiControl is Added
function GuiControl::onAdd	(%this) {
   //Check if there's a GuiGroup set and add ctrl to it if exist
   if (%this.guiGroup !$= "" ) 
     addCtrlToGuiGroup(%this);   
}
//------------------------------------------------------------------------------

//==============================================================================
// Add a GuiControl to it's GuiGroup SimSet
function addCtrlToGuiGroup(%ctrl) {    
   //Leave if invalid object
   if (!isObject(%ctrl)) return;

   %group = $GuiGroup_[%ctrl.guiGroup];
   if (!isObject(%group)) {
       %group = newSimSet("GuiGroup_"@%ctrl.guiGroup,$Group_GuiGroup);
   }
   else if (%group.getObjectIndex(%ctrl) >= 0){     
      echo("Object:" SPC %ctrl.getName() SPC "is already in the group:" SPC %ctrl.guiGroup);
      return;
   }
   %group.add(%ctrl);

}
//------------------------------------------------------------------------------

//==============================================================================
// Call up to 10 actions on all GuiControl in a GuiGroup (Don't add trailing ;)
function doGuiGroupAction(%groupType,%act1,%act2,%act3,%act4,%act5,%act6,%act7,%act8,%act9,%act10)
{    
   %group = $GuiGroup_[%groupType];
   if (!isObject(%group)) {      
       echo("Try to call a GuiGroup action on invalid group:" SPC %groupType);
       return;
   }
   foreach(%ctrl in %group) {
       %id = 1;
       while (%act[%id] !$="") {
           eval("%ctrl."@%act[%id]@";");
           %id++;
       }
   }
   return true;
}
//------------------------------------------------------------------------------

I'm still planning to enhance the call actions system but I'd like to know if any of you have better solution to do something similar.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...