summaryrefslogtreecommitdiffstats
path: root/crawl-ref
diff options
context:
space:
mode:
authorJohanna Ploog <j-p-e-g@users.sourceforge.net>2010-01-15 21:26:39 +0100
committerJohanna Ploog <j-p-e-g@users.sourceforge.net>2010-01-15 21:26:39 +0100
commitdb0e3300dd36a98734dd081e35dadd3a0c6a8aa4 (patch)
tree5d91418ba2b00bccab6131c8c294ab82f1128b16 /crawl-ref
parent4224dfb2d2276ae82502dcf2b04ae099bfe44100 (diff)
downloadcrawl-ref-db0e3300dd36a98734dd081e35dadd3a0c6a8aa4.tar.gz
crawl-ref-db0e3300dd36a98734dd081e35dadd3a0c6a8aa4.zip
New method _command_to_string() returning human-readable key names.
The plan is to replace the hardcoded command key names on the help screen and in the tutorial with these dynamic ones respecting redefined keys. Unfortunately, several commands have multiple assignments and macro.cc's command_to_key() only returns the last one, which might not be what the player is actually using. For example, I don't have a Numpad, so all mentions of it are of no use to me, and I'd rather have the vi keys listed, which in turn many other players have no interest in. You can check the current key assignments if you comment out the DEBUG_DUMP_COMMANDS definition in chardump.cc and then create a character dump. This will be removed once I'm finished here.
Diffstat (limited to 'crawl-ref')
-rw-r--r--crawl-ref/source/chardump.cc4
-rw-r--r--crawl-ref/source/command.cc1
-rw-r--r--crawl-ref/source/macro.cc88
-rw-r--r--crawl-ref/source/macro.h1
4 files changed, 93 insertions, 1 deletions
diff --git a/crawl-ref/source/chardump.cc b/crawl-ref/source/chardump.cc
index 36480530ee..1ec449eeb7 100644
--- a/crawl-ref/source/chardump.cc
+++ b/crawl-ref/source/chardump.cc
@@ -163,6 +163,7 @@ static void dump_section(dump_params &par)
}
}
+// #define DEBUG_DUMP_COMMANDS
bool dump_char(const std::string &fname, bool show_prices, bool full_id,
const scorefile_entry *se)
{
@@ -177,6 +178,9 @@ bool dump_char(const std::string &fname, bool show_prices, bool full_id,
par.section = Options.dump_order[i];
dump_section(par);
}
+#ifdef DEBUG_DUMP_COMMANDS
+ list_all_commands(par.text);
+#endif
return write_dump(fname, par);
}
diff --git a/crawl-ref/source/command.cc b/crawl-ref/source/command.cc
index 981da89674..fe86234b1a 100644
--- a/crawl-ref/source/command.cc
+++ b/crawl-ref/source/command.cc
@@ -2123,7 +2123,6 @@ void show_butchering_help()
show_specific_help( getHelpString("butchering") );
}
-
static void _add_formatted_keyhelp(column_composer &cols)
{
cols.add_formatted(
diff --git a/crawl-ref/source/macro.cc b/crawl-ref/source/macro.cc
index d1fa5f004e..41fcdbc327 100644
--- a/crawl-ref/source/macro.cc
+++ b/crawl-ref/source/macro.cc
@@ -1235,3 +1235,91 @@ void bind_command_to_key(command_type cmd, int key)
key_map[key] = cmd;
cmd_map[cmd] = key;
}
+
+static std::string _special_keys_to_string(int key)
+{
+ const bool shift = (key >= CK_SHIFT_UP && key <= CK_SHIFT_PGDN);
+ const bool ctrl = (key >= CK_CTRL_UP && key <= CK_CTRL_PGDN);
+
+ std::string cmd = "";
+
+ int newkey = key;
+ if (shift)
+ {
+ newkey -= (CK_SHIFT_UP - CK_UP);
+ cmd = "Shift-";
+ }
+ else if (ctrl)
+ {
+ newkey -= (CK_CTRL_UP - CK_UP);
+ cmd = "Ctrl-";
+ }
+
+ switch (newkey)
+ {
+ case CK_ENTER: cmd += "Enter"; break;
+ case CK_BKSP: cmd += "Backspace"; break;
+ case CK_ESCAPE: cmd += "Esc"; break;
+ case CK_DELETE: cmd += "Del"; break;
+ case CK_UP: cmd += "Up"; break;
+ case CK_DOWN: cmd += "Down"; break;
+ case CK_LEFT: cmd += "Left"; break;
+ case CK_RIGHT: cmd += "Right"; break;
+ case CK_INSERT: cmd += "Ins"; break;
+ case CK_HOME: cmd += "Home"; break;
+ case CK_END: cmd += "End"; break;
+ case CK_CLEAR: cmd += "Clear"; break;
+ case CK_PGUP: cmd += "PgUp"; break;
+ case CK_PGDN: cmd += "PgDn"; break;
+ }
+
+ return (cmd);
+}
+
+static std::string _command_to_string(command_type cmd)
+{
+ const int key = command_to_key(cmd);
+
+ const std::string desc = _special_keys_to_string(key);
+ if (!desc.empty())
+ return (desc);
+
+ if (key >= 32 && key < 256)
+ snprintf(info, INFO_SIZE, "%c", (char) key);
+ else if (key > 1000 && key <= 1009)
+ {
+ const int numpad = (key - 1000);
+ snprintf(info, INFO_SIZE, "Numpad %d", numpad);
+ }
+ else
+ {
+ const int ch = key + 'A' - 1;
+ if (ch >= 'A' && ch <= 'Z')
+ snprintf(info, INFO_SIZE, "Ctrl-%c", (char) ch);
+ else
+ snprintf(info, INFO_SIZE, "%d", key);
+ }
+
+ std::string result = info;
+ return (result);
+}
+
+void list_all_commands(std::string &commands)
+{
+ for (int i = CMD_NO_CMD; i < CMD_MAX_CMD; i++)
+ {
+ const command_type cmd = (command_type) i;
+
+ const std::string command_name = command_to_name(cmd);
+ if (command_name == "CMD_NO_CMD")
+ continue;
+
+ if (context_for_command(cmd) != KMC_DEFAULT)
+ continue;
+
+ snprintf(info, INFO_SIZE, "%s: %s\n",
+ command_name.c_str(), _command_to_string(cmd).c_str());
+ commands += info;
+ }
+ commands += "\n";
+}
diff --git a/crawl-ref/source/macro.h b/crawl-ref/source/macro.h
index 0e847a1b55..20c1d0750c 100644
--- a/crawl-ref/source/macro.h
+++ b/crawl-ref/source/macro.h
@@ -94,4 +94,5 @@ int command_to_key(command_type cmd);
KeymapContext context_for_command(command_type cmd);
void bind_command_to_key(command_type cmd, int key);
+void list_all_commands(std::string &commands);
#endif