Merge branch 'master' of github.com:supertuxkart/stk-code

This commit is contained in:
hiker 2015-08-05 17:02:55 +10:00
commit 41f744baf3
3 changed files with 32 additions and 22 deletions

View File

@ -560,7 +560,9 @@ EventPropagation RibbonWidget::focused(const int playerID)
{ {
if (m_selection[playerID] != -1) if (m_selection[playerID] != -1)
{ {
m_active_children.get(m_selection[playerID])->focused(playerID); int selection = m_selection[playerID];
if (selection < m_active_children.size())
m_active_children.get(selection)->focused(playerID);
} }
} }

View File

@ -39,8 +39,6 @@ GrandPrixManager::GrandPrixManager()
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
GrandPrixManager::~GrandPrixManager() GrandPrixManager::~GrandPrixManager()
{ {
for(unsigned int i=0; i<m_gp_data.size(); i++)
delete m_gp_data[i];
} // ~GrandPrixManager } // ~GrandPrixManager
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -84,9 +82,10 @@ void GrandPrixManager::loadDir(const std::string& dir, enum GrandPrixData::GPGro
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void GrandPrixManager::load(const std::string& filename, enum GrandPrixData::GPGroupType group) void GrandPrixManager::load(const std::string& filename, enum GrandPrixData::GPGroupType group)
{ {
GrandPrixData* gp = NULL;
try try
{ {
GrandPrixData* gp = new GrandPrixData(filename, group); gp = new GrandPrixData(filename, group);
m_gp_data.push_back(gp); m_gp_data.push_back(gp);
Log::debug("GrandPrixManager", Log::debug("GrandPrixManager",
"Grand Prix '%s' loaded from %s", "Grand Prix '%s' loaded from %s",
@ -94,6 +93,8 @@ void GrandPrixManager::load(const std::string& filename, enum GrandPrixData::GPG
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
if (gp != NULL)
delete gp;
Log::error("GrandPrixManager", Log::error("GrandPrixManager",
"Ignoring Grand Prix %s (%s)\n", filename.c_str(), e.what()); "Ignoring Grand Prix %s (%s)\n", filename.c_str(), e.what());
} }
@ -102,9 +103,7 @@ void GrandPrixManager::load(const std::string& filename, enum GrandPrixData::GPG
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void GrandPrixManager::reload() void GrandPrixManager::reload()
{ {
for(unsigned int i=0; i<m_gp_data.size(); i++) m_gp_data.clearAndDeleteAll();
delete m_gp_data[i];
m_gp_data.clear();
loadFiles(); loadFiles();
} // reload } // reload
@ -124,7 +123,7 @@ std::string GrandPrixManager::generateId()
unique = true; unique = true;
for (unsigned int i = 0; i < m_gp_data.size(); i++) for (unsigned int i = 0; i < m_gp_data.size(); i++)
{ {
if (m_gp_data[i]->getId() == s.str()) if (m_gp_data[i].getId() == s.str())
{ {
unique = false; unique = false;
break; break;
@ -139,25 +138,31 @@ std::string GrandPrixManager::generateId()
bool GrandPrixManager::existsName(const irr::core::stringw& name) const bool GrandPrixManager::existsName(const irr::core::stringw& name) const
{ {
for (unsigned int i = 0; i < m_gp_data.size(); i++) for (unsigned int i = 0; i < m_gp_data.size(); i++)
if (m_gp_data[i]->getName() == name) if (m_gp_data[i].getName() == name)
return true; return true;
return false; return false;
} // existsName } // existsName
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
GrandPrixData* GrandPrixManager::getGrandPrix(const std::string& s) const const GrandPrixData* GrandPrixManager::getGrandPrix(const std::string& s) const
{ {
return editGrandPrix(s); for (unsigned int i = 0; i<m_gp_data.size(); i++)
{
if (m_gp_data[i].getId() == s)
return m_gp_data.get(i);
} // for i in m_gp_data
return NULL;
} // getGrandPrix } // getGrandPrix
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
GrandPrixData* GrandPrixManager::editGrandPrix(const std::string& s) const GrandPrixData* GrandPrixManager::editGrandPrix(const std::string& s)
{ {
for(unsigned int i=0; i<m_gp_data.size(); i++) for(unsigned int i=0; i<m_gp_data.size(); i++)
{ {
if(m_gp_data[i]->getId() == s) if (m_gp_data[i].getId() == s)
return m_gp_data[i]; return m_gp_data.get(i);
} // for i in m_gp_data } // for i in m_gp_data
return NULL; return NULL;
@ -166,13 +171,12 @@ GrandPrixData* GrandPrixManager::editGrandPrix(const std::string& s) const
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void GrandPrixManager::checkConsistency() void GrandPrixManager::checkConsistency()
{ {
for(unsigned int i=0; i<m_gp_data.size(); i++) for (int i = (int)m_gp_data.size() - 1; i >= 0; i--)
{ {
if(!m_gp_data[i]->checkConsistency()) if (!m_gp_data[i].checkConsistency())
{ {
// delete this GP, since a track is missing // delete this GP, since a track is missing
delete *(m_gp_data.erase(m_gp_data.begin()+i)); m_gp_data.erase(i);
i--;
} }
} }
} // checkConsistency } // checkConsistency

View File

@ -23,6 +23,7 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include "utils/ptr_vector.hpp"
#include "irrlicht.h" #include "irrlicht.h"
class GrandPrixData; class GrandPrixData;
@ -35,7 +36,7 @@ class GrandPrixManager
private: private:
static const char* SUFFIX; static const char* SUFFIX;
std::vector<GrandPrixData*> m_gp_data; PtrVector<GrandPrixData> m_gp_data;
/** Load all the grands prix from the 3 directories known */ /** Load all the grands prix from the 3 directories known */
void loadFiles(); void loadFiles();
@ -51,12 +52,11 @@ public:
GrandPrixManager(); GrandPrixManager();
~GrandPrixManager(); ~GrandPrixManager();
void reload(); void reload();
GrandPrixData* getGrandPrix(const std::string& s) const;
bool existsName(const irr::core::stringw& name) const; bool existsName(const irr::core::stringw& name) const;
void checkConsistency(); void checkConsistency();
// Methods for the gp editor // Methods for the gp editor
GrandPrixData* editGrandPrix(const std::string& s) const; GrandPrixData* editGrandPrix(const std::string& s);
GrandPrixData* createNewGP(const irr::core::stringw& newName); GrandPrixData* createNewGP(const irr::core::stringw& newName);
GrandPrixData* copy(const std::string& id, GrandPrixData* copy(const std::string& id,
const irr::core::stringw& newName); const irr::core::stringw& newName);
@ -64,7 +64,11 @@ public:
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/** Returns a pointer to the data for the specified GP. /** Returns a pointer to the data for the specified GP.
* \param i Index of the GP. */ * \param i Index of the GP. */
GrandPrixData* getGrandPrix(const int i) const { return m_gp_data[i]; } const GrandPrixData* getGrandPrix(const std::string& s) const;
// ------------------------------------------------------------------------
/** Returns a pointer to the data for the specified GP.
* \param i Index of the GP. */
const GrandPrixData* getGrandPrix(const int i) const { return m_gp_data.get(i); }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/** Returns the number of GPs. */ /** Returns the number of GPs. */
unsigned int getNumberOfGrandPrix() const { return (int)m_gp_data.size(); } unsigned int getNumberOfGrandPrix() const { return (int)m_gp_data.size(); }