From: Hourier Date: Mon, 18 May 2020 12:28:49 +0000 (+0900) Subject: [Refactor] #40392 Moved add_history_from_pref_line() from birth.c/h to inter-pret... X-Git-Tag: vmacos3.0.0-alpha52~1336 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=75705d626057c51aac88aaa75449e4fe4c126c8f;p=hengbandforosx%2Fhengbandosx.git [Refactor] #40392 Moved add_history_from_pref_line() from birth.c/h to inter-pret-pref-file.c/h, read_histpref() from birth.c to read-pref-file.c/h and separated history-editor.c/h from birth.c/h --- diff --git a/Hengband/Hengband/Hengband.vcxproj b/Hengband/Hengband/Hengband.vcxproj index 02a4d40ac..35541f2ec 100644 --- a/Hengband/Hengband/Hengband.vcxproj +++ b/Hengband/Hengband/Hengband.vcxproj @@ -157,6 +157,7 @@ + @@ -381,6 +382,7 @@ + diff --git a/Hengband/Hengband/Hengband.vcxproj.filters b/Hengband/Hengband/Hengband.vcxproj.filters index ae9214f2b..d16b51c8d 100644 --- a/Hengband/Hengband/Hengband.vcxproj.filters +++ b/Hengband/Hengband/Hengband.vcxproj.filters @@ -914,6 +914,9 @@ birth + + birth + @@ -1879,6 +1882,9 @@ birth + + birth + diff --git a/src/Makefile.am b/src/Makefile.am index 6ede2138f..3ab95dcff 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -45,6 +45,7 @@ hengband_SOURCES = \ birth/initial-equipments-table.c birth/initial-equipments-table.h \ birth/inventory-initializer.c birth/inventory-initializer.h \ birth/game-play-initializer.c birth/game-play-initializer.h \ + birth/history-editor.c birth/history-editor.h \ \ main/music-definitions-table.c main/music-definitions-table.h \ main/sound-definitions-table.c main/sound-definitions-table.h \ diff --git a/src/birth/birth.c b/src/birth/birth.c index 9017d6b9e..304eb0d0c 100644 --- a/src/birth/birth.c +++ b/src/birth/birth.c @@ -26,7 +26,6 @@ #include "floor/floor.h" #include "birth/history.h" #include "io/write-diary.h" -#include "locale/japanese.h" #include "market/store.h" #include "monster/monster.h" #include "monster/monster-race.h" @@ -51,6 +50,8 @@ #include "view/display-birth.h" // 暫定。後で消す予定。 #include "birth/inventory-initializer.h" #include "birth/game-play-initializer.h" +#include "birth/history-editor.h" +#include "io/read-pref-file.h" /*! * オートローラーの内容を描画する間隔 / @@ -961,263 +962,6 @@ static bool get_chara_limits(player_type* creature_ptr) return TRUE; } -#define HISTPREF_LIMIT 1024 -static char* histpref_buf = NULL; - -/*! - * @brief 生い立ちメッセージの内容をバッファに加える。 / Hook function for reading the histpref.prf file. - * @return なし - */ -void add_history_from_pref_line(concptr t) -{ - if (!histpref_buf) - return; - - my_strcat(histpref_buf, t, HISTPREF_LIMIT); -} - -/*! - * @brief 生い立ちメッセージをファイルからロードする。 - * @return なし - */ -static bool do_cmd_histpref(player_type* creature_ptr, void (*process_autopick_file_command)(char*)) -{ - char buf[80]; - errr err; - int i, j, n; - char *s, *t; - char temp[64 * 4]; - char histbuf[HISTPREF_LIMIT]; - - if (!get_check(_("生い立ち設定ファイルをロードしますか? ", "Load background history preference file? "))) - return FALSE; - - histbuf[0] = '\0'; - histpref_buf = histbuf; - - sprintf(buf, _("histedit-%s.prf", "histpref-%s.prf"), creature_ptr->base_name); - err = process_histpref_file(creature_ptr, buf, process_autopick_file_command); - - if (0 > err) { - strcpy(buf, _("histedit.prf", "histpref.prf")); - err = process_histpref_file(creature_ptr, buf, process_autopick_file_command); - } - - if (err) { - msg_print(_("生い立ち設定ファイルの読み込みに失敗しました。", "Failed to load background history preference.")); - msg_print(NULL); - histpref_buf = NULL; - return FALSE; - } else if (!histpref_buf[0]) { - msg_print(_("有効な生い立ち設定はこのファイルにありません。", "There does not exist valid background history preference.")); - msg_print(NULL); - histpref_buf = NULL; - return FALSE; - } - - for (i = 0; i < 4; i++) - creature_ptr->history[i][0] = '\0'; - - /* loop */ - for (s = histpref_buf; *s == ' '; s++) - ; - - n = strlen(s); - while ((n > 0) && (s[n - 1] == ' ')) - s[--n] = '\0'; - - roff_to_buf(s, 60, temp, sizeof(temp)); - t = temp; - for (i = 0; i < 4; i++) { - if (t[0] == 0) - break; - else { - strcpy(creature_ptr->history[i], t); - t += strlen(t) + 1; - } - } - - for (i = 0; i < 4; i++) { - /* loop */ - for (j = 0; creature_ptr->history[i][j]; j++) - ; - - for (; j < 59; j++) - creature_ptr->history[i][j] = ' '; - creature_ptr->history[i][59] = '\0'; - } - - histpref_buf = NULL; - return TRUE; -} - -/*! - * @brief 生い立ちメッセージを編集する。/Character background edit-mode - * @return なし - */ -static void edit_history(player_type* creature_ptr, void (*process_autopick_file_command)(char*)) -{ - char old_history[4][60]; - for (int i = 0; i < 4; i++) { - sprintf(old_history[i], "%s", creature_ptr->history[i]); - } - - for (int i = 0; i < 4; i++) { - /* loop */ - int j; - for (j = 0; creature_ptr->history[i][j]; j++) - ; - - for (; j < 59; j++) - creature_ptr->history[i][j] = ' '; - creature_ptr->history[i][59] = '\0'; - } - - display_player(creature_ptr, 1, map_name); - c_put_str(TERM_L_GREEN, _("(キャラクターの生い立ち - 編集モード)", "(Character Background - Edit Mode)"), 11, 20); - put_str(_("[ カーソルキーで移動、Enterで終了、Ctrl-Aでファイル読み込み ]", "[ Cursor key for Move, Enter for End, Ctrl-A for Read pref ]"), 17, 10); - TERM_LEN y = 0; - TERM_LEN x = 0; - while (TRUE) { - int skey; - char c; - - for (int i = 0; i < 4; i++) { - put_str(creature_ptr->history[i], i + 12, 10); - } -#ifdef JP - if (iskanji2(creature_ptr->history[y], x)) - c_put_str(TERM_L_BLUE, format("%c%c", creature_ptr->history[y][x], creature_ptr->history[y][x + 1]), y + 12, x + 10); - else -#endif - c_put_str(TERM_L_BLUE, format("%c", creature_ptr->history[y][x]), y + 12, x + 10); - - Term_gotoxy(x + 10, y + 12); - skey = inkey_special(TRUE); - if (!(skey & SKEY_MASK)) - c = (char)skey; - else - c = 0; - - if (skey == SKEY_UP || c == KTRL('p')) { - y--; - if (y < 0) - y = 3; -#ifdef JP - if ((x > 0) && (iskanji2(creature_ptr->history[y], x - 1))) - x--; -#endif - } else if (skey == SKEY_DOWN || c == KTRL('n')) { - y++; - if (y > 3) - y = 0; -#ifdef JP - if ((x > 0) && (iskanji2(creature_ptr->history[y], x - 1))) - x--; -#endif - } else if (skey == SKEY_RIGHT || c == KTRL('f')) { -#ifdef JP - if (iskanji2(creature_ptr->history[y], x)) - x++; -#endif - x++; - if (x > 58) { - x = 0; - if (y < 3) - y++; - } - } else if (skey == SKEY_LEFT || c == KTRL('b')) { - x--; - if (x < 0) { - if (y) { - y--; - x = 58; - } else - x = 0; - } - -#ifdef JP - if ((x > 0) && (iskanji2(creature_ptr->history[y], x - 1))) - x--; -#endif - } else if (c == '\r' || c == '\n') { - Term_erase(0, 11, 255); - Term_erase(0, 17, 255); - put_str(_("(キャラクターの生い立ち - 編集済み)", "(Character Background - Edited)"), 11, 20); - break; - } else if (c == ESCAPE) { - clear_from(11); - put_str(_("(キャラクターの生い立ち)", "(Character Background)"), 11, 25); - for (int i = 0; i < 4; i++) { - sprintf(creature_ptr->history[i], "%s", old_history[i]); - put_str(creature_ptr->history[i], i + 12, 10); - } - - break; - } else if (c == KTRL('A')) { - if (do_cmd_histpref(creature_ptr, process_autopick_file_command)) { -#ifdef JP - if ((x > 0) && (iskanji2(creature_ptr->history[y], x - 1))) - x--; -#endif - } - } else if (c == '\010') { - x--; - if (x < 0) { - if (y) { - y--; - x = 58; - } else - x = 0; - } - - creature_ptr->history[y][x] = ' '; -#ifdef JP - if ((x > 0) && (iskanji2(creature_ptr->history[y], x - 1))) { - x--; - creature_ptr->history[y][x] = ' '; - } -#endif - } -#ifdef JP - else if (iskanji(c) || isprint(c)) -#else - else if (isprint(c)) /* BUGFIX */ -#endif - { -#ifdef JP - if (iskanji2(creature_ptr->history[y], x)) { - creature_ptr->history[y][x + 1] = ' '; - } - - if (iskanji(c)) { - if (x > 57) { - x = 0; - y++; - if (y > 3) - y = 0; - } - - if (iskanji2(creature_ptr->history[y], x + 1)) { - creature_ptr->history[y][x + 2] = ' '; - } - - creature_ptr->history[y][x++] = c; - - c = inkey(); - } -#endif - creature_ptr->history[y][x++] = c; - if (x > 58) { - x = 0; - y++; - if (y > 3) - y = 0; - } - } - } -} - /*! * @brief player_birth()関数のサブセット/Helper function for 'player_birth()' * @details diff --git a/src/birth/birth.h b/src/birth/birth.h index 7ad3164fc..6824c2431 100644 --- a/src/birth/birth.h +++ b/src/birth/birth.h @@ -4,5 +4,4 @@ extern s32b stat_match[6]; extern s32b auto_round; -extern void add_history_from_pref_line(concptr t); extern void player_birth(player_type *creature_ptr, void(*process_autopick_file_command)(char*)); diff --git a/src/birth/history-editor.c b/src/birth/history-editor.c new file mode 100644 index 000000000..a28ceeb68 --- /dev/null +++ b/src/birth/history-editor.c @@ -0,0 +1,176 @@ +#include "system/angband.h" +#include "birth/history-editor.h" +#include "io/files.h" +#include "view/display-main-window.h" // 暫定。後で消す. +#include "term/gameterm.h" +#include "view/display-player.h" // 暫定。後で消す. +#include "locale/japanese.h" +#include "io/read-pref-file.h" + +/*! + * @brief 生い立ちメッセージを編集する。/Character background edit-mode + * @param creature_ptr プレーヤーへの参照ポインタ + * @param process_autopick_file_command 自動拾いファイルコマンドへの関数ポインタ + * @return なし + */ +void edit_history(player_type *creature_ptr, void (*process_autopick_file_command)(char *)) +{ + char old_history[4][60]; + for (int i = 0; i < 4; i++) { + sprintf(old_history[i], "%s", creature_ptr->history[i]); + } + + for (int i = 0; i < 4; i++) { + /* loop */ + int j; + for (j = 0; creature_ptr->history[i][j]; j++) + ; + + for (; j < 59; j++) + creature_ptr->history[i][j] = ' '; + creature_ptr->history[i][59] = '\0'; + } + + display_player(creature_ptr, 1, map_name); + c_put_str(TERM_L_GREEN, _("(キャラクターの生い立ち - 編集モード)", "(Character Background - Edit Mode)"), 11, 20); + put_str(_("[ カーソルキーで移動、Enterで終了、Ctrl-Aでファイル読み込み ]", "[ Cursor key for Move, Enter for End, Ctrl-A for Read pref ]"), 17, 10); + TERM_LEN y = 0; + TERM_LEN x = 0; + while (TRUE) { + char c; + + for (int i = 0; i < 4; i++) { + put_str(creature_ptr->history[i], i + 12, 10); + } +#ifdef JP + if (iskanji2(creature_ptr->history[y], x)) + c_put_str(TERM_L_BLUE, format("%c%c", creature_ptr->history[y][x], creature_ptr->history[y][x + 1]), y + 12, x + 10); + else +#endif + c_put_str(TERM_L_BLUE, format("%c", creature_ptr->history[y][x]), y + 12, x + 10); + + Term_gotoxy(x + 10, y + 12); + int skey = inkey_special(TRUE); + if (!(skey & SKEY_MASK)) + c = (char)skey; + else + c = 0; + + if (skey == SKEY_UP || c == KTRL('p')) { + y--; + if (y < 0) + y = 3; +#ifdef JP + if ((x > 0) && (iskanji2(creature_ptr->history[y], x - 1))) + x--; +#endif + } else if (skey == SKEY_DOWN || c == KTRL('n')) { + y++; + if (y > 3) + y = 0; +#ifdef JP + if ((x > 0) && (iskanji2(creature_ptr->history[y], x - 1))) + x--; +#endif + } else if (skey == SKEY_RIGHT || c == KTRL('f')) { +#ifdef JP + if (iskanji2(creature_ptr->history[y], x)) + x++; +#endif + x++; + if (x > 58) { + x = 0; + if (y < 3) + y++; + } + } else if (skey == SKEY_LEFT || c == KTRL('b')) { + x--; + if (x < 0) { + if (y) { + y--; + x = 58; + } else + x = 0; + } + +#ifdef JP + if ((x > 0) && (iskanji2(creature_ptr->history[y], x - 1))) + x--; +#endif + } else if (c == '\r' || c == '\n') { + Term_erase(0, 11, 255); + Term_erase(0, 17, 255); + put_str(_("(キャラクターの生い立ち - 編集済み)", "(Character Background - Edited)"), 11, 20); + break; + } else if (c == ESCAPE) { + clear_from(11); + put_str(_("(キャラクターの生い立ち)", "(Character Background)"), 11, 25); + for (int i = 0; i < 4; i++) { + sprintf(creature_ptr->history[i], "%s", old_history[i]); + put_str(creature_ptr->history[i], i + 12, 10); + } + + break; + } else if (c == KTRL('A')) { + if (read_histpref(creature_ptr, process_autopick_file_command)) { +#ifdef JP + if ((x > 0) && (iskanji2(creature_ptr->history[y], x - 1))) + x--; +#endif + } + } else if (c == '\010') { + x--; + if (x < 0) { + if (y) { + y--; + x = 58; + } else + x = 0; + } + + creature_ptr->history[y][x] = ' '; +#ifdef JP + if ((x > 0) && (iskanji2(creature_ptr->history[y], x - 1))) { + x--; + creature_ptr->history[y][x] = ' '; + } +#endif + } +#ifdef JP + else if (iskanji(c) || isprint(c)) +#else + else if (isprint(c)) /* BUGFIX */ +#endif + { +#ifdef JP + if (iskanji2(creature_ptr->history[y], x)) { + creature_ptr->history[y][x + 1] = ' '; + } + + if (iskanji(c)) { + if (x > 57) { + x = 0; + y++; + if (y > 3) + y = 0; + } + + if (iskanji2(creature_ptr->history[y], x + 1)) { + creature_ptr->history[y][x + 2] = ' '; + } + + creature_ptr->history[y][x++] = c; + + c = inkey(); + } +#endif + creature_ptr->history[y][x++] = c; + if (x > 58) { + x = 0; + y++; + if (y > 3) + y = 0; + } + } + } +} diff --git a/src/birth/history-editor.h b/src/birth/history-editor.h new file mode 100644 index 000000000..435a1dffe --- /dev/null +++ b/src/birth/history-editor.h @@ -0,0 +1,3 @@ +#pragma once + +void edit_history(player_type *creature_ptr, void (*process_autopick_file_command)(char *)); diff --git a/src/io/interpret-pref-file.c b/src/io/interpret-pref-file.c index 4b518d668..307960da8 100644 --- a/src/io/interpret-pref-file.c +++ b/src/io/interpret-pref-file.c @@ -15,6 +15,8 @@ #define MAX_MACRO_CHARS 65536 // 1つのマクロキー押下で実行可能なコマンド最大数 (エスケープシーケンス含む). +char *histpref_buf = NULL; + /*! * @brief Rトークンの解釈 / Process "R::/" -- attr/char for monster races * @param buf バッファ @@ -507,3 +509,15 @@ errr interpret_pref_file(player_type *creature_ptr, char *buf) return 1; } } + +/*! + * @brief 生い立ちメッセージの内容をバッファに加える。 / Hook function for reading the histpref.prf file. + * @return なし + */ +void add_history_from_pref_line(concptr t) +{ + if (!histpref_buf) + return; + + my_strcat(histpref_buf, t, HISTPREF_LIMIT); +} diff --git a/src/io/interpret-pref-file.h b/src/io/interpret-pref-file.h index 9f1e62f1e..b96c63ac2 100644 --- a/src/io/interpret-pref-file.h +++ b/src/io/interpret-pref-file.h @@ -2,4 +2,9 @@ #include "system/angband.h" +#define HISTPREF_LIMIT 1024 + +extern char *histpref_buf; + errr interpret_pref_file(player_type *creature_ptr, char *buf); +void add_history_from_pref_line(concptr t); diff --git a/src/io/read-pref-file.c b/src/io/read-pref-file.c index 179c6249f..c83bef3c0 100644 --- a/src/io/read-pref-file.c +++ b/src/io/read-pref-file.c @@ -301,3 +301,78 @@ void load_all_pref_files(player_type* player_ptr) autopick_load_pref(player_ptr, FALSE); } + +/*! + * @brief 生い立ちメッセージをファイルからロードする。 + * @return なし + */ +bool read_histpref(player_type *creature_ptr, void (*process_autopick_file_command)(char *)) +{ + char buf[80]; + errr err; + int i, j, n; + char *s, *t; + char temp[64 * 4]; + char histbuf[HISTPREF_LIMIT]; + + if (!get_check(_("生い立ち設定ファイルをロードしますか? ", "Load background history preference file? "))) + return FALSE; + + histbuf[0] = '\0'; + histpref_buf = histbuf; + + sprintf(buf, _("histedit-%s.prf", "histpref-%s.prf"), creature_ptr->base_name); + err = process_histpref_file(creature_ptr, buf, process_autopick_file_command); + + if (0 > err) { + strcpy(buf, _("histedit.prf", "histpref.prf")); + err = process_histpref_file(creature_ptr, buf, process_autopick_file_command); + } + + if (err) { + msg_print(_("生い立ち設定ファイルの読み込みに失敗しました。", "Failed to load background history preference.")); + msg_print(NULL); + histpref_buf = NULL; + return FALSE; + } else if (!histpref_buf[0]) { + msg_print(_("有効な生い立ち設定はこのファイルにありません。", "There does not exist valid background history preference.")); + msg_print(NULL); + histpref_buf = NULL; + return FALSE; + } + + for (i = 0; i < 4; i++) + creature_ptr->history[i][0] = '\0'; + + /* loop */ + for (s = histpref_buf; *s == ' '; s++) + ; + + n = strlen(s); + while ((n > 0) && (s[n - 1] == ' ')) + s[--n] = '\0'; + + roff_to_buf(s, 60, temp, sizeof(temp)); + t = temp; + for (i = 0; i < 4; i++) { + if (t[0] == 0) + break; + else { + strcpy(creature_ptr->history[i], t); + t += strlen(t) + 1; + } + } + + for (i = 0; i < 4; i++) { + /* loop */ + for (j = 0; creature_ptr->history[i][j]; j++) + ; + + for (; j < 59; j++) + creature_ptr->history[i][j] = ' '; + creature_ptr->history[i][59] = '\0'; + } + + histpref_buf = NULL; + return TRUE; +} diff --git a/src/io/read-pref-file.h b/src/io/read-pref-file.h index ecf55537f..0a42de5d1 100644 --- a/src/io/read-pref-file.h +++ b/src/io/read-pref-file.h @@ -6,6 +6,7 @@ extern char auto_dump_footer[]; errr process_pref_file(player_type *creature_ptr, concptr name, void(*process_autopick_file_command)(char*)); errr process_autopick_file(player_type *creature_ptr, concptr name, void(*process_autopick_file_command)(char*)); errr process_histpref_file(player_type *creature_ptr, concptr name, void(*process_autopick_file_command)(char*)); +bool read_histpref(player_type *creature_ptr, void (*process_autopick_file_command)(char *)); void auto_dump_printf(FILE *auto_dump_stream, concptr fmt, ...); bool open_auto_dump(FILE **fpp, concptr buf, concptr mark);