OSDN Git Service

[Refactor] #1621 Separated wiz_select_sval() from wiz_create_itemtype()
authorHourier <66951241+Hourier@users.noreply.github.com>
Thu, 23 Sep 2021 09:58:50 +0000 (18:58 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Fri, 24 Sep 2021 11:35:40 +0000 (20:35 +0900)
src/wizard/wizard-special-process.cpp

index 42b659d..74da4fd 100644 (file)
@@ -137,31 +137,13 @@ static std::tuple<bool, KIND_OBJECT_IDX> wiz_select_tval()
     return std::make_tuple(true, selection);
 }
 
-/*!
- * @brief ベースアイテムのウィザード生成のために大項目IDと小項目IDを取得する /
- * Specify tval and sval (type and subtype of object) originally
- * @return ベースアイテムID
- * @details
- * by RAK, heavily modified by -Bernd-
- * This function returns the k_idx of an object type, or zero if failed
- * List up to 50 choices in three columns
- */
-static KIND_OBJECT_IDX wiz_create_itemtype()
+static KIND_OBJECT_IDX wiz_select_sval(const tval_type tval, concptr tval_description)
 {
-    term_clear();
-    auto [result, selection] = wiz_select_tval();
-    if (!result) {
-        return 0;
-    }
-
-    tval_type tval = i2enum<tval_type>(tvals[selection].tval);
-    concptr tval_desc = tvals[selection].desc;
-    term_clear();
     auto num = 0;
     KIND_OBJECT_IDX choice[80]{};
     char buf[160]{};
     char ch;
-    for (const autok_ref : k_info) {
+    for (const auto &k_ref : k_info) {
         if (num >= 80) {
             break;
         }
@@ -171,7 +153,7 @@ static KIND_OBJECT_IDX wiz_create_itemtype()
         }
 
         auto row = 2 + (num % 20);
-        auto col = 20 * (num / 20);
+        auto col = _(30, 32) * (num / 20);
         ch = listsym[num];
         strcpy(buf, "                    ");
         strip_name(buf, k_ref.idx);
@@ -180,21 +162,45 @@ static KIND_OBJECT_IDX wiz_create_itemtype()
     }
 
     auto max_num = num;
-    if (!get_com(format(_("%s群の具体的なアイテムを選んで下さい", "What Kind of %s? "), tval_desc), &ch, false)) {
+    if (!get_com(format(_("%s群の具体的なアイテムを選んで下さい", "What Kind of %s? "), tval_description), &ch, false)) {
         return 0;
     }
 
-    for (num = 0; num < max_num; num++) {
-        if (listsym[num] == ch) {
+    KIND_OBJECT_IDX selection;
+    for (selection = 0; selection < max_num; selection++) {
+        if (listsym[selection] == ch) {
             break;
         }
     }
 
-    if ((num < 0) || (num >= max_num)) {
+    if ((selection < 0) || (selection >= max_num)) {
+        return 0;
+    }
+
+    return choice[selection];
+}
+
+/*!
+ * @brief ベースアイテムのウィザード生成のために大項目IDと小項目IDを取得する /
+ * Specify tval and sval (type and subtype of object) originally
+ * @return ベースアイテムID
+ * @details
+ * by RAK, heavily modified by -Bernd-
+ * This function returns the k_idx of an object type, or zero if failed
+ * List up to 50 choices in three columns
+ */
+static KIND_OBJECT_IDX wiz_create_itemtype()
+{
+    term_clear();
+    auto [result, selection] = wiz_select_tval();
+    if (!result) {
         return 0;
     }
 
-    return choice[num];
+    tval_type tval = i2enum<tval_type>(tvals[selection].tval);
+    concptr tval_description = tvals[selection].desc;
+    term_clear();
+    return wiz_select_sval(tval, tval_description);
 }
 
 /*!