Public Member Functions | |
virtual void | OnRender () |
called every frame before the menu is rendered | |
void | Update () |
gServerMenu (const char *title) | |
~gServerMenu () | |
virtual void | HandleEvent (SDL_Event event) |
handles a key press | |
void | Render (REAL y, const tString &servername, const tOutput &score, const tOutput &users, const tOutput &ping) |
void | Render (REAL y, const tString &servername, const tString &score, const tString &users, const tString &ping) |
Private Attributes | |
int | sortKey_ |
Definition at line 105 of file gServerBrowser.cpp.
gServerMenu::gServerMenu | ( | const char * | title | ) |
Definition at line 454 of file gServerBrowser.cpp.
References nServerInfo::GetFirstServer(), uMenu::items, GrowingArrayBase::Len(), tListItem< T >::Next(), uMenu::ReverseItems(), uMenu::selected, gServerMenuItem::SetServer(), and tNEW.
00455 : uMenu(title, false) 00456 , sortKey_( nServerInfo::KEY_SCORE ) 00457 { 00458 nServerInfo *run = nServerInfo::GetFirstServer(); 00459 while (run) 00460 { 00461 gServerMenuItem *item = tNEW(gServerMenuItem)(this); 00462 item->SetServer(run); 00463 run = run->Next(); 00464 } 00465 00466 ReverseItems(); 00467 00468 if (items.Len() <= 0) 00469 { 00470 selected = 1; 00471 tNEW(gServerMenuItem)(this); 00472 } 00473 else 00474 selected = items.Len(); 00475 }
gServerMenu::~gServerMenu | ( | ) |
Definition at line 477 of file gServerBrowser.cpp.
References uMenu::items, and GrowingArrayBase::Len().
void gServerMenu::OnRender | ( | ) | [virtual] |
called every frame before the menu is rendered
Reimplemented from uMenu.
Definition at line 340 of file gServerBrowser.cpp.
References uMenu::OnRender(), tSysTimeFloat(), and Update().
00341 { 00342 uMenu::OnRender(); 00343 00344 // next time the server list is to be resorted 00345 static double sg_serverMenuRefreshTimeout=-1E+32f; 00346 00347 if (sg_serverMenuRefreshTimeout < tSysTimeFloat()) 00348 { 00349 Update(); 00350 sg_serverMenuRefreshTimeout = tSysTimeFloat()+2.0f; 00351 } 00352 }
void gServerMenu::Update | ( | ) |
Definition at line 354 of file gServerBrowser.cpp.
References nServerInfo::CalcScoreAll(), continuePoll, gServerInfo::GetFirstServer(), getFriends(), getFriendsEnabled(), nServerInfo::GetFromLANContinuously(), uMenuItem::GetID(), gServerMenuItem::GetServer(), uMenu::items, tString::Len(), GrowingArrayBase::Len(), MAX_FRIENDS, gServerInfo::menuItem, mi, gServerInfo::Next(), NULL, REAL, uMenu::ReverseItems(), uMenu::selected, gServerMenuItem::SetServer(), sg_queryType, sg_RequestLANcontinuously, gServerInfo::show, tListItem< nServerInfo >::Sort(), sortKey_, nServerInfo::StartQueryAll(), tString::StrPos(), tNEW, tSysTimeFloat(), nServerInfo::UserNames(), and nServerInfo::Users().
Referenced by gServerBrowser::BrowseServers(), HandleEvent(), and OnRender().
00355 { 00356 // get currently selected server 00357 gServerMenuItem *item = NULL; 00358 if ( selected < items.Len() ) 00359 { 00360 item = dynamic_cast<gServerMenuItem*>(items(selected)); 00361 } 00362 gServerInfo* info = NULL; 00363 if ( item ) 00364 { 00365 info = item->GetServer(); 00366 } 00367 00368 // keep the cursor position relative to the top, if possible 00369 int selectedFromTop = items.Len() - selected; 00370 00371 ReverseItems(); 00372 00373 nServerInfo::CalcScoreAll(); 00374 nServerInfo::Sort( nServerInfo::PrimaryKey( sortKey_ ) ); 00375 00376 int mi = 1; 00377 gServerInfo *run = gServerInfo::GetFirstServer(); 00378 bool oneFound = false; //so we can display all if none were found 00379 while (run) 00380 { 00381 //check friend filter 00382 if (getFriendsEnabled()) 00383 { 00384 run->show = false; 00385 int i; 00386 tString userNames = run->UserNames(); 00387 tString* friends = getFriends(); 00388 for (i = MAX_FRIENDS; i>=0; i--) 00389 { 00390 if (run->Users() > 0 && friends[i].Len() > 1 && userNames.StrPos(friends[i]) >= 0) 00391 { 00392 oneFound = true; 00393 run->show = true; 00394 } 00395 } 00396 } 00397 run = run->Next(); 00398 } 00399 00400 run = gServerInfo::GetFirstServer(); 00401 { 00402 while (run) 00403 { 00404 if (run->show || oneFound == false) 00405 { 00406 if (mi >= items.Len()) 00407 tNEW(gServerMenuItem)(this); 00408 00409 gServerMenuItem *item = dynamic_cast<gServerMenuItem*>(items(mi)); 00410 item->SetServer(run); 00411 mi++; 00412 } 00413 run = run->Next(); 00414 } 00415 } 00416 00417 if (items.Len() == 1) 00418 selected = 1; 00419 00420 while(mi < items.Len() && items.Len() > 2) 00421 { 00422 uMenuItem *it = items(items.Len()-1); 00423 delete it; 00424 } 00425 00426 ReverseItems(); 00427 00428 // keep the cursor position relative to the top, if possible ( calling function will handle the clamping ) 00429 selected = items.Len() - selectedFromTop; 00430 00431 // set cursor to currently selected server, if possible 00432 if ( info && info->menuItem ) 00433 { 00434 selected = info->menuItem->GetID(); 00435 } 00436 00437 if (sg_RequestLANcontinuously) 00438 { 00439 static REAL timeout=-1E+32f; 00440 00441 if (timeout < tSysTimeFloat()) 00442 { 00443 nServerInfo::GetFromLANContinuously(); 00444 if (!continuePoll) 00445 { 00446 nServerInfo::StartQueryAll( sg_queryType ); 00447 continuePoll = true; 00448 } 00449 timeout = tSysTimeFloat()+10; 00450 } 00451 } 00452 }
void gServerMenu::HandleEvent | ( | SDL_Event | event | ) | [virtual] |
handles a key press
Reimplemented from uMenu.
Definition at line 308 of file gServerBrowser.cpp.
References FriendsToggle(), uMenu::HandleEvent(), nServerInfo::KEY_MAX, sortKey_, and Update().
00309 { 00310 #ifndef DEDICATED 00311 switch (event.type) 00312 { 00313 case SDL_KEYDOWN: 00314 switch (event.key.keysym.sym) 00315 { 00316 case(SDLK_LEFT): 00317 sortKey_ = ( sortKey_ + nServerInfo::KEY_MAX-1 ) % nServerInfo::KEY_MAX; 00318 Update(); 00319 return; 00320 break; 00321 case(SDLK_RIGHT): 00322 sortKey_ = ( sortKey_ + 1 ) % nServerInfo::KEY_MAX; 00323 Update(); 00324 return; 00325 break; 00326 case(SDLK_m): 00327 FriendsToggle(); 00328 Update(); 00329 return; 00330 break; 00331 default: 00332 break; 00333 } 00334 } 00335 #endif 00336 00337 uMenu::HandleEvent( event ); 00338 }
void gServerMenu::Render | ( | REAL | y, | |
const tString & | servername, | |||
const tOutput & | score, | |||
const tOutput & | users, | |||
const tOutput & | ping | |||
) |
Definition at line 502 of file gServerBrowser.cpp.
References tColoredString::ColorString(), nServerInfo::KEY_MAX, nServerInfo::KEY_NAME, nServerInfo::KEY_PING, nServerInfo::KEY_SCORE, nServerInfo::KEY_USERS, and sortKey_.
Referenced by gServerMenuItem::Render().
00505 { 00506 tColoredString highlight, normal; 00507 highlight << tColoredString::ColorString( 1,.7,.7 ); 00508 normal << tColoredString::ColorString( .7,.3,.3 ); 00509 00510 tString sn, s, u, p; 00511 00512 sn << normal; 00513 s << normal; 00514 u << normal; 00515 p << normal; 00516 00517 switch ( sortKey_ ) 00518 { 00519 case nServerInfo::KEY_NAME: 00520 sn = highlight; 00521 break; 00522 case nServerInfo::KEY_PING: 00523 p = highlight; 00524 break; 00525 case nServerInfo::KEY_USERS: 00526 u = highlight; 00527 break; 00528 case nServerInfo::KEY_SCORE: 00529 s = highlight; 00530 break; 00531 case nServerInfo::KEY_MAX: 00532 break; 00533 } 00534 00535 sn << servername;// tColoredString::RemoveColors( servername ); 00536 s << score; 00537 u << users; 00538 p << ping; 00539 00540 Render(y, sn, s, u, p); 00541 }
void gServerMenu::Render | ( | REAL | y, | |
const tString & | servername, | |||
const tString & | score, | |||
const tString & | users, | |||
const tString & | ping | |||
) |
Definition at line 489 of file gServerBrowser.cpp.
References DisplayText(), sr_fontServerBrowser, sr_glOut, and text_height.
00492 { 00493 if (sr_glOut) 00494 { 00495 DisplayText(-.9f, y, text_height, servername.c_str(), sr_fontServerBrowser, -1); 00496 DisplayText(.6f, y, text_height, ping.c_str(), sr_fontServerBrowser, 1); 00497 DisplayText(.75f, y, text_height, users.c_str(), sr_fontServerBrowser, 1); 00498 DisplayText(.9f, y, text_height, score.c_str(), sr_fontServerBrowser, 1); 00499 } 00500 }
int gServerMenu::sortKey_ [private] |
Definition at line 107 of file gServerBrowser.cpp.
Referenced by HandleEvent(), Render(), and Update().