From ed6ff0a94ac090d3357ee6885c2f4fb309530db6 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 12 May 2012 13:12:37 +0200 Subject: [PATCH] cleanup 3 --- apps/openmw/mwgui/container.cpp | 224 +++++++----------- apps/openmw/mwgui/container.hpp | 40 ++-- apps/openmw/mwgui/inventorywindow.cpp | 2 +- apps/openmw/mwgui/inventorywindow.hpp | 2 +- .../mygui/openmw_container_window_layout.xml | 9 +- .../mygui/openmw_inventory_window_layout.xml | 9 +- files/mygui/openmw_scroll_skin.xml | 1 - 7 files changed, 133 insertions(+), 154 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index b46dfdf53..b4d369806 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -25,108 +25,99 @@ using namespace MWGui; using namespace Widgets; -ContainerWindow::ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop) - : WindowBase("openmw_container_window_layout.xml", parWindowManager), +ContainerBase::ContainerBase(WindowManager& parWindowManager,DragAndDrop* dragAndDrop,std::string guiFile) + : WindowBase(guiFile, parWindowManager), mDragAndDrop(dragAndDrop), mContainer() { - setText("_Main", "Name of Container"); - getWidget(mContainerWidget, "Items"); - getWidget(mTakeButton, "TakeButton"); - getWidget(mCloseButton, "CloseButton"); + getWidget(mItemView, "ItemView"); - mCloseButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onCloseButtonClicked); - mTakeButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onTakeAllButtonClicked); - mContainerWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onContainerClicked); + mContainerWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerBase::onContainerClicked); + static_cast(mMainWidget)->eventWindowChangeCoord += MyGUI::newDelegate(this, &ContainerBase::onWindowResize); +} - setText("CloseButton", MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sClose")->str); - setText("TakeButton", MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sTakeAll")->str); +ContainerBase::~ContainerBase() +{ +} - // 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); +void ContainerBase::onSelectedItem(MyGUI::Widget* _sender) +{ + if(!mDragAndDrop->mIsOnDragAndDrop) + { + mDragAndDrop->mIsOnDragAndDrop = true; + _sender->detachFromWidget(); + _sender->attachToWidget(mDragAndDrop->mDragAndDropWidget); - int w = MyGUI::RenderManager::getInstance().getViewSize().width; - int h = MyGUI::RenderManager::getInstance().getViewSize().height; - setCoord(w-600,h-300,600,300); + ItemWidget* item = static_cast(_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(this); + drawItems(); + std::cout << "selected!"; + } } -ContainerWindow::ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop,std::string guiFile) - : WindowBase(guiFile, parWindowManager), - mDragAndDrop(dragAndDrop), - mContainer() +void ContainerBase::onContainerClicked(MyGUI::Widget* _sender) { - setText("_Main", "Name of Container"); - adjustWindowCaption(); - getWidget(mContainerWidget, "Items"); - mContainerWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onContainerClicked); + std::cout << "container clicked"; + if(mDragAndDrop->mIsOnDragAndDrop) //drop widget here + { + ItemWidget* item = static_cast(mDragAndDrop->mDraggedWidget); + std::cout << item->mPos << (*mDragAndDrop->mStore.begin()).getTypeName(); + if(item->mPtr.getContainerStore() == 0) std::cout << "nocontainer!"; + 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(); + } } -ContainerWindow::~ContainerWindow() + +void ContainerBase::onWindowResize(MyGUI::Window* window) { } -void ContainerWindow::setName(std::string contName) +void ContainerBase::setName(std::string contName) { setText("_Main", contName); adjustWindowCaption(); } - - -void ContainerWindow::open(MWWorld::Ptr container) +void ContainerBase::open(MWWorld::Ptr container) { mContainer = container; setName(MWWorld::Class::get(container).getName(container)); - //MWWorld::ContainerStore* containerStore = container.getContainerStore(); drawItems(); setVisible(true); } -void ContainerWindow::drawItems() +void ContainerBase::drawItems() { while (mContainerWidget->getChildCount()) { MyGUI::Gui::getInstance().destroyWidget(mContainerWidget->getChildAt(0)); } MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); - //mContainerWidget-> - - /*MWWorld::ManualRef furRef (mWindowManager.getStore(), "fur_cuirass"); - furRef.getPtr().getRefData().setCount (5); - MWWorld::ManualRef bukkitRef (mWindowManager.getStore(), "misc_com_bucket_01"); - MWWorld::ManualRef broomRef (mWindowManager.getStore(), "misc_com_broom_01"); - MWWorld::ManualRef goldRef (mWindowManager.getStore(), "gold_100"); - - containerStore.add(furRef.getPtr()); - containerStore.add(furRef.getPtr()); - containerStore.add(furRef.getPtr()); - containerStore.add(broomRef.getPtr()); - containerStore.add(broomRef.getPtr()); - containerStore.add(broomRef.getPtr()); - containerStore.add(broomRef.getPtr()); - containerStore.add(broomRef.getPtr()); - containerStore.add(broomRef.getPtr()); - containerStore.add(broomRef.getPtr()); - containerStore.add(broomRef.getPtr()); - containerStore.add(broomRef.getPtr()); - containerStore.add(broomRef.getPtr()); - containerStore.add(bukkitRef.getPtr()); - containerStore.add(bukkitRef.getPtr()); - containerStore.add(bukkitRef.getPtr()); - containerStore.add(bukkitRef.getPtr()); - containerStore.add(bukkitRef.getPtr()); - containerStore.add(bukkitRef.getPtr()); - containerStore.add(bukkitRef.getPtr()); - containerStore.add(bukkitRef.getPtr()); - containerStore.add(bukkitRef.getPtr()); - containerStore.add(bukkitRef.getPtr()); - containerStore.add(goldRef.getPtr());*/ - - - // ESMS::LiveCellRef *ref = iter->get(); int x = 4; int y = 4; @@ -143,10 +134,9 @@ void ContainerWindow::drawItems() path+=MWWorld::Class::get(*iter).getInventoryIcon(*iter); ItemWidget* image = mContainerWidget->createWidget("ImageBox", MyGUI::IntCoord(x, y, 32, 32), MyGUI::Align::Default); MyGUI::TextBox* text = image->createWidget("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,&ContainerBase::onSelectedItem); image->mPos = index; image->mPtr = *iter; - //image->eventMouseMove += MyGUI::newDelegate(this,&ContainerWindow::onMouseMove); x += 36; if(count % 20 == 0) { @@ -166,7 +156,7 @@ void ContainerWindow::drawItems() } } -void ContainerWindow::Update() +void ContainerBase::Update() { if(mDragAndDrop->mIsOnDragAndDrop) { @@ -176,6 +166,35 @@ void ContainerWindow::Update() } } +// ------------------------------------------------------------------------------------------------ + +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); +} + +ContainerWindow::~ContainerWindow() +{ +} + void ContainerWindow::onCloseButtonClicked(MyGUI::Widget* _sender) { if(!mDragAndDrop->mIsOnDragAndDrop) @@ -194,64 +213,3 @@ void ContainerWindow::onTakeAllButtonClicked(MyGUI::Widget* _sender) setVisible(false); } } - -void ContainerWindow::onSelectedItem(MyGUI::Widget* _sender) -{ - if(!mDragAndDrop->mIsOnDragAndDrop) - { - mDragAndDrop->mIsOnDragAndDrop = true; - _sender->detachFromWidget(); - _sender->attachToWidget(mDragAndDrop->mDragAndDropWidget); - - ItemWidget* item = static_cast(_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(this); - drawItems(); - std::cout << "selected!"; - } -} - -void ContainerWindow::onMouseMove(MyGUI::Widget* _sender, int _left, int _top) -{ - /*if(_sender->getUserString("drag") == "on") - { - _sender->setPosition(_left,_top); - - }*/ -} - -void ContainerWindow::onContainerClicked(MyGUI::Widget* _sender) -{ - std::cout << "container clicked"; - if(mDragAndDrop->mIsOnDragAndDrop) //drop widget here - { - ItemWidget* item = static_cast(mDragAndDrop->mDraggedWidget); - std::cout << item->mPos << (*mDragAndDrop->mStore.begin()).getTypeName(); - if(item->mPtr.getContainerStore() == 0) std::cout << "nocontainer!"; - 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(); - } -} diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index ad029ae80..84b63abc8 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -27,6 +27,7 @@ namespace MWGui { class WindowManager; class ContainerWindow; + class ContainerBase; } @@ -36,44 +37,55 @@ namespace MWGui { public: bool mIsOnDragAndDrop; - ContainerWindow* mContainerWindow; + ContainerBase* mContainerWindow; MyGUI::Widget* mDraggedWidget; MyGUI::Widget* mDragAndDropWidget; MWWorld::ContainerStore mStore; MWWorld::Ptr mItem; }; - class ContainerWindow : public WindowBase + class ContainerBase : public WindowBase { public: - ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop); - ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop, - std::string guiFile); + ContainerBase(WindowManager& parWindowManager, DragAndDrop* dragAndDrop, std::string guiFile); + virtual ~ContainerBase(); void open(MWWorld::Ptr container); void setName(std::string contName); void Update(); + protected: + MyGUI::ScrollView* mItemView; + MyGUI::Widget* mContainerWidget; + + DragAndDrop* mDragAndDrop; + MWWorld::Ptr mContainer; + + void onSelectedItem(MyGUI::Widget* _sender); + void onContainerClicked(MyGUI::Widget* _sender); + void onWindowResize(MyGUI::Window* window); + + void drawItems(); + }; + + class ContainerWindow : public ContainerBase + { + public: + ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop); + virtual ~ContainerWindow(); protected: std::vector mContainerWidgets; - MyGUI::ItemBoxPtr mContainerWidget; - MyGUI::ButtonPtr mTakeButton; - MyGUI::ButtonPtr mCloseButton; - DragAndDrop* mDragAndDrop; + MyGUI::Button* mTakeButton; + MyGUI::Button* mCloseButton; - MWWorld::Ptr mContainer; bool mIsValid;//is in the right GUI Mode - void drawItems(); void onCloseButtonClicked(MyGUI::Widget* _sender); void onTakeAllButtonClicked(MyGUI::Widget* _sender); - void onSelectedItem(MyGUI::Widget* _sender); - void onContainerClicked(MyGUI::Widget* _sender); - void onMouseMove(MyGUI::Widget* _sender, int _left, int _top); }; } #endif // CONTAINER_H diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index cb628ba4a..416be5367 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -22,7 +22,7 @@ namespace MWGui { InventoryWindow::InventoryWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop) - :ContainerWindow(parWindowManager,dragAndDrop,"openmw_inventory_window_layout.xml") + : ContainerBase(parWindowManager,dragAndDrop,"openmw_inventory_window_layout.xml") { } diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp index 21f27b12f..152f8b0d0 100644 --- a/apps/openmw/mwgui/inventorywindow.hpp +++ b/apps/openmw/mwgui/inventorywindow.hpp @@ -21,7 +21,7 @@ namespace MWGui namespace MWGui { - class InventoryWindow : public MWGui::ContainerWindow + class InventoryWindow : public MWGui::ContainerBase { public: InventoryWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop); diff --git a/files/mygui/openmw_container_window_layout.xml b/files/mygui/openmw_container_window_layout.xml index 25156c5a2..9679519d4 100644 --- a/files/mygui/openmw_container_window_layout.xml +++ b/files/mygui/openmw_container_window_layout.xml @@ -3,8 +3,13 @@ - - + + + + + + + diff --git a/files/mygui/openmw_inventory_window_layout.xml b/files/mygui/openmw_inventory_window_layout.xml index 766cacdb1..40d89f221 100644 --- a/files/mygui/openmw_inventory_window_layout.xml +++ b/files/mygui/openmw_inventory_window_layout.xml @@ -3,7 +3,7 @@ - + @@ -14,7 +14,12 @@ - + + + + + + diff --git a/files/mygui/openmw_scroll_skin.xml b/files/mygui/openmw_scroll_skin.xml index 39437d54e..64e467661 100644 --- a/files/mygui/openmw_scroll_skin.xml +++ b/files/mygui/openmw_scroll_skin.xml @@ -4,7 +4,6 @@ -