Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
52 changes: 52 additions & 0 deletions soh/soh/Enhancements/PluginManager/PluginManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "PluginManager.h"
#include "../../UIWidgets.hpp"
#include "../../util.h"
#include "../../OTRGlobals.h"

#include "WidgetFactory.h"

void PluginManagerDrawPlugins() {
ImGui::Text("Plugins");

WidgetFactory& factory = WidgetFactory::GetInstance();

// Retrieve all registered widget names
std::vector<std::string> widgetNames = factory.GetRegisteredWidgetNames();

// Create a table to show the widgets
if (ImGui::BeginTable("WidgetTable", 2, ImGuiTableFlags_Borders)) {
ImGui::TableSetupColumn("Plugin Name");
ImGui::TableSetupColumn("Plugin Options");
ImGui::TableHeadersRow();

for (const std::string& widgetName : widgetNames) {
std::unique_ptr<Widget> widget = factory.CreateWidget(widgetName);

if (widgetName.find("Settings") != std::string::npos) {
ImGui::SameLine();
widget->Draw();
widget->Settings();
} else {
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::Text("%s", widget->GetLabel().c_str());
ImGui::TableSetColumnIndex(1);
widget->Draw();
}

}

ImGui::EndTable();
}

}


void PluginManager::DrawElement() {
ImGui::SetNextWindowSize(ImVec2(400, 400), ImGuiCond_FirstUseEver);
PluginManagerDrawPlugins();
}

void PluginManager::InitElement() {

}
16 changes: 16 additions & 0 deletions soh/soh/Enhancements/PluginManager/PluginManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef PLUGINMANAGER_H
#define PLUGINMANAGER_H

#include "GuiWindow.h"


class PluginManager : public Ship::GuiWindow {
public:
using GuiWindow::GuiWindow;

void InitElement();
void DrawElement();
void UpdateElement() override{};
};

#endif // PLUGINMANAGER_H
62 changes: 62 additions & 0 deletions soh/soh/Enhancements/PluginManager/Plugins/ElectrocuteButton.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include "../WidgetFactory.h"

bool openSettings = false;

// Derived widget class for a button
class ButtonWidget : public Widget {
public:
ButtonWidget(const std::string& tableLabel, const std::string& buttonLabel, std::function<void()> onClickAction)
: tableLabel(tableLabel), buttonLabel(buttonLabel), onClickAction(onClickAction) {}

const std::string& GetLabel() const override {
return tableLabel;
}

void Draw() override {
if (ImGui::Button(buttonLabel.c_str())) {
onClickAction();
}
}

void Settings() override {
if (openSettings) {
ImGui::SetNextWindowSize(ImVec2(400, 400), ImGuiCond_FirstUseEver);
ImGui::Begin("Electrocute Settings", &openSettings);

UIWidgets::PaddedEnhancementCheckbox("Enable Button", "gEnhancements.CanShock", true, true);

ImGui::End();
}
}

private:
std::string tableLabel; // Label for the table
std::string buttonLabel; // Label for the button
std::function<void()> onClickAction;
};

static WidgetRegistrar electrocuteButtonRegistrar(
"ElectrocuteButton",
[]() -> std::unique_ptr<Widget> {
return std::make_unique<ButtonWidget>(
"Electrocute Player", // Table label
"Electrocute", // Button label
[]() {
if (CVarGetInteger("gEnhancements.CanShock", 0) == 1) {
GameInteractor::RawAction::ElectrocutePlayer();
}
}
);
}
);

static WidgetRegistrar electrocuteSettingsButtonRegistrar(
"ElectrocuteSettingsButton",
[]() -> std::unique_ptr<Widget> {
return std::make_unique<ButtonWidget>(
"Open Settings", // Table label
"Settings", // Button label
[]() { openSettings = !openSettings; }
);
}
);
12 changes: 12 additions & 0 deletions soh/soh/Enhancements/PluginManager/Widget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once
#include <string>
#include <imgui.h>

// Base class for all widgets
class Widget {
public:
virtual ~Widget() = default;
virtual const std::string& GetLabel() const = 0;
virtual void Draw() = 0;
virtual void Settings() = 0;
};
57 changes: 57 additions & 0 deletions soh/soh/Enhancements/PluginManager/WidgetFactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#pragma once
#include "soh/OTRGlobals.h"
#include <unordered_map>
#include <functional>
#include <string>
#include <vector>
#include <memory>
#include "Widget.h"
#include "soh/Enhancements/game-interactor/GameInteractor.h"
#include "soh/UIWidgets.hpp"


