2012-05-03 03:33:33 +02:00
|
|
|
#include "scrollwindow.hpp"
|
|
|
|
|
2015-01-10 02:50:43 +01:00
|
|
|
#include <MyGUI_ScrollView.h>
|
|
|
|
|
2014-02-23 20:11:05 +01:00
|
|
|
#include <components/esm/loadbook.hpp>
|
2015-01-10 03:56:06 +01:00
|
|
|
#include <components/widgets/imagebutton.hpp>
|
2014-02-23 20:11:05 +01:00
|
|
|
|
2012-05-03 05:26:05 +02:00
|
|
|
#include "../mwbase/environment.hpp"
|
2012-07-27 12:00:10 +02:00
|
|
|
#include "../mwbase/world.hpp"
|
2012-08-09 14:33:21 +02:00
|
|
|
#include "../mwbase/soundmanager.hpp"
|
2012-08-12 18:11:09 +02:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
2012-08-09 14:33:21 +02:00
|
|
|
|
2015-08-21 21:12:39 +12:00
|
|
|
#include "../mwmechanics/actorutil.hpp"
|
|
|
|
|
2012-05-03 05:26:05 +02:00
|
|
|
#include "../mwworld/actiontake.hpp"
|
|
|
|
|
2012-05-23 12:23:35 +02:00
|
|
|
#include "formatting.hpp"
|
|
|
|
|
2013-05-08 13:55:15 +02:00
|
|
|
namespace
|
|
|
|
{
|
2014-09-12 05:14:21 +02:00
|
|
|
void adjustButton (Gui::ImageButton* button)
|
2013-05-08 13:55:15 +02:00
|
|
|
{
|
|
|
|
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 18:56:48 -04:00
|
|
|
namespace MWGui
|
2012-05-03 03:33:33 +02:00
|
|
|
{
|
2012-05-08 00:39:52 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
ScrollWindow::ScrollWindow ()
|
|
|
|
: WindowBase("openmw_scroll.layout")
|
|
|
|
, mTakeButtonShow(true)
|
|
|
|
, mTakeButtonAllowed(true)
|
|
|
|
{
|
|
|
|
getWidget(mTextView, "TextView");
|
2012-05-03 05:26:05 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
getWidget(mCloseButton, "CloseButton");
|
|
|
|
mCloseButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ScrollWindow::onCloseButtonClicked);
|
2012-05-03 05:26:05 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
getWidget(mTakeButton, "TakeButton");
|
|
|
|
mTakeButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ScrollWindow::onTakeButtonClicked);
|
2012-05-03 03:33:33 +02:00
|
|
|
|
2013-05-08 13:55:15 +02:00
|
|
|
adjustButton(mCloseButton);
|
|
|
|
adjustButton(mTakeButton);
|
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
center();
|
|
|
|
}
|
2012-05-03 05:26:05 +02:00
|
|
|
|
2015-06-04 20:31:28 +02:00
|
|
|
void ScrollWindow::openScroll (MWWorld::Ptr scroll, bool showTakeButton)
|
2013-04-17 18:56:48 -04:00
|
|
|
{
|
|
|
|
// no 3d sounds because the object could be in a container.
|
|
|
|
MWBase::Environment::get().getSoundManager()->playSound ("scroll", 1.0, 1.0);
|
2012-05-08 00:39:52 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
mScroll = scroll;
|
2012-05-08 00:39:52 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
MWWorld::LiveCellRef<ESM::Book> *ref = mScroll.get<ESM::Book>();
|
2012-05-08 00:39:52 +02:00
|
|
|
|
2014-09-20 00:11:04 +02:00
|
|
|
Formatting::BookFormatter formatter;
|
|
|
|
formatter.markupToWidget(mTextView, ref->mBase->mText, 390, mTextView->getHeight());
|
|
|
|
MyGUI::IntSize size = mTextView->getChildAt(0)->getSize();
|
2012-05-08 00:39:52 +02:00
|
|
|
|
2014-07-26 02:23:42 +02:00
|
|
|
// Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the scrollbar is hidden
|
|
|
|
mTextView->setVisibleVScroll(false);
|
2013-04-17 18:56:48 -04:00
|
|
|
if (size.height > mTextView->getSize().height)
|
|
|
|
mTextView->setCanvasSize(MyGUI::IntSize(410, size.height));
|
|
|
|
else
|
|
|
|
mTextView->setCanvasSize(410, mTextView->getSize().height);
|
2014-07-26 02:23:42 +02:00
|
|
|
mTextView->setVisibleVScroll(true);
|
2012-05-15 18:05:53 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
mTextView->setViewOffset(MyGUI::IntPoint(0,0));
|
2012-05-15 18:05:53 +02:00
|
|
|
|
2015-03-11 20:33:55 +01:00
|
|
|
setTakeButtonShow(showTakeButton);
|
2013-04-17 18:56:48 -04:00
|
|
|
}
|
2013-02-17 15:56:22 +01:00
|
|
|
|
2014-05-26 23:13:37 -04:00
|
|
|
void ScrollWindow::exit()
|
|
|
|
{
|
|
|
|
MWBase::Environment::get().getSoundManager()->playSound ("scroll", 1.0, 1.0);
|
|
|
|
|
|
|
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Scroll);
|
|
|
|
}
|
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void ScrollWindow::setTakeButtonShow(bool show)
|
|
|
|
{
|
|
|
|
mTakeButtonShow = show;
|
|
|
|
mTakeButton->setVisible(mTakeButtonShow && mTakeButtonAllowed);
|
|
|
|
}
|
2012-05-03 05:26:05 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void ScrollWindow::setInventoryAllowed(bool allowed)
|
|
|
|
{
|
|
|
|
mTakeButtonAllowed = allowed;
|
|
|
|
mTakeButton->setVisible(mTakeButtonShow && mTakeButtonAllowed);
|
|
|
|
}
|
2012-05-03 05:26:05 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void ScrollWindow::onCloseButtonClicked (MyGUI::Widget* _sender)
|
|
|
|
{
|
2014-05-26 23:13:37 -04:00
|
|
|
exit();
|
2013-04-17 18:56:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollWindow::onTakeButtonClicked (MyGUI::Widget* _sender)
|
|
|
|
{
|
2013-07-18 19:01:13 -07:00
|
|
|
MWBase::Environment::get().getSoundManager()->playSound("Item Book Up", 1.0, 1.0);
|
2012-05-03 05:26:05 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
MWWorld::ActionTake take(mScroll);
|
2015-08-21 21:12:39 +12:00
|
|
|
take.execute (MWMechanics::getPlayer());
|
2012-05-03 05:26:05 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Scroll);
|
|
|
|
}
|
2012-05-03 03:33:33 +02:00
|
|
|
}
|