mirror of
https://github.com/zeldaret/ss
synced 2026-09-01 09:32:58 -04:00
More d_message cleanup
This commit is contained in:
@@ -181,6 +181,9 @@ static char *sMsbfFileNames[80] = {
|
||||
"599-Demo.msbf",
|
||||
};
|
||||
|
||||
dMessage_c *dMessage_c::sInstance;
|
||||
dTagProcessor_c *dMessage_c::sTagProcessor;
|
||||
|
||||
static void *msbAlloc(size_t size) {}
|
||||
|
||||
static void msbFree(void *ptr) {}
|
||||
@@ -255,6 +258,107 @@ int dMessage_c::draw() {
|
||||
return SUCCEEDED;
|
||||
}
|
||||
|
||||
const wchar_t *dMessage_c::getTextMessageByLabel(const char *label, bool global, wchar_t *dstBuf, u32 maxLen) {
|
||||
return sInstance->getTextMessageByLabelInternal(label, nullptr, global, dstBuf, maxLen);
|
||||
}
|
||||
|
||||
const wchar_t *dMessage_c::getTextMessageByLabel(
|
||||
const char *label, dTagProcessor_c *pTagProcessor, bool global, wchar_t *dstBuf, u32 maxLen
|
||||
) {
|
||||
return sInstance->getTextMessageByLabelInternal(label, pTagProcessor, global, dstBuf, maxLen);
|
||||
}
|
||||
|
||||
const wchar_t *dMessage_c::formatText(const wchar_t *text) {
|
||||
return sInstance->formatTextInternal(text);
|
||||
}
|
||||
|
||||
const wchar_t *dMessage_c::getTextMessageByLabelInternal(
|
||||
const char *label, dTagProcessor_c *pTagProcessor, bool global, wchar_t *dstBuf, u32 maxLen
|
||||
) {
|
||||
s32 fileIndex = mCurrentTextFileNumber;
|
||||
MsbtInfo *info = nullptr;
|
||||
|
||||
if (global) {
|
||||
fileIndex = getMsbtIndexForLabelInternal(label);
|
||||
}
|
||||
|
||||
if (fileIndex >= 0) {
|
||||
info = getMsbtInfoForIndex(fileIndex);
|
||||
}
|
||||
|
||||
const wchar_t *text = LMS_GetTextByLabel(info, label);
|
||||
if (pTagProcessor == nullptr) {
|
||||
pTagProcessor = sTagProcessor;
|
||||
}
|
||||
|
||||
u32 outLen = 0;
|
||||
s32 textIdx = LMS_GetTextIndexByLabel(info, label);
|
||||
MsbtAttrInfo *att = LMS_GetAttribute(info, textIdx);
|
||||
pTagProcessor->setMsgWindowSubtype(att->c_0x00);
|
||||
pTagProcessor->setField_0x90D(att->c_0x01);
|
||||
|
||||
// Strip trailing newline
|
||||
wchar_t *end;
|
||||
s32 i;
|
||||
|
||||
if (dstBuf != nullptr) {
|
||||
pTagProcessor->format(nullptr, text, dstBuf, maxLen, &outLen, nullptr);
|
||||
i = outLen - 1;
|
||||
end = &dstBuf[i];
|
||||
for (; i > 0; i--) {
|
||||
if (*end != L'\n') {
|
||||
break;
|
||||
}
|
||||
*end-- = L'\0';
|
||||
}
|
||||
// no return - might be intentional since dstBuf already has the result
|
||||
} else {
|
||||
static wchar_t sBuf[0x400] = {};
|
||||
pTagProcessor->format(nullptr, text, sBuf, ARRAY_LENGTH(sBuf) - 1, &outLen, nullptr);
|
||||
i = outLen - 1;
|
||||
end = &sBuf[i];
|
||||
for (; i > 0; i--) {
|
||||
if (*end != L'\n') {
|
||||
break;
|
||||
}
|
||||
*end = L'\0';
|
||||
end--;
|
||||
}
|
||||
|
||||
return sBuf;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const wchar_t *dMessage_c::formatTextInternal(const wchar_t *text) {
|
||||
u32 outLen = 0;
|
||||
static wchar_t sBuf[0x200] = {};
|
||||
sTagProcessor->format(nullptr, text, sBuf, ARRAY_LENGTH(sBuf), &outLen, nullptr);
|
||||
s32 i = outLen - 1;
|
||||
wchar_t *end = &sBuf[i];
|
||||
for (; i > 0; i--) {
|
||||
if (*end != L'\n') {
|
||||
break;
|
||||
}
|
||||
*end = L'\0';
|
||||
end--;
|
||||
}
|
||||
|
||||
return sBuf;
|
||||
}
|
||||
|
||||
bool dMessage_c::isValidTextLabel(const char *name) {
|
||||
return sInstance->checkIsValidTextLabel(name);
|
||||
}
|
||||
|
||||
bool dMessage_c::checkIsValidTextLabel(const char *name) {
|
||||
if (name == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return getTextIndexForLabel(name) >= 0;
|
||||
}
|
||||
|
||||
const char *dMessage_c::getMsbtFileName(s32 idx) {
|
||||
static SizedString<128> sPath;
|
||||
|
||||
@@ -281,6 +385,47 @@ s32 dMessage_c::getMsbfNumberByIndex(s32 index) {
|
||||
return atoi(getMsbfFileName(index));
|
||||
}
|
||||
|
||||
s32 dMessage_c::getTextIndexForLabel(const char *label) {
|
||||
s32 idx = getMsbtIndexForLabelInternal(label);
|
||||
MsbtInfo *info = nullptr;
|
||||
if (idx >= 0) {
|
||||
info = getMsbtInfoForIndex(idx);
|
||||
}
|
||||
return LMS_GetTextIndexByLabel(info, label);
|
||||
}
|
||||
|
||||
s32 dMessage_c::getMsbtIndexForLabelInternal(const char *label) {
|
||||
if (mCurrentTextFileNumber <= 81) {
|
||||
MsbtInfo *info = getMsbtInfoForIndex(mCurrentTextFileNumber);
|
||||
if (LMS_GetTextIndexByLabel(info, label) >= 0) {
|
||||
return mCurrentTextFileNumber;
|
||||
}
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < 82; i++) {
|
||||
if (getMsbtInfoForIndex(i) != nullptr) {
|
||||
if (LMS_GetTextIndexByLabel(getMsbtInfoForIndex(i), label) >= 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
MsbtInfo *dMessage_c::getMsbtInfoForIndex(s32 index) {
|
||||
return sInstance->getMsbtInfoForIndexInternal(index);
|
||||
}
|
||||
|
||||
MsbtInfo *dMessage_c::getMsbtInfoForIndexInternal(s32 index) {
|
||||
UnkTextThing *thing = UnkTextThing::getInstance();
|
||||
MsbtInfo *overrideMsbt = thing->getMsbtInfo(index);
|
||||
if (overrideMsbt != nullptr && thing->getField_0x7B4() == true) {
|
||||
return overrideMsbt;
|
||||
}
|
||||
return mpMsgs[index];
|
||||
}
|
||||
|
||||
extern "C" u8 fn_80054F30();
|
||||
|
||||
static SizedString<8> sCurrentLanguage;
|
||||
|
||||
+1
-5
@@ -439,8 +439,6 @@ void LytBase_c::setPropertiesRecursive(nw4r::lyt::Pane *pane, f32 posX, f32 posY
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" const wchar_t *fn_801B2600(const wchar_t *);
|
||||
|
||||
void LytBase_c::setProperties(nw4r::lyt::Pane *pane, f32 posX, f32 posY, f32 scale, f32 spaceX, f32 spaceY) {
|
||||
if (pane->GetName()[0] != 'T') {
|
||||
return;
|
||||
@@ -608,7 +606,7 @@ bool LytBase_c::fn_800ABCE0(
|
||||
return false;
|
||||
}
|
||||
|
||||
textbox1->setTextWithGlobalTextProcessor(fn_801B2600(text));
|
||||
textbox1->setTextWithGlobalTextProcessor(dMessage_c::formatText(text));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -678,8 +676,6 @@ bool LytBase_c::fn_800AC040(dTextBox_c *textbox1, dTextBox_c *textbox2, wchar_t
|
||||
return fn_800AC1AC(list, textbox1, textbox2, destBuf, maxLen);
|
||||
}
|
||||
|
||||
extern "C" void fn_800AF840(dTextBox_c *textbox1, MsbtInfo *, const char *, int arg, void *unk);
|
||||
|
||||
bool LytBase_c::fn_800AC1AC(
|
||||
const nw4r::lyt::res::ExtUserData *userDatum, dTextBox_c *textbox1, dTextBox_c *textbox2, wchar_t *destBuf, u32 maxLen
|
||||
) {
|
||||
|
||||
@@ -300,8 +300,6 @@ s32 dTextBox_c::calcTextLines(const wchar_t *src, dTagProcessor_c *tagProcessor)
|
||||
return tagProcessor->getNumLinesMaybe();
|
||||
}
|
||||
|
||||
extern "C" const wchar_t *getTextMessageByLabel(const char *labelId, int, int, int);
|
||||
|
||||
void dTextBox_c::setMessageWithGlobalTextProcessor(const char *labelId, void *unused, void *unk, ...) {
|
||||
va_list l;
|
||||
va_start(l, str);
|
||||
@@ -310,7 +308,7 @@ void dTextBox_c::setMessageWithGlobalTextProcessor(const char *labelId, void *un
|
||||
}
|
||||
|
||||
void dTextBox_c::setMessageWithGlobalTextProcessorV(const char *labelId, void *unused, void *unk, va_list list) {
|
||||
const wchar_t *text = getTextMessageByLabel(labelId, 1, 0, 0);
|
||||
const wchar_t *text = dMessage_c::getTextMessageByLabel(labelId, true, nullptr, 0);
|
||||
setTextWithGlobalTextProcessorV(text, unk, list);
|
||||
if (GetFont() != nullptr) {
|
||||
resizeTextToFit(GetSize().width);
|
||||
|
||||
Reference in New Issue
Block a user