Skip to content

Commit

Permalink
Added support for multiple info message popups
Browse files Browse the repository at this point in the history
  • Loading branch information
Aemony committed Feb 18, 2024
1 parent fc2c1d0 commit 1a38e8c
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 150 deletions.
1 change: 0 additions & 1 deletion include/SKIF.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ extern PopupState EmptySpaceMenu; // Library: used to show an options menu f
extern PopupState AddGamePopup; // Library: show an add custom game prompt
extern PopupState RemoveGamePopup; // Library: show a remove custom game prompt
extern PopupState ModifyGamePopup; // Library: show a modify custom game prompt
extern PopupState ConfirmPopup; // Library: show a confirm prompt with text set through confirmPopupText
extern PopupState UpdatePromptPopup; // App Mode: show an update prompt
extern PopupState HistoryPopup; // Monitor / About: show a changelog popup
extern PopupState AutoUpdatePopup; // Show changelog from the latest auto-installed update
Expand Down
14 changes: 4 additions & 10 deletions include/utility/skif_imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ ImVec4 SKIF_ImGui_sRGBtoLinear (ImVec4 col);
void SKIF_ImGui_StyleColorsDark (ImGuiStyle* dst = nullptr);
void SKIF_ImGui_StyleColorsLight (ImGuiStyle* dst = nullptr);
void SKIF_ImGui_AdjustAppModeSize (HMONITOR monitor);
void SKIF_ImGui_InfoMessage (const std::string szTitle, const std::string szLabel);
bool SKIF_ImGui_IsFocused (void);
bool SKIF_ImGui_IsMouseHovered (void);
bool SKIF_ImGui_IsAnyInputDown (void);
Expand Down Expand Up @@ -43,15 +44,8 @@ void SKIF_ImGui_InvalidateFonts (void);
// to among other things force 1.0f for the alpha color channel (w)
static ImVec4 SKIF_ImGui_ImDerp (const ImVec4& a, const ImVec4& b, float t) { return ImVec4 (a.x + ((b.x - a.x) * t), a.y + ((b.y - a.y) * t), a.z + ((b.z - a.z) * t), 1.0f /*a.w + (b.w - a.w) * t */); }

// Fonts
extern bool SKIF_bFontChineseSimplified,
SKIF_bFontChineseAll,
SKIF_bFontCyrillic,
SKIF_bFontJapanese,
SKIF_bFontKorean,
SKIF_bFontThai,
SKIF_bFontVietnamese,
SKIF_bFontAwesomeSolid,
SKIF_bFontAwesomeBrands;
// Message popups
extern PopupState PopupMessageInfo; // App Mode: show an informational message box with text set through SKIF_ImGui_InfoMessage

// Fonts
extern ImFont* fontConsolas;
19 changes: 14 additions & 5 deletions src/SKIF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2810,6 +2810,15 @@ wWinMain ( _In_ HINSTANCE hInstance,
_inject._RefreshSKDLLVersions ();
}


// Process any existing message popups
extern void
SKIF_ImGui_InfoMessage_Process (void);
SKIF_ImGui_InfoMessage_Process ( );


// Handle the update popup

static std::wstring updateRoot = SK_FormatStringW (LR"(%ws\Version\)", _path_cache.specialk_userdata);
static float UpdateAvailableWidth = 0.0f;

