1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-22 18:53:52 +00:00

some work for dropping objects.

This commit is contained in:
gugus 2012-04-30 13:01:18 +02:00
parent 5603cb312c
commit 5f8c08b18b
6 changed files with 93 additions and 62 deletions

View file

@ -24,10 +24,10 @@ using namespace MWGui;
using namespace Widgets; using namespace Widgets;
ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,MyGUI::Widget* dragAndDropWidget) ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,DragAndDrop* dragAndDrop)
: WindowBase("openmw_container_window_layout.xml", parWindowManager), : WindowBase("openmw_container_window_layout.xml", parWindowManager),
mEnvironment(environment), mEnvironment(environment),
mDragAndDropWidget(dragAndDropWidget) mDragAndDrop(dragAndDrop)
{ {
setText("_Main", "Name of Container"); setText("_Main", "Name of Container");
@ -42,27 +42,23 @@ ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Enviro
getWidget(closeButton, "CloseButton"); getWidget(closeButton, "CloseButton");
closeButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onByeClicked); closeButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onByeClicked);
mContainerWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onContainerClicked);
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,MyGUI::Widget* dragAndDropWidget,std::string guiFile) ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,DragAndDrop* dragAndDrop,std::string guiFile)
: WindowBase(guiFile, parWindowManager), : WindowBase(guiFile, parWindowManager),
mEnvironment(environment), mEnvironment(environment),
mDragAndDropWidget(dragAndDropWidget) mDragAndDrop(dragAndDrop)
{ {
setText("_Main", "Name of Container"); setText("_Main", "Name of Container");
//center(); //center();
adjustWindowCaption(); adjustWindowCaption();
getWidget(mContainerWidget, "Items"); getWidget(mContainerWidget, "Items");
mContainerWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onContainerClicked);
mIsOnDragAndDrop = false;
mDraggedWidget = 0;
//getWidget(takeButton, "TakeButton"); //getWidget(takeButton, "TakeButton");
//getWidget(closeButton, "CloseButton"); //getWidget(closeButton, "CloseButton");
@ -151,7 +147,7 @@ void ContainerWindow::open(MWWorld::Ptr& container)
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.push_back(image); //mContainerWidgets
int pos = path.rfind("."); int pos = path.rfind(".");
path.erase(pos); path.erase(pos);
@ -168,30 +164,36 @@ void ContainerWindow::open(MWWorld::Ptr& container)
void ContainerWindow::Update() void ContainerWindow::Update()
{ {
if(mIsOnDragAndDrop) if(mDragAndDrop->mIsOnDragAndDrop)
{ {
if(mDraggedWidget) if(mDragAndDrop->mDraggedWidget)
mDraggedWidget->setPosition(MyGUI::InputManager::getInstance().getMousePosition()); mDragAndDrop->mDraggedWidget->setPosition(MyGUI::InputManager::getInstance().getMousePosition());
else mIsOnDragAndDrop = false; //If this happens, there is a bug. else mDragAndDrop->mIsOnDragAndDrop = false; //If this happens, there is a bug.
} }
} }
void ContainerWindow::onByeClicked(MyGUI::Widget* _sender) void ContainerWindow::onByeClicked(MyGUI::Widget* _sender)
{ {
if(!mDragAndDrop->mIsOnDragAndDrop)
{
mEnvironment.mWindowManager->setGuiMode(GM_Game); mEnvironment.mWindowManager->setGuiMode(GM_Game);
setVisible(false); setVisible(false);
}
} }
void ContainerWindow::onSelectedItem(MyGUI::Widget* _sender) void ContainerWindow::onSelectedItem(MyGUI::Widget* _sender)
{ {
mIsOnDragAndDrop = true; if(!mDragAndDrop->mIsOnDragAndDrop)
{
mDragAndDrop->mIsOnDragAndDrop = true;
_sender->detachFromWidget(); _sender->detachFromWidget();
_sender->attachToWidget(mDragAndDropWidget); _sender->attachToWidget(mDragAndDrop->mDragAndDropWidget);
//std::cout << mContainerWidget->getParent()->getParent()->getName(); //std::cout << mContainerWidget->getParent()->getParent()->getName();
_sender->setUserString("drag","on"); _sender->setUserString("drag","on");
mDraggedWidget = _sender; mDragAndDrop->mDraggedWidget = _sender;
mDragAndDrop->mContainerWindow = const_cast<MWGui::ContainerWindow*>(this);
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)
@ -202,3 +204,16 @@ void ContainerWindow::onMouseMove(MyGUI::Widget* _sender, int _left, int _top)
}*/ }*/
} }
void ContainerWindow::onContainerClicked(MyGUI::Widget* _sender)
{
std::cout << "container clicked";
if(mDragAndDrop->mIsOnDragAndDrop) //drop widget here
{
mDragAndDrop->mIsOnDragAndDrop = false;
mDragAndDrop->mDraggedWidget->detachFromWidget();
mDragAndDrop->mDraggedWidget->attachToWidget(mContainerWidget);
mDragAndDrop->mDraggedWidget = 0;
mDragAndDrop->mContainerWindow = 0;
}
}

