Allow customizing HUD aspect ratio independently from game aspect ratio

This commit is contained in:
Kiloku 2025-01-12 20:15:37 -03:00 committed by Lywx
parent 2d538fac86
commit 913fbfdd14
6 changed files with 126 additions and 39 deletions

View File

@ -119,7 +119,7 @@ Gfx sRadioDamageDL[] = {
};
void HUD_MatrixTranslateCoordLeft(f32* transX, f32* transY) {
*transX = OTRGetRectDimensionFromLeftEdgeForcedAspect(*transX, 4.0f/3) - (SCREEN_WIDTH / 2.0f);
*transX = OTRGetRectDimensionFromLeftEdgeOverride(*transX) - (SCREEN_WIDTH / 2.0f);
*transY = (SCREEN_HEIGHT / 2.0f) - *transY;
}
@ -976,9 +976,9 @@ void HUD_LivesCount2_Draw(f32 x, f32 y, s32 number) {
x2 += (2 - i) * 4;
if (gShowLevelClearStatusScreen == 0) {
x0 = OTRGetDimensionFromRightEdgeForcedAspect(x0, 4.0f/3);
x1 = OTRGetDimensionFromRightEdgeForcedAspect(x1, 4.0f/3);
x2 = OTRGetDimensionFromRightEdgeForcedAspect(x2, 4.0f/3);
x0 = OTRGetDimensionFromRightEdgeOverride(x0);
x1 = OTRGetDimensionFromRightEdgeOverride(x1);
x2 = OTRGetDimensionFromRightEdgeOverride(x2);
}
Lib_TextureRect_CI4(&gMasterDisp, sLivesCounterTexs[form], sLivesCounterTLUTs[form], 16, 16, x0, y0, 1.0f, 1.0f);
@ -1236,7 +1236,7 @@ void HUD_LevelClearStatusScreen_Draw(void) {
RCP_SetupDL(&gMasterDisp, SETUPDL_76_POINT);
gDPSetPrimColor(gMasterDisp++, 0, 0, 90, 160, 200, 255);
HUD_Number_Draw(OTRGetRectDimensionFromLeftEdgeForcedAspect(24.0f, 4.0f/3), 30.0f + 3.0f, D_801617C0[5], 1.0f, false, 999);
HUD_Number_Draw(OTRGetRectDimensionFromLeftEdgeOverride(24.0f), 30.0f + 3.0f, D_801617C0[5], 1.0f, false, 999);
gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 255, 255);
Lib_TextureRect_IA8(&gMasterDisp, aTextEnemiesDown, 64, 25, x0, y0 + 4.0f, 1.0f, 1.0f);
@ -1498,8 +1498,8 @@ void HUD_PauseScreen_Update(void) {
sPauseScreenTimer[0] = 0;
case 3:
Graphics_FillRectangle(&gMasterDisp, OTRGetRectDimensionFromLeftEdgeForcedAspect(0, 4.0f/3), 0,
OTRGetDimensionFromRightEdgeForcedAspect(SCREEN_WIDTH, 4.0f/3), SCREEN_HEIGHT, 0, 0, 0, 255);
Graphics_FillRectangle(&gMasterDisp, OTRGetRectDimensionFromLeftEdgeOverride(0), 0,
OTRGetDimensionFromRightEdgeOverride(SCREEN_WIDTH), SCREEN_HEIGHT, 0, 0, 0, 255);
gFillScreenAlphaTarget = 0;
@ -1548,8 +1548,8 @@ void HUD_PauseScreen_Update(void) {
break;
case 4:
Graphics_FillRectangle(&gMasterDisp, OTRGetRectDimensionFromLeftEdgeForcedAspect(0, 4.0f/3), 0,
OTRGetDimensionFromRightEdgeForcedAspect(SCREEN_WIDTH, 4.0f/3), SCREEN_HEIGHT, 0, 0, 0, 255);
Graphics_FillRectangle(&gMasterDisp, OTRGetRectDimensionFromLeftEdgeOverride(0), 0,
OTRGetDimensionFromRightEdgeOverride(SCREEN_WIDTH), SCREEN_HEIGHT, 0, 0, 0, 255);
if (sPauseScreenTimer[0] < 140) {
break;
}
@ -1567,8 +1567,8 @@ void HUD_PauseScreen_Update(void) {
}
case 5:
Graphics_FillRectangle(&gMasterDisp, OTRGetRectDimensionFromLeftEdgeForcedAspect(0, 4.0f/3), 0,
OTRGetDimensionFromRightEdgeForcedAspect(SCREEN_WIDTH, 4.0f/3), SCREEN_HEIGHT, 0, 0, 0, 255);
Graphics_FillRectangle(&gMasterDisp, OTRGetRectDimensionFromLeftEdgeOverride(0), 0,
OTRGetDimensionFromRightEdgeOverride(SCREEN_WIDTH), SCREEN_HEIGHT, 0, 0, 0, 255);
for (i = 0; i < 6; i++) {
if (gPrevPlanetTeamShields[i] == -1) {
@ -2033,22 +2033,22 @@ s32 HUD_RadarMarks_Update(void) {
switch (gCurrentLevel) {
case LEVEL_CORNERIA:
gHudOffsetRect = OTRGetDimensionFromRightEdgeForcedAspect(0.0f, 4.0f/3);
gHudOffsetRect = OTRGetDimensionFromRightEdgeOverride(0.0f);
gHudOffsetPers = gHudOffsetRect * 2.15f;
break;
case LEVEL_SECTOR_Z:
gHudOffsetRect = OTRGetDimensionFromRightEdgeForcedAspect(0.0f, 4.0f/3);
gHudOffsetRect = OTRGetDimensionFromRightEdgeOverride(0.0f);
gHudOffsetPers = gHudOffsetRect * 5.50f;
break;
case LEVEL_BOLSE:
gHudOffsetRect = OTRGetDimensionFromRightEdgeForcedAspect(0.0f, 4.0f/3);
gHudOffsetRect = OTRGetDimensionFromRightEdgeOverride(0.0f);
gHudOffsetPers = gHudOffsetRect * 2.70f;
break;
default:
gHudOffsetRect = OTRGetDimensionFromRightEdgeForcedAspect(0.0f, 4.0f/3);
gHudOffsetRect = OTRGetDimensionFromRightEdgeOverride(0.0f);
gHudOffsetPers = gHudOffsetRect * 3.35f;
break;
}
@ -2250,7 +2250,7 @@ void HUD_RadioCharacterName_Draw(void) {
RCP_SetupDL(&gMasterDisp, SETUPDL_76_POINT);
gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 0, 255);
f32 xPos = OTRGetRectDimensionFromLeftEdgeForcedAspect(73.0f, 4.0f/3);
f32 xPos = OTRGetRectDimensionFromLeftEdgeOverride(73.0f);
switch ((s32) gRadioMsgRadioId) {
case RCID_FOX:
@ -2435,7 +2435,7 @@ void HUD_PlayerShieldGauge_Update(void) {
}
void HUD_PlayerShieldGauge_Draw(f32 x, f32 y) {
x = OTRGetRectDimensionFromLeftEdgeForcedAspect(x, 4.0f/3);
x = OTRGetRectDimensionFromLeftEdgeOverride(x);
RCP_SetupDL(&gMasterDisp, SETUPDL_75);
gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 255, 255);
HUD_ShieldGaugeBars_Draw(x + 7.0f, y + 2.0f, D_801617A8, 1.0f, D_801617AC);
@ -3011,16 +3011,16 @@ void HUD_BoostGauge_Draw(f32 xPos, f32 yPos) {
sp68 = 24.0f;
switch (gPlayerNum) {
case 1:
xPos = OTRGetRectDimensionFromLeftEdgeForcedAspect(xPos, 4.0f/3);
xPos = OTRGetRectDimensionFromLeftEdgeOverride(xPos);
break;
case 2:
xPos = OTRGetRectDimensionFromLeftEdgeForcedAspect(xPos, 4.0f/3);
xPos = OTRGetRectDimensionFromLeftEdgeOverride(xPos);
break;
case 3:
xPos = OTRGetDimensionFromRightEdgeForcedAspect(xPos, 4.0f/3);
xPos = OTRGetDimensionFromRightEdgeOverride(xPos);
break;
case 4:
xPos = OTRGetDimensionFromRightEdgeForcedAspect(xPos, 4.0f/3);
xPos = OTRGetDimensionFromRightEdgeOverride(xPos);
break;
}
} else {
@ -3028,7 +3028,7 @@ void HUD_BoostGauge_Draw(f32 xPos, f32 yPos) {
sp60 = 2.0f;
sp68 = 40.0f;
playerNum = 4; // index for Single Player
xPos = OTRGetDimensionFromRightEdgeForcedAspect(xPos, 4.0f/3);
xPos = OTRGetDimensionFromRightEdgeOverride(xPos);
boostGaugeXpos[playerNum] = xPos;
boostGaugeYpos[playerNum] = yPos;
}
@ -3174,14 +3174,14 @@ void HUD_DrawBossHealth(void) {
temp4 = sp3C + 6.0f;
temp5 = temp1 + 10.0f;
temp2 = OTRGetRectDimensionFromLeftEdgeForcedAspect(temp2, 4.0f/3);
temp4 = OTRGetRectDimensionFromLeftEdgeForcedAspect(temp4, 4.0f/3);
temp2 = OTRGetRectDimensionFromLeftEdgeOverride(temp2);
temp4 = OTRGetRectDimensionFromLeftEdgeOverride(temp4);
RCP_SetupDL(&gMasterDisp, SETUPDL_78_POINT);
gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 255, 255);
Lib_TextureRect_CI4(&gMasterDisp, D_1011A40, D_1011AB0, 32, 7, temp2, temp3, 1.0f, 1.0f);
f32 border = sp3C;
border = OTRGetRectDimensionFromLeftEdgeForcedAspect(border, 4.0f/3);
border = OTRGetRectDimensionFromLeftEdgeOverride(border);
RCP_SetupDL(&gMasterDisp, SETUPDL_76_POINT);
Lib_TextureRect_IA8(&gMasterDisp, D_1002040, 40, 12, border, temp1, 1.0f, 1.0f);
@ -3214,7 +3214,7 @@ void HUD_DrawBossHealth(void) {
if (D_801616C4 >= 0.88f) {
temp6 = sp3C + 8.0f;
temp7 = 101.0f - ((2200.0f / 69.0f) * D_801616C8) + temp1;
temp6 = OTRGetRectDimensionFromLeftEdgeForcedAspect(temp6, 4.0f/3);
temp6 = OTRGetRectDimensionFromLeftEdgeOverride(temp6);
if (D_801616C8 > 0.0f) {
// LTODO: FIX BOSS BAR
Lib_TextureRect_RGBA16(&gMasterDisp, D_Tex_800D99F8, 32, 32, temp6 + 0.5f, temp7, 0.2f, D_801616C8);
@ -3408,7 +3408,7 @@ void HUD_BombCounter_Draw(f32 x, f32 y) {
f32 temp_fv0;
f32 temp;
x = OTRGetDimensionFromRightEdgeForcedAspect(x, 4.0f/3);
x = OTRGetDimensionFromRightEdgeOverride(x);
// Max bombs
if (gBombCount[gPlayerNum] > 9) {
@ -5521,7 +5521,7 @@ void HUD_Score_Draw(f32 x, f32 y) {
f32 y1;
f32 xScale;
x = OTRGetRectDimensionFromLeftEdgeForcedAspect(x, 4.0f/3);
x = OTRGetRectDimensionFromLeftEdgeOverride(x);
if (gHitCount > gDisplayedHitCount) {
temp3 = gDisplayedHitCount + 1;

View File

@ -126,11 +126,11 @@ void Radio_PlayMessage(u16* msg, RadioCharacterId character) {
switch (gGameState) {
case GSTATE_TITLE:
gRadioPrintPosY = 176;
gRadioPrintPosX = OTRGetRectDimensionFromLeftEdgeForcedAspect(85.0f, 4.0f/3);
gRadioTextBoxPosX = OTRGetRectDimensionFromLeftEdgeForcedAspect(80.0f, 4.0f/3);
gRadioPrintPosX = OTRGetRectDimensionFromLeftEdgeOverride(85.0f);
gRadioTextBoxPosX = OTRGetRectDimensionFromLeftEdgeOverride(80.0f);
gRadioTextBoxPosY = 174.0f;
gRadioTextBoxScaleX = 4.63f;
gRadioPortraitPosX = OTRGetRectDimensionFromLeftEdgeForcedAspect(32.0f, 4.0f/3);
gRadioPortraitPosX = OTRGetRectDimensionFromLeftEdgeOverride(32.0f);
gRadioPortraitPosY = 174.0f;
break;
@ -146,11 +146,11 @@ void Radio_PlayMessage(u16* msg, RadioCharacterId character) {
case GSTATE_PLAY:
gRadioPrintPosY = 180;
gRadioPrintPosX = OTRGetRectDimensionFromLeftEdgeForcedAspect(79.0f, 4.0f/3);
gRadioTextBoxPosX = OTRGetRectDimensionFromLeftEdgeForcedAspect(74.0f, 4.0f/3);
gRadioPrintPosX = OTRGetRectDimensionFromLeftEdgeOverride(79.0f);
gRadioTextBoxPosX = OTRGetRectDimensionFromLeftEdgeOverride(74.0f);
gRadioTextBoxPosY = 178.0f;
gRadioTextBoxScaleX = 4.53f;
gRadioPortraitPosX = OTRGetRectDimensionFromLeftEdgeForcedAspect(26.0f, 4.0f/3);
gRadioPortraitPosX = OTRGetRectDimensionFromLeftEdgeOverride(26.0f);
gRadioPortraitPosY = 178.0f;
break;
}
@ -712,12 +712,12 @@ void Radio_Draw(void) {
(gCurrentRadioPortrait != RCID_1000)) {
RCP_SetupDL(&gMasterDisp, SETUPDL_76_POINT);
gDPSetPrimColor(gMasterDisp++, 0x00, 0x00, 255, 255, 0, 255);
Graphics_DisplaySmallText(OTRGetRectDimensionFromLeftEdgeForcedAspect(31.0f, 4.0f/3), 167, 1.0f, 1.0f, "DOWN");
Graphics_DisplaySmallText(OTRGetRectDimensionFromLeftEdgeOverride(31.0f), 167, 1.0f, 1.0f, "DOWN");
HUD_TeamDownWrench_Draw(1);
}
if (((gCurrentRadioPortrait != RCID_STATIC) && (gCurrentRadioPortrait != RCID_STATIC + 1)) &&
(gCurrentRadioPortrait != RCID_1000)) {
HUD_TeamShields_Draw(OTRGetRectDimensionFromLeftEdgeForcedAspect(22.0f, 4.0f/3), 165.0f, gTeamShields[idx]);
HUD_TeamShields_Draw(OTRGetRectDimensionFromLeftEdgeOverride(22.0f), 165.0f, gTeamShields[idx]);
}
}
@ -761,11 +761,11 @@ void Radio_Draw(void) {
(gCurrentRadioPortrait != RCID_STATIC + 1) && (gCurrentRadioPortrait != RCID_1000)) {
RCP_SetupDL(&gMasterDisp, SETUPDL_76_POINT);
gDPSetPrimColor(gMasterDisp++, 0x00, 0x00, 255, 255, 0, 255);
Graphics_DisplaySmallText(OTRGetRectDimensionFromLeftEdgeForcedAspect(31.0f, 4.0f/3), 167, 1.0f, 1.0f, "DOWN");
Graphics_DisplaySmallText(OTRGetRectDimensionFromLeftEdgeOverride(31.0f), 167, 1.0f, 1.0f, "DOWN");
}
if (((gCurrentRadioPortrait != RCID_STATIC) && (gCurrentRadioPortrait != RCID_STATIC + 1)) &&
(gCurrentRadioPortrait != RCID_1000)) {
HUD_TeamShields_Draw(OTRGetRectDimensionFromLeftEdgeForcedAspect(22.0f, 4.0f/3), 165.0f, gActors[idx].health * 2.55f);
HUD_TeamShields_Draw(OTRGetRectDimensionFromLeftEdgeOverride(22.0f), 165.0f, gActors[idx].health * 2.55f);
}
}
if (((gCurrentRadioPortrait != RCID_STATIC) && (gCurrentRadioPortrait != RCID_STATIC + 1)) &&

View File

@ -11,7 +11,7 @@ void Training_RingPassCount_Draw(void) {
if (gRingPassCount != 0) {
RCP_SetupDL(&gMasterDisp, SETUPDL_83_POINT);
gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 255, 255);
HUD_Number_Draw(OTRGetDimensionFromRightEdge(250.0f), 50.0f, gRingPassCount, 1.0f, 0, 999);
HUD_Number_Draw(OTRGetDimensionFromRightEdgeOverride(250.0f), 50.0f, gRingPassCount, 1.0f, 0, 999);
}
}

View File

@ -538,6 +538,14 @@ extern "C" float OTRGetAspectRatio() {
return gfx_current_dimensions.aspect_ratio;
}
extern "C" float OTRGetHUDAspectRatio() {
if (CVarGetInteger("gHUDAspectRatio.Enabled", 0) == 0 || CVarGetInteger("gHUDAspectRatio.X", 0) == 0 || CVarGetInteger("gHUDAspectRatio.Y", 0) == 0)
{
return OTRGetAspectRatio();
}
return ((float)CVarGetInteger("gHUDAspectRatio.X", 1) / (float)CVarGetInteger("gHUDAspectRatio.Y", 1));
}
extern "C" float OTRGetDimensionFromLeftEdge(float v) {
return (gfx_native_dimensions.width / 2 - gfx_native_dimensions.height / 2 * OTRGetAspectRatio() + (v));
}
@ -555,6 +563,15 @@ extern "C" float OTRGetDimensionFromRightEdgeForcedAspect(float v, float aspectR
return (gfx_native_dimensions.width / 2 + gfx_native_dimensions.height / 2 * (aspectRatio > 0 ? aspectRatio : OTRGetAspectRatio()) -
(gfx_native_dimensions.width - v));
}
extern "C" float OTRGetDimensionFromLeftEdgeOverride(float v) {
return OTRGetDimensionFromLeftEdgeForcedAspect(v, OTRGetHUDAspectRatio());
}
extern "C" float OTRGetDimensionFromRightEdgeOverride(float v) {
return OTRGetDimensionFromRightEdgeForcedAspect(v, OTRGetHUDAspectRatio());
}
// Gets the width of the current render target area
extern "C" uint32_t OTRGetGameRenderWidth() {
return gfx_current_dimensions.width;
@ -581,6 +598,14 @@ extern "C" int16_t OTRGetRectDimensionFromRightEdgeForcedAspect(float v, float a
return ((int) ceilf(OTRGetDimensionFromRightEdgeForcedAspect(v, aspectRatio)));
}
extern "C" int16_t OTRGetRectDimensionFromLeftEdgeOverride(float v) {
return OTRGetRectDimensionFromLeftEdgeForcedAspect(v, OTRGetHUDAspectRatio());
}
extern "C" int16_t OTRGetRectDimensionFromRightEdgeOverride(float v) {
return OTRGetRectDimensionFromRightEdgeForcedAspect(v, OTRGetHUDAspectRatio());
}
extern "C" int32_t OTRConvertHUDXToScreenX(int32_t v) {
float gameAspectRatio = gfx_current_dimensions.aspect_ratio;
int32_t gameHeight = gfx_current_dimensions.height;

View File

@ -54,6 +54,7 @@ uint8_t GameEngine_OTRSigCheck(char* imgData);
uint32_t OTRGetCurrentWidth(void);
uint32_t OTRGetCurrentHeight(void);
float OTRGetAspectRatio(void);
float OTRGetHUDAspectRatio();
int32_t OTRConvertHUDXToScreenX(int32_t v);
float OTRGetDimensionFromLeftEdge(float v);
float OTRGetDimensionFromRightEdge(float v);
@ -63,6 +64,10 @@ float OTRGetDimensionFromLeftEdgeForcedAspect(float v, float aspectRatio);
float OTRGetDimensionFromRightEdgeForcedAspect(float v, float aspectRatio);
int16_t OTRGetRectDimensionFromLeftEdgeForcedAspect(float v, float aspectRatio);
int16_t OTRGetRectDimensionFromRightEdgeForcedAspect(float v, float aspectRatio);
float OTRGetDimensionFromLeftEdgeOverride(float v);
float OTRGetDimensionFromRightEdgeOverride(float v);
int16_t OTRGetRectDimensionFromLeftEdgeOverride(float v);
int16_t OTRGetRectDimensionFromRightEdgeOverride(float v);
uint32_t OTRGetGameRenderWidth();
uint32_t OTRGetGameRenderHeight();
void* GameEngine_Malloc(size_t size);

View File

@ -440,6 +440,10 @@ void DrawGameMenu() {
}
}
static const char* hudAspects[] = {
"Native", "Custom", "Original (4:3)", "Widescreen (16:9)", "Nintendo 3DS (5:3)", "16:10 (8:5)", "Ultrawide (21:9)"
};
void DrawEnhancementsMenu() {
if (UIWidgets::BeginMenu("Enhancements")) {
@ -484,6 +488,59 @@ void DrawEnhancementsMenu() {
ImGui::EndMenu();
}
if (UIWidgets::BeginMenu("HUD")) {
if (UIWidgets::CVarCombobox("HUD Aspect Ratio", "gHUDAspectRatio.Selection", hudAspects,
{
.tooltip = "Which Aspect Ratio to use when drawing the HUD (Radar, gauges and radio messages)",
.defaultIndex = 0,
})) {
CVarSetInteger("gHUDAspectRatio.Enabled", 1);
switch (CVarGetInteger("gHUDAspectRatio.Selection", 0)) {
case 0:
CVarSetInteger("gHUDAspectRatio.Enabled", 0);
CVarSetInteger("gHUDAspectRatio.X", 0);
CVarSetInteger("gHUDAspectRatio.Y", 0);
break;
case 1:
if (CVarGetInteger("gHUDAspectRatio.X", 0) <= 0){
CVarSetInteger("gHUDAspectRatio.X", 1);
}
if (CVarGetInteger("gHUDAspectRatio.Y", 0) <= 0){
CVarSetInteger("gHUDAspectRatio.Y", 1);
}
break;
case 2:
CVarSetInteger("gHUDAspectRatio.X", 4);
CVarSetInteger("gHUDAspectRatio.Y", 3);
break;
case 3:
CVarSetInteger("gHUDAspectRatio.X", 16);
CVarSetInteger("gHUDAspectRatio.Y", 9);
break;
case 4:
CVarSetInteger("gHUDAspectRatio.X", 5);
CVarSetInteger("gHUDAspectRatio.Y", 3);
break;
case 5:
CVarSetInteger("gHUDAspectRatio.X", 8);
CVarSetInteger("gHUDAspectRatio.Y", 5);
break;
case 6:
CVarSetInteger("gHUDAspectRatio.X", 21);
CVarSetInteger("gHUDAspectRatio.Y", 9);
break;
}
}
if (CVarGetInteger("gHUDAspectRatio.Selection", 0) == 1)
{
UIWidgets::CVarSliderInt("Horizontal: %d", "gHUDAspectRatio.X", 1, 100, 1);
UIWidgets::CVarSliderInt("Vertical: %d", "gHUDAspectRatio.Y", 1, 100, 1);
}
ImGui::EndMenu();
}
ImGui::EndMenu();
}
}