Skip to content

Commit 2f2cab5

Browse files
Add a UI button to delete servers from the "Recent" tab (#2253)
* add a UI button to remove any server from the "Recent" tab * fix code style * Tweak icon initial alpha Co-authored-by: patrikjuvonen <22572159+patrikjuvonen@users.noreply.github.com>
1 parent ab2d769 commit 2f2cab5

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

Client/core/ServerBrowser/CServerBrowser.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,17 @@ void CServerBrowser::CreateTab(ServerBrowserType type, const char* szName)
346346
m_pAddressFavoriteIcon[type]->LoadFromFile("cgui\\images\\serverbrowser\\favorite.png");
347347
m_pAddressFavoriteIcon[type]->SetAlpha(0.3f);
348348
m_pAddressFavoriteIcon[type]->SetClickHandler(GUI_CALLBACK(&CServerBrowser::OnFavouritesClick, this));
349+
350+
// Remove recent played icon
351+
if (type == ServerBrowserTypes::RECENTLY_PLAYED)
352+
{
353+
m_pRemoveFromRecentIcon[type] = reinterpret_cast<CGUIStaticImage*>(pManager->CreateStaticImage(m_pEditAddress[type]));
354+
m_pRemoveFromRecentIcon[type]->SetPosition(CVector2D(fWidth - 40 - 8, (SB_BUTTON_SIZE_Y - 16) / 2), false);
355+
m_pRemoveFromRecentIcon[type]->SetSize(CVector2D(16, 16), false);
356+
m_pRemoveFromRecentIcon[type]->LoadFromFile("cgui\\images\\serverbrowser\\trashcan.png");
357+
m_pRemoveFromRecentIcon[type]->SetAlpha(0.3f);
358+
m_pRemoveFromRecentIcon[type]->SetClickHandler(GUI_CALLBACK(&CServerBrowser::OnRemoveFromRecentClick, this));
359+
}
349360

350361
// History Combo
351362
fWidth = fWidth + COMBOBOX_ARROW_SIZE_X;
@@ -593,6 +604,8 @@ void CServerBrowser::DeleteTab(ServerBrowserType type)
593604
delete m_pComboAddressHistory[type];
594605

595606
delete m_pAddressFavoriteIcon[type];
607+
if (type == ServerBrowserTypes::RECENTLY_PLAYED)
608+
delete m_pRemoveFromRecentIcon[type];
596609
delete m_pEditSearch[type];
597610
delete m_pButtonRefreshIcon[type];
598611

@@ -877,6 +890,9 @@ void CServerBrowser::UpdateServerList(ServerBrowserType Type, bool bClearServerL
877890

878891
m_pServerList[Type]->ForceUpdate();
879892
pList->SetUpdated(false);
893+
894+
if (Type == ServerBrowserTypes::RECENTLY_PLAYED)
895+
m_pRemoveFromRecentIcon[Type]->SetAlpha(0.3f);
880896
}
881897

882898
void CServerBrowser::CreateHistoryList()
@@ -1132,6 +1148,8 @@ bool CServerBrowser::RemoveSelectedServerFromRecentlyPlayedList()
11321148
m_pServerList[Type]->RemoveRow(iSelectedItem);
11331149
SaveRecentlyPlayedList();
11341150

1151+
m_pRemoveFromRecentIcon[Type]->SetAlpha(0.3f);
1152+
11351153
return true;
11361154
}
11371155

@@ -1223,6 +1241,14 @@ bool CServerBrowser::OnClick(CGUIElement* pElement)
12231241

12241242
// save the selected server
12251243
m_iSelectedServer[Type] = iSelectedIndex;
1244+
1245+
if (Type == ServerBrowserTypes::RECENTLY_PLAYED)
1246+
m_pRemoveFromRecentIcon[Type]->SetAlpha(1.0f);
1247+
}
1248+
else
1249+
{
1250+
if (Type == ServerBrowserTypes::RECENTLY_PLAYED)
1251+
m_pRemoveFromRecentIcon[Type]->SetAlpha(0.3f);
12261252
}
12271253
return true;
12281254
}
@@ -1421,6 +1447,11 @@ bool CServerBrowser::OnFavouritesClick(CGUIElement* pElement)
14211447
return true;
14221448
}
14231449

1450+
bool CServerBrowser::OnRemoveFromRecentClick(CGUIElement* pElement)
1451+
{
1452+
return RemoveSelectedServerFromRecentlyPlayedList();
1453+
}
1454+
14241455
bool CServerBrowser::OnAddressChanged(CGUIElement* pElement)
14251456
{
14261457
unsigned short usPort;

Client/core/ServerBrowser/CServerBrowser.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ class CServerBrowser : public CSingleton<CServerBrowser>
163163
CGUIComboBox* m_pComboAddressHistory[SERVER_BROWSER_TYPE_COUNT];
164164
CGUIStaticImage* m_pSearchTypeIcon[SERVER_BROWSER_TYPE_COUNT];
165165
CGUIStaticImage* m_pAddressFavoriteIcon[SERVER_BROWSER_TYPE_COUNT];
166+
CGUIStaticImage* m_pRemoveFromRecentIcon[SERVER_BROWSER_TYPE_COUNT];
166167

167168
CGUIComboBox* m_pComboSearchType[SERVER_BROWSER_TYPE_COUNT];
168169
CGUIEdit* m_pEditSearch[SERVER_BROWSER_TYPE_COUNT];
@@ -216,6 +217,7 @@ class CServerBrowser : public CSingleton<CServerBrowser>
216217
bool OnRefreshClick(CGUIElement* pElement);
217218
bool OnInfoClick(CGUIElement* pElement);
218219
bool OnFavouritesClick(CGUIElement* pElement);
220+
bool OnRemoveFromRecentClick(CGUIElement* pElement);
219221
bool OnBackClick(CGUIElement* pElement);
220222
bool OnGeneralHelpClick(CGUIElement* pElement);
221223
bool OnGeneralHelpDeactivate(CGUIElement* pElement);
Loading

0 commit comments

Comments
 (0)