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

69 lines
1.8 KiB
C++
Raw Normal View History

#include "itemselection.hpp"
2015-01-10 02:50:43 +01:00
#include <MyGUI_Button.h>
2022-09-22 21:26:05 +03:00
#include <MyGUI_TextBox.h>
2015-01-10 02:50:43 +01:00
2013-05-11 18:38:27 +02:00
#include "inventoryitemmodel.hpp"
2022-09-22 21:26:05 +03:00
#include "itemview.hpp"
2013-05-11 18:38:27 +02:00
#include "sortfilteritemmodel.hpp"
namespace MWGui
{
2022-09-22 21:26:05 +03:00
ItemSelectionDialog::ItemSelectionDialog(const std::string& label)
2013-05-11 18:38:27 +02:00
: WindowModal("openmw_itemselection_dialog.layout")
2018-10-09 10:21:12 +04:00
, mSortModel(nullptr)
{
2013-05-11 18:38:27 +02:00
getWidget(mItemView, "ItemView");
mItemView->eventItemClicked += MyGUI::newDelegate(this, &ItemSelectionDialog::onSelectedItem);
MyGUI::TextBox* l;
getWidget(l, "Label");
2022-09-22 21:26:05 +03:00
l->setCaptionWithReplacing(label);
MyGUI::Button* cancelButton;
getWidget(cancelButton, "CancelButton");
cancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ItemSelectionDialog::onCancelButtonClicked);
center();
}
2017-09-23 12:18:39 +02:00
bool ItemSelectionDialog::exit()
{
eventDialogCanceled();
2017-09-23 12:18:39 +02:00
return true;
}
2013-05-11 18:38:27 +02:00
void ItemSelectionDialog::openContainer(const MWWorld::Ptr& container)
{
2022-08-31 19:03:45 +02: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 18:38:27 +02: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 18:38:27 +02:00
ItemStack item = mSortModel->getItem(index);
eventItemSelected(item.mBase);
}
void ItemSelectionDialog::onCancelButtonClicked(MyGUI::Widget* sender)
{
exit();
}
}