Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions example/example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down
5 changes: 5 additions & 0 deletions src/entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct EntityConfig
std::vector<Vector2> shape;
bool showsTraces;
Octant defaultOctant;
std::string name;
};

struct EntityTextureConfig
Expand Down Expand Up @@ -50,13 +51,18 @@ class Entity
const EntityTextureConfig &entityTextureConfig,
const TraceTextureConfig &traceTextureConfig);
~Entity();

public:
int GetId();
int GetDrawingLayer();
float GetZIndex();
bool GetSelected();
std::vector<Vector2> GetShape();
Vector2 GetPosition();
bool GetShowsTraces();
const std::string &GetName();

public:
bool IsMoving();
void SetSelected(bool selected);
void SetPath(const std::vector<Vector2> &path);
Expand Down
18 changes: 18 additions & 0 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ void Game::Draw()
}
}

HandleEntityTooltip();

EndMode2D();
EndDrawing();
}
Expand Down Expand Up @@ -172,3 +174,19 @@ void Game::HandleEntityTraces()
}
}
}

void Game::HandleEntityTooltip()
{
Vector2 mousePosition = GetMousePosition();

for (const auto &entity : m_entities)
{
std::vector<Vector2> 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);
}
}
}
1 change: 1 addition & 0 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ class Game
bool HandleEntitySelection();
void HandleEntityMovement();
void HandleEntityTraces();
void HandleEntityTooltip();
};
2 changes: 2 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ int main(int argc, char *argv[])
auto tomlDefaultPosition = toml::find<std::vector<float>>(tomlEntity, "DefaultPosition");
auto tomlDrawingLayer = toml::find<int>(tomlEntity, "DrawingLayer");
auto tomlShowsTraces = toml::find_or<bool>(tomlEntity, "ShowsTraces", false);
auto tomlName = toml::find_or<std::string>(tomlEntity, "Name", "");
auto tomlShape = toml::find<std::vector<std::vector<float>>>(tomlEntity, "Shape");
auto tomlEntityTexture = toml::find<toml::value>(tomlEntity, "EntityTexture");
auto tomlTexturePath = mapFileDir / toml::find<std::string>(tomlEntityTexture, "Path");
Expand Down Expand Up @@ -68,6 +69,7 @@ int main(int argc, char *argv[])
shape,
tomlShowsTraces,
GetOctantFrom(tomlDefaultOctant),
tomlName,
};

EntityTextureConfig textureConfig = {
Expand Down