1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-23 15:39:42 +00:00

Book/scroll window refactoring

This commit is contained in:
scrawl 2015-03-11 20:33:55 +01:00
parent 37a6d7da76
commit 48ea6286fd
9 changed files with 33 additions and 41 deletions

View file

@ -150,8 +150,6 @@ namespace MWBase
/// \todo investigate, if we really need to expose every single lousy UI element to the outside world
virtual MWGui::DialogueWindow* getDialogueWindow() = 0;
virtual MWGui::InventoryWindow* getInventoryWindow() = 0;
virtual MWGui::BookWindow* getBookWindow() = 0;
virtual MWGui::ScrollWindow* getScrollWindow() = 0;
virtual MWGui::CountDialog* getCountDialog() = 0;
virtual MWGui::ConfirmationDialog* getConfirmationDialog() = 0;
virtual MWGui::TradeWindow* getTradeWindow() = 0;
@ -300,6 +298,8 @@ namespace MWBase
virtual void startSpellBuying(const MWWorld::Ptr& actor) = 0;
virtual void startTrade(const MWWorld::Ptr& actor) = 0;
virtual void openContainer(const MWWorld::Ptr& container, bool loot) = 0;
virtual void showBook(const MWWorld::Ptr& item, bool showTakeButton) = 0;
virtual void showScroll(const MWWorld::Ptr& item, bool showTakeButton) = 0;
virtual void showSoulgemDialog (MWWorld::Ptr item) = 0;

View file

@ -73,7 +73,7 @@ namespace MWGui
mPages.clear();
}
void BookWindow::open (MWWorld::Ptr book)
void BookWindow::open (MWWorld::Ptr book, bool showTakeButton)
{
mBook = book;
@ -90,7 +90,7 @@ namespace MWGui
updatePages();
setTakeButtonShow(true);
setTakeButtonShow(showTakeButton);
}
void BookWindow::exit()

View file

@ -16,10 +16,7 @@ namespace MWGui
virtual void exit();
void open(MWWorld::Ptr book);
void setTakeButtonShow(bool show);
void nextPage();
void prevPage();
void open(MWWorld::Ptr book, bool showTakeButton);
void setInventoryAllowed(bool allowed);
protected:
@ -28,6 +25,10 @@ namespace MWGui
void onCloseButtonClicked (MyGUI::Widget* sender);
void onTakeButtonClicked (MyGUI::Widget* sender);
void onMouseWheel(MyGUI::Widget* _sender, int _rel);
void setTakeButtonShow(bool show);
void nextPage();
void prevPage();
void updatePages();
void clearPages();

View file

@ -23,8 +23,6 @@
#include "../mwbase/scriptmanager.hpp"
#include "../mwrender/characterpreview.hpp"
#include "bookwindow.hpp"
#include "scrollwindow.hpp"
#include "itemview.hpp"
#include "inventoryitemmodel.hpp"
#include "sortfilteritemmodel.hpp"
@ -430,13 +428,6 @@ namespace MWGui
action->execute (MWBase::Environment::get().getWorld()->getPlayerPtr());
// this is necessary for books/scrolls: if they are already in the player's inventory,
// the "Take" button should not be visible.
// NOTE: the take button is "reset" when the window opens, so we can safely do the following
// without screwing up future book windows
MWBase::Environment::get().getWindowManager()->getBookWindow()->setTakeButtonShow(false);
MWBase::Environment::get().getWindowManager()->getScrollWindow()->setTakeButtonShow(false);
mSkippedToEquip = MWWorld::Ptr();
}
else

View file

@ -48,7 +48,7 @@ namespace MWGui
center();
}
void ScrollWindow::open (MWWorld::Ptr scroll)
void ScrollWindow::open (MWWorld::Ptr scroll, bool showTakeButton)
{
// no 3d sounds because the object could be in a container.
MWBase::Environment::get().getSoundManager()->playSound ("scroll", 1.0, 1.0);
@ -71,7 +71,7 @@ namespace MWGui
mTextView->setViewOffset(MyGUI::IntPoint(0,0));
setTakeButtonShow(true);
setTakeButtonShow(showTakeButton);
}
void ScrollWindow::exit()

View file

@ -17,14 +17,14 @@ namespace MWGui
public:
ScrollWindow ();
void open (MWWorld::Ptr scroll);
void open (MWWorld::Ptr scroll, bool showTakeButton);
virtual void exit();
void setTakeButtonShow(bool show);
void setInventoryAllowed(bool allowed);
protected:
void onCloseButtonClicked (MyGUI::Widget* _sender);
void onTakeButtonClicked (MyGUI::Widget* _sender);
void setTakeButtonShow(bool show);
private:
Gui::ImageButton* mCloseButton;

