summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/macro.cc
diff options
context:
space:
mode:
authorDarshan Shaligram <dshaligram@users.sourceforge.net>2011-01-10 20:46:27 +0530
committerDarshan Shaligram <dshaligram@users.sourceforge.net>2011-01-10 20:49:16 +0530
commit52227691bfd5009ec6be92f42b3db900f7d9a690 (patch)
tree10b257f14106b38b6a69a64d686cc4f5016807c4 /crawl-ref/source/macro.cc
parentaa2e8439057cba218bb83f0d3b4f2865169c610a (diff)
downloadcrawl-ref-52227691bfd5009ec6be92f42b3db900f7d9a690.tar.gz
crawl-ref-52227691bfd5009ec6be92f42b3db900f7d9a690.zip
More feedback at the macro prompt: make it clear exactly what macro/keymap was defined, deleted, etc. Never leave the prompt dangling without an acknowledgement.
Diffstat (limited to 'crawl-ref/source/macro.cc')
-rw-r--r--crawl-ref/source/macro.cc78
1 files changed, 55 insertions, 23 deletions
diff --git a/crawl-ref/source/macro.cc b/crawl-ref/source/macro.cc
index 5fcd1d3492..3824eb3a64 100644
--- a/crawl-ref/source/macro.cc
+++ b/crawl-ref/source/macro.cc
@@ -397,9 +397,9 @@ static void macro_add(macromap &mapref, keyseq key, keyseq action)
/*
* Remove a macro.
*/
-static void macro_del(macromap &mapref, keyseq key)
+static bool macro_del(macromap &mapref, keyseq key)
{
- mapref.erase(key);
+ return mapref.erase(key) != 0;
}
static void _register_expanded_keys(int num, bool reverse);
@@ -812,9 +812,19 @@ void flush_input_buffer(int reason)
}
}
-static void _input_action_raw(keyseq* action)
+static std::string _macro_prompt_string(const std::string &macro_type)
{
- msgwin_prompt("Input macro action: ");
+ return make_stringf("Input %s action: ", macro_type.c_str());
+}
+
+static void _macro_prompt(const std::string &macro_type)
+{
+ msgwin_prompt(_macro_prompt_string(macro_type));
+}
+
+static void _input_action_raw(const std::string &macro_type, keyseq* action)
+{
+ _macro_prompt(macro_type);
const int x = wherex();
const int y = wherey();
bool done = false;
@@ -847,13 +857,26 @@ static void _input_action_raw(keyseq* action)
msgwin_reply(vtostr(*action));
}
-static void _input_action_text(keyseq* action)
+static void _input_action_text(const std::string &macro_type, keyseq* action)
{
char buff[1024];
- msgwin_get_line_autohist("Input macro action: ", buff, sizeof(buff));
+ msgwin_get_line_autohist(_macro_prompt_string(macro_type),
+ buff, sizeof(buff));
*action = parse_keyseq(buff);
}
+static std::string _macro_type_name(bool keymap, KeymapContext keymc)
+{
+ return make_stringf("%s%s",
+ keymap ? (keymc == KMC_DEFAULT ? "default " :
+ keymc == KMC_LEVELMAP ? "level-map " :
+ keymc == KMC_TARGETING ? "targeting " :
+ keymc == KMC_CONFIRM ? "confirm " :
+ keymc == KMC_MENU ? "menu "
+ : "buggy") : "",
+ (keymap ? "keymap" : "macro"));
+}
+
void macro_add_query(void)
{
int input;
@@ -913,17 +936,10 @@ void macro_add_query(void)
// reference to the appropriate mapping
macromap &mapref = (keymap ? Keymaps[keymc] : Macros);
-
- std::string prompt = make_stringf("Input %s%s trigger key: ",
- keymap ? (keymc == KMC_DEFAULT ? "default " :
- keymc == KMC_LEVELMAP ? "level-map " :
- keymc == KMC_TARGETING ? "targeting " :
- keymc == KMC_CONFIRM ? "confirm " :
- keymc == KMC_MENU ? "menu "
- : "buggy") : "",
- (keymap ? "keymap" : "macro"));
-
- msgwin_prompt(prompt);
+ const std::string macro_type = _macro_type_name(keymap, keymc);
+ const std::string trigger_prompt = make_stringf("Input %s trigger key: ",
+ macro_type.c_str());
+ msgwin_prompt(trigger_prompt);
keyseq key;
mouse_control mc(MOUSE_MODE_MACRO);
@@ -931,7 +947,7 @@ void macro_add_query(void)
msgwin_reply(vtostr(key));
- if (mapref[key].size() > 0)
+ if (mapref.find(key) != mapref.end() && !mapref[key].empty())
{
std::string action = vtostr(mapref[key]);
action = replace_all(action, "<", "<<");
@@ -943,12 +959,15 @@ void macro_add_query(void)
input = tolower(input);
if (input == 'a' || key_is_escape(input))
{
- mpr("Aborting.");
+ canned_msg(MSG_OK);
return;
}
else if (input == 'c')
{
- mpr("Cleared.");
+ mprf("Cleared %s '%s' => '%s'.",
+ macro_type.c_str(),
+ vtostr(key).c_str(),
+ vtostr(mapref[key]).c_str());
macro_del(mapref, key);
crawl_state.unsaved_macros = true;
return;
@@ -957,14 +976,27 @@ void macro_add_query(void)
keyseq action;
if (raw)
- _input_action_raw(&action);
+ _input_action_raw(macro_type, &action);
else
- _input_action_text(&action);
+ _input_action_text(macro_type, &action);
if (action.empty())
- macro_del(mapref, key);
+ {
+ const bool deleted_macro = macro_del(mapref, key);
+ if (deleted_macro)
+ mprf("Deleted %s for '%s'.",
+ macro_type.c_str(),
+ vtostr(key).c_str());
+ else
+ canned_msg(MSG_OK);
+ }
else
+ {
macro_add(mapref, key, action);
+ mprf("Created %s '%s' => '%s'.",
+ macro_type.c_str(),
+ vtostr(key).c_str(), vtostr(action).c_str());
+ }
crawl_state.unsaved_macros = true;
redraw_screen();