Example #1
0
void CWndControl::SetTexture(const string& filename, bool tiles)
{
    m_textureName = filename;
    m_tiles = tiles;
    m_hasTexture = false;
    m_texture = null;
    DeleteArray(m_textureTiles);

    if (m_textureName.isEmpty())
        return;

    if (m_tiles && GetTilesCount() > 0)
    {
        m_textureTiles = new CTexture*[GetTilesCount()];
        memset(m_textureTiles, 0, sizeof(CTexture*) * GetTilesCount());

        string temp;
        const string name = m_textureName.left(m_textureName.size() - 6);
        const string ext = m_textureName.right(4);
        for (int i = 0; i < GetTilesCount(); i++)
        {
            temp = name % string().sprintf("%02d", i) % ext;
            m_textureTiles[i] = TextureMng->GetGUITexture(temp);

            if (m_textureTiles[i])
                m_hasTexture = true;
        }
    }
    else
    {
        m_texture = TextureMng->GetGUITexture(m_textureName);
        if (m_texture)
            m_hasTexture = true;
    }
}
Example #2
0
void TileSet::LoadResources(gd::Project &game)
{
    try
    {
        gd::ImageResource & image = dynamic_cast<gd::ImageResource&>(game.GetResourcesManager().GetResource(textureName));
        //Load the resource into a wxBitmap (IDE only) and also get its SFMLTextureWrapper
#if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI)
        //Force to change the working directory to make it work
        wxString oldWorkingDir = wxGetCwd();
        wxSetWorkingDirectory(wxFileName::FileName(game.GetProjectFile()).GetPath());
#endif

        m_tilesetTexture = game.GetImageManager()->GetSFMLTexture(textureName);

#if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI)
        wxSetWorkingDirectory(oldWorkingDir);
        if ( wxFileExists(image.GetAbsoluteFile(game)) )
        {
            m_tilesetBitmap.LoadFile(image.GetAbsoluteFile(game), wxBITMAP_TYPE_ANY);
        }
#endif

        //Readjust the m_collidable std::vector according to the number of tiles
        m_collidable.resize(GetTilesCount(), true);
    }
    catch(...)
    {
        m_tilesetTexture = std::shared_ptr<SFMLTextureWrapper>();
    }
}
Example #3
0
void CWndControl::PaintFrame()
{
    if (m_hasTexture)
    {
        if (m_tiles && GetTilesCount() > 0)
        {
            if (GetTilesCount() == 12)
                m_render2D->Render12Tiles(GetWindowRect(false), m_textureTiles);
            else if (GetTilesCount() == 9)
                m_render2D->Render9Tiles(GetWindowRect(false), m_textureTiles);
        }
        else
            m_render2D->RenderTexture(QPoint(0, 0), m_texture);

        if (HasFlag(WBS_CAPTION))
#if __VER >= 19
            m_render2D->RenderText(s_titleFont, m_text, QPoint(m_windowRect.width() / 2 - s_titleFont->GetSize(m_text).width() / 2, 8), D3DCOLOR_XRGB(246, 204, 77));
#else
            m_render2D->RenderText(s_titleFont, m_text, QPoint(10, 4), m_color);
#endif
    }
    else
    {
        const QRect winRect = GetWindowRect(false);
        QRect rect = winRect;
        rect.setBottom(19);
        m_render2D->RenderTexture(rect, s_defaultBackground);
        rect = winRect;
        rect.setRight(rect.right() + 1);
        m_render2D->RenderRoundRect(rect, D3DCOLOR_ARGB(255, 0, 0, 0));
        rect.adjust(1, 1, -1, -1);
        m_render2D->RenderRoundRect(rect, D3DCOLOR_ARGB(255, 160, 160, 160));
        rect.adjust(1, 1, -1, -1);
        m_render2D->RenderRoundRect(rect, 0xffffffff);
        rect.adjust(1, 1, -1, -1);
        m_render2D->RenderRoundRect(rect, D3DCOLOR_ARGB(255, 160, 160, 160));

        if (HasFlag(WBS_CAPTION))
        {
            rect = winRect;
            rect.setBottom(21);
            rect.adjust(3, 3, -2, 0);
            m_render2D->RenderGradationRect(rect, D3DCOLOR_ARGB(255, 255, 255, 255), D3DCOLOR_ARGB(255, 150, 150, 150), D3DCOLOR_ARGB(255, 230, 230, 230));
            m_render2D->RenderText(s_textFont, m_text, QPoint(17, 7), m_color);
        }
    }
}
Example #4
0
void TileSet::ResetHitboxes()
{
    m_hitboxes.clear();
    if (m_dirty)
        return;

    m_hitboxes.assign(GetTilesCount(), TileHitbox::Rectangle(tileSize));
}
Example #5
0
void TileSet::ResetHitboxes()
{
    m_collidable.clear();
    m_hitboxes.clear();

    if (IsDirty())
        return;

    m_collidable.assign(GetTilesCount(), true);
}
Example #6
0
void TileSet::Generate()
{
    m_dirty = true;

    if (!m_tilesetTexture)
        return;

    std::cout << "Generating texture coords..." << std::endl;

    //Calculates the number of rows and columns in the tileset
    int columns(0), rows(0);
    if (tileSize.x == 0 || tileSize.y == 0)
        return;
    columns = (m_tilesetTexture->texture.getSize().x + tileSpacing.x) / (tileSize.x + tileSpacing.x);
    rows = (m_tilesetTexture->texture.getSize().y + tileSpacing.y) / (tileSize.y + tileSpacing.y);

    //Generate the TextureCoords and the sub-bitmaps (only in IDE)
    m_coords.clear();
    for(int row = 0; row < rows; row++)
    {
        for(int col = 0; col < columns; col++)
        {
            //TileTextureCoords
            TileTextureCoords tileCoords;
            tileCoords.topLeft = sf::Vector2f(col * (tileSize.x + tileSpacing.x),
                                              row * (tileSize.y + tileSpacing.y));
            tileCoords.topRight = sf::Vector2f(col * (tileSize.x + tileSpacing.x) + tileSize.x,
                                               row * (tileSize.y + tileSpacing.y));
            tileCoords.bottomRight = sf::Vector2f(col * (tileSize.x + tileSpacing.x) + tileSize.x,
                                                  row * (tileSize.y + tileSpacing.y) + tileSize.y);
            tileCoords.bottomLeft = sf::Vector2f(col * (tileSize.x + tileSpacing.x),
                                                 row * (tileSize.y + tileSpacing.y) + tileSize.y);
            m_coords.push_back(tileCoords);
        }
    }

    //Puts the default hitbox for new tiles (if there are more tiles than before)
    if (GetTilesCount() > m_hitboxes.size())
        m_hitboxes.insert(m_hitboxes.end(), (GetTilesCount()-m_hitboxes.size()), TileHitbox::Rectangle(tileSize));

    std::cout << "OK" << std::endl;
    m_dirty = false;
}