Merge remote-tracking branch 'origin/master' into new_login
This commit is contained in:
@@ -39,6 +39,6 @@ or collect any achievements while being online."
|
||||
</box>
|
||||
</div>
|
||||
|
||||
<icon-button id="back" x="0" y="0" height="15%" icon="gui/back.png"/>
|
||||
<icon-button id="back" x="0" y="0" height="8%" icon="gui/back.png"/>
|
||||
|
||||
</stkgui>
|
||||
|
||||
@@ -81,6 +81,7 @@ MusicInformation::MusicInformation(const XMLNode *root,
|
||||
m_normal_music = NULL;
|
||||
m_fast_music = NULL;
|
||||
m_enable_fast = false;
|
||||
m_music_waiting = false;
|
||||
m_faster_time = 1.0f;
|
||||
m_max_pitch = 0.1f;
|
||||
m_gain = 1.0f;
|
||||
|
||||
@@ -308,7 +308,16 @@ void Camera::setInitialTransform()
|
||||
*/
|
||||
void Camera::smoothMoveCamera(float dt)
|
||||
{
|
||||
|
||||
Kart *kart = dynamic_cast<Kart*>(m_kart);
|
||||
if (kart->isFlying())
|
||||
{
|
||||
Vec3 vec3 = m_kart->getXYZ() + Vec3(sin(m_kart->getHeading()) * -4.0f, 0.5f, cos(m_kart->getHeading()) * -4.0f);
|
||||
m_camera->setTarget(m_kart->getXYZ().toIrrVector());
|
||||
m_camera->setPosition(vec3.toIrrVector());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
core::vector3df current_position = m_camera->getPosition();
|
||||
// Smoothly interpolate towards the position and target
|
||||
const KartProperties *kp = m_kart->getKartProperties();
|
||||
@@ -345,6 +354,7 @@ void Camera::smoothMoveCamera(float dt)
|
||||
{
|
||||
current_position += (wanted_position - current_position) * dt * 5;
|
||||
}
|
||||
|
||||
if(m_mode!=CM_FALLING)
|
||||
m_camera->setPosition(current_position);
|
||||
m_camera->setTarget(current_target);//set new target
|
||||
|
||||
@@ -2272,38 +2272,33 @@ void Kart::updateSliding()
|
||||
*/
|
||||
void Kart::updateFlying()
|
||||
{
|
||||
m_body->setLinearVelocity(m_body->getLinearVelocity() * 0.99f);
|
||||
|
||||
if (m_controls.m_accel)
|
||||
{
|
||||
float orientation = getHeading();
|
||||
m_body->applyCentralImpulse(btVector3(60.0f*sin(orientation), 0.0,
|
||||
60.0f*cos(orientation)));
|
||||
btVector3 velocity = m_body->getLinearVelocity();
|
||||
if (velocity.length() < 25)
|
||||
{
|
||||
float orientation = getHeading();
|
||||
m_body->applyCentralImpulse(btVector3(100.0f*sin(orientation), 0.0,
|
||||
100.0f*cos(orientation)));
|
||||
}
|
||||
}
|
||||
else if (m_controls.m_brake)
|
||||
{
|
||||
btVector3 velocity = m_body->getLinearVelocity();
|
||||
if (velocity.length() > -15)
|
||||
{
|
||||
float orientation = getHeading();
|
||||
m_body->applyCentralImpulse(btVector3(-100.0f*sin(orientation), 0.0,
|
||||
-100.0*cos(orientation)));
|
||||
}
|
||||
}
|
||||
|
||||
if (m_controls.m_steer != 0.0f)
|
||||
{
|
||||
m_body->applyTorque(btVector3(0.0, m_controls.m_steer * 3500.0f, 0.0));
|
||||
}
|
||||
if (m_controls.m_brake)
|
||||
{
|
||||
btVector3 velocity = m_body->getLinearVelocity();
|
||||
|
||||
const float x = velocity.x();
|
||||
if (x > 0.2f) velocity.setX(x - 0.2f);
|
||||
else if (x < -0.2f) velocity.setX(x + 0.2f);
|
||||
else velocity.setX(0);
|
||||
|
||||
const float y = velocity.y();
|
||||
if (y > 0.2f) velocity.setY(y - 0.2f);
|
||||
else if (y < -0.2f) velocity.setY(y + 0.2f);
|
||||
else velocity.setY(0);
|
||||
|
||||
const float z = velocity.z();
|
||||
if (z > 0.2f) velocity.setZ(z - 0.2f);
|
||||
else if (z < -0.2f) velocity.setZ(z + 0.2f);
|
||||
else velocity.setZ(0);
|
||||
|
||||
m_body->setLinearVelocity(velocity);
|
||||
|
||||
} // if brake
|
||||
|
||||
// dampen any roll while flying, makes the kart hard to control
|
||||
btVector3 velocity = m_body->getAngularVelocity();
|
||||
|
||||
@@ -469,7 +469,8 @@ void PhysicalObject::init()
|
||||
btVector3(0,extend.getY()*0.5f, 0));
|
||||
m_motion_state = new btDefaultMotionState(m_init_pos);
|
||||
btVector3 inertia;
|
||||
m_shape->calculateLocalInertia(m_mass, inertia);
|
||||
if (m_body_type != MP_EXACT)
|
||||
m_shape->calculateLocalInertia(m_mass, inertia);
|
||||
btRigidBody::btRigidBodyConstructionInfo info(m_mass, m_motion_state,
|
||||
m_shape, inertia);
|
||||
|
||||
|
||||
@@ -35,10 +35,11 @@
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
GrandPrixData::GrandPrixData(const std::string& filename) throw(std::logic_error)
|
||||
GrandPrixData::GrandPrixData(const std::string& filename)
|
||||
{
|
||||
m_filename = filename;
|
||||
m_id = StringUtils::getBasename(StringUtils::removeExtension(filename));
|
||||
m_id = StringUtils::getBasename(
|
||||
StringUtils::removeExtension(filename));
|
||||
m_editable = (filename.find(file_manager->getGPDir(), 0) == 0);
|
||||
reload();
|
||||
}
|
||||
@@ -77,85 +78,98 @@ void GrandPrixData::reload()
|
||||
std::auto_ptr<XMLNode> root(file_manager->createXMLTree(m_filename));
|
||||
if (root.get() == NULL)
|
||||
{
|
||||
Log::error("GrandPrixData","Error while trying to read grandprix file '%s'",
|
||||
m_filename.c_str());
|
||||
throw std::logic_error("File not found");
|
||||
Log::error("GrandPrixData",
|
||||
"Error while trying to read xml Grand Prix from file '%s'. "
|
||||
"Is the file readable for supertuxkart?",
|
||||
m_filename.c_str());
|
||||
throw std::runtime_error("File couldn't be read");
|
||||
}
|
||||
|
||||
bool foundName = false;
|
||||
|
||||
if (root->getName() == "supertuxkart_grand_prix")
|
||||
if (root->getName() != "supertuxkart_grand_prix")
|
||||
{
|
||||
if (root->get("name", &m_name) == 0)
|
||||
{
|
||||
Log::error("GrandPrixData", "Error while trying to read grandprix file '%s' : "
|
||||
"missing 'name' attribute\n", m_filename.c_str());
|
||||
throw std::logic_error("File contents are incomplete or corrupt");
|
||||
}
|
||||
foundName = true;
|
||||
Log::error("GrandPrixData",
|
||||
"Error while trying to read Grand Prix file '%s': "
|
||||
"Root node has the wrong name %s", m_filename.c_str(),
|
||||
root->getName().c_str());
|
||||
throw std::runtime_error("Wrong root node name");
|
||||
}
|
||||
else
|
||||
|
||||
if (!root->get("name", &m_name))
|
||||
{
|
||||
Log::error("GrandPrixData", "Error while trying to read grandprix file '%s' : "
|
||||
"Root node has an unexpected name\n", m_filename.c_str());
|
||||
throw std::logic_error("File contents are incomplete or corrupt");
|
||||
Log::error("GrandPrixData",
|
||||
"Error while trying to read grandprix file '%s': "
|
||||
"missing 'name' attribute", m_filename.c_str());
|
||||
throw std::runtime_error("Missing name attribute");
|
||||
}
|
||||
|
||||
|
||||
// Every iteration means parsing one track entry
|
||||
const int amount = root->getNumNodes();
|
||||
for (int i=0; i<amount; i++)
|
||||
for (int i = 0; i < amount; i++)
|
||||
{
|
||||
const XMLNode* node = root->getNode(i);
|
||||
|
||||
// read a track entry
|
||||
if (node->getName() == "track")
|
||||
if (node->getName() != "track")
|
||||
{
|
||||
std::string trackID;
|
||||
int numLaps;
|
||||
bool reversed = false;
|
||||
|
||||
const int idFound = node->get("id", &trackID );
|
||||
const int lapFound = node->get("laps", &numLaps );
|
||||
// Will stay false if not found
|
||||
node->get("reverse", &reversed );
|
||||
|
||||
if (!idFound || !lapFound)
|
||||
{
|
||||
Log::error("GrandPrixData", "Error while trying to read grandprix file '%s' : "
|
||||
"<track> tag does not have idi and laps reverse attributes. \n",
|
||||
m_filename.c_str());
|
||||
throw std::logic_error("File contents are incomplete or corrupt");
|
||||
}
|
||||
|
||||
// Make sure the track really is reversible
|
||||
Track* t = track_manager->getTrack(trackID);
|
||||
if (t != NULL && reversed)
|
||||
{
|
||||
reversed = t->reverseAvailable();
|
||||
}
|
||||
|
||||
m_tracks.push_back(trackID);
|
||||
m_laps.push_back(numLaps);
|
||||
m_reversed.push_back(reversed);
|
||||
|
||||
assert(m_tracks.size() == m_laps.size() );
|
||||
assert(m_laps.size() == m_reversed.size());
|
||||
Log::error("GrandPrixData"
|
||||
"Unknown node in Grand Prix XML file '%s': %s",
|
||||
m_filename.c_str(), node->getName().c_str());
|
||||
throw std::runtime_error("Unknown node in the XML file");
|
||||
}
|
||||
else
|
||||
|
||||
// 1. Parsing the id atttribute
|
||||
std::string track_id;
|
||||
if (!node->get("id", &track_id))
|
||||
{
|
||||
std::cerr << "Unknown node in Grand Prix XML file : " << node->getName().c_str() << std::endl;
|
||||
throw std::runtime_error("Unknown node in sfx XML file");
|
||||
Log::error("GrandPrixData",
|
||||
"The id attribute is missing in the %d. track entry of "
|
||||
"the Grand Prix file '%s'.", i, m_filename.c_str());
|
||||
throw std::runtime_error("Missing track id");
|
||||
}
|
||||
}// nend for
|
||||
|
||||
// sanity checks
|
||||
if (!foundName)
|
||||
{
|
||||
Log::error("GrandPrixData", "Error while trying to read grandprix file '%s' : "
|
||||
"missing 'name' attribute\n", m_filename.c_str());
|
||||
throw std::logic_error("File contents are incomplete or corrupt");
|
||||
}
|
||||
}
|
||||
// 1.1 Checking if the track exists
|
||||
Track* t = track_manager->getTrack(track_id);
|
||||
if (t == NULL)
|
||||
{
|
||||
Log::error("GrandPrixData",
|
||||
"The Grand Prix file '%s' contains a track '%s' that "
|
||||
"does not exist", m_filename.c_str(), track_id.c_str());
|
||||
throw std::runtime_error("Unknown track");
|
||||
}
|
||||
|
||||
// 2. Parsing the number of laps
|
||||
int number_of_laps;
|
||||
if (!node->get("laps", &number_of_laps))
|
||||
{
|
||||
Log::error("GrandPrixData",
|
||||
"The laps attribute is missing in the %d. track entry "
|
||||
"of the Grand Prix file '%s'.", i, m_filename.c_str());
|
||||
throw std::runtime_error("Missing track id");
|
||||
}
|
||||
|
||||
if (number_of_laps < 1)
|
||||
{
|
||||
Log::error("GrandPrixData",
|
||||
"Track '%s' in the Grand Prix file '%s' should be raced "
|
||||
"with %d laps, which isn't possible.", track_id.c_str(),
|
||||
m_filename.c_str());
|
||||
throw std::runtime_error("Lap count lower than 1");
|
||||
}
|
||||
|
||||
// 3. Parsing the reversed attribute
|
||||
bool reversed = false; // Stays false if not found
|
||||
node->get("reverse", &reversed );
|
||||
if (!t->reverseAvailable())
|
||||
reversed = false;
|
||||
|
||||
// Adding parsed data
|
||||
m_tracks.push_back(track_id);
|
||||
m_laps.push_back(number_of_laps);
|
||||
m_reversed.push_back(reversed);
|
||||
|
||||
assert(m_tracks.size() == m_laps.size() );
|
||||
assert(m_laps.size() == m_reversed.size());
|
||||
} // end for all root nodes
|
||||
} // reload()
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
bool GrandPrixData::writeToFile()
|
||||
@@ -165,14 +179,15 @@ bool GrandPrixData::writeToFile()
|
||||
UTFWriter file(m_filename.c_str());
|
||||
if (file.is_open())
|
||||
{
|
||||
file << L"\n<supertuxkart_grand_prix name=\"" << m_name << L"\">\n\n";
|
||||
file << L"\n<supertuxkart_grand_prix name=\"" << m_name
|
||||
<< L"\">\n\n";
|
||||
for (unsigned int i = 0; i < m_tracks.size(); i++)
|
||||
{
|
||||
file <<
|
||||
L"\t<track id=\"" << m_tracks[i] <<
|
||||
L"\" laps=\"" << m_laps[i] <<
|
||||
L"\" reverse=\"" << (m_reversed[i] ? L"true" : L"false") <<
|
||||
L"\" />\n";
|
||||
L"\t<track id=\"" << m_tracks[i] <<
|
||||
L"\" laps=\"" << m_laps[i] <<
|
||||
L"\" reverse=\"" << (m_reversed[i] ? L"true" : L"false")
|
||||
<< L"\" />\n";
|
||||
}
|
||||
file << L"\n</supertuxkart_grand_prix>\n";
|
||||
|
||||
@@ -185,33 +200,32 @@ bool GrandPrixData::writeToFile()
|
||||
}
|
||||
catch (std::runtime_error& e)
|
||||
{
|
||||
Log::error("GrandPrixData", "Failed to write '%s'; cause: %s\n",
|
||||
m_filename.c_str(), e.what());
|
||||
Log::error("GrandPrixData",
|
||||
"Failed to write grand prix to '%s'; cause: %s",
|
||||
m_filename.c_str(), e.what());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
bool GrandPrixData::checkConsistency(bool chatty) const
|
||||
bool GrandPrixData::checkConsistency(bool log_error) const
|
||||
{
|
||||
for (unsigned int i = 0; i<m_tracks.size(); i++)
|
||||
for (unsigned int i = 0; i < m_tracks.size(); i++)
|
||||
{
|
||||
Track* t = track_manager->getTrack(m_tracks[i]);
|
||||
|
||||
if (t == NULL)
|
||||
if (track_manager->getTrack(m_tracks[i]) == NULL)
|
||||
{
|
||||
if (chatty)
|
||||
if (log_error)
|
||||
{
|
||||
Log::error("GrandPrixData", "Grand Prix '%ls': Track '%s' does not exist!\n",
|
||||
m_name.c_str(), m_tracks[i].c_str());
|
||||
Log::error("GrandPrixData", "This Grand Prix will not be available.\n");
|
||||
Log::error("GrandPrixData",
|
||||
"The grand prix '%ls' won't be available because "
|
||||
"the track '%s' does not exist!", m_name.c_str(),
|
||||
m_tracks[i].c_str());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // for i
|
||||
}
|
||||
return true;
|
||||
} // checkConsistency
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -221,15 +235,17 @@ bool GrandPrixData::checkConsistency(bool chatty) const
|
||||
* is unlocked). It also prevents people from using the grand prix editor as
|
||||
* a way to play tracks that still haven't been unlocked
|
||||
*/
|
||||
bool GrandPrixData::isTrackAvailable(const std::string &id, bool includeLocked) const
|
||||
bool GrandPrixData::isTrackAvailable(const std::string &id,
|
||||
bool includeLocked ) const
|
||||
{
|
||||
if (includeLocked)
|
||||
return true;
|
||||
else if (id == "fortmagma")
|
||||
return !PlayerManager::getCurrentPlayer()->isLocked("fortmagma");
|
||||
else
|
||||
return (!m_editable || !PlayerManager::get()->getCurrentPlayer()->isLocked(id));
|
||||
} // isTrackAvailable
|
||||
return (!m_editable ||
|
||||
!PlayerManager::get()->getCurrentPlayer()->isLocked(id));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
std::vector<std::string> GrandPrixData::getTrackNames(bool includeLocked) const
|
||||
@@ -239,9 +255,9 @@ std::vector<std::string> GrandPrixData::getTrackNames(bool includeLocked) const
|
||||
{
|
||||
if(isTrackAvailable(m_tracks[i], includeLocked))
|
||||
names.push_back(m_tracks[i]);
|
||||
} // for i
|
||||
}
|
||||
return names;
|
||||
} // getTrackNames
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
std::vector<int> GrandPrixData::getLaps(bool includeLocked) const
|
||||
@@ -250,8 +266,9 @@ std::vector<int> GrandPrixData::getLaps(bool includeLocked) const
|
||||
for (unsigned int i = 0; i< m_tracks.size(); i++)
|
||||
if(isTrackAvailable(m_tracks[i], includeLocked))
|
||||
laps.push_back(m_laps[i]);
|
||||
|
||||
return laps;
|
||||
} // getLaps
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
std::vector<bool> GrandPrixData::getReverse(bool includeLocked) const
|
||||
@@ -260,14 +277,15 @@ std::vector<bool> GrandPrixData::getReverse(bool includeLocked) const
|
||||
for (unsigned int i = 0; i< m_tracks.size(); i++)
|
||||
if(isTrackAvailable(m_tracks[i], includeLocked))
|
||||
reverse.push_back(m_reversed[i]);
|
||||
|
||||
return reverse;
|
||||
} // getReverse
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
bool GrandPrixData::isEditable() const
|
||||
{
|
||||
return m_editable;
|
||||
} // isEditable
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
unsigned int GrandPrixData::getNumberOfTracks(bool includeLocked) const
|
||||
@@ -334,49 +352,47 @@ void GrandPrixData::moveDown(const unsigned int track)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void GrandPrixData::addTrack(Track* track, unsigned int laps, bool reverse,
|
||||
int position)
|
||||
int position)
|
||||
{
|
||||
int n;
|
||||
|
||||
n = getNumberOfTracks(true);
|
||||
int n = getNumberOfTracks(true);
|
||||
assert (track != NULL);
|
||||
assert (laps > 0);
|
||||
assert (position >= -1 && position < n);
|
||||
assert (-1 < position && position < n);
|
||||
|
||||
if (position < 0 || position == (n - 1) || m_tracks.empty())
|
||||
{
|
||||
//Append new track to the end of the list
|
||||
// Append new track to the end of the list
|
||||
m_tracks.push_back(track->getIdent());
|
||||
m_laps.push_back(laps);
|
||||
m_reversed.push_back(reverse);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Insert new track right after the specified position. Caution:
|
||||
//std::vector inserts elements _before_ the specified position
|
||||
m_tracks.insert(m_tracks.begin() + position + 1, track->getIdent());
|
||||
m_laps.insert(m_laps.begin() + position + 1, laps);
|
||||
m_reversed.insert(m_reversed.begin() + position + 1, reverse);
|
||||
// Insert new track right after the specified position. Caution:
|
||||
// std::vector inserts elements _before_ the specified position
|
||||
m_tracks. insert(m_tracks.begin() + position + 1, track->getIdent());
|
||||
m_laps. insert(m_laps.begin() + position + 1, laps );
|
||||
m_reversed.insert(m_reversed.begin() + position + 1, reverse );
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void GrandPrixData::editTrack(unsigned int t, Track* track,
|
||||
unsigned int laps, bool reverse)
|
||||
void GrandPrixData::editTrack(unsigned int index, Track* track,
|
||||
unsigned int laps, bool reverse)
|
||||
{
|
||||
assert (t < getNumberOfTracks(true));
|
||||
assert (index < getNumberOfTracks(true));
|
||||
assert (track != NULL);
|
||||
assert (laps > 0);
|
||||
|
||||
m_tracks[t] = track->getIdent();
|
||||
m_laps[t] = laps;
|
||||
m_reversed[t] = reverse;
|
||||
m_tracks[index] = track->getIdent();
|
||||
m_laps[index] = laps;
|
||||
m_reversed[index] = reverse;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void GrandPrixData::remove(const unsigned int track)
|
||||
{
|
||||
assert (track < getNumberOfTracks(true));
|
||||
assert (0 < track && track < getNumberOfTracks(true));
|
||||
|
||||
m_tracks.erase(m_tracks.begin() + track);
|
||||
m_laps.erase(m_laps.begin() + track);
|
||||
|
||||
@@ -51,7 +51,7 @@ private:
|
||||
* (ie. 'volcano'). */
|
||||
std::vector<std::string> m_tracks;
|
||||
|
||||
/** The number of laps that each track should be raced, in the right order */
|
||||
/** The number of laps that each track will be raced, in the right order */
|
||||
std::vector<int> m_laps;
|
||||
|
||||
/** Whether the track in question should be done in reverse mode */
|
||||
@@ -69,22 +69,25 @@ private:
|
||||
bool isTrackAvailable(const std::string &id, bool includeLocked) const;
|
||||
|
||||
public:
|
||||
|
||||
/** Load the GrandPrixData from the given filename */
|
||||
#if (defined(WIN32) || defined(_WIN32)) && !defined(__MINGW32__)
|
||||
#pragma warning(disable:4290)
|
||||
# pragma warning(disable:4290)
|
||||
#endif
|
||||
GrandPrixData (const std::string& filename) throw(std::logic_error);
|
||||
GrandPrixData () {}; // empty for initialising
|
||||
/** Load the GrandPrixData from the given filename */
|
||||
GrandPrixData(const std::string& filename);
|
||||
/** Needed for simple creation of an instance of GrandPrixData */
|
||||
GrandPrixData() {};
|
||||
|
||||
// Methods for the GP editor
|
||||
void setId(const std::string& id);
|
||||
void setName(const irr::core::stringw& name);
|
||||
void setFilename(const std::string& filename);
|
||||
void setEditable(const bool editable);
|
||||
/** Load the grand prix from the file set by the constructor or the grand
|
||||
* prix editor */
|
||||
void reload();
|
||||
bool writeToFile();
|
||||
|
||||
bool checkConsistency(bool chatty=true) const;
|
||||
bool checkConsistency(bool log_error=true) const;
|
||||
std::vector<std::string> getTrackNames(const bool includeLocked=false) const;
|
||||
std::vector<int> getLaps(const bool includeLocked=false) const;
|
||||
std::vector<bool> getReverse(const bool includeLocked=false) const;
|
||||
@@ -98,22 +101,22 @@ public:
|
||||
void moveDown(const unsigned int track);
|
||||
void addTrack(Track* track, unsigned int laps,
|
||||
bool reverse, int position=-1);
|
||||
void editTrack(unsigned int t, Track* track,
|
||||
void editTrack(unsigned int index, Track* track,
|
||||
unsigned int laps, bool reverse);
|
||||
void remove(const unsigned int track);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** @return the (potentially translated) user-visible name of the Grand
|
||||
* Prix (apply fribidi as needed) */
|
||||
irr::core::stringw getName() const { return _LTR(m_name.c_str()); }
|
||||
irr::core::stringw getName() const { return _LTR(m_name.c_str()); }
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** @return the internal name identifier of the Grand Prix (not translated) */
|
||||
const std::string& getId() const { return m_id; }
|
||||
/** @return the internal indentifier of the Grand Prix (not translated) */
|
||||
const std::string& getId() const { return m_id; }
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the filename of the grand prix xml file. */
|
||||
const std::string& getFilename() const { return m_filename; }
|
||||
const std::string& getFilename() const { return m_filename; }
|
||||
|
||||
}; // GrandPrixData
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
#include "race/grand_prix_manager.hpp"
|
||||
|
||||
#include "config/user_config.hpp"
|
||||
#include "grand_prix_data.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "race/grand_prix_data.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -36,12 +36,13 @@ void GrandPrixManager::loadFiles()
|
||||
{
|
||||
std::set<std::string> dirs;
|
||||
|
||||
//Add all the directories to a set to avoid duplicates
|
||||
// Add all the directories to a set to avoid duplicates
|
||||
dirs.insert(file_manager->getAsset(FileManager::GRANDPRIX, ""));
|
||||
dirs.insert(file_manager->getGPDir());
|
||||
dirs.insert(UserConfigParams::m_additional_gp_directory);
|
||||
|
||||
for (std::set<std::string>::const_iterator it = dirs.begin(); it != dirs.end(); ++it)
|
||||
for (std::set<std::string>::const_iterator it = dirs.begin();
|
||||
it != dirs.end (); ++it)
|
||||
{
|
||||
std::string dir = *it;
|
||||
if (!dir.empty() && dir[dir.size() - 1] == '/')
|
||||
@@ -52,35 +53,34 @@ void GrandPrixManager::loadFiles()
|
||||
// ----------------------------------------------------------------------------
|
||||
void GrandPrixManager::loadDir(const std::string& dir)
|
||||
{
|
||||
Log::info("GrandPrixManager", "Loading Grand Prix files from %s", dir.c_str());
|
||||
Log::info("GrandPrixManager",
|
||||
"Loading Grand Prix files from %s", dir.c_str());
|
||||
assert(!dir.empty() && dir[dir.size() - 1] == '/');
|
||||
|
||||
// Findout which grand prixs are available and load them
|
||||
// Findout which grand prix are available and load them
|
||||
std::set<std::string> result;
|
||||
file_manager->listFiles(result, dir);
|
||||
for(std::set<std::string>::iterator i = result.begin(); i != result.end(); i++)
|
||||
{
|
||||
for(std::set<std::string>::iterator i = result.begin();
|
||||
i != result.end(); i++)
|
||||
if (StringUtils::hasSuffix(*i, SUFFIX))
|
||||
load(dir + *i);
|
||||
} // for i
|
||||
} // loadDir
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void GrandPrixManager::load(const std::string& filename)
|
||||
{
|
||||
GrandPrixData* gp;
|
||||
|
||||
try
|
||||
{
|
||||
gp = new GrandPrixData(filename);
|
||||
GrandPrixData* gp = new GrandPrixData(filename);
|
||||
m_gp_data.push_back(gp);
|
||||
Log::debug("GrandPrixManager", "Grand Prix '%s' loaded from %s",
|
||||
gp->getId().c_str(), filename.c_str());
|
||||
Log::debug("GrandPrixManager",
|
||||
"Grand Prix '%s' loaded from %s",
|
||||
gp->getId().c_str(), filename.c_str());
|
||||
}
|
||||
catch (std::logic_error& er)
|
||||
catch (std::runtime_error& e)
|
||||
{
|
||||
Log::error("GrandPrixManager", "Ignoring GP %s (%s)\n",
|
||||
filename.c_str(), er.what());
|
||||
Log::error("GrandPrixManager",
|
||||
"Ignoring grand prix %s (%s)\n", filename.c_str(), e.what());
|
||||
}
|
||||
} // load
|
||||
|
||||
@@ -99,44 +99,42 @@ std::string GrandPrixManager::generateId()
|
||||
{
|
||||
std::stringstream s;
|
||||
|
||||
do
|
||||
bool unique = false;
|
||||
while(!unique)
|
||||
{
|
||||
s.clear();
|
||||
s << "usr_gp_" << ((rand() % 90000000) + 10000000);
|
||||
} while (existsId(s.str()));
|
||||
|
||||
// Check if the id already exists
|
||||
unique = true;
|
||||
for (unsigned int i = 0; i < m_gp_data.size(); i++)
|
||||
{
|
||||
if (m_gp_data[i]->getId() == s.str())
|
||||
{
|
||||
unique = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return s.str();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
bool GrandPrixManager::existsId(const std::string& id) const
|
||||
{
|
||||
bool exists;
|
||||
|
||||
exists = false;
|
||||
for (unsigned int i = 0; !exists && i < m_gp_data.size(); i++)
|
||||
exists = (m_gp_data[i]->getId() == id);
|
||||
|
||||
return exists;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
bool GrandPrixManager::existsName(const irr::core::stringw& name) const
|
||||
{
|
||||
bool exists;
|
||||
for (unsigned int i = 0; i < m_gp_data.size(); i++)
|
||||
if (m_gp_data[i]->getName() == name)
|
||||
return true;
|
||||
|
||||
exists = false;
|
||||
for (unsigned int i = 0; !exists && i < m_gp_data.size(); i++)
|
||||
exists = (m_gp_data[i]->getName() == name);
|
||||
|
||||
return exists;
|
||||
return false;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
GrandPrixManager::GrandPrixManager()
|
||||
{
|
||||
loadFiles();
|
||||
} // GrandPrixManager
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
GrandPrixManager::~GrandPrixManager()
|
||||
@@ -144,21 +142,24 @@ GrandPrixManager::~GrandPrixManager()
|
||||
for(unsigned int i=0; i<m_gp_data.size(); i++)
|
||||
{
|
||||
delete m_gp_data[i];
|
||||
} // for i
|
||||
|
||||
} // ~GrandPrixManager
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
const GrandPrixData* GrandPrixManager::getGrandPrix(const std::string& s) const
|
||||
GrandPrixData* GrandPrixManager::getGrandPrix(const std::string& s) const
|
||||
{
|
||||
return editGrandPrix(s);
|
||||
} // getGrandPrix
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
GrandPrixData* GrandPrixManager::editGrandPrix(const std::string& s) const
|
||||
{
|
||||
for(unsigned int i=0; i<m_gp_data.size(); i++)
|
||||
if(m_gp_data[i]->getId()==s) return m_gp_data[i];
|
||||
{
|
||||
if(m_gp_data[i]->getId() == s)
|
||||
return m_gp_data[i];
|
||||
} // for i in m_gp_data
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -177,7 +178,7 @@ void GrandPrixManager::checkConsistency()
|
||||
} // checkConsistency
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
GrandPrixData* GrandPrixManager::createNew(const irr::core::stringw& newName)
|
||||
GrandPrixData* GrandPrixManager::createNewGP(const irr::core::stringw& newName)
|
||||
{
|
||||
if (existsName(newName))
|
||||
return NULL;
|
||||
@@ -197,7 +198,7 @@ GrandPrixData* GrandPrixManager::createNew(const irr::core::stringw& newName)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
GrandPrixData* GrandPrixManager::copy(const std::string& id,
|
||||
const irr::core::stringw& newName)
|
||||
const irr::core::stringw& newName)
|
||||
{
|
||||
if (existsName(newName))
|
||||
return NULL;
|
||||
@@ -228,6 +229,7 @@ void GrandPrixManager::remove(const std::string& id)
|
||||
}
|
||||
else
|
||||
{
|
||||
Log::warn("GrandPrixManager", "Grand Prix '%s' cannot be removed\n", gp->getId().c_str());
|
||||
Log::warn("GrandPrixManager",
|
||||
"Grand Prix '%s' can not be removed", gp->getId().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,30 +32,37 @@ class GrandPrixManager
|
||||
private:
|
||||
static const char* SUFFIX;
|
||||
|
||||
std::vector<GrandPrixData*> m_gp_data;
|
||||
|
||||
/** Load all the grands prix from the 3 directories known */
|
||||
void loadFiles();
|
||||
/** Load all the grands prix in one directory */
|
||||
void loadDir(const std::string& dir);
|
||||
/** Load a grand prix and add it to m_gp_data*/
|
||||
void load(const std::string &filename);
|
||||
|
||||
/** Generates a new unique indentifier for a user defined grand prix */
|
||||
std::string generateId();
|
||||
|
||||
bool existsId(const std::string& id) const;
|
||||
bool existsName(const irr::core::stringw& name) const;
|
||||
|
||||
std::vector<GrandPrixData*> m_gp_data;
|
||||
public:
|
||||
GrandPrixManager();
|
||||
~GrandPrixManager();
|
||||
void reload();
|
||||
const GrandPrixData* getGrandPrix(const int i) const { return m_gp_data[i]; }
|
||||
const GrandPrixData* getGrandPrix(const std::string& s) const;
|
||||
GrandPrixData* editGrandPrix(const std::string& s) const;
|
||||
unsigned int getNumberOfGrandPrix() const { return m_gp_data.size(); }
|
||||
void checkConsistency();
|
||||
GrandPrixManager();
|
||||
~GrandPrixManager();
|
||||
void reload();
|
||||
GrandPrixData* getGrandPrix(const int i) const { return m_gp_data[i]; }
|
||||
GrandPrixData* getGrandPrix(const std::string& s) const;
|
||||
unsigned int getNumberOfGrandPrix() const { return m_gp_data.size(); }
|
||||
void checkConsistency();
|
||||
|
||||
GrandPrixData* createNew(const irr::core::stringw& newName);
|
||||
GrandPrixData* copy(const std::string& id, const irr::core::stringw& newName);
|
||||
void remove(const std::string& id);
|
||||
// Methods for the gp editor
|
||||
GrandPrixData* editGrandPrix(const std::string& s) const;
|
||||
GrandPrixData* createNewGP(const irr::core::stringw& newName);
|
||||
GrandPrixData* copy(const std::string& id,
|
||||
const irr::core::stringw& newName);
|
||||
void remove(const std::string& id);
|
||||
}; // GrandPrixManager
|
||||
|
||||
extern GrandPrixManager *grand_prix_manager;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -272,10 +272,8 @@ void EditGPScreen::setModified(const bool modified)
|
||||
// -----------------------------------------------------------------------------
|
||||
void EditGPScreen::setSelected(const int selected)
|
||||
{
|
||||
IconButtonWidget* button_up = getWidget<IconButtonWidget>("up");
|
||||
assert(button_up != NULL);
|
||||
IconButtonWidget* button_down = getWidget<IconButtonWidget>("down");
|
||||
assert(button_down != NULL);
|
||||
assert(getWidget<IconButtonWidget>("up") != NULL);
|
||||
assert(getWidget<IconButtonWidget>("down") != NULL);
|
||||
|
||||
m_selected = selected;
|
||||
}
|
||||
@@ -307,14 +305,14 @@ bool EditGPScreen::save()
|
||||
else
|
||||
{
|
||||
new MessageDialog(
|
||||
_("An error occurred while trying to save your grand prix"),
|
||||
_("An error occurred while trying to save your grand prix."),
|
||||
MessageDialog::MESSAGE_DIALOG_OK, NULL, false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void EditGPScreen::back ()
|
||||
void EditGPScreen::back()
|
||||
{
|
||||
m_action.clear();
|
||||
m_modified = false;
|
||||
@@ -324,11 +322,11 @@ void EditGPScreen::back ()
|
||||
// -----------------------------------------------------------------------------
|
||||
bool EditGPScreen::canMoveUp() const
|
||||
{
|
||||
return (m_selected > 0 && m_selected < m_list->getItemCount());
|
||||
return (0 < m_selected && m_selected < m_list->getItemCount());
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
bool EditGPScreen::canMoveDown() const
|
||||
{
|
||||
return (m_selected >= 0 && m_selected < (m_list->getItemCount() - 1));
|
||||
return (0 <= m_selected && m_selected < m_list->getItemCount() - 1);
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ void GrandPrixEditorScreen::onNewGPWithName(const stringw& newName)
|
||||
}
|
||||
else if (m_action == "new")
|
||||
{
|
||||
setSelection(grand_prix_manager->createNew(newName));
|
||||
setSelection(grand_prix_manager->createNewGP(newName));
|
||||
}
|
||||
|
||||
loadGPList();
|
||||
|
||||
@@ -68,6 +68,10 @@ void GuestLoginScreen::eventCallback(Widget* widget, const std::string& name,
|
||||
else if(button=="cancel")
|
||||
StateManager::get()->escapePressed();
|
||||
}
|
||||
else if (name == "back")
|
||||
{
|
||||
StateManager::get()->escapePressed();
|
||||
}
|
||||
|
||||
} // eventCallback
|
||||
|
||||
|
||||
@@ -180,6 +180,10 @@ void LoginScreen::eventCallback(Widget* widget, const std::string& name,
|
||||
else if(button=="cancel")
|
||||
StateManager::get()->escapePressed();
|
||||
}
|
||||
else if (name == "back")
|
||||
{
|
||||
StateManager::get()->escapePressed();
|
||||
}
|
||||
|
||||
} // eventCallback
|
||||
|
||||
|
||||
@@ -203,6 +203,10 @@ void RegisterScreen::eventCallback(Widget* widget, const std::string& name,
|
||||
else if(button=="cancel")
|
||||
StateManager::get()->escapePressed();
|
||||
}
|
||||
else if (name == "back")
|
||||
{
|
||||
StateManager::get()->escapePressed();
|
||||
}
|
||||
|
||||
} // eventCallback
|
||||
|
||||
|
||||
@@ -78,6 +78,7 @@ enum DebugMenuCommand
|
||||
DEBUG_ATTACHMENT_BOMB,
|
||||
DEBUG_ATTACHMENT_ANVIL,
|
||||
DEBUG_TOGGLE_GUI,
|
||||
DEBUG_HIDE_KARTS,
|
||||
DEBUG_THROTTLE_FPS,
|
||||
DEBUG_TWEAK_SHADER_EXPOSURE,
|
||||
DEBUG_TWEAK_SHADER_LWHITE
|
||||
@@ -181,10 +182,10 @@ bool onEvent(const SEvent &event)
|
||||
sub->addItem(L"Anvil", DEBUG_ATTACHMENT_ANVIL);
|
||||
sub->addItem(L"Parachute", DEBUG_ATTACHMENT_PARACHUTE);
|
||||
|
||||
mnu->addItem(L"Adjust shaders >", -1, true, true);
|
||||
sub = mnu->getSubMenu(3);
|
||||
sub->addItem(L"Exposure", DEBUG_TWEAK_SHADER_EXPOSURE);
|
||||
sub->addItem(L"LWhite", DEBUG_TWEAK_SHADER_LWHITE);
|
||||
//mnu->addItem(L"Adjust shaders >", -1, true, true);
|
||||
//sub = mnu->getSubMenu(3);
|
||||
//sub->addItem(L"Exposure", DEBUG_TWEAK_SHADER_EXPOSURE);
|
||||
//sub->addItem(L"LWhite", DEBUG_TWEAK_SHADER_LWHITE);
|
||||
|
||||
mnu->addItem(L"Profiler",DEBUG_PROFILER);
|
||||
if (UserConfigParams::m_profiler_enabled)
|
||||
@@ -194,6 +195,7 @@ bool onEvent(const SEvent &event)
|
||||
mnu->addItem(L"Save replay", DEBUG_SAVE_REPLAY);
|
||||
mnu->addItem(L"Save history", DEBUG_SAVE_HISTORY);
|
||||
mnu->addItem(L"Toggle GUI", DEBUG_TOGGLE_GUI);
|
||||
mnu->addItem(L"Hide karts", DEBUG_HIDE_KARTS);
|
||||
|
||||
|
||||
g_debug_menu_visible = true;
|
||||
@@ -393,13 +395,17 @@ bool onEvent(const SEvent &event)
|
||||
if (world == NULL) return false;
|
||||
RaceGUIBase* gui = world->getRaceGUI();
|
||||
if (gui != NULL) gui->m_enabled = !gui->m_enabled;
|
||||
|
||||
}
|
||||
else if (cmdID == DEBUG_HIDE_KARTS)
|
||||
{
|
||||
World* world = World::getWorld();
|
||||
if (world == NULL) return false;
|
||||
const int count = World::getWorld()->getNumKarts();
|
||||
for (int n=0; n<count; n++)
|
||||
for (int n = 0; n<count; n++)
|
||||
{
|
||||
AbstractKart* kart = world->getKart(n);
|
||||
if (kart->getController()->isPlayerController())
|
||||
kart->getNode()->setVisible(gui->m_enabled);
|
||||
kart->getNode()->setVisible(false);
|
||||
}
|
||||
}
|
||||
else if (cmdID == DEBUG_TWEAK_SHADER_EXPOSURE)
|
||||
|
||||
Reference in New Issue
Block a user