2012-05-03 01:33:33 +00:00
|
|
|
#include "scrollwindow.hpp"
|
|
|
|
|
2015-01-10 01:50:43 +00:00
|
|
|
#include <MyGUI_ScrollView.h>
|
|
|
|
|
2014-02-23 19:11:05 +00:00
|
|
|
#include <components/esm/loadbook.hpp>
|
2015-01-10 02:56:06 +00:00
|
|
|
#include <components/widgets/imagebutton.hpp>
|
2014-02-23 19:11:05 +00:00
|
|
|
|
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-12 16:11:09 +00:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
2012-08-09 12:33:21 +00:00
|
|
|
|
2015-08-21 09:12:39 +00:00
|
|
|
#include "../mwmechanics/actorutil.hpp"
|
|
|
|
|
2012-05-03 03:26:05 +00:00
|
|
|
#include "../mwworld/actiontake.hpp"
|
2017-09-22 19:26:41 +00:00
|
|
|
#include "../mwworld/class.hpp"
|
2012-05-03 03:26:05 +00:00
|
|
|
|
2012-05-23 10:23:35 +00:00
|
|
|
#include "formatting.hpp"
|
|
|
|
|
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 ()
|
2019-04-01 17:47:12 +00:00
|
|
|
: BookWindowBase("openmw_scroll.layout")
|
2013-04-17 22:56:48 +00:00
|
|
|
, 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
|
|
|
|
2019-04-01 17:47:12 +00:00
|
|
|
adjustButton("CloseButton");
|
|
|
|
adjustButton("TakeButton");
|
2013-05-08 11:55:15 +00:00
|
|
|
|
2017-09-23 22:23:08 +00:00
|
|
|
mCloseButton->eventKeyButtonPressed += MyGUI::newDelegate(this, &ScrollWindow::onKeyButtonPressed);
|
|
|
|
mTakeButton->eventKeyButtonPressed += MyGUI::newDelegate(this, &ScrollWindow::onKeyButtonPressed);
|
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
center();
|
|
|
|
}
|
2012-05-03 03:26:05 +00:00
|
|
|
|
2017-09-22 19:26:41 +00:00
|
|
|
void ScrollWindow::setPtr (const MWWorld::Ptr& scroll)
|
2013-04-17 22:56:48 +00:00
|
|
|
{
|
|
|
|
mScroll = scroll;
|
2012-05-07 22:39:52 +00:00
|
|
|
|
2017-09-22 19:26:41 +00:00
|
|
|
MWWorld::Ptr player = MWMechanics::getPlayer();
|
|
|
|
bool showTakeButton = scroll.getContainerStore() != &player.getClass().getContainerStore(player);
|
|
|
|
|
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
|
|
|
|
2014-09-19 22:11:04 +00:00
|
|
|
Formatting::BookFormatter formatter;
|
|
|
|
formatter.markupToWidget(mTextView, ref->mBase->mText, 390, mTextView->getHeight());
|
|
|
|
MyGUI::IntSize size = mTextView->getChildAt(0)->getSize();
|
2012-05-07 22:39:52 +00:00
|
|
|
|
2014-07-26 00:23:42 +00: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 22:56:48 +00:00
|
|
|
if (size.height > mTextView->getSize().height)
|
2017-09-23 22:23:08 +00:00
|
|
|
mTextView->setCanvasSize(mTextView->getWidth(), size.height);
|
2013-04-17 22:56:48 +00:00
|
|
|
else
|
2017-09-23 22:23:08 +00:00
|
|
|
mTextView->setCanvasSize(mTextView->getWidth(), mTextView->getSize().height);
|
2014-07-26 00:23:42 +00:00
|
|
|
mTextView->setVisibleVScroll(true);
|
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
|
|
|
|
2015-03-11 19:33:55 +00:00
|
|
|
setTakeButtonShow(showTakeButton);
|
2017-09-23 22:23:08 +00:00
|
|
|
|
2019-06-08 23:08:09 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mCloseButton);
|
2017-09-23 22:23:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollWindow::onKeyButtonPressed(MyGUI::Widget *sender, MyGUI::KeyCode key, MyGUI::Char character)
|
|
|
|
{
|
|
|
|
int scroll = 0;
|
|
|
|
if (key == MyGUI::KeyCode::ArrowUp)
|
|
|
|
scroll = 40;
|
|
|
|
else if (key == MyGUI::KeyCode::ArrowDown)
|
|
|
|
scroll = -40;
|
|
|
|
|
|
|
|
if (scroll != 0)
|
|
|
|
mTextView->setViewOffset(mTextView->getViewOffset() + MyGUI::IntPoint(0, scroll));
|
2013-04-17 22:56:48 +00:00
|
|
|
}
|
2013-02-17 14:56:22 +00:00
|
|
|
|
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)
|
|
|
|
{
|
2017-09-23 10:18:39 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Scroll);
|
2013-04-17 22:56:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollWindow::onTakeButtonClicked (MyGUI::Widget* _sender)
|
|
|
|
{
|
2017-07-10 11:48:00 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->playSound("Item Book Up");
|
2012-05-03 03:26:05 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
MWWorld::ActionTake take(mScroll);
|
2015-08-21 09:12:39 +00:00
|
|
|
take.execute (MWMechanics::getPlayer());
|
2012-05-03 03:26:05 +00:00
|
|
|
|
2017-09-22 22:00:40 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Scroll, true);
|
2013-04-17 22:56:48 +00:00
|
|
|
}
|
2012-05-03 01:33:33 +00:00
|
|
|
}
|