1
0
mirror of https://github.com/luanti-org/luanti.git synced 2026-01-14 05:15:21 +01:00

Allow taking screenshots in main menu (#16749)

Co-authored-by: sfan5 <sfan5@live.de>
Co-authored-by: siliconsniffer <siliconsniffer@users.noreply.github.com>
This commit is contained in:
siliconsniffer
2025-12-21 12:08:16 +01:00
committed by GitHub
parent 17a33fccd7
commit f91e58abab
8 changed files with 162 additions and 63 deletions

View File

@@ -22,6 +22,7 @@
#include <ICameraSceneNode.h>
#include <IGUIStaticText.h>
#include "client/imagefilters.h"
#include "util/screenshot.h"
#include "util/tracy_wrapper.h"
#include "script/common/c_types.h" // LuaError
@@ -39,6 +40,13 @@ void TextDestGuiEngine::gotText(const StringMap &fields)
m_engine->getScriptIface()->handleMainMenuButtons(fields);
}
void TextDestGuiEngine::requestScreenshot()
{
if (m_engine) {
m_engine->requestScreenshot();
}
}
/******************************************************************************/
MenuTextureSource::~MenuTextureSource()
{
@@ -367,6 +375,14 @@ void GUIEngine::run()
// the menu.
drawHeader(driver);
// Take screenshot if requested
// Must be before endScene() to capture the rendered frame
if (m_take_screenshot) {
m_take_screenshot = false;
std::string filename;
takeScreenshot(driver, filename);
}
driver->endScene();
}

View File

@@ -62,6 +62,11 @@ public:
*/
void gotText(const StringMap &fields);
/**
* Request a screenshot from the main menu
*/
void requestScreenshot();
private:
/** target to transmit data to */
GUIEngine *m_engine = nullptr;
@@ -146,6 +151,14 @@ public:
return m_scriptdir;
}
/**
* Request taking a screenshot on the next frame
*/
void requestScreenshot()
{
m_take_screenshot = true;
}
/**
* Get translations for content
*
@@ -199,6 +212,9 @@ private:
/** variable used to abort menu and return back to main game handling */
bool m_startgame = false;
/** flag to take a screenshot on next frame */
bool m_take_screenshot = false;
/** scripting interface */
std::unique_ptr<MainMenuScripting> m_script;

View File

@@ -33,6 +33,7 @@
#include "client/fontengine.h"
#include "client/sound.h"
#include "util/numeric.h"
#include "util/screenshot.h"
#include "util/string.h" // for parseColorString()
#include "irrlicht_changes/static_text.h"
#include "client/guiscalingfilter.h"
@@ -4082,9 +4083,13 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
return true;
}
if (m_client != NULL && event.KeyInput.PressedDown &&
if (event.KeyInput.PressedDown &&
(kp == getKeySetting("keymap_screenshot"))) {
m_client->makeScreenshot();
if (m_client) {
m_client->makeScreenshot();
} else if (m_text_dst) { // in main menu
m_text_dst->requestScreenshot();
}
}
if (event.KeyInput.PressedDown && kp == getKeySetting("keymap_toggle_debug")) {

View File

@@ -68,6 +68,7 @@ struct TextDest
virtual ~TextDest() = default;
virtual void gotText(const StringMap &fields) = 0;
virtual void requestScreenshot() {}
std::string m_formname;
};