Added a search field to the network games list

floating-point
Julius Michaelis 2010-09-19 19:01:31 +02:00
parent c80fcf1a62
commit 4a55192db8
5 changed files with 63 additions and 11 deletions

View File

@ -1012,6 +1012,8 @@ IDS_NET_INPUT=Netzwerk Eingehend
IDS_NET_INVALIDREF=Ungültige Spielreferenz!
IDS_NET_IP=IP:
IDS_NET_IP_DESC=Spiel mit angegebener Adresse beitreten. Adresse eingeben um einem bekannten Spiel direkt beizutreten.
IDS_NET_MSSEARCH=Suche:
IDS_NET_MSSEARCH_DESC=Liste nach Schlüsselwörtern durchsuchen.
IDS_NET_JOINGAME=Netzwerkbeitritt
IDS_NET_JOINGAMEBY=Trete Spiel von %s bei...
IDS_NET_JOINGAME_BTN=&Beitreten

View File

@ -1012,6 +1012,8 @@ IDS_NET_INPUT=Network Input
IDS_NET_INVALIDREF=Invalid reference!
IDS_NET_IP=IP:
IDS_NET_IP_DESC=Join address of selected game. Enter an address here to join a game directly.
IDS_NET_MSSEARCH=Search:
IDS_NET_MSSEARCH_DESC=Search masterserver games for keywords.
IDS_NET_JOINGAME=Joining network game
IDS_NET_JOINGAMEBY=Joining game by %s...
IDS_NET_JOINGAME_BTN=&Join game

View File

@ -423,10 +423,12 @@ namespace C4GUI
pCurr->GetBounds().y = 0;
pCurr->UpdateOwnPos();
}
iOverallHgt = pCurr->GetBounds().Hgt;
if(pCurr->fVisible) iOverallHgt = pCurr->GetBounds().Hgt;
else iOverallHgt = 0;
// others stacked under it
while ((pCurr = pCurr->GetNext()))
{
if(!pCurr->fVisible) continue; //Do not reserve space for hidden elements
int32_t iYSpace = pCurr->GetListItemTopSpacing();
int32_t iNewY = iOverallHgt + iYSpace;
iOverallHgt += pCurr->GetBounds().Hgt + iYSpace;

View File

@ -326,17 +326,19 @@ void C4StartupNetListEntry::UpdateSmallState()
void C4StartupNetListEntry::UpdateEntrySize()
{
// restack all labels by their size
int32_t iLblCnt = (fIsSmall ? 2 : InfoLabelCount), iY=1;
for (int i=0; i<iLblCnt; ++i)
{
C4Rect rcBounds = pInfoLbl[i]->GetBounds();
rcBounds.y = iY;
iY += rcBounds.Hgt + 2;
if(fVisible) {
// restack all labels by their size
int32_t iLblCnt = (fIsSmall ? 2 : InfoLabelCount), iY=1;
for (int i=0; i<iLblCnt; ++i)
{
C4Rect rcBounds = pInfoLbl[i]->GetBounds();
rcBounds.y = iY;
iY += rcBounds.Hgt + 2;
pInfoLbl[i]->SetBounds(rcBounds);
}
// resize this control
GetBounds().Hgt = iY-1;
}
// resize this control
GetBounds().Hgt = iY-1;
} else GetBounds().Hgt = 0;
UpdateSize();
}
@ -377,6 +379,12 @@ void C4StartupNetListEntry::UpdateText()
if (fRestackElements) UpdateEntrySize();
}
void C4StartupNetListEntry::SetVisibility(bool fToValue) {
bool fChange = fToValue != fVisible;
C4GUI::Window::SetVisibility(fToValue);
if(fChange) UpdateEntrySize();
}
void C4StartupNetListEntry::AddStatusIcon(C4GUI::Icons eIcon, const char *szToolTip)
{
// safety
@ -552,6 +560,17 @@ bool C4StartupNetListEntry::IsSameRefQueryAddress(const char *szJoinaddress)
return SEqualNoCase(sRefClientAddress.getData(), szJoinaddress);
}
bool C4StartupNetListEntry::KeywordMatch(const char *szMatch)
{
// only finished references
if (!pRef) return false;
if(SSearchNoCase(pRef->getTitle(),szMatch)) return true;
C4Client *pHost = pRef->Parameters.Clients.getHost();
if(pHost && SSearchNoCase(pHost->getName(),szMatch)) return true;
if(SSearchNoCase(pRef->getComment(),szMatch)) return true;
return false;
}
const char *C4StartupNetListEntry::GetJoinAddress()
{
// only unresolved references
@ -628,6 +647,19 @@ C4StartupNetDlg::C4StartupNetDlg() : C4StartupDlg(LoadResStr("IDS_DLG_NETSTART")
C4GUI::ComponentAligner caGameList(pSheetGameList->GetContainedClientRect(), 0,0, false);
C4GUI::WoodenLabel *pGameListLbl; int32_t iCaptHgt = C4GUI::WoodenLabel::GetDefaultHeight(&::GraphicsResource.TextFont);
pGameListLbl = new C4GUI::WoodenLabel(LoadResStr("IDS_NET_GAMELIST"), caGameList.GetFromTop(iCaptHgt), C4GUI_Caption2FontClr, &::GraphicsResource.TextFont, ALeft);
// search field
C4GUI::WoodenLabel *pSearchLbl;
const char *szSearchLblText = LoadResStr("IDS_NET_MSSEARCH");
int32_t iSearchWdt=100, iSearchHgt;
::GraphicsResource.TextFont.GetTextExtent(szSearchLblText, iSearchWdt, iSearchHgt, true);
C4GUI::ComponentAligner caSearch(caGameList.GetFromTop(iSearchHgt), 0,0);
pSearchLbl = new C4GUI::WoodenLabel(szSearchLblText, caSearch.GetFromLeft(iSearchWdt+10), C4GUI_Caption2FontClr, &::GraphicsResource.TextFont);
const char *szSearchTip = LoadResStr("IDS_NET_MSSEARCH_DESC");
pSearchLbl->SetToolTip(szSearchTip);
pSheetGameList->AddElement(pSearchLbl);
pSearchFieldEdt = new C4GUI::CallbackEdit<C4StartupNetDlg>(caSearch.GetAll(), this, &C4StartupNetDlg::OnSearchFieldEnter);
pSearchFieldEdt->SetToolTip(szSearchTip);
pSheetGameList->AddElement(pSearchFieldEdt);
//const char *szGameSelListTip = LoadResStr("IDS_NET_GAMELIST_INFO"); disabled this tooltip, it's mainly disturbing when browsing the list
//pGameListLbl->SetToolTip(szGameSelListTip);
pSheetGameList->AddElement(pGameListLbl);
@ -846,6 +878,9 @@ void C4StartupNetDlg::UpdateList(bool fGotReference)
if (fUpdatingList) return;
fUpdatingList = true;
pGameSelList->FreezeScrolling();
// Games display mask
const char *szGameMask = pSearchFieldEdt->GetText();
if (!szGameMask) szGameMask = "";
// Update all child entries
bool fAnyRemoval = false;
C4GUI::Element *pElem, *pNextElem = pGameSelList->GetFirst();
@ -854,6 +889,7 @@ void C4StartupNetDlg::UpdateList(bool fGotReference)
pNextElem = pElem->GetNext(); // determine next exec element now - execution
C4StartupNetListEntry *pEntry = static_cast<C4StartupNetListEntry *>(pElem);
// do item updates
if(pEntry->GetReference()) pEntry->SetVisibility(pEntry->KeywordMatch(szGameMask));
bool fKeepEntry = true;
if (fGotReference)
fKeepEntry = pEntry->OnReference();
@ -984,6 +1020,11 @@ bool C4StartupNetDlg::DoOK()
return true;
}
}
if (GetFocus() == pSearchFieldEdt)
{
UpdateList();
return true;
}
// get currently selected item
C4GUI::Element *pSelection = pGameSelList->GetSelectedItem();
StdCopyStrBuf strNoJoin(LoadResStr("IDS_NET_NOJOIN"));

