mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-31 20:56:39 +00:00 
			
		
		
		
	potion effects in tooltip
This commit is contained in:
		
							parent
							
								
									b82c39c8be
								
							
						
					
					
						commit
						22f524f8d5
					
				
					 5 changed files with 84 additions and 40 deletions
				
			
		|  | @ -124,7 +124,7 @@ namespace MWClass | |||
|         text += "\n" + store.gameSettings.search("sWeight")->str + ": " + MWGui::ToolTips::toString(ref->base->data.weight); | ||||
|         text += MWGui::ToolTips::getValueString(ref->base->data.value, store.gameSettings.search("sValue")->str); | ||||
| 
 | ||||
|         ESM::EffectList list = ref->base->effects; | ||||
|         info.effects = &ref->base->effects; | ||||
| 
 | ||||
|         if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { | ||||
|             text += MWGui::ToolTips::getMiscString(ref->ref.owner, "Owner"); | ||||
|  |  | |||
|  | @ -202,7 +202,7 @@ void BirthDialog::updateSpells() | |||
| 
 | ||||
|                 MyGUI::IntCoord spellCoord = coord; | ||||
|                 spellCoord.height = 24; // TODO: This should be fetched from the skin somehow, or perhaps a widget in the layout as a template?
 | ||||
|                 spellWidget->createEffectWidgets(spellItems, spellArea, spellCoord, category); | ||||
|                 spellWidget->createEffectWidgets(spellItems, spellArea, spellCoord, (category == 0) ? MWEffectList::EF_Constant : 0); | ||||
|                 coord.top = spellCoord.top; | ||||
| 
 | ||||
|                 ++i; | ||||
|  |  | |||
|  | @ -225,6 +225,31 @@ IntSize ToolTips::createToolTip(const ToolTipInfo& info) | |||
|     IntSize totalSize = IntSize( std::max(textSize.width, captionSize.width + ((image != "") ? imageCaptionHPadding : 0)), | ||||
|         ((text != "") ? textSize.height + imageCaptionVPadding : 0) + captionHeight ); | ||||
| 
 | ||||
|     if (info.effects != 0) | ||||
|     { | ||||
|         Widget* effectArea = mDynamicToolTipBox->createWidget<Widget>("", | ||||
|             IntCoord(0, totalSize.height, 300, 300-totalSize.height), | ||||
|             Align::Stretch, "ToolTipEffectArea"); | ||||
| 
 | ||||
|         IntCoord coord(0, 6, totalSize.width, 24); | ||||
| 
 | ||||
|         /**
 | ||||
|          * \todo | ||||
|          * the various potion effects should appear in the tooltip depending if the player  | ||||
|          * has enough skill in alchemy to know about the effects of this potion. | ||||
|          */ | ||||
| 
 | ||||
|         Widgets::MWEffectListPtr effectsWidget = effectArea->createWidget<Widgets::MWEffectList> | ||||
|             ("MW_StatName", coord, Align::Default, "ToolTipEffectsWidget"); | ||||
|         effectsWidget->setWindowManager(mWindowManager); | ||||
|         effectsWidget->setEffectList(info.effects); | ||||
| 
 | ||||
|         std::vector<MyGUI::WidgetPtr> effectItems; | ||||
|         effectsWidget->createEffectWidgets(effectItems, effectArea, coord, true, Widgets::MWEffectList::EF_Potion); | ||||
|         totalSize.height += coord.top-6; | ||||
|         totalSize.width = std::max(totalSize.width, coord.width); | ||||
|     } | ||||
| 
 | ||||
|     if (info.enchant != "") | ||||
|     { | ||||
|         Widget* enchantArea = mDynamicToolTipBox->createWidget<Widget>("", | ||||
|  | @ -236,10 +261,11 @@ IntSize ToolTips::createToolTip(const ToolTipInfo& info) | |||
|         Widgets::MWEffectListPtr enchantWidget = enchantArea->createWidget<Widgets::MWEffectList> | ||||
|             ("MW_StatName", coord, Align::Default, "ToolTipEnchantWidget"); | ||||
|         enchantWidget->setWindowManager(mWindowManager); | ||||
|         enchantWidget->setEnchantmentId(info.enchant); | ||||
|         enchantWidget->setEffectList(&enchant->effects); | ||||
| 
 | ||||
|         std::vector<MyGUI::WidgetPtr> enchantEffectItems; | ||||
|         enchantWidget->createEffectWidgets(enchantEffectItems, enchantArea, coord, true, (enchant->data.type == ESM::Enchantment::ConstantEffect)); | ||||
|         int flag = (enchant->data.type == ESM::Enchantment::ConstantEffect) ? Widgets::MWEffectList::EF_Constant : 0; | ||||
|         enchantWidget->createEffectWidgets(enchantEffectItems, enchantArea, coord, true, flag); | ||||
|         totalSize.height += coord.top-6; | ||||
|         totalSize.width = std::max(totalSize.width, coord.width); | ||||
| 
 | ||||
|  |  | |||
|  | @ -222,7 +222,7 @@ void MWSpell::setSpellId(const std::string &spellId) | |||
|     updateWidgets(); | ||||
| } | ||||
| 
 | ||||
| void MWSpell::createEffectWidgets(std::vector<MyGUI::WidgetPtr> &effects, MyGUI::WidgetPtr creator, MyGUI::IntCoord &coord, const int category) | ||||
| void MWSpell::createEffectWidgets(std::vector<MyGUI::WidgetPtr> &effects, MyGUI::WidgetPtr creator, MyGUI::IntCoord &coord, int flags) | ||||
| { | ||||
|     const ESMS::ESMStore &store = mWindowManager->getStore(); | ||||
|     const ESM::Spell *spell = store.spells.search(id); | ||||
|  | @ -234,7 +234,7 @@ void MWSpell::createEffectWidgets(std::vector<MyGUI::WidgetPtr> &effects, MyGUI: | |||
|     { | ||||
|         effect = creator->createWidget<MWSpellEffect>("MW_EffectImage", coord, MyGUI::Align::Default); | ||||
|         effect->setWindowManager(mWindowManager); | ||||
|         effect->setConstant(category == 0); | ||||
|         effect->setFlags(flags); | ||||
|         effect->setSpellEffect(*it); | ||||
|         effects.push_back(effect); | ||||
|         coord.top += effect->getHeight(); | ||||
|  | @ -270,32 +270,29 @@ MWSpell::~MWSpell() | |||
| 
 | ||||
| MWEffectList::MWEffectList() | ||||
|     : mWindowManager(nullptr) | ||||
|     , mEffectList(0) | ||||
| { | ||||
| } | ||||
| 
 | ||||
| void MWEffectList::setEnchantmentId(const std::string &enchantId) | ||||
| void MWEffectList::setEffectList(const ESM::EffectList* list) | ||||
| { | ||||
|     id = enchantId; | ||||
|     mEffectList = list; | ||||
|     updateWidgets(); | ||||
| } | ||||
| 
 | ||||
| void MWEffectList::createEffectWidgets(std::vector<MyGUI::WidgetPtr> &effects, MyGUI::WidgetPtr creator, MyGUI::IntCoord &coord, bool center, bool constant) | ||||
| void MWEffectList::createEffectWidgets(std::vector<MyGUI::WidgetPtr> &effects, MyGUI::WidgetPtr creator, MyGUI::IntCoord &coord, bool center, int flags) | ||||
| { | ||||
|     const ESMS::ESMStore &store = mWindowManager->getStore(); | ||||
|     const ESM::Enchantment *enchant = store.enchants.search(id); | ||||
|     MYGUI_ASSERT(enchant, "enchantment with id '" << id << "' not found"); | ||||
| 
 | ||||
|     // We don't know the width of all the elements beforehand, so we do it in
 | ||||
|     // 2 steps: first, create all widgets and check their width
 | ||||
|     MWSpellEffectPtr effect = nullptr; | ||||
|     std::vector<ESM::ENAMstruct>::const_iterator end = enchant->effects.list.end(); | ||||
|     std::vector<ESM::ENAMstruct>::const_iterator end = mEffectList->list.end(); | ||||
|     int maxwidth = coord.width; | ||||
|     for (std::vector<ESM::ENAMstruct>::const_iterator it = enchant->effects.list.begin(); it != end; ++it) | ||||
|     for (std::vector<ESM::ENAMstruct>::const_iterator it = mEffectList->list.begin(); it != end; ++it) | ||||
|     { | ||||
|         effect = creator->createWidget<MWSpellEffect>("MW_EffectImage", coord, MyGUI::Align::Default); | ||||
|         effect->setWindowManager(mWindowManager); | ||||
|         effect->setFlags(flags); | ||||
|         effect->setSpellEffect(*it); | ||||
|         effect->setConstant(constant); | ||||
|         effects.push_back(effect); | ||||
| 
 | ||||
|         if (effect->getRequestedWidth() > maxwidth) | ||||
|  | @ -344,7 +341,7 @@ MWSpellEffect::MWSpellEffect() | |||
|     , imageWidget(nullptr) | ||||
|     , textWidget(nullptr) | ||||
|     , mRequestedWidth(0) | ||||
|     , mIsConstant(0) | ||||
|     , mFlags(0) | ||||
| { | ||||
| } | ||||
| 
 | ||||
|  | @ -359,6 +356,18 @@ void MWSpellEffect::updateWidgets() | |||
|     if (!mWindowManager) | ||||
|         return; | ||||
| 
 | ||||
|     // lists effects that have no magnitude (e.g. invisiblity)
 | ||||
|     /// \todo this list is probably incomplete
 | ||||
|     std::vector<std::string> effectsWithoutMagnitude; | ||||
|     effectsWithoutMagnitude.push_back("sEffectInvisibility"); | ||||
|     effectsWithoutMagnitude.push_back("sEffectStuntedMagicka"); | ||||
|     effectsWithoutMagnitude.push_back("sEffectParalyze"); | ||||
| 
 | ||||
|     // lists effects that have no duration (e.g. open lock)
 | ||||
|     /// \todo this list is probably incomplete
 | ||||
|     std::vector<std::string> effectsWithoutDuration; | ||||
|     effectsWithoutDuration.push_back("sEffectOpen"); | ||||
| 
 | ||||
|     const ESMS::ESMStore &store = mWindowManager->getStore(); | ||||
|     const ESM::MagicEffect *magicEffect = store.magicEffects.search(effect.effectID); | ||||
|     if (textWidget) | ||||
|  | @ -371,7 +380,8 @@ void MWSpellEffect::updateWidgets() | |||
|             std::string sec =  " " + mWindowManager->getGameSettingString("ssecond", ""); | ||||
|             std::string secs =  " " + mWindowManager->getGameSettingString("sseconds", ""); | ||||
| 
 | ||||
|             std::string spellLine = effectIDToString(effect.effectID); | ||||
|             std::string effectIDStr = effectIDToString(effect.effectID); | ||||
|             std::string spellLine = mWindowManager->getGameSettingString(effectIDStr, ""); | ||||
|             if (effect.skill >= 0 && effect.skill < ESM::Skill::Length) | ||||
|             { | ||||
|                 spellLine += " " + mWindowManager->getGameSettingString(ESM::Skill::sSkillNameIds[effect.skill], ""); | ||||
|  | @ -390,7 +400,9 @@ void MWSpellEffect::updateWidgets() | |||
|                 }; | ||||
|                 spellLine += " " + mWindowManager->getGameSettingString(attributes[effect.attribute], ""); | ||||
|             } | ||||
|             if (effect.magnMin >= 0 || effect.magnMax >= 0) | ||||
| 
 | ||||
|             bool hasMagnitude = (std::find(effectsWithoutMagnitude.begin(), effectsWithoutMagnitude.end(), effectIDStr) == effectsWithoutMagnitude.end()); | ||||
|             if ((effect.magnMin >= 0 || effect.magnMax >= 0) && hasMagnitude) | ||||
|             { | ||||
|                 if (effect.magnMin == effect.magnMax) | ||||
|                     spellLine += " " + boost::lexical_cast<std::string>(effect.magnMin) + " " + ((effect.magnMin == 1) ? pt : pts); | ||||
|  | @ -401,20 +413,25 @@ void MWSpellEffect::updateWidgets() | |||
|             } | ||||
| 
 | ||||
|             // constant effects have no duration and no target
 | ||||
|             if (!mIsConstant) | ||||
|             if (!(mFlags & MWEffectList::EF_Constant)) | ||||
|             { | ||||
|                 if (effect.duration >= 0) | ||||
|                 bool hasDuration = (std::find(effectsWithoutDuration.begin(), effectsWithoutDuration.end(), effectIDStr) == effectsWithoutDuration.end()); | ||||
|                 if (effect.duration >= 0 && hasDuration) | ||||
|                 { | ||||
|                     spellLine += " " + mWindowManager->getGameSettingString("sfor", "") + " " + boost::lexical_cast<std::string>(effect.duration) + ((effect.duration == 1) ? sec : secs); | ||||
|                 } | ||||
| 
 | ||||
|                 std::string on = mWindowManager->getGameSettingString("sonword", ""); | ||||
|                 if (effect.range == ESM::RT_Self) | ||||
|                     spellLine += " " + on + " " + mWindowManager->getGameSettingString("sRangeSelf", ""); | ||||
|                 else if (effect.range == ESM::RT_Touch) | ||||
|                     spellLine += " " + on + " " + mWindowManager->getGameSettingString("sRangeTouch", ""); | ||||
|                 else if (effect.range == ESM::RT_Target) | ||||
|                     spellLine += " " + on + " " + mWindowManager->getGameSettingString("sRangeTarget", ""); | ||||
|                 // potions have no target
 | ||||
|                 if (!(mFlags & MWEffectList::EF_Potion)) | ||||
|                 { | ||||
|                     std::string on = mWindowManager->getGameSettingString("sonword", ""); | ||||
|                     if (effect.range == ESM::RT_Self) | ||||
|                         spellLine += " " + on + " " + mWindowManager->getGameSettingString("sRangeSelf", ""); | ||||
|                     else if (effect.range == ESM::RT_Touch) | ||||
|                         spellLine += " " + on + " " + mWindowManager->getGameSettingString("sRangeTouch", ""); | ||||
|                     else if (effect.range == ESM::RT_Target) | ||||
|                         spellLine += " " + on + " " + mWindowManager->getGameSettingString("sRangeTarget", ""); | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             static_cast<MyGUI::TextBox*>(textWidget)->setCaption(spellLine); | ||||
|  | @ -574,11 +591,8 @@ std::string MWSpellEffect::effectIDToString(const short effectID) | |||
|     names[30] ="sEffectWeaknesstoShock"; | ||||
| 
 | ||||
|     assert(names.find(effectID) != names.end() && "Unimplemented effect type"); | ||||
|     std::string res = mWindowManager->getGameSettingString(names[effectID], ""); | ||||
|     if (res == "") | ||||
|         std::cout << "Warning: Unknown effect name " << names[effectID] << std::endl; | ||||
| 
 | ||||
|     return res; | ||||
|     return names[effectID]; | ||||
| } | ||||
| 
 | ||||
| MWSpellEffect::~MWSpellEffect() | ||||
|  |  | |||
|  | @ -153,19 +153,23 @@ namespace MWGui | |||
| 
 | ||||
|             typedef MWMechanics::Stat<int> EnchantmentValue; | ||||
| 
 | ||||
|             enum EffectFlags | ||||
|             { | ||||
|                 EF_Potion = 0x01, // potions have no target (target is always the player) 
 | ||||
|                 EF_Constant = 0x02 // constant effect means that duration will not be displayed
 | ||||
|             }; | ||||
| 
 | ||||
|             void setWindowManager(WindowManager* parWindowManager) { mWindowManager = parWindowManager; } | ||||
|             void setEnchantmentId(const std::string &enchantId); | ||||
|             void setEffectList(const ESM::EffectList* list); | ||||
| 
 | ||||
|             /**
 | ||||
|              * @param vector to store the created effect widgets | ||||
|              * @param parent widget | ||||
|              * @param coordinates to use, will be expanded if more space is needed | ||||
|              * @param center the effect widgets horizontally | ||||
|              * @param are the effects of this enchantment constant? | ||||
|              * @param various flags, see MWEffectList::EffectFlags | ||||
|              */ | ||||
|             void createEffectWidgets(std::vector<MyGUI::WidgetPtr> &effects, MyGUI::WidgetPtr creator, MyGUI::IntCoord &coord, bool center, bool constant); | ||||
| 
 | ||||
|             const std::string &getSpellId() const { return id; } | ||||
|             void createEffectWidgets(std::vector<MyGUI::WidgetPtr> &effects, MyGUI::WidgetPtr creator, MyGUI::IntCoord &coord, bool center, int flags); | ||||
| 
 | ||||
|         protected: | ||||
|             virtual ~MWEffectList(); | ||||
|  | @ -176,7 +180,7 @@ namespace MWGui | |||
|             void updateWidgets(); | ||||
| 
 | ||||
|             WindowManager* mWindowManager; | ||||
|             std::string id; | ||||
|             const ESM::EffectList* mEffectList; | ||||
|         }; | ||||
|         typedef MWEffectList* MWEffectListPtr; | ||||
| 
 | ||||
|  | @ -190,7 +194,7 @@ namespace MWGui | |||
| 
 | ||||
|             void setWindowManager(WindowManager* parWindowManager) { mWindowManager = parWindowManager; } | ||||
|             void setSpellEffect(SpellEffectValue value); | ||||
|             void setConstant(bool constant) { mIsConstant = constant; } | ||||
|             void setFlags(int flags) { mFlags = flags; } | ||||
| 
 | ||||
|             std::string effectIDToString(const short effectID); | ||||
| 
 | ||||
|  | @ -209,7 +213,7 @@ namespace MWGui | |||
| 
 | ||||
|             WindowManager* mWindowManager; | ||||
|             SpellEffectValue effect; | ||||
|             bool mIsConstant; // constant effect
 | ||||
|             int mFlags; | ||||
|             MyGUI::ImageBox* imageWidget; | ||||
|             MyGUI::TextBox* textWidget; | ||||
|             int mRequestedWidth; | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue