Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

vehicletypeselector.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           cargodialog.cpp  -  description
00003                              -------------------
00004     begin                : Tue Oct 24 2000
00005     copyright            : (C) 2000 by Martin Bickel
00006     email                : bickel@asc-hq.org
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "vehicletypeselector.h"
00019 #include "selectionwindow.h"
00020 #include "unitinfodialog.h"
00021 
00022 #include "../vehicletype.h"
00023 #include "../iconrepository.h"
00024 #include "../spfst.h"
00025 #include "../unitset.h"
00026 
00027 VehicleTypeBaseWidget :: VehicleTypeBaseWidget( PG_Widget* parent, const PG_Point& pos, int width, const Vehicletype* vehicletype, const Player& player ) : SelectionWidget( parent, PG_Rect( pos.x, pos.y, width, fieldsizey+10 )), vt( vehicletype ), actplayer(player)
00028 {
00029    int col1 = 50;
00030    int lineheight  = 20;
00031 
00032    int sw = (width - col1 - 10) / 6;
00033 
00034    PG_Label* lbl1 = new PG_Label( this, PG_Rect( col1, 0, 3 * sw, lineheight ), vt->name );
00035    lbl1->SetFontSize( lbl1->GetFontSize() -2 );
00036 
00037    PG_Label* lbl2 = new PG_Label( this, PG_Rect( col1, lineheight, 3 * sw, lineheight ), vt->description );
00038    lbl2->SetFontSize( lbl2->GetFontSize() -2 );
00039 
00040 
00041    PG_Button* b = new PG_Button( this, PG_Rect( buttonXPos(width, 0 ), Height()/2-lineheight, 2*lineheight, 2*lineheight ));
00042    b->SetIcon( IconRepository::getIcon( "blue-i.png").getBaseSurface() );
00043    b->sigClick.connect( SigC::slot( *this, &VehicleTypeBaseWidget::info ));
00044    
00045    SetTransparency( 255 );
00046 };
00047 
00048 int VehicleTypeBaseWidget::buttonXPos( int width, int num )
00049 {
00050    int col1 = 50;
00051    int sw = (width - col1 - 10) / 6;
00052    return col1 + 3 * sw + (10 + sw) * num;
00053 }
00054 
00055 
00056 
00057 bool VehicleTypeBaseWidget::info()
00058 {
00059    unitInfoDialog( vt );
00060    return true;
00061 }
00062 
00063 
00064 ASCString VehicleTypeBaseWidget::getName() const
00065 {
00066    return vt->getName();
00067 };
00068 
00069 void VehicleTypeBaseWidget::display( SDL_Surface * surface, const PG_Rect & src, const PG_Rect & dst )
00070 {
00071    if ( !getClippingSurface().valid() )
00072       getClippingSurface() = Surface::createSurface( fieldsizex + 10, fieldsizey + 10, 32, 0 );
00073 
00074    getClippingSurface().Fill(0);
00075 
00076    vt->paint( getClippingSurface(), SPoint(5,5), actplayer.getPlayerColor(), 0 );
00077    PG_Draw::BlitSurface( getClippingSurface().getBaseSurface(), src, surface, dst);
00078 }
00079 
00080 Surface VehicleTypeBaseWidget::clippingSurface;
00081 
00082 
00083 
00084 VehicleTypeResourceWidget::VehicleTypeResourceWidget( PG_Widget* parent, const PG_Point& pos, int width, const Vehicletype* vehicletype, int lackingResources, const Resources& cost, const Player& player )
00085    : VehicleTypeBaseWidget( parent,pos, width, vehicletype, player )
00086 {
00087    int col1 = 50;
00088    int lineheight  = 20;
00089 
00090    int sw = (width - col1 - 10) / 6;
00091 
00092    static const char* filenames[3] = { "energy.png", "material.png", "fuel.png" };
00093 
00094    for ( int i = 0; i < 3; ++i ) {
00095       new PG_Image ( this, PG_Point( col1 + 2 + 5 * sw, i * 12 + 5), IconRepository::getIcon( filenames[i] ).getBaseSurface(), false  );
00096       PG_Label* lbl = new PG_Label( this, PG_Rect( col1 + 3 * sw, i * 12, sw * 2, lineheight ), ASCString::toString(cost.resource(i)) );
00097       lbl->SetAlignment( PG_Label::RIGHT );
00098       lbl->SetFontSize( lbl->GetFontSize() - 3 );
00099       if ( lackingResources & (1<<i) )
00100          lbl->SetFontColor( 0xff0000);
00101    }
00102 }
00103       
00104 
00105 VehicleTypeCountWidget::VehicleTypeCountWidget( PG_Widget* parent, const PG_Point& pos, int width, const Vehicletype* vehicletype, const Player& player, int number )
00106    : VehicleTypeBaseWidget( parent,pos, width, vehicletype, player )
00107 {
00108    int col1 = 50;
00109    int lineheight  = 20;
00110 
00111    int sw = (width - col1 - 10) / 6;
00112 
00113    PG_Label* lbl = new PG_Label( this, PG_Rect( col1 + 4 * sw, 0, sw * 2, lineheight*2 ), ASCString::toString(number) );
00114    lbl->SetAlignment( PG_Label::RIGHT );
00115    lbl->SetFontSize( lbl->GetFontSize() + 5 );
00116 }
00117 
00118 VehicleTypeCountLocateWidget::VehicleTypeCountLocateWidget( PG_Widget* parent, const PG_Point& pos, int width, const Vehicletype* vehicletype, const Player& player, int number )
00119    : VehicleTypeCountWidget( parent, pos, width, vehicletype, player, number )
00120 {
00121    int lineheight  = 20;
00122    
00123    PG_Button* b = new PG_Button( this, PG_Rect( buttonXPos(width, 1 ), Height()/2-lineheight, 2*lineheight, 2*lineheight ));
00124    b->SetIcon( IconRepository::getIcon( "magnifier.png").getBaseSurface() );
00125    b->sigClick.connect( SigC::slot( *this, &VehicleTypeCountLocateWidget::locate ));
00126          
00127 }
00128 
00129 bool VehicleTypeCountLocateWidget::locate()
00130 {
00131    locateVehicles( getVehicletype() );
00132    return true;
00133 }
00134 
00135 
00136 VehicleTypeSelectionItemFactory :: VehicleTypeSelectionItemFactory( Resources plantResources, const Container& types, const Player& player ) : actplayer(player), showResourcesForUnit(true), original_items( types )
00137 {
00138    restart();
00139    setAvailableResource( plantResources );
00140 };
00141 
00142 VehicleTypeSelectionItemFactory :: VehicleTypeSelectionItemFactory( const Container& types, const Player& player ) : actplayer(player), showResourcesForUnit(false), original_items( types )
00143 {
00144    restart();
00145 };
00146 
00147 
00148 
00149 void VehicleTypeSelectionItemFactory::restart()
00150 {
00151    items = getOriginalItems();
00152    sort( items.begin(), items.end(), vehicleComp );
00153    it = items.begin();
00154 };
00155 
00156 
00157 SelectionWidget* VehicleTypeSelectionItemFactory::spawnNextItem( PG_Widget* parent, const PG_Point& pos )
00158 {
00159    if ( it != items.end() ) {
00160       const Vehicletype* v = *(it++);
00161       if ( showResourcesForUnit ) {
00162          Resources cost  = getCost(v);
00163 
00164          int lackingResources = 0;
00165          for ( int r = 0; r < 3; ++r )
00166             if ( plantResources.resource(r) < cost.resource(r))
00167                lackingResources |= 1 << r;
00168          return new VehicleTypeResourceWidget( parent, pos, parent->Width() - 15, v, lackingResources, cost, actplayer );
00169       } else
00170          return new VehicleTypeBaseWidget( parent, pos, parent->Width() - 15, v, actplayer );
00171    } else
00172       return NULL;
00173 };
00174 
00175 SigC::Signal1<void,const Vehicletype*> VehicleTypeSelectionItemFactory::showVehicleInfo;
00176 
00177 
00178 void VehicleTypeSelectionItemFactory::itemSelected( const SelectionWidget* widget, bool mouse )
00179 {
00180    if ( !widget )
00181       return;
00182 
00183    const VehicleTypeBaseWidget* fw = dynamic_cast<const VehicleTypeBaseWidget*>(widget);
00184    assert( fw );
00185 
00186    showVehicleInfo( fw->getVehicletype() );
00187    
00188    vehicleTypeSelected( fw->getVehicletype(), mouse );
00189 }
00190 

Generated on Tue Jun 24 01:27:55 2008 for Advanced Strategic Command by  doxygen 1.4.2