From ad3646cb1504707e7ef763caaba47c20b631ce3f Mon Sep 17 00:00:00 2001 From: Emanuel Guevel Date: Tue, 13 Aug 2013 04:57:45 +0200 Subject: [PATCH] Fix spell icons displayed when effect ended --- apps/openmw/mwgui/spellicons.cpp | 95 +++++++++++++++++--------------- 1 file changed, 52 insertions(+), 43 deletions(-) diff --git a/apps/openmw/mwgui/spellicons.cpp b/apps/openmw/mwgui/spellicons.cpp index 5e7ed498d3..9812c0f8a9 100644 --- a/apps/openmw/mwgui/spellicons.cpp +++ b/apps/openmw/mwgui/spellicons.cpp @@ -129,48 +129,17 @@ namespace MWGui effectInfo.mMagnitude = static_cast (0.05*it->second.second / (0.1 * magicEffect->mData.mBaseCost)); } - effects[effectIt->mEffectID].push_back (effectInfo); } } int w=2; - if (adjustSize) - { - int s = effects.size() * 16+4; - if (effects.empty()) - s = 0; - int diff = parent->getWidth() - s; - parent->setSize(s, parent->getHeight()); - parent->setPosition(parent->getLeft()+diff, parent->getTop()); - } - - for (std::map >::const_iterator it = effects.begin(); it != effects.end(); ++it) { - MyGUI::ImageBox* image; - if (mWidgetMap.find(it->first) == mWidgetMap.end()) - image = parent->createWidget - ("ImageBox", MyGUI::IntCoord(w,2,16,16), MyGUI::Align::Default); - else - image = mWidgetMap[it->first]; - mWidgetMap[it->first] = image; - image->setPosition(w,2); - image->setVisible(true); - const ESM::MagicEffect* effect = MWBase::Environment::get().getWorld ()->getStore ().get().find(it->first); - std::string icon = effect->mIcon; - icon[icon.size()-3] = 'd'; - icon[icon.size()-2] = 'd'; - icon[icon.size()-1] = 's'; - icon = "icons\\" + icon; - - image->setImageTexture(icon); - w += 16; - float remainingDuration = 0; std::string sourcesDescription; @@ -210,20 +179,61 @@ namespace MWGui } } - std::string name = ESM::MagicEffect::effectIdToString (it->first); + if (remainingDuration > 0.f) + { + MyGUI::ImageBox* image; + if (mWidgetMap.find(it->first) == mWidgetMap.end()) + { + image = parent->createWidget + ("ImageBox", MyGUI::IntCoord(w,2,16,16), MyGUI::Align::Default); + mWidgetMap[it->first] = image; - ToolTipInfo tooltipInfo; - tooltipInfo.caption = "#{" + name + "}"; - tooltipInfo.icon = effect->mIcon; - tooltipInfo.text = sourcesDescription; - tooltipInfo.imageSize = 16; - tooltipInfo.wordWrap = false; + std::string icon = effect->mIcon; + icon[icon.size()-3] = 'd'; + icon[icon.size()-2] = 'd'; + icon[icon.size()-1] = 's'; + icon = "icons\\" + icon; - image->setUserData(tooltipInfo); - image->setUserString("ToolTipType", "ToolTipInfo"); + image->setImageTexture(icon); - // Fade out during the last 5 seconds - image->setAlpha(std::min(remainingDuration/fadeTime, 1.f)); + std::string name = ESM::MagicEffect::effectIdToString (it->first); + + ToolTipInfo tooltipInfo; + tooltipInfo.caption = "#{" + name + "}"; + tooltipInfo.icon = effect->mIcon; + tooltipInfo.imageSize = 16; + tooltipInfo.wordWrap = false; + + image->setUserData(tooltipInfo); + image->setUserString("ToolTipType", "ToolTipInfo"); + } + else + image = mWidgetMap[it->first]; + + image->setPosition(w,2); + image->setVisible(true); + w += 16; + + ToolTipInfo* tooltipInfo = image->getUserData(); + tooltipInfo->text = sourcesDescription; + + // Fade out during the last 5 seconds + image->setAlpha(std::min(remainingDuration/fadeTime, 1.f)); + } + else if (mWidgetMap.find(it->first) != mWidgetMap.end()) + { + mWidgetMap[it->first]->setVisible(false); + } + } + + if (adjustSize) + { + int s = w + 2; + if (effects.empty()) + s = 0; + int diff = parent->getWidth() - s; + parent->setSize(s, parent->getHeight()); + parent->setPosition(parent->getLeft()+diff, parent->getTop()); } // hide inactive effects @@ -232,7 +242,6 @@ namespace MWGui if (effects.find(it->first) == effects.end()) it->second->setVisible(false); } - }