Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce in-game Randomizer Settings menu, remove plando mode #4804

Merged
merged 9 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions soh/include/z64.h
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,9 @@ typedef struct {
uint8_t bossRushOffset;
int16_t bossRushUIAlpha;
uint16_t bossRushArrowOffset;
uint8_t randomizerIndex;
int16_t randomizerUIAlpha;
uint16_t randomizerArrowOffset;
} FileChooseContext; // size = 0x1CAE0

// Macros for `EntranceInfo.field`
Expand Down
69 changes: 69 additions & 0 deletions soh/soh/Enhancements/FileSelectEnhancements.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include "FileSelectEnhancements.h"

#include "soh/OTRGlobals.h"

#include <array>
#include <string>
#include <vector>

std::array<std::string, LANGUAGE_MAX> RandomizerSettingsMenuText[RSM_MAX] = {
{
// English
"Start Randomizer",
// German
"Start Randomizer",
// French
"Start Randomizer",
},
{
// English
"Generate New Randomizer Seed",
// German
"Generate New Randomizer Seed",
// French
"Generate New Randomizer Seed",
},
{
// English
"Open Randomizer Settings",
// German
"Open Randomizer Settings",
// French
"Open Randomizer Settings",
},
{
// English
"Generating...",
// German
"Generating...",
// French
"Generating...",
},
{
// English
"No randomizer seed loaded.\nPlease generate one first"
#if defined(__WIIU__) || defined(__SWITCH__)
".",
#else
",\nor drop a spoiler log on the game window.",
#endif
// German
"No randomizer seed loaded.\nPlease generate one first"
#if defined(__WIIU__) || defined(__SWITCH__)
".",
#else
",\nor drop a spoiler log on the game window.",
#endif
// French
"Aucune Seed de Randomizer actuellement disponible.\nGénérez-en une dans les \"Randomizer Settings\""
#if (defined(__WIIU__) || defined(__SWITCH__))
"."
#else
"\nou glissez un spoilerlog sur la fenêtre du jeu."
#endif
},
};

const char* SohFileSelect_GetSettingText(uint8_t optionIndex, uint8_t language) {
return RandomizerSettingsMenuText[optionIndex][language].c_str();
}
23 changes: 23 additions & 0 deletions soh/soh/Enhancements/FileSelectEnhancements.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef FILE_SELECT_ENHANCEMENTS_H
#define FILE_SELECT_ENHANCEMENTS_H

#include "z64.h"

#ifdef __cplusplus
extern "C" {
#endif
const char* SohFileSelect_GetSettingText(u8 optionIndex, u8 language);
#ifdef __cplusplus
};
#endif

typedef enum {
RSM_START_RANDOMIZER,
RSM_GENERATE_RANDOMIZER,
RSM_OPEN_RANDOMIZER_SETTINGS,
RSM_GENERATING,
RSM_NO_RANDOMIZER_GENERATED,
RSM_MAX,
} RandomizerSettingsMenuEnums;

#endif
1 change: 0 additions & 1 deletion soh/soh/Enhancements/randomizer/3drando/rando_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ void RandoMain::GenerateRando(std::set<RandomizerCheck> excludedLocations, std::
Rando::Context::GetInstance()->SetSeedGenerated(GenerateRandomizer(excludedLocations, enabledTricks, seedString));

Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
Rando::Context::GetInstance()->SetPlandoLoaded(false);
}
24 changes: 6 additions & 18 deletions soh/soh/Enhancements/randomizer/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,6 @@ void Context::SetSpoilerLoaded(const bool spoilerLoaded) {
mSpoilerLoaded = spoilerLoaded;
}

bool Context::IsPlandoLoaded() const {
return mPlandoLoaded;
}

void Context::SetPlandoLoaded(const bool plandoLoaded) {
mPlandoLoaded = plandoLoaded;
}

