mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-04-23 00:30:03 +00:00
add players and servers colors
fix color bug with game version
This commit is contained in:
102
src/gui/Gui.cpp
102
src/gui/Gui.cpp
@@ -49,12 +49,13 @@ class MyMainFrame : public wxFrame {
|
|||||||
static void GameVersionLabel();
|
static void GameVersionLabel();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Here you put the frame functions:
|
|
||||||
wxStaticText* txtStatusResult;
|
wxStaticText* txtStatusResult;
|
||||||
static inline wxStaticText* txtGameVersion, *txtPlayers, *txtModVersion, *txtServers;
|
static inline wxStaticText* txtGameVersion, *txtPlayers, *txtModVersion, *txtServers;
|
||||||
wxButton* btnLaunch;
|
wxButton* btnLaunch;
|
||||||
|
|
||||||
bool DarkMode = wxSystemSettings::GetAppearance().IsDark();
|
bool DarkMode = wxSystemSettings::GetAppearance().IsDark();
|
||||||
void GetStats();
|
void GetStats();
|
||||||
|
|
||||||
void OnClickAccount(wxCommandEvent& event);
|
void OnClickAccount(wxCommandEvent& event);
|
||||||
void OnClickSettings(wxCommandEvent& event);
|
void OnClickSettings(wxCommandEvent& event);
|
||||||
void OnClickLaunch(wxCommandEvent& event);
|
void OnClickLaunch(wxCommandEvent& event);
|
||||||
@@ -68,8 +69,6 @@ class MyAccountFrame : public wxFrame {
|
|||||||
MyAccountFrame();
|
MyAccountFrame();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Here you put the frame functions:
|
|
||||||
|
|
||||||
bool DarkMode = wxSystemSettings::GetAppearance().IsDark();
|
bool DarkMode = wxSystemSettings::GetAppearance().IsDark();
|
||||||
void OnClickRegister(wxCommandEvent& event);
|
void OnClickRegister(wxCommandEvent& event);
|
||||||
void OnClickLogout(wxCommandEvent& event);
|
void OnClickLogout(wxCommandEvent& event);
|
||||||
@@ -84,11 +83,12 @@ class MySettingsFrame : public wxFrame {
|
|||||||
void UpdateGameDirectory(const std::string& path);
|
void UpdateGameDirectory(const std::string& path);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Here you put the frame functions:
|
|
||||||
wxDirPickerCtrl* ctrlGameDirectory, *ctrlProfileDirectory, *ctrlCacheDirectory;
|
wxDirPickerCtrl* ctrlGameDirectory, *ctrlProfileDirectory, *ctrlCacheDirectory;
|
||||||
wxCheckBox* checkConsole;
|
wxCheckBox* checkConsole;
|
||||||
wxChoice* choiceController;
|
wxChoice* choiceController;
|
||||||
|
|
||||||
bool DarkMode = wxSystemSettings::GetAppearance().IsDark();
|
bool DarkMode = wxSystemSettings::GetAppearance().IsDark();
|
||||||
|
|
||||||
void OnClickConsole(wxCommandEvent& event);
|
void OnClickConsole(wxCommandEvent& event);
|
||||||
void OnChangedGameDir (wxFileDirPickerEvent& event);
|
void OnChangedGameDir (wxFileDirPickerEvent& event);
|
||||||
void OnChangedBuild (wxCommandEvent& event);
|
void OnChangedBuild (wxCommandEvent& event);
|
||||||
@@ -98,17 +98,30 @@ class MySettingsFrame : public wxFrame {
|
|||||||
wxDECLARE_EVENT_TABLE();
|
wxDECLARE_EVENT_TABLE();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/////////// Get Stats Function ///////////
|
||||||
void MyMainFrame::GetStats () {
|
void MyMainFrame::GetStats () {
|
||||||
std::string results = HTTP::Get("https://backend.beammp.com/stats_raw");
|
std::string results = HTTP::Get("https://backend.beammp.com/stats_raw");
|
||||||
|
|
||||||
nlohmann::json jf = nlohmann::json::parse(results);
|
nlohmann::json jf = nlohmann::json::parse(results, nullptr, false);
|
||||||
if (!jf.empty()) {
|
if (!jf.is_discarded() && !jf.empty()) {
|
||||||
txtPlayers->SetLabel(to_string(jf["Players"]));
|
txtPlayers->SetLabel(to_string(jf["Players"]));
|
||||||
txtServers->SetLabel(to_string(jf["PublicServers"]));
|
txtServers->SetLabel(to_string(jf["PublicServers"]));
|
||||||
|
|
||||||
|
if (jf["Players"].get<int>() < 699)
|
||||||
|
txtPlayers->SetForegroundColour("green");
|
||||||
|
else
|
||||||
|
txtPlayers->SetForegroundColour(wxColour(255,173,0));
|
||||||
|
|
||||||
|
if (jf["PublicServers"].get<int>() < 749)
|
||||||
|
txtServers->SetForegroundColour("green");
|
||||||
|
else
|
||||||
|
txtServers->SetForegroundColour(wxColour(255,173,0));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
txtPlayers->SetLabel("NA");
|
txtPlayers->SetLabel("NA");
|
||||||
|
txtPlayers->SetForegroundColour("red");
|
||||||
txtServers->SetLabel("NA");
|
txtServers->SetLabel("NA");
|
||||||
wxMessageBox("Couldn't get game stats", "Error");
|
txtServers->SetForegroundColour("red");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +132,7 @@ void MySettingsFrame::UpdateInfo() {
|
|||||||
ctrlCacheDirectory->SetPath(UIData::CachePath);
|
ctrlCacheDirectory->SetPath(UIData::CachePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////// Load Config function ///////////
|
/////////// Load Config Function ///////////
|
||||||
void LoadConfig() {
|
void LoadConfig() {
|
||||||
if (fs::exists("Launcher.toml")) {
|
if (fs::exists("Launcher.toml")) {
|
||||||
toml::parse_result config = toml::parse_file("Launcher.toml");
|
toml::parse_result config = toml::parse_file("Launcher.toml");
|
||||||
@@ -156,7 +169,8 @@ void LoadConfig() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////// MainFrame Event Table ///////////
|
/////////// Event Tables ///////////
|
||||||
|
//MainFrame:
|
||||||
wxBEGIN_EVENT_TABLE(MyMainFrame, wxFrame)
|
wxBEGIN_EVENT_TABLE(MyMainFrame, wxFrame)
|
||||||
EVT_BUTTON(39, MyMainFrame::OnClickAccount)
|
EVT_BUTTON(39, MyMainFrame::OnClickAccount)
|
||||||
EVT_BUTTON(40, MyMainFrame::OnClickSettings)
|
EVT_BUTTON(40, MyMainFrame::OnClickSettings)
|
||||||
@@ -164,13 +178,13 @@ wxBEGIN_EVENT_TABLE(MyMainFrame, wxFrame)
|
|||||||
EVT_BUTTON(42, MyMainFrame::OnClickLogo)
|
EVT_BUTTON(42, MyMainFrame::OnClickLogo)
|
||||||
wxEND_EVENT_TABLE()
|
wxEND_EVENT_TABLE()
|
||||||
|
|
||||||
/////////// AccountFrame Event Table ///////////
|
//AccountFrame:
|
||||||
wxBEGIN_EVENT_TABLE(MyAccountFrame, wxFrame)
|
wxBEGIN_EVENT_TABLE(MyAccountFrame, wxFrame)
|
||||||
EVT_BUTTON(43, MyAccountFrame::OnClickRegister)
|
EVT_BUTTON(43, MyAccountFrame::OnClickRegister)
|
||||||
EVT_BUTTON(44, MyAccountFrame::OnClickLogout)
|
EVT_BUTTON(44, MyAccountFrame::OnClickLogout)
|
||||||
wxEND_EVENT_TABLE()
|
wxEND_EVENT_TABLE()
|
||||||
|
|
||||||
/////////// SettingsFrame Event Table ///////////
|
//SettingsFrame:
|
||||||
wxBEGIN_EVENT_TABLE(MySettingsFrame, wxFrame)
|
wxBEGIN_EVENT_TABLE(MySettingsFrame, wxFrame)
|
||||||
EVT_CHECKBOX(45, MySettingsFrame::OnClickConsole)
|
EVT_CHECKBOX(45, MySettingsFrame::OnClickConsole)
|
||||||
EVT_DIRPICKER_CHANGED(46, MySettingsFrame::OnChangedGameDir)
|
EVT_DIRPICKER_CHANGED(46, MySettingsFrame::OnChangedGameDir)
|
||||||
@@ -180,7 +194,7 @@ wxBEGIN_EVENT_TABLE(MySettingsFrame, wxFrame)
|
|||||||
EVT_BUTTON(12, MySettingsFrame::OnResetCache)
|
EVT_BUTTON(12, MySettingsFrame::OnResetCache)
|
||||||
wxEND_EVENT_TABLE()
|
wxEND_EVENT_TABLE()
|
||||||
|
|
||||||
/////////// OnInit function to show frame ///////////
|
/////////// OnInit Function ///////////
|
||||||
bool MyApp::OnInit() {
|
bool MyApp::OnInit() {
|
||||||
LoadConfig();
|
LoadConfig();
|
||||||
auto* MainFrame = new MyMainFrame();
|
auto* MainFrame = new MyMainFrame();
|
||||||
@@ -243,7 +257,7 @@ void WindowsConsole (bool isChecked) {
|
|||||||
::fclose(stderr);
|
::fclose(stderr);
|
||||||
::fclose(stdin);
|
::fclose(stdin);
|
||||||
}
|
}
|
||||||
// Clear the error state for all of the C++ standard streams. Attempting to accessing the streams before they refer
|
// Clear the error state for all the C++ standard streams. Attempting to accessing the streams before they refer
|
||||||
// to a valid target causes the stream to enter an error state. Clearing the error state will fix this problem,
|
// to a valid target causes the stream to enter an error state. Clearing the error state will fix this problem,
|
||||||
// which seems to occur in newer version of Visual Studio even when the console has not been read from or written
|
// which seems to occur in newer version of Visual Studio even when the console has not been read from or written
|
||||||
// to yet.
|
// to yet.
|
||||||
@@ -265,15 +279,14 @@ void WindowsConsole (bool isChecked) {
|
|||||||
file->SetForegroundColour("white");
|
file->SetForegroundColour("white");
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
/////////// Read json function ///////////
|
/////////// Read json Function ///////////
|
||||||
std::string jsonRead () {
|
std::string jsonRead () {
|
||||||
fs::path path = fs::path (UIData::GamePath).append("integrity.json");
|
fs::path path = fs::path (UIData::GamePath).append("integrity.json");
|
||||||
if (fs::exists(path)) {
|
if (fs::exists(path)) {
|
||||||
std::ifstream ifs(path);
|
std::ifstream ifs(path);
|
||||||
nlohmann::json jf = nlohmann::json::parse(ifs);
|
nlohmann::json jf = nlohmann::json::parse(ifs, nullptr, false);
|
||||||
if (!jf.empty()) return jf["version"];
|
if (!jf.is_discarded() && !jf.empty()) return jf["version"];
|
||||||
}
|
}
|
||||||
|
|
||||||
else wxMessageBox("Couldn't read game version, check game path in settings", "Error");
|
else wxMessageBox("Couldn't read game version, check game path in settings", "Error");
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@@ -368,13 +381,10 @@ MyMainFrame::MyMainFrame() :
|
|||||||
txtNews->SetForegroundColour("white");
|
txtNews->SetForegroundColour("white");
|
||||||
txtUpdate->SetForegroundColour("white");
|
txtUpdate->SetForegroundColour("white");
|
||||||
txtGameVersionTitle->SetForegroundColour("white");
|
txtGameVersionTitle->SetForegroundColour("white");
|
||||||
txtGameVersion->SetForegroundColour("white");
|
|
||||||
txtPlayersTitle->SetForegroundColour("white");
|
txtPlayersTitle->SetForegroundColour("white");
|
||||||
txtPlayers->SetForegroundColour("white");
|
|
||||||
txtModVersionTitle->SetForegroundColour("white");
|
txtModVersionTitle->SetForegroundColour("white");
|
||||||
txtModVersion->SetForegroundColour("white");
|
txtModVersion->SetForegroundColour("white");
|
||||||
txtServersTitle->SetForegroundColour("white");
|
txtServersTitle->SetForegroundColour("white");
|
||||||
txtServers->SetForegroundColour("white");
|
|
||||||
txtPatreon->SetForegroundColour("white");
|
txtPatreon->SetForegroundColour("white");
|
||||||
txtStatus->SetForegroundColour("white");
|
txtStatus->SetForegroundColour("white");
|
||||||
|
|
||||||
@@ -395,23 +405,6 @@ MyMainFrame::MyMainFrame() :
|
|||||||
txtStatusResult->SetForegroundColour("green");
|
txtStatusResult->SetForegroundColour("green");
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////// Game Version Label function ///////////
|
|
||||||
void MyMainFrame::GameVersionLabel() {
|
|
||||||
std::string read = jsonRead();
|
|
||||||
if (!read.empty()) {
|
|
||||||
txtGameVersion->SetLabel(read);
|
|
||||||
VersionParser CurrentVersion(read);
|
|
||||||
if (CurrentVersion > Launcher::SupportedVersion)
|
|
||||||
txtGameVersion->SetForegroundColour("orange");
|
|
||||||
else if (CurrentVersion < Launcher::SupportedVersion)
|
|
||||||
txtGameVersion->SetForegroundColour("red");
|
|
||||||
else txtGameVersion->SetForegroundColour("green");
|
|
||||||
} else {
|
|
||||||
txtGameVersion->SetLabel(wxT("NA"));
|
|
||||||
txtGameVersion->SetForegroundColour("red");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////// Account Frame Content ///////////
|
/////////// Account Frame Content ///////////
|
||||||
MyAccountFrame::MyAccountFrame() : wxFrame(nullptr, wxID_ANY, "Account Manager", wxDefaultPosition,wxDefaultSize,
|
MyAccountFrame::MyAccountFrame() : wxFrame(nullptr, wxID_ANY, "Account Manager", wxDefaultPosition,wxDefaultSize,
|
||||||
wxMINIMIZE_BOX | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX) {
|
wxMINIMIZE_BOX | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX) {
|
||||||
@@ -506,7 +499,7 @@ MySettingsFrame::MySettingsFrame() :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////// UpdateConfig function ///////////
|
/////////// UpdateConfig Function ///////////
|
||||||
template <typename ValueType>
|
template <typename ValueType>
|
||||||
void UpdateConfig (const std::string& key, ValueType&& value) {
|
void UpdateConfig (const std::string& key, ValueType&& value) {
|
||||||
if (fs::exists("Launcher.toml")) {
|
if (fs::exists("Launcher.toml")) {
|
||||||
@@ -521,6 +514,30 @@ void UpdateConfig (const std::string& key, ValueType&& value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/////////// Game Version Label Function ///////////
|
||||||
|
void MyMainFrame::GameVersionLabel() {
|
||||||
|
std::string read = jsonRead();
|
||||||
|
if (!read.empty()) {
|
||||||
|
txtGameVersion->SetLabel(read);
|
||||||
|
VersionParser CurrentVersion(read);
|
||||||
|
if (CurrentVersion > Launcher::SupportedVersion)
|
||||||
|
txtGameVersion->SetForegroundColour(wxColour(255,173,0));
|
||||||
|
else if (CurrentVersion < Launcher::SupportedVersion)
|
||||||
|
txtGameVersion->SetForegroundColour("red");
|
||||||
|
else txtGameVersion->SetForegroundColour("green");
|
||||||
|
} else {
|
||||||
|
txtGameVersion->SetLabel(wxT("NA"));
|
||||||
|
txtGameVersion->SetForegroundColour("red");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////// Update Game Directory Function ///////////
|
||||||
|
void MySettingsFrame::UpdateGameDirectory(const std::string& path) {
|
||||||
|
ctrlGameDirectory->SetPath(path);
|
||||||
|
UIData::GamePath = path;
|
||||||
|
MyMainFrame::GameVersionLabel();
|
||||||
|
}
|
||||||
|
|
||||||
/////////// OnClick Account Event ///////////
|
/////////// OnClick Account Event ///////////
|
||||||
void MyMainFrame::OnClickAccount(wxCommandEvent& event WXUNUSED(event)) {
|
void MyMainFrame::OnClickAccount(wxCommandEvent& event WXUNUSED(event)) {
|
||||||
auto* AccountFrame = new MyAccountFrame();
|
auto* AccountFrame = new MyAccountFrame();
|
||||||
@@ -603,13 +620,6 @@ void MySettingsFrame::OnClickConsole(wxCommandEvent& event) {
|
|||||||
UpdateConfig("Console", status);
|
UpdateConfig("Console", status);
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////// Update Game Directory Function ///////////
|
|
||||||
void MySettingsFrame::UpdateGameDirectory(const std::string& path) {
|
|
||||||
ctrlGameDirectory->SetPath(path);
|
|
||||||
UIData::GamePath = path;
|
|
||||||
MyMainFrame::GameVersionLabel();
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////// OnChanged Game Path Event ///////////
|
/////////// OnChanged Game Path Event ///////////
|
||||||
void MySettingsFrame::OnChangedGameDir(wxFileDirPickerEvent& event) {
|
void MySettingsFrame::OnChangedGameDir(wxFileDirPickerEvent& event) {
|
||||||
std::string NewPath = event.GetPath().utf8_string();
|
std::string NewPath = event.GetPath().utf8_string();
|
||||||
@@ -624,8 +634,6 @@ void MySettingsFrame::OnChangedBuild(wxCommandEvent& event) {
|
|||||||
UpdateConfig("Build", key);
|
UpdateConfig("Build", key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/////////// AutoDetect Game Function ///////////
|
/////////// AutoDetect Game Function ///////////
|
||||||
void MySettingsFrame::OnAutoDetectGame (wxCommandEvent& event) {
|
void MySettingsFrame::OnAutoDetectGame (wxCommandEvent& event) {
|
||||||
HKEY BeamNG;
|
HKEY BeamNG;
|
||||||
|
|||||||
Reference in New Issue
Block a user