Previous Blog Next Blog
Prev/Next Blog
by date

Plan for John Vanderbeck

Plan for John Vanderbeck
Name:John Vanderbeck 
Date Posted:May 03, 2004
Rating:Not Rated
Public:YES
Comments:YES
RSS Feed:GarageGames Blog feedor Subscribe with .
Profile Page:View profile page for John Vanderbeck

Blog post
Show Tool Plugin System
This isn't a long post, but just a quick .plan to say.. YES! WOOHOOO!! I just finished implementing the raw skeleton of the plugin system and tested it with a very simple plugin that changes the loading behaviour of static objects. This is a huge step forward for me in the development of the new Show Tool, as this was probably the most work intensive aspect of it.


// Show Tool Plugin
// This script file implements a Show Tool Plugin
// Plugin interface is designed by John Vanderbeck and Novus Delta, LLC

// Plugin Name: StaticGravityMod
// Description: This is a very simple plugin designed to illustrate most of the
// basics behaviours of a plugin. What this will do is add some controls to the
// Show Tool allowing the user to change the gravityMod on displayed static shapes
// as well as modifying the datablocks on shape load to achieve the effect.
// Events Used: onLoadStaticShape

// This code registers the plugin with the Show Tool and is required for all
// plugins. The code is the same for all plugins, but replace "StaticGravityMod"
// with the name of your plugin. It must be all one word with no spaces.
new ScriptObject(StaticGravityMod); // create an instance of our plugin
StaticGravityMod.pluginId = $gShow.registerPlugin("StaticGravityMod"); // register our plugin and save our assigned ID
if (StaticGravityMod.pluginId == 0)
{
// Plugin failed to register properly. This could happen if the plugin name
// is already in use by another plugin, there are no more slots available for
// another plugin, or the system just barfed :)
// In any case the plugin was NOT loaded and will not be called.
echo("StaticGravityMod: ERROR, Plugin failed to register. Plugin is not loaded and will not be available.");
// cleanup
StaticGravityMod.delete();
}

// This code is executed by the Show Tool when the plugin is first loaded. This provides the
// plugin with a place to do first run intialization
function StaticGravityMod::onCreate(%this)
{
echo("onCreate");
if ($gShow.registerEvent("StaticGravityMod", "onLoadStaticShape") == 0)
echo("StaticGravityMod: ERROR, Plugin failed to properly register for the onLoadStaticShape event.");
}

// This code is executed by the Show Tool when the tool is shutting down and the plugin is to be unloaded.
// This provides a place for the plugin to clean up and free memory
function StaticGravityMod::onDestroy(%this)
{
echo("onDestroy");
}

// This code is executed by the Show Tool when a UI button belonging to the plugin
// is to be displayed, or is pressed
function StaticGravityMod::onButton(%this, %buttonName, %state)
{
echo("onButton(" @ %buttonName @ ", " @ %state @ ")");
// %buttonName will be the text name of the UI button
// %state will either be "Query" or "Pressed"
// "Query" indicates that the Show Tool is about to display this button
// and is giving you a chance to do any last chance modifications to the button
// before it is displayed, such as making it inactive or changing its appearence.
//
// "Pressed" indicates that the specified button was pressed (clicked on) by the
// user and the Show Tool is giving you the opportunity to perform whatever actions
// you need to perform based on this.
//
// If %state is "Query" and this function returns 0, then the Show Tool will attempt
// to disable the button or make it inactive. To do this it will first make the button
// unclickable, then it will look to see if an inactive version of the button was made
// available to the tool. If so it will display that button instead of the active one.
// This provides a quick and easy way to disable the button. If the return is 1, the
// button will be made active. If %state is "Pressed" then the return value is ignored.
}

// This code is the heart of the plugin in most cases. The main interface
// with the Show Tool and Plugin consists of events. The plugin specifies that
// it wants to be told when certain events occur, and when they do this code
// is executed so that the plugin can respond.
function StaticGravityMod::onEvent(%this, %event, %eventParam1, %eventParam2)
{
echo("onEvent(" @ %event @ ", " @ %eventParam1 @ ", " @ %eventParam2 @ ")");
// %event will contain the name of the event which is being sent.
// "onLoadStaticShape" - Whenever the user loads a static shape,
// after the datablock has been loaded but before the shape
// is created, this event is called.
//
// %eventParam1 and %eventParam2 will contain event specific information
// which varies for each event.

switch$(%event)
{
case "onLoadStaticShape":
if (%eventParam1 $= "preLoad")
{
%this.gravityMod = 1;
eval(%this.buildDatablock());
}
}
}

// What functions are available on the Show Tool side for the plugin to use? How does the
// plugin manipulate the Show Tool?
//
// The first way the plugin can manipulate the Show Tool is through the use of the main Show
// global. This variable is "$gShow" and is the main location of all Show Tool related
// variables and functions. All interaction with the Show Tool will go through this global.
// A list of variables will be eventually placed in here for documentation.
//
// The second way the plugin can function is by calling key functions on the Show Tool.
// You've already seen one, the "registerPlugin" function. The rest will be
// detailed below eventually.
//
// registerPlugin(pluginName)
// registerEvent(pluginName, event)
// unregisterEvent(pluginName, event)
// guiAddButton(buttonName,buttonImage,initialState,group)
// guiSetButtonState(buttonName,state)
// guiSetButtonGroup(buttonName,group)
// guiSetButtonImage(buttonName,buttonImage)
// guiGetButtonPosition(buttonName)

//-------------------------------------------------------------------------------
// Custom functions for this specific plugin. Note: All functions, ALL, of them
// should be contained inside the plugin's namespace to avoid any possible problems
// with duplicated names.
function StaticGravityMod::buildDatablock(%this)
{
%db = "datablock ItemData(GenericItem)" @
"{" @
"gravityMod = " @ %this.gravityMod @ ";" @
"};";
echo("Datablock:\n" @ %db);
return %db;
}

Recent Blog Posts
List:04/06/05 - Plan for John Vanderbeck
04/04/05 - Plan for John Vanderbeck
02/08/05 - Plan for John Vanderbeck
08/20/04 - Plan for John Vanderbeck
05/22/04 - Plan for John Vanderbeck
05/14/04 - Plan for John Vanderbeck
05/03/04 - Plan for John Vanderbeck
04/25/04 - Plan for John Vanderbeck

Submit ResourceSubmit your own resources!

Eric Forhan   (May 03, 2004 at 15:39 GMT)
You're one busy man!

Stefan Lundmark   (May 03, 2004 at 22:11 GMT)
Geez you're learning fast too. :)

You must be a member and be logged in to either append comments or rate this resource.