Basic Design and Programming for the Map Editor

by Dale M.A. Johnson


created 3/28/06


The document lays out a basic programming framework that the Map Editor should use. The purpose of this document is to lay a solid foundation for the actual programming, so that the programming process for the map editor will not be a series of shots in the dark.


Class Overview

The base class for the map editor should be CMapEditor. Only the primary functions of the map editor (the system menu, the palettes and the "tile rover") should be in the class. Everything else should be divided into other classes, preferably classified by tool.


Map Display

The display of the map is handled entirely by the CMapDisplay class. Other functions have no business fooling with anything in this class.


To display the map to the buffer, call field.Display(iMap, iX, iY, bObjects). iMap is the refrence number of the map to display. iX and iY are the coordinates of which tile to display in the upper-left hand corner (offseting the map based on this). Passing true to bObjects will cause objects (event triggers, etc.) to become visable. These only need to be visable when editing a map--In game, they will not need to be displayed. field.Display() will also need to display all the units on the field as well.


field.Display() will ONLY display the map, objects, and units. Whatever function calls it needs to display the GUI, mouse, etc. on its own depending on its own individual needs. Technical details regarding field.Display() are outside the scope of this document.



The main loop function for the map editor is map.Core() This function will continue to loop until map.Menu() is called and returns 1. map.Core() is primarily the "tile rover," that is, it handles input from the mouse interacting with the map, ie, laying terrain, placing objects, etc.


The two other most important function routines for the map editor are the previously mentioned map.Menu() and map.Palette(). map.Menu() handles the system menu and returns either a 1 or 0 on termination. If map.Core() calls this function, and it returns 1, that means the user has selected to exit the map editor. In this case, map.Core() needs to check if the user has saved the map they are working on, and if not, if they would like to (or if they would rather cancel). After this, map.Core() must terminate as well.


map.Palette() handles the Tool Palette and Terrain Palettes. Because it is part of the CMapEditor class, it doesn't need to return any value, simply allowing the user to select a tool and terrain/object/unit to place. If the user presses TAB, ESC, or clicks outside the palettes, this function terminates and control is returned to map.Core().


The only other true member of CMapEditor should be map.Display(). Basically, its only job is to call field.Display() to display the actual map, and then pop the GUI and mouse cursor in over it.


Selecting a Tile

While map.Core() is active, it will deduce what tile the mouse is hovering over on the map. To do this, it simply takes the mouse cursor's x and y position on screen and divides them by 16 (the size of a single tile). From this, it can calculate what tile the mouse is hovering over, then display a box icon around that tile, highlighting it and alerting the user to which tile they will affect.


If the user right or left-clicks, map.Core() will call up a different function depending on the tool the user currently has active. These tool functions need to be in their own, seperate classes away from the CMapEditor class. These functions will execute whatever task the user has specified, and then return immediantly without any input. If any of these functions returns a negative number, it means an error has occuried (for example, the user might have already placed the maximum alloted units for a map).