1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-10-22 11:56:35 +00:00

update container window when item is added or removed

This commit is contained in:
Kindi 2025-04-01 13:03:11 +08:00
parent e20d52d23c
commit 0547f09bf0
5 changed files with 23 additions and 2 deletions

View file

@ -160,6 +160,12 @@ namespace MWGui
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mCloseButton);
setTitle(container.getClass().getName(container));
mPtr.getClass().getContainerStore(mPtr).setContListener(this);
}
void ContainerWindow::updateItemView()
{
mItemView->update();
}
void ContainerWindow::resetReference()

View file

@ -6,6 +6,8 @@
#include "itemmodel.hpp"
#include "../mwworld/containerstore.hpp"
namespace MyGUI
{
class Gui;
@ -21,7 +23,7 @@ namespace MWGui
namespace MWGui
{
class ContainerWindow : public WindowBase, public ReferenceInterface
class ContainerWindow : public WindowBase, public ReferenceInterface, public MWWorld::ContainerStoreListener
{
public:
ContainerWindow(DragAndDrop* dragAndDrop);
@ -38,6 +40,11 @@ namespace MWGui
void treatNextOpenAsLoot() { mTreatNextOpenAsLoot = true; }
void updateItemView();
void itemAdded(const MWWorld::ConstPtr& item, int count) override { updateItemView(); }
void itemRemoved(const MWWorld::ConstPtr& item, int count) override { updateItemView(); }
std::string_view getWindowIdForLua() const override { return "Container"; }
private:

View file

@ -91,6 +91,8 @@ namespace MWGui
MWBase::Environment::get().getWindowManager()->setDragDrop(true);
mIsOnDragAndDrop = true;
MWBase::Environment::get().getWindowManager()->getInventoryWindow()->updateItemView();
}
void DragAndDrop::drop(ItemModel* targetModel, ItemView* targetView)

View file

@ -145,6 +145,8 @@ namespace MWGui
auto tradeModel = std::make_unique<TradeItemModel>(std::make_unique<InventoryItemModel>(mPtr), MWWorld::Ptr());
mTradeModel = tradeModel.get();
mPtr.getClass().getInventoryStore(mPtr).setContListener(this);
if (mSortModel) // reuse existing SortModel when possible to keep previous category/filter settings
mSortModel->setSourceModel(std::move(tradeModel));
else

View file

@ -5,6 +5,7 @@
#include "windowpinnablebase.hpp"
#include "../mwrender/characterpreview.hpp"
#include "../mwworld/containerstore.hpp"
#include "../mwworld/ptr.hpp"
namespace osg
@ -30,7 +31,7 @@ namespace MWGui
class DragAndDrop;
class ItemModel;
class InventoryWindow : public WindowPinnableBase
class InventoryWindow : public WindowPinnableBase, public MWWorld::ContainerStoreListener
{
public:
InventoryWindow(DragAndDrop* dragAndDrop, osg::Group* parent, Resource::ResourceSystem* resourceSystem);
@ -62,6 +63,9 @@ namespace MWGui
void setGuiMode(GuiMode mode);
void itemAdded(const MWWorld::ConstPtr& item, int count) override { updateItemView(); }
void itemRemoved(const MWWorld::ConstPtr& item, int count) override { updateItemView(); }
/// Cycle to previous/next weapon
void cycle(bool next);