From fab4cfecb13d90e1ac8a8cf7278f82ca78628d48 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 26 Aug 2012 10:52:06 +0200 Subject: [PATCH] some unfinished work on quick keys window --- apps/openmw/CMakeLists.txt | 3 +- apps/openmw/mwgui/class.cpp | 19 +- apps/openmw/mwgui/class.hpp | 8 +- apps/openmw/mwgui/confirmationdialog.cpp | 13 +- apps/openmw/mwgui/confirmationdialog.hpp | 4 +- apps/openmw/mwgui/countdialog.cpp | 15 +- apps/openmw/mwgui/countdialog.hpp | 4 +- apps/openmw/mwgui/itemselection.cpp | 39 +++ apps/openmw/mwgui/itemselection.hpp | 28 +++ apps/openmw/mwgui/mode.hpp | 4 +- apps/openmw/mwgui/quickkeysmenu.cpp | 237 ++++++++++++++++++ apps/openmw/mwgui/quickkeysmenu.hpp | 84 +++++++ apps/openmw/mwgui/window_base.cpp | 23 +- apps/openmw/mwgui/window_base.hpp | 17 +- apps/openmw/mwgui/windowmanagerimp.cpp | 7 + apps/openmw/mwgui/windowmanagerimp.hpp | 2 + apps/openmw/mwinput/inputmanagerimp.cpp | 82 +++++- apps/openmw/mwinput/inputmanagerimp.hpp | 16 ++ files/mygui/CMakeLists.txt | 4 + .../mygui/openmw_itemselection_dialog.layout | 20 ++ .../mygui/openmw_magicselection_dialog.layout | 19 ++ files/mygui/openmw_quickkeys_menu.layout | 38 +++ .../mygui/openmw_quickkeys_menu_assign.layout | 28 +++ 23 files changed, 655 insertions(+), 59 deletions(-) create mode 100644 apps/openmw/mwgui/itemselection.cpp create mode 100644 apps/openmw/mwgui/itemselection.hpp create mode 100644 apps/openmw/mwgui/quickkeysmenu.cpp create mode 100644 apps/openmw/mwgui/quickkeysmenu.hpp create mode 100644 files/mygui/openmw_itemselection_dialog.layout create mode 100644 files/mygui/openmw_magicselection_dialog.layout create mode 100644 files/mygui/openmw_quickkeys_menu.layout create mode 100644 files/mygui/openmw_quickkeys_menu_assign.layout diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 1b4ae209d..fae76dd64 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -28,7 +28,8 @@ add_openmw_dir (mwgui dialogue_history window_base stats_window messagebox journalwindow charactercreation map_window window_pinnable_base cursorreplace tooltips scrollwindow bookwindow list formatting inventorywindow container hud countdialog tradewindow settingswindow - confirmationdialog alchemywindow referenceinterface spellwindow mainmenu + confirmationdialog alchemywindow referenceinterface spellwindow mainmenu quickkeysmenu + itemselection ) add_openmw_dir (mwdialogue diff --git a/apps/openmw/mwgui/class.cpp b/apps/openmw/mwgui/class.cpp index eaf191819..971740b5e 100644 --- a/apps/openmw/mwgui/class.cpp +++ b/apps/openmw/mwgui/class.cpp @@ -695,7 +695,7 @@ void CreateClassDialog::onBackClicked(MyGUI::Widget* _sender) /* SelectSpecializationDialog */ SelectSpecializationDialog::SelectSpecializationDialog(MWBase::WindowManager& parWindowManager) - : WindowBase("openmw_chargen_select_specialization.layout", parWindowManager) + : WindowModal("openmw_chargen_select_specialization.layout", parWindowManager) { // Centre dialog center(); @@ -727,13 +727,10 @@ SelectSpecializationDialog::SelectSpecializationDialog(MWBase::WindowManager& pa cancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SelectSpecializationDialog::onCancelClicked); int buttonWidth = cancelButton->getTextSize().width + 24; cancelButton->setCoord(216 - buttonWidth, 90, buttonWidth, 21); - - MyGUI::InputManager::getInstance().addWidgetModal(mMainWidget); } SelectSpecializationDialog::~SelectSpecializationDialog() { - MyGUI::InputManager::getInstance().removeWidgetModal(mMainWidget); } // widget controls @@ -760,7 +757,7 @@ void SelectSpecializationDialog::onCancelClicked(MyGUI::Widget* _sender) /* SelectAttributeDialog */ SelectAttributeDialog::SelectAttributeDialog(MWBase::WindowManager& parWindowManager) - : WindowBase("openmw_chargen_select_attribute.layout", parWindowManager) + : WindowModal("openmw_chargen_select_attribute.layout", parWindowManager) { // Centre dialog center(); @@ -785,13 +782,10 @@ SelectAttributeDialog::SelectAttributeDialog(MWBase::WindowManager& parWindowMan cancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SelectAttributeDialog::onCancelClicked); int buttonWidth = cancelButton->getTextSize().width + 24; cancelButton->setCoord(186 - buttonWidth, 180, buttonWidth, 21); - - MyGUI::InputManager::getInstance().addWidgetModal(mMainWidget); } SelectAttributeDialog::~SelectAttributeDialog() { - MyGUI::InputManager::getInstance().removeWidgetModal(mMainWidget); } // widget controls @@ -812,7 +806,7 @@ void SelectAttributeDialog::onCancelClicked(MyGUI::Widget* _sender) /* SelectSkillDialog */ SelectSkillDialog::SelectSkillDialog(MWBase::WindowManager& parWindowManager) - : WindowBase("openmw_chargen_select_skill.layout", parWindowManager) + : WindowModal("openmw_chargen_select_skill.layout", parWindowManager) { // Centre dialog center(); @@ -884,12 +878,10 @@ SelectSkillDialog::SelectSkillDialog(MWBase::WindowManager& parWindowManager) int buttonWidth = cancelButton->getTextSize().width + 24; cancelButton->setCoord(447 - buttonWidth, 218, buttonWidth, 21); - MyGUI::InputManager::getInstance().addWidgetModal(mMainWidget); } SelectSkillDialog::~SelectSkillDialog() { - MyGUI::InputManager::getInstance().removeWidgetModal(mMainWidget); } // widget controls @@ -908,7 +900,7 @@ void SelectSkillDialog::onCancelClicked(MyGUI::Widget* _sender) /* DescriptionDialog */ DescriptionDialog::DescriptionDialog(MWBase::WindowManager& parWindowManager) - : WindowBase("openmw_chargen_class_description.layout", parWindowManager) + : WindowModal("openmw_chargen_class_description.layout", parWindowManager) { // Centre dialog center(); @@ -924,13 +916,10 @@ DescriptionDialog::DescriptionDialog(MWBase::WindowManager& parWindowManager) // Make sure the edit box has focus MyGUI::InputManager::getInstance().setKeyFocusWidget(mTextEdit); - - MyGUI::InputManager::getInstance().addWidgetModal(mMainWidget); } DescriptionDialog::~DescriptionDialog() { - MyGUI::InputManager::getInstance().removeWidgetModal(mMainWidget); } // widget controls diff --git a/apps/openmw/mwgui/class.hpp b/apps/openmw/mwgui/class.hpp index 4baceed1e..bcb5c2627 100644 --- a/apps/openmw/mwgui/class.hpp +++ b/apps/openmw/mwgui/class.hpp @@ -134,7 +134,7 @@ namespace MWGui std::string mCurrentClassId; }; - class SelectSpecializationDialog : public WindowBase + class SelectSpecializationDialog : public WindowModal { public: SelectSpecializationDialog(MWBase::WindowManager& parWindowManager); @@ -165,7 +165,7 @@ namespace MWGui ESM::Class::Specialization mSpecializationId; }; - class SelectAttributeDialog : public WindowBase + class SelectAttributeDialog : public WindowModal { public: SelectAttributeDialog(MWBase::WindowManager& parWindowManager); @@ -198,7 +198,7 @@ namespace MWGui ESM::Attribute::AttributeID mAttributeId; }; - class SelectSkillDialog : public WindowBase + class SelectSkillDialog : public WindowModal { public: SelectSkillDialog(MWBase::WindowManager& parWindowManager); @@ -234,7 +234,7 @@ namespace MWGui ESM::Skill::SkillEnum mSkillId; }; - class DescriptionDialog : public WindowBase + class DescriptionDialog : public WindowModal { public: DescriptionDialog(MWBase::WindowManager& parWindowManager); diff --git a/apps/openmw/mwgui/confirmationdialog.cpp b/apps/openmw/mwgui/confirmationdialog.cpp index 1c68da9e5..d22181d60 100644 --- a/apps/openmw/mwgui/confirmationdialog.cpp +++ b/apps/openmw/mwgui/confirmationdialog.cpp @@ -8,7 +8,7 @@ namespace MWGui { ConfirmationDialog::ConfirmationDialog(MWBase::WindowManager& parWindowManager) : - WindowBase("openmw_confirmation_dialog.layout", parWindowManager) + WindowModal("openmw_confirmation_dialog.layout", parWindowManager) { getWidget(mMessage, "Message"); getWidget(mOkButton, "OkButton"); @@ -32,9 +32,6 @@ namespace MWGui center(); - // make other gui elements inaccessible while this dialog is open - MyGUI::InputManager::getInstance().addWidgetModal(mMainWidget); - int okButtonWidth = mOkButton->getTextSize().width + 24; mOkButton->setCoord(mMainWidget->getWidth() - 30 - okButtonWidth, mOkButton->getTop(), @@ -52,19 +49,13 @@ namespace MWGui { eventCancelClicked(); - close(); + setVisible(false); } void ConfirmationDialog::onOkButtonClicked(MyGUI::Widget* _sender) { eventOkClicked(); - close(); - } - - void ConfirmationDialog::close() - { setVisible(false); - MyGUI::InputManager::getInstance().removeWidgetModal(mMainWidget); } } diff --git a/apps/openmw/mwgui/confirmationdialog.hpp b/apps/openmw/mwgui/confirmationdialog.hpp index a78028b1c..45941f2ad 100644 --- a/apps/openmw/mwgui/confirmationdialog.hpp +++ b/apps/openmw/mwgui/confirmationdialog.hpp @@ -5,7 +5,7 @@ namespace MWGui { - class ConfirmationDialog : public WindowBase + class ConfirmationDialog : public WindowModal { public: ConfirmationDialog(MWBase::WindowManager& parWindowManager); @@ -26,8 +26,6 @@ namespace MWGui void onCancelButtonClicked(MyGUI::Widget* _sender); void onOkButtonClicked(MyGUI::Widget* _sender); - - void close(); }; } diff --git a/apps/openmw/mwgui/countdialog.cpp b/apps/openmw/mwgui/countdialog.cpp index 6d9415354..0ed9cf8ca 100644 --- a/apps/openmw/mwgui/countdialog.cpp +++ b/apps/openmw/mwgui/countdialog.cpp @@ -8,7 +8,7 @@ namespace MWGui { CountDialog::CountDialog(MWBase::WindowManager& parWindowManager) : - WindowBase("openmw_count_window.layout", parWindowManager) + WindowModal("openmw_count_window.layout", parWindowManager) { getWidget(mSlider, "CountSlider"); getWidget(mItemEdit, "ItemEdit"); @@ -40,9 +40,6 @@ namespace MWGui 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); @@ -63,14 +60,14 @@ namespace MWGui void CountDialog::onCancelButtonClicked(MyGUI::Widget* _sender) { - close(); + setVisible(false); } void CountDialog::onOkButtonClicked(MyGUI::Widget* _sender) { eventOkClicked(NULL, mSlider->getScrollPosition()+1); - close(); + setVisible(false); } void CountDialog::onEditTextChange(MyGUI::EditBox* _sender) @@ -99,10 +96,4 @@ namespace MWGui { 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 index 6002dadfe..80da6eea0 100644 --- a/apps/openmw/mwgui/countdialog.hpp +++ b/apps/openmw/mwgui/countdialog.hpp @@ -5,7 +5,7 @@ namespace MWGui { - class CountDialog : public WindowBase + class CountDialog : public WindowModal { public: CountDialog(MWBase::WindowManager& parWindowManager); @@ -30,8 +30,6 @@ namespace MWGui void onOkButtonClicked(MyGUI::Widget* _sender); void onEditTextChange(MyGUI::EditBox* _sender); void onSliderMoved(MyGUI::ScrollBar* _sender, size_t _position); - - void close(); }; } diff --git a/apps/openmw/mwgui/itemselection.cpp b/apps/openmw/mwgui/itemselection.cpp new file mode 100644 index 000000000..14b1cf8ee --- /dev/null +++ b/apps/openmw/mwgui/itemselection.cpp @@ -0,0 +1,39 @@ +#include "itemselection.hpp" + +namespace MWGui +{ + + ItemSelectionDialog::ItemSelectionDialog(const std::string &label, ContainerBase::Filter filter, MWBase::WindowManager& parWindowManager) + : ContainerBase(NULL) + , WindowModal("openmw_itemselection_dialog.layout", parWindowManager) + { + mFilter = filter; + + MyGUI::ScrollView* itemView; + MyGUI::Widget* containerWidget; + getWidget(containerWidget, "Items"); + getWidget(itemView, "ItemView"); + setWidgets(containerWidget, itemView); + + MyGUI::TextBox* l; + getWidget(l, "Label"); + l->setCaptionWithReplacing (label); + + MyGUI::Button* cancelButton; + getWidget(cancelButton, "CancelButton"); + cancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ItemSelectionDialog::onCancelButtonClicked); + + center(); + } + + void ItemSelectionDialog::onSelectedItemImpl(MWWorld::Ptr item) + { + eventItemSelected(item); + } + + void ItemSelectionDialog::onCancelButtonClicked(MyGUI::Widget* sender) + { + eventDialogCanceled(); + } + +} diff --git a/apps/openmw/mwgui/itemselection.hpp b/apps/openmw/mwgui/itemselection.hpp new file mode 100644 index 000000000..cab125f1f --- /dev/null +++ b/apps/openmw/mwgui/itemselection.hpp @@ -0,0 +1,28 @@ +#include "container.hpp" + +#include "../mwworld/ptr.hpp" + +namespace MWGui +{ + + class ItemSelectionDialog : public ContainerBase, public WindowModal + { + public: + ItemSelectionDialog(const std::string& label, ContainerBase::Filter filter, MWBase::WindowManager& parWindowManager); + + typedef MyGUI::delegates::CMultiDelegate0 EventHandle_Void; + typedef MyGUI::delegates::CMultiDelegate1 EventHandle_Item; + + EventHandle_Item eventItemSelected; + EventHandle_Void eventDialogCanceled; + + + private: + virtual void onReferenceUnavailable() { ; } + + virtual void onSelectedItemImpl(MWWorld::Ptr item); + + void onCancelButtonClicked(MyGUI::Widget* sender); + }; + +} diff --git a/apps/openmw/mwgui/mode.hpp b/apps/openmw/mwgui/mode.hpp index 8b502ce7c..2d6f69871 100644 --- a/apps/openmw/mwgui/mode.hpp +++ b/apps/openmw/mwgui/mode.hpp @@ -32,7 +32,9 @@ namespace MWGui GM_Review, // interactive MessageBox - GM_InterMessageBox + GM_InterMessageBox, + + GM_QuickKeysMenu }; // Windows shown in inventory mode diff --git a/apps/openmw/mwgui/quickkeysmenu.cpp b/apps/openmw/mwgui/quickkeysmenu.cpp new file mode 100644 index 000000000..a9aa3e616 --- /dev/null +++ b/apps/openmw/mwgui/quickkeysmenu.cpp @@ -0,0 +1,237 @@ +#include "quickkeysmenu.hpp" + +#include + +#include "../mwbase/environment.hpp" +#include "../mwbase/world.hpp" +#include "../mwworld/player.hpp" + +#include "windowmanagerimp.hpp" +#include "itemselection.hpp" + +namespace MWGui +{ + + QuickKeysMenu::QuickKeysMenu(MWBase::WindowManager& parWindowManager) + : WindowBase("openmw_quickkeys_menu.layout", parWindowManager) + , mAssignDialog(0) + , mItemSelectionDialog(0) + , mMagicSelectionDialog(0) + { + getWidget(mOkButton, "OKButton"); + getWidget(mInstructionLabel, "InstructionLabel"); + + mMainWidget->setSize(mMainWidget->getWidth(), + mMainWidget->getHeight() + (mInstructionLabel->getTextSize().height - mInstructionLabel->getHeight())); + + int okButtonWidth = mOkButton->getTextSize ().width + 24; + mOkButton->setCoord(mOkButton->getLeft() - (okButtonWidth - mOkButton->getWidth()), + mOkButton->getTop(), + okButtonWidth, + mOkButton->getHeight()); + mOkButton->eventMouseButtonClick += MyGUI::newDelegate(this, &QuickKeysMenu::onOkButtonClicked); + + center(); + + + for (int i = 0; i < 10; ++i) + { + MyGUI::Button* button; + getWidget(button, "QuickKey" + boost::lexical_cast(i+1)); + + if (i != 9) // 10th quick key is always set to hand-to-hand + button->eventMouseButtonClick += MyGUI::newDelegate(this, &QuickKeysMenu::onQuickKeyButtonClicked); + + unassign(button, i); + + mQuickKeyButtons.push_back(button); + + } + } + + QuickKeysMenu::~QuickKeysMenu() + { + delete mAssignDialog; + } + + void QuickKeysMenu::unassign(MyGUI::Widget* key, int index) + { + while (key->getChildCount ()) + MyGUI::Gui::getInstance ().destroyWidget (key->getChildAt(0)); + + MyGUI::TextBox* textBox = key->createWidgetReal("SandText", MyGUI::FloatCoord(0,0,1,1), MyGUI::Align::Default); + textBox->setTextAlign (MyGUI::Align::Center); + textBox->setCaption (boost::lexical_cast(index+1)); + textBox->setNeedMouseFocus (false); + } + + void QuickKeysMenu::onQuickKeyButtonClicked(MyGUI::Widget* sender) + { + int index = -1; + for (int i = 0; i < 10; ++i) + { + if (sender == mQuickKeyButtons[i] || sender->getParent () == mQuickKeyButtons[i]) + { + index = i; + break; + } + } + assert(index != -1); + mSelectedIndex = index; + + { + // open assign dialog + if (!mAssignDialog) + mAssignDialog = new QuickKeysMenuAssign(mWindowManager, this); + mAssignDialog->setVisible (true); + } + } + + void QuickKeysMenu::onOkButtonClicked (MyGUI::Widget *sender) + { + mWindowManager.removeGuiMode(GM_QuickKeysMenu); + } + + + void QuickKeysMenu::onItemButtonClicked(MyGUI::Widget* sender) + { + if (!mItemSelectionDialog ) + { + mItemSelectionDialog = new ItemSelectionDialog("#{sQuickMenu6}", ContainerBase::Filter_All, mWindowManager); + mItemSelectionDialog->eventItemSelected += MyGUI::newDelegate(this, &QuickKeysMenu::onAssignItem); + mItemSelectionDialog->eventDialogCanceled += MyGUI::newDelegate(this, &QuickKeysMenu::onAssignItemCancel); + } + mItemSelectionDialog->setVisible(true); + mItemSelectionDialog->openContainer(MWBase::Environment::get().getWorld()->getPlayer().getPlayer()); + mItemSelectionDialog->drawItems (); + + mAssignDialog->setVisible (false); + } + + void QuickKeysMenu::onMagicButtonClicked(MyGUI::Widget* sender) + { + if (!mMagicSelectionDialog ) + { + mMagicSelectionDialog = new MagicSelectionDialog(mWindowManager, this); + } + mMagicSelectionDialog->setVisible(true); + + mAssignDialog->setVisible (false); + } + + void QuickKeysMenu::onUnassignButtonClicked(MyGUI::Widget* sender) + { + unassign(mQuickKeyButtons[mSelectedIndex], mSelectedIndex); + mAssignDialog->setVisible (false); + } + + void QuickKeysMenu::onCancelButtonClicked(MyGUI::Widget* sender) + { + mAssignDialog->setVisible (false); + } + + void QuickKeysMenu::onAssignItem(MWWorld::Ptr item) + { + MyGUI::Button* button = mQuickKeyButtons[mSelectedIndex]; + while (button->getChildCount ()) + MyGUI::Gui::getInstance ().destroyWidget (button->getChildAt(0)); + + MyGUI::ImageBox* image = button->createWidget("ImageBox", MyGUI::IntCoord(9, 8, 42, 42), MyGUI::Align::Default); + image->setUserString ("ToolTipType", "ItemPtr"); + image->setUserData(item); + std::string path = std::string("icons\\"); + path += MWWorld::Class::get(item).getInventoryIcon(item); + int pos = path.rfind("."); + path.erase(pos); + path.append(".dds"); + image->setImageTexture (path); + image->eventMouseButtonClick += MyGUI::newDelegate(this, &QuickKeysMenu::onQuickKeyButtonClicked); + + mItemSelectionDialog->setVisible(false); + } + + void QuickKeysMenu::onAssignItemCancel() + { + mItemSelectionDialog->setVisible(false); + } + + void QuickKeysMenu::onAssignMagicItem (MWWorld::Ptr item) + { + + } + + void QuickKeysMenu::onAssignMagic (const std::string& spellId) + { + + } + + void QuickKeysMenu::onAssignMagicCancel () + { + mMagicSelectionDialog->setVisible(false); + } + + // --------------------------------------------------------------------------------------------------------- + + QuickKeysMenuAssign::QuickKeysMenuAssign (MWBase::WindowManager &parWindowManager, QuickKeysMenu* parent) + : WindowModal("openmw_quickkeys_menu_assign.layout", parWindowManager) + , mParent(parent) + { + getWidget(mLabel, "Label"); + getWidget(mItemButton, "ItemButton"); + getWidget(mMagicButton, "MagicButton"); + getWidget(mUnassignButton, "UnassignButton"); + getWidget(mCancelButton, "CancelButton"); + + mItemButton->eventMouseButtonClick += MyGUI::newDelegate(mParent, &QuickKeysMenu::onItemButtonClicked); + mMagicButton->eventMouseButtonClick += MyGUI::newDelegate(mParent, &QuickKeysMenu::onMagicButtonClicked); + mUnassignButton->eventMouseButtonClick += MyGUI::newDelegate(mParent, &QuickKeysMenu::onUnassignButtonClicked); + mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(mParent, &QuickKeysMenu::onCancelButtonClicked); + + + int maxWidth = mItemButton->getTextSize ().width + 24; + maxWidth = std::max(maxWidth, mMagicButton->getTextSize ().width + 24); + maxWidth = std::max(maxWidth, mUnassignButton->getTextSize ().width + 24); + maxWidth = std::max(maxWidth, mCancelButton->getTextSize ().width + 24); + + mMainWidget->setSize(maxWidth + 24, mMainWidget->getHeight()); + mLabel->setSize(maxWidth, mLabel->getHeight()); + + mItemButton->setCoord((maxWidth - mItemButton->getTextSize().width-24)/2 + 8, + mItemButton->getTop(), + mItemButton->getTextSize().width + 24, + mItemButton->getHeight()); + mMagicButton->setCoord((maxWidth - mMagicButton->getTextSize().width-24)/2 + 8, + mMagicButton->getTop(), + mMagicButton->getTextSize().width + 24, + mMagicButton->getHeight()); + mUnassignButton->setCoord((maxWidth - mUnassignButton->getTextSize().width-24)/2 + 8, + mUnassignButton->getTop(), + mUnassignButton->getTextSize().width + 24, + mUnassignButton->getHeight()); + mCancelButton->setCoord((maxWidth - mCancelButton->getTextSize().width-24)/2 + 8, + mCancelButton->getTop(), + mCancelButton->getTextSize().width + 24, + mCancelButton->getHeight()); + + center(); + } + + + // --------------------------------------------------------------------------------------------------------- + + MagicSelectionDialog::MagicSelectionDialog(MWBase::WindowManager &parWindowManager, QuickKeysMenu* parent) + : WindowModal("openmw_magicselection_dialog.layout", parWindowManager) + , mParent(parent) + { + getWidget(mCancelButton, "CancelButton"); + mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &MagicSelectionDialog::onCancelButtonClicked); + + center(); + } + + void MagicSelectionDialog::onCancelButtonClicked (MyGUI::Widget *sender) + { + mParent->onAssignMagicCancel (); + } + +} diff --git a/apps/openmw/mwgui/quickkeysmenu.hpp b/apps/openmw/mwgui/quickkeysmenu.hpp new file mode 100644 index 000000000..496806109 --- /dev/null +++ b/apps/openmw/mwgui/quickkeysmenu.hpp @@ -0,0 +1,84 @@ +#ifndef MWGUI_QUICKKEYS_H +#define MWGUI_QUICKKEYS_H + + +#include "../mwworld/ptr.hpp" + +#include "window_base.hpp" + +namespace MWGui +{ + + class QuickKeysMenuAssign; + class ItemSelectionDialog; + class MagicSelectionDialog; + + class QuickKeysMenu : public WindowBase + { + public: + QuickKeysMenu(MWBase::WindowManager& parWindowManager); + ~QuickKeysMenu(); + + + void onItemButtonClicked(MyGUI::Widget* sender); + void onMagicButtonClicked(MyGUI::Widget* sender); + void onUnassignButtonClicked(MyGUI::Widget* sender); + void onCancelButtonClicked(MyGUI::Widget* sender); + + void onAssignItem (MWWorld::Ptr item); + void onAssignItemCancel (); + void onAssignMagicItem (MWWorld::Ptr item); + void onAssignMagic (const std::string& spellId); + void onAssignMagicCancel (); + + + private: + MyGUI::EditBox* mInstructionLabel; + MyGUI::Button* mOkButton; + + std::vector mQuickKeyButtons; + + QuickKeysMenuAssign* mAssignDialog; + ItemSelectionDialog* mItemSelectionDialog; + MagicSelectionDialog* mMagicSelectionDialog; + + int mSelectedIndex; + + + void onQuickKeyButtonClicked(MyGUI::Widget* sender); + void onOkButtonClicked(MyGUI::Widget* sender); + + void unassign(MyGUI::Widget* key, int index); + }; + + class QuickKeysMenuAssign : public WindowModal + { + public: + QuickKeysMenuAssign(MWBase::WindowManager& parWindowManager, QuickKeysMenu* parent); + + private: + MyGUI::TextBox* mLabel; + MyGUI::Button* mItemButton; + MyGUI::Button* mMagicButton; + MyGUI::Button* mUnassignButton; + MyGUI::Button* mCancelButton; + + QuickKeysMenu* mParent; + }; + + class MagicSelectionDialog : public WindowModal + { + public: + MagicSelectionDialog(MWBase::WindowManager& parWindowManager, QuickKeysMenu* parent); + + private: + MyGUI::Button* mCancelButton; + + QuickKeysMenu* mParent; + + void onCancelButtonClicked (MyGUI::Widget* sender); + }; +} + + +#endif diff --git a/apps/openmw/mwgui/window_base.cpp b/apps/openmw/mwgui/window_base.cpp index dbb37efbb..38bee9ea3 100644 --- a/apps/openmw/mwgui/window_base.cpp +++ b/apps/openmw/mwgui/window_base.cpp @@ -12,17 +12,15 @@ WindowBase::WindowBase(const std::string& parLayout, MWBase::WindowManager& parW { } -void WindowBase::open() -{ -} - void WindowBase::setVisible(bool visible) { bool wasVisible = mMainWidget->getVisible(); mMainWidget->setVisible(visible); - if (!wasVisible && visible) + if (visible) open(); + else if (wasVisible && !visible) + close(); } void WindowBase::center() @@ -40,3 +38,18 @@ void WindowBase::center() coord.top = (gameWindowSize.height - coord.height)/2; mMainWidget->setCoord(coord); } + +WindowModal::WindowModal(const std::string& parLayout, MWBase::WindowManager& parWindowManager) + : WindowBase(parLayout, parWindowManager) +{ +} + +void WindowModal::open() +{ + MyGUI::InputManager::getInstance ().addWidgetModal (mMainWidget); +} + +void WindowModal::close() +{ + MyGUI::InputManager::getInstance ().removeWidgetModal (mMainWidget); +} diff --git a/apps/openmw/mwgui/window_base.hpp b/apps/openmw/mwgui/window_base.hpp index 74d874bb8..afdf4d065 100644 --- a/apps/openmw/mwgui/window_base.hpp +++ b/apps/openmw/mwgui/window_base.hpp @@ -20,8 +20,9 @@ namespace MWGui // Events typedef MyGUI::delegates::CMultiDelegate1 EventHandle_WindowBase; - virtual void open(); - virtual void setVisible(bool visible); // calls open() if visible is true and was false before + virtual void open() {} + virtual void close () {} + virtual void setVisible(bool visible); void center(); /** Event : Dialog finished, OK button clicked.\n @@ -33,6 +34,18 @@ namespace MWGui /// \todo remove MWBase::WindowManager& mWindowManager; }; + + + /* + * "Modal" windows cause the rest of the interface to be unaccessible while they are visible + */ + class WindowModal : public WindowBase + { + public: + WindowModal(const std::string& parLayout, MWBase::WindowManager& parWindowManager); + virtual void open(); + virtual void close(); + }; } #endif diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 676eb2046..f1ee01c4d 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -41,6 +41,7 @@ #include "confirmationdialog.hpp" #include "alchemywindow.hpp" #include "spellwindow.hpp" +#include "quickkeysmenu.hpp" using namespace MWGui; @@ -133,6 +134,7 @@ WindowManager::WindowManager( mConfirmationDialog = new ConfirmationDialog(*this); mAlchemyWindow = new AlchemyWindow(*this); mSpellWindow = new SpellWindow(*this); + mQuickKeysMenu = new QuickKeysMenu(*this); mInputBlocker = mGui->createWidget("",0,0,w,h,MyGUI::Align::Default,"Windows",""); @@ -226,6 +228,7 @@ void WindowManager::updateVisible() mSettingsWindow->setVisible(false); mAlchemyWindow->setVisible(false); mSpellWindow->setVisible(false); + mQuickKeysMenu->setVisible(false); // Mouse is visible whenever we're not in game mode MyGUI::PointerManager::getInstance().setVisible(isGuiMode()); @@ -254,6 +257,9 @@ void WindowManager::updateVisible() GuiMode mode = mGuiModes.back(); switch(mode) { + case GM_QuickKeysMenu: + mQuickKeysMenu->setVisible (true); + break; case GM_MainMenu: mMenu->setVisible(true); break; @@ -652,6 +658,7 @@ void WindowManager::processChangedSettings(const Settings::CategorySettingVector mAlchemyWindow->center(); mScrollWindow->center(); mBookWindow->center(); + mQuickKeysMenu->center(); mDragAndDrop->mDragAndDropWidget->setSize(MyGUI::IntSize(x, y)); mInputBlocker->setSize(MyGUI::IntSize(x,y)); } diff --git a/apps/openmw/mwgui/windowmanagerimp.hpp b/apps/openmw/mwgui/windowmanagerimp.hpp index 391305594..f27522986 100644 --- a/apps/openmw/mwgui/windowmanagerimp.hpp +++ b/apps/openmw/mwgui/windowmanagerimp.hpp @@ -60,6 +60,7 @@ namespace MWGui class MessageBoxManager; class SettingsWindow; class AlchemyWindow; + class QuickKeysMenu; class WindowManager : public MWBase::WindowManager { @@ -209,6 +210,7 @@ namespace MWGui ConfirmationDialog* mConfirmationDialog; AlchemyWindow* mAlchemyWindow; SpellWindow* mSpellWindow; + QuickKeysMenu* mQuickKeysMenu; CharacterCreation* mCharGen; diff --git a/apps/openmw/mwinput/inputmanagerimp.cpp b/apps/openmw/mwinput/inputmanagerimp.cpp index a7cce25c0..8f4fde7a4 100644 --- a/apps/openmw/mwinput/inputmanagerimp.cpp +++ b/apps/openmw/mwinput/inputmanagerimp.cpp @@ -188,7 +188,40 @@ namespace MWInput case A_ToggleSpell: toggleSpell (); break; - } + case A_QuickKey1: + quickKey(1); + break; + case A_QuickKey2: + quickKey(2); + break; + case A_QuickKey3: + quickKey(3); + break; + case A_QuickKey4: + quickKey(4); + break; + case A_QuickKey5: + quickKey(5); + break; + case A_QuickKey6: + quickKey(6); + break; + case A_QuickKey7: + quickKey(7); + break; + case A_QuickKey8: + quickKey(8); + break; + case A_QuickKey9: + quickKey(9); + break; + case A_QuickKey10: + quickKey(10); + break; + case A_QuickKeysMenu: + showQuickKeysMenu(); + break; + } } } @@ -545,6 +578,17 @@ namespace MWInput // .. but don't touch any other mode. } + void InputManager::quickKey (int index) + { + std::cout << "quick key " << index << std::endl; + } + + void InputManager::showQuickKeysMenu() + { + if (!mWindows.isGuiMode ()) + mWindows.pushGuiMode (MWGui::GM_QuickKeysMenu); + } + void InputManager::activate() { mEngine.activate(); @@ -587,7 +631,8 @@ namespace MWInput defaultKeyBindings[A_MoveRight] = OIS::KC_D; defaultKeyBindings[A_ToggleWeapon] = OIS::KC_F; defaultKeyBindings[A_ToggleSpell] = OIS::KC_R; - defaultKeyBindings[A_Console] = OIS::KC_F1; + defaultKeyBindings[A_QuickKeysMenu] = OIS::KC_F1; + defaultKeyBindings[A_Console] = OIS::KC_F2; defaultKeyBindings[A_Crouch] = OIS::KC_LCONTROL; defaultKeyBindings[A_AutoMove] = OIS::KC_Q; defaultKeyBindings[A_Jump] = OIS::KC_E; @@ -595,9 +640,20 @@ namespace MWInput defaultKeyBindings[A_Rest] = OIS::KC_T; defaultKeyBindings[A_GameMenu] = OIS::KC_ESCAPE; defaultKeyBindings[A_TogglePOV] = OIS::KC_TAB; + defaultKeyBindings[A_QuickKey1] = OIS::KC_1; + defaultKeyBindings[A_QuickKey2] = OIS::KC_2; + defaultKeyBindings[A_QuickKey3] = OIS::KC_3; + defaultKeyBindings[A_QuickKey4] = OIS::KC_4; + defaultKeyBindings[A_QuickKey5] = OIS::KC_5; + defaultKeyBindings[A_QuickKey6] = OIS::KC_6; + defaultKeyBindings[A_QuickKey7] = OIS::KC_7; + defaultKeyBindings[A_QuickKey8] = OIS::KC_8; + defaultKeyBindings[A_QuickKey9] = OIS::KC_9; + defaultKeyBindings[A_QuickKey10] = OIS::KC_0; std::map defaultMouseButtonBindings; defaultMouseButtonBindings[A_Inventory] = OIS::MB_Right; + defaultMouseButtonBindings[A_Use] = OIS::MB_Left; for (int i = 0; i < A_Last; ++i) { @@ -645,6 +701,17 @@ namespace MWInput descriptions[A_Rest] = "sRestKey"; descriptions[A_Inventory] = "sInventory"; descriptions[A_TogglePOV] = "sTogglePOVCmd"; + descriptions[A_QuickKeysMenu] = "sQuickMenu"; + descriptions[A_QuickKey1] = "sQuick1Cmd"; + descriptions[A_QuickKey2] = "sQuick2Cmd"; + descriptions[A_QuickKey3] = "sQuick3Cmd"; + descriptions[A_QuickKey4] = "sQuick4Cmd"; + descriptions[A_QuickKey5] = "sQuick5Cmd"; + descriptions[A_QuickKey6] = "sQuick6Cmd"; + descriptions[A_QuickKey7] = "sQuick7Cmd"; + descriptions[A_QuickKey8] = "sQuick8Cmd"; + descriptions[A_QuickKey9] = "sQuick9Cmd"; + descriptions[A_QuickKey10] = "sQuick10Cmd"; if (descriptions[action] == "") return ""; // not configurable @@ -685,6 +752,17 @@ namespace MWInput ret.push_back(A_Journal); ret.push_back(A_Rest); ret.push_back(A_Console); + ret.push_back(A_QuickKeysMenu); + ret.push_back(A_QuickKey1); + ret.push_back(A_QuickKey2); + ret.push_back(A_QuickKey3); + ret.push_back(A_QuickKey4); + ret.push_back(A_QuickKey5); + ret.push_back(A_QuickKey6); + ret.push_back(A_QuickKey7); + ret.push_back(A_QuickKey8); + ret.push_back(A_QuickKey9); + ret.push_back(A_QuickKey10); return ret; } diff --git a/apps/openmw/mwinput/inputmanagerimp.hpp b/apps/openmw/mwinput/inputmanagerimp.hpp index 71d43b8d5..a7a2df852 100644 --- a/apps/openmw/mwinput/inputmanagerimp.hpp +++ b/apps/openmw/mwinput/inputmanagerimp.hpp @@ -168,6 +168,9 @@ namespace MWInput void toggleAutoMove(); void exitNow(); + void quickKey (int index); + void showQuickKeysMenu(); + bool actionIsActive (int id); void loadKeyDefaults(bool force = false); @@ -220,6 +223,19 @@ namespace MWInput A_TogglePOV, + A_QuickKey1, + A_QuickKey2, + A_QuickKey3, + A_QuickKey4, + A_QuickKey5, + A_QuickKey6, + A_QuickKey7, + A_QuickKey8, + A_QuickKey9, + A_QuickKey10, + + A_QuickKeysMenu, + A_Last // Marker for the last item }; }; diff --git a/files/mygui/CMakeLists.txt b/files/mygui/CMakeLists.txt index 3a5430c6f..2e448a369 100644 --- a/files/mygui/CMakeLists.txt +++ b/files/mygui/CMakeLists.txt @@ -65,6 +65,10 @@ set(MYGUI_FILES openmw_tooltips.layout openmw_trade_window.layout openmw_windows.skin.xml + openmw_quickkeys_menu.layout + openmw_quickkeys_menu_assign.layout + openmw_itemselection_dialog.layout + openmw_magicselection_dialog.layout smallbars.png VeraMono.ttf ) diff --git a/files/mygui/openmw_itemselection_dialog.layout b/files/mygui/openmw_itemselection_dialog.layout new file mode 100644 index 000000000..93681e69e --- /dev/null +++ b/files/mygui/openmw_itemselection_dialog.layout @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/files/mygui/openmw_magicselection_dialog.layout b/files/mygui/openmw_magicselection_dialog.layout new file mode 100644 index 000000000..7834b0ed9 --- /dev/null +++ b/files/mygui/openmw_magicselection_dialog.layout @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/files/mygui/openmw_quickkeys_menu.layout b/files/mygui/openmw_quickkeys_menu.layout new file mode 100644 index 000000000..a45f2896f --- /dev/null +++ b/files/mygui/openmw_quickkeys_menu.layout @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/files/mygui/openmw_quickkeys_menu_assign.layout b/files/mygui/openmw_quickkeys_menu_assign.layout new file mode 100644 index 000000000..4bbd9f1fa --- /dev/null +++ b/files/mygui/openmw_quickkeys_menu_assign.layout @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +