Skip to content

Commit

Permalink
Update settings logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Karaulov committed Nov 23, 2022
1 parent 015efc8 commit f2ec7ff
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 144 deletions.
35 changes: 21 additions & 14 deletions src/editor/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void Gui::init()


// ImFileDialog requires you to set the CreateTexture and DeleteTexture
ifd::FileDialog::Instance().CreateTexture = [](unsigned char* data, int w, int h, char fmt) -> void*{
ifd::FileDialog::Instance().CreateTexture = [](unsigned char* data, int w, int h, char fmt) -> void* {
GLuint tex;

glGenTextures(1, &tex);
Expand Down Expand Up @@ -1116,13 +1116,9 @@ void Gui::drawMenuBar()
ImGui::EndMenu();
}

if (ImGui::MenuItem("Test"))
if (map && dirExists(g_settings.gamedir + "/svencoop_addon/maps/"))
{
if (!map || !dirExists(g_settings.gamedir + "/svencoop_addon/maps/"))
{
logf("Failed. No svencoop directory found.\n");
}
else
if (ImGui::MenuItem("Sven Test"))
{
std::string mapPath = g_settings.gamedir + "/svencoop_addon/maps/" + map->bsp_name + ".bsp";
std::string entPath = g_settings.gamedir + "/svencoop_addon/scripts/maps/bspguy/maps/" + map->bsp_name + ".ent";
Expand All @@ -1143,13 +1139,12 @@ void Gui::drawMenuBar()
logf("Check that the directories in the path exist, and that you have permission to write in them.\n");
}
}
}

if (ImGui::IsItemHovered() && g.HoveredIdTimer > g_tooltip_delay)
{
ImGui::BeginTooltip();
ImGui::TextUnformatted("Saves the .bsp and .ent file to your svencoop_addon folder.\n\nAI nodes will be stripped to skip node graph generation.\n");
ImGui::EndTooltip();
if (ImGui::IsItemHovered() && g.HoveredIdTimer > g_tooltip_delay)
{
ImGui::BeginTooltip();
ImGui::TextUnformatted("Saves the .bsp and .ent file to your svencoop_addon folder.\n\nAI nodes will be stripped to skip node graph generation.\n");
ImGui::EndTooltip();
}
}

if (ImGui::MenuItem("Reload", 0, false, !app->isLoading))
Expand Down Expand Up @@ -3204,6 +3199,7 @@ void Gui::drawSettings()
}
ImGui::DragInt("Undo Levels", &app->undoLevels, 0.05f, 0, 64);
ImGui::Checkbox("Verbose Logging", &g_verbose);
ImGui::SameLine();
ImGui::Checkbox("Make map backup", &g_settings.backUpMap);
if (ImGui::IsItemHovered() && g.HoveredIdTimer > g_tooltip_delay)
{
Expand All @@ -3219,6 +3215,17 @@ void Gui::drawSettings()
ImGui::TextUnformatted("Hack original map CRC after anything edited.");
ImGui::EndTooltip();
}

if (ImGui::Button("RESET ALL SETTINGS"))
{
g_settings.reset();
}
if (ImGui::IsItemHovered() && g.HoveredIdTimer > g_tooltip_delay)
{
ImGui::BeginTooltip();
ImGui::TextUnformatted("Warning! You want to return all settings to default values?!");
ImGui::EndTooltip();
}
}
else if (settingsTab == 1)
{
Expand Down
187 changes: 58 additions & 129 deletions src/editor/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,58 @@ void AppSettings::loadDefault()
monsterOnlyTriggers.clear();
}

