Fix wide-string player names (only if irrlicht 1.8 is used)

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@8060 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2011-03-25 15:52:59 +00:00
parent c4660216fd
commit de743669f8
2 changed files with 50 additions and 48 deletions

View File

@ -23,8 +23,51 @@
#include <stdexcept>
using namespace irr;
#if IRRLICHT_VERSION_MAJOR > 1 || (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR >= 8)
// ----------------------------------------------------------------------------
XMLWriter::XMLWriter(const char* dest) : m_base(dest, std::ios::out | std::ios::binary)
{
if (!m_base.is_open())
{
throw std::runtime_error("Failed to open file for writing : " + std::string(dest));
}
// FIXME: make sure to properly handle endianness
wchar_t BOM = 0xFEFF; // UTF-16 BOM is 0xFEFF; UTF-32 BOM is 0x0000FEFF. So this works in either case
m_base.write((char *) &BOM, sizeof(wchar_t));
}
// ----------------------------------------------------------------------------
XMLWriter& XMLWriter::operator<< (const irr::core::stringw& txt)
{
m_base.write((char *) txt.c_str(), txt.size() * sizeof(wchar_t));
return *this;
}
// ----------------------------------------------------------------------------
XMLWriter& XMLWriter::operator<< (const wchar_t*txt)
{
m_base.write((char *) txt, wcslen(txt) * sizeof(wchar_t));
return *this;
}
// ----------------------------------------------------------------------------
void XMLWriter::close()
{
m_base.close();
}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#else // Non-unicode version for irrlicht 1.7 and before
XMLWriter::XMLWriter(const char* dest) : m_base(dest, std::ios::out | std::ios::binary)
{
if (!m_base.is_open())
@ -60,47 +103,4 @@ void XMLWriter::close()
// ----------------------------------------------------------------------------
// UNICODE version below, deactivated until irrlicht devs fix their XML reading bug...
#if 0
// ----------------------------------------------------------------------------
XMLWriter::XMLWriter(const char* dest) : m_base(dest, std::ios::out | std::ios::binary)
{
if (!m_base.is_open())
{
throw std::runtime_error("Failed to open file for writing : " + std::string(dest));
}
// FIXME: make sure the BOM makes sense on platforms where sizeof(wchar_t) is 32 bits
// FIXME: make sure to properly handle endianness
wchar_t BOM = 0xFEFF;
m_base.write((char *) &BOM, sizeof(wchar_t));
}
// ----------------------------------------------------------------------------
XMLWriter& XMLWriter::operator<< (const irr::core::stringw& txt)
{
m_base.write((char *) txt.c_str(), txt.size() * sizeof(wchar_t));
return *this;
}
// ----------------------------------------------------------------------------
XMLWriter& XMLWriter::operator<< (const wchar_t*txt)
{
m_base.write((char *) txt, wcslen(txt) * sizeof(wchar_t));
return *this;
}
// ----------------------------------------------------------------------------
void XMLWriter::close()
{
m_base.close();
}
// ----------------------------------------------------------------------------
#endif

View File

@ -85,7 +85,11 @@ void OptionsScreenPlayers::init()
bool OptionsScreenPlayers::gotNewPlayerName(const stringw& newName, PlayerProfile* player)
{
// FIXME: Using a truncated ASCII string for internal ID. Let's cross our fingers
// and hope no one enters two player names that, when stripped down to ASCII,
// give the same identifier...
stringc newNameC( newName );
ListWidget* players = this->getWidget<ListWidget>("players");
if (players == NULL) return false;
@ -102,20 +106,18 @@ bool OptionsScreenPlayers::gotNewPlayerName(const stringw& newName, PlayerProfil
// add new player
UserConfigParams::m_all_players.push_back( new PlayerProfile(newName) );
players->addItem( newNameC.c_str(), newNameC.c_str() );
players->addItem( newNameC.c_str(), newName );
}
else // ---- Rename existing player
{
player->setName( newNameC.c_str() );
player->setName( newName );
// refresh list display
players->clear();
const int playerAmount = UserConfigParams::m_all_players.size();
for(int n=0; n<playerAmount; n++)
{
// FIXME: encoding issues
players->addItem(core::stringc(UserConfigParams::m_all_players[n].getName().c_str()).c_str(),
UserConfigParams::m_all_players[n].getName());
players->addItem(newNameC.c_str(), UserConfigParams::m_all_players[n].getName());
}
}