View file

@ -25,18 +25,26 @@ namespace MyGUI
namespace MWGui namespace MWGui
{ {
class WindowManager; class WindowManager;
class ContainerWindow;
} }
namespace MWGui namespace MWGui
{ {
class DragAndDrop
{
public:
bool mIsOnDragAndDrop;
ContainerWindow* mContainerWindow;
MyGUI::Widget* mDraggedWidget;
MyGUI::Widget* mDragAndDropWidget;
};
class ContainerWindow : public WindowBase class ContainerWindow : public WindowBase
{ {
public: public:
ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,MyGUI::Widget* dragAndDropWidget); ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,DragAndDrop* dragAndDrop);
ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,MyGUI::Widget* dragAndDropWidget, ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,DragAndDrop* dragAndDrop,
std::string guiFile); std::string guiFile);
@ -53,12 +61,11 @@ namespace MWGui
MyGUI::ButtonPtr takeButton; MyGUI::ButtonPtr takeButton;
MyGUI::ButtonPtr closeButton; MyGUI::ButtonPtr closeButton;
MyGUI::Widget* mDragAndDropWidget; DragAndDrop* mDragAndDrop;
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);
void onContainerClicked(MyGUI::Widget* _sender);
void onMouseMove(MyGUI::Widget* _sender, int _left, int _top); void onMouseMove(MyGUI::Widget* _sender, int _left, int _top);
//MWWorld::Ptr& mContainer; //MWWorld::Ptr& mContainer;

View file

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

View file

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

View file