void AppSettings::reset()
{
loadDefault();

fgdPaths.clear();
fgdPaths.push_back("/moddir/GameDefinitionFile.fgd");

resPaths.clear();
resPaths.push_back("/moddir/");
resPaths.push_back("/moddir_addon/");

conditionalPointEntTriggers.clear();
conditionalPointEntTriggers.push_back("trigger_once");
conditionalPointEntTriggers.push_back("trigger_multiple");
conditionalPointEntTriggers.push_back("trigger_counter");
conditionalPointEntTriggers.push_back("trigger_gravity");
conditionalPointEntTriggers.push_back("trigger_teleport");

entsThatNeverNeedAnyHulls.clear();
entsThatNeverNeedAnyHulls.push_back("env_bubbles");
entsThatNeverNeedAnyHulls.push_back("func_tankcontrols");
entsThatNeverNeedAnyHulls.push_back("func_traincontrols");
entsThatNeverNeedAnyHulls.push_back("func_vehiclecontrols");
entsThatNeverNeedAnyHulls.push_back("trigger_autosave"); // obsolete in sven
entsThatNeverNeedAnyHulls.push_back("trigger_endsection"); // obsolete in sven

entsThatNeverNeedCollision.clear();
entsThatNeverNeedCollision.push_back("func_illusionary");
entsThatNeverNeedCollision.push_back("func_mortar_field");

passableEnts.clear();
passableEnts.push_back("func_door");
passableEnts.push_back("func_door_rotating");
passableEnts.push_back("func_pendulum");
passableEnts.push_back("func_tracktrain");
passableEnts.push_back("func_train");
passableEnts.push_back("func_water");
passableEnts.push_back("momentary_door");

playerOnlyTriggers.clear();
playerOnlyTriggers.push_back("func_ladder");
playerOnlyTriggers.push_back("game_zone_player");
playerOnlyTriggers.push_back("player_respawn_zone");
playerOnlyTriggers.push_back("trigger_cdaudio");
playerOnlyTriggers.push_back("trigger_changelevel");
playerOnlyTriggers.push_back("trigger_transition");

monsterOnlyTriggers.clear();
monsterOnlyTriggers.push_back("func_monsterclip");
monsterOnlyTriggers.push_back("trigger_monsterjump");
}

void AppSettings::load()
{
std::ifstream file(g_settings_path);
Expand Down Expand Up @@ -312,134 +364,21 @@ void AppSettings::load()
}
#endif


// Restore default window height if invalid.
if (windowHeight <= 0 || windowWidth <= 0)
{
windowHeight = 600;
windowWidth = 800;
}


if (conditionalPointEntTriggers.empty())
{
conditionalPointEntTriggers.push_back("trigger_once");
conditionalPointEntTriggers.push_back("trigger_multiple");
conditionalPointEntTriggers.push_back("trigger_counter");
conditionalPointEntTriggers.push_back("trigger_gravity");
conditionalPointEntTriggers.push_back("trigger_teleport");
}

if (entsThatNeverNeedAnyHulls.empty())
{
entsThatNeverNeedAnyHulls.push_back("env_bubbles");
entsThatNeverNeedAnyHulls.push_back("func_tankcontrols");
entsThatNeverNeedAnyHulls.push_back("func_traincontrols");
entsThatNeverNeedAnyHulls.push_back("func_vehiclecontrols");
entsThatNeverNeedAnyHulls.push_back("trigger_autosave"); // obsolete in sven
entsThatNeverNeedAnyHulls.push_back("trigger_endsection"); // obsolete in sven
}

if (entsThatNeverNeedCollision.empty())
{
entsThatNeverNeedCollision.push_back("func_illusionary");
entsThatNeverNeedCollision.push_back("func_mortar_field");
}

if (passableEnts.empty())
{
passableEnts.push_back("func_door");
passableEnts.push_back("func_door_rotating");
passableEnts.push_back("func_pendulum");
passableEnts.push_back("func_tracktrain");
passableEnts.push_back("func_train");
passableEnts.push_back("func_water");
passableEnts.push_back("momentary_door");
}

if (playerOnlyTriggers.empty())
{
playerOnlyTriggers.push_back("func_ladder");
playerOnlyTriggers.push_back("game_zone_player");
playerOnlyTriggers.push_back("player_respawn_zone");
playerOnlyTriggers.push_back("trigger_cdaudio");
playerOnlyTriggers.push_back("trigger_changelevel");
playerOnlyTriggers.push_back("trigger_transition");
}

if (monsterOnlyTriggers.empty())
{
monsterOnlyTriggers.push_back("func_monsterclip");
monsterOnlyTriggers.push_back("trigger_monsterjump");
}

if (fgdPaths.empty())
{
fgdPaths.push_back("/svencoop/sven-coop.fgd");
}

