//  gui change val events
//-----------------------------------------------------------------
void CGui::slTweak(Slider* sl, float val)
{
	std::string name = sl->getName();

	EditBox* edit = fEd(name + "E");
	if (edit)
		edit->setCaption(fToStr(val,3,6));

	TweakSetMtrPar(name, val);
}
///  Championships list  sel changed,  fill Stages list
//----------------------------------------------------------------------------------------------------------------------
void App::listChampChng(MyGUI::MultiList2* chlist, size_t id)
{
	if (id==ITEM_NONE || liChamps->getItemCount() == 0)  return;
	
	//  update champ stages
	liStages->removeAllItems();

	int pos = s2i(liChamps->getItemNameAt(id).substr(7))-1;
	if (pos < 0 || pos >= champs.champs.size())  {  LogO("Error champ sel > size.");  return;  }

	int n = 1, p = pSet->gui.champ_rev ? 1 : 0;
	const Champ& ch = champs.champs[pos];
	for (int i=0; i < ch.trks.size(); ++i,++n)
	{
		const ChampTrack& trk = ch.trks[i];
		String clr = GetSceneryColor(trk.name);
		liStages->addItem(clr+ toStr(n/10)+toStr(n%10), 0);  int l = liStages->getItemCount()-1;
		liStages->setSubItemNameAt(1,l, clr+ trk.name.c_str());

		int id = tracksXml.trkmap[trk.name];  // if (id > 0)
		const TrackInfo& ti = tracksXml.trks[id-1];

		float carMul = GetCarTimeMul(pSet->game.car[0], pSet->game.sim_mode);
		float time = (times.trks[trk.name] * trk.laps /*+ 2*/) / carMul;

		liStages->setSubItemNameAt(2,l, clr+ ti.scenery);
		liStages->setSubItemNameAt(3,l, clrsDiff[ti.diff]+ TR("#{Diff"+toStr(ti.diff)+"}"));

		liStages->setSubItemNameAt(4,l, "#80C0F0"+GetTimeShort(time));  //toStr(trk.laps)
		liStages->setSubItemNameAt(5,l, "#E0F0FF"+fToStr(progress[p].champs[pos].trks[i].points,1,3));
	}
	//  descr
	EditBox* ed = mGUI->findWidget<EditBox>("ChampDescr");
	if (ed)  ed->setCaption(ch.descr);

	//  update champ details (on stages tab)
	TextBox* txt;
	txt = (TextBox*)mWndGame->findWidget("valChDiff");
	if (txt)  txt->setCaption(TR("#{Diff"+toStr(ch.diff)+"}"));
	txt = (TextBox*)mWndGame->findWidget("valChTracks");
	if (txt)  txt->setCaption(toStr(ch.trks.size()));

	txt = (TextBox*)mWndGame->findWidget("valChDist");
	if (txt)  txt->setCaption(/*toStr(ch.length)*/"-");  // sum from find tracks..
	txt = (TextBox*)mWndGame->findWidget("valChTime");
	if (txt)  txt->setCaption(GetTimeString(ch.time));

	txt = (TextBox*)mWndGame->findWidget("valChProgress");
	if (txt)  txt->setCaption(fToStr(100.f * progress[p].champs[pos].curTrack / champs.champs[pos].trks.size(),1,5));
	txt = (TextBox*)mWndGame->findWidget("valChScore");
	if (txt)  txt->setCaption(fToStr(progress[p].champs[pos].points,1,5));
}
///  Championships list  sel changed,  fill Stages list
//---------------------------------------------------------------------
void App::listChampChng(MyGUI::MultiList2* chlist, size_t pos)
{
	if (pos==ITEM_NONE)  return;
	if (pos >= champs.champs.size())  {  LogO("Error champ sel > size.");  return;  }
	
	//  update champ stages
	liStages->removeAllItems();
	float allTime = 0.f;  int n=1;
	const Champ& ch = champs.champs[pos];
	for (int i=0; i < ch.trks.size(); ++i,++n)
	{
		const ChampTrack& trk = ch.trks[i];
		String clr = GetSceneryColor(trk.name);
		liStages->addItem(clr+ toStr(n/10)+toStr(n%10), 0);  int l = liStages->getItemCount()-1;
		liStages->setSubItemNameAt(1,l, clr+ trk.name.c_str());

		int id = tracksXml.trkmap[trk.name];  // if (id > 0)
		const TrackInfo& ti = tracksXml.trks[id-1];

		float time = (champs.trkTimes[trk.name] * trk.laps + 2) * (1.f - trk.factor);
		allTime += time;  // sum trk time, total champ time

		liStages->setSubItemNameAt(2,l, clr+ ti.scenery);
		liStages->setSubItemNameAt(3,l, clrDiff[ti.diff]+ TR("#{Diff"+toStr(ti.diff)+"}"));

		liStages->setSubItemNameAt(4,l, "#80C0F0"+GetTimeString(time));  //toStr(trk.laps)
		liStages->setSubItemNameAt(5,l, "#E0F0FF"+fToStr(progress.champs[pos].trks[i].score,1,5));
	}
	//  descr
	EditBox* ed = mGUI->findWidget<EditBox>("ChampDescr");
	if (ed)  ed->setCaption(ch.descr);

	//  update champ details (on stages tab)
	TextBox* txt;
	txt = (TextBox*)mWndGame->findWidget("valChDiff");
	if (txt)  txt->setCaption(TR("#{Diff"+toStr(ch.diff)+"}"));
	txt = (TextBox*)mWndGame->findWidget("valChTracks");
	if (txt)  txt->setCaption(toStr(ch.trks.size()));

	txt = (TextBox*)mWndGame->findWidget("valChDist");
	if (txt)  txt->setCaption(/*toStr(ch.length)*/"-");  // sum from find tracks..
	txt = (TextBox*)mWndGame->findWidget("valChTime");
	if (txt)  txt->setCaption(GetTimeString(allTime));

	txt = (TextBox*)mWndGame->findWidget("valChProgress");
	if (txt)  txt->setCaption(fToStr(100.f * progress.champs[pos].curTrack / champs.champs[pos].trks.size(),1,5));
	txt = (TextBox*)mWndGame->findWidget("valChScore");
	if (txt)  txt->setCaption(fToStr(progress.champs[pos].score,1,5));
}
Beispiel #4
0
bool GuiPopup::Show(
	PopupDelegate* delegate, const UString& title, bool modal,
	const MyGUI::UString& text0, const MyGUI::UString& text1, const MyGUI::UString& text2, const MyGUI::UString& text3,
	const MyGUI::UString& edit0, const MyGUI::UString& edit1, const MyGUI::UString& edit2, const MyGUI::UString& edit3,
	const MyGUI::UString& button0, const MyGUI::UString& button1, const MyGUI::UString& button2, const MyGUI::UString& button3)
{
	if (isVisible)
		return false;
	isVisible = true;
	btnResult = -1;

	//  window    -----------------------
	int numEdits = 0;
	if (!text0.empty())  ++numEdits;  if (!text1.empty())  ++numEdits;
	if (!text2.empty())  ++numEdits;  if (!text3.empty())  ++numEdits;

	int scr_w = mPlatform->getRenderManagerPtr()->getViewSize().width, scr_h = mPlatform->getRenderManagerPtr()->getViewSize().height;
	int wnd_w = 392, wnd_h = 140 + numEdits * 80,
		wnd_x = (scr_w - wnd_w)/2, wnd_y = (scr_h - wnd_h)/2;  // center

	mWnd = mGUI->createWidget<Window>("WindowC", wnd_x,wnd_y, wnd_w,wnd_h, Align::Center, "Popup", "WndPop");
	mWnd->setColour(Colour(0.8f,0.96f,1.f));
	mWnd->setAlpha(0.9f);
	mWnd->setCaption(title);

	mDelegates.clear();  // add delegate
	mDelegates += delegate;

	if (modal)
		InputManager::getInstance().addWidgetModal(mWnd);


	//  text, edit  -----------------------
	int y = 24,  yadd = 80;
	if (!text0.empty())  {
		TextBox* text = mWnd->createWidget<TextBox>("TextBox", 16,    y, 352,28, Align::Default, "PopText0");	text->setCaption(text0);
		EditBox* edit = mWnd->createWidget<EditBox>("EditBox", 16, 32+y, 352,28, Align::Default, "PopEdit0");	edit->setCaption(edit0);
		y += yadd;
	}
	if (!text1.empty())  {
		TextBox* text = mWnd->createWidget<TextBox>("TextBox", 16,    y, 352,28, Align::Default, "PopText1");	text->setCaption(text1);
		EditBox* edit = mWnd->createWidget<EditBox>("EditBox", 16, 32+y, 352,28, Align::Default, "PopEdit1");	edit->setCaption(edit1);
		y += yadd;
	}
	if (!text2.empty())  {
		TextBox* text = mWnd->createWidget<TextBox>("TextBox", 16,    y, 352,28, Align::Default, "PopText2");	text->setCaption(text2);
		EditBox* edit = mWnd->createWidget<EditBox>("EditBox", 16, 32+y, 352,28, Align::Default, "PopEdit2");	edit->setCaption(edit2);
		y += yadd;
	}
	if (!text3.empty())  {
		TextBox* text = mWnd->createWidget<TextBox>("TextBox", 16,    y, 352,28, Align::Default, "PopText3");	text->setCaption(text3);
		EditBox* edit = mWnd->createWidget<EditBox>("EditBox", 16, 32+y, 352,28, Align::Default, "PopEdit3");	edit->setCaption(edit3);
		y += yadd;
	}

	//  buttons  -----------------------
	y += 12;
	int numBtns = 0;
	if (!button0.empty())  ++numBtns;  if (!button1.empty())  ++numBtns;
	if (!button2.empty())  ++numBtns;  if (!button3.empty())  ++numBtns;

	if (numBtns == 0)  ++numBtns;  // at least 1
	int xmarg = 20, w = (wnd_w - xmarg*2) / numBtns;
	int x = wnd_w - xmarg - w;

	if (!button0.empty())  {
		Button* btn = mWnd->createWidget<Button>("Button",  x,y, w-16,36, Align::Default, "PopBtn0");  btn->setCaption(button0);
		btn->setColour(Colour(0.7f,0.85f,1.0f));
		btn->eventMouseButtonClick += newDelegate(this, &GuiPopup::ButtonClick);  x -= w;
	}
	if (!button1.empty())  {
		Button* btn = mWnd->createWidget<Button>("Button",  x,y, w-16,36, Align::Default, "PopBtn1");  btn->setCaption(button1);
		btn->setColour(Colour(0.6f,0.8f,1.0f));
		btn->eventMouseButtonClick += newDelegate(this, &GuiPopup::ButtonClick);  x -= w;
	}
	if (!button2.empty())  {
		Button* btn = mWnd->createWidget<Button>("Button",  x,y, w-16,36, Align::Default, "PopBtn2");  btn->setCaption(button2);
		btn->setColour(Colour(0.6f,0.8f,1.0f));
		btn->eventMouseButtonClick += newDelegate(this, &GuiPopup::ButtonClick);  x -= w;
	}
	if (!button3.empty())  {
		Button* btn = mWnd->createWidget<Button>("Button",  x,y, w-16,36, Align::Default, "PopBtn3");  btn->setCaption(button3);
		btn->setColour(Colour(0.6f,0.8f,1.0f));
		btn->eventMouseButtonClick += newDelegate(this, &GuiPopup::ButtonClick);  x -= w;
	}

	return true;
}
Beispiel #5
0
IntSize ToolTips::createToolTip(const MWGui::ToolTipInfo& info)
{
    mDynamicToolTipBox->setVisible(true);

    std::string caption = info.caption;
    std::string image = info.icon;
    int imageSize = (image != "") ? 32 : 0;
    std::string text = info.text;

    // remove the first newline (easier this way)
    if (text.size() > 0 && text[0] == '\n')
        text.erase(0, 1);

    const ESM::Enchantment* enchant;
    const ESMS::ESMStore& store = MWBase::Environment::get().getWorld()->getStore();
    if (info.enchant != "")
    {
        enchant = store.enchants.search(info.enchant);
        if (enchant->data.type == ESM::Enchantment::CastOnce)
            text += "\n" + store.gameSettings.search("sItemCastOnce")->str;
        else if (enchant->data.type == ESM::Enchantment::WhenStrikes)
            text += "\n" + store.gameSettings.search("sItemCastWhenStrikes")->str;
        else if (enchant->data.type == ESM::Enchantment::WhenUsed)
            text += "\n" + store.gameSettings.search("sItemCastWhenUsed")->str;
        else if (enchant->data.type == ESM::Enchantment::ConstantEffect)
            text += "\n" + store.gameSettings.search("sItemCastConstant")->str;
    }

    // this the maximum width of the tooltip before it starts word-wrapping
    setCoord(0, 0, 300, 300);

    const IntPoint padding(8, 8);

    const int imageCaptionHPadding = (caption != "" ? 8 : 0);
    const int imageCaptionVPadding = (caption != "" ? 4 : 0);

    std::string realImage = "icons\\" + image;
    findImageExtension(realImage);

    EditBox* captionWidget = mDynamicToolTipBox->createWidget<EditBox>("NormalText", IntCoord(0, 0, 300, 300), Align::Left | Align::Top, "ToolTipCaption");
    captionWidget->setProperty("Static", "true");
    captionWidget->setCaption(caption);
    IntSize captionSize = captionWidget->getTextSize();

    int captionHeight = std::max(caption != "" ? captionSize.height : 0, imageSize);

    EditBox* textWidget = mDynamicToolTipBox->createWidget<EditBox>("SandText", IntCoord(0, captionHeight+imageCaptionVPadding, 300, 300-captionHeight-imageCaptionVPadding), Align::Stretch, "ToolTipText");
    textWidget->setProperty("Static", "true");
    textWidget->setProperty("MultiLine", "true");
    textWidget->setProperty("WordWrap", "true");
    textWidget->setCaption(text);
    textWidget->setTextAlign(Align::HCenter | Align::Top);
    IntSize textSize = textWidget->getTextSize();

    captionSize += IntSize(imageSize, 0); // adjust for image
    IntSize totalSize = IntSize( std::max(textSize.width, captionSize.width + ((image != "") ? imageCaptionHPadding : 0)),
        ((text != "") ? textSize.height + imageCaptionVPadding : 0) + captionHeight );

    if (!info.effects.empty())
    {
        Widget* effectArea = mDynamicToolTipBox->createWidget<Widget>("",
            IntCoord(0, totalSize.height, 300, 300-totalSize.height),
            Align::Stretch, "ToolTipEffectArea");

        IntCoord coord(0, 6, totalSize.width, 24);

        /**
         * \todo
         * the various potion effects should appear in the tooltip depending if the player 
         * has enough skill in alchemy to know about the effects of this potion.
         */

        Widgets::MWEffectListPtr effectsWidget = effectArea->createWidget<Widgets::MWEffectList>
            ("MW_StatName", coord, Align::Default, "ToolTipEffectsWidget");
        effectsWidget->setWindowManager(mWindowManager);
        effectsWidget->setEffectList(info.effects);

        std::vector<MyGUI::WidgetPtr> effectItems;
        effectsWidget->createEffectWidgets(effectItems, effectArea, coord, true, Widgets::MWEffectList::EF_NoTarget);
        totalSize.height += coord.top-6;
        totalSize.width = std::max(totalSize.width, coord.width);
    }

    if (info.enchant != "")
    {
        Widget* enchantArea = mDynamicToolTipBox->createWidget<Widget>("",
            IntCoord(0, totalSize.height, 300, 300-totalSize.height),
            Align::Stretch, "ToolTipEnchantArea");

        IntCoord coord(0, 6, totalSize.width, 24);

        Widgets::MWEffectListPtr enchantWidget = enchantArea->createWidget<Widgets::MWEffectList>
            ("MW_StatName", coord, Align::Default, "ToolTipEnchantWidget");
        enchantWidget->setWindowManager(mWindowManager);
        enchantWidget->setEffectList(Widgets::MWEffectList::effectListFromESM(&enchant->effects));

        std::vector<MyGUI::WidgetPtr> enchantEffectItems;
        int flag = (enchant->data.type == ESM::Enchantment::ConstantEffect) ? Widgets::MWEffectList::EF_Constant : 0;
        enchantWidget->createEffectWidgets(enchantEffectItems, enchantArea, coord, true, flag);
        totalSize.height += coord.top-6;
        totalSize.width = std::max(totalSize.width, coord.width);

        if (enchant->data.type == ESM::Enchantment::WhenStrikes
            || enchant->data.type == ESM::Enchantment::WhenUsed)
        {
            /// \todo store the current enchantment charge somewhere
            int charge = enchant->data.charge;

            const int chargeWidth = 204;

            TextBox* chargeText = enchantArea->createWidget<TextBox>("SandText", IntCoord(0, 0, 10, 18), Align::Default, "ToolTipEnchantChargeText");
            chargeText->setCaption(store.gameSettings.search("sCharges")->str);
            const int chargeTextWidth = chargeText->getTextSize().width + 5;

            const int chargeAndTextWidth = chargeWidth + chargeTextWidth;

            totalSize.width = std::max(totalSize.width, chargeAndTextWidth);

            chargeText->setCoord((totalSize.width - chargeAndTextWidth)/2, coord.top+6, chargeTextWidth, 18);

            IntCoord chargeCoord;
            if (totalSize.width < chargeWidth)
            {
                totalSize.width = chargeWidth;
                chargeCoord = IntCoord(0, coord.top+6, chargeWidth, 18);
            }
            else
            {
                chargeCoord = IntCoord((totalSize.width - chargeAndTextWidth)/2 + chargeTextWidth, coord.top+6, chargeWidth, 18);
            }
            Widgets::MWDynamicStatPtr chargeWidget = enchantArea->createWidget<Widgets::MWDynamicStat>
                ("MW_ChargeBar", chargeCoord, Align::Default, "ToolTipEnchantCharge");
            chargeWidget->setValue(charge, charge);
            totalSize.height += 24;
        }
    }

    captionWidget->setCoord( (totalSize.width - captionSize.width)/2 + imageSize,
        (captionHeight-captionSize.height)/2,
        captionSize.width-imageSize,
        captionSize.height);

    captionWidget->setPosition (captionWidget->getPosition() + padding);
    textWidget->setPosition (textWidget->getPosition() + IntPoint(0, padding.top)); // only apply vertical padding, the horizontal works automatically due to Align::HCenter

    if (image != "")
    {
        ImageBox* imageWidget = mDynamicToolTipBox->createWidget<ImageBox>("ImageBox",
            IntCoord((totalSize.width - captionSize.width - imageCaptionHPadding)/2, 0, imageSize, imageSize),
            Align::Left | Align::Top, "ToolTipImage");
        imageWidget->setImageTexture(realImage);
        imageWidget->setPosition (imageWidget->getPosition() + padding);
    }

    totalSize += IntSize(padding.left*2, padding.top*2);

    return totalSize;
}
///  gui tweak page, material properties
//------------------------------------------------------------------------------------------------------------
void CGui::CreateGUITweakMtr()
{
	ScrollView* view = app->mGui->findWidget<ScrollView>("TweakView",false);
	if (!view)  return;
	
	//  clear last view
	MyGUI::EnumeratorWidgetPtr widgets = view->getEnumerator ();
	app->mGui->destroyWidgets(widgets);

	if (pSet->tweak_mtr == "")  return;
	sh::MaterialInstance* mat = app->mFactory->getMaterialInstance(pSet->tweak_mtr);
	//if (!mat)  return;
	
	int y = 0;
	const sh::PropertyMap& props = mat->listProperties();
	for (sh::PropertyMap::const_iterator it = props.begin(); it != props.end(); ++it)
	{
		sh::PropertyValuePtr pv = (*it).second;
		std::string name = (*it).first;
		
		//  get type
		std::string sVal = pv->_getStringValue();
		//? if (boost::is_alnum(sVal))  continue;
		bool isStr = false;
		for (int c=0; c < sVal.length(); ++c)  if (sVal[c] >= 'a' && sVal[c] <= 'z')
			isStr = true;

		if (!isStr)
		{
			//  get size
			std::vector<std::string> tokens;
			boost::split(tokens, sVal, boost::is_any_of(" "));
			int size = tokens.size();

			//LogO("PROP: " + name + "  val: " + sVal + "  type:" + toStr(type));
			const static char ch[6] = "rgbau";
			const static Colour clrsType[5] = {Colour(0.9,0.9,0.7),Colour(0.8,1.0,0.8),
						Colour(0.7,0.85,1.0),Colour(0.7,1.0,1.0),Colour(1.0,1.0,1.0)};

			//  for each component (xy,rgb..)
			for (int i=0; i < size; ++i)
			{
				String nameSi = name + ":" + toStr(size) + "." + toStr(i);  // size and id in name
				float val = boost::lexical_cast<float> (tokens[i]);
				int t = std::min(4,i);  const Colour& clr = clrsType[std::max(0,std::min(4,size-1))];

				//  name text
				int x = 0, xs = 150;
				TextBox* txt = view->createWidget<TextBox>("TextBox", x,y, xs,20, Align::Default, nameSi + ".txt");
				gcom->setOrigPos(txt, "OptionsWnd");  txt->setTextColour(clr);
				txt->setCaption(size == 1 ? name : name + "." + ch[t]);

				//  val edit
				x += xs;  xs = 60;
				EditBox* edit = view->createWidget<EditBox>("EditBox", x,y, xs,20, Align::Default, nameSi + "E");
				gcom->setOrigPos(edit, "OptionsWnd");  edit->setTextColour(clr);  edit->setColour(clr);
				edit->setCaption(fToStr(val,3,6));
				if (edit->eventEditTextChange.empty())  edit->eventEditTextChange += newDelegate(this, &CGui::edTweak);
				
				//  slider
				x += xs + 10;  xs = 400;
				Slider* sl = view->createWidget<Slider>("Slider", x,y-1, xs,19, Align::Default, nameSi);
				gcom->setOrigPos(sl, "OptionsWnd");  sl->setColour(clr);
				sl->setValue(val);  //powf(val * 1.f/2.f, 1.f/2.f));  //v
				if (sl->eventValueChanged.empty())  sl->eventValueChanged += newDelegate(this, &CGui::slTweak);

				y += 22;
			}
			y += 8;
		}
	}
	view->setCanvasSize(1100, y+500);  //?..
	view->setCanvasAlign(Align::Default);

	gcom->doSizeGUI(view->getEnumerator());
}