Commit bbd29b4b authored by Leeor Dicker's avatar Leeor Dicker

TilePalette is now a draggable window. Also includes a lot of code refactoring throughout.

- Pulled key processing for setting editor states.
- Fixed scrolling speed with keyboard arrow keys.
- Replaced several awkward ternary bool flips with cleaner code.
- TilePalette now hooks its own event handlers instead of the much older style of event injection.
- Toolbar layer visibility now fully hooked up and working.
- Pulled some unused code form Map.
- Map can now have its BG layer set to be drawn or not drawn like other layers. This is only useful in the tile editor itself.
- TilePalette will no longer draw itself or respond to events when in hidden.
- Pulled show/hide images from TilePalette.
parent 1367cd26
......@@ -363,7 +363,7 @@ void EditorState::updateScroll()
mSelectorRect = mMap.injectMousePosition(mMouseCoords);
}
float delta = mTimer.delta();
float delta = (mTimer.delta() / 1000.0f);
mMap.moveCamera(static_cast<float>(mScrollVector.x()) * delta, static_cast<float>(mScrollVector.y()) * delta);
}
......@@ -408,9 +408,6 @@ void EditorState::onKeyDown(KeyCode key, KeyModifier mod, bool repeat)
return;
}
stringstream str;
//int x, y;
switch(key)
{
case KEY_ESCAPE:
......@@ -433,44 +430,9 @@ void EditorState::onKeyDown(KeyCode key, KeyModifier mod, bool repeat)
mScrollVector.y() = SCROLL_SPEED;
break;
case KEY_1:
// FIXME: Make this adjust the toolbar instead of directly manipulating fields here.
/*setState(STATE_BASE_TILE_INDEX);
mMap.drawCollision(false);*/
break;
case KEY_2:
// FIXME: Make this adjust the toolbar instead of directly manipulating fields here.
/*setState(STATE_BASE_DETAIL_TILE_INDEX);
mMap.drawCollision(false);*/
break;
case KEY_3:
// FIXME: Make this adjust the toolbar instead of directly manipulating fields here.
/*setState(STATE_DETAIL_TILE_INDEX);
mMap.drawCollision(false);*/
break;
case KEY_4:
// FIXME: Make this adjust the toolbar instead of directly manipulating fields here.
/*setState(STATE_FOREGROUND_TILE_INDEX);
mMap.drawCollision(false);*/
break;
case KEY_5:
// FIXME: Make this adjust the toolbar instead of directly manipulating fields here.
/*
setState(STATE_TILE_COLLISION);
mMap.drawCollision(true);
*/
break;
case KEY_F1:
mDrawDebug ? mDrawDebug = false : mDrawDebug = true;
if(mDrawDebug)
mMap.showLinks(true);
else
mMap.showLinks(false);
mDrawDebug = !mDrawDebug;
mMap.showLinks(mDrawDebug);
break;
// Stealing this for dumping the minimap for now
......@@ -487,36 +449,17 @@ void EditorState::onKeyDown(KeyCode key, KeyModifier mod, bool repeat)
mLinkCell = &mMap.getCell(mMouseCoords);
mCellInspectRect = mMap.injectMousePosition(mMouseCoords);
mTxtLinkDestination.text(mLinkCell->link());
str << mLinkCell->link_destination().x();
mTxtLinkDestX.text(str.str());
str.str("");
str << mLinkCell->link_destination().y();
mTxtLinkDestY.text(str.str());
mTxtLinkDestX.text(string_format("%i", mLinkCell->link_destination().x()));
mTxtLinkDestY.text(string_format("%i", mLinkCell->link_destination().y()));
setState(STATE_MAP_LINK_EDIT);
break;
case KEY_F4:
saveMap();
break;
case KEY_F5:
mMap.toggleBgDetail();
break;
case KEY_F6:
mMap.toggleDetail();
break;
case KEY_F7:
mMap.toggleForeground();
break;
case KEY_F10:
mHideUi ? mHideUi = false : mHideUi = true;
mHideUi = !mHideUi;
break;
case KEY_m:
mDrawMiniMap ? mDrawMiniMap = false : mDrawMiniMap = true;
mDrawMiniMap = !mDrawMiniMap;
break;
case KEY_z:
......@@ -576,13 +519,12 @@ void EditorState::onMouseMove(int x, int y, int relX, int relY)
if(mRightButtonDown && mEditState != STATE_MAP_LINK_EDIT)
{
mMap.moveCamera(relX, relY);
}
else
{
mMouseCoords(x, y);
mTilePalette.onMouseMove(x, y, relX, relY);
if(mLeftButtonDown && !isPointInRect(mMouseCoords, mTilePalette.rect()))
{
if(mEditState != STATE_MAP_LINK_EDIT && isPointInRect(x, y, MINI_MAP_X, MINI_MAP_Y, mMiniMap->rect().w(), mMiniMap->rect().h()))
......@@ -595,7 +537,7 @@ void EditorState::onMouseMove(int x, int y, int relX, int relY)
}
// Avoid modifying tiles if we're in the 'toolbar area'
if (y < 32)
if (y < 32 || mTilePalette.dragging())
return;
if(mEditState == STATE_TILE_COLLISION)
......@@ -639,8 +581,6 @@ void EditorState::onMouseUp(MouseButton button, int x, int y)
if(button == BUTTON_LEFT)
{
mLeftButtonDown = false;
mTilePalette.onMouseUp(button, x, y);
if(mEditState == STATE_MAP_LINK_EDIT)
{
}
......@@ -670,6 +610,9 @@ void EditorState::handleLeftButtonDown(int x, int y)
{
Point_2d pt(x, y);
if (isPointInRect(pt, mTilePalette.rect()))
return;
if(mEditState != STATE_MAP_LINK_EDIT && mDrawMiniMap && isPointInRect(x, y, MINI_MAP_X, MINI_MAP_Y, mMiniMap->rect().w(), mMiniMap->rect().h()))
{
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));
......@@ -681,20 +624,6 @@ void EditorState::handleLeftButtonDown(int x, int y)
return;
}
// Check the tile palette.
if(mTilePalette.hidden() && isPointInRect(pt, mTilePalette.rect()))
{
showTilePalette();
return; // Ignore other click processing if the palette was clicked.
}
if(!mTilePalette.hidden() && isPointInRect(pt, mTilePalette.closeRect()))
{
hideTilePalette();
return; // Ignore other click processing if the palette was clicked.
}
// Avoid inserting tiles if we're in the 'toolbar area'
if (y < 32)
return;
......@@ -715,10 +644,6 @@ void EditorState::handleLeftButtonDown(int x, int y)
mPlacingCollision = true;
}
}
else if(isPointInRect(pt, mTilePalette.rect()))
{
mTilePalette.onMouseDown(BUTTON_LEFT, x, y);
}
else
{
saveUndo();
......@@ -850,31 +775,42 @@ void EditorState::patternErase(Cell::TileLayer layer)
}
/**
* Changes the edit mode and unhides the tile palette.
*/
void EditorState::showTilePalette()
{
mTilePalette.hidden(false);
}
/**
* Changes the edit mode and hides the tile palette.
*/
void EditorState::hideTilePalette()
{
mTilePalette.hidden(true);
}
void EditorState::toolbar_event(ToolBar::ToolBarAction _act, bool _b)
void EditorState::toolbar_event(ToolBar::ToolBarAction _act)
{
switch (_act)
{
case ToolBar::TOOLBAR_SAVE:
saveMap();
break;
case ToolBar::TOOLBAR_LAYER_BG_EDIT:
mEditState = STATE_BASE_TILE_INDEX;
break;
case ToolBar::TOOLBAR_LAYER_BG_DETAIL_EDIT:
mEditState = STATE_BASE_DETAIL_TILE_INDEX;
break;
case ToolBar::TOOLBAR_LAYER_DETAIL_EDIT:
mEditState = STATE_DETAIL_TILE_INDEX;
break;
case ToolBar::TOOLBAR_LAYER_FOREGROUND_EDIT:
mEditState = STATE_FOREGROUND_TILE_INDEX;
break;
case ToolBar::TOOLBAR_LAYER_COLLISION_EDIT:
mEditState = STATE_TILE_COLLISION;
break;
case ToolBar::TOOLBAR_LAYER_BG_TOGGLE:
case ToolBar::TOOLBAR_LAYER_BG_DETAIL_TOGGLE:
case ToolBar::TOOLBAR_LAYER_DETAIL_TOGGLE:
case ToolBar::TOOLBAR_LAYER_FOREGROUND_TOGGLE:
case ToolBar::TOOLBAR_LAYER_COLLISION_TOGGLE:
mMap.drawBg(mToolBar.show_bg());
mMap.drawBgDetail(mToolBar.show_bg_detail());
mMap.drawDetail(mToolBar.show_detail());
mMap.drawForeground(mToolBar.show_foreground());
mMap.drawCollision(mToolBar.show_collision());
if (mToolBar.show_collision())
mTilePalette.reset();
break;
default:
break;
......
......@@ -25,7 +25,6 @@ enum EditState
STATE_DETAIL_TILE_INDEX,
STATE_FOREGROUND_TILE_INDEX,
STATE_TILE_COLLISION,
STATE_TILE_ERASE,
STATE_MAP_LINK_EDIT
};
......@@ -87,9 +86,6 @@ private:
void patternStamp(Cell::TileLayer layer);
void patternErase(Cell::TileLayer layer);
void showTilePalette();
void hideTilePalette();
void handleLeftButtonDown(int x, int y);
void handleRightButtonDown();
void handleMiddleButtonDown();
......@@ -103,7 +99,7 @@ private:
void drawMiniMap();
void createMiniMap();
void toolbar_event(ToolBar::ToolBarAction _act, bool _b);
void toolbar_event(ToolBar::ToolBarAction _act);
private:
......
......@@ -19,7 +19,8 @@ const int EDGE_MARGIN = 10;
*/
Map::Map(const string& mapPath): mField(0, 0),
mViewport(0, 0, static_cast<int>(Utility<Renderer>::get().width()), static_cast<int>(Utility<Renderer>::get().height())),
mCameraFocus(NULL),
mCameraFocus(nullptr),
mDrawBg(true),
mDrawBgDetail(true),
mDrawDetail(true),
mDrawForeground(true),
......@@ -40,7 +41,8 @@ Map::Map(const string& name, const string& tsetPath, int width, int height): mNa
mTileset(tsetPath, CELL_DIMENSIONS.w(), CELL_DIMENSIONS.h()),
mViewport(0, 0, static_cast<int>(Utility<Renderer>::get().width()), static_cast<int>(Utility<Renderer>::get().height())),
mCameraSpace(0, 0, mField.width() * mTileset.width() - mViewport.w(), mField.height() * mTileset.height() - mViewport.h()),
mCameraFocus(NULL),
mCameraFocus(nullptr),
mDrawBg(true),
mDrawBgDetail(true),
mDrawDetail(true),
mDrawForeground(true),
......@@ -48,18 +50,14 @@ Map::Map(const string& name, const string& tsetPath, int width, int height): mNa
mShowLinks(false),
mShowTitlePlaque(false),
mEdgeExit(false)
{
//cout << mViewport.x << " " << mViewport.h << " " << mCameraSpace.w << " " << mCameraSpace.h << endl;
}
{}
/**
* D'tor
*/
Map::~Map()
{
//std::cout << "Map d'tor: " << mName << endl;
}
{}
/**
......@@ -139,6 +137,12 @@ void Map::showLinks(bool show)
}
void Map::drawBg(bool draw)
{
mDrawBg = draw;
}
void Map::drawBgDetail(bool draw)
{
mDrawBgDetail = draw;
......@@ -157,33 +161,6 @@ void Map::drawForeground(bool draw)
}
/**
* Toggles visibility of the Base Detail layer.
*/
void Map::toggleBgDetail()
{
flipBool(mDrawBgDetail);
}
/**
* Toggles visibility of the Detail layer.
*/
void Map::toggleDetail()
{
flipBool(mDrawDetail);
}
/**
* Toggles visibility of the Foreground layer.
*/
void Map::toggleForeground()
{
flipBool(mDrawForeground);
}
void Map::cameraFocus(Entity* entity)
{
mCameraFocus = entity;
......@@ -358,7 +335,7 @@ 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();
if (cell.index(Cell::LAYER_BASE) >= 0)
if (mDrawBg && cell.index(Cell::LAYER_BASE) >= 0)
mTileset.drawTile(cell.index(Cell::LAYER_BASE), rasterX, rasterY);
if(mDrawBgDetail && cell.index(Cell::LAYER_BASE_DETAIL) >= 0)
......
......@@ -53,9 +53,6 @@ public:
void dump(const std::string& filePath);
void drawCollision(bool draw);
void showLinks(bool show);
void viewport(const Rectangle_2d& _r);
const Rectangle_2d viewport() const { return mViewport; }
......@@ -81,13 +78,13 @@ protected:
friend class EditorState;
void drawBg(bool draw);
void drawBgDetail(bool draw);
void drawDetail(bool draw);
void drawForeground(bool draw);
void drawCollision(bool draw);
void toggleBgDetail();
void toggleDetail();
void toggleForeground();
void showLinks(bool show);
GameField& field() { return mField; }
void field(const GameField& field) { mField = field; }
......@@ -132,6 +129,7 @@ private:
EntityPtrList mEntityList;
bool mDrawBg; /**< Flag indicating that the background layer should be drawn. */
bool mDrawBgDetail; /**< Flag indicating that the background detail layer should be drawn. */
bool mDrawDetail; /**< Flag indicating that the detail layer should be drawn. */
bool mDrawForeground; /**< Flag indicating that the foreground layer should be drawn. */
......
......@@ -4,36 +4,44 @@
#include "Common.h"
const Point_2d PALETTE_DIMENSIONS = Point_2d(196, 320);
const Point_2d PALETTE_DIMENSIONS = Point_2d(196, 315);
const Point_2d FIRST_TILE_COORDINATE = Point_2d(2, 18);
const Point_2d TILE_SLOT_PADDING = Point_2d(0, 0);
const Point_2d TILE_GRID_DIMENSIONS = Point_2d(6, 8);
const Point_2d CLOSE_BOX_DIMENSIONS = Point_2d(12, 12);
const int NUM_TILES_PER_PAGE = TILE_GRID_DIMENSIONS.x() * TILE_GRID_DIMENSIONS.y();
const int HIDE_HEIGHT = 15;
/**
* C'Tor
*/
TilePalette::TilePalette(): mFont(nullptr),
mTset(nullptr),
mRect(Utility<Renderer>::get().width() - PALETTE_DIMENSIONS.x(), Utility<Renderer>::get().height() - HIDE_HEIGHT, PALETTE_DIMENSIONS.x(), PALETTE_DIMENSIONS.y()),
mCloseRect(mRect.x() + mRect.w() - (CLOSE_BOX_DIMENSIONS.x() + 2), mRect.y() + 2, CLOSE_BOX_DIMENSIONS.x(), CLOSE_BOX_DIMENSIONS.y()),
mShow(Utility<Configuration>::get().option(CONFIG_UI_TILEPALETTE_SHOW_IMAGE)),
mHide(Utility<Configuration>::get().option(CONFIG_UI_TILEPALETTE_DOWN_IMAGE)),
mRect(Utility<Renderer>::get().screenCenterX() - PALETTE_DIMENSIONS.x() / 2, 125, PALETTE_DIMENSIONS.x(), PALETTE_DIMENSIONS.y()),
mNumPages(0),
mCurrentPage(0),
mTsetIndex(0),
mHidden(true),
mHidden(false),
mLeftButtonDown(false),
mMouseOverTiles(false)
mMouseOverTiles(false),
mDragging(false)
{
init();
}
TilePalette::~TilePalette()
{
int yPosition = Utility<Renderer>::get().height() - PALETTE_DIMENSIONS.y() + 295;
EventHandler& e = Utility<EventHandler>::get();
e.mouseButtonDown().Disconnect(this, &TilePalette::onMouseDown);
e.mouseButtonUp().Disconnect(this, &TilePalette::onMouseUp);
e.mouseMotion().Disconnect(this, &TilePalette::onMouseMove);
}
void TilePalette::init()
{
int yPosition = rect().y() + rect().h() - 25;
mBtnPrev.size(30, 20);
mBtnPrev.position(mRect.x() + 2, yPosition);
......@@ -44,6 +52,12 @@ TilePalette::TilePalette(): mFont(nullptr),
mBtnNext.position(mRect.x() + mRect.w() - (mBtnNext.width() + 2), yPosition);
mBtnNext.image(Utility<Configuration>::get().option(CONFIG_UI_TILEPALETTE_NEXT_IMAGE));
mBtnNext.click().Connect(this, &TilePalette::button_Next_click);
// Hook events
EventHandler& e = Utility<EventHandler>::get();
e.mouseButtonDown().Connect(this, &TilePalette::onMouseDown);
e.mouseButtonUp().Connect(this, &TilePalette::onMouseUp);
e.mouseMotion().Connect(this, &TilePalette::onMouseMove);
}
......@@ -87,18 +101,17 @@ void TilePalette::tileset(Tileset* tset)
mNumPages = divideUp(mTset->numTiles(), NUM_TILES_PER_PAGE);
mSlots.clear();
mSlots.resize(TILE_GRID_DIMENSIONS.y());
for(int row = 0; row < TILE_GRID_DIMENSIONS.y(); row++)
{
for(int col = 0; col < TILE_GRID_DIMENSIONS.x(); col++)
{
mSlots[row].push_back(Rectangle_2d(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()) + Utility<Renderer>::get().height() - PALETTE_DIMENSIONS.y(), mTset->width(), mTset->height()));
mSlots[row].push_back(Rectangle_2d(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()) + rect().y(), mTset->width(), mTset->height()));
}
}
mTileGridRect = Rectangle_2d(mRect.x() + FIRST_TILE_COORDINATE.x(), mRect.y() + FIRST_TILE_COORDINATE.y(), TILE_GRID_DIMENSIONS.x() * mTset->width(), TILE_GRID_DIMENSIONS.y() * mTset->height());
mTileGridRect(mRect.x() + FIRST_TILE_COORDINATE.x(), mRect.y() + FIRST_TILE_COORDINATE.y(), TILE_GRID_DIMENSIONS.x() * mTset->width(), TILE_GRID_DIMENSIONS.y() * mTset->height());
}
......@@ -114,17 +127,6 @@ void TilePalette::hidden(bool hidden)
return;
mHidden = hidden;
Renderer& r = Utility<Renderer>::get();
// Adjust TilePalette area rect depending on whether or not it's hidden.
if(mHidden)
mRect = Rectangle_2d(r.width() - PALETTE_DIMENSIONS.x(), r.height() - HIDE_HEIGHT, PALETTE_DIMENSIONS.x(), PALETTE_DIMENSIONS.y());
else
mRect = Rectangle_2d(r.width() - PALETTE_DIMENSIONS.x(), r.height() - PALETTE_DIMENSIONS.y(), PALETTE_DIMENSIONS.x(), PALETTE_DIMENSIONS.y());
mCloseRect = Rectangle_2d(mRect.x() + mRect.w() - (CLOSE_BOX_DIMENSIONS.x() + 2), mRect.y() + 2, CLOSE_BOX_DIMENSIONS.x(), CLOSE_BOX_DIMENSIONS.y());
mTileGridRect = Rectangle_2d(mRect.x() + FIRST_TILE_COORDINATE.x(), mRect.y() + FIRST_TILE_COORDINATE.y(), TILE_GRID_DIMENSIONS.x() * mTset->width(), TILE_GRID_DIMENSIONS.y() * mTset->height());
}
......@@ -133,13 +135,15 @@ void TilePalette::hidden(bool hidden)
*/
void TilePalette::update()
{
if (hidden())
return;
Renderer& r = Utility<Renderer>::get();
if(mHidden || !mTset)
if(!mTset)
{
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.drawImage(mShow, mRect.x() + mRect.w() - mShow.width() - 1, mRect.y() + 1);
if(mFont)
r.drawTextShadow(*mFont, "Tile Palette", mRect.x() + 2, mRect.y(), 1, 255, 255, 255, 0, 0, 0);
......@@ -151,9 +155,6 @@ void TilePalette::update()
r.drawBox(mRect, 0, 0, 0, 100);
r.drawBoxFilled(mRect.x(), mRect.y(), mRect.w(), mRect.h(), 200, 200, 0, 65);
// Draw the close button
r.drawImage(mHide, mRect.x() + mRect.w() - mHide.width() - 1, mRect.y() + 1);
// Draw buttons
mBtnPrev.update();
mBtnNext.update();
......@@ -201,6 +202,26 @@ void TilePalette::onMouseMove(int x, int y, int relX, int relY)
if(hidden())
return;
if (mDragging)
{
mRect.x(mRect.x() + relX);
mRect.y(mRect.y() + relY);
mBtnPrev.position(mBtnPrev.positionX() + relX, mBtnPrev.positionY() + relY);
mBtnNext.position(mBtnNext.positionX() + relX, mBtnNext.positionY() + relY);
for (size_t row = 0; row < mSlots.size(); ++row)
{
for (size_t col = 0; col < mSlots[row].size(); ++col)
{
mSlots[row][col].x(mSlots[row][col].x() + relX);
mSlots[row][col].y(mSlots[row][col].y() + relY);
}
}
return;
}
mMouseCoords(x, y);
if(isPointInRect(mMouseCoords, mTileGridRect))
......@@ -212,12 +233,17 @@ void TilePalette::onMouseMove(int x, int y, int relX, int relY)
void TilePalette::onMouseDown(MouseButton button, int x, int y)
{
if(hidden())
if(hidden() || (button != BUTTON_LEFT))
return;
// ????? Will always be true regardless of which button is actually pushed.
mLeftButtonDown = true;
if (isPointInRect(x, y, rect().x(), rect().y(), rect().w(), 17))
{
mDragging = true;
return;
}
Point_2d pt(x, y);
mDragOrigin = pt;
......@@ -249,7 +275,7 @@ void TilePalette::onMouseDown(MouseButton button, int x, int y)
void TilePalette::onMouseUp(MouseButton button, int x, int y)
{
if(hidden())
if (hidden() || mSlots.empty() || (button != BUTTON_LEFT))
return;
Point_2d pt(x, y);
......@@ -273,7 +299,20 @@ void TilePalette::onMouseUp(MouseButton button, int x, int y)
}
}
mLeftButtonDown = false;
mDragging = false;
mLeftButtonDown = !(button == BUTTON_LEFT);
}
/**
* Determine a pattern using two selected points.
*/
void TilePalette::reset()
{
mTsetIndex = 0;
mCurrentPage = 0;
mBrushPattern.size(1, 1);
}
......
......@@ -25,6 +25,7 @@ class TilePalette
{
public:
TilePalette();
~TilePalette();
// Sets the internal tileset pointer.
void tileset(Tileset* tset);
......@@ -39,18 +40,17 @@ public:
const Pattern& pattern() const { return mBrushPattern; }
const Rectangle_2d& rect() const { return mRect; }
const Rectangle_2d& closeRect() const { return mCloseRect; }
int index() const { return mTsetIndex; }
void onMouseDown(MouseButton button, int x, int y);
void onMouseUp(MouseButton button, int x, int y);
void reset();
void onMouseMove(int x, int y, int relX, int relY);
bool dragging() const { return mDragging; }
private:
typedef std::vector<std::vector<Rectangle_2d> > RectList;
void init();
void button_Prev_click();
void button_Next_click();
......@@ -59,13 +59,16 @@ private:
Rectangle_2d getRectFromPoints(const Point_2d& pt1, const Point_2d& pt2);
void onMouseDown(MouseButton button, int x, int y);
void onMouseUp(MouseButton button, int x, int y);
void onMouseMove(int x, int y, int relX, int relY);
private:
Font* mFont; /**< Font to use to draw basic information. */
Tileset* mTset; /**< Pointer to a Tileset. TilePalette does not own this Tileset object. */
Rectangle_2d mRect; /**< Area and position of the palette. */
Rectangle_2d mCloseRect; /**< Area of the 'close button' */
Rectangle_2d mTileGridRect; /**< Area that the tiles are over. */
RectList mSlots; /**< List of rectangles for each slot. */
......@@ -73,9 +76,6 @@ private:
Button mBtnPrev; /**< */
Button mBtnNext; /**< */
Image mShow; /**< Displayed in the title area when the palette is hidden. */
Image mHide; /**< Displayed in the title area when the palette is not hidden. */
Pattern mBrushPattern; /**< Brush pattern for stamp and pattern floods. */
int mNumPages; /**< Number of pages the palette needs to show. */
......@@ -91,5 +91,5 @@ private:
bool mHidden; /**< Flag indicating that the palette shouldn't be drawn. */
bool mLeftButtonDown; /**< Flag indicating that the left mouse button is depressed. */
bool mMouseOverTiles; /**< Flag indicating that the mouse is actually over the tiles. */
bool mDragging; /**< Flag indicating that the tile palette is being dragged from its title bar. */
};
......@@ -94,30 +94,35 @@ void ToolBar::initUi()
btnLayerBaseToggle.toggle(true);
btnLayerBaseToggle.size(22, 28);
btnLayerBaseToggle.position(btnLayerCollision.positionX() + btnLayerCollision.width() + 18 + BUTTON_SPACE, 2);
btnLayerBaseToggle.click().Connect(this, &ToolBar::btnLayerBaseToggle_Clicked);
btnLayerBaseDetailToggle.image("sys/layer_bd_show.png");
btnLayerBaseDetailToggle.type(Button::BUTTON_TOGGLE);
btnLayerBaseDetailToggle.toggle(true);
btnLayerBaseDetailToggle.size(22, 28);
btnLayerBaseDetailToggle.position(btnLayerBaseToggle.positionX() + btnLayerBaseToggle.width() + BUTTON_SPACE, 2);
btnLayerBaseDetailToggle.click().Connect(this, &ToolBar::btnLayerBaseDetailToggle_Clicked);
btnLayerDetailToggle.image("sys/layer_d_show.png");
btnLayerDetailToggle.type(Button::BUTTON_TOGGLE);
btnLayerDetailToggle.toggle(true);
btnLayerDetailToggle.size(22, 28);
btnLayerDetailToggle.position(btnLayerBaseDetailToggle.positionX() + btnLayerBaseDetailToggle.width() + BUTTON_SPACE, 2);
btnLayerDetailToggle.click().Connect(this, &ToolBar::btnLayerDetailToggle_Clicked);
btnLayerForegroundToggle.image("sys/layer_fg_show.png");
btnLayerForegroundToggle.type(Button::BUTTON_TOGGLE);
btnLayerForegroundToggle.toggle(true);
btnLayerForegroundToggle.size(22, 28);
btnLayerForegroundToggle.position(btnLayerDetailToggle.positionX() + btnLayerDetailToggle.width() + BUTTON_SPACE, 2);
btnLayerForegroundToggle.click().Connect(this, &ToolBar::btnLayerForegroundToggle_Clicked);
btnLayerCollisionToggle.image("sys/collision_show.png");
btnLayerCollisionToggle.type(Button::BUTTON_TOGGLE);
btnLayerCollisionToggle.toggle(false);
btnLayerCollisionToggle.size(22, 28);
btnLayerCollisionToggle.position(btnLayerForegroundToggle.positionX() + btnLayerForegroundToggle.width() + BUTTON_SPACE, 2);
btnLayerCollisionToggle.click().Connect(this, &ToolBar::btnLayerCollisionToggle_Clicked);
hookEvents();
}
......@@ -165,6 +170,17 @@ void ToolBar::update()
}
void ToolBar::resetTools()
{
btnLayerCollisionToggle.toggle(false);
btnLayerCollisionToggle.enabled(true);
btnLayerBaseDetailToggle_Clicked();
btnFill.enabled(true);
btnErase.enabled(true);
}
void ToolBar::btnLayerBase_Clicked()
{
btnLayerBase.toggle(true);
......@@ -172,6 +188,10 @@ void ToolBar::btnLayerBase_Clicked()
btnLayerDetail.toggle(false);
btnLayerForeground.toggle(false);
btnLayerCollision.toggle(false);
resetTools();
mToolbarEvent(TOOLBAR_LAYER_BG_EDIT);
}
......@@ -182,6 +202,10 @@ void ToolBar::btnLayerBaseDetail_Clicked()
btnLayerDetail.toggle(false);
btnLayerForeground.toggle(false);
btnLayerCollision.toggle(false);