Commit 0badde97 authored by Leeor Dicker's avatar Leeor Dicker

Implements Issue #3 (Disallow edits to layers that are hidden).

- Added a function, layer_hidden(), to EditorState source file that does a quick check for layer visibility based on state of the editor.
- EditorState ignores calls to changeTileTexture() when the current layer is hidden.
- EditorState draws a 'layer hidden' hint attached to the mouse pointer when the current layer is hidden.
parent c8982c9b
......@@ -45,9 +45,6 @@
<ClInclude Include="..\..\src\StartState.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Tileset.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Common.h">
<Filter>Header Files</Filter>
</ClInclude>
......@@ -90,6 +87,9 @@
<ClInclude Include="..\..\src\Map\Tileset.h">
<Filter>Header Files\Map</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Tileset.h">
<Filter>Resource Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\EditorState.cpp">
......
......@@ -21,12 +21,32 @@ std::map<EditState, string> StateStringMap; /**< EditState string table. */
std::map<int, EditState> StateIntMap; /**< EditState int table. */
std::map<EditState, Cell::TileLayer> StateToLayer; /**< Translation table between a specific edit state and tile layer. */
bool layer_hidden(EditState _s, ToolBar& _t)
{
switch (_s)
{
case STATE_BASE_TILE_INDEX:
return !_t.show_bg();
case STATE_BASE_DETAIL_TILE_INDEX:
return !_t.show_bg_detail();
case STATE_DETAIL_TILE_INDEX:
return !_t.show_detail();
case STATE_FOREGROUND_TILE_INDEX:
return !_t.show_foreground();
case STATE_TILE_COLLISION:
return !_t.show_collision();
default:
return false;
}
}
EditorState::EditorState(const string& mapPath):
mMousePointer(nullptr),
mPointer_Normal("sys/normal.png"),
mPointer_Fill("sys/fill.png"),
mPointer_Eraser("sys/eraser.png"),
mLayerHidden("sys/layer_hidden.png"),
mFont("fonts/ui-normal.png", 7, 9, 0),
mLinkCell(nullptr),
mMap(mapPath),
......@@ -48,6 +68,7 @@ EditorState::EditorState(const string& name, const string& mapPath, const string
mPointer_Normal("sys/normal.png"),
mPointer_Fill("sys/fill.png"),
mPointer_Eraser("sys/eraser.png"),
mLayerHidden("sys/layer_hidden.png"),
mFont("fonts/ui-normal.png", 7, 9, 0),
mLinkCell(nullptr),
mMap(name, tsetPath, w, h),
......@@ -259,6 +280,8 @@ State* EditorState::update()
r.drawTextShadow(mFont, "Map File: " + mMapSavePath, r.screenCenterX() - (mFont.width("Map File: " + mMapSavePath) / 2), r.height() - (mFont.height() + 2), 1, 255, 255, 255, 0, 0, 0);
r.drawImage(*mMousePointer, mMouseCoords.x(), mMouseCoords.y());
if (layer_hidden(mEditState, mToolBar))
r.drawImage(mLayerHidden, mMouseCoords.x(), mMouseCoords.y() + 34, 1.0f, 255, 255, 0, 255);
return mReturnState;
}
......@@ -572,6 +595,9 @@ void EditorState::changeTileTexture()
if (StateToLayer.find(mEditState) == StateToLayer.end())
throw Exception(0, "Bad State", "EditorState::changeTileTExture() called with an invalid state.");
if (layer_hidden(mEditState, mToolBar))
return;
if (mToolBar.flood())
{
if (mToolBar.flood_contiguous())
......@@ -581,8 +607,10 @@ void EditorState::changeTileTexture()
}
else if (mToolBar.pencil())
pattern(StateToLayer[mEditState]);
else
else if (mToolBar.erase())
pattern(StateToLayer[mEditState], -1);
else // Defined this way to avoid forgetting to add possible new tools to the check.
return;
mMapChanged = true;
return;
......
......@@ -110,6 +110,8 @@ private:
Image mPointer_Fill;
Image mPointer_Eraser;
Image mLayerHidden;
// PRIMITIVES
Point_2d mMouseCoords;
Point_2d mSavedMouseCoords;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment