1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 18:19:55 +00:00
openmw-tes3mp/apps/openmw/mwgui/countdialog.cpp

100 lines
3.1 KiB
C++
Raw Normal View History

#include "countdialog.hpp"
2015-01-10 01:50:43 +00:00
#include <MyGUI_Button.h>
#include <MyGUI_ScrollBar.h>
#include <MyGUI_RenderManager.h>
2014-09-25 18:28:00 +00:00
#include <components/widgets/numericeditbox.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/windowmanager.hpp"
namespace MWGui
{
CountDialog::CountDialog() :
WindowModal("openmw_count_window.layout")
{
getWidget(mSlider, "CountSlider");
getWidget(mItemEdit, "ItemEdit");
getWidget(mItemText, "ItemText");
getWidget(mLabelText, "LabelText");
getWidget(mOkButton, "OkButton");
getWidget(mCancelButton, "CancelButton");
mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &CountDialog::onCancelButtonClicked);
mOkButton->eventMouseButtonClick += MyGUI::newDelegate(this, &CountDialog::onOkButtonClicked);
2014-09-25 18:28:00 +00:00
mItemEdit->eventValueChanged += MyGUI::newDelegate(this, &CountDialog::onEditValueChanged);
mSlider->eventScrollChangePosition += MyGUI::newDelegate(this, &CountDialog::onSliderMoved);
2013-05-16 18:05:22 +00:00
// make sure we read the enter key being pressed to accept multiple items
mItemEdit->eventEditSelectAccept += MyGUI::newDelegate(this, &CountDialog::onEnterKeyPressed);
}
void CountDialog::openCountDialog(const std::string& item, const std::string& message, const int maxCount)
{
setVisible(true);
2012-09-22 19:35:57 +00:00
mLabelText->setCaptionWithReplacing(message);
2012-05-18 15:58:33 +00:00
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());
2013-05-16 17:40:00 +00:00
// by default, the text edit field has the focus of the keyboard
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mItemEdit);
mSlider->setScrollPosition(maxCount-1);
2014-09-25 18:28:00 +00:00
mItemEdit->setMinValue(1);
mItemEdit->setMaxValue(maxCount);
mItemEdit->setValue(maxCount);
}
void CountDialog::cancel() //Keeping this here as I don't know if anything else relies on it.
{
exit();
}
void CountDialog::exit()
{
setVisible(false);
}
void CountDialog::onCancelButtonClicked(MyGUI::Widget* _sender)
{
cancel();
}
void CountDialog::onOkButtonClicked(MyGUI::Widget* _sender)
{
eventOkClicked(NULL, mSlider->getScrollPosition()+1);
setVisible(false);
}
2013-05-16 17:40:00 +00:00
// essentially duplicating what the OK button does if user presses
// Enter key
void CountDialog::onEnterKeyPressed(MyGUI::EditBox* _sender)
{
eventOkClicked(NULL, mSlider->getScrollPosition()+1);
2013-05-16 18:05:22 +00:00
setVisible(false);
2013-05-16 17:40:00 +00:00
}
2014-09-25 18:28:00 +00:00
void CountDialog::onEditValueChanged(int value)
{
2014-09-25 18:28:00 +00:00
mSlider->setScrollPosition(value-1);
}
void CountDialog::onSliderMoved(MyGUI::ScrollBar* _sender, size_t _position)
{
2014-09-25 18:28:00 +00:00
mItemEdit->setValue(_position+1);
}
}