コード例 #1
0
ファイル: inventorywindow.cpp プロジェクト: SlavaHill/openmw
    void InventoryWindow::pickUpObject (MWWorld::Ptr object)
    {
        /// \todo scripts

        // make sure the object is of a type that can be picked up
        std::string type = object.getTypeName();
        if ( (type != typeid(ESM::Apparatus).name())
            && (type != typeid(ESM::Armor).name())
            && (type != typeid(ESM::Book).name())
            && (type != typeid(ESM::Clothing).name())
            && (type != typeid(ESM::Ingredient).name())
            && (type != typeid(ESM::Light).name())
            && (type != typeid(ESM::Miscellaneous).name())
            && (type != typeid(ESM::Tool).name())
            && (type != typeid(ESM::Probe).name())
            && (type != typeid(ESM::Repair).name())
            && (type != typeid(ESM::Weapon).name())
            && (type != typeid(ESM::Potion).name()))
            return;

        // sound
        std::string sound = MWWorld::Class::get(object).getUpSoundId(object);
        MWBase::Environment::get().getSoundManager()->playSound(sound, 1, 1);

        int count = object.getRefData().getCount();

        // add to player inventory
        // can't use ActionTake here because we need an MWWorld::Ptr to the newly inserted object
        MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
        MWWorld::Ptr newObject = *MWWorld::Class::get (player).getContainerStore (player).add (object);
        // remove from world
        MWBase::Environment::get().getWorld()->deleteObject (object);

        mDragAndDrop->mIsOnDragAndDrop = true;
        mDragAndDrop->mDraggedCount = count;

        std::string path = std::string("icons\\");
        path += MWWorld::Class::get(newObject).getInventoryIcon(newObject);
        MyGUI::ImageBox* baseWidget = mContainerWidget->createWidget<ImageBox>("ImageBox", MyGUI::IntCoord(0, 0, 42, 42), MyGUI::Align::Default);
        baseWidget->detachFromWidget();
        baseWidget->attachToWidget(mDragAndDrop->mDragAndDropWidget);
        baseWidget->setUserData(newObject);
        mDragAndDrop->mDraggedWidget = baseWidget;
        ImageBox* image = baseWidget->createWidget<ImageBox>("ImageBox", MyGUI::IntCoord(5, 5, 32, 32), MyGUI::Align::Default);
        int pos = path.rfind(".");
        path.erase(pos);
        path.append(".dds");
        image->setImageTexture(path);
        image->setNeedMouseFocus(false);

        // text widget that shows item count
        MyGUI::TextBox* text = image->createWidget<MyGUI::TextBox>("SandBrightText", MyGUI::IntCoord(0, 14, 32, 18), MyGUI::Align::Default, std::string("Label"));
        text->setTextAlign(MyGUI::Align::Right);
        text->setNeedMouseFocus(false);
        text->setTextShadow(true);
        text->setTextShadowColour(MyGUI::Colour(0,0,0));
        text->setCaption(getCountString(count));
        mDragAndDrop->mDraggedFrom = this;
    }
コード例 #2
0
void VehicleSelectScreen::buildUI()
{
	m_logger->logMessage("VehicleSelectScreen::buildUI()");

	m_guiLayout = LayoutManager::getInstance().loadLayout(m_uiFileName);

	ImageBox* parentBG = Gui::getInstance().findWidget<ImageBox>("backImg");
	parentBG->setSize(RenderManager::getInstance().getViewSize());
	parentBG->setImageTexture("blue_back.jpg");

	m_vehiclePreview = Gui::getInstance().findWidget<ImageBox>("vehicleModel");

	m_enginePowerProgress = Gui::getInstance().findWidget<ProgressBar>("enginePowerProgress");
	m_maxSpeedProgress = Gui::getInstance().findWidget<ProgressBar>("maxSpeedProgress");
	m_tractionProgress = Gui::getInstance().findWidget<ProgressBar>("tractionProgress");
	m_accelProgress = Gui::getInstance().findWidget<ProgressBar>("accelProgress");

	m_enginePowerProgress->setProgressRange(100);
	m_maxSpeedProgress->setProgressRange(100);
	m_tractionProgress->setProgressRange(100);
	m_accelProgress->setProgressRange(100);

	m_vehicleNameLabel = Gui::getInstance().findWidget<TextBox>("vehicleNameLabel");
	m_infoLabel = Gui::getInstance().findWidget<TextBox>("infoLabel");

	m_bgMusic = AudioManager::getSingleton().createMusic("menu.ogg", AudioType::SOUND_2D_LOOPING);
	m_bgMusic->play();
	m_bgMusic->setVolume(0.5);

	m_backBtn = Gui::getInstance().findWidget<Button>("backBtn");
	m_selectBtn = Gui::getInstance().findWidget<Button>("selectBtn");
	m_prevBtn = Gui::getInstance().findWidget<ImageBox>("prevBtn");
	m_nextBtn = Gui::getInstance().findWidget<ImageBox>("nextBtn");
	
	m_selectBtn->eventMouseButtonClick += newDelegate(this, &VehicleSelectScreen::buttonClicked);
	m_prevBtn->eventMouseButtonClick += newDelegate(this, &VehicleSelectScreen::buttonClicked);
	m_backBtn->eventMouseButtonClick += newDelegate(this, &VehicleSelectScreen::buttonClicked);
	m_nextBtn->eventMouseButtonClick += newDelegate(this, &VehicleSelectScreen::buttonClicked);

	m_selectBtn->eventMouseSetFocus += newDelegate(this, &VehicleSelectScreen::buttonHovered);
	m_prevBtn->eventMouseSetFocus += newDelegate(this, &VehicleSelectScreen::buttonHovered);
	m_backBtn->eventMouseSetFocus += newDelegate(this, &VehicleSelectScreen::buttonHovered);
	m_nextBtn->eventMouseSetFocus += newDelegate(this, &VehicleSelectScreen::buttonHovered);

	inflateVehicleInfo();
}
コード例 #3
0
ファイル: tooltips.cpp プロジェクト: SlavaHill/openmw
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;
}