if (resPaths.empty())
{
resPaths.push_back("/svencoop/");
resPaths.push_back("/svencoop_addon/");
resPaths.push_back("/svencoop_downloads/");
resPaths.push_back("/svencoop_hd/");
}
if (lines_readed > 0)
g_settings.settingLoaded = true;
else
logf("Failed to load user config: %s\n", g_settings_path.c_str());
}
else
{
g_settings.windowY = 0;
g_settings.windowX = 0;
#ifdef WIN32
g_settings.windowY = 30;
#endif
windowHeight = 600;
windowWidth = 800;

fgdPaths.push_back("/svencoop/sven-coop.fgd");

resPaths.push_back("/svencoop/");
resPaths.push_back("/svencoop_addon/");
resPaths.push_back("/svencoop_downloads/");
resPaths.push_back("/svencoop_hd/");

conditionalPointEntTriggers.push_back("trigger_once");
conditionalPointEntTriggers.push_back("trigger_multiple");
conditionalPointEntTriggers.push_back("trigger_counter");
conditionalPointEntTriggers.push_back("trigger_gravity");
conditionalPointEntTriggers.push_back("trigger_teleport");

entsThatNeverNeedAnyHulls.push_back("env_bubbles");
entsThatNeverNeedAnyHulls.push_back("func_tankcontrols");
entsThatNeverNeedAnyHulls.push_back("func_traincontrols");
entsThatNeverNeedAnyHulls.push_back("func_vehiclecontrols");
entsThatNeverNeedAnyHulls.push_back("trigger_autosave"); // obsolete in sven
entsThatNeverNeedAnyHulls.push_back("trigger_endsection"); // obsolete in sven

entsThatNeverNeedCollision.push_back("func_illusionary");
entsThatNeverNeedCollision.push_back("func_mortar_field");

passableEnts.push_back("func_door");
passableEnts.push_back("func_door_rotating");
passableEnts.push_back("func_pendulum");
passableEnts.push_back("func_tracktrain");
passableEnts.push_back("func_train");
passableEnts.push_back("func_water");
passableEnts.push_back("momentary_door");

playerOnlyTriggers.push_back("func_ladder");
playerOnlyTriggers.push_back("game_zone_player");
playerOnlyTriggers.push_back("player_respawn_zone");
playerOnlyTriggers.push_back("trigger_cdaudio");
playerOnlyTriggers.push_back("trigger_changelevel");
playerOnlyTriggers.push_back("trigger_transition");

monsterOnlyTriggers.push_back("func_monsterclip");
monsterOnlyTriggers.push_back("trigger_monsterjump");


reset();
logf("Failed to open user config: %s\n", g_settings_path.c_str());
}
}
Expand Down Expand Up @@ -530,20 +469,12 @@ void AppSettings::save(std::string path)

void AppSettings::save()
{

if (!dirExists(g_config_dir))
{
createDir(g_config_dir);
}

if (g_app->saveSettings())
{
save(g_settings_path);
}
else
{
logf("Settings can not be saved because not loaded\n");
}
g_app->saveSettings();
save(g_settings_path);
}

int g_scroll = 0;
Expand Down Expand Up @@ -995,7 +926,7 @@ void Renderer::reloadMaps()
logf("Reloaded maps\n");
}

bool Renderer::saveSettings()
void Renderer::saveSettings()
{
g_settings.debug_open = gui->showDebugWidget;
g_settings.keyvalue_open = gui->showKeyvalueWidget;
Expand All @@ -1015,7 +946,6 @@ bool Renderer::saveSettings()
g_settings.undoLevels = undoLevels;
g_settings.moveSpeed = moveSpeed;
g_settings.rotSpeed = rotationSpeed;
return true;
}

void Renderer::loadSettings()
Expand Down Expand Up @@ -1903,7 +1833,6 @@ void Renderer::pickObject()
}
}


if (movingEnt && oldEntIdx != pickInfo.entIdx)
{
ungrabEnt();
Expand Down
3 changes: 2 additions & 1 deletion src/editor/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ struct AppSettings

void loadDefault();
void load();
void reset();
void save();
void save(std::string path);
};
Expand Down Expand Up @@ -151,7 +152,7 @@ class Renderer
void postLoadFgds();
void reloadMaps();
void clearMaps();
bool saveSettings();
void saveSettings();
void loadSettings();


Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ int main(int argc, char* argv[])
g_settings_path = fileExists(GetCurrentWorkingDir() + "bspguy.cfg") ? GetCurrentWorkingDir() + "bspguy.cfg" : getConfigDir() + "bspguy.cfg";
g_config_dir = fileExists(GetCurrentWorkingDir() + "bspguy.cfg") ? GetCurrentWorkingDir() : getConfigDir();

// test svencoop merge
//return test();

CommandLine cli(argc, argv);
Expand Down

0 comments on commit f2ec7ff

Please sign in to comment.