View file

@ -1278,8 +1278,6 @@ namespace MWGui
MWGui::DialogueWindow* WindowManager::getDialogueWindow() { return mDialogueWindow; }
MWGui::InventoryWindow* WindowManager::getInventoryWindow() { return mInventoryWindow; }
MWGui::BookWindow* WindowManager::getBookWindow() { return mBookWindow; }
MWGui::ScrollWindow* WindowManager::getScrollWindow() { return mScrollWindow; }
MWGui::CountDialog* WindowManager::getCountDialog() { return mCountDialog; }
MWGui::ConfirmationDialog* WindowManager::getConfirmationDialog() { return mConfirmationDialog; }
MWGui::TradeWindow* WindowManager::getTradeWindow() { return mTradeWindow; }
@ -1898,4 +1896,16 @@ namespace MWGui
mContainerWindow->open(container, loot);
}
void WindowManager::showBook(const MWWorld::Ptr &item, bool showTakeButton)
{
pushGuiMode(GM_Book);
mBookWindow->open(item, showTakeButton);
}
void WindowManager::showScroll(const MWWorld::Ptr &item, bool showTakeButton)
{
pushGuiMode(GM_Scroll);
mScrollWindow->open(item, showTakeButton);
}
}

View file

@ -155,8 +155,6 @@ namespace MWGui
/// \todo investigate, if we really need to expose every single lousy UI element to the outside world
virtual MWGui::DialogueWindow* getDialogueWindow();
virtual MWGui::InventoryWindow* getInventoryWindow();
virtual MWGui::BookWindow* getBookWindow();
virtual MWGui::ScrollWindow* getScrollWindow();
virtual MWGui::CountDialog* getCountDialog();
virtual MWGui::ConfirmationDialog* getConfirmationDialog();
virtual MWGui::TradeWindow* getTradeWindow();
@ -293,6 +291,8 @@ namespace MWGui
virtual void startSpellBuying(const MWWorld::Ptr &actor);
virtual void startTrade(const MWWorld::Ptr &actor);
virtual void openContainer(const MWWorld::Ptr &container, bool loot);
virtual void showBook(const MWWorld::Ptr& item, bool showTakeButton);
virtual void showScroll(const MWWorld::Ptr& item, bool showTakeButton);
virtual void frameStarted(float dt);

View file

@ -4,13 +4,8 @@
#include "../mwbase/windowmanager.hpp"
#include "../mwbase/world.hpp"
#include "../mwworld/player.hpp"
#include "../mwmechanics/npcstats.hpp"
#include "../mwgui/bookwindow.hpp"
#include "../mwgui/scrollwindow.hpp"
#include "player.hpp"
#include "class.hpp"
#include "esmstore.hpp"
@ -33,27 +28,22 @@ namespace MWWorld
return;
}
bool showTakeButton = (getTarget().getContainerStore() != &actor.getClass().getContainerStore(actor));
LiveCellRef<ESM::Book> *ref = getTarget().get<ESM::Book>();
if (ref->mBase->mData.mIsScroll)
{
MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Scroll);
MWBase::Environment::get().getWindowManager()->getScrollWindow()->open(getTarget());
}
MWBase::Environment::get().getWindowManager()->showScroll(getTarget(), showTakeButton);
else
{
MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Book);
MWBase::Environment::get().getWindowManager()->getBookWindow()->open(getTarget());
}
MWBase::Environment::get().getWindowManager()->showBook(getTarget(), showTakeButton);
MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr();
MWMechanics::NpcStats& npcStats = player.getClass().getNpcStats (player);
MWMechanics::NpcStats& npcStats = actor.getClass().getNpcStats (actor);
// Skill gain from books
if (ref->mBase->mData.mSkillID >= 0 && ref->mBase->mData.mSkillID < ESM::Skill::Length
&& !npcStats.hasBeenUsed (ref->mBase->mId))
{
MWWorld::LiveCellRef<ESM::NPC> *playerRef = player.get<ESM::NPC>();
MWWorld::LiveCellRef<ESM::NPC> *playerRef = actor.get<ESM::NPC>();
const ESM::Class *class_ =
MWBase::Environment::get().getWorld()->getStore().get<ESM::Class>().find (