GUI: add custom title format to settings dialog

This commit is contained in:
Megamouse 2020-02-14 01:08:02 +01:00
parent 23f1515448
commit ee54ba970a
15 changed files with 268 additions and 147 deletions

View file

@ -16,6 +16,7 @@
#include "Emu/Cell/lv2/sys_prx.h"
#include "Emu/Cell/lv2/sys_rsx.h"
#include "Emu/title.h"
#include "Emu/IdManager.h"
#include "Emu/RSX/GSRender.h"
#include "Emu/RSX/Capture/rsx_replay.h"
@ -44,8 +45,6 @@
#include "display_sleep_control.h"
#include "rpcs3_version.h"
#if defined(_WIN32) || defined(HAVE_VULKAN)
#include "Emu/RSX/VK/VulkanAPI.h"
#endif
@ -1867,124 +1866,16 @@ void Emulator::Stop(bool restart)
}
}
std::string Emulator::FormatTitle(double fps) const
std::string Emulator::GetFormattedTitle(double fps) const
{
// Get version by substringing VersionNumber-buildnumber-commithash to get just the part before the dash
std::string version = rpcs3::get_version().to_string();
const auto last_minus = version.find_last_of('-');
rpcs3::title_format_data title_data;
title_data.format = g_cfg.misc.title_format.to_string();
title_data.title = GetTitle();
title_data.title_id = GetTitleID();
title_data.renderer = g_cfg.video.renderer.to_string();
title_data.fps = fps;
// Add branch and commit hash to version on frame unless it's master.
if (rpcs3::get_branch() != "master"sv && rpcs3::get_branch() != "HEAD"sv)
{
version = version.substr(0, ~last_minus ? last_minus + 9 : last_minus);
version += '-';
version += rpcs3::get_branch();
}
else
{
version = version.substr(0, last_minus);
}
auto [title_format, life1] = g_cfg.misc.title_format.get();
// Parse title format string
std::string title_string;
// Backward compatibility hack
std::size_t fmt_start = 0;
if (g_cfg.misc.show_fps_in_title.get() == false)
{
if (title_format.starts_with("FPS: %F | "))
{
// Remove "FPS" from the title if detected
fmt_start = 10;
}
}
for (std::size_t i = fmt_start; i < title_format.size();)
{
const char c1 = title_format[i];
if (c1 == '\0')
{
break;
}
switch (c1)
{
case '%':
{
const char c2 = title_format[i + 1];
if (c2 == '\0')
{
title_string += '%';
i++;
continue;
}
switch (c2)
{
case '%':
{
title_string += '%';
break;
}
case 'T':
{
title_string += this->GetTitle();
break;
}
case 't':
{
title_string += this->GetTitleID();
break;
}
case 'R':
{
fmt::append(title_string, "%s", g_cfg.video.renderer.get());
break;
}
case 'V':
{
title_string += version;
break;
}
case 'F':
{
if (g_cfg.misc.show_fps_in_title)
{
fmt::append(title_string, "%.2f", fps);
}
else
{
title_string += "Disabled";
}
break;
}
default:
{
title_string += '%';
title_string += c2;
break;
}
}
i += 2;
break;
}
default:
{
title_string += c1;
i += 1;
break;
}
}
}
return title_string;
return rpcs3::get_formatted_title(title_data);
}
std::string cfg_root::node_vfs::get(const cfg::string& _cfg, const char* _def) const