OSDN Git Service

[Refactor] #39964 Separated process_dirty_expression() from draw_text_editor() in...
authorHourier <hourier@users.sourceforge.jp>
Sun, 26 Apr 2020 08:59:31 +0000 (17:59 +0900)
committerHourier <hourier@users.sourceforge.jp>
Sun, 26 Apr 2020 08:59:31 +0000 (17:59 +0900)
src/autopick/autopick-drawer.c

index 34b0746..27c9c36 100644 (file)
@@ -1,5 +1,4 @@
 /*!
- * todo 長過ぎる、要関数分割
  * @brief 自動拾いエディタを表示させる
  * @date 2020/04/26
  * @author Hourier
 #include "gameterm.h"
 #include "files.h"
 
+
+static void process_dirty_expression(player_type *player_ptr, text_body_type *tb)
+{
+       if (tb->dirty_flags & DIRTY_EXPRESSION == 0) return;
+
+       byte state = 0;
+       for (int y = 0; tb->lines_list[y]; y++)
+       {
+               concptr s = tb->lines_list[y];
+               char *ss, *s_keep;
+               tb->states[y] = state;
+
+               if (*s++ != '?') continue;
+               if (*s++ != ':') continue;
+
+               if (streq(s, "$AUTOREGISTER"))
+                       state |= LSTAT_AUTOREGISTER;
+
+               int s_len = strlen(s);
+               ss = (char *)string_make(s);
+               s_keep = ss;
+
+               char f;
+               concptr v = process_pref_file_expr(player_ptr, &ss, &f);
+               if (streq(v, "0")) state |= LSTAT_BYPASS;
+               else state &= ~LSTAT_BYPASS;
+
+               C_KILL(s_keep, s_len + 1, char);
+               tb->states[y] = state | LSTAT_EXPRESSION;
+       }
+
+       tb->dirty_flags |= DIRTY_ALL;
+}
+
+
 /*
  * Draw text
  */
 void draw_text_editor(player_type *player_ptr, text_body_type *tb)
 {
-       int i;
        int by1 = 0, by2 = 0;
 
        Term_get_size(&tb->wid, &tb->hgt);
@@ -31,7 +64,7 @@ void draw_text_editor(player_type *player_ptr, text_body_type *tb)
 
 #ifdef JP
        /* Don't let cursor at second byte of kanji */
-       for (i = 0; tb->lines_list[tb->cy][i]; i++)
+       for (int i = 0; tb->lines_list[tb->cy][i]; i++)
                if (iskanji(tb->lines_list[tb->cy][i]))
                {
                        i++;
@@ -71,48 +104,13 @@ void draw_text_editor(player_type *player_ptr, text_body_type *tb)
        {
                char buf[MAX_LINELEN];
                int sepa_length = tb->wid;
-               for (i = 0; i < sepa_length; i++)
+               for (int i = 0; i < sepa_length; i++)
                        buf[i] = '-';
-               buf[i] = '\0';
+               buf[sepa_length] = '\0';
                Term_putstr(0, tb->hgt + 1, sepa_length, TERM_WHITE, buf);
        }
 
-       if (tb->dirty_flags & DIRTY_EXPRESSION)
-       {
-               byte state = 0;
-               for (int y = 0; tb->lines_list[y]; y++)
-               {
-                       char f;
-                       concptr v;
-                       concptr s = tb->lines_list[y];
-                       char *ss, *s_keep;
-                       int s_len;
-
-                       tb->states[y] = state;
-
-                       if (*s++ != '?') continue;
-                       if (*s++ != ':') continue;
-
-                       if (streq(s, "$AUTOREGISTER"))
-                               state |= LSTAT_AUTOREGISTER;
-
-                       s_len = strlen(s);
-                       ss = (char *)string_make(s);
-                       s_keep = ss;
-
-                       v = process_pref_file_expr(player_ptr, &ss, &f);
-
-                       if (streq(v, "0")) state |= LSTAT_BYPASS;
-                       else state &= ~LSTAT_BYPASS;
-
-                       C_KILL(s_keep, s_len + 1, char);
-
-                       tb->states[y] = state | LSTAT_EXPRESSION;
-               }
-
-               tb->dirty_flags |= DIRTY_ALL;
-       }
-
+       process_dirty_expression(player_ptr, tb);
        if (tb->mark)
        {
                tb->dirty_flags |= DIRTY_ALL;
@@ -121,7 +119,8 @@ void draw_text_editor(player_type *player_ptr, text_body_type *tb)
                by2 = MAX(tb->my, tb->cy);
        }
 
-       for (i = 0; i < tb->hgt; i++)
+       int erase_height = 0;
+       for (int i = 0; i < tb->hgt; i++)
        {
                int leftcol = 0;
                concptr msg;
@@ -184,9 +183,11 @@ void draw_text_editor(player_type *player_ptr, text_body_type *tb)
                        if (x0 < bx2) Term_addstr(bx2 - bx1, TERM_YELLOW, msg + (bx1 - x0));
                        Term_addstr(-1, color, msg + (bx2 - x0));
                }
+
+               erase_height++;
        }
 
-       for (; i < tb->hgt; i++)
+       for (int i = erase_height; i < tb->hgt; i++)
        {
                Term_erase(0, i + 1, tb->wid);
        }
@@ -197,7 +198,7 @@ void draw_text_editor(player_type *player_ptr, text_body_type *tb)
 
        autopick_type an_entry, *entry = &an_entry;
        concptr str1 = NULL, str2 = NULL;
-       for (i = 0; i < DESCRIPT_HGT; i++)
+       for (int i = 0; i < DESCRIPT_HGT; i++)
        {
                Term_erase(0, tb->hgt + 2 + i, tb->wid);
        }
@@ -288,7 +289,7 @@ void draw_text_editor(player_type *player_ptr, text_body_type *tb)
 
                roff_to_buf(buf, 81, temp, sizeof(temp));
                t = temp;
-               for (i = 0; i < 3; i++)
+               for (int i = 0; i < 3; i++)
                {
                        if (t[0] == 0)
                                break;
@@ -298,6 +299,7 @@ void draw_text_editor(player_type *player_ptr, text_body_type *tb)
                                t += strlen(t) + 1;
                        }
                }
+
                autopick_free_entry(entry);
        }