Skip to content

Commit

Permalink
MenuBook: Allow closing of open book with book=close event
Browse files Browse the repository at this point in the history
  • Loading branch information
dorkster committed Dec 31, 2024
1 parent 0eb5c75 commit 1ec0bfa
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 15 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion docs/attribute-reference.html
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ <h4>EventManager</h4>

<p><strong>event.save_game</strong> | <code>bool</code> | If true, the game is saved when the event is triggered. The respawn position is set to where the player is standing.</p>

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

<p><strong>event.script</strong> | <code>filename</code> | Loads and executes an Event from a file.</p>

Expand Down
2 changes: 1 addition & 1 deletion src/EventManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/GameStatePlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/MenuBook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 5 additions & 4 deletions src/MenuBook.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -95,6 +92,10 @@ class MenuBook : public Menu {
{}
};

std::string book_name;
std::string last_book_name;
bool book_loaded;

WidgetButton *closeButton;
std::vector<BookImage> images;
std::vector<BookText> text;
Expand Down
6 changes: 2 additions & 4 deletions src/MenuManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ FLARE. If not, see http://www.gnu.org/licenses/

#include <SDL.h>

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);

Expand Down

0 comments on commit 1ec0bfa

Please sign in to comment.