You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
244 lines
5.7 KiB
244 lines
5.7 KiB
15 years ago
|
#include <tqpixmap.h>
|
||
|
#include <tqpainter.h>
|
||
|
#include <tqcolor.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdeapplication.h>
|
||
15 years ago
|
#include <kiconloader.h>
|
||
12 years ago
|
#include <tdeglobalsettings.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdeglobal.h>
|
||
15 years ago
|
#include "map_widget.moc"
|
||
|
|
||
13 years ago
|
ConquestMap::ConquestMap( Map *newMap, TQWidget *parent )
|
||
|
: TQGridView( parent ),
|
||
15 years ago
|
SECTOR_HEIGHT( 28 ), SECTOR_WIDTH( 28 ),
|
||
|
BOARD_HEIGHT( newMap->getRows() * SECTOR_HEIGHT ),
|
||
|
BOARD_WIDTH( newMap->getColumns() * SECTOR_WIDTH ),
|
||
|
map( newMap ), gridColor( 50, 80, 50 ),
|
||
|
hiLiteRow( -1 ), hiLiteCol( -1 )
|
||
|
{
|
||
12 years ago
|
labelFont = TDEGlobalSettings::generalFont();
|
||
15 years ago
|
labelFont.setPointSize( 8 );
|
||
|
|
||
|
setFrameStyle( NoFrame );
|
||
|
setPaletteBackgroundColor( black );
|
||
|
setMinimumSize( BOARD_HEIGHT, BOARD_WIDTH );
|
||
|
|
||
|
setCellWidth( SECTOR_WIDTH );
|
||
|
setCellHeight( SECTOR_HEIGHT );
|
||
|
setNumRows( map->getRows() );
|
||
|
setNumCols( map->getColumns() );
|
||
|
|
||
|
setMinimumSize( BOARD_HEIGHT, BOARD_WIDTH );
|
||
|
setMaximumSize( BOARD_HEIGHT, BOARD_WIDTH );
|
||
|
|
||
15 years ago
|
connect( map, TQT_SIGNAL( update() ), this, TQT_SLOT( mapUpdate() ) );
|
||
15 years ago
|
|
||
15 years ago
|
TQTimer *timer = new TQTimer( this );
|
||
|
connect( timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(squareBlink()) );
|
||
15 years ago
|
timer->start( 500, false );
|
||
|
|
||
|
viewport()->setMouseTracking( true );
|
||
|
setMouseTracking( true );
|
||
|
|
||
|
show();
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
ConquestMap::~ConquestMap()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
|
void
|
||
15 years ago
|
ConquestMap::contentsMousePressEvent( TQMouseEvent *e )
|
||
15 years ago
|
{
|
||
|
int row, col;
|
||
|
|
||
|
row = rowAt( e->y() );
|
||
|
col = columnAt( e->x() );
|
||
|
|
||
|
if( map->getSector( row, col ).hasPlanet() ) {
|
||
|
emit planetSelected( map->getSector( row, col ).getPlanet() );
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
void
|
||
15 years ago
|
ConquestMap::contentsMouseMoveEvent( TQMouseEvent *e )
|
||
15 years ago
|
{
|
||
|
// highlight the square under the mouse
|
||
|
int row, col;
|
||
|
|
||
|
row = rowAt( e->y() );
|
||
|
col = columnAt( e->x() );
|
||
|
|
||
|
// Check to make sure the mouse is in a valid grid location
|
||
|
if( (row < 0 || col < 0) ||
|
||
|
(row >= BOARD_ROWS || col >= BOARD_COLS) ) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
|
||
|
if( (hiLiteRow != -1) && (hiLiteCol != -1) ) {
|
||
15 years ago
|
TQPainter p( viewport() );
|
||
15 years ago
|
|
||
|
p.translate( hiLiteCol * cellWidth(), hiLiteRow * cellHeight() );
|
||
|
|
||
|
drawSector( &p, map->getSector(hiLiteRow,hiLiteCol) );
|
||
|
|
||
|
hiLiteRow = -1;
|
||
|
hiLiteCol = -1;
|
||
|
|
||
|
}
|
||
|
|
||
|
if( map->getSector( row, col ).hasPlanet() ) {
|
||
15 years ago
|
TQPainter p( viewport() );
|
||
15 years ago
|
|
||
|
p.translate( col * cellWidth(),row * cellHeight() );
|
||
|
|
||
|
drawSector( &p, map->getSector(row,col), false, true );
|
||
|
emit planetHighlighted(map->getSector( row, col ).getPlanet() );
|
||
|
|
||
|
hiLiteRow = row;
|
||
|
hiLiteCol = col;
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
void
|
||
|
ConquestMap::unselectPlanet()
|
||
|
{
|
||
|
map->setSelectedSector();
|
||
|
}
|
||
|
|
||
|
|
||
|
void
|
||
15 years ago
|
ConquestMap::paintCell( TQPainter *p, int row, int col )
|
||
15 years ago
|
{
|
||
|
drawSector( p, map->getSector( row, col ) );
|
||
|
}
|
||
|
|
||
|
void
|
||
|
ConquestMap::squareBlink()
|
||
|
{
|
||
|
static bool blinkState = true;
|
||
|
|
||
|
int row, col;
|
||
|
if( map->selectedSector( row, col ) ) {
|
||
15 years ago
|
TQPainter p( this, true );
|
||
15 years ago
|
|
||
|
p.translate( col * cellWidth(), row * cellHeight() );
|
||
|
|
||
|
if( blinkState ) {
|
||
|
drawSector( &p, map->getSector(row,col), true );
|
||
|
} else {
|
||
|
drawSector( &p, map->getSector(row,col), false );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if( blinkState )
|
||
|
blinkState = false;
|
||
|
else
|
||
|
blinkState = true;
|
||
|
}
|
||
|
|
||
|
|
||
|
void
|
||
|
ConquestMap::mapUpdate()
|
||
|
{
|
||
13 years ago
|
viewport()->repaint(false);
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
void
|
||
15 years ago
|
ConquestMap::drawSector( TQPainter *p, Sector §or, bool borderStrobe, bool highlight )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQColor labelColor( white );
|
||
|
TQPoint labelCorner;
|
||
15 years ago
|
|
||
|
if( sector.hasPlanet() ) {
|
||
15 years ago
|
TQPixmap pm;
|
||
15 years ago
|
|
||
|
// simple (pathetic) way to "randomize"
|
||
|
// the planet graphic
|
||
|
// and also a really dirty hack to make the planet
|
||
|
// name more visible (hard coded pixel offsets)
|
||
|
switch( ((sector.getRow()+sector.getColumn()) % 9) + 1 ) {
|
||
|
case 1 :
|
||
15 years ago
|
pm = TQPixmap( IMAGE_PLANET_1 );
|
||
|
labelCorner = TQPoint( 18, 14 );
|
||
15 years ago
|
break;
|
||
|
case 2 :
|
||
15 years ago
|
pm = TQPixmap( IMAGE_PLANET_2 );
|
||
|
labelCorner = TQPoint( 2, 14 );
|
||
15 years ago
|
break;
|
||
|
case 3 :
|
||
15 years ago
|
pm = TQPixmap( IMAGE_PLANET_3 );
|
||
|
labelCorner = TQPoint( 2, 26 );
|
||
15 years ago
|
break;
|
||
|
case 4 :
|
||
15 years ago
|
pm = TQPixmap( IMAGE_PLANET_4 );
|
||
|
labelCorner = TQPoint( 18, 26 );
|
||
15 years ago
|
break;
|
||
|
case 5 :
|
||
15 years ago
|
pm = TQPixmap( IMAGE_PLANET_5 );
|
||
|
labelCorner = TQPoint( 18, 26 );
|
||
15 years ago
|
break;
|
||
|
case 6 :
|
||
15 years ago
|
pm = TQPixmap( IMAGE_PLANET_6 );
|
||
|
labelCorner = TQPoint( 18, 26 );
|
||
15 years ago
|
break;
|
||
|
case 7 :
|
||
15 years ago
|
pm = TQPixmap( IMAGE_PLANET_7 );
|
||
|
labelCorner = TQPoint( 18, 26 );
|
||
15 years ago
|
break;
|
||
|
case 8 :
|
||
15 years ago
|
pm = TQPixmap( IMAGE_PLANET_8 );
|
||
|
labelCorner = TQPoint( 18, 26 );
|
||
15 years ago
|
break;
|
||
|
case 9 :
|
||
15 years ago
|
pm = TQPixmap( IMAGE_PLANET_9 );
|
||
|
labelCorner = TQPoint( 18, 26 );
|
||
15 years ago
|
break;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQPoint pos;
|
||
15 years ago
|
|
||
|
pos.setX( ( SECTOR_HEIGHT / 2 ) - ( pm.height() / 2 ) );
|
||
|
pos.setY( ( SECTOR_WIDTH / 2 ) - ( pm.width() / 2 ) );
|
||
|
|
||
15 years ago
|
p->drawPixmap( pos, pm, TQRect(0, 0, pm.height(), pm.width() ) );
|
||
15 years ago
|
|
||
|
p->setFont( labelFont );
|
||
|
p->setPen( labelColor );
|
||
|
|
||
|
p->drawText( labelCorner, sector.getPlanet()->getName() );
|
||
|
|
||
|
if( borderStrobe ) {
|
||
15 years ago
|
TQPen gridPen( sector.getPlanet()->getPlayer()->getColor() );
|
||
15 years ago
|
p->setPen( gridPen );
|
||
|
} else if( highlight ) {
|
||
15 years ago
|
TQPen gridPen( white );
|
||
15 years ago
|
p->setPen( gridPen );
|
||
|
} else {
|
||
15 years ago
|
TQPen gridPen( gridColor );
|
||
15 years ago
|
p->setPen( gridPen );
|
||
|
}
|
||
|
|
||
|
} else {
|
||
|
p->eraseRect( 0, 0, SECTOR_WIDTH, SECTOR_HEIGHT );
|
||
|
|
||
15 years ago
|
TQPen gridPen( gridColor );
|
||
15 years ago
|
|
||
|
p->setPen( gridPen );
|
||
|
}
|
||
|
|
||
|
p->drawRect( 0, 0, SECTOR_HEIGHT, SECTOR_WIDTH );
|
||
|
|
||
|
}
|
||
|
|
||
|
|