// WidgetFactory responsible for creating widgets and storing registrations
class WidgetFactory {
public:
// A map that stores creation functions by widget name
using CreateWidgetFunc = std::function<std::unique_ptr<Widget>()>;

static WidgetFactory& GetInstance() {
static WidgetFactory instance;
return instance;
}

// Registers a widget creation function with the given name
void RegisterWidget(const std::string& name, CreateWidgetFunc func) {
widgetCreators[name] = func;
}

// Creates a widget by name
std::unique_ptr<Widget> CreateWidget(const std::string& name) const {
auto it = widgetCreators.find(name);
if (it != widgetCreators.end()) {
return it->second();
}
return nullptr;
}

// Returns a list of registered widget names
std::vector<std::string> GetRegisteredWidgetNames() const {
std::vector<std::string> names;
for (const auto& pair : widgetCreators) {
names.push_back(pair.first);
}
return names;
}

private:
std::unordered_map<std::string, CreateWidgetFunc> widgetCreators;
};

// Helper class for static registration of widgets
class WidgetRegistrar {
public:
WidgetRegistrar(const std::string& name, WidgetFactory::CreateWidgetFunc func) {
WidgetFactory::GetInstance().RegisterWidget(name, func);
}
};
2 changes: 2 additions & 0 deletions soh/soh/OTRGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
#include "util.h"
#include <boost_custom/container_hash/hash_32.hpp>

#include "soh/Enhancements/PluginManager/PluginManager.h"

#if not defined (__SWITCH__) && not defined(__WIIU__)
#include "Extractor/Extract.h"
#endif
Expand Down
7 changes: 7 additions & 0 deletions soh/soh/SohGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ namespace SohGui {
std::shared_ptr<AdvancedResolutionSettings::AdvancedResolutionSettingsWindow> mAdvancedResolutionSettingsWindow;
std::shared_ptr<SohModalWindow> mModalWindow;

std::shared_ptr<PluginManager> mPluginManager;

void SetupGuiElements() {
auto gui = Ship::Context::GetInstance()->GetWindow()->GetGui();

Expand Down Expand Up @@ -203,6 +205,9 @@ namespace SohGui {
mModalWindow = std::make_shared<SohModalWindow>(CVAR_WINDOW("ModalWindow"), "Modal Window");
gui->AddGuiWindow(mModalWindow);
mModalWindow->Show();

mPluginManager = std::make_shared<PluginManager>(CVAR_WINDOW("PluginManager"), "Plugin Manager");
gui->AddGuiWindow(mPluginManager);
}

void Destroy() {
Expand Down Expand Up @@ -232,6 +237,8 @@ namespace SohGui {
mSohMenuBar = nullptr;
mInputViewer = nullptr;
mInputViewerSettings = nullptr;

mPluginManager = nullptr;
}

void RegisterPopup(std::string title, std::string message, std::string button1, std::string button2, std::function<void()> button1callback, std::function<void()> button2callback) {
Expand Down
2 changes: 2 additions & 0 deletions soh/soh/SohGui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "Enhancements/randomizer/randomizer_settings_window.h"
#include "SohModals.h"

#include "soh/Enhancements/PluginManager/PluginManager.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
10 changes: 10 additions & 0 deletions soh/soh/SohMenuBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include "Enhancements/randomizer/randomizer_settings_window.h"
#include "Enhancements/resolution-editor/ResolutionEditor.h"

#include "Enhancements/PluginManager/PluginManager.h"

extern bool isBetaQuestEnabled;

extern "C" PlayState* gPlayState;
Expand Down Expand Up @@ -551,6 +553,7 @@ void DrawSettingsMenu() {
extern std::shared_ptr<AudioEditor> mAudioEditorWindow;
extern std::shared_ptr<CosmeticsEditorWindow> mCosmeticsEditorWindow;
extern std::shared_ptr<GameplayStatsWindow> mGameplayStatsWindow;
extern std::shared_ptr<PluginManager> mPluginManager;

void DrawEnhancementsMenu() {
if (ImGui::BeginMenu("Enhancements"))
Expand Down Expand Up @@ -1456,6 +1459,13 @@ void DrawEnhancementsMenu() {
mGameplayStatsWindow->ToggleVisibility();
}
}

if (mPluginManager) {
if (ImGui::Button(GetWindowButtonText("Plugin Manager", CVarGetInteger(CVAR_WINDOW("PluginManager"), 0)).c_str(), ImVec2(-1.0f, 0.0f))) {
mPluginManager->ToggleVisibility();
}
}

ImGui::PopStyleVar(3);
ImGui::PopStyleColor(1);

Expand Down