Skip to content

Commit

Permalink
sort addons in UI only
Browse files Browse the repository at this point in the history
  • Loading branch information
DeltaGW2 committed Oct 22, 2024
1 parent 14a5628 commit 2485ae5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 28 deletions.
20 changes: 0 additions & 20 deletions src/Loader/Loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,6 @@ namespace Loader

QueuedAddons.erase(it);

SortAddons();
ArcDPS::GetPlugins();
}
}
Expand Down Expand Up @@ -1305,25 +1304,6 @@ namespace Loader
return nullptr;
}

void SortAddons()
{
std::sort(Addons.begin(), Addons.end(), [](Addon* lhs, Addon* rhs)
{
std::string lcmp = lhs->Definitions && lhs->Definitions->Name
? String::ToLower(String::Normalize(lhs->Definitions->Name))
: String::ToLower(lhs->Path.filename().string());

std::string rcmp = rhs->Definitions && rhs->Definitions->Name
? String::ToLower(String::Normalize(rhs->Definitions->Name))
: String::ToLower(rhs->Path.filename().string());

return
(lhs->IsFavorite > rhs->IsFavorite) ||
((lhs->IsFavorite == rhs->IsFavorite) && (lhs->IsDisabledUntilUpdate > rhs->IsDisabledUntilUpdate)) ||
((lhs->IsFavorite == rhs->IsFavorite) && (lhs->IsDisabledUntilUpdate == rhs->IsDisabledUntilUpdate) && lcmp < rcmp);
});
}

void GetGameBuild()
{
/* prepare client request */
Expand Down
6 changes: 0 additions & 6 deletions src/Loader/Loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,6 @@ namespace Loader
///----------------------------------------------------------------------------------------------------
Addon* FindAddonByMD5(std::vector<unsigned char> aMD5);

///----------------------------------------------------------------------------------------------------
/// SortAddons:
/// Sorts addons by name but prioritizes DUU state.
///----------------------------------------------------------------------------------------------------
void SortAddons();

///----------------------------------------------------------------------------------------------------
/// GetGameBuild:
/// Gets the game build and sets the Disable Until Update state.
Expand Down
18 changes: 16 additions & 2 deletions src/UI/Widgets/MainWindow/Addons/Addons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ void CAddonsWindow::AddonItem(AddonItemData& aAddonData, float aWidth)
{
aAddonData.NexusAddon->IsFavorite = !aAddonData.NexusAddon->IsFavorite;
Loader::SaveAddonConfig();
Loader::SortAddons(); // quite ugly to call from here, but oh well
this->Invalidate();
clickedFavorite = true;
}
Expand Down Expand Up @@ -1065,7 +1064,6 @@ void CAddonsWindow::RenderDetails()
//Logger->Debug(CH_GUI, "ToggleDUU called: %s", it.second->Definitions->Name);

Loader::SaveAddonConfig();
Loader::SortAddons(); // quite ugly to call from here, but oh well
this->Invalidate();

if (addonData.NexusAddon->State == EAddonState::Loaded)
Expand Down Expand Up @@ -1301,6 +1299,22 @@ void CAddonsWindow::PopulateAddons()
this->SetContent(addonItem);
}
}

std::sort(this->Addons.begin(), this->Addons.end(), [](AddonItemData& lhs, AddonItemData& rhs)
{
std::string lcmp = lhs.NexusAddon->Definitions && lhs.NexusAddon->Definitions->Name
? String::ToLower(String::Normalize(lhs.NexusAddon->Definitions->Name))
: String::ToLower(lhs.NexusAddon->Path.filename().string());

std::string rcmp = rhs.NexusAddon->Definitions && rhs.NexusAddon->Definitions->Name
? String::ToLower(String::Normalize(rhs.NexusAddon->Definitions->Name))
: String::ToLower(rhs.NexusAddon->Path.filename().string());

return
(lhs.NexusAddon->IsFavorite > rhs.NexusAddon->IsFavorite) ||
((lhs.NexusAddon->IsFavorite == rhs.NexusAddon->IsFavorite) && (lhs.NexusAddon->IsDisabledUntilUpdate > rhs.NexusAddon->IsDisabledUntilUpdate)) ||
((lhs.NexusAddon->IsFavorite == rhs.NexusAddon->IsFavorite) && (lhs.NexusAddon->IsDisabledUntilUpdate == rhs.NexusAddon->IsDisabledUntilUpdate) && lcmp < rcmp);
});
}

void CAddonsWindow::PopulateLibrary()
Expand Down

0 comments on commit 2485ae5

Please sign in to comment.