____                _       __
    / __ )____  _____   | |     / /___ ___________
   / __  / __ \/ ___/   | | /| / / __ `/ ___/ ___/
  / /_/ / /_/ (__  )    | |/ |/ / /_/ / /  (__  )
 /_____/\____/____/     |__/|__/\__,_/_/  /____/

       A futuristic real-time strategy game.
          This file is part of Bos Wars.
(C) Copyright 2001-2007 by the Bos Wars and Stratagus Project. Distributed under the "GNU General Public License"

editloop.cpp File Reference

The editor main loop. More...

#include <stdio.h>
#include <stdlib.h>
#include <sstream>
#include <deque>
#include "stratagus.h"
#include "unittype.h"
#include "unit_cache.h"
#include "video.h"
#include "map.h"
#include "patch.h"
#include "patch_type.h"
#include "minimap.h"
#include "settings.h"
#include "network.h"
#include "sound_server.h"
#include "ui.h"
#include "interface.h"
#include "font.h"
#include "widgets.h"
#include "editor.h"
#include "results.h"
#include "menus.h"
#include "sound.h"
#include "iolib.h"
#include "iocompat.h"
#include "replay.h"
#include "guichan.h"
#include "script.h"

Go to the source code of this file.

Classes

struct  EditorAction
class  EditorUnitSliderListener
class  EditorPatchSliderListener

Defines

#define IconSpacing   (IconWidth + 2)
#define UNIT_ICON_X   (IconSpacing)
 Unit mode icon.
#define UNIT_ICON_Y   (0)
 Unit mode icon.
#define PATCH_ICON_X   (IconSpacing * 2)
 Tile mode icon.
#define PATCH_ICON_Y   (0)
 Tile mode icon.
#define START_ICON_X   (IconSpacing * 3)
 Start mode icon.
#define START_ICON_Y   (0)
 Start mode icon.

Enumerations

enum  _mode_buttons_ { SelectButton = 201, UnitButton, PatchButton, StartButton }
enum  EditorActionType { EditorActionTypePlaceUnit, EditorActionTypeRemoveUnit }

Functions

void DoScrollArea (int state, bool fast)
void DrawGuichanWidgets ()
void CleanGame ()
static void EditorUndoAction ()
static void EditorRedoAction ()
static void EditorAddUndoAction (EditorAction action)
void InitDefinedVariables ()
void SetEditorSelectIcon (const std::string &icon)
void SetEditorUnitsIcon (const std::string &icon)
void SetEditorPatchIcon (const std::string &icon)
void SetEditorStartUnit (const std::string &name)
 Start the editor.
static void EditorActionPlaceUnit (int x, int y, CUnitType *type, CPlayer *player)
static void EditorPlaceUnit (int x, int y, CUnitType *type, CPlayer *player)
static void EditorActionRemoveUnit (CUnit *unit)
static void EditorRemoveUnit (CUnit *unit)
static int CalculateVisibleIcons ()
static void CalculateMaxIconSize ()
static void RecalculateShownUnits ()
static void CleanEditAi ()
static void DrawPlayers ()
static void DrawUnitIcons ()
static void DrawPatchIcons ()
static void DrawEditorPanel ()
static void DrawMapCursor ()
static void DrawStartLocations ()
static void ShowUnitInfo (const CUnit *unit)
static void ShowPatchInfo (const CPatch *patch)
static void EditorUpdateDisplay ()
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 keychar)
static void EditorCallbackMouse (int x, int y)
static void EditorCallbackExit ()
static void CreatePatchIcons ()
static void CleanPatchIcons ()
int EditorSaveMap (const std::string &file)
 Start the patch editor.
static void EditorMainLoop ()
void StartEditor (const std::string &filename)
 Save a map from editor.

Variables

CEditor Editor
const char * EditorStartFile
 Editor CCL start file.
static int IconWidth
 Icon width in panels.
static int IconHeight
 Icon height in panels.
static int ButtonPanelWidth
static int ButtonPanelHeight
static CPatchPatchUnderCursor
 Patch under cursor.
static int PatchOffsetX
static int PatchOffsetY
static bool UnitPlacedThisPress = false
 Only allow one unit per press.
static bool PatchPlacedThisPress = false
 Only allow one patch per press.
static bool UpdateMinimap = false
 Update units on the minimap.
static bool UpdateMinimapTerrain = false
 Terrain has changed, minimap needs updating.
static bool DraggingPatch = false
 The user is currently dragging a patch.
static int VisibleIcons
 Number of icons that are visible at a time.
static std::deque< EditorActionEditorUndoActions
static std::deque< EditorActionEditorRedoActions
gcn::GuiGui
 A Gui object - binds it all together.
static gcn::ContainereditorContainer
static gcn::SlidereditorUnitSlider
static gcn::SlidereditorPatchSlider
static EditorUnitSliderListenereditorUnitSliderListener
static EditorPatchSliderListenereditorPatchSliderListener
static MenuScreeneditAiMenu
static gcn::LabeleditAiLabel
static gcn::CheckBoxeditAiCheckBox
static gcn::ButtoneditAiOKButton
static gcn::ButtoneditAiCancelButton


Detailed Description

The editor main loop.

Definition in file editloop.cpp.


Define Documentation

#define IconSpacing   (IconWidth + 2)

Definition at line 74 of file editloop.cpp.

#define PATCH_ICON_X   (IconSpacing * 2)

Tile mode icon.

Definition at line 77 of file editloop.cpp.

Referenced by DrawEditorPanel(), and EditorCallbackMouse().

#define PATCH_ICON_Y   (0)

Tile mode icon.

Definition at line 78 of file editloop.cpp.

Referenced by DrawEditorPanel(), and EditorCallbackMouse().

#define START_ICON_X   (IconSpacing * 3)

Start mode icon.

Definition at line 79 of file editloop.cpp.

Referenced by DrawEditorPanel(), and EditorCallbackMouse().

#define START_ICON_Y   (0)

Start mode icon.

Definition at line 80 of file editloop.cpp.

Referenced by DrawEditorPanel(), and EditorCallbackMouse().

#define UNIT_ICON_X   (IconSpacing)

Unit mode icon.

Definition at line 75 of file editloop.cpp.

Referenced by DrawEditorPanel(), and EditorCallbackMouse().

#define UNIT_ICON_Y   (0)

Unit mode icon.

Definition at line 76 of file editloop.cpp.

Referenced by DrawEditorPanel(), and EditorCallbackMouse().


Enumeration Type Documentation

Enumerator:
SelectButton  Select mode button.
UnitButton  Unit mode button.
PatchButton  Patch mode button.
StartButton 

Definition at line 106 of file editloop.cpp.

Enumerator:
EditorActionTypePlaceUnit 
EditorActionTypeRemoveUnit 

Definition at line 113 of file editloop.cpp.


Function Documentation

static void CalculateMaxIconSize (  )  [static]

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

Definition at line 432 of file editloop.cpp.

References Assert, CIcon::G, CGraphic::Height, IconConfig::Icon, CUnitType::Icon, IconHeight, IconWidth, int(), UnitTypeByIdent(), CEditor::UnitTypes, and CGraphic::Width.

Referenced by CEditor::Init().

static int CalculateVisibleIcons (  )  [static]

Calculate the number of icons that can be displayed

Returns:
Number of icons that can be displayed.

Definition at line 405 of file editloop.cpp.

References CUserInterface::ButtonPanel, ButtonPanelHeight, ButtonPanelWidth, IconHeight, IconWidth, UI, CButtonPanel::X, and CButtonPanel::Y.

Referenced by CEditor::Init().

static void CleanEditAi (  )  [static]

Definition at line 487 of file editloop.cpp.

Referenced by StartEditor().

void CleanGame ( void   ) 

Cleanup game.

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

Definition at line 343 of file stratagus.cpp.

References CMap::Clean(), CleanAi(), CleanGroups(), CleanMessages(), CleanMissiles(), CleanReplayLog(), CleanSelections(), CleanTriggers(), CleanUnits(), CursorBuilding, EndReplayLog(), FreePathfinder(), FreeVisionTable(), Map, and UnitUnderCursor.

Referenced by StartEditor(), and StartMap().

static void CleanPatchIcons (  )  [static]

Clean up the patch icons

Definition at line 1716 of file editloop.cpp.

References CGraphic::Free(), and CEditor::ShownPatchTypes.

Referenced by StartEditor().

static void CreatePatchIcons (  )  [static]

void DoScrollArea ( int  state,
bool  fast 
)

Handle scrolling area.

Parameters:
state Scroll direction/state.
fast Flag scroll faster.
Todo:
Support dynamic acceleration of scroll speed.
Todo:
If the scroll key is longer pressed the area is scrolled faster.

Definition at line 100 of file mainloop.cpp.

References CursorX, CursorY, FRAMES_PER_SECOND, HandleMouseMove(), CViewport::MapHeight, CViewport::MapWidth, CViewport::MapX, CViewport::MapY, CViewport::OffsetX, CViewport::OffsetY, ScrollDown, ScrollLeft, ScrollNone, ScrollRight, ScrollUp, CUserInterface::SelectedViewport, CViewport::Set(), SkipFrames, TileSizeX, TileSizeY, UI, and VideoSyncSpeed.

Referenced by EditorMainLoop(), and GameMainLoop().

static void DrawEditorPanel (  )  [static]

void DrawGuichanWidgets (  ) 

Definition at line 160 of file widgets.cpp.

Referenced by EditorUpdateDisplay(), PatchEditorUpdateDisplay(), and UpdateDisplay().

static void DrawMapCursor (  )  [static]

static void DrawPatchIcons (  )  [static]

static void DrawPlayers (  )  [static]

static void DrawStartLocations (  )  [static]

static void DrawUnitIcons (  )  [static]

static void EditorActionPlaceUnit ( int  x,
int  y,
CUnitType type,
CPlayer player 
) [static]

Place unit.

Parameters:
x X map tile coordinate.
y Y map tile coordinate.
type Unit type to edit.
player Player owning the unit.

Definition at line 240 of file editloop.cpp.

References DebugPrint, MakeUnitAndPlace(), CUnitType::Neutral, NoUnitP, OnTopDetails(), CBuildRestrictionOnTop::Parent, PlayerNumNeutral, Players, CUnit::Release(), CUnit::Remove(), CBuildRestrictionOnTop::ReplaceOnBuild, CUnit::ResourcesHeld, CUnitCache::Select(), UnitCache, UnitClearOrders(), UnitLost(), UnitMax, and UpdateMinimap.

Referenced by EditorPlaceUnit(), EditorRedoAction(), and EditorUndoAction().

static void EditorActionRemoveUnit ( CUnit unit  )  [static]

static void EditorAddUndoAction ( EditorAction  action  )  [static]

Definition at line 390 of file editloop.cpp.

References EditorRedoActions, and EditorUndoActions.

Referenced by EditorPlaceUnit(), and EditorRemoveUnit().

static void EditorCallbackButtonDown ( unsigned  button  )  [static]

Called if mouse button pressed down.

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

Definition at line 966 of file editloop.cpp.

References _, CPatchManager::add(), ButtonAreaMenu, ButtonAreaUnderCursor, ButtonUnderCursor, CanBuildUnitType(), CStatusLine::Clear(), GameSound::Click, CursorConfig::Cursor, CursorBuilding, CursorOn, CursorOnButton, CursorOnMap, CursorOnMinimap, CEditor::CursorPatchIndex, CEditor::CursorPlayer, CursorStartX, CursorStartY, CEditor::CursorUnitIndex, CursorX, CursorY, DraggingPatch, EditorEditPatch, EditorEditUnit, EditorPlaceUnit(), EditorSelecting, EditorSetStartLocation, GameCursor, GameMenuButtonClicked, GameSounds, CPatchType::getName(), GetViewport(), CPatch::getX(), CPatch::getY(), CMap::Info, LeftButton, Map, CViewport::MapHeight, CViewport::MapWidth, MaxSampleVolume, MiddleButton, CUserInterface::Minimap, MouseButtons, MouseHoldShift, CUserInterface::MouseViewport, CMap::PatchManager, PatchOffsetX, PatchOffsetY, PatchPlacedThisPress, GameSound::PlacementError, GameSound::PlacementSuccess, PlayerNobody, Players, CMapInfo::PlayerType, PlayGameSound(), CMinimap::Screen2MapX(), CMinimap::Screen2MapY(), CUserInterface::Scroll, SelectButton, CEditor::SelectedPatchIndex, CEditor::SelectedPlayer, CEditor::SelectedUnitIndex, CUserInterface::SelectedViewport, CStatusLine::Set(), CViewport::Set(), gcn::Widget::setVisible(), CEditor::ShownPatchTypes, CEditor::ShownUnitTypes, CEditor::ShowPatchOutlines, SoundConfig::Sound, StartButton, CPlayer::StartX, CPlayer::StartY, CEditor::State, CUserInterface::StatusLine, ThisPlayer, TileSizeX, TileSizeY, UI, UnitButton, UnitPlacedThisPress, UpdateMinimapTerrain, CViewport::Viewport2MapX(), and CViewport::Viewport2MapY().

Referenced by EditorMainLoop(), and CEditor::Init().

static void EditorCallbackButtonUp ( unsigned  button  )  [static]

static void EditorCallbackExit (  )  [static]

Callback for exit.

Definition at line 1684 of file editloop.cpp.

Referenced by CEditor::Init().

static void EditorCallbackKeyDown ( unsigned  key,
unsigned  keychar 
) [static]

static void EditorCallbackKeyRepeated ( unsigned  key,
unsigned  keychar 
) [static]

Callback for input.

Definition at line 1306 of file editloop.cpp.

References EditorRedoAction(), EditorUndoAction(), KeyModifiers, and ModifierControl.

Referenced by CEditor::Init().

static void EditorCallbackKeyUp ( unsigned  key,
unsigned  keychar 
) [static]

Handle key up.

Parameters:
key Key scancode.
keychar Character code.

Definition at line 1273 of file editloop.cpp.

References HandleKeyModifiersUp(), KeyScrollState, ScrollDown, ScrollLeft, ScrollRight, and ScrollUp.

Referenced by CEditor::Init().

static void EditorCallbackMouse ( int  x,
int  y 
) [static]

Callback for input movement of the cursor.

Parameters:
x Screen X position.
y Screen Y position.

Definition at line 1331 of file editloop.cpp.

References _, ButtonAreaMenu, ButtonAreaUnderCursor, CUserInterface::ButtonPanel, ButtonPanelHeight, ButtonUnderCursor, ButtonUnderMenu, CanBuildUnitType(), CStatusLine::Clear(), CursorConfig::Cursor, CursorBuilding, CursorOn, CursorOnButton, CursorOnMap, CursorOnMinimap, CursorOnUnknown, CEditor::CursorPatchIndex, CEditor::CursorPlayer, CEditor::CursorUnitIndex, CursorX, CursorY, EditorEditPatch, EditorEditUnit, EditorPlaceUnit(), EditorSelecting, EditorSetStartLocation, CMapArea::EndX, CViewport::EndX, CMapArea::EndY, CViewport::EndY, GameCursor, CPatchType::getName(), CPatchManager::getPatch(), CPatchType::getTileHeight(), CPatchType::getTileWidth(), GetViewport(), CMinimap::H, HandleCursorMove(), HandleMouseScrollArea(), IconHeight, IconWidth, CMap::Info, CUserInterface::InfoPanel, LeftButton, Map, CUserInterface::MapArea, CViewport::MapHeight, CViewport::MapWidth, CViewport::MapX, CViewport::MapY, CUserInterface::MenuButton, CUserInterface::Minimap, MouseButtons, MouseScrollMap(), MouseScrollState, CUserInterface::MouseViewport, CPatchManager::move(), CViewport::OffsetX, CViewport::OffsetY, PATCH_ICON_X, PATCH_ICON_Y, CEditor::PatchIndex, CMap::PatchManager, PatchOffsetX, PatchOffsetY, PlayerMax, PlayerNobody, Players, CMapInfo::PlayerType, CUserInterface::Point, RestrictCursorToMinimap(), RestrictCursorToViewport(), CMinimap::Screen2MapX(), CMinimap::Screen2MapY(), CUserInterface::Scroll, ScrollNone, SelectButton, CEditor::SelectedPlayer, CUserInterface::SelectedViewport, CStatusLine::Set(), CViewport::Set(), CEditor::ShownPatchTypes, CEditor::ShownUnitTypes, ShowPatchInfo(), ShowUnitInfo(), START_ICON_X, START_ICON_Y, StartButton, CEditor::State, CUserInterface::StatusLine, TileSizeX, TileSizeY, UI, UNIT_ICON_X, UNIT_ICON_Y, UnitButton, CEditor::UnitIndex, UnitOnScreen(), UnitPlacedThisPress, UnitUnderCursor, UpdateMinimapTerrain, CViewport::Viewport2MapX(), CViewport::Viewport2MapY(), CMinimap::W, CViewport::X, CMapArea::X, CUIButton::X, CInfoPanel::X, CButtonPanel::X, CMinimap::X, CViewport::Y, CMapArea::Y, CUIButton::Y, CInfoPanel::Y, CButtonPanel::Y, and CMinimap::Y.

Referenced by CEditor::Init().

static void EditorMainLoop (  )  [static]

static void EditorPlaceUnit ( int  x,
int  y,
CUnitType type,
CPlayer player 
) [static]

Edit unit.

Parameters:
x X map tile coordinate.
y Y map tile coordinate.
type Unit type to edit.
player Player owning the unit.

Definition at line 290 of file editloop.cpp.

References EditorActionPlaceUnit(), EditorActionTypePlaceUnit, EditorAddUndoAction(), EditorAction::Player, EditorAction::Type, EditorAction::UnitType, EditorAction::X, and EditorAction::Y.

Referenced by EditorCallbackButtonDown(), and EditorCallbackMouse().

static void EditorRedoAction (  )  [static]

static void EditorRemoveUnit ( CUnit unit  )  [static]

int EditorSaveMap ( const std::string &  file  ) 

Start the patch editor.

Save a map from editor.

Parameters:
file Save 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

Definition at line 1855 of file editloop.cpp.

References Map, SaveStratagusMap(), and StratagusLibPath.

Referenced by tolua_stratagus_EditorSaveMap00().

static void EditorUndoAction (  )  [static]

static void EditorUpdateDisplay (  )  [static]

void InitDefinedVariables (  ) 

Define already variables, useful for drawing now.

Definition at line 1351 of file script_unittype.cpp.

Referenced by EditorMainLoop(), and UnitTypeCclRegister().

static void RecalculateShownUnits (  )  [static]

void SetEditorPatchIcon ( const std::string &  icon  ) 

Set the editor's patch icon

Parameters:
icon The icon to use.

Definition at line 213 of file editloop.cpp.

References IconConfig::Name, and CEditor::Patch.

Referenced by tolua_stratagus_SetEditorPatchIcon00().

void SetEditorSelectIcon ( const std::string &  icon  ) 

Set the editor's select icon

Parameters:
icon The icon to use.

Definition at line 193 of file editloop.cpp.

References IconConfig::Name, and CEditor::Select.

Referenced by tolua_stratagus_SetEditorSelectIcon00().

void SetEditorStartUnit ( const std::string &  name  ) 

Start the editor.

Set the editor's start location unit

Parameters:
name The name of the unit to use.

Definition at line 223 of file editloop.cpp.

References CEditor::StartUnitName.

Referenced by tolua_stratagus_SetEditorStartUnit00().

void SetEditorUnitsIcon ( const std::string &  icon  ) 

Set the editor's units icon

Parameters:
icon The icon to use.

Definition at line 203 of file editloop.cpp.

References IconConfig::Name, and CEditor::Units.

Referenced by tolua_stratagus_SetEditorUnitsIcon00().

static void ShowPatchInfo ( const CPatch patch  )  [static]

Show info about a patch.

Parameters:
patch Patch pointer.

Definition at line 852 of file editloop.cpp.

References _, CPatchType::getName(), CPatch::getType(), CPatch::getX(), CPatch::getY(), CStatusLine::Set(), CUserInterface::StatusLine, and UI.

Referenced by EditorCallbackMouse().

static void ShowUnitInfo ( const CUnit unit  )  [static]

void StartEditor ( const std::string &  filename  ) 


Variable Documentation

int ButtonPanelHeight [static]

int ButtonPanelWidth [static]

Definition at line 93 of file editloop.cpp.

Referenced by CalculateVisibleIcons(), DrawPatchIcons(), DrawUnitIcons(), and CEditor::Init().

bool DraggingPatch = false [static]

The user is currently dragging a patch.

Definition at line 103 of file editloop.cpp.

Referenced by EditorCallbackButtonDown(), EditorCallbackButtonUp(), and EditorMainLoop().

Definition at line 485 of file editloop.cpp.

Definition at line 483 of file editloop.cpp.

Definition at line 482 of file editloop.cpp.

Definition at line 481 of file editloop.cpp.

Definition at line 484 of file editloop.cpp.

Definition at line 136 of file editloop.cpp.

Definition at line 138 of file editloop.cpp.

Definition at line 180 of file editloop.cpp.

std::deque<EditorAction> EditorRedoActions [static]

const char* EditorStartFile

Editor CCL start file.

Definition at line 88 of file editloop.cpp.

Referenced by CEditor::Init(), and main().

std::deque<EditorAction> EditorUndoActions [static]

Definition at line 137 of file editloop.cpp.

Definition at line 159 of file editloop.cpp.

A Gui object - binds it all together.

Definition at line 51 of file widgets.cpp.

Referenced by initGuichan().

int IconHeight [static]

int IconWidth [static]

int PatchOffsetX [static]

Definition at line 97 of file editloop.cpp.

Referenced by EditorCallbackButtonDown(), and EditorCallbackMouse().

int PatchOffsetY [static]

Definition at line 98 of file editloop.cpp.

Referenced by EditorCallbackButtonDown(), and EditorCallbackMouse().

bool PatchPlacedThisPress = false [static]

Only allow one patch per press.

Definition at line 100 of file editloop.cpp.

Referenced by EditorCallbackButtonDown(), and EditorCallbackButtonUp().

Patch under cursor.

Definition at line 96 of file editloop.cpp.

bool UnitPlacedThisPress = false [static]

Only allow one unit per press.

Definition at line 99 of file editloop.cpp.

Referenced by EditorCallbackButtonDown(), EditorCallbackButtonUp(), and EditorCallbackMouse().

bool UpdateMinimap = false [static]

Update units on the minimap.

Definition at line 101 of file editloop.cpp.

Referenced by EditorActionPlaceUnit(), EditorActionRemoveUnit(), EditorCallbackKeyDown(), and EditorMainLoop().

bool UpdateMinimapTerrain = false [static]

Terrain has changed, minimap needs updating.

Definition at line 102 of file editloop.cpp.

Referenced by EditorCallbackButtonDown(), EditorCallbackKeyDown(), EditorCallbackMouse(), and EditorMainLoop().

int VisibleIcons [static]

Number of icons that are visible at a time.

Definition at line 104 of file editloop.cpp.

Referenced by EditorPatchSliderListener::action(), EditorUnitSliderListener::action(), CEditor::Init(), and RecalculateShownUnits().


Generated on Sat Feb 21 00:28:16 2009 for Bos Wars by  doxygen 1.5.6