Ejemplo n.º 1
0
void MapView::loadViewComponents()
{
    // ================================================== Tile options ==================================================
    int offset = 75;
    int n = 0;

    TileOption * wallOption = new TileOption(Cell::CellType::Wall, screenWidth - 200, 100 + offset * n++, 200, 50);
    TileOption * floorOption = new TileOption(Cell::CellType::Surface, screenWidth - 200, 100 + offset * n++, 200, 50);
    TileOption * startOption = new TileOption(Cell::CellType::Start, screenWidth - 200, 100 + offset * n++, 200, 50);
    TileOption * endOption = new TileOption(Cell::CellType::End, screenWidth - 200, 100 + offset * n++, 200, 50);
    TileOption * emptyOption = new TileOption(Cell::CellType::Empty, screenWidth - 200, 100 + offset * n++, 200, 50);

    wallOption->setRenderers(renderer, &texture, &text);
    floorOption->setRenderers(renderer, &texture, &text);
    startOption->setRenderers(renderer, &texture, &text);
    endOption->setRenderers(renderer, &texture, &text);
    emptyOption->setRenderers(renderer, &texture, &text);

    clickables->push_back(wallOption);
    clickables->push_back(floorOption);
    clickables->push_back(startOption);
    clickables->push_back(endOption);
    clickables->push_back(emptyOption);

    // Attach to observable
    wallOption->attach(this);
    floorOption->attach(this);
    startOption->attach(this);
    endOption->attach(this);
    emptyOption->attach(this);

    wallOption = nullptr;
    floorOption = nullptr;
    startOption = nullptr;
    endOption = nullptr;
    emptyOption = nullptr;

    // ==================================================== Map tiles ====================================================
    int mapColumns = mapModel->getWidth();
    int mapRows = mapModel->getHeight();

    int tileTextureWidth = 400 / mapColumns;
    int tileTextureHeight = 400 / mapRows;

    int currentX = 25;
    int currentY = 125;

    MapTile * mt = nullptr;
    for (int i = 0; i < mapColumns; i++)
    {
        for (int j = 0; j < mapRows; j++)
        {
            mt = new MapTile(mapModel, i, j, currentX, currentY, tileTextureWidth, tileTextureHeight);
            mt->setRenderers(renderer, &texture, &text);
            clickables->push_back(mt);
            mt->attach(this);
            mt = nullptr;
            currentY += tileTextureHeight;
        }
        currentX += tileTextureWidth;
        currentY = 125;
    }

    // ==================================================== Button(s) ====================================================
    Button * validateButton = new Button(screenWidth - 300, screenHeight - 50, 300, 50);
    validateButton->setRenderers(renderer, &texture, &text);
    clickables->push_back(validateButton);
    validateButton->attach(this);
    validateButton = nullptr;
}