GetItemEntry Context::GetFinalGIEntry(const RandomizerCheck rc, const bool checkObtainability, const GetItemID ogItemId) {
const auto itemLoc = GetItemLocation(rc);
if (itemLoc->GetPlacedRandomizerGet() == RG_NONE) {
Expand Down Expand Up @@ -279,27 +271,23 @@ std::string sanitize(std::string stringValue) {
return stringValue;
}

void Context::ParseSpoiler(const char* spoilerFileName, const bool plandoMode) {
void Context::ParseSpoiler(const char* spoilerFileName) {
std::ifstream spoilerFileStream(sanitize(spoilerFileName));
if (!spoilerFileStream) {
return;
}
mSeedGenerated = false;
mSpoilerLoaded = false;
mPlandoLoaded = false;
try {
nlohmann::json spoilerFileJson;
spoilerFileStream >> spoilerFileJson;
ParseHashIconIndexesJson(spoilerFileJson);
mSettings->ParseJson(spoilerFileJson);
if (plandoMode) {
ParseItemLocationsJson(spoilerFileJson);
ParseHintJson(spoilerFileJson);
mEntranceShuffler->ParseJson(spoilerFileJson);
mDungeons->ParseJson(spoilerFileJson);
mTrials->ParseJson(spoilerFileJson);
mPlandoLoaded = true;
}
ParseItemLocationsJson(spoilerFileJson);
ParseHintJson(spoilerFileJson);
mEntranceShuffler->ParseJson(spoilerFileJson);
mDungeons->ParseJson(spoilerFileJson);
mTrials->ParseJson(spoilerFileJson);
mSpoilerLoaded = true;
mSeedGenerated = false;
} catch (...) {
Expand Down
5 changes: 1 addition & 4 deletions soh/soh/Enhancements/randomizer/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ class Context {
void SetSeedGenerated(bool seedGenerated = true);
bool IsSpoilerLoaded() const;
void SetSpoilerLoaded(bool spoilerLoaded = true);
bool IsPlandoLoaded() const;
void SetPlandoLoaded(bool plandoLoaded = true);
std::shared_ptr<Settings> GetSettings();
std::shared_ptr<EntranceShuffler> GetEntranceShuffler();
std::shared_ptr<Dungeons> GetDungeons();
Expand All @@ -78,7 +76,7 @@ class Context {
Option& GetOption(RandomizerSettingKey key) const;
TrickOption& GetTrickOption(RandomizerTrick key) const;
GetItemEntry GetFinalGIEntry(RandomizerCheck rc, bool checkObtainability = true, GetItemID ogItemId = GI_NONE);
void ParseSpoiler(const char* spoilerFileName, bool plandoMode);
void ParseSpoiler(const char* spoilerFileName);
void ParseHashIconIndexesJson(nlohmann::json spoilerFileJson);
void ParseItemLocationsJson(nlohmann::json spoilerFileJson);
void WriteHintJson(nlohmann::ordered_json& spoilerFileJson);
Expand Down Expand Up @@ -106,6 +104,5 @@ class Context {
std::shared_ptr<Kaleido> mKaleido;
bool mSeedGenerated = false;
bool mSpoilerLoaded = false;
bool mPlandoLoaded = false;
};
} // namespace Rando
1 change: 0 additions & 1 deletion soh/soh/Enhancements/randomizer/randomizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1968,7 +1968,6 @@ void RandomizerSettingsWindow::DrawElement() {
ctx->SetSpoilerLoaded(false);
GenerateRandomizer(CVarGetInteger(CVAR_RANDOMIZER_SETTING("ManualSeedEntry"), 0) ? seedString : "");
}
UIWidgets::Tooltip("You can also press L on the Quest Select screen to generate a new seed");
ImGui::EndDisabled();

UIWidgets::Spacer(0);
Expand Down
18 changes: 5 additions & 13 deletions soh/soh/OTRGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1902,7 +1902,7 @@ extern "C" int GetEquipNowMessage(char* buffer, char* src, const int maxBufferSi
}

extern "C" void Randomizer_ParseSpoiler(const char* fileLoc) {
OTRGlobals::Instance->gRandoContext->ParseSpoiler(fileLoc, CVarGetInteger(CVAR_GENERAL("PlandoMode"), 0));
OTRGlobals::Instance->gRandoContext->ParseSpoiler(fileLoc);
}

extern "C" void Randomizer_LoadHintMessages() {
Expand Down Expand Up @@ -1993,14 +1993,6 @@ extern "C" GetItemEntry GetItemMystery() {
return { ITEM_NONE_FE, 0, 0, 0, 0, 0, 0, ITEM_NONE_FE, 0, false, ITEM_FROM_NPC, ITEM_CATEGORY_JUNK, NULL, MOD_RANDOMIZER, (CustomDrawFunc)Randomizer_DrawMysteryItem };
}

extern "C" void Randomizer_GenerateSeed() {
std::string seed = "";
if (OTRGlobals::Instance->gRandoContext->IsSpoilerLoaded()) {
seed = OTRGlobals::Instance->gRandoContext->GetSettings()->GetSeedString();
}
GenerateRandomizer(seed);
}

extern "C" uint8_t Randomizer_IsSeedGenerated() {
return OTRGlobals::Instance->gRandoContext->IsSeedGenerated() ? 1 : 0;
}
Expand All @@ -2017,12 +2009,12 @@ extern "C" void Randomizer_SetSpoilerLoaded(bool spoilerLoaded) {
OTRGlobals::Instance->gRandoContext->SetSpoilerLoaded(spoilerLoaded);
}

extern "C" uint8_t Randomizer_IsPlandoLoaded() {
return OTRGlobals::Instance->gRandoContext->IsPlandoLoaded() ? 1 : 0;
extern "C" uint8_t Randomizer_GenerateRandomizer() {
return GenerateRandomizer() ? 1 : 0;
}

extern "C" void Randomizer_SetPlandoLoaded(bool plandoLoaded) {
OTRGlobals::Instance->gRandoContext->SetPlandoLoaded(plandoLoaded);
extern "C" void Randomizer_ShowRandomizerMenu() {
SohGui::ShowRandomizerSettingsMenu();
}

CustomMessage Randomizer_GetCustomGetItemMessage(Player* player) {
Expand Down
5 changes: 2 additions & 3 deletions soh/soh/OTRGlobals.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,12 @@ RandomizerInf Randomizer_GetRandomizerInfFromCheck(RandomizerCheck randomizerChe
bool Randomizer_IsCheckShuffled(RandomizerCheck check);
GetItemEntry GetItemMystery();
ItemObtainability Randomizer_GetItemObtainabilityFromRandomizerCheck(RandomizerCheck randomizerCheck);
void Randomizer_GenerateSeed();
uint8_t Randomizer_IsSeedGenerated();
void Randomizer_SetSeedGenerated(bool seedGenerated);
uint8_t Randomizer_IsSpoilerLoaded();
void Randomizer_SetSpoilerLoaded(bool spoilerLoaded);
uint8_t Randomizer_IsPlandoLoaded();
void Randomizer_SetPlandoLoaded(bool plandoLoaded);
uint8_t Randomizer_GenerateRandomizer();
//void Randomizer_ShowRandomizerMenu();
int CustomMessage_RetrieveIfExists(PlayState* play);
void Overlay_DisplayText(float duration, const char* text);
void Overlay_DisplayText_Seconds(int seconds, const char* text);
Expand Down
4 changes: 4 additions & 0 deletions soh/soh/SohGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,8 @@ namespace SohGui {
void RegisterPopup(std::string title, std::string message, std::string button1, std::string button2, std::function<void()> button1callback, std::function<void()> button2callback) {
mModalWindow->RegisterPopup(title, message, button1, button2, button1callback, button2callback);
}

void ShowRandomizerSettingsMenu() {
mRandomizerSettingsWindow->Show();
}
Comment on lines +270 to +272
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not very happy with this living inside SohGui.cpp but I've tried to extern the window pointer in other places and just couldn't get it to work. If someone has any other options I'm all ears.

}
1 change: 1 addition & 0 deletions soh/soh/SohGui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ namespace SohGui {
void Draw();
void Destroy();
void RegisterPopup(std::string title, std::string message, std::string button1 = "OK", std::string button2 = "", std::function<void()> button1callback = nullptr, std::function<void()> button2callback = nullptr);
void ShowRandomizerSettingsMenu();
}

#endif /* SohGui_hpp */
22 changes: 7 additions & 15 deletions soh/soh/SohMenuBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2108,25 +2108,17 @@ void DrawRemoteControlMenu() {
#endif

extern std::shared_ptr<RandomizerSettingsWindow> mRandomizerSettingsWindow;
extern std::shared_ptr<PlandomizerWindow> mPlandomizerWindow;
extern std::shared_ptr<ItemTrackerWindow> mItemTrackerWindow;
extern std::shared_ptr<ItemTrackerSettingsWindow> mItemTrackerSettingsWindow;
extern std::shared_ptr<EntranceTrackerWindow> mEntranceTrackerWindow;
extern std::shared_ptr<EntranceTrackerSettingsWindow> mEntranceTrackerSettingsWindow;
extern std::shared_ptr<CheckTracker::CheckTrackerWindow> mCheckTrackerWindow;
extern std::shared_ptr<CheckTracker::CheckTrackerSettingsWindow> mCheckTrackerSettingsWindow;
extern std::shared_ptr<PlandomizerWindow> mPlandomizerWindow;
extern "C" u8 Randomizer_GetSettingValue(RandomizerSettingKey randoSettingKey);

void DrawRandomizerMenu() {
if (ImGui::BeginMenu("Randomizer")) {
UIWidgets::EnhancementCheckbox("Plando Mode", CVAR_GENERAL("PlandoMode"));
UIWidgets::Tooltip(
"When dropping a spoiler file on the game window, parse the full spoiler file instead of just the "
"necessary "
"parts to regenerate a seed.\n\nKeep in mind if you do this, all custom text will only be available in the "
"language present in the spoilerfile. You can use this to edit a previously generated spoilerfile that has "
"been edited with custom hint text and item locations. May be useful for debugging.");
UIWidgets::PaddedSeparator();
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(12.0f, 6.0f));
ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, ImVec2(0, 0));
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f);
Expand All @@ -2144,17 +2136,17 @@ void DrawRandomizerMenu() {
static float separationToOptionsButton = 5.0f;
#endif

if (mPlandomizerWindow) {
if (ImGui::Button(GetWindowButtonText("Plandomizer Editor", CVarGetInteger(CVAR_WINDOW("PlandomizerWindow"), 0)).c_str(), buttonSize)) {
mPlandomizerWindow->ToggleVisibility();
if (mRandomizerSettingsWindow) {
if (ImGui::Button(GetWindowButtonText("Randomizer Settings", CVarGetInteger(CVAR_WINDOW("RandomizerSettings"), 0)).c_str(), buttonSize)) {
mRandomizerSettingsWindow->ToggleVisibility();
}
}

UIWidgets::Spacer(0);

if (mRandomizerSettingsWindow) {
if (ImGui::Button(GetWindowButtonText("Randomizer Settings", CVarGetInteger(CVAR_WINDOW("RandomizerSettings"), 0)).c_str(), buttonSize)) {
mRandomizerSettingsWindow->ToggleVisibility();
if (mPlandomizerWindow) {
if (ImGui::Button(GetWindowButtonText("Plandomizer Editor", CVarGetInteger(CVAR_WINDOW("PlandomizerWindow"), 0)).c_str(), buttonSize)) {
mPlandomizerWindow->ToggleVisibility();
}
}

Expand Down
2 changes: 1 addition & 1 deletion soh/src/code/z_sram.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ void Sram_InitSave(FileChooseContext* fileChooseCtx) {

u8 currentQuest = fileChooseCtx->questType[fileChooseCtx->buttonIndex];

if (currentQuest == QUEST_RANDOMIZER && (Randomizer_IsSeedGenerated() || Randomizer_IsPlandoLoaded())) {
if (currentQuest == QUEST_RANDOMIZER && (Randomizer_IsSeedGenerated() || Randomizer_IsSpoilerLoaded())) {
gSaveContext.questId = QUEST_RANDOMIZER;

Randomizer_InitSaveFile();
Expand Down
6 changes: 5 additions & 1 deletion soh/src/overlays/gamestates/ovl_file_choose/file_choose.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ typedef enum {
CM_BOSS_RUSH_MENU,
CM_START_BOSS_RUSH_MENU,
CM_BOSS_RUSH_TO_QUEST,
CM_GENERATE_SEED,
CM_ROTATE_TO_RANDOMIZER_SETTINGS_MENU,
CM_RANDOMIZER_SETTINGS_MENU,
CM_START_RANDOMIZER_SETTINGS_MENU,
CM_RANDOMIZER_SETTINGS_MENU_TO_QUEST,
CM_NAME_ENTRY_TO_RANDOMIZER_SETTINGS_MENU,
} ConfigMode;

typedef enum {
Expand Down
Loading
Loading