1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-11-29 11:34:29 +00:00
openmw/apps/openmw/mwgui/companionwindow.hpp
elsid 463de2d791
Instantly transfer items if alt key is pressed
Support player's inventory, container and companion windows with
dropping and picking up items from the world.

Add ItemTransfer class to handle transfers similar to DragAndDrop. When
a container window is opened the view is added to the set of targets and
removed when closed. If ALT is pressed instead of starting dragging an
item perform a transfer. If there is 1 target which is not a source move
item there. If there is no target drop item into the world using
WorldItemModel.

Special case is picking up an item. Don't start dragging, just update
the player's inventory view because the item is already there.
2025-07-12 13:34:59 +02:00

80 lines
2.2 KiB
C++

#ifndef OPENMW_MWGUI_COMPANIONWINDOW_H
#define OPENMW_MWGUI_COMPANIONWINDOW_H
#include "referenceinterface.hpp"
#include "windowbase.hpp"
#include "../mwworld/containerstore.hpp"
#include <components/misc/notnullptr.hpp>
namespace MWGui
{
namespace Widgets
{
class MWDynamicStat;
}
class MessageBoxManager;
class ItemView;
class DragAndDrop;
class SortFilterItemModel;
class CompanionItemModel;
class ItemTransfer;
class CompanionWindow : public WindowBase, public ReferenceInterface, public MWWorld::ContainerStoreListener
{
public:
explicit CompanionWindow(DragAndDrop& dragAndDrop, ItemTransfer& itemTransfer, MessageBoxManager* manager);
bool exit() override;
void resetReference() override;
void setPtr(const MWWorld::Ptr& actor) override;
void onFrame(float dt) override;
void clear() override { resetReference(); }
void itemAdded(const MWWorld::ConstPtr& item, int count) override;
void itemRemoved(const MWWorld::ConstPtr& item, int count) override;
std::string_view getWindowIdForLua() const override { return "Companion"; }
private:
ItemView* mItemView;
SortFilterItemModel* mSortModel;
CompanionItemModel* mModel;
int mSelectedItem;
bool mUpdateNextFrame;
Misc::NotNullPtr<DragAndDrop> mDragAndDrop;
Misc::NotNullPtr<ItemTransfer> mItemTransfer;
MyGUI::Button* mCloseButton;
MyGUI::EditBox* mFilterEdit;
MyGUI::TextBox* mProfitLabel;
Widgets::MWDynamicStat* mEncumbranceBar;
MessageBoxManager* mMessageBoxManager;
void onItemSelected(int index);
void onNameFilterChanged(MyGUI::EditBox* _sender);
void onBackgroundSelected();
void dragItem(MyGUI::Widget* sender, std::size_t count);
void transferItem(MyGUI::Widget* sender, std::size_t count);
void onMessageBoxButtonClicked(int button);
void updateEncumbranceBar();
void onCloseButtonClicked(MyGUI::Widget* _sender);
void onReferenceUnavailable() override;
void onOpen() override;
void onClose() override;
};
}
#endif