Store imgui.ini and user.imstyle in dhewm3 config dir instead of $PWD

This commit is contained in:
Daniel Gibson 2024-06-04 10:52:30 +02:00
parent 81d912ab4b
commit 51270dd390
2 changed files with 11 additions and 4 deletions

View file

@ -313,7 +313,8 @@ bool ReadImGuiStyle( ImGuiStyle& s, const char* filename )
{ {
FILE* f = DG_IMSAVESTYLE_FOPEN( filename, "r" ); // TODO: "rt" on Windows? FILE* f = DG_IMSAVESTYLE_FOPEN( filename, "r" ); // TODO: "rt" on Windows?
if ( f == nullptr ) { if ( f == nullptr ) {
warnPrintf( "Couldn't open '%s' for reading\n", filename ); // DG: shut up this warning, user don't *have* to write their own style
//warnPrintf( "Couldn't open '%s' for reading\n", filename );
return false; return false;
} }

View file

@ -73,8 +73,9 @@ static ImVec2 warningOverlayStartPos;
idStr GetUserStyleFilename() idStr GetUserStyleFilename()
{ {
// TODO: put this into the config dir idStr ret( cvarSystem->GetCVarString( "fs_configpath" ) );
return idStr( "user.imstyle" ); ret += "/user.imstyle";
return ret;
} }
static void UpdateWarningOverlay() static void UpdateWarningOverlay()
@ -227,10 +228,15 @@ bool Init(void* _sdlWindow, void* sdlGlContext)
common->Warning( "Failed to create ImGui Context!\n" ); common->Warning( "Failed to create ImGui Context!\n" );
return false; return false;
} }
ImGuiIO& io = ImGui::GetIO(); (void)io; ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
static idStr iniPath;
iniPath = cvarSystem->GetCVarString( "fs_configpath" );
iniPath += "/imgui.ini";
io.IniFilename = iniPath.c_str();
SetImGuiStyle( Style::Dhewm3 ); SetImGuiStyle( Style::Dhewm3 );
userStyle = ImGui::GetStyle(); // set dhewm3 style as default, in case the user style is missing values userStyle = ImGui::GetStyle(); // set dhewm3 style as default, in case the user style is missing values
if ( DG::ReadImGuiStyle( userStyle, GetUserStyleFilename() ) && imgui_style.GetInteger() == 2 ) { if ( DG::ReadImGuiStyle( userStyle, GetUserStyleFilename() ) && imgui_style.GetInteger() == 2 ) {