Skip to content

Commit 5706f1c

Browse files
committed
Added a mod list viewer
1 parent 2048093 commit 5706f1c

2 files changed

Lines changed: 103 additions & 62 deletions

File tree

src/port/Engine.cpp

Lines changed: 54 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -172,39 +172,34 @@ GameEngine::GameEngine() : dictionary(nullptr) {
172172
{ SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, 0, "No" },
173173
};
174174

175-
const SDL_MessageBoxColorScheme colorScheme = {
176-
{
177-
/* [SDL_MESSAGEBOX_COLOR_BACKGROUND] */
178-
{ 35, 35, 35 }, // Dark Grey
179-
/* [SDL_MESSAGEBOX_COLOR_TEXT] */
180-
{ 240, 240, 240 }, // Off-White
181-
/* [SDL_MESSAGEBOX_COLOR_BUTTON_BORDER] */
182-
{ 255, 100, 100 }, // Warning Red/Orange
183-
/* [SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND] */
184-
{ 60, 60, 60 }, // Lighter Grey
185-
/* [SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED] */
186-
{ 200, 60, 60 } // Dark Red/Orange when hovered/selected
187-
}
188-
};
189-
190-
const SDL_MessageBoxData messageboxdata = {
191-
SDL_MESSAGEBOX_WARNING,
192-
nullptr,
193-
"Security Warning: Untrusted Author",
194-
message.c_str(),
195-
SDL_arraysize(buttons),
196-
buttons,
197-
&colorScheme
198-
};
175+
const SDL_MessageBoxColorScheme colorScheme = { {
176+
/* [SDL_MESSAGEBOX_COLOR_BACKGROUND] */
177+
{ 35, 35, 35 }, // Dark Grey
178+
/* [SDL_MESSAGEBOX_COLOR_TEXT] */
179+
{ 240, 240, 240 }, // Off-White
180+
/* [SDL_MESSAGEBOX_COLOR_BUTTON_BORDER] */
181+
{ 255, 100, 100 }, // Warning Red/Orange
182+
/* [SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND] */
183+
{ 60, 60, 60 }, // Lighter Grey
184+
/* [SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED] */
185+
{ 200, 60, 60 } // Dark Red/Orange when hovered/selected
186+
} };
187+
188+
const SDL_MessageBoxData messageboxdata = { SDL_MESSAGEBOX_WARNING,
189+
nullptr,
190+
"Security Warning: Untrusted Author",
191+
message.c_str(),
192+
SDL_arraysize(buttons),
193+
buttons,
194+
&colorScheme };
199195

200196
int buttonid;
201197
if (SDL_ShowMessageBox(&messageboxdata, &buttonid) < 0) {
202198
return false;
203199
}
204200

205201
return buttonid == 1;
206-
}
207-
);
202+
});
208203

209204
gsFast3dWindow = std::make_shared<Fast::Fast3dWindow>(std::vector<std::shared_ptr<Ship::GuiWindow>>({}));
210205
this->context->InitWindow(gsFast3dWindow);
@@ -955,45 +950,42 @@ void GameEngine::LoadScripts() {
955950
auto scripting = Ship::Context::GetInstance()->GetScriptSystem();
956951
Notification::Emit(
957952
{ .message = "Loading mods this may take a while...", .remainingTime = (totalScripts * 5.0f), .mute = true });
958-
static std::shared_ptr<BS::thread_pool> mThreadPool = std::make_shared<BS::thread_pool>(1);
959-
mThreadPool->submit_task([&]() -> void {
960-
auto currentScriptName = std::make_shared<std::string>("");
961-
auto currentScript = std::make_shared<std::atomic<int>>(0);
962-
auto notification = std::make_shared<Notification::Options>();
963-
notification->mute = true;
964-
notification->remainingTime = 7.0f;
965-
try {
966-
scripting->CompileAll([&](const std::shared_ptr<Ship::Archive>& archive) {
967-
if (!archive)
968-
return;
969-
970-
auto& info = archive->GetManifest();
971-
*currentScriptName = info.Name;
972-
int scriptNum = ++(*currentScript);
973-
974-
notification->message =
975-
fmt::format("Loading {} ({}/{})", *currentScriptName, scriptNum, this->totalScripts);
976-
977-
Notification::Emit(*notification);
978-
});
979-
} catch (std::exception& e) {
953+
auto currentScriptName = std::make_shared<std::string>("");
954+
auto currentScript = std::make_shared<std::atomic<int>>(0);
955+
auto notification = std::make_shared<Notification::Options>();
956+
notification->mute = true;
957+
notification->remainingTime = 7.0f;
958+
try {
959+
scripting->CompileAll([&](const std::shared_ptr<Ship::Archive>& archive) {
960+
if (!archive)
961+
return;
962+
963+
auto& info = archive->GetManifest();
964+
*currentScriptName = info.Name;
965+
int scriptNum = ++(*currentScript);
966+
980967
notification->message =
981-
fmt::format("Failed to build {} ({}/{})", *currentScriptName, (*currentScript + 1), this->totalScripts);
982-
SPDLOG_ERROR("Failed to build script {}: {}", *currentScriptName, e.what());
968+
fmt::format("Loading {} ({}/{})", *currentScriptName, scriptNum, this->totalScripts);
969+
983970
Notification::Emit(*notification);
984-
}
971+
});
972+
} catch (std::exception& e) {
973+
notification->message =
974+
fmt::format("Failed to build {} ({}/{})", *currentScriptName, (*currentScript + 1), this->totalScripts);
975+
SPDLOG_ERROR("Failed to build script {}: {}", *currentScriptName, e.what());
976+
Notification::Emit(*notification);
977+
}
985978

986-
try {
987-
context->GetScriptSystem()->LoadAll();
988-
Notification::Emit({ .message = "Finished loading mods!", .remainingTime = 5.0f, .mute = true });
989-
} catch (std::exception& e) {
990-
SPDLOG_ERROR("Failed to load scripts: {}", e.what());
991-
Notification::Emit({ .message = "Failed to load some mods, check logs for details.",
992-
.messageColor = ImVec4(1.0f, 0.5f, 0.5f, 1.0f),
993-
.remainingTime = 5.0f,
994-
.mute = true });
995-
}
996-
});
979+
try {
980+
context->GetScriptSystem()->LoadAll();
981+
Notification::Emit({ .message = "Finished loading mods!", .remainingTime = 5.0f, .mute = true });
982+
} catch (std::exception& e) {
983+
SPDLOG_ERROR("Failed to load scripts: {}", e.what());
984+
Notification::Emit({ .message = "Failed to load some mods, check logs for details.",
985+
.messageColor = ImVec4(1.0f, 0.5f, 0.5f, 1.0f),
986+
.remainingTime = 5.0f,
987+
.mute = true });
988+
}
997989
}
998990

