change button IDs and function locations

This commit is contained in:
Sam39 2022-08-16 10:48:15 +03:00
parent 81208afb2a
commit 11e4c11132

View File

@ -72,6 +72,7 @@ class MyAccountFrame : public wxFrame {
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);
void OnClickLogin(wxCommandEvent& event);
wxDECLARE_EVENT_TABLE(); wxDECLARE_EVENT_TABLE();
}; };
@ -98,6 +99,32 @@ class MySettingsFrame : public wxFrame {
wxDECLARE_EVENT_TABLE(); wxDECLARE_EVENT_TABLE();
}; };
/////////// Event Tables ///////////
//MainFrame (ID range 1 to 99):
wxBEGIN_EVENT_TABLE(MyMainFrame, wxFrame)
EVT_BUTTON(1, MyMainFrame::OnClickAccount)
EVT_BUTTON(2, MyMainFrame::OnClickSettings)
EVT_BUTTON(3, MyMainFrame::OnClickLaunch)
EVT_BUTTON(4, MyMainFrame::OnClickLogo)
wxEND_EVENT_TABLE()
//AccountFrame (ID range 100 to 199):
wxBEGIN_EVENT_TABLE(MyAccountFrame, wxFrame)
EVT_BUTTON(100, MyAccountFrame::OnClickLogout)
EVT_BUTTON(101, MyAccountFrame::OnClickRegister)
EVT_BUTTON(102, MyAccountFrame::OnClickLogin)
wxEND_EVENT_TABLE()
//SettingsFrame (ID range 200 to 299):
wxBEGIN_EVENT_TABLE(MySettingsFrame, wxFrame)
EVT_DIRPICKER_CHANGED(200, MySettingsFrame::OnChangedGameDir)
EVT_BUTTON(201, MySettingsFrame::OnAutoDetectGame)
EVT_BUTTON(202, MySettingsFrame::OnAutoDetectProfile)
EVT_BUTTON(203, MySettingsFrame::OnResetCache)
EVT_CHOICE(204, MySettingsFrame::OnChangedBuild)
EVT_CHECKBOX(205, MySettingsFrame::OnClickConsole)
wxEND_EVENT_TABLE()
/////////// Get Stats Function /////////// /////////// 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");
@ -107,12 +134,12 @@ void MyMainFrame::GetStats () {
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) if (jf["Players"].get<int>() < 559)
txtPlayers->SetForegroundColour("green"); txtPlayers->SetForegroundColour("green");
else else
txtPlayers->SetForegroundColour(wxColour(255,173,0)); txtPlayers->SetForegroundColour(wxColour(255,173,0));
if (jf["PublicServers"].get<int>() < 749) if (jf["PublicServers"].get<int>() > 679)
txtServers->SetForegroundColour("green"); txtServers->SetForegroundColour("green");
else else
txtServers->SetForegroundColour(wxColour(255,173,0)); txtServers->SetForegroundColour(wxColour(255,173,0));
@ -132,6 +159,13 @@ void MySettingsFrame::UpdateInfo() {
ctrlCacheDirectory->SetPath(UIData::CachePath); ctrlCacheDirectory->SetPath(UIData::CachePath);
} }
/////////// Update Game Directory Function ///////////
void MySettingsFrame::UpdateGameDirectory(const std::string& path) {
ctrlGameDirectory->SetPath(path);
UIData::GamePath = path;
MyMainFrame::GameVersionLabel();
}
/////////// Load Config Function /////////// /////////// Load Config Function ///////////
void LoadConfig() { void LoadConfig() {
if (fs::exists("Launcher.toml")) { if (fs::exists("Launcher.toml")) {
@ -169,31 +203,6 @@ void LoadConfig() {
} }
} }
/////////// Event Tables ///////////
//MainFrame:
wxBEGIN_EVENT_TABLE(MyMainFrame, wxFrame)
EVT_BUTTON(39, MyMainFrame::OnClickAccount)
EVT_BUTTON(40, MyMainFrame::OnClickSettings)
EVT_BUTTON(41, MyMainFrame::OnClickLaunch)
EVT_BUTTON(42, MyMainFrame::OnClickLogo)
wxEND_EVENT_TABLE()
//AccountFrame:
wxBEGIN_EVENT_TABLE(MyAccountFrame, wxFrame)
EVT_BUTTON(43, MyAccountFrame::OnClickRegister)
EVT_BUTTON(44, MyAccountFrame::OnClickLogout)
wxEND_EVENT_TABLE()
//SettingsFrame:
wxBEGIN_EVENT_TABLE(MySettingsFrame, wxFrame)
EVT_CHECKBOX(45, MySettingsFrame::OnClickConsole)
EVT_DIRPICKER_CHANGED(46, MySettingsFrame::OnChangedGameDir)
EVT_CHOICE(47, MySettingsFrame::OnChangedBuild)
EVT_BUTTON(10, MySettingsFrame::OnAutoDetectGame)
EVT_BUTTON(11, MySettingsFrame::OnAutoDetectProfile)
EVT_BUTTON(12, MySettingsFrame::OnResetCache)
wxEND_EVENT_TABLE()
/////////// OnInit Function /////////// /////////// OnInit Function ///////////
bool MyApp::OnInit() { bool MyApp::OnInit() {
LoadConfig(); LoadConfig();
@ -269,16 +278,6 @@ void WindowsConsole (bool isChecked) {
std::wcin.clear(); std::wcin.clear();
} }
/////////// TestFrame Function ///////////
/*MyTestFrame::MyTestFrame() :
wxFrame(nullptr, wxID_ANY, "BeamMP Launcher V3", wxDefaultPosition,wxDefaultSize,
wxMINIMIZE_BOX | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX) {
auto* file = new wxFileDialog (this, wxT("Test"), wxT(""),wxT(""));
file->SetPosition(wxPoint(250,250));
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");
@ -291,7 +290,17 @@ std::string jsonRead () {
return ""; return "";
} }
/////////// MainFrame Function /////////// /////////// TestFrame Function ///////////
/*MyTestFrame::MyTestFrame() :
wxFrame(nullptr, wxID_ANY, "BeamMP Launcher V3", wxDefaultPosition,wxDefaultSize,
wxMINIMIZE_BOX | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX) {
auto* file = new wxFileDialog (this, wxT("Test"), wxT(""),wxT(""));
file->SetPosition(wxPoint(250,250));
file->SetForegroundColour("white");
}*/
/////////// Main Frame Content ///////////
MyMainFrame::MyMainFrame() : MyMainFrame::MyMainFrame() :
wxFrame(nullptr, wxID_ANY, "BeamMP Launcher V3", wxDefaultPosition,wxDefaultSize, wxFrame(nullptr, wxID_ANY, "BeamMP Launcher V3", wxDefaultPosition,wxDefaultSize,
wxMINIMIZE_BOX | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX) { wxMINIMIZE_BOX | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX) {
@ -355,7 +364,7 @@ MyMainFrame::MyMainFrame() :
auto* HorizontalLine3 = new wxStaticLine(panel, wxID_ANY, wxPoint(10, 550), wxSize(950, 1)); auto* HorizontalLine3 = new wxStaticLine(panel, wxID_ANY, wxPoint(10, 550), wxSize(950, 1));
//Account: //Account:
auto* bitmap = new wxBitmapButton(panel, 39, wxBitmapBundle(wxImage("icons/default.png", wxBITMAP_TYPE_PNG).Scale(45,45, wxIMAGE_QUALITY_HIGH)), wxPoint(20, 560), wxSize(45,45)); auto* bitmap = new wxBitmapButton(panel, 1, wxBitmapBundle(wxImage("icons/default.png", wxBITMAP_TYPE_PNG).Scale(45,45, wxIMAGE_QUALITY_HIGH)), wxPoint(20, 560), wxSize(45,45));
if (isSignedIn()) if (isSignedIn())
bitmap->SetBitmap(wxBitmapBundle(wxImage("icons/default.png", wxBITMAP_TYPE_PNG).Scale(45,45, wxIMAGE_QUALITY_HIGH))); bitmap->SetBitmap(wxBitmapBundle(wxImage("icons/default.png", wxBITMAP_TYPE_PNG).Scale(45,45, wxIMAGE_QUALITY_HIGH)));
@ -363,8 +372,8 @@ MyMainFrame::MyMainFrame() :
bitmap->SetBitmap(wxBitmapBundle(wxImage("icons/default.png", wxBITMAP_TYPE_PNG).Scale(45,45, wxIMAGE_QUALITY_HIGH))); bitmap->SetBitmap(wxBitmapBundle(wxImage("icons/default.png", wxBITMAP_TYPE_PNG).Scale(45,45, wxIMAGE_QUALITY_HIGH)));
//Buttons: //Buttons:
auto btnSettings = new wxButton(panel, 40, wxT("Settings"), wxPoint(730,570), wxSize(110, 25)); auto btnSettings = new wxButton(panel, 2, wxT("Settings"), wxPoint(730,570), wxSize(110, 25));
btnLaunch = new wxButton(panel, 41, wxT("Launch"), wxPoint(850,570), wxSize(110, 25)); btnLaunch = new wxButton(panel, 3, wxT("Launch"), wxPoint(850,570), wxSize(110, 25));
GetStats(); GetStats();
@ -394,12 +403,12 @@ MyMainFrame::MyMainFrame() :
HorizontalLine3->SetForegroundColour("white"); HorizontalLine3->SetForegroundColour("white");
//Logo: //Logo:
auto* logo = new wxBitmapButton(panel, 42, wxBitmapBundle(wxImage("icons/BeamMP_white.png", wxBITMAP_TYPE_PNG).Scale(100,100, wxIMAGE_QUALITY_HIGH)), wxPoint(850, -15), wxSize(100,100), wxBORDER_NONE); auto* logo = new wxBitmapButton(panel, 4, wxBitmapBundle(wxImage("icons/BeamMP_white.png", wxBITMAP_TYPE_PNG).Scale(100,100, wxIMAGE_QUALITY_HIGH)), wxPoint(850, -15), wxSize(100,100), wxBORDER_NONE);
logo->SetBackgroundColour(wxColour(40, 40, 40)); logo->SetBackgroundColour(wxColour(40, 40, 40));
} }
else { else {
//Logo: //Logo:
auto* logo = new wxBitmapButton(panel, 42, wxBitmapBundle(wxImage("icons/BeamMP_black.png", wxBITMAP_TYPE_PNG).Scale(100,100, wxIMAGE_QUALITY_HIGH)), wxPoint(850, -15), wxSize(100,100), wxBORDER_NONE); auto* logo = new wxBitmapButton(panel, 4, wxBitmapBundle(wxImage("icons/BeamMP_black.png", wxBITMAP_TYPE_PNG).Scale(100,100, wxIMAGE_QUALITY_HIGH)), wxPoint(850, -15), wxSize(100,100), wxBORDER_NONE);
logo->SetBackgroundColour("white"); logo->SetBackgroundColour("white");
} }
txtStatusResult->SetForegroundColour("green"); txtStatusResult->SetForegroundColour("green");
@ -413,13 +422,14 @@ MyAccountFrame::MyAccountFrame() : wxFrame(nullptr, wxID_ANY, "Account Manager",
wxImage::AddHandler(handler); wxImage::AddHandler(handler);
wxStaticBitmap *image; wxStaticBitmap *image;
image = new wxStaticBitmap( this, wxID_ANY, wxBitmapBundle(wxImage("icons/BeamMP_black.png", wxBITMAP_TYPE_PNG).Scale(120,120, wxIMAGE_QUALITY_HIGH)), wxPoint(180,20), wxSize(120, 120)); image = new wxStaticBitmap( this, wxID_ANY, wxBitmapBundle(wxImage("icons/BeamMP_black.png", wxBITMAP_TYPE_PNG).Scale(120,120, wxIMAGE_QUALITY_HIGH)), wxPoint(180,20), wxSize(120, 120));
auto* panel = new wxPanel(this, wxID_ANY, wxPoint(), wxSize(500,650));
if (isSignedIn()) { if (isSignedIn()) {
image->SetBitmap(wxBitmapBundle(wxImage("icons/default.png", wxBITMAP_TYPE_PNG).Scale(120,120, wxIMAGE_QUALITY_HIGH))); image->SetBitmap(wxBitmapBundle(wxImage("icons/default.png", wxBITMAP_TYPE_PNG).Scale(120,120, wxIMAGE_QUALITY_HIGH)));
auto* txtName = new wxStaticText(this, wxID_ANY, wxT("Username: BeamMP"), wxPoint(180, 200)); auto* txtName = new wxStaticText(panel, wxID_ANY, wxT("Username: BeamMP"), wxPoint(180, 200));
auto* txtEmail = new wxStaticText(this, wxID_ANY, wxT("Email: beamMP@gmail.com"), wxPoint(180, 250)); auto* txtEmail = new wxStaticText(panel, wxID_ANY, wxT("Email: beamMP@gmail.com"), wxPoint(180, 250));
auto btnLogout = new wxButton(this, 44, wxT("Logout"), wxPoint(185,550), wxSize(110, 25)); auto btnLogout = new wxButton(panel, 100, wxT("Logout"), wxPoint(185,550), wxSize(110, 25));
//UI Colors: //UI Colors:
if (DarkMode) { if (DarkMode) {
@ -429,7 +439,6 @@ MyAccountFrame::MyAccountFrame() : wxFrame(nullptr, wxID_ANY, "Account Manager",
} }
} }
else { else {
auto* panel = new wxPanel(this, wxID_ANY, wxPoint(), wxSize(500,650));
image->SetBitmap(wxBitmapBundle(wxImage("icons/default.png", wxBITMAP_TYPE_PNG).Scale(120,120, wxIMAGE_QUALITY_HIGH))); image->SetBitmap(wxBitmapBundle(wxImage("icons/default.png", wxBITMAP_TYPE_PNG).Scale(120,120, wxIMAGE_QUALITY_HIGH)));
auto* txtLogin = new wxStaticText(panel, wxID_ANY, wxT("Login with your BeamMP account."), wxPoint(150, 200)); auto* txtLogin = new wxStaticText(panel, wxID_ANY, wxT("Login with your BeamMP account."), wxPoint(150, 200));
@ -439,8 +448,8 @@ MyAccountFrame::MyAccountFrame() : wxFrame(nullptr, wxID_ANY, "Account Manager",
ctrlUsername->SetHint("Username / Email"); ctrlUsername->SetHint("Username / Email");
ctrlPassword->SetHint("Password"); ctrlPassword->SetHint("Password");
auto btnLogin = new wxButton(panel, wxID_ANY, wxT("Login"), wxPoint(120,375), wxSize(110, 25)); auto btnRegister = new wxButton(panel, 101, wxT("Register"), wxPoint(250,375), wxSize(110, 25));
auto btnRegister = new wxButton(panel, 43, wxT("Register"), wxPoint(250,375), wxSize(110, 25)); auto btnLogin = new wxButton(panel, 102, wxT("Login"), wxPoint(120,375), wxSize(110, 25));
//UI Colors: //UI Colors:
if (DarkMode) { if (DarkMode) {
@ -457,20 +466,20 @@ MySettingsFrame::MySettingsFrame() :
auto* panel = new wxPanel(this, wxID_ANY, wxPoint(), wxSize(500,650)); auto* panel = new wxPanel(this, wxID_ANY, wxPoint(), wxSize(500,650));
auto* txtGameDirectory = new wxStaticText(panel, wxID_ANY, wxT("Game Directory: "), wxPoint(30, 100)); auto* txtGameDirectory = new wxStaticText(panel, wxID_ANY, wxT("Game Directory: "), wxPoint(30, 100));
ctrlGameDirectory = new wxDirPickerCtrl (panel, 46, wxEmptyString, wxT("Game Directory"), wxPoint(130, 100), wxSize(300,-1)); ctrlGameDirectory = new wxDirPickerCtrl (panel, 200, wxEmptyString, wxT("Game Directory"), wxPoint(130, 100), wxSize(300,-1));
ctrlGameDirectory->SetLabel("GamePath"); ctrlGameDirectory->SetLabel("GamePath");
MySettingsFrame::SetFocus(); MySettingsFrame::SetFocus();
auto btnDetectGameDirectory = new wxButton(panel, 10, wxT("Detect"), wxPoint(185,140), wxSize(90, 25)); auto btnDetectGameDirectory = new wxButton(panel, 201, wxT("Detect"), wxPoint(185,140), wxSize(90, 25));
auto* txtProfileDirectory = new wxStaticText(panel, wxID_ANY, wxT("Profile Directory: "), wxPoint(30, 200)); auto* txtProfileDirectory = new wxStaticText(panel, wxID_ANY, wxT("Profile Directory: "), wxPoint(30, 200));
ctrlProfileDirectory = new wxDirPickerCtrl (panel, 46, wxEmptyString, wxT("Profile Directory"), wxPoint(130, 200), wxSize(300,-1)); ctrlProfileDirectory = new wxDirPickerCtrl (panel, 200, wxEmptyString, wxT("Profile Directory"), wxPoint(130, 200), wxSize(300,-1));
ctrlProfileDirectory->SetLabel("ProfilePath"); ctrlProfileDirectory->SetLabel("ProfilePath");
auto btnDetectProfileDirectory = new wxButton(panel, 11, wxT("Detect"), wxPoint(185,240), wxSize(90, 25)); auto btnDetectProfileDirectory = new wxButton(panel, 202, wxT("Detect"), wxPoint(185,240), wxSize(90, 25));
auto* txtCacheDirectory = new wxStaticText(panel, wxID_ANY, wxT("Cache Directory: "), wxPoint(30, 300)); auto* txtCacheDirectory = new wxStaticText(panel, wxID_ANY, wxT("Cache Directory: "), wxPoint(30, 300));
ctrlCacheDirectory = new wxDirPickerCtrl (panel, 46, wxEmptyString, wxT("Cache Directory"), wxPoint(130, 300), wxSize(300,-1)); ctrlCacheDirectory = new wxDirPickerCtrl (panel, 200, wxEmptyString, wxT("Cache Directory"), wxPoint(130, 300), wxSize(300,-1));
ctrlCacheDirectory->SetLabel("CachePath"); ctrlCacheDirectory->SetLabel("CachePath");
auto btnCacheDirectory = new wxButton(panel, 12, wxT("Reset"), wxPoint(185,340), wxSize(90, 25)); auto btnCacheDirectory = new wxButton(panel, 203, wxT("Reset"), wxPoint(185,340), wxSize(90, 25));
auto* txtBuild = new wxStaticText(panel, wxID_ANY, wxT("Build: "), wxPoint(30, 400)); auto* txtBuild = new wxStaticText(panel, wxID_ANY, wxT("Build: "), wxPoint(30, 400));
wxArrayString BuildChoices; wxArrayString BuildChoices;
@ -478,10 +487,10 @@ MySettingsFrame::MySettingsFrame() :
BuildChoices.Add("Release"); BuildChoices.Add("Release");
BuildChoices.Add("EA"); BuildChoices.Add("EA");
BuildChoices.Add("Dev"); BuildChoices.Add("Dev");
choiceController = new wxChoice (panel, 47, wxPoint(85, 400), wxSize(120, 20), BuildChoices); choiceController = new wxChoice (panel, 204, wxPoint(85, 400), wxSize(120, 20), BuildChoices);
choiceController->Select(0); choiceController->Select(0);
checkConsole = new wxCheckBox (panel, 45, " Show Console", wxPoint(30, 450)); checkConsole = new wxCheckBox (panel, 205, " Show Console", wxPoint(30, 450));
//UI Colors: //UI Colors:
if (DarkMode) { if (DarkMode) {
@ -531,13 +540,6 @@ void MyMainFrame::GameVersionLabel() {
} }
} }
/////////// 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();
@ -573,23 +575,6 @@ void MyMainFrame::OnClickSettings(wxCommandEvent& event WXUNUSED(event)) {
} }
SettingsFrame->UpdateInfo(); SettingsFrame->UpdateInfo();
SettingsFrame->Show(true); SettingsFrame->Show(true);
}
/////////// OnClick Logo Event ///////////
void MyMainFrame::OnClickLogo(wxCommandEvent& event WXUNUSED(event)) {
wxLaunchDefaultApplication("https://beammp.com");
}
/////////// OnClick Register Event ///////////
void MyAccountFrame::OnClickRegister(wxCommandEvent& event WXUNUSED(event)) {
wxLaunchDefaultApplication("https://forum.beammp.com/signup");
}
/////////// OnClick Logout Event ///////////
void MyAccountFrame::OnClickLogout(wxCommandEvent& event WXUNUSED(event)) {
} }
/////////// OnClick Launch Event /////////// /////////// OnClick Launch Event ///////////
@ -611,6 +596,30 @@ void MyMainFrame::OnClickLaunch(wxCommandEvent& event WXUNUSED(event)) {
wxMessageBox("Please launch BeamNG.drive manually in case of Steam issues.", "Alert"); wxMessageBox("Please launch BeamNG.drive manually in case of Steam issues.", "Alert");
FirstTime = false; FirstTime = false;
} }
}
/////////// OnClick Logo Event ///////////
void MyMainFrame::OnClickLogo(wxCommandEvent& event WXUNUSED(event)) {
wxLaunchDefaultApplication("https://beammp.com");
}
/////////// OnClick Register Event ///////////
void MyAccountFrame::OnClickRegister(wxCommandEvent& event WXUNUSED(event)) {
wxLaunchDefaultApplication("https://forum.beammp.com/signup");
}
/////////// OnClick Login Event ///////////
void MyAccountFrame::OnClickLogin(wxCommandEvent& event WXUNUSED(event)) {
}
/////////// OnClick Logout Event ///////////
void MyAccountFrame::OnClickLogout(wxCommandEvent& event WXUNUSED(event)) {
} }
/////////// OnClick Console Event /////////// /////////// OnClick Console Event ///////////