Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎮 UI Presets (Novice/Regular/Expert/Minimallist) #3071

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions source/main/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ CVar* flexbody_defrag_invert_lookup;

// GUI
CVar* ui_show_live_repair_controls;
CVar* ui_preset;
CVar* ui_hide_gui;

// Instance management
void SetCacheSystem (CacheSystem* obj) { g_cache_system = obj; }
Expand Down Expand Up @@ -495,6 +497,18 @@ std::string ToLocalizedString(SimResetMode e)
}
}

std::string ToLocalizedString(UiPreset e)
{
switch (e)
{
case UiPreset::NOVICE: return _LC("UiPreset", "Novice");
case UiPreset::REGULAR: return _LC("UiPreset", "Regular");
case UiPreset::EXPERT: return _LC("UiPreset", "Expert");
case UiPreset::MINIMALLIST: return _LC("UiPreset", "Minimallist");
default: return "";
}
}

const char* MsgTypeToString(MsgType type)
{
switch (type)
Expand Down
16 changes: 15 additions & 1 deletion source/main/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,18 @@ enum class SimResetMode
};
std::string ToLocalizedString(SimResetMode e);

/// See `UiPresets[]` list in GUIManager.cpp (declared extern in GUIManager.h)
// Do NOT change numbers - used for indexing `RoR::UiPresetEntry::uip_values`
enum class UiPreset
{
NOVICE,
REGULAR,
EXPERT,
MINIMALLIST,
Count
};
std::string ToLocalizedString(UiPreset e);

