Launcher: several fixes and improvements

- Reload map list each time the combo box is opened (needs to refresh if user installed a new map while launcher is still open).
- Reload playlists each time the combo box is opened (makes sure that the list is up-to-date if user modified it in any way).
- Use global VPK dir regex to parse out map names.
This commit is contained in:
Kawe Mazidjatari 2024-04-23 00:06:11 +02:00
parent 84abfced6a
commit bdc7929286
2 changed files with 42 additions and 15 deletions

View File

@ -6,8 +6,10 @@
#include "basepanel.h" #include "basepanel.h"
#include "sdklauncher.h" #include "sdklauncher.h"
#include "mathlib/bits.h" #include "mathlib/bits.h"
#include "vpklib/packedstore.h"
#include "vstdlib/keyvaluessystem.h" #include "vstdlib/keyvaluessystem.h"
#include "filesystem/filesystem_std.h" #include "filesystem/filesystem_std.h"
#include "tier2/fileutils.h"
extern CFileSystem_Stdio* FileSystem(); extern CFileSystem_Stdio* FileSystem();
@ -93,6 +95,7 @@ void CSurface::Init()
this->m_MapCombo->SetLocation({ 15, 25 }); this->m_MapCombo->SetLocation({ 15, 25 });
this->m_MapCombo->SetTabIndex(0); this->m_MapCombo->SetTabIndex(0);
this->m_MapCombo->SetSelectedIndex(0); this->m_MapCombo->SetSelectedIndex(0);
this->m_MapCombo->DropDownOpened += ReloadMaplists;
this->m_MapCombo->SetAnchor(Forms::AnchorStyles::Top | Forms::AnchorStyles::Left); this->m_MapCombo->SetAnchor(Forms::AnchorStyles::Top | Forms::AnchorStyles::Left);
this->m_MapCombo->SetDropDownStyle(Forms::ComboBoxStyle::DropDownList); this->m_MapCombo->SetDropDownStyle(Forms::ComboBoxStyle::DropDownList);
this->m_GameGroup->AddControl(this->m_MapCombo); this->m_GameGroup->AddControl(this->m_MapCombo);
@ -111,6 +114,7 @@ void CSurface::Init()
this->m_PlaylistCombo->SetLocation({ 15, 50 }); this->m_PlaylistCombo->SetLocation({ 15, 50 });
this->m_PlaylistCombo->SetTabIndex(0); this->m_PlaylistCombo->SetTabIndex(0);
this->m_PlaylistCombo->SetSelectedIndex(0); this->m_PlaylistCombo->SetSelectedIndex(0);
this->m_PlaylistCombo->DropDownOpened += ReloadPlaylists;
this->m_PlaylistCombo->SetAnchor(Forms::AnchorStyles::Top | Forms::AnchorStyles::Left); this->m_PlaylistCombo->SetAnchor(Forms::AnchorStyles::Top | Forms::AnchorStyles::Left);
this->m_PlaylistCombo->SetDropDownStyle(Forms::ComboBoxStyle::DropDownList); this->m_PlaylistCombo->SetDropDownStyle(Forms::ComboBoxStyle::DropDownList);
this->m_GameGroup->AddControl(this->m_PlaylistCombo); this->m_GameGroup->AddControl(this->m_PlaylistCombo);
@ -159,7 +163,6 @@ void CSurface::Init()
this->m_PlaylistFileTextBox->SetTabIndex(0); this->m_PlaylistFileTextBox->SetTabIndex(0);
this->m_PlaylistFileTextBox->SetText("playlists_r5_patch.txt"); this->m_PlaylistFileTextBox->SetText("playlists_r5_patch.txt");
this->m_PlaylistFileTextBox->SetAnchor(Forms::AnchorStyles::Top | Forms::AnchorStyles::Left); this->m_PlaylistFileTextBox->SetAnchor(Forms::AnchorStyles::Top | Forms::AnchorStyles::Left);
this->m_PlaylistFileTextBox->LostFocus += &ReloadPlaylists;
this->m_GameGroupExt->AddControl(this->m_PlaylistFileTextBox); this->m_GameGroupExt->AddControl(this->m_PlaylistFileTextBox);
this->m_PlaylistFileLabel = new UIX::UIXLabel(); this->m_PlaylistFileLabel = new UIX::UIXLabel();
@ -536,9 +539,6 @@ void CSurface::Init()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void CSurface::Setup() void CSurface::Setup()
{ {
this->ParseMaps();
this->ParsePlaylists();
this->m_ModeCombo->Items.Add("Host"); this->m_ModeCombo->Items.Add("Host");
this->m_ModeCombo->Items.Add("Server"); this->m_ModeCombo->Items.Add("Server");
this->m_ModeCombo->Items.Add("Client"); this->m_ModeCombo->Items.Add("Client");
@ -744,29 +744,33 @@ void CSurface::LaunchGame(Forms::Control* pSender)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void CSurface::ParseMaps() void CSurface::ParseMaps()
{ {
if (!m_MapCombo->Items.Contains(""))
m_MapCombo->Items.Add("");
const fs::path vpkPath("vpk"); const fs::path vpkPath("vpk");
if (!fs::exists(vpkPath)) if (!fs::exists(vpkPath))
{ {
return; return;
} }
fs::directory_iterator directoryIterator(vpkPath); fs::directory_iterator directoryIterator(vpkPath);
std::regex archiveRegex{ R"([^_]*_(.*)(.bsp.pak000_dir).*)" }; std::cmatch regexMatches;
std::smatch regexMatches;
m_MapCombo->Items.Add("");
for (const fs::directory_entry& directoryEntry : directoryIterator) for (const fs::directory_entry& directoryEntry : directoryIterator)
{ {
std::string fileName = directoryEntry.path().u8string(); std::string fileName = directoryEntry.path().u8string();
std::regex_search(fileName, regexMatches, archiveRegex); std::regex_search(fileName.c_str(), regexMatches, g_VpkDirFileRegex);
if (!regexMatches.empty()) if (!regexMatches.empty())
{ {
if (regexMatches[1].str().compare("frontend") == 0) const std::sub_match<const char*>& match = regexMatches[2];
if (match.compare("frontend") == 0)
{ {
continue; continue;
} }
else if (regexMatches[1].str().compare("mp_common") == 0) else if (match.compare("mp_common") == 0)
{ {
if (!this->m_MapCombo->Items.Contains("mp_lobby")) if (!this->m_MapCombo->Items.Contains("mp_lobby"))
{ {
@ -774,9 +778,14 @@ void CSurface::ParseMaps()
} }
continue; continue;
} }
else if (!this->m_MapCombo->Items.Contains(regexMatches[1].str().c_str())) else
{ {
this->m_MapCombo->Items.Add(regexMatches[1].str().c_str()); const string mapName = match.str();
if (!this->m_MapCombo->Items.Contains(match.str().c_str()))
{
this->m_MapCombo->Items.Add(match.str().c_str());
}
} }
} }
} }
@ -787,14 +796,14 @@ void CSurface::ParseMaps()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void CSurface::ParsePlaylists() void CSurface::ParsePlaylists()
{ {
if (!m_PlaylistCombo->Items.Contains(""))
m_PlaylistCombo->Items.Add("");
CUtlString playlistPath; CUtlString playlistPath;
playlistPath.Format("platform\\%s", this->m_PlaylistFileTextBox->Text().ToCString()); playlistPath.Format("platform\\%s", this->m_PlaylistFileTextBox->Text().ToCString());
const char* pPlaylistPath = playlistPath.String(); const char* pPlaylistPath = playlistPath.String();
if (!m_PlaylistCombo->Items.Contains(""))
m_PlaylistCombo->Items.Add("");
if (!FileSystem()->FileExists(pPlaylistPath)) if (!FileSystem()->FileExists(pPlaylistPath))
return; return;
@ -822,6 +831,20 @@ void CSurface::ParsePlaylists()
} }
} }
//-----------------------------------------------------------------------------
// Purpose: clears the form and reloads the map list
// Input : *pSender -
//-----------------------------------------------------------------------------
void CSurface::ReloadMaplists(Forms::Control* pSender)
{
CSurface* pSurface = reinterpret_cast<CSurface*>(pSender->FindForm());
pSurface->m_MapCombo->Items.Clear();
pSurface->m_MapCombo->OnSizeChanged();
pSurface->ParseMaps();
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: clears the form and reloads the playlist // Purpose: clears the form and reloads the playlist
// Input : *pSender - // Input : *pSender -
@ -832,6 +855,7 @@ void CSurface::ReloadPlaylists(Forms::Control* pSender)
pSurface->m_PlaylistCombo->Items.Clear(); pSurface->m_PlaylistCombo->Items.Clear();
pSurface->m_PlaylistCombo->OnSizeChanged(); pSurface->m_PlaylistCombo->OnSizeChanged();
pSurface->ParsePlaylists(); pSurface->ParsePlaylists();
} }

View File

@ -40,7 +40,10 @@ private:
static void LaunchGame(Forms::Control* pSender); static void LaunchGame(Forms::Control* pSender);
static void CleanSDK(Forms::Control* pSender); static void CleanSDK(Forms::Control* pSender);
static void UpdateSDK(Forms::Control* pSender); static void UpdateSDK(Forms::Control* pSender);
static void ReloadMaplists(Forms::Control* pSender);
static void ReloadPlaylists(Forms::Control* pSender); static void ReloadPlaylists(Forms::Control* pSender);
static void VirtualItemToClipboard(const std::unique_ptr<MouseEventArgs>& pEventArgs, Forms::Control* pSender); static void VirtualItemToClipboard(const std::unique_ptr<MouseEventArgs>& pEventArgs, Forms::Control* pSender);
static void GetVirtualItem(const std::unique_ptr<Forms::RetrieveVirtualItemEventArgs>& pEventArgs, Forms::Control* pSender); static void GetVirtualItem(const std::unique_ptr<Forms::RetrieveVirtualItemEventArgs>& pEventArgs, Forms::Control* pSender);
static void ForwardCommandToGame(Forms::Control* pSender); static void ForwardCommandToGame(Forms::Control* pSender);