Editor Plugin Tutorial
From C4 Engine Wiki
This tutorial is largely based off of Reshka's code
Contents |
Introduction
This tutorial will show you the basics of creating an editor plug-in. Because these plug-ins are compiled into separate DLL files, they can be easily shared with other C4 users. Plug-ins also help keep your custom code separate from the engine code, making maintenance easier.
This tutorial was written with C4 version 159 and Visual Studio Express 2008 and updated to include code seen in C4 version 2.8 and Visual Studio 2010.
Get The Files
Download the skeleton project and unzip it into your base C4 directory. It will create dummy files in ToolCode and create a new VisualStudio project which can be added by right-clicking on the C4 Solution in VS and clicking Add->Existing Project. The project is in the VisualStudio/C4/MyEditorPlugin directory.
MyEditorPlugin.cpp/.h - This file holds a custom plugin class that gets build into a .DLL file. That DLL gets loaded into the engine when the engine executable is started.
MyEditorPage.cpp/.h - The editor page is used to hold custom controls that can interact with a world. The most simple example is using a button to add a custom node to the world file.
Checkpoint One
With the new solution added, you should be able to compile the entire solution. Once it is done compiling, launch C4 and create a new world. You should see 'My Editor Page' listed under the Page menu and see a pane for it on the left.
Tip: Between version 159 and 2.8, you'll find that the C4 Engine has changed a bit.
1) The engine library file is no longer named C4.lib, but instead C4Engine.lib. You'll need to update that in the Linker->Input section of the project properties.
2) The EditorObject class now exists in C4EditorSupport.h, so you'll have to #include that at the top of MyEditorPlugin.cpp.
3) The EditorPage has a new constructor of the following signature: EditorPage(Type type, const char * panelFilename). You'll have to build a panel or copy/paste one from the existing set of editor pages (found in Data/Tools/WorldEditor/) and set the panelFilename in the constructor to your new panel. Don't forget to make sure the panel's Window Title is filled in and doesn't match any other existing editor pages.
Changing The Name
The obvious changes are the class and filenames. A simple search and replace can take care of that. If you want to rename the plug-in DLL, you'll need to change the following project settings:
Linker->General->Output File->Filename.dll

