diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 5ecb2eea8..972c7f2e4 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -26,7 +26,7 @@ add_openmw_dir (mwgui text_input widgets race class birth review window_manager console dialogue dialogue_history window_base stats_window messagebox journalwindow charactercreation map_window window_pinnable_base cursorreplace tooltips scrollwindow bookwindow list - formatting itemwidget inventorywindow container hud + formatting itemwidget inventorywindow container hud countdialog ) add_openmw_dir (mwdialogue diff --git a/apps/openmw/mwgui/class.hpp b/apps/openmw/mwgui/class.hpp index 0e3348086..6f0138aa4 100644 --- a/apps/openmw/mwgui/class.hpp +++ b/apps/openmw/mwgui/class.hpp @@ -34,7 +34,7 @@ namespace MWGui typedef delegates::CMultiDelegate1 EventHandle_Int; /** Event : Button was clicked.\n - signature : void method(MyGUI::WidgetPtr widget, int index)\n + signature : void method(int index)\n */ EventHandle_Int eventButtonSelected; diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 82b695a2b..afcd398a4 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -1,7 +1,12 @@ #include "container.hpp" -#include "window_manager.hpp" -#include "widgets.hpp" +#include +#include +#include +#include +#include + +#include #include "../mwbase/environment.hpp" #include "../mwworld/manualref.hpp" @@ -13,14 +18,9 @@ #include "../mwinput/inputmanager.hpp" #include "../mwsound/soundmanager.hpp" -#include -#include -#include -#include -#include - -#include - +#include "window_manager.hpp" +#include "widgets.hpp" +#include "countdialog.hpp" using namespace MWGui; using namespace Widgets; @@ -49,7 +49,10 @@ void ContainerBase::onSelectedItem(MyGUI::Widget* _sender) { if(!mDragAndDrop->mIsOnDragAndDrop) { - int count = (*_sender->getUserData()).getRefData().getCount(); + mSelectedItem = _sender; + + MWWorld::Ptr object = (*_sender->getUserData()); + int count = object.getRefData().getCount(); if (MWBase::Environment::get().getInputManager()->getShiftDown() || count == 1) { @@ -61,8 +64,10 @@ void ContainerBase::onSelectedItem(MyGUI::Widget* _sender) } else { - /// \todo count selection window - onSelectedItemImpl(_sender, count); + CountDialog* dialog = MWBase::Environment::get().getWindowManager()->getCountDialog(); + dialog->open(MWWorld::Class::get(object).getName(object), count); + dialog->eventOkClicked.clear(); + dialog->eventOkClicked += MyGUI::newDelegate(this, &ContainerBase::onSelectedItemImpl); } } else @@ -72,10 +77,10 @@ void ContainerBase::onSelectedItem(MyGUI::Widget* _sender) void ContainerBase::onSelectedItemImpl(MyGUI::Widget* _sender, int count) { mDragAndDrop->mIsOnDragAndDrop = true; - _sender->detachFromWidget(); - _sender->attachToWidget(mDragAndDrop->mDragAndDropWidget); + mSelectedItem->detachFromWidget(); + mSelectedItem->attachToWidget(mDragAndDrop->mDragAndDropWidget); - MWWorld::Ptr object = *_sender->getUserData(); + MWWorld::Ptr object = *mSelectedItem->getUserData(); int originalCount = object.getRefData().getCount(); object.getRefData().setCount(count); mDragAndDrop->mStore.add(object); @@ -84,9 +89,10 @@ void ContainerBase::onSelectedItemImpl(MyGUI::Widget* _sender, int count) std::string sound = MWWorld::Class::get(object).getUpSoundId(object); MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); - mDragAndDrop->mDraggedWidget = _sender; + mDragAndDrop->mDraggedWidget = mSelectedItem; mDragAndDrop->mContainerWindow = const_cast(this); - static_cast(_sender->getChildAt(0)->getChildAt(0))->setCaption(getCountString((*mDragAndDrop->mStore.begin()).getRefData().getCount())); + static_cast(mSelectedItem->getChildAt(0)->getChildAt(0))->setCaption( + getCountString((*mDragAndDrop->mStore.begin()).getRefData().getCount())); drawItems(); MWBase::Environment::get().getWindowManager()->setDragDrop(true); diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index 5cdc8ef1d..20dc16cca 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -68,6 +68,8 @@ namespace MWGui MyGUI::ScrollView* mItemView; MyGUI::Widget* mContainerWidget; + MyGUI::Widget* mSelectedItem; + DragAndDrop* mDragAndDrop; MWWorld::Ptr mContainer; diff --git a/apps/openmw/mwgui/countdialog.cpp b/apps/openmw/mwgui/countdialog.cpp new file mode 100644 index 000000000..dc7e75e0e --- /dev/null +++ b/apps/openmw/mwgui/countdialog.cpp @@ -0,0 +1,110 @@ +#include "countdialog.hpp" + +#include + +#include "../mwbase/environment.hpp" +#include "../mwworld/world.hpp" + +namespace MWGui +{ + CountDialog::CountDialog(WindowManager& parWindowManager) : + WindowBase("openmw_count_window_layout.xml", parWindowManager) + { + getWidget(mSlider, "CountSlider"); + getWidget(mItemEdit, "ItemEdit"); + getWidget(mItemText, "ItemText"); + getWidget(mLabelText, "LabelText"); + getWidget(mOkButton, "OkButton"); + getWidget(mCancelButton, "CancelButton"); + + mOkButton->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sOk")->str); + mCancelButton->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sCancel")->str); + mLabelText->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sTake")->str); + + mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &CountDialog::onCancelButtonClicked); + mOkButton->eventMouseButtonClick += MyGUI::newDelegate(this, &CountDialog::onOkButtonClicked); + mItemEdit->eventEditTextChange += MyGUI::newDelegate(this, &CountDialog::onEditTextChange); + mSlider->eventScrollChangePosition += MyGUI::newDelegate(this, &CountDialog::onSliderMoved); + } + + void CountDialog::open(const std::string& item, const int maxCount) + { + setVisible(true); + + MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize(); + + mSlider->setScrollRange(maxCount); + mItemText->setCaption(item); + + int width = std::max(mItemText->getTextSize().width + 128, 320); + setCoord(viewSize.width/2 - width/2, + viewSize.height/2 - mMainWidget->getHeight()/2, + width, + mMainWidget->getHeight()); + + // make other gui elements inaccessible while this dialog is open + MyGUI::InputManager::getInstance().addWidgetModal(mMainWidget); + + MyGUI::InputManager::getInstance().setKeyFocusWidget(mItemEdit); + + mSlider->setScrollPosition(maxCount-1); + mItemEdit->setCaption(boost::lexical_cast(maxCount)); + + int okButtonWidth = mOkButton->getTextSize().width + 24; + mOkButton->setCoord(width - 30 - okButtonWidth, + mOkButton->getTop(), + okButtonWidth, + mOkButton->getHeight()); + + int cancelButtonWidth = mCancelButton->getTextSize().width + 24; + mCancelButton->setCoord(width - 30 - okButtonWidth - cancelButtonWidth - 8, + mCancelButton->getTop(), + cancelButtonWidth, + mCancelButton->getHeight()); + } + + void CountDialog::onCancelButtonClicked(MyGUI::Widget* _sender) + { + close(); + } + + void CountDialog::onOkButtonClicked(MyGUI::Widget* _sender) + { + eventOkClicked(NULL, mSlider->getScrollPosition()+1); + + close(); + } + + void CountDialog::onEditTextChange(MyGUI::EditBox* _sender) + { + if (_sender->getCaption() == "") + return; + + unsigned int count; + try + { + count = boost::lexical_cast(_sender->getCaption()); + } + catch (std::bad_cast&) + { + count = 1; + } + if (count > mSlider->getScrollRange()) + { + count = mSlider->getScrollRange(); + } + mSlider->setScrollPosition(count-1); + onSliderMoved(mSlider, count-1); + } + + void CountDialog::onSliderMoved(MyGUI::ScrollBar* _sender, size_t _position) + { + mItemEdit->setCaption(boost::lexical_cast(_position+1)); + } + + void CountDialog::close() + { + setVisible(false); + MyGUI::InputManager::getInstance().removeWidgetModal(mMainWidget); + } +} diff --git a/apps/openmw/mwgui/countdialog.hpp b/apps/openmw/mwgui/countdialog.hpp new file mode 100644 index 000000000..b6c836c9d --- /dev/null +++ b/apps/openmw/mwgui/countdialog.hpp @@ -0,0 +1,39 @@ +#ifndef MWGUI_COUNTDIALOG_H +#define MWGUI_COUNTDIALOG_H + +#include "window_base.hpp" + +namespace MWGui +{ + class CountDialog : public WindowBase + { + public: + CountDialog(WindowManager& parWindowManager); + void open(const std::string& item, const int maxCount); + + typedef MyGUI::delegates::CMultiDelegate2 EventHandle_WidgetInt; + + /** Event : Ok button was clicked.\n + signature : void method(MyGUI::Widget* _sender, int _count)\n + */ + EventHandle_WidgetInt eventOkClicked; + + private: + MyGUI::ScrollBar* mSlider; + MyGUI::EditBox* mItemEdit; + MyGUI::TextBox* mItemText; + MyGUI::TextBox* mLabelText; + MyGUI::Button* mOkButton; + MyGUI::Button* mCancelButton; + + void onCancelButtonClicked(MyGUI::Widget* _sender); + void onOkButtonClicked(MyGUI::Widget* _sender); + void onEditTextChange(MyGUI::EditBox* _sender); + void onSliderMoved(MyGUI::ScrollBar* _sender, size_t _position); + + void close(); + }; + +} + +#endif diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index c93d5303c..a068de7d9 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -14,6 +14,7 @@ #include "list.hpp" #include "hud.hpp" #include "mainmenu.hpp" +#include "countdialog.hpp" #include "../mwmechanics/mechanicsmanager.hpp" #include "../mwinput/inputmanager.hpp" @@ -46,6 +47,7 @@ WindowManager::WindowManager( , mDialogueWindow(nullptr) , mBookWindow(NULL) , mScrollWindow(NULL) + , mCountDialog(NULL) , mCharGen(NULL) , playerClass() , playerName() @@ -112,6 +114,7 @@ WindowManager::WindowManager( mToolTips = new ToolTips(this); mScrollWindow = new ScrollWindow(*this); mBookWindow = new BookWindow(*this); + mCountDialog = new CountDialog(*this); // The HUD is always on hud->setVisible(true); diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index cff93266c..3f5df5789 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -71,6 +71,7 @@ namespace MWGui class InfoBoxDialog; class DialogueWindow; class MessageBoxManager; + class CountDialog; struct ClassPoint { @@ -133,6 +134,7 @@ namespace MWGui MWGui::BookWindow* getBookWindow() {return mBookWindow;} MWGui::ScrollWindow* getScrollWindow() {return mScrollWindow;} + MWGui::CountDialog* getCountDialog() {return mCountDialog;} MyGUI::Gui* getGui() const { return gui; } @@ -223,6 +225,7 @@ namespace MWGui InventoryWindow *mInventoryWindow; ScrollWindow* mScrollWindow; BookWindow* mBookWindow; + CountDialog* mCountDialog; CharacterCreation* mCharGen; diff --git a/files/mygui/CMakeLists.txt b/files/mygui/CMakeLists.txt index ae9ddd395..2ee823d2a 100644 --- a/files/mygui/CMakeLists.txt +++ b/files/mygui/CMakeLists.txt @@ -55,6 +55,7 @@ configure_file("${SDIR}/openmw_tooltips.xml" "${DDIR}/openmw_tooltips.xml" COPYO configure_file("${SDIR}/openmw_scroll_layout.xml" "${DDIR}/openmw_scroll_layout.xml" COPYONLY) configure_file("${SDIR}/openmw_scroll_skin.xml" "${DDIR}/openmw_scroll_skin.xml" COPYONLY) configure_file("${SDIR}/openmw_book_layout.xml" "${DDIR}/openmw_book_layout.xml" COPYONLY) +configure_file("${SDIR}/openmw_count_window_layout.xml" "${DDIR}/openmw_count_window_layout.xml" COPYONLY) configure_file("${SDIR}/atlas1.cfg" "${DDIR}/atlas1.cfg" COPYONLY) configure_file("${SDIR}/smallbars.png" "${DDIR}/smallbars.png" COPYONLY) configure_file("${SDIR}/transparent.png" "${DDIR}/transparent.png" COPYONLY) diff --git a/files/mygui/openmw_count_window_layout.xml b/files/mygui/openmw_count_window_layout.xml new file mode 100644 index 000000000..38ba7644f --- /dev/null +++ b/files/mygui/openmw_count_window_layout.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +