From c5f66373c3b125497216eb4ca59b034ec344fc28 Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Tue, 19 Jul 2022 22:51:39 -0400 Subject: [PATCH] Adds ability to store and retrieve textbox size and position. --- soh/include/z64.h | 3 ++ .../custom_message/CustomMessage.cpp | 5 ++- .../custom_message/CustomMessage.h | 7 +++- soh/soh/Enhancements/randomizer/randomizer.h | 7 ++-- .../randomizer/randomizer_custom_messages.cpp | 42 +++++++++++-------- soh/soh/OTRGlobals.cpp | 8 ++-- soh/soh/z_message_OTR.cpp | 5 ++- soh/src/code/z_message_PAL.c | 2 +- 8 files changed, 50 insertions(+), 29 deletions(-) diff --git a/soh/include/z64.h b/soh/include/z64.h index fdc634e58..a16134f08 100644 --- a/soh/include/z64.h +++ b/soh/include/z64.h @@ -30,6 +30,9 @@ #include "ichain.h" #include "regs.h" +#define NOGDI +#define WIN32_LEAN_AND_MEAN + #if defined(_WIN64) || defined(__x86_64__) || defined(__arm64__) #define _SOH64 #endif diff --git a/soh/soh/Enhancements/custom_message/CustomMessage.cpp b/soh/soh/Enhancements/custom_message/CustomMessage.cpp index 437c16ac8..20170a7ba 100644 --- a/soh/soh/Enhancements/custom_message/CustomMessage.cpp +++ b/soh/soh/Enhancements/custom_message/CustomMessage.cpp @@ -100,7 +100,7 @@ bool CustomMessage::CreateMessage(std::string tableID, uint16_t textID, CustomMe return InsertCustomMessage(tableID, textID, messages); } -std::string CustomMessage::RetrieveMessage(std::string tableID, uint16_t textID) { +std::string CustomMessage::RetrieveMessage(GlobalContext* globalCtx, std::string tableID, uint16_t textID) { std::unordered_map::const_iterator result = messageTables.find(tableID); if (result == messageTables.end()) { return ""; @@ -111,6 +111,9 @@ std::string CustomMessage::RetrieveMessage(std::string tableID, uint16_t textID) return ""; } CustomMessageEntry messages = message_pair->second; + MessageContext* msgCtx = &globalCtx->msgCtx; + Font* font = &msgCtx->font; + font->charTexBuf[0] = (messages.textBoxType << 4) | messages.textBoxPos; switch (gSaveContext.language) { case LANGUAGE_FRA: return messages.french; diff --git a/soh/soh/Enhancements/custom_message/CustomMessage.h b/soh/soh/Enhancements/custom_message/CustomMessage.h index 66afaf15c..513cdaf60 100644 --- a/soh/soh/Enhancements/custom_message/CustomMessage.h +++ b/soh/soh/Enhancements/custom_message/CustomMessage.h @@ -1,7 +1,8 @@ #pragma once #include #include -#include "variables.h" +#include "z64.h" +#include #undef MESSAGE_END @@ -15,6 +16,8 @@ #define QM_BLACK 0x47 typedef struct { + TextBoxType textBoxType; + TextBoxPosition textBoxPos; std::string english; std::string german; std::string french; @@ -49,6 +52,6 @@ class CustomMessage { bool CreateGetItemMessage(std::string tableID, GetItemID giid, ItemID iid, CustomMessageEntry messages); bool CreateMessage(std::string tableID, uint16_t textID, CustomMessageEntry messages); - std::string RetrieveMessage(std::string tableID, uint16_t textID); + std::string RetrieveMessage(GlobalContext* globalCtx, std::string tableID, uint16_t textID); bool AddCustomMessageTable(std::string tableID); }; \ No newline at end of file diff --git a/soh/soh/Enhancements/randomizer/randomizer.h b/soh/soh/Enhancements/randomizer/randomizer.h index 22047a9d8..5f9f1f1bc 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.h +++ b/soh/soh/Enhancements/randomizer/randomizer.h @@ -4,8 +4,8 @@ #include #include "../../../include/ultra64.h" #include "../../../include/z64item.h" -#include #include +#include class Randomizer { private: @@ -16,7 +16,6 @@ class Randomizer { std::string ganonHintText; std::string ganonText; std::unordered_map randoSettings; - static const std::string customMessageTableID; GetItemID GetItemFromGet(RandomizerGet randoGet, GetItemID ogItemId); GetItemID GetItemFromActor(s16 actorId, s16 actorParams, s16 sceneNum, GetItemID ogItemId); void ParseRandomizerSettingsFile(const char* spoilerFileName); @@ -27,6 +26,8 @@ class Randomizer { Randomizer(); ~Randomizer(); + static const std::string customMessageTableID; + static Sprite* GetSeedTexture(uint8_t index); s16 GetItemModelFromId(s16 itemId); s32 GetItemIDFromGetItemID(s32 getItemId); @@ -43,7 +44,7 @@ class Randomizer { std::string GetHintFromCheck(RandomizerCheck check); GetItemID GetRandomizedItemIdFromKnownCheck(RandomizerCheck randomizerCheck, GetItemID ogId); GetItemID GetRandomizedItemId(GetItemID ogId, s16 actorId, s16 actorParams, s16 sceneNum); - std::string GetCustomGetItemMessage(GetItemID giid); + //std::string GetCustomGetItemMessage(GlobalContext* globalCtx, GetItemID giid); static void CreateCustomMessages(); }; diff --git a/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp b/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp index 62e213cda..8ac220fca 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp @@ -1,44 +1,52 @@ #include "randomizer.h" #include "soh/Enhancements/custom_message/CustomMessage.h" +#include -#define MESSAGES(eng, ger, fra) {eng, ger, fra} +#define NOGDI +#define WIN32_LEAN_AND_MEAN void Randomizer::CreateCustomMessages() { CustomMessage* customMessage = CustomMessage::Instance; customMessage->AddCustomMessageTable(Randomizer::customMessageTableID); customMessage->CreateGetItemMessage( Randomizer::customMessageTableID, GI_BOTTLE_WITH_BLUE_FIRE, ITEM_BLUE_FIRE, - MESSAGES("You got a %rBottle with Blue &Fire%w! Use it to melt Red Ice!", "", "")); + { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, + "You got a %rBottle with Blue &Fire%w! Use it to melt Red Ice!", "", "" }); customMessage->CreateGetItemMessage( Randomizer::customMessageTableID, GI_BOTTLE_WITH_BIG_POE, ITEM_BIG_POE, - MESSAGES("You got a %rBig Poe in a Bottle%w!&Sell it to the Ghost Shop!", "", "")); + { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, + "You got a %rBig Poe in a Bottle%w!&Sell it to the Ghost Shop!", "", "" }); customMessage->CreateGetItemMessage( Randomizer::customMessageTableID, GI_BOTTLE_WITH_BLUE_POTION, ITEM_POTION_BLUE, - MESSAGES("You got a %rBottle of Blue Potion%w!&Drink it to replenish your&%ghealth%w and %bmagic%w!", "", "")); + { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, + "You got a %rBottle of Blue Potion%w!&Drink it to replenish your&%ghealth%w and %bmagic%w!", "", "" }); customMessage->CreateGetItemMessage( Randomizer::customMessageTableID, GI_BOTTLE_WITH_FISH, ITEM_FISH, - MESSAGES("You got a %rFish in a Bottle%w!&It looks fresh and delicious!&They say Jabu-Jabu loves them!", "", "")); + { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, + "You got a %rFish in a Bottle%w!&It looks fresh and delicious!&They say Jabu-Jabu loves them!", "", "" }); customMessage->CreateGetItemMessage( Randomizer::customMessageTableID, GI_BOTTLE_WITH_BUGS, ITEM_BUG, - { "You got a %rBug in a Bottle%w!&They love to burrow in&dirt holes!", "", "" }); + { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, "You got a %rBug in a Bottle%w!&They love to burrow in&dirt holes!", "", "" }); customMessage->CreateGetItemMessage( Randomizer::customMessageTableID, GI_BOTTLE_WITH_FAIRY, ITEM_FAIRY, - { "You got a %rFairy in a Bottle%w!&Use it wisely!", "", "" }); + { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, "You got a %rFairy in a Bottle%w!&Use it wisely!", "", "" }); customMessage->CreateGetItemMessage( Randomizer::customMessageTableID, GI_BOTTLE_WITH_RED_POTION, ITEM_POTION_RED, - { "You got a %rBottle of Red Potion%w!&Drink it to replenish your&%ghealth%w!", "", "" }); + { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, "You got a %rBottle of Red Potion%w!&Drink it to replenish your&%ghealth%w!", "", "" }); customMessage->CreateGetItemMessage( Randomizer::customMessageTableID, GI_BOTTLE_WITH_GREEN_POTION, ITEM_POTION_GREEN, - { "You got a %rBottle of Green Potion%w!&Drink it to replenish your&%bmagic%w!", "", "" }); + { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, + "You got a %rBottle of Green Potion%w!&Drink it to replenish your&%bmagic%w!", "", "" }); customMessage->CreateGetItemMessage( Randomizer::customMessageTableID, GI_BOTTLE_WITH_POE, ITEM_POE, - { "You got a %rPoe in a Bottle%w!&That creepy Ghost Shop might&be interested in this...", "", "" }); + { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, + "You got a %rPoe in a Bottle%w!&That creepy Ghost Shop might&be interested in this...", "", "" }); } -std::string Randomizer::GetCustomGetItemMessage(GetItemID giid) { - if (!gSaveContext.n64ddFlag) { - return "Not Randomized."; - } - - return CustomMessage::Instance->RetrieveMessage(Randomizer::customMessageTableID, giid); -} \ No newline at end of file +//std::string Randomizer::GetCustomGetItemMessage(GlobalContext* globalCtx, GetItemID giid) { +// if (!gSaveContext.n64ddFlag) { +// return "Not Randomized."; +// } +// +// return CustomMessage::Instance->RetrieveMessage(globalCtx, Randomizer::customMessageTableID, giid); +//} \ No newline at end of file diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 309c0a951..c048d3358 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -1505,8 +1505,8 @@ extern "C" s32 Randomizer_GetItemIdFromKnownCheck(RandomizerCheck randomizerChec return OTRGlobals::Instance->gRandomizer->GetRandomizedItemIdFromKnownCheck(randomizerCheck, ogId); } -extern "C" int Randomizer_GetCustomGetItemMessage(GetItemID giid, char* buffer, const int maxBufferSize) { - const std::string& getItemText = OTRGlobals::Instance->gRandomizer->GetCustomGetItemMessage(giid); +extern "C" int Randomizer_GetCustomGetItemMessage(GlobalContext* globalCtx, GetItemID giid, char* buffer, const int maxBufferSize) { + const std::string& getItemText = CustomMessage::Instance->RetrieveMessage(globalCtx, Randomizer::customMessageTableID, giid); if (getItemText == "") { return false; } @@ -1523,7 +1523,7 @@ extern "C" int CustomMessage_RetrieveIfExists(GlobalContext* globalCtx) { if (textId == 0xF8) { font->charTexBuf[0] = 0x23; if (msgCtx->msgLength = font->msgLength = Randomizer_GetCustomGetItemMessage( - (GetItemID)GET_PLAYER(globalCtx)->getItemId, buffer, maxBufferSize)) { + globalCtx, (GetItemID)GET_PLAYER(globalCtx)->getItemId, buffer, maxBufferSize)) { return true; } else { switch (gSaveContext.language) { @@ -1551,7 +1551,7 @@ extern "C" int CustomMessage_RetrieveIfExists(GlobalContext* globalCtx) { } else { textId = 0x00B5; } - message = CustomMessage::Instance->RetrieveMessage("BaseGameOverrides", textId); + message = CustomMessage::Instance->RetrieveMessage(globalCtx, "BaseGameOverrides", textId); if (message != "") { return msgCtx->msgLength = font->msgLength = CopyStringToCharBuffer(message, buffer, maxBufferSize); } diff --git a/soh/soh/z_message_OTR.cpp b/soh/soh/z_message_OTR.cpp index e6ef4bb76..503d3e14b 100644 --- a/soh/soh/z_message_OTR.cpp +++ b/soh/soh/z_message_OTR.cpp @@ -100,6 +100,7 @@ extern "C" void OTRMessage_Init() CustomMessage::Instance->CreateGetItemMessage( customMessageTableID, (GetItemID)0x00B4, ITEM_SKULL_TOKEN, { + TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, "You got a %rGold Skulltula Token%w!&You've collected %r\x19%w tokens&in total!\x0E\x3C", "Du erhälst ein %rGoldene&Skulltula-Symbol%w! Du hast&insgesamt %r\x19%w symbol gesammelt!\x0E\x3C", "Vous obtenez un %rSymbole de&Skulltula d'or%w! Vous avez&collecté %r\x19\%w symboles en tout!\x0E\x3C" @@ -107,7 +108,9 @@ extern "C" void OTRMessage_Init() ); CustomMessage::Instance->CreateGetItemMessage( customMessageTableID, (GetItemID)0x00B5, ITEM_SKULL_TOKEN, - { "You got a %rGold Skulltula Token%w!&You've collected %r\x19%w tokens&in total!", + { + TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, + "You got a %rGold Skulltula Token%w!&You've collected %r\x19%w tokens&in total!", "Du erhälst ein %rGoldene&Skulltula-Symbol%w! Du hast&insgesamt %r\x19%w symbol gesammelt!", "Vous obtenez un %rSymbole de&Skulltula d'or%w! Vous avez&collecté %r\x19\%w symboles en tout!" }); } \ No newline at end of file diff --git a/soh/src/code/z_message_PAL.c b/soh/src/code/z_message_PAL.c index 196821e9e..e44e5f325 100644 --- a/soh/src/code/z_message_PAL.c +++ b/soh/src/code/z_message_PAL.c @@ -1709,7 +1709,7 @@ void Message_OpenText(GlobalContext* globalCtx, u16 textId) { msgCtx->msgLength = font->msgLength = Randomizer_CopyHintFromCheck(hintCheck, font->msgBuf, sizeof(font->msgBuf)); } else if (gSaveContext.n64ddFlag && (textId == 0x7040 || textId == 0x7088)) { // rando hints at altar - msgCtx->msgLength = font->msgLength = CopyAltarMessage(font->msgBuf, sizeof(font->msgBuf)); + msgCtx->msgLength = font->msgLength = Randomizer_CopyAltarMessage(font->msgBuf, sizeof(font->msgBuf)); } else if (gSaveContext.n64ddFlag && (textId == 0x10A2 || textId == 0x10DC || textId == 0x10DD)) { msgCtx->msgLength = font->msgLength = CopyScrubMessage(textId, font->msgBuf, sizeof(font->msgBuf)); } else if (gSaveContext.n64ddFlag && textId == 0x70CC) {