OSDN Git Service

[Refactor] #2138 Separated get_command() from request_command()
authorHourier <66951241+Hourier@users.noreply.github.com>
Sat, 19 Feb 2022 08:54:04 +0000 (17:54 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Sun, 20 Feb 2022 14:51:52 +0000 (23:51 +0900)
src/io/input-key-requester.cpp
src/io/input-key-requester.h

index ccc02df..5c8d06f 100644 (file)
@@ -71,22 +71,7 @@ void InputKeyRequestor::request_command()
             stop_term_fresh();
         }
 
-        int16_t cmd;
-        if (command_new) {
-            msg_erase();
-            cmd = command_new;
-            command_new = 0;
-        } else {
-            msg_flag = false;
-            num_more = 0;
-            inkey_flag = true;
-            term_fresh();
-            cmd = inkey(true);
-            if (!this->shopping && command_menu && ((cmd == '\r') || (cmd == '\n') || (cmd == 'x') || (cmd == 'X')) && !keymap_act[mode][(byte)(cmd)]) {
-                cmd = this->inkey_from_menu();
-            }
-        }
-
+        auto cmd = this->get_command(mode);
         prt("", 0, 0);
         if (cmd == '0') {
             auto old_arg = command_arg;
@@ -217,6 +202,27 @@ void InputKeyRequestor::request_command()
     prt("", 0, 0);
 }
 
+short InputKeyRequestor::get_command(const keymap_mode mode)
+{
+    if (command_new) {
+        msg_erase();
+        auto cmd_back = command_new;
+        command_new = 0;
+        return cmd_back;
+    }
+
+    msg_flag = false;
+    num_more = 0;
+    inkey_flag = true;
+    term_fresh();
+    short cmd = inkey(true);
+    if (!this->shopping && command_menu && ((cmd == '\r') || (cmd == '\n') || (cmd == 'x') || (cmd == 'X')) && !keymap_act[mode][(byte)(cmd)]) {
+        cmd = this->inkey_from_menu();
+    }
+
+    return cmd;
+}
+
 char InputKeyRequestor::inkey_from_menu()
 {
     auto basey = this->player_ptr->y - panel_row_min > 10 ? 2 : 13;
index 4aae20d..8b78e95 100644 (file)
@@ -27,5 +27,6 @@ private:
     int shopping;
     char request_command_buffer[256]{}; /*!< Special buffer to hold the action of the current keymap */
 
+    short get_command(const keymap_mode mode);
     char inkey_from_menu();
 };