mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 10:53:53 +00:00
the GUI part of drag and drop is working
This commit is contained in:
parent
60ad6f01d4
commit
e9134717d6
3 changed files with 35 additions and 27 deletions
|
@ -18,26 +18,11 @@
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
#include "../mwworld/class.hpp"
|
#include "../mwworld/class.hpp"
|
||||||
#include "../mwinput/inputmanager.hpp"
|
#include "../mwinput/inputmanager.hpp"
|
||||||
|
#include "itemwidget.hpp"
|
||||||
|
|
||||||
|
|
||||||
using namespace MWGui;
|
using namespace MWGui;
|
||||||
using namespace Widgets;
|
using namespace Widgets;
|
||||||
class ItemWidget: public MyGUI::ImageBox
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ItemWidget()
|
|
||||||
:ImageBox()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
virtual ~ItemWidget()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void setPtr(MWWorld::Ptr &ptr,int pos){mPtr = ptr;mPos = pos;}
|
|
||||||
|
|
||||||
MWWorld::Ptr mPtr;
|
|
||||||
int mPos;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,DragAndDrop* dragAndDrop)
|
ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,DragAndDrop* dragAndDrop)
|
||||||
|
@ -149,39 +134,36 @@ void ContainerWindow::drawItems()
|
||||||
int x = 4;
|
int x = 4;
|
||||||
int y = 4;
|
int y = 4;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
for (MWWorld::ContainerStoreIterator iter (containerStore.begin()); iter!=containerStore.end(); ++iter)
|
for (MWWorld::ContainerStoreIterator iter (containerStore.begin()); iter!=containerStore.end(); ++iter)
|
||||||
{
|
{
|
||||||
count++;
|
index++;
|
||||||
if(iter->getRefData().getCount() > 0)
|
if(iter->getRefData().getCount() > 0)
|
||||||
{
|
{
|
||||||
|
count++;
|
||||||
std::string path = std::string("icons\\");
|
std::string path = std::string("icons\\");
|
||||||
path+=MWWorld::Class::get(*iter).getInventoryIcon(*iter);
|
path+=MWWorld::Class::get(*iter).getInventoryIcon(*iter);
|
||||||
ItemWidget* image = mContainerWidget->createWidget<ItemWidget>("ImageBox", MyGUI::IntCoord(x, y, 32, 32), MyGUI::Align::Default);
|
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"));
|
MyGUI::TextBox* text = image->createWidget<MyGUI::TextBox>("SandBrightText", MyGUI::IntCoord(x, y, 18, 18), MyGUI::Align::Default, std::string("Label"));
|
||||||
image->eventMouseButtonClick += MyGUI::newDelegate(this,&ContainerWindow::onSelectedItem);
|
image->eventMouseButtonClick += MyGUI::newDelegate(this,&ContainerWindow::onSelectedItem);
|
||||||
//image->setPtr(*iter,count);
|
image->mPos = index;
|
||||||
image->mPos = count;
|
image->mPtr = *iter;
|
||||||
|
|
||||||
//image->mPtr = *iter;
|
|
||||||
//image->eventMouseMove += MyGUI::newDelegate(this,&ContainerWindow::onMouseMove);
|
//image->eventMouseMove += MyGUI::newDelegate(this,&ContainerWindow::onMouseMove);
|
||||||
/*x += 36;
|
x += 36;
|
||||||
if(count % 20 == 0)
|
if(count % 20 == 0)
|
||||||
{
|
{
|
||||||
y += 36;
|
y += 36;
|
||||||
x = 4;
|
x = 4;
|
||||||
count = 0;
|
count = 0;
|
||||||
}*/
|
}
|
||||||
|
|
||||||
if(iter->getRefData().getCount() > 1)
|
if(iter->getRefData().getCount() > 1)
|
||||||
text->setCaption(boost::lexical_cast<std::string>(iter->getRefData().getCount()));
|
text->setCaption(boost::lexical_cast<std::string>(iter->getRefData().getCount()));
|
||||||
//mContainerWidgets
|
|
||||||
|
|
||||||
int pos = path.rfind(".");
|
int pos = path.rfind(".");
|
||||||
path.erase(pos);
|
path.erase(pos);
|
||||||
path.append(".dds");
|
path.append(".dds");
|
||||||
//std::cout << path << std::endl;
|
|
||||||
image->setImageTexture(path);
|
image->setImageTexture(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -251,7 +233,13 @@ void ContainerWindow::onContainerClicked(MyGUI::Widget* _sender)
|
||||||
std::cout << "container clicked";
|
std::cout << "container clicked";
|
||||||
if(mDragAndDrop->mIsOnDragAndDrop) //drop widget here
|
if(mDragAndDrop->mIsOnDragAndDrop) //drop widget here
|
||||||
{
|
{
|
||||||
//mContainer.getContainerStore()->add(mDragAndDrop->mDraggedWidget->
|
ItemWidget* item = static_cast<ItemWidget*>(mDragAndDrop->mDraggedWidget);
|
||||||
|
std::cout << item->mPos << item->mPtr.getTypeName();
|
||||||
|
if(item->mPtr.getContainerStore() == 0) std::cout << "nocontainer!";
|
||||||
|
std::cout << item->mPtr.getContainerStore()->getType(item->mPtr);
|
||||||
|
MWWorld::Ptr ptr = item->mPtr;
|
||||||
|
//MWWorld::World
|
||||||
|
//mContainer.getContainerStore()->add(item->mPtr);
|
||||||
mDragAndDrop->mIsOnDragAndDrop = false;
|
mDragAndDrop->mIsOnDragAndDrop = false;
|
||||||
mDragAndDrop->mDraggedWidget->detachFromWidget();
|
mDragAndDrop->mDraggedWidget->detachFromWidget();
|
||||||
mDragAndDrop->mDraggedWidget->attachToWidget(mContainerWidget);
|
mDragAndDrop->mDraggedWidget->attachToWidget(mContainerWidget);
|
||||||
|
|
18
apps/openmw/mwgui/itemwidget.hpp
Normal file
18
apps/openmw/mwgui/itemwidget.hpp
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#ifndef MWGUI_ITEM_WIDGET_H
|
||||||
|
#define MWGUI_ITEM_WIDGET_H
|
||||||
|
#include <openengine/gui/layout.hpp>
|
||||||
|
#include "../mwworld/ptr.hpp"
|
||||||
|
|
||||||
|
namespace MWGui
|
||||||
|
{
|
||||||
|
class ItemWidget: public MyGUI::ImageBox
|
||||||
|
{
|
||||||
|
MYGUI_RTTI_DERIVED( ItemWidget )
|
||||||
|
public:
|
||||||
|
|
||||||
|
MWWorld::Ptr mPtr;
|
||||||
|
int mPos;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -9,6 +9,7 @@
|
||||||
#include "messagebox.hpp"
|
#include "messagebox.hpp"
|
||||||
#include "container.hpp"
|
#include "container.hpp"
|
||||||
#include "inventorywindow.hpp"
|
#include "inventorywindow.hpp"
|
||||||
|
#include "itemwidget.hpp"
|
||||||
|
|
||||||
#include "../mwmechanics/mechanicsmanager.hpp"
|
#include "../mwmechanics/mechanicsmanager.hpp"
|
||||||
#include "../mwinput/inputmanager.hpp"
|
#include "../mwinput/inputmanager.hpp"
|
||||||
|
@ -68,6 +69,7 @@ WindowManager::WindowManager(MWWorld::Environment& environment,
|
||||||
|
|
||||||
//Register own widgets with MyGUI
|
//Register own widgets with MyGUI
|
||||||
MyGUI::FactoryManager::getInstance().registerFactory<DialogueHistory>("Widget");
|
MyGUI::FactoryManager::getInstance().registerFactory<DialogueHistory>("Widget");
|
||||||
|
MyGUI::FactoryManager::getInstance().registerFactory<ItemWidget>("Widget");
|
||||||
|
|
||||||
// Get size info from the Gui object
|
// Get size info from the Gui object
|
||||||
assert(gui);
|
assert(gui);
|
||||||
|
|
Loading…
Reference in a new issue