From 52dac5c58dd3eebef7b34cdc58b80d19b1eeeded Mon Sep 17 00:00:00 2001 From: M1NDOVERFL0W Date: Mon, 27 Feb 2023 02:52:06 +0000 Subject: [PATCH] Build menu buttons highlighting in mouse hovering (#1012) (#1024) --- src/engine/ResourcesManager.cxx | 19 ++++++++++--------- src/engine/ResourcesManager.hxx | 5 ++++- src/game/ui/BuildMenu.cxx | 20 ++++++++++++++++++-- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/engine/ResourcesManager.cxx b/src/engine/ResourcesManager.cxx index 3e70864985..e64a1b8363 100644 --- a/src/engine/ResourcesManager.cxx +++ b/src/engine/ResourcesManager.cxx @@ -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()) diff --git a/src/engine/ResourcesManager.hxx b/src/engine/ResourcesManager.hxx index 8f0828d6c7..c3b31bd9fc 100644 --- a/src/engine/ResourcesManager.hxx +++ b/src/engine/ResourcesManager.hxx @@ -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 */ diff --git a/src/game/ui/BuildMenu.cxx b/src/game/ui/BuildMenu.cxx index 796445e979..1ee366af26 100644 --- a/src/game/ui/BuildMenu.cxx +++ b/src/game/ui/BuildMenu.cxx @@ -137,9 +137,25 @@ template 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