game[talk]: try to allow more go back

+ add a hidden go front option using left/right arrow
This commit is contained in:
ALONSO Laurent
2021-10-08 10:03:27 +02:00
committed by Celtic Minstrel
parent 9ef5463364
commit 278c315df4
5 changed files with 64 additions and 32 deletions

View File

@@ -569,9 +569,10 @@ void cDialog::handle_events() {
// Ideally, this should be the only draw call that is done in a cycle. // Ideally, this should be the only draw call that is done in a cycle.
if (need_redraw) if (need_redraw)
draw(); draw();
else
// Prevent the loop from executing too fast. // Prevent the loop from executing too fast
fps_limiter.frame_finished(); // when the user does nothing
fps_limiter.frame_finished();
} }
} }

View File

@@ -1579,7 +1579,6 @@ bool handle_keystroke(const sf::Event& event){
kb::Numpad4,kb::Numpad5,kb::Numpad6, kb::Numpad4,kb::Numpad5,kb::Numpad6,
kb::Numpad7,kb::Numpad8,kb::Numpad9 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}; 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) { if(event.key.code == kb::Escape) {
@@ -1647,19 +1646,21 @@ bool handle_keystroke(const sf::Event& event){
if(overall_mode == MODE_TALKING) { if(overall_mode == MODE_TALKING) {
if(chr2 == kb::Escape) if(chr2 == kb::Escape)
chr2 = kb::D; chr2 = kb::D;
if(chr2 == kb::Space) if(chr2 == kb::Space || chr2== kb::Numpad4)
chr2 = kb::G; chr2 = kb::G;
for(short i = 0; i < 9; i++) 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};
if(chr2 == talk_chars[i] && (!talk_end_forced || i == 6 || i == 5)) { for(short i = 0; i < 10; i++) {
// related to talk_area_rect, unsure why adding +9 is needed? if(chr2 != talk_chars[i]) continue;
pass_point = talk_words[i].rect.topLeft(); if (talk_end_forced && i != 5 && i != 6) continue;
pass_point.x += talk_area_rect.left+9; // related to talk_area_rect, unsure why adding +9 is needed?
pass_point.y += talk_area_rect.top+9; pass_point = talk_words[i].rect.topLeft();
pass_point = mainPtr.mapCoordsToPixel(pass_point, mainView); pass_point.x += talk_area_rect.left+9;
pass_event.mouseButton.x = pass_point.x; pass_point.y += talk_area_rect.top+9;
pass_event.mouseButton.y = pass_point.y; pass_point = mainPtr.mapCoordsToPixel(pass_point, mainView);
are_done = handle_action(pass_event); 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 else if(overall_mode == MODE_SHOPPING) { // shopping keystrokes
if(chr2 == kb::Escape) { if(chr2 == kb::Escape) {

View File

@@ -77,6 +77,8 @@ bool can_save_talk;
short store_talk_face_pic; short store_talk_face_pic;
int current_talk_node; int current_talk_node;
extern std::vector<word_rect_t> talk_words; extern std::vector<word_rect_t> talk_words;
static size_t talk_history_pos;
static std::vector<int> talk_history_nodes;
// Shopping vars // 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) { static void update_last_talk(int new_node) {
// Store last node in the Go Back button if (new_node==TALK_BUY || new_node==TALK_BUSINESS || new_node==TALK_SELL)
for(word_rect_t& word : talk_words) { return;
if(word.word != "Go Back") continue; // Store last node in the Go Back/Front button
word.node = current_talk_node; if (talk_history_pos>=talk_history_nodes.size())
current_talk_node = new_node; talk_history_nodes.push_back(new_node);
break; 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() { 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 // first initialise talk_words here
talk_words.clear(); 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{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,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}, rectangle{343,4,363,134},
}; };
static const char*const preset_words[9] = { static const char*const preset_words[10] = {
"Look", "Name", "Job", "Look", "Name", "Job",
"Buy", "Sell", "Record", "Buy", "Sell", "Record",
"Done", "Go Back", "Done", "Go Back", "Go Front",
"Ask About...", "Ask About...",
}; };
// Place buttons at bottom. // 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]); word_rect_t preset_word(preset_words[i], preset_rects[i]);
preset_word.on = Colours::DARK_GREEN; preset_word.on = Colours::DARK_GREEN;
preset_word.off = Colours::LIGHT_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 5: preset_word.node = TALK_RECORD; break;
case 6: preset_word.node = TALK_DONE; break; case 6: preset_word.node = TALK_DONE; break;
case 7: preset_word.node = TALK_BACK; 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); 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 = ""; save_talk_str2 = "";
can_save_talk = true; 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); place_talk_str(save_talk_str1, "", 0, dummy_rect);
put_item_screen(stat_window); put_item_screen(stat_window);
@@ -742,12 +751,28 @@ void handle_talk_event(location p) {
wordRect.offset(talk_area_rect.topLeft()); 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... wordRect.offset(-1, -10); // TODO: This corrects for the byzantine offsets that win_draw_string applies for some reason...
if(!p.in(wordRect)) continue; if(!p.in(wordRect)) continue;
click_talk_rect(word); if (word.node != TALK_FRONT)
click_talk_rect(word);
which_talk_entry = word.node; which_talk_entry = word.node;
break; break;
} }
if(which_talk_entry == TALK_DUNNO) if(which_talk_entry == TALK_DUNNO)
return; 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) { switch(which_talk_entry) {
case TALK_DUNNO: case TALK_DUNNO:
@@ -810,6 +835,8 @@ void handle_talk_event(location p) {
SPECIAL_DONE: SPECIAL_DONE:
end_talk_mode(); end_talk_mode();
return; 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 case TALK_BACK: // only if there's nothing to go back to
return; // so, there's nothing to do here return; // so, there's nothing to do here
case TALK_ASK: // ask about case TALK_ASK: // ask about

View File

@@ -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; style.colour = Colours::DARK_GREEN;
else else
style.colour = Colours::LIGHT_GREEN; 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) 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); 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<rectangle> word_rects = draw_string_hilite(talk_gworld, word_place_rect, str, style, hilites, color ? Colours::DARK_BLUE : Colours::DARK_RED); std::vector<rectangle> word_rects = draw_string_hilite(talk_gworld, word_place_rect, str, style, hilites, color ? Colours::DARK_BLUE : Colours::DARK_RED);
if(!talk_end_forced) { 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 // Now build the list of word rects
for(size_t i = 0; i < hilites.size(); i++) { for(size_t i = 0; i < hilites.size(); i++) {
word_rect_t thisRect; word_rect_t thisRect;

View File

@@ -27,6 +27,7 @@ enum {
TALK_DONE = -14, TALK_DONE = -14,
TALK_BACK = -15, TALK_BACK = -15,
TALK_ASK = -16, TALK_ASK = -16,
TALK_FRONT = -17,
}; };
void apply_unseen_mask(); void apply_unseen_mask();