Exemple #1
0
void Item::setId(int id)
{
    mId = id;

    // Types 0 and 1 are not equippable items.
    mEquipment = id && getInfo().getType() >= 2;

    // Load the associated image
    if (mImage)
        mImage->decRef();

    if (mDrawImage)
        mDrawImage->decRef();

    ResourceManager *resman = ResourceManager::getInstance();
    SpriteDisplay display = getInfo().getDisplay();
    std::string imagePath = paths.getStringValue("itemIcons")
                            + display.image;
    mImage = resman->getImage(imagePath);
    mDrawImage = resman->getImage(imagePath);

    if (!mImage)
        mImage = Theme::getImageFromTheme(paths.getValue("unknownItemFile",
                                                         "unknown-item.png"));

    if (!mDrawImage)
        mDrawImage = Theme::getImageFromTheme(
                                            paths.getValue("unknownItemFile",
                                                           "unknown-item.png"));
}
ItemContainer::ItemContainer(Inventory *inventory, bool forceQuantity):
    mInventory(inventory),
    mGridColumns(1),
    mGridRows(1),
    mSelectedIndex(-1),
    mHighlightedIndex(-1),
    mLastUsedSlot(-1),
    mSelectionStatus(SEL_NONE),
    mForceQuantity(forceQuantity),
    mSwapItems(false),
    mDescItems(false)
{
    mItemPopup = new ItemPopup;
    setFocusable(true);

    ResourceManager *resman = ResourceManager::getInstance();

    mSelImg = resman->getImage("graphics/gui/selection.png");
    if (!mSelImg)
        logger->error("Unable to load selection.png");

    addKeyListener(this);
    addMouseListener(this);
    addWidgetListener(this);
}
CheckBox::CheckBox(const std::string &caption, bool selected):
    gcn::CheckBox(caption, selected),
    mHasMouse(false)
{
    if (instances == 0)
    {
        ResourceManager *resman = ResourceManager::getInstance();
        Image *checkBox = resman->getImage("graphics/gui/checkbox.png");
        checkBoxNormal = checkBox->getSubImage(0, 0, 9, 10);
        checkBoxChecked = checkBox->getSubImage(9, 0, 9, 10);
        checkBoxDisabled = checkBox->getSubImage(18, 0, 9, 10);
        checkBoxDisabledChecked = checkBox->getSubImage(27, 0, 9, 10);
        checkBoxNormalHi = checkBox->getSubImage(36, 0, 9, 10);
        checkBoxCheckedHi = checkBox->getSubImage(45, 0, 9, 10);
        checkBoxNormal->setAlpha(mAlpha);
        checkBoxChecked->setAlpha(mAlpha);
        checkBoxDisabled->setAlpha(mAlpha);
        checkBoxDisabledChecked->setAlpha(mAlpha);
        checkBoxNormalHi->setAlpha(mAlpha);
        checkBoxCheckedHi->setAlpha(mAlpha);
        checkBox->decRef();
    }

    instances++;
}
Exemple #4
0
void Button::init()
{
    setFrameSize(0);

    if (mInstances == 0)
    {
        // Load the skin
        ResourceManager *resman = ResourceManager::getInstance();
        Image *btn[BUTTON_COUNT];

        int a, x, y, mode;

        for (mode = 0; mode < BUTTON_COUNT; mode++)
        {
            btn[mode] = resman->getImage(data[mode].file);
            a = 0;
            for (y = 0; y < 3; y++)
            {
                for (x = 0; x < 3; x++)
                {
                    button[mode].grid[a] = btn[mode]->getSubImage(
                            data[x].gridX, data[y].gridY,
                            data[x + 1].gridX - data[x].gridX + 1,
                            data[y + 1].gridY - data[y].gridY + 1);
                    a++;
                }
            }
            btn[mode]->decRef();
        }
        updateAlpha();
    }
    mInstances++;
}
Exemple #5
0
void Map::initializeOverlays()
{
    ResourceManager *resman = ResourceManager::getInstance();

    for (int i = 0;
         hasProperty("overlay" + toString(i) + "image");
         i++)
    {
        const std::string name = "overlay" + toString(i);

        Image *img = resman->getImage(getProperty(name + "image"));
        const float speedX = getFloatProperty(name + "scrollX");
        const float speedY = getFloatProperty(name + "scrollY");
        const float parallax = getFloatProperty(name + "parallax");
        const bool keepRatio = getBoolProperty(name + "keepratio");

        if (img)
        {
            mOverlays.push_back(
                    new AmbientOverlay(img, parallax, speedX, speedY, keepRatio));

            // The AmbientOverlay takes control over the image.
            img->decRef();
        }
    }
}
Exemple #6
0
void Minimap::setMap(Map *map)
{
    // Set the title for the Minimap
    std::string caption;

    if (map)
        caption = map->getName();

    if (caption.empty())
        caption = _("Map");

    minimap->setCaption(caption);

    // Adapt the image
    if (mMapImage)
    {
        mMapImage->decRef();
        mMapImage = 0;
    }

    if (map)
    {
        ResourceManager *resman = ResourceManager::getInstance();
        mMapImage = resman->getImage(map->getProperty("minimap"));
    }

    if (mMapImage)
    {
        const int offsetX = 2 * getPadding();
        const int offsetY = getTitleBarHeight() + getPadding();
        const int titleWidth = getFont()->getWidth(getCaption()) + 15;
        const int mapWidth = mMapImage->getWidth() < 100 ?
                             mMapImage->getWidth() + offsetX : 100;
        const int mapHeight = mMapImage->getHeight() < 100 ?
                              mMapImage->getHeight() + offsetY : 100;

        setMinWidth(mapWidth > titleWidth ? mapWidth : titleWidth);
        setMinHeight(mapHeight);

        mWidthProportion = (float) mMapImage->getWidth() / map->getWidth();
        mHeightProportion = (float) mMapImage->getHeight() / map->getHeight();

        setMaxWidth(mMapImage->getWidth() > titleWidth ?
                    mMapImage->getWidth() + offsetX : titleWidth);
        setMaxHeight(mMapImage->getHeight() + offsetY);

        setDefaultSize(getX(), getY(), getWidth(), getHeight());
        resetToDefaultSize();

        if (mShow)
            setVisible(true);
    }
    else
    {
        if (!isSticky())
            setVisible(false);
    }
}
Exemple #7
0
ItemContainer::ItemContainer(Inventory *inventory,
                             const std::string &actionEventId,
                             gcn::ActionListener *listener):
    mInventory(inventory),
    mSelectedItemIndex(NO_ITEM),
    mLastSelectedItemId(NO_ITEM),
    mEquipSlotsFilter(NO_ITEM)
{
    if (!actionEventId.empty())
        setActionEventId(actionEventId);

    if (listener && !actionEventId.empty())
        addActionListener(listener);

    if (mInstances == 0)
    {
        mItemPopup = new ItemPopup();
        mItemPopup->setOpaque(false);

        mShowItemInfo = config.getValue("showItemPopups", true);
        mConfigListener = new ItemContainerConfigListener(this);
        config.addListener("showItemPopups", mConfigListener);

        mPopupMenu = new PopupMenu(TRADE);

        ResourceManager *resman = ResourceManager::getInstance();

        mSelImg = resman->getImage("graphics/gui/selection.png");

        if (!mSelImg)
            logger->error("Unable to load selection.png");
    }

    mProtFocusListener = new ProtectedFocusListener();

    mProtFocusListener->blockKey(SDLK_LEFT);
    mProtFocusListener->blockKey(SDLK_RIGHT);
    mProtFocusListener->blockKey(SDLK_UP);
    mProtFocusListener->blockKey(SDLK_DOWN);
    mProtFocusListener->blockKey(SDLK_SPACE);
    mProtFocusListener->blockKey(SDLK_RETURN);

    mInstances++;

    mMaxItems = mInventory->getLastUsedSlot(); // Count from 0, usage from 2

    addFocusListener(mProtFocusListener);
    addFocusListener(this);
    addKeyListener(this);
    addMouseListener(this);
    addWidgetListener(this);

    setFocusable(true);
}
Exemple #8
0
void
Wellcome::load()
{
    ResourceManager *resman = ResourceManager::getInstance();
    mSlide->decRef();
    mSlide = resman->getImage(mList.at(mCurrentSlide));
    if (mCurrentSlide == mList.size()-1) mNext->setEnabled(false);
    else  mNext->setEnabled(true);

    if (mCurrentSlide == 0) mPrev->setEnabled(false);
    else  mPrev->setEnabled(true);
}
Exemple #9
0
    void setIcon(const std::string &iconPath)
    {
        ResourceManager *res = ResourceManager::getInstance();
        if (!iconPath.empty())
        {
            icon = res->getImage(iconPath);
        }

        if (!icon)
        {
            icon = Theme::getImageFromTheme(
                                       paths.getStringValue("unknownItemFile"));
        }
    }
