Skip to content

Commit

Permalink
Adds ability to store and retrieve textbox size and position.
Browse files Browse the repository at this point in the history
  • Loading branch information
leggettc18 committed Jul 20, 2022
1 parent 2d1aa1d commit c5f6637
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 29 deletions.
3 changes: 3 additions & 0 deletions soh/include/z64.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion soh/soh/Enhancements/custom_message/CustomMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, CustomMessageTable>::const_iterator result = messageTables.find(tableID);
if (result == messageTables.end()) {
return "";
Expand All @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions soh/soh/Enhancements/custom_message/CustomMessage.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once
#include <string>
#include <unordered_map>
#include "variables.h"
#include "z64.h"
#include <message_data_static.h>

#undef MESSAGE_END

Expand All @@ -15,6 +16,8 @@
#define QM_BLACK 0x47

typedef struct {
TextBoxType textBoxType;
TextBoxPosition textBoxPos;
std::string english;
std::string german;
std::string french;
Expand Down Expand Up @@ -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);
};
7 changes: 4 additions & 3 deletions soh/soh/Enhancements/randomizer/randomizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <string>
#include "../../../include/ultra64.h"
#include "../../../include/z64item.h"
#include <randomizerTypes.h>
#include <memory>
#include <soh/Enhancements/randomizer/randomizerTypes.h>

class Randomizer {
private:
Expand All @@ -16,7 +16,6 @@ class Randomizer {
std::string ganonHintText;
std::string ganonText;
std::unordered_map<RandomizerSettingKey, u8> 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);
Expand All @@ -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);
Expand All @@ -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();
};

Expand Down
42 changes: 25 additions & 17 deletions soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp
Original file line number Diff line number Diff line change
@@ -1,44 +1,52 @@
#include "randomizer.h"
#include "soh/Enhancements/custom_message/CustomMessage.h"
#include <message_data_static.h>

#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);
}
//std::string Randomizer::GetCustomGetItemMessage(GlobalContext* globalCtx, GetItemID giid) {
// if (!gSaveContext.n64ddFlag) {
// return "Not Randomized.";
// }
//
// return CustomMessage::Instance->RetrieveMessage(globalCtx, Randomizer::customMessageTableID, giid);
//}
8 changes: 4 additions & 4 deletions soh/soh/OTRGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down
5 changes: 4 additions & 1 deletion soh/soh/z_message_OTR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,17 @@ 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"
}
);
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!" });
}
2 changes: 1 addition & 1 deletion soh/src/code/z_message_PAL.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit c5f6637

Please sign in to comment.