OSDN Git Service

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