OSDN Git Service

Merge pull request #959 from shimitei/feature/#946_fix_history_editor
[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 "system/player-type-definition.h"
5 #include "term/screen-processor.h"
6 #include "term/term-color-types.h"
7 #include "util/int-char-converter.h"
8 #include "view/display-player.h" // 暫定。後で消す.
9 #ifdef  JP
10 #include "locale/japanese.h"
11 #endif
12
13 /*!
14  * @brief 生い立ちメッセージを編集する。/Character background edit-mode
15  * @param creature_ptr プレーヤーへの参照ポインタ
16  * @return なし
17  */
18 void edit_history(player_type *creature_ptr)
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             char kanji[3] = { creature_ptr->history[y][x], creature_ptr->history[y][x + 1], '\0' };
50             c_put_str(TERM_L_BLUE, format("%s", kanji), y + 12, x + 10);
51         } else
52 #endif
53             c_put_str(TERM_L_BLUE, format("%c", creature_ptr->history[y][x]), y + 12, x + 10);
54
55         term_gotoxy(x + 10, y + 12);
56         int skey = inkey_special(TRUE);
57         if (!(skey & SKEY_MASK))
58             c = (char)skey;
59         else
60             c = 0;
61
62         if (skey == SKEY_UP || c == KTRL('p')) {
63             y--;
64             if (y < 0)
65                 y = 3;
66 #ifdef JP
67             if ((x > 0) && (iskanji2(creature_ptr->history[y], x - 1)))
68                 x--;
69 #endif
70         } else if (skey == SKEY_DOWN || c == KTRL('n')) {
71             y++;
72             if (y > 3)
73                 y = 0;
74 #ifdef JP
75             if ((x > 0) && (iskanji2(creature_ptr->history[y], x - 1)))
76                 x--;
77 #endif
78         } else if (skey == SKEY_RIGHT || c == KTRL('f')) {
79 #ifdef JP
80             if (iskanji2(creature_ptr->history[y], x))
81                 x++;
82 #endif
83             x++;
84             if (x > 58) {
85                 x = 0;
86                 if (y < 3)
87                     y++;
88             }
89         } else if (skey == SKEY_LEFT || c == KTRL('b')) {
90             x--;
91             if (x < 0) {
92                 if (y) {
93                     y--;
94                     x = 58;
95                 } else
96                     x = 0;
97             }
98
99 #ifdef JP
100             if ((x > 0) && (iskanji2(creature_ptr->history[y], x - 1)))
101                 x--;
102 #endif
103         } else if (c == '\r' || c == '\n') {
104             term_erase(0, 11, 255);
105             term_erase(0, 17, 255);
106             put_str(_("(キャラクターの生い立ち - 編集済み)", "(Character Background - Edited)"), 11, 20);
107             break;
108         } else if (c == ESCAPE) {
109             clear_from(11);
110             put_str(_("(キャラクターの生い立ち)", "(Character Background)"), 11, 25);
111             for (int i = 0; i < 4; i++) {
112                 sprintf(creature_ptr->history[i], "%s", old_history[i]);
113                 put_str(creature_ptr->history[i], i + 12, 10);
114             }
115
116             break;
117         } else if (c == KTRL('A')) {
118             if (read_histpref(creature_ptr)) {
119 #ifdef JP
120                 if ((x > 0) && (iskanji2(creature_ptr->history[y], x - 1)))
121                     x--;
122 #endif
123             }
124         } else if (c == '\010') {
125             x--;
126             if (x < 0) {
127                 if (y) {
128                     y--;
129                     x = 58;
130                 } else
131                     x = 0;
132             }
133
134             creature_ptr->history[y][x] = ' ';
135 #ifdef JP
136             if ((x > 0) && (iskanji2(creature_ptr->history[y], x - 1))) {
137                 x--;
138                 creature_ptr->history[y][x] = ' ';
139             }
140 #endif
141         }
142 #ifdef JP
143         else if (iskanji(c) || isprint(c))
144 #else
145         else if (isprint(c)) /* BUGFIX */
146 #endif
147         {
148 #ifdef JP
149             if (iskanji2(creature_ptr->history[y], x)) {
150                 creature_ptr->history[y][x + 1] = ' ';
151             }
152
153             if (iskanji(c)) {
154                 if (x > 57) {
155                     x = 0;
156                     y++;
157                     if (y > 3)
158                         y = 0;
159                 }
160
161                 if (iskanji2(creature_ptr->history[y], x + 1)) {
162                     creature_ptr->history[y][x + 2] = ' ';
163                 }
164
165                 creature_ptr->history[y][x++] = c;
166
167                 c = inkey();
168             }
169 #endif
170             creature_ptr->history[y][x++] = c;
171             if (x > 58) {
172                 x = 0;
173                 y++;
174                 if (y > 3)
175                     y = 0;
176             }
177         }
178     }
179 }