implemented item count selection dialog
parent
320cc7d020
commit
24a0fecd37
@ -0,0 +1,110 @@
|
|||||||
|
#include "countdialog.hpp"
|
||||||
|
|
||||||
|
#include <boost/lexical_cast.hpp>
|
||||||
|
|
||||||
|
#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<std::string>(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<unsigned int>(_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<std::string>(_position+1));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CountDialog::close()
|
||||||
|
{
|
||||||
|
setVisible(false);
|
||||||
|
MyGUI::InputManager::getInstance().removeWidgetModal(mMainWidget);
|
||||||
|
}
|
||||||
|
}
|
@ -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<MyGUI::Widget*, int> 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
|
@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<MyGUI type="Layout">
|
||||||
|
<Widget type="Window" skin="MW_Dialog" layer="Windows" position="0 0 600 125" name="_Main">
|
||||||
|
<Property key="Visible" value="false"/>
|
||||||
|
|
||||||
|
<Widget type="TextBox" skin="SandText" position="4 0 592 24" name="LabelText" align="Left Top HStretch">
|
||||||
|
<Property key="TextAlign" value="Center"/>
|
||||||
|
</Widget>
|
||||||
|
|
||||||
|
<Widget type="TextBox" skin="SandText" position="4 30 532 24" name="ItemText" align="Left Top HStretch">
|
||||||
|
<Property key="TextAlign" value="Right"/>
|
||||||
|
</Widget>
|
||||||
|
|
||||||
|
<Widget type="EditBox" skin="MW_TextEdit" position="540 30 32 24" name="ItemEdit" align="Right Top">
|
||||||
|
<Property key="TextAlign" value="Center"/>
|
||||||
|
</Widget>
|
||||||
|
|
||||||
|
<Widget type="ScrollBar" skin="MW_HScroll" position="28 60 544 18" name="CountSlider" align="Left Top HStretch">
|
||||||
|
<Property key="MoveToClick" value="true"/>
|
||||||
|
</Widget>
|
||||||
|
|
||||||
|
<Widget type="Button" skin="MW_Button" position="512 90 60 24" name="OkButton" align="Right Top"/>
|
||||||
|
<Widget type="Button" skin="MW_Button" position="417 90 60 24" name="CancelButton" align="Right Top"/>
|
||||||
|
|
||||||
|
</Widget>
|
||||||
|
</MyGUI>
|
Loading…
Reference in New Issue