From 43d1af3a44b4766c48fd37f8473dcbc56c8966ad Mon Sep 17 00:00:00 2001 From: kichikuou Date: Sun, 19 Jan 2025 09:03:23 +0900 Subject: [PATCH] AGS: Refactor text layout logic --- src/resource.cpp | 2 ++ src/sys/ags.cpp | 72 +++++++++++++++++++-------------------- src/sys/ags.h | 38 +++++++++++++-------- src/sys/ags_text.cpp | 50 +++++++++++---------------- src/sys/ags_window.cpp | 76 ++++++++++++++++++------------------------ src/sys/nact.cpp | 8 ++--- src/sys/nact_input.cpp | 2 ++ src/sys/nact_sys1.cpp | 56 ++++++++++--------------------- src/sys/nact_sys2.cpp | 20 ++++------- src/sys/nact_sys3.cpp | 50 ++++++++++++--------------- src/win/nact_win.cpp | 2 ++ 11 files changed, 163 insertions(+), 213 deletions(-) diff --git a/src/resource.cpp b/src/resource.cpp index 07fd1ad..6f71ecd 100644 --- a/src/resource.cpp +++ b/src/resource.cpp @@ -1,6 +1,8 @@ #ifdef _WIN32 #include #undef ERROR +#undef min +#undef max #endif #include "common.h" diff --git a/src/sys/ags.cpp b/src/sys/ags.cpp index ac9b42a..753a7bd 100644 --- a/src/sys/ags.cpp +++ b/src/sys/ags.cpp @@ -193,33 +193,31 @@ AGS::AGS(const Config& config, const GameId& game_id) : game_id(game_id), dirty( src_screen = dest_screen = 0; // メッセージ表示 - text_dest_x = text_w[0].sx; - text_dest_y = text_w[0].sy + 2; - text_font_maxsize = 0; - text_space = 2; - text_font_size = 16; + text.reset_pos(text_w[0].sx, text_w[0].sy + 2); + text.line_space = 2; + text.font_size = 16; if (game_id.sys_ver == 1) { - text_font_color = 15 + 16; - text_frame_color = 15 + 16; - text_back_color = 0 + 16; + text.font_color = 15 + 16; + text.frame_color = 15 + 16; + text.back_color = 0 + 16; } else { - text_font_color = 15; - text_frame_color = 15; - text_back_color = 0; + text.font_color = 15; + text.frame_color = 15; + text.back_color = 0; } // メニュー表示 - menu_dest_x = 2; - menu_dest_y = 0; - menu_font_size = 16; + menu.reset_pos(2, 2); + menu.line_space = 4; + menu.font_size = 16; if (game_id.sys_ver == 1) { - menu_font_color = 15 + 16; - menu_frame_color = 15 + 16; - menu_back_color = 0 + 16; + menu.font_color = 15 + 16; + menu.frame_color = 15 + 16; + menu.back_color = 0 + 16; } else { - menu_font_color = 15; - menu_frame_color = 15; - menu_back_color = 0; + menu.font_color = 15; + menu.frame_color = 15; + menu.back_color = 0; } menu_fix = false; @@ -274,18 +272,18 @@ AGS::~AGS() void AGS::load(FILEIO* fio) { - menu_font_size = fio->getw(); - text_font_size = fio->getw(); + menu.font_size = fio->getw(); + text.font_size = fio->getw(); palette_bank = fio->getw(); if (!palette_bank) { palette_bank = -1; } - text_font_color = fio->getw(); - menu_font_color = fio->getw(); - menu_frame_color = fio->getw(); - menu_back_color = fio->getw(); - text_frame_color = fio->getw(); - text_back_color = fio->getw(); + text.font_color = fio->getw(); + menu.font_color = fio->getw(); + menu.frame_color = fio->getw(); + menu.back_color = fio->getw(); + text.frame_color = fio->getw(); + text.back_color = fio->getw(); for (int i = 0; i < 10; i++) { menu_w[i].clear_saved(); menu_w[i].sx = fio->getw(); @@ -312,15 +310,15 @@ void AGS::load(FILEIO* fio) void AGS::save(FILEIO* fio) { - fio->putw(menu_font_size); - fio->putw(text_font_size); + fio->putw(menu.font_size); + fio->putw(text.font_size); fio->putw(palette_bank == -1 ? 0 : palette_bank); - fio->putw(text_font_color); - fio->putw(menu_font_color); - fio->putw(menu_frame_color); - fio->putw(menu_back_color); - fio->putw(text_frame_color); - fio->putw(text_back_color); + fio->putw(text.font_color); + fio->putw(menu.font_color); + fio->putw(menu.frame_color); + fio->putw(menu.back_color); + fio->putw(text.frame_color); + fio->putw(text.back_color); for (int i = 0; i < 10; i++) { fio->putw(menu_w[i].sx); fio->putw(menu_w[i].sy); @@ -505,7 +503,7 @@ int AGS::calculate_menu_max(int window) { if (game_id.is(GameId::INTRUDER)) return 6; if (game_id.is(GameId::GAKUEN)) - return (menu_w[window - 1].ey - menu_w[window - 1].sy) / (menu_font_size + 4); + return (menu_w[window - 1].ey - menu_w[window - 1].sy) / (menu.font_size + 4); return 11; } diff --git a/src/sys/ags.h b/src/sys/ags.h index 2cea0a5..7af3aa0 100644 --- a/src/sys/ags.h +++ b/src/sys/ags.h @@ -7,6 +7,7 @@ #ifndef _AGS_H_ #define _AGS_H_ +#include #include #include #include @@ -153,23 +154,32 @@ public: int window_width, window_height; int screen_width, screen_height; + struct TextContext { + SDL_Point pos; + int origin_x; + int line_space; + int font_size; + uint8_t font_color; + uint8_t frame_color; + uint8_t back_color; + int current_line_height; + + void reset_pos(int x, int y) { + pos.x = origin_x = x; + pos.y = y; + current_line_height = 0; + } + void newline() { + pos.x = origin_x; + pos.y += std::max(font_size, current_line_height) + line_space; + current_line_height = 0; + } + }; // メッセージ表示 - int text_dest_x; - int text_dest_y; - int text_space; - int text_font_size; - uint8 text_font_color; - uint8 text_frame_color; - uint8 text_back_color; - int text_font_maxsize; // その行での最大フォントサイズ + TextContext text; // メニュー表示 - int menu_dest_x; - int menu_dest_y; - int menu_font_size; - uint8 menu_font_color; - uint8 menu_frame_color; - uint8 menu_back_color; + TextContext menu; bool menu_fix; bool draw_hankaku; diff --git a/src/sys/ags_text.cpp b/src/sys/ags_text.cpp index 240b7d8..629df33 100644 --- a/src/sys/ags_text.cpp +++ b/src/sys/ags_text.cpp @@ -349,31 +349,21 @@ int convert_to_hankaku(int code) void AGS::draw_text(const char* string, bool text_wait) { - int screen, dest_x, dest_y, font_size; - uint8 font_color; - + if (!*string) + return; uint8 antialias_cache[256*7]; if (antialias) memset(antialias_cache, 0, 256); - if (draw_menu) { - screen = 2; - dest_x = menu_dest_x; - dest_y = menu_dest_y; - font_size = menu_font_size; - font_color = menu_font_color; - } else { - screen = dest_screen; - dest_x = text_dest_x; - dest_y = text_dest_y; - font_size = text_font_size; - font_color = text_font_color; - if (*string && text_font_maxsize < text_font_size) - text_font_maxsize = text_font_size; - } + TextContext& ctx = draw_menu ? menu : text; + int screen = draw_menu ? 2 : dest_screen; + int dest_x = ctx.pos.x; + int dest_y = ctx.pos.y; + if (ctx.current_line_height < ctx.font_size) + ctx.current_line_height = ctx.font_size; TTF_Font* font = NULL; - switch (font_size) { + switch (ctx.font_size) { case 16: font = hFont16; break; case 24: font = hFont24; break; case 32: font = hFont32; break; @@ -383,7 +373,7 @@ void AGS::draw_text(const char* string, bool text_wait) int ascent = TTF_FontAscent(font); int descent = TTF_FontDescent(font); // Adjust dest_y if the font height is larger than the specified size. - dest_y -= (ascent - descent - font_size) / 2; + dest_y -= (ascent - descent - ctx.font_size) / 2; while (*string) { int code = g_nact->encoding->next_codepoint(&string); @@ -396,16 +386,16 @@ void AGS::draw_text(const char* string, bool text_wait) // 文字出力 if (GAIJI_FIRST <= code && code <= GAIJI_LAST) { // Use unadjusted dest_y here. - draw_gaiji(screen, dest_x, draw_menu ? menu_dest_y : text_dest_y, code, font_size, font_color); - dest_x += font_size; + draw_gaiji(screen, dest_x, ctx.pos.y, code, ctx.font_size, ctx.font_color); + dest_x += ctx.font_size; } else { if (!draw_menu) texthook_character(g_nact->get_scenario_page(), code); if (antialias) - draw_char_antialias(screen, dest_x, dest_y, code, font, font_color, antialias_cache); + draw_char_antialias(screen, dest_x, dest_y, code, font, ctx.font_color, antialias_cache); else - draw_char(screen, dest_x, dest_y, code, font, font_color); + draw_char(screen, dest_x, dest_y, code, font, ctx.font_color); int miny, maxy, advance; TTF_GlyphMetrics(font, code, NULL, NULL, &miny, &maxy, &advance); @@ -418,20 +408,18 @@ void AGS::draw_text(const char* string, bool text_wait) if (!draw_menu && text_wait && code != ' ') { // 画面更新 if(screen == 0) - draw_screen(text_dest_x, dest_y, dest_x - text_dest_x, ascent - descent); - text_dest_x = dest_x; + draw_screen(ctx.pos.x, dest_y, dest_x - ctx.pos.x, ascent - descent); + ctx.pos.x = dest_x; // Wait g_nact->text_wait(); } } - if (draw_menu) - menu_dest_x = dest_x; - else if (!text_wait) { + if (!draw_menu && !text_wait) { // 画面更新 if(screen == 0) - draw_screen(text_dest_x, dest_y, dest_x - text_dest_x, ascent - descent); - text_dest_x = dest_x; + draw_screen(ctx.pos.x, dest_y, dest_x - ctx.pos.x, ascent - descent); } + ctx.pos.x = dest_x; } void AGS::draw_char(int dest, int dest_x, int dest_y, uint16 code, TTF_Font* font, uint8 color) diff --git a/src/sys/ags_window.cpp b/src/sys/ags_window.cpp index 111c765..a7cccf1 100644 --- a/src/sys/ags_window.cpp +++ b/src/sys/ags_window.cpp @@ -112,27 +112,20 @@ void AGS::clear_text_window(int index, bool erase) if(erase) { if (w.frame && fade_level) { - draw_window(w.sx - 8, w.sy - 8, w.ex + 8, w.ey + 8, true, text_frame_color, text_back_color); + draw_window(w.sx - 8, w.sy - 8, w.ex + 8, w.ey + 8, true, text.frame_color, text.back_color); } else { - box_fill(0, w.sx, w.sy, w.ex, w.ey, text_back_color); + box_fill(0, w.sx, w.sy, w.ex, w.ey, text.back_color); } } - text_dest_x = w.sx; - text_dest_y = w.sy + 2;//text_space; - text_font_maxsize = 0; + text.reset_pos(w.sx, w.sy + 2); } bool AGS::return_text_line(int index) { - Window& w = text_w[index - 1]; - text_dest_x = w.sx; - text_dest_y += (text_font_maxsize > text_font_size) ? text_font_maxsize : text_font_size; - text_dest_y += text_space; - text_font_maxsize = 0; - - // 次の行が表示しきれるか? - return (text_dest_y + text_font_size) > w.ey ? true : false; + text.newline(); + // Return true if the next line exceeds the bottom of the window + return text.pos.y + text.font_size > text_w[index - 1].ey; } void AGS::draw_push(int index) @@ -148,22 +141,22 @@ void AGS::draw_push(int index) int y = w.ey - 16; for(int i = 0; i < 16; i++) { - if(pattern[i] & 0x8000) vram[0][y + i][x + 0] = text_font_color; - if(pattern[i] & 0x4000) vram[0][y + i][x + 1] = text_font_color; - if(pattern[i] & 0x2000) vram[0][y + i][x + 2] = text_font_color; - if(pattern[i] & 0x1000) vram[0][y + i][x + 3] = text_font_color; - if(pattern[i] & 0x0800) vram[0][y + i][x + 4] = text_font_color; - if(pattern[i] & 0x0400) vram[0][y + i][x + 5] = text_font_color; - if(pattern[i] & 0x0200) vram[0][y + i][x + 6] = text_font_color; - if(pattern[i] & 0x0100) vram[0][y + i][x + 7] = text_font_color; - if(pattern[i] & 0x0080) vram[0][y + i][x + 8] = text_font_color; - if(pattern[i] & 0x0040) vram[0][y + i][x + 9] = text_font_color; - if(pattern[i] & 0x0020) vram[0][y + i][x + 10] = text_font_color; - if(pattern[i] & 0x0010) vram[0][y + i][x + 11] = text_font_color; - if(pattern[i] & 0x0008) vram[0][y + i][x + 12] = text_font_color; - if(pattern[i] & 0x0004) vram[0][y + i][x + 13] = text_font_color; - if(pattern[i] & 0x0002) vram[0][y + i][x + 14] = text_font_color; - if(pattern[i] & 0x0001) vram[0][y + i][x + 15] = text_font_color; + if(pattern[i] & 0x8000) vram[0][y + i][x + 0] = text.font_color; + if(pattern[i] & 0x4000) vram[0][y + i][x + 1] = text.font_color; + if(pattern[i] & 0x2000) vram[0][y + i][x + 2] = text.font_color; + if(pattern[i] & 0x1000) vram[0][y + i][x + 3] = text.font_color; + if(pattern[i] & 0x0800) vram[0][y + i][x + 4] = text.font_color; + if(pattern[i] & 0x0400) vram[0][y + i][x + 5] = text.font_color; + if(pattern[i] & 0x0200) vram[0][y + i][x + 6] = text.font_color; + if(pattern[i] & 0x0100) vram[0][y + i][x + 7] = text.font_color; + if(pattern[i] & 0x0080) vram[0][y + i][x + 8] = text.font_color; + if(pattern[i] & 0x0040) vram[0][y + i][x + 9] = text.font_color; + if(pattern[i] & 0x0020) vram[0][y + i][x + 10] = text.font_color; + if(pattern[i] & 0x0010) vram[0][y + i][x + 11] = text.font_color; + if(pattern[i] & 0x0008) vram[0][y + i][x + 12] = text.font_color; + if(pattern[i] & 0x0004) vram[0][y + i][x + 13] = text.font_color; + if(pattern[i] & 0x0002) vram[0][y + i][x + 14] = text.font_color; + if(pattern[i] & 0x0001) vram[0][y + i][x + 15] = text.font_color; } draw_screen(x, y, 16, 16); } @@ -200,7 +193,7 @@ void AGS::open_text_window(int index, bool erase) if(erase) { // 窓初期化 - draw_window(sx, sy, ex, ey, w.frame, text_frame_color, text_back_color); + draw_window(sx, sy, ex, ey, w.frame, text.frame_color, text.back_color); } else if (w.save && w.window) { // 窓復帰 sx = w.window_x; @@ -215,10 +208,7 @@ void AGS::open_text_window(int index, bool erase) SDL_SetSurfacePalette(hBmpScreen[0], screen_palette); } - // テキスト描画位置更新 - text_dest_x = w.sx; - text_dest_y = w.sy + text_space;; - text_font_maxsize = 0; + text.reset_pos(w.sx, w.sy + text.line_space); } void AGS::close_text_window(int index, bool update) @@ -260,11 +250,8 @@ void AGS::close_text_window(int index, bool update) SDL_SetSurfacePalette(hBmpScreen[0], screen_palette); } - // テキスト描画位置更新 if(update) { - text_dest_x = w.sx; - text_dest_y = w.sy + text_space;; - text_font_maxsize = 0; + text.reset_pos(w.sx, w.sy + text.line_space); } } @@ -282,7 +269,8 @@ void AGS::set_text_window(int index, int sx, int sy, int ex, int ey, bool save) void AGS::clear_menu_window() { SDL_Rect rect = {0, 0, 640, 480}; - SDL_FillRect(hBmpScreen[2], &rect, menu_back_color); + SDL_FillRect(hBmpScreen[2], &rect, menu.back_color); + menu.reset_pos(2, 2); } void AGS::open_menu_window(int index) @@ -291,7 +279,7 @@ void AGS::open_menu_window(int index) int sx = w.sx; int sy = w.sy; int ex = w.ex; - int ey = menu_fix ? w.ey : sy + menu_dest_y - 1; + int ey = menu_fix ? w.ey : sy + menu.pos.y - 3; int width = ex - sx + 1; int height = ey - sy + 1; int wsx = sx - (w.frame ? 8 : 0); @@ -317,11 +305,11 @@ void AGS::open_menu_window(int index) } // メニュー表示 - draw_window(wsx, wsy, wex, wey, w.frame, menu_frame_color, menu_back_color); + draw_window(wsx, wsy, wex, wey, w.frame, menu.frame_color, menu.back_color); SDL_Rect src_rect = {0, 0, width, height}; SDL_Rect dst_rect = {sx, sy, width, height}; SDL_BlitSurface(hBmpScreen[2], &src_rect, hBmpScreen[0], &dst_rect); - box_line(0, sx, sy, ex, sy + menu_font_size + 3, menu_frame_color); + box_line(0, sx, sy, ex, sy + menu.font_size + 3, menu.frame_color); draw_screen(wsx, wsy, wwidth, wheight); } @@ -331,14 +319,14 @@ void AGS::redraw_menu_window(int index, int selected) int sx = w.sx; int sy = w.sy; int ex = w.ex; - int ey = menu_fix ? w.ey : sy + menu_dest_y - 1; + int ey = menu_fix ? w.ey : sy + menu.pos.y - 3; int width = ex - sx + 1; int height = ey - sy + 1; SDL_Rect src_rect = {0, 0, width, height}; SDL_Rect dst_rect = {sx, sy, width, height}; SDL_BlitSurface(hBmpScreen[2], &src_rect, hBmpScreen[0], &dst_rect); - box_line(0, sx, sy + (menu_font_size + 4) * selected, ex, sy + (menu_font_size + 4) * (selected + 1) - 1, menu_frame_color); + box_line(0, sx, sy + (menu.font_size + 4) * selected, ex, sy + (menu.font_size + 4) * (selected + 1) - 1, menu.frame_color); draw_screen(sx, sy, width, height); } diff --git a/src/sys/nact.cpp b/src/sys/nact.cpp index 8f4b396..65eac7f 100644 --- a/src/sys/nact.cpp +++ b/src/sys/nact.cpp @@ -326,19 +326,15 @@ void NACT::cmd_page_call() void NACT::cmd_set_menu() { if(ags->draw_menu) { - ags->menu_dest_x = 2; - ags->menu_dest_y += ags->menu_font_size + 2; + ags->menu.newline(); ags->draw_menu = false; TRACE("$"); } else { if (menu_items.empty()) { ags->clear_menu_window(); - ags->menu_dest_y = 0; } menu_items.emplace_back(sco.getw()); - ags->menu_dest_x = 2; - ags->menu_dest_y += 2; ags->draw_menu = true; if (game_id.is(GameId::GAKUEN)) @@ -638,7 +634,7 @@ int NACT::menu_select(int num_items) ags->get_menu_window_rect(menu_window, &sx, &sy, &ex, nullptr); int mx = ex - 16; int my = sy + 10; - int height = ags->menu_font_size + 4; + int height = ags->menu.font_size + 4; int current_index = 0; set_cursor(mx, my); diff --git a/src/sys/nact_input.cpp b/src/sys/nact_input.cpp index c8e4fb9..aa427e4 100644 --- a/src/sys/nact_input.cpp +++ b/src/sys/nact_input.cpp @@ -7,6 +7,8 @@ #ifdef _WIN32 #include #undef ERROR +#undef min +#undef max #endif #include #include "nact.h" diff --git a/src/sys/nact_sys1.cpp b/src/sys/nact_sys1.cpp index 7c12a99..723e9c1 100644 --- a/src/sys/nact_sys1.cpp +++ b/src/sys/nact_sys1.cpp @@ -193,29 +193,24 @@ top: int id[32], index = 0; ags->clear_menu_window(); - ags->menu_dest_y = 0; ags->draw_menu = true; if(cnt <= menu_max) { // 1ページ内に全て表示できる for(int i = 0; i < MAX_VERB; i++) { if(chk[i]) { - ags->menu_dest_x = 2; - ags->menu_dest_y += 2; ags->draw_text(caption_verb[i].c_str()); + ags->menu.newline(); id[index++] = i; - ags->menu_dest_y += ags->menu_font_size + 2; } } } else { top2: for(int i = page; i < MAX_VERB; i++) { if(chk[i]) { - ags->menu_dest_x = 2; - ags->menu_dest_y += 2; ags->draw_text(caption_verb[i].c_str()); + ags->menu.newline(); id[index++] = i; - ags->menu_dest_y += ags->menu_font_size + 2; } page = i + 1; if(index == menu_max - 1) { @@ -228,11 +223,9 @@ top2: goto top2; } // 次のページを追加 - ags->menu_dest_x = 2; - ags->menu_dest_y += 2; ags->draw_text(strings.next_page.c_str()); + ags->menu.newline(); id[index++] = -1; - ags->menu_dest_y += ags->menu_font_size + 2; } ags->draw_menu = false; @@ -282,35 +275,28 @@ top: int id[32], index = 0; ags->clear_menu_window(); - ags->menu_dest_y = 0; ags->draw_menu = true; if(cnt <= menu_max - 1) { // 1ページ内に全て表示できる for(int i = 0; i < MAX_OBJ; i++) { if(chk[i]) { - ags->menu_dest_x = 2; - ags->menu_dest_y += 2; ags->draw_text(caption_obj[i].c_str()); + ags->menu.newline(); id[index++] = i; - ags->menu_dest_y += ags->menu_font_size + 2; } } // 戻るを追加 - ags->menu_dest_x = 2; - ags->menu_dest_y += 2; ags->draw_text(strings.back.c_str()); + ags->menu.newline(); id[index++] = 0; - ags->menu_dest_y += ags->menu_font_size + 2; } else { top2: for(int i = page; i < MAX_OBJ; i++) { if(chk[i]) { - ags->menu_dest_x = 2; - ags->menu_dest_y += 2; ags->draw_text(caption_obj[i].c_str()); + ags->menu.newline(); id[index++] = i; - ags->menu_dest_y += ags->menu_font_size + 2; } page = i + 1; if(index == menu_max - 2) { @@ -323,18 +309,14 @@ top2: goto top2; } // 戻るを追加 - ags->menu_dest_x = 2; - ags->menu_dest_y += 2; ags->draw_text(strings.back.c_str()); + ags->menu.newline(); id[index++] = 0; - ags->menu_dest_y += ags->menu_font_size + 2; // 次のページを追加 - ags->menu_dest_x = 2; - ags->menu_dest_y += 2; ags->draw_text(strings.next_page.c_str()); + ags->menu.newline(); id[index++] = -1; - ags->menu_dest_y += ags->menu_font_size + 2; } ags->draw_menu = false; @@ -376,7 +358,7 @@ void NACT_Sys1::cmd_p() { int param = sco.getd(); - ags->text_font_color = (uint8)((param & 0x7) + 16); + ags->text.font_color = (uint8)((param & 0x7) + 16); TRACE("P %d:", param); } @@ -814,20 +796,18 @@ public: } // 矢印を表示する - int x = ags->text_dest_x; - int y = ags->text_dest_y; - int color = ags->text_font_color; - ags->text_font_size = 24; - ags->text_font_color = 16; + SDL_Point orig_pos = ags->text.pos; + int orig_color = ags->text.font_color; + ags->text.font_size = 24; + ags->text.font_color = 16; - ags->text_dest_x = 456; - ags->text_dest_y = 103; + ags->text.pos.x = 456; + ags->text.pos.y = 103; ags->draw_text(buf[param - 1]); - ags->text_dest_x = x; - ags->text_dest_y = y; - ags->text_font_size = 16; - ags->text_font_color = color; + ags->text.pos = orig_pos; + ags->text.font_size = 16; + ags->text.font_color = orig_color; } else if (cmd == 2) { if (param == 0) { // Clear the screen diff --git a/src/sys/nact_sys2.cpp b/src/sys/nact_sys2.cpp index f35ed31..75430de 100644 --- a/src/sys/nact_sys2.cpp +++ b/src/sys/nact_sys2.cpp @@ -275,16 +275,13 @@ void NACT_Sys2::cmd_open_verb() int id[32], index = 0; ags->clear_menu_window(); - ags->menu_dest_y = 0; ags->draw_menu = true; for(int i = 0; i < MAX_VERB; i++) { if(chk[i]) { - ags->menu_dest_x = 2; - ags->menu_dest_y += 2; ags->draw_text(caption_verb[i].c_str()); + ags->menu.newline(); id[index++] = i; - ags->menu_dest_y += ags->menu_font_size + 2; } } ags->draw_menu = false; @@ -329,24 +326,19 @@ void NACT_Sys2::cmd_open_obj(int verb) int id[32], index = 0; ags->clear_menu_window(); - ags->menu_dest_y = 0; ags->draw_menu = true; for(int i = 0; i < MAX_OBJ; i++) { if(chk[i]) { - ags->menu_dest_x = 2; - ags->menu_dest_y += 2; ags->draw_text(caption_obj[i].c_str()); + ags->menu.newline(); id[index++] = i; - ags->menu_dest_y += ags->menu_font_size + 2; } } // 戻るを追加 - ags->menu_dest_x = 2; - ags->menu_dest_y += 2; ags->draw_text(strings.back.c_str()); + ags->menu.newline(); id[index++] = 0; - ags->menu_dest_y += ags->menu_font_size + 2; ags->draw_menu = false; int selection = menu_select(index); @@ -595,7 +587,7 @@ void NACT_Sys2::cmd_p() int param = sco.getd(); if (!game_id.is(GameId::YAKATA2) && !game_id.is(GameId::DALK_HINT) && !game_id.is(GameId::RANCE3_HINT)) { - ags->text_font_color = (uint8)((param & 0x7) + 16); + ags->text.font_color = (uint8)((param & 0x7) + 16); } TRACE("P %d:", param); @@ -751,10 +743,10 @@ void NACT_Sys2::cmd_y() RND = 1; break; case 25: - ags->menu_font_size = (param == 1) ? 16 : (param == 2) ? 24 : (param == 3) ? 32 : (param == 4) ? 48 : (param == 5) ? 64 : 16; + ags->menu.font_size = (param == 1) ? 16 : (param == 2) ? 24 : (param == 3) ? 32 : (param == 4) ? 48 : (param == 5) ? 64 : 16; break; case 26: - ags->text_font_size = (param == 1) ? 16 : (param == 2) ? 24 : (param == 3) ? 32 : (param == 4) ? 48 : (param == 5) ? 64 : 16; + ags->text.font_size = (param == 1) ? 16 : (param == 2) ? 24 : (param == 3) ? 32 : (param == 4) ? 48 : (param == 5) ? 64 : 16; break; case 27: { diff --git a/src/sys/nact_sys3.cpp b/src/sys/nact_sys3.cpp index b9427b5..c5d8b60 100644 --- a/src/sys/nact_sys3.cpp +++ b/src/sys/nact_sys3.cpp @@ -152,16 +152,13 @@ void NACT_Sys3::cmd_open_verb() int id[32], index = 0; ags->clear_menu_window(); - ags->menu_dest_y = 0; ags->draw_menu = true; for(int i = 0; i < MAX_VERB; i++) { if(chk[i]) { - ags->menu_dest_x = 2; - ags->menu_dest_y += 2; ags->draw_text(caption_verb[i].c_str()); + ags->menu.newline(); id[index++] = i; - ags->menu_dest_y += ags->menu_font_size + 2; } } ags->draw_menu = false; @@ -206,24 +203,19 @@ void NACT_Sys3::cmd_open_obj(int verb) int id[32], index = 0; ags->clear_menu_window(); - ags->menu_dest_y = 0; ags->draw_menu = true; for(int i = 0; i < MAX_OBJ; i++) { if(chk[i]) { - ags->menu_dest_x = 2; - ags->menu_dest_y += 2; ags->draw_text(caption_obj[i].c_str()); + ags->menu.newline(); id[index++] = i; - ags->menu_dest_y += ags->menu_font_size + 2; } } // 戻るを追加 - ags->menu_dest_x = 2; - ags->menu_dest_y += 2; ags->draw_text(strings.back.c_str()); + ags->menu.newline(); id[index++] = 0; - ags->menu_dest_y += ags->menu_font_size + 2; ags->draw_menu = false; int selection = menu_select(index); @@ -673,8 +665,8 @@ void NACT_Sys3::cmd_t() TRACE("T %d,%d:", x, y); // x方向はカラム単位で切り捨て - ags->text_dest_x = column ? x * 8 : x & 0xfff8; - ags->text_dest_y = y; + ags->text.pos.x = column ? x * 8 : x & 0xfff8; + ags->text.pos.y = y; } void NACT_Sys3::cmd_u() @@ -831,17 +823,17 @@ void NACT_Sys3::cmd_y() case 24: break; case 25: - ags->menu_font_size = (param == 1) ? 16 : (param == 2) ? 24 : (param == 3) ? 32 : (param == 4) ? 48 : (param == 5) ? 64 : 16; + ags->menu.font_size = (param == 1) ? 16 : (param == 2) ? 24 : (param == 3) ? 32 : (param == 4) ? 48 : (param == 5) ? 64 : 16; break; case 26: - ags->text_font_size = (param == 1) ? 16 : (param == 2) ? 24 : (param == 3) ? 32 : (param == 4) ? 48 : (param == 5) ? 64 : 16; + ags->text.font_size = (param == 1) ? 16 : (param == 2) ? 24 : (param == 3) ? 32 : (param == 4) ? 48 : (param == 5) ? 64 : 16; break; case 27: tvar_maxlen = param; text_dialog(); break; case 28: - ags->text_space = (param == 0) ? 2 : 0; + ags->text.line_space = (param == 0) ? 2 : 0; break; case 30: ags->src_screen = param ? 1 : 0; @@ -1099,17 +1091,17 @@ void NACT_Sys3::cmd_z() if(cmd == 0) { ags->palette_bank = (uint8)(param & 0xff); } else if(cmd == 1) { - ags->text_font_color = (uint8)(param & 0xff); + ags->text.font_color = (uint8)(param & 0xff); } else if(cmd == 2) { - ags->menu_font_color = (uint8)(param & 0xff); + ags->menu.font_color = (uint8)(param & 0xff); } else if(cmd == 3) { - ags->menu_frame_color = (uint8)(param & 0xff); + ags->menu.frame_color = (uint8)(param & 0xff); } else if(cmd == 4) { - ags->menu_back_color = (uint8)(param & 0xff); + ags->menu.back_color = (uint8)(param & 0xff); } else if(cmd == 5) { - ags->text_frame_color = (uint8)(param & 0xff); + ags->text.frame_color = (uint8)(param & 0xff); } else if(cmd == 6) { - ags->text_back_color = (uint8)(param & 0xff); + ags->text.back_color = (uint8)(param & 0xff); } else if(cmd == 7) { ags->cursor_color = (uint8)(param & 0xff); } else if(101 <= cmd && cmd <= 199) { @@ -1261,15 +1253,15 @@ bool NACT_Sys3::k3_hack(const K3HackInfo* info_table) ags->draw_window( info->left - 6, info->top - 6, info->left + info->w * info->cols + 6, info->top + info->h + 6, - true, ags->menu_frame_color, ags->menu_back_color); - int orig_font_size = ags->text_font_size; - ags->text_dest_x = info->left; - ags->text_dest_y = info->top; - ags->text_font_size = info->w; + true, ags->menu.frame_color, ags->menu.back_color); + int orig_font_size = ags->text.font_size; + ags->text.pos.x = info->left; + ags->text.pos.y = info->top; + ags->text.font_size = info->w; ags->draw_text("12345"); - ags->text_font_size = orig_font_size; + ags->text.font_size = orig_font_size; int left = info->left + info->w * (var[info->var] - 1); - ags->box_line(0, left, info->top, left + info->w, info->top + info->h, ags->text_font_color); + ags->box_line(0, left, info->top, left + info->w, info->top + info->h, ags->text.font_color); } // Only You: Prevents the cursor from being locked due to unselectable cells. diff --git a/src/win/nact_win.cpp b/src/win/nact_win.cpp index 7eef88b..82d166f 100644 --- a/src/win/nact_win.cpp +++ b/src/win/nact_win.cpp @@ -1,6 +1,8 @@ #include #include #undef ERROR +#undef min +#undef max #include #include "nact.h" #include "SDL_syswm.h"