Skip to content

Commit

Permalink
Added initial categorization imlementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Aemony committed Feb 10, 2024
1 parent 4c0e0b5 commit 5e74fd6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/stores/Steam/app_record.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ struct app_record_s {
int uses = 0; // Number of times game has been launched
std::string used = ""; // Unix timestamp (in string) of when the game was last used
std::string used_formatted = ""; // Friendly human-readable representation of the Unix timestamp
std::string group = ""; // Category to sort the game under
int hidden = -1; // Is app hidden? (-1 = unset; 0 = no; 1 = yes)
int pinned = -1; // Is app pinned? (-1 = unset; 0 = no; 1 = yes; 99 = Special K)
} skif;
Expand Down
38 changes: 37 additions & 1 deletion src/tabs/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ UpdateJsonMetaData (app_record_s* pApp, bool bWriteToDisk)
{ "Hidden", pApp->skif.hidden },
{ "Uses", pApp->skif.uses },
{ "Used", pApp->skif.used },
{ "Group", pApp->skif.group },
{ "Pin", pApp->skif.pinned }
};

Expand Down Expand Up @@ -2143,7 +2144,9 @@ DrawGameContextMenu (app_record_s* pApp)
if (ImGui::MenuItem ("Name", pApp->skif.name.c_str()))
SKIF_Util_SetClipboardData (SK_UTF8ToWideChar(pApp->skif.name));
}


if (ImGui::MenuItem ("Group", pApp->skif.group.c_str()))
SKIF_Util_SetClipboardData (SK_UTF8ToWideChar(pApp->skif.group));
if (ImGui::MenuItem ("Uses", std::to_string (pApp->skif.uses).c_str()))
SKIF_Util_SetClipboardData ( std::to_wstring(pApp->skif.uses));
SKIF_ImGui_SetHoverTip ("The number of times this game has been launched.");
Expand Down Expand Up @@ -4799,6 +4802,7 @@ SKIF_UI_Tab_DrawLibrary (void)
int keyHidden = -1; // will be 1 for hidden Steam games; 0 for the rest
int keyUses = 0;
std::string keyUsed = "";
std::string keyGroup = "";
int keyPinned = -1; // will be 1 for favorited Steam games; 0 for the rest

// Special K defaults to pinned
Expand Down Expand Up @@ -4827,6 +4831,9 @@ SKIF_UI_Tab_DrawLibrary (void)

if (key.contains("Pin"))
keyPinned = key.at("Pin");

if (key.contains("Group"))
keyGroup = key.at("Group");
}

// Populate SKIF's custom variables with the values as well
Expand All @@ -4836,6 +4843,7 @@ SKIF_UI_Tab_DrawLibrary (void)
app.second.skif.hidden = keyHidden;
app.second.skif.uses = keyUses;
app.second.skif.used = keyUsed;
app.second.skif.group = keyGroup;
app.second.skif.pinned = keyPinned;

// Human-readable time format (local time)
Expand All @@ -4857,6 +4865,7 @@ SKIF_UI_Tab_DrawLibrary (void)
{ "Hidden", app.second.skif.hidden },
{ "Uses", app.second.skif.uses },
{ "Used", app.second.skif.used },
{ "Group", app.second.skif.group },
{ "Pin", app.second.skif.pinned }
};

Expand Down Expand Up @@ -5880,6 +5889,9 @@ SKIF_UI_Tab_DrawLibrary (void)
if (g_apps.empty())
ImGui::Selectable ("Loading games...###GamesCurrentlyLoading", false, ImGuiSelectableFlags_Disabled);

static std::string current_group = "";
static int groups = 0;

int pinned = 0;
int pinned_top = 0;
bool resetNumOnTop = true;
Expand Down Expand Up @@ -5938,6 +5950,30 @@ SKIF_UI_Tab_DrawLibrary (void)
ImGui::Separator ( );
pinned = 0;
}

// If we are passed top pinned and regular pinned, order by group
if (pinned_top == 0 && pinned == 0)
{
static bool group_opened = false;

if (app.second.skif.group != current_group)
{
if (groups > 0)
{
ImGui::PushStyleColor (ImGuiCol_Text, ImGui::GetStyleColorVec4 (ImGuiCol_TextDisabled));
ImGui::PushStyleColor (ImGuiCol_Header, ImGui::GetStyleColorVec4 (ImGuiCol_Header) * ImVec4 (0.7f, 0.7f, 0.7f, 1.0f));
group_opened = ImGui::CollapsingHeader ((app.second.skif.group.empty() ? "Uncategorized" : app.second.skif.group.c_str()), 0); // ImGuiTreeNodeFlags_DefaultOpen
ImGui::PopStyleColor ( );
ImGui::PopStyleColor ( );
}

current_group = app.second.skif.group;
groups++;
}

if (groups > 0 && ! group_opened)
continue;
}

bool selected = (selection.appid == app.second.id &&
selection.store == app.second.store);
Expand Down
21 changes: 21 additions & 0 deletions src/utility/games.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,27 @@ SKIF_GamingCollection::SortApps (std::vector <std::pair <std::string, app_record
break;
}

// Sort by group
std::stable_sort ( apps->begin (),
apps->end (),
[]( const std::pair <std::string, app_record_s>& a,
const std::pair <std::string, app_record_s>& b ) -> int
{
return a.second.skif.group.compare(
b.second.skif.group
) < 0;
}
);

// Sort all uncategorized entries last
std::stable_partition ( apps->begin (),
apps->end (),
[]( const std::pair <std::string, app_record_s>& a ) -> bool
{
return ! a.second.skif.group.empty();
}
);

// Then apply any pins
std::stable_sort ( apps->begin (),
apps->end (),
Expand Down

0 comments on commit 5e74fd6

Please sign in to comment.