Skip to content

Commit

Permalink
Build menu buttons highlighting in mouse hovering (#1012) (#1024)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomoravec authored Feb 27, 2023
1 parent 3227b7c commit 52dac5c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
19 changes: 10 additions & 9 deletions src/engine/ResourcesManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,22 @@ void ResourcesManager::loadUITexture()
}
}

SDL_Texture *ResourcesManager::getUITexture(const std::string &uiElement)
SDL_Texture *ResourcesManager::getUITexture(const std::string &uiElement, const std::string& uiTextureType)
{
std::string texture = "Texture_Default";
if (m_uiTextureMap[uiElement].find(texture) != m_uiTextureMap[uiElement].end())
{
return m_uiTextureMap[uiElement].at(texture);
}
if (m_uiTextureMap[uiElement].find("Texture_Default") != m_uiTextureMap[uiElement].end())
if (m_uiTextureMap[uiElement].find(uiTextureType) != m_uiTextureMap[uiElement].end())
{
// If no texture is found, check if there's a default texture
return m_uiTextureMap[uiElement].at("Texture_Default");
return m_uiTextureMap[uiElement].at(uiTextureType);
}

throw UIError(TRACE_INFO "No texture found for " + uiElement);
}

SDL_Texture *ResourcesManager::getUITexture(const std::string &uiElement)
{
static const std::string defaultTextureType = "Texture_Default";
return getUITexture(uiElement, defaultTextureType);
}

SDL_Texture *ResourcesManager::getTileTexture(const std::string &id)
{
if (m_tileTextureMap.find(id) != m_tileTextureMap.end())
Expand Down
5 changes: 4 additions & 1 deletion src/engine/ResourcesManager.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ public:
ResourcesManager(ResourcesManager const &) = delete;
ResourcesManager &operator=(ResourcesManager const &) = delete;

/// retrieves texture for a tileID
/** Retrieves default texture for a tileID and type */
SDL_Texture *getUITexture(const std::string &uiElement, const std::string &uiTextureType);

/** Retrieves default texture for a tileID */
SDL_Texture *getUITexture(const std::string &uiElement);

/** Retrieves Color of a specific tileID at coordinates with the texture */
Expand Down
20 changes: 18 additions & 2 deletions src/game/ui/BuildMenu.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,25 @@ template <class Holder> void drawSubmenu(ImVec2 pos, float categoryOffset, const
menu->onClick(btn);
}

if (ui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && ui::GetHoveredTimer() > menu->getTooltipDelay())
if (ui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
{
ui::SetTooltip(btn->getId().c_str());
if (ui::GetHoveredTimer() > menu->getTooltipDelay())
{
ui::SetTooltip("%s", btn->getId().c_str());
}

if (deep == 0)
{
static const std::string textureHoveringTypeStr = "Texture_Hovering";
btn->m_tex = ResourcesManager::instance().getUITexture(btn->m_texstr, textureHoveringTypeStr);
}
}
else
{
if (deep == 0)
{
btn->m_tex = ResourcesManager::instance().getUITexture(btn->m_texstr);
}
}

// calc next subcategory position center
Expand Down

0 comments on commit 52dac5c

Please sign in to comment.