Merge pull request #1287 from akortunov/spellsorting

Spellbuying menu improvements
pull/258/head
scrawl 8 years ago committed by GitHub
commit 9ac409e61c

@ -22,7 +22,6 @@ namespace MWGui
SpellBuyingWindow::SpellBuyingWindow() :
WindowBase("openmw_spell_buying_window.layout")
, mLastPos(0)
, mCurrentY(0)
{
getWidget(mCancelButton, "CancelButton");
@ -37,13 +36,20 @@ namespace MWGui
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_SpellBuying);
}
void SpellBuyingWindow::addSpell(const std::string& spellId)
bool SpellBuyingWindow::sortSpells (const ESM::Spell* left, const ESM::Spell* right)
{
std::string leftName = Misc::StringUtils::lowerCase(left->mName);
std::string rightName = Misc::StringUtils::lowerCase(right->mName);
return leftName.compare(rightName) < 0;
}
void SpellBuyingWindow::addSpell(const ESM::Spell& spell)
{
const MWWorld::ESMStore &store =
MWBase::Environment::get().getWorld()->getStore();
const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find(spellId);
int price = static_cast<int>(spell->mData.mCost*store.get<ESM::GameSetting>().find("fSpellValueMult")->getFloat());
int price = static_cast<int>(spell.mData.mCost*store.get<ESM::GameSetting>().find("fSpellValueMult")->getFloat());
price = MWBase::Environment::get().getMechanicsManager()->getBarterOffer(mPtr,price,true);
MWWorld::Ptr player = MWMechanics::getPlayer();
@ -64,13 +70,13 @@ namespace MWGui
mCurrentY += sLineHeight;
toAdd->setUserData(price);
toAdd->setCaptionWithReplacing(spell->mName+" - "+MyGUI::utility::toString(price)+"#{sgp}");
toAdd->setCaptionWithReplacing(spell.mName+" - "+MyGUI::utility::toString(price)+"#{sgp}");
toAdd->setSize(mSpellsView->getWidth(),sLineHeight);
toAdd->eventMouseWheel += MyGUI::newDelegate(this, &SpellBuyingWindow::onMouseWheel);
toAdd->setUserString("ToolTipType", "Spell");
toAdd->setUserString("Spell", spellId);
toAdd->setUserString("Spell", spell.mId);
toAdd->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellBuyingWindow::onSpellButtonClick);
mSpellsWidgetMap.insert(std::make_pair (toAdd, spellId));
mSpellsWidgetMap.insert(std::make_pair (toAdd, spell.mId));
}
void SpellBuyingWindow::clearSpells()
@ -82,7 +88,7 @@ namespace MWGui
mSpellsWidgetMap.clear();
}
void SpellBuyingWindow::startSpellBuying(const MWWorld::Ptr& actor)
void SpellBuyingWindow::startSpellBuying(const MWWorld::Ptr& actor, int startOffset)
{
center();
mPtr = actor;
@ -90,6 +96,8 @@ namespace MWGui
MWMechanics::Spells& merchantSpells = actor.getClass().getCreatureStats (actor).getSpells();
std::vector<const ESM::Spell*> spellsToSort;
for (MWMechanics::Spells::TIterator iter = merchantSpells.begin(); iter!=merchantSpells.end(); ++iter)
{
const ESM::Spell* spell = iter->first;
@ -109,15 +117,25 @@ namespace MWGui
if (playerHasSpell(iter->first->mId))
continue;
addSpell (iter->first->mId);
spellsToSort.push_back(iter->first);
}
std::stable_sort(spellsToSort.begin(), spellsToSort.end(), sortSpells);
for (std::vector<const ESM::Spell*>::iterator it = spellsToSort.begin() ; it != spellsToSort.end(); ++it)
{
addSpell(**it);
}
spellsToSort.clear();
updateLabels();
// Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the scrollbar is hidden
mSpellsView->setVisibleVScroll(false);
mSpellsView->setCanvasSize (MyGUI::IntSize(mSpellsView->getWidth(), std::max(mSpellsView->getHeight(), mCurrentY)));
mSpellsView->setVisibleVScroll(true);
mSpellsView->setViewOffset(MyGUI::IntPoint(0, startOffset));
}
bool SpellBuyingWindow::playerHasSpell(const std::string &id)
@ -143,7 +161,7 @@ namespace MWGui
MWMechanics::CreatureStats& npcStats = mPtr.getClass().getCreatureStats(mPtr);
npcStats.setGoldPool(npcStats.getGoldPool() + price);
startSpellBuying(mPtr);
startSpellBuying(mPtr, mSpellsView->getViewOffset().top);
MWBase::Environment::get().getWindowManager()->playSound("Item Gold Up");
}

@ -4,6 +4,8 @@
#include "windowbase.hpp"
#include "referenceinterface.hpp"
#include "../mwworld/esmstore.hpp"
namespace MyGUI
{
class Gui;
@ -23,7 +25,7 @@ namespace MWGui
public:
SpellBuyingWindow();
void startSpellBuying(const MWWorld::Ptr& actor);
void startSpellBuying(const MWWorld::Ptr& actor, int startOffset);
virtual void exit();
@ -38,7 +40,7 @@ namespace MWGui
void onCancelButtonClicked(MyGUI::Widget* _sender);
void onSpellButtonClick(MyGUI::Widget* _sender);
void onMouseWheel(MyGUI::Widget* _sender, int _rel);
void addSpell(const std::string& spellID);
void addSpell(const ESM::Spell& spell);
void clearSpells();
int mLastPos,mCurrentY;
@ -49,6 +51,9 @@ namespace MWGui
virtual void onReferenceUnavailable();
bool playerHasSpell (const std::string& id);
private:
static bool sortSpells (const ESM::Spell* left, const ESM::Spell* right);
};
}

@ -2034,7 +2034,7 @@ namespace MWGui
void WindowManager::startSpellBuying(const MWWorld::Ptr &actor)
{
pushGuiMode(GM_SpellBuying);
mSpellBuyingWindow->startSpellBuying(actor);
mSpellBuyingWindow->startSpellBuying(actor, 0);
}
void WindowManager::startTrade(const MWWorld::Ptr &actor)

Loading…
Cancel
Save