From 278c315df4c66526fc56045fd99f4b935573fb7a Mon Sep 17 00:00:00 2001 From: ALONSO Laurent Date: Fri, 8 Oct 2021 10:03:27 +0200 Subject: [PATCH] game[talk]: try to allow more go back + add a hidden go front option using left/right arrow --- src/dialogxml/dialogs/dialog.cpp | 7 ++-- src/game/boe.actions.cpp | 27 ++++++++-------- src/game/boe.dlgutil.cpp | 55 ++++++++++++++++++++++++-------- src/game/boe.newgraph.cpp | 6 ++-- src/game/boe.newgraph.hpp | 1 + 5 files changed, 64 insertions(+), 32 deletions(-) diff --git a/src/dialogxml/dialogs/dialog.cpp b/src/dialogxml/dialogs/dialog.cpp index 77146d07..50b4fc8b 100644 --- a/src/dialogxml/dialogs/dialog.cpp +++ b/src/dialogxml/dialogs/dialog.cpp @@ -569,9 +569,10 @@ void cDialog::handle_events() { // Ideally, this should be the only draw call that is done in a cycle. if (need_redraw) draw(); - - // Prevent the loop from executing too fast. - fps_limiter.frame_finished(); + else + // Prevent the loop from executing too fast + // when the user does nothing + fps_limiter.frame_finished(); } } diff --git a/src/game/boe.actions.cpp b/src/game/boe.actions.cpp index a80d5ab8..e3d094f9 100644 --- a/src/game/boe.actions.cpp +++ b/src/game/boe.actions.cpp @@ -1579,7 +1579,6 @@ bool handle_keystroke(const sf::Event& event){ kb::Numpad4,kb::Numpad5,kb::Numpad6, kb::Numpad7,kb::Numpad8,kb::Numpad9 }; - Key talk_chars[9] = {kb::L,kb::N,kb::J,kb::B,kb::S,kb::R,kb::D,kb::G,kb::A}; Key shop_chars[8] = {kb::A,kb::B,kb::C,kb::D,kb::E,kb::F,kb::G,kb::H}; if(event.key.code == kb::Escape) { @@ -1647,19 +1646,21 @@ bool handle_keystroke(const sf::Event& event){ if(overall_mode == MODE_TALKING) { if(chr2 == kb::Escape) chr2 = kb::D; - if(chr2 == kb::Space) + if(chr2 == kb::Space || chr2== kb::Numpad4) chr2 = kb::G; - for(short i = 0; i < 9; i++) - if(chr2 == talk_chars[i] && (!talk_end_forced || i == 6 || i == 5)) { - // related to talk_area_rect, unsure why adding +9 is needed? - pass_point = talk_words[i].rect.topLeft(); - pass_point.x += talk_area_rect.left+9; - pass_point.y += talk_area_rect.top+9; - pass_point = mainPtr.mapCoordsToPixel(pass_point, mainView); - pass_event.mouseButton.x = pass_point.x; - pass_event.mouseButton.y = pass_point.y; - are_done = handle_action(pass_event); - } + Key const talk_chars[10] = {kb::L,kb::N,kb::J,kb::B,kb::S,kb::R,kb::D,kb::G,kb::Numpad6,kb::A}; + for(short i = 0; i < 10; i++) { + if(chr2 != talk_chars[i]) continue; + if (talk_end_forced && i != 5 && i != 6) continue; + // related to talk_area_rect, unsure why adding +9 is needed? + pass_point = talk_words[i].rect.topLeft(); + pass_point.x += talk_area_rect.left+9; + pass_point.y += talk_area_rect.top+9; + pass_point = mainPtr.mapCoordsToPixel(pass_point, mainView); + pass_event.mouseButton.x = pass_point.x; + pass_event.mouseButton.y = pass_point.y; + are_done = handle_action(pass_event); + } } else if(overall_mode == MODE_SHOPPING) { // shopping keystrokes if(chr2 == kb::Escape) { diff --git a/src/game/boe.dlgutil.cpp b/src/game/boe.dlgutil.cpp index c25afeb1..fe3f5758 100644 --- a/src/game/boe.dlgutil.cpp +++ b/src/game/boe.dlgutil.cpp @@ -77,6 +77,8 @@ bool can_save_talk; short store_talk_face_pic; int current_talk_node; extern std::vector talk_words; +static size_t talk_history_pos; +static std::vector talk_history_nodes; // Shopping vars @@ -154,13 +156,16 @@ void start_shop_mode(short which,short cost_adj,std::string store_name) { } static void update_last_talk(int new_node) { - // Store last node in the Go Back button - for(word_rect_t& word : talk_words) { - if(word.word != "Go Back") continue; - word.node = current_talk_node; - current_talk_node = new_node; - break; + if (new_node==TALK_BUY || new_node==TALK_BUSINESS || new_node==TALK_SELL) + return; + // Store last node in the Go Back/Front button + if (talk_history_pos>=talk_history_nodes.size()) + talk_history_nodes.push_back(new_node); + else if (new_node != talk_history_nodes[talk_history_pos]) { + talk_history_nodes[talk_history_pos]=new_node; + talk_history_nodes.resize(talk_history_pos+1); } + ++talk_history_pos; } void end_shop_mode() { @@ -595,21 +600,21 @@ void start_talk_mode(short m_num,short personality,mon_num_t monst_type,short st // first initialise talk_words here talk_words.clear(); - static const rectangle preset_rects[9] = { + static const rectangle preset_rects[10] = { rectangle{366,4,386,54}, rectangle{366,70,386,130}, rectangle{366,136,386,186}, rectangle{389,4,409,54}, rectangle{389,70,409,120}, rectangle{389,121,409,186}, - rectangle{389,210,409,270}, rectangle{366,190,386,270}, + rectangle{389,210,409,270}, rectangle{366,190,386,270}, rectangle{1999,1999,2100,2100}, rectangle{343,4,363,134}, }; - static const char*const preset_words[9] = { + static const char*const preset_words[10] = { "Look", "Name", "Job", "Buy", "Sell", "Record", - "Done", "Go Back", + "Done", "Go Back", "Go Front", "Ask About...", }; // Place buttons at bottom. - for(short i = 0; i < 9; i++) { + for(short i = 0; i < 10; i++) { word_rect_t preset_word(preset_words[i], preset_rects[i]); preset_word.on = Colours::DARK_GREEN; preset_word.off = Colours::LIGHT_GREEN; @@ -622,7 +627,8 @@ void start_talk_mode(short m_num,short personality,mon_num_t monst_type,short st case 5: preset_word.node = TALK_RECORD; break; case 6: preset_word.node = TALK_DONE; break; case 7: preset_word.node = TALK_BACK; break; - case 8: preset_word.node = TALK_ASK; break; + case 8: preset_word.node = TALK_FRONT; break; + case 9: preset_word.node = TALK_ASK; break; } talk_words.push_back(preset_word); } @@ -635,6 +641,9 @@ void start_talk_mode(short m_num,short personality,mon_num_t monst_type,short st save_talk_str2 = ""; can_save_talk = true; + talk_history_nodes.clear(); + talk_history_nodes.push_back(TALK_LOOK); + talk_history_pos=1; place_talk_str(save_talk_str1, "", 0, dummy_rect); put_item_screen(stat_window); @@ -742,13 +751,29 @@ void handle_talk_event(location p) { wordRect.offset(talk_area_rect.topLeft()); wordRect.offset(-1, -10); // TODO: This corrects for the byzantine offsets that win_draw_string applies for some reason... if(!p.in(wordRect)) continue; - click_talk_rect(word); + if (word.node != TALK_FRONT) + click_talk_rect(word); which_talk_entry = word.node; break; } if(which_talk_entry == TALK_DUNNO) return; - + if (which_talk_entry==TALK_BACK) { + if (talk_history_pos<2 || talk_history_pos>=talk_history_nodes.size()+2) { + beep(); + return; + } + talk_history_pos-=2; + which_talk_entry=talk_history_nodes[talk_history_pos]; + } + else if (which_talk_entry==TALK_FRONT) { + if (talk_history_pos>=talk_history_nodes.size()) { + beep(); + return; + } + which_talk_entry=talk_history_nodes[talk_history_pos]; + } + switch(which_talk_entry) { case TALK_DUNNO: SPECIAL_DUNNO: @@ -810,6 +835,8 @@ void handle_talk_event(location p) { SPECIAL_DONE: end_talk_mode(); return; + case TALK_FRONT:// only if there's nothing to go front to + return; // so, there's nothing to do here case TALK_BACK: // only if there's nothing to go back to return; // so, there's nothing to do here case TALK_ASK: // ask about diff --git a/src/game/boe.newgraph.cpp b/src/game/boe.newgraph.cpp index 17b6f4f1..f58d4966 100644 --- a/src/game/boe.newgraph.cpp +++ b/src/game/boe.newgraph.cpp @@ -949,7 +949,9 @@ void place_talk_str(std::string str_to_place,std::string str_to_place2,short col style.colour = Colours::DARK_GREEN; else style.colour = Colours::LIGHT_GREEN; - for(short i = 0; i < 9; i++) { + for(short i = 0; i < 10; i++) { + if (i==8) // TALK_FRONT shadow + continue; if(!talk_end_forced || i == 6 || i == 5) win_draw_string(talk_gworld,talk_words[i].rect,talk_words[i].word,eTextMode::LEFT_TOP,style); } @@ -978,7 +980,7 @@ void place_talk_str(std::string str_to_place,std::string str_to_place2,short col std::vector word_rects = draw_string_hilite(talk_gworld, word_place_rect, str, style, hilites, color ? Colours::DARK_BLUE : Colours::DARK_RED); if(!talk_end_forced) { - talk_words.resize(9); // clean the talk_words (if this code is called many times) + talk_words.resize(10); // clean the talk_words (if this code is called many times) // Now build the list of word rects for(size_t i = 0; i < hilites.size(); i++) { word_rect_t thisRect; diff --git a/src/game/boe.newgraph.hpp b/src/game/boe.newgraph.hpp index e531a8ad..f8880b63 100644 --- a/src/game/boe.newgraph.hpp +++ b/src/game/boe.newgraph.hpp @@ -27,6 +27,7 @@ enum { TALK_DONE = -14, TALK_BACK = -15, TALK_ASK = -16, + TALK_FRONT = -17, }; void apply_unseen_mask();