Esempio n. 1
0
void Flared_NS::Layer::set(size_t n, size_t index, ITileInfo* i_interface)
{
    if(!index)
        return;
    
    Tileset* curtile = nullptr;
    for( auto i : d_list)
    {
        if( i->getCount() >= index)
        {
            curtile = i;
            break;
        }
        index -= i->getCount();
    }
    
    if(!curtile)
        throw std::runtime_error("Tilesets don't contain index");
    
    d_layer.at(n).info().path =  curtile->getName();
    d_layer.at(n).info().w = curtile->getTileWidth();
    d_layer.at(n).info().h = curtile->getTileHeight();
    d_layer.at(n).info().x = curtile->getPositionX(index);
    d_layer.at(n).info().y = curtile->getPositionY(index);
    d_layer.at(n).info().setTileInfoInterface(i_interface);
}
Esempio n. 2
0
void Map::drawTile(int id,int x, int y)
{
	for(int k=0; k < tilesets.getSize(); k++)
	{
		Tileset* tileset = tilesets.get(k);
		if(id <= tileset->getLasttId() && id >= tileset->getFirstId())
		{
			id -= tileset->getFirstId();
			int tw = tileset->getTileWidth();
			int th = tileset->getTileHeight();
			int imw = al_get_bitmap_width(tileset->getImage());

			//tile
			int sx = id*tw % imw;
			int sy = id/(imw/tw)*th;

			al_draw_bitmap_region(tileset->getImage(),sx,sy,tileWidth,tileHeight,(x*tileWidth) - (xOffs%tileWidth),(y*tileHeight) - (yOffs%tileHeight),0);
		}
	}
}
Esempio n. 3
0
void MapperTilesetBox::draw(gcn::Graphics* graphics){
    // draw components
    InfraellyWindow::draw(graphics);

    //draw selection overlay
    if( !tilesetList->empty() ){
        Tileset *selectedTs = tilesetList->at( tilesetDropDown->getSelected() );
        if( selectedTs != NULL ){
            if( selectedTs->getImage() != NULL ){
                //tile width and height
                int tileWidth = selectedTs->getTileWidth();
                int tileHeight = selectedTs->getTileHeight();

                //calculate amount of px off the screen
                int offsetX = tilesetImage->getX();
                int offsetY = tilesetImage->getY();

                // convert pixel values to row, width
                int offCol = offsetX/tileWidth;
                int offRow = offsetY/tileHeight;



                //get the row and col of the selected tile
                int trueCol = selectedTile.getCol();
                int trueRow = selectedTile.getRow();


                //to find out the reletive row/col to draw to
                //  we must minus the offscreen tiles from the true tiles co-ords
                int drawCol = trueCol + offCol;
                int drawRow = trueRow + offRow;


                //calculate where to draw in pxs
                int drawX = (drawCol * tileWidth) + (tilesetImageScroller->getX() + getFrameSize());
                int drawY = (drawRow * tileHeight) + (tilesetImageScroller->getY() + getTitleBarHeight());


                //add offsets according to scroller
                drawX += offsetX%tileWidth;
                drawY += offsetY%tileHeight;


                //dimensions of the frame
                gcn::Rectangle d( drawX+selectedTs->getXOffset(),
                                  drawY+selectedTs->getYOffset(),
                                  tileWidth, tileHeight );

                //only draw if within region
                if(  ( d.x < tilesetImageScroller->getX()+tilesetImageScroller->getWidth() ) &&
                     ( d.x+d.width > tilesetImageScroller->getX() ) &&
                     ( d.y < tilesetImageScroller->getY()+tilesetImageScroller->getHeight()+getTitleBarHeight() ) &&
                     ( d.y+d.height > tilesetImageScroller->getY()+getTitleBarHeight() )
                ){
                    //setcolour to blue
                    graphics->setColor( gcn::Color( 0, 0, 255) );
                    //draw a frame
                    graphics->drawRectangle( d );
                    //decrease the dimensions by one pixel
                    ++d.x;
                    ++d.y;
                    d.width -= 2;
                    d.height -= 2;
                    //draw another frame (inside prev one)
                    graphics->drawRectangle( d );
                } else {
                    //not in region, draw a bob
                    //off the left
                    if( (d.x+d.width) < tilesetImageScroller->getX() ){
                        d.x = tilesetImageScroller->getX();
                        d.y += (tileHeight/2)-5;
                    };
                    //off the right
                    if( d.x > (tilesetImageScroller->getWidth()+tilesetImageScroller->getX()) ){
                        d.x = tilesetImageScroller->getWidth()-10;
                        d.y += (tileHeight/2)-5;

                    };
                    //off the top
                    if( (d.y+d.height) < tilesetImageScroller->getY() ){
                        d.y = tilesetImageScroller->getY()+getTitleBarHeight();
                        d.x += (tileWidth/2)-5;
                    };
                    //off the bottom
                    if( d.y > (tilesetImageScroller->getHeight()+tilesetImageScroller->getY()+getTitleBarHeight())  ){
                        d.y = tilesetImageScroller->getY()+tilesetImageScroller->getHeight()+getTitleBarHeight() - 10;
                        d.x += (tileWidth/2)-5;
                    };
                    //draw the bob (5x5px box)
                    d.width = 10;
                    d.height = 10;
                    //setcolour to red
                    graphics->setColor( gcn::Color( 255, 0, 0) );
                    graphics->fillRectangle( d );
                }
            }
        }
    }
}
Esempio n. 4
0
void MapperTilesetBox::mouseClicked(gcn::MouseEvent& mouseEvent){
    InfraellyWindow::mouseClicked(mouseEvent);

    if( mouseEvent.isConsumed() ){ return; };

    //if click was from closeTilesetButton
    if( mouseEvent.getSource() == closeTilesetButton ){
        //consume mouse event
        mouseEvent.consume();
        //get the pointer to the tileset to remove
        Tileset *toRemove = tilesetList->at( tilesetDropDown->getSelected() );

        //check if the user is trying to dlete teh nullTS
        if( toRemove != tilesetList->at(0) ){
            //store number to remove
            int removeIndex = tilesetDropDown->getSelected();
            //change the selected ts to the nullTS
            tilesetDropDown->setSelected(0);
            //delete the entry from teh list
            tilesetList->removeElementAt( removeIndex );


            //if there is a map activley associated
            if( world != NULL ){
                //stip dependency from map working on
                //if there IS dependency
                if( !world->empty() ){
                    //cycle through layers
                    for( size_t i = 0; i < world->size(); ++i ){
                        //cycle thru tiles
                        for( size_t j = 0; j < world->getLayer(i).getHeight() * world->getLayer(i).getWidth(); ++j){
                            if( world->getLayer(i).index(j).getTileset() == toRemove ){
                                world->getLayer(i).index(j).setTileset(NULL);
                            }
                        }
                    }
                }
            }
            //dependency of tileset stripped
            //delete the tileset
            cache::tilesets.erase(toRemove);

            //remove from selected tile
            selectedTile.setSource(NULL,0,0);
        }
    }


    //click from the tilesetImage
    if( mouseEvent.getSource() == tilesetImage ){
        //consume mouse event
        mouseEvent.consume();
        if( !tilesetList->empty() ){
            Tileset *selectedTs = selectedTile.getTileset();
            if( selectedTs != NULL ){
                // tileset select
                int tileWidth = selectedTs->getTileWidth();
                int tileHeight = selectedTs->getTileHeight();

                // get the x-y co-ords reletive to the tileset region
                int col = mouseEvent.getX() - (tilesetImage->getX()+selectedTs->getXOffset());
                int row = mouseEvent.getY() - (tilesetImage->getY()+selectedTs->getYOffset());

                // if its a multiple of tilewidth/height (ie in the barrier between)
                if( col % tileWidth == 0){ ++col; };
                if( row % tileHeight == 0){ ++row; };

                // turn co-ords into row/col
                col = col/tileWidth;
                row = row/tileHeight;


                // calculate the amount of tiles off the screen
                int trueCol = tilesetImage->getX();
                int trueRow = tilesetImage->getY();

                //  if its a multiple of tilewidth/height (ie in the barrier between)
                if( trueCol % tileWidth == 0){ ++col; };
                if( trueRow % tileHeight == 0){ ++row; };
                // turn co-ords into row/col
                trueCol = trueCol/tileWidth;
                trueRow = trueRow/tileHeight;
                //add the on screen offset to the offsecreen tiles
                trueCol += col-1;
                trueRow += row-1;

                //store the tile's new row-col
                selectedTile.setSource( selectedTs, trueCol, trueRow);
                //store attribute if on atrib ts
                if( selectedTile.getTileset() == attribTs ){
                    selectedTile.setAttribute(attribGrid[trueCol][trueRow]);
                }
            }// end if null
        }//end if empty list
    }//end if event from drop down*/
}