diff --git a/src/editor/editloop.cpp b/src/editor/editloop.cpp index 5d6f55e967..0b40119ed7 100644 --- a/src/editor/editloop.cpp +++ b/src/editor/editloop.cpp @@ -658,8 +658,6 @@ static void DrawUnitIcons() if (i == Editor.CursorUnitIndex) { Video.DrawRectangleClip(ColorWhite, x - 1, y - 1, w + 2, h + 2); - Editor.PopUpX = x; - Editor.PopUpY = y; } return true; }); @@ -808,8 +806,6 @@ static void DrawTileIcons() if (i == Editor.CursorTileIndex) { Video.DrawRectangleClip(ColorWhite, x - 1, y - 1, Map.Tileset->getPixelTileSize().x + 2, Map.Tileset->getPixelTileSize().y + 2); - Editor.PopUpX = x; - Editor.PopUpY = y; } return true; @@ -2185,102 +2181,84 @@ void EditorMainLoop() UpdateMinimap = true; - while (1) { - Editor.MapLoaded = false; - Editor.Running = EditorEditing; - - Editor.Init(); - - // Unit Types is now valid, update the tools - // TODO (timfel): This is very ugly/hacky, but the entire editor is, unfortunately... - int newW = toolDropdown->getWidth(); - for (std::string entry : Editor.UnitTypes) { - if (entry.rfind("--", 0) != std::string::npos) { - std::string e = entry.substr(2); - toolListStrings.push_back(e); - int strW = toolDropdown->getFont()->getWidth(e) + 20; - if (newW < strW) { - newW = strW; - } + Editor.Running = EditorEditing; + + Editor.Init(); + + // Unit Types is now valid, update the tools + // TODO (timfel): This is very ugly/hacky, but the entire editor is, unfortunately... + int newW = toolDropdown->getWidth(); + for (std::string entry : Editor.UnitTypes) { + if (entry.rfind("--", 0) != std::string::npos) { + std::string e = entry.substr(2); + toolListStrings.push_back(e); + int strW = toolDropdown->getFont()->getWidth(e) + 20; + if (newW < strW) { + newW = strW; } } - toolDropdown->setListModel(new StringListModel(toolListStrings)); - toolDropdown->setWidth(newW); + } + toolDropdown->setListModel(new StringListModel(toolListStrings)); + toolDropdown->setWidth(newW); - overlaysDropdown->setX(toolDropdown->getX() + toolDropdown->getWidth() + 10); + overlaysDropdown->setX(toolDropdown->getX() + toolDropdown->getWidth() + 10); - //ProcessMenu("menu-editor-tips", 1); - InterfaceState = IfaceState::Normal; + //ProcessMenu("menu-editor-tips", 1); + InterfaceState = IfaceState::Normal; - SetVideoSync(); + SetVideoSync(); - GameCursor = UI.Point.Cursor; - InterfaceState = IfaceState::Normal; - Editor.State = EditorStateType::Selecting; - UI.SelectedViewport = UI.Viewports; - TileCursorSize = 1; - - bool start = true; - - while (Editor.Running) { - if (FrameCounter % CYCLES_PER_SECOND == 0) { - if (UpdateMinimap) { - UI.Minimap.Update(); - UpdateMinimap = false; - } + GameCursor = UI.Point.Cursor; + InterfaceState = IfaceState::Normal; + Editor.State = EditorStateType::Selecting; + UI.SelectedViewport = UI.Viewports; + TileCursorSize = 1; + + bool start = true; + + while (Editor.Running) { + if (FrameCounter % CYCLES_PER_SECOND == 0) { + if (UpdateMinimap) { + UI.Minimap.Update(); + UpdateMinimap = false; } + } - EditorUpdateDisplay(); - - // - // Map scrolling - // - if (UI.MouseScroll) { - int tbX, tbY; - toolDropdown->getAbsolutePosition(tbX, tbY); - tbX += CursorScreenPos.x; - tbY += CursorScreenPos.y; - if (!(toolDropdown->getDimension().isContaining(tbX, tbY))) { - DoScrollArea(MouseScrollState, 0, MouseScrollState == 0 && KeyScrollState > 0); - } - } - if (UI.KeyScroll) { - if (CursorOn == ECursorOn::Map) { - DoScrollArea(KeyScrollState, (KeyModifiers & ModifierControl) != 0, MouseScrollState == 0 && KeyScrollState > 0); - } - if (CursorOn == ECursorOn::Map && (MouseButtons & LeftButton) && - (Editor.State == EditorStateType::EditTile || - Editor.State == EditorStateType::EditUnit)) { - EditorCallbackButtonDown(0); - } - } + EditorUpdateDisplay(); - if (start) { - start = false; - if (UI.MenuButton.Callback) { - UI.MenuButton.Callback->action(gcn::ActionEvent(nullptr, "")); - } + // + // Map scrolling + // + if (UI.MouseScroll) { + int tbX, tbY; + toolDropdown->getAbsolutePosition(tbX, tbY); + tbX += CursorScreenPos.x; + tbY += CursorScreenPos.y; + if (!(toolDropdown->getDimension().isContaining(tbX, tbY))) { + DoScrollArea(MouseScrollState, 0, MouseScrollState == 0 && KeyScrollState > 0); } - - WaitEventsOneFrame(); } - CursorBuilding = nullptr; - if (!Editor.MapLoaded) { - break; + if (UI.KeyScroll) { + if (CursorOn == ECursorOn::Map) { + DoScrollArea(KeyScrollState, (KeyModifiers & ModifierControl) != 0, MouseScrollState == 0 && KeyScrollState > 0); + } + if (CursorOn == ECursorOn::Map && (MouseButtons & LeftButton) && + (Editor.State == EditorStateType::EditTile || + Editor.State == EditorStateType::EditUnit)) { + EditorCallbackButtonDown(0); + } } - CleanModules(); - - LoadCcl(Parameters::Instance.luaStartFilename); // Reload the main config file - - PreMenuSetup(); - - InterfaceState = IfaceState::Menu; - GameCursor = UI.Point.Cursor; + if (start) { + start = false; + if (UI.MenuButton.Callback) { + UI.MenuButton.Callback->action(gcn::ActionEvent(nullptr, "")); + } + } - Video.ClearScreen(); - Invalidate(); + WaitEventsOneFrame(); } + CursorBuilding = nullptr; CommandLogDisabled = OldCommandLogDisabled; SetCallbacks(old_callbacks); diff --git a/src/editor/editor.cpp b/src/editor/editor.cpp index 75b32a6cfc..ea230c3c25 100644 --- a/src/editor/editor.cpp +++ b/src/editor/editor.cpp @@ -59,27 +59,11 @@ #include "editor.h" -#include "player.h" - -/*---------------------------------------------------------------------------- --- Defines -----------------------------------------------------------------------------*/ - -/*---------------------------------------------------------------------------- --- Variables -----------------------------------------------------------------------------*/ - /*---------------------------------------------------------------------------- -- Functions ----------------------------------------------------------------------------*/ -CEditor::CEditor() : - TerrainEditable(true), - StartUnit(nullptr), - UnitIndex(0), CursorUnitIndex(-1), SelectedUnitIndex(-1), - TileIndex(0), CursorTileIndex(-1), SelectedTileIndex(-1), - CursorPlayer(-1), SelectedPlayer(PlayerNumNeutral), - MapLoaded(false), WriteCompressedMaps(true), PopUpX(-1), PopUpY(-1) +CEditor::CEditor() { #define WATER_TILE 0x10 #define COAST_TILE 0x30 diff --git a/src/editor/edmap.cpp b/src/editor/edmap.cpp index 20c99c95cb..376ad692a1 100644 --- a/src/editor/edmap.cpp +++ b/src/editor/edmap.cpp @@ -98,7 +98,7 @@ static uint32_t QuadFromTile(const Vec2i &pos) ** @param tileIndex Tile type to edit. ** @param lock_pos map tile coordinate, that should not be changed in callback. */ -void EditorChangeTile(const Vec2i &pos, int tileIndex, const Vec2i &lock_pos, bool changeSurroundings) +static void EditorChangeTile(const Vec2i &pos, int tileIndex, const Vec2i &lock_pos, bool changeSurroundings) { Assert(Map.Info.IsPointOnMap(pos)); diff --git a/src/include/editor.h b/src/include/editor.h index cc5e2fc992..dd891610d9 100644 --- a/src/include/editor.h +++ b/src/include/editor.h @@ -72,6 +72,8 @@ class CEditor /// Make random map void CreateRandomMap(bool shuffleTransitions = false) const; + +public: /// Variables for random map creation int BaseTileIndex; /// Tile to fill the map with initially; std::vector> RandomTiles; /// other tiles to fill randomly. (tile, count, area size) @@ -81,35 +83,28 @@ class CEditor std::vector ShownUnitTypes; /// Shown editor unit-type table. std::vector ShownTileTypes; /// Shown editor tile-type table. - bool TerrainEditable; /// Is the terrain editable ? + bool TerrainEditable = true; /// Is the terrain editable? IconConfig Select; /// Editor's select icon. IconConfig Units; /// Editor's units icon. std::string StartUnitName; /// name of the Unit used to display the start location. - const CUnitType *StartUnit; /// Unit used to display the start location. + const CUnitType *StartUnit = nullptr; /// Unit used to display the start location. - int UnitIndex; /// Unit icon draw index. - int CursorUnitIndex; /// Unit icon under cursor. - int SelectedUnitIndex; /// Unit type to draw. + int UnitIndex = 0; /// Unit icon draw index. + int CursorUnitIndex = -1; /// Unit icon under cursor. + int SelectedUnitIndex = -1; /// Unit type to draw. - int TileIndex; /// tile icon draw index. - int CursorTileIndex; /// tile icon under cursor. - int SelectedTileIndex; /// tile type to draw. + int TileIndex = 0; /// tile icon draw index. + int CursorTileIndex = -1; /// tile icon under cursor. + int SelectedTileIndex = -1; /// tile type to draw. uint8_t HighlightElevationLevel {0}; uint8_t SelectedElevationLevel {0}; - int CursorPlayer; /// Player under the cursor. - int SelectedPlayer; /// Player selected for draw. - - bool MapLoaded; /// Map loaded in editor - bool WriteCompressedMaps; /// Use compression when saving + int CursorPlayer = -1; /// Player under the cursor. + int SelectedPlayer = PlayerNumNeutral; /// Player selected for draw. - EditorRunningType Running; /// Editor is running - - EditorStateType State; /// Current editor state - - int PopUpX; - int PopUpY; + EditorRunningType Running = EditorNotRunning; /// Editor is running + EditorStateType State = EditorStateType::Selecting; /// Current editor state fieldHighlightChecker OverlayHighlighter {nullptr}; }; @@ -145,8 +140,6 @@ extern void EditorCclRegister(); /// Update surroundings for tile changes extern void EditorTileChanged(const Vec2i &pos); -extern void EditorChangeTile(const Vec2i &pos, int tileIndex, int d, bool changeSurroundings); - //@} #endif // !__EDITOR_H__ diff --git a/src/tolua/editor.pkg b/src/tolua/editor.pkg index 6e033006c9..e895883b61 100644 --- a/src/tolua/editor.pkg +++ b/src/tolua/editor.pkg @@ -12,7 +12,6 @@ class CEditor vector UnitTypes; bool TerrainEditable; const CUnitType *StartUnit; - bool WriteCompressedMaps; EditorRunningType Running; void CreateRandomMap(bool shuffleTranslitions) const; };