0

I have these two classes:

[Serializable]
public class Level
{
    public List<Entity> Entities { get; set; }

    public Level()
    {
        Entities = new List<Entity>();
    }
}

[Serializable]
public class Entity
{
    public string ID { get; set; }
    public string Class { get; set; }
    public string TextureName { get; set; }
    public int X { get; set; }
    public int Y { get; set; }
    public Box BoundingBox { get; set; }
}

I want to create a small level editor, where I can place 'Entity' objects in a 'Level' object.

So, I want to create a windows forms application, and create a 'Panel' control representing the 'Level' object (just one instance), and 'PictureBox' controls on that panel to represent 'Entity' objects.

When I click on a 'PictureBox' control, I want to get the corresponding 'Entity' object to get its properties (which I could show in a 'PropertyGrid', for example).

How do I do it?

I tried to create custom controls ('Panel' implementing the 'Level' class, and 'PictureBox' implementing the 'Entity' class), but that feels messy, since the first one always holds duplicate data (the control, AND the object separately).

I could also create a custom 'PictureBox' control holding just the ID of an 'Entity' object, and create methods to search the corresponding 'Entity'.

I am currently looking into model-view-controller and model-view-presenter architectures, just to get an idea how to solve the problem (the look up via Id is done there for example), but I do not need the strict seperation of UI and data right now.

Any help is much appreciated.

Kai Hartmann
  • 3,106
  • 1
  • 31
  • 45

0 Answers0