2012-05-03 01:33:33 +00:00
|
|
|
#include "scrollwindow.hpp"
|
|
|
|
|
2014-02-23 19:11:05 +00:00
|
|
|
#include <components/esm/loadbook.hpp>
|
|
|
|
|
2012-05-03 03:26:05 +00:00
|
|
|
#include "../mwbase/environment.hpp"
|
2012-07-27 10:00:10 +00:00
|
|
|
#include "../mwbase/world.hpp"
|
2012-08-09 12:33:21 +00:00
|
|
|
#include "../mwbase/soundmanager.hpp"
|
2012-08-12 16:11:09 +00:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
2012-08-09 12:33:21 +00:00
|
|
|
|
2012-05-03 03:26:05 +00:00
|
|
|
#include "../mwworld/actiontake.hpp"
|
|
|
|
|
2012-05-23 10:23:35 +00:00
|
|
|
#include "formatting.hpp"
|
|
|
|
|
2013-05-08 11:55:15 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
void adjustButton (MWGui::ImageButton* button)
|
|
|
|
{
|
|
|
|
MyGUI::IntSize diff = button->getSize() - button->getRequestedSize();
|
|
|
|
button->setSize(button->getRequestedSize());
|
|
|
|
|
|
|
|
if (button->getAlign().isRight())
|
|
|
|
button->setPosition(button->getPosition() + MyGUI::IntPoint(diff.width,0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
namespace MWGui
|
2012-05-03 01:33:33 +00:00
|
|
|
{
|
2012-05-07 22:39:52 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
ScrollWindow::ScrollWindow ()
|
|
|
|
: WindowBase("openmw_scroll.layout")
|
|
|
|
, mTakeButtonShow(true)
|
|
|
|
, mTakeButtonAllowed(true)
|
|
|
|
{
|
|
|
|
getWidget(mTextView, "TextView");
|
2012-05-03 03:26:05 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
getWidget(mCloseButton, "CloseButton");
|
|
|
|
mCloseButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ScrollWindow::onCloseButtonClicked);
|
2012-05-03 03:26:05 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
getWidget(mTakeButton, "TakeButton");
|
|
|
|
mTakeButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ScrollWindow::onTakeButtonClicked);
|
2012-05-03 01:33:33 +00:00
|
|
|
|
2013-05-08 11:55:15 +00:00
|
|
|
adjustButton(mCloseButton);
|
|
|
|
adjustButton(mTakeButton);
|
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
center();
|
|
|
|
}
|
2012-05-03 03:26:05 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
void ScrollWindow::open (MWWorld::Ptr scroll)
|
|
|
|
{
|
|
|
|
// no 3d sounds because the object could be in a container.
|
|
|
|
MWBase::Environment::get().getSoundManager()->playSound ("scroll", 1.0, 1.0);
|
2012-05-07 22:39:52 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
mScroll = scroll;
|
2012-05-07 22:39:52 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::Book> *ref = mScroll.get<ESM::Book>();
|
2012-05-07 22:39:52 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
BookTextParser parser;
|
2013-05-02 03:35:25 +00:00
|
|
|
MyGUI::IntSize size = parser.parseScroll(ref->mBase->mText, mTextView, 390);
|
2012-05-07 22:39:52 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
if (size.height > mTextView->getSize().height)
|
|
|
|
mTextView->setCanvasSize(MyGUI::IntSize(410, size.height));
|
|
|
|
else
|
|
|
|
mTextView->setCanvasSize(410, mTextView->getSize().height);
|
2012-05-15 16:05:53 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
mTextView->setViewOffset(MyGUI::IntPoint(0,0));
|
2012-05-15 16:05:53 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
setTakeButtonShow(true);
|
|
|
|
}
|
2013-02-17 14:56:22 +00:00
|
|
|
|
2014-05-27 03:13:37 +00:00
|
|
|
void ScrollWindow::exit()
|
|
|
|
{
|
|
|
|
MWBase::Environment::get().getSoundManager()->playSound ("scroll", 1.0, 1.0);
|
|
|
|
|
|
|
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Scroll);
|
|
|
|
}
|
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
void ScrollWindow::setTakeButtonShow(bool show)
|
|
|
|
{
|
|
|
|
mTakeButtonShow = show;
|
|
|
|
mTakeButton->setVisible(mTakeButtonShow && mTakeButtonAllowed);
|
|
|
|
}
|
2012-05-03 03:26:05 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
void ScrollWindow::setInventoryAllowed(bool allowed)
|
|
|
|
{
|
|
|
|
mTakeButtonAllowed = allowed;
|
|
|
|
mTakeButton->setVisible(mTakeButtonShow && mTakeButtonAllowed);
|
|
|
|
}
|
2012-05-03 03:26:05 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
void ScrollWindow::onCloseButtonClicked (MyGUI::Widget* _sender)
|
|
|
|
{
|
2014-05-27 03:13:37 +00:00
|
|
|
exit();
|
2013-04-17 22:56:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollWindow::onTakeButtonClicked (MyGUI::Widget* _sender)
|
|
|
|
{
|
2013-07-19 02:01:13 +00:00
|
|
|
MWBase::Environment::get().getSoundManager()->playSound("Item Book Up", 1.0, 1.0);
|
2012-05-03 03:26:05 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
MWWorld::ActionTake take(mScroll);
|
2014-01-08 17:39:44 +00:00
|
|
|
take.execute (MWBase::Environment::get().getWorld()->getPlayerPtr());
|
2012-05-03 03:26:05 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Scroll);
|
|
|
|
}
|
2012-05-03 01:33:33 +00:00
|
|
|
}
|