From 07695342c34783fcd7a9f25d46a19a016185b8fd Mon Sep 17 00:00:00 2001 From: martinstarman Date: Sat, 4 Apr 2026 09:48:01 +0200 Subject: [PATCH] feat: entity tooltip --- example/example.toml | 2 ++ src/entity.cpp | 5 +++++ src/entity.h | 6 ++++++ src/game.cpp | 18 ++++++++++++++++++ src/game.h | 1 + src/main.cpp | 2 ++ 6 files changed, 34 insertions(+) diff --git a/example/example.toml b/example/example.toml index 59e0d0b..421a6c1 100644 --- a/example/example.toml +++ b/example/example.toml @@ -44,6 +44,7 @@ Path = "textures/sand.png" DefaultOctant = "East" DefaultPosition = [150.0, 150.0] DrawingLayer = 1 +Name = "Entity #1" Shape = [[-32.0, -32.0], [-32.0, 32.0], [32.0, 32.0], [32.0, -32.0]] [Entities.EntityTexture] @@ -59,6 +60,7 @@ TracesPerSecond = 3 DefaultOctant = "NorthWest" DefaultPosition = [300.0, 150.0] DrawingLayer = 1 +Name = "Entity #2" Shape = [[-32.0, -32.0], [-32.0, 32.0], [32.0, 32.0], [32.0, -32.0]] [Entities.EntityTexture] diff --git a/src/entity.cpp b/src/entity.cpp index 9b551aa..73ad518 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -83,6 +83,11 @@ bool Entity::GetShowsTraces() return m_entityConfig.showsTraces; } +const std::string &Entity::GetName() +{ + return m_entityConfig.name; +} + bool Entity::IsMoving() { return m_path.size() > 0; diff --git a/src/entity.h b/src/entity.h index a4820a8..2568e04 100644 --- a/src/entity.h +++ b/src/entity.h @@ -20,6 +20,7 @@ struct EntityConfig std::vector shape; bool showsTraces; Octant defaultOctant; + std::string name; }; struct EntityTextureConfig @@ -50,6 +51,8 @@ class Entity const EntityTextureConfig &entityTextureConfig, const TraceTextureConfig &traceTextureConfig); ~Entity(); + +public: int GetId(); int GetDrawingLayer(); float GetZIndex(); @@ -57,6 +60,9 @@ class Entity std::vector GetShape(); Vector2 GetPosition(); bool GetShowsTraces(); + const std::string &GetName(); + +public: bool IsMoving(); void SetSelected(bool selected); void SetPath(const std::vector &path); diff --git a/src/game.cpp b/src/game.cpp index 38e6226..7085531 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -54,6 +54,8 @@ void Game::Draw() } } + HandleEntityTooltip(); + EndMode2D(); EndDrawing(); } @@ -172,3 +174,19 @@ void Game::HandleEntityTraces() } } } + +void Game::HandleEntityTooltip() +{ + Vector2 mousePosition = GetMousePosition(); + + for (const auto &entity : m_entities) + { + std::vector shape = entity->GetShape(); + std::string name = entity->GetName(); + + if (CheckCollisionPointPoly(mousePosition, &shape[0], shape.size()) && name != "") + { + DrawText(name.c_str(), mousePosition.x, mousePosition.y, 10, DARKGRAY); + } + } +} diff --git a/src/game.h b/src/game.h index 993ecd7..4750201 100644 --- a/src/game.h +++ b/src/game.h @@ -27,4 +27,5 @@ class Game bool HandleEntitySelection(); void HandleEntityMovement(); void HandleEntityTraces(); + void HandleEntityTooltip(); }; diff --git a/src/main.cpp b/src/main.cpp index bcecdb4..499e7a3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -35,6 +35,7 @@ int main(int argc, char *argv[]) auto tomlDefaultPosition = toml::find>(tomlEntity, "DefaultPosition"); auto tomlDrawingLayer = toml::find(tomlEntity, "DrawingLayer"); auto tomlShowsTraces = toml::find_or(tomlEntity, "ShowsTraces", false); + auto tomlName = toml::find_or(tomlEntity, "Name", ""); auto tomlShape = toml::find>>(tomlEntity, "Shape"); auto tomlEntityTexture = toml::find(tomlEntity, "EntityTexture"); auto tomlTexturePath = mapFileDir / toml::find(tomlEntityTexture, "Path"); @@ -68,6 +69,7 @@ int main(int argc, char *argv[]) shape, tomlShowsTraces, GetOctantFrom(tomlDefaultOctant), + tomlName, }; EntityTextureConfig textureConfig = {