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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920
|
/****************************************************************
**
** Attal : Lords of Doom
**
** displayBase.cpp
** inside the base
**
** Version : $Id: displayBase.cpp,v 1.22 2004/12/13 15:14:59 lusum Exp $
**
** Author(s) : Pascal Audoux - Sardi Carlo
**
** Date : 03/09/2000
**
** Licence :
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2, or (at your option)
** any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
****************************************************************/
#include "displayBase.h"
// generic include files
// include files for QT
#include <qapplication.h>
#include <qlayout.h>
#include <qpixmap.h>
#include <qpushbutton.h>
#include <qmessagebox.h>
#include <qsignalmapper.h>
// application specific include files
#include "conf.h"
#include "libCommon/attalSocket.h"
#include "libCommon/dataTheme.h"
#include "libCommon/genericBuilding.h"
#include "libCommon/genericLord.h"
#include "libCommon/log.h"
#include "libClient/displayCreature.h"
#include "libClient/game.h"
#include "libClient/gui.h"
#include "libClient/imageTheme.h"
#include "libClient/insideAction.h"
#include "libClient/insideBase.h"
#include "libClient/market.h"
#include "libClient/unitExchange.h"
extern QString DATA_PATH;
extern QString IMAGE_PATH;
extern ImageTheme ImageTheme;
extern DataTheme DataTheme;
DisplayBase::DisplayBase( QWidget * parent, const char * name )
: QWidget( parent, name )
{
_player = 0;
_base = 0;
_socket = 0;
_game = 0;
_dialog = 0;
_inside = new InsideBase( this );
_panel = new BaseRightPanel( this );
InsideBaseView * view = new InsideBaseView( _inside, this );
QVBoxLayout * layV1 = new QVBoxLayout();
if( qApp->desktop()->width() >= 1024 ) {
view->setFixedSize( 960, 720 );
view->setVScrollBarMode( QScrollView::AlwaysOff );
view->setHScrollBarMode( QScrollView::AlwaysOff );
layV1->addWidget( view );
layV1->addStretch( 1 );
} else {
view->setMaximumSize( 960, 720 );
layV1->addWidget( view, 1 );
//layV1->addStretch( 1 );
}
QHBoxLayout * layout = new QHBoxLayout( this );
layout->addLayout( layV1, 1 );
layout->addWidget( _panel );
layout->activate();
connect( view, SIGNAL( sig_building( GenericInsideBuilding * ) ), SLOT( slot_building( GenericInsideBuilding * ) ) );
connect( _panel, SIGNAL( sig_quit() ), SIGNAL( sig_quit() ) );
//connect( _baseButtons, SIGNAL( sig_exchange() ), _baseLords, SLOT( slot_exchange() ) );
//connect( _baseLords, SIGNAL( sig_exchange( bool ) ), _baseButtons, SLOT( slot_exchange( bool ) ) );
}
DisplayBase::~DisplayBase()
{
}
void DisplayBase::handleSocket()
{
_game->handleSocket();
_socket->reReadData();
switch( _socket->getCla1() ) {
case SO_MSG:
break;
case SO_GAME:
break;
case SO_TURN:
break;
case SO_MODIF:
if( ( _socket->getCla2() == C_MOD_BASE ) &&
( _socket->getCla3() == C_BASE_BUILDING ) ) {
int row = _socket->readInt();
int col = _socket->readInt();
uchar level = _socket->readChar();
bool create = (bool)_socket->readChar();
if( ( _base->getCell()->getRow() == row ) &&
( _base->getCell()->getCol() == col ) ) {
if( create ) {
GenericInsideBuilding * building = _base->getBuildingByType( level );
_inside->addBuilding( building );
} else {
_inside->delBuilding( level );
}
}
if(_dialog)
_dialog->updateView();
} else if( ( _socket->getCla2() == C_MOD_BASE ) && ( _socket->getCla3() == C_BASE_UNIT ) ) {
reinit();
}
if( ( _socket->getCla2() == C_MOD_PLAYER ) && ( _socket->getCla3() == C_PLAY_RESS ) ) {
/// XXX:_baseSummary->reinit();
}
break;
case SO_QR:
break;
case SO_MVT:
break;
case SO_TECHNIC:
break;
case SO_EXCH:
break;
case SO_CONNECT:
break;
case SO_FIGHT:
break;
default:
logEE( "Unknown socket_class" );
}
}
void DisplayBase::slot_building( GenericInsideBuilding * building )
{
if( _base ) {
InsideBuildingModel * model = DataTheme.bases.at( _base->getRace() )->getBuildingModel( building->getLevel() );
if( model->getAction() ) {
switch( model->getAction()->getType() ) {
case INSIDE_NONE:
break;
case INSIDE_VILLAGE:
actionAllBuildings();
break;
case INSIDE_CASTLE:
actionAllCreatures();
break;
case INSIDE_CREA:
actionSomeCreatures( building );
break;
case INSIDE_MARKET:
actionMarket();
break;
default:
logEE( "Unknown action %d", model->getAction()->getType() );
break;
}
}
}
}
void DisplayBase::actionAllBuildings()
{
_dialog = new InsideActionAllBuildings( _base );
if(_dialog){
_dialog->setSocket( _socket );
_dialog->setPlayer( _player );
_dialog->exec();
delete _dialog;
_dialog = 0;
}
}
void DisplayBase::actionAllCreatures()
{
DisplayCreatureBase creatures( _base, this );
creatures.initSocket( _socket );
creatures.init( _player );
creatures.exec();
}
void DisplayBase::actionSomeCreatures( GenericInsideBuilding * building )
{
if( _base ) {
InsideAction * action = DataTheme.bases.at( _base->getRace() )->getBuildingModel( building->getLevel() )->getAction();
if( action ) {
//InsideActionSomeCreature dialog( action->getParam( 0 ), action->getParam( 1 ) );
BuyCreature dialog( this );
dialog.initSocket( _socket );
int race = action->getParam( 0 );
int level = action->getParam( 1 );
dialog.init( _player, _base, DataTheme.creatures.at( race, level ) );
if( dialog.exec() ) {
// try to buy some creature
}
}
}
}
void DisplayBase::actionMarket()
{
Market mark( this );
mark.setPrices( _player->getPriceMarket());
mark.initSocket( _socket );
mark.exec();
reinit();
}
void DisplayBase::setPlayer( Player * player )
{
_player = player;
_panel->setPlayer( player );
}
void DisplayBase::setBase( GenericBase * base )
{
_base = base;
//_baseSummary->setBase( base );
//_baseLords->setBase( base );
_panel->setBase( base );
_inside->setBase( base );
}
void DisplayBase::reinit()
{
/// XXX:_baseSummary->reinit();
_panel->reinit();
}
void DisplayBase::setSocket( AttalSocket * socket )
{
_socket = socket;
_panel->setSocket( socket );
}
/*
void DisplayBase::slot_newLord()
{
if( _baseLords->isVisitor() ) {
QMessageBox::critical( this, "Error", "There is already a visiting lord" );
return;
}
}
*/
//
// ----- BaseRightPanel -----
//
BaseRightPanel::BaseRightPanel( QWidget * parent, const char * name )
: QWidget( parent, name )
{
_player = 0;
_socket = 0;
_base = 0;
_displayLords = 0;
_pbLord = new QPushButton( this );
_pbLord->setFixedSize( 60, 60 );
_lordLabel = new QLabel( this );
_lordLabel->setText( "\n\n" );
_lordLabel->setAlignment( Qt::AlignHCenter | Qt::WordBreak );
_lordLabel->setMinimumWidth( 64 );
_lordLabel->setMinimumHeight( _lordLabel->sizeHint().height() );
_pbInfo = new QPushButton( this );
_pbInfo->setText( "Info" );
FIXEDSIZE( _pbInfo );
_bases = new BaseButtons( this );
/// XXX: use pixmap instead
QPushButton * pbQuit = createButtonOk( this );
FIXEDSIZE( pbQuit );
QVBoxLayout * layout = new QVBoxLayout( this );
layout->setMargin( 5 );
layout->setSpacing( 10 );
layout->addWidget( _pbLord );
layout->addWidget( _lordLabel );
layout->addSpacing( 10 );
layout->addWidget( _pbInfo );
layout->addStretch( 1 );
layout->addWidget( _bases );
layout->addWidget( pbQuit );
layout->activate();
connect( pbQuit, SIGNAL( clicked() ), SIGNAL( sig_quit() ) );
connect( _pbLord, SIGNAL( clicked() ), SLOT( slot_lords() ) );
connect( _pbInfo, SIGNAL( clicked() ), SLOT( slot_info() ) );
}
void BaseRightPanel::slot_lords()
{
_displayLords = new DisplayBaseLord( this );
/// XXX: could be gathered
_displayLords->init( _player, _base, _socket );
_displayLords->exec();
reinit();
delete _displayLords;
_displayLords = 0;
}
void BaseRightPanel::slot_info()
{
DisplayBaseInfo displayInfo( this );
displayInfo.init( _player, _base );
displayInfo.exec();
}
void BaseRightPanel::setPlayer( Player * player )
{
/// XXX: set lord pixmap
_player = player;
}
void BaseRightPanel::setSocket( AttalSocket * socket )
{
_socket = socket;
}
void BaseRightPanel::setBase( GenericBase * base )
{
_base = base;
reinit();
}
void BaseRightPanel::reinit()
{
GenericLord * lord = 0;
QString text;
text = "\nNo lord\n";
if( _base->getGarrisonLord() ) {
lord = _base->getGarrisonLord();
text.sprintf( "Lord\n%s\n(Guarrison)", lord->getName().latin1() );
} else if( _base->getVisitorLord() ) {
lord = _base->getVisitorLord();
text.sprintf( "Lord\n%s\n(Visitor)", lord->getName().latin1() );
}
if( lord ) {
_pbLord->setPixmap( * _player->getLordPixmapById( lord->getId() ) );
} else {
/// XXX: should be optimized in imageTheme
_pbLord->setPixmap( QPixmap( IMAGE_PATH + "/lords/noLord.png" ) );
}
_lordLabel->setText( text );
if(_displayLords)
_displayLords->reinit();
}
//
// ----- BaseSummary -----
//
BaseSummary::BaseSummary( QWidget * parent, const char * name )
: QWidget( parent, name )
{
_base = 0;
int i;
_popul = new QLabel( this );
QVBoxLayout * layout = new QVBoxLayout( this );
QHBoxLayout * lay1 = new QHBoxLayout();
_ress = new RessourceWin(this);
lay1->addWidget( _ress );
layout->addLayout( lay1 );
layout->addStretch( 2 );
layout->addWidget( _popul );
QHBoxLayout * lay2 = new QHBoxLayout();
lay2->addStretch( 1 );
for( i = 0; i < 4; i++ ) {
_unitIco[i] = new UnitSummary( this );
lay2->addWidget( _unitIco[i] );
lay2->addStretch( 1 );
}
layout->addLayout( lay2 );
QHBoxLayout * lay3 = new QHBoxLayout();
lay3->addStretch( 1 );
for( i = 0; i < 4; i++ ) {
_unitIco[4+i] = new UnitSummary( this );
lay3->addWidget( _unitIco[4+i] );
lay3->addStretch( 1 );
}
layout->addLayout( lay3 );
layout->addStretch( 1 );
layout->activate();
setFixedHeight( 240 );
}
void BaseSummary::setPlayer( Player * player )
{
_player = player;
_ress->setPlayer(player);
for( int i = 0; i < 8; i++ ) {
_unitIco[i]->setPlayer( player );
}
}
void BaseSummary::reinit()
{
_ress->reinit();
_popul->setText(QString(" Population %1 ").arg(_base->getPopulation(),10,10));
}
void BaseSummary::setBase( GenericBase * base )
{
_base = base;
reinit();
}
//
// ----- DisplayBaseInfo -----
//
DisplayBaseInfo::DisplayBaseInfo( QWidget * parent, const char * name )
: QDialog( parent, name, true )
{
_widget = new BaseSummary( this );
QPushButton * pbOk = new QPushButton( this );
pbOk->setText( "Ok" );
FIXEDSIZE( pbOk );
QHBoxLayout * layH1 = new QHBoxLayout();
layH1->addStretch( 1 );
layH1->addWidget( pbOk );
layH1->addStretch( 1 );
QVBoxLayout * layout = new QVBoxLayout( this );
layout->setSpacing( 5 );
layout->setMargin( 5 );
layout->addWidget( _widget );
layout->addLayout( layH1 );
layout->activate();
connect( pbOk, SIGNAL( clicked() ), SLOT( accept() ) );
}
void DisplayBaseInfo::init( Player * player, GenericBase * base )
{
_widget->setBase( base );
_widget->setPlayer( player );
}
void DisplayBaseInfo::reinit()
{
_widget->reinit();
}
//
// ----- BaseLords -----
//
BaseLords::BaseLords( QWidget * parent, const char * name )
: QWidget( parent, name )
{
_base = 0;
_isExchange = false;
_socket = 0;
setFixedHeight( 240 );
QVBoxLayout * layout = new QVBoxLayout( this );
_garrison = new BaseTroop( true, this );
layout->addWidget( _garrison, 1 );
_visitor = new BaseTroop( false, this );
layout->addWidget( _visitor, 1 );
layout->activate();
connect( _garrison, SIGNAL( sig_photo() ), SLOT( slot_photoGarrison() ) );
connect( _garrison, SIGNAL( sig_unit( int ) ), SLOT( slot_unitGarrison( int ) ) );
connect( _visitor, SIGNAL( sig_photo() ), SLOT( slot_photoVisitor() ) );
connect( _visitor, SIGNAL( sig_unit( int ) ), SLOT( slot_unitVisitor( int ) ) );
_garrisonSelected = false;
_visitorSelected = false;
_unitGarrison = -1;
_unitVisitor = -1;
}
void BaseLords::setPlayer( Player * player )
{
_player = player;
_garrison->setPlayer( player );
_visitor->setPlayer( player );
}
void BaseLords::setBase( GenericBase * base )
{
_base = base;
_garrison->setBase( base );
_visitor->setBase( base );
_garrisonSelected = false;
_visitorSelected = false;
}
void BaseLords::reinit()
{
_garrison->reinit();
_visitor->reinit();
}
void BaseLords::slot_exchange()
{
_isExchange = !_isExchange;
}
void BaseLords::slot_photoGarrison()
{
unselectUnits();
if( _garrisonSelected ) {
/// XXX: show info lord
_garrisonSelected = false;
} else {
if( _visitorSelected ) {
exchangeLords();
} else if( _base->isGarrisonLord() ) {
_garrisonSelected = true;
}
}
}
void BaseLords::slot_photoVisitor()
{
unselectUnits();
if( _visitorSelected ) {
/// XXX: show info lord
_visitorSelected = false;
} else {
if( _garrisonSelected ) {
exchangeLords();
} else if( _base->isVisitorLord() ) {
_visitorSelected = true;
}
}
}
void BaseLords::exchangeLords()
{
_garrisonSelected = false;
_visitorSelected = false;
_base->exchangeLords();
GenericLord * visitor = _base->getVisitorLord();
_visitor->setLord( visitor );
if( visitor ) {
_socket->sendLordGarrison( visitor, false );
}
GenericLord * garrison = _base->getGarrisonLord();
_garrison->setLord( garrison );
if( garrison ) {
_socket->sendLordGarrison( garrison, true );
}
}
void BaseLords::exchangeUnitsGV()
{
GenericLord * garrison = _base->getGarrisonLord();
GenericLord * visitor = _base->getVisitorLord();
if(visitor){
if(garrison){
_socket->sendExchangeUnit( garrison, _unitGarrison, visitor, _unitVisitor );
} else {
_socket->sendExchangeBaseUnit( _base, _unitGarrison, visitor, _unitVisitor );
}
}
_garrison->reinit();
_visitor->reinit();
}
void BaseLords::exchangeUnitsVG()
{
GenericLord * garrison = _base->getGarrisonLord();
GenericLord * visitor = _base->getVisitorLord();
if(garrison){
_socket->sendExchangeUnit( garrison, _unitGarrison, visitor, _unitVisitor );
} else {
_socket->sendExchangeBaseUnit( _base, _unitGarrison, visitor, _unitVisitor );
}
_garrison->reinit();
_visitor->reinit();
}
void BaseLords::exchangeUnitsGG( int u1, int u2 )
{
if( u1 == u2 ) {
return;
}
GenericLord * garrison = _base->getGarrisonLord();
if(garrison){
_socket->sendExchangeUnit( garrison, u1, garrison, u2 );
} else {
_socket->sendExchangeBaseUnit( _base, u1, 0, u2 );
}
_garrison->reinit();
}
void BaseLords::exchangeUnitsVV( int u1, int u2 )
{
if( u1 == u2 ) {
return;
}
GenericLord * visitor = _base->getVisitorLord();
_socket->sendExchangeUnit( visitor, u1, visitor, u2 );
_visitor->reinit();
}
void BaseLords::slot_unitGarrison( int num )
{
unselectPhoto();
if( _isExchange ) {
if( _unitGarrison != -1 ) {
} else {
}
} else {
if( ( _unitGarrison != -1 ) || ( _unitVisitor != -1 ) ) {
if( _unitGarrison != -1 ) {
exchangeUnitsGG( _unitGarrison, num );
} else {
_unitGarrison = num;
exchangeUnitsVG();
}
unselectUnits();
} else {
if( _base->getGarrisonUnit( num ) != 0 ) {
_unitGarrison = num;
_garrison->selectUnit( _unitGarrison );
emit sig_exchange( true );
}
}
}
}
void BaseLords::slot_unitVisitor( int num )
{
unselectPhoto();
if( _isExchange ) {
} else {
if( ( _unitGarrison != -1 ) || ( _unitVisitor != -1 ) ) {
if( _unitVisitor != -1 ) {
exchangeUnitsVV( _unitVisitor, num );
} else {
_unitVisitor = num;
exchangeUnitsGV();
}
unselectUnits();
} else {
if( _base->getVisitorUnit( num ) != 0 ) {
_unitVisitor = num;
_visitor->selectUnit( _unitVisitor );
emit sig_exchange( true );
}
}
}
}
void BaseLords::unselectUnits()
{
_unitGarrison = -1;
_garrison->unselectUnits();
_unitVisitor = -1;
_visitor->unselectUnits();
emit sig_exchange( false );
}
void BaseLords::unselectPhoto()
{
_garrisonSelected = false;
_garrison->unselectPhoto();
_visitorSelected = false;
_visitor->unselectPhoto();
}
//
// ----- DisplayBaseLord -----
//
DisplayBaseLord::DisplayBaseLord( QWidget * parent, const char * name )
: QDialog( parent, name, true )
{
_widget = new BaseLords( this );
QPushButton * pbOk = new QPushButton( this );
pbOk->setText( "Ok" );
FIXEDSIZE( pbOk );
QHBoxLayout * layH1 = new QHBoxLayout();
layH1->addStretch( 1 );
layH1->addWidget( pbOk );
layH1->addStretch( 1 );
QVBoxLayout * layout = new QVBoxLayout( this );
layout->addWidget( _widget, 1 );
layout->addLayout( layH1 );
layout->activate();
connect( pbOk, SIGNAL( clicked() ), SLOT( accept() ) );
}
void DisplayBaseLord::init( Player * player, GenericBase * base, AttalSocket * socket )
{
_widget->setPlayer( player );
_widget->setSocket( socket );
_widget->setBase( base );
}
void DisplayBaseLord::reinit()
{
_widget->reinit();
}
//
// ----- BaseButtons -----
//
BaseButtons::BaseButtons( QWidget * parent, const char * name )
: QWidget( parent, name )
{
QVBoxLayout * layout = new QVBoxLayout( this );
_pbExch = new QPushButton( this );
_pbExch->setFixedSize( 50, 40 );
layout->addWidget( _pbExch );
layout->addStretch( 1 );
layout->activate();
setFixedHeight( 240 );
_pbExch->setEnabled( false );
connect( _pbExch, SIGNAL( clicked() ), SIGNAL( sig_exchange() ) );
}
void BaseButtons::slot_exchange( bool st )
{
if( st ) {
_pbExch->setEnabled( true );
} else {
_pbExch->setEnabled( false );
}
}
//
// ----- UnitSummary -----
//
UnitSummary::UnitSummary( QWidget * parent, const char * name )
: QWidget( parent, name )
{
_ico = new QLabel( this );
_ico->setFixedSize( 50, 40 );
_nb = new QLabel( this );
_nb->setFixedSize( 50, 20 );
_nb->setAlignment( AlignCenter );
_nb->move( 0, 40 );
setFixedSize( 50, 60 );
}
void UnitSummary::setCreature( int /*id*/ )
{
/// XXX: TODO
logEE( "not yet implemented" );
}
void UnitSummary::setNumber( int num )
{
if( num == 0 ) {
_nb->setText( "" );
} else {
_nb->setText( "+" + QString::number( num ) );
}
}
//
// ----- BaseTroop -----
//
BaseTroop::BaseTroop( bool isGarrison, QWidget * parent, const char * name )
: QWidget( parent, name )
{
_isGarrison = isGarrison;
_lord = 0;
QHBoxLayout * layout = new QHBoxLayout( this );
_photo = new Icon( this );
layout->addWidget( _photo );
layout->addStretch( 1 );
QSignalMapper * sigmap = new QSignalMapper( this );
for( int i = 0; i < MAX_UNIT; i++ ) {
_units[i] = new Icon( this );
layout->addWidget( _units[i] );
sigmap->setMapping( _units[i], i );
connect( _units[i], SIGNAL( sig_clicked() ), sigmap, SLOT( map() ) );
}
layout->addStretch( 1 );
layout->activate();
connect( _photo, SIGNAL( sig_clicked() ), SIGNAL( sig_photo() ) );
connect( sigmap, SIGNAL( mapped( int ) ), SIGNAL( sig_unit( int ) ) );
}
void BaseTroop::clear()
{
_lord = 0;
_photo->clear();
for( int i = 0; i < MAX_UNIT; i++ ) {
_units[i]->clear();
}
}
void BaseTroop::setLord( GenericLord * lord )
{
_lord = lord;
reinit();
}
void BaseTroop::setBase( GenericBase * base )
{
_base = base;
if( _isGarrison ) {
_lord = base->getGarrisonLord();
} else {
_lord = base->getVisitorLord();
}
reinit();
}
void BaseTroop::reinit()
{
if( _lord == 0 ) {
clear();
if( _isGarrison ) {
for( int i = 0; i < MAX_UNIT; i++ ) {
if( _base->getUnit( i ) ) {
_units[i]->setPixmap( QPixmap( ImageTheme.getPhotoCreature( _base->getUnit( i ) ) ) );
}
}
}
return;
}
_photo->setPixmap( *_player->getLordPixmapById( _lord->getId() ) );
for( int i = 0; i < MAX_UNIT; i++ ) {
if( _lord->getUnit( i ) ) {
_units[i]->setPixmap( QPixmap( ImageTheme.getPhotoCreature( _lord->getUnit( i ) ) ) );
} else {
_units[i]->clear();
}
}
}
|