2012-05-03 03:33:33 +02:00
|
|
|
#include "bookwindow.hpp"
|
|
|
|
|
2017-09-26 18:20:24 +02:00
|
|
|
#include <MyGUI_InputManager.h>
|
2015-01-10 02:50:43 +01:00
|
|
|
#include <MyGUI_TextBox.h>
|
|
|
|
|
2022-01-22 15:58:41 +01:00
|
|
|
#include <components/esm3/loadbook.hpp>
|
2014-02-23 20:11:05 +01:00
|
|
|
|
2012-05-03 05:26:05 +02:00
|
|
|
#include "../mwbase/environment.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"
|
2017-09-22 21:26:41 +02:00
|
|
|
#include "../mwworld/class.hpp"
|
2012-05-03 05:26:05 +02:00
|
|
|
|
2012-05-23 12:23:35 +02:00
|
|
|
#include "formatting.hpp"
|
2012-05-10 11:03:27 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
namespace MWGui
|
2012-05-03 03:33:33 +02:00
|
|
|
{
|
2012-05-03 05:26:05 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
BookWindow::BookWindow()
|
2019-04-01 21:47:12 +04:00
|
|
|
: BookWindowBase("openmw_book.layout")
|
2015-04-30 19:24:27 -05:00
|
|
|
, mCurrentPage(0)
|
2013-04-17 18:56:48 -04:00
|
|
|
, mTakeButtonShow(true)
|
|
|
|
, mTakeButtonAllowed(true)
|
|
|
|
{
|
|
|
|
getWidget(mCloseButton, "CloseButton");
|
|
|
|
mCloseButton->eventMouseButtonClick += MyGUI::newDelegate(this, &BookWindow::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, &BookWindow::onTakeButtonClicked);
|
2012-05-03 05:26:05 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
getWidget(mNextPageButton, "NextPageBTN");
|
|
|
|
mNextPageButton->eventMouseButtonClick += MyGUI::newDelegate(this, &BookWindow::onNextPageButtonClicked);
|
2012-05-03 05:26:05 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
getWidget(mPrevPageButton, "PrevPageBTN");
|
|
|
|
mPrevPageButton->eventMouseButtonClick += MyGUI::newDelegate(this, &BookWindow::onPrevPageButtonClicked);
|
2012-05-10 11:03:27 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
getWidget(mLeftPageNumber, "LeftPageNumber");
|
|
|
|
getWidget(mRightPageNumber, "RightPageNumber");
|
2012-05-10 11:03:27 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
getWidget(mLeftPage, "LeftPage");
|
|
|
|
getWidget(mRightPage, "RightPage");
|
2012-05-03 03:33:33 +02:00
|
|
|
|
2019-04-01 21:47:12 +04:00
|
|
|
adjustButton("CloseButton");
|
|
|
|
adjustButton("TakeButton");
|
|
|
|
adjustButton("PrevPageBTN");
|
|
|
|
float scale = adjustButton("NextPageBTN");
|
2013-05-08 13:55:15 +02:00
|
|
|
|
2014-01-04 01:13:19 +01:00
|
|
|
mLeftPage->setNeedMouseFocus(true);
|
|
|
|
mLeftPage->eventMouseWheel += MyGUI::newDelegate(this, &BookWindow::onMouseWheel);
|
|
|
|
mRightPage->setNeedMouseFocus(true);
|
|
|
|
mRightPage->eventMouseWheel += MyGUI::newDelegate(this, &BookWindow::onMouseWheel);
|
|
|
|
|
2017-09-24 00:23:08 +02:00
|
|
|
mNextPageButton->eventKeyButtonPressed += MyGUI::newDelegate(this, &BookWindow::onKeyButtonPressed);
|
|
|
|
mPrevPageButton->eventKeyButtonPressed += MyGUI::newDelegate(this, &BookWindow::onKeyButtonPressed);
|
|
|
|
mTakeButton->eventKeyButtonPressed += MyGUI::newDelegate(this, &BookWindow::onKeyButtonPressed);
|
|
|
|
mCloseButton->eventKeyButtonPressed += MyGUI::newDelegate(this, &BookWindow::onKeyButtonPressed);
|
|
|
|
|
2013-05-08 13:55:15 +02:00
|
|
|
if (mNextPageButton->getSize().width == 64)
|
|
|
|
{
|
|
|
|
// english button has a 7 pixel wide strip of garbage on its right edge
|
|
|
|
mNextPageButton->setSize(64 - 7, mNextPageButton->getSize().height);
|
2019-04-01 21:47:12 +04:00
|
|
|
mNextPageButton->setImageCoord(
|
|
|
|
MyGUI::IntCoord(0, 0, (64 - 7) * scale, mNextPageButton->getSize().height * scale));
|
2013-05-08 13:55:15 +02:00
|
|
|
}
|
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
center();
|
|
|
|
}
|
|
|
|
|
2014-01-04 01:13:19 +01:00
|
|
|
void BookWindow::onMouseWheel(MyGUI::Widget* _sender, int _rel)
|
|
|
|
{
|
|
|
|
if (_rel < 0)
|
|
|
|
nextPage();
|
|
|
|
else
|
|
|
|
prevPage();
|
|
|
|
}
|
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void BookWindow::clearPages()
|
2012-05-10 11:03:27 +02:00
|
|
|
{
|
2013-04-17 18:56:48 -04:00
|
|
|
mPages.clear();
|
2012-05-10 11:03:27 +02:00
|
|
|
}
|
2012-05-03 05:26:05 +02:00
|
|
|
|
2017-09-22 21:26:41 +02:00
|
|
|
void BookWindow::setPtr(const MWWorld::Ptr& book)
|
2013-04-17 18:56:48 -04:00
|
|
|
{
|
|
|
|
mBook = book;
|
2012-05-08 00:39:52 +02:00
|
|
|
|
2017-09-22 21:26:41 +02:00
|
|
|
MWWorld::Ptr player = MWMechanics::getPlayer();
|
|
|
|
bool showTakeButton = book.getContainerStore() != &player.getClass().getContainerStore(player);
|
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
clearPages();
|
|
|
|
mCurrentPage = 0;
|
2012-05-10 11:03:27 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
MWWorld::LiveCellRef<ESM::Book>* ref = mBook.get<ESM::Book>();
|
2012-05-08 00:39:52 +02:00
|
|
|
|
2014-09-20 00:11:04 +02:00
|
|
|
Formatting::BookFormatter formatter;
|
|
|
|
mPages = formatter.markupToWidget(mLeftPage, ref->mBase->mText);
|
|
|
|
formatter.markupToWidget(mRightPage, ref->mBase->mText);
|
2012-05-10 11:03:27 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
updatePages();
|
2012-05-15 18:05:53 +02:00
|
|
|
|
2015-03-11 20:33:55 +01:00
|
|
|
setTakeButtonShow(showTakeButton);
|
2017-09-24 00:23:08 +02:00
|
|
|
|
2019-06-09 02:08:09 +03:00
|
|
|
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mCloseButton);
|
2013-04-17 18:56:48 -04:00
|
|
|
}
|
2012-05-15 18:05:53 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void BookWindow::setTakeButtonShow(bool show)
|
|
|
|
{
|
|
|
|
mTakeButtonShow = show;
|
|
|
|
mTakeButton->setVisible(mTakeButtonShow && mTakeButtonAllowed);
|
|
|
|
}
|
2013-02-17 15:56:22 +01:00
|
|
|
|
2017-09-24 00:23:08 +02:00
|
|
|
void BookWindow::onKeyButtonPressed(MyGUI::Widget* sender, MyGUI::KeyCode key, MyGUI::Char character)
|
|
|
|
{
|
|
|
|
if (key == MyGUI::KeyCode::ArrowUp)
|
|
|
|
prevPage();
|
|
|
|
else if (key == MyGUI::KeyCode::ArrowDown)
|
|
|
|
nextPage();
|
|
|
|
}
|
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void BookWindow::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 BookWindow::onCloseButtonClicked(MyGUI::Widget* sender)
|
|
|
|
{
|
2017-09-23 12:18:39 +02:00
|
|
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Book);
|
2013-04-17 18:56:48 -04:00
|
|
|
}
|
2012-05-03 05:26:05 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void BookWindow::onTakeButtonClicked(MyGUI::Widget* sender)
|
|
|
|
{
|
2017-07-10 15:48:00 +04:00
|
|
|
MWBase::Environment::get().getWindowManager()->playSound("Item Book Up");
|
2012-05-03 05:26:05 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
MWWorld::ActionTake take(mBook);
|
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_Book);
|
|
|
|
}
|
2012-05-03 05:26:05 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void BookWindow::onNextPageButtonClicked(MyGUI::Widget* sender)
|
2012-05-10 11:03:27 +02:00
|
|
|
{
|
2013-06-13 00:50:07 -05:00
|
|
|
nextPage();
|
2012-05-10 11:03:27 +02:00
|
|
|
}
|
2012-05-03 03:33:33 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void BookWindow::onPrevPageButtonClicked(MyGUI::Widget* sender)
|
2012-05-10 11:03:27 +02:00
|
|
|
{
|
2013-06-13 00:50:07 -05:00
|
|
|
prevPage();
|
2012-05-10 11:03:27 +02:00
|
|
|
}
|
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void BookWindow::updatePages()
|
2012-05-10 11:03:27 +02:00
|
|
|
{
|
2015-01-10 03:01:01 +01:00
|
|
|
mLeftPageNumber->setCaption(MyGUI::utility::toString(mCurrentPage * 2 + 1));
|
|
|
|
mRightPageNumber->setCaption(MyGUI::utility::toString(mCurrentPage * 2 + 2));
|
2013-04-17 18:56:48 -04:00
|
|
|
|
2017-09-26 18:20:24 +02:00
|
|
|
MyGUI::Widget* focus = MyGUI::InputManager::getInstance().getKeyFocusWidget();
|
|
|
|
bool nextPageVisible = (mCurrentPage + 1) * 2 < mPages.size();
|
|
|
|
mNextPageButton->setVisible(nextPageVisible);
|
|
|
|
bool prevPageVisible = mCurrentPage != 0;
|
|
|
|
mPrevPageButton->setVisible(prevPageVisible);
|
|
|
|
|
|
|
|
if (focus == mNextPageButton && !nextPageVisible && prevPageVisible)
|
2019-06-09 02:08:09 +03:00
|
|
|
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mPrevPageButton);
|
2017-09-26 18:20:24 +02:00
|
|
|
else if (focus == mPrevPageButton && !prevPageVisible && nextPageVisible)
|
2019-06-09 02:08:09 +03:00
|
|
|
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mNextPageButton);
|
2014-09-20 00:11:04 +02:00
|
|
|
|
|
|
|
if (mPages.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
MyGUI::Widget* paper;
|
|
|
|
|
|
|
|
paper = mLeftPage->getChildAt(0);
|
|
|
|
paper->setCoord(paper->getPosition().left, -mPages[mCurrentPage * 2].first, paper->getWidth(),
|
|
|
|
mPages[mCurrentPage * 2].second);
|
|
|
|
|
|
|
|
paper = mRightPage->getChildAt(0);
|
|
|
|
if ((mCurrentPage + 1) * 2 <= mPages.size())
|
|
|
|
{
|
|
|
|
paper->setCoord(paper->getPosition().left, -mPages[mCurrentPage * 2 + 1].first, paper->getWidth(),
|
|
|
|
mPages[mCurrentPage * 2 + 1].second);
|
|
|
|
paper->setVisible(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
paper->setVisible(false);
|
|
|
|
}
|
2012-05-10 11:03:27 +02:00
|
|
|
}
|
2013-04-17 18:56:48 -04:00
|
|
|
|
2013-06-13 00:50:07 -05:00
|
|
|
void BookWindow::nextPage()
|
|
|
|
{
|
2013-06-13 00:52:26 -05:00
|
|
|
if ((mCurrentPage + 1) * 2 < mPages.size())
|
2013-06-13 00:50:07 -05:00
|
|
|
{
|
2018-05-01 16:21:58 +04:00
|
|
|
MWBase::Environment::get().getWindowManager()->playSound("book page2");
|
2013-06-13 00:50:07 -05:00
|
|
|
|
|
|
|
++mCurrentPage;
|
|
|
|
|
|
|
|
updatePages();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void BookWindow::prevPage()
|
|
|
|
{
|
2013-06-13 00:52:26 -05:00
|
|
|
if (mCurrentPage > 0)
|
2013-06-13 00:50:07 -05:00
|
|
|
{
|
2018-05-01 16:21:58 +04:00
|
|
|
MWBase::Environment::get().getWindowManager()->playSound("book page");
|
2013-06-13 00:50:07 -05:00
|
|
|
|
|
|
|
--mCurrentPage;
|
|
|
|
|
|
|
|
updatePages();
|
|
|
|
}
|
|
|
|
}
|
2013-05-08 13:55:15 +02:00
|
|
|
|
2012-05-03 05:26:05 +02:00
|
|
|
}
|