Shipwright/soh/soh/Enhancements/custom-message/CustomMessageManager.h

110 lines
3.6 KiB
C
Raw Normal View History

#pragma once
#include <string>
#include <unordered_map>
2022-08-08 21:14:29 -04:00
#include "../../../include/z64item.h"
Randomizer v2 (#1065) * Revert changes to GetItemFromGet * Fixes Ganon's Boss Key shuffled while regular boss Keys aren't. * Enum + combo box * Add obtainability checks correctly * combobox title rename + no number tracking * Fix repeatable purchases and bottles rendering incorrectly * Move shopsanity option in GUI * Struct instead of ImVec + basic comportment for all case * Attempt to fix odd build issue * Cast randoGet for ganons boss key * Remove redundancy in KD room * Update logic Cvar names * Fix Ganons Trials coming from old save files. Fixes #1365 * Fixes crash when entering Ganon's Castle lobby on linux. * Makes `Item_Give` safe to use with a NULL globalCtx. This should allow it's use for giving items to Link's Pocket during rando save initialization. * Converts Song from Impa to use `Item_Give` * Adds more options for Link's starting item. * Removes unneeded `GiveLinkItem` functions. * and make it build * bring back new rando dropdown * gSaveContext access in GameMenuBar.cpp * Implement Skip Scarecrow's Song * Reimplement progressive Bombchus * Rando-next: Deku Nut and Seed ammo gives a blue rupee Fixes #1390 * Fixes Link starting with BGS * Persist item tracker notes * Adjust Hooks include * Use SohImGui::RequestCvarSaveOnNextTick * Fix issues from LUS refactor * Fix for overriding deku scrub messages * Fix mistake from merge oops * Restore checkboxes to enhancements menu These got lost in the merge * Update location access logic Including MQ locations in Spirit and GC now * Implement rando bombchu drops * Missing break * Simplify mudwall collision check There was no need to have a second collider specifically for Ice Arrow hits * Update settings.cpp * Simplify mudwall collision check * Restore checkboxes in menu Accidentally lost these during merge * Clean up bool * Update logic Cvar name * Fixed capacity on ammmo tracking * Fix for beans obtainability * Hook into file delete and clear notes * Incorporate magic arrows in rando settings * Update tooltip To inform the player that they might have to reload the room if they're enabling this for the first time. * Update tooltip * Add line break in tooltip * Tooltip wording + line break * tweak on main logic * All color logic for all types * Fix: changes to please new LUS * Ensure itemTrackerNotes vector is not fully empty * Implement's Tycoon Wallet. * Refactor DrawItemCount and Use EnhancementCombobox for tracker capacity options * small tweaks and rename * always display XX/YY when in ammo/capacity mode * Move all merchant messages to be generated on file load * added hovertext for the number display * Swap german and french translations for shop messages * Set key colors to be on by default * Add another flag to skip mask shop * Fix Sold Out bug * Fix gerudo keys, add disabled checkbox * tooltip line break * Add trials required and merchant prices to save file instead of loading from active spoiler log * Remove trialsRequired persisting in save manager * Adds slotIndex to girla (shop item actor) and uses that for IdentifyShopItem. * Fix issue when merchantPrices is empty * Fix for a single zeroed merchantPrice entry * Fix #1417 * Implements items selling out and fixes issues with purchasing some items. * Fixes order of operations so Rupees will be spent. * Fixes sold out items not getting overwritten by the randomized info. * Clarify var names and comments Also preserve chain platform cutscene in spirit based on Link's position * Remove !=0 from cvar check * Clarify var names and comments * Rename randomizerMerchantPrices to merchantPrices * Handle shop items in SaveManager * Fix merge mistake * Base whats in the bazaar shop on entranceIndex instead of age * Tidy up chain platform cutscene check * Fix merge error Didn't mean to have Zhora changes in here yet * Use 3drando item table for parsing spoiler names * Use another nested method instead of one at the top level to fetch the table * Add missing newline * Remove log * Respect custom draw functions * Fix issues with rendering songs * Fix localized item names for shopsanity * Implements a larger array of Sprites for the Icon Hash. * Uses the hash instead of seed for spoilerfile name and icons. * Removes some unused functions and variables in `spoiler_log.cpp` * Prevents leading 0s added to hash from being in file name * Changes filename format to icon indexes separated by dashes * Hopefully makes Jenkins happy * Hopefully makes Jenkins happy * [Rando] Child Gerudo Fortress 37th Heartpiece randomized Fixes #1071 * Add descriptions to save editor flags editor, and added randomizer flags (#1386) * Add descriptions to save editor flags editor, and added randomizer flags * Hide randomizer flags when not on a randomizer save * Move flag descriptions to header file * Update soh/soh/Enhancements/debugger/debugSaveEditor.h * Update soh/soh/Enhancements/debugger/debugSaveEditor.h * Fix merge error * crash on pause menu on linux (only in appimage) Fixes #1437 * Applies fix to Song from Impa as well. * Allow buying tunics as child when shopsanity is on * Fix for custom draw methods overriding sold out sign * Simplify logic around shopsanity and fix some issues * Fix dungeon reward stone rotation and add particles * Fix some issues with ice traps * Fix adult wallet having its own max capacity * Fix amount of keys given for BotW * format * Use EnGirlAShopItem enum instead of raw hex values * [#1434] Renders non-warp songs more consistently with warp songs * A few changes around merchant messages * Various changes from PR feedback * Rando: Junk Hint missing french translation * Typo * Fix free scrub being at 0 instead of TEXT_SCRUB_RANDOM * Replace magic numbers in message handler * Update soh/src/overlays/actors/ovl_En_Ossan/z_en_ossan.c Co-authored-by: briaguya <70942617+briaguya-ai@users.noreply.github.com> * Update soh/src/overlays/actors/ovl_En_Ossan/z_en_ossan.c Co-authored-by: briaguya <70942617+briaguya-ai@users.noreply.github.com> * Fix BGS softlock for shopsanity * Support tycoon wallet on tracker * Revert "Fix BGS softlock for shopsanity" This reverts commit 5fdb961ea460fb9a035cf0bb6ae77bfeedc1de0f. * [#1053] Resolves an issue with shop items and bombchu bowling where BGS would display two message boxes * Implements some necessary plumbing and resolves several Ice Trap Softlocks. Adds a way for an item entry to tell what type of check it came from (NPC vs Chest vs Freestanding, etc.) Sets this value from chests and item00 actors. Relocates pendingIceTraps to save context so it can persist through cutscenes and get stored on save init for Link's Pocket and Song from Impa. Restructures pendingIceTraps into a counter rather than a true or false, so that we can be frozen multiple times in a row if applicable (atm that should only be at the start of a run if Link's Pocket and Song from Impa were both Ice Traps). Adds a textbox for Ice Traps and a special case of holding up nothing in the get item process. This fixes all the cases where Ice Traps would softlock due to the actor giving the item expecting a closing textbox. After holding the item above his head Link increments the pendingIceTraps counter by one and sets whatever flag he has pending. None of the above plumbing applies to Ice Traps from chests, those work exactly the same as before, as do freestanding item00 ice traps (thanks to the additional check for ITEM_FROM_FREESTANDING. OoT and Ruto's Letter count as NPC's, so they get the FOWL text box and set a pending ice trap rather than immediately freezing, since Link weill be in the water. Link will get frozen the next time he touches land, which in the case of OoT is after the fade to white and right before the Song of Time check. Fixes all the other softlocks I'm aware of, including Fishing, Bombchu Bowling, Skull Kid, and losing the second Gerudo Archery check. * fix bgs check in player * move bgs logic for tokensanity into MOD_NONE check * set bgs flag before `Item_Give`ing * move bgs flag into `MOD_NONE` check in girla * use existing check in `z_player` * Adds comment explaining the decision to default ITEM_FROM_NPC. * Rename pendingIceTraps to pendingIceTrapCount * Adds some RANDOTODO comments about cleaning up a couple things. * Merge branch 'develop-zhora' into ztornn * manually restore changes to `z_player.c` * Fix after some ice trap prepwork from earlier * Actual fix * Woops * More rupee names * Actually fix it * Add back comment * Fix Skip Scarecrow Song * Fix ruto's letter and LH sun stick rendering * Also fixes it for treasure chest game * Tweak: Rando French Wallet * ADD: French Tycoon * Hide dungeon items/notes by default * [#1301] Fix issue with UI not restoring after getting an item from biggoron * Update soh/src/overlays/actors/ovl_En_Go2/z_en_go2.c * Update soh/src/overlays/actors/ovl_En_Go2/z_en_go2.c * Fix random crash that only affected one person for some reason Co-authored-by: Garrett Cox <garrettjcox@gmail.com> Co-authored-by: Christopher Leggett <chris@leggett.dev> Co-authored-by: PurpleHato <linkvssangoku.jr@gmail.com> Co-authored-by: Sarge-117 <adam_branston@outlook.com> Co-authored-by: briaguya <briaguya@alice> Co-authored-by: aMannus <mannusmenting@gmail.com> Co-authored-by: lil David <1337lilDavid@gmail.com> Co-authored-by: Sarge-117 <108380086+Sarge-117@users.noreply.github.com> Co-authored-by: louist103 <35883445+louist103@users.noreply.github.com>
2022-09-21 00:50:22 -04:00
#include "../../../include/message_data_textbox_types.h"
#undef MESSAGE_END
#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
typedef struct {
TextBoxType textBoxType;
TextBoxPosition textBoxPos;
std::string english;
std::string german;
std::string french;
} CustomMessageEntry;
// Message Entry without the text type and position, useful for when
// you need an array of these to loop over for registration
// that will all have the same textbox type and position.
typedef struct {
std::string english;
std::string german;
std::string french;
} CustomMessageMinimal;
#define NULL_CUSTOM_MESSAGE \
{ (TextBoxType)(-1), (TextBoxPosition)(-1), "", "", "" }
typedef std::unordered_map<uint16_t, CustomMessageEntry> CustomMessageTable;
class CustomMessageManager {
private:
std::unordered_map<std::string, char> textBoxSpecialCharacters;
std::unordered_map<std::string, char> colors;
std::unordered_map<std::string, CustomMessageTable> messageTables;
void ReplaceSpecialCharacters(std::string &string);
void ReplaceColors(std::string& string);
bool InsertCustomMessage(std::string tableID, uint16_t textID, CustomMessageEntry messages);
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 CustomMessageManager* Instance;
CustomMessageManager();
~CustomMessageManager();
/*
Formats the provided Custom Message Entry and inserts it into the table with the provided tableID,
with the provided giid (getItemID) as its key. This function also inserts the icon corresponding to
the provided iid (itemID) at the beginning of each page of the textbox.
*/
Rework Get Item Table to be more flexible for adding custom items (#1050) * Adds ItemTableManager class. * Implements new getItem table in game. * Adds rando item table and way to differentiate tables in GetItemEntry. * Adds rough ability to differentiate between rando and vanilla items.merge stashed changes from before develop-zhora merge * Change ItemTableID to be uint16_t so we can use ModIndex for it. * Should fix switch build * Should fix switch build pt 2 * Adds new files to CMakeLists. * Implements fixes for competing getItem calls. * Correctly renders freestanding items Particle effects are probably broken, need to fix them still, I pretty much know how I would do that. * Fixed Particle effects in the new getItem system. * Fixes item fanfares * Partially fixes Ice Traps Obtaining a freestanding Ice Trap causes link to slide forward and receiving one from an NPC plays the sound effect and damage animation but doesn't freeze link. * Some more partial ice trap fixing that wasn't pushed earlier * Removes unused function override * Replaces ::find with ::at and adds exception handling * Removes some commented out code. * Refactors rando's GetItemEntry array into two arrays. One array is for the vanilla items that don't have GetItemEntries in vanilla, the other is for rando exclusive items. They are stored in separate arrays before getting added to the table so that we can apply different modIndexes. The items in the first table have are handled by the vanilla Item_Give, and the second table needed a custom `Randomizer_Item_Give` function. * Renames, relocates, and implements ModIndex enum. * Removes now unused ItemIDs and GetItemIDs Also makes all the necessary changes to other code that was still using them indirectly through the GI to GID map that was removed. There's quite a lot of changes here and I haven't had time to test them yet. * Re-implements GIMESSAGE_UNTRANSLATED as macro * Removes commented out function. * Throws exception if an invalid itemID is used Addresses https://github.com/HarbourMasters/Shipwright/pull/1050#discussion_r943694857 * Removes ARRAY_SIZE in favor of ARRAY_COUNT ARRAY_COUNT already exists in `macros.h`, I just didn't find it before. Addresses https://github.com/HarbourMasters/Shipwright/pull/1050#discussion_r943153833 * Inverts CheckContainsRandoItem to CheckContainsVanillaItem. Addresses https://github.com/HarbourMasters/Shipwright/pull/1050#discussion_r940895135 * Cleanup, bugfixes, removing the `- 1`s from `z_player.c` * Fixes some funky formatting that got committed earlier. * Adds else if to added fanfare sound cases. Addresses https://github.com/HarbourMasters/Shipwright/pull/1050#discussion_r940112924 and https://github.com/HarbourMasters/Shipwright/pull/1050#discussion_r940113492 * Extends GetItemEntry to include getItemId Also adapts some existing calls for both the entry and the id to only get the entry. * Extends GetItemEntry to include GID. This allows for using it later when drawing freestanding items. Addresses https://github.com/HarbourMasters/Shipwright/pull/1050#discussion_r943168136 * Rando-specific items use new textId again. This got lost when merging develop-zhora in because I didn't have custom messages merged when I started this. * Sets global modIndex to MOD_NONE on scene load Fixes a crash when buying items in shops due to them not triggering the rando code that normally sets these items. May have also been crashing vanilla playthroughs. * Realized I had the bgm conditions wrong. * Fixes "static drops" (i.e. sticks from withered babas) * Fixes LACS/Prelude situation... again. * Fixes too many arguments error. Not sure why this didn't fail to build on Windows before. * Fixes Link's Pocket items. * Simplifies sram init for rando-specific items * Fixes issues with approaching bottleable items. * Fixes Ruto's Letter. It was accidentally getting classified as a rando item. * Should re-fix freestanding ice traps * Makes freestanding items set player->getItemEntry. This prevents freestanding items from setting the global modIndex. This is part of a larger transition that needs to happen to switch to setting getItemEntries for all of the rando items. This prevents some things that set getItemId of GI_MAX from granting a Fire Medallion when the global modIndex is MOD_RANDOMIZER. * Makes sure we aren't using getItemEntry when not randoed. * Replace Randomizer_GetRandomizedItemId with Randomizer_GetRandomizedItem and Randomizer_GetItemIdFromKnownCheck with Randomizer_GetItemFromKnownCheck * Introduce some new methods and migrate most actors to them * Fixes ocarina game skull kids to set player->getItemEntry * Sets `z_en_box.c` to set `player->getItemEntry` * Fix logical errors and migrate most of the rest of the rando checks to GiveItemEntryFromActor * Use GiveItemEntryFromActorWithFixedRange in item00 * Fixes Anju to set player->getItemEntry. * Add a few missing cases * Additional fix for Skull Kid * Fixes vanilla ice traps and randomized ice smoke * Fixes rendering of treasure chest game items. * Removes unused `Randomizer_GetItemIdFromGetItemId`. * Cleans up an if statement for item00. * Cleans up another if statement in item00 * This should fix a bug with the Gerudo Archery minigame. I wasn't able to get the bug to happen after making this change. * Documents our new GiveItemEntry fuctions. * Uses more descriptive type name for ItemIDs for creating custom messages. * Fixes potential issue with if statement. * Fixes missed type change. Co-authored-by: Garrett Cox <garrettjcox@gmail.com>
2022-08-23 20:11:38 -04:00
bool CreateGetItemMessage(std::string tableID, uint16_t giid, ItemID iid, CustomMessageEntry messages);
/*
Formats the provided Custom Message Entry and inserts it into the table with the provided tableID,
with the provided textID as its key.
*/
bool CreateMessage(std::string tableID, uint16_t textID, CustomMessageEntry messages);
/*
Retrieves a message from the table with id tableID with the provided textID.
Returns a NULL_CUSTOM_MESSAGE if the message or table does not exist.
*/
CustomMessageEntry RetrieveMessage(std::string tableID, uint16_t textID);
/*
Empties out the message table identified by tableID.
Returns true if successful and false if not (for instance
if a table with the provided tableID does not exist).
*/
bool ClearMessageTable(std::string tableID);
/*
Creates an empty CustomMessageTable accessible at the provided
tableID, returns true if creation was successful and false
if not.
*/
bool AddCustomMessageTable(std::string tableID);
/*
Replaces special characters and certain symbols with control codes
& for newline, ^ for wait-for-input, and @ for the player name,
as well as %<letter> for colors (i.e. %r for red and %w for white).
*/
void FormatCustomMessage(std::string& message, ItemID iid);
/*
Replaces special characters and certain symbols with control codes
& for newline, ^ for wait-for-input, and @ for the player name,
as well as %<letter> for colors (i.e. %r for red and %w for white).
*/
void FormatCustomMessage(std::string& message);
};