999991
void GameEngine::Create(int argc, char* argv[]) {

src/port/ui/GhostshipMenuDevTools.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ void GhostshipMenu::AddMenuDevTools() {
135135
}
136136

137137
void GhostshipMenu::AddModMenu() {
138+
auto mods = Ship::Context::GetInstance()->GetResourceManager()->GetArchiveManager()->GetArchives();
138139
AddMenuEntry("Mods", CVAR_SETTING("Menu.ModsSidebarSection"));
139140

140141
WidgetPath path = { "Mods", "General", SECTION_COLUMN_1 };
@@ -146,6 +147,54 @@ void GhostshipMenu::AddModMenu() {
146147
Ship::Context::GetInstance()->GetScriptSystem()->UnloadAll();
147148
GameEngine::Instance->LoadScripts();
148149
});
150+
151+
// Assuming you have defined the path where these cards should go
152+
// WidgetPath path = { "Mods", "Installed Mods", SECTION_COLUMN_1 };
153+
154+
for (const auto& entry : *mods) {
155+
const auto& info = entry->GetManifest();
156+
if (info.Name.empty()) {
157+
continue;
158+
}
159+
160+
const bool isCodeMod = !info.Main.empty() || !info.Binaries.empty();
161+
162+
std::string modCardName = info.Name;
163+
if (isCodeMod) {
164+
modCardName += " (Code Mod)";
165+
}
166+
167+
AddWidget(path, modCardName, WIDGET_SEPARATOR_TEXT).Options(UIWidgets::TextOptions{});
168+
169+
AddWidget(path, "Author: " + info.Author + " | Version: " + info.Version, WIDGET_TEXT)
170+
.Options(UIWidgets::TextOptions{});
171+
172+
std::string securityText = entry->IsSigned() ? "Security: Signed (Trusted)" : "Security: Untrusted";
173+
AddWidget(path, securityText, WIDGET_TEXT).Options(UIWidgets::TextOptions{});
174+
175+
if (!info.Dependencies.empty()) {
176+
std::string depsString = "Dependencies: ";
177+
for (size_t i = 0; i < info.Dependencies.size(); ++i) {
178+
depsString += info.Dependencies[i];
179+
if (i < info.Dependencies.size() - 1)
180+
depsString += ", ";
181+
}
182+
183+
AddWidget(path, depsString, WIDGET_TEXT).Options(UIWidgets::TextOptions{});
184+
}
185+
186+
if (!info.Description.empty()) {
187+
AddWidget(path, info.Description, WIDGET_TEXT).Options(UIWidgets::TextOptions{});
188+
}
189+
190+
if (!info.Website.empty()) {
191+
AddWidget(path, "Open Webpage##" + info.Name, WIDGET_BUTTON)
192+
.Options(UIWidgets::ButtonOptions{})
193+
.Callback([info](WidgetInfo&) { SDL_OpenURL(info.Website.c_str()); });
194+
}
195+
196+
AddWidget(path, "##Spacer_" + info.Name, WIDGET_SEPARATOR).Options(UIWidgets::WidgetOptions{});
197+
}
149198
};
150199

151200
} // namespace GhostshipGui

0 commit comments

Comments
 (0)