2012-05-03 01:33:33 +00:00
|
|
|
#include "bookwindow.hpp"
|
|
|
|
|
2015-01-10 01:50:43 +00:00
|
|
|
#include <MyGUI_TextBox.h>
|
|
|
|
|
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"
|
2012-05-10 09:03:27 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
namespace MWGui
|
2012-05-03 01:33:33 +00:00
|
|
|
{
|
2012-05-03 03:26:05 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
BookWindow::BookWindow ()
|
|
|
|
: WindowBase("openmw_book.layout")
|
2015-05-01 00:24:27 +00:00
|
|
|
, mCurrentPage(0)
|
2013-04-17 22:56:48 +00:00
|
|
|
, mTakeButtonShow(true)
|
|
|
|
, mTakeButtonAllowed(true)
|
|
|
|
{
|
|
|
|
getWidget(mCloseButton, "CloseButton");
|
|
|
|
mCloseButton->eventMouseButtonClick += MyGUI::newDelegate(this, &BookWindow::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, &BookWindow::onTakeButtonClicked);
|
2012-05-03 03:26:05 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
getWidget(mNextPageButton, "NextPageBTN");
|
|
|
|
mNextPageButton->eventMouseButtonClick += MyGUI::newDelegate(this, &BookWindow::onNextPageButtonClicked);
|
2012-05-03 03:26:05 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
getWidget(mPrevPageButton, "PrevPageBTN");
|
|
|
|
mPrevPageButton->eventMouseButtonClick += MyGUI::newDelegate(this, &BookWindow::onPrevPageButtonClicked);
|
2012-05-10 09:03:27 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
getWidget(mLeftPageNumber, "LeftPageNumber");
|
|
|
|
getWidget(mRightPageNumber, "RightPageNumber");
|
2012-05-10 09:03:27 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
getWidget(mLeftPage, "LeftPage");
|
|
|
|
getWidget(mRightPage, "RightPage");
|
2012-05-03 01:33:33 +00:00
|
|
|
|
2013-05-08 11:55:15 +00:00
|
|
|
adjustButton(mCloseButton);
|
|
|
|
adjustButton(mTakeButton);
|
|
|
|
adjustButton(mNextPageButton);
|
|
|
|
adjustButton(mPrevPageButton);
|
|
|
|
|
2014-01-04 00:13:19 +00:00
|
|
|
mLeftPage->setNeedMouseFocus(true);
|
|
|
|
mLeftPage->eventMouseWheel += MyGUI::newDelegate(this, &BookWindow::onMouseWheel);
|
|
|
|
mRightPage->setNeedMouseFocus(true);
|
|
|
|
mRightPage->eventMouseWheel += MyGUI::newDelegate(this, &BookWindow::onMouseWheel);
|
|
|
|
|
2013-05-08 11:55:15 +00: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);
|
|
|
|
mNextPageButton->setImageCoord(MyGUI::IntCoord(0,0,64-7,mNextPageButton->getSize().height));
|
|
|
|
}
|
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
center();
|
|
|
|
}
|
|
|
|
|
2014-01-04 00:13:19 +00:00
|
|
|
void BookWindow::onMouseWheel(MyGUI::Widget *_sender, int _rel)
|
|
|
|
{
|
|
|
|
if (_rel < 0)
|
|
|
|
nextPage();
|
|
|
|
else
|
|
|
|
prevPage();
|
|
|
|
}
|
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
void BookWindow::clearPages()
|
2012-05-10 09:03:27 +00:00
|
|
|
{
|
2013-04-17 22:56:48 +00:00
|
|
|
mPages.clear();
|
2012-05-10 09:03:27 +00:00
|
|
|
}
|
2012-05-03 03:26:05 +00:00
|
|
|
|
2015-06-04 18:31:28 +00:00
|
|
|
void BookWindow::openBook (MWWorld::Ptr book, bool showTakeButton)
|
2013-04-17 22:56:48 +00:00
|
|
|
{
|
|
|
|
mBook = book;
|
2012-05-07 22:39:52 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
clearPages();
|
|
|
|
mCurrentPage = 0;
|
2012-05-10 09:03:27 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
MWBase::Environment::get().getSoundManager()->playSound ("book open", 1.0, 1.0);
|
2012-05-10 09:03:27 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::Book> *ref = mBook.get<ESM::Book>();
|
2012-05-07 22:39:52 +00:00
|
|
|
|
2014-09-19 22:11:04 +00:00
|
|
|
Formatting::BookFormatter formatter;
|
|
|
|
mPages = formatter.markupToWidget(mLeftPage, ref->mBase->mText);
|
|
|
|
formatter.markupToWidget(mRightPage, ref->mBase->mText);
|
2012-05-10 09:03:27 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
updatePages();
|
2012-05-15 16:05:53 +00:00
|
|
|
|
2015-03-11 19:33:55 +00:00
|
|
|
setTakeButtonShow(showTakeButton);
|
2013-04-17 22:56:48 +00:00
|
|
|
}
|
2012-05-15 16:05:53 +00:00
|
|
|
|
2014-05-27 03:13:37 +00:00
|
|
|
void BookWindow::exit()
|
|
|
|
{
|
|
|
|
// no 3d sounds because the object could be in a container.
|
|
|
|
MWBase::Environment::get().getSoundManager()->playSound ("book close", 1.0, 1.0);
|
|
|
|
|
|
|
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Book);
|
|
|
|
}
|
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
void BookWindow::setTakeButtonShow(bool show)
|
|
|
|
{
|
|
|
|
mTakeButtonShow = show;
|
|
|
|
mTakeButton->setVisible(mTakeButtonShow && mTakeButtonAllowed);
|
|
|
|
}
|
2013-02-17 14:56:22 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
void BookWindow::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 BookWindow::onCloseButtonClicked (MyGUI::Widget* sender)
|
|
|
|
{
|
2014-05-27 03:13:37 +00:00
|
|
|
exit();
|
2013-04-17 22:56:48 +00:00
|
|
|
}
|
2012-05-03 03:26:05 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
void BookWindow::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(mBook);
|
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_Book);
|
|
|
|
}
|
2012-05-03 03:26:05 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
void BookWindow::onNextPageButtonClicked (MyGUI::Widget* sender)
|
2012-05-10 09:03:27 +00:00
|
|
|
{
|
2013-06-13 05:50:07 +00:00
|
|
|
nextPage();
|
2012-05-10 09:03:27 +00:00
|
|
|
}
|
2012-05-03 01:33:33 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
void BookWindow::onPrevPageButtonClicked (MyGUI::Widget* sender)
|
2012-05-10 09:03:27 +00:00
|
|
|
{
|
2013-06-13 05:50:07 +00:00
|
|
|
prevPage();
|
2012-05-10 09:03:27 +00:00
|
|
|
}
|
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
void BookWindow::updatePages()
|
2012-05-10 09:03:27 +00:00
|
|
|
{
|
2015-01-10 02:01:01 +00:00
|
|
|
mLeftPageNumber->setCaption( MyGUI::utility::toString(mCurrentPage*2 + 1) );
|
|
|
|
mRightPageNumber->setCaption( MyGUI::utility::toString(mCurrentPage*2 + 2) );
|
2013-04-17 22:56:48 +00:00
|
|
|
|
2013-05-02 03:35:25 +00:00
|
|
|
//If it is the last page, hide the button "Next Page"
|
|
|
|
if ( (mCurrentPage+1)*2 == mPages.size()
|
|
|
|
|| (mCurrentPage+1)*2 == mPages.size() + 1)
|
|
|
|
{
|
|
|
|
mNextPageButton->setVisible(false);
|
|
|
|
} else {
|
|
|
|
mNextPageButton->setVisible(true);
|
|
|
|
}
|
|
|
|
//If it is the fist page, hide the button "Prev Page"
|
|
|
|
if (mCurrentPage == 0) {
|
|
|
|
mPrevPageButton->setVisible(false);
|
|
|
|
} else {
|
|
|
|
mPrevPageButton->setVisible(true);
|
|
|
|
}
|
2014-09-19 22:11:04 +00: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 09:03:27 +00:00
|
|
|
}
|
2013-04-17 22:56:48 +00:00
|
|
|
|
2014-09-12 03:14:21 +00:00
|
|
|
void BookWindow::adjustButton (Gui::ImageButton* button)
|
2013-05-08 11:55:15 +00: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));
|
|
|
|
}
|
2014-02-23 19:11:05 +00:00
|
|
|
|
2013-06-13 05:50:07 +00:00
|
|
|
void BookWindow::nextPage()
|
|
|
|
{
|
2013-06-13 05:52:26 +00:00
|
|
|
if ((mCurrentPage+1)*2 < mPages.size())
|
2013-06-13 05:50:07 +00:00
|
|
|
{
|
|
|
|
MWBase::Environment::get().getSoundManager()->playSound ("book page2", 1.0, 1.0);
|
|
|
|
|
|
|
|
++mCurrentPage;
|
|
|
|
|
|
|
|
updatePages();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void BookWindow::prevPage()
|
|
|
|
{
|
2013-06-13 05:52:26 +00:00
|
|
|
if (mCurrentPage > 0)
|
2013-06-13 05:50:07 +00:00
|
|
|
{
|
|
|
|
MWBase::Environment::get().getSoundManager()->playSound ("book page", 1.0, 1.0);
|
|
|
|
|
|
|
|
--mCurrentPage;
|
|
|
|
|
|
|
|
updatePages();
|
|
|
|
}
|
|
|
|
}
|
2013-05-08 11:55:15 +00:00
|
|
|
|
2012-05-03 03:26:05 +00:00
|
|
|
}
|