Skip to content

Commit

Permalink
fix: improve registry list UX
Browse files Browse the repository at this point in the history
  • Loading branch information
zziger committed Aug 27, 2024
1 parent f02ec8a commit 078bc45
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 38 deletions.
1 change: 1 addition & 0 deletions .idea/editor.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/git_toolbox_blame.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

1 change: 1 addition & 0 deletions src/supermod/registry/RegistryManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class RegistryManager

static async::task<void> FetchEntries();
static std::map<std::string, Entry>& GetEntries() { return entries; }
static bool HasEntry(std::string id) { return entries.contains(id); }
static bool CanManageMod(const Entry& entry)
{
if (!user)
Expand Down
8 changes: 8 additions & 0 deletions src/supermod/ui/widgets/mods/contextMenuWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <supermod/modloader/ModManager.hpp>
#include <supermod/modloader/mod/info/ModInfoFilesystem.hpp>
#include <supermod/ui/Ui.hpp>
#include <supermod/ui/windows/main_views/views.hpp>

void sm::ui::widgets::mods::ContextMenu(const std::shared_ptr<modloader::Mod>& mod)
{
Expand Down Expand Up @@ -41,6 +42,13 @@ void sm::ui::widgets::mods::ContextMenu(const std::shared_ptr<modloader::Mod>& m
if (mod->IsActive())
Tooltip("Мод должен быть выключен для перезагрузки", ImGuiHoveredFlags_AllowWhenDisabled);

if (ImGui::MenuItem(ICON_MD_DOWNLOAD " Показать в загрузке модов", nullptr, false,
sm::registry::RegistryManager::HasEntry(mod->GetID())))
{
windows::main::MainWindowState::currentView = windows::main::REGISTRY;
windows::main::MainWindowState::activeRegistryMod = mod->GetID();
}

ImGui::Separator();

const auto willRemove = mod->HasFlag(modloader::Mod::Flag::REMOVAL_SCHEDULED);
Expand Down
22 changes: 12 additions & 10 deletions src/supermod/ui/windows/mainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ bool SelectableIcon(const char* title, const char* icon, const bool selected)
return value;
}

void Tab(const char* icon, const int index)
void Tab(const char* icon, const windows::main::ViewType type)
{
if (SelectableIcon(windows::main::VIEW_NAMES[index].c_str(), icon, windows::main::currentView == index))
windows::main::currentView = index;
if (SelectableIcon(windows::main::VIEW_NAMES[static_cast<int>(type)].c_str(), icon,
windows::main::MainWindowState::currentView == type))
windows::main::MainWindowState::currentView = type;
}

void Link(const char* title, const char* icon, const char* url)
Expand Down Expand Up @@ -65,17 +66,18 @@ void windows::Main()
ImGui::SetNextWindowSizeConstraints(ImVec2(500, menuSize + headerSize), ImVec2(FLT_MAX, FLT_MAX));
Ui::ConstraintWindow("###MainWindow");

if (ImGui::Begin(std::format("SuperMod / {}###MainWindow", main::VIEW_NAMES[main::currentView]).c_str(),
&Ui::menuOpen))
if (ImGui::Begin(
std::format("SuperMod / {}###MainWindow", main::VIEW_NAMES[main::MainWindowState::currentView]).c_str(),
&Ui::menuOpen))
{
ImGui::BeginChild("menu", ImVec2(Ui::ScaledPx(fontSize), 0));

ImGui::BeginChild("upper", ImVec2(Ui::ScaledPx(fontSize), (-Ui::ScaledPx(fontSize) - spacing.y * 2) * 2));
Ui::PushFont(fontSize);
Tab(ICON_MD_FORMAT_LIST_BULLETED, 0);
Tab(ICON_MD_DOWNLOAD, 1);
Tab(ICON_MD_SETTINGS, 2);
Tab(ICON_MD_BUILD, 3);
Tab(ICON_MD_FORMAT_LIST_BULLETED, main::MODS);
Tab(ICON_MD_DOWNLOAD, main::REGISTRY);
Tab(ICON_MD_SETTINGS, main::SETTINGS);
Tab(ICON_MD_BUILD, main::TOOLS);
Ui::PopFont();
ImGui::EndChild();

Expand All @@ -89,7 +91,7 @@ void windows::Main()
ImGui::SameLine();
ImGui::BeginChild("content", ImVec2(0, 0));

main::View(main::currentView);
main::View(main::MainWindowState::currentView);

ImGui::EndChild();
}
Expand Down
38 changes: 24 additions & 14 deletions src/supermod/ui/windows/main_views/registryView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ using namespace std::chrono;

void sm::ui::windows::main::RegistryView()
{
static std::optional<std::string> activeMod;
const auto& activeMod = MainWindowState::activeRegistryMod;
static int activeVersion = 0;

auto& mods = registry::RegistryManager::GetEntries();
Expand All @@ -31,10 +31,10 @@ void sm::ui::windows::main::RegistryView()
for (const auto& loadedMod : mods)
{
if (widgets::mods::SelectableRegistry(loadedMod.second.latestVersion, loadedMod.first == activeMod) &&
loadedMod.second.versions.size() > 0)
!loadedMod.second.versions.empty())
{
activeVersion = 0;
activeMod = loadedMod.first;
MainWindowState::activeRegistryMod = loadedMod.first;
}
ImGui::Spacing();
}
Expand Down Expand Up @@ -103,21 +103,29 @@ void sm::ui::windows::main::RegistryView()
widgets::registry::Uploader(mod.uploader);
ImGui::Spacing();

ImGui::SetNextItemWidth(300);
auto versionPreview = version.version.str();
if (!version.verified)
{
versionPreview += " " ICON_MD_SAFETY_CHECK;
}
auto currentMod = modloader::ModManager::FindModByID(mod.id);

auto versionDisplayName = [&](const registry::RegistryManager::EntryVersion& ver,
bool latest) -> std::string {
auto displayName = version.version.str();

if (ImGui::BeginCombo("##Version", versionPreview.c_str()))
if (currentMod != nullptr && ver.version == currentMod->GetInfo()->version)
displayName += " (Уст.)";

if (!version.verified)
displayName += " " ICON_MD_SAFETY_CHECK;

return displayName;
};

ImGui::SetNextItemWidth(300);
if (ImGui::BeginCombo("##Version",
versionDisplayName(version, mod.latestVersionValue == version.version).c_str()))
{
for (int n = 0; n < mod.versions.size(); n++)
{
const bool is_selected = activeVersion == n;
auto text = mod.versions[n].version.str();
if (!mod.versions[n].verified)
text += " " ICON_MD_SAFETY_CHECK;
auto text = versionDisplayName(mod.versions[n], mod.latestVersionValue == mod.versions[n].version);
if (ImGui::Selectable(text.c_str(), is_selected))
activeVersion = n;

Expand All @@ -129,7 +137,9 @@ void sm::ui::windows::main::RegistryView()
}

ImGui::SameLine();
if (ImGui::Button("Установить"))
if (ImGui::Button(currentMod != nullptr && currentMod->GetInfo()->version == version.version
? "Переустановить"
: "Установить"))
{
modloader::ModInstaller::AddProvider(
std::make_shared<modloader::ModSourceProviderRegistry>(info.GetID(), version.version.str()));
Expand Down
24 changes: 18 additions & 6 deletions src/supermod/ui/windows/main_views/views.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,45 @@

namespace sm::ui::windows::main
{
enum ViewType
{
MODS,
REGISTRY,
SETTINGS,
TOOLS
};

static const std::vector<std::string> VIEW_NAMES = {"Моды", "Скачать моды", "Настройки", "Инструменты"};

void ModsView();
void RegistryView();
void SettingsView();
void ToolsView();

inline void View(const int index)
inline void View(const ViewType index)
{
switch (index)
{
case 0:
case MODS:
ModsView();
break;
case 1:
case REGISTRY:
RegistryView();
break;
case 2:
case SETTINGS:
SettingsView();
break;
case 3:
case TOOLS:
ToolsView();
break;
default:
break;
}
}

static inline int currentView = 0;
struct MainWindowState
{
static inline ViewType currentView = MODS;
static inline std::optional<std::string> activeRegistryMod = std::nullopt;
};
} // namespace sm::ui::windows::main

0 comments on commit 078bc45

Please sign in to comment.