add mod version logic

This commit is contained in:
Sam39 2022-08-19 15:27:58 +03:00
parent 40ea3ff6f8
commit 0132c7fdc6

View File

@ -59,11 +59,11 @@ class MyMainFrame : public wxFrame {
wxStaticText* txtUpdate; wxStaticText* txtUpdate;
wxBitmapButton* BitAccount; wxBitmapButton* BitAccount;
void OnClickAccount(wxCommandEvent& event); void OnClickAccount(wxCommandEvent& event);
wxButton* btnLaunch;
private: private:
wxStaticText* txtStatusResult; wxStaticText* txtStatusResult;
static inline wxStaticText *txtGameVersion, *txtPlayers, *txtModVersion, *txtServers; static inline wxStaticText *txtGameVersion, *txtPlayers, *txtModVersion, *txtServers;
wxButton* btnLaunch;
bool DarkMode = wxSystemSettings::GetAppearance().IsDark(); bool DarkMode = wxSystemSettings::GetAppearance().IsDark();
void GetStats(); void GetStats();
@ -150,11 +150,20 @@ void MyMainFrame::GetStats() {
else else
txtServers->SetForegroundColour(wxColour(255, 173, 0)); txtServers->SetForegroundColour(wxColour(255, 173, 0));
if (!jf["ModVersion"].is_null()) {
txtModVersion->SetForegroundColour("green");
txtModVersion->SetLabel(to_string(jf["ModVersion"]));
} else {
txtModVersion->SetLabel("NA");
txtModVersion->SetForegroundColour("red");
}
} else { } else {
txtPlayers->SetLabel("NA"); txtPlayers->SetLabel("NA");
txtPlayers->SetForegroundColour("red"); txtPlayers->SetForegroundColour("red");
txtServers->SetLabel("NA"); txtServers->SetLabel("NA");
txtServers->SetForegroundColour("red"); txtServers->SetForegroundColour("red");
txtModVersion->SetLabel("NA");
txtModVersion->SetForegroundColour("red");
} }
} }
@ -497,7 +506,6 @@ std::string GetPictureName() {
return ""; return "";
} }
/////////// Progress Bar Function /////////// /////////// Progress Bar Function ///////////
bool ProgressBar(size_t c, size_t t) { bool ProgressBar(size_t c, size_t t) {
int Percent = int(round(double(c) / double(t) * 100)); int Percent = int(round(double(c) / double(t) * 100));
@ -526,6 +534,7 @@ void Relaunch(const std::string& executable) {
/////////// Update Check Function /////////// /////////// Update Check Function ///////////
void UpdateCheck() { void UpdateCheck() {
MyMainFrame::MainFrameInstance->btnLaunch->Disable();
std::string link; std::string link;
std::string HTTP = HTTP::Get("https://beammp.com/builds/launcher?version=true"); std::string HTTP = HTTP::Get("https://beammp.com/builds/launcher?version=true");
bool fallback = false; bool fallback = false;
@ -573,7 +582,7 @@ void UpdateCheck() {
} }
Relaunch(EP); Relaunch(EP);
} else MyMainFrame::MainFrameInstance->txtUpdate->SetLabel("BeamMP V" + Launcher::FullVersion); } else MyMainFrame::MainFrameInstance->btnLaunch->Enable();
} }
/////////// Main Frame Content /////////// /////////// Main Frame Content ///////////
@ -606,14 +615,10 @@ MyMainFrame::MyMainFrame() :
auto* HyperPatreon = new wxHyperlinkCtrl(panel, wxID_ANY, wxT("Patreon"), wxT("https://www.patreon.com/BeamMP"), wxPoint(240, 10)); auto* HyperPatreon = new wxHyperlinkCtrl(panel, wxID_ANY, wxT("Patreon"), wxT("https://www.patreon.com/BeamMP"), wxPoint(240, 10));
// Update: // Update:
txtUpdate = new wxStaticText(panel, wxID_ANY, wxT("Updating BeamMP "), wxPoint(10, 490)); txtUpdate = new wxStaticText(panel, wxID_ANY, wxT("BeamMP V" + Launcher::FullVersion), wxPoint(10, 490));
UpdateBar = new wxGauge(panel, wxID_ANY, 100, wxPoint(10, 520), wxSize(127, -1)); UpdateBar = new wxGauge(panel, wxID_ANY, 100, wxPoint(10, 520), wxSize(127, -1));
UpdateBar->SetValue(0); UpdateBar->SetValue(100);
while (UpdateBar->GetValue() < 101) {
txtUpdate->SetLabel(wxT("Updating BeamMP: " + std::to_string(UpdateBar->GetValue()) + "%"));
UpdateBar->SetValue(UpdateBar->GetValue() + 1);
}
// Information: // Information:
auto* txtGameVersionTitle = new wxStaticText(panel, wxID_ANY, wxT("Game Version: "), wxPoint(160, 490)); auto* txtGameVersionTitle = new wxStaticText(panel, wxID_ANY, wxT("Game Version: "), wxPoint(160, 490));
@ -666,7 +671,6 @@ MyMainFrame::MyMainFrame() :
txtGameVersionTitle->SetForegroundColour("white"); txtGameVersionTitle->SetForegroundColour("white");
txtPlayersTitle->SetForegroundColour("white"); txtPlayersTitle->SetForegroundColour("white");
txtModVersionTitle->SetForegroundColour("white"); txtModVersionTitle->SetForegroundColour("white");
txtModVersion->SetForegroundColour("white");
txtServersTitle->SetForegroundColour("white"); txtServersTitle->SetForegroundColour("white");
txtPatreon->SetForegroundColour("white"); txtPatreon->SetForegroundColour("white");
txtStatus->SetForegroundColour("white"); txtStatus->SetForegroundColour("white");