2012-05-17 13:36:25 +02:00
|
|
|
#include "tradewindow.hpp"
|
|
|
|
|
2015-01-10 02:50:43 +01:00
|
|
|
#include <MyGUI_Button.h>
|
|
|
|
#include <MyGUI_ControllerManager.h>
|
2019-05-17 10:49:00 +04:00
|
|
|
#include <MyGUI_ControllerRepeatClick.h>
|
2015-01-10 02:50:43 +01:00
|
|
|
#include <MyGUI_InputManager.h>
|
2012-05-17 21:56:16 +02:00
|
|
|
|
2022-08-03 00:00:54 +02:00
|
|
|
#include <components/misc/strings/format.hpp>
|
2014-09-25 20:28:00 +02:00
|
|
|
#include <components/widgets/numericeditbox.hpp>
|
|
|
|
|
2012-11-10 00:38:45 +01:00
|
|
|
#include "../mwbase/dialoguemanager.hpp"
|
2012-05-17 19:53:04 +02:00
|
|
|
#include "../mwbase/environment.hpp"
|
2012-11-05 19:53:55 +01:00
|
|
|
#include "../mwbase/mechanicsmanager.hpp"
|
2012-11-10 00:38:45 +01:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
2012-07-03 12:30:50 +02:00
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
|
2013-05-11 18:38:27 +02:00
|
|
|
#include "../mwworld/class.hpp"
|
|
|
|
#include "../mwworld/containerstore.hpp"
|
2015-02-09 15:01:49 +01:00
|
|
|
#include "../mwworld/esmstore.hpp"
|
2012-05-17 19:53:04 +02:00
|
|
|
|
2015-08-21 21:12:39 +12:00
|
|
|
#include "../mwmechanics/actorutil.hpp"
|
2016-06-04 12:28:47 -04:00
|
|
|
#include "../mwmechanics/creaturestats.hpp"
|
2012-11-08 13:38:20 +01:00
|
|
|
|
2013-05-11 18:38:27 +02:00
|
|
|
#include "containeritemmodel.hpp"
|
|
|
|
#include "countdialog.hpp"
|
2012-05-17 21:56:16 +02:00
|
|
|
#include "inventorywindow.hpp"
|
2013-05-11 18:38:27 +02:00
|
|
|
#include "itemview.hpp"
|
|
|
|
#include "sortfilteritemmodel.hpp"
|
2020-04-10 23:14:00 +03:00
|
|
|
#include "tooltips.hpp"
|
2013-05-11 18:38:27 +02:00
|
|
|
#include "tradeitemmodel.hpp"
|
2012-05-17 21:15:48 +02:00
|
|
|
|
2014-06-26 14:59:33 +02:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
int getEffectiveValue(MWWorld::Ptr item, int count)
|
|
|
|
{
|
2015-03-08 13:22:56 +13:00
|
|
|
float price = static_cast<float>(item.getClass().getValue(item));
|
2014-06-26 14:59:33 +02:00
|
|
|
if (item.getClass().hasItemHealth(item))
|
2018-10-25 16:09:07 +03:00
|
|
|
{
|
2018-10-25 15:45:31 +03:00
|
|
|
price *= item.getClass().getItemNormalizedHealth(item);
|
2018-10-25 16:09:07 +03:00
|
|
|
}
|
2015-03-08 13:07:29 +13:00
|
|
|
return static_cast<int>(price * count);
|
2014-06-26 14:59:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-05-17 13:36:25 +02:00
|
|
|
namespace MWGui
|
|
|
|
{
|
2013-05-11 18:38:27 +02:00
|
|
|
TradeWindow::TradeWindow()
|
|
|
|
: WindowBase("openmw_trade_window.layout")
|
2018-10-09 10:21:12 +04:00
|
|
|
, mSortModel(nullptr)
|
|
|
|
, mTradeModel(nullptr)
|
2015-04-25 13:37:42 -05:00
|
|
|
, mItemToSell(-1)
|
|
|
|
, mCurrentBalance(0)
|
2013-07-31 18:46:32 +02:00
|
|
|
, mCurrentMerchantOffer(0)
|
2012-05-17 13:36:25 +02:00
|
|
|
{
|
2012-05-17 21:15:48 +02:00
|
|
|
getWidget(mFilterAll, "AllButton");
|
|
|
|
getWidget(mFilterWeapon, "WeaponButton");
|
|
|
|
getWidget(mFilterApparel, "ApparelButton");
|
|
|
|
getWidget(mFilterMagic, "MagicButton");
|
|
|
|
getWidget(mFilterMisc, "MiscButton");
|
|
|
|
|
|
|
|
getWidget(mMaxSaleButton, "MaxSaleButton");
|
|
|
|
getWidget(mCancelButton, "CancelButton");
|
|
|
|
getWidget(mOfferButton, "OfferButton");
|
|
|
|
getWidget(mPlayerGold, "PlayerGold");
|
|
|
|
getWidget(mMerchantGold, "MerchantGold");
|
|
|
|
getWidget(mIncreaseButton, "IncreaseButton");
|
|
|
|
getWidget(mDecreaseButton, "DecreaseButton");
|
|
|
|
getWidget(mTotalBalance, "TotalBalance");
|
|
|
|
getWidget(mTotalBalanceLabel, "TotalBalanceLabel");
|
|
|
|
getWidget(mBottomPane, "BottomPane");
|
2020-02-24 18:14:40 +00:00
|
|
|
getWidget(mFilterEdit, "FilterEdit");
|
2012-05-17 21:15:48 +02:00
|
|
|
|
2013-05-11 18:38:27 +02:00
|
|
|
getWidget(mItemView, "ItemView");
|
|
|
|
mItemView->eventItemClicked += MyGUI::newDelegate(this, &TradeWindow::onItemSelected);
|
|
|
|
|
2012-05-17 21:15:48 +02:00
|
|
|
mFilterAll->setStateSelected(true);
|
|
|
|
|
2012-05-17 19:53:04 +02:00
|
|
|
mFilterAll->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onFilterChanged);
|
|
|
|
mFilterWeapon->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onFilterChanged);
|
|
|
|
mFilterApparel->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onFilterChanged);
|
|
|
|
mFilterMagic->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onFilterChanged);
|
|
|
|
mFilterMisc->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onFilterChanged);
|
2020-02-24 18:14:40 +00:00
|
|
|
mFilterEdit->eventEditTextChange += MyGUI::newDelegate(this, &TradeWindow::onNameFilterChanged);
|
2012-05-17 19:53:04 +02:00
|
|
|
|
2012-05-17 21:15:48 +02:00
|
|
|
mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onCancelButtonClicked);
|
|
|
|
mOfferButton->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onOfferButtonClicked);
|
2013-03-04 12:21:38 +01:00
|
|
|
mMaxSaleButton->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onMaxSaleButtonClicked);
|
2013-02-10 08:50:36 +04:00
|
|
|
mIncreaseButton->eventMouseButtonPressed += MyGUI::newDelegate(this, &TradeWindow::onIncreaseButtonPressed);
|
|
|
|
mIncreaseButton->eventMouseButtonReleased += MyGUI::newDelegate(this, &TradeWindow::onBalanceButtonReleased);
|
|
|
|
mDecreaseButton->eventMouseButtonPressed += MyGUI::newDelegate(this, &TradeWindow::onDecreaseButtonPressed);
|
|
|
|
mDecreaseButton->eventMouseButtonReleased += MyGUI::newDelegate(this, &TradeWindow::onBalanceButtonReleased);
|
2012-05-17 21:15:48 +02:00
|
|
|
|
2014-09-25 20:28:00 +02:00
|
|
|
mTotalBalance->eventValueChanged += MyGUI::newDelegate(this, &TradeWindow::onBalanceValueChanged);
|
2017-09-24 13:10:50 +02:00
|
|
|
mTotalBalance->eventEditSelectAccept += MyGUI::newDelegate(this, &TradeWindow::onAccept);
|
2018-09-20 16:02:26 +04:00
|
|
|
mTotalBalance->setMinValue(
|
|
|
|
std::numeric_limits<int>::min() + 1); // disallow INT_MIN since abs(INT_MIN) is undefined
|
2014-05-31 13:53:36 +02:00
|
|
|
|
2012-06-29 16:48:50 +02:00
|
|
|
setCoord(400, 0, 400, 300);
|
2012-05-17 13:36:25 +02:00
|
|
|
}
|
2012-05-17 17:15:44 +02:00
|
|
|
|
2017-09-22 21:26:41 +02:00
|
|
|
void TradeWindow::setPtr(const MWWorld::Ptr& actor)
|
2014-04-27 19:03:33 +02:00
|
|
|
{
|
2013-05-11 18:38:27 +02:00
|
|
|
mPtr = actor;
|
2012-05-17 21:56:16 +02:00
|
|
|
|
|
|
|
mCurrentBalance = 0;
|
2012-11-08 13:38:20 +01:00
|
|
|
mCurrentMerchantOffer = 0;
|
2012-05-17 21:56:16 +02:00
|
|
|
|
2013-05-11 18:38:27 +02:00
|
|
|
std::vector<MWWorld::Ptr> itemSources;
|
2020-10-13 17:46:32 +02:00
|
|
|
// Important: actor goes first, so purchased items come out of the actor's pocket first
|
|
|
|
itemSources.push_back(actor);
|
2013-05-11 18:38:27 +02:00
|
|
|
MWBase::Environment::get().getWorld()->getContainersOwnedBy(actor, itemSources);
|
2014-03-27 01:23:56 -04:00
|
|
|
|
2013-05-27 02:18:36 +02:00
|
|
|
std::vector<MWWorld::Ptr> worldItems;
|
|
|
|
MWBase::Environment::get().getWorld()->getItemsOwnedBy(actor, worldItems);
|
2012-05-18 17:27:55 +02:00
|
|
|
|
2022-08-31 18:49:50 +02:00
|
|
|
auto tradeModel
|
|
|
|
= std::make_unique<TradeItemModel>(std::make_unique<ContainerItemModel>(itemSources, worldItems), mPtr);
|
|
|
|
mTradeModel = tradeModel.get();
|
2022-08-31 19:03:45 +02:00
|
|
|
auto sortModel = std::make_unique<SortFilterItemModel>(std::move(tradeModel));
|
|
|
|
mSortModel = sortModel.get();
|
|
|
|
mItemView->setModel(std::move(sortModel));
|
2015-06-04 23:09:40 +03:00
|
|
|
mItemView->resetScrollBars();
|
2012-05-18 17:27:55 +02:00
|
|
|
|
2012-05-17 21:56:16 +02:00
|
|
|
updateLabels();
|
2013-11-16 22:29:40 +01:00
|
|
|
|
2014-05-22 20:37:22 +02:00
|
|
|
setTitle(actor.getClass().getName(actor));
|
2013-11-30 08:33:18 +01:00
|
|
|
|
|
|
|
onFilterChanged(mFilterAll);
|
2020-02-24 18:14:40 +00:00
|
|
|
mFilterEdit->setCaption("");
|
2012-05-17 19:53:04 +02:00
|
|
|
}
|
|
|
|
|
2017-09-23 22:00:15 +02:00
|
|
|
void TradeWindow::onFrame(float dt)
|
|
|
|
{
|
|
|
|
checkReferenceAvailable();
|
|
|
|
}
|
|
|
|
|
2020-02-24 18:14:40 +00:00
|
|
|
void TradeWindow::onNameFilterChanged(MyGUI::EditBox* _sender)
|
|
|
|
{
|
|
|
|
mSortModel->setNameFilter(_sender->getCaption());
|
|
|
|
mItemView->update();
|
|
|
|
}
|
|
|
|
|
2012-05-17 19:53:04 +02:00
|
|
|
void TradeWindow::onFilterChanged(MyGUI::Widget* _sender)
|
|
|
|
{
|
|
|
|
if (_sender == mFilterAll)
|
2013-05-11 18:38:27 +02:00
|
|
|
mSortModel->setCategory(SortFilterItemModel::Category_All);
|
2012-05-17 19:53:04 +02:00
|
|
|
else if (_sender == mFilterWeapon)
|
2013-05-11 18:38:27 +02:00
|
|
|
mSortModel->setCategory(SortFilterItemModel::Category_Weapon);
|
2012-05-17 19:53:04 +02:00
|
|
|
else if (_sender == mFilterApparel)
|
2013-05-11 18:38:27 +02:00
|
|
|
mSortModel->setCategory(SortFilterItemModel::Category_Apparel);
|
2012-05-17 19:53:04 +02:00
|
|
|
else if (_sender == mFilterMagic)
|
2013-05-11 18:38:27 +02:00
|
|
|
mSortModel->setCategory(SortFilterItemModel::Category_Magic);
|
2012-05-17 19:53:04 +02:00
|
|
|
else if (_sender == mFilterMisc)
|
2013-05-11 18:38:27 +02:00
|
|
|
mSortModel->setCategory(SortFilterItemModel::Category_Misc);
|
2012-05-17 19:53:04 +02:00
|
|
|
|
|
|
|
mFilterAll->setStateSelected(false);
|
|
|
|
mFilterWeapon->setStateSelected(false);
|
|
|
|
mFilterApparel->setStateSelected(false);
|
|
|
|
mFilterMagic->setStateSelected(false);
|
|
|
|
mFilterMisc->setStateSelected(false);
|
|
|
|
|
2014-09-13 04:07:40 +02:00
|
|
|
_sender->castType<MyGUI::Button>()->setStateSelected(true);
|
2013-05-11 18:38:27 +02:00
|
|
|
|
|
|
|
mItemView->update();
|
2012-05-17 17:15:44 +02:00
|
|
|
}
|
2012-05-17 21:15:48 +02:00
|
|
|
|
2013-05-11 18:38:27 +02:00
|
|
|
int TradeWindow::getMerchantServices()
|
2012-05-17 21:15:48 +02:00
|
|
|
{
|
2014-05-22 20:37:22 +02:00
|
|
|
return mPtr.getClass().getServices(mPtr);
|
2013-05-11 18:38:27 +02:00
|
|
|
}
|
|
|
|
|
2017-09-23 12:18:39 +02:00
|
|
|
bool TradeWindow::exit()
|
2014-05-26 23:13:37 -04:00
|
|
|
{
|
|
|
|
mTradeModel->abort();
|
|
|
|
MWBase::Environment::get().getWindowManager()->getInventoryWindow()->getTradeModel()->abort();
|
2017-09-23 12:18:39 +02:00
|
|
|
return true;
|
2014-05-26 23:13:37 -04:00
|
|
|
}
|
|
|
|
|
2013-05-11 18:38:27 +02:00
|
|
|
void TradeWindow::onItemSelected(int index)
|
|
|
|
{
|
|
|
|
const ItemStack& item = mSortModel->getItem(index);
|
|
|
|
|
|
|
|
MWWorld::Ptr object = item.mBase;
|
|
|
|
int count = item.mCount;
|
|
|
|
bool shift = MyGUI::InputManager::getInstance().isShiftPressed();
|
|
|
|
if (MyGUI::InputManager::getInstance().isControlPressed())
|
|
|
|
count = 1;
|
|
|
|
|
|
|
|
if (count > 1 && !shift)
|
|
|
|
{
|
|
|
|
CountDialog* dialog = MWBase::Environment::get().getWindowManager()->getCountDialog();
|
|
|
|
std::string message = "#{sQuanityMenuMessage02}";
|
2022-08-16 21:15:03 +02:00
|
|
|
std::string name{ object.getClass().getName(object) };
|
|
|
|
name += MWGui::ToolTips::getSoulString(object.getCellRef());
|
2020-04-10 23:14:00 +03:00
|
|
|
dialog->openCountDialog(name, message, count);
|
2013-05-11 18:38:27 +02:00
|
|
|
dialog->eventOkClicked.clear();
|
|
|
|
dialog->eventOkClicked += MyGUI::newDelegate(this, &TradeWindow::sellItem);
|
|
|
|
mItemToSell = mSortModel->mapToSource(index);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mItemToSell = mSortModel->mapToSource(index);
|
2018-10-09 10:21:12 +04:00
|
|
|
sellItem(nullptr, count);
|
2013-05-11 18:38:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TradeWindow::sellItem(MyGUI::Widget* sender, int count)
|
|
|
|
{
|
|
|
|
const ItemStack& item = mTradeModel->getItem(mItemToSell);
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
const ESM::RefId& sound = item.mBase.getClass().getUpSoundId(item.mBase);
|
2017-07-10 15:48:00 +04:00
|
|
|
MWBase::Environment::get().getWindowManager()->playSound(sound);
|
2013-05-11 18:38:27 +02:00
|
|
|
|
|
|
|
TradeItemModel* playerTradeModel
|
|
|
|
= MWBase::Environment::get().getWindowManager()->getInventoryWindow()->getTradeModel();
|
|
|
|
|
|
|
|
if (item.mType == ItemStack::Type_Barter)
|
|
|
|
{
|
|
|
|
// this was an item borrowed to us by the player
|
|
|
|
mTradeModel->returnItemBorrowedToUs(mItemToSell, count);
|
|
|
|
playerTradeModel->returnItemBorrowedFromUs(mItemToSell, mTradeModel, count);
|
|
|
|
buyFromNpc(item.mBase, count, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// borrow item to player
|
|
|
|
playerTradeModel->borrowItemToUs(mItemToSell, mTradeModel, count);
|
|
|
|
mTradeModel->borrowItemFromUs(mItemToSell, count);
|
|
|
|
buyFromNpc(item.mBase, count, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
MWBase::Environment::get().getWindowManager()->getInventoryWindow()->updateItemView();
|
|
|
|
mItemView->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TradeWindow::borrowItem(int index, size_t count)
|
|
|
|
{
|
|
|
|
TradeItemModel* playerTradeModel
|
|
|
|
= MWBase::Environment::get().getWindowManager()->getInventoryWindow()->getTradeModel();
|
|
|
|
mTradeModel->borrowItemToUs(index, playerTradeModel, count);
|
|
|
|
mItemView->update();
|
|
|
|
sellToNpc(playerTradeModel->getItem(index).mBase, count, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TradeWindow::returnItem(int index, size_t count)
|
|
|
|
{
|
|
|
|
TradeItemModel* playerTradeModel
|
|
|
|
= MWBase::Environment::get().getWindowManager()->getInventoryWindow()->getTradeModel();
|
|
|
|
const ItemStack& item = playerTradeModel->getItem(index);
|
|
|
|
mTradeModel->returnItemBorrowedFromUs(index, playerTradeModel, count);
|
|
|
|
mItemView->update();
|
|
|
|
sellToNpc(item.mBase, count, true);
|
2012-05-17 21:15:48 +02:00
|
|
|
}
|
|
|
|
|
2013-11-21 04:27:53 +01:00
|
|
|
void TradeWindow::addOrRemoveGold(int amount, const MWWorld::Ptr& actor)
|
2012-09-08 18:17:03 -04:00
|
|
|
{
|
2014-05-22 20:37:22 +02:00
|
|
|
MWWorld::ContainerStore& store = actor.getClass().getContainerStore(actor);
|
2012-11-06 11:29:18 +04:00
|
|
|
|
2013-08-13 01:19:33 +02:00
|
|
|
if (amount > 0)
|
2012-09-08 18:17:03 -04:00
|
|
|
{
|
2014-01-08 23:37:46 +01:00
|
|
|
store.add(MWWorld::ContainerStore::sGoldId, amount, actor);
|
2012-09-08 18:17:03 -04:00
|
|
|
}
|
2013-08-13 01:19:33 +02:00
|
|
|
else
|
|
|
|
{
|
2014-01-08 23:37:46 +01:00
|
|
|
store.remove(MWWorld::ContainerStore::sGoldId, -amount, actor);
|
2013-08-13 01:19:33 +02:00
|
|
|
}
|
2012-09-08 18:17:03 -04:00
|
|
|
}
|
|
|
|
|
2012-05-17 21:15:48 +02:00
|
|
|
void TradeWindow::onOfferButtonClicked(MyGUI::Widget* _sender)
|
|
|
|
{
|
2013-05-11 18:38:27 +02:00
|
|
|
TradeItemModel* playerItemModel
|
|
|
|
= MWBase::Environment::get().getWindowManager()->getInventoryWindow()->getTradeModel();
|
|
|
|
|
2012-11-08 23:16:40 +01:00
|
|
|
const MWWorld::Store<ESM::GameSetting>& gmst
|
|
|
|
= MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
|
|
|
|
|
2021-10-05 18:00:53 +00:00
|
|
|
if (mTotalBalance->getValue() == 0)
|
|
|
|
mCurrentBalance = 0;
|
2021-10-12 18:19:19 +02:00
|
|
|
|
2012-05-18 22:06:25 +02:00
|
|
|
// were there any items traded at all?
|
2020-10-13 17:46:32 +02:00
|
|
|
const std::vector<ItemStack>& playerBought = playerItemModel->getItemsBorrowedToUs();
|
|
|
|
const std::vector<ItemStack>& merchantBought = mTradeModel->getItemsBorrowedToUs();
|
2014-04-27 19:03:33 +02:00
|
|
|
if (playerBought.empty() && merchantBought.empty())
|
2012-05-18 22:06:25 +02:00
|
|
|
{
|
|
|
|
// user notification
|
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox("#{sBarterDialog11}");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-21 21:12:39 +12:00
|
|
|
MWWorld::Ptr player = MWMechanics::getPlayer();
|
2014-01-08 23:37:46 +01:00
|
|
|
int playerGold = player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId);
|
|
|
|
|
2012-05-18 22:06:25 +02:00
|
|
|
// check if the player can afford this
|
2014-01-08 23:37:46 +01:00
|
|
|
if (mCurrentBalance < 0 && playerGold < std::abs(mCurrentBalance))
|
2012-05-18 22:06:25 +02:00
|
|
|
{
|
|
|
|
// user notification
|
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox("#{sBarterDialog1}");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if the merchant can afford this
|
2013-03-04 12:21:38 +01:00
|
|
|
if (mCurrentBalance > 0 && getMerchantGold() < mCurrentBalance)
|
2012-05-18 22:06:25 +02:00
|
|
|
{
|
|
|
|
// user notification
|
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox("#{sBarterDialog2}");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-22 13:04:36 +01:00
|
|
|
// check if the player is attempting to sell back an item stolen from this actor
|
2020-10-13 17:46:32 +02:00
|
|
|
for (const ItemStack& itemStack : merchantBought)
|
2014-01-22 13:04:36 +01:00
|
|
|
{
|
2019-03-02 13:27:59 +04:00
|
|
|
if (MWBase::Environment::get().getMechanicsManager()->isItemStolenFrom(
|
|
|
|
itemStack.mBase.getCellRef().getRefId(), mPtr))
|
2014-01-22 13:04:36 +01:00
|
|
|
{
|
2018-08-29 18:38:12 +03:00
|
|
|
std::string msg = gmst.find("sNotifyMessage49")->mValue.getString();
|
2019-05-19 12:33:57 +04:00
|
|
|
msg = Misc::StringUtils::format(msg, itemStack.mBase.getClass().getName(itemStack.mBase));
|
2014-01-22 13:04:36 +01:00
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox(msg);
|
2017-08-14 10:41:37 +04:00
|
|
|
|
2019-03-02 13:27:59 +04:00
|
|
|
MWBase::Environment::get().getMechanicsManager()->confiscateStolenItemToOwner(
|
|
|
|
player, itemStack.mBase, mPtr, itemStack.mCount);
|
2017-08-14 10:41:37 +04:00
|
|
|
|
2014-01-22 13:04:36 +01:00
|
|
|
onCancelButtonClicked(mCancelButton);
|
2017-09-26 23:27:53 +02:00
|
|
|
MWBase::Environment::get().getWindowManager()->exitCurrentGuiMode();
|
2014-01-22 13:04:36 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-04 12:28:47 -04:00
|
|
|
bool offerAccepted = mTrading.haggle(player, mPtr, mCurrentBalance, mCurrentMerchantOffer);
|
2015-02-04 21:18:43 +01:00
|
|
|
|
2016-06-04 12:28:47 -04:00
|
|
|
// apply disposition change if merchant is NPC
|
|
|
|
if (mPtr.getClass().isNpc())
|
|
|
|
{
|
2018-08-29 18:38:12 +03:00
|
|
|
int dispositionDelta = offerAccepted ? gmst.find("iBarterSuccessDisposition")->mValue.getInteger()
|
|
|
|
: gmst.find("iBarterFailDisposition")->mValue.getInteger();
|
2014-05-31 18:28:00 +02:00
|
|
|
|
2018-08-01 17:31:35 +03:00
|
|
|
MWBase::Environment::get().getDialogueManager()->applyBarterDispositionChange(dispositionDelta);
|
2013-05-11 18:38:27 +02:00
|
|
|
}
|
2012-11-08 13:38:20 +01:00
|
|
|
|
2016-06-04 12:28:47 -04:00
|
|
|
// display message on haggle failure
|
|
|
|
if (!offerAccepted)
|
|
|
|
{
|
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox("#{sNotifyMessage9}");
|
|
|
|
return;
|
|
|
|
}
|
2012-11-08 13:38:20 +01:00
|
|
|
|
2013-05-11 18:38:27 +02:00
|
|
|
// make the item transfer
|
2014-09-28 12:18:46 +02:00
|
|
|
mTradeModel->transferItems();
|
|
|
|
playerItemModel->transferItems();
|
2012-05-18 20:53:24 +02:00
|
|
|
|
2013-11-21 04:27:53 +01:00
|
|
|
// transfer the gold
|
2012-09-10 17:44:59 +02:00
|
|
|
if (mCurrentBalance != 0)
|
2013-11-21 04:27:53 +01:00
|
|
|
{
|
2014-01-08 23:37:46 +01:00
|
|
|
addOrRemoveGold(mCurrentBalance, player);
|
2014-03-28 12:01:56 -04:00
|
|
|
mPtr.getClass().getCreatureStats(mPtr).setGoldPool(
|
|
|
|
mPtr.getClass().getCreatureStats(mPtr).getGoldPool() - mCurrentBalance);
|
2013-11-21 04:27:53 +01:00
|
|
|
}
|
2012-05-18 22:21:44 +02:00
|
|
|
|
2017-09-25 18:07:49 +02:00
|
|
|
eventTradeDone();
|
2014-01-03 17:39:57 +01:00
|
|
|
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Item Gold Up"));
|
2013-04-10 00:32:05 -04:00
|
|
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Barter);
|
2012-05-17 21:15:48 +02:00
|
|
|
}
|
|
|
|
|
2017-09-24 13:10:50 +02:00
|
|
|
void TradeWindow::onAccept(MyGUI::EditBox* sender)
|
|
|
|
{
|
|
|
|
onOfferButtonClicked(sender);
|
2018-09-10 12:55:00 +04:00
|
|
|
|
|
|
|
// To do not spam onAccept() again and again
|
|
|
|
MWBase::Environment::get().getWindowManager()->injectKeyRelease(MyGUI::KeyCode::None);
|
2017-09-24 13:10:50 +02:00
|
|
|
}
|
|
|
|
|
2012-05-17 21:15:48 +02:00
|
|
|
void TradeWindow::onCancelButtonClicked(MyGUI::Widget* _sender)
|
|
|
|
{
|
2014-05-26 23:13:37 -04:00
|
|
|
exit();
|
2017-09-23 12:18:39 +02:00
|
|
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Barter);
|
2012-05-17 21:15:48 +02:00
|
|
|
}
|
2012-05-17 21:56:16 +02:00
|
|
|
|
2013-03-04 12:21:38 +01:00
|
|
|
void TradeWindow::onMaxSaleButtonClicked(MyGUI::Widget* _sender)
|
|
|
|
{
|
|
|
|
mCurrentBalance = getMerchantGold();
|
|
|
|
updateLabels();
|
|
|
|
}
|
|
|
|
|
2014-09-11 00:25:09 +02:00
|
|
|
void TradeWindow::addRepeatController(MyGUI::Widget* widget)
|
|
|
|
{
|
2019-05-17 10:49:00 +04:00
|
|
|
MyGUI::ControllerItem* item
|
|
|
|
= MyGUI::ControllerManager::getInstance().createItem(MyGUI::ControllerRepeatClick::getClassTypeName());
|
|
|
|
MyGUI::ControllerRepeatClick* controller = static_cast<MyGUI::ControllerRepeatClick*>(item);
|
|
|
|
controller->eventRepeatClick += newDelegate(this, &TradeWindow::onRepeatClick);
|
2014-09-11 00:25:09 +02:00
|
|
|
MyGUI::ControllerManager::getInstance().addItem(widget, controller);
|
|
|
|
}
|
|
|
|
|
2013-02-10 08:50:36 +04:00
|
|
|
void TradeWindow::onIncreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id)
|
|
|
|
{
|
2014-09-11 00:25:09 +02:00
|
|
|
addRepeatController(_sender);
|
2013-02-10 08:50:36 +04:00
|
|
|
onIncreaseButtonTriggered();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TradeWindow::onDecreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id)
|
|
|
|
{
|
2014-09-11 00:25:09 +02:00
|
|
|
addRepeatController(_sender);
|
2013-02-10 08:50:36 +04:00
|
|
|
onDecreaseButtonTriggered();
|
|
|
|
}
|
|
|
|
|
2014-09-11 00:25:09 +02:00
|
|
|
void TradeWindow::onRepeatClick(MyGUI::Widget* widget, MyGUI::ControllerItem* controller)
|
|
|
|
{
|
|
|
|
if (widget == mIncreaseButton)
|
|
|
|
onIncreaseButtonTriggered();
|
|
|
|
else if (widget == mDecreaseButton)
|
|
|
|
onDecreaseButtonTriggered();
|
|
|
|
}
|
|
|
|
|
2013-02-10 08:50:36 +04:00
|
|
|
void TradeWindow::onBalanceButtonReleased(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id)
|
|
|
|
{
|
2014-09-11 00:25:09 +02:00
|
|
|
MyGUI::ControllerManager::getInstance().removeItem(_sender);
|
2013-02-10 08:50:36 +04:00
|
|
|
}
|
|
|
|
|
2014-09-25 20:28:00 +02:00
|
|
|
void TradeWindow::onBalanceValueChanged(int value)
|
2014-05-31 13:53:36 +02:00
|
|
|
{
|
2021-10-04 08:12:15 +08:00
|
|
|
int previousBalance = mCurrentBalance;
|
|
|
|
|
2014-09-25 20:28:00 +02:00
|
|
|
// Entering a "-" sign inverts the buying/selling state
|
|
|
|
mCurrentBalance = (mCurrentBalance >= 0 ? 1 : -1) * value;
|
|
|
|
updateLabels();
|
|
|
|
|
2021-10-04 20:44:56 +00:00
|
|
|
if (mCurrentBalance == 0)
|
2021-10-04 08:12:15 +08:00
|
|
|
mCurrentBalance = previousBalance;
|
|
|
|
|
2014-09-25 20:28:00 +02:00
|
|
|
if (value != std::abs(value))
|
|
|
|
mTotalBalance->setValue(std::abs(value));
|
2014-05-31 13:53:36 +02:00
|
|
|
}
|
|
|
|
|
2013-02-10 08:50:36 +04:00
|
|
|
void TradeWindow::onIncreaseButtonTriggered()
|
2012-11-08 13:38:20 +01:00
|
|
|
{
|
2014-11-06 03:51:18 +01:00
|
|
|
// prevent overflows, and prevent entering INT_MIN since abs(INT_MIN) is undefined
|
2018-09-20 16:02:26 +04:00
|
|
|
if (mCurrentBalance == std::numeric_limits<int>::max()
|
|
|
|
|| mCurrentBalance == std::numeric_limits<int>::min() + 1)
|
2014-11-06 03:51:18 +01:00
|
|
|
return;
|
2021-10-04 20:44:56 +00:00
|
|
|
if (mTotalBalance->getValue() == 0)
|
|
|
|
mCurrentBalance = 0;
|
2016-04-09 17:49:21 -04:00
|
|
|
if (mCurrentBalance < 0)
|
|
|
|
mCurrentBalance -= 1;
|
|
|
|
else
|
|
|
|
mCurrentBalance += 1;
|
2012-11-08 13:38:20 +01:00
|
|
|
updateLabels();
|
|
|
|
}
|
|
|
|
|
2013-02-10 08:50:36 +04:00
|
|
|
void TradeWindow::onDecreaseButtonTriggered()
|
2012-11-08 13:38:20 +01:00
|
|
|
{
|
2021-10-04 20:44:56 +00:00
|
|
|
if (mTotalBalance->getValue() == 0)
|
|
|
|
mCurrentBalance = 0;
|
2016-04-09 17:49:21 -04:00
|
|
|
if (mCurrentBalance < 0)
|
|
|
|
mCurrentBalance += 1;
|
|
|
|
else
|
|
|
|
mCurrentBalance -= 1;
|
2012-11-08 13:38:20 +01:00
|
|
|
updateLabels();
|
|
|
|
}
|
|
|
|
|
2012-05-17 21:56:16 +02:00
|
|
|
void TradeWindow::updateLabels()
|
|
|
|
{
|
2015-08-21 21:12:39 +12:00
|
|
|
MWWorld::Ptr player = MWMechanics::getPlayer();
|
2014-01-08 23:37:46 +01:00
|
|
|
int playerGold = player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId);
|
2015-01-10 02:50:43 +01:00
|
|
|
mPlayerGold->setCaptionWithReplacing("#{sYourGold} " + MyGUI::utility::toString(playerGold));
|
2012-05-17 21:56:16 +02:00
|
|
|
|
2021-10-04 08:12:15 +08:00
|
|
|
TradeItemModel* playerTradeModel
|
|
|
|
= MWBase::Environment::get().getWindowManager()->getInventoryWindow()->getTradeModel();
|
|
|
|
const std::vector<ItemStack>& playerBorrowed = playerTradeModel->getItemsBorrowedToUs();
|
|
|
|
const std::vector<ItemStack>& merchantBorrowed = mTradeModel->getItemsBorrowedToUs();
|
|
|
|
|
2021-10-04 02:16:01 +00:00
|
|
|
if (playerBorrowed.empty() && merchantBorrowed.empty())
|
|
|
|
{
|
2021-10-04 08:12:15 +08:00
|
|
|
mCurrentBalance = 0;
|
|
|
|
}
|
|
|
|
|
2016-04-09 17:49:21 -04:00
|
|
|
if (mCurrentBalance < 0)
|
2012-05-17 21:56:16 +02:00
|
|
|
{
|
2016-04-09 17:49:21 -04:00
|
|
|
mTotalBalanceLabel->setCaptionWithReplacing("#{sTotalCost}");
|
2012-05-17 21:56:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-09 17:49:21 -04:00
|
|
|
mTotalBalanceLabel->setCaptionWithReplacing("#{sTotalSold}");
|
2012-05-17 21:56:16 +02:00
|
|
|
}
|
2014-09-25 20:28:00 +02:00
|
|
|
|
|
|
|
mTotalBalance->setValue(std::abs(mCurrentBalance));
|
2012-05-17 21:56:16 +02:00
|
|
|
|
2015-01-10 02:50:43 +01:00
|
|
|
mMerchantGold->setCaptionWithReplacing("#{sSellerGold} " + MyGUI::utility::toString(getMerchantGold()));
|
2012-05-17 22:24:47 +02:00
|
|
|
}
|
2012-05-17 21:56:16 +02:00
|
|
|
|
2014-09-22 11:26:16 +02:00
|
|
|
void TradeWindow::updateOffer()
|
2012-05-18 22:06:25 +02:00
|
|
|
{
|
2014-09-22 11:26:16 +02:00
|
|
|
TradeItemModel* playerTradeModel
|
|
|
|
= MWBase::Environment::get().getWindowManager()->getInventoryWindow()->getTradeModel();
|
2013-01-02 18:58:52 +04:00
|
|
|
|
2014-09-22 11:26:16 +02:00
|
|
|
int merchantOffer = 0;
|
|
|
|
|
2019-05-09 20:42:22 +03:00
|
|
|
// The offered price must be capped at 75% of the base price to avoid exploits
|
|
|
|
// connected to buying and selling the same item.
|
|
|
|
// This value has been determined by researching the limitations of the vanilla formula
|
|
|
|
// and may not be sufficient if getBarterOffer behavior has been changed.
|
2020-10-13 17:46:32 +02:00
|
|
|
const std::vector<ItemStack>& playerBorrowed = playerTradeModel->getItemsBorrowedToUs();
|
2019-03-02 13:27:59 +04:00
|
|
|
for (const ItemStack& itemStack : playerBorrowed)
|
2014-09-22 11:26:16 +02:00
|
|
|
{
|
2019-05-09 20:42:22 +03:00
|
|
|
const int basePrice = getEffectiveValue(itemStack.mBase, itemStack.mCount);
|
|
|
|
const int cap
|
|
|
|
= static_cast<int>(std::max(1.f, 0.75f * basePrice)); // Minimum buying price -- 75% of the base
|
|
|
|
const int buyingPrice
|
|
|
|
= MWBase::Environment::get().getMechanicsManager()->getBarterOffer(mPtr, basePrice, true);
|
|
|
|
merchantOffer -= std::max(cap, buyingPrice);
|
2014-09-22 11:26:16 +02:00
|
|
|
}
|
|
|
|
|
2020-10-13 17:46:32 +02:00
|
|
|
const std::vector<ItemStack>& merchantBorrowed = mTradeModel->getItemsBorrowedToUs();
|
2019-03-02 13:27:59 +04:00
|
|
|
for (const ItemStack& itemStack : merchantBorrowed)
|
2014-09-22 11:26:16 +02:00
|
|
|
{
|
2019-05-09 20:42:22 +03:00
|
|
|
const int basePrice = getEffectiveValue(itemStack.mBase, itemStack.mCount);
|
2019-05-13 09:50:32 +03:00
|
|
|
const int cap
|
|
|
|
= static_cast<int>(std::max(1.f, 0.75f * basePrice)); // Maximum selling price -- 75% of the base
|
2019-05-09 20:42:22 +03:00
|
|
|
const int sellingPrice
|
|
|
|
= MWBase::Environment::get().getMechanicsManager()->getBarterOffer(mPtr, basePrice, false);
|
2019-05-19 23:43:40 +03:00
|
|
|
merchantOffer += mPtr.getClass().isNpc() ? std::min(cap, sellingPrice) : sellingPrice;
|
2014-09-22 11:26:16 +02:00
|
|
|
}
|
2012-05-18 22:06:25 +02:00
|
|
|
|
2014-09-22 11:26:16 +02:00
|
|
|
int diff = merchantOffer - mCurrentMerchantOffer;
|
|
|
|
mCurrentMerchantOffer = merchantOffer;
|
|
|
|
mCurrentBalance += diff;
|
2012-05-18 22:06:25 +02:00
|
|
|
updateLabels();
|
|
|
|
}
|
|
|
|
|
2014-09-22 11:26:16 +02:00
|
|
|
void TradeWindow::sellToNpc(const MWWorld::Ptr& item, int count, bool boughtItem)
|
2012-05-18 22:06:25 +02:00
|
|
|
{
|
2014-09-22 11:26:16 +02:00
|
|
|
updateOffer();
|
|
|
|
}
|
2012-05-18 22:06:25 +02:00
|
|
|
|
2014-09-22 11:26:16 +02:00
|
|
|
void TradeWindow::buyFromNpc(const MWWorld::Ptr& item, int count, bool soldItem)
|
|
|
|
{
|
|
|
|
updateOffer();
|
2012-05-18 22:06:25 +02:00
|
|
|
}
|
2012-05-27 01:14:33 +02:00
|
|
|
|
|
|
|
void TradeWindow::onReferenceUnavailable()
|
|
|
|
{
|
|
|
|
// remove both Trade and Dialogue (since you always trade with the NPC/creature that you have previously talked
|
|
|
|
// to)
|
2013-04-10 00:32:05 -04:00
|
|
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Barter);
|
2017-09-26 23:27:53 +02:00
|
|
|
MWBase::Environment::get().getWindowManager()->exitCurrentGuiMode();
|
2012-05-27 01:14:33 +02:00
|
|
|
}
|
2013-03-04 12:21:38 +01:00
|
|
|
|
|
|
|
int TradeWindow::getMerchantGold()
|
|
|
|
{
|
2014-03-28 12:01:56 -04:00
|
|
|
int merchantGold = mPtr.getClass().getCreatureStats(mPtr).getGoldPool();
|
2013-03-04 12:21:38 +01:00
|
|
|
return merchantGold;
|
|
|
|
}
|
2014-03-27 01:23:56 -04:00
|
|
|
|
2014-07-07 23:37:59 +02:00
|
|
|
void TradeWindow::resetReference()
|
|
|
|
{
|
|
|
|
ReferenceInterface::resetReference();
|
2018-10-09 10:21:12 +04:00
|
|
|
mItemView->setModel(nullptr);
|
|
|
|
mTradeModel = nullptr;
|
|
|
|
mSortModel = nullptr;
|
2014-07-07 23:37:59 +02:00
|
|
|
}
|
2020-10-13 17:46:32 +02:00
|
|
|
|
|
|
|
void TradeWindow::onClose()
|
|
|
|
{
|
2020-10-27 18:08:14 +03:00
|
|
|
// Make sure the window was actually closed and not temporarily hidden.
|
|
|
|
if (MWBase::Environment::get().getWindowManager()->containsMode(GM_Barter))
|
|
|
|
return;
|
2020-10-13 17:46:32 +02:00
|
|
|
resetReference();
|
|
|
|
}
|
2021-07-15 22:31:26 +02:00
|
|
|
|
|
|
|
void TradeWindow::onDeleteCustomData(const MWWorld::Ptr& ptr)
|
|
|
|
{
|
|
|
|
if (mTradeModel && mTradeModel->usesContainer(ptr))
|
|
|
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Barter);
|
|
|
|
}
|
2012-05-17 13:36:25 +02:00
|
|
|
}
|