void Repair::updateRepairView() { MWWorld::LiveCellRef<ESM::Repair> *ref = mRepair.getTool().get<ESM::Repair>(); int uses = (mRepair.getTool().getCellRef().mCharge != -1) ? mRepair.getTool().getCellRef().mCharge : ref->mBase->mData.mUses; float quality = ref->mBase->mData.mQuality; std::stringstream qualityStr; qualityStr << std::setprecision(3) << quality; mUsesLabel->setCaptionWithReplacing("#{sUses} " + boost::lexical_cast<std::string>(uses)); mQualityLabel->setCaptionWithReplacing("#{sQuality} " + qualityStr.str()); bool toolBoxVisible = (mRepair.getTool().getRefData().getCount() != 0); mToolBox->setVisible(toolBoxVisible); bool toolBoxWasVisible = (mRepairBox->getPosition().top != mToolBox->getPosition().top); if (toolBoxVisible && !toolBoxWasVisible) { // shrink mRepairBox->setPosition(mRepairBox->getPosition() + MyGUI::IntPoint(0,mToolBox->getSize().height)); mRepairBox->setSize(mRepairBox->getSize() - MyGUI::IntSize(0,mToolBox->getSize().height)); } else if (!toolBoxVisible && toolBoxWasVisible) { // expand mRepairBox->setPosition(MyGUI::IntPoint (mRepairBox->getPosition().left, mToolBox->getPosition().top)); mRepairBox->setSize(mRepairBox->getSize() + MyGUI::IntSize(0,mToolBox->getSize().height)); } while (mRepairView->getChildCount()) MyGUI::Gui::getInstance().destroyWidget(mRepairView->getChildAt(0)); int currentY = 0; MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); MWWorld::ContainerStore& store = MWWorld::Class::get(player).getContainerStore(player); int categories = MWWorld::ContainerStore::Type_Weapon | MWWorld::ContainerStore::Type_Armor; for (MWWorld::ContainerStoreIterator iter (store.begin(categories)); iter!=store.end(); ++iter) { if (MWWorld::Class::get(*iter).hasItemHealth(*iter)) { int maxDurability = MWWorld::Class::get(*iter).getItemMaxHealth(*iter); int durability = (iter->getCellRef().mCharge == -1) ? maxDurability : iter->getCellRef().mCharge; if (maxDurability == durability) continue; MyGUI::TextBox* text = mRepairView->createWidget<MyGUI::TextBox> ( "SandText", MyGUI::IntCoord(8, currentY, mRepairView->getWidth()-8, 18), MyGUI::Align::Default); text->setCaption(MWWorld::Class::get(*iter).getName(*iter)); text->setNeedMouseFocus(false); currentY += 19; MyGUI::ImageBox* icon = mRepairView->createWidget<MyGUI::ImageBox> ( "ImageBox", MyGUI::IntCoord(16, currentY, 32, 32), MyGUI::Align::Default); std::string path = std::string("icons\\"); path += MWWorld::Class::get(*iter).getInventoryIcon(*iter); int pos = path.rfind("."); path.erase(pos); path.append(".dds"); icon->setImageTexture (path); icon->setUserString("ToolTipType", "ItemPtr"); icon->setUserData(*iter); icon->eventMouseButtonClick += MyGUI::newDelegate(this, &Repair::onRepairItem); icon->eventMouseWheel += MyGUI::newDelegate(this, &Repair::onMouseWheel); Widgets::MWDynamicStatPtr chargeWidget = mRepairView->createWidget<Widgets::MWDynamicStat> ("MW_ChargeBar", MyGUI::IntCoord(72, currentY+2, 199, 20), MyGUI::Align::Default); chargeWidget->setValue(durability, maxDurability); chargeWidget->setNeedMouseFocus(false); currentY += 32 + 4; } } mRepairView->setCanvasSize (MyGUI::IntSize(mRepairView->getWidth(), std::max(mRepairView->getHeight(), currentY))); }
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; }
void Repair::updateRepairView() { MWWorld::LiveCellRef<ESM::Repair> *ref = mRepair.getTool().get<ESM::Repair>(); int uses = mRepair.getTool().getClass().getItemHealth(mRepair.getTool()); float quality = ref->mBase->mData.mQuality; std::stringstream qualityStr; qualityStr << std::setprecision(3) << quality; mUsesLabel->setCaptionWithReplacing("#{sUses} " + boost::lexical_cast<std::string>(uses)); mQualityLabel->setCaptionWithReplacing("#{sQuality} " + qualityStr.str()); bool toolBoxVisible = (mRepair.getTool().getRefData().getCount() != 0); mToolBox->setVisible(toolBoxVisible); bool toolBoxWasVisible = (mRepairBox->getPosition().top != mToolBox->getPosition().top); if (toolBoxVisible && !toolBoxWasVisible) { // shrink mRepairBox->setPosition(mRepairBox->getPosition() + MyGUI::IntPoint(0,mToolBox->getSize().height)); mRepairBox->setSize(mRepairBox->getSize() - MyGUI::IntSize(0,mToolBox->getSize().height)); } else if (!toolBoxVisible && toolBoxWasVisible) { // expand mRepairBox->setPosition(MyGUI::IntPoint (mRepairBox->getPosition().left, mToolBox->getPosition().top)); mRepairBox->setSize(mRepairBox->getSize() + MyGUI::IntSize(0,mToolBox->getSize().height)); } while (mRepairView->getChildCount()) MyGUI::Gui::getInstance().destroyWidget(mRepairView->getChildAt(0)); int currentY = 0; MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::ContainerStore& store = player.getClass().getContainerStore(player); int categories = MWWorld::ContainerStore::Type_Weapon | MWWorld::ContainerStore::Type_Armor; for (MWWorld::ContainerStoreIterator iter (store.begin(categories)); iter!=store.end(); ++iter) { if (iter->getClass().hasItemHealth(*iter)) { int maxDurability = iter->getClass().getItemMaxHealth(*iter); int durability = iter->getClass().getItemHealth(*iter); if (maxDurability == durability) continue; MyGUI::TextBox* text = mRepairView->createWidget<MyGUI::TextBox> ( "SandText", MyGUI::IntCoord(8, currentY, mRepairView->getWidth()-8, 18), MyGUI::Align::Default); text->setCaption(iter->getClass().getName(*iter)); text->setNeedMouseFocus(false); currentY += 19; ItemWidget* icon = mRepairView->createWidget<ItemWidget> ( "MW_ItemIconSmall", MyGUI::IntCoord(16, currentY, 32, 32), MyGUI::Align::Default); icon->setItem(*iter); icon->setUserString("ToolTipType", "ItemPtr"); icon->setUserData(*iter); icon->eventMouseButtonClick += MyGUI::newDelegate(this, &Repair::onRepairItem); icon->eventMouseWheel += MyGUI::newDelegate(this, &Repair::onMouseWheel); Widgets::MWDynamicStatPtr chargeWidget = mRepairView->createWidget<Widgets::MWDynamicStat> ("MW_ChargeBar", MyGUI::IntCoord(72, currentY+2, 199, 20), MyGUI::Align::Default); chargeWidget->setValue(durability, maxDurability); chargeWidget->setNeedMouseFocus(false); currentY += 32 + 4; } } // Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the scrollbar is hidden mRepairView->setVisibleVScroll(false); mRepairView->setCanvasSize (MyGUI::IntSize(mRepairView->getWidth(), std::max(mRepairView->getHeight(), currentY))); mRepairView->setVisibleVScroll(true); }
void Recharge::updateView() { MWWorld::Ptr gem = *mGemIcon->getUserData<MWWorld::Ptr>(); std::string soul = gem.getCellRef().getSoul(); const ESM::Creature *creature = MWBase::Environment::get().getWorld()->getStore().get<ESM::Creature>().find(soul); mChargeLabel->setCaptionWithReplacing("#{sCharges} " + MyGUI::utility::toString(creature->mData.mSoul)); bool toolBoxVisible = (gem.getRefData().getCount() != 0); mGemBox->setVisible(toolBoxVisible); bool toolBoxWasVisible = (mBox->getPosition().top != mGemBox->getPosition().top); if (toolBoxVisible && !toolBoxWasVisible) { // shrink mBox->setPosition(mBox->getPosition() + MyGUI::IntPoint(0, mGemBox->getSize().height)); mBox->setSize(mBox->getSize() - MyGUI::IntSize(0,mGemBox->getSize().height)); } else if (!toolBoxVisible && toolBoxWasVisible) { // expand mBox->setPosition(MyGUI::IntPoint (mBox->getPosition().left, mGemBox->getPosition().top)); mBox->setSize(mBox->getSize() + MyGUI::IntSize(0,mGemBox->getSize().height)); } while (mView->getChildCount()) MyGUI::Gui::getInstance().destroyWidget(mView->getChildAt(0)); int currentY = 0; MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::ContainerStore& store = player.getClass().getContainerStore(player); for (MWWorld::ContainerStoreIterator iter (store.begin()); iter!=store.end(); ++iter) { std::string enchantmentName = iter->getClass().getEnchantment(*iter); if (enchantmentName.empty()) continue; const ESM::Enchantment* enchantment = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().find(enchantmentName); if (iter->getCellRef().getEnchantmentCharge() >= enchantment->mData.mCharge || iter->getCellRef().getEnchantmentCharge() == -1) continue; MyGUI::TextBox* text = mView->createWidget<MyGUI::TextBox> ( "SandText", MyGUI::IntCoord(8, currentY, mView->getWidth()-8, 18), MyGUI::Align::Default); text->setCaption(iter->getClass().getName(*iter)); text->setNeedMouseFocus(false); currentY += 19; ItemWidget* icon = mView->createWidget<ItemWidget> ( "MW_ItemIconSmall", MyGUI::IntCoord(16, currentY, 32, 32), MyGUI::Align::Default); icon->setItem(*iter); icon->setUserString("ToolTipType", "ItemPtr"); icon->setUserData(*iter); icon->eventMouseButtonClick += MyGUI::newDelegate(this, &Recharge::onItemClicked); icon->eventMouseWheel += MyGUI::newDelegate(this, &Recharge::onMouseWheel); Widgets::MWDynamicStatPtr chargeWidget = mView->createWidget<Widgets::MWDynamicStat> ("MW_ChargeBar", MyGUI::IntCoord(72, currentY+2, 199, 20), MyGUI::Align::Default); chargeWidget->setValue(static_cast<int>(iter->getCellRef().getEnchantmentCharge()), enchantment->mData.mCharge); chargeWidget->setNeedMouseFocus(false); currentY += 32 + 4; } // Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the scrollbar is hidden mView->setVisibleVScroll(false); mView->setCanvasSize (MyGUI::IntSize(mView->getWidth(), std::max(mView->getHeight(), currentY))); mView->setVisibleVScroll(true); }
void Recharge::updateView() { MWWorld::Ptr gem = *mGemIcon->getUserData<MWWorld::Ptr>(); std::string soul = gem.getCellRef().mSoul; const ESM::Creature *creature = MWBase::Environment::get().getWorld()->getStore().get<ESM::Creature>().find(soul); mChargeLabel->setCaptionWithReplacing("#{sCharges} " + boost::lexical_cast<std::string>(creature->mData.mSoul)); bool toolBoxVisible = (gem.getRefData().getCount() != 0); mGemBox->setVisible(toolBoxVisible); bool toolBoxWasVisible = (mBox->getPosition().top != mGemBox->getPosition().top); if (toolBoxVisible && !toolBoxWasVisible) { // shrink mBox->setPosition(mBox->getPosition() + MyGUI::IntPoint(0, mGemBox->getSize().height)); mBox->setSize(mBox->getSize() - MyGUI::IntSize(0,mGemBox->getSize().height)); } else if (!toolBoxVisible && toolBoxWasVisible) { // expand mBox->setPosition(MyGUI::IntPoint (mBox->getPosition().left, mGemBox->getPosition().top)); mBox->setSize(mBox->getSize() + MyGUI::IntSize(0,mGemBox->getSize().height)); } while (mView->getChildCount()) MyGUI::Gui::getInstance().destroyWidget(mView->getChildAt(0)); int currentY = 0; MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); MWWorld::ContainerStore& store = MWWorld::Class::get(player).getContainerStore(player); for (MWWorld::ContainerStoreIterator iter (store.begin()); iter!=store.end(); ++iter) { std::string enchantmentName = iter->getClass().getEnchantment(*iter); if (enchantmentName.empty()) continue; const ESM::Enchantment* enchantment = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().find(enchantmentName); if (iter->getCellRef().mEnchantmentCharge >= enchantment->mData.mCharge || iter->getCellRef().mEnchantmentCharge == -1) continue; MyGUI::TextBox* text = mView->createWidget<MyGUI::TextBox> ( "SandText", MyGUI::IntCoord(8, currentY, mView->getWidth()-8, 18), MyGUI::Align::Default); text->setCaption(MWWorld::Class::get(*iter).getName(*iter)); text->setNeedMouseFocus(false); currentY += 19; MyGUI::ImageBox* icon = mView->createWidget<MyGUI::ImageBox> ( "ImageBox", MyGUI::IntCoord(16, currentY, 32, 32), MyGUI::Align::Default); std::string path = std::string("icons\\"); path += MWWorld::Class::get(*iter).getInventoryIcon(*iter); int pos = path.rfind("."); path.erase(pos); path.append(".dds"); icon->setImageTexture (path); icon->setUserString("ToolTipType", "ItemPtr"); icon->setUserData(*iter); icon->eventMouseButtonClick += MyGUI::newDelegate(this, &Recharge::onItemClicked); icon->eventMouseWheel += MyGUI::newDelegate(this, &Recharge::onMouseWheel); Widgets::MWDynamicStatPtr chargeWidget = mView->createWidget<Widgets::MWDynamicStat> ("MW_ChargeBar", MyGUI::IntCoord(72, currentY+2, 199, 20), MyGUI::Align::Default); chargeWidget->setValue(iter->getCellRef().mEnchantmentCharge, enchantment->mData.mCharge); chargeWidget->setNeedMouseFocus(false); currentY += 32 + 4; } mView->setCanvasSize (MyGUI::IntSize(mView->getWidth(), std::max(mView->getHeight(), currentY))); }