From e2e74507bbc5ce16bad61bedc0bd881acdbea280 Mon Sep 17 00:00:00 2001 From: j-p-e-g Date: Mon, 16 Jun 2008 13:51:20 +0000 Subject: Implemented a modified version of FR 1994116: change inscription interface. Instead of "Do you wish to inscribe this item? (y/n)" directly print "Add what to inscription? (You may also (a)utoinscribe or (c)lear it.)" (a) and (c) only where applicable, of course. This has two benefits: No extra prompt needed to inscribe anything, and I've finally managed to merge both the { prompt and inscribing from viewing into the same function. Escape or pressing Enter on an empty inscription string (or one only consisting of spaces) will return without changing anything. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@5879 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/describe.cc | 142 +++++++++++++++++++++---------------------- crawl-ref/source/describe.h | 2 +- crawl-ref/source/item_use.cc | 2 +- crawl-ref/source/tutorial.cc | 22 ++----- crawl-ref/source/tutorial.h | 2 +- 5 files changed, 76 insertions(+), 94 deletions(-) (limited to 'crawl-ref/source') diff --git a/crawl-ref/source/describe.cc b/crawl-ref/source/describe.cc index 49b53f767b..4cf3fe0697 100644 --- a/crawl-ref/source/describe.cc +++ b/crawl-ref/source/describe.cc @@ -1916,83 +1916,65 @@ void describe_item( item_def &item, bool allow_inscribe ) if (allow_inscribe && wherey() <= get_number_of_lines() - 3) { cgotoxy(1, wherey() + 2); - - std::string ainscrip; - - if (is_random_artefact(item)) - ainscrip = _randart_auto_inscription(item); - - // Only allow autoinscription if we don't have all the text - // already. - const bool allow_autoinscribe = - is_random_artefact(item) - && !ainscrip.empty() - && item.inscription.find(ainscrip) == std::string::npos; - - if (allow_autoinscribe) - { - formatted_string::parse_string( - "Do you wish to inscribe this item? " - "('a' to autoinscribe) ").display(); - } - else - { - formatted_string::parse_string( - "Do you wish to inscribe this item? ").display(); - } - - if (Options.tutorial_left && wherey() <= get_number_of_lines() - 5) - tutorial_inscription_info(allow_autoinscribe); - -#ifdef USE_TILE - const int keyin = getch_ck(); - if (toupper(keyin) == 'Y') -#else - const int keyin = getch(); - if (toupper(keyin) == 'Y') -#endif - { - char buf[79]; - cprintf("\nInscribe with what? "); - if (!cancelable_get_line(buf, sizeof buf)) - { - item.inscription = buf; - } - } - else if (allow_autoinscribe - && (toupper(keyin) == 'A' || keyin == CK_MOUSE_B1)) - { - // Remove previous randart inscription - _trim_randart_inscrip(item); - - if (!item.inscription.empty()) - item.inscription += ", "; - - item.inscription += ainscrip; - } + inscribe_item(item, false); } - else if (getch() == 0) - getch(); } -void inscribe_item(item_def &item) +// There are currently two ways to inscribe an item: +// * using the inscribe command ('{') -> proper_prompt = true +// * from the inventory when viewing an item -> proper_prompt = false +// +// Thus, proper_prompt also controls whether a tutorial explanation can be +// shown, or whether the pre- and post-inscription item names need to be +// printed. +void inscribe_item(item_def &item, bool proper_prompt) { - mpr(item.name(DESC_INVENTORY).c_str(), MSGCH_EQUIPMENT); + if (proper_prompt) + mpr(item.name(DESC_INVENTORY).c_str(), MSGCH_EQUIPMENT); + const bool is_inscribed = !item.inscription.empty(); std::string ainscrip; + // Only allow autoinscription if we don't have all the text + // already. + bool need_autoinscribe = false; if (is_random_artefact(item)) + { ainscrip = _randart_auto_inscription(item); + if (!ainscrip.empty() + && (!is_inscribed + || item.inscription.find(ainscrip) == std::string::npos)) + { + need_autoinscribe = true; + } + } - // Only allow autoinscription if we don't have all the text - // already. - const bool autoinscribe = - is_random_artefact(item) - && !ainscrip.empty() - && item.inscription.find(ainscrip) == std::string::npos; + std::string prompt = (is_inscribed ? "Add what to inscription? " + : "Inscribe with what? "); + if (need_autoinscribe || is_inscribed) + { + prompt += "(You may also "; + if (need_autoinscribe) + { + prompt += "(a)utoinscribe"; + if (is_inscribed) + prompt += " or "; + } + if (is_inscribed) + prompt += "(c)lear it"; + prompt += ".) "; + } - mprf( MSGCH_PROMPT, "Inscribe with what%s? ", - autoinscribe ? " ('a' to autoinscribe)" : "" ); + if (proper_prompt) + mpr(prompt.c_str(), MSGCH_PROMPT); + else + { + prompt = "" + prompt + ""; + formatted_string::parse_string(prompt).display(); + + if (Options.tutorial_left && wherey() <= get_number_of_lines() - 5) + tutorial_inscription_info(need_autoinscribe, prompt); + } char buf[79]; if (!cancelable_get_line(buf, sizeof buf)) @@ -2006,7 +1988,8 @@ void inscribe_item(item_def &item) break; } - if (autoinscribe && buf[1] == 0 && (buf[0] == 'a' || buf[0] == 'A')) + if (need_autoinscribe && buf[1] == 0 + && (buf[0] == 'a' || buf[0] == 'A')) { // Remove previous randart inscription _trim_randart_inscrip(item); @@ -2016,16 +1999,27 @@ void inscribe_item(item_def &item) item.inscription += ainscrip; } - else - item.inscription = std::string(buf); + else if (is_inscribed && buf[1] == 0 + && (buf[0] == 'c' || buf[0] == 'C')) + { + item.inscription.clear(); + } + else if (strlen(buf) > 0) + { + if (is_inscribed) + item.inscription += ", "; - mpr(item.name(DESC_INVENTORY).c_str(), MSGCH_EQUIPMENT); - you.wield_change = true; + item.inscription += std::string(buf); + } + + if (proper_prompt) + { + mpr(item.name(DESC_INVENTORY).c_str(), MSGCH_EQUIPMENT); + you.wield_change = true; + } } - else - { + else if (proper_prompt) canned_msg(MSG_OK); - } } //--------------------------------------------------------------- // diff --git a/crawl-ref/source/describe.h b/crawl-ref/source/describe.h index fd17f3a834..a8014d7b95 100644 --- a/crawl-ref/source/describe.h +++ b/crawl-ref/source/describe.h @@ -61,7 +61,7 @@ void describe_feature_wide(int x, int y); * called from: item_use - shopping * *********************************************************************** */ void describe_item( item_def &item, bool allow_inscribe = false ); -void inscribe_item( item_def &item ); +void inscribe_item( item_def &item, bool proper_prompt ); // last updated 12 Jun 2008 {jpeg} /* *********************************************************************** diff --git a/crawl-ref/source/item_use.cc b/crawl-ref/source/item_use.cc index 96d5f3f4d3..f51f23c9fb 100644 --- a/crawl-ref/source/item_use.cc +++ b/crawl-ref/source/item_use.cc @@ -3534,7 +3534,7 @@ void prompt_inscribe_item() return; } - inscribe_item(you.inv[item_slot]); + inscribe_item(you.inv[item_slot], true); } void drink( int slot ) diff --git a/crawl-ref/source/tutorial.cc b/crawl-ref/source/tutorial.cc index 76f32ea905..496ce598a1 100644 --- a/crawl-ref/source/tutorial.cc +++ b/crawl-ref/source/tutorial.cc @@ -3475,7 +3475,7 @@ void tutorial_describe_item(const item_def &item) formatted_string::parse_block(broken, false).display(); } // tutorial_describe_item() -void tutorial_inscription_info(bool autoinscribe) +void tutorial_inscription_info(bool autoinscribe, std::string prompt) { // Don't print anything if there's not enough space. if (wherey() >= get_number_of_lines() - 1) @@ -3500,8 +3500,7 @@ void tutorial_inscription_info(bool autoinscribe) { text << EOL "Artefacts can be autoinscribed to give a brief overview of their " EOL - "known properties. Here, doing a left mouse click will autoinscribe " EOL - "this item."; + "known properties."; longtext = true; } @@ -3511,20 +3510,9 @@ void tutorial_inscription_info(bool autoinscribe) formatted_string::parse_string(text.str()).display(); - if (longtext && wherey() <= get_number_of_lines() - 2) - { - if (autoinscribe) - { - formatted_string::parse_string( - "So, do you wish to inscribe this item? " - "('a' to autoinscribe) ").display(); - } - else - { - formatted_string::parse_string( - "So, do you wish to inscribe this item? ").display(); - } - } + // Ask a second time, if it's been a longish interruption. + if (longtext && !prompt.empty() && wherey() <= get_number_of_lines() - 2) + formatted_string::parse_string(prompt).display(); } bool tutorial_pos_interesting(int x, int y) diff --git a/crawl-ref/source/tutorial.h b/crawl-ref/source/tutorial.h index a9646570e2..e0d94d2b0a 100644 --- a/crawl-ref/source/tutorial.h +++ b/crawl-ref/source/tutorial.h @@ -48,7 +48,7 @@ void print_tut_skills_info(void); // Additional information for tutorial players. void tutorial_describe_item(const item_def &item); -void tutorial_inscription_info(bool autoinscribe); +void tutorial_inscription_info(bool autoinscribe, std::string prompt); bool tutorial_pos_interesting(int x, int y); void tutorial_describe_pos(int x, int y); bool tutorial_feat_interesting(dungeon_feature_type feat); -- cgit v1.2.3-54-g00ecf