Add basic dashboard panel

Basic dashboard for the average user, along with an install/repair button that is yet to be implemented.
This commit is contained in:
Kawe Mazidjatari 2023-07-26 15:56:08 +02:00
parent c7d5bc5c86
commit b85d91defb
7 changed files with 206 additions and 55 deletions

View File

@ -10,8 +10,10 @@ add_sources( SOURCE_GROUP "Core"
)
add_sources( SOURCE_GROUP "GUI"
"basepanel.cpp"
"basepanel.h"
"advanced_surface.cpp"
"advanced_surface.h"
"base_surface.cpp"
"base_surface.h"
)
add_sources( SOURCE_GROUP "Resource"

View File

@ -3,7 +3,7 @@
// Purpose: Launcher user interface implementation.
//
//=============================================================================//
#include "basepanel.h"
#include "advanced_surface.h"
#include "sdklauncher.h"
#include "mathlib/bits.h"
#include "utility/vdf_parser.h"
@ -11,7 +11,7 @@
//-----------------------------------------------------------------------------
// Purpose: creates the surface layout
//-----------------------------------------------------------------------------
void CSurface::Init()
void CAdvancedSurface::Init()
{
// START DESIGNER CODE
const INT WindowX = 800;
@ -20,7 +20,7 @@ void CSurface::Init()
this->SuspendLayout();
this->SetAutoScaleDimensions({ 6, 13 });
this->SetAutoScaleMode(Forms::AutoScaleMode::Font);
this->SetText("Dashboard");
this->SetText("Advanced Dashboard");
this->SetClientSize({ WindowX, WindowY });
this->SetFormBorderStyle(Forms::FormBorderStyle::FixedSingle);
this->SetStartPosition(Forms::FormStartPosition::CenterScreen);
@ -499,7 +499,7 @@ void CSurface::Init()
//-----------------------------------------------------------------------------
// Purpose: post-init surface setup
//-----------------------------------------------------------------------------
void CSurface::Setup()
void CAdvancedSurface::Setup()
{
this->ParseMaps();
this->ParsePlaylists();
@ -520,7 +520,7 @@ void CSurface::Setup()
//-----------------------------------------------------------------------------
// Purpose: load and apply settings
//-----------------------------------------------------------------------------
void CSurface::LoadSettings()
void CAdvancedSurface::LoadSettings()
{
const fs::path settingsPath(Format("platform/%s/%s", SDK_SYSTEM_CFG_PATH, LAUNCHER_SETTING_FILE));
if (!fs::exists(settingsPath))
@ -618,7 +618,7 @@ void CSurface::LoadSettings()
//-----------------------------------------------------------------------------
// Purpose: save current launcher state
//-----------------------------------------------------------------------------
void CSurface::SaveSettings()
void CAdvancedSurface::SaveSettings()
{
const fs::path settingsPath(Format("platform/%s/%s", SDK_SYSTEM_CFG_PATH, LAUNCHER_SETTING_FILE));
const fs::path parentPath = settingsPath.parent_path();
@ -680,27 +680,27 @@ void CSurface::SaveSettings()
// Purpose: load callback
// Input : *pSender -
//-----------------------------------------------------------------------------
void CSurface::OnLoad(Forms::Control* pSender)
void CAdvancedSurface::OnLoad(Forms::Control* pSender)
{
((CSurface*)pSender->FindForm())->LoadSettings();
((CAdvancedSurface*)pSender->FindForm())->LoadSettings();
}
//-----------------------------------------------------------------------------
// Purpose: close callback
// Input : *pSender -
//-----------------------------------------------------------------------------
void CSurface::OnClose(const std::unique_ptr<FormClosingEventArgs>& /*pEventArgs*/, Forms::Control* pSender)
void CAdvancedSurface::OnClose(const std::unique_ptr<FormClosingEventArgs>& /*pEventArgs*/, Forms::Control* pSender)
{
((CSurface*)pSender->FindForm())->SaveSettings();
((CAdvancedSurface*)pSender->FindForm())->SaveSettings();
}
//-----------------------------------------------------------------------------
// Purpose: removes redundant files from the game install
// Input : *pSender -
//-----------------------------------------------------------------------------
void CSurface::CleanSDK(Forms::Control* pSender)
void CAdvancedSurface::CleanSDK(Forms::Control* pSender)
{
CSurface* pSurface = reinterpret_cast<CSurface*>(pSender->FindForm());
CAdvancedSurface* pSurface = reinterpret_cast<CAdvancedSurface*>(pSender->FindForm());
pSurface->m_LogList.push_back(LogList_t(spdlog::level::info, "Running cleaner for SDK installation\n"));
pSurface->m_ConsoleListView->SetVirtualListSize(static_cast<int32_t>(pSurface->m_LogList.size()));
@ -711,9 +711,9 @@ void CSurface::CleanSDK(Forms::Control* pSender)
// Purpose: updates the SDK
// Input : *pSender -
//-----------------------------------------------------------------------------
void CSurface::UpdateSDK(Forms::Control* pSender)
void CAdvancedSurface::UpdateSDK(Forms::Control* pSender)
{
CSurface* pSurface = reinterpret_cast<CSurface*>(pSender->FindForm());
CAdvancedSurface* pSurface = reinterpret_cast<CAdvancedSurface*>(pSender->FindForm());
pSurface->m_LogList.push_back(LogList_t(spdlog::level::info, "Running updater for SDK installation\n"));
pSurface->m_ConsoleListView->SetVirtualListSize(static_cast<int32_t>(pSurface->m_LogList.size()));
@ -724,9 +724,9 @@ void CSurface::UpdateSDK(Forms::Control* pSender)
// Purpose: launches the game with the SDK
// Input : *pSender -
//-----------------------------------------------------------------------------
void CSurface::LaunchGame(Forms::Control* pSender)
void CAdvancedSurface::LaunchGame(Forms::Control* pSender)
{
CSurface* pSurface = reinterpret_cast<CSurface*>(pSender->FindForm());
CAdvancedSurface* pSurface = reinterpret_cast<CAdvancedSurface*>(pSender->FindForm());
pSurface->m_LogList.clear(); // Clear console.
pSurface->m_ConsoleListView->SetVirtualListSize(0);
@ -735,7 +735,7 @@ void CSurface::LaunchGame(Forms::Control* pSender)
string svParameter;
pSurface->AppendParameterInternal(svParameter, "-launcher");
eLaunchMode launchMode = g_pLauncher->GetMainSurface()->BuildParameter(svParameter);
eLaunchMode launchMode = pSurface->BuildParameter(svParameter);
uint64_t nProcessorAffinity = pSurface->GetProcessorAffinity(svParameter);
if (g_pLauncher->CreateLaunchContext(launchMode, nProcessorAffinity, svParameter.c_str(), "startup_launcher.cfg"))
@ -745,7 +745,7 @@ void CSurface::LaunchGame(Forms::Control* pSender)
//-----------------------------------------------------------------------------
// Purpose: parses all available maps from the main vpk directory
//-----------------------------------------------------------------------------
void CSurface::ParseMaps()
void CAdvancedSurface::ParseMaps()
{
const fs::path vpkPath("vpk");
if (!fs::exists(vpkPath))
@ -788,7 +788,7 @@ void CSurface::ParseMaps()
//-----------------------------------------------------------------------------
// Purpose: parses all playlists from user selected playlist file
//-----------------------------------------------------------------------------
void CSurface::ParsePlaylists()
void CAdvancedSurface::ParsePlaylists()
{
fs::path playlistPath(Format("platform\\%s", this->m_PlaylistFileTextBox->Text().ToCString()));
m_PlaylistCombo->Items.Add("");
@ -831,9 +831,9 @@ void CSurface::ParsePlaylists()
// Purpose: clears the form and reloads the playlist
// Input : *pSender -
//-----------------------------------------------------------------------------
void CSurface::ReloadPlaylists(Forms::Control* pSender)
void CAdvancedSurface::ReloadPlaylists(Forms::Control* pSender)
{
CSurface* pSurface = reinterpret_cast<CSurface*>(pSender->FindForm());
CAdvancedSurface* pSurface = reinterpret_cast<CAdvancedSurface*>(pSender->FindForm());
pSurface->m_PlaylistCombo->Items.Clear();
pSurface->m_PlaylistCombo->OnSizeChanged();
@ -845,12 +845,12 @@ void CSurface::ReloadPlaylists(Forms::Control* pSender)
// Input : &pEventArgs -
// Input : *pSender -
//-----------------------------------------------------------------------------
void CSurface::VirtualItemToClipboard(const std::unique_ptr<MouseEventArgs>& pEventArgs, Forms::Control* pSender)
void CAdvancedSurface::VirtualItemToClipboard(const std::unique_ptr<MouseEventArgs>& pEventArgs, Forms::Control* pSender)
{
if (pEventArgs->Button != Forms::MouseButtons::Right)
return;
CSurface* pSurface = reinterpret_cast<CSurface*>(pSender->FindForm());
CAdvancedSurface* pSurface = reinterpret_cast<CAdvancedSurface*>(pSender->FindForm());
List<uint32_t> lSelected = pSurface->m_ConsoleListView->SelectedIndices();
if (!lSelected.Count())
@ -868,9 +868,9 @@ void CSurface::VirtualItemToClipboard(const std::unique_ptr<MouseEventArgs>& pEv
// Input : &pEventArgs -
// *pSender -
//-----------------------------------------------------------------------------
void CSurface::GetVirtualItem(const std::unique_ptr<Forms::RetrieveVirtualItemEventArgs>& pEventArgs, Forms::Control* pSender)
void CAdvancedSurface::GetVirtualItem(const std::unique_ptr<Forms::RetrieveVirtualItemEventArgs>& pEventArgs, Forms::Control* pSender)
{
CSurface* pSurface = reinterpret_cast<CSurface*>(pSender->FindForm());
CAdvancedSurface* pSurface = reinterpret_cast<CAdvancedSurface*>(pSender->FindForm());
if (static_cast<int>(pSurface->m_LogList.size()) <= 0)
return;
@ -915,9 +915,9 @@ void CSurface::GetVirtualItem(const std::unique_ptr<Forms::RetrieveVirtualItemEv
// Purpose: forward input command to all game window instances
// Input : *pSender -
//-----------------------------------------------------------------------------
void CSurface::ForwardCommandToGame(Forms::Control* pSender)
void CAdvancedSurface::ForwardCommandToGame(Forms::Control* pSender)
{
CSurface* pSurface = reinterpret_cast<CSurface*>(pSender->FindForm());
CAdvancedSurface* pSurface = reinterpret_cast<CAdvancedSurface*>(pSender->FindForm());
vector<HWND> vecHandles;
if (!EnumWindows(EnumWindowsProc, reinterpret_cast<LPARAM>(&vecHandles)))
@ -957,7 +957,7 @@ void CSurface::ForwardCommandToGame(Forms::Control* pSender)
// *szParameter -
// *szArgument -
//-----------------------------------------------------------------------------
void CSurface::AppendParameterInternal(string& svParameterList, const char* szParameter, const char* szArgument /*= nullptr*/)
void CAdvancedSurface::AppendParameterInternal(string& svParameterList, const char* szParameter, const char* szArgument /*= nullptr*/)
{
if (szArgument)
svParameterList.append(Format("%s \"%s\"\n", szParameter, szArgument));
@ -969,7 +969,7 @@ void CSurface::AppendParameterInternal(string& svParameterList, const char* szPa
// Purpose: appends the reversed core count value to the command line buffer
// Input : &svParameters -
//-----------------------------------------------------------------------------
void CSurface::AppendProcessorParameters(string& svParameters)
void CAdvancedSurface::AppendProcessorParameters(string& svParameters)
{
const int nReservedCores = atoi(this->m_ReservedCoresTextBox->Text().ToCString());
if (nReservedCores > -1) // A reserved core count of 0 seems to crash the game on some systems.
@ -990,7 +990,7 @@ void CSurface::AppendProcessorParameters(string& svParameters)
// Purpose: appends the console parameters
// Input : &svParameters -
//-----------------------------------------------------------------------------
void CSurface::AppendConsoleParameters(string& svParameters)
void CAdvancedSurface::AppendConsoleParameters(string& svParameters)
{
if (this->m_ConsoleToggle->Checked())
AppendParameterInternal(svParameters, "-wconsole");
@ -1007,7 +1007,7 @@ void CSurface::AppendConsoleParameters(string& svParameters)
// Purpose: appends the video parameters
// Input : &svParameters -
//-----------------------------------------------------------------------------
void CSurface::AppendVideoParameters(string& svParameters)
void CAdvancedSurface::AppendVideoParameters(string& svParameters)
{
if (this->m_WindowedToggle->Checked())
AppendParameterInternal(svParameters, "-windowed");
@ -1036,7 +1036,7 @@ void CSurface::AppendVideoParameters(string& svParameters)
// Purpose: appends the host parameters
// Input : &svParameters -
//-----------------------------------------------------------------------------
void CSurface::AppendHostParameters(string& svParameters)
void CAdvancedSurface::AppendHostParameters(string& svParameters)
{
if (!String::IsNullOrEmpty(this->m_HostNameTextBox->Text()))
{
@ -1065,7 +1065,7 @@ void CSurface::AppendHostParameters(string& svParameters)
// Purpose: appends the net parameters
// Input : &svParameters -
//-----------------------------------------------------------------------------
void CSurface::AppendNetParameters(string& svParameters)
void CAdvancedSurface::AppendNetParameters(string& svParameters)
{
AppendParameterInternal(svParameters, "+net_encryptionEnable", this->m_NetEncryptionToggle->Checked() ? "1" : "0");
AppendParameterInternal(svParameters, "+net_useRandomKey", this->m_NetRandomKeyToggle->Checked() ? "1" : "0");
@ -1080,7 +1080,7 @@ void CSurface::AppendNetParameters(string& svParameters)
// Input : &svParameters -
// Output : eLaunchMode [HOST - SERVER - CLIENT - NONE]
//-----------------------------------------------------------------------------
eLaunchMode CSurface::BuildParameter(string& svParameters)
eLaunchMode CAdvancedSurface::BuildParameter(string& svParameters)
{
eLaunchMode results = eLaunchMode::LM_NONE;
@ -1241,7 +1241,7 @@ eLaunchMode CSurface::BuildParameter(string& svParameters)
// dedi cvar if core count = 1
// Input : &svParameters -
//-----------------------------------------------------------------------------
uint64_t CSurface::GetProcessorAffinity(string& svParameters)
uint64_t CAdvancedSurface::GetProcessorAffinity(string& svParameters)
{
char* pEnd;
const uint64_t nProcessorAffinity = strtoull(this->m_ProcessorAffinityTextBox->Text().ToCString(), &pEnd, 16);
@ -1261,7 +1261,7 @@ uint64_t CSurface::GetProcessorAffinity(string& svParameters)
// Purpose: gets the control item value
// Input : *pControl -
//-----------------------------------------------------------------------------
const char* CSurface::GetControlValue(Forms::Control* pControl)
const char* CAdvancedSurface::GetControlValue(Forms::Control* pControl)
{
switch (pControl->GetType())
{
@ -1280,10 +1280,10 @@ const char* CSurface::GetControlValue(Forms::Control* pControl)
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CSurface::CSurface() : Forms::Form()
CAdvancedSurface::CAdvancedSurface() : Forms::Form()
{
this->Init();
this->Setup();
}
CSurface* g_pMainUI;
CAdvancedSurface* g_pMainUI;

View File

@ -12,13 +12,10 @@ struct LogList_t
string m_svText;
};
class CSurface : public Forms::Form
class CAdvancedSurface : public Forms::Form
{
public:
CSurface();
virtual ~CSurface()
{
};
CAdvancedSurface();
UIX::UIXListView* ConsoleListView() const { return m_ConsoleListView; };
std::vector<LogList_t> m_LogList;

View File

@ -0,0 +1,106 @@
//=============================================================================//
//
// Purpose: Launcher user interface implementation.
//
//=============================================================================//
#include "base_surface.h"
#include "advanced_surface.h"
#include "tier1/xorstr.h"
CBaseSurface::CBaseSurface()
{
const INT WindowX = 400;
const INT WindowY = 194;
this->SuspendLayout();
this->SetAutoScaleDimensions({ 6, 13 });
this->SetAutoScaleMode(Forms::AutoScaleMode::Font);
this->SetText(XorStr("R5Reloaded"));
this->SetClientSize({ WindowX, WindowY });
this->SetFormBorderStyle(Forms::FormBorderStyle::FixedSingle);
this->SetStartPosition(Forms::FormStartPosition::CenterScreen);
this->SetMinimizeBox(true);
this->SetMaximizeBox(false);
this->SetBackColor(Drawing::Color(47, 54, 61));
const INT BASE_GROUP_OFFSET = 12;
this->m_BaseGroup = new UIX::UIXGroupBox();
this->m_BaseGroup->SetSize({ WindowX-(BASE_GROUP_OFFSET*2), WindowY-(BASE_GROUP_OFFSET*2) });
this->m_BaseGroup->SetLocation({ BASE_GROUP_OFFSET, BASE_GROUP_OFFSET });
this->m_BaseGroup->SetTabIndex(0);
this->m_BaseGroup->SetText("");
this->m_BaseGroup->SetAnchor(Forms::AnchorStyles::Top | Forms::AnchorStyles::Left);
this->AddControl(this->m_BaseGroup);
const bool isInstalled = fs::exists("r5apex.exe");
this->m_ManageButton = new UIX::UIXButton();
this->m_ManageButton->SetSize({ 168, 70 });
this->m_ManageButton->SetLocation({ 10, 10 });
this->m_ManageButton->SetTabIndex(9);
this->m_ManageButton->SetText(isInstalled ? XorStr("Launch Apex") : XorStr("Install Apex"));
this->m_ManageButton->SetAnchor(Forms::AnchorStyles::Bottom | Forms::AnchorStyles::Left);
this->m_ManageButton->Click += isInstalled ? &OnAdvancedClick : &OnAdvancedClick;
m_BaseGroup->AddControl(this->m_ManageButton);
this->m_RepairButton = new UIX::UIXButton();
this->m_RepairButton->SetSize({ 168, 70 });
this->m_RepairButton->SetLocation({ 10, 90 });
this->m_RepairButton->SetTabIndex(9);
this->m_RepairButton->SetEnabled(isInstalled);
this->m_RepairButton->SetText(XorStr("Repair Apex"));
this->m_RepairButton->SetAnchor(Forms::AnchorStyles::Bottom | Forms::AnchorStyles::Left);
this->m_RepairButton->Click += &OnAdvancedClick;
m_BaseGroup->AddControl(this->m_RepairButton);
this->m_DonateButton = new UIX::UIXButton();
this->m_DonateButton->SetSize({ 178, 43 });
this->m_DonateButton->SetLocation({ 188, 10 });
this->m_DonateButton->SetTabIndex(9);
this->m_DonateButton->SetText(XorStr("Support Amos (The Creator)"));
this->m_DonateButton->SetAnchor(Forms::AnchorStyles::Bottom | Forms::AnchorStyles::Left);
this->m_DonateButton->Click += &OnSupportClick;
m_BaseGroup->AddControl(this->m_DonateButton);
this->m_JoinButton = new UIX::UIXButton();
this->m_JoinButton->SetSize({ 178, 43 });
this->m_JoinButton->SetLocation({ 188, 63 });
this->m_JoinButton->SetTabIndex(9);
this->m_JoinButton->SetText(XorStr("Join our Discord"));
this->m_JoinButton->SetAnchor(Forms::AnchorStyles::Bottom | Forms::AnchorStyles::Left);
this->m_JoinButton->Click += &OnJoinClick;
m_BaseGroup->AddControl(this->m_JoinButton);
this->m_AdvancedButton = new UIX::UIXButton();
this->m_AdvancedButton->SetSize({ 178, 43 });
this->m_AdvancedButton->SetLocation({ 188, 116 });
this->m_AdvancedButton->SetTabIndex(9);
this->m_AdvancedButton->SetEnabled(isInstalled);
this->m_AdvancedButton->SetText(XorStr("Advanced Options"));
this->m_AdvancedButton->SetAnchor(Forms::AnchorStyles::Bottom | Forms::AnchorStyles::Left);
this->m_AdvancedButton->Click += &OnAdvancedClick;
m_BaseGroup->AddControl(this->m_AdvancedButton);
}
void CBaseSurface::OnAdvancedClick(Forms::Control* Sender)
{
auto pAdvancedSurface = std::make_unique<CAdvancedSurface>();
pAdvancedSurface->ShowDialog((Forms::Form*)Sender->FindForm());
}
void CBaseSurface::OnSupportClick(Forms::Control* /*Sender*/)
{
//auto pAdvancedSurface = std::make_unique<CAdvancedSurface>();
//pAdvancedSurface->ShowDialog((Forms::Form*)Sender->FindForm());
ShellExecute(0, 0, XorStr("https://www.paypal.com/donate/?hosted_button_id=S28DHC2TF6UV4"), 0, 0, SW_SHOW);
}
void CBaseSurface::OnJoinClick(Forms::Control* /*Sender*/)
{
//auto pAdvancedSurface = std::make_unique<CAdvancedSurface>();
//pAdvancedSurface->ShowDialog((Forms::Form*)Sender->FindForm());
ShellExecute(0, 0, XorStr("https://discord.com/invite/jqMkUdXrBr"), 0, 0, SW_SHOW);
}

View File

@ -0,0 +1,43 @@
#pragma once
#include "advanced_surface.h"
class CBaseSurface : public Forms::Form
{
public:
CBaseSurface();
virtual ~CBaseSurface()
{
};
protected:
static void OnAdvancedClick(Forms::Control* Sender);
static void OnSupportClick(Forms::Control* Sender);
static void OnJoinClick(Forms::Control* Sender);
private:
enum class eMode
{
NONE = -1,
HOST,
SERVER,
CLIENT,
};
enum class eVisibility
{
PUBLIC,
HIDDEN,
};
// Game.
UIX::UIXGroupBox* m_BaseGroup;
UIX::UIXButton* m_ManageButton;
UIX::UIXButton* m_RepairButton;
UIX::UIXButton* m_DonateButton;
UIX::UIXButton* m_JoinButton;
UIX::UIXButton* m_AdvancedButton;
};

View File

@ -4,7 +4,8 @@
//
//=============================================================================//
#include "tier0/binstream.h"
#include "basepanel.h"
#include "base_surface.h"
#include "advanced_surface.h"
#include "sdklauncher.h"
///////////////////////////////////////////////////////////////////////////////
@ -15,7 +16,7 @@ void CLauncher::RunSurface()
Forms::Application::EnableVisualStyles();
UIX::UIXTheme::InitializeRenderer(new Themes::KoreTheme());
m_pSurface = new CSurface();
m_pSurface = new CBaseSurface();
Forms::Application::Run(g_pLauncher->m_pSurface);
UIX::UIXTheme::ShutdownRenderer();
}

View File

@ -1,6 +1,8 @@
#pragma once
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#include "base_surface.h"
class CLauncher
{
public:
@ -30,12 +32,12 @@ public:
m_pLogger->log(nLevel, svBuffer);
m_pLogger->flush();
if (m_pSurface)
{
m_pSurface->m_LogList.push_back(LogList_t(nLevel, svBuffer));
m_pSurface->ConsoleListView()->SetVirtualListSize(static_cast<int32_t>(m_pSurface->m_LogList.size()));
m_pSurface->ConsoleListView()->Refresh();
}
//if (m_pSurface)
//{
// m_pSurface->m_LogList.push_back(LogList_t(nLevel, svBuffer));
// m_pSurface->ConsoleListView()->SetVirtualListSize(static_cast<int32_t>(m_pSurface->m_LogList.size()));
// m_pSurface->ConsoleListView()->Refresh();
//}
}
void RunSurface();
@ -49,10 +51,10 @@ public:
void SetupLaunchContext(const char* szConfig, const char* szGameDll, const char* szCommandLine);
bool LaunchProcess() const;
CSurface* GetMainSurface() const { return m_pSurface; }
CBaseSurface* GetMainSurface() const { return m_pSurface; }
private:
CSurface* m_pSurface;
CBaseSurface* m_pSurface;
std::shared_ptr<spdlog::logger> m_pLogger;
uint64_t m_ProcessorAffinity;