_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes
editloop.cpp File Reference
#include <deque>
#include "stratagus.h"
#include "editor.h"
#include "commands.h"
#include "font.h"
#include "game.h"
#include "guichan.h"
#include "interface.h"
#include "iocompat.h"
#include "iolib.h"
#include "map.h"
#include "menus.h"
#include "minimap.h"
#include "network.h"
#include "parameters.h"
#include "replay.h"
#include "script.h"
#include "settings.h"
#include "sound.h"
#include "sound_server.h"
#include "tileset.h"
#include "translate.h"
#include "ui.h"
#include "unit_find.h"
#include "unittype.h"
#include "video.h"
#include "widgets.h"

Classes

struct  EditorAction
 
class  EditorUnitSliderListener
 
class  EditorSliderListener
 

editloop.cpp - The editor main loop.

#define UNIT_ICON_X   (IconWidth + 7)
 
#define UNIT_ICON_Y   (0)
 
#define TILE_ICON_X   (IconWidth * 2 + 16)
 
#define TILE_ICON_Y   (2)
 
#define START_ICON_X   (IconWidth * 3 + 16)
 
#define START_ICON_Y   (2)
 
enum  _mode_buttons_ { SelectButton = 201, UnitButton, TileButton, StartButton }
 
enum  EditorActionType { EditorActionTypePlaceUnit, EditorActionTypeRemoveUnit }
 
static int IconWidth
 
static int IconHeight
 Icon width in panels. More...
 
static int ButtonPanelWidth
 Icon height in panels. More...
 
static int ButtonPanelHeight
 
char TileToolRandom
 
static char TileToolDecoration
 Tile tool draws random. More...
 
static int TileCursorSize
 Tile tool draws with decorations. More...
 
static bool UnitPlacedThisPress = false
 Tile cursor size 1x1 2x2 ... 4x4. More...
 
static bool UpdateMinimap = false
 Only allow one unit per press. More...
 
static int MirrorEdit = 0
 Update units on the minimap. More...
 
static int VisibleUnitIcons
 Mirror editing enabled. More...
 
static int VisibleTileIcons
 Number of icons that are visible at a time. More...
 
static std::deque< EditorActionEditorUndoActions
 
static std::deque< EditorActionEditorRedoActions
 
gcn::GuiGui
 
static gcn::ContainereditorContainer
 
static gcn::SlidereditorUnitSlider
 
static gcn::SlidereditorSlider
 
static EditorUnitSliderListenereditorUnitSliderListener
 
static EditorSliderListenereditorSliderListener
 
void DoScrollArea (int state, bool fast, bool isKeyboard)
 Editor callbacks. More...
 
void DrawGuichanWidgets ()
 
void CleanGame ()
 
static void EditorUndoAction ()
 
static void EditorRedoAction ()
 
static void EditorAddUndoAction (EditorAction action)
 
static void EditTile (const Vec2i &pos, int tile)
 
static void EditTilesInternal (const Vec2i &pos, int tile, int size)
 
static void EditTiles (const Vec2i &pos, int tile, int size)
 
static void EditorActionPlaceUnit (const Vec2i &pos, const CUnitType &type, CPlayer *player)
 
static void EditorPlaceUnit (const Vec2i &pos, CUnitType &type, CPlayer *player)
 
static void EditorActionRemoveUnit (CUnit &unit)
 
static void EditorRemoveUnit (CUnit &unit)
 
static int CalculateVisibleIcons (bool tiles=false)
 
static void CalculateMaxIconSize ()
 
static void RecalculateShownUnits ()
 
static void DrawPlayers ()
 
static void DrawUnitIcons ()
 
static void DrawTileIcon (unsigned tilenum, unsigned x, unsigned y, unsigned flags)
 
static void DrawTileIcons ()
 
static void DrawEditorPanel_SelectIcon ()
 
static void DrawEditorPanel_UnitsIcon ()
 
static void DrawEditorPanel_StartIcon ()
 
static void DrawEditorPanel ()
 
static void DrawMapCursor ()
 
static void DrawCross (const PixelPos &topleft_pos, const PixelSize &size, Uint32 color)
 
