From c6af5f390418dafd8bc6b0d8d0285109da6a5aa8 Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Tue, 24 Sep 2024 20:08:29 -0400 Subject: [PATCH 1/9] Change Screenshot Functionality --- Source/capture.cpp | 41 ++++++++++------------------------------- 1 file changed, 10 insertions(+), 31 deletions(-) diff --git a/Source/capture.cpp b/Source/capture.cpp index 5f8863f57d7..f56c2d8f7f8 100644 --- a/Source/capture.cpp +++ b/Source/capture.cpp @@ -26,6 +26,7 @@ #include "engine/backbuffer_state.hpp" #include "engine/dx.h" #include "engine/palette.h" +#include "plrmsg.h" #include "utils/file_util.h" #include "utils/log.hpp" #include "utils/paths.h" @@ -57,40 +58,19 @@ FILE *CaptureFile(std::string *dstPath) return OpenFile(dstPath->c_str(), "wb"); } -/** - * @brief Make a red version of the given palette and apply it to the screen. - */ -void RedPalette() -{ - for (int i = 0; i < 256; i++) { - system_palette[i].g = 0; - system_palette[i].b = 0; - } - palette_update(); - BltFast(nullptr, nullptr); - RenderPresent(); -} - } // namespace void CaptureScreen() { - SDL_Color palette[256]; std::string fileName; - const uint32_t startTime = SDL_GetTicks(); FILE *outStream = CaptureFile(&fileName); if (outStream == nullptr) { - LogError("Failed to open {} for writing: {}", fileName, std::strerror(errno)); + auto errorMessage = fmt::format(fmt::runtime(_(/* TRANSLATORS: {fileName} is the file path where the screenshot was attempted to be saved. */ "Failed to open {} for writing: {}")), fileName, std::strerror(errno)); + LogError("{}", errorMessage); + EventPlrMsg(errorMessage, UiFlags::ColorWhitegold); return; } - DrawAndBlit(); - PaletteGetEntries(256, palette); - RedPalette(); - for (int i = 0; i < 256; i++) { - system_palette[i] = palette[i]; - } - palette_update(); const tl::expected result = #if DEVILUTIONX_SCREENSHOT_FORMAT == DEVILUTIONX_SCREENSHOT_FORMAT_PCX @@ -100,16 +80,15 @@ void CaptureScreen() #endif if (!result.has_value()) { - LogError("Failed to save screenshot at {}: ", fileName, result.error()); + auto errorMessage = fmt::format(fmt::runtime(_(/* TRANSLATORS: {fileName} is the file path where the screenshot was attempted to be saved. {result.error()} is the error message returned during the save attempt. */ "Failed to save screenshot at {}: {}")), fileName, result.error()); + LogError("{}", errorMessage); + EventPlrMsg(errorMessage, UiFlags::ColorWhitegold); RemoveFile(fileName.c_str()); } else { - Log("Screenshot saved at {}", fileName); - } - const uint32_t timePassed = SDL_GetTicks() - startTime; - if (timePassed < 300) { - SDL_Delay(300 - timePassed); + auto successMessage = fmt::format(fmt::runtime(_(/* TRANSLATORS: {fileName} is the file path where the screenshot was successfully saved. */ "Screenshot saved at {}")), fileName); + Log("{}", successMessage); + EventPlrMsg(successMessage, UiFlags::ColorWhitegold); } - RedrawEverything(); } } // namespace devilution From f8adc9130569a7934d73589cd527524e6b63a872 Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Tue, 24 Sep 2024 21:45:35 -0400 Subject: [PATCH 2/9] Update capture.cpp --- Source/capture.cpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/Source/capture.cpp b/Source/capture.cpp index f56c2d8f7f8..0220c83ab78 100644 --- a/Source/capture.cpp +++ b/Source/capture.cpp @@ -46,7 +46,7 @@ FILE *CaptureFile(std::string *dstPath) const std::time_t tt = std::time(nullptr); const std::tm *tm = std::localtime(&tt); const std::string filename = tm != nullptr - ? fmt::format("Screenshot from {:04}-{:02}-{:02} {:02}-{:02}-{:02}", + ? fmt::format("{:04}-{:02}-{:02} {:02}-{:02}-{:02}", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec) : "Screenshot"; *dstPath = StrCat(paths::PrefPath(), filename, ext); @@ -60,6 +60,16 @@ FILE *CaptureFile(std::string *dstPath) } // namespace +std::string FileNameForChat(const std::string &fullPath) +{ + // Extracts just the file name from the full path + auto pos = fullPath.find_last_of("\\/"); + if (pos == std::string::npos) { + return fullPath; + } + return fullPath.substr(pos + 1); +} + void CaptureScreen() { std::string fileName; @@ -68,7 +78,9 @@ void CaptureScreen() if (outStream == nullptr) { auto errorMessage = fmt::format(fmt::runtime(_(/* TRANSLATORS: {fileName} is the file path where the screenshot was attempted to be saved. */ "Failed to open {} for writing: {}")), fileName, std::strerror(errno)); LogError("{}", errorMessage); - EventPlrMsg(errorMessage, UiFlags::ColorWhitegold); + + auto chatMessage = fmt::format(fmt::runtime(_(/* TRANSLATORS: {fileName} is the name of the file where the screenshot was attempted to be saved. */ "Failed to open {} for writing")), FileNameForChat(fileName)); + EventPlrMsg(chatMessage, UiFlags::ColorWhitegold); return; } @@ -80,14 +92,18 @@ void CaptureScreen() #endif if (!result.has_value()) { - auto errorMessage = fmt::format(fmt::runtime(_(/* TRANSLATORS: {fileName} is the file path where the screenshot was attempted to be saved. {result.error()} is the error message returned during the save attempt. */ "Failed to save screenshot at {}: {}")), fileName, result.error()); + auto errorMessage = fmt::format(fmt::runtime(_(/* TRANSLATORS: {fileName} is the file path where the screenshot was attempted to be saved. {result.error()} is the error message returned during the save attempt. */ "Failed to save screenshot {}: {}")), fileName, result.error()); LogError("{}", errorMessage); - EventPlrMsg(errorMessage, UiFlags::ColorWhitegold); + + auto chatMessage = fmt::format(fmt::runtime(_(/* TRANSLATORS: {fileName} is the name of the file where the screenshot was attempted to be saved. */ "Failed to save screenshot {}")), FileNameForChat(fileName)); + EventPlrMsg(chatMessage, UiFlags::ColorWhitegold); RemoveFile(fileName.c_str()); } else { auto successMessage = fmt::format(fmt::runtime(_(/* TRANSLATORS: {fileName} is the file path where the screenshot was successfully saved. */ "Screenshot saved at {}")), fileName); Log("{}", successMessage); - EventPlrMsg(successMessage, UiFlags::ColorWhitegold); + + auto chatMessage = fmt::format(fmt::runtime(_(/* TRANSLATORS: {fileName} is the name of the file where the screenshot was successfully saved. */ "Screenshot saved as {}")), FileNameForChat(fileName)); + EventPlrMsg(chatMessage, UiFlags::ColorWhitegold); } } From 735535418351655f373c2b1e9a7468f2c20777db Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Tue, 24 Sep 2024 23:02:28 -0400 Subject: [PATCH 3/9] anon --- Source/capture.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/capture.cpp b/Source/capture.cpp index 0220c83ab78..57576afab97 100644 --- a/Source/capture.cpp +++ b/Source/capture.cpp @@ -58,8 +58,6 @@ FILE *CaptureFile(std::string *dstPath) return OpenFile(dstPath->c_str(), "wb"); } -} // namespace - std::string FileNameForChat(const std::string &fullPath) { // Extracts just the file name from the full path @@ -70,6 +68,8 @@ std::string FileNameForChat(const std::string &fullPath) return fullPath.substr(pos + 1); } +} // namespace + void CaptureScreen() { std::string fileName; From 2e0b6f229c336b61223893ee73a93fa760e68460 Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Wed, 25 Sep 2024 22:18:34 -0400 Subject: [PATCH 4/9] Sound and ignore gamma --- Source/capture.cpp | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/Source/capture.cpp b/Source/capture.cpp index 57576afab97..a73bc82d7f3 100644 --- a/Source/capture.cpp +++ b/Source/capture.cpp @@ -46,7 +46,7 @@ FILE *CaptureFile(std::string *dstPath) const std::time_t tt = std::time(nullptr); const std::tm *tm = std::localtime(&tt); const std::string filename = tm != nullptr - ? fmt::format("{:04}-{:02}-{:02} {:02}-{:02}-{:02}", + ? fmt::format("Screenshot from {:04}-{:02}-{:02} {:02}-{:02}-{:02}", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec) : "Screenshot"; *dstPath = StrCat(paths::PrefPath(), filename, ext); @@ -72,17 +72,21 @@ std::string FileNameForChat(const std::string &fullPath) void CaptureScreen() { + SDL_Color palette[256]; std::string fileName; + const uint32_t startTime = SDL_GetTicks(); FILE *outStream = CaptureFile(&fileName); if (outStream == nullptr) { - auto errorMessage = fmt::format(fmt::runtime(_(/* TRANSLATORS: {fileName} is the file path where the screenshot was attempted to be saved. */ "Failed to open {} for writing: {}")), fileName, std::strerror(errno)); - LogError("{}", errorMessage); - - auto chatMessage = fmt::format(fmt::runtime(_(/* TRANSLATORS: {fileName} is the name of the file where the screenshot was attempted to be saved. */ "Failed to open {} for writing")), FileNameForChat(fileName)); - EventPlrMsg(chatMessage, UiFlags::ColorWhitegold); + LogError("Failed to open {} for writing: {}", fileName, std::strerror(errno)); return; } + DrawAndBlit(); + + auto tempPalette = system_palette; + system_palette = orig_palette; + palette_update(); + RedrawEverything(); const tl::expected result = #if DEVILUTIONX_SCREENSHOT_FORMAT == DEVILUTIONX_SCREENSHOT_FORMAT_PCX @@ -92,19 +96,16 @@ void CaptureScreen() #endif if (!result.has_value()) { - auto errorMessage = fmt::format(fmt::runtime(_(/* TRANSLATORS: {fileName} is the file path where the screenshot was attempted to be saved. {result.error()} is the error message returned during the save attempt. */ "Failed to save screenshot {}: {}")), fileName, result.error()); - LogError("{}", errorMessage); - - auto chatMessage = fmt::format(fmt::runtime(_(/* TRANSLATORS: {fileName} is the name of the file where the screenshot was attempted to be saved. */ "Failed to save screenshot {}")), FileNameForChat(fileName)); - EventPlrMsg(chatMessage, UiFlags::ColorWhitegold); + LogError("Failed to save screenshot at {}: ", fileName, result.error()); RemoveFile(fileName.c_str()); } else { - auto successMessage = fmt::format(fmt::runtime(_(/* TRANSLATORS: {fileName} is the file path where the screenshot was successfully saved. */ "Screenshot saved at {}")), fileName); - Log("{}", successMessage); - - auto chatMessage = fmt::format(fmt::runtime(_(/* TRANSLATORS: {fileName} is the name of the file where the screenshot was successfully saved. */ "Screenshot saved as {}")), FileNameForChat(fileName)); - EventPlrMsg(chatMessage, UiFlags::ColorWhitegold); + Log("Screenshot saved at {}", fileName); + PlaySFX(SfxID::MenuSelect); } + + system_palette = tempPalette; + palette_update(); + RedrawEverything(); } } // namespace devilution From 629e236c2788f1d8c75f68025538eaf60ba6c9b4 Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Wed, 25 Sep 2024 22:20:21 -0400 Subject: [PATCH 5/9] Remove unused --- Source/capture.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Source/capture.cpp b/Source/capture.cpp index a73bc82d7f3..96cc3a9cc2e 100644 --- a/Source/capture.cpp +++ b/Source/capture.cpp @@ -58,16 +58,6 @@ FILE *CaptureFile(std::string *dstPath) return OpenFile(dstPath->c_str(), "wb"); } -std::string FileNameForChat(const std::string &fullPath) -{ - // Extracts just the file name from the full path - auto pos = fullPath.find_last_of("\\/"); - if (pos == std::string::npos) { - return fullPath; - } - return fullPath.substr(pos + 1); -} - } // namespace void CaptureScreen() From b30a874e61b2a31c7163c80331b6e4f77d22d075 Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Wed, 25 Sep 2024 22:20:35 -0400 Subject: [PATCH 6/9] Update capture.cpp --- Source/capture.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/capture.cpp b/Source/capture.cpp index 96cc3a9cc2e..cf78da099f3 100644 --- a/Source/capture.cpp +++ b/Source/capture.cpp @@ -26,7 +26,6 @@ #include "engine/backbuffer_state.hpp" #include "engine/dx.h" #include "engine/palette.h" -#include "plrmsg.h" #include "utils/file_util.h" #include "utils/log.hpp" #include "utils/paths.h" From f5062bd428eb0ebdd23c50e1c7684d700dc1a0c8 Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Wed, 25 Sep 2024 22:23:52 -0400 Subject: [PATCH 7/9] Update capture.cpp --- Source/capture.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/capture.cpp b/Source/capture.cpp index cf78da099f3..9eb6c217a3e 100644 --- a/Source/capture.cpp +++ b/Source/capture.cpp @@ -23,6 +23,7 @@ #include "utils/surface_to_png.hpp" #endif +#include "effects.h" #include "engine/backbuffer_state.hpp" #include "engine/dx.h" #include "engine/palette.h" @@ -75,7 +76,6 @@ void CaptureScreen() auto tempPalette = system_palette; system_palette = orig_palette; palette_update(); - RedrawEverything(); const tl::expected result = #if DEVILUTIONX_SCREENSHOT_FORMAT == DEVILUTIONX_SCREENSHOT_FORMAT_PCX From 071b8149ed0da8a69694babcd82e7af84a0859ed Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Wed, 25 Sep 2024 22:24:32 -0400 Subject: [PATCH 8/9] Update capture.cpp --- Source/capture.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/capture.cpp b/Source/capture.cpp index 9eb6c217a3e..797d3c32334 100644 --- a/Source/capture.cpp +++ b/Source/capture.cpp @@ -74,6 +74,7 @@ void CaptureScreen() DrawAndBlit(); auto tempPalette = system_palette; + system_palette = orig_palette; palette_update(); @@ -91,7 +92,6 @@ void CaptureScreen() Log("Screenshot saved at {}", fileName); PlaySFX(SfxID::MenuSelect); } - system_palette = tempPalette; palette_update(); RedrawEverything(); From 60bcdf657c8c349067bd5b607e5fb2397504a8c2 Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Mon, 7 Oct 2024 22:28:03 -0400 Subject: [PATCH 9/9] Update capture.cpp --- Source/capture.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/capture.cpp b/Source/capture.cpp index 797d3c32334..d5b2dcef49e 100644 --- a/Source/capture.cpp +++ b/Source/capture.cpp @@ -62,7 +62,6 @@ FILE *CaptureFile(std::string *dstPath) void CaptureScreen() { - SDL_Color palette[256]; std::string fileName; const uint32_t startTime = SDL_GetTicks();