Properties

Published May 20, 2007
Advertisement


Once again, I couldn't find a built in control that provided what I wanted for property editing, so I've implemented the above property grid manually.

I'm drawing the lines and text with GDI+ methods, then moving a borderless TextBox over the selected value. When the selection changes, the relevant property is validated and updated. Works really well.

The PropertyForm actually owns a list of MapItemProperties, which can have either a Number or Text type. The idea is that the same form can be used to edit the properties of different sorts of items.

I just add values to the PropertyForm's List and update it. Plan is to have a delegate callback that is called when a value is succesfully updated so I can then manually update whatever is being edited.

In theory, I should even be able to select multiple items (once they are implemented) and have the property form show the common items for all of them.

Pretty cool really. I must learn how to turn these into reusable components at some point.
Previous Entry Progress on Map.NET
Next Entry Components
0 likes 5 comments

Comments

walle
Are you using tree different forms in one "window" or are the two other forms positioned at the side of the main form or are they controls?

Basically is my question, how have you designed the app? :)
May 20, 2007 05:26 PM
Programmer16
Did you check out the PropertyGrid component? That's what I always use.

Map editor is coming along nicely! You said you're releasing it with Udo, right? (can't remember; haven't been getting a lot of sleep lately lol.)
May 20, 2007 07:27 PM
Aardvajk
Walle - three different windows. The right hand two are stay-on-top resizable tool windows.

Programmer16 - I looked at the PropertyGrid, but it looked to me like you had to assign a C# object to it. The properties I need to edit are dynamic properties specified in a scheme file that correspond to the properties of the objects in my game. Can the PropertyGrid be used for that? I couldn't find a way to make it work.
May 21, 2007 01:32 AM
Programmer16
Quote:Original post by EasilyConfused
Programmer16 - I looked at the PropertyGrid, but it looked to me like you had to assign a C# object to it. The properties I need to edit are dynamic properties specified in a scheme file that correspond to the properties of the objects in my game. Can the PropertyGrid be used for that? I couldn't find a way to make it work.


I'm not quite sure what you mean, but here's an example of using it:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
	public partial class Form1 : Form
	{
		class Object
		{
			public String Name;
			public Point Location;

			public Object(String Name, Point Location)
			{
				this.Name = Name;
				this.Location = Location;
			}

			[DisplayName("Object Name")]
			public String ObjName
			{
				get
				{
					return Name;
				}

				set
				{
					Name = value;
				}
			}

			[DisplayName("Object Location")]
			public Point ObjLocation
			{
				get
				{
					return Location;
				}

				set
				{
					Location = value;
				}
			}
		};

		Object MyObject = new Object("Donny", new Point(10, 10));

		public Form1()
		{
			InitializeComponent();

			propertyGrid1.Select();
			propertyGrid1.SelectedObject = MyObject;
		}
	}
}



With this I can set my name and location in the property grid.

If this isn't what you need, totally ignore me lol.
May 21, 2007 03:20 AM
Aardvajk
Appreciate the explaination and that looks like a really useful control to know about, but unfortunately for this project the objects whose properties I need to edit do not have a corresponding C# object.

For example, inside of Udo (in C++) there are Block objects that have properties like X, Y, Width, Height and so on.

When you define a scheme file for Map.NET (just a text file), you define the items you can place on the map and their properties like:


item 10 "Block"
    X=0 Y=0 Width=64 Height=64 Attribute=8 end
    image "block.bmp"


Map.NET requires that X, Y, Width and Height are defined but the rest are arbitrary. These are all the properties I need to edit in a property editor.

When Map.NET exports the compiled level map, it writes out each property value into the file for each item. The C++ Udo code then loads these properties into each object from the file.

Hope that makes more sense.
May 21, 2007 05:08 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement