Esempio n. 1
0
/*
 * @brief Converts a string into a Ogre UTF string. This is necessary if you need to handle non ascii characters (like accents: ó á and such).
 * @note Source: http://www.ogre3d.org/forums/viewtopic.php?t=32814&highlight=utfstring
 * @param str String to convert
 * @return the converted to UTF string
 */
Ogre::UTFString toUTF( const std::string& str)
{
   Ogre::UTFString UTFString;
   int i;
   Ogre::UTFString::code_point cp;
   for (i=0; i<(int)str.size(); ++i)
   {
      cp = str[i];
      cp &= 0xFF;
      UTFString.append(1, cp);
   }
	return UTFString;
}
	void TextIterator::cutMaxLengthFromBeginning(size_t _max)
	{
		// узнаем размер без тегов
		size_t size = getSize();
		if (size <= _max) return;

		// разница 
		size_t diff = size - _max;

		// последний цвет
		Ogre::UTFString::iterator iter_colour = mEnd;

		// теперь пройдем от начала и узнаем реальную позицию разницы
		Ogre::UTFString::iterator iter=mText.begin();
		for (; iter!=mEnd; ++iter)
		{
			if ((*iter) == L'#')
			{
				Ogre::UTFString::iterator save = iter;

				// следующий символ
				++ iter;
				if (iter == mEnd) break;

				// тэг цвета
				if ((*iter) != L'#')
				{
					// остальные 5 символов цвета
					for (size_t pos=0; pos<5; pos++)
					{
						++ iter;
						if (iter == mEnd)
						{
							-- iter;
							break;
						}
					}
					// сохраняем цвет
					iter_colour = save;
				}
				continue;
			}
			// обычный символ был
			if (diff == 0) break;
			-- diff;
		}

		Ogre::UTFString colour;
		// если бы цвет, то вставляем назад
		if (iter_colour != mEnd)
		{
			colour.append(iter_colour, iter_colour + size_t(7));
		}

		mCurrent = erase(mText.begin(), iter);
		mEnd = mText.end();
		mSave = mText.end(); //FIXME
		mPosition = 0;
		mSize = _max;

		if ( ! colour.empty() ) setTagColour(colour);

	}
void CLASS::UpdateControls(CacheEntry *entry)
{
	Ogre::String outBasename = "";
	Ogre::String outPath = "";
	Ogre::StringUtil::splitFilename(entry->filecachename, outBasename, outPath);

	SetPreviewImage(outBasename);

	if (entry->sectionconfigs.size())
	{
		m_Config->setVisible(true);
		m_Config->removeAllItems();
		for (std::vector<Ogre::String>::iterator its = entry->sectionconfigs.begin(); its != entry->sectionconfigs.end(); its++)
		{
			try
			{
				m_Config->addItem(*its, *its);
			}
			catch (...)
			{
				m_Config->addItem("ENCODING ERROR", *its);
			}
		}
		m_Config->setIndexSelected(0);

		m_vehicle_configs.clear();
		Ogre::String configstr = *m_Config->getItemDataAt<Ogre::String>(0);
		m_vehicle_configs.push_back(configstr);
	}
	else
	{
		m_Config->setVisible(false);
	}
	Ogre::UTFString authors = "";
	std::set<Ogre::String> author_names;
	for (auto it = entry->authors.begin(); it != entry->authors.end(); it++)
	{
		if (!it->type.empty() && !it->name.empty())
		{
			Ogre::String name = it->name;
			Ogre::StringUtil::trim(name);
			author_names.insert(name);
		}
	}
	for (std::set<Ogre::String>::iterator it = author_names.begin(); it != author_names.end(); it++)
	{
		Ogre::UTFString name = ANSI_TO_UTF(*it);
		authors.append(U(" ") + name);
	}
	if (authors.length() == 0)
	{
		authors = _L("no author information available");
	}

	try
	{
		m_EntryName->setCaption(convertToMyGUIString(ANSI_TO_UTF(entry->dname)));
	}
	catch (...)
	{
		m_EntryName->setCaption("ENCODING ERROR");
	}

	Ogre::UTFString c = U("#FF7D02"); // colour key shortcut
	Ogre::UTFString nc = U("#FFFFFF"); // colour key shortcut

	Ogre::UTFString newline = U("\n");

	Ogre::UTFString descriptiontxt = U("#66FF33") + ANSI_TO_UTF(entry->description) + nc + newline;

	descriptiontxt = descriptiontxt + _L("Author(s): ") + c + authors + nc + newline;


	if (entry->version > 0)           descriptiontxt = descriptiontxt + _L("Version: ") + c + TOUTFSTRING(entry->version) + nc + newline;
	if (entry->wheelcount > 0)        descriptiontxt = descriptiontxt + _L("Wheels: ") + c + TOUTFSTRING(entry->wheelcount) + U("x") + TOUTFSTRING(entry->propwheelcount) + nc + newline;
	if (entry->truckmass > 0)         descriptiontxt = descriptiontxt + _L("Mass: ") + c + TOUTFSTRING((int)(entry->truckmass / 1000.0f)) + U(" ") + _L("tons") + nc + newline;
	if (entry->loadmass > 0)          descriptiontxt = descriptiontxt + _L("Load Mass: ") + c + TOUTFSTRING((int)(entry->loadmass / 1000.0f)) + U(" ") + _L("tons") + nc + newline;
	if (entry->nodecount > 0)         descriptiontxt = descriptiontxt + _L("Nodes: ") + c + TOUTFSTRING(entry->nodecount) + nc + newline;
	if (entry->beamcount > 0)         descriptiontxt = descriptiontxt + _L("Beams: ") + c + TOUTFSTRING(entry->beamcount) + nc + newline;
	if (entry->shockcount > 0)        descriptiontxt = descriptiontxt + _L("Shocks: ") + c + TOUTFSTRING(entry->shockcount) + nc + newline;
	if (entry->hydroscount > 0)       descriptiontxt = descriptiontxt + _L("Hydros: ") + c + TOUTFSTRING(entry->hydroscount) + nc + newline;
	if (entry->soundsourcescount > 0) descriptiontxt = descriptiontxt + _L("SoundSources: ") + c + TOUTFSTRING(entry->soundsourcescount) + nc + newline;
	if (entry->commandscount > 0)     descriptiontxt = descriptiontxt + _L("Commands: ") + c + TOUTFSTRING(entry->commandscount) + nc + newline;
	if (entry->rotatorscount > 0)     descriptiontxt = descriptiontxt + _L("Rotators: ") + c + TOUTFSTRING(entry->rotatorscount) + nc + newline;
	if (entry->exhaustscount > 0)     descriptiontxt = descriptiontxt + _L("Exhausts: ") + c + TOUTFSTRING(entry->exhaustscount) + nc + newline;
	if (entry->flarescount > 0)       descriptiontxt = descriptiontxt + _L("Flares: ") + c + TOUTFSTRING(entry->flarescount) + nc + newline;
	if (entry->torque > 0)            descriptiontxt = descriptiontxt + _L("Torque: ") + c + TOUTFSTRING(entry->torque) + nc + newline;
	if (entry->flexbodiescount > 0)   descriptiontxt = descriptiontxt + _L("Flexbodies: ") + c + TOUTFSTRING(entry->flexbodiescount) + nc + newline;
	if (entry->propscount > 0)        descriptiontxt = descriptiontxt + _L("Props: ") + c + TOUTFSTRING(entry->propscount) + nc + newline;
	if (entry->wingscount > 0)        descriptiontxt = descriptiontxt + _L("Wings: ") + c + TOUTFSTRING(entry->wingscount) + nc + newline;
	if (entry->hasSubmeshs)           descriptiontxt = descriptiontxt + _L("Using Submeshs: ") + c + TOUTFSTRING(entry->hasSubmeshs) + nc + newline;
	if (entry->numgears > 0)          descriptiontxt = descriptiontxt + _L("Transmission Gear Count: ") + c + TOUTFSTRING(entry->numgears) + nc + newline;
	if (entry->minrpm > 0)            descriptiontxt = descriptiontxt + _L("Engine RPM: ") + c + TOUTFSTRING(entry->minrpm) + U(" - ") + TOUTFSTRING(entry->maxrpm) + nc + newline;
	if (!entry->uniqueid.empty() && entry->uniqueid != "no-uid") descriptiontxt = descriptiontxt + _L("Unique ID: ") + c + entry->uniqueid + nc + newline;
	if (!entry->guid.empty() && entry->guid != "no-guid")		descriptiontxt = descriptiontxt + _L("GUID: ") + c + entry->guid + nc + newline;
	if (entry->usagecounter > 0)      descriptiontxt = descriptiontxt + _L("Times used: ") + c + TOUTFSTRING(entry->usagecounter) + nc + newline;

	if (entry->addtimestamp > 0)
	{
		char tmp[255] = "";
		time_t epch = entry->addtimestamp;
		sprintf(tmp, "%s", asctime(gmtime(&epch)));
		descriptiontxt = descriptiontxt + _L("Date and Time installed: ") + c + Ogre::String(tmp) + nc + newline;
	}

	Ogre::UTFString driveableStr[5] = { _L("Non-Driveable"), _L("Truck"), _L("Airplane"), _L("Boat"), _L("Machine") };
	if (entry->nodecount > 0) descriptiontxt = descriptiontxt + _L("Vehicle Type: ") + c + driveableStr[entry->driveable] + nc + newline;

	descriptiontxt = descriptiontxt + "#FF0000\n"; // red colour for the props

	if (entry->forwardcommands) descriptiontxt = descriptiontxt + _L("[forwards commands]") + newline;
	if (entry->importcommands) descriptiontxt = descriptiontxt + _L("[imports commands]") + newline;
	if (entry->rollon) descriptiontxt = descriptiontxt + _L("[is rollon]") + newline;
	if (entry->rescuer) descriptiontxt = descriptiontxt + _L("[is rescuer]") + newline;
	if (entry->custom_particles) descriptiontxt = descriptiontxt + _L("[uses custom particles]") + newline;
	if (entry->fixescount > 0) descriptiontxt = descriptiontxt + _L("[has fixes]") + newline;
	// t is the default, do not display it
	//if (entry->enginetype == 't') descriptiontxt = descriptiontxt +_L("[TRUCK ENGINE]") + newline;
	if (entry->enginetype == 'c') descriptiontxt = descriptiontxt + _L("[car engine]") + newline;
	if (entry->type == "Zip") descriptiontxt = descriptiontxt + _L("[zip archive]") + newline;
	if (entry->type == "FileSystem") descriptiontxt = descriptiontxt + _L("[unpacked in directory]") + newline;

	descriptiontxt = descriptiontxt + "#66CCFF\n"; // now blue-ish color*

	if (!entry->dirname.empty()) descriptiontxt = descriptiontxt + _L("Source: ") + entry->dirname + newline;
	if (!entry->fname.empty()) descriptiontxt = descriptiontxt + _L("Filename: ") + entry->fname + newline;
	if (!entry->hash.empty() && entry->hash != "none") descriptiontxt = descriptiontxt + _L("Hash: ") + entry->hash + newline;
	if (!entry->hash.empty()) descriptiontxt = descriptiontxt + _L("Mod Number: ") + TOUTFSTRING(entry->number) + newline;

	if (!entry->sectionconfigs.empty())
	{
		descriptiontxt = descriptiontxt + U("\n\n#e10000") + _L("Please select a configuration below!") + nc + U("\n\n");
	}

	trimUTFString(descriptiontxt);

	m_EntryDescription->setCaption(convertToMyGUIString(descriptiontxt));
}