Add refresh rate selection in settings
This commit is contained in:
+11
-2
@@ -212,6 +212,13 @@ scenes::lobby::lobby()
|
||||
auto json_show_plots = root["show_performance_metrics"];
|
||||
if (json_show_plots.is_bool())
|
||||
show_performance_metrics = json_show_plots.get_bool();
|
||||
|
||||
auto rate = root["preferred_refresh_rate"];
|
||||
if (rate.is_double())
|
||||
{
|
||||
preferred_refresh_rate = rate.get_double();
|
||||
session.set_refresh_rate(preferred_refresh_rate);
|
||||
}
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
@@ -277,8 +284,10 @@ void scenes::lobby::save_config()
|
||||
std::ofstream json(application::get_config_path() / "client.json");
|
||||
|
||||
json << "{\"servers\":[" << servers_str << "],"
|
||||
<< "\"show_performance_metrics\":" << std::boolalpha << show_performance_metrics
|
||||
<< "}";
|
||||
<< "\"show_performance_metrics\":" << std::boolalpha << show_performance_metrics;
|
||||
if (preferred_refresh_rate != 0.)
|
||||
json << ",\"preferred_refresh_rate\":" << preferred_refresh_rate ;
|
||||
json << "}";
|
||||
}
|
||||
|
||||
static std::string ip_address_to_string(const in_addr& addr)
|
||||
|
||||
@@ -111,6 +111,7 @@ class lobby : public scene_impl<lobby>
|
||||
tab last_current_tab = tab::server_list;
|
||||
ImTextureID about_picture;
|
||||
|
||||
float preferred_refresh_rate = 0;
|
||||
bool show_performance_metrics = false;
|
||||
|
||||
void gui_connecting();
|
||||
|
||||
@@ -330,6 +330,27 @@ void scenes::lobby::gui_settings()
|
||||
{
|
||||
ImGuiStyle & style = ImGui::GetStyle();
|
||||
|
||||
{
|
||||
const auto & refresh_rates = session.get_refresh_rates();
|
||||
float current = session.get_current_refresh_rate();
|
||||
if (not refresh_rates.empty())
|
||||
{
|
||||
if (ImGui::BeginCombo("Refresh rate", fmt::format("{}", current).c_str()))
|
||||
{
|
||||
for (float rate: refresh_rates)
|
||||
{
|
||||
if (ImGui::Selectable(fmt::format("{}", rate).c_str(), rate == current) and rate != current)
|
||||
{
|
||||
session.set_refresh_rate(rate);
|
||||
preferred_refresh_rate = rate;
|
||||
save_config();
|
||||
}
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui::Checkbox("Show performance metrics", &show_performance_metrics))
|
||||
save_config();
|
||||
vibrate_on_hover();
|
||||
|
||||
Reference in New Issue
Block a user