OSDN Git Service

[Refactor] 意味もなく引き回しているprocess_autopick_file_command引数の削除
[hengbandforosx/hengbandosx.git] / src / birth / history-editor.cpp
1 #include "birth/history-editor.h"
2 #include "io/input-key-acceptor.h"
3 #include "io/read-pref-file.h"
4 #include "term/screen-processor.h"
5 #include "term/term-color-types.h"
6 #include "util/int-char-converter.h"
7 #include "view/display-player.h" // 暫定。後で消す.
8 #ifdef  JP
9 #include "locale/japanese.h"
10 #endif
11
12 /*!
13  * @brief 生い立ちメッセージを編集する。/Character background edit-mode
14  * @param creature_ptr プレーヤーへの参照ポインタ
15  * @return なし
16  */
17 void edit_history(player_type *creature_ptr)
18 {
19     char old_history[4][60];
20     for (int i = 0; i < 4; i++) {
21         sprintf(old_history[i], "%s", creature_ptr->history[i]);
22     }
23
24     for (int i = 0; i < 4; i++) {
25         /* loop */
26         int j;
27         for (j = 0; creature_ptr->history[i][j]; j++)
28             ;
29
30         for (; j < 59; j++)
31             creature_ptr->history[i][j] = ' ';
32         creature_ptr->history[i][59] = '\0';
33     }
34
35     display_player(creature_ptr, 1);
36     c_put_str(TERM_L_GREEN, _("(キャラクターの生い立ち - 編集モード)", "(Character Background - Edit Mode)"), 11, 20);
37     put_str(_("[ カーソルキーで移動、Enterで終了、Ctrl-Aでファイル読み込み ]", "[ Cursor key for Move, Enter for End, Ctrl-A for Read pref ]"), 17, 10);
38     TERM_LEN y = 0;
39     TERM_LEN x = 0;
40     while (TRUE) {
41         char c;
42
43         for (int i = 0; i < 4; i++) {
44             put_str(creature_ptr->history[i], i + 12, 10);
45         }
46 #ifdef JP
47         if (iskanji2(creature_ptr->history[y], x))
48             c_put_str(TERM_L_BLUE, format("%c%c", creature_ptr->history[y][x], creature_ptr->history[y][x + 1]), y + 12, x + 10);
49         else
50 #endif
51             c_put_str(TERM_L_BLUE, format("%c", creature_ptr->history[y][x]), y + 12, x + 10);
52
53         term_gotoxy(x + 10, y + 12);
54         int skey = inkey_special(TRUE);
55         if (!(skey & SKEY_MASK))
56             c = (char)skey;
57         else
58             c = 0;
59
60         if (skey == SKEY_UP || c == KTRL('p')) {
61             y--;
62             if (y < 0)
63                 y = 3;
64 #ifdef JP
65             if ((x > 0) && (iskanji2(creature_ptr->history[y], x - 1)))
66                 x--;
67 #endif
68         } else if (skey == SKEY_DOWN || c == KTRL('n')) {
69             y++;
70             if (y > 3)
71                 y = 0;
72 #ifdef JP
73             if ((x > 0) && (iskanji2(creature_ptr->history[y], x - 1)))
74                 x--;
75 #endif
76         } else if (skey == SKEY_RIGHT || c == KTRL('f')) {
77 #ifdef JP
78             if (iskanji2(creature_ptr->history[y], x))
79                 x++;
80 #endif
81             x++;
82             if (x > 58) {
83                 x = 0;
84                 if (y < 3)
85                     y++;
86             }
87         } else if (skey == SKEY_LEFT || c == KTRL('b')) {
88             x--;
89             if (x < 0) {
90                 if (y) {
91                     y--;
92                     x = 58;
93                 } else
94                     x = 0;
95             }
96
97 #ifdef JP
98             if ((x > 0) && (iskanji2(creature_ptr->history[y], x - 1)))
99                 x--;
100 #endif
101         } else if (c == '\r' || c == '\n') {
102             term_erase(0, 11, 255);
103             term_erase(0, 17, 255);
104             put_str(_("(キャラクターの生い立ち - 編集済み)", "(Character Background - Edited)"), 11, 20);
105             break;
106         } else if (c == ESCAPE) {
107             clear_from(11);
108             put_str(_("(キャラクターの生い立ち)", "(Character Background)"), 11, 25);
109             for (int i = 0; i < 4; i++) {
110                 sprintf(creature_ptr->history[i], "%s", old_history[i]);
111                 put_str(creature_ptr->history[i], i + 12, 10);
112             }
113
114             break;
115         } else if (c == KTRL('A')) {
116             if (read_histpref(creature_ptr)) {
117 #ifdef JP
118                 if ((x > 0) && (iskanji2(creature_ptr->history[y], x - 1)))
119                     x--;
120 #endif
121             }
122         } else if (c == '\010') {
123             x--;
124             if (x < 0) {
125                 if (y) {
126                     y--;
127                     x = 58;
128                 } else
129                     x = 0;
130             }
131
132             creature_ptr->history[y][x] = ' ';
133 #ifdef JP
134             if ((x > 0) && (iskanji2(creature_ptr->history[y], x - 1))) {
135                 x--;
136                 creature_ptr->history[y][x] = ' ';
137             }
138 #endif
139         }
140 #ifdef JP
141         else if (iskanji(c) || isprint(c))
142 #else
143         else if (isprint(c)) /* BUGFIX */
144 #endif
145         {
146 #ifdef JP
147             if (iskanji2(creature_ptr->history[y], x)) {
148                 creature_ptr->history[y][x + 1] = ' ';
149             }
150
151             if (iskanji(c)) {
152                 if (x > 57) {
153                     x = 0;
154                     y++;
155                     if (y > 3)
156                         y = 0;
157                 }
158
159                 if (iskanji2(creature_ptr->history[y], x + 1)) {
160                     creature_ptr->history[y][x + 2] = ' ';
161                 }
162
163                 creature_ptr->history[y][x++] = c;
164
165                 c = inkey();
166             }
167 #endif
168             creature_ptr->history[y][x++] = c;
169             if (x > 58) {
170                 x = 0;
171                 y++;
172                 if (y > 3)
173                     y = 0;
174             }
175         }
176     }
177 }