mirror of https://github.com/pret/pokeemerald.git
some work on international string util
This commit is contained in:
parent
96c5966ff3
commit
9d4acb9635
|
@ -5,127 +5,6 @@
|
|||
|
||||
.text
|
||||
|
||||
thumb_func_start GetStringCenterAlignXOffset
|
||||
@ s32 GetStringCenterAlignXOffset(u8 fontId, u8 *str, s32 totalWidth)
|
||||
GetStringCenterAlignXOffset: @ 81DB35C
|
||||
push {lr}
|
||||
movs r3, 0
|
||||
bl GetStringCenterAlignXOffsetWithLetterSpacing
|
||||
pop {r1}
|
||||
bx r1
|
||||
thumb_func_end GetStringCenterAlignXOffset
|
||||
|
||||
thumb_func_start GetStringRightAlignXOffset
|
||||
@ s32 GetStringRightAlignXOffset(u8 fontId, u8 *str, s32 totalWidth)
|
||||
GetStringRightAlignXOffset: @ 81DB368
|
||||
push {lr}
|
||||
movs r3, 0
|
||||
bl GetStringWidthDifference
|
||||
pop {r1}
|
||||
bx r1
|
||||
thumb_func_end GetStringRightAlignXOffset
|
||||
|
||||
thumb_func_start GetStringCenterAlignXOffsetWithLetterSpacing
|
||||
@ s32 GetStringCenterAlignXOffsetWithLetterSpacing(u8 fontId, u8 *str, s32 totalWidth, s16 letterSpacing)
|
||||
GetStringCenterAlignXOffsetWithLetterSpacing: @ 81DB374
|
||||
push {lr}
|
||||
bl GetStringWidthDifference
|
||||
lsrs r1, r0, 31
|
||||
adds r0, r1
|
||||
asrs r0, 1
|
||||
pop {r1}
|
||||
bx r1
|
||||
thumb_func_end GetStringCenterAlignXOffsetWithLetterSpacing
|
||||
|
||||
thumb_func_start GetStringWidthDifference
|
||||
@ s32 GetStringWidthDifference(u8 fontId, u8 *str, s32 totalWidth, s16 letterSpacing)
|
||||
GetStringWidthDifference: @ 81DB384
|
||||
push {r4,lr}
|
||||
adds r4, r2, 0
|
||||
adds r2, r3, 0
|
||||
lsls r0, 24
|
||||
lsrs r0, 24
|
||||
lsls r2, 16
|
||||
asrs r2, 16
|
||||
bl GetStringWidth
|
||||
cmp r4, r0
|
||||
bgt _081DB39E
|
||||
movs r0, 0
|
||||
b _081DB3A0
|
||||
_081DB39E:
|
||||
subs r0, r4, r0
|
||||
_081DB3A0:
|
||||
pop {r4}
|
||||
pop {r1}
|
||||
bx r1
|
||||
thumb_func_end GetStringWidthDifference
|
||||
|
||||
thumb_func_start GetMaxWidthInMenuTable
|
||||
GetMaxWidthInMenuTable: @ 81DB3A8
|
||||
push {r4-r6,lr}
|
||||
movs r6, 0
|
||||
cmp r6, r1
|
||||
bge _081DB3CC
|
||||
adds r5, r0, 0
|
||||
adds r4, r1, 0
|
||||
_081DB3B4:
|
||||
ldr r1, [r5]
|
||||
movs r0, 0x1
|
||||
movs r2, 0
|
||||
bl GetStringWidth
|
||||
cmp r0, r6
|
||||
ble _081DB3C4
|
||||
adds r6, r0, 0
|
||||
_081DB3C4:
|
||||
adds r5, 0x8
|
||||
subs r4, 0x1
|
||||
cmp r4, 0
|
||||
bne _081DB3B4
|
||||
_081DB3CC:
|
||||
adds r0, r6, 0
|
||||
bl convert_pixel_width_to_tile_width
|
||||
pop {r4-r6}
|
||||
pop {r1}
|
||||
bx r1
|
||||
thumb_func_end GetMaxWidthInMenuTable
|
||||
|
||||
thumb_func_start sub_81DB3D8
|
||||
sub_81DB3D8: @ 81DB3D8
|
||||
push {r4-r7,lr}
|
||||
mov r7, r8
|
||||
push {r7}
|
||||
mov r8, r0
|
||||
adds r7, r1, 0
|
||||
adds r5, r2, 0
|
||||
movs r6, 0
|
||||
movs r4, 0
|
||||
cmp r6, r5
|
||||
bge _081DB40A
|
||||
_081DB3EC:
|
||||
adds r0, r7, r4
|
||||
ldrb r0, [r0]
|
||||
lsls r0, 3
|
||||
add r0, r8
|
||||
ldr r1, [r0]
|
||||
movs r0, 0x1
|
||||
movs r2, 0
|
||||
bl GetStringWidth
|
||||
cmp r0, r6
|
||||
ble _081DB404
|
||||
adds r6, r0, 0
|
||||
_081DB404:
|
||||
adds r4, 0x1
|
||||
cmp r4, r5
|
||||
blt _081DB3EC
|
||||
_081DB40A:
|
||||
adds r0, r6, 0
|
||||
bl convert_pixel_width_to_tile_width
|
||||
pop {r3}
|
||||
mov r8, r3
|
||||
pop {r4-r7}
|
||||
pop {r1}
|
||||
bx r1
|
||||
thumb_func_end sub_81DB3D8
|
||||
|
||||
thumb_func_start sub_81DB41C
|
||||
sub_81DB41C: @ 81DB41C
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
#ifndef GUARD_INTERNATIONAL_STRING_UTIL_H
|
||||
#define GUARD_INTERNATIONAL_STRING_UTIL_H
|
||||
|
||||
s32 GetStringCenterAlignXOffset(s32 fontId, const u8 *str, s32 totalWidth);
|
||||
s32 GetStringRightAlignXOffset(s32 fontId, const u8 *str, s32 totalWidth);
|
||||
s32 GetStringCenterAlignXOffsetWithLetterSpacing(s32 fontId, const u8 *str, s32 totalWidth, s32 letterSpacing);
|
||||
s32 GetStringWidthDifference(s32 fontId, const u8 *str, s32 totalWidth, s32 letterSpacing);
|
||||
s32 GetMaxWidthInMenuTable(const u8 **str, s32 arg1);
|
||||
s32 sub_81DB3D8(const u8 **str, u8* arg1, s32 arg2);
|
||||
// sub_81DB41C
|
||||
// sub_81DB468
|
||||
// sub_81DB494
|
||||
// sub_81DB4DC
|
||||
// sub_81DB52C
|
||||
// sub_81DB554
|
||||
// sub_81DB5AC
|
||||
// sub_81DB5E8
|
||||
// sub_81DB620
|
||||
|
||||
#endif // GUARD_INTERNATIONAL_STRING_UTIL_H
|
|
@ -264,6 +264,7 @@ SECTIONS {
|
|||
asm/unk_sprite_file.o(.text);
|
||||
asm/unk_transition.o(.text);
|
||||
asm/unk_transition_2.o(.text);
|
||||
src/international_string_util.o(.text);
|
||||
asm/international_string_util.o(.text);
|
||||
} =0
|
||||
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
#include "text_window.h"
|
||||
#include "string_util.h"
|
||||
#include "menu.h"
|
||||
#include "international_string_util.h"
|
||||
|
||||
#define MAX_COINS 9999
|
||||
|
||||
EWRAM_DATA u8 sCoinsWindowId = 0;
|
||||
|
||||
extern s32 GetStringRightAlignXOffset(u8 fontId, u8 *str, s32 totalWidth);
|
||||
extern void sub_819746C(u8 windowId, bool8 copyToVram);
|
||||
|
||||
extern const u8 gText_Coins[];
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
#include "global.h"
|
||||
#include "international_string_util.h"
|
||||
#include "text.h"
|
||||
|
||||
extern s32 convert_pixel_width_to_tile_width(s32 a0); // script menu
|
||||
|
||||
s32 GetStringCenterAlignXOffset(s32 fontId, const u8 *str, s32 totalWidth)
|
||||
{
|
||||
return GetStringCenterAlignXOffsetWithLetterSpacing(fontId, str, totalWidth, 0);
|
||||
}
|
||||
|
||||
s32 GetStringRightAlignXOffset(s32 fontId, const u8 *str, s32 totalWidth)
|
||||
{
|
||||
return GetStringWidthDifference(fontId, str, totalWidth, 0);
|
||||
}
|
||||
|
||||
s32 GetStringCenterAlignXOffsetWithLetterSpacing(s32 fontId, const u8 *str, s32 totalWidth, s32 letterSpacing)
|
||||
{
|
||||
return GetStringWidthDifference(fontId, str, totalWidth, letterSpacing) / 2;
|
||||
}
|
||||
|
||||
s32 GetStringWidthDifference(s32 fontId, const u8 *str, s32 totalWidth, s32 letterSpacing)
|
||||
{
|
||||
s32 stringWidth = GetStringWidth(fontId, str, letterSpacing);
|
||||
if (totalWidth > stringWidth)
|
||||
return totalWidth - stringWidth;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
s32 GetMaxWidthInMenuTable(const u8 **str, s32 arg1)
|
||||
{
|
||||
s32 i, var;
|
||||
|
||||
for (var = 0, i = 0; i < arg1; i++)
|
||||
{
|
||||
s32 stringWidth = GetStringWidth(1, str[i * 2], 0);
|
||||
if (stringWidth > var)
|
||||
var = stringWidth;
|
||||
}
|
||||
|
||||
return convert_pixel_width_to_tile_width(var);
|
||||
}
|
||||
|
||||
s32 sub_81DB3D8(const u8 **str, u8* arg1, s32 arg2)
|
||||
{
|
||||
s32 i, var;
|
||||
|
||||
for (var = 0, i = 0; i < arg2; i++)
|
||||
{
|
||||
s32 stringWidth = GetStringWidth(1, str[arg1[i] * 2], 0);
|
||||
if (stringWidth > var)
|
||||
var = stringWidth;
|
||||
}
|
||||
|
||||
return convert_pixel_width_to_tile_width(var);
|
||||
}
|
Loading…
Reference in New Issue