OSDN Git Service

[Refactor] #39964 Separated autopick-command-menu.c/h from autopick.c
authorHourier <hourier@users.sourceforge.jp>
Sun, 26 Apr 2020 01:59:06 +0000 (10:59 +0900)
committerHourier <hourier@users.sourceforge.jp>
Sun, 26 Apr 2020 04:28:31 +0000 (13:28 +0900)
Hengband_vcs2017/Hengband/Hengband.vcxproj
Hengband_vcs2017/Hengband/Hengband.vcxproj.filters
src/Makefile.am
src/autopick/autopick-command-menu.c [new file with mode: 0644]
src/autopick/autopick-command-menu.h [new file with mode: 0644]
src/autopick/autopick.c

index 34fcd28..9b5ae3a 100644 (file)
   <ItemGroup>\r
     <ClCompile Include="..\..\src\artifact.c" />\r
     <ClCompile Include="..\..\src\autopick\autopick-adder.c" />\r
+    <ClCompile Include="..\..\src\autopick\autopick-command-menu.c" />\r
     <ClCompile Include="..\..\src\autopick\autopick-describer.c" />\r
     <ClCompile Include="..\..\src\autopick\autopick-destroyer.c" />\r
     <ClCompile Include="..\..\src\autopick\autopick-drawer.c" />\r
     <ClCompile Include="..\..\src\realm-sorcery.c" />\r
     <ClInclude Include="..\..\src\artifact.h" />\r
     <ClInclude Include="..\..\src\autopick\autopick-adder.h" />\r
+    <ClInclude Include="..\..\src\autopick\autopick-command-menu.h" />\r
     <ClInclude Include="..\..\src\autopick\autopick-commands-table.h" />\r
     <ClInclude Include="..\..\src\autopick\autopick-describer.h" />\r
     <ClInclude Include="..\..\src\autopick\autopick-destroyer.h" />\r
index 270b590..94d346c 100644 (file)
     <ClCompile Include="..\..\src\autopick\autopick-registry.c">
       <Filter>autopick</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\autopick\autopick-command-menu.c">
+      <Filter>autopick</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\src\gamevalue.h" />
     <ClInclude Include="..\..\src\autopick\autopick-registry.h">
       <Filter>autopick</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\autopick\autopick-command-menu.h">
+      <Filter>autopick</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\src\wall.bmp" />
index 7a8c0a7..8e2c994 100644 (file)
@@ -29,6 +29,7 @@ hengband_SOURCES = \
        autopick/autopick-searcher.c autopick/autopick-searcher.h \
        autopick/autopick-inserter-killer.c autopick/autopick-inserter-killer.h \
        autopick/autopick-registry.c autopick/autopick-registry.h \
+       autopick/autopick-command-menu.c autopick/autopick-command-menu.h \
        \
        avatar.h avatar.c birth.c birth.h \
        \
diff --git a/src/autopick/autopick-command-menu.c b/src/autopick/autopick-command-menu.c
new file mode 100644 (file)
index 0000000..a318f96
--- /dev/null
@@ -0,0 +1,126 @@
+#include "angband.h"
+#include "autopick/autopick-command-menu.h"
+#include "autopick/autopick-util.h"
+#include "autopick/autopick-menu-data-table.h"
+#include "gameterm.h"
+
+/*
+ * Display the menu, and get a command
+ */
+int do_command_menu(int level, int start)
+{
+       int max_len = 0;
+       int col0 = 5 + level * 7;
+       int row0 = 1 + level * 3;
+       int menu_id_list[26];
+       bool redraw = TRUE;
+       char linestr[MAX_LINELEN];
+
+       byte menu_key = 0;
+       for (int i = start; menu_data[i].level >= level; i++)
+       {
+               /* Ignore lower level sub menus */
+               if (menu_data[i].level > level) continue;
+
+               int len = strlen(menu_data[i].name);
+               if (len > max_len) max_len = len;
+
+               menu_id_list[menu_key] = i;
+               menu_key++;
+       }
+
+       while (menu_key < 26)
+       {
+               menu_id_list[menu_key] = -1;
+               menu_key++;
+       }
+
+       int max_menu_wid = max_len + 3 + 3;
+
+       /* Prepare box line */
+       linestr[0] = '\0';
+       strcat(linestr, "+");
+       for (int i = 0; i < max_menu_wid + 2; i++)
+       {
+               strcat(linestr, "-");
+       }
+
+       strcat(linestr, "+");
+
+       while (TRUE)
+       {
+               if (redraw)
+               {
+                       int row1 = row0 + 1;
+                       Term_putstr(col0, row0, -1, TERM_WHITE, linestr);
+
+                       menu_key = 0;
+                       for (int i = start; menu_data[i].level >= level; i++)
+                       {
+                               char com_key_str[3];
+                               concptr str;
+                               if (menu_data[i].level > level) continue;
+
+                               if (menu_data[i].com_id == -1)
+                               {
+                                       strcpy(com_key_str, _("▼", ">"));
+                               }
+                               else if (menu_data[i].key != -1)
+                               {
+                                       com_key_str[0] = '^';
+                                       com_key_str[1] = menu_data[i].key + '@';
+                                       com_key_str[2] = '\0';
+                               }
+                               else
+                               {
+                                       com_key_str[0] = '\0';
+                               }
+
+                               str = format("| %c) %-*s %2s | ", menu_key + 'a', max_len, menu_data[i].name, com_key_str);
+
+                               Term_putstr(col0, row1++, -1, TERM_WHITE, str);
+
+                               menu_key++;
+                       }
+
+                       Term_putstr(col0, row1, -1, TERM_WHITE, linestr);
+                       redraw = FALSE;
+               }
+
+               prt(format(_("(a-%c) コマンド:", "(a-%c) Command:"), menu_key + 'a' - 1), 0, 0);
+               char key = inkey();
+
+               if (key == ESCAPE) return 0;
+
+               int com_id;
+               bool is_alphabet = key >= 'a' && key <= 'z';
+               if (!is_alphabet)
+               {
+                       com_id = get_com_id(key);
+                       if (com_id)
+                       {
+                               return com_id;
+                       }
+
+                       continue;
+               }
+
+               int menu_id = menu_id_list[key - 'a'];
+
+               if (menu_id < 0) continue;
+
+               com_id = menu_data[menu_id].com_id;
+
+               if (com_id == -1)
+               {
+                       com_id = do_command_menu(level + 1, menu_id + 1);
+
+                       if (com_id) return com_id;
+                       else redraw = TRUE;
+               }
+               else if (com_id)
+               {
+                       return com_id;
+               }
+       }
+}
diff --git a/src/autopick/autopick-command-menu.h b/src/autopick/autopick-command-menu.h
new file mode 100644 (file)
index 0000000..429eda2
--- /dev/null
@@ -0,0 +1,3 @@
+#pragma once
+
+int do_command_menu(int level, int start);
index 2309a2c..f45ef3b 100644 (file)
@@ -28,6 +28,7 @@
 #include "autopick/autopick-searcher.h"
 #include "autopick/autopick-inserter-killer.h"
 #include "autopick/autopick-registry.h"