enum VisibilityMasks
{
DEPTHMAP_ENABLED = BITMASK(1),
Expand Down Expand Up @@ -458,7 +470,9 @@ extern CVar* flexbody_defrag_reorder_texcoords;
extern CVar* flexbody_defrag_invert_lookup;

// GUI
extern CVar* ui_show_live_repair_controls;
extern CVar* ui_show_live_repair_controls; //!< bool
extern CVar* ui_preset; //!< enum `RoR::UiPreset`
extern CVar* ui_hide_gui; //!< bool; The 'hide GUI' hotkey state

// ------------------------------------------------------------------------------------------------
// Global objects
Expand Down
35 changes: 29 additions & 6 deletions source/main/gui/GUIManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,19 @@

#define RESOURCE_FILENAME "MyGUI_Core.xml"

namespace RoR {
using namespace RoR;

/// Global list of UI Presets, selectable via Settings menu in TopMenubar
UiPresetEntry RoR::UiPresets[] =
{
// Cvar name | NOVICE, REGULAR, EXPERT, MINIMALLIST
{ "gfx_surveymap_icons", {"true", "true", "true", "false"} },
{ "gfx_declutter_map", {"false", "true", "false", "true"} },
{ "ui_show_live_repair_controls", {"true", "false", "false", "false"} },

// List closure
{ nullptr, {} }
};

GUIManager::GUIManager()
{
Expand Down Expand Up @@ -124,6 +136,19 @@ bool GUIManager::AreStaticMenusAllowed() //!< i.e. top menubar / vehicle UI butt
!this->FlexbodyDebug.IsHovered());
}

void GUIManager::ApplyUiPreset() //!< reads cvar 'ui_preset'
{
const int preset = App::ui_preset->getInt();
int i = 0;
while (UiPresets[i].uip_cvar != nullptr)
{
App::GetConsole()->cVarSet(
UiPresets[i].uip_cvar,
UiPresets[i].uip_values[preset]);
i++;
}
}

void GUIManager::DrawSimulationGui(float dt)
{
if (App::app_state->getEnum<AppState>() == AppState::SIMULATION)
Expand Down Expand Up @@ -174,7 +199,7 @@ void GUIManager::DrawSimGuiBuffered(GfxActor* player_gfx_actor)

if (!this->ConsoleWindow.IsVisible())
{
if (!m_hide_gui)
if (!App::ui_hide_gui->getBool())
{
this->ChatBox.Draw(); // Messages must be always visible
}
Expand Down Expand Up @@ -262,7 +287,7 @@ void GUIManager::SetSceneManagerForGuiRendering(Ogre::SceneManager* scene_manage

void GUIManager::SetGuiHidden(bool hidden)
{
m_hide_gui = hidden;
App::ui_hide_gui->setVal(hidden);
App::GetOverlayWrapper()->showDashboardOverlays(!hidden, App::GetGameContext()->GetPlayerActor());
if (hidden)
{
Expand Down Expand Up @@ -374,7 +399,7 @@ void GUIManager::SetupImGui()

void GUIManager::DrawCommonGui()
{
if (App::mp_state->getEnum<MpState>() == MpState::CONNECTED && !m_hide_gui)
if (App::mp_state->getEnum<MpState>() == MpState::CONNECTED && !App::ui_hide_gui->getBool())
{
this->MpClientList.Draw();
}
Expand Down Expand Up @@ -527,5 +552,3 @@ void GUIManager::UpdateInputEvents(float dt)
}
}
}

} // namespace RoR
15 changes: 13 additions & 2 deletions source/main/gui/GUIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "OgreImGui.h"
#include "Application.h"
#include "CVar.h"
#include "GUI_MessageBox.h"

// GUI panels
Expand Down Expand Up @@ -61,8 +62,18 @@
#include <MyGUI_UString.h>
#include <OgreOverlay.h>

#include <string>

namespace RoR {

struct UiPresetEntry
{
const char* uip_cvar;
std::string uip_values[(int)UiPreset::Count];
};

extern UiPresetEntry UiPresets[];

class GUIManager
{
public:
Expand Down Expand Up @@ -135,6 +146,7 @@ class GUIManager
bool IsGuiCaptureKeyboardRequested() const { return m_gui_kb_capture_requested; }
void ApplyGuiCaptureKeyboard(); //!< Call after rendered frame to apply queued value
bool AreStaticMenusAllowed(); //!< i.e. top menubar / vehicle UI buttons
void ApplyUiPreset(); //!< reads cvar 'ui_preset'

void NewImGuiFrame(float dt);
void DrawMainMenuGui();
Expand All @@ -143,7 +155,7 @@ class GUIManager
void DrawCommonGui();

void SetGuiHidden(bool visible);
bool IsGuiHidden() const { return m_hide_gui; }
bool IsGuiHidden() const { return App::ui_hide_gui->getBool(); }

void SetSceneManagerForGuiRendering(Ogre::SceneManager* scene_manager);

Expand All @@ -168,7 +180,6 @@ class GUIManager

MyGUI::Gui* m_mygui = nullptr;
MyGUI::OgrePlatform* m_mygui_platform = nullptr;
bool m_hide_gui = false;
OgreImGui m_imgui;
GuiTheme m_theme;
bool m_gui_kb_capture_queued = false; //!< Resets and accumulates every frame
Expand Down
102 changes: 97 additions & 5 deletions source/main/gui/panels/GUI_GameSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ void GameSettings::Draw()
ImGui::EndChild();
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem(_LC("GameSettings", "UI")))
{
ImGui::BeginChild("Settings-UI-scroll", ImVec2(0.f, child_height), false);
this->DrawUiSettings();
ImGui::EndChild();
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem(_LC("GameSettings", "Graphics")))
{
ImGui::BeginChild("Settings-Graphics-scroll", ImVec2(0.f, child_height), false);
Expand Down Expand Up @@ -242,9 +249,6 @@ void GameSettings::DrawGameplaySettings()
DrawGCombo(App::sim_gearbox_mode, _LC("GameSettings", "Gearbox mode"),
m_combo_items_gearbox_mode.c_str());

DrawGCheckbox(App::gfx_speedo_digital, _LC("GameSettings", "Digital speedometer"));
DrawGCheckbox(App::gfx_speedo_imperial, _LC("GameSettings", "Imperial speedometer"));

//DrawGCheckbox(App::gfx_flexbody_cache, "Enable flexbody cache");

DrawGCheckbox(App::sim_spawn_running, _LC("GameSettings", "Engines spawn running"));
Expand All @@ -266,8 +270,6 @@ void GameSettings::DrawGameplaySettings()
DrawGCheckbox(App::io_discord_rpc, _LC("GameSettings", "Discord Rich Presence"));

DrawGCheckbox(App::sim_quickload_dialog, _LC("GameSettings", "Show confirm. UI dialog for quickload"));

DrawGCheckbox(App::ui_show_live_repair_controls, _LC("GameSettings", "Show controls in live repair box"));
}

void GameSettings::DrawAudioSettings()
Expand Down Expand Up @@ -300,6 +302,27 @@ void GameSettings::DrawAudioSettings()
#endif // USE_OPENAL
}

void GameSettings::DrawUiSettings()
{
ImGui::TextDisabled("%s", _LC("GameSettings", "UI settings"));

this->DrawUiPresetCombo();

ImGui::Separator();

DrawGCheckbox(App::gfx_speedo_digital, _LC("GameSettings", "Digital speedometer"));
DrawGCheckbox(App::gfx_speedo_imperial, _LC("GameSettings", "Imperial speedometer"));

DrawGCheckbox(App::ui_show_live_repair_controls, _LC("GameSettings", "Show controls in live repair box"));

DrawGCheckbox(App::gfx_surveymap_icons, _LC("GameSettings", "Overview map icons"));
if (App::gfx_surveymap_icons->getBool())
{
DrawGCheckbox(App::gfx_declutter_map, _LC("GameSettings", "Declutter overview map"));
}

}

void GameSettings::DrawGraphicsSettings()
{
ImGui::TextDisabled("%s", _LC("GameSettings", "Video settings"));
Expand Down Expand Up @@ -533,4 +556,73 @@ void GameSettings::SetVisible(bool v)
ImAddItemToComboboxString(m_combo_items_input_grab, ToLocalizedString(IoInputGrabMode::DYNAMIC));
ImTerminateComboboxString(m_combo_items_input_grab);
}

if (m_cached_uipreset_combo_string == "")
{
ImAddItemToComboboxString(m_cached_uipreset_combo_string, ToLocalizedString(UiPreset::NOVICE));
ImAddItemToComboboxString(m_cached_uipreset_combo_string, ToLocalizedString(UiPreset::REGULAR));
ImAddItemToComboboxString(m_cached_uipreset_combo_string, ToLocalizedString(UiPreset::EXPERT));
ImAddItemToComboboxString(m_cached_uipreset_combo_string, ToLocalizedString(UiPreset::MINIMALLIST));
ImTerminateComboboxString(m_cached_uipreset_combo_string);
}
}

void GameSettings::DrawUiPresetCombo()
{
ImGui::PushID("uiPreset");


DrawGCombo(App::ui_preset, _LC("TopMenubar", "UI Preset"), m_cached_uipreset_combo_string.c_str());
if (ImGui::IsItemEdited())
{
App::GetGuiManager()->ApplyUiPreset();
}
if (ImGui::IsItemHovered())
{
ImGui::BeginTooltip();
const float COLLUMNWIDTH_NAME = 175.f;
const float COLLUMNWIDTH_VALUE = 60.f;
// Hack to make space for the table (doesn't autoresize)
ImGui::Dummy(ImVec2(COLLUMNWIDTH_NAME + COLLUMNWIDTH_VALUE*((int)UiPreset::Count), 1.f));

// UiPresets table
ImGui::Columns((int)UiPreset::Count + 1);
ImGui::SetColumnWidth(0, COLLUMNWIDTH_NAME);
for (int i = 0; i < (int)UiPreset::Count; i++)
{
ImGui::SetColumnWidth(i+1, COLLUMNWIDTH_VALUE);
}

// table header
ImGui::TextDisabled("%s", "Setting");
ImGui::NextColumn();
for (int i = 0; i < (int)UiPreset::Count; i++)
{
ImGui::TextDisabled("%s", ToLocalizedString((UiPreset)i).c_str());
ImGui::NextColumn();
}

// table body
ImGui::Separator();

int presetId = 0;
while (UiPresets[presetId].uip_cvar != nullptr)
{
ImGui::Text("%s", UiPresets[presetId].uip_cvar);
ImGui::NextColumn();
for (int i = 0; i < (int)UiPreset::Count; i++)
{
ImGui::Text("%s", UiPresets[presetId].uip_values[i].c_str());
ImGui::NextColumn();
}

presetId++;
}

// end table
ImGui::Columns(1);
ImGui::EndTooltip();
}

ImGui::PopID(); //"uiPreset"
}
5 changes: 5 additions & 0 deletions source/main/gui/panels/GUI_GameSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ class GameSettings
void DrawRenderSystemSettings();
void DrawGeneralSettings();
void DrawGameplaySettings();
void DrawUiSettings();
void DrawGraphicsSettings();
void DrawAudioSettings();
void DrawControlSettings();
void DrawDiagSettings();

// Helpers
void DrawUiPresetCombo();

// GUI state
bool m_is_visible = false;

Expand All @@ -62,6 +66,7 @@ class GameSettings
std::string m_combo_items_water_mode;
std::string m_combo_items_extcam_mode;
std::string m_combo_items_input_grab;
std::string m_cached_uipreset_combo_string;
};

} // namespace GUI
Expand Down
Loading