diff --git a/src/game/console_cmd.c b/src/game/console_cmd.c index 1e640ab13..a85ea53cc 100644 --- a/src/game/console_cmd.c +++ b/src/game/console_cmd.c @@ -709,7 +709,7 @@ static COMMAND_RESULT Console_Cmd_LoadGame(const char *args) return CR_FAILURE; } - if (g_SavegameRequester.is_item_blocked[slot_idx]) { + if (g_SavegameRequester.items[slot_idx].is_blocked) { Console_Log(GS(OSD_LOAD_GAME_FAIL_UNAVAILABLE_SLOT), slot_num); return CR_FAILURE; } diff --git a/src/game/option/option_passport.c b/src/game/option/option_passport.c index eaf07d43e..fb3f86192 100644 --- a/src/game/option/option_passport.c +++ b/src/game/option/option_passport.c @@ -58,12 +58,10 @@ static REQUEST_INFO m_NewGameRequester = { .pix_width = 162, .line_height = TEXT_HEIGHT + 7, .is_blockable = false, - .is_item_blocked = NULL, .x = 0, .y = 0, .heading_text = NULL, - .item_texts = NULL, - 0, + .items = NULL, }; static REQUEST_INFO m_SelectLevelRequester = { @@ -76,12 +74,10 @@ static REQUEST_INFO m_SelectLevelRequester = { .pix_width = 292, .line_height = TEXT_HEIGHT + 7, .is_blockable = false, - .is_item_blocked = NULL, .x = 0, .y = -32, .heading_text = NULL, - .item_texts = NULL, - 0, + .items = NULL, }; REQUEST_INFO g_SavegameRequester = { @@ -94,12 +90,10 @@ REQUEST_INFO g_SavegameRequester = { .pix_width = 292, .line_height = TEXT_HEIGHT + 7, .is_blockable = false, - .is_item_blocked = NULL, .x = 0, .y = -32, .heading_text = NULL, - .item_texts = NULL, - 0, + .items = NULL, }; static void Option_PassportInitText(void); @@ -409,7 +403,7 @@ static void Option_PassportLoadGame(void) m_PassportStatus.mode = PASSPORT_MODE_LOAD_GAME; } } else if (m_PassportStatus.mode == PASSPORT_MODE_LOAD_GAME) { - if (!g_SavegameRequester.is_item_blocked[g_SavegameRequester.requested] + if (!g_SavegameRequester.items[g_SavegameRequester.requested].is_blocked || !g_SavegameRequester.is_blockable) { if (g_InputDB.menu_right) { g_GameInfo.current_save_slot = g_SavegameRequester.requested; @@ -426,10 +420,10 @@ static void Option_PassportLoadGame(void) Text_SetPos( m_Text[TEXT_LEVEL_ARROW_RIGHT], 130, g_SavegameRequester - .texts + .items [g_SavegameRequester.requested - g_SavegameRequester.line_offset] - ->pos.y); + .content->pos.y); Text_Hide(m_Text[TEXT_LEVEL_ARROW_RIGHT], false); } else { Text_Hide(m_Text[TEXT_LEVEL_ARROW_RIGHT], true); @@ -440,7 +434,7 @@ static void Option_PassportLoadGame(void) Text_Hide(m_Text[TEXT_LEVEL_ARROW_RIGHT], true); } - if (g_SavegameRequester.is_item_blocked[g_SavegameRequester.requested] + if (g_SavegameRequester.items[g_SavegameRequester.requested].is_blocked && g_SavegameRequester.is_blockable) { Text_Hide(m_Text[TEXT_LEVEL_ARROW_RIGHT], true); } @@ -465,10 +459,10 @@ static void Option_PassportSelectLevel(void) Text_SetPos( m_Text[TEXT_LEVEL_ARROW_LEFT], -130, m_SelectLevelRequester - .texts + .items [m_SelectLevelRequester.requested - m_SelectLevelRequester.line_offset] - ->pos.y); + .content->pos.y); Text_Hide(m_Text[TEXT_LEVEL_ARROW_LEFT], false); } else { Text_Hide(m_Text[TEXT_LEVEL_ARROW_LEFT], true); diff --git a/src/game/phase/phase_pause.c b/src/game/phase/phase_pause.c index f3549adb3..eab8a8224 100644 --- a/src/game/phase/phase_pause.c +++ b/src/game/phase/phase_pause.c @@ -44,12 +44,10 @@ static REQUEST_INFO m_PauseRequester = { .pix_width = 160, .line_height = TEXT_HEIGHT + 7, .is_blockable = false, - .is_item_blocked = NULL, .x = 0, .y = 0, .heading_text = NULL, - .item_texts = NULL, - 0, + .items = NULL, }; static void Phase_Pause_RemoveText(void); diff --git a/src/game/requester.c b/src/game/requester.c index 929733c7d..5cf661951 100644 --- a/src/game/requester.c +++ b/src/game/requester.c @@ -24,24 +24,23 @@ static void Requester_SetItem( REQUEST_INFO *req, const int32_t idx, const bool is_blocked, const char *const fmt, va_list va) { - if (req->item_texts[idx]) { - Memory_FreePointer(&req->item_texts[idx]); + if (req->items[idx].content_text) { + Memory_FreePointer(&req->items[idx].content_text); } va_list va_dup; va_copy(va_dup, va); const size_t out_size = vsnprintf(NULL, 0, fmt, va) + 1; - req->item_texts[idx] = Memory_Alloc(sizeof(char) * out_size); - vsnprintf(req->item_texts[idx], out_size, fmt, va_dup); - req->is_item_blocked[idx] = is_blocked; + req->items[idx].content_text = Memory_Alloc(sizeof(char) * out_size); + vsnprintf(req->items[idx].content_text, out_size, fmt, va_dup); + req->items[idx].is_blocked = is_blocked; va_end(va_dup); } void Requester_Init(REQUEST_INFO *req, const uint16_t max_items) { req->max_items = max_items; - req->is_item_blocked = Memory_Alloc(sizeof(bool) * max_items); - req->item_texts = Memory_Alloc(sizeof(char *) * max_items); + req->items = Memory_Alloc(sizeof(REQUESTER_ITEM) * max_items); Requester_ClearTextstrings(req); } @@ -50,11 +49,10 @@ void Requester_Shutdown(REQUEST_INFO *req) Requester_ClearTextstrings(req); Memory_FreePointer(&req->heading_text); - Memory_FreePointer(&req->is_item_blocked); for (int i = 0; i < req->max_items; i++) { - Memory_FreePointer(&req->item_texts[i]); + Memory_FreePointer(&req->items[i].content_text); } - Memory_FreePointer(&req->item_texts); + Memory_FreePointer(&req->items); } void Requester_ClearTextstrings(REQUEST_INFO *req) @@ -68,9 +66,9 @@ void Requester_ClearTextstrings(REQUEST_INFO *req) Text_Remove(req->moredown); req->moredown = NULL; - for (int i = 0; i < MAX_REQLINES; i++) { - Text_Remove(req->texts[i]); - req->texts[i] = NULL; + for (int i = 0; i < req->max_items; i++) { + Text_Remove(req->items[i].content); + req->items[i].content = NULL; } req->items_used = 0; @@ -157,35 +155,38 @@ int32_t Requester_Display(REQUEST_INFO *req) } for (int i = 0; i < line_qty; i++) { - if (!req->texts[i]) { - req->texts[i] = Text_Create( + if (!req->items[i].content) { + req->items[i].content = Text_Create( 0, line_one_off + req->line_height * i, - req->item_texts[req->line_offset + i]); - Text_CentreH(req->texts[i], 1); - Text_AlignBottom(req->texts[i], 1); + req->items[req->line_offset + i].content_text); + Text_CentreH(req->items[i].content, 1); + Text_AlignBottom(req->items[i].content, 1); } if (req->line_offset + i == req->requested) { Text_AddBackground( - req->texts[i], req->pix_width - BOX_PADDING - 1 * BOX_BORDER, 0, - 0, 0, TS_REQUESTED); - Text_AddOutline(req->texts[i], true, TS_REQUESTED); + req->items[i].content, + req->pix_width - BOX_PADDING - 1 * BOX_BORDER, 0, 0, 0, + TS_REQUESTED); + Text_AddOutline(req->items[i].content, true, TS_REQUESTED); } else { - Text_RemoveBackground(req->texts[i]); - Text_RemoveOutline(req->texts[i]); + Text_RemoveBackground(req->items[i].content); + Text_RemoveOutline(req->items[i].content); } } if (req->line_offset != req->line_old_offset) { for (int i = 0; i < line_qty; i++) { - if (req->texts[i]) { + if (req->items[i].content) { Text_ChangeText( - req->texts[i], req->item_texts[req->line_offset + i]); + req->items[i].content, + req->items[req->line_offset + i].content_text); + ; } } } if (g_InputDB.menu_confirm) { - if (req->is_item_blocked[req->requested] && req->is_blockable) { + if (req->is_blockable && req->items[req->requested].is_blocked) { g_Input = (INPUT_STATE) { 0 }; return 0; } else { diff --git a/src/global/types.h b/src/global/types.h index 1de52f830..bad5a0d9e 100644 --- a/src/global/types.h +++ b/src/global/types.h @@ -1822,6 +1822,12 @@ typedef struct BOX_INFO { int16_t overlap_index; } BOX_INFO; +typedef struct { + bool is_blocked; + char *content_text; + TEXTSTRING *content; +} REQUESTER_ITEM; + typedef struct REQUEST_INFO { uint16_t items_used; uint16_t max_items; @@ -1832,16 +1838,14 @@ typedef struct REQUEST_INFO { uint16_t pix_width; uint16_t line_height; bool is_blockable; - bool *is_item_blocked; int16_t x; int16_t y; char *heading_text; - char **item_texts; TEXTSTRING *heading; TEXTSTRING *background; TEXTSTRING *moreup; TEXTSTRING *moredown; - TEXTSTRING *texts[MAX_REQLINES]; + REQUESTER_ITEM *items; } REQUEST_INFO; typedef struct IMOTION_INFO {