static void DrawStartLocations ()
 
static void DrawEditorInfo ()
 
static void ShowUnitInfo (const CUnit &unit)
 
void EditorUpdateDisplay ()
 Update editor display. More...
 
static void EditorCallbackButtonUp (unsigned button)
 
static void EditorCallbackButtonDown (unsigned button)
 
static void EditorCallbackKeyDown (unsigned key, unsigned keychar)
 
static void EditorCallbackKeyUp (unsigned key, unsigned keychar)
 
static void EditorCallbackKeyRepeated (unsigned key, unsigned)
 
static bool EditorCallbackMouse_EditUnitArea (const PixelPos &screenPos)
 
static bool EditorCallbackMouse_EditTileArea (const PixelPos &screenPos)
 
static void EditorCallbackMouse (const PixelPos &pos)
 
static void EditorCallbackExit ()
 
int EditorSaveMap (const std::string &file)
 Save a map from editor. More...
 
void EditorMainLoop ()
 Editor main event loop. More...
 
void StartEditor (const char *filename)
 Start the editor. More...
 

Macro Definition Documentation

#define START_ICON_X   (IconWidth * 3 + 16)
#define START_ICON_Y   (2)
#define TILE_ICON_X   (IconWidth * 2 + 16)
#define TILE_ICON_Y   (2)
#define UNIT_ICON_X   (IconWidth + 7)
#define UNIT_ICON_Y   (0)

Enumeration Type Documentation

Enumerator
SelectButton 
UnitButton 

Select mode button.

TileButton 

Unit mode button.

StartButton 

Tile mode button.

Enumerator
EditorActionTypePlaceUnit 
EditorActionTypeRemoveUnit 

Function Documentation

static void CalculateMaxIconSize ( )
static

Calculate the max height and the max width of icons, and assign them to IconHeight and IconWidth

static int CalculateVisibleIcons ( bool  tiles = false)
static

Calculate the number of icons that can be displayed

Returns
Number of icons that can be displayed.
void CleanGame ( )

Cleanup game.

Call each module to clean up. Contrary to CleanModules, maps can be restarted without reloading all lua files.

void DoScrollArea ( int  state,
bool  fast,
bool  isKeyboard 
)

Editor callbacks.

Handle scrolling area.

Parameters
stateScroll direction/state.
fastFlag scroll faster.
Todo:

Support dynamic acceleration of scroll speed.

If the scroll key is longer pressed the area is scrolled faster.

static void DrawCross ( const PixelPos topleft_pos,
const PixelSize size,
Uint32  color 
)
static
static void DrawEditorInfo ( )
static

Draw editor info.

If cursor is on map or minimap show information about the current tile.

static void DrawEditorPanel ( )
static

Draw the editor panels.

static void DrawEditorPanel_SelectIcon ( )
static
static void DrawEditorPanel_StartIcon ( )
static
static void DrawEditorPanel_UnitsIcon ( )
static
void DrawGuichanWidgets ( )
static void DrawMapCursor ( )
static

Draw special cursor on map.

Todo:
support for bigger cursors (2x2, 3x3 ...)
static void DrawPlayers ( )
static

Draw a table with the players

static void DrawStartLocations ( )
static

Draw the start locations of all active players on the map

static void DrawTileIcon ( unsigned  tilenum,
unsigned  x,
unsigned  y,
unsigned  flags 
)
static

Draw a tile icon

Parameters
tilenumTile number to display
xX display position
yY display position
flagsState of the icon (IconActive,IconClicked,...)
static void DrawTileIcons ( )
static

Draw tile icons.

Todo:
for the start the solid tiles are hardcoded If we have more solid tiles, than they fit into the panel, we need some new ideas.
static void DrawUnitIcons ( )
static

Draw unit icons.

static void EditorActionPlaceUnit ( const Vec2i pos,
const CUnitType type,
CPlayer player 
)
static

Place unit.

Parameters
posmap tile coordinate.
typeUnit type to edit.
playerPlayer owning the unit.
Todo:
FIXME: Check if the player has already a start-point.
Bug:
This function does not support mirror editing!
static void EditorActionRemoveUnit ( CUnit unit)
static