Exemple #10
0
Wellcome::Wellcome():
    Window("Hoşgeldin :)")
{
    setResizable(false);
    setDefaultSize(50, 50, 420, 430);
    loadWindowState();
    setResizable(false);
    ResourceManager *resman = ResourceManager::getInstance();
    mSlide = resman->getImage("graphics/sunular/basla1/g_00.png");

    setVisible(true);
    mNext = new Button("İleri","next",this);
    mPrev = new Button("Geri","prev",this);
    mFinish = new Button("Kapat","close",this);

    mNext->setPosition(205, getHeight()- mNext->getHeight() - getTitleBarHeight());
    mNext->setWidth(100);
    add(mNext);

    mPrev->setPosition(105,getHeight()- mPrev->getHeight() - getTitleBarHeight());
    mPrev->setWidth(100);
    add(mPrev);

    mFinish->setPosition(330,0);
    mFinish->setWidth(100);
    add(mFinish);

    mAgain = new CheckBox("Girişte göster.",false);
    mAgain->setPosition(mNext->getX() + mNext->getWidth() + 2 ,getHeight()- mAgain->getHeight() - getTitleBarHeight()-5);
    add(mAgain);

    mList.push_back("graphics/sunular/basla1/g_00.png");
    mList.push_back("graphics/sunular/basla1/g_01.png");
    mList.push_back("graphics/sunular/basla1/g_02.png");
    mList.push_back("graphics/sunular/basla1/g_03.png");
    mList.push_back("graphics/sunular/basla1/g_04.png");
    mList.push_back("graphics/sunular/basla1/g_05.png");
    mList.push_back("graphics/sunular/basla1/g_06.png");
    mList.push_back("graphics/sunular/basla1/g_07.png");
    mList.push_back("graphics/sunular/basla1/g_08.png");
//    mList.push_back("graphics/sunular/basla1/g_09.png");
//    mList.push_back("graphics/sunular/basla1/g_10.png");
    mCurrentSlide = 0;
    current_npc = 0;
    NPC::isTalking = false;
    addActionListener(this);
}
ItemShortcutContainer::ItemShortcutContainer():
    ShortcutContainer(),
    mItemClicked(false),
    mItemMoved(NULL)
{
    addMouseListener(this);
    addWidgetListener(this);

    mItemPopup = new ItemPopup;

    ResourceManager *resman = ResourceManager::getInstance();

    mBackgroundImg = resman->getImage("graphics/gui/item_shortcut_bgr.png");
    mMaxItems = itemShortcut->getItemCount();

    mBackgroundImg->setAlpha(config.getValue("guialpha", 0.8));

    mBoxHeight = mBackgroundImg->getHeight();
    mBoxWidth = mBackgroundImg->getWidth();
}
Exemple #12
0
EmotePopup::EmotePopup():
    mSelectedEmoteIndex(-1),
    mHoveredEmoteIndex(-1),
    mRowCount(1),
    mColumnCount(1)
{
    // Setup emote sprites
    for (int i = 0; i <= EmoteDB::getLast(); ++i)
    {
        mEmotes.push_back(EmoteDB::getAnimation(i));
    }

    ResourceManager *resman = ResourceManager::getInstance();
    mSelectionImage = resman->getImage("graphics/gui/selection.png");
    if (!mSelectionImage)
        logger->error("Unable to load selection.png");

    mSelectionImage->setAlpha(config.getValue("guialpha", 0.8));

    addMouseListener(this);
    recalculateSize();
    setVisible(true);
}
Exemple #13
0
void Minimap::setMap(Map *map)
{
    // Adapt the image
    if (mMapImage)
    {
        mMapImage->decRef();
        mMapImage = 0;
    }

    if (map)
    {
        mMap = map;
        std::string tempname =
            "graphics/minimaps/" + map->getFilename() + ".png";
        ResourceManager *resman = ResourceManager::getInstance();

        std::string minimapName = map->getProperty("minimap");

        if (minimapName.empty() && resman->exists(tempname))
            minimapName = tempname;

        if (!minimapName.empty())
            mMapImage = resman->getImage(minimapName);
    }

    if (mMapImage)
    {
        mWidthProportion = (float) mMapImage->getWidth() / map->getWidth();
        mHeightProportion = (float) mMapImage->getHeight() / map->getHeight();

        setVisible(true);
    }
    else
    {
        setVisible(true);
    }
}
RadioButton::RadioButton(const std::string &caption, const std::string &group,
        bool marked):
    gcn::RadioButton(caption, group, marked),
    mHasMouse(false)
{
    if (instances == 0)
    {
        ResourceManager *resman = ResourceManager::getInstance();
        radioNormal = resman->getImage("graphics/gui/radioout.png");
        radioChecked = resman->getImage("graphics/gui/radioin.png");
        radioDisabled = resman->getImage("graphics/gui/radioout.png");
        radioDisabledChecked = resman->getImage("graphics/gui/radioin.png");
        radioNormalHi = resman->getImage("graphics/gui/radioout_highlight.png");
        radioCheckedHi = resman->getImage("graphics/gui/radioin_highlight.png");
        radioNormal->setAlpha(mAlpha);
        radioChecked->setAlpha(mAlpha);
        radioDisabled->setAlpha(mAlpha);
        radioDisabledChecked->setAlpha(mAlpha);
        radioNormalHi->setAlpha(mAlpha);
        radioCheckedHi->setAlpha(mAlpha);
    }

    instances++;
}
CharCreateDialog::CharCreateDialog(Window *parent, int slot):
    Window(_("Create Character"), true, parent),
    mSlot(slot)
{
    mPlayer = new Player(0, 0, NULL);
    mPlayer->setGender(GENDER_MALE);

    ResourceManager *resman = ResourceManager::getInstance();
    mBackGround = resman->getImage("graphics/elektrik/gui_login_window.png");

    gcn::Label *girisLabel = new gcn::Label(_("-=KARAKTER OLUŞTUR=-"));
    girisLabel->setPosition(150,140);
    girisLabel->setFont(font_bas_b_1_16);
    girisLabel->setForegroundColor(gcn::Color(0xaa,0xbb,0xcc));
    girisLabel->adjustSize();
    add(girisLabel);

    int numberOfHairColors = ColorDB::size();

    srand((unsigned)time(0));
    mHairStyle = rand() % mPlayer->getNumOfHairstyles();
    mHairColor = rand() % numberOfHairColors;
    updateHair();

    mNameField = new TextField("");
    mNameLabel = new Label(_("Name:"));
    // TRANSLATORS: This is a narrow symbol used to denote 'next'.
    // You may change this symbol if your language uses another.
    mNextHairColorButton = new Button(_(">"), "nextcolor", this);
    // TRANSLATORS: This is a narrow symbol used to denote 'previous'.
    // You may change this symbol if your language uses another.
    mPrevHairColorButton = new Button(_("<"), "prevcolor", this);
    mHairColorLabel = new Label(_("Hair color:"));
    mNextHairStyleButton = new Button(_(">"), "nextstyle", this);
    mPrevHairStyleButton = new Button(_("<"), "prevstyle", this);
    mHairStyleLabel = new Label(_("Hair style:"));
    mCreateButton = new Button(_("Create"), "create", this);
    mCancelButton = new Button(_("Cancel"), "cancel", this);
    mMale = new RadioButton(_("Male"), "gender");
    mFemale = new RadioButton(_("Female"), "gender");

    // Default to a Male character
    mMale->setSelected(true);

    mMale->setActionEventId("gender");
    mFemale->setActionEventId("gender");

    mMale->addActionListener(this);
    mFemale->addActionListener(this);

    mPlayerBox = new PlayerBox(mPlayer);

    mPlayerBox->setWidth(74);

    mNameField->setActionEventId("create");
    mNameField->addActionListener(this);

    mAttributesLeft = new Label(strprintf(_("Please distribute %d points"), 99));

    int w = 200;
    int h = 330;


    ContainerPlacer place;
    place = getPlacer(5,15);
    place(0,0,mNameLabel);
    place(1,0,mNameField,2);
    place = getPlacer(5,16);
    place(0,0,mHairColorLabel);
    place(1,0,mPrevHairColorButton);
    place(2,0,mPlayerBox,1,10).setPadding(3);
    place(3,0,mNextHairColorButton);
    place(0,1,mHairStyleLabel);
    place(1,1,mPrevHairStyleButton);
    place(3,1,mNextHairStyleButton);
    reflowLayout(350,335);

    mCreateButton->setPosition(200,345);
    mCancelButton->setPosition(260,345);
    mCancelButton->setWidth(mCreateButton->getWidth());

    add(mPlayerBox);
    add(mNameField);
    add(mNameLabel);
    add(mNextHairColorButton);
    add(mPrevHairColorButton);
    add(mHairColorLabel);
    add(mNextHairStyleButton);
    add(mPrevHairStyleButton);
    add(mHairStyleLabel);
    add(mCreateButton);
    add(mCancelButton);
//    add(mAttributesLeft);
//    add(mMale);
//    add(mFemale);

    setSize(573,507);
    center();
    setVisible(true);
    mNameField->requestFocus();
}
Exemple #16
0
void Slider::init()
{
    int x, y, w, h,o1,o2;
    setFrameSize(0);

    // Load resources
    if (mInstances == 0)
    {
        mAlpha = config.getValue("guialpha", 0.8);

        ResourceManager *resman = ResourceManager::getInstance();
        Image *slider = resman->getImage("graphics/gui/slider.png");
        Image *highlight = resman->getImage("graphics/gui/sliderhi.png");

        x = 0; y = 0;
        w = 15; h = 6;
        o1 = 4; o2 = 11;
        hStart = slider->getSubImage(x, y, o1 - x, h);
        hStartHi = highlight->getSubImage(x, y, o1 - x, h);
        hMid = slider->getSubImage(o1, y, o2 - o1, h);
        hMidHi = highlight->getSubImage(o1, y, o2 - o1, h);
        hEnd = slider->getSubImage(o2, y, w - o2 + x, h);
        hEndHi = highlight->getSubImage(o2, y, w - o2 + x, h);

        x = 6; y = 8;
        w = 9; h = 10;
        hGrip = slider->getSubImage(x, y, w, h);
        hGripHi = highlight->getSubImage(x, y, w, h);

        x = 0; y = 6;
        w = 6; h = 21;
        o1 = 10; o2 = 18;
        vStart = slider->getSubImage(x, y, w, o1 - y);
        vStartHi = highlight->getSubImage(x, y, w, o1 - y);
        vMid = slider->getSubImage(x, o1, w, o2 - o1);
        vMidHi = highlight->getSubImage(x, o1, w, o2 - o1);
        vEnd = slider->getSubImage(x, o2, w, h - o2 + y);
        vEndHi = highlight->getSubImage(x, o2, w, h - o2 + y);

        x = 6; y = 8;
        w = 9; h = 10;
        vGrip = slider->getSubImage(x, y, w, h);
        vGripHi = highlight->getSubImage(x, y, w, h);

        slider->decRef();
        highlight->decRef();

        hStart->setAlpha(mAlpha);
        hStartHi->setAlpha(mAlpha);
        hMid->setAlpha(mAlpha);
        hMidHi->setAlpha(mAlpha);
        hEnd->setAlpha(mAlpha);
        hEndHi->setAlpha(mAlpha);
        hGrip->setAlpha(mAlpha);
        hGripHi->setAlpha(mAlpha);

        vStart->setAlpha(mAlpha);
        vStartHi->setAlpha(mAlpha);
        vMid->setAlpha(mAlpha);
        vMidHi->setAlpha(mAlpha);
        vEnd->setAlpha(mAlpha);
        vEndHi->setAlpha(mAlpha);
        vGrip->setAlpha(mAlpha);
        vGripHi->setAlpha(mAlpha);

        mConfigListener = new SliderConfigListener(this);
        config.addListener("guialpha", mConfigListener);
    }

    mProtFocusListener = new ProtectedFocusListener();

    addFocusListener(mProtFocusListener);

    mProtFocusListener->blockKey(SDLK_LEFT);
    mProtFocusListener->blockKey(SDLK_RIGHT);
    mProtFocusListener->blockKey(SDLK_UP);
    mProtFocusListener->blockKey(SDLK_DOWN);

    mInstances++;

    setMarkerLength(hGrip->getWidth());
}
Exemple #17
0
Particle *Particle::addEffect(const std::string &particleEffectFile,
                              int pixelX, int pixelY, int rotation)
{
    Particle *newParticle = NULL;

    XML::Document doc(particleEffectFile);
    xmlNodePtr rootNode = doc.rootNode();

    if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "effect"))
    {
        logger->log("Error loading particle: %s", particleEffectFile.c_str());
        return NULL;
    }

    ResourceManager *resman = ResourceManager::getInstance();

    // Parse particles
    for_each_xml_child_node(effectChildNode, rootNode)
    {
        // We're only interested in particles
        if (!xmlStrEqual(effectChildNode->name, BAD_CAST "particle"))
            continue;

        // Determine the exact particle type
        xmlNodePtr node;

        // Animation
        if ((node = XML::findFirstChildByName(effectChildNode, "animation")))
        {
            newParticle = new AnimationParticle(mMap, node);
        }
        // Rotational
        else if ((node = XML::findFirstChildByName(effectChildNode, "rotation")))
        {
            newParticle = new RotationalParticle(mMap, node);
        }
        // Image
        else if ((node = XML::findFirstChildByName(effectChildNode, "image")))
        {
            Image *img= resman->getImage((const char*)
                    node->xmlChildrenNode->content);

            newParticle = new ImageParticle(mMap, img);
        }
        // Other
        else
        {
            newParticle = new Particle(mMap);
        }

        // Read and set the basic properties of the particle
        float offsetX = XML::getFloatProperty(effectChildNode, "position-x", 0);
        float offsetY = XML::getFloatProperty(effectChildNode, "position-y", 0);
        float offsetZ = XML::getFloatProperty(effectChildNode, "position-z", 0);
        Vector position (mPos.x + (float)pixelX + offsetX,
                         mPos.y + (float)pixelY + offsetY,
                         mPos.z + offsetZ);
        newParticle->moveTo(position);

        int lifetime = XML::getProperty(effectChildNode, "lifetime", -1);
        newParticle->setLifetime(lifetime);
        bool resizeable = "false" != XML::getProperty(effectChildNode, "size-adjustable", "false");
        newParticle->setAllowSizeAdjust(resizeable);

        // Look for additional emitters for this particle
        for_each_xml_child_node(emitterNode, effectChildNode)
        {
            if (xmlStrEqual(emitterNode->name, BAD_CAST "emitter"))
            {
                ParticleEmitter *newEmitter;
                newEmitter = new ParticleEmitter(emitterNode, newParticle, mMap,
                                                 rotation);
                newParticle->addEmitter(newEmitter);
            }
            else if (xmlStrEqual(emitterNode->name, BAD_CAST "deatheffect"))
            {
                std::string deathEffect = (const char*)emitterNode->xmlChildrenNode->content;
                char deathEffectConditions = 0x00;
                if (XML::getBoolProperty(emitterNode, "on-floor", true))
                {
                    deathEffectConditions += Particle::DEAD_FLOOR;
                }
                if (XML::getBoolProperty(emitterNode, "on-sky", true))
                {
                    deathEffectConditions += Particle::DEAD_SKY;
                }
                if (XML::getBoolProperty(emitterNode, "on-other", false))
                {
                    deathEffectConditions += Particle::DEAD_OTHER;
                }
                if (XML::getBoolProperty(emitterNode, "on-impact", true))
                {
                    deathEffectConditions += Particle::DEAD_IMPACT;
                }
                if (XML::getBoolProperty(emitterNode, "on-timeout", true))
                {
                    deathEffectConditions += Particle::DEAD_TIMEOUT;
                }
                newParticle->setDeathEffect(deathEffect, deathEffectConditions);
            }
        }

        mChildParticles.push_back(newParticle);
    }

    return newParticle;
}
Exemple #18
0
void Map::initializeAmbientLayers()
{
    ResourceManager *resman = ResourceManager::getInstance();

    // search for "foreground*" or "overlay*" (old term) in map properties
    for (int i = 0; /* terminated by a break */; i++)
    {
        std::string name;
        if (hasProperty("foreground" + toString(i) + "image"))
        {
            name = "foreground" + toString(i);
        }
        else if (hasProperty("overlay" + toString(i) + "image"))
        {
            name = "overlay" + toString(i);
        }
        else
        {
            break; // the FOR loop
        }

        Image *img = resman->getImage(getProperty(name + "image"));
        const float speedX = getFloatProperty(name + "scrollX");
        const float speedY = getFloatProperty(name + "scrollY");
        const float parallax = getFloatProperty(name + "parallax");
        const bool keepRatio = getBoolProperty(name + "keepratio");

        if (img)
        {
            mForegrounds.push_back(
                    new AmbientLayer(img, parallax, speedX, speedY, keepRatio));

            // The AmbientLayer takes control over the image.
            img->decRef();
        }
    }


    // search for "background*" in map properties
    for (int i = 0;
         hasProperty("background" + toString(i) + "image");
         i++)
    {
        const std::string name = "background" + toString(i);

        Image *img = resman->getImage(getProperty(name + "image"));
        const float speedX = getFloatProperty(name + "scrollX");
        const float speedY = getFloatProperty(name + "scrollY");
        const float parallax = getFloatProperty(name + "parallax");
        const bool keepRatio = getBoolProperty(name + "keepratio");

        if (img)
        {
            mBackgrounds.push_back(
                    new AmbientLayer(img, parallax, speedX, speedY, keepRatio));

            // The AmbientLayer takes control over the image.
            img->decRef();
        }
    }
}
Exemple #19
0
ParticleEmitter::ParticleEmitter(const xmlNodePtr &emitterNode, Particle *target,
                                 Map *map, const int rotation):
    mOutputPauseLeft(0),
    mParticleImage(0)
{
    mMap = map;
    mParticleTarget = target;

    // Initializing default values
    mParticlePosX.set(0.0f);
    mParticlePosY.set(0.0f);
    mParticlePosZ.set(0.0f);
    mParticleAngleHorizontal.set(0.0f);
    mParticleAngleVertical.set(0.0f);
    mParticlePower.set(0.0f);
    mParticleGravity.set(0.0f);
    mParticleRandomness.set(0);
    mParticleBounce.set(0.0f);
    mParticleFollow = false;
    mParticleAcceleration.set(0.0f);
    mParticleDieDistance.set(-1.0f);
    mParticleMomentum.set(1.0f);
    mParticleLifetime.set(-1);
    mParticleFadeOut.set(0);
    mParticleFadeIn.set(0);
    mOutput.set(1);
    mOutputPause.set(0);
    mParticleAlpha.set(1.0f);

    for_each_xml_child_node(propertyNode, emitterNode)
    {
        if (xmlStrEqual(propertyNode->name, BAD_CAST "property"))
        {
            std::string name = XML::getProperty(propertyNode, "name", "");

            if (name == "position-x")
                mParticlePosX = readParticleEmitterProp(propertyNode, 0.0f);
            else if (name == "position-y")
            {

                mParticlePosY = readParticleEmitterProp(propertyNode, 0.0f);
                mParticlePosY.minVal *= SIN45;
                mParticlePosY.maxVal *= SIN45;
                mParticlePosY.changeAmplitude *= SIN45;
             }
            else if (name == "position-z")
            {
                mParticlePosZ = readParticleEmitterProp(propertyNode, 0.0f);
                mParticlePosZ.minVal *= SIN45;
                mParticlePosZ.maxVal *= SIN45;
                mParticlePosZ.changeAmplitude *= SIN45;
            }
            else if (name == "image")
            {
                std::string image = XML::getProperty(propertyNode, "value", "");
                // Don't leak when multiple images are defined
                if (!image.empty() && !mParticleImage)
                {
                    ResourceManager *resman = ResourceManager::getInstance();
                    mParticleImage = resman->getImage(image);
                }
            }
            else if (name == "horizontal-angle")
            {
                mParticleAngleHorizontal = readParticleEmitterProp(propertyNode, 0.0f);
                mParticleAngleHorizontal.minVal += rotation;
                mParticleAngleHorizontal.minVal *= DEG_RAD_FACTOR;
                mParticleAngleHorizontal.maxVal += rotation;
                mParticleAngleHorizontal.maxVal *= DEG_RAD_FACTOR;
                mParticleAngleHorizontal.changeAmplitude *= DEG_RAD_FACTOR;
            }
            else if (name == "vertical-angle")
            {
                mParticleAngleVertical = readParticleEmitterProp(propertyNode, 0.0f);
                mParticleAngleVertical.minVal *= DEG_RAD_FACTOR;
                mParticleAngleVertical.maxVal *= DEG_RAD_FACTOR;
                mParticleAngleVertical.changeAmplitude *= DEG_RAD_FACTOR;
            }
            else if (name == "power")
                mParticlePower = readParticleEmitterProp(propertyNode, 0.0f);
            else if (name == "gravity")
                mParticleGravity = readParticleEmitterProp(propertyNode, 0.0f);
            else if (name == "randomnes" || name == "randomness") // legacy bug
                mParticleRandomness = readParticleEmitterProp(propertyNode, 0);
            else if (name == "bounce")
                mParticleBounce = readParticleEmitterProp(propertyNode, 0.0f);
            else if (name == "lifetime")
            {
                mParticleLifetime = readParticleEmitterProp(propertyNode, 0);
                mParticleLifetime.minVal += 1;
            }
            else if (name == "output")
            {
                mOutput = readParticleEmitterProp(propertyNode, 0);
                mOutput.maxVal +=1;
            }
            else if (name == "output-pause")
            {
                mOutputPause = readParticleEmitterProp(propertyNode, 0);
                mOutputPauseLeft = mOutputPause.value(0);
            }
            else if (name == "acceleration")
                mParticleAcceleration = readParticleEmitterProp(propertyNode, 0.0f);
            else if (name == "die-distance")
                mParticleDieDistance = readParticleEmitterProp(propertyNode, 0.0f);
            else if (name == "momentum")
                mParticleMomentum = readParticleEmitterProp(propertyNode, 1.0f);
            else if (name == "fade-out")
                mParticleFadeOut = readParticleEmitterProp(propertyNode, 0);
            else if (name == "fade-in")
                mParticleFadeIn = readParticleEmitterProp(propertyNode, 0);
            else if (name == "alpha")
                mParticleAlpha = readParticleEmitterProp(propertyNode, 1.0f);
            else if (name == "follow-parent")
                mParticleFollow = true;
            else
            {
                logger->log("Particle Engine: Warning, unknown emitter property \"%s\"",
                            name.c_str());
            }
        }
        else if (xmlStrEqual(propertyNode->name, BAD_CAST "emitter"))
        {
            ParticleEmitter newEmitter(propertyNode, mParticleTarget, map);
            mParticleChildEmitters.push_back(newEmitter);
        }
        else if (xmlStrEqual(propertyNode->name, BAD_CAST "rotation"))
        {
            ImageSet *imageset = ResourceManager::getInstance()->getImageSet(
                XML::getProperty(propertyNode, "imageset", ""),
                XML::getProperty(propertyNode, "width", 0),
                XML::getProperty(propertyNode, "height", 0));

            // Get animation frames
            for_each_xml_child_node(frameNode, propertyNode)
            {
                int delay = XML::getProperty(frameNode, "delay", 0);
                int offsetX = XML::getProperty(frameNode, "offsetX", 0);
                int offsetY = XML::getProperty(frameNode, "offsetY", 0);
                offsetY -= imageset->getHeight() - mMap->getTileHeight();
                offsetX -= (imageset->getWidth() - mMap->getTileWidth()) / 2;

                if (xmlStrEqual(frameNode->name, BAD_CAST "frame"))
                {
                    int index = XML::getProperty(frameNode, "index", -1);

                    if (index < 0)
                    {
                        logger->log("No valid value for 'index'");
                        continue;
                    }

                    Image *img = imageset->get(index);

                    if (!img)
                    {
                        logger->log("No image at index %d", index);
                        continue;
                    }

                    mParticleRotation.addFrame(img, delay, offsetX, offsetY);
                }
                else if (xmlStrEqual(frameNode->name, BAD_CAST "sequence"))
                {
                    int start = XML::getProperty(frameNode, "start", -1);
                    int end = XML::getProperty(frameNode, "end", -1);

                    if (start < 0 || end < 0)
                    {
                        logger->log("No valid value for 'start' or 'end'");
                        continue;
                    }

                    while (end >= start)
                    {
                        Image *img = imageset->get(start);

                        if (!img)
                        {
                            logger->log("No image at index %d", start);
                            continue;
                        }

                        mParticleRotation.addFrame(img, delay, offsetX, offsetY);
                        start++;
                    }
                }
                else if (xmlStrEqual(frameNode->name, BAD_CAST "end"))
                    mParticleRotation.addTerminator();

            } // for frameNode
        }
Exemple #20
0
Windowiki::Windowiki(const std::string& caption, bool modal, Windowiki *parent):
    gcn::Window(caption),
    mGrip(0),
    mParent(parent),
    mWindowName("Window iki"),
    mShowTitle(true),
    mModal(modal),
    mResizable(true),
    mMouseResize(0),
    mSticky(false),
    mMinWinWidth(125),
    mMinWinHeight(250),
    mMaxWinWidth(INT_MAX),
    mMaxWinHeight(INT_MAX),
    mCloseButton(false)
{



   if (!windowikiContainer) {
        throw GCN_EXCEPTION("Window::Window. no windowContainer set");
   }
    if (instancesiki == 0)
    {
        // Load static resources
        ResourceManager *resman = ResourceManager::getInstance();
        Image *dBorders = resman->getImage("graphics/gui/ppp.png");
        borderiki.grid[0] = dBorders->getSubImage(0, 0, 15, 24); //sol üst taraf
        borderiki.grid[1] = dBorders->getSubImage(50, 0, 5, 48); //üst tarafýn devamlýlýðý
        borderiki.grid[2] = dBorders->getSubImage(15, 0, 15, 25); // sað üst taraf
        borderiki.grid[3] = dBorders->getSubImage(0, 110, 44, 5); // sol taraf devamlýlýk
        borderiki.grid[4] = resman->getImage("graphics/gui/ff.png");
        borderiki.grid[5] = dBorders->getSubImage(115, 210, 42, 10); // sað taraf devamlýlýk
        borderiki.grid[6] = dBorders->getSubImage(0, 30, 15, 30); //sol alt taraf
        borderiki.grid[7] = dBorders->getSubImage(89, 0, 5, 61); //alt taraf devamlýlýk
        borderiki.grid[8] = dBorders->getSubImage(0, 15, 0, 55); //sað alt taraf
        dBorders->decRef();

        closeImage = resman->getImage("graphics/gui/close_button.png");
        solustImage = resman->getImage("graphics/gui/solust.png");
        sagustImage = resman->getImage("graphics/gui/sagust.png");
        solaltImage = resman->getImage("graphics/gui/solalt.png");
        sagaltImage = resman->getImage("graphics/gui/sagalt.png");

        windowikiConfigListener = new WindowikiConfigListener();
        // Send GUI alpha changed for initialization
//þeffaf pencereyi kapattým.
//        windowikiConfigListener->optionChanged("guialpha");
//        config.addListener("guialpha", windowikiConfigListener);
    }
    instancesiki++;
    setPadding(5);
    setTitleBarHeight(30);
    // Add chrome
//    mChrome = new GCContainer();
//    mChrome->setOpaque(false);
//    gcn::Window::add(mChrome);

    // Add this window to the window container

    windowikiContainer->add(this);

    if (mModal)
    {
        requestModalFocus();
    }

    // Windows are invisible by default
    setVisible(false);
}
Exemple #21
0
Particle*
Particle::addEffect(const std::string &particleEffectFile,
                    int pixelX, int pixelY, int rotation)
{
    Particle *newParticle = NULL;

    XML::Document doc(particleEffectFile);
    xmlNodePtr rootNode = doc.rootNode();

    if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "effect"))
    {
        logger->log("Error loading particle: %s", particleEffectFile.c_str());
        return NULL;
    }

    ResourceManager *resman = ResourceManager::getInstance();

    // Parse particles
    for_each_xml_child_node(effectChildNode, rootNode)
    {
        // We're only interested in particles
        if (!xmlStrEqual(effectChildNode->name, BAD_CAST "particle"))
            continue;

        // Determine the exact particle type
        xmlNodePtr node;

        // Animation
        if ((node = XML::findFirstChildByName(
                        effectChildNode, "animation"))) {
            newParticle = new AnimationParticle(mMap, node);
        }
        // Image
        else if ((node = XML::findFirstChildByName(
                        effectChildNode, "image"))) {
            Image *img= resman->getImage((const char*)
                    node->xmlChildrenNode->content);

            newParticle = new ImageParticle(mMap, img);
        }
        // Other
        else {
            newParticle = new Particle(mMap);
        }

        // Read and set the basic properties of the particle
        int offsetX = XML::getProperty(effectChildNode, "position-x", 0);
        int offsetY = XML::getProperty(effectChildNode, "position-y", 0);
        int offsetZ = XML::getProperty(effectChildNode, "position-z", 0);

        int particleX = (int) mPos.x + pixelX + offsetX;
        int particleY = (int) mPos.y + pixelY + offsetY;
        int particleZ = (int) mPos.z          + offsetZ;

        int lifetime = XML::getProperty(effectChildNode, "lifetime", -1);

        newParticle->setPosition(particleX, particleY, particleZ);
        newParticle->setLifetime(lifetime);

        // Look for additional emitters for this particle
        for_each_xml_child_node(emitterNode, effectChildNode)
        {
            if (!xmlStrEqual(emitterNode->name, BAD_CAST "emitter"))
                continue;

            ParticleEmitter *newEmitter;
            newEmitter = new ParticleEmitter(emitterNode, newParticle, mMap, rotation);
            newParticle->addEmitter(newEmitter);
        }

        mChildParticles.push_back(newParticle);
    }

    return newParticle;
}
Exemple #22
0
void ItemPopup::setItem(const ItemInfo &item, bool showImage)
{
    if (item.getName() == mItemName->getCaption())
        return;

    int space = 0;

    Image *oldImage = mIcon->getImage();
    if (oldImage)
        oldImage->decRef();

    if (showImage)
    {
        ResourceManager *resman = ResourceManager::getInstance();
        Image *image = resman->getImage(
                                  paths.getStringValue("itemIcons")
                                  + item.getDisplay().image);

        mIcon->setImage(image);
        if (image)
        {
            int x = getPadding();
            int y = getPadding();
            mIcon->setPosition(x, y);
            space = mIcon->getWidth();
        }
    }
    else
    {
        mIcon->setImage(0);
    }

    mItemType = item.getItemType();

    std::string caption = item.getName();
    if (!mItemEquipSlot.empty())
        caption += " (" + mItemEquipSlot + ")";

    mItemName->setCaption(caption);
    mItemName->adjustSize();
    mItemName->setForegroundColor(getColorFromItemType(mItemType));
    mItemName->setPosition(getPadding() + space, getPadding());

    mItemDesc->setTextWrapped(item.getDescription(), ITEMPOPUP_WRAP_WIDTH);
    {
        const std::vector<std::string> &effect = item.getEffect();
        std::string temp = "";
        for (std::vector<std::string>::const_iterator it = effect.begin(),
             it_end = effect.end(); it != it_end; ++it)
            temp += temp.empty() ? *it : "\n" + *it;
        mItemEffect->setTextWrapped(temp, ITEMPOPUP_WRAP_WIDTH);
    }
    mItemWeight->setTextWrapped(strprintf(_("Weight: %s"),
                                Units::formatWeight(item.getWeight()).c_str()),
                                ITEMPOPUP_WRAP_WIDTH);

    int minWidth = mItemName->getWidth() + space;

    if (mItemDesc->getMinWidth() > minWidth)
        minWidth = mItemDesc->getMinWidth();
    if (mItemEffect->getMinWidth() > minWidth)
        minWidth = mItemEffect->getMinWidth();
    if (mItemWeight->getMinWidth() > minWidth)
        minWidth = mItemWeight->getMinWidth();

    minWidth += 8;
    setWidth(minWidth);

    const int numRowsDesc = mItemDesc->getNumberOfRows();
    const int numRowsEffect = mItemEffect->getNumberOfRows();
    const int numRowsWeight = mItemWeight->getNumberOfRows();
    const int fontHeight = getFont()->getHeight();

    int nameHeight;
    if (mIcon->getHeight() > 2 * fontHeight)
        nameHeight = mIcon->getHeight();
    else
        nameHeight = 2 * fontHeight;

    if (item.getEffect().empty())
    {
        setContentSize(minWidth, nameHeight +
                        (numRowsDesc + numRowsWeight + 1) * fontHeight);

        mItemWeight->setPosition(getPadding(),
                                nameHeight + (numRowsDesc + 1) * fontHeight);
    }
    else
    {
        setContentSize(minWidth, nameHeight + (numRowsDesc + numRowsEffect +
                        numRowsWeight + 1) * fontHeight);

        mItemWeight->setPosition(getPadding(), nameHeight + (numRowsDesc +
                                    numRowsEffect + 1) * fontHeight);
    }

    mItemDesc->setPosition(getPadding(), nameHeight);
    mItemEffect->setPosition(getPadding(), nameHeight +
                            (numRowsDesc + 1) * fontHeight);
}