@ -36,7 +36,7 @@ WindowManager::WindowManager(MWWorld::Environment& environment,
, mMessageBoxManager(NULL) , mMessageBoxManager(NULL)
, console(NULL) , console(NULL)
, mJournal(NULL) , mJournal(NULL)
, dialogueWindow(nullptr) , mDialogueWindow(nullptr)
, mCharGen(NULL) , mCharGen(NULL)
, playerClass() , playerClass()
, playerName() , playerName()
@ -77,6 +77,12 @@ WindowManager::WindowManager(MWWorld::Environment& environment,
MyGUI::Widget* dragAndDropWidget = gui->createWidgetT("Widget","",0,0,w,h,MyGUI::Align::Default,"DragAndDrop","DragAndDropWidget"); MyGUI::Widget* dragAndDropWidget = gui->createWidgetT("Widget","",0,0,w,h,MyGUI::Align::Default,"DragAndDrop","DragAndDropWidget");
dragAndDropWidget->setVisible(false); dragAndDropWidget->setVisible(false);
DragAndDrop* mDragAndDrop = new DragAndDrop();
mDragAndDrop->mIsOnDragAndDrop = false;
mDragAndDrop->mDraggedWidget = 0;
mDragAndDrop->mDragAndDropWidget = dragAndDropWidget;
mDragAndDrop->mContainerWindow = 0;
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);
@ -84,9 +90,9 @@ WindowManager::WindowManager(MWWorld::Environment& environment,
console = new Console(w,h, environment, extensions); console = new Console(w,h, environment, extensions);
mJournal = new JournalWindow(*this); mJournal = new JournalWindow(*this);
mMessageBoxManager = new MessageBoxManager(this); mMessageBoxManager = new MessageBoxManager(this);
dialogueWindow = new DialogueWindow(*this,environment); mDialogueWindow = new DialogueWindow(*this,environment);
containerWindow = new ContainerWindow(*this,environment,dragAndDropWidget); mContainerWindow = new ContainerWindow(*this,environment,mDragAndDrop);
mInventoryWindow = new InventoryWindow(*this,environment,dragAndDropWidget); mInventoryWindow = new InventoryWindow(*this,environment,mDragAndDrop);
// The HUD is always on // The HUD is always on
hud->setVisible(true); hud->setVisible(true);
@ -124,10 +130,11 @@ WindowManager::~WindowManager()
delete menu; delete menu;
delete stats; delete stats;
delete mJournal; delete mJournal;
delete dialogueWindow; delete mDialogueWindow;
delete containerWindow; delete mContainerWindow;
delete mInventoryWindow; delete mInventoryWindow;
delete mCharGen; delete mCharGen;
delete mDragAndDrop;
cleanupGarbage(); cleanupGarbage();
} }
@ -186,8 +193,8 @@ void WindowManager::updateVisible()
stats->setVisible(false); stats->setVisible(false);
console->disable(); console->disable();
mJournal->setVisible(false); mJournal->setVisible(false);
dialogueWindow->setVisible(false); mDialogueWindow->setVisible(false);
containerWindow->setVisible(false); mContainerWindow->setVisible(false);
mInventoryWindow->setVisible(false); mInventoryWindow->setVisible(false);
// Mouse is visible whenever we're not in game mode // Mouse is visible whenever we're not in game mode
@ -229,12 +236,12 @@ void WindowManager::updateVisible()
break; break;
} }
case GM_Container: case GM_Container:
containerWindow->setVisible(true); mContainerWindow->setVisible(true);
mInventoryWindow->setVisible(true); mInventoryWindow->setVisible(true);
mInventoryWindow->openInventory(); mInventoryWindow->openInventory();
break; break;
case GM_Dialogue: case GM_Dialogue:
dialogueWindow->open(); mDialogueWindow->open();
break; break;
case GM_InterMessageBox: case GM_InterMessageBox:
if(!mMessageBoxManager->isInteractiveMessageBox()) { if(!mMessageBoxManager->isInteractiveMessageBox()) {
@ -413,11 +420,11 @@ const std::string &WindowManager::getGameSettingString(const std::string &id, co
void WindowManager::onDialogueWindowBye() void WindowManager::onDialogueWindowBye()
{ {
if (dialogueWindow) if (mDialogueWindow)
{ {
//FIXME set some state and stuff? //FIXME set some state and stuff?
//removeDialog(dialogueWindow); //removeDialog(dialogueWindow);
dialogueWindow->setVisible(false); mDialogueWindow->setVisible(false);
} }
setGuiMode(GM_Game); setGuiMode(GM_Game);
} }
@ -426,7 +433,7 @@ void WindowManager::onFrame (float frameDuration)
{ {
mMessageBoxManager->onFrame(frameDuration); mMessageBoxManager->onFrame(frameDuration);
mInventoryWindow->Update(); mInventoryWindow->Update();
containerWindow->Update(); mContainerWindow->Update();
} }
const ESMS::ESMStore& WindowManager::getStore() const const ESMS::ESMStore& WindowManager::getStore() const

View file

@ -63,6 +63,7 @@ namespace MWGui
class JournalWindow; class JournalWindow;
class CharacterCreation; class CharacterCreation;
class ContainerWindow; class ContainerWindow;
class DragAndDrop;
class InventoryWindow; class InventoryWindow;
class TextInputDialog; class TextInputDialog;
class InfoBoxDialog; class InfoBoxDialog;
@ -126,9 +127,9 @@ namespace MWGui
updateVisible(); updateVisible();
} }
MWGui::DialogueWindow* getDialogueWindow() {return dialogueWindow;} MWGui::DialogueWindow* getDialogueWindow() {return mDialogueWindow;}
MWGui::ContainerWindow* getContainerWindow() {return containerWindow;} MWGui::ContainerWindow* getContainerWindow() {return mContainerWindow;}
MyGUI::Gui* getGui() const { return gui; } MyGUI::Gui* getGui() const { return gui; }
@ -203,8 +204,9 @@ namespace MWGui
MessageBoxManager *mMessageBoxManager; MessageBoxManager *mMessageBoxManager;
Console *console; Console *console;
JournalWindow* mJournal; JournalWindow* mJournal;
DialogueWindow *dialogueWindow; DialogueWindow *mDialogueWindow;
ContainerWindow *containerWindow; ContainerWindow *mContainerWindow;
DragAndDrop* mDragAndDrop;
InventoryWindow *mInventoryWindow; InventoryWindow *mInventoryWindow;
CharacterCreation* mCharGen; CharacterCreation* mCharGen;