Commit 1367cd26 authored by Leeor Dicker's avatar Leeor Dicker

Eraser function is now working.

- EditState now checks for the eraser button toggled when running its tile index logic.
- Base layer can now be erased -- changed clear color to make holes in the base layer obvious.
- Pulled event hooks for tool buttons as the logic polls for state instead of storing it in EditorState.
- Updated map to handle cases of 'empty' tiles in the base layer.
parent 961b08c3
......@@ -220,7 +220,7 @@ void EditorState::button_MapLinkCancel_Click()
State* EditorState::update()
{
Renderer& r = Utility<Renderer>::get();
r.clearScreen(COLOR_BLACK);
r.clearScreen(COLOR_MAGENTA);
updateScroll();
updateSelector();
......@@ -772,14 +772,16 @@ void EditorState::handleMiddleButtonDown()
*/
void EditorState::changeTileTexture()
{
auto it = StateToLayer.find(mEditState);
if (it == StateToLayer.end())
if (StateToLayer.find(mEditState) == StateToLayer.end())
throw Exception(0, "Bad State", "EditorState::changeTileTExture() called with an invalid state.");
if (mToolBar.floodfill()) patternFill(StateToLayer[mEditState]);
else patternStamp(StateToLayer[mEditState]);
if (mToolBar.flood())
patternFill(StateToLayer[mEditState]);
else if (mToolBar.pencil())
patternStamp(StateToLayer[mEditState]);
else
patternErase(StateToLayer[mEditState]);
return;
}
......@@ -826,6 +828,29 @@ void EditorState::patternStamp(Cell::TileLayer layer)
}
void EditorState::patternErase(Cell::TileLayer layer)
{
Point_2d& pt = mMap.getGridCoords(mMouseCoords);
const Pattern& p = mTilePalette.pattern();
for (int row = 0; row < p.height(); row++)
{
for (int col = 0; col < p.width(); col++)
{
int x = pt.x() - ((p.width() - 1) - col);
int y = pt.y() - ((p.height() - 1) - row);
if (x >= 0 && y >= 0)
mMap.getCellByGridCoords(x, y).index(layer, -1);
}
}
mMapChanged = true;
}
/**
* Changes the edit mode and unhides the tile palette.
*/
......
......@@ -85,6 +85,7 @@ private:
void changeTileTexture();
void patternFill(Cell::TileLayer layer);
void patternStamp(Cell::TileLayer layer);
void patternErase(Cell::TileLayer layer);
void showTilePalette();
void hideTilePalette();
......
......@@ -358,7 +358,8 @@ void Map::update()
int rasterX = mViewport.x() + ((col - tileUpperLeft.x()) * mTileset.width()) - offsetX + mViewport.x();
int rasterY = mViewport.y() + ((row - tileUpperLeft.y()) * mTileset.height()) - offsetY + mViewport.y();
mTileset.drawTile(cell.index(Cell::LAYER_BASE), rasterX, rasterY);
if (cell.index(Cell::LAYER_BASE) >= 0)
mTileset.drawTile(cell.index(Cell::LAYER_BASE), rasterX, rasterY);
if(mDrawBgDetail && cell.index(Cell::LAYER_BASE_DETAIL) >= 0)
mTileset.drawTile(cell.index(Cell::LAYER_BASE_DETAIL), rasterX, rasterY);
......
......@@ -223,9 +223,6 @@ void ToolBar::btnSave_Clicked()
void ToolBar::btnPencil_Clicked()
{
if(!btnPencil.toggled())
mToolbarEvent(TOOLBAR_PENCIL, true);
btnPencil.toggle(true);
btnFill.toggle(false);
btnErase.toggle(false);
......@@ -234,9 +231,6 @@ void ToolBar::btnPencil_Clicked()
void ToolBar::btnFill_Clicked()
{
if (!btnFill.toggled())
mToolbarEvent(TOOLBAR_FILL, true);
btnPencil.toggle(false);
btnFill.toggle(true);
btnErase.toggle(false);
......@@ -245,9 +239,6 @@ void ToolBar::btnFill_Clicked()
void ToolBar::btnErase_Clicked()
{
if (!btnErase.toggled())
mToolbarEvent(TOOLBAR_ERASE, true);
btnPencil.toggle(false);
btnFill.toggle(false);
btnErase.toggle(true);
......
......@@ -14,9 +14,6 @@ public:
enum ToolBarAction
{
TOOLBAR_SAVE,
TOOLBAR_PENCIL,
TOOLBAR_FILL,
TOOLBAR_ERASE,
TOOLBAR_LAYER_BG_EDIT,
TOOLBAR_LAYER_BG_DETAIL_EDIT,
TOOLBAR_LAYER_DETAIL_EDIT,
......@@ -44,7 +41,9 @@ public:
ToolBarEvent& toolbar_event() { return mToolbarEvent; }
bool floodfill() const { return btnFill.toggled(); }
bool pencil() const { return btnPencil.toggled(); }
bool flood() const { return btnFill.toggled(); }
bool erase() const { return btnErase.toggled(); }
private:
......
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