View File

@ -111,6 +111,7 @@ public:
bool Execute(); // update stuff - if false is returned, the item is to be removed
bool OnReference(); // like Execute(), but only called if some reference was received
void UpdateCollapsed(bool fToCollapseValue);
void SetVisibility(bool fToValue);
const char *GetError() { return fError ? sError.getData() : NULL; } // return error message, if any is set
C4Network2Reference *GrabReference(); // grab the reference so it won't be deleted when this item is removed
@ -118,6 +119,7 @@ public:
bool IsSameHost(const C4Network2Reference *pRef2); // check whether the reference was created by the same host as this one
bool IsSameAddress(const C4Network2Reference *pRef2); // check whether there is at least one matching address (address and port)
bool IsSameRefQueryAddress(const char *szJoinAddress); // check whether reference query was created with same host address
bool KeywordMatch(const char *szMatch); // check whether any of the reference contents match a given keyword
const char *GetJoinAddress(); // ref queries only: Get direct join address
};
@ -138,6 +140,7 @@ private:
C4GUI::CallbackButton<C4StartupNetDlg, C4GUI::IconButton> *btnInternet, *btnRecord, *btnUpdate; // right side buttons
C4GUI::Button *btnJoin, *btnRefresh;
C4GUI::Edit *pJoinAddressEdt;
C4GUI::Edit *pSearchFieldEdt;
class C4ChatControl *pChatCtrl;
C4GUI::WoodenLabel *pChatTitleLabel;
C4StartupNetListEntry *pMasterserverClient; // set if masterserver query is enabled: Checks clonk.de for new games
@ -178,6 +181,8 @@ protected:
void OnBtnUpdate(C4GUI::Control *btn);
C4GUI::Edit::InputResult OnJoinAddressEnter(C4GUI::Edit *edt, bool fPasting, bool fPastingMore)
{ DoOK(); return C4GUI::Edit::IR_Abort; }
C4GUI::Edit::InputResult OnSearchFieldEnter(C4GUI::Edit *edt, bool fPasting, bool fPastingMore)
{ DoOK(); return C4GUI::Edit::IR_Abort; }
void OnChatTitleChange(const StdStrBuf &sNewTitle);
private: