Commit 008c7984 authored by Leeor Dicker's avatar Leeor Dicker

Toggle buttons for minimap/tilepalette added.

- Buttons to toggle visibility of minimap/tilepalette added.
- Cleaned up some tile placement logic that would cause painting over the area the tilepalette was over to not be painted even if the window was hidden.
- Fixed some mouse reaction logic in TilePalette.
- Updated visual style of the tile palette. It's very plain but it's functional.
parent bbd29b4b
......@@ -14,7 +14,7 @@ const float SCROLL_SPEED = 250.0f;
const float MINI_MAP_X = 10.0f;
const float MINI_MAP_Y = 65.0f;
SDL_Surface* MINI_MAP_SURFACE = NULL; // UGLY HACK!
SDL_Surface* MINI_MAP_SURFACE = nullptr; // HACK!
std::map<EditState, string> StateStringMap; /**< EditState string table. */
......@@ -516,35 +516,34 @@ void EditorState::onQuit()
*/
void EditorState::onMouseMove(int x, int y, int relX, int relY)
{
if(mRightButtonDown && mEditState != STATE_MAP_LINK_EDIT)
{
mMap.moveCamera(relX, relY);
return;
}
else
{
mMouseCoords(x, y);
mMouseCoords(x, y);
if(mLeftButtonDown && !isPointInRect(mMouseCoords, mTilePalette.rect()))
if(mLeftButtonDown)
{
if(mEditState != STATE_MAP_LINK_EDIT && isPointInRect(x, y, MINI_MAP_X, MINI_MAP_Y, mMiniMap->rect().w(), mMiniMap->rect().h()))
{
if(mEditState != STATE_MAP_LINK_EDIT && isPointInRect(x, y, MINI_MAP_X, MINI_MAP_Y, mMiniMap->rect().w(), mMiniMap->rect().h()))
{
if(!mDrawMiniMap)
return;
mMap.setCamera((mMap.tileset().width() * (x - MINI_MAP_X)) - (Utility<Renderer>::get().width() / 2), (mMap.tileset().height() * (y - MINI_MAP_Y)) - (Utility<Renderer>::get().height() / 2));
if(!mDrawMiniMap)
return;
}
// Avoid modifying tiles if we're in the 'toolbar area'
if (y < 32 || mTilePalette.dragging())
return;
if(mEditState == STATE_TILE_COLLISION)
mMap.getCell(mMouseCoords).blocked(mPlacingCollision);
else
changeTileTexture();
mMap.setCamera((mMap.tileset().width() * (x - MINI_MAP_X)) - (Utility<Renderer>::get().width() / 2), (mMap.tileset().height() * (y - MINI_MAP_Y)) - (Utility<Renderer>::get().height() / 2));
return;
}
// Avoid modifying tiles if we're in the 'toolbar area'
if (y < 32 || mTilePalette.dragging())
return;
if(mEditState == STATE_TILE_COLLISION)
mMap.getCell(mMouseCoords).blocked(mPlacingCollision);
else
changeTileTexture();
}
}
......@@ -807,10 +806,13 @@ void EditorState::toolbar_event(ToolBar::ToolBarAction _act)
mMap.drawDetail(mToolBar.show_detail());
mMap.drawForeground(mToolBar.show_foreground());
mMap.drawCollision(mToolBar.show_collision());
if (mToolBar.show_collision())
mTilePalette.reset();
if (mToolBar.show_collision()) mTilePalette.reset();
break;
case ToolBar::TOOLBAR_MINIMAP_TOGGLE:
mDrawMiniMap = mToolBar.show_minimap();
break;
case ToolBar::TOOLBAR_TILE_PALETTE_TOGGLE:
mTilePalette.hidden(!mToolBar.show_tilepalette());
break;
default:
break;
......
......@@ -4,7 +4,7 @@
#include "Common.h"
const Point_2d PALETTE_DIMENSIONS = Point_2d(196, 315);
const Point_2d PALETTE_DIMENSIONS = Point_2d(196, 300);
const Point_2d FIRST_TILE_COORDINATE = Point_2d(2, 18);
const Point_2d TILE_SLOT_PADDING = Point_2d(0, 0);
......@@ -41,10 +41,10 @@ TilePalette::~TilePalette()
void TilePalette::init()
{
int yPosition = rect().y() + rect().h() - 25;
int yPosition = rect().y() + rect().h() - 23;
mBtnPrev.size(30, 20);
mBtnPrev.position(mRect.x() + 2, yPosition);
mBtnPrev.position(mRect.x() + 3, yPosition);
mBtnPrev.image(Utility<Configuration>::get().option(CONFIG_UI_TILEPALETTE_PREV_IMAGE));
mBtnPrev.click().Connect(this, &TilePalette::button_Prev_click);
......@@ -140,20 +140,22 @@ void TilePalette::update()
Renderer& r = Utility<Renderer>::get();
if(!mTset)
r.drawBoxFilled(rect(), 180, 180, 180);
r.drawBoxFilled(mTileGridRect, 70, 70, 70);
r.drawBoxFilled(rect().x(), rect().y(), rect().w(), 16, 200, 200, 200);
r.drawLine(rect().x(), rect().y() + 16, rect().x() + rect().w(), rect().y() + 16, 0, 0, 0);
r.drawBox(rect(), 0, 0, 0);
if (mFont)
{
r.drawBox(mRect.x(), mRect.y(), mRect.w(), mRect.h(), 0, 0, 0, 100);
r.drawBoxFilled(mRect.x(), mRect.y(), mRect.w(), mRect.h(), 200, 200, 0, 65);
r.drawText(*mFont, "Tile Palette", mRect.x() + 2, mRect.y() + 4, 0, 0, 0);
r.drawText(*mFont, "Tile Palette", mRect.x() + 3, mRect.y() + 4, 0, 0, 0); // cheap way of getting a 'bold' typeface. Inefficient.
r.drawText(*mFont, string_format("Page: %i of %i", mCurrentPage + 1, mNumPages), mBtnPrev.positionX() + mBtnPrev.width() + 4, mRect.y() + 280, 0, 0, 0);
}
if(mFont)
r.drawTextShadow(*mFont, "Tile Palette", mRect.x() + 2, mRect.y(), 1, 255, 255, 255, 0, 0, 0);
if(!mTset)
return;
}
// Draw the background box.
r.drawBox(mRect, 0, 0, 0, 100);
r.drawBoxFilled(mRect.x(), mRect.y(), mRect.w(), mRect.h(), 200, 200, 0, 65);
// Draw buttons
mBtnPrev.update();
......@@ -169,17 +171,10 @@ void TilePalette::update()
if(index < mTset->numTiles())
mTset->drawTile(index, FIRST_TILE_COORDINATE.x() + (col * mTset->width()) + (col * TILE_SLOT_PADDING.x()) + mRect.x(), FIRST_TILE_COORDINATE.y() + (row * mTset->height()) + (row * TILE_SLOT_PADDING.y()) + mRect.y());
//r.drawBox(mSlots[(row * TILE_GRID_DIMENSIONS.x()) + col], 0, 0, 0);
r.drawBox(mSlots[row][col], 0, 0, 0);
}
}
if(mFont)
{
r.drawTextShadow(*mFont, "Tile Palette", mRect.x() + 2, mRect.y() + 2, 1, 255, 255, 255, 0, 0, 0);
r.drawTextShadow(*mFont, string_format("Page: %i of %i", mCurrentPage + 1, mNumPages), mRect.x() + 1, mRect.y() + 275, 1, 255, 255, 255, 0, 0, 0);
}
// Draw Selectors
if(mTsetIndex / NUM_TILES_PER_PAGE == mCurrentPage)
{
......@@ -210,6 +205,9 @@ void TilePalette::onMouseMove(int x, int y, int relX, int relY)
mBtnPrev.position(mBtnPrev.positionX() + relX, mBtnPrev.positionY() + relY);
mBtnNext.position(mBtnNext.positionX() + relX, mBtnNext.positionY() + relY);
mTileGridRect.x(mTileGridRect.x() + relX);
mTileGridRect.y(mTileGridRect.y() + relY);
for (size_t row = 0; row < mSlots.size(); ++row)
{
for (size_t col = 0; col < mSlots[row].size(); ++col)
......@@ -236,14 +234,17 @@ void TilePalette::onMouseDown(MouseButton button, int x, int y)
if(hidden() || (button != BUTTON_LEFT))
return;
mLeftButtonDown = true;
if (isPointInRect(x, y, rect().x(), rect().y(), rect().w(), 17))
{
mDragging = true;
return;
}
if (!(isPointInRect(x, y, rect().x(), rect().y(), rect().w(), rect().h())))
return;
mLeftButtonDown = true;
Point_2d pt(x, y);
mDragOrigin = pt;
......@@ -278,6 +279,9 @@ void TilePalette::onMouseUp(MouseButton button, int x, int y)
if (hidden() || mSlots.empty() || (button != BUTTON_LEFT))
return;
if(!mLeftButtonDown && !mDragging)
return;
Point_2d pt(x, y);
for(int row = 0; row < TILE_GRID_DIMENSIONS.y(); row++)
......
......@@ -124,6 +124,21 @@ void ToolBar::initUi()
btnLayerCollisionToggle.position(btnLayerForegroundToggle.positionX() + btnLayerForegroundToggle.width() + BUTTON_SPACE, 2);
btnLayerCollisionToggle.click().Connect(this, &ToolBar::btnLayerCollisionToggle_Clicked);
// WINDOW VISIBILITY
btnMiniMapToggle.image("sys/map.png");
btnMiniMapToggle.type(Button::BUTTON_TOGGLE);
btnMiniMapToggle.toggle(true);
btnMiniMapToggle.size(22, 28);
btnMiniMapToggle.position(Utility<Renderer>::get().width() - 48, 2);
btnMiniMapToggle.click().Connect(this, &ToolBar::btnMiniMapToggle_Clicked);
btnTilePaletteToggle.image("sys/palette.png");
btnTilePaletteToggle.type(Button::BUTTON_TOGGLE);
btnTilePaletteToggle.toggle(true);
btnTilePaletteToggle.size(22, 28);
btnTilePaletteToggle.position(Utility<Renderer>::get().width() - 24, 2);
btnTilePaletteToggle.click().Connect(this, &ToolBar::btnTilePaletteToggle_Clicked);
hookEvents();
}
......@@ -167,6 +182,9 @@ void ToolBar::update()
btnLayerDetailToggle.update();
btnLayerForegroundToggle.update();
btnLayerCollisionToggle.update();
btnMiniMapToggle.update();
btnTilePaletteToggle.update();
}
......@@ -315,3 +333,15 @@ void ToolBar::btnLayerCollisionToggle_Clicked()
{
mToolbarEvent(TOOLBAR_LAYER_COLLISION_TOGGLE);
}
void ToolBar::btnMiniMapToggle_Clicked()
{
mToolbarEvent(TOOLBAR_MINIMAP_TOGGLE);
}
void ToolBar::btnTilePaletteToggle_Clicked()
{
mToolbarEvent(TOOLBAR_TILE_PALETTE_TOGGLE);
}
......@@ -51,6 +51,9 @@ public:
bool show_foreground() const { return btnLayerForegroundToggle.toggled(); }
bool show_collision() const { return btnLayerCollisionToggle.toggled(); }
bool show_minimap() const { return btnMiniMapToggle.toggled(); }
bool show_tilepalette() const { return btnTilePaletteToggle.toggled(); }
private:
void initUi();
......@@ -81,6 +84,9 @@ private:
void btnLayerForegroundToggle_Clicked();
void btnLayerCollisionToggle_Clicked();
void btnMiniMapToggle_Clicked();
void btnTilePaletteToggle_Clicked();
private:
Font mFont;
......@@ -105,5 +111,8 @@ private:
Button btnLayerForegroundToggle;
Button btnLayerCollisionToggle;
Button btnMiniMapToggle;
Button btnTilePaletteToggle;
ToolBarEvent mToolbarEvent;
};
\ No newline at end of file
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