Skip to content

Commit

Permalink
Renames CustomMessage to CustomMessageManager
Browse files Browse the repository at this point in the history
  • Loading branch information
leggettc18 committed Jul 26, 2022
1 parent 4c9e4b2 commit 8224763
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 56 deletions.
4 changes: 2 additions & 2 deletions soh/soh.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="soh\Enhancements\custom_message\CustomMessage.cpp" />
<ClCompile Include="soh\Enhancements\custom_message\CustomMessageManager.cpp" />
<ClCompile Include="soh\Enhancements\cosmetics\CosmeticsEditor.cpp" />
<ClCompile Include="soh\Enhancements\debugger\actorViewer.cpp" />
<ClCompile Include="soh\Enhancements\gfx.c" />
Expand Down Expand Up @@ -944,7 +944,7 @@
<ClCompile Include="src\overlays\misc\ovl_map_mark_data\z_map_mark_data.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="soh\Enhancements\custom_message\CustomMessage.h" />
<ClInclude Include="soh\Enhancements\custom_message\CustomMessageManager.h" />
<ClInclude Include="soh\Enhancements\cosmetics\CosmeticsEditor.h" />
<ClInclude Include="soh\Enhancements\debugger\actorViewer.h" />
<ClCompile Include="soh\Enhancements\randomizer\randomizer.h" />
Expand Down
4 changes: 2 additions & 2 deletions soh/soh.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -2379,7 +2379,7 @@
<ClCompile Include="soh\Enhancements\randomizer\randomizer_item_tracker.cpp">
<Filter>Source Files\src</Filter>
</ClCompile>
<ClCompile Include="soh\Enhancements\custom_message\CustomMessage.cpp">
<ClCompile Include="soh\Enhancements\custom_message\CustomMessageManager.cpp">
<Filter>Source Files\soh\Enhancements\custom-message</Filter>
</ClCompile>
</ItemGroup>
Expand Down Expand Up @@ -4070,7 +4070,7 @@
<ClInclude Include="soh\Enhancements\randomizer\randomizer_item_tracker.h">
<Filter>Source Files\src</Filter>
</ClInclude>
<ClInclude Include="soh\Enhancements\custom_message\CustomMessage.h">
<ClInclude Include="soh\Enhancements\custom_message\CustomMessageManager.h">
<Filter>Header Files\soh\Enhancements\custom-message</Filter>
</ClInclude>
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "CustomMessage.h"
#include "CustomMessageManager.h"
#include <algorithm>

using namespace std::literals::string_literals;

CustomMessage::CustomMessage() {
CustomMessageManager::CustomMessageManager() {
this->textBoxSpecialCharacters = { { "À", 0x80 }, { "î", 0x81 }, { "Â", 0x82 }, { "Ä", 0x83 }, { "Ç", 0x84 },
{ "È", 0x85 }, { "É", 0x86 }, { "Ê", 0x87 }, { "Ë", 0x88 }, { "Ï", 0x89 },
{ "Ô", 0x8A }, { "Ö", 0x8B }, { "Ù", 0x8C }, { "Û", 0x8D }, { "Ü", 0x8E },
Expand All @@ -15,13 +15,13 @@ CustomMessage::CustomMessage() {
{ "c", QM_LBLUE }, { "p", QM_PINK }, { "y", QM_YELLOW }, { "B", QM_BLACK } };
}

CustomMessage::~CustomMessage() {
CustomMessageManager::~CustomMessageManager() {
this->textBoxSpecialCharacters.clear();
this->colors.clear();
this->messageTables.clear();
}

void CustomMessage::ReplaceSpecialCharacters(std::string& string) {
void CustomMessageManager::ReplaceSpecialCharacters(std::string& string) {
// add special characters
for (auto specialCharacterPair : this->textBoxSpecialCharacters) {
size_t start_pos = 0;
Expand All @@ -34,7 +34,7 @@ void CustomMessage::ReplaceSpecialCharacters(std::string& string) {
}
}

void CustomMessage::ReplaceColors(std::string& string) {
void CustomMessageManager::ReplaceColors(std::string& string) {
for (auto colorPair : colors) {
std::string textToReplace = "%";
textToReplace += colorPair.first;
Expand All @@ -46,7 +46,7 @@ void CustomMessage::ReplaceColors(std::string& string) {
}
}

void CustomMessage::FormatCustomMessage(std::string& message, ItemID iid) {
void CustomMessageManager::FormatCustomMessage(std::string& message, ItemID iid) {
message.insert(0, ITEM_OBTAINED(iid));
size_t start_pos = 0;
std::replace(message.begin(), message.end(), '&', NEWLINE()[0]);
Expand All @@ -60,7 +60,7 @@ void CustomMessage::FormatCustomMessage(std::string& message, ItemID iid) {
message += MESSAGE_END();
}

void CustomMessage::FormatCustomMessage(std::string& message) {
void CustomMessageManager::FormatCustomMessage(std::string& message) {
size_t start_pos = 0;
std::replace(message.begin(), message.end(), '&', NEWLINE()[0]);
std::replace(message.begin(), message.end(), '^', WAIT_FOR_INPUT()[0]);
Expand All @@ -70,7 +70,7 @@ void CustomMessage::FormatCustomMessage(std::string& message) {
message += MESSAGE_END();
}

bool CustomMessage::InsertCustomMessage(std::string tableID, uint16_t textID, CustomMessageEntry messages) {
bool CustomMessageManager::InsertCustomMessage(std::string tableID, uint16_t textID, CustomMessageEntry messages) {
auto result = messageTables.find(tableID);
if (result == messageTables.end()) {
return false;
Expand All @@ -82,22 +82,22 @@ bool CustomMessage::InsertCustomMessage(std::string tableID, uint16_t textID, Cu



bool CustomMessage::CreateGetItemMessage(std::string tableID, GetItemID giid, ItemID iid, CustomMessageEntry messages) {
bool CustomMessageManager::CreateGetItemMessage(std::string tableID, GetItemID giid, ItemID iid, CustomMessageEntry messages) {
FormatCustomMessage(messages.english, iid);
FormatCustomMessage(messages.german, iid);
FormatCustomMessage(messages.french, iid);
const uint16_t textID = giid;
return InsertCustomMessage(tableID, textID, messages);
}

bool CustomMessage::CreateMessage(std::string tableID, uint16_t textID, CustomMessageEntry messages) {
bool CustomMessageManager::CreateMessage(std::string tableID, uint16_t textID, CustomMessageEntry messages) {
FormatCustomMessage(messages.english);
FormatCustomMessage(messages.german);
FormatCustomMessage(messages.french);
return InsertCustomMessage(tableID, textID, messages);
}

CustomMessageEntry CustomMessage::RetrieveMessage(std::string tableID, uint16_t textID) {
CustomMessageEntry CustomMessageManager::RetrieveMessage(std::string tableID, uint16_t textID) {
std::unordered_map<std::string, CustomMessageTable>::const_iterator result = messageTables.find(tableID);
if (result == messageTables.end()) {
return NULL_CUSTOM_MESSAGE;
Expand All @@ -111,7 +111,7 @@ CustomMessageEntry CustomMessage::RetrieveMessage(std::string tableID, uint16_t
return message;
}

bool CustomMessage::ClearMessageTable(std::string tableID) {
bool CustomMessageManager::ClearMessageTable(std::string tableID) {
auto result = messageTables.find(tableID);
if (result == messageTables.end()) {
return false;
Expand All @@ -120,31 +120,31 @@ bool CustomMessage::ClearMessageTable(std::string tableID) {
messageTable.clear();
}

bool CustomMessage::AddCustomMessageTable(std::string tableID) {
bool CustomMessageManager::AddCustomMessageTable(std::string tableID) {
CustomMessageTable newMessageTable;
return messageTables.emplace(tableID, newMessageTable).second;
}

std::string CustomMessage::MESSAGE_END() {
std::string CustomMessageManager::MESSAGE_END() {
return "\x02"s;
}

std::string CustomMessage::ITEM_OBTAINED(uint8_t x) {
std::string CustomMessageManager::ITEM_OBTAINED(uint8_t x) {
return "\x13"s + char(x);
}

std::string CustomMessage::NEWLINE() {
std::string CustomMessageManager::NEWLINE() {
return "\x01"s;
}

std::string CustomMessage::COLOR(uint8_t x) {
std::string CustomMessageManager::COLOR(uint8_t x) {
return "\x05"s + char(x);
}

std::string CustomMessage::WAIT_FOR_INPUT() {
std::string CustomMessageManager::WAIT_FOR_INPUT() {
return "\x04"s;
}

std::string CustomMessage::PLAYER_NAME() {
std::string CustomMessageManager::PLAYER_NAME() {
return "\x0F"s;
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ typedef struct {

typedef std::unordered_map<uint16_t, CustomMessageEntry> CustomMessageTable;

class CustomMessage {
class CustomMessageManager {
private:
std::unordered_map<std::string, char> textBoxSpecialCharacters;
std::unordered_map<std::string, char> colors;
Expand All @@ -56,10 +56,10 @@ class CustomMessage {
std::string PLAYER_NAME();

public:
static CustomMessage* Instance;
static CustomMessageManager* Instance;

CustomMessage();
~CustomMessage();
CustomMessageManager();
~CustomMessageManager();

bool CreateGetItemMessage(std::string tableID, GetItemID giid, ItemID iid, CustomMessageEntry messages);
bool CreateMessage(std::string tableID, uint16_t textID, CustomMessageEntry messages);
Expand Down
20 changes: 10 additions & 10 deletions soh/soh/Enhancements/randomizer/randomizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "3drando/rando_main.hpp"
#include <soh/Enhancements/debugger/ImGuiHelpers.h>
#include "Lib/ImGui/imgui_internal.h"
#include <soh/Enhancements/custom_message/CustomMessage.h>
#include <soh/Enhancements/custom_message/CustomMessageManager.h>

using json = nlohmann::json;
using namespace std::literals::string_literals;
Expand Down Expand Up @@ -1483,22 +1483,22 @@ void Randomizer::LoadHintLocations(const char* spoilerFileName) {
ParseHintLocationsFile(spoilerFileName);
}

CustomMessage::Instance->ClearMessageTable(Randomizer::hintMessageTableID);
CustomMessage::Instance->AddCustomMessageTable(Randomizer::hintMessageTableID);
CustomMessageManager::Instance->ClearMessageTable(Randomizer::hintMessageTableID);
CustomMessageManager::Instance->AddCustomMessageTable(Randomizer::hintMessageTableID);

CustomMessage::Instance->CreateMessage(
CustomMessageManager::Instance->CreateMessage(
Randomizer::hintMessageTableID, 0x7040,
{ TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, gSaveContext.childAltarText,
gSaveContext.childAltarText, gSaveContext.childAltarText });
CustomMessage::Instance->CreateMessage(
CustomMessageManager::Instance->CreateMessage(
Randomizer::hintMessageTableID, 0x7088,
{ TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, gSaveContext.adultAltarText,
gSaveContext.adultAltarText, gSaveContext.adultAltarText });
CustomMessage::Instance->CreateMessage(
CustomMessageManager::Instance->CreateMessage(
Randomizer::hintMessageTableID, 0x70CC,
{ TEXTBOX_TYPE_BLACK, TEXTBOX_POS_BOTTOM, gSaveContext.ganonHintText,
gSaveContext.ganonHintText, gSaveContext.ganonHintText });
CustomMessage::Instance->CreateMessage(
CustomMessageManager::Instance->CreateMessage(
Randomizer::hintMessageTableID, 0x70CD,
{ TEXTBOX_TYPE_BLACK, TEXTBOX_POS_BOTTOM, gSaveContext.ganonText,
gSaveContext.ganonText, gSaveContext.ganonText });
Expand All @@ -1511,7 +1511,7 @@ void Randomizer::LoadHintLocations(const char* spoilerFileName) {
for (auto hintLocation : gSaveContext.hintLocations) {
if(hintLocation.check == RC_LINKS_POCKET) break;
this->hintLocations[hintLocation.check] = hintLocation.hintText;
CustomMessage::Instance->CreateMessage(
CustomMessageManager::Instance->CreateMessage(
Randomizer::hintMessageTableID, hintLocation.check, { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, hintLocation.hintText, hintLocation.hintText, hintLocation.hintText });
}
}
Expand Down Expand Up @@ -4750,7 +4750,7 @@ typedef struct {
} GetItemMessage;

void CreateGetItemMessages(std::vector<GetItemMessage> messageEntries) {
CustomMessage* customMessage = CustomMessage::Instance;
CustomMessageManager* customMessage = CustomMessageManager::Instance;
customMessage->AddCustomMessageTable(Randomizer::getItemMessageTableID);
for (GetItemMessage messageEntry : messageEntries) {
customMessage->CreateGetItemMessage(Randomizer::getItemMessageTableID, messageEntry.giid, messageEntry.iid,
Expand All @@ -4761,7 +4761,7 @@ void CreateGetItemMessages(std::vector<GetItemMessage> messageEntries) {
}

void CreateScrubMessages() {
CustomMessage* customMessage = CustomMessage::Instance;
CustomMessageManager* customMessage = CustomMessageManager::Instance;
customMessage->AddCustomMessageTable(Randomizer::scrubMessageTableID);
const std::vector<u8> prices = { 10, 40 };
for (u8 price : prices) {
Expand Down
22 changes: 11 additions & 11 deletions soh/soh/OTRGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#include "variables.h"
#include "macros.h"
#include <Utils/StringHelper.h>
#include <soh/Enhancements/custom_message/CustomMessage.h>
#include <soh/Enhancements/custom_message/CustomMessageManager.h>

#ifdef __APPLE__
#include <SDL_scancode.h>
Expand All @@ -59,7 +59,7 @@

OTRGlobals* OTRGlobals::Instance;
SaveManager* SaveManager::Instance;
CustomMessage* CustomMessage::Instance;
CustomMessageManager* CustomMessageManager::Instance;

OTRGlobals::OTRGlobals() {
context = Ship::GlobalCtx2::CreateInstance("Ship of Harkinian");
Expand Down Expand Up @@ -114,7 +114,7 @@ extern "C" void InitOTR() {
#endif
OTRGlobals::Instance = new OTRGlobals();
SaveManager::Instance = new SaveManager();
CustomMessage::Instance = new CustomMessage();
CustomMessageManager::Instance = new CustomMessageManager();
auto t = OTRGlobals::Instance->context->GetResourceManager()->LoadFile("version");

if (!t->bHasLoadError)
Expand Down Expand Up @@ -1420,7 +1420,7 @@ extern "C" CustomMessageEntry Randomizer_CopyScrubMessage(u16 scrubTextId) {
price = 40;
break;
}
return CustomMessage::Instance->RetrieveMessage(Randomizer::scrubMessageTableID, price);
return CustomMessageManager::Instance->RetrieveMessage(Randomizer::scrubMessageTableID, price);
}

extern "C" int CopyScrubMessage(u16 scrubTextId, char* buffer, const int maxBufferSize) {
Expand Down Expand Up @@ -1496,22 +1496,22 @@ extern "C" int CopyScrubMessage(u16 scrubTextId, char* buffer, const int maxBuff
}

extern "C" CustomMessageEntry Randomizer_CopyAltarMessage() {
return (LINK_IS_ADULT) ? CustomMessage::Instance->RetrieveMessage(Randomizer::hintMessageTableID, 0x7088)
: CustomMessage::Instance->RetrieveMessage(Randomizer::hintMessageTableID, 0x7040);
return (LINK_IS_ADULT) ? CustomMessageManager::Instance->RetrieveMessage(Randomizer::hintMessageTableID, 0x7088)
: CustomMessageManager::Instance->RetrieveMessage(Randomizer::hintMessageTableID, 0x7040);
}

extern "C" CustomMessageEntry Randomizer_CopyGanonText() {
return CustomMessage::Instance->RetrieveMessage(Randomizer::hintMessageTableID, 0x70CD);
return CustomMessageManager::Instance->RetrieveMessage(Randomizer::hintMessageTableID, 0x70CD);
}

extern "C" CustomMessageEntry Randomizer_CopyGanonHintText() {
return CustomMessage::Instance->RetrieveMessage(Randomizer::hintMessageTableID, 0x70CC);
return CustomMessageManager::Instance->RetrieveMessage(Randomizer::hintMessageTableID, 0x70CC);
}

extern "C" CustomMessageEntry Randomizer_CopyHintFromCheck(RandomizerCheck check) {
// we don't want to make a copy of the std::string returned from GetHintFromCheck
// so we're just going to let RVO take care of it
const CustomMessageEntry hintText = CustomMessage::Instance->RetrieveMessage(Randomizer::hintMessageTableID, check);
const CustomMessageEntry hintText = CustomMessageManager::Instance->RetrieveMessage(Randomizer::hintMessageTableID, check);
return hintText;
}

Expand All @@ -1524,7 +1524,7 @@ extern "C" s32 Randomizer_GetItemIdFromKnownCheck(RandomizerCheck randomizerChec
}

extern "C" CustomMessageEntry Randomizer_GetCustomGetItemMessage(GetItemID giid, char* buffer, const int maxBufferSize) {
const CustomMessageEntry getItemText = CustomMessage::Instance->RetrieveMessage(Randomizer::getItemMessageTableID, giid);
const CustomMessageEntry getItemText = CustomMessageManager::Instance->RetrieveMessage(Randomizer::getItemMessageTableID, giid);
return getItemText;
}

Expand Down Expand Up @@ -1588,7 +1588,7 @@ extern "C" int CustomMessage_RetrieveIfExists(GlobalContext* globalCtx) {
} else {
textId = 0x00B5;
}
messageEntry = CustomMessage::Instance->RetrieveMessage("BaseGameOverrides", textId);
messageEntry = CustomMessageManager::Instance->RetrieveMessage("BaseGameOverrides", textId);
}
}
if (messageEntry.textBoxType != -1) {
Expand Down
16 changes: 8 additions & 8 deletions soh/soh/z_message_OTR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "global.h"
#include "vt.h"
#include <Text.h>
#include <soh/Enhancements/custom_message/CustomMessage.h>
#include <soh/Enhancements/custom_message/CustomMessageManager.h>

extern "C" MessageTableEntry* sNesMessageEntryTablePtr;
extern "C" MessageTableEntry* sGerMessageEntryTablePtr;
Expand Down Expand Up @@ -95,21 +95,21 @@ extern "C" void OTRMessage_Init()
sStaffMessageEntryTablePtr[i].msgSize = file2->messages[i].msg.size();
}

CustomMessage::Instance->AddCustomMessageTable(customMessageTableID);
CustomMessage::Instance->CreateGetItemMessage(
CustomMessageManager::Instance->AddCustomMessageTable(customMessageTableID);
CustomMessageManager::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"
"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(
CustomMessageManager::Instance->CreateGetItemMessage(
customMessageTableID, (GetItemID)0x00B5, 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!",
"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!" });
"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!" });
}

0 comments on commit 8224763

Please sign in to comment.