Documentation/Programming Tutorials/Adding additional gui controls to selected entities in the Map Editor

From NeoAxis 3D Engine Wiki

Jump to: navigation, search
Go to higher level
RTSGridPathFindSystem Properties

Contents

Intoduction

When working in the map editor, we often look to the window with the properties of objects (Properties window). Also you may have noticed that for some types of objects, under the list of properties, there may be additional buttons, combo box and other controls. We call this extended functionality of the properties.

In this tutorial, we will tell you how to create a similar extension.

Description

Here's the simple example of adding a button. Look at the properties of the HeightmapTerrain as a similar example.

HeightmapTerrain Properties

If you are the owner of Commercial License, you may find the code of terrain and the code for adding the button in the source of HeightmapTerrain.dll and HeightmapTerrain.Editor.dll assemblies.

We will consider the example of adding a button to the the water surface object (WaterPlane).

Adding the code

In Visual Studio open our solution and then WaterPlane.cs from GameEntities.dll. Then add the following code:

Namespace links:

using System.Windows.Forms;
using Engine.MapSystem.Editor;

Base code:

	public class WaterPlaneExtendedFunctionalityDescriptor : MapGeneralObjectExtendedFunctionalityDescriptor
	{
		public WaterPlaneExtendedFunctionalityDescriptor( Control parentControl, object owner )
			: base( parentControl, owner )
		{
			Button button;
 
			//Edit button
			button = new Button();
			parentControl.Controls.Add( button );
			button.Location = new System.Drawing.Point( 8, 8 );
			button.Size = new System.Drawing.Size( 75, 26 );
			button.Text = "My Button";
			button.UseVisualStyleBackColor = true;
			button.Click += buttonEditFind_Click;
		}
 
		void buttonEditFind_Click( object sender, EventArgs e )
		{
			MessageBox.Show( "Click!" );
		}
	}
Warning! If your class is inherited from MapObject, then WaterPlaneExtendedFunctionalityDescriptor 
will inherit MapObjectExtendedFunctionalityDescriptor.

Add the following attribute to the WaterPlane class so it looks like this:

[ExtendedFunctionalityDescriptor( typeof( WaterPlaneExtendedFunctionalityDescriptor ) )]
public class WaterPlane : MapGeneralObject


Adding the dependencies

We need to add the following assemblies to GameEntities.dll:

  • System.Windows.Forms.dll. System assembly for creating WinForms applications.
  • MapSystem.Editor.dll and Utils.Editor.dll.


Done! Now compile the project and run the map editor. Let's open some map with the water surface (eg ConstructionsDemo). With the WaterPlane selected, we will see our button:

ExtendedFunctionality03.jpg


How to remove reference to System.Windows.Forms.dll from GameEntities.dll

You may have noticed that some of the assemblies in the engine have a name in the form of (Name).Editor.dll. For example the assembly MapSystem.dll has MapSystem.Editor.dll attached. Such assemblies are only needed for toolset (resource and map editor). In such assemblies stored code is needed only for editors. You may ask why you need to allocate code in a separate assembly? This is recommended to get rid of dependence on System.Windows.Forms.dll in game code. This is desirable to do if you want to minimize resource consumption by your application. Also Web Player does not include the assembly System.Windows.Forms.dll and you can not run your game in the browser, if there is such a dependency.

Ok! Now we will consider the example of an additional assembly GameEntities.Editor.dll, in which will be the code for adding button to the properties considered earlier.

  • Create a new dll project GameEntities.Editor.dll. Adjust the compile options.
  • Move over the main code:
namespace Engine.GameEntities.Editor
{
	public class WaterPlaneExtendedFunctionalityDescriptor : MapGeneralObjectExtendedFunctionalityDescriptor
	{
		public WaterPlaneExtendedFunctionalityDescriptor( Control parentControl, object owner )
			: base( parentControl, owner )
		{
			Button button;
 
			//Edit button
			button = new Button();
			parentControl.Controls.Add( button );
			button.Location = new System.Drawing.Point( 8, 8 );
			button.Size = new System.Drawing.Size( 75, 26 );
			button.Text = "My Button";
			button.UseVisualStyleBackColor = true;
			button.Click += buttonEditFind_Click;
		}
 
		void buttonEditFind_Click( object sender, EventArgs e )
		{
			MessageBox.Show( "Click!" );
		}
	}
}
  • Now change the attribute of WaterPlane class:
[ExtendedFunctionalityDescriptor( "Engine.GameEntities.Editor.WaterPlaneExtendedFunctionalityDescriptor, GameEntities.Editor" )]
public class WaterPlane : MapGeneralObject

First parameter - this is the full name of the class. Second - assembly name without the extension.