gameevent_dialogs.cpp

Go to the documentation of this file.
00001 
00005 /*
00006     This file is part of Advanced Strategic Command; http://www.asc-hq.de
00007     Copyright (C) 1994-2010  Martin Bickel  and  Marc Schellenberger
00008 
00009     This program is free software; you can redistribute it and/or modify
00010     it under the terms of the GNU General Public License as published by
00011     the Free Software Foundation; either version 2 of the License, or
00012     (at your option) any later version.
00013 
00014     This program is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017     GNU General Public License for more details.
00018 
00019     You should have received a copy of the GNU General Public License
00020     along with this program; see the file COPYING. If not, write to the 
00021     Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
00022     Boston, MA  02111-1307  USA
00023 */
00024 
00025 #include <stdio.h>
00026 
00027 #include "global.h"
00028 #include "buildingtype.h"
00029 #include "vehicletype.h"
00030 #include "newfont.h"
00031 #include "typen.h"
00032 // #include "basegfx.h"
00033 #include "dlg_box.h"
00034 #include "newfont.h"
00035 #include "vehicletype.h"
00036 #include "buildingtype.h"
00037 #include "spfst.h"
00038 
00039 #include "gameevents.h"
00040 // #include "events.h"
00041 #include "gameoptions.h"
00042 #include "loadimage.h"
00043 #include "errors.h"
00044 #include "itemrepository.h"
00045 #include "gameevent_dialogs.h"
00046 #include "dialog.h"
00047 #include "spfst-legacy.h"
00048 
00049 #include "dialogs/fieldmarker.h"
00050 #include "widgets/textrenderer.h"
00051 #include "dialogs/selectionwindow.h"
00052 #include "dialogs/vehicletypeselector.h"
00053 #include <pgpropertyeditor.h>
00054 #include <pgpropertyfield_checkbox.h>
00055 
00056 #ifdef karteneditor
00057 # include "edmisc.h"
00058 # include "edselfnt.h"
00059 # include "maped-mainscreen.h"
00060  extern int  selectfield(int * cx ,int  * cy);
00061 
00062 #else
00063 int  selectfield(int * cx ,int  * cy)
00064 {
00065   return 0;
00066 }
00067 void editpolygon (Poly_gon& poly) {};
00068 Vehicle* selectUnitFromMap() { return NULL; };
00069 #endif
00070 
00071 // �S GetXYSel
00072 
00073 bool chooseWeather( int& weather )
00074 {
00075 #ifdef karteneditor
00076    vector<ASCString> entries;
00077 
00078    for ( int w = 0; w < cwettertypennum; ++w )
00079       entries.push_back ( cwettertypen[ w ] );
00080 
00081    int value = chooseString ( "choose operation target", entries, weather );
00082    if ( value < 0 )
00083       return false;
00084    else
00085       weather = value;
00086 
00087 #endif
00088   return true;
00089 }
00090 
00091 bool chooseTerrain( int& terrainID )
00092 {
00093 #ifdef karteneditor
00094    selectItemID( terrainID, terrainTypeRepository );
00095 #endif
00096   return true;
00097 }
00098 
00099 bool chooseObject( int& objectID )
00100 {
00101 #ifdef karteneditor
00102    selectItemID( objectID, objectTypeRepository );
00103 #endif
00104   return true;
00105 }
00106 
00107 bool chooseVehicleType( int& vehicleTypeID )
00108 {
00109 #ifdef karteneditor
00110    selectItemID( vehicleTypeID, vehicleTypeRepository );
00111 #endif
00112   return true;
00113 }
00114 
00115 #if 0
00116 
00117 class  tgetxy : public tdialogbox {
00118               ASCString titlename;
00119           public :
00120               int action;
00121               int x,y;
00122               void init(void);
00123               virtual void run(void);
00124               virtual ASCString getTitle() { return "X/Y Pos"; };
00125               virtual int condition(void);
00126               virtual void buttonpressed(int id);
00127               };
00128 
00129 void         tgetxy::init(void)
00130 {
00131    tdialogbox::init();
00132 
00133    titlename = getTitle();
00134    title = titlename.c_str();
00135    x1 = 150;
00136    xsize = 320;
00137    y1 = 150;
00138    ysize = 140;
00139    action = 0;
00140 
00141    windowstyle = windowstyle ^ dlg_in3d;
00142 
00143 
00144    addbutton("~D~one",20,ysize - 40,100,ysize - 20,0,1,1,true);
00145    addkey(1,ct_enter);
00146    addbutton("~C~ancel",120,ysize - 40,200,ysize - 20,0,1,2,true);
00147    addbutton("~M~ap",220,ysize - 40,300,ysize - 20,0,1,3,true);
00148    addbutton("~X~-Pos",20,60,150,80,2,1,4,true);
00149    addeingabe(4,&x,-1,actmap->xsize - 1);
00150    addbutton("~Y~-Pos",170,60,300,80,2,1,5,true);
00151    addeingabe(5,&y,-1,actmap->ysize - 1);
00152 
00153    buildgraphics();
00154 
00155    mousevisible(true); 
00156 } 
00157 
00158 
00159 void         tgetxy::run(void)
00160 { 
00161 
00162    do { 
00163       tdialogbox::run(); 
00164    }  while (! ( (taste == ct_esc) || (action == 1) || (action == 2) ) );
00165    if ((action == 2) || (taste == ct_esc)) x = 50000; 
00166 } 
00167 
00168 int         tgetxy::condition(void)
00169 {
00170    return 1;
00171 }
00172 
00173 void         tgetxy::buttonpressed(int         id)
00174 {
00175 
00176    tdialogbox::buttonpressed(id);
00177    switch (id) {
00178 
00179       case 1:
00180       case 2:   action = id;
00181    break;
00182       case 3: {
00183                   mousevisible(false);
00184                   x = actmap->getCursor().x;
00185                   y = actmap->getCursor().y;
00186                   displaymap();
00187                   mousevisible(true);
00188                   do {
00189                      if ( !selectfield(&x,&y) )
00190                         break;
00191                   } while ( condition() != 1 ); /* enddo */
00192                   mousevisible(false);
00193                   redraw();
00194                   enablebutton(4);
00195                   enablebutton(5);
00196                   mousevisible(true);
00197                   
00198                 }
00199    break;
00200    } 
00201 } 
00202 
00203 
00204 void         getxy( int *x, int *y)
00205 { tgetxy       ce;
00206 
00207    ce.x = *x ;
00208    ce.y = *y ;
00209    ce.init();
00210    ce.run();
00211    if ( ce.x != 50000 )
00212    {
00213       *x = ce.x;
00214       *y = ce.y;
00215    }
00216    ce.done();
00217 }
00218 
00219 
00220 void selectFields( FieldAddressing::Fields& fields )
00221 {
00222    typedef vector<MapCoordinate>::iterator It;
00223    vector<MapCoordinate> backup = fields;
00224 
00225    actmap->cleartemps();
00226    for ( It i = fields.begin(); i != fields.end(); ++i )
00227       actmap->getField(*i)->a.temp = 1;
00228 
00229    displaymap();
00230    displaymessage("use space to select the fields\nfinish the selection by pressing enter",3);
00231    int res ;
00232    do {
00233       int x,y;
00234       res = selectfield(&x,&y);
00235       if ( res == 2 ) {
00236          It i = find ( fields.begin(), fields.end(), MapCoordinate (x,y) );
00237          if ( i != fields.end() ) {
00238             actmap->getField(*i)->a.temp = 0;
00239             fields.erase( i ); 
00240          } else {
00241             actmap->getField(x,y)->a.temp = 1;
00242             fields.push_back ( MapCoordinate(x,y));
00243          }
00244          displaymap();
00245       }
00246 
00247    } while ( res == 2 ); /* enddo */
00248 
00249    if ( res == 0 )
00250       fields = backup;
00251 
00252    actmap->cleartemps();
00253    displaymap();
00254 }
00255 
00256 
00257 // �S GetXYUnitSel
00258 
00259 class  tgetxyunit : public tgetxy {
00260           public :
00261               ASCString getTitle() { return "Select Unit"; };
00262               virtual int condition(void);
00263               //virtual bool container( ContainerBase* cnt );
00264               };
00265 
00266 
00267 int         tgetxyunit::condition(void)
00268 {
00269    if ( getfield( x, y ) )
00270       if ( getfield(x,y)->vehicle )
00271           return 1;
00272    return 0;
00273 }
00274 
00275 
00276 
00277 void         getxy_unit(int *x,int *y)
00278 { tgetxyunit       gu;
00279 
00280    gu.x = *x;
00281    gu.y = *y;
00282    gu.init();
00283    gu.run();
00284    *x = gu.x;
00285    *y = gu.y;
00286    gu.done();
00287 }
00288 
00289 class  tgetxybuilding : public tgetxy {
00290           public :
00291               virtual int condition(void);
00292               };
00293 
00294 
00295 // �S GetXYBuildingSel
00296 
00297 int         tgetxybuilding::condition(void)
00298 {
00299    if ( getfield( x, y ) )
00300       if ( getfield(x,y)->building ) 
00301           return 1;
00302    return 0;
00303 }
00304 
00305 void         getxy_building(int *x,int *y)
00306 { tgetxybuilding       gb;
00307 
00308    gb.x = *x ;
00309    gb.y = *y ;
00310    gb.init();
00311    gb.run();
00312    *x = gb.x;
00313    *y = gb.y;
00314    gb.done();
00315 } 
00316 
00317 
00318 #endif
00319 
00320 
00321 void         getxy_building(int *x,int *y)
00322 {
00323    SelectBuildingFromMap::CoordinateList list;
00324    list.push_back ( MapCoordinate( *x, *y ));
00325    
00326    SelectBuildingFromMap sbfm( list, actmap );
00327    sbfm.Show();
00328    sbfm.RunModal();
00329 
00330    if ( list.empty() ) {
00331       *x = -1;
00332       *y = -1;
00333    } else {
00334       *x = list.begin()->x;
00335       *y = list.begin()->y;
00336    }
00337 }
00338 
00339 void selectFields( FieldAddressing::Fields& fields )
00340 {
00341    SelectFromMap sbfm( fields, actmap );
00342    sbfm.Show();
00343    sbfm.RunModal();
00344 }
00345 
00346 class UnitListFactory: public SelectionItemFactory, public SigC::Object  {
00347    public:
00348       typedef list<const VehicleType*> UnitList;
00349    private:
00350       const UnitList& unitList;
00351    protected:
00352       UnitList::const_iterator it;
00353       void itemSelected( const SelectionWidget* widget, bool mouse ) 
00354       {
00355       };
00356    public:
00357       UnitListFactory( const UnitList& units )  : unitList( units )
00358       {
00359          restart();
00360       };
00361       
00362       void restart()
00363       {
00364          it = unitList.begin();
00365       }
00366       
00367       SelectionWidget* spawnNextItem( PG_Widget* parent, const PG_Point& pos )
00368       {
00369          if ( it != unitList.end() ) {
00370             const VehicleType* v = *(it++);
00371             return new VehicleTypeBaseWidget( parent, pos, parent->Width() - 15, v, actmap->getCurrentPlayer() );
00372          } else
00373             return NULL;
00374       };
00375 };
00376 
00377 
00378 
00379 class UnitAvailabilityWindow : public ItemSelectorWindow {
00380    private:
00381       bool eventKeyDown(const SDL_KeyboardEvent* key)
00382       {
00383          if ( key->keysym.sym == SDLK_RETURN ) {
00384             QuitModal();
00385             return true;
00386          }
00387          return ItemSelectorWindow::eventKeyDown( key );
00388       };
00389 
00390    public:
00391       UnitAvailabilityWindow ( PG_Widget *parent, const PG_Rect &r , const ASCString& title, UnitListFactory* itemFactory ) 
00392    : ItemSelectorWindow( parent, r, title, itemFactory ) 
00393       {
00394       };
00395 };      
00396 
00397 
00398 
00399 void ShowNewTechnology::showTechnology( const Technology* tech, const TechnologyPresenter::Gadgets& newGadgetsAvailable )
00400 {
00401    if ( tech ) {
00402       ASCString text = "#fontsize=18#Research completed#fontsize=12#\n\n";
00403 
00404       text = "Our scientists have mastered a new technology:\n\n#fontsize=18#";
00405 
00406       text += tech->name + "#fontsize=12#\n\n";
00407 
00408       if ( tech->relatedUnitID > 0 )
00409          text += "#vehicletype=" + ASCString::toString(tech->relatedUnitID) + "#\n\n";
00410 
00411       text += tech->infotext;
00412 
00413       if ( newGadgetsAvailable.units.size() ) {
00414          text += "\n#fontsize=15#\nNew units available for production:#fontsize=12#\n";
00415          
00416          for ( std::list<const VehicleType*>::const_iterator i = newGadgetsAvailable.units.begin(); i != newGadgetsAvailable.units.end(); ++i )
00417             text += "#vehicletype=" + ASCString::toString((*i)->id) + "#\n";
00418       }
00419       
00420       ViewFormattedText tr ("Research", text, PG_Rect(-1,-1, 400,250) );
00421       tr.Show();
00422       tr.RunModal();
00423    }
00424 }
00425 
00426 
00427 
00428 int selectunit ( int unitnetworkid )
00429 {
00430   SelectUnitFromMap::CoordinateList list;
00431 
00432   Vehicle* v = actmap->getUnit ( unitnetworkid );
00433   if ( v )
00434       list.push_back ( v->getPosition() );
00435 
00436   SelectUnitFromMap sufm ( list, actmap );
00437   sufm.Show();
00438   sufm.RunModal();
00439 
00440   if ( list.empty() )
00441      return 0;
00442   
00443   MapField* fld = actmap->getField( *list.begin() );
00444   if ( fld && fld->vehicle )
00445      return fld->vehicle->networkid;
00446   else
00447      return 0;
00448 }
00449 
00450 
00451 class  tplayerselall : public tdialogbox {
00452           public :
00453               int action;
00454               int bkgcolor;
00455               int playerbit;
00456               void init(void);
00457               virtual void run(void);
00458               virtual void buttonpressed(int id);
00459               void anzeige(void);
00460               };
00461 
00462 
00463 
00464 
00465 void         tplayerselall::init(void)
00466 {
00467    char *s1;
00468 
00469    tdialogbox::init(); 
00470    title = "Player Select";
00471    x1 = 50;
00472    xsize = 370;
00473    y1 = 50;
00474    ysize = 380;
00475    action = 0;
00476    bkgcolor = lightgray;
00477 
00478    windowstyle = windowstyle ^ dlg_in3d;
00479 
00480    int i;
00481    for (i=0;i<8 ;i++ ) {
00482       s1 = new(char[12]);
00483       strcpy(s1,"Player ~");
00484       strcat(s1,strrr(i+1));
00485       strcat(s1,"~");
00486       addbutton(s1,20,55+i*30,150,75+i*30,0,1,6+i,true);
00487       addkey(1,ct_1+i);
00488    }
00489 
00490 //   addbutton("~A~ll not allied",20,ysize - 40,170,ysize - 20,0,1,1,true);
00491 //   addkey(1,ct_enter);
00492    addbutton("~O~K",200,ysize - 40,350,ysize - 20,0,1,2,true);
00493 
00494    buildgraphics();
00495 
00496    for ( i=0; i<8 ;i++ )
00497       bar(x1 + 170,y1 + 60 + i*30 ,x1 + 190 ,y1 + 70 + i * 30,20 + ( i << 3 ));
00498 
00499    anzeige();
00500 
00501    mousevisible(true);
00502 }
00503 
00504 void         tplayerselall::anzeige(void)
00505 {
00506    mousevisible(false);
00507    for (int i=0;i<8 ;i++ ) {
00508       if ( playerbit & ( 1 << i ) ) 
00509          rectangle (x1 + 16,y1+51+i*30,x1+154,y1+79+i*30, 20 );
00510       else
00511          rectangle (x1 + 16,y1+51+i*30,x1+154,y1+79+i*30, bkgcolor );
00512    }
00513    mousevisible(true);
00514 }
00515 
00516 
00517 void         tplayerselall::run(void)
00518 {
00519 
00520    do {
00521       tdialogbox::run();
00522       // if (taste == ct_f1) help ( 1060 );
00523    }  while (!((taste == ct_esc) || ((action == 1) || (action ==2))));
00524    if ((action == 1) || (taste == ct_esc))
00525       playerbit = 1;
00526 }
00527 
00528 
00529 void         tplayerselall::buttonpressed(int         id)
00530 {
00531    tdialogbox::buttonpressed(id);
00532    switch (id) {
00533 
00534       case 1:
00535       case 2:   action = id;
00536         break;
00537       case 6:
00538       case 7:
00539       case 8:
00540       case 9:
00541       case 10:
00542       case 11:
00543       case 12:
00544       case 13: {
00545             playerbit ^=  1 << ( id-6 ) ;
00546          anzeige();
00547       }
00548    break; 
00549    } 
00550 } 
00551 
00552 
00553 void playerselall( int *playerbitmap)
00554 { tplayerselall       sc;
00555 
00556    sc.playerbit = *playerbitmap;
00557    sc.init();
00558    sc.run();
00559    sc.done();
00560    *playerbitmap = sc.playerbit;
00561 }
00562 
00563 
00564 
00565 bool ReinforcementSelector::mark()
00566 {
00567    MapCoordinate pos = actmap->getCursor();
00568    if  ( !accept(pos))
00569       return false;
00570 
00571    CoordinateList::iterator i = find( coordinateList.begin(), coordinateList.end(), pos );
00572    if ( i == coordinateList.end() )
00573       coordinateList.push_back ( pos );
00574 
00575    cut( pos );
00576 
00577    showFieldMarking( coordinateList );
00578 
00579    updateList();
00580    return true;
00581 }
00582 
00583 void ReinforcementSelector::cut( const MapCoordinate& pos )
00584 {
00585    MapField* fld = actmap->getField( pos );
00586    if (!fld )
00587       return;
00588 
00589    cutPositions.push_back( pos );
00590    
00591    if ( fld->vehicle ) {
00592       MemoryStream stream ( &buf, tnstream::appending );
00593       stream.writeInt( Reinforcements::ReinfVehicle );
00594       fld->vehicle->write ( stream );
00595       objectNum++;
00596       delete fld->vehicle;
00597       fld->vehicle = NULL;
00598    } else
00599       if ( fld->building ) {
00600          MemoryStream stream ( &buf, tnstream::appending );
00601          stream.writeInt( Reinforcements::ReinfBuilding );
00602          fld->building->write ( stream );
00603          objectNum++;
00604          delete fld->building;
00605          fld->building = NULL;
00606       }
00607 }
00608 
00609 
00610 bool ReinforcementSelector::isOk()
00611 {
00612    for ( CoordinateList::const_iterator i = coordinateList.begin(); i !=  coordinateList.end(); ++i  ) 
00613       if ( find( cutPositions.begin(), cutPositions.end(), *i ) == cutPositions.end() )
00614          cut( *i );
00615    return true;  
00616 }
00617 
00618 
00619 bool BitMapEditor::ok()
00620 {
00621    reference = 0;
00622    propertyEditor->Apply();
00623    for ( int i = 0; i < bitCount; ++i ) 
00624       if ( values[i] )
00625          reference |= 1 << i;
00626 
00627    QuitModal();
00628    return true;
00629 }
00630 
00631 BitMapEditor::BitMapEditor( BitType& value, const ASCString& title, const vector<ASCString>& names ) : ASC_PG_Dialog(NULL, PG_Rect(-1,-1,300,500), title ), reference(value)
00632 {
00633    propertyEditor = new ASC_PropertyEditor( this, PG_Rect( 10, GetTitlebarHeight(), Width() - 20, Height() - GetTitlebarHeight() - 50 ), "PropertyEditor", 70 );
00634 
00635 
00636    bitCount = names.size();
00637    int counter = 0;
00638    for ( vector<ASCString>::const_iterator i = names.begin(); i != names.end(); ++i ) {
00639       bool v = value & (1 << counter );
00640       values[counter] = v;
00641       new PG_PropertyField_Checkbox<bool>( propertyEditor, *i, &(values[counter]) );
00642       ++counter;
00643    }
00644 
00645    PG_Button* ok = new PG_Button( this, PG_Rect( Width() - 100, Height() - 40, 90, 30), "OK" );
00646    ok->sigClick.connect( SigC::slot( *this, &BitMapEditor::ok ));
00647 }
00648 

Generated on Mon May 21 01:26:33 2012 for Advanced Strategic Command by  doxygen 1.5.1