OSDN Git Service

Merge branch 'master' of git.osdn.net:/gitroot/hengband/hengband
[hengband/hengband.git] / src / birth / history-editor.c
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  * @param process_autopick_file_command 自動拾いファイルコマンドへの関数ポインタ
16  * @return なし
17  */
18 void edit_history(player_type *creature_ptr, void (*process_autopick_file_command)(char *))
19 {
20     char old_history[4][60];
21     for (int i = 0; i < 4; i++) {
22         sprintf(old_history[i], "%s", creature_ptr->history[i]);
23     }
24
25     for (int i = 0; i < 4; i++) {
26         /* loop */
27         int j;
28         for (j = 0; creature_ptr->history[i][j]; j++)
29             ;
30
31         for (; j < 59; j++)
32             creature_ptr->history[i][j] = ' ';
33         creature_ptr->history[i][59] = '\0';
34     }
35
36     display_player(creature_ptr, 1);
37     c_put_str(TERM_L_GREEN, _("(キャラクターの生い立ち - 編集モード)", "(Character Background - Edit Mode)"), 11, 20);
38     put_str(_("[ カーソルキーで移動、Enterで終了、Ctrl-Aでファイル読み込み ]", "[ Cursor key for Move, Enter for End, Ctrl-A for Read pref ]"), 17, 10);
39     TERM_LEN y = 0;
40     TERM_LEN x = 0;
41     while (TRUE) {
42         char c;
43
44         for (int i = 0; i < 4; i++) {
45             put_str(creature_ptr->history[i], i + 12, 10);
46         }
47 #ifdef JP
48         if (iskanji2(creature_ptr->history[y], x))
49             c_put_str(TERM_L_BLUE, format("%c%c", creature_ptr->history[y][x], creature_ptr->history[y][x + 1]), y + 12, x + 10);
50         else
51 #endif
52             c_put_str(TERM_L_BLUE, format("%c", creature_ptr->history[y][x]), y + 12, x + 10);
53
54         term_gotoxy(x + 10, y + 12);
55         int skey = inkey_special(TRUE);
56         if (!(skey & SKEY_MASK))
57             c = (char)skey;
58         else
59             c = 0;
60
61         if (skey == SKEY_UP || c == KTRL('p')) {
62             y--;
63             if (y < 0)
64                 y = 3;
65 #ifdef JP
66             if ((x > 0) && (iskanji2(creature_ptr->history[y], x - 1)))
67                 x--;
68 #endif
69         } else if (skey == SKEY_DOWN || c == KTRL('n')) {
70             y++;
71             if (y > 3)
72                 y = 0;
73 #ifdef JP
74             if ((x > 0) && (iskanji2(creature_ptr->history[y], x - 1)))
75                 x--;
76 #endif
77         } else if (skey == SKEY_RIGHT || c == KTRL('f')) {
78 #ifdef JP
79             if (iskanji2(creature_ptr->history[y], x))
80                 x++;
81 #endif
82             x++;
83             if (x > 58) {
84                 x = 0;
85                 if (y < 3)
86                     y++;
87             }
88         } else if (skey == SKEY_LEFT || c == KTRL('b')) {
89             x--;
90             if (x < 0) {
91                 if (y) {
92                     y--;
93                     x = 58;
94                 } else
95                     x = 0;
96             }
97
98 #ifdef JP
99             if ((x > 0) && (iskanji2(creature_ptr->history[y], x - 1)))
100                 x--;
101 #endif
102         } else if (c == '\r' || c == '\n') {
103             term_erase(0, 11, 255);
104             term_erase(0, 17, 255);
105             put_str(_("(キャラクターの生い立ち - 編集済み)", "(Character Background - Edited)"), 11, 20);
106             break;
107         } else if (c == ESCAPE) {
108             clear_from(11);
109             put_str(_("(キャラクターの生い立ち)", "(Character Background)"), 11, 25);
110             for (int i = 0; i < 4; i++) {
111                 sprintf(creature_ptr->history[i], "%s", old_history[i]);
112                 put_str(creature_ptr->history[i], i + 12, 10);
113             }
114
115             break;
116         } else if (c == KTRL('A')) {
117             if (read_histpref(creature_ptr, process_autopick_file_command)) {
118 #ifdef JP
119                 if ((x > 0) && (iskanji2(creature_ptr->history[y], x - 1)))
120                     x--;
121 #endif
122             }
123         } else if (c == '\010') {
124             x--;
125             if (x < 0) {
126                 if (y) {
127                     y--;
128                     x = 58;
129                 } else
130                     x = 0;
131             }
132
133             creature_ptr->history[y][x] = ' ';
134 #ifdef JP
135             if ((x > 0) && (iskanji2(creature_ptr->history[y], x - 1))) {
136                 x--;
137                 creature_ptr->history[y][x] = ' ';
138             }
139 #endif
140         }
141 #ifdef JP
142         else if (iskanji(c) || isprint(c))
143 #else
144         else if (isprint(c)) /* BUGFIX */
145 #endif
146         {
147 #ifdef JP
148             if (iskanji2(creature_ptr->history[y], x)) {
149                 creature_ptr->history[y][x + 1] = ' ';
150             }
151
152             if (iskanji(c)) {
153                 if (x > 57) {
154                     x = 0;
155                     y++;
156                     if (y > 3)
157                         y = 0;
158                 }
159
160                 if (iskanji2(creature_ptr->history[y], x + 1)) {
161                     creature_ptr->history[y][x + 2] = ' ';
162                 }
163
164                 creature_ptr->history[y][x++] = c;
165
166                 c = inkey();
167             }
168 #endif
169             creature_ptr->history[y][x++] = c;
170             if (x > 58) {
171                 x = 0;
172                 y++;
173                 if (y > 3)
174                     y = 0;
175             }
176         }
177     }
178 }