Expand Down Expand Up @@ -3235,7 +3244,7 @@ wWinMain ( _In_ HINSTANCE hInstance,
if (ImGui::IsMouseDragging (ImGuiMouseButton_Left) &&
SKIF_ImGui_GetWindowModeState ( ) &&
( AddGamePopup == PopupState_Opened ||
ConfirmPopup == PopupState_Opened ||
PopupMessageInfo == PopupState_Opened ||
ModifyGamePopup == PopupState_Opened ||
RemoveGamePopup == PopupState_Opened ||
UpdatePromptPopup == PopupState_Opened ||
Expand All @@ -3245,8 +3254,8 @@ wWinMain ( _In_ HINSTANCE hInstance,
if ( AddGamePopup == PopupState_Opened)
AddGamePopup = PopupState_Open;
else if ( ConfirmPopup == PopupState_Opened)
ConfirmPopup = PopupState_Open;
else if ( PopupMessageInfo == PopupState_Opened)
PopupMessageInfo = PopupState_Open;
else if ( ModifyGamePopup == PopupState_Opened)
ModifyGamePopup = PopupState_Open;
else if ( RemoveGamePopup == PopupState_Opened)
Expand Down Expand Up @@ -3307,8 +3316,8 @@ wWinMain ( _In_ HINSTANCE hInstance,
// But don't close those of interest
if ( AddGamePopup != PopupState_Open &&
AddGamePopup != PopupState_Opened &&
ConfirmPopup != PopupState_Open &&
ConfirmPopup != PopupState_Opened &&
PopupMessageInfo != PopupState_Open &&
PopupMessageInfo != PopupState_Opened &&
ModifyGamePopup != PopupState_Open &&
ModifyGamePopup != PopupState_Opened &&
UpdatePromptPopup != PopupState_Open &&
Expand Down
137 changes: 37 additions & 100 deletions src/tabs/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,10 @@ PopupState CoverMenu = PopupState_Closed;
PopupState IconMenu = PopupState_Closed;
PopupState ServiceMenu = PopupState_Closed;

PopupState AddGamePopup = PopupState_Closed;
PopupState RemoveGamePopup = PopupState_Closed;
PopupState ModifyGamePopup = PopupState_Closed;
PopupState ConfirmPopup = PopupState_Closed;
PopupState AddGamePopup = PopupState_Closed;
PopupState RemoveGamePopup = PopupState_Closed;
PopupState ModifyGamePopup = PopupState_Closed;

std::string confirmPopupTitle;
std::string confirmPopupText;
std::wstring file_metadata;

std::wstring dragDroppedFilePath = L"";
Expand Down Expand Up @@ -510,8 +507,7 @@ LaunchGame (app_record_s* pApp)
if ( pApp->store != app_record_s::Store::Steam && pApp->store != app_record_s::Store::Epic &&
! launchConfig->isExecutableFullPathValid ( ))
{
confirmPopupText = "Could not launch game due to missing executable:\n\n" + launchConfig->getExecutableFullPathUTF8 ( );
ConfirmPopup = PopupState_Open;
SKIF_ImGui_InfoMessage ("Missing executable", "Could not launch game due to missing executable:\n\n" + launchConfig->getExecutableFullPathUTF8 ( ));
}

else {
Expand Down Expand Up @@ -792,13 +788,13 @@ LaunchGame (app_record_s* pApp)
steamLaunchOptions.insert (pos, R"(%)"), // Escape the character
pos = steamLaunchOptions.find ('%', pos + 2)) // Find the next occurence
{ }
confirmPopupText = "Could not launch game due to conflicting launch options in Steam:\n"
"\n"
+ steamLaunchOptions + "\n"
"\n"
"Please change the launch options in Steam before trying again.";
ConfirmPopup = PopupState_Open;

SKIF_ImGui_InfoMessage ("Conflicting configuration",
"Could not launch game due to conflicting launch options in Steam:\n"
"\n"
+ steamLaunchOptions + "\n"
"\n"
"Please change the launch options in Steam before trying again.");

PLOG_WARNING << "Steam game " << pApp->id << " (" << pApp->names.normal << ") was unable to launch due to a conflict with the launch option of Steam!";
}
Expand Down Expand Up @@ -1011,12 +1007,12 @@ LaunchGame (app_record_s* pApp)
pos = confirmCopy.find ('%', pos + 2)) // Find the next occurence
{ }

confirmPopupText = "Could not launch game due to conflicting launch options in Steam:\n"
"\n"
+ confirmCopy + "\n"
"\n"
"Please change the launch options in Steam before trying again.";
ConfirmPopup = PopupState_Open;
SKIF_ImGui_InfoMessage ("Conflicting configuration",
"Could not launch game due to conflicting launch options in Steam:\n"
"\n"
+ confirmCopy + "\n"
"\n"
"Please change the launch options in Steam before trying again.");

PLOG_WARNING << "Steam game " << pApp->id << " (" << pApp->names.normal << ") was unable to launch due to a conflict with the launch option of Steam: " << confirmCopy;
}
Expand Down Expand Up @@ -1091,33 +1087,23 @@ SaveGameCover (app_record_s* pApp, std::wstring_view path)
if (extOriginal == L".bmp")
extTarget = L".png";

// Unsupported file format
if (extTarget != L".jpg" &&
extTarget != L".png")
{
confirmPopupTitle = "Unsupported image format";
confirmPopupText = "Please use a supported image format:\n"
"\n"
"*.png\n"
"*.jpg\n"
"*.jpeg\n"
"*.webp (no animation)";
ConfirmPopup = PopupState_Open;

return false;
}
constexpr char* error_title =
"Unsupported image format";
constexpr char* error_label =
"Please use a supported image format:\n"
"\n"
"*.png\n"
"*.jpg\n"
"*.jpeg\n"
"*.webp (no animation)";

// For local files, check if they do. in fact, exist and are local files
if (! isURL && ! std::filesystem::is_regular_file (fsPath, ec))

if (
( extTarget != L".jpg" && extTarget != L".png" ) || // Unsupported file format
(! isURL && ! std::filesystem::is_regular_file (fsPath, ec) ) // For local files, check if they do. in fact, exist and are local files
)
{
confirmPopupTitle = "Unsupported image format";
confirmPopupText = "Please use a supported image format:\n"
"\n"
"*.png\n"
"*.jpg\n"
"*.jpeg\n"
"*.webp (no animation)";
ConfirmPopup = PopupState_Open;
SKIF_ImGui_InfoMessage (error_title, error_label);

return false;
}
Expand Down Expand Up @@ -2100,7 +2086,9 @@ DrawGameContextMenu (app_record_s* pApp)
if (pApp->store == app_record_s::Store::Steam)
linkArgs += L" SKIF_SteamAppId=" + std::to_wstring (pApp->id);

confirmPopupTitle = "Create desktop shortcut";
constexpr char* info_title = "Create desktop shortcut";
constexpr char* info_label_success = "A desktop shortcut has been created.";
constexpr char* info_label_failure = "Failed to create a desktop shortcut!";

if (SKIF_Util_CreateShortcut (
linkPath.c_str(),
Expand All @@ -2111,11 +2099,9 @@ DrawGameContextMenu (app_record_s* pApp)
pApp->launch_configs[0].getExecutableFullPath().c_str()
)
)
confirmPopupText = "A desktop shortcut has been created.";
SKIF_ImGui_InfoMessage (info_title, info_label_success);
else
confirmPopupText = "Failed to create a desktop shortcut!";

ConfirmPopup = PopupState_Open;
SKIF_ImGui_InfoMessage (info_title, info_label_failure);
}
}

Expand Down Expand Up @@ -7675,55 +7661,6 @@ SKIF_UI_Tab_DrawLibrary (void)

#pragma region Popups

static float fConfirmPopupWidth;
if (ConfirmPopup == PopupState_Open)
{
fConfirmPopupWidth = ImGui::CalcTextSize (confirmPopupText.c_str()).x + ImGui::GetStyle().IndentSpacing * 3.0f; // 60.0f * SKIF_ImGui_GlobalDPIScale
ImGui::OpenPopup ("###ConfirmPopup");
ImGui::SetNextWindowSize (ImVec2 (fConfirmPopupWidth, 0.0f));
}

ImGui::SetNextWindowPos (ImGui::GetCurrentWindowRead()->Viewport->GetMainRect().GetCenter(), ImGuiCond_Always, ImVec2 (0.5f, 0.5f));
if (ImGui::BeginPopupModal ((confirmPopupTitle + "###ConfirmPopup").c_str(), nullptr, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove))
{
if (ConfirmPopup == PopupState_Open)
{
// Set the popup as opened after it has appeared (fixes popup not opening from other tabs)
ImGuiWindow* window = ImGui::FindWindowByName ("###ConfirmPopup");
if (window != nullptr && ! window->Appearing)
ConfirmPopup = PopupState_Opened;
}

ImGui::TreePush ("ConfirmTreePush");

SKIF_ImGui_Spacing ( );

ImGui::Text (confirmPopupText.c_str());

SKIF_ImGui_Spacing ( );
SKIF_ImGui_Spacing ( );

ImVec2 vButtonSize = ImVec2(80.0f * SKIF_ImGui_GlobalDPIScale, 0.0f);

ImGui::SetCursorPosX (fConfirmPopupWidth / 2 - vButtonSize.x / 2);

if (ImGui::Button ("OK", vButtonSize))
{
confirmPopupText = "";
ConfirmPopup = PopupState_Closed;
ImGui::CloseCurrentPopup ( );
}

SKIF_ImGui_DisallowMouseDragMove ( );

SKIF_ImGui_Spacing ( );

ImGui::TreePop ( );

ImGui::EndPopup ( );
}


if (RemoveGamePopup == PopupState_Open)
{
ImGui::OpenPopup("###RemoveGamePopup");
Expand Down
26 changes: 14 additions & 12 deletions src/utility/games.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,6 @@ SKIF_GamingCollection::RefreshRunningApps (std::vector <std::pair <std::string,
static DWORD lastGameRefresh = 0;
static std::wstring exeSteam = L"steam.exe";

extern std::string confirmPopupTitle;
extern std::string confirmPopupText;
extern bool steamRunning;
extern bool steamFallback;
extern SKIF_Util_CreateProcess_s iPlayCache[15];
Expand Down Expand Up @@ -456,16 +454,20 @@ SKIF_GamingCollection::RefreshRunningApps (std::vector <std::pair <std::string,
{
_registry.bWarningRTSS = true;
_registry.regKVWarningRTSS.putData (_registry.bWarningRTSS);
confirmPopupTitle = "One-time warning about RTSS.exe";
confirmPopupText = "RivaTuner Statistics Server (RTSS) occasionally conflicts with Special K.\n"
"Try closing it down if Special K does not behave as expected, or enable\n"
"the option 'Use Microsoft Detours API hooking' in the settings of RTSS.\n"
"\n"
"If you use MSI Afterburner, try closing it as well as otherwise it will\n"
"automatically restart RTSS silently in the background.\n"
"\n"
"This warning will not appear again.";
ConfirmPopup = PopupState_Open;

constexpr char* error_title =
"One-time warning about RTSS.exe";
constexpr char* error_label =
"RivaTuner Statistics Server (RTSS) occasionally conflicts with Special K.\n"
"Try closing it down if Special K does not behave as expected, or enable\n"
"the option 'Use Microsoft Detours API hooking' in the settings of RTSS.\n"
"\n"
"If you use MSI Afterburner, try closing it as well as otherwise it will\n"
"automatically restart RTSS silently in the background.\n"
"\n"
"This warning will not appear again.";

SKIF_ImGui_InfoMessage (error_title, error_label);
}

} while (Process32NextW (hProcessSnap, &pe32));
Expand Down
Loading

0 comments on commit 1a38e8c

Please sign in to comment.