|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
#include "spellswindow.hpp"
|
|
|
|
|
#include "spellbuyingwindow.hpp"
|
|
|
|
|
|
|
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
|
|
|
|
|
@ -18,19 +18,16 @@
|
|
|
|
|
|
|
|
|
|
namespace MWGui
|
|
|
|
|
{
|
|
|
|
|
const int SpellsWindow::sLineHeight = 18;
|
|
|
|
|
const int SpellBuyingWindow::sLineHeight = 18;
|
|
|
|
|
|
|
|
|
|
SpellsWindow::SpellsWindow(MWBase::WindowManager& parWindowManager) :
|
|
|
|
|
SpellBuyingWindow::SpellBuyingWindow(MWBase::WindowManager& parWindowManager) :
|
|
|
|
|
WindowBase("openmw_spells_window.layout", parWindowManager)
|
|
|
|
|
, ContainerBase(NULL) // no drag&drop
|
|
|
|
|
, mSpellsWidgetMap()
|
|
|
|
|
, mCurrentY(0)
|
|
|
|
|
, mLastPos(0)
|
|
|
|
|
, mSpellsWidgets()
|
|
|
|
|
, mSpellsPriceMap()
|
|
|
|
|
{
|
|
|
|
|
setCoord(0, 0, 450, 300);
|
|
|
|
|
center();
|
|
|
|
|
|
|
|
|
|
getWidget(mCancelButton, "CancelButton");
|
|
|
|
|
getWidget(mPlayerGold, "PlayerGold");
|
|
|
|
@ -40,11 +37,11 @@ namespace MWGui
|
|
|
|
|
getWidget(mSpellsClientWidget, "SpellsClient");
|
|
|
|
|
getWidget(mSpellsScrollerWidget, "SpellsScroller");
|
|
|
|
|
|
|
|
|
|
mSpellsClientWidget->eventMouseWheel += MyGUI::newDelegate(this, &SpellsWindow::onMouseWheel);
|
|
|
|
|
mSpellsClientWidget->eventMouseWheel += MyGUI::newDelegate(this, &SpellBuyingWindow::onMouseWheel);
|
|
|
|
|
|
|
|
|
|
mSpellsScrollerWidget->eventScrollChangePosition += MyGUI::newDelegate(this, &SpellsWindow::onScrollChangePosition);
|
|
|
|
|
mSpellsScrollerWidget->eventScrollChangePosition += MyGUI::newDelegate(this, &SpellBuyingWindow::onScrollChangePosition);
|
|
|
|
|
|
|
|
|
|
mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellsWindow::onCancelButtonClicked);
|
|
|
|
|
mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellBuyingWindow::onCancelButtonClicked);
|
|
|
|
|
|
|
|
|
|
int cancelButtonWidth = mCancelButton->getTextSize().width + 24;
|
|
|
|
|
mCancelButton->setCoord(430-cancelButtonWidth,
|
|
|
|
@ -59,71 +56,40 @@ namespace MWGui
|
|
|
|
|
mSelect->getTop(),
|
|
|
|
|
mSelect->getTextSize().width,
|
|
|
|
|
mSelect->getHeight());
|
|
|
|
|
|
|
|
|
|
static_cast<MyGUI::Window*>(mMainWidget)->eventWindowChangeCoord += MyGUI::newDelegate(this, &SpellsWindow::onWindowResize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SpellsWindow::addSpell(std::string spellID)
|
|
|
|
|
void SpellBuyingWindow::addSpell(std::string spellID)
|
|
|
|
|
{
|
|
|
|
|
MyGUI::Button* toAdd;
|
|
|
|
|
|
|
|
|
|
toAdd = mSpellsClientWidget->createWidget<MyGUI::Button>("SandText", 0, mCurrentY, 200, sLineHeight, MyGUI::Align::Default);
|
|
|
|
|
mCurrentY += sLineHeight;
|
|
|
|
|
const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().spells.find(spellID);
|
|
|
|
|
/// \todo price adjustment depending on merchantile skill
|
|
|
|
|
int price = spell->data.cost*MWBase::Environment::get().getWorld()->getStore().gameSettings.search("fSpellValueMult")->f;
|
|
|
|
|
mSpellsPriceMap.insert(std::pair<const ESM::Spell*, int>(spell,price));
|
|
|
|
|
if (price>mWindowManager.getInventoryWindow()->getPlayerGold())
|
|
|
|
|
toAdd->setCaption("#A3997B" + spell->name+" - "+boost::lexical_cast<std::string>(price)+MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sgp")->str);
|
|
|
|
|
else
|
|
|
|
|
toAdd->setCaption(spell->name+" - "+boost::lexical_cast<std::string>(price)+MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sgp")->str);
|
|
|
|
|
toAdd = mSpellsClientWidget->createWidget<MyGUI::Button>((price>mWindowManager.getInventoryWindow()->getPlayerGold()) ? "SandTextGreyedOut" : "SpellText", 0, mCurrentY, 200, sLineHeight, MyGUI::Align::Default);
|
|
|
|
|
mCurrentY += sLineHeight;
|
|
|
|
|
/// \todo price adjustment depending on merchantile skill
|
|
|
|
|
toAdd->setUserData(price);
|
|
|
|
|
toAdd->setCaption(spell->name+" - "+boost::lexical_cast<std::string>(price)+MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sgp")->str);
|
|
|
|
|
toAdd->setSize(toAdd->getTextSize().width,sLineHeight);
|
|
|
|
|
toAdd->eventMouseWheel += MyGUI::newDelegate(this, &SpellsWindow::onMouseWheel);
|
|
|
|
|
toAdd->eventMouseWheel += MyGUI::newDelegate(this, &SpellBuyingWindow::onMouseWheel);
|
|
|
|
|
toAdd->setUserString("ToolTipType", "Spell");
|
|
|
|
|
toAdd->setUserString("Spell", spellID);
|
|
|
|
|
toAdd->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellsWindow::onSpellButtonClick);
|
|
|
|
|
toAdd->eventMouseSetFocus += MyGUI::newDelegate(this, &SpellsWindow::onFocus);
|
|
|
|
|
toAdd->eventMouseLostFocus += MyGUI::newDelegate(this, &SpellsWindow::onFocusLost);
|
|
|
|
|
mSpellsWidgets.push_back(toAdd);
|
|
|
|
|
toAdd->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellBuyingWindow::onSpellButtonClick);
|
|
|
|
|
mSpellsWidgetMap.insert(std::pair<MyGUI::Widget*, const ESM::Spell*>(toAdd,spell));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SpellsWindow::onFocusLost(MyGUI::Widget* _sender, MyGUI::Widget* _old)
|
|
|
|
|
{
|
|
|
|
|
updateLabels();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SpellsWindow::onFocus(MyGUI::Widget* _sender, MyGUI::Widget* _old)
|
|
|
|
|
{
|
|
|
|
|
updateLabels();
|
|
|
|
|
MyGUI::Button* toUpdate;
|
|
|
|
|
toUpdate = (MyGUI::Button*) _sender;
|
|
|
|
|
const ESM::Spell* spell = mSpellsWidgetMap.find(toUpdate)->second;
|
|
|
|
|
int price = mSpellsPriceMap.find(spell)->second;
|
|
|
|
|
if (price>mWindowManager.getInventoryWindow()->getPlayerGold())
|
|
|
|
|
toUpdate->setCaption("#A3997B" + spell->name+" - "+boost::lexical_cast<std::string>(price)+MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sgp")->str);
|
|
|
|
|
else
|
|
|
|
|
toUpdate->setCaption("#D8C09A" + spell->name+" - "+boost::lexical_cast<std::string>(price)+MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sgp")->str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SpellsWindow::clearSpells()
|
|
|
|
|
void SpellBuyingWindow::clearSpells()
|
|
|
|
|
{
|
|
|
|
|
mSpellsScrollerWidget->setScrollPosition(0);
|
|
|
|
|
onScrollChangePosition(mSpellsScrollerWidget, mSpellsScrollerWidget->getScrollPosition());
|
|
|
|
|
mCurrentY = 0;
|
|
|
|
|
mSpellsWidgets.clear();
|
|
|
|
|
while (mSpellsClientWidget->getChildCount()!=0)
|
|
|
|
|
{
|
|
|
|
|
MyGUI::Widget* toRemove;
|
|
|
|
|
toRemove = mSpellsClientWidget->getChildAt(0);
|
|
|
|
|
mSpellsClientWidget->_destroyChildWidget(toRemove);
|
|
|
|
|
}
|
|
|
|
|
while (mSpellsClientWidget->getChildCount())
|
|
|
|
|
MyGUI::Gui::getInstance().destroyWidget(mSpellsClientWidget->getChildAt(0));
|
|
|
|
|
mSpellsWidgetMap.clear();
|
|
|
|
|
mSpellsPriceMap.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SpellsWindow::startSpells(MWWorld::Ptr actor)
|
|
|
|
|
void SpellBuyingWindow::startSpellBuying(MWWorld::Ptr actor)
|
|
|
|
|
{
|
|
|
|
|
center();
|
|
|
|
|
mActor = actor;
|
|
|
|
|
clearSpells();
|
|
|
|
|
|
|
|
|
|
if (actor.getTypeName() == typeid(ESM::NPC).name())
|
|
|
|
@ -150,10 +116,10 @@ namespace MWGui
|
|
|
|
|
updateScroller();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SpellsWindow::onSpellButtonClick(MyGUI::Widget* _sender)
|
|
|
|
|
void SpellBuyingWindow::onSpellButtonClick(MyGUI::Widget* _sender)
|
|
|
|
|
{
|
|
|
|
|
const ESM::Spell* spell = mSpellsWidgetMap.find(_sender)->second;
|
|
|
|
|
int price = mSpellsPriceMap.find(spell)->second;
|
|
|
|
|
int price = *_sender->getUserData<int>();
|
|
|
|
|
|
|
|
|
|
if (mWindowManager.getInventoryWindow()->getPlayerGold()>=price)
|
|
|
|
|
{
|
|
|
|
@ -162,48 +128,19 @@ namespace MWGui
|
|
|
|
|
MWMechanics::Spells& spells = stats.getSpells();
|
|
|
|
|
spells.add(spell->name);
|
|
|
|
|
mWindowManager.getTradeWindow()->addOrRemoveGold(-price);
|
|
|
|
|
mSpellsWidgetMap.erase(_sender);
|
|
|
|
|
mSpellsPriceMap.erase(spell);
|
|
|
|
|
for (std::vector<MyGUI::WidgetPtr>::iterator it = mSpellsWidgets.begin(); it != mSpellsWidgets.end(); ++it)
|
|
|
|
|
{
|
|
|
|
|
if (*it==_sender)
|
|
|
|
|
{
|
|
|
|
|
mSpellsWidgets.erase(it);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mSpellsClientWidget->_destroyChildWidget(_sender);
|
|
|
|
|
unsigned int i;
|
|
|
|
|
mSpellsScrollerWidget->setScrollPosition(0);
|
|
|
|
|
onScrollChangePosition(mSpellsScrollerWidget, mSpellsScrollerWidget->getScrollPosition());
|
|
|
|
|
mCurrentY = 0;
|
|
|
|
|
for (i=0;i<mSpellsClientWidget->getChildCount();i++)
|
|
|
|
|
{
|
|
|
|
|
MyGUI::Widget* toMove;
|
|
|
|
|
toMove = mSpellsClientWidget->getChildAt(i);
|
|
|
|
|
toMove->setPosition(0,mCurrentY);
|
|
|
|
|
mCurrentY+=sLineHeight;
|
|
|
|
|
}
|
|
|
|
|
updateScroller();
|
|
|
|
|
startSpellBuying(mActor);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
updateLabels();
|
|
|
|
|
updateScroller();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SpellsWindow::onWindowResize(MyGUI::Window* _sender)
|
|
|
|
|
void SpellBuyingWindow::onCancelButtonClicked(MyGUI::Widget* _sender)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
mWindowManager.removeGuiMode(GM_SpellBuying);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SpellsWindow::onCancelButtonClicked(MyGUI::Widget* _sender)
|
|
|
|
|
{
|
|
|
|
|
mWindowManager.removeGuiMode(GM_Spells);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SpellsWindow::updateLabels()
|
|
|
|
|
void SpellBuyingWindow::updateLabels()
|
|
|
|
|
{
|
|
|
|
|
mPlayerGold->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sGold")->str
|
|
|
|
|
+ ": " + boost::lexical_cast<std::string>(mWindowManager.getInventoryWindow()->getPlayerGold()));
|
|
|
|
@ -211,28 +148,16 @@ namespace MWGui
|
|
|
|
|
mPlayerGold->getTop(),
|
|
|
|
|
mPlayerGold->getTextSize().width,
|
|
|
|
|
mPlayerGold->getHeight());
|
|
|
|
|
unsigned int i;
|
|
|
|
|
for (i=0;i<mSpellsClientWidget->getChildCount();i++)
|
|
|
|
|
{
|
|
|
|
|
MyGUI::Button* toUpdate;
|
|
|
|
|
toUpdate = (MyGUI::Button*) mSpellsClientWidget->getChildAt(i);
|
|
|
|
|
const ESM::Spell* spell = mSpellsWidgetMap.find(toUpdate)->second;
|
|
|
|
|
int price = mSpellsPriceMap.find(spell)->second;
|
|
|
|
|
if (price>mWindowManager.getInventoryWindow()->getPlayerGold())
|
|
|
|
|
toUpdate->setCaption("#A3997B" + spell->name+" - "+boost::lexical_cast<std::string>(price)+MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sgp")->str);
|
|
|
|
|
else
|
|
|
|
|
toUpdate->setCaption(spell->name+" - "+boost::lexical_cast<std::string>(price)+MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sgp")->str);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SpellsWindow::onReferenceUnavailable()
|
|
|
|
|
void SpellBuyingWindow::onReferenceUnavailable()
|
|
|
|
|
{
|
|
|
|
|
// remove both Spells and Dialogue (since you always trade with the NPC/creature that you have previously talked to)
|
|
|
|
|
mWindowManager.removeGuiMode(GM_Spells);
|
|
|
|
|
mWindowManager.removeGuiMode(GM_SpellBuying);
|
|
|
|
|
mWindowManager.removeGuiMode(GM_Dialogue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SpellsWindow::updateScroller()
|
|
|
|
|
void SpellBuyingWindow::updateScroller()
|
|
|
|
|
{
|
|
|
|
|
mSpellsScrollerWidget->setScrollRange(std::max(mCurrentY - mSpellsClientWidget->getHeight(), 0));
|
|
|
|
|
mSpellsScrollerWidget->setScrollPage(std::max(mSpellsClientWidget->getHeight() - sLineHeight, 0));
|
|
|
|
@ -240,7 +165,7 @@ namespace MWGui
|
|
|
|
|
mSpellsScrollerWidget->setTrackSize( (mSpellsBoxWidget->getHeight() / float(mCurrentY)) * mSpellsScrollerWidget->getLineSize() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SpellsWindow::onScrollChangePosition(MyGUI::ScrollBar* scroller, size_t pos)
|
|
|
|
|
void SpellBuyingWindow::onScrollChangePosition(MyGUI::ScrollBar* scroller, size_t pos)
|
|
|
|
|
{
|
|
|
|
|
int diff = mLastPos - pos;
|
|
|
|
|
// Adjust position of all widget according to difference
|
|
|
|
@ -248,14 +173,16 @@ namespace MWGui
|
|
|
|
|
return;
|
|
|
|
|
mLastPos = pos;
|
|
|
|
|
|
|
|
|
|
std::vector<MyGUI::WidgetPtr>::const_iterator end = mSpellsWidgets.end();
|
|
|
|
|
for (std::vector<MyGUI::WidgetPtr>::const_iterator it = mSpellsWidgets.begin(); it != end; ++it)
|
|
|
|
|
unsigned int i;
|
|
|
|
|
for (i=0;i<mSpellsClientWidget->getChildCount();i++)
|
|
|
|
|
{
|
|
|
|
|
(*it)->setCoord((*it)->getCoord() + MyGUI::IntPoint(0, diff));
|
|
|
|
|
MyGUI::Widget* toMove;
|
|
|
|
|
toMove = mSpellsClientWidget->getChildAt(i);
|
|
|
|
|
toMove->setCoord(toMove->getCoord() + MyGUI::IntPoint(0, diff));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SpellsWindow::onMouseWheel(MyGUI::Widget* _sender, int _rel)
|
|
|
|
|
void SpellBuyingWindow::onMouseWheel(MyGUI::Widget* _sender, int _rel)
|
|
|
|
|
{
|
|
|
|
|
if (mSpellsScrollerWidget->getScrollPosition() - _rel*0.3 < 0)
|
|
|
|
|
mSpellsScrollerWidget->setScrollPosition(0);
|
|
|
|
@ -267,3 +194,4 @@ namespace MWGui
|
|
|
|
|
onScrollChangePosition(mSpellsScrollerWidget, mSpellsScrollerWidget->getScrollPosition());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|