mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-02 07:45:35 +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 += "\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);
|
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()) {
|
if (MWBase::Environment::get().getWindowManager()->getFullHelp()) {
|
||||||
text += MWGui::ToolTips::getMiscString(ref->ref.owner, "Owner");
|
text += MWGui::ToolTips::getMiscString(ref->ref.owner, "Owner");
|
||||||
|
|
|
@ -202,7 +202,7 @@ void BirthDialog::updateSpells()
|
||||||
|
|
||||||
MyGUI::IntCoord spellCoord = coord;
|
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?
|
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;
|
coord.top = spellCoord.top;
|
||||||
|
|
||||||
++i;
|
++i;
|
||||||
|
|
|
@ -225,6 +225,31 @@ IntSize ToolTips::createToolTip(const ToolTipInfo& info)
|
||||||
IntSize totalSize = IntSize( std::max(textSize.width, captionSize.width + ((image != "") ? imageCaptionHPadding : 0)),
|
IntSize totalSize = IntSize( std::max(textSize.width, captionSize.width + ((image != "") ? imageCaptionHPadding : 0)),
|
||||||
((text != "") ? textSize.height + imageCaptionVPadding : 0) + captionHeight );
|
((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 != "")
|
if (info.enchant != "")
|
||||||
{
|
{
|
||||||
Widget* enchantArea = mDynamicToolTipBox->createWidget<Widget>("",
|
Widget* enchantArea = mDynamicToolTipBox->createWidget<Widget>("",
|
||||||
|
@ -236,10 +261,11 @@ IntSize ToolTips::createToolTip(const ToolTipInfo& info)
|
||||||
Widgets::MWEffectListPtr enchantWidget = enchantArea->createWidget<Widgets::MWEffectList>
|
Widgets::MWEffectListPtr enchantWidget = enchantArea->createWidget<Widgets::MWEffectList>
|
||||||
("MW_StatName", coord, Align::Default, "ToolTipEnchantWidget");
|
("MW_StatName", coord, Align::Default, "ToolTipEnchantWidget");
|
||||||
enchantWidget->setWindowManager(mWindowManager);
|
enchantWidget->setWindowManager(mWindowManager);
|
||||||
enchantWidget->setEnchantmentId(info.enchant);
|
enchantWidget->setEffectList(&enchant->effects);
|
||||||
|
|
||||||
std::vector<MyGUI::WidgetPtr> enchantEffectItems;
|
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.height += coord.top-6;
|
||||||
totalSize.width = std::max(totalSize.width, coord.width);
|
totalSize.width = std::max(totalSize.width, coord.width);
|
||||||
|
|
||||||
|
|
|
@ -222,7 +222,7 @@ void MWSpell::setSpellId(const std::string &spellId)
|
||||||
updateWidgets();
|
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 ESMS::ESMStore &store = mWindowManager->getStore();
|
||||||
const ESM::Spell *spell = store.spells.search(id);
|
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 = creator->createWidget<MWSpellEffect>("MW_EffectImage", coord, MyGUI::Align::Default);
|
||||||
effect->setWindowManager(mWindowManager);
|
effect->setWindowManager(mWindowManager);
|
||||||
effect->setConstant(category == 0);
|
effect->setFlags(flags);
|
||||||
effect->setSpellEffect(*it);
|
effect->setSpellEffect(*it);
|
||||||
effects.push_back(effect);
|
effects.push_back(effect);
|
||||||
coord.top += effect->getHeight();
|
coord.top += effect->getHeight();
|
||||||
|
@ -270,32 +270,29 @@ MWSpell::~MWSpell()
|
||||||
|
|
||||||
MWEffectList::MWEffectList()
|
MWEffectList::MWEffectList()
|
||||||
: mWindowManager(nullptr)
|
: mWindowManager(nullptr)
|
||||||
|
, mEffectList(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void MWEffectList::setEnchantmentId(const std::string &enchantId)
|
void MWEffectList::setEffectList(const ESM::EffectList* list)
|
||||||
{
|
{
|
||||||
id = enchantId;
|
mEffectList = list;
|
||||||
updateWidgets();
|
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
|
// 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
|
// 2 steps: first, create all widgets and check their width
|
||||||
MWSpellEffectPtr effect = nullptr;
|
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;
|
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 = creator->createWidget<MWSpellEffect>("MW_EffectImage", coord, MyGUI::Align::Default);
|
||||||
effect->setWindowManager(mWindowManager);
|
effect->setWindowManager(mWindowManager);
|
||||||
|
effect->setFlags(flags);
|
||||||
effect->setSpellEffect(*it);
|
effect->setSpellEffect(*it);
|
||||||
effect->setConstant(constant);
|
|
||||||
effects.push_back(effect);
|
effects.push_back(effect);
|
||||||
|
|
||||||
if (effect->getRequestedWidth() > maxwidth)
|
if (effect->getRequestedWidth() > maxwidth)
|
||||||
|
@ -344,7 +341,7 @@ MWSpellEffect::MWSpellEffect()
|
||||||
, imageWidget(nullptr)
|
, imageWidget(nullptr)
|
||||||
, textWidget(nullptr)
|
, textWidget(nullptr)
|
||||||
, mRequestedWidth(0)
|
, mRequestedWidth(0)
|
||||||
, mIsConstant(0)
|
, mFlags(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -359,6 +356,18 @@ void MWSpellEffect::updateWidgets()
|
||||||
if (!mWindowManager)
|
if (!mWindowManager)
|
||||||
return;
|
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 ESMS::ESMStore &store = mWindowManager->getStore();
|
||||||
const ESM::MagicEffect *magicEffect = store.magicEffects.search(effect.effectID);
|
const ESM::MagicEffect *magicEffect = store.magicEffects.search(effect.effectID);
|
||||||
if (textWidget)
|
if (textWidget)
|
||||||
|
@ -371,7 +380,8 @@ void MWSpellEffect::updateWidgets()
|
||||||
std::string sec = " " + mWindowManager->getGameSettingString("ssecond", "");
|
std::string sec = " " + mWindowManager->getGameSettingString("ssecond", "");
|
||||||
std::string secs = " " + mWindowManager->getGameSettingString("sseconds", "");
|
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)
|
if (effect.skill >= 0 && effect.skill < ESM::Skill::Length)
|
||||||
{
|
{
|
||||||
spellLine += " " + mWindowManager->getGameSettingString(ESM::Skill::sSkillNameIds[effect.skill], "");
|
spellLine += " " + mWindowManager->getGameSettingString(ESM::Skill::sSkillNameIds[effect.skill], "");
|
||||||
|
@ -390,7 +400,9 @@ void MWSpellEffect::updateWidgets()
|
||||||
};
|
};
|
||||||
spellLine += " " + mWindowManager->getGameSettingString(attributes[effect.attribute], "");
|
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)
|
if (effect.magnMin == effect.magnMax)
|
||||||
spellLine += " " + boost::lexical_cast<std::string>(effect.magnMin) + " " + ((effect.magnMin == 1) ? pt : pts);
|
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
|
// 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);
|
spellLine += " " + mWindowManager->getGameSettingString("sfor", "") + " " + boost::lexical_cast<std::string>(effect.duration) + ((effect.duration == 1) ? sec : secs);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string on = mWindowManager->getGameSettingString("sonword", "");
|
// potions have no target
|
||||||
if (effect.range == ESM::RT_Self)
|
if (!(mFlags & MWEffectList::EF_Potion))
|
||||||
spellLine += " " + on + " " + mWindowManager->getGameSettingString("sRangeSelf", "");
|
{
|
||||||
else if (effect.range == ESM::RT_Touch)
|
std::string on = mWindowManager->getGameSettingString("sonword", "");
|
||||||
spellLine += " " + on + " " + mWindowManager->getGameSettingString("sRangeTouch", "");
|
if (effect.range == ESM::RT_Self)
|
||||||
else if (effect.range == ESM::RT_Target)
|
spellLine += " " + on + " " + mWindowManager->getGameSettingString("sRangeSelf", "");
|
||||||
spellLine += " " + on + " " + mWindowManager->getGameSettingString("sRangeTarget", "");
|
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);
|
static_cast<MyGUI::TextBox*>(textWidget)->setCaption(spellLine);
|
||||||
|
@ -574,11 +591,8 @@ std::string MWSpellEffect::effectIDToString(const short effectID)
|
||||||
names[30] ="sEffectWeaknesstoShock";
|
names[30] ="sEffectWeaknesstoShock";
|
||||||
|
|
||||||
assert(names.find(effectID) != names.end() && "Unimplemented effect type");
|
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()
|
MWSpellEffect::~MWSpellEffect()
|
||||||
|
|
|
@ -153,19 +153,23 @@ namespace MWGui
|
||||||
|
|
||||||
typedef MWMechanics::Stat<int> EnchantmentValue;
|
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 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 vector to store the created effect widgets
|
||||||
* @param parent widget
|
* @param parent widget
|
||||||
* @param coordinates to use, will be expanded if more space is needed
|
* @param coordinates to use, will be expanded if more space is needed
|
||||||
* @param center the effect widgets horizontally
|
* @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);
|
void createEffectWidgets(std::vector<MyGUI::WidgetPtr> &effects, MyGUI::WidgetPtr creator, MyGUI::IntCoord &coord, bool center, int flags);
|
||||||
|
|
||||||
const std::string &getSpellId() const { return id; }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ~MWEffectList();
|
virtual ~MWEffectList();
|
||||||
|
@ -176,7 +180,7 @@ namespace MWGui
|
||||||
void updateWidgets();
|
void updateWidgets();
|
||||||
|
|
||||||
WindowManager* mWindowManager;
|
WindowManager* mWindowManager;
|
||||||
std::string id;
|
const ESM::EffectList* mEffectList;
|
||||||
};
|
};
|
||||||
typedef MWEffectList* MWEffectListPtr;
|
typedef MWEffectList* MWEffectListPtr;
|
||||||
|
|
||||||
|
@ -190,7 +194,7 @@ namespace MWGui
|
||||||
|
|
||||||
void setWindowManager(WindowManager* parWindowManager) { mWindowManager = parWindowManager; }
|
void setWindowManager(WindowManager* parWindowManager) { mWindowManager = parWindowManager; }
|
||||||
void setSpellEffect(SpellEffectValue value);
|
void setSpellEffect(SpellEffectValue value);
|
||||||
void setConstant(bool constant) { mIsConstant = constant; }
|
void setFlags(int flags) { mFlags = flags; }
|
||||||
|
|
||||||
std::string effectIDToString(const short effectID);
|
std::string effectIDToString(const short effectID);
|
||||||
|
|
||||||
|
@ -209,7 +213,7 @@ namespace MWGui
|
||||||
|
|
||||||
WindowManager* mWindowManager;
|
WindowManager* mWindowManager;
|
||||||
SpellEffectValue effect;
|
SpellEffectValue effect;
|
||||||
bool mIsConstant; // constant effect
|
int mFlags;
|
||||||
MyGUI::ImageBox* imageWidget;
|
MyGUI::ImageBox* imageWidget;
|
||||||
MyGUI::TextBox* textWidget;
|
MyGUI::TextBox* textWidget;
|
||||||
int mRequestedWidth;
|
int mRequestedWidth;
|
||||||
|
|
Loading…
Reference in a new issue