OSDN Git Service

Merge pull request #3569 from sikabane-works/release/3.0.0.88-alpha
[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 "locale/japanese.h"
5 #include "system/player-type-definition.h"
6 #include "term/screen-processor.h"
7 #include "term/term-color-types.h"
8 #include "util/int-char-converter.h"
9 #include "util/string-processor.h"
10 #include "view/display-player.h" // 暫定。後で消す.
11
12 /*!
13  * @brief 生い立ちメッセージを編集する。/Character background edit-mode
14  * @param player_ptr プレイヤーへの参照ポインタ
15  */
16 void edit_history(PlayerType *player_ptr)
17 {
18     std::string old_history[4];
19     for (int i = 0; i < 4; i++) {
20         old_history[i] = player_ptr->history[i];
21     }
22
23     for (int i = 0; i < 4; i++) {
24         /* loop */
25         int j;
26         for (j = 0; player_ptr->history[i][j]; j++) {
27             ;
28         }
29
30         for (; j < 59; j++) {
31             player_ptr->history[i][j] = ' ';
32         }
33         player_ptr->history[i][59] = '\0';
34     }
35
36     (void)display_player(player_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(player_ptr->history[i], i + 12, 10);
46         }
47 #ifdef JP
48         if (iskanji2(player_ptr->history[y], x)) {
49             char kanji[3] = { player_ptr->history[y][x], player_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", player_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
63         if (skey == SKEY_UP || c == KTRL('p')) {
64             y--;
65             if (y < 0) {
66                 y = 3;
67             }
68 #ifdef JP
69             if ((x > 0) && (iskanji2(player_ptr->history[y], x - 1))) {
70                 x--;
71             }
72 #endif
73         } else if (skey == SKEY_DOWN || c == KTRL('n')) {
74             y++;
75             if (y > 3) {
76                 y = 0;
77             }
78 #ifdef JP
79             if ((x > 0) && (iskanji2(player_ptr->history[y], x - 1))) {
80                 x--;
81             }
82 #endif
83         } else if (skey == SKEY_RIGHT || c == KTRL('f')) {
84 #ifdef JP
85             if (iskanji2(player_ptr->history[y], x)) {
86                 x++;
87             }
88 #endif
89             x++;
90             if (x > 58) {
91                 x = 0;
92                 if (y < 3) {
93                     y++;
94                 }
95             }
96         } else if (skey == SKEY_LEFT || c == KTRL('b')) {
97             x--;
98             if (x < 0) {
99                 if (y) {
100                     y--;
101                     x = 58;
102                 } else {
103                     x = 0;
104                 }
105             }
106
107 #ifdef JP
108             if ((x > 0) && (iskanji2(player_ptr->history[y], x - 1))) {
109                 x--;
110             }
111 #endif
112         } else if (c == '\r' || c == '\n') {
113             term_erase(0, 11);
114             term_erase(0, 17);
115             put_str(_("(キャラクターの生い立ち - 編集済み)", "(Character Background - Edited)"), 11, 20);
116             break;
117         } else if (c == ESCAPE) {
118             clear_from(11);
119             put_str(_("(キャラクターの生い立ち)", "(Character Background)"), 11, 25);
120             for (int i = 0; i < 4; i++) {
121                 angband_strcpy(player_ptr->history[i], old_history[i], sizeof(player_ptr->history[i]));
122                 put_str(player_ptr->history[i], i + 12, 10);
123             }
124
125             break;
126         } else if (c == KTRL('A')) {
127             if (read_histpref(player_ptr)) {
128 #ifdef JP
129                 if ((x > 0) && (iskanji2(player_ptr->history[y], x - 1))) {
130                     x--;
131                 }
132 #endif
133             }
134         } else if (c == '\010') {
135             x--;
136             if (x < 0) {
137                 if (y) {
138                     y--;
139                     x = 58;
140                 } else {
141                     x = 0;
142                 }
143             }
144
145             player_ptr->history[y][x] = ' ';
146 #ifdef JP
147             if ((x > 0) && (iskanji2(player_ptr->history[y], x - 1))) {
148                 x--;
149                 player_ptr->history[y][x] = ' ';
150             }
151 #endif
152         }
153 #ifdef JP
154         else if (iskanji(c) || isprint(c))
155 #else
156         else if (isprint(c)) /* BUGFIX */
157 #endif
158         {
159 #ifdef JP
160             if (iskanji2(player_ptr->history[y], x)) {
161                 player_ptr->history[y][x + 1] = ' ';
162             }
163
164             if (iskanji(c)) {
165                 if (x > 57) {
166                     x = 0;
167                     y++;
168                     if (y > 3) {
169                         y = 0;
170                     }
171                 }
172
173                 if (iskanji2(player_ptr->history[y], x + 1)) {
174                     player_ptr->history[y][x + 2] = ' ';
175                 }
176
177                 player_ptr->history[y][x++] = c;
178
179                 c = inkey();
180             }
181 #endif
182             player_ptr->history[y][x++] = c;
183             if (x > 58) {
184                 x = 0;
185                 y++;
186                 if (y > 3) {
187                     y = 0;
188                 }
189             }
190         }
191     }
192 }