Add + support for mini printf

This commit is contained in:
DizzyEggg 2025-06-10 16:43:55 +02:00
parent 20db3cf040
commit 42e2ce0b1f
6 changed files with 53 additions and 47 deletions

View File

@ -6,6 +6,15 @@
#include "pokemon.h"
#include "structs/str_status_text.h"
enum
{
BUFFER_MOVE_JUST_NAME,
BUFFER_MOVE_SET_ICON_POSITIONED_PP_UNUSED, // Uses different formatting - unused
BUFFER_MOVE_SET_ICON_POSITIONED_PP,
BUFFER_MOVE_STAR_ICON_POSITIONED_PP_UNUSED, // Uses different formatting - unused
BUFFER_MOVE_STAR_ICON_POSITIONED_PP,
};
#define X_PP_COORD_DEFAULT 106
// size: 0xC
@ -13,8 +22,8 @@ typedef struct MoveBufferStruct
{
u32 style;
s32 xPPCoord;
u8 unk8;
u8 unk9;
bool8 redColor;
bool8 useRedColorForChargingMoves;
} MoveBufferStruct;
// size: 0x8

View File

@ -299,21 +299,21 @@ void sub_801F280(bool8 param_1)
move = &gUnknown_203B270->moves[i];
if (MoveFlagExists(move)) {
if (gUnknown_203B270->isTeamLeader) {
uStack_30.style = 2;
uStack_30.style = BUFFER_MOVE_SET_ICON_POSITIONED_PP;
}
else {
uStack_30.style = 4;
uStack_30.style = BUFFER_MOVE_STAR_ICON_POSITIONED_PP;
}
if (gUnknown_203B270->unk6) {
uStack_30.unk9 = 1;
uStack_30.useRedColorForChargingMoves = TRUE;
}
else {
uStack_30.unk9 = 0;
uStack_30.useRedColorForChargingMoves = FALSE;
}
if (i >= MAX_MON_MOVES) {
uStack_30.unk8 = 1;
uStack_30.redColor = TRUE;
}
BufferDefaultMoveName(gFormatBuffer_Items[0],move,&uStack_30);

View File

@ -47,11 +47,11 @@ extern s32 ActionToDungeonSubMenuId(u16 param_1);
extern s32 gDungeonSubMenuItemsCount;
extern MenuInputStruct gDungeonMenu;
static void ShowMovesMenuWindows(Entity *entity, EntityInfo *entInfo, u8 a2, WindowTemplates *windows, WindowHeader *header, u8 *arg5, s32 arg6, s32 arg7);
static void ShowMovesMenuWindows(Entity *entity, EntityInfo *entInfo, bool8 redColorForChargingMoves, WindowTemplates *windows, WindowHeader *header, u8 *arg5, s32 arg6, s32 arg7);
static void AddMovesSubMenuOptions(Entity *entity, bool8 addLinkOptions, bool8 addUseMove);
static void SetSubMenuOptionAction(ActionContainer *a0, s32 a1, s32 a2);
static void MenuChosenOptionToAction(ActionContainer *a0, s32 a1);
static void PrintMoveNamesOnWindow(s32 count, Entity *entity, Move *moves, s32 windowId, u8 a4, s32 a5);
static void PrintMoveNamesOnWindow(s32 count, Entity *entity, Move *moves, s32 windowId, bool8 redColorForChargingMoves, s32 a5);
static bool8 IsMoveLinkedAndNotCharging(EntityInfo *entInfo, s32 moveId_);
static bool8 IsMoveLinked(EntityInfo *entInfo, s32 id);
static void ShowMovesInfoWindow(Move *moves, s32 firstMoveId, s32 movesCount);
@ -413,7 +413,7 @@ bool8 ShowDungeonMovesMenu(Entity * entity, bool8 addLinkOptions, bool8 addUseMo
return ret;
}
static void ShowMovesMenuWindows(Entity *entity, EntityInfo *entInfo, u8 a2, WindowTemplates *windows, WindowHeader *header, u8 *arg5, s32 arg6, s32 arg7)
static void ShowMovesMenuWindows(Entity *entity, EntityInfo *entInfo, bool8 redColorForChargingMoves, WindowTemplates *windows, WindowHeader *header, u8 *arg5, s32 arg6, s32 arg7)
{
s32 i, movesCount;
WindowTemplate windowNew = {
@ -473,13 +473,13 @@ static void ShowMovesMenuWindows(Entity *entity, EntityInfo *entInfo, u8 a2, Win
}
}
PrintMoveNamesOnWindow(4, entity, entInfo->moves.moves, 0, a2, arg6);
PrintMoveNamesOnWindow(4, entity, entInfo->moves.moves, 0, redColorForChargingMoves, arg6);
sub_80073B8(2);
PrintFormattedStringOnWindow(4, 0, gUnknown_80FDFE8, 2, '\0');
sub_80073E0(2);
}
static void PrintMoveNamesOnWindow(s32 count, Entity *entity, Move *moves, s32 windowId, u8 a4, s32 a5)
static void PrintMoveNamesOnWindow(s32 count, Entity *entity, Move *moves, s32 windowId, bool8 redColorForChargingMoves, s32 a5)
{
s32 i;
EntityInfo *entInfo = GetEntInfo(entity);
@ -489,18 +489,18 @@ static void PrintMoveNamesOnWindow(s32 count, Entity *entity, Move *moves, s32 w
PrintFormattedStringOnWindow((a5 * 8) + 10, 0, gUnknown_80FE978, windowId, '\0');
for (i = 0; i < count; i++) {
s32 x, y;
MoveBufferStruct movStruct = {0, .xPPCoord = X_PP_COORD_DEFAULT, 0, a4};
MoveBufferStruct movStruct = {0, .xPPCoord = X_PP_COORD_DEFAULT, .redColor = FALSE, .useRedColorForChargingMoves = redColorForChargingMoves};
Move *move = &moves[i];
if (MoveFlagExists(move)) {
if (entInfo->isTeamLeader) {
movStruct.style = 2;
movStruct.style = BUFFER_MOVE_SET_ICON_POSITIONED_PP;
}
else {
movStruct.style = 4;
movStruct.style = BUFFER_MOVE_STAR_ICON_POSITIONED_PP;
}
movStruct.unk8 = (CanMonsterUseMove(entity, move, TRUE) == FALSE);
movStruct.redColor = (CanMonsterUseMove(entity, move, TRUE) == FALSE);
BufferMoveName(gFormatBuffer_Items[0], move, &movStruct);
y = GetMenuEntryYCoord(&gDungeonMenu, i);
if (MoveFlagLinkChain(move)) {

View File

@ -1567,18 +1567,18 @@ static void PrintMoveNamesOnBottomWindow(Entity *entity)
s32 i;
for (i = 0; i < MAX_MON_MOVES; i++) {
MoveBufferStruct movStruct = {0, .xPPCoord = X_PP_COORD_DEFAULT, 0, 0};
MoveBufferStruct movStruct = {0, .xPPCoord = X_PP_COORD_DEFAULT, .redColor = FALSE, .useRedColorForChargingMoves = FALSE};
Move *move = &entInfo->moves.moves[i];
if (MoveFlagExists(move)) {
if (entInfo->isTeamLeader) {
movStruct.style = 2;
movStruct.style = BUFFER_MOVE_SET_ICON_POSITIONED_PP;
}
else {
movStruct.style = 4;
movStruct.style = BUFFER_MOVE_STAR_ICON_POSITIONED_PP;
}
movStruct.unk8 = (CanMonsterUseMove(entity, move, TRUE) == FALSE);
movStruct.redColor = (CanMonsterUseMove(entity, move, TRUE) == FALSE);
BufferMoveName(gFormatBuffer_Items[0], move, &movStruct);
if (MoveFlagLinkChain(move)) {

View File

@ -75,7 +75,7 @@ static s32 mini_strlen(const char *s)
return len;
}
static s32 mini_itoa(s32 value, u32 radix, s32 uppercase, bool32 unsig, char *buffer)
static s32 mini_itoa(s32 value, u32 radix, s32 uppercase, bool32 unsig, bool32 plus_sign, char *buffer)
{
char *pbuffer = buffer;
s32 negative = 0;
@ -101,6 +101,8 @@ static s32 mini_itoa(s32 value, u32 radix, s32 uppercase, bool32 unsig, char *bu
if (negative)
*(pbuffer++) = '-';
else if (plus_sign && !negative)
*(pbuffer++) = '+';
*(pbuffer) = '\0';
@ -190,7 +192,7 @@ s32 mini_vpprintf(void *buf, const char *fmt, va_list va)
s32 pad_to = 0;
char l = 0;
//char alt_form = 0; // '#'
//char plus_sign = 0; // '+'
bool8 plus_sign = FALSE;
bool8 flagsDone = FALSE;
char *ptr;
@ -202,7 +204,7 @@ s32 mini_vpprintf(void *buf, const char *fmt, va_list va)
switch (ch)
{
//case '#': alt_form = 1; ch = *(fmt++); break;
//case '+': plus_sign = 1; ch = *(fmt++); break;
case '+': plus_sign = TRUE; ch = *(fmt++); break;
case '0': pad_char = '0'; ch = *(fmt++); break;
default: flagsDone = TRUE; break;
}
@ -237,17 +239,17 @@ s32 mini_vpprintf(void *buf, const char *fmt, va_list va)
case 'd':
if(l)
{
len = mini_itoa(va_arg(va, u32), 10, 0, (ch=='u'), bf2);
len = mini_itoa(va_arg(va, u32), 10, 0, (ch=='u'), plus_sign, bf2);
}
else
{
if(ch == 'u')
{
len = mini_itoa((u32) va_arg(va, u32), 10, 0, 1, bf2);
len = mini_itoa((u32) va_arg(va, u32), 10, 0, 1, plus_sign, bf2);
}
else
{
len = mini_itoa((s32) va_arg(va, s32), 10, 0, 0, bf2);
len = mini_itoa((s32) va_arg(va, s32), 10, 0, 0, plus_sign, bf2);
}
}
len = mini_pad(bf2, len, pad_char, pad_to, bf);
@ -258,11 +260,11 @@ s32 mini_vpprintf(void *buf, const char *fmt, va_list va)
case 'X':
if(l)
{
len = mini_itoa(va_arg(va, u32), 16, (ch=='X'), 1, bf2);
len = mini_itoa(va_arg(va, u32), 16, (ch=='X'), 1, plus_sign, bf2);
}
else
{
len = mini_itoa((u32) va_arg(va, u32), 16, (ch=='X'), 1, bf2);
len = mini_itoa((u32) va_arg(va, u32), 16, (ch=='X'), 1, plus_sign, bf2);
}
len = mini_pad(bf2, len, pad_char, pad_to, bf);
len = _putsAscii(bf, len, buf);

View File

@ -58,16 +58,11 @@ void BufferDefaultMoveName(u8 *buffer, Move *move, const MoveBufferStruct *buffe
BufferMoveName(buffer, &moveCopy, bufferParams);
}
enum
{
BUFFER_MOVE_JUST_NAME,
};
void BufferMoveName(u8 *buffer, Move *move, const MoveBufferStruct *bufferParams)
{
u32 color;
u32 basePP;
u8 localBuffer[12];
u8 ginsengBoostStr[12];
color = GetColorForMove(move);
@ -75,43 +70,43 @@ void BufferMoveName(u8 *buffer, Move *move, const MoveBufferStruct *bufferParams
bufferParams = &sDefaultMoveBufferParams;
if (move->ginseng != 0)
sprintfStatic(localBuffer, _("%+d"), move->ginseng);
sprintfStatic(ginsengBoostStr, _("%+d"), move->ginseng);
else
localBuffer[0] = '\0';
ginsengBoostStr[0] = '\0';
if (bufferParams->unk8 != 0)
if (bufferParams->redColor)
color = COLOR_RED;
if (bufferParams->unk9 != 0 && DoesMoveCharge(move->id))
if (bufferParams->useRedColorForChargingMoves && DoesMoveCharge(move->id))
color = COLOR_RED;
switch (bufferParams->style) {
case BUFFER_MOVE_JUST_NAME:
sprintfStatic(buffer, _("{color}%c%s%s{reset}"),
color, sMovesData[move->id].name, localBuffer);
color, sMovesData[move->id].name, ginsengBoostStr);
break;
case 1:
case BUFFER_MOVE_SET_ICON_POSITIONED_PP_UNUSED:
basePP = GetMoveBasePP(move);
sprintfStatic(buffer, _("{color}%c#:%s%s%s#;%c%2d/%2d{reset}"),
color, move->moveFlags & MOVE_FLAG_SET ? _("{ICON_SET}") : _("{ICON_BLANK}"),
sMovesData[move->id].name, localBuffer, bufferParams->xPPCoord, move->PP, basePP);
sMovesData[move->id].name, ginsengBoostStr, bufferParams->xPPCoord, move->PP, basePP);
break;
case 2:
case BUFFER_MOVE_SET_ICON_POSITIONED_PP:
basePP = GetMoveBasePP(move);
sprintfStatic(buffer, _("{color}%c%s%s%s{MOVE_X_POSITION}%c%2d/%2d{reset}"),
color, move->moveFlags & MOVE_FLAG_SET ? _("{ICON_SET}") : _("{ICON_BLANK}"),
sMovesData[move->id].name, localBuffer, bufferParams->xPPCoord, move->PP, basePP);
sMovesData[move->id].name, ginsengBoostStr, bufferParams->xPPCoord, move->PP, basePP);
break;
case 3:
case BUFFER_MOVE_STAR_ICON_POSITIONED_PP_UNUSED:
basePP = GetMoveBasePP(move);
sprintfStatic(buffer, _("{color}%c#:%s%s%s#;%c%2d/%2d{reset}"),
color, move->moveFlags & MOVE_FLAG_ENABLED_FOR_AI ? _("{STAR_BULLET}") : _("{ICON_BLANK}"),
sMovesData[move->id].name, localBuffer, bufferParams->xPPCoord, move->PP, basePP);
sMovesData[move->id].name, ginsengBoostStr, bufferParams->xPPCoord, move->PP, basePP);
break;
case 4:
case BUFFER_MOVE_STAR_ICON_POSITIONED_PP:
basePP = GetMoveBasePP(move);
sprintfStatic(buffer, _("{color}%c%s%s%s{MOVE_X_POSITION}%c%2d/%2d{reset}"),
color, move->moveFlags & MOVE_FLAG_ENABLED_FOR_AI ? _("{STAR_BULLET}") : _("{ICON_BLANK}"),
sMovesData[move->id].name, localBuffer, bufferParams->xPPCoord, move->PP, basePP);
sMovesData[move->id].name, ginsengBoostStr, bufferParams->xPPCoord, move->PP, basePP);
break;
}
}