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

Classes
editloop.cpp File Reference
#include <deque>
#include <stdint.h>
#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
 

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
 
bool TileToolNoFixup = false
 
char TileToolRandom
 Allow setting every tile, no fixups. More...
 
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 = 0
 Mirror editing enabled. More...
 
static int VisibleTileIcons = 0
 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::SlidereditorSlider
 
static gcn::DropDowntoolDropdown
 
void DoScrollArea (int state, bool fast, bool isKeyboard)
 Editor callbacks. More...
 
void DrawGuichanWidgets ()
 
void CleanGame ()
 
void CreateGame (const std::string &filename, CMap *map)
 forward declaration More...
 
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 void CalculateMaxIconSize ()
 
static void RecalculateShownUnits (size_t start=0, size_t stop=INT_MAX)
 
static int getPlayerButtonSize ()
 
static std::vector< int > getSelectionArea ()
 
static std::vector< int > getButtonArea ()
 
static bool forEachPlayerSelectionBoxArea (std::function< bool(int, int, int, int, int)> forEach)
 
static void DrawPlayers ()
 
static bool forEachUnitIconArea (std::function< bool(int, ButtonStyle *, int, int, int, int)> forEach)
 
static void DrawUnitIcons ()
 
static bool forEachTileOptionArea (std::function< bool(bool, std::string, int, int, int, int, int)> forEach)
 
static void DrawTileOptions ()
 
static bool forEachTileIconArea (std::function< bool(int, int, int, int, int)> forEach)
 
static void DrawTileIcons ()
 
static void DrawIntoSelectionArea ()
 
static void DrawIntoButtonArea ()
 
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...
 
int EditorSaveMapWithResize (const std::string &file, Vec2i newSize, Vec2i offset)
 
void EditorMainLoop ()
 Editor main event loop. More...
 
void StartEditor (const char *filename)
 Start the editor. More...
 

Macro Definition Documentation

◆ START_ICON_X

#define START_ICON_X   (IconWidth * 3 + 16)

◆ START_ICON_Y

#define START_ICON_Y   (2)

◆ TILE_ICON_X

#define TILE_ICON_X   (IconWidth * 2 + 16)

◆ TILE_ICON_Y

#define TILE_ICON_Y   (2)

◆ UNIT_ICON_X

#define UNIT_ICON_X   (IconWidth + 7)

◆ UNIT_ICON_Y

#define UNIT_ICON_Y   (0)

Enumeration Type Documentation

◆ _mode_buttons_

Enumerator
SelectButton 
UnitButton 

Select mode button.

TileButton 

Unit mode button.

StartButton 

Tile mode button.

◆ EditorActionType

Enumerator
EditorActionTypePlaceUnit 
EditorActionTypeRemoveUnit 

Function Documentation

◆ CalculateMaxIconSize()

static void CalculateMaxIconSize ( )
static

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

◆ CleanGame()

void CleanGame ( )

Cleanup game.

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

◆ CreateGame()

void CreateGame ( const std::string &  filename,
CMap map 
)

forward declaration

CreateGame.

Load map, graphics, sounds, etc

Parameters
filenamemap filename
mapmap loaded
Todo:
FIXME: use in this function InitModules / LoadModules!!!

◆ DoScrollArea()

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.

◆ DrawCross()

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

◆ DrawEditorInfo()

static void DrawEditorInfo ( )
static

Draw editor info.

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

◆ DrawEditorPanel()

static void DrawEditorPanel ( )
static

Draw the editor panels.

◆ DrawGuichanWidgets()

void DrawGuichanWidgets ( )

◆ DrawIntoButtonArea()

static void DrawIntoButtonArea ( )
static

◆ DrawIntoSelectionArea()

static void DrawIntoSelectionArea ( )
static

◆ DrawMapCursor()

static void DrawMapCursor ( )
static

Draw special cursor on map.

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

◆ DrawPlayers()

static void DrawPlayers ( )
static

Draw a table with the players

◆ DrawStartLocations()

static void DrawStartLocations ( )
static

Draw the start locations of all active players on the map

◆ DrawTileIcons()

static void DrawTileIcons ( )
static

Draw tile icons.

◆ DrawTileOptions()

static void DrawTileOptions ( )
static

◆ DrawUnitIcons()

static void DrawUnitIcons ( )
static

Draw unit icons into button area

◆ EditorActionPlaceUnit()

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!

◆ EditorActionRemoveUnit()

static void EditorActionRemoveUnit ( CUnit unit)
static

Remove a unit

◆ EditorAddUndoAction()

static void EditorAddUndoAction ( EditorAction  action)
static

◆ EditorCallbackButtonDown()

static void EditorCallbackButtonDown ( unsigned  button)
static

Called if mouse button pressed down.

Parameters
buttonMouse button number (0 left, 1 middle, 2 right)

◆ EditorCallbackButtonUp()

static void EditorCallbackButtonUp ( unsigned  button)
static

Callback for input.

◆ EditorCallbackExit()

static void EditorCallbackExit ( )
static

Callback for exit.

◆ EditorCallbackKeyDown()

static void EditorCallbackKeyDown ( unsigned  key,
unsigned  keychar 
)
static

Handle key down.

Parameters
keyKey scancode.
keycharCharacter code.

◆ EditorCallbackKeyRepeated()

static void EditorCallbackKeyRepeated ( unsigned  key,
unsigned   
)
static

Callback for input.

◆ EditorCallbackKeyUp()

