diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 0fc841ce6e..b112c3f38c 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -46,7 +46,7 @@ add_openmw_dir (mwsound add_openmw_dir (mwworld refdata world physicssystem scene globals class action nullaction actionteleport containerstore actiontalk actiontake manualref player cellfunctors - cells localscripts customdata weather inventorystore ptr + cells localscripts customdata weather inventorystore ptr actionread ) add_openmw_dir (mwclass diff --git a/apps/openmw/mwclass/book.cpp b/apps/openmw/mwclass/book.cpp index ab659b4805..2409f95e45 100644 --- a/apps/openmw/mwclass/book.cpp +++ b/apps/openmw/mwclass/book.cpp @@ -8,7 +8,7 @@ #include "../mwbase/environment.hpp" #include "../mwworld/ptr.hpp" -#include "../mwworld/actiontake.hpp" +#include "../mwworld/actionread.hpp" #include "../mwworld/world.hpp" #include "../mwrender/objects.hpp" @@ -60,12 +60,8 @@ namespace MWClass boost::shared_ptr Book::activate (const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const { - // TODO implement reading - - MWBase::Environment::get().getSoundManager()->playSound3D (ptr, getUpSoundId(ptr), 1.0, 1.0, MWSound::Play_NoTrack); - return boost::shared_ptr ( - new MWWorld::ActionTake (ptr)); + new MWWorld::ActionRead (ptr)); } std::string Book::getScript (const MWWorld::Ptr& ptr) const diff --git a/apps/openmw/mwgui/bookwindow.cpp b/apps/openmw/mwgui/bookwindow.cpp index ce816a6693..4b6082b814 100644 --- a/apps/openmw/mwgui/bookwindow.cpp +++ b/apps/openmw/mwgui/bookwindow.cpp @@ -1,15 +1,58 @@ #include "bookwindow.hpp" +#include "../mwbase/environment.hpp" +#include "../mwinput/inputmanager.hpp" +#include "../mwsound/soundmanager.hpp" +#include "../mwworld/actiontake.hpp" + using namespace MWGui; -BookWindow::BookWindow(WindowManager& parWindowManager) : +BookWindow::BookWindow (WindowManager& parWindowManager) : WindowBase("openmw_book_layout.xml", parWindowManager) { - //setVisible(false); + getWidget(mCloseButton, "CloseButton"); + mCloseButton->eventMouseButtonClick += MyGUI::newDelegate(this, &BookWindow::onCloseButtonClicked); + + getWidget(mTakeButton, "TakeButton"); + mTakeButton->eventMouseButtonClick += MyGUI::newDelegate(this, &BookWindow::onTakeButtonClicked); + + getWidget(mNextPageButton, "NextPageBTN"); + mNextPageButton->eventMouseButtonClick += MyGUI::newDelegate(this, &BookWindow::onNextPageButtonClicked); + + getWidget(mPrevPageButton, "PrevPageBTN"); + mPrevPageButton->eventMouseButtonClick += MyGUI::newDelegate(this, &BookWindow::onPrevPageButtonClicked); + center(); } -void BookWindow::open(MWWorld::Ptr book) +void BookWindow::open (MWWorld::Ptr book) +{ + MWBase::Environment::get().getSoundManager()->playSound3D (book, "book open", 1.0, 1.0); + + mBook = book; +} + +void BookWindow::onCloseButtonClicked (MyGUI::Widget* _sender) +{ + MWBase::Environment::get().getSoundManager()->playSound3D (mBook, "book close", 1.0, 1.0); + + MWBase::Environment::get().getInputManager()->setGuiMode(MWGui::GM_Game); +} + +void BookWindow::onTakeButtonClicked (MyGUI::Widget* _sender) +{ + MWBase::Environment::get().getSoundManager()->playSound3D (mBook, "Item Book Up", 1.0, 1.0, MWSound::Play_NoTrack); + + MWWorld::ActionTake take(mBook); + take.execute(); + + MWBase::Environment::get().getInputManager()->setGuiMode (GM_Game); +} + +void BookWindow::onNextPageButtonClicked (MyGUI::Widget* _sender) { } +void BookWindow::onPrevPageButtonClicked (MyGUI::Widget* _sender) +{ +} diff --git a/apps/openmw/mwgui/bookwindow.hpp b/apps/openmw/mwgui/bookwindow.hpp index 57f45f0172..bc017e326f 100644 --- a/apps/openmw/mwgui/bookwindow.hpp +++ b/apps/openmw/mwgui/bookwindow.hpp @@ -12,6 +12,20 @@ namespace MWGui public: BookWindow(WindowManager& parWindowManager); void open(MWWorld::Ptr book); + + protected: + void onNextPageButtonClicked (MyGUI::Widget* _sender); + void onPrevPageButtonClicked (MyGUI::Widget* _sender); + void onCloseButtonClicked (MyGUI::Widget* _sender); + void onTakeButtonClicked (MyGUI::Widget* _sender); + + private: + MyGUI::Button* mCloseButton; + MyGUI::Button* mTakeButton; + MyGUI::Button* mNextPageButton; + MyGUI::Button* mPrevPageButton; + + MWWorld::Ptr mBook; }; } diff --git a/apps/openmw/mwgui/mode.hpp b/apps/openmw/mwgui/mode.hpp index 55f0952ce5..fa31bb1c4e 100644 --- a/apps/openmw/mwgui/mode.hpp +++ b/apps/openmw/mwgui/mode.hpp @@ -12,12 +12,12 @@ namespace MWGui GM_Console, // Console mode GM_Journal, // Journal mode - // None of the following are implemented yet + GM_Scroll, // Read scroll + GM_Book, // Read book GM_Dialogue, // NPC interaction GM_Barter, GM_Rest, - // .. more here .. // Startup character creation dialogs GM_Name, diff --git a/apps/openmw/mwgui/scrollwindow.cpp b/apps/openmw/mwgui/scrollwindow.cpp index ab4065e418..a5135722fc 100644 --- a/apps/openmw/mwgui/scrollwindow.cpp +++ b/apps/openmw/mwgui/scrollwindow.cpp @@ -1,14 +1,44 @@ #include "scrollwindow.hpp" +#include "../mwbase/environment.hpp" +#include "../mwinput/inputmanager.hpp" +#include "../mwworld/actiontake.hpp" +#include "../mwsound/soundmanager.hpp" + using namespace MWGui; -ScrollWindow::ScrollWindow(WindowManager& parWindowManager) : +ScrollWindow::ScrollWindow (WindowManager& parWindowManager) : WindowBase("openmw_scroll_layout.xml", parWindowManager) { - setVisible(false); + getWidget(mCloseButton, "CloseButton"); + mCloseButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ScrollWindow::onCloseButtonClicked); + + getWidget(mTakeButton, "TakeButton"); + mTakeButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ScrollWindow::onTakeButtonClicked); + center(); } -void ScrollWindow::open(MWWorld::Ptr scroll) +void ScrollWindow::open (MWWorld::Ptr scroll) { + MWBase::Environment::get().getSoundManager()->playSound3D (scroll, "scroll", 1.0, 1.0); + + mScroll = scroll; +} + +void ScrollWindow::onCloseButtonClicked (MyGUI::Widget* _sender) +{ + MWBase::Environment::get().getSoundManager()->playSound3D (mScroll, "scroll", 1.0, 1.0); + + MWBase::Environment::get().getInputManager()->setGuiMode (GM_Game); +} + +void ScrollWindow::onTakeButtonClicked (MyGUI::Widget* _sender) +{ + MWBase::Environment::get().getSoundManager()->playSound3D (mScroll, "Item Book Up", 1.0, 1.0, MWSound::Play_NoTrack); + + MWWorld::ActionTake take(mScroll); + take.execute(); + + MWBase::Environment::get().getInputManager()->setGuiMode (GM_Game); } diff --git a/apps/openmw/mwgui/scrollwindow.hpp b/apps/openmw/mwgui/scrollwindow.hpp index d7f5cd686c..e4968995e4 100644 --- a/apps/openmw/mwgui/scrollwindow.hpp +++ b/apps/openmw/mwgui/scrollwindow.hpp @@ -10,8 +10,18 @@ namespace MWGui class ScrollWindow : public WindowBase { public: - ScrollWindow(WindowManager& parWindowManager); - void open(MWWorld::Ptr scroll); + ScrollWindow (WindowManager& parWindowManager); + void open (MWWorld::Ptr scroll); + + protected: + void onCloseButtonClicked (MyGUI::Widget* _sender); + void onTakeButtonClicked (MyGUI::Widget* _sender); + + private: + MyGUI::Button* mCloseButton; + MyGUI::Button* mTakeButton; + + MWWorld::Ptr mScroll; }; } diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index 40fc9308d7..d082efe0c9 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -185,6 +185,8 @@ void WindowManager::updateVisible() stats->setVisible(false); console->disable(); mJournal->setVisible(false); + mScrollWindow->setVisible(false); + mBookWindow->setVisible(false); dialogueWindow->setVisible(false); // Mouse is visible whenever we're not in game mode @@ -205,6 +207,12 @@ void WindowManager::updateVisible() case GM_Console: console->enable(); break; + case GM_Scroll: + mScrollWindow->setVisible(true); + break; + case GM_Book: + mBookWindow->setVisible(true); + break; case GM_Name: case GM_Race: case GM_Class: diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index 13da6c7f01..b84c74441b 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -127,6 +127,9 @@ namespace MWGui MWGui::DialogueWindow* getDialogueWindow() {return dialogueWindow;} + MWGui::BookWindow* getBookWindow() {return mBookWindow;} + MWGui::ScrollWindow* getScrollWindow() {return mScrollWindow;} + MyGUI::Gui* getGui() const { return gui; } void wmUpdateFps(float fps, size_t triangleCount, size_t batchCount) diff --git a/apps/openmw/mwworld/actionread.cpp b/apps/openmw/mwworld/actionread.cpp new file mode 100644 index 0000000000..0d37e06f58 --- /dev/null +++ b/apps/openmw/mwworld/actionread.cpp @@ -0,0 +1,31 @@ +#include "actionread.hpp" + +#include "../mwbase/environment.hpp" +#include "../mwgui/window_manager.hpp" +#include "../mwgui/bookwindow.hpp" +#include "../mwgui/scrollwindow.hpp" + +namespace MWWorld +{ + ActionRead::ActionRead (const MWWorld::Ptr& object) : mObject (object) + { + } + + void ActionRead::execute () + { + ESMS::LiveCellRef *ref = + mObject.get(); + + if (ref->base->data.isScroll) + { + MWBase::Environment::get().getWindowManager()->setGuiMode(MWGui::GM_Scroll); + MWBase::Environment::get().getWindowManager()->getScrollWindow()->open(mObject); + } + else + { + MWBase::Environment::get().getWindowManager()->setGuiMode(MWGui::GM_Book); + MWBase::Environment::get().getWindowManager()->getBookWindow()->open(mObject); + } + } +} + diff --git a/apps/openmw/mwworld/actionread.hpp b/apps/openmw/mwworld/actionread.hpp new file mode 100644 index 0000000000..a4b495f794 --- /dev/null +++ b/apps/openmw/mwworld/actionread.hpp @@ -0,0 +1,21 @@ +#ifndef GAME_MWWORLD_ACTIONREAD_H +#define GAME_MWWORLD_ACTIONREAD_H + +#include "action.hpp" +#include "ptr.hpp" + +namespace MWWorld +{ + class ActionRead : public Action + { + Ptr mObject; // book or scroll to read + + public: + /// @param book or scroll to read + ActionRead (const Ptr& object); + + virtual void execute (); + }; +} + +#endif // ACTIONOPEN_H