+#include "autopick/autopick-command-menu.h"
 #include "gameterm.h"
 #include "autopick/autopick.h"
 #include "core/show-file.h"
@@ -368,128 +369,6 @@ static bool add_empty_line(text_body_type *tb)
 }
 
 
-/*
- * Display the menu, and get a command
- */
-static int do_command_menu(int level, int start)
-{
-       int max_len = 0;
-       int col0 = 5 + level * 7;
-       int row0 = 1 + level * 3;
-       int menu_id_list[26];
-       bool redraw = TRUE;
-       char linestr[MAX_LINELEN];
-
-       byte menu_key = 0;
-       for (int i = start; menu_data[i].level >= level; i++)
-       {
-               /* Ignore lower level sub menus */
-               if (menu_data[i].level > level) continue;
-
-               int len = strlen(menu_data[i].name);
-               if (len > max_len) max_len = len;
-
-               menu_id_list[menu_key] = i;
-               menu_key++;
-       }
-
-       while (menu_key < 26)
-       {
-               menu_id_list[menu_key] = -1;
-               menu_key++;
-       }
-
-       int max_menu_wid = max_len + 3 + 3;
-
-       /* Prepare box line */
-       linestr[0] = '\0';
-       strcat(linestr, "+");
-       for (int i = 0; i < max_menu_wid + 2; i++)
-       {
-               strcat(linestr, "-");
-       }
-
-       strcat(linestr, "+");
-
-       while (TRUE)
-       {
-               if (redraw)
-               {
-                       int row1 = row0 + 1;
-                       Term_putstr(col0, row0, -1, TERM_WHITE, linestr);
-
-                       menu_key = 0;
-                       for (int i = start; menu_data[i].level >= level; i++)
-                       {
-                               char com_key_str[3];
-                               concptr str;
-                               if (menu_data[i].level > level) continue;
-
-                               if (menu_data[i].com_id == -1)
-                               {
-                                       strcpy(com_key_str, _("▼", ">"));
-                               }
-                               else if (menu_data[i].key != -1)
-                               {
-                                       com_key_str[0] = '^';
-                                       com_key_str[1] = menu_data[i].key + '@';
-                                       com_key_str[2] = '\0';
-                               }
-                               else
-                               {
-                                       com_key_str[0] = '\0';
-                               }
-
-                               str = format("| %c) %-*s %2s | ", menu_key + 'a', max_len, menu_data[i].name, com_key_str);
-
-                               Term_putstr(col0, row1++, -1, TERM_WHITE, str);
-
-                               menu_key++;
-                       }
-
-                       Term_putstr(col0, row1, -1, TERM_WHITE, linestr);
-                       redraw = FALSE;
-               }
-
-               prt(format(_("(a-%c) コマンド:", "(a-%c) Command:"), menu_key + 'a' - 1), 0, 0);
-               char key = inkey();
-
-               if (key == ESCAPE) return 0;
-
-               int com_id;
-               bool is_alphabet = key >= 'a' && key <= 'z';
-               if (!is_alphabet)
-               {
-                       com_id = get_com_id(key);
-                       if (com_id)
-                       {
-                               return com_id;
-                       }
-
-                       continue;
-               }
-
-               int menu_id = menu_id_list[key - 'a'];
-
-               if (menu_id < 0) continue;
-
-               com_id = menu_data[menu_id].com_id;
-
-               if (com_id == -1)
-               {
-                       com_id = do_command_menu(level + 1, menu_id + 1);
-
-                       if (com_id) return com_id;
-                       else redraw = TRUE;
-               }
-               else if (com_id)
-               {
-                       return com_id;
-               }
-       }
-}
-
-
 static chain_str_type *new_chain_str(concptr str)
 {
        chain_str_type *chain;