Skip to content

Commit

Permalink
add welcome modal
Browse files Browse the repository at this point in the history
  • Loading branch information
Poggu committed Mar 20, 2024
1 parent 3753190 commit b6604ea
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 1 deletion.
41 changes: 41 additions & 0 deletions src/config/config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "config.h"
#include <nlohmann/json.hpp>
#include <fstream>
#include <tier0/dbg.h>

using json = nlohmann::json;

void PluginConfig::LoadConfig()
{
std::ifstream file(m_path);

if (!file.is_open())
return;

try
{
json j;
j << file;
file.close();

m_bWelcomeSeen = j["WelcomeSeen"];
}
catch (const std::exception& e)
{
ConMsg("Exception: %s", e.what());
}
}
void PluginConfig::SaveConfig()
{
std::ofstream file(m_path);

if (!file.is_open())
return;

json j = {
{"WelcomeSeen", m_bWelcomeSeen}
};

file << j.dump(2);
file.close();
}
13 changes: 13 additions & 0 deletions src/config/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <filesystem>

class PluginConfig
{
public:
void LoadConfig();
void SaveConfig();
void SetPath(std::filesystem::path&& path) { m_path = path; }
public:
bool m_bWelcomeSeen = false;
private:
std::filesystem::path m_path;
};
2 changes: 2 additions & 0 deletions src/extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ PLUGIN_EXPOSE(CS2ServerGUI, g_CS2ServerGUI);
bool CS2ServerGUI::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
{
PLUGIN_SAVEVARS();
m_config.SetPath((std::filesystem::path(Plat_GetGameDirectory()) / "csgo/addons/CS2ServerGUI/config.json"));
m_config.LoadConfig();

GET_V_IFACE_CURRENT(GetEngineFactory, Interfaces::engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
GET_V_IFACE_CURRENT(GetEngineFactory, Interfaces::icvar, ICvar, CVAR_INTERFACE_VERSION);
Expand Down
3 changes: 3 additions & 0 deletions src/extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <igameevents.h>
#include <sh_vector.h>
#include "networksystem/inetworkserializer.h"
#include "config/config.h"

class CS2ServerGUI : public ISmmPlugin, public IMetamodListener
{
Expand Down Expand Up @@ -52,6 +53,8 @@ class CS2ServerGUI : public ISmmPlugin, public IMetamodListener
const char *GetVersion();
const char *GetDate();
const char *GetLogTag();
public:
PluginConfig m_config;
};

extern CS2ServerGUI g_CS2ServerGUI;
Expand Down
30 changes: 29 additions & 1 deletion src/imgui/gui.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <imgui.h>
#include <imgui.h>
#include "main.h"
#include "panels/entitybrowser/entitybrowser.h"
#include "panels/menubar/menubar.h"
Expand All @@ -9,11 +9,13 @@
#include "panels/dumper/commandlist/commandlist.h"
#include "panels/eventlogger/eventlogger.h"
#include <ImGuiFileDialog.h>
#include "extension.h"

namespace GUI
{

void DrawFileDialogs();
void DrawWelcomeModal();

void DrawMainWindow()
{
Expand All @@ -38,6 +40,7 @@ void DrawMainWindow()
MenuBar::Draw();

DrawFileDialogs();
DrawWelcomeModal();
}

void DrawFileDialogs()
Expand Down Expand Up @@ -67,4 +70,29 @@ void DrawFileDialogs()
}
}

void DrawWelcomeModal()
{
if (!g_CS2ServerGUI.m_config.m_bWelcomeSeen)
{
g_CS2ServerGUI.m_config.m_bWelcomeSeen = true;
g_CS2ServerGUI.m_config.SaveConfig();

ImGui::OpenPopup("Welcome");
}

ImVec2 center = ImGui::GetMainViewport()->GetCenter();
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));

if (ImGui::BeginPopupModal("Welcome", NULL, ImGuiWindowFlags_AlwaysAutoResize))
{
ImGui::Text("CS2ServerGUI is a debugging tool designed for development purposes.");
ImGui::Text("It is not intended for use in production environments.");
ImGui::Separator();
ImGui::Spacing();

if (ImGui::Button("I understand")) { ImGui::CloseCurrentPopup(); }
ImGui::EndPopup();
}
}

} // namespace GUI

0 comments on commit b6604ea

Please sign in to comment.