From fad34f7bb9f07791fee68460a3686f4f65901194 Mon Sep 17 00:00:00 2001 From: kichikuou Date: Sat, 18 Jan 2025 09:28:53 +0900 Subject: [PATCH] Refactor text / menu window code --- src/sys/ags.cpp | 147 +------------------ src/sys/ags.h | 49 ++++--- src/sys/ags_window.cpp | 326 ++++++++++++++++++++++++++++------------- src/sys/nact.cpp | 5 +- src/sys/nact_sys2.cpp | 39 +---- src/sys/nact_sys3.cpp | 40 +---- 6 files changed, 279 insertions(+), 327 deletions(-) diff --git a/src/sys/ags.cpp b/src/sys/ags.cpp index fa6f76f..66167fd 100644 --- a/src/sys/ags.cpp +++ b/src/sys/ags.cpp @@ -15,20 +15,6 @@ extern SDL_Window* g_window; extern SDL_Renderer* g_renderer; static SDL_Surface* display_surface; -#define SET_TEXT(n, x1, y1, x2, y2, f) { \ - text_w[n].sx = x1; \ - text_w[n].sy = y1; \ - text_w[n].ex = x2; \ - text_w[n].ey = y2; \ - text_w[n].frame = f; \ -} -#define SET_MENU(n, x1, y1, x2, y2, f) { \ - menu_w[n].sx = x1; \ - menu_w[n].sy = y1; \ - menu_w[n].ex = x2; \ - menu_w[n].ey = y2; \ - menu_w[n].frame = f; \ -} #define SET_BOX(n, c, x1, y1, x2, y2) { \ box[n].color = c; \ box[n].sx = x1; \ @@ -209,94 +195,7 @@ AGS::AGS(const Config& config, const GameId& game_id) : game_id(game_id), dirty( SDL_SetPaletteColors(screen_palette, program_palette->colors, 0, 256); - // Bコマンド - for(int i = 0; i < 10; i++) { - // ウィンドウの初期位置はシステムによって異なる - switch (game_id.game) { - case GameId::BUNKASAI: - SET_TEXT(i, 24, 304, 616, 384, false); - SET_MENU(i, 440, 18, 620, 178, true); - break; - case GameId::CRESCENT: - SET_TEXT(i, 24, 288, 616, 378, false); - // 本来は横メニュー - SET_MENU(i, 464, 50, 623, 240, true); - break; - case GameId::RANCE2: - case GameId::RANCE2_HINT: - SET_TEXT(i, 8, 285, 502, 396, false); - SET_MENU(i, 431, 19, 624, 181, false); - break; - case GameId::DPS: - case GameId::DPS_SG_FAHREN: - case GameId::DPS_SG_KATEI: - case GameId::DPS_SG_NOBUNAGA: - case GameId::DPS_SG2_ANTIQUE: - case GameId::DPS_SG2_IKENAI: - case GameId::DPS_SG2_AKAI: - case GameId::DPS_SG3_RABBIT: - case GameId::DPS_SG3_SHINKON: - case GameId::DPS_SG3_SOTSUGYOU: - SET_TEXT(i, 48, 288, 594, 393, false); - //SET_MENU(i, 48, 288, 584, 393, false); - SET_MENU(i, 48, 288, 594, 393, false); - break; - case GameId::FUKEI: - SET_TEXT(i, 44, 282, 593, 396, false); - SET_MENU(i, 460, 14, 635, 214, false); - break; - case GameId::INTRUDER: - SET_TEXT(i, 8, 280, 629, 393, false); - SET_MENU(i, 448, 136, 623, 340, true); - break; - case GameId::TENGU: - SET_TEXT(i, 44, 282, 593, 396, false); - SET_MENU(i, 452, 14, 627, 214, false); - break; - case GameId::TOUSHIN_HINT: - SET_TEXT(i, 8, 311, 623, 391, false); - SET_MENU(i, 452, 14, 627, 214, true); - break; - case GameId::LITTLE_VAMPIRE: - SET_TEXT(i, 8, 255, 615, 383, false); - SET_MENU(i, 448, 11, 615, game_id.language == ENGLISH ? 234 : 224, false); - break; - case GameId::YAKATA: - SET_TEXT(i, 48, 288, 594, 393, false); - SET_MENU(i, 452, 14, 627, 214, false); - break; - case GameId::DALK_HINT: - SET_TEXT(i, 24, 308, 376, 386, false); - SET_MENU(i, 404, 28, 604, 244, true); - break; - case GameId::RANCE3_HINT: - SET_TEXT(i, 104, 304, 615, 383, false); - SET_MENU(i, 464, 24, 623, 200, true); - break; - case GameId::YAKATA2: - SET_TEXT(i, 104, 304, 620, 382, false); - SET_MENU(i, 420, 28, 620, 244, true); - break; - case GameId::GAKUEN: - SET_TEXT(i, 8, 260, 505, 384, false); - if (i == 1) { - SET_MENU(i, 128, 32, 337, 178, true); - } else { - SET_MENU(i, 288, 30, 433, 210, true); - } - break; - default: - SET_TEXT(i, 8, 311, 623, 391, true); - SET_MENU(i, 464, 80, 623, 240, true); - break; - } - text_w[i].push = false; - text_w[i].screen = NULL; - text_w[i].window = NULL; - menu_w[i].push = true; - menu_w[i].screen = NULL; - menu_w[i].window = NULL; - } + init_windows(); // Eコマンド for(int i = 0; i < 20; i++) { @@ -375,22 +274,6 @@ AGS::AGS(const Config& config, const GameId& game_id) : game_id(game_id), dirty( AGS::~AGS() { - // 退避領域の開放 - for(int i = 0; i < 10; i++) { - if(menu_w[i].screen) { - SDL_FreeSurface(menu_w[i].screen); - } - if(menu_w[i].window) { - SDL_FreeSurface(menu_w[i].window); - } - if(text_w[i].screen) { - SDL_FreeSurface(text_w[i].screen); - } - if(text_w[i].window) { - SDL_FreeSurface(text_w[i].window); - } - } - // カーソル開放 for(int i = 0; i < 10; i++) { if(hCursor[i]) { @@ -434,42 +317,26 @@ void AGS::load(FILEIO* fio) 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(); menu_w[i].sy = fio->getw(); menu_w[i].ex = fio->getw(); menu_w[i].ey = fio->getw(); - menu_w[i].push = fio->getw() ? true : false; + menu_w[i].save = fio->getw() ? true : false; menu_w[i].frame = fio->getw() ? true : false; fio->getw(); fio->getw(); - - if (menu_w[i].screen) { - SDL_FreeSurface(menu_w[i].screen); - } - menu_w[i].screen = NULL; - if (menu_w[i].window) { - SDL_FreeSurface(menu_w[i].window); - } - menu_w[i].window = NULL; } for (int i = 0; i < 10; i++) { + text_w[i].clear_saved(); text_w[i].sx = fio->getw(); text_w[i].sy = fio->getw(); text_w[i].ex = fio->getw(); text_w[i].ey = fio->getw(); - text_w[i].push = fio->getw() ? true : false; + text_w[i].save = fio->getw() ? true : false; text_w[i].frame = fio->getw() ? true : false; fio->getw(); fio->getw(); - - if (text_w[i].screen) { - SDL_FreeSurface(text_w[i].screen); - } - text_w[i].screen = NULL; - if (text_w[i].window) { - SDL_FreeSurface(text_w[i].window); - } - text_w[i].window = NULL; } } @@ -489,7 +356,7 @@ void AGS::save(FILEIO* fio) fio->putw(menu_w[i].sy); fio->putw(menu_w[i].ex); fio->putw(menu_w[i].ey); - fio->putw(menu_w[i].push ? 1 : 0); + fio->putw(menu_w[i].save ? 1 : 0); fio->putw(menu_w[i].frame ? 1 : 0); fio->putw(0); fio->putw(0); @@ -499,7 +366,7 @@ void AGS::save(FILEIO* fio) fio->putw(text_w[i].sy); fio->putw(text_w[i].ex); fio->putw(text_w[i].ey); - fio->putw(text_w[i].push ? 1 : 0); + fio->putw(text_w[i].save ? 1 : 0); fio->putw(text_w[i].frame ? 1 : 0); fio->putw(0); fio->putw(0); diff --git a/src/sys/ags.h b/src/sys/ags.h index 6f56184..1c0b912 100644 --- a/src/sys/ags.h +++ b/src/sys/ags.h @@ -115,11 +115,20 @@ public: void draw_push(int index); void open_text_window(int index, bool erase); void close_text_window(int index, bool update); + void set_text_window(int index, int sx, int sy, int ex, int ey, bool save); + void set_text_window_frame(int index, bool frame) { + text_w[index - 1].frame = frame; + } void clear_menu_window(); void open_menu_window(int index); void redraw_menu_window(int index, int selected); void close_menu_window(int index); + void get_menu_window_rect(int index, int* sx, int* sy, int* ex, int* ey); + void set_menu_window(int index, int sx, int sy, int ex, int ey, bool save); + void set_menu_window_frame(int index, bool frame) { + menu_w[index - 1].frame = frame; + } void load_cursor(int page); void select_cursor(); @@ -162,24 +171,6 @@ public: bool draw_hankaku; bool draw_menu; - // ウィンドウ (Bコマンド) - typedef struct { - int sx; - int sy; - int ex; - int ey; - bool frame; - bool push; - SDL_Surface* screen; - int screen_x; - int screen_y; - SDL_Surface* window; - int window_x; - int window_y; - } WINDOW; - WINDOW menu_w[10]; - WINDOW text_w[10]; - // ボックス (E, Y7コマンド) typedef struct { uint8 color; @@ -205,6 +196,28 @@ public: int cursor_index; private: + // Window (B command) + struct Window { + int sx; + int sy; + int ex; + int ey; + bool frame; + bool save; + SDL_Surface* screen; + int screen_x; + int screen_y; + SDL_Surface* window; + int window_x; + int window_y; + + ~Window() { clear_saved(); } + void clear_saved(); + }; + Window menu_w[10]; + Window text_w[10]; + void init_windows(); + Dri acg; const char* bmp_prefix = NULL; }; diff --git a/src/sys/ags_window.cpp b/src/sys/ags_window.cpp index 236d821..111c765 100644 --- a/src/sys/ags_window.cpp +++ b/src/sys/ags_window.cpp @@ -7,38 +7,132 @@ #include "ags.h" #include +void AGS::Window::clear_saved() +{ + if (screen) { + SDL_FreeSurface(screen); + screen = nullptr; + } + if (window) { + SDL_FreeSurface(window); + window = nullptr; + } +} + +void AGS::init_windows() +{ + for (int i = 0; i < 10; i++) { + // ウィンドウの初期位置はシステムによって異なる + switch (game_id.game) { + case GameId::BUNKASAI: + text_w[i] = {24, 304, 616, 384, false}; + menu_w[i] = {440, 18, 620, 178, true}; + break; + case GameId::CRESCENT: + text_w[i] = {24, 288, 616, 378, false}; + // 本来は横メニュー + menu_w[i] = {464, 50, 623, 240, true}; + break; + case GameId::RANCE2: + case GameId::RANCE2_HINT: + text_w[i] = {8, 285, 502, 396, false}; + menu_w[i] = {431, 19, 624, 181, false}; + break; + case GameId::DPS: + case GameId::DPS_SG_FAHREN: + case GameId::DPS_SG_KATEI: + case GameId::DPS_SG_NOBUNAGA: + case GameId::DPS_SG2_ANTIQUE: + case GameId::DPS_SG2_IKENAI: + case GameId::DPS_SG2_AKAI: + case GameId::DPS_SG3_RABBIT: + case GameId::DPS_SG3_SHINKON: + case GameId::DPS_SG3_SOTSUGYOU: + text_w[i] = {48, 288, 594, 393, false}; + //menu_w[i] = {48, 288, 584, 393, false}; + menu_w[i] = {48, 288, 594, 393, false}; + break; + case GameId::FUKEI: + text_w[i] = {44, 282, 593, 396, false}; + menu_w[i] = {460, 14, 635, 214, false}; + break; + case GameId::INTRUDER: + text_w[i] = {8, 280, 629, 393, false}; + menu_w[i] = {448, 136, 623, 340, true}; + break; + case GameId::TENGU: + text_w[i] = {44, 282, 593, 396, false}; + menu_w[i] = {452, 14, 627, 214, false}; + break; + case GameId::TOUSHIN_HINT: + text_w[i] = {8, 311, 623, 391, false}; + menu_w[i] = {452, 14, 627, 214, true}; + break; + case GameId::LITTLE_VAMPIRE: + text_w[i] = {8, 255, 615, 383, false}; + menu_w[i] = {448, 11, 615, game_id.language == ENGLISH ? 234 : 224, false}; + break; + case GameId::YAKATA: + text_w[i] = {48, 288, 594, 393, false}; + menu_w[i] = {452, 14, 627, 214, false}; + break; + case GameId::DALK_HINT: + text_w[i] = {24, 308, 376, 386, false}; + menu_w[i] = {404, 28, 604, 244, true}; + break; + case GameId::RANCE3_HINT: + text_w[i] = {104, 304, 615, 383, false}; + menu_w[i] = {464, 24, 623, 200, true}; + break; + case GameId::YAKATA2: + text_w[i] = {104, 304, 620, 382, false}; + menu_w[i] = {420, 28, 620, 244, true}; + break; + case GameId::GAKUEN: + text_w[i] = {8, 260, 505, 384, false}; + if (i == 1) { + menu_w[i] = {128, 32, 337, 178, true}; + } else { + menu_w[i] = {288, 30, 433, 210, true}; + } + break; + default: + text_w[i] = {8, 311, 623, 391, true}; + menu_w[i] = {464, 80, 623, 240, true}; + break; + } + text_w[i].save = false; + menu_w[i].save = true; + } +} + void AGS::clear_text_window(int index, bool erase) { - int sx = text_w[index - 1].sx; - int sy = text_w[index - 1].sy; - int ex = text_w[index - 1].ex; - int ey = text_w[index - 1].ey; + Window& w = text_w[index - 1]; if(erase) { - if(text_w[index - 1].frame && fade_level) { - draw_window(sx - 8, sy - 8, ex + 8, ey + 8, true, text_frame_color, text_back_color); + 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); } else { - box_fill(0, sx, sy, ex, ey, text_back_color); + box_fill(0, w.sx, w.sy, w.ex, w.ey, text_back_color); } } - text_dest_x = sx; - text_dest_y = sy + 2;//text_space; + text_dest_x = w.sx; + text_dest_y = w.sy + 2;//text_space; text_font_maxsize = 0; } bool AGS::return_text_line(int index) { - int sx = text_w[index - 1].sx; - int ey = text_w[index - 1].ey; - - text_dest_x = sx; + 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) > ey ? true : false; + return (text_dest_y + text_font_size) > w.ey ? true : false; } void AGS::draw_push(int index) @@ -49,8 +143,9 @@ void AGS::draw_push(int index) 0x9000, 0x9974, 0xe944, 0x8977, 0x8915, 0x8775, 0x0000, 0xffff }; - int x = text_w[index - 1].ex - 16; - int y = text_w[index - 1].ey - 16; + Window& w = text_w[index - 1]; + int x = w.ex - 16; + 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; @@ -75,97 +170,115 @@ void AGS::draw_push(int index) void AGS::open_text_window(int index, bool erase) { - int sx = text_w[index - 1].sx - (text_w[index - 1].frame ? 8 : 0); - int sy = text_w[index - 1].sy - (text_w[index - 1].frame ? 8 : 0); - int ex = text_w[index - 1].ex + (text_w[index - 1].frame ? 8 : 0); - int ey = text_w[index - 1].ey + (text_w[index - 1].frame ? 8 : 0); + Window& w = text_w[index - 1]; + int sx = w.sx - (w.frame ? 8 : 0); + int sy = w.sy - (w.frame ? 8 : 0); + int ex = w.ex + (w.frame ? 8 : 0); + int ey = w.ey + (w.frame ? 8 : 0); int width = ex - sx + 1; int height = ey - sy + 1; + if (game_id.is(GameId::PROG_CD) && !erase) { + // prostudent G オープニング画面化け対策 + w.clear_saved(); + } + // 画面退避 - if(text_w[index - 1].push) { - if(text_w[index - 1].screen) { - SDL_FreeSurface(text_w[index - 1].screen); + if (w.save) { + if (w.screen) { + SDL_FreeSurface(w.screen); } - text_w[index - 1].screen = SDL_CreateRGBSurfaceWithFormat(0, width, height, 8, SDL_PIXELFORMAT_INDEX8); - text_w[index - 1].screen_x = sx; - text_w[index - 1].screen_y = sy; - SDL_SetPaletteColors(text_w[index - 1].screen->format->palette, screen_palette->colors, 0, 256); + w.screen = SDL_CreateRGBSurfaceWithFormat(0, width, height, 8, SDL_PIXELFORMAT_INDEX8); + w.screen_x = sx; + w.screen_y = sy; + SDL_SetPaletteColors(w.screen->format->palette, screen_palette->colors, 0, 256); SDL_Rect rect = {sx, sy, width, height}; - SDL_BlitSurface(hBmpScreen[0], &rect, text_w[index - 1].screen, NULL); + SDL_BlitSurface(hBmpScreen[0], &rect, w.screen, NULL); } if(erase) { // 窓初期化 - draw_window(sx, sy, ex, ey, text_w[index - 1].frame, text_frame_color, text_back_color); - } else if(text_w[index - 1].push && text_w[index - 1].window) { + draw_window(sx, sy, ex, ey, w.frame, text_frame_color, text_back_color); + } else if (w.save && w.window) { // 窓復帰 - sx = text_w[index - 1].window_x; - sy = text_w[index - 1].window_y; - width = text_w[index - 1].window->w; - height = text_w[index - 1].window->h; + sx = w.window_x; + sy = w.window_y; + width = w.window->w; + height = w.window->h; - SDL_SetSurfacePalette(hBmpScreen[0], text_w[index - 1].window->format->palette); + SDL_SetSurfacePalette(hBmpScreen[0], w.window->format->palette); SDL_Rect rect = {sx, sy, width, height}; - SDL_BlitSurface(text_w[index - 1].window, NULL, hBmpScreen[0], &rect); + SDL_BlitSurface(w.window, NULL, hBmpScreen[0], &rect); draw_screen(sx, sy, width, height); SDL_SetSurfacePalette(hBmpScreen[0], screen_palette); } // テキスト描画位置更新 - text_dest_x = text_w[index - 1].sx; - text_dest_y = text_w[index - 1].sy + text_space;; + text_dest_x = w.sx; + text_dest_y = w.sy + text_space;; text_font_maxsize = 0; } void AGS::close_text_window(int index, bool update) { - int sx = text_w[index - 1].sx - (text_w[index - 1].frame ? 8 : 0); - int sy = text_w[index - 1].sy - (text_w[index - 1].frame ? 8 : 0); - int ex = text_w[index - 1].ex + (text_w[index - 1].frame ? 8 : 0); - int ey = text_w[index - 1].ey + (text_w[index - 1].frame ? 8 : 0); + Window& w = text_w[index - 1]; + int sx = w.sx - (w.frame ? 8 : 0); + int sy = w.sy - (w.frame ? 8 : 0); + int ex = w.ex + (w.frame ? 8 : 0); + int ey = w.ey + (w.frame ? 8 : 0); int width = ex - sx + 1; int height = ey - sy + 1; // 窓退避 - if(text_w[index - 1].push) { - if(text_w[index - 1].window) { - SDL_FreeSurface(text_w[index - 1].window); + if (w.save) { + if (w.window) { + SDL_FreeSurface(w.window); } - text_w[index - 1].window = SDL_CreateRGBSurfaceWithFormat(0, width, height, 8, SDL_PIXELFORMAT_INDEX8); - text_w[index - 1].window_x = sx; - text_w[index - 1].window_y = sy; - SDL_SetPaletteColors(text_w[index - 1].window->format->palette, screen_palette->colors, 0, 256); + w.window = SDL_CreateRGBSurfaceWithFormat(0, width, height, 8, SDL_PIXELFORMAT_INDEX8); + w.window_x = sx; + w.window_y = sy; + SDL_SetPaletteColors(w.window->format->palette, screen_palette->colors, 0, 256); SDL_Rect rect = {sx, sy, width, height}; - SDL_BlitSurface(hBmpScreen[0], &rect, text_w[index - 1].window, NULL); + SDL_BlitSurface(hBmpScreen[0], &rect, w.window, NULL); } // 画面復帰 - if(text_w[index - 1].push && text_w[index - 1].screen) { - sx = text_w[index - 1].screen_x; - sy = text_w[index - 1].screen_y; - width = text_w[index - 1].screen->w; - height = text_w[index - 1].screen->h; + if (w.save && w.screen) { + sx = w.screen_x; + sy = w.screen_y; + width = w.screen->w; + height = w.screen->h; - SDL_SetSurfacePalette(hBmpScreen[0], text_w[index - 1].screen->format->palette); + SDL_SetSurfacePalette(hBmpScreen[0], w.screen->format->palette); SDL_Rect rect = {sx, sy, width, height}; - SDL_BlitSurface(text_w[index - 1].screen, NULL, hBmpScreen[0], &rect); + SDL_BlitSurface(w.screen, NULL, hBmpScreen[0], &rect); draw_screen(sx, sy, width, height); SDL_SetSurfacePalette(hBmpScreen[0], screen_palette); } // テキスト描画位置更新 if(update) { - text_dest_x = text_w[index - 1].sx; - text_dest_y = text_w[index - 1].sy + text_space;; + text_dest_x = w.sx; + text_dest_y = w.sy + text_space;; text_font_maxsize = 0; } } +void AGS::set_text_window(int index, int sx, int sy, int ex, int ey, bool save) +{ + Window& w = text_w[index - 1]; + w.clear_saved(); + w.sx = sx; + w.sy = sy; + w.ex = ex; + w.ey = ey; + w.save = save; +} + void AGS::clear_menu_window() { SDL_Rect rect = {0, 0, 640, 480}; @@ -174,36 +287,37 @@ void AGS::clear_menu_window() void AGS::open_menu_window(int index) { - int sx = menu_w[index - 1].sx; - int sy = menu_w[index - 1].sy; - int ex = menu_w[index - 1].ex; - int ey = menu_fix ? menu_w[index - 1].ey : sy + menu_dest_y - 1; + Window &w = menu_w[index - 1]; + int sx = w.sx; + int sy = w.sy; + int ex = w.ex; + int ey = menu_fix ? w.ey : sy + menu_dest_y - 1; int width = ex - sx + 1; int height = ey - sy + 1; - int wsx = sx - (menu_w[index - 1].frame ? 8 : 0); - int wsy = sy - (menu_w[index - 1].frame ? 8 : 0); - int wex = ex + (menu_w[index - 1].frame ? 8 : 0); - int wey = ey + (menu_w[index - 1].frame ? 8 : 0); + int wsx = sx - (w.frame ? 8 : 0); + int wsy = sy - (w.frame ? 8 : 0); + int wex = ex + (w.frame ? 8 : 0); + int wey = ey + (w.frame ? 8 : 0); int wwidth = wex - wsx + 1; int wheight = wey - wsy + 1; // 画面退避 - if(menu_w[index - 1].push) { - if(menu_w[index - 1].screen) { - SDL_FreeSurface(menu_w[index - 1].screen); + if (w.save) { + if (w.screen) { + SDL_FreeSurface(w.screen); } - menu_w[index - 1].screen = SDL_CreateRGBSurfaceWithFormat(0, wwidth, wheight, 8, SDL_PIXELFORMAT_INDEX8); - menu_w[index - 1].screen_x = wsx; - menu_w[index - 1].screen_y = wsy; - SDL_SetPaletteColors(menu_w[index - 1].screen->format->palette, screen_palette->colors, 0, 256); + w.screen = SDL_CreateRGBSurfaceWithFormat(0, wwidth, wheight, 8, SDL_PIXELFORMAT_INDEX8); + w.screen_x = wsx; + w.screen_y = wsy; + SDL_SetPaletteColors(w.screen->format->palette, screen_palette->colors, 0, 256); SDL_Rect rect = {wsx, wsy, wwidth, wheight}; - SDL_BlitSurface(hBmpScreen[0], &rect, menu_w[index - 1].screen, NULL); + SDL_BlitSurface(hBmpScreen[0], &rect, w.screen, NULL); } // メニュー表示 - draw_window(wsx, wsy, wex, wey, menu_w[index - 1].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); @@ -213,10 +327,11 @@ void AGS::open_menu_window(int index) void AGS::redraw_menu_window(int index, int selected) { - int sx = menu_w[index - 1].sx; - int sy = menu_w[index - 1].sy; - int ex = menu_w[index - 1].ex; - int ey = menu_fix ? menu_w[index - 1].ey : sy + menu_dest_y - 1; + Window &w = menu_w[index - 1]; + int sx = w.sx; + int sy = w.sy; + int ex = w.ex; + int ey = menu_fix ? w.ey : sy + menu_dest_y - 1; int width = ex - sx + 1; int height = ey - sy + 1; @@ -229,35 +344,50 @@ void AGS::redraw_menu_window(int index, int selected) void AGS::close_menu_window(int index) { + Window &w = menu_w[index - 1]; // 画面復帰 - if(menu_w[index - 1].push && menu_w[index - 1].screen) { - int sx = menu_w[index - 1].screen_x; - int sy = menu_w[index - 1].screen_y; - int width = menu_w[index - 1].screen->w; - int height = menu_w[index - 1].screen->h; - - SDL_SetSurfacePalette(hBmpScreen[0], menu_w[index - 1].screen->format->palette); - SDL_Rect rect = {sx, sy, width, height}; - SDL_BlitSurface(menu_w[index - 1].screen, NULL, hBmpScreen[0], &rect); - draw_screen(sx, sy, width, height); + if (w.save && w.screen) { + SDL_SetSurfacePalette(hBmpScreen[0], w.screen->format->palette); + SDL_Rect rect = {w.screen_x, w.screen_y, w.screen->w, w.screen->h}; + SDL_BlitSurface(w.screen, NULL, hBmpScreen[0], &rect); + draw_screen(w.screen_x, w.screen_y, w.screen->w, w.screen->h); SDL_SetSurfacePalette(hBmpScreen[0], screen_palette); } } +void AGS::get_menu_window_rect(int index, int* sx, int* sy, int* ex, int* ey) +{ + Window &w = menu_w[index - 1]; + if (sx) *sx = w.sx; + if (sy) *sy = w.sy; + if (ex) *ex = w.ex; + if (ey) *ey = w.ey; +} + +void AGS::set_menu_window(int index, int sx, int sy, int ex, int ey, bool save) +{ + Window &w = menu_w[index - 1]; + w.clear_saved(); + w.sx = sx; + w.sy = sy; + w.ex = ex; + w.ey = ey; + w.save = save; +} + void AGS::draw_window(int sx, int sy, int ex, int ey, bool frame, uint8 frame_color, uint8 back_color) { SDL_Rect rect = {sx, sy, ex - sx + 1, ey - sy + 1}; SDL_FillRect(hBmpScreen[0], &rect, back_color); if(frame) { - SDL_Rect top = {sx + 1, sy + 1, ex - sx - 1, 2}; - SDL_Rect bottom = {sx + 1, ey - 2, ex - sx - 1, 2}; - SDL_Rect left = {sx + 1, sy + 1, 2, ey - sy - 1}; - SDL_Rect right = {ex - 2, sy + 1, 2, ey - sy - 1}; - SDL_FillRect(hBmpScreen[0], &top, frame_color); - SDL_FillRect(hBmpScreen[0], &bottom, frame_color); - SDL_FillRect(hBmpScreen[0], &left, frame_color); - SDL_FillRect(hBmpScreen[0], &right, frame_color); + SDL_Rect rects[] = { + {sx + 1, sy + 1, ex - sx - 1, 2}, + {sx + 1, ey - 2, ex - sx - 1, 2}, + {sx + 1, sy + 1, 2, ey - sy - 1}, + {ex - 2, sy + 1, 2, ey - sy - 1}, + }; + SDL_FillRects(hBmpScreen[0], rects, 4, frame_color); box_line(0, sx + 4, sy + 4, ex - 4, ey - 4, frame_color); } draw_screen(sx, sy, ex - sx + 1, ey - sy + 1); diff --git a/src/sys/nact.cpp b/src/sys/nact.cpp index ea63e44..8f4b396 100644 --- a/src/sys/nact.cpp +++ b/src/sys/nact.cpp @@ -634,9 +634,8 @@ int NACT::menu_select(int num_items) ags->open_menu_window(menu_window); // マウス移動 - int sx = ags->menu_w[menu_window - 1].sx; - int sy = ags->menu_w[menu_window - 1].sy; - int ex = ags->menu_w[menu_window - 1].ex; + int sx, sy, ex; + 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; diff --git a/src/sys/nact_sys2.cpp b/src/sys/nact_sys2.cpp index a9c9d68..588dc6f 100644 --- a/src/sys/nact_sys2.cpp +++ b/src/sys/nact_sys2.cpp @@ -358,45 +358,20 @@ void NACT_Sys2::cmd_b() if (game_id.is(GameId::AYUMI_FD) || game_id.is(GameId::AYUMI_HINT) || game_id.is(GameId::DRSTOP)) { p5 = 1; } - ags->menu_w[index - 1].sx = p1 * 8; - ags->menu_w[index - 1].sy = p2; - ags->menu_w[index - 1].ex = p3 * 8 - 1; - ags->menu_w[index - 1].ey = p4; - ags->menu_w[index - 1].push = p5 ? true : false; - - // 退避画面の破棄 - if(ags->menu_w[index - 1].screen) { - SDL_FreeSurface(ags->menu_w[index - 1].screen); - ags->menu_w[index - 1].screen = NULL; - } + ags->set_menu_window(index, p1 * 8, p2, p3 * 8 - 1, p4, p5); break; case 2: if (game_id.is(GameId::AYUMI_FD) || game_id.is(GameId::AYUMI_HINT) || game_id.is(GameId::DRSTOP)) { p1 = 1; } // if (game_id.is(GameId::PROG_FD)) { -// ags->menu_w[index - 1].frame = (index == 1 || index == 3) ? true : false; -// } else - ags->menu_w[index - 1].frame = p1 ? true : false; +// p1 = (index == 1 || index == 3); +// } + ags->set_menu_window_frame(index, p1); menu_window = index; break; case 3: - ags->text_w[index - 1].sx = p1 * 8; - ags->text_w[index - 1].sy = p2; - ags->text_w[index - 1].ex = p3 * 8 - 1; - ags->text_w[index - 1].ey = p4; - ags->text_w[index - 1].push = p5 ? true : false; - - // 退避画面の破棄 - if(ags->text_w[index - 1].screen) { - SDL_FreeSurface(ags->text_w[index - 1].screen); - ags->text_w[index - 1].screen = NULL; - } - // 退避窓の破棄 - if(ags->text_w[index - 1].window) { - SDL_FreeSurface(ags->text_w[index - 1].window); - ags->text_w[index - 1].window = NULL; - } + ags->set_text_window(index, p1 * 8, p2, p3 * 8 - 1, p4, p5); break; case 4: if (game_id.is(GameId::AYUMI_FD) || game_id.is(GameId::AYUMI_HINT)) { @@ -409,9 +384,9 @@ void NACT_Sys2::cmd_b() if(p5 == 0) { // ウィンドウ退避 // if (game_id.is(GameId::PROG_FD)) { -// ags->text_w[index - 1].frame = (index == 1 || index == 3) ? true : false; +// p1 = (index == 1 || index == 3); // } else - ags->text_w[index - 1].frame = p1 ? true : false; + ags->set_text_window_frame(index, p1); ags->open_text_window(index, p4 ? false : true); text_window = index; } else { diff --git a/src/sys/nact_sys3.cpp b/src/sys/nact_sys3.cpp index 8d47586..9331ad9 100644 --- a/src/sys/nact_sys3.cpp +++ b/src/sys/nact_sys3.cpp @@ -255,51 +255,19 @@ void NACT_Sys3::cmd_b() if (game_id.is(GameId::AYUMI_CD) || game_id.is(GameId::AYUMI_LIVE_256) || game_id.is(GameId::AYUMI_LIVE_FULL)) { p5 = 1; } - ags->menu_w[index - 1].sx = column ? p1 * 8 : p1 & 0xfff8; - ags->menu_w[index - 1].sy = p2; - ags->menu_w[index - 1].ex = column ? p3 * 8 - 1 : (p3 & 0xfff8) - 1; - ags->menu_w[index - 1].ey = p4; - ags->menu_w[index - 1].push = p5 ? true : false; - - // 退避画面の破棄 - if(ags->menu_w[index - 1].screen) { - SDL_FreeSurface(ags->menu_w[index - 1].screen); - ags->menu_w[index - 1].screen = NULL; - } + ags->set_menu_window(index, column ? p1 * 8 : p1 & 0xfff8, p2, column ? p3 * 8 - 1 : (p3 & 0xfff8) - 1, p4, p5); break; case 2: - ags->menu_w[index - 1].frame = p1 ? true : false; + ags->set_menu_window_frame(index, p1); menu_window = index; break; case 3: - ags->text_w[index - 1].sx = column ? p1 * 8 : p1 & 0xfff8; - ags->text_w[index - 1].sy = p2; - ags->text_w[index - 1].ex = column ? p3 * 8 - 1 : (p3 & 0xfff8) - 1; - ags->text_w[index - 1].ey = p4; - ags->text_w[index - 1].push = p5 ? true : false; - - // 退避画面の破棄 - if(ags->text_w[index - 1].screen) { - SDL_FreeSurface(ags->text_w[index - 1].screen); - ags->text_w[index - 1].screen = NULL; - } - // 退避窓の破棄 - if(ags->text_w[index - 1].window) { - SDL_FreeSurface(ags->text_w[index - 1].window); - ags->text_w[index - 1].window = NULL; - } + ags->set_text_window(index, column ? p1 * 8 : p1 & 0xfff8, p2, column ? p3 * 8 - 1 : (p3 & 0xfff8) - 1, p4, p5); break; case 4: if(p5 == 0) { // ウィンドウ退避 - if (game_id.is(GameId::PROG_CD) && p4) { - // prostudent G オープニング画面化け対策 - if(ags->text_w[index - 1].window) { - SDL_FreeSurface(ags->text_w[index - 1].window); - ags->text_w[index - 1].window = NULL; - } - } - ags->text_w[index - 1].frame = p1 ? true : false; + ags->set_text_window_frame(index, p1); ags->open_text_window(index, p4 ? false : true); text_window = index; } else {