Skip to content

Commit

Permalink
[CLT] fix(tilegrid): fix pointed tile evaluating
Browse files Browse the repository at this point in the history
  • Loading branch information
Insineer committed Oct 6, 2019
1 parent 1ab5b05 commit 7ad462a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
14 changes: 10 additions & 4 deletions OSS13 Client/Sources/Graphics/TileGrid/TileGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ void TileGrid::drawContainer() const {
uf::vec2i pixel = (uf::vec2i(fov) + rpos(tile->GetRelPos() - cameraRelPos).xy() - shift) * tileSize;
object->Draw(&buffer, pixel);
if (cursorPosition >= pixel && cursorPosition < pixel + uf::vec2i(tileSize)) {
underCursorTile = tile;
if (!object->PixelTransparent(cursorPosition - pixel))
underCursorObject = object;
}
Expand All @@ -103,7 +102,6 @@ void TileGrid::drawContainer() const {
}

buffer.display();

}

void TileGrid::SetSize(const uf::vec2i &size) {
Expand Down Expand Up @@ -136,13 +134,21 @@ bool TileGrid::OnMouseButtonPressed(sf::Mouse::Button button, uf::vec2i position
return false;
}

Tile *TileGrid::countTileUnderCursor(uf::vec2i mousePosition) {
auto coords = mousePosition / tileSize - uf::vec2i(shift) + uf::vec2i(Global::MIN_PADDING);
return GetTileRel(uf::vec3i(coords, cameraRelPos.z));
}

bool TileGrid::OnMouseMoved(uf::vec2i position) {
cursorPosition = position;
cursorPosition -= GetAbsolutePosition();
cursorPosition = uf::vec2f(cursorPosition) / GetScale().x;
if (cursorPosition <= GetSize()) return true;
else {
if (cursorPosition <= GetSize()) {
underCursorTile = countTileUnderCursor(cursorPosition);
return true;
} else {
cursorPosition = { -1, -1 };
underCursorTile = nullptr;
return false;
}
}
Expand Down
9 changes: 6 additions & 3 deletions OSS13 Client/Sources/Graphics/TileGrid/TileGrid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ class TileGrid : public Container {
std::unordered_map< uint, uptr<Object> > &GetObjects(); // TODO: remove this

protected:
void drawContainer() const override final;
void drawContainer() const override final;

private:
Tile *countTileUnderCursor(uf::vec2i mousePosition);

private:
uf::vec2i numOfTiles;
Expand Down Expand Up @@ -108,8 +111,8 @@ class TileGrid : public Container {
sf::Time stun;

uf::vec2i cursorPosition;
mutable Object *underCursorObject;
mutable Tile *underCursorTile;
mutable Object *underCursorObject{};
mutable Tile *underCursorTile{};

bool objectClicked;
bool rmbClicked{false};
Expand Down

0 comments on commit 7ad462a

Please sign in to comment.