Remove a unit

static void EditorAddUndoAction ( EditorAction  action)
static
static void EditorCallbackButtonDown ( unsigned  button)
static

Called if mouse button pressed down.

Parameters
buttonMouse button number (0 left, 1 middle, 2 right)
static void EditorCallbackButtonUp ( unsigned  button)
static

Callback for input.

static void EditorCallbackExit ( )
static

Callback for exit.

static void EditorCallbackKeyDown ( unsigned  key,
unsigned  keychar 
)
static

Handle key down.

Parameters
keyKey scancode.
keycharCharacter code.
static void EditorCallbackKeyRepeated ( unsigned  key,
unsigned   
)
static

Callback for input.

static void EditorCallbackKeyUp ( unsigned  key,
unsigned  keychar 
)
static

Handle key up.

Parameters
keyKey scancode.
keycharCharacter code.
static void EditorCallbackMouse ( const PixelPos pos)
static

Callback for input movement of the cursor.

Parameters
posScreen position.
static bool EditorCallbackMouse_EditTileArea ( const PixelPos screenPos)
static
static bool EditorCallbackMouse_EditUnitArea ( const PixelPos screenPos)
static
void EditorMainLoop ( )

Editor main event loop.

Editor main event loop.

static void EditorPlaceUnit ( const Vec2i pos,
CUnitType type,
CPlayer player 
)
static

Edit unit.

Parameters
posmap tile coordinate.
typeUnit type to edit.
playerPlayer owning the unit.
static void EditorRedoAction ( )
static
static void EditorRemoveUnit ( CUnit unit)
static

Remove a unit

int EditorSaveMap ( const std::string &  file)

Save a map from editor.

Save a map from editor.

Parameters
fileSave the level to this file.
Returns
0 for success, -1 for error
Todo:
FIXME: Check if the map is valid, contains no failures. At least two players, one human slot, every player a startpoint ...
static void EditorUndoAction ( )
static
void EditorUpdateDisplay ( )

Update editor display.

Update editor display.

static void EditTile ( const Vec2i pos,
int  tile 
)
static

Edit tile.

Parameters
posmap tile coordinate.
tileTile type to edit.
static void EditTiles ( const Vec2i pos,
int  tile,
int  size 
)
static

Edit tiles

Parameters
posmap tile coordinate.
tileTile type to edit.
sizeSize of rectangle
static void EditTilesInternal ( const Vec2i pos,
int  tile,
int  size 
)
static

Edit tiles (internal, used by EditTiles()).

Parameters
posmap tile coordinate.
tileTile type to edit.
sizeSize of rectangle
Bug:
This function does not support mirror editing!
static void RecalculateShownUnits ( )
static

Recalculate the shown units.

static void ShowUnitInfo ( const CUnit unit)
static

Show info about unit.

Parameters
unitUnit pointer.
void StartEditor ( const char *  filename)

Start the editor.

Start the editor

Parameters
filenameMap to load, NULL to create a new map

Variable Documentation

int ButtonPanelHeight
static
int ButtonPanelWidth
static

Icon height in panels.

gcn::Container* editorContainer
static
std::deque<EditorAction> EditorRedoActions
static
gcn::Slider* editorSlider
static
EditorSliderListener* editorSliderListener
static
std::deque<EditorAction> EditorUndoActions
static
gcn::Slider* editorUnitSlider
static
EditorUnitSliderListener* editorUnitSliderListener
static
gcn::Gui* Gui
int IconHeight
static

Icon width in panels.

int IconWidth
static
int MirrorEdit = 0
static

Update units on the minimap.

int TileCursorSize
static

Tile tool draws with decorations.

char TileToolDecoration
static

Tile tool draws random.

char TileToolRandom
bool UnitPlacedThisPress = false
static

Tile cursor size 1x1 2x2 ... 4x4.

bool UpdateMinimap = false
static

Only allow one unit per press.

int VisibleTileIcons
static

Number of icons that are visible at a time.

int VisibleUnitIcons
static

Mirror editing enabled.

(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.