2012-04-15 15:52:39 +00:00
|
|
|
#include "container.hpp"
|
|
|
|
|
|
|
|
#include "window_manager.hpp"
|
|
|
|
#include "widgets.hpp"
|
2012-05-11 14:58:07 +00:00
|
|
|
#include "itemwidget.hpp"
|
2012-04-15 15:52:39 +00:00
|
|
|
|
2012-05-11 09:52:07 +00:00
|
|
|
#include "../mwbase/environment.hpp"
|
2012-04-15 15:52:39 +00:00
|
|
|
#include "../mwworld/manualref.hpp"
|
2012-05-11 14:58:07 +00:00
|
|
|
#include "../mwworld/world.hpp"
|
|
|
|
#include "../mwworld/containerstore.hpp"
|
|
|
|
#include "../mwworld/class.hpp"
|
|
|
|
#include "../mwclass/container.hpp"
|
|
|
|
#include "../mwinput/inputmanager.hpp"
|
|
|
|
|
2012-04-15 15:52:39 +00:00
|
|
|
#include <cmath>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <iterator>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <iostream>
|
2012-05-11 14:58:07 +00:00
|
|
|
|
2012-04-15 15:52:39 +00:00
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
using namespace MWGui;
|
|
|
|
using namespace Widgets;
|
|
|
|
|
|
|
|
|
2012-05-12 11:12:37 +00:00
|
|
|
ContainerBase::ContainerBase(WindowManager& parWindowManager,DragAndDrop* dragAndDrop,std::string guiFile)
|
|
|
|
: WindowBase(guiFile, parWindowManager),
|
2012-05-06 09:04:07 +00:00
|
|
|
mDragAndDrop(dragAndDrop),
|
|
|
|
mContainer()
|
2012-04-15 15:52:39 +00:00
|
|
|
{
|
2012-04-21 18:35:45 +00:00
|
|
|
getWidget(mContainerWidget, "Items");
|
2012-05-12 11:12:37 +00:00
|
|
|
getWidget(mItemView, "ItemView");
|
2012-04-15 15:52:39 +00:00
|
|
|
|
2012-05-12 11:12:37 +00:00
|
|
|
mContainerWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerBase::onContainerClicked);
|
|
|
|
}
|
2012-04-27 18:54:39 +00:00
|
|
|
|
2012-05-12 11:12:37 +00:00
|
|
|
ContainerBase::~ContainerBase()
|
|
|
|
{
|
|
|
|
}
|
2012-05-11 14:58:07 +00:00
|
|
|
|
2012-05-12 11:12:37 +00:00
|
|
|
void ContainerBase::onSelectedItem(MyGUI::Widget* _sender)
|
|
|
|
{
|
|
|
|
if(!mDragAndDrop->mIsOnDragAndDrop)
|
|
|
|
{
|
|
|
|
mDragAndDrop->mIsOnDragAndDrop = true;
|
|
|
|
_sender->detachFromWidget();
|
|
|
|
_sender->attachToWidget(mDragAndDrop->mDragAndDropWidget);
|
2012-05-11 14:58:07 +00:00
|
|
|
|
2012-05-12 11:12:37 +00:00
|
|
|
ItemWidget* item = static_cast<ItemWidget*>(_sender);
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer);
|
|
|
|
for (MWWorld::ContainerStoreIterator iter (containerStore.begin()); iter!=containerStore.end(); ++iter)
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
if(count == item->mPos)
|
|
|
|
{
|
|
|
|
mDragAndDrop->mStore.add(*iter);
|
|
|
|
iter->getRefData().setCount(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//containerStore.
|
|
|
|
//std::cout << mContainerWidget->getParent()->getParent()->getName();
|
|
|
|
_sender->setUserString("drag","on");
|
|
|
|
mDragAndDrop->mDraggedWidget = _sender;
|
|
|
|
mDragAndDrop->mContainerWindow = const_cast<MWGui::ContainerBase*>(this);
|
|
|
|
drawItems();
|
|
|
|
std::cout << "selected!";
|
|
|
|
}
|
2012-04-15 15:52:39 +00:00
|
|
|
}
|
|
|
|
|
2012-05-12 11:12:37 +00:00
|
|
|
void ContainerBase::onContainerClicked(MyGUI::Widget* _sender)
|
2012-04-21 08:51:01 +00:00
|
|
|
{
|
2012-05-12 11:12:37 +00:00
|
|
|
std::cout << "container clicked";
|
|
|
|
if(mDragAndDrop->mIsOnDragAndDrop) //drop widget here
|
|
|
|
{
|
|
|
|
ItemWidget* item = static_cast<ItemWidget*>(mDragAndDrop->mDraggedWidget);
|
|
|
|
std::cout << item->mPos << (*mDragAndDrop->mStore.begin()).getTypeName();
|
2012-05-12 11:30:34 +00:00
|
|
|
if((*item->getUserData<MWWorld::Ptr>()).getContainerStore() == 0) std::cout << "nocontainer!";
|
2012-05-12 11:12:37 +00:00
|
|
|
MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer);
|
|
|
|
containerStore.add(*mDragAndDrop->mStore.begin());
|
|
|
|
mDragAndDrop->mStore.clear();
|
|
|
|
mDragAndDrop->mIsOnDragAndDrop = false;
|
|
|
|
mDragAndDrop->mDraggedWidget->detachFromWidget();
|
|
|
|
mDragAndDrop->mDraggedWidget->attachToWidget(mContainerWidget);
|
|
|
|
mDragAndDrop->mDraggedWidget = 0;
|
|
|
|
mDragAndDrop->mContainerWindow = 0;
|
|
|
|
drawItems();
|
|
|
|
}
|
2012-04-21 08:51:01 +00:00
|
|
|
}
|
2012-05-12 11:12:37 +00:00
|
|
|
|
|
|
|
void ContainerBase::setName(std::string contName)
|
2012-04-15 15:52:39 +00:00
|
|
|
{
|
|
|
|
setText("_Main", contName);
|
2012-05-11 14:58:07 +00:00
|
|
|
adjustWindowCaption();
|
2012-04-15 15:52:39 +00:00
|
|
|
}
|
|
|
|
|
2012-05-12 11:12:37 +00:00
|
|
|
void ContainerBase::open(MWWorld::Ptr container)
|
2012-04-15 15:52:39 +00:00
|
|
|
{
|
2012-05-06 09:04:07 +00:00
|
|
|
mContainer = container;
|
2012-04-15 15:52:39 +00:00
|
|
|
setName(MWWorld::Class::get(container).getName(container));
|
2012-05-06 09:04:07 +00:00
|
|
|
drawItems();
|
|
|
|
setVisible(true);
|
|
|
|
}
|
2012-04-15 15:52:39 +00:00
|
|
|
|
2012-05-12 11:12:37 +00:00
|
|
|
void ContainerBase::drawItems()
|
2012-05-06 09:04:07 +00:00
|
|
|
{
|
2012-05-11 14:27:24 +00:00
|
|
|
while (mContainerWidget->getChildCount())
|
|
|
|
{
|
|
|
|
MyGUI::Gui::getInstance().destroyWidget(mContainerWidget->getChildAt(0));
|
|
|
|
}
|
2012-05-06 09:04:07 +00:00
|
|
|
MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer);
|
2012-04-15 15:52:39 +00:00
|
|
|
|
|
|
|
int x = 4;
|
|
|
|
int y = 4;
|
|
|
|
int count = 0;
|
2012-05-08 10:59:47 +00:00
|
|
|
int index = 0;
|
2012-04-15 15:52:39 +00:00
|
|
|
|
|
|
|
for (MWWorld::ContainerStoreIterator iter (containerStore.begin()); iter!=containerStore.end(); ++iter)
|
|
|
|
{
|
2012-05-08 10:59:47 +00:00
|
|
|
index++;
|
2012-05-06 09:04:07 +00:00
|
|
|
if(iter->getRefData().getCount() > 0)
|
2012-04-15 15:52:39 +00:00
|
|
|
{
|
2012-05-08 10:59:47 +00:00
|
|
|
count++;
|
2012-05-06 09:04:07 +00:00
|
|
|
std::string path = std::string("icons\\");
|
|
|
|
path+=MWWorld::Class::get(*iter).getInventoryIcon(*iter);
|
|
|
|
ItemWidget* image = mContainerWidget->createWidget<ItemWidget>("ImageBox", MyGUI::IntCoord(x, y, 32, 32), MyGUI::Align::Default);
|
|
|
|
MyGUI::TextBox* text = image->createWidget<MyGUI::TextBox>("SandBrightText", MyGUI::IntCoord(x, y, 18, 18), MyGUI::Align::Default, std::string("Label"));
|
2012-05-12 11:12:37 +00:00
|
|
|
image->eventMouseButtonClick += MyGUI::newDelegate(this,&ContainerBase::onSelectedItem);
|
2012-05-12 11:30:34 +00:00
|
|
|
image->setUserString("ToolTipType", "ItemPtr");
|
|
|
|
image->setUserData(*iter);
|
2012-05-08 10:59:47 +00:00
|
|
|
image->mPos = index;
|
|
|
|
x += 36;
|
2012-05-06 09:04:07 +00:00
|
|
|
if(count % 20 == 0)
|
|
|
|
{
|
2012-04-15 15:52:39 +00:00
|
|
|
y += 36;
|
|
|
|
x = 4;
|
|
|
|
count = 0;
|
2012-05-08 10:59:47 +00:00
|
|
|
}
|
2012-04-15 15:52:39 +00:00
|
|
|
|
2012-05-06 09:04:07 +00:00
|
|
|
if(iter->getRefData().getCount() > 1)
|
|
|
|
text->setCaption(boost::lexical_cast<std::string>(iter->getRefData().getCount()));
|
2012-04-15 15:52:39 +00:00
|
|
|
|
2012-05-06 09:04:07 +00:00
|
|
|
int pos = path.rfind(".");
|
|
|
|
path.erase(pos);
|
|
|
|
path.append(".dds");
|
|
|
|
image->setImageTexture(path);
|
|
|
|
}
|
|
|
|
}
|
2012-04-15 15:52:39 +00:00
|
|
|
}
|
|
|
|
|
2012-05-12 11:12:37 +00:00
|
|
|
void ContainerBase::Update()
|
2012-04-15 15:52:39 +00:00
|
|
|
{
|
2012-04-30 11:01:18 +00:00
|
|
|
if(mDragAndDrop->mIsOnDragAndDrop)
|
2012-04-27 18:54:39 +00:00
|
|
|
{
|
2012-04-30 11:01:18 +00:00
|
|
|
if(mDragAndDrop->mDraggedWidget)
|
|
|
|
mDragAndDrop->mDraggedWidget->setPosition(MyGUI::InputManager::getInstance().getMousePosition());
|
|
|
|
else mDragAndDrop->mIsOnDragAndDrop = false; //If this happens, there is a bug.
|
2012-04-15 15:52:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-12 11:12:37 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
ContainerWindow::ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop)
|
|
|
|
: ContainerBase(parWindowManager, dragAndDrop, "openmw_container_window_layout.xml")
|
|
|
|
{
|
|
|
|
getWidget(mTakeButton, "TakeButton");
|
|
|
|
getWidget(mCloseButton, "CloseButton");
|
|
|
|
|
|
|
|
mCloseButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onCloseButtonClicked);
|
|
|
|
mTakeButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onTakeAllButtonClicked);
|
|
|
|
|
|
|
|
setText("CloseButton", MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sClose")->str);
|
|
|
|
setText("TakeButton", MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sTakeAll")->str);
|
|
|
|
|
|
|
|
// adjust buttons size to fit text
|
|
|
|
int closeButtonWidth = mCloseButton->getTextSize().width+24;
|
|
|
|
int takeButtonWidth = mTakeButton->getTextSize().width+24;
|
|
|
|
mCloseButton->setCoord(600-20-closeButtonWidth, mCloseButton->getCoord().top, closeButtonWidth, mCloseButton->getCoord().height);
|
|
|
|
mTakeButton->setCoord(600-20-closeButtonWidth-takeButtonWidth-8, mTakeButton->getCoord().top, takeButtonWidth, mTakeButton->getCoord().height);
|
|
|
|
|
|
|
|
int w = MyGUI::RenderManager::getInstance().getViewSize().width;
|
|
|
|
int h = MyGUI::RenderManager::getInstance().getViewSize().height;
|
|
|
|
setCoord(w-600,h-300,600,300);
|
2012-05-12 11:46:03 +00:00
|
|
|
|
|
|
|
static_cast<MyGUI::Window*>(mMainWidget)->eventWindowChangeCoord += MyGUI::newDelegate(this, &ContainerWindow::onWindowResize);
|
2012-05-12 11:12:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ContainerWindow::~ContainerWindow()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-05-12 11:46:03 +00:00
|
|
|
void ContainerWindow::onWindowResize(MyGUI::Window* window)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-05-11 14:34:36 +00:00
|
|
|
void ContainerWindow::onCloseButtonClicked(MyGUI::Widget* _sender)
|
2012-04-15 19:02:54 +00:00
|
|
|
{
|
2012-04-30 11:01:18 +00:00
|
|
|
if(!mDragAndDrop->mIsOnDragAndDrop)
|
|
|
|
{
|
2012-05-11 09:52:07 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->setGuiMode(GM_Game);
|
2012-04-30 11:01:18 +00:00
|
|
|
setVisible(false);
|
|
|
|
}
|
2012-04-15 15:52:39 +00:00
|
|
|
}
|
|
|
|
|
2012-05-11 14:58:07 +00:00
|
|
|
void ContainerWindow::onTakeAllButtonClicked(MyGUI::Widget* _sender)
|
|
|
|
{
|
|
|
|
if(!mDragAndDrop->mIsOnDragAndDrop)
|
|
|
|
{
|
|
|
|
/// \todo
|
|
|
|
MWBase::Environment::get().getWindowManager()->setGuiMode(GM_Game);
|
|
|
|
setVisible(false);
|
|
|
|
}
|
|
|
|
}
|