1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-20 06:23:54 +00:00

Merge remote-tracking branch 'potatoesmaster/tradewindow'

This commit is contained in:
Marc Zinnschlag 2013-03-04 19:42:51 +01:00
commit 8a887a0aef
3 changed files with 38 additions and 35 deletions

View file

@ -64,6 +64,7 @@ namespace MWGui
mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onCancelButtonClicked); mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onCancelButtonClicked);
mOfferButton->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onOfferButtonClicked); mOfferButton->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onOfferButtonClicked);
mMaxSaleButton->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onMaxSaleButtonClicked);
mIncreaseButton->eventMouseButtonPressed += MyGUI::newDelegate(this, &TradeWindow::onIncreaseButtonPressed); mIncreaseButton->eventMouseButtonPressed += MyGUI::newDelegate(this, &TradeWindow::onIncreaseButtonPressed);
mIncreaseButton->eventMouseButtonReleased += MyGUI::newDelegate(this, &TradeWindow::onBalanceButtonReleased); mIncreaseButton->eventMouseButtonReleased += MyGUI::newDelegate(this, &TradeWindow::onBalanceButtonReleased);
mDecreaseButton->eventMouseButtonPressed += MyGUI::newDelegate(this, &TradeWindow::onDecreaseButtonPressed); mDecreaseButton->eventMouseButtonPressed += MyGUI::newDelegate(this, &TradeWindow::onDecreaseButtonPressed);
@ -191,21 +192,7 @@ namespace MWGui
} }
// check if the merchant can afford this // check if the merchant can afford this
int merchantgold; if (mCurrentBalance > 0 && getMerchantGold() < mCurrentBalance)
if (mPtr.getTypeName() == typeid(ESM::NPC).name())
{
MWWorld::LiveCellRef<ESM::NPC>* ref = mPtr.get<ESM::NPC>();
if (ref->mBase->mNpdt52.mGold == -10)
merchantgold = ref->mBase->mNpdt12.mGold;
else
merchantgold = ref->mBase->mNpdt52.mGold;
}
else // ESM::Creature
{
MWWorld::LiveCellRef<ESM::Creature>* ref = mPtr.get<ESM::Creature>();
merchantgold = ref->mBase->mData.mGold;
}
if (mCurrentBalance > 0 && merchantgold < mCurrentBalance)
{ {
// user notification // user notification
MWBase::Environment::get().getWindowManager()-> MWBase::Environment::get().getWindowManager()->
@ -293,6 +280,12 @@ namespace MWGui
mWindowManager.removeGuiMode(GM_Barter); mWindowManager.removeGuiMode(GM_Barter);
} }
void TradeWindow::onMaxSaleButtonClicked(MyGUI::Widget* _sender)
{
mCurrentBalance = getMerchantGold();
updateLabels();
}
void TradeWindow::onIncreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id) void TradeWindow::onIncreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id)
{ {
mBalanceButtonsState = BBS_Increase; mBalanceButtonsState = BBS_Increase;
@ -341,22 +334,7 @@ namespace MWGui
mTotalBalance->setCaption(boost::lexical_cast<std::string>(-mCurrentBalance)); mTotalBalance->setCaption(boost::lexical_cast<std::string>(-mCurrentBalance));
} }
int merchantgold; mMerchantGold->setCaptionWithReplacing("#{sSellerGold} " + boost::lexical_cast<std::string>(getMerchantGold()));
if (mPtr.getTypeName() == typeid(ESM::NPC).name())
{
MWWorld::LiveCellRef<ESM::NPC>* ref = mPtr.get<ESM::NPC>();
if (ref->mBase->mNpdt52.mGold == -10)
merchantgold = ref->mBase->mNpdt12.mGold;
else
merchantgold = ref->mBase->mNpdt52.mGold;
}
else // ESM::Creature
{
MWWorld::LiveCellRef<ESM::Creature>* ref = mPtr.get<ESM::Creature>();
merchantgold = ref->mBase->mData.mGold;
}
mMerchantGold->setCaptionWithReplacing("#{sSellerGold} " + boost::lexical_cast<std::string>(merchantgold));
} }
std::vector<MWWorld::Ptr> TradeWindow::getEquippedItems() std::vector<MWWorld::Ptr> TradeWindow::getEquippedItems()
@ -468,4 +446,25 @@ namespace MWGui
mWindowManager.removeGuiMode(GM_Barter); mWindowManager.removeGuiMode(GM_Barter);
mWindowManager.removeGuiMode(GM_Dialogue); mWindowManager.removeGuiMode(GM_Dialogue);
} }
int TradeWindow::getMerchantGold()
{
int merchantGold;
if (mPtr.getTypeName() == typeid(ESM::NPC).name())
{
MWWorld::LiveCellRef<ESM::NPC>* ref = mPtr.get<ESM::NPC>();
if (ref->mBase->mNpdt52.mGold == -10)
merchantGold = ref->mBase->mNpdt12.mGold;
else
merchantGold = ref->mBase->mNpdt52.mGold;
}
else // ESM::Creature
{
MWWorld::LiveCellRef<ESM::Creature>* ref = mPtr.get<ESM::Creature>();
merchantGold = ref->mBase->mData.mGold;
}
return merchantGold;
}
} }

View file

@ -74,6 +74,7 @@ namespace MWGui
void onFilterChanged(MyGUI::Widget* _sender); void onFilterChanged(MyGUI::Widget* _sender);
void onOfferButtonClicked(MyGUI::Widget* _sender); void onOfferButtonClicked(MyGUI::Widget* _sender);
void onCancelButtonClicked(MyGUI::Widget* _sender); void onCancelButtonClicked(MyGUI::Widget* _sender);
void onMaxSaleButtonClicked(MyGUI::Widget* _sender);
void onIncreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id); void onIncreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id);
void onDecreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id); void onDecreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id);
void onBalanceButtonReleased(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id); void onBalanceButtonReleased(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id);
@ -93,6 +94,9 @@ namespace MWGui
void updateLabels(); void updateLabels();
virtual void onReferenceUnavailable(); virtual void onReferenceUnavailable();
private:
int getMerchantGold();
}; };
} }

View file

@ -51,10 +51,6 @@
<Property key="TextAlign" value="Center"/> <Property key="TextAlign" value="Center"/>
</Widget> </Widget>
<Widget type="AutoSizedButton" skin="MW_Button" position="0 60 60 24" name="MaxSaleButton" align="Left Top">
<Property key="Caption" value="Max. Sale"/> <!-- GMST sMaxSale doesn't work -->
</Widget>
<Widget type="HBox" position="0 60 566 24" align="Right Bottom"> <Widget type="HBox" position="0 60 566 24" align="Right Bottom">
<Widget type="Widget"> <Widget type="Widget">
<UserString key="HStretch" value="true"/> <UserString key="HStretch" value="true"/>
@ -66,6 +62,10 @@
<Property key="Caption" value="#{sCancel}"/> <Property key="Caption" value="#{sCancel}"/>
</Widget> </Widget>
</Widget> </Widget>
<Widget type="AutoSizedButton" skin="MW_Button" position="0 60 60 24" name="MaxSaleButton" align="Left Top">
<Property key="Caption" value="Max. Sale"/> <!-- GMST sMaxSale doesn't work -->
</Widget>
</Widget> </Widget>
</Widget> </Widget>