Bugfix: the previously selected character wasn't selected by default anymore.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2480 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk
2008-11-19 23:56:33 +00:00
parent aa27ba317d
commit c4e4a94211
2 changed files with 29 additions and 11 deletions

View File

@@ -132,17 +132,7 @@ CharSel::CharSel(int whichPlayer)
const int LAST_KART = user_config->m_player[m_player_index].getLastKartId();
if( LAST_KART != -1 && kart_properties_manager->kartAvailable(LAST_KART))// is LAST_KART not in vector of selected karts
{
int local_index = 0;
for(unsigned int i=0; i<m_index_avail_karts.size(); i++)
{
if(m_index_avail_karts[i]==LAST_KART)
{
local_index = i;
break;
}
}
m_offset = local_index - m_max_entries/2;
if(m_offset<0) m_offset+=(int)m_index_avail_karts.size();
int local_index = computeOffset();
widget_manager->setSelectedWgt(WTOK_NAME0 +(m_max_entries-1)/2);
switchCharacter(local_index);
}
@@ -344,6 +334,12 @@ void CharSel::update(float dt)
// Switch group will update the list of selected karts, i.e. use the
// information about kart availability just received from the server
switchGroup();
// Now try to select the previously selected kart again (in network
// karts might be removed if they are not available on all computers,
// so we have to recompute offset)
computeOffset();
// Now hide the message window and display the widgets:
widget_manager->hideWgt(WTOK_MESSAGE);
widget_manager->showWgt(WTOK_TITLE, WTOK_DOWN);
@@ -403,6 +399,27 @@ void CharSel::update(float dt)
widget_manager->update(dt);
} // update
//----------------------------------------------------------------------------
/** This computes m_offset so that the previously selected kart is selected
* by default.
*/
int CharSel::computeOffset()
{
int local_index = 0;
int last_kart = user_config->m_player[m_player_index].getLastKartId();
for(unsigned int i=0; i<m_index_avail_karts.size(); i++)
{
if(m_index_avail_karts[i]==last_kart)
{
local_index = i;
break;
}
}
m_offset = local_index - m_max_entries/2;
if(m_offset<0) m_offset+=(int)m_index_avail_karts.size();
return local_index;
} // recmoputeOffset
//----------------------------------------------------------------------------
/** Pushes the next menu onto the stack. In case of split screen that might
* be another instance of the character selection menu.

View File

@@ -45,6 +45,7 @@ private:
void switchGroup();
void nextMenu();
void switchCharacter(int n);
int computeOffset();
public:
CharSel(int which_player);
~CharSel();