1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-09 12:42:11 +00:00
OpenMW/apps/openmw/mwgui/itemselection.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

69 lines
1.8 KiB
C++
Raw Normal View History

#include "itemselection.hpp"
2015-01-10 01:50:43 +00:00
#include <MyGUI_Button.h>
#include <MyGUI_TextBox.h>
2013-05-11 16:38:27 +00:00
#include "inventoryitemmodel.hpp"
#include "itemview.hpp"
#include "sortfilteritemmodel.hpp"
namespace MWGui
{
2013-05-11 16:38:27 +00:00
ItemSelectionDialog::ItemSelectionDialog(const std::string& label)
: WindowModal("openmw_itemselection_dialog.layout")
2018-10-09 06:21:12 +00:00
, mSortModel(nullptr)
{
2013-05-11 16:38:27 +00:00
getWidget(mItemView, "ItemView");
mItemView->eventItemClicked += MyGUI::newDelegate(this, &ItemSelectionDialog::onSelectedItem);
MyGUI::TextBox* l;
getWidget(l, "Label");
l->setCaptionWithReplacing(label);
MyGUI::Button* cancelButton;
getWidget(cancelButton, "CancelButton");
cancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ItemSelectionDialog::onCancelButtonClicked);
center();
}
2017-09-23 10:18:39 +00:00
bool ItemSelectionDialog::exit()
{
eventDialogCanceled();
2017-09-23 10:18:39 +00:00
return true;
}
2013-05-11 16:38:27 +00:00
void ItemSelectionDialog::openContainer(const MWWorld::Ptr& container)
{
2022-08-31 17:03:45 +00:00
auto sortModel = std::make_unique<SortFilterItemModel>(std::make_unique<InventoryItemModel>(container));
mSortModel = sortModel.get();
mItemView->setModel(std::move(sortModel));
mItemView->resetScrollBars();
2013-05-11 16:38:27 +00:00
}
void ItemSelectionDialog::setCategory(int category)
{
mSortModel->setCategory(category);
mItemView->update();
}
void ItemSelectionDialog::setFilter(int filter)
{
mSortModel->setFilter(filter);
mItemView->update();
}
void ItemSelectionDialog::onSelectedItem(int index)
{
2013-05-11 16:38:27 +00:00
ItemStack item = mSortModel->getItem(index);
eventItemSelected(item.mBase);
}
void ItemSelectionDialog::onCancelButtonClicked(MyGUI::Widget* sender)
{
exit();
}
}