static void EditorCallbackKeyUp ( unsigned  key,
unsigned  keychar 
)
static

Handle key up.

Parameters
keyKey scancode.
keycharCharacter code.

◆ EditorCallbackMouse()

static void EditorCallbackMouse ( const PixelPos pos)
static

Callback for input movement of the cursor.

Parameters
posScreen position.

◆ EditorCallbackMouse_EditTileArea()

static bool EditorCallbackMouse_EditTileArea ( const PixelPos screenPos)
static

◆ EditorCallbackMouse_EditUnitArea()

static bool EditorCallbackMouse_EditUnitArea ( const PixelPos screenPos)
static

◆ EditorMainLoop()

void EditorMainLoop ( )

Editor main event loop.

Editor main event loop.

◆ EditorPlaceUnit()

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.

◆ EditorRedoAction()

static void EditorRedoAction ( )
static

◆ EditorRemoveUnit()

static void EditorRemoveUnit ( CUnit unit)
static

Remove a unit

◆ EditorSaveMap()

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 ...

◆ EditorSaveMapWithResize()

int EditorSaveMapWithResize ( const std::string &  file,
Vec2i  newSize,
Vec2i  offset 
)

◆ EditorUndoAction()

static void EditorUndoAction ( )
static

◆ EditorUpdateDisplay()

void EditorUpdateDisplay ( )

Update editor display.

Update editor display.

◆ EditTile()

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

Edit tile.

Parameters
posmap tile coordinate.
tileTile type to edit or -1, to edit the tile under the brush according to the modifiers

◆ EditTiles()

static void EditTiles ( const Vec2i pos,
int  tile,
int  size 
)
static

Edit tiles

Parameters
posmap tile coordinate.
tileTile type to edit.
sizeSize of rectangle

◆ EditTilesInternal()

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!

◆ forEachPlayerSelectionBoxArea()

static bool forEachPlayerSelectionBoxArea ( std::function< bool(int, int, int, int, int)>  forEach)
static

Call the forEach callback with each player icon's <playerNum,x,y,w,h>. Return false to cancel iteration.

Returns the last value returned by forEach. This can be used to detect if an early cancellation of the iteration was requested.

◆ forEachTileIconArea()

static bool forEachTileIconArea ( std::function< bool(int, int, int, int, int)>  forEach)
static

Call the forEach callback with each tile's <EditorTileIndex,x,y,w,h>. Return false to cancel iteration.

Returns the last value returned by forEach. This can be used to detect if an early cancellation of the iteration was requested.

◆ forEachTileOptionArea()

static bool forEachTileOptionArea ( std::function< bool(bool, std::string, int, int, int, int, int)>  forEach)
static

Call the forEach callback with each tile option buttons's <is-active boolean,label string,i,x,y,w,h>. Return false to cancel iteration.

Returns the last value returned by forEach. This can be used to detect if an early cancellation of the iteration was requested.

◆ forEachUnitIconArea()

static bool forEachUnitIconArea ( std::function< bool(int, ButtonStyle *, int, int, int, int)>  forEach)
static

Call the forEach callback with each unit icon's <EditorUnitIndex,ButtonStyle,x,y,w,h>. Return false to cancel iteration;

Returns the last value returned by forEach. This can be used to detect if an early cancellation of the iteration was requested.

◆ getButtonArea()

static std::vector<int> getButtonArea ( )
static

◆ getPlayerButtonSize()

static int getPlayerButtonSize ( )
static

◆ getSelectionArea()

static std::vector<int> getSelectionArea ( )
static

◆ RecalculateShownUnits()

static void RecalculateShownUnits ( size_t  start = 0,
size_t  stop = INT_MAX 
)
static

Recalculate the shown units.

◆ ShowUnitInfo()

static void ShowUnitInfo ( const CUnit unit)
static

Show info about unit.

Parameters
unitUnit pointer.

◆ StartEditor()

void StartEditor ( const char *  filename)

Start the editor.

Start the editor

Parameters
filenameMap to load, NULL to create a new map

Variable Documentation

◆ ButtonPanelHeight

int ButtonPanelHeight
static

◆ ButtonPanelWidth

int ButtonPanelWidth
static

Icon height in panels.

◆ editorContainer

gcn::Container* editorContainer
static

◆ EditorRedoActions

std::deque<EditorAction> EditorRedoActions
static

◆ editorSlider

gcn::Slider* editorSlider
static

◆ EditorUndoActions

std::deque<EditorAction> EditorUndoActions
static

◆ Gui

gcn::Gui* Gui

◆ IconHeight

int IconHeight
static

Icon width in panels.

◆ IconWidth

int IconWidth
static

◆ MirrorEdit

int MirrorEdit = 0
static

Update units on the minimap.

◆ TileCursorSize

int TileCursorSize
static

Tile tool draws with decorations.

◆ TileToolDecoration

char TileToolDecoration
static

Tile tool draws random.

◆ TileToolNoFixup

bool TileToolNoFixup = false

◆ TileToolRandom

char TileToolRandom

Allow setting every tile, no fixups.

◆ toolDropdown

gcn::DropDown* toolDropdown
static

◆ UnitPlacedThisPress

bool UnitPlacedThisPress = false
static

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

◆ UpdateMinimap

bool UpdateMinimap = false
static

Only allow one unit per press.

◆ VisibleTileIcons

int VisibleTileIcons = 0
static

Number of icons that are visible at a time.

◆ VisibleUnitIcons

int VisibleUnitIcons = 0
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.