WarCry continues its series of developer journals from the folks behind PlayXpert, an in-game browser system. The PlayXpert software is highly customizable and the community is invited to create widgets to further its personal feel. Check out the Wild World of Widgets!
We’re back to talk about building PlayXpert Widgets. As we explained in the last two articles, PlayXpert provides an open platform allowing developers to build applications (we call Widgets), that can be used in any PC game. This month, we’re going to explore the nuts and bolts of developing a widget and illustrate the ease of developing widgets.
To build a Widget, you should already know how to develop a Windows application or Class Library. You should know what an interface is, and how to implement one.
Anatomy of a Widget
A Widget is essentially a Windows Class Library – a real application, with full access to all .NET services.
There are only two mandatory requirements to be called a Widget:
- It must implement the IWidget interface.
- The Widget must be licensed with our licensing tool. The licensing process is completely free, and only takes a few seconds.
We have developed a simple Widget template that you can use in Visual Studio 2008 as a starting point.
The IWidget interface provides PlayXpert with all the information that it needs to load and unload the Widget and display Widget information to users, like Name, Version, etc. The IWidget interface also allows your Widget to tell PlayXpert which features it implements, through the GetWidgetFeatures() method. When a Widget is first loaded, it is given a reference to the ICore interface, which allows it to get access to all the other major interfaces in the PlayXpert Core.
In order to foster high widget quality on the PlayXpert platform and protect our users from any potentially rogue developers, we use a strong-name based licensing system to sign each widget, and validate it against our servers at runtime. Each widget’s license key must be associated to a PlayXpert user, and each user account is associated to an email address.
We have developed a PlayXpert AddIn for Visual Studio 2008 that automatically licenses Widgets each time you build. If you build a project that implements the IWidget interface, it will look for your license key set. If it doesn’t find one, it will automatically contact our servers and allocate a new key for the Widget. Once a license key has been generated by our servers and cached in your project, you will not have to enter your password again. The licensor will then automatically calculate a signature for your Widget.
There is no reason that a Widget must have a button on the dock – you could develop a widget that just monitors a farm of game servers, and reset the servers if they didn’t respond, popping up a balloon to tell you so, all while you were locked in a desperate battle with legions of tanks from the safety of your Walker in Battlefield 2142. But, most Widgets will want to implement a button on the dock. The way that you do this is to return a feature named “Dock” from IWidget.GetWidgetFeatures(). The PlayXpert Core will then query your widget for the actual object that implements the “Dock” feature, and you return an object that implements the IDockItem interface. If you need to put multiple buttons on the Dock, there are functions in the IDock interface to allow you to do this.
The PlayXpert Core Library (CoreLib) includes controls that allow you to interact with the user while in-game. Of these, the main one is PXPForm, which is a drop-in replacement for the normal Windows Form. It functions almost exactly like a regular form, except that it manages all of the interaction with our graphics driver, and performs all of the skinning functions for you. This allows you to concentrate on the functions of your Widget without worrying about how to get it to display in-game, or getting it to look similar to the other widgets when the user changes the PlayXpert skin.
This overview should give you a flavor of some of the things that can be done with a PlayXpert Widget, and illustrate how easy it is to build. For more information, see the Widget Developer Community on http://www.playxpert.com, and download our SDK.