Skip to content

Commit

Permalink
Cleanup Editor:
Browse files Browse the repository at this point in the history
Remove unused `MapLoaded`/`WriteCompressedMaps`/`PopUpX`/`PopUpY`
  • Loading branch information
Jarod42 committed Apr 24, 2024
1 parent 32bb8f1 commit ac32992
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 125 deletions.
148 changes: 63 additions & 85 deletions src/editor/editloop.cpp
Expand Up @@ -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;
});
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 1 addition & 17 deletions src/editor/editor.cpp
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/editor/edmap.cpp
Expand Up @@ -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));

Expand Down
35 changes: 14 additions & 21 deletions src/include/editor.h
Expand Up @@ -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<std::tuple<int, int, int>> RandomTiles; /// other tiles to fill randomly. (tile, count, area size)
Expand All @@ -81,35 +83,28 @@ class CEditor
std::vector<const CUnitType *> ShownUnitTypes; /// Shown editor unit-type table.
std::vector<unsigned int> 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};
};
Expand Down Expand Up @@ -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__
1 change: 0 additions & 1 deletion src/tolua/editor.pkg
Expand Up @@ -12,7 +12,6 @@ class CEditor
vector<string> UnitTypes;
bool TerrainEditable;
const CUnitType *StartUnit;
bool WriteCompressedMaps;
EditorRunningType Running;
void CreateRandomMap(bool shuffleTranslitions) const;
};
Expand Down

0 comments on commit ac32992

Please sign in to comment.