Objects can now be selected and follow mouse movements.

actorid
gugus 13 years ago
parent a6419c3596
commit 5603cb312c

@ -17,15 +17,17 @@
#include "../mwworld/containerstore.hpp" #include "../mwworld/containerstore.hpp"
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwinput/inputmanager.hpp"
using namespace MWGui; using namespace MWGui;
using namespace Widgets; using namespace Widgets;
ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment) ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,MyGUI::Widget* dragAndDropWidget)
: WindowBase("openmw_container_window_layout.xml", parWindowManager), : WindowBase("openmw_container_window_layout.xml", parWindowManager),
mEnvironment(environment) mEnvironment(environment),
mDragAndDropWidget(dragAndDropWidget)
{ {
setText("_Main", "Name of Container"); setText("_Main", "Name of Container");
@ -43,17 +45,24 @@ ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Enviro
setText("CloseButton","Close"); setText("CloseButton","Close");
setText("TakeButton","Take All"); setText("TakeButton","Take All");
mIsOnDragAndDrop = false;
mDraggedWidget = 0;
//mContainerWidget->eventMouseItemActivate += MyGUI::newDelegate(this,&ContainerWindow::onSelectedItem); //mContainerWidget->eventMouseItemActivate += MyGUI::newDelegate(this,&ContainerWindow::onSelectedItem);
} }
ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,std::string guiFile) ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,MyGUI::Widget* dragAndDropWidget,std::string guiFile)
: WindowBase(guiFile, parWindowManager), : WindowBase(guiFile, parWindowManager),
mEnvironment(environment) mEnvironment(environment),
mDragAndDropWidget(dragAndDropWidget)
{ {
setText("_Main", "Name of Container"); setText("_Main", "Name of Container");
//center(); //center();
adjustWindowCaption(); adjustWindowCaption();
getWidget(mContainerWidget, "Items"); getWidget(mContainerWidget, "Items");
mIsOnDragAndDrop = false;
mDraggedWidget = 0;
//getWidget(takeButton, "TakeButton"); //getWidget(takeButton, "TakeButton");
//getWidget(closeButton, "CloseButton"); //getWidget(closeButton, "CloseButton");
@ -130,7 +139,7 @@ void ContainerWindow::open(MWWorld::Ptr& container)
MyGUI::ImageBox* image = mContainerWidget->createWidget<MyGUI::ImageBox>("ImageBox", MyGUI::IntCoord(x, y, 32, 32), MyGUI::Align::Default); MyGUI::ImageBox* image = mContainerWidget->createWidget<MyGUI::ImageBox>("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->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)
{ {
@ -159,7 +168,12 @@ void ContainerWindow::open(MWWorld::Ptr& container)
void ContainerWindow::Update() void ContainerWindow::Update()
{ {
if(mIsOnDragAndDrop)
{
if(mDraggedWidget)
mDraggedWidget->setPosition(MyGUI::InputManager::getInstance().getMousePosition());
else mIsOnDragAndDrop = false; //If this happens, there is a bug.
}
} }
void ContainerWindow::onByeClicked(MyGUI::Widget* _sender) void ContainerWindow::onByeClicked(MyGUI::Widget* _sender)
@ -171,17 +185,20 @@ void ContainerWindow::onByeClicked(MyGUI::Widget* _sender)
void ContainerWindow::onSelectedItem(MyGUI::Widget* _sender) void ContainerWindow::onSelectedItem(MyGUI::Widget* _sender)
{ {
mIsOnDragAndDrop = true;
_sender->detachFromWidget(); _sender->detachFromWidget();
_sender->attachToWidget(mContainerWidget->getParent()->getParent()); _sender->attachToWidget(mDragAndDropWidget);
std::cout << mContainerWidget->getParent()->getParent()->getName(); //std::cout << mContainerWidget->getParent()->getParent()->getName();
_sender->setUserString("drag","on"); _sender->setUserString("drag","on");
mDraggedWidget = _sender;
std::cout << "selected!"; std::cout << "selected!";
} }
void ContainerWindow::onMouseMove(MyGUI::Widget* _sender, int _left, int _top) void ContainerWindow::onMouseMove(MyGUI::Widget* _sender, int _left, int _top)
{ {
if(_sender->getUserString("drag") == "on") /*if(_sender->getUserString("drag") == "on")
{ {
_sender->setPosition(_left,_top); _sender->setPosition(_left,_top);
}
}*/
} }

@ -35,8 +35,9 @@ namespace MWGui
class ContainerWindow : public WindowBase class ContainerWindow : public WindowBase
{ {
public: public:
ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment); ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,MyGUI::Widget* dragAndDropWidget);
ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,std::string guiFile); ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,MyGUI::Widget* dragAndDropWidget,
std::string guiFile);
void open(MWWorld::Ptr& container); void open(MWWorld::Ptr& container);
@ -52,7 +53,9 @@ namespace MWGui
MyGUI::ButtonPtr takeButton; MyGUI::ButtonPtr takeButton;
MyGUI::ButtonPtr closeButton; MyGUI::ButtonPtr closeButton;
MyGUI::Widget* mDragAndDropWidget;
bool mIsOnDragAndDrop;
MyGUI::Widget* mDraggedWidget;
void onByeClicked(MyGUI::Widget* _sender); void onByeClicked(MyGUI::Widget* _sender);
void onSelectedItem(MyGUI::Widget* _sender); void onSelectedItem(MyGUI::Widget* _sender);

@ -21,8 +21,8 @@
namespace MWGui namespace MWGui
{ {
InventoryWindow::InventoryWindow(WindowManager& parWindowManager,MWWorld::Environment& environment) InventoryWindow::InventoryWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,MyGUI::Widget* dragAndDropWidget)
:ContainerWindow(parWindowManager,environment,"openmw_inventory_window_layout.xml") :ContainerWindow(parWindowManager,environment,dragAndDropWidget,"openmw_inventory_window_layout.xml")
{ {
} }

@ -24,7 +24,7 @@ namespace MWGui
class InventoryWindow : public MWGui::ContainerWindow class InventoryWindow : public MWGui::ContainerWindow
{ {
public: public:
InventoryWindow(WindowManager& parWindowManager,MWWorld::Environment& environment); InventoryWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,MyGUI::Widget* dragAndDropWidget);
void openInventory(); void openInventory();
}; };

@ -65,7 +65,7 @@ WindowManager::WindowManager(MWWorld::Environment& environment,
// Set up the GUI system // Set up the GUI system
mGuiManager = new OEngine::GUI::MyGUIManager(mOgre->getWindow(), mOgre->getScene(), false, logpath); mGuiManager = new OEngine::GUI::MyGUIManager(mOgre->getWindow(), mOgre->getScene(), false, logpath);
gui = mGuiManager->getGui(); gui = mGuiManager->getGui();
//Register own widgets with MyGUI //Register own widgets with MyGUI
MyGUI::FactoryManager::getInstance().registerFactory<DialogueHistory>("Widget"); MyGUI::FactoryManager::getInstance().registerFactory<DialogueHistory>("Widget");
@ -74,6 +74,9 @@ WindowManager::WindowManager(MWWorld::Environment& environment,
int w = MyGUI::RenderManager::getInstance().getViewSize().width; int w = MyGUI::RenderManager::getInstance().getViewSize().width;
int h = MyGUI::RenderManager::getInstance().getViewSize().height; int h = MyGUI::RenderManager::getInstance().getViewSize().height;
MyGUI::Widget* dragAndDropWidget = gui->createWidgetT("Widget","",0,0,w,h,MyGUI::Align::Default,"DragAndDrop","DragAndDropWidget");
dragAndDropWidget->setVisible(false);
hud = new HUD(w,h, showFPSLevel); hud = new HUD(w,h, showFPSLevel);
menu = new MainMenu(w,h); menu = new MainMenu(w,h);
map = new MapWindow(*this); map = new MapWindow(*this);
@ -82,8 +85,8 @@ WindowManager::WindowManager(MWWorld::Environment& environment,
mJournal = new JournalWindow(*this); mJournal = new JournalWindow(*this);
mMessageBoxManager = new MessageBoxManager(this); mMessageBoxManager = new MessageBoxManager(this);
dialogueWindow = new DialogueWindow(*this,environment); dialogueWindow = new DialogueWindow(*this,environment);
containerWindow = new ContainerWindow(*this,environment); containerWindow = new ContainerWindow(*this,environment,dragAndDropWidget);
mInventoryWindow = new InventoryWindow(*this,environment); mInventoryWindow = new InventoryWindow(*this,environment,dragAndDropWidget);
// The HUD is always on // The HUD is always on
hud->setVisible(true); hud->setVisible(true);
@ -422,6 +425,8 @@ void WindowManager::onDialogueWindowBye()
void WindowManager::onFrame (float frameDuration) void WindowManager::onFrame (float frameDuration)
{ {
mMessageBoxManager->onFrame(frameDuration); mMessageBoxManager->onFrame(frameDuration);
mInventoryWindow->Update();
containerWindow->Update();
} }
const ESMS::ESMStore& WindowManager::getStore() const const ESMS::ESMStore& WindowManager::getStore() const

@ -10,4 +10,5 @@
<Layer name="Popup" overlapped="true" peek="true"/> <Layer name="Popup" overlapped="true" peek="true"/>
<Layer name="Pointer" overlapped="false" peek="false"/> <Layer name="Pointer" overlapped="false" peek="false"/>
<Layer name="Statistic" overlapped="false" peek="false"/> <Layer name="Statistic" overlapped="false" peek="false"/>
<Layer name="DragAndDrop" overlapped="false" peek="true"/>
</MyGUI> </MyGUI>

Loading…
Cancel
Save