summaryrefslogtreecommitdiffstats
path: root/konquest/minimap.cpp
blob: 479e997e628360cecebfed088bfd0795b901e4eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <tqpixmap.h>
#include <tqpainter.h>

#include <tdeapplication.h>
#include <kiconloader.h>

#include "minimap.h"
#include "minimap.moc"

MiniMap::MiniMap(  TQWidget *parent, const char *name )
    : TQGridView( parent, name ),
    SECTOR_HEIGHT( 12 ), SECTOR_WIDTH( 12 ),
    BOARD_HEIGHT( 10 * SECTOR_HEIGHT ),
    BOARD_WIDTH( 10 * SECTOR_WIDTH ),
    map( 0 )
{
    setFrameStyle( NoFrame );
    setPaletteBackgroundColor( black );
    setMinimumSize( BOARD_HEIGHT, BOARD_WIDTH );

    setCellWidth( SECTOR_WIDTH );
    setCellHeight( SECTOR_HEIGHT );
    setNumRows( 10 );
    setNumCols( 10 );

    setMinimumSize( BOARD_HEIGHT, BOARD_WIDTH );
    setMaximumSize( BOARD_HEIGHT, BOARD_WIDTH );
}

void
MiniMap::setMap(Map *newMap)
{
    map = newMap;
    BOARD_HEIGHT = map->getRows() * SECTOR_HEIGHT;
    BOARD_WIDTH  = map->getColumns() * SECTOR_WIDTH;
    setNumRows( map->getRows() );
    setNumCols( map->getColumns() );

    setMinimumSize( BOARD_HEIGHT, BOARD_WIDTH );
    setMaximumSize( BOARD_HEIGHT, BOARD_WIDTH );

    connect( map, TQT_SIGNAL( update() ), this, TQT_SLOT( mapUpdate() ) );
}

MiniMap::~MiniMap()
{
}


void
MiniMap::paintCell( TQPainter *p, int row, int col )
{
    drawSector( p, map->getSector( row, col ) );
}

void
MiniMap::mapUpdate()
{
    updateContents();
}


void
MiniMap::drawSector( TQPainter *p, Sector &sector )
{
    TQRect r( 0, 0, SECTOR_WIDTH, SECTOR_HEIGHT );

    p->setPen( black );
    p->setBrush( black );
    p->drawRect( r );

    if( sector.hasPlanet() ) {
        p->setPen( sector.getPlanet()->getPlayer()->getColor() );
        p->setBrush( sector.getPlanet()->getPlayer()->getColor() );

        p->drawPie( r, 0, (360 * 16)-1 );
    }
}