コード例 #1
0
void SendPrivateChat(int target_uid, Ogre::UTFString chatline, Ogre::UTFString target_username)
{
#ifdef USE_SOCKETW
	char buffer[MAX_MESSAGE_LENGTH] = {0};
	
	const char *chat_msg = (const char *)chatline.asUTF8_c_str();

	// format: int of UID, then chat message
	memcpy(buffer, &target_uid, sizeof(int));
	strncpy(buffer + sizeof(int), chat_msg, MAX_MESSAGE_LENGTH - sizeof(int));

	size_t len = sizeof(int) + chatline.size() * sizeof(wchar_t);
	buffer[len] = 0;

	RoR::Networking::AddPacket(m_stream_id, MSG2_UTF_PRIVCHAT, (unsigned int)len, buffer);

	if (target_username.empty())
	{
		user_info_t user;
		if (RoR::Networking::GetUserInfo(target_uid, user))
		{
			target_username = GetColouredName(user.username, user.colournum);
		}
	}

	// add local visual
	Ogre::UTFString local_username = GetColouredName(RoR::Networking::GetUsername(), RoR::Networking::GetUserColor());
	Ogre::UTFString nmsg = local_username + RoR::Color::WhisperColour + _L(" [whispered to ") + RoR::Color::NormalColour + target_username + RoR::Color::WhisperColour + "]" + RoR::Color::NormalColour + ": " + chatline;
#ifdef USE_MYGUI
	RoR::Application::GetGuiManager()->pushMessageChatBox(nmsg);
#endif // USE_MYGUI
#endif // USE_SOCKETW
}
コード例 #2
0
ファイル: ChatSystem.cpp プロジェクト: Winceros/main
void ChatSystem::sendPrivateChat(int target_uid, Ogre::UTFString chatline, Ogre::UTFString username)
{
#ifdef USE_SOCKETW
	char buffer[MAX_MESSAGE_LENGTH] = "";
	
	const char *chat_msg = (const char *)chatline.asUTF8_c_str();

	// format: int of UID, then chat message
	memcpy(buffer, &target_uid, sizeof(int));
	strncpy(buffer + sizeof(int), chat_msg, MAX_MESSAGE_LENGTH - sizeof(int));

	size_t len = sizeof(int) + chatline.size() * sizeof(wchar_t);
	buffer[len] = 0;

	this->addPacket(MSG2_UTF_PRIVCHAT, (unsigned int)len, buffer);

	if(username.empty())
	{
		client_t *c = net->getClientInfo(target_uid);
		if(c) username = getColouredName(*c);
	}

	// add local visual
#ifdef USE_MYGUI
	UTFString nmsg = net->getNickname(true) + normalColour + whisperColour + _L(" [whispered to ") + normalColour + username + whisperColour + "]" + normalColour + ": " + chatline;
	Console::getInstance().putMessage(Console::CONSOLE_MSGTYPE_NETWORK, Console::CONSOLE_LOCAL_CHAT, nmsg, "script_key.png");
#endif // USE_MYGUI
#endif // USE_SOCKETW
}
コード例 #3
0
ファイル: utils.cpp プロジェクト: Winceros/main
void trimUTFString( Ogre::UTFString &str, bool left, bool right)
{
	static const String delims = " \t\r";
	if(right)
		str.erase(str.find_last_not_of(delims)+1); // trim right
	if(left)
		str.erase(0, str.find_first_not_of(delims)); // trim left
}
コード例 #4
0
ファイル: GameRootLinux.cpp プロジェクト: 9981juhehua/Hardwar
bool GameRootLinux::isLocked()
{
    Ogre::UTFString homeDir = this->getHomeDirectory();

    // check if the folder exists otherwise create it
    if (opendir(homeDir.asUTF8_c_str()) == nullptr)
    {
        if (mkdir(homeDir.asUTF8_c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
        {
            OGRE_EXCEPT(Ogre::Exception::ERR_INVALID_STATE, "Can not create folder in home directory", "GameRootLinux::isLocked");
        }
    }

    homeDir = homeDir+Ogre::UTFString("/pid");

    std::fstream runfile;
    char* buf;
    int len, pid;
    runfile.open(homeDir.asUTF8_c_str(), std::fstream::in | std::fstream::out | std::fstream::app);

    // No file, game not running
    if (!runfile.is_open())
        return false;

    runfile.seekg (0, std::ios::end);
    len = runfile.tellg();
    runfile.seekg (0, std::ios::beg);

    if (len > 20)
    {
        // should only store a number         
        runfile.close();
        return true;
    }
    buf = OGRE_NEW char[len];
    runfile.read(buf,len);
    runfile.close();

    pid = atoi(buf);

    OGRE_DELETE buf;
    buf = 0;

    if (pid < 1)
        return false;

    Ogre::String proc = "/proc/"+Ogre::StringConverter::toString(pid)+"/status";
    runfile.open(proc.c_str(), std::fstream::in);

    // No file, game not running
    if (!runfile.is_open())
        return false;

    runfile.close();
    return true;
}
コード例 #5
0
ファイル: GameRootLinux.cpp プロジェクト: 9981juhehua/Hardwar
Ogre::UTFString GameRootLinux::getHomeDirectory()
{
    Ogre::UTFString homeDir;
    homeDir = Ogre::UTFString(getenv("HOME"));
    if (homeDir.empty())
    {
        struct passwd *pw = getpwuid(getuid());
        homeDir = Ogre::UTFString(pw->pw_dir);
    }
    return homeDir + Ogre::UTFString("/.hardwar");
}
コード例 #6
0
	void TextIterator::clearNewLine(Ogre::UTFString & _text)
	{
		for (Ogre::UTFString::iterator iter=_text.begin(); iter!=_text.end(); ++iter) {
			if ( ((*iter) == Font::FONT_CODE_NEL) ||
				((*iter) == Font::FONT_CODE_CR) ||
				((*iter) == Font::FONT_CODE_LF) )
			{
				(*iter) = Font::FONT_CODE_SPACE;
			}
		}
	}
コード例 #7
0
ファイル: eString.cpp プロジェクト: sroske/Cing
/*
 * @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;
}
コード例 #8
0
ファイル: GameRootLinux.cpp プロジェクト: 9981juhehua/Hardwar
void GameRootLinux::setLocked(const bool& locked)
{
    Ogre::UTFString homeDir = this->getHomeDirectory() + Ogre::UTFString("/pid");
    std::fstream runfile;
    std::string buf;

    remove(homeDir.asUTF8_c_str());
    if (locked)
    {
        buf = Ogre::String(Ogre::StringConverter::toString(getpid()));
        runfile.open(homeDir.asUTF8_c_str(), std::fstream::in | std::fstream::out | std::fstream::app);
        runfile.write(buf.c_str(),buf.size());
        runfile.close();
    }
}
コード例 #9
0
	bool TextIterator::setTagColour(Ogre::UTFString _colour)
	{
		if (mCurrent == mEnd) return false;
		// очищаем все цвета
		clearTagColour();
		// на всякий
		if (mCurrent == mEnd) return false;

		// проверяем на цвет хоть чуть чуть
		if ( (_colour.size() != 7) || (_colour.find(L'#', 1) != _colour.npos) ) return false;

		// непосредственная вставка
		insert(mCurrent, _colour);

		return true;
	}
コード例 #10
0
bool EditorFrameHandler::SelectObject(Ogre::UTFString name)
{
	MyGUI::Gui *gui = GUISystem::GetInstance()->GetGui();
	if (ObjectDescription)
	{
		//ObjectDescription->Hide();
		//gui->destroyWidget(ObjectDescription.get());
		ObjectDescription->Destroy();		
	}
	if (SelectedObjectName == name || name.empty())
	{
		delete ObjectDescription;
		ObjectDescription = NULL;
		return false;
	}

	std::map<Ogre::UTFString, SEditableDescription>::iterator iRes = EditorNodes.find(name);
	assert(EditorNodes.end()!=iRes);
	if (EditorNodes.end()!=iRes)
	{
		SelectedObjectName = name;
		SelectedObject = &iRes->second;
		ObjectDescription = new ObjectDescriptionLayout("EditorObjectOptions.layout");
		ObjectDescription->Load();
		ObjectDescription->Parse(SelectedObject->EditElement);
		ObjectDescription->Show();
	}
	return true;
}
コード例 #11
0
void SendChat(Ogre::UTFString chatline)
{
#ifdef USE_SOCKETW
	const char *utf8_line = chatline.asUTF8_c_str();
	RoR::Networking::AddPacket(m_stream_id, MSG2_UTF_CHAT, (unsigned int)strlen(utf8_line), (char *)utf8_line);
#endif // USE_SOCKETW
}
コード例 #12
0
	void TextIterator::insert(Ogre::UTFString::iterator & _start, Ogre::UTFString & _insert)
	{
		// сбрасываем размер
		mSize = ITEM_NONE;
		// записываем в историю
		if (mHistory) mHistory->push_back(TextCommandInfo(_insert, _start-mText.begin(), TextCommandInfo::COMMAND_INSERT));
		// запоминаем позицию итератора
		size_t pos = _start - mText.begin();
		size_t pos_save = (mSave==mEnd) ? ITEM_NONE : _start - mText.begin();
		// непосредственно вставляем
		mText.insert(_start, _insert.begin(), _insert.end());
		// возвращаем итераторы
		_start = mText.begin() + pos;
		mEnd = mText.end();
		(pos_save==ITEM_NONE) ? mSave = mEnd : mSave = mText.begin() + pos_save;
	}
コード例 #13
0
ファイル: Character.cpp プロジェクト: Speciesx/rigs-of-rods
// Helper function
void Character::ReportError(const char* detail)
{
#ifdef USE_SOCKETW
    Ogre::UTFString username;
    RoRnet::UserInfo info;
    if (!RoR::Networking::GetUserInfo(m_source_id, info))
        username = "******";
    else
        username = info.username;

    char msg_buf[300];
    snprintf(msg_buf, 300,
        "[RoR|Networking] ERROR on m_is_remote character (User: '******', SourceID: %d, StreamID: %d): ",
        username.asUTF8_c_str(), m_source_id, m_stream_id);

    LOGSTREAM << msg_buf << detail;
#endif
}
コード例 #14
0
Ogre::UTFString GetColouredName(Ogre::UTFString nick, int colour_number)
{
	Ogre::ColourValue col_val = PlayerColours::getSingleton().getColour(colour_number);
	char tmp[255] = {0};
	sprintf(tmp, "#%02X%02X%02X", (unsigned int)(col_val.r * 255.0f), (unsigned int)(col_val.g * 255.0f), (unsigned int)(col_val.b * 255.0f));

	// replace # with X in nickname so the user cannot fake the colour
	for (unsigned int i=0; i<nick.size(); i++)
		if (nick[i] == '#') nick[i] = 'X';

	return tryConvertUTF(tmp) + nick;
}
コード例 #15
0
	void MultiList::flipList()
	{

		if (ITEM_NONE == mSortColumnIndex) return;

		size_t end = mVectorColumnInfo.front().list->getItemCount();
		if (0 == end) return;
		end --;
		size_t start = 0;

		Ogre::UTFString tmp;
		tmp.reserve(64);
		size_t index1, index2;

		VectorSizeT vec;
		size_t size2 = mToSortIndex.size();
		vec.resize(size2);
		for (size_t pos=0; pos<size2; ++pos) vec[mToSortIndex[pos]] = pos;

		while (start < end) {

			for (VectorColumnInfo::iterator iter=mVectorColumnInfo.begin(); iter!=mVectorColumnInfo.end(); ++iter) {
				tmp = (*iter).list->getItem(start);
				(*iter).list->setItem(start, (*iter).list->getItem(end));
				(*iter).list->setItem(end, tmp);
			}

			index1 = vec[start];
			index2 = vec[end];

			mToSortIndex[index1] = mToSortIndex[index2];
			mToSortIndex[index2] = start;

			vec[start] = vec[end];
			vec[end] = index1;

			start++;
			end--;
		}
	}
コード例 #16
0
	// возвращает текст без тегов
	Ogre::UTFString TextIterator::getOnlyText(const Ogre::UTFString& _text)
	{
		Ogre::UTFString ret;
		ret.reserve(_text.size());

		Ogre::UTFString::const_iterator end = _text.end();
		for (Ogre::UTFString::const_iterator iter=_text.begin(); iter!=end; ++iter) {

			if ((*iter) == L'#') {
				// следующий символ
				++ iter;
				if (iter == end) break;

				// тэг цвета
				if ((*iter) != L'#') {
					// остальные 5 символов цвета
					for (size_t pos=0; pos<5; pos++) {
						++ iter;
						if (iter == end) {
							--iter;
							break;
						}
					}
					continue;
				}
			}

			// обыкновенный символ
			ret.push_back(*iter);
		}

		return ret;
	}
コード例 #17
0
ファイル: errorutils.cpp プロジェクト: Winceros/main
int showOgreWebError(Ogre::UTFString title, Ogre::UTFString err, Ogre::UTFString url)
{
#ifndef NOOGRE
    // this only works in non-embedded mode
    // make no sense in embedded mode anyways ...

    storederror = true;
    stored_title = title;
    stored_err = err;
    stored_url = url;

    RigsOfRods *ror = RigsOfRods::getSingletonPtr();
    if(ror) ror->tryShutdown();

#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
    printf("\n\n%s: %s / url: %s\n\n", title.asUTF8_c_str(), err.asUTF8_c_str(), url.asUTF8_c_str());
#endif
    return 0;
#else
    return showWebError(Ogre::UTFString("Rigs of Rods: ") + title, err, url);
#endif //NOOGRE
}
コード例 #18
0
void CLASS::eventCommandAccept(MyGUI::Edit* _sender)
{
	Ogre::UTFString msg = convertFromMyGUIString(_sender->getCaption());
	isTyping = false;
	_sender->setCaption("");

	if (autoHide)
		_sender->setEnabled(false);

	if (msg.empty())
	{
		// discard the empty message
		return;
	}

	if (msg[0] == '/' || msg[0] == '\\')
	{
		Ogre::StringVector args = Ogre::StringUtil::split(msg, " ");
		if (args[0] == "/whisper")
		{
			if (args.size() != 3)
			{
				pushMsg("usage: /whisper username message");
				return;
			}
			netChat->sendPrivateChat(args[1], args[2]);
			return;
		}
	}

	if (gEnv->network && netChat)
	{
		netChat->sendChat(msg.c_str());
		return;
	}

	//MyGUI::InputManager::getInstance().resetKeyFocusWidget();
	RoR::Application::GetGuiManager()->UnfocusGui();
}
コード例 #19
0
ファイル: ChatSystem.cpp プロジェクト: jirijunek/rigs-of-rods
Ogre::UTFString GetColouredName(Ogre::UTFString nick, int colour_number)
{
#ifdef USE_SOCKETW
    Ogre::ColourValue col_val = Networking::GetPlayerColor(colour_number);
    char tmp[255] = {0};
    sprintf(tmp, "#%02X%02X%02X", (unsigned int)(col_val.r * 255.0f), (unsigned int)(col_val.g * 255.0f), (unsigned int)(col_val.b * 255.0f));

    // replace # with X in nickname so the user cannot fake the colour
    for (unsigned int i = 0; i < nick.size(); i++)
        if (nick[i] == '#')
            nick[i] = 'X';

    return tryConvertUTF(tmp) + nick;
#else // USE_SOCKETW
    return nick;
#endif // USE_SOCKETW
}
コード例 #20
0
ファイル: errorutils.cpp プロジェクト: Winceros/main
int showWebError(Ogre::UTFString title, Ogre::UTFString err, Ogre::UTFString url)
{
    // NO logmanager use, because it could be that its not initialized yet!
    //LOG("web message box: " + title + ": " + err + " / url: " + url);
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
    Ogre::UTFString additional = _L("\n\nYou can eventually get help here:\n\n") + url + _L("\n\nDo you want to open that address in your default browser now?");
    err = err + additional;
    int Response = MessageBoxW( NULL, err.asWStr_c_str(), title.asWStr_c_str(), MB_YESNO | MB_ICONERROR | MB_TOPMOST | MB_SYSTEMMODAL | MB_SETFOREGROUND );
    // 6 (IDYES) = yes, 7 (IDNO) = no
    if(Response == IDYES)
    {
        // Microsoft conversion hell follows :|
        wchar_t *command = L"open";
        ShellExecuteW(NULL, command, url.asWStr_c_str(), NULL, NULL, SW_SHOWNORMAL);
    }
#elif OGRE_PLATFORM == OGRE_PLATFORM_LINUX
    printf("\n\n%s: %s / url: %s\n\n", title.asUTF8_c_str(), err.asUTF8_c_str(), url.asUTF8_c_str());
#elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE
    printf("\n\n%s: %s / url: %s\n\n", title.asUTF8_c_str(), err.asUTF8_c_str(), url.asUTF8_c_str());
    //CFOptionFlags flgs;
    //CFUserNotificationDisplayAlert(0, kCFUserNotificationStopAlertLevel, NULL, NULL, NULL, "An exception has occured!", err.c_str(), NULL, NULL, NULL, &flgs);
#endif
    return 0;
}
コード例 #21
0
ファイル: errorutils.cpp プロジェクト: Winceros/main
int showMsgBox(Ogre::UTFString title, Ogre::UTFString err, int type)
{
    // we might call the showMsgBox without having ogre created yet!
    //LOG("message box: " + title + ": " + err);
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
    int mtype = MB_ICONERROR;
    if(type == 1) mtype = MB_ICONINFORMATION;
    MessageBoxW( NULL, err.asWStr_c_str(), title.asWStr_c_str(), MB_OK | mtype | MB_TOPMOST);
#elif OGRE_PLATFORM == OGRE_PLATFORM_LINUX
    printf("\n\n%s: %s\n\n", title.asUTF8_c_str(), err.asUTF8_c_str());
#elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE
    printf("\n\n%s: %s\n\n", title.asUTF8_c_str(), err.asUTF8_c_str());
    //CFOptionFlags flgs;
    //CFUserNotificationDisplayAlert(0, kCFUserNotificationStopAlertLevel, NULL, NULL, NULL, T("A network error occured"), T("Bad server port."), NULL, NULL, NULL, &flgs);
#endif
    return 0;
}
コード例 #22
0
ファイル: ChatSystem.cpp プロジェクト: Winceros/main
Ogre::UTFString ChatSystem::getColouredName(Ogre::UTFString nick, int auth, int colourNumber)
{
	Ogre::ColourValue col_val = PlayerColours::getSingleton().getColour(colourNumber);
	char tmp[255] = "";
	sprintf(tmp, "#%02X%02X%02X", (unsigned int)(col_val.r * 255.0f), (unsigned int)(col_val.g * 255.0f), (unsigned int)(col_val.b * 255.0f));

	// replace # with X in nickname so the user cannot fake the colour
	for(unsigned int i=0; i<nick.size(); i++)
		if(nick[i] == '#') nick[i] = 'X';

	return tryConvertUTF(tmp) + nick;

#if 0
	// old code: colour not depending on auth status anymore ...

	if(auth == AUTH_NONE)  col = "#c9c9c9"; // grey
	if(auth & AUTH_BOT )   col = "#0000c9"; // blue
	if(auth & AUTH_RANKED) col = "#00c900"; // green
	if(auth & AUTH_MOD)    col = "#c90000"; // red
	if(auth & AUTH_ADMIN)  col = "#c97100"; // orange

	return col + nick;
#endif //0
}
コード例 #23
0
ファイル: ChatSystem.cpp プロジェクト: Winceros/main
void ChatSystem::sendChat(Ogre::UTFString chatline)
{
	const char *utf8_line = chatline.asUTF8_c_str();
	this->addPacket(MSG2_UTF_CHAT, (unsigned int)strlen(utf8_line), (char *)utf8_line);
}
コード例 #24
0
void CLASS::UpdateStats(float dt, Beam *truck)
{
	if (!MAIN_WIDGET->getVisible()) return;

	if (b_fpsbox)
	{
		const Ogre::RenderTarget::FrameStats& stats = Application::GetOgreSubsystem()->GetRenderWindow()->getStatistics();
		m_cur_fps->setCaptionWithReplacing("Current FPS: " + Ogre::StringConverter::toString(stats.lastFPS));
		m_avg_fps->setCaptionWithReplacing("Average FPS: " + Ogre::StringConverter::toString(stats.avgFPS));
		m_worst_fps->setCaptionWithReplacing("Worst FPS: " + Ogre::StringConverter::toString(stats.worstFPS));
		m_best_fps->setCaptionWithReplacing("Best FPS: " + Ogre::StringConverter::toString(stats.bestFPS));
		m_triangle_count->setCaptionWithReplacing("Triangle count: " + Ogre::StringConverter::toString(stats.triangleCount));
		m_batch_count->setCaptionWithReplacing("Batch count: " + Ogre::StringConverter::toString(stats.batchCount));
	}
	else
		m_fpscounter_box->setVisible(false);

	if (b_truckinfo && truck != nullptr)
	{
		m_truck_name->setCaptionWithReplacing(truck->getTruckName());
		truckstats = "\n"; //always reset on each frame + space

		//taken from TruckHUD.cpp, needs cleanup
		beam_t *beam = truck->getBeams();
		float average_deformation = 0.0f;
		float beamstress = 0.0f;
		float current_deformation = 0.0f;
		float mass = truck->getTotalMass();
		int beamCount = truck->getBeamCount();
		int beambroken = 0;
		int beamdeformed = 0;

		for (int i = 0; i < beamCount; i++, beam++)
		{
			if (beam->broken != 0)
			{
				beambroken++;
			}
			beamstress += beam->stress;
			current_deformation = fabs(beam->L - beam->refL);
			if (fabs(current_deformation) > 0.0001f && beam->type != BEAM_HYDRO && beam->type != BEAM_INVISIBLE_HYDRO)
			{
				beamdeformed++;
			}
			average_deformation += current_deformation;
		}


		float health = ((float)beambroken / (float)beamCount) * 10.0f + ((float)beamdeformed / (float)beamCount);
		if (health < 1.0f)
		{
			truckstats = truckstats + MainThemeColor + "Vehicle's health: " + WhiteColor + TOUTFSTRING(Round((1.0f - health) * 100.0f, 2)) + U("%") + "\n";
		}
		else if (health >= 1.0f)
		{
			//When this condition is true, it means that health is at 0% which means 100% of destruction.
			truckstats = truckstats + MainThemeColor + "Vehicle's destruction: " + WhiteColor + U("100%") + "\n";
		}

		truckstats = truckstats + MainThemeColor + "Beam count: " + WhiteColor + TOUTFSTRING(beamCount) + "\n";
		truckstats = truckstats + MainThemeColor + "Broken Beams count: " + WhiteColor + TOUTFSTRING(beambroken) + U(" (") + TOUTFSTRING(Round((float)beambroken / (float)beamCount, 2) * 100.0f) + U("%)") + "\n";
		truckstats = truckstats + MainThemeColor + "Deformed Beams count: " + WhiteColor + TOUTFSTRING(beamdeformed) + U(" (") + TOUTFSTRING(Round((float)beamdeformed / (float)beamCount, 2) * 100.0f) + U("%)") + "\n";
		truckstats = truckstats + MainThemeColor + "Average Deformation: " + WhiteColor + TOUTFSTRING(Round((float)average_deformation / (float)beamCount, 4) * 100.0f) + "\n";

		//Taken from TruckHUD.cpp ..
		wchar_t beamstressstr[256];
		swprintf(beamstressstr, 256, L"%+08.0f", 1 - (float)beamstress / (float)beamCount);
		truckstats = truckstats + MainThemeColor + "Average Stress: " + WhiteColor + Ogre::UTFString(beamstressstr) + "\n";

		truckstats = truckstats + "\n"; //Some space

		int ncount = truck->getNodeCount();
		int wcount = truck->getWheelNodeCount();
		wchar_t nodecountstr[256];
		swprintf(nodecountstr, 256, L"%d (wheels: %d)", ncount, wcount);
		truckstats = truckstats + MainThemeColor + "Node count: " + WhiteColor + Ogre::UTFString(nodecountstr) + "\n";

		wchar_t truckmassstr[256];
		Ogre::UTFString massstr;
		swprintf(truckmassstr, 256, L"%ls %8.2f kg (%.2f tons)", massstr.asWStr_c_str(), mass, mass / 1000.0f);
		truckstats = truckstats + MainThemeColor + "Total mass: " + WhiteColor + Ogre::UTFString(truckmassstr) + "\n";

		truckstats = truckstats + "\n"; //Some space

		if (truck->driveable == TRUCK && truck->engine)
		{
			if (truck->engine->getRPM() > truck->engine->getMaxRPM())
				truckstats = truckstats + MainThemeColor + "Engine RPM: " + RedColor + TOUTFSTRING(Round(truck->engine->getRPM())) + U(" / ") + TOUTFSTRING(Round(truck->engine->getMaxRPM())) + "\n";
			else
				truckstats = truckstats + MainThemeColor + "Engine RPM: " + WhiteColor + TOUTFSTRING(Round(truck->engine->getRPM())) + U(" / ") + TOUTFSTRING(Round(truck->engine->getMaxRPM())) + "\n";

			float currentKw = (((truck->engine->getRPM() * truck->engine->getEngineTorque() *(3.14159265358979323846 /* pi.. */ / 30)) / 1000));

			truckstats = truckstats + MainThemeColor + "Current Power: " + WhiteColor + TOUTFSTRING(Round(currentKw *1.34102209)) + U(" hp / ") + TOUTFSTRING(Round(currentKw)) + U(" Kw") + "\n";

			float velocityKMH = truck->WheelSpeed* 3.6f;
			float velocityMPH = truck->WheelSpeed * 2.23693629f;
			float carSpeedKPH = truck->nodes[0].Velocity.length() * 3.6f;
			float carSpeedMPH = truck->nodes[0].Velocity.length() * 2.23693629f;

			// apply a deadzone ==> no flickering +/-
			if (fabs(truck->WheelSpeed) < 1.0f)
			{
				velocityKMH = velocityMPH = 0.0f;
			}
			if (fabs(truck->nodes[0].Velocity.length()) < 1.0f)
			{
				carSpeedKPH = carSpeedMPH = 0.0f;
			}

			//Some kind of wheel skidding detection? lol
			if (Round(velocityKMH, 0.1) > Round(carSpeedKPH, 0.1) + 2)
				truckstats = truckstats + MainThemeColor + "Wheel speed: " + RedColor + TOUTFSTRING(Round(velocityKMH)) + U(" km/h (") + TOUTFSTRING(Round(velocityMPH)) + U(" mph)") + "\n";
			else if (Round(velocityKMH, 0.1) < Round(carSpeedKPH, 0.1) - 2)
				truckstats = truckstats + MainThemeColor + "Wheel speed: " + BlueColor + TOUTFSTRING(Round(velocityKMH)) + U(" km/h (") + TOUTFSTRING(Round(velocityMPH)) + U(" mph)") + "\n";
			else
				truckstats = truckstats + MainThemeColor + "Wheel speed: " + WhiteColor + TOUTFSTRING(Round(velocityKMH)) + U(" km/h (") + TOUTFSTRING(Round(velocityMPH)) + U(" mph)") + "\n";

			truckstats = truckstats + MainThemeColor + "Car speed: " + WhiteColor + TOUTFSTRING(Round(carSpeedKPH)) + U(" km/h (") + TOUTFSTRING(Round(carSpeedMPH)) + U(" mph)") + "\n";
		}
		else 
		{
			float speedKN = truck->nodes[0].Velocity.length() * 1.94384449f;
			truckstats = truckstats + MainThemeColor + "Current Speed: " + WhiteColor + TOUTFSTRING(Round(speedKN)) + U(" kn (") + TOUTFSTRING(Round(speedKN * 1.852)) + U(" km/h) (") + TOUTFSTRING(Round(speedKN * 1.151)) + U(" mph)") + "\n";
			float altitude = truck->nodes[0].AbsPosition.y / 30.48 * 100;

			truckstats = truckstats + MainThemeColor + "Altitude: " + WhiteColor + TOUTFSTRING(Round(altitude)) + U(" feet (") + TOUTFSTRING(Round(altitude * 0.30480)) + U(" meters)") + "\n";

			if (truck->driveable == AIRPLANE)
			{
				for (int i = 0; i < 8; i++)
				{
					if (truck->aeroengines[i] && truck->aeroengines[i]->getType() == AeroEngine::AEROENGINE_TYPE_TURBOJET)
						truckstats = truckstats + MainThemeColor + "Engine " + TOUTFSTRING(i + 1 /*not to start with 0, players wont like it i guess*/) + " : " + WhiteColor + TOUTFSTRING(Round(truck->aeroengines[i]->getRPM())) + "%" + "\n";
					else if (truck->aeroengines[i] && truck->aeroengines[i]->getType() == AeroEngine::AEROENGINE_TYPE_TURBOPROP)
						truckstats = truckstats + MainThemeColor + "Engine " + TOUTFSTRING(i + 1 /*not to start with 0, players wont like it i guess*/) + " : " + WhiteColor + TOUTFSTRING(Round(truck->aeroengines[i]->getRPM())) + " RPM" + "\n";
				}
			}
			else if(truck->driveable == BOAT)
			{
				for (int i = 0; i < 8; i++)
				{
					if (truck->screwprops[i])
						truckstats = truckstats + MainThemeColor + "Engine " + TOUTFSTRING(i + 1 /*not to start with 0, players wont like it i guess*/) + " : " + WhiteColor + TOUTFSTRING(Round(truck->screwprops[i]->getThrottle() *100 )) + "%" + "\n";
				}
			}
				
		}

		/*
		truckstats = truckstats + MainThemeColor + "maxG: " + WhiteColor + Ogre::UTFString(geesstr) + "\n";
		*/

		//Is this really usefull? people really use it?
		truckstats = truckstats + "\n"; //Some space

		wchar_t geesstr[256];
		Ogre::Vector3 gees = truck->getGForces();
		// apply deadzones ==> no flickering +/-
		if (fabs(gees.y) < 0.01) gees.y = 0.0f;
		if (fabs(gees.z) < 0.01) gees.z = 0.0f;
		Ogre::UTFString tmp = _L("Vertical: %1.2fg | Saggital: %1.2fg | Lateral: %1.2fg");
		swprintf(geesstr, 256, tmp.asWStr_c_str(), gees.x, gees.y, gees.z);
		truckstats = truckstats + MainThemeColor + "Gees: " + WhiteColor + Ogre::UTFString(geesstr) + "\n";

		if (truck->driveable == TRUCK || truck->driveable == AIRPLANE || truck->driveable == BOAT)
		{
			if (gees.x > maxPosVerG[truck->driveable])
				maxPosVerG[truck->driveable] = gees.x;
			if (gees.x < maxNegVerG[truck->driveable])
				maxNegVerG[truck->driveable] = gees.x;

			if (gees.y > maxPosSagG[truck->driveable])
				maxPosSagG[truck->driveable] = gees.y;
			if (gees.y < maxNegSagG[truck->driveable])
				maxNegSagG[truck->driveable] = gees.y;

			if (gees.z > maxPosLatG[truck->driveable])
				maxPosLatG[truck->driveable] = gees.z;
			if (gees.z < maxNegLatG[truck->driveable])
				maxNegLatG[truck->driveable] = gees.z;

			tmp = _L("V %1.2fg %1.2fg // S %1.2fg %1.2fg // L %1.2fg %1.2fg");
			swprintf(geesstr, 256, tmp.asWStr_c_str(),
				maxPosVerG[truck->driveable],
				maxNegVerG[truck->driveable],
				maxPosSagG[truck->driveable],
				maxNegSagG[truck->driveable],
				maxPosLatG[truck->driveable],
				maxNegLatG[truck->driveable]
				);
			truckstats = truckstats + MainThemeColor + "maxG: " + WhiteColor + Ogre::UTFString(geesstr) + "\n";
		}

		m_truck_stats->setCaptionWithReplacing(truckstats);
	}
	else 
		m_truckinfo_box->setVisible(false);

}
コード例 #25
0
ファイル: materialview.cpp プロジェクト: jacmoe/ogitor
//----------------------------------------------------------------------------------------
QString ConvertToQString(Ogre::UTFString& value)
{
    QByteArray encodedString((const char*)value.data(), value.size() * 2);
    QTextCodec *codec = QTextCodec::codecForName("UTF-16");
    return codec->toUnicode(encodedString);
}
コード例 #26
0
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));
}
コード例 #27
0
	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);

	}