Exiting a race then starting a new one now works (now 100% clean, and I'm not 100% sure about memory mangement, but a step in the right direction)

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@4136 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2009-10-20 14:02:07 +00:00
parent b21b0c230b
commit 8f4efd2a60
7 changed files with 82 additions and 55 deletions

View File

@ -53,6 +53,7 @@ void initGUI()
void AbstractStateManager::enterGameState()
{
if (getCurrentScreen() != NULL) getCurrentScreen()->tearDown();
m_menu_stack.clear();
m_menu_stack.push_back("race");
m_game_mode = GAME;

View File

@ -53,6 +53,8 @@ DynamicRibbonWidget::DynamicRibbonWidget(const bool combo, const int max_rows)
// -----------------------------------------------------------------------------
void DynamicRibbonWidget::add()
{
//printf("****DynamicRibbonWidget::add()****\n");
m_has_label = (m_text == "bottom");
m_label_height = m_has_label ? 25 : 0; // FIXME : get height from font, don't hardcode
@ -140,6 +142,8 @@ void DynamicRibbonWidget::add()
// -----------------------------------------------------------------------------
void DynamicRibbonWidget::setSubElements()
{
//printf("****DynamicRibbonWidget::setSubElements()****\n");
// ---- Clean-up what was previously there
for (int i=0; i<m_children.size(); i++)
{
@ -239,9 +243,15 @@ void DynamicRibbonWidget::addItem( const irr::core::stringw& user_name, const st
m_items.push_back(desc);
}
// -----------------------------------------------------------------------------
void DynamicRibbonWidget::clearItems()
void DynamicRibbonWidget::clearItems(bool widgetsToo)
{
m_items.clear();
if (widgetsToo)
{
m_children.clearWithoutDeleting();
m_rows.clearWithoutDeleting();
}
m_previous_item_count = 0;
}
#if 0
@ -594,6 +604,8 @@ void DynamicRibbonWidget::updateItemDisplay()
// -----------------------------------------------------------------------------
void DynamicRibbonWidget::setSelection(int item_id)
{
//printf("****DynamicRibbonWidget::setSelection()****\n");
if (m_rows.size() > 1)
{
std::cout << "\n/!\\ Warning, DynamicRibbonWidget::setSelection only makes sense on 1-row ribbons " <<
@ -621,6 +633,8 @@ void DynamicRibbonWidget::setSelection(int item_id)
// -----------------------------------------------------------------------------
void DynamicRibbonWidget::setSelection(int item_id, const int playerID)
{
//printf("****DynamicRibbonWidget::setSelection()****\n");
m_selected_item[playerID] = item_id;
@ -631,6 +645,7 @@ void DynamicRibbonWidget::setSelection(int item_id, const int playerID)
for (int r=0; r<m_row_amount; r++)
{
//printf("Looking for %s in row %i\n", name.c_str(), r);
id = m_rows[r].findItemNamed(name.c_str());
if (id > -1)
{

View File

@ -151,7 +151,7 @@ namespace GUIEngine
/** Clears all items added through 'addItem'. You can then add new items with 'addItem' and call
'updateItemDisplay' to update the display. */
void clearItems();
void clearItems(bool widgetsToo=false);
/** Register a listener to be notified of selection changes within the ribbon */
void registerHoverListener(DynamicRibbonHoverListener* listener);

View File

@ -360,8 +360,12 @@ void RibbonWidget::setLabel(const int id, irr::core::stringw new_name)
int RibbonWidget::findItemNamed(const char* internalName)
{
const int size = m_children.size();
printf("Ribbon : Looking for %s among %i items\n", internalName, size);
for (int n=0; n<size; n++)
{
printf(" Ribbon : Looking for %s in item %i : %s\n", internalName, n, m_children[n].m_properties[PROP_ID].c_str());
if (m_children[n].m_properties[PROP_ID] == internalName) return n;
}
return -1;

View File

@ -148,4 +148,8 @@ void FeatureUnlockedCutScene::onUpdate(float dt, irr::video::IVideoDriver* drive
void FeatureUnlockedCutScene::eventCallback(GUIEngine::Widget* widget, const std::string& name)
{
if (name == "back")
{
StateManager::get()->escapePressed();
}
}

View File

@ -553,7 +553,7 @@ bool KartSelectionScreen::playerQuit(ActivePlayer* player)
int playerID = -1;
DynamicRibbonWidget* w = this->getWidget<DynamicRibbonWidget>("karts");
if (w == NULL )
if (w == NULL)
{
std::cout << "playerQuit() called outside of kart selection screen.\n";
return false;
@ -627,6 +627,11 @@ void KartSelectionScreen::tearDown()
{
//g_player_karts.clearWithoutDeleting();
g_player_karts.clearAndDeleteAll();
// List is rebuilt everytime.
DynamicRibbonWidget* w = this->getWidget<DynamicRibbonWidget>("karts");
assert(w != NULL);
w->clearItems(true);
}
// -----------------------------------------------------------------------------
@ -645,42 +650,38 @@ void KartSelectionScreen::init()
karthoverListener = new KartHoverListener();
w->registerHoverListener(karthoverListener);
}
// Build kart list
// (it is built everytikme, to account for .g. locking)
std::vector<int> group = kart_properties_manager->getKartsInGroup("standard");
const int kart_amount = group.size();
//Widget* area = this->getWidget("playerskarts");
// add Tux (or whatever default kart) first
std::string& default_kart = UserConfigParams::m_default_kart;
for(int n=0; n<kart_amount; n++)
{
const KartProperties* prop = kart_properties_manager->getKartById(group[n]);
if (prop->getIdent() == default_kart)
{
std::string icon_path = file_manager->getDataDir() ;
icon_path += "/karts/" + prop->getIdent() + "/" + prop->getIconFile();
w->addItem(prop->getName(), prop->getIdent().c_str(), icon_path.c_str());
std::cout << "Add item : " << prop->getIdent().c_str() << std::endl;
break;
}
}
if (!this->m_inited)
{
// Build kart list
std::vector<int> group = kart_properties_manager->getKartsInGroup("standard");
const int kart_amount = group.size();
// add Tux (or whatever default kart) first
std::string& default_kart = UserConfigParams::m_default_kart;
for(int n=0; n<kart_amount; n++)
// add others
for(int n=0; n<kart_amount; n++)
{
const KartProperties* prop = kart_properties_manager->getKartById(group[n]);
if (prop->getIdent() != default_kart)
{
const KartProperties* prop = kart_properties_manager->getKartById(group[n]);
if (prop->getIdent() == default_kart)
{
std::string icon_path = file_manager->getDataDir() ;
icon_path += "/karts/" + prop->getIdent() + "/" + prop->getIconFile();
w->addItem(prop->getName(), prop->getIdent().c_str(), icon_path.c_str());
break;
}
std::string icon_path = file_manager->getDataDir() ;
icon_path += "/karts/" + prop->getIdent() + "/" + prop->getIconFile();
w->addItem(prop->getName(), prop->getIdent().c_str(), icon_path.c_str());
std::cout << "Add item : " << prop->getIdent().c_str() << std::endl;
}
// add others
for(int n=0; n<kart_amount; n++)
{
const KartProperties* prop = kart_properties_manager->getKartById(group[n]);
if (prop->getIdent() != default_kart)
{
std::string icon_path = file_manager->getDataDir() ;
icon_path += "/karts/" + prop->getIdent() + "/" + prop->getIconFile();
w->addItem(prop->getName(), prop->getIdent().c_str(), icon_path.c_str());
}
}
this->m_inited = true;
}
/*
@ -713,8 +714,6 @@ void KartSelectionScreen::init()
// Player 0 select first kart (Tux)
w->setSelection(0, 0);
w->m_rows[0].requestFocus();
this->m_inited = true;
}
// -----------------------------------------------------------------------------

View File

@ -66,31 +66,35 @@ void TracksScreen::init()
DynamicRibbonWidget* w = this->getWidget<DynamicRibbonWidget>("tracks");
assert( w != NULL );
if (!this->m_inited)
const int trackAmount = track_manager->getNumberOfTracks();
bool hasLockedTracks = false;
for (int n=0; n<trackAmount; n++)
{
const int trackAmount = track_manager->getNumberOfTracks();
bool hasLockedTracks = false;
for (int n=0; n<trackAmount; n++)
Track* curr = track_manager->getTrack(n);
if (unlock_manager->isLocked(curr->getIdent()))
{
Track* curr = track_manager->getTrack(n);
if (unlock_manager->isLocked(curr->getIdent()))
{
hasLockedTracks = true;
continue;
}
w->addItem(curr->getName(), curr->getIdent(), curr->getScreenshotFile());
hasLockedTracks = true;
continue;
}
if (hasLockedTracks)
{
w->addItem(_("Locked Tracks"), "Lock", "textures/gui_lock.png");
}
this->m_inited = true;
w->addItem(curr->getName(), curr->getIdent(), curr->getScreenshotFile());
}
if (hasLockedTracks)
{
w->addItem(_("Locked Tracks"), "Lock", "textures/gui_lock.png");
}
w->updateItemDisplay();
}
void TracksScreen::tearDown()
{
// List is rebuilt everytime (for instance, locking might change, etc.)
DynamicRibbonWidget* w = this->getWidget<DynamicRibbonWidget>("tracks");
assert(w != NULL);
// FIXME : the 'true' argument to force deleting references to irrLicht widgets is an ugly hack
// Ideally the widget should find out by itself and take care of that.
w->clearItems(true);
}