Skip to content

Commit

Permalink
port Requester_Display
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Sep 5, 2024
1 parent 99f60e7 commit 9e8c9d5
Show file tree
Hide file tree
Showing 7 changed files with 288 additions and 10 deletions.
16 changes: 8 additions & 8 deletions docs/progress.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion docs/progress.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3242,7 +3242,7 @@ typedef enum {
0x004256E0 0x001B + void __cdecl Requester_Item_CenterAlign(REQUEST_INFO *req, TEXTSTRING *txt);
0x00425700 0x0054 + void __cdecl Requester_Item_LeftAlign(REQUEST_INFO *req, TEXTSTRING *txt);
0x00425760 0x0056 + void __cdecl Requester_Item_RightAlign(REQUEST_INFO *req, TEXTSTRING *txt);
0x004257C0 0x0866 - int32_t __cdecl Requester_Display(REQUEST_INFO *req, int32_t des, int32_t backgrounds);
0x004257C0 0x0866 + int32_t __cdecl Requester_Display(REQUEST_INFO *req, int32_t des, int32_t backgrounds);
0x00426030 0x00AA + void __cdecl Requester_SetHeading(REQUEST_INFO *req, char *text1, uint32_t flags1, char *text2, uint32_t flags2);
0x004260E0 0x0013 + void __cdecl Requester_RemoveAllItems(REQUEST_INFO *req);
0x00426100 0x00C0 + void __cdecl Requester_ChangeItem(REQUEST_INFO *req, int32_t item, const char *text1, uint32_t flags1, const char *text2, uint32_t flags2);
Expand Down Expand Up @@ -4671,3 +4671,9 @@ typedef enum {
0x0051A24C + int32_t g_KeySelector;
0x0051A248 + int32_t g_KeyCursor;
0x00466FA8 - const char *g_KeyNames[];
0x00464500 - const uint16_t g_Requester_BackgroundGour1[];
0x00464520 - const uint16_t g_Requester_BackgroundGour2[];
0x00464538 - const uint16_t g_Requester_MainGour1[];
0x00464558 - const uint16_t g_Requester_MainGour2[];
0x00464590 - const uint16_t g_Requester_SelectionGour2[];
0x004645A8 - const uint16_t g_Requester_UnselectionGour1[];
264 changes: 264 additions & 0 deletions src/game/requester.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,270 @@ void __cdecl Requester_Shutdown(REQUEST_INFO *const req)
req->ready = 0;
}

int32_t __cdecl Requester_Display(
REQUEST_INFO *const req, const bool destroy, const bool backgrounds)
{
int32_t line_qty = req->visible_count;
const int32_t lines_height = line_qty * req->line_height + 10;
const int32_t line_one_off = req->y_pos - lines_height;

const uint32_t render_width = GetRenderWidth();
const uint32_t render_height = GetRenderHeight();
if (render_width != req->render_width
|| render_height != req->render_height) {
Requester_Shutdown(req);
req->render_width = render_width;
req->render_height = render_height;
}

req->pitem_flags1 = g_RequesterFlags1;
req->pitem_flags2 = g_RequesterFlags2;
if (req->items_count < req->visible_count) {
line_qty = req->items_count;
}

/* heading */
if (req->heading_flags1 & REQ_USE) {
if (req->heading_text1 == NULL) {
req->heading_text1 = Text_Create(
req->x_pos, line_one_off - req->line_height - 10, req->z_pos,
req->heading_string1);
Text_CentreH(req->heading_text1, true);
Text_AlignBottom(req->heading_text1, true);
if (backgrounds) {
Text_AddBackground(
req->heading_text1, req->pix_width - 4, 0, 0, 0, 8, 0,
g_Requester_MainGour1, 2u);
Text_AddOutline(
req->heading_text1, 1, 4, g_Requester_MainGour2, 0);
}
}

if (req->heading_flags1 & REQ_ALIGN_LEFT) {
Requester_Item_LeftAlign(req, req->heading_text1);
}
if (req->heading_flags1 & REQ_ALIGN_RIGHT) {
Requester_Item_RightAlign(req, req->heading_text1);
}
}

/* heading 2 */
if (req->heading_flags2 & REQ_USE) {
if (req->heading_text2) {
} else {
req->heading_text2 = Text_Create(
req->x_pos, line_one_off - req->line_height - 10, req->z_pos,
req->heading_string2);
Text_CentreH(req->heading_text2, true);
Text_AlignBottom(req->heading_text2, true);
if (backgrounds) {
Text_AddBackground(
req->heading_text2, req->pix_width - 4, 0, 0, 0, 8, 0,
g_Requester_MainGour1, 2u);
Text_AddOutline(
req->heading_text2, 1, 4, g_Requester_MainGour2, 0);
}
}

if (req->heading_flags2 & REQ_ALIGN_LEFT) {
Requester_Item_LeftAlign(req, req->heading_text2);
}

if (req->heading_flags2 & REQ_ALIGN_RIGHT) {
Requester_Item_RightAlign(req, req->heading_text2);
}
}

/* background */
if (backgrounds && !req->background_text
&& (req->background_flags & 1) != 0) {
req->background_text = Text_Create(
req->x_pos, line_one_off - req->line_height - 12, 0, " ");
Text_CentreH(req->background_text, true);
Text_AlignBottom(req->background_text, true);
Text_AddBackground(
req->background_text, req->pix_width,
req->line_height + lines_height + 12, 0, 0, 48, 0,
g_Requester_BackgroundGour1, 1u);
Text_AddOutline(
req->background_text, 1, 15, g_Requester_BackgroundGour2, 0);
}

/* arrows */
if (req->line_offset) {
if (!req->moreup_text && (req->moreup_flags & 1) != 0) {
Text_CentreH(req->moreup_text, true);
Text_AlignBottom(req->moreup_text, true);
}
} else {
Text_Remove(req->moreup_text);
req->moreup_text = NULL;
}

if (req->items_count <= req->visible_count + req->line_offset) {
Text_Remove(req->moredown_text);
req->moredown_text = NULL;
} else if (!req->moredown_text && (req->moredown_flags & 1) != 0) {
Text_CentreH(req->moredown_text, true);
Text_AlignBottom(req->moredown_text, true);
}

/* item texts */
for (int32_t i = 0; i < line_qty; i++) {
const int32_t n = i + req->line_offset;

TEXTSTRING **const text1 = &req->item_texts1[i];
if (req->pitem_flags1[n] & REQ_USE) {
if (*text1 == NULL) {
*text1 = Text_Create(
0, line_one_off + req->line_height * i, 0,
&req->pitem_strings1[n * req->item_string_len]);
Text_CentreH(*text1, true);
Text_AlignBottom(*text1, true);
}
if (req->no_selector || n != req->selected) {
Text_RemoveBackground(*text1);
Text_RemoveOutline(*text1);
} else {
Text_AddBackground(
*text1, req->pix_width - 12, 0, 0, 0, 16, 0,
g_Requester_UnselectionGour1, 1u);
Text_AddOutline(*text1, 1, 4, g_Requester_SelectionGour2, 0);
}

if (req->pitem_flags1[n] & REQ_ALIGN_LEFT) {
Requester_Item_LeftAlign(req, *text1);
} else if (req->pitem_flags1[n] & REQ_ALIGN_RIGHT) {
Requester_Item_RightAlign(req, *text1);
} else {
Requester_Item_CenterAlign(req, *text1);
}
} else {
Text_Remove(*text1);
Text_RemoveBackground(*text1);
Text_RemoveOutline(*text1);
*text1 = NULL;
}

TEXTSTRING **const text2 = &req->item_texts2[i];
if (req->pitem_flags2[n] & REQ_USE) {
if (*text2 == NULL) {
*text2 = Text_Create(
0, line_one_off + req->line_height * i, 0,
&req->pitem_strings2[n * req->item_string_len]);
Text_CentreH(*text2, true);
Text_AlignBottom(*text2, true);
}
if (req->pitem_flags2[n] & REQ_ALIGN_LEFT) {
Requester_Item_LeftAlign(req, *text2);
} else if (req->pitem_flags2[n] & REQ_ALIGN_RIGHT) {
Requester_Item_RightAlign(req, *text2);
} else {
Requester_Item_CenterAlign(req, *text2);
}
} else {
Text_Remove(*text2);
Text_RemoveBackground(*text2);
Text_RemoveOutline(*text2);
*text2 = NULL;
}
}

if (req->line_offset != req->line_old_offset) {
for (int32_t i = 0; i < line_qty; i++) {
const int32_t n = req->line_offset + i;

TEXTSTRING **text1 = &req->item_texts1[i];
if (*text1 != NULL && (req->pitem_flags1[n] & REQ_USE)) {
Text_ChangeText(
*text1, &req->pitem_strings1[n * req->item_string_len]);
}
if (req->pitem_flags1[n] & REQ_ALIGN_LEFT) {
Requester_Item_LeftAlign(req, *text1);
} else if (req->pitem_flags1[n] & REQ_ALIGN_RIGHT) {
Requester_Item_RightAlign(req, *text1);
} else {
Requester_Item_CenterAlign(req, *text1);
}

TEXTSTRING **text2 = &req->item_texts2[i];
if (*text2 != NULL && (req->pitem_flags2[n] & REQ_USE)) {
Text_ChangeText(
*text2, &req->pitem_strings2[n * req->item_string_len]);
}
if (req->pitem_flags2[n] & REQ_ALIGN_LEFT) {
Requester_Item_LeftAlign(req, *text2);
} else if (req->pitem_flags2[n] & REQ_ALIGN_RIGHT) {
Requester_Item_RightAlign(req, *text2);
} else {
Requester_Item_CenterAlign(req, *text2);
}
}
}

if (g_InputDB & IN_BACK) {
if (req->no_selector) {
req->line_old_offset = req->line_offset;
if (req->visible_count + req->line_offset < req->items_count) {
req->line_offset++;
return 0;
}
} else {
if (req->selected < req->items_count - 1) {
req->selected++;
}
req->line_old_offset = req->line_offset;
if (req->selected > req->line_offset + req->visible_count - 1) {
req->line_offset++;
return 0;
}
}
return 0;
}

if (g_InputDB & IN_FORWARD) {
if (req->no_selector) {
req->line_old_offset = req->line_offset;
if (req->line_offset > 0) {
req->line_offset--;
return 0;
}
} else {
if (req->selected > 0) {
req->selected--;
}
req->line_old_offset = req->line_offset;
if (req->selected < req->line_offset) {
req->line_offset--;
return 0;
}
}
return 0;
}

if (!(g_InputDB & IN_SELECT)) {
if ((g_InputDB & IN_DESELECT) && destroy) {
Requester_Shutdown(req);
return -1;
}
return 0;
}

// TODO: WTF!?
if (!strncmp(
req->item_texts1[req->selected - req->line_offset]->text,
g_GF_PCStrings[GF_S_PC_EMPTY_SLOT], 12)
&& !strcmp(
g_PasswordText1->text,
g_GF_GameStrings[GF_S_GAME_PASSPORT_LOAD_GAME])) {
g_Input = 0;
return 0;
}

Requester_Shutdown(req);
return req->selected + 1;
}

void __cdecl Requester_RemoveAllItems(REQUEST_INFO *const req)
{
req->items_count = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/game/requester.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

void __cdecl Requester_Init(REQUEST_INFO *req);
void __cdecl Requester_Shutdown(REQUEST_INFO *req);
int32_t __cdecl Requester_Display(
REQUEST_INFO *req, bool destroy, bool backgrounds);
void __cdecl Requester_RemoveAllItems(REQUEST_INFO *req);
void __cdecl Requester_Item_CenterAlign(REQUEST_INFO *req, TEXTSTRING *text);
void __cdecl Requester_Item_LeftAlign(REQUEST_INFO *req, TEXTSTRING *text);
Expand Down
1 change: 0 additions & 1 deletion src/global/funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@
#define Inv_Ring_MotionCameraPitch ((void __cdecl (*)(RING_INFO *ring, int16_t target))0x004254B0)
#define Inv_Ring_MotionItemSelect ((void __cdecl (*)(RING_INFO *ring, INVENTORY_ITEM *inv_item))0x004254D0)
#define Inv_Ring_MotionItemDeselect ((void __cdecl (*)(RING_INFO *ring, INVENTORY_ITEM *inv_item))0x00425530)
#define Requester_Display ((int32_t __cdecl (*)(REQUEST_INFO *req, int32_t des, int32_t backgrounds))0x004257C0)
#define AddAssaultTime ((int32_t __cdecl (*)(uint32_t time))0x004262B0)
#define HarpoonBolt_Control ((void __cdecl (*)(int16_t item_num))0x0042C0F0)
#define Rocket_Control ((void __cdecl (*)(int16_t item_num))0x0042C530)
Expand Down
6 changes: 6 additions & 0 deletions src/global/vars_decomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
#define g_CineTargetAngle (*(int16_t*)0x00464310) // = 0x4000
#define g_OverlayStatus (*(int32_t*)0x004644E0) // = 1
#define g_Inv_NFrames (*(int32_t*)0x004644F8)
#define g_Requester_BackgroundGour1 (*(const uint16_t(*)[])0x00464500)
#define g_Requester_BackgroundGour2 (*(const uint16_t(*)[])0x00464520)
#define g_Requester_MainGour1 (*(const uint16_t(*)[])0x00464538)
#define g_Requester_MainGour2 (*(const uint16_t(*)[])0x00464558)
#define g_Requester_SelectionGour2 (*(const uint16_t(*)[])0x00464590)
#define g_Requester_UnselectionGour1 (*(const uint16_t(*)[])0x004645A8)
#define g_Inv_Item_Stopwatch (*(INVENTORY_ITEM*)0x00464A90)
#define g_Inv_Item_Pistols (*(INVENTORY_ITEM*)0x00464AE0)
#define g_Inv_Item_Flare (*(INVENTORY_ITEM*)0x00464B30)
Expand Down
1 change: 1 addition & 0 deletions src/inject_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ static void Inject_Requester(const bool enable)
{
INJECT(enable, 0x004255A0, Requester_Init);
INJECT(enable, 0x00425630, Requester_Shutdown);
INJECT(enable, 0x004257C0, Requester_Display);
INJECT(enable, 0x004256E0, Requester_Item_CenterAlign);
INJECT(enable, 0x00425700, Requester_Item_LeftAlign);
INJECT(enable, 0x00425760, Requester_Item_RightAlign);
Expand Down

0 comments on commit 9e8c9d5

Please sign in to comment.