diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index af940d261..da7409fe4 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -20,6 +20,7 @@ Engine features: * New mouse movment behavior. Click once to move the player to a target and, if applicable, interact with it. * Stats on the character page are now organized by categories: Core, Offense, Defense, and Misc. * Speed and Attack Speed are now able to be shown in the Character menu. +* Events can now use 'book=close' to close the active book. * Android: Enabled use of external input devices (gamepads, keyboards, mice) Engine fixes: diff --git a/docs/attribute-reference.html b/docs/attribute-reference.html index a2f562d2d..6f098f76f 100644 --- a/docs/attribute-reference.html +++ b/docs/attribute-reference.html @@ -664,7 +664,7 @@

EventManager

event.save_game | bool | If true, the game is saved when the event is triggered. The respawn position is set to where the player is standing.

-

event.book | filename | Opens a book by filename.

+

event.book | ["close", filename] | Opens a book by filename. 'close' can be used in place of the filename to close an already open book.

event.script | filename | Loads and executes an Event from a file.

diff --git a/src/EventManager.cpp b/src/EventManager.cpp index 5f38105c2..3ba9b19b7 100644 --- a/src/EventManager.cpp +++ b/src/EventManager.cpp @@ -670,7 +670,7 @@ bool EventManager::loadEventComponentString(std::string &key, std::string &val, e->data[0].Bool = Parse::toBool(val); } else if (key == "book") { - // @ATTR event.book|filename|Opens a book by filename. + // @ATTR event.book|["close", filename]|Opens a book by filename. 'close' can be used in place of the filename to close an already open book. e->type = EventComponent::BOOK; e->s = val; diff --git a/src/GameStatePlay.cpp b/src/GameStatePlay.cpp index e2878122a..62887581d 100644 --- a/src/GameStatePlay.cpp +++ b/src/GameStatePlay.cpp @@ -481,14 +481,14 @@ void GameStatePlay::checkLog() { */ void GameStatePlay::checkBook() { // Map events can open books - if (mapr->show_book != "") { - menu->book->book_name = mapr->show_book; + if (!mapr->show_book.empty()) { + menu->book->setBookFilename(mapr->show_book); mapr->show_book = ""; } // items can be readable books - if (menu->inv->show_book != "") { - menu->book->book_name = menu->inv->show_book; + if (!menu->inv->show_book.empty()) { + menu->book->setBookFilename(menu->inv->show_book); menu->inv->show_book = ""; } } diff --git a/src/MenuBook.cpp b/src/MenuBook.cpp index 2198c1ac6..4b183f78d 100644 --- a/src/MenuBook.cpp +++ b/src/MenuBook.cpp @@ -51,6 +51,16 @@ MenuBook::MenuBook() tablist = TabList(); } +void MenuBook::setBookFilename(const std::string& filename) { + if (visible && (filename.empty() || filename == "close")) { + closeWindow(); + snd->play(sfx_close, snd->DEFAULT_CHANNEL, snd->NO_POS, !snd->LOOP); + } + else { + book_name = filename; + } +} + void MenuBook::loadBook() { if (last_book_name != book_name) { last_book_name.clear(); diff --git a/src/MenuBook.h b/src/MenuBook.h index 16bbf5606..5b887f294 100644 --- a/src/MenuBook.h +++ b/src/MenuBook.h @@ -42,10 +42,7 @@ class MenuBook : public Menu { void logic(); void render(); void closeWindow(); - - std::string book_name; - std::string last_book_name; - bool book_loaded; + void setBookFilename(const std::string& filename); private: class BookImage { @@ -95,6 +92,10 @@ class MenuBook : public Menu { {} }; + std::string book_name; + std::string last_book_name; + bool book_loaded; + WidgetButton *closeButton; std::vector images; std::vector text; diff --git a/src/MenuManager.cpp b/src/MenuManager.cpp index 7d61f061f..260707947 100644 --- a/src/MenuManager.cpp +++ b/src/MenuManager.cpp @@ -1647,8 +1647,7 @@ void MenuManager::closeLeft() { questlog->visible = false; exit->visible = false; stash->visible = false; - book->closeWindow(); - book->book_name = ""; + book->setBookFilename(""); num_picker->visible = false; talker->setNPC(NULL); @@ -1666,8 +1665,7 @@ void MenuManager::closeRight() { inv->visible = false; pow->visible = false; exit->visible = false; - book->closeWindow(); - book->book_name = ""; + book->setBookFilename(""); num_picker->visible = false; talker->setNPC(NULL); diff --git a/src/Version.cpp b/src/Version.cpp index dca293749..cc17aa9c5 100644 --- a/src/Version.cpp +++ b/src/Version.cpp @@ -30,7 +30,7 @@ FLARE. If not, see http://www.gnu.org/licenses/ #include -Version VersionInfo::ENGINE(1, 14, 80); +Version VersionInfo::ENGINE(1, 14, 81); Version VersionInfo::MIN(0, 0, 0); Version VersionInfo::MAX(USHRT_MAX, USHRT_MAX, USHRT_MAX);