Skip to content

Commit b6604ea

Browse files
author
Poggu
committed
add welcome modal
1 parent 3753190 commit b6604ea

File tree

5 files changed

+88
-1
lines changed

5 files changed

+88
-1
lines changed

src/config/config.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include "config.h"
2+
#include <nlohmann/json.hpp>
3+
#include <fstream>
4+
#include <tier0/dbg.h>
5+
6+
using json = nlohmann::json;
7+
8+
void PluginConfig::LoadConfig()
9+
{
10+
std::ifstream file(m_path);
11+
12+
if (!file.is_open())
13+
return;
14+
15+
try
16+
{
17+
json j;
18+
j << file;
19+
file.close();
20+
21+
m_bWelcomeSeen = j["WelcomeSeen"];
22+
}
23+
catch (const std::exception& e)
24+
{
25+
ConMsg("Exception: %s", e.what());
26+
}
27+
}
28+
void PluginConfig::SaveConfig()
29+
{
30+
std::ofstream file(m_path);
31+
32+
if (!file.is_open())
33+
return;
34+
35+
json j = {
36+
{"WelcomeSeen", m_bWelcomeSeen}
37+
};
38+
39+
file << j.dump(2);
40+
file.close();
41+
}

src/config/config.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <filesystem>
2+
3+
class PluginConfig
4+
{
5+
public:
6+
void LoadConfig();
7+
void SaveConfig();
8+
void SetPath(std::filesystem::path&& path) { m_path = path; }
9+
public:
10+
bool m_bWelcomeSeen = false;
11+
private:
12+
std::filesystem::path m_path;
13+
};

src/extension.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ PLUGIN_EXPOSE(CS2ServerGUI, g_CS2ServerGUI);
190190
bool CS2ServerGUI::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
191191
{
192192
PLUGIN_SAVEVARS();
193+
m_config.SetPath((std::filesystem::path(Plat_GetGameDirectory()) / "csgo/addons/CS2ServerGUI/config.json"));
194+
m_config.LoadConfig();
193195

194196
GET_V_IFACE_CURRENT(GetEngineFactory, Interfaces::engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
195197
GET_V_IFACE_CURRENT(GetEngineFactory, Interfaces::icvar, ICvar, CVAR_INTERFACE_VERSION);

src/extension.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <igameevents.h>
2525
#include <sh_vector.h>
2626
#include "networksystem/inetworkserializer.h"
27+
#include "config/config.h"
2728

2829
class CS2ServerGUI : public ISmmPlugin, public IMetamodListener
2930
{
@@ -52,6 +53,8 @@ class CS2ServerGUI : public ISmmPlugin, public IMetamodListener
5253
const char *GetVersion();
5354
const char *GetDate();
5455
const char *GetLogTag();
56+
public:
57+
PluginConfig m_config;
5558
};
5659

5760
extern CS2ServerGUI g_CS2ServerGUI;

src/imgui/gui.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <imgui.h>
1+
#include <imgui.h>
22
#include "main.h"
33
#include "panels/entitybrowser/entitybrowser.h"
44
#include "panels/menubar/menubar.h"
@@ -9,11 +9,13 @@
99
#include "panels/dumper/commandlist/commandlist.h"
1010
#include "panels/eventlogger/eventlogger.h"
1111
#include <ImGuiFileDialog.h>
12+
#include "extension.h"
1213

1314
namespace GUI
1415
{
1516

1617
void DrawFileDialogs();
18+
void DrawWelcomeModal();
1719

1820
void DrawMainWindow()
1921
{
@@ -38,6 +40,7 @@ void DrawMainWindow()
3840
MenuBar::Draw();
3941

4042
DrawFileDialogs();
43+
DrawWelcomeModal();
4144
}
4245

4346
void DrawFileDialogs()
@@ -67,4 +70,29 @@ void DrawFileDialogs()
6770
}
6871
}
6972

73+
void DrawWelcomeModal()
74+
{
75+
if (!g_CS2ServerGUI.m_config.m_bWelcomeSeen)
76+
{
77+
g_CS2ServerGUI.m_config.m_bWelcomeSeen = true;
78+
g_CS2ServerGUI.m_config.SaveConfig();
79+
80+
ImGui::OpenPopup("Welcome");
81+
}
82+
83+
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
84+
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
85+
86+
if (ImGui::BeginPopupModal("Welcome", NULL, ImGuiWindowFlags_AlwaysAutoResize))
87+
{
88+
ImGui::Text("CS2ServerGUI is a debugging tool designed for development purposes.");
89+
ImGui::Text("It is not intended for use in production environments.");
90+
ImGui::Separator();
91+
ImGui::Spacing();
92+
93+
if (ImGui::Button("I understand")) { ImGui::CloseCurrentPopup(); }
94+
ImGui::EndPopup();
95+
}
96+
}
97+
7098
} // namespace GUI

0 commit comments

Comments
 (0)