diff options
author | Johanna Ploog <j-p-e-g@users.sourceforge.net> | 2010-01-15 21:26:39 +0100 |
---|---|---|
committer | Johanna Ploog <j-p-e-g@users.sourceforge.net> | 2010-01-15 21:26:39 +0100 |
commit | db0e3300dd36a98734dd081e35dadd3a0c6a8aa4 (patch) | |
tree | 5d91418ba2b00bccab6131c8c294ab82f1128b16 /crawl-ref/source/macro.cc | |
parent | 4224dfb2d2276ae82502dcf2b04ae099bfe44100 (diff) | |
download | crawl-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/source/macro.cc')
-rw-r--r-- | crawl-ref/source/macro.cc | 88 |
1 files changed, 88 insertions, 0 deletions
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"; +} |