forked from HarbourMasters/Shipwright
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactors CustomMessages to not be rando specific.
Pulls the Custom Message related code out into it's own class, which has an initialization phase where other enhancements / future features can create messages during an initialization phase to be stored and retrieved later. Along with this refactoring, the 4 bottle messages from the previous rando-specific system are now created and stored during intialization and retrieved by their getItemId. Now that it isn't rando specific, the goal is to move anything text changes that are hard-coded into z_message_PAL.c and refactor it so that future text additions/overrides can be done without modifying that file.
- Loading branch information
1 parent
3f2111a
commit 4eaf70b
Showing
10 changed files
with
182 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#include "CustomMessage.h" | ||
#include <algorithm> | ||
|
||
using namespace std::literals::string_literals; | ||
|
||
CustomMessage::CustomMessage() { | ||
this->textBoxSpecialCharacters = { { "À", 0x80 }, { "î", 0x81 }, { "Â", 0x82 }, { "Ä", 0x83 }, { "Ç", 0x84 }, | ||
{ "È", 0x85 }, { "É", 0x86 }, { "Ê", 0x87 }, { "Ë", 0x88 }, { "Ï", 0x89 }, | ||
{ "Ô", 0x8A }, { "Ö", 0x8B }, { "Ù", 0x8C }, { "Û", 0x8D }, { "Ü", 0x8E }, | ||
{ "ß", 0x8F }, { "à", 0x90 }, { "á", 0x91 }, { "â", 0x92 }, { "ä", 0x93 }, | ||
{ "ç", 0x94 }, { "è", 0x95 }, { "é", 0x96 }, { "ê", 0x97 }, { "ë", 0x98 }, | ||
{ "ï", 0x99 }, { "ô", 0x9A }, { "ö", 0x9B }, { "ù", 0x9C }, { "û", 0x9D }, | ||
{ "ü", 0x9E } }; | ||
this->colors = { { "w", QM_WHITE }, { "r", QM_RED }, { "g", QM_GREEN }, { "b", QM_BLUE }, | ||
{ "c", QM_LBLUE }, { "p", QM_PINK }, { "y", QM_YELLOW }, { "B", QM_BLACK } }; | ||
} | ||
|
||
CustomMessage::~CustomMessage() { | ||
this->textBoxSpecialCharacters.clear(); | ||
} | ||
|
||
void CustomMessage::ReplaceSpecialCharacters(std::string& string) { | ||
// add special characters | ||
for (auto specialCharacterPair : textBoxSpecialCharacters) { | ||
size_t start_pos = 0; | ||
std::string textBoxSpecialCharacterString = ""; | ||
textBoxSpecialCharacterString += specialCharacterPair.second; | ||
while ((start_pos = string.find(specialCharacterPair.first, start_pos)) != std::string::npos) { | ||
string.replace(start_pos, specialCharacterPair.first.length(), textBoxSpecialCharacterString); | ||
start_pos += textBoxSpecialCharacterString.length(); | ||
} | ||
} | ||
} | ||
|
||
void CustomMessage::ReplaceColors(std::string& string) { | ||
for (auto colorPair : colors) { | ||
std::string textToReplace = "%"; | ||
textToReplace += colorPair.first; | ||
size_t start_pos = 0; | ||
while ((start_pos = string.find(textToReplace)) != std::string::npos) { | ||
string.replace(start_pos, textToReplace.length(), COLOR(colorPair.second)); | ||
start_pos += textToReplace.length(); | ||
} | ||
} | ||
} | ||
|
||
void CustomMessage::CreateGetItemMessage(GetItemID giid, ItemID iid, std::string messages[LANGUAGE_MAX]) { | ||
for (int i = 0; i < LANGUAGE_MAX; i++) { | ||
if (!(messages[i].empty())) { | ||
std::string message = messages[i]; | ||
std::string formattedMessage = ITEM_OBTAINED(iid) + message; | ||
size_t start_pos = 0; | ||
std::replace(formattedMessage.begin(), formattedMessage.end(), '&', NEWLINE()[0]); | ||
while ((start_pos = formattedMessage.find('^', start_pos)) != std::string::npos) { | ||
formattedMessage.replace(start_pos, 1, WAIT_FOR_INPUT() + ITEM_OBTAINED(iid)); | ||
start_pos += 3; | ||
} | ||
std::replace(formattedMessage.begin(), formattedMessage.end(), '@', PLAYER_NAME()[0]); | ||
ReplaceSpecialCharacters(formattedMessage); | ||
ReplaceColors(formattedMessage); | ||
formattedMessage += MESSAGE_END(); | ||
this->getItemMessageTable[i].emplace(giid, formattedMessage); | ||
} else { | ||
this->getItemMessageTable[i].emplace(giid, MESSAGE_END()); | ||
} | ||
} | ||
} | ||
|
||
std::string CustomMessage::RetrieveGetItemMessage(GetItemID giid) { | ||
std::unordered_map<GetItemID, std::string>::const_iterator result = | ||
getItemMessageTable[gSaveContext.language].find(giid); | ||
if (result == getItemMessageTable[gSaveContext.language].end()) { | ||
switch (gSaveContext.language) { | ||
case LANGUAGE_FRA: | ||
return "Il n'y a pas de message personnalisé pour cet élément."; | ||
case LANGUAGE_GER: | ||
return "Für diesen Artikel gibt es keine benutzerdefinierte Nachricht."; | ||
case LANGUAGE_ENG: | ||
default: | ||
return "There is no custom message for this item."; | ||
} | ||
} | ||
return result->second; | ||
} | ||
|
||
std::string CustomMessage::MESSAGE_END() { | ||
return "\x02"s; | ||
} | ||
|
||
std::string CustomMessage::ITEM_OBTAINED(uint8_t x) { | ||
return "\x13"s + char(x); | ||
} | ||
|
||
std::string CustomMessage::NEWLINE() { | ||
return "\x01"s; | ||
} | ||
|
||
std::string CustomMessage::COLOR(uint8_t x) { | ||
return "\x05"s + char(x); | ||
} | ||
|
||
std::string CustomMessage::WAIT_FOR_INPUT() { | ||
return "\x04"s; | ||
} | ||
|
||
std::string CustomMessage::PLAYER_NAME() { | ||
return "\x0F"s; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#pragma once | ||
#include <string> | ||
#include <unordered_map> | ||
#include "variables.h" | ||
|
||
#define QM_WHITE 0x00 | ||
#define QM_RED 0x41 | ||
#define QM_GREEN 0x42 | ||
#define QM_BLUE 0x43 | ||
#define QM_LBLUE 0x44 | ||
#define QM_PINK 0x45 | ||
#define QM_YELLOW 0x46 | ||
#define QM_BLACK 0x47 | ||
|
||
class CustomMessage { | ||
private: | ||
std::unordered_map<std::string, char> textBoxSpecialCharacters; | ||
std::unordered_map<std::string, char> colors; | ||
std::unordered_map<GetItemID, std::string> getItemMessageTable[LANGUAGE_MAX]; | ||
|
||
void ReplaceSpecialCharacters(std::string &string); | ||
void ReplaceColors(std::string& string); | ||
|
||
std::string MESSAGE_END(); | ||
std::string ITEM_OBTAINED(uint8_t x); | ||
std::string NEWLINE(); | ||
std::string COLOR(uint8_t x); | ||
std::string WAIT_FOR_INPUT(); | ||
std::string PLAYER_NAME(); | ||
|
||
public: | ||
static CustomMessage* Instance; | ||
|
||
CustomMessage(); | ||
~CustomMessage(); | ||
|
||
void CreateGetItemMessage(GetItemID giid, ItemID iid, std::string messages[LANGUAGE_MAX]); | ||
std::string RetrieveGetItemMessage(GetItemID giid); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 23 additions & 44 deletions
67
soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,33 @@ | ||
#include "randomizer_custom_messages.h" | ||
#include "randomizer.h" | ||
#include <variables.h> | ||
#include "soh/Enhancements/custom_message/CustomMessage.h" | ||
|
||
using namespace std::literals::string_literals; | ||
|
||
std::string Randomizer::GetCustomGetItemMessage(GetItemID giid) { | ||
if (!gSaveContext.n64ddFlag) { | ||
return "Not Randomized."; | ||
} | ||
#define MESSAGES(eng, ger, fra) (new std::string[]{eng, ger, fra}) | ||
|
||
void Randomizer::CreateCustomMessages() { | ||
CustomMessage* customMessage = CustomMessage::Instance; | ||
customMessage->CreateGetItemMessage( | ||
GI_BOTTLE_WITH_BLUE_FIRE, ITEM_BLUE_FIRE, | ||
MESSAGES("You got a %rBottle with Blue &Fire%w! Use it to melt Red Ice!", "", "")); | ||
customMessage->CreateGetItemMessage( | ||
GI_BOTTLE_WITH_BIG_POE, ITEM_BIG_POE, | ||
MESSAGES("You got a %rBig Poe in a bottle%w!&Sell it to the Ghost Shop!", "", "")); | ||
customMessage->CreateGetItemMessage( | ||
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!", "", "")); | ||
customMessage->CreateGetItemMessage( | ||
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!", "", | ||
"")); | ||
|
||
switch (giid) { | ||
case GI_BOTTLE_WITH_BLUE_FIRE: | ||
switch (gSaveContext.language) { | ||
case LANGUAGE_FRA: | ||
case LANGUAGE_GER: | ||
case LANGUAGE_ENG: | ||
default: | ||
return ITEM_OBTAINED(ITEM_BLUE_FIRE) + "You got a " + COLOR(QM_RED) + "Bottle with Blue " + | ||
NEWLINE() + "Fire" + COLOR(QM_WHITE) + "! Use it to melt Red Ice!" + | ||
MESSAGE_END(); | ||
} | ||
default: | ||
switch (gSaveContext.language) { | ||
case LANGUAGE_FRA: | ||
return "Il n'y a pas de message personnalisé pour cet élément."; | ||
case LANGUAGE_GER: | ||
return "Für diesen Artikel gibt es keine benutzerdefinierte Nachricht."; | ||
case LANGUAGE_ENG: | ||
default: | ||
return "There is no custom message for this item."; | ||
} | ||
} | ||
} | ||
|
||
std::string MESSAGE_END() { | ||
return "\x02"s; | ||
} | ||
|
||
std::string ITEM_OBTAINED(uint8_t x) { | ||
return "\x13"s + char(x); | ||
} | ||
|
||
std::string NEWLINE() { | ||
return "\x01"s; | ||
} | ||
|
||
std::string COLOR(uint8_t x) { | ||
return "\x05"s + char(x); | ||
} | ||
std::string Randomizer::GetCustomGetItemMessage(GetItemID giid) { | ||
if (!gSaveContext.n64ddFlag) { | ||
return "Not Randomized."; | ||
} | ||
|
||
std::string WAIT_FOR_INPUT() { | ||
return "\x04"s; | ||
return CustomMessage::Instance->RetrieveGetItemMessage(giid); | ||
} |
19 changes: 0 additions & 19 deletions
19
soh/soh/Enhancements/randomizer/randomizer_custom_messages.h
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters