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

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-2005  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 
00048 #include "dialogs/fieldmarker.h"
00049 #include "widgets/textrenderer.h"
00050 #include <pgpropertyeditor.h>
00051 #include <pgpropertyfield_checkbox.h>
00052 
00053 #ifdef karteneditor
00054 # include "edmisc.h"
00055 # include "edselfnt.h"
00056 # include "maped-mainscreen.h"
00057  extern int  selectfield(int * cx ,int  * cy);
00058 
00059 #else
00060 int  selectfield(int * cx ,int  * cy)
00061 {
00062   return 0;
00063 }
00064 void editpolygon (Poly_gon& poly) {};
00065 Vehicle* selectUnitFromMap() { return NULL; };
00066 #endif
00067 
00068 // �S GetXYSel
00069 
00070 bool chooseWeather( int& weather )
00071 {
00072 #ifdef karteneditor
00073    vector<ASCString> entries;
00074 
00075    for ( int w = 0; w < cwettertypennum; ++w )
00076       entries.push_back ( cwettertypen[ w ] );
00077 
00078    int value = chooseString ( "choose operation target", entries, weather );
00079    if ( value < 0 )
00080       return false;
00081    else
00082       weather = value;
00083 
00084 #endif
00085   return true;
00086 }
00087 
00088 bool chooseTerrain( int& terrainID )
00089 {
00090 #ifdef karteneditor
00091    selectItemID( terrainID, terrainTypeRepository );
00092 #endif
00093   return true;
00094 }
00095 
00096 bool chooseObject( int& objectID )
00097 {
00098 #ifdef karteneditor
00099    selectItemID( objectID, objectTypeRepository );
00100 #endif
00101   return true;
00102 }
00103 
00104 bool chooseVehicleType( int& vehicleTypeID )
00105 {
00106 #ifdef karteneditor
00107    selectItemID( vehicleTypeID, vehicleTypeRepository );
00108 #endif
00109   return true;
00110 }
00111 
00112 #if 0
00113 
00114 class  tgetxy : public tdialogbox {
00115               ASCString titlename;
00116           public :
00117               int action;
00118               int x,y;
00119               void init(void);
00120               virtual void run(void);
00121               virtual ASCString getTitle() { return "X/Y Pos"; };
00122               virtual int condition(void);
00123               virtual void buttonpressed(int id);
00124               };
00125 
00126 void         tgetxy::init(void)
00127 {
00128    tdialogbox::init();
00129 
00130    titlename = getTitle();
00131    title = titlename.c_str();
00132    x1 = 150;
00133    xsize = 320;
00134    y1 = 150;
00135    ysize = 140;
00136    action = 0;
00137 
00138    windowstyle = windowstyle ^ dlg_in3d;
00139 
00140 
00141    addbutton("~D~one",20,ysize - 40,100,ysize - 20,0,1,1,true);
00142    addkey(1,ct_enter);
00143    addbutton("~C~ancel",120,ysize - 40,200,ysize - 20,0,1,2,true);
00144    addbutton("~M~ap",220,ysize - 40,300,ysize - 20,0,1,3,true);
00145    addbutton("~X~-Pos",20,60,150,80,2,1,4,true);
00146    addeingabe(4,&x,-1,actmap->xsize - 1);
00147    addbutton("~Y~-Pos",170,60,300,80,2,1,5,true);
00148    addeingabe(5,&y,-1,actmap->ysize - 1);
00149 
00150    buildgraphics();
00151 
00152    mousevisible(true); 
00153 } 
00154 
00155 
00156 void         tgetxy::run(void)
00157 { 
00158 
00159    do { 
00160       tdialogbox::run(); 
00161    }  while (! ( (taste == ct_esc) || (action == 1) || (action == 2) ) );
00162    if ((action == 2) || (taste == ct_esc)) x = 50000; 
00163 } 
00164 
00165 int         tgetxy::condition(void)
00166 {
00167    return 1;
00168 }
00169 
00170 void         tgetxy::buttonpressed(int         id)
00171 {
00172 
00173    tdialogbox::buttonpressed(id);
00174    switch (id) {
00175 
00176       case 1:
00177       case 2:   action = id;
00178    break;
00179       case 3: {
00180                   mousevisible(false);
00181                   x = actmap->getCursor().x;
00182                   y = actmap->getCursor().y;
00183                   displaymap();
00184                   mousevisible(true);
00185                   do {
00186                      if ( !selectfield(&x,&y) )
00187                         break;
00188                   } while ( condition() != 1 ); /* enddo */
00189                   mousevisible(false);
00190                   redraw();
00191                   enablebutton(4);
00192                   enablebutton(5);
00193                   mousevisible(true);
00194                   
00195                 }
00196    break;
00197    } 
00198 } 
00199 
00200 
00201 void         getxy( int *x, int *y)
00202 { tgetxy       ce;
00203 
00204    ce.x = *x ;
00205    ce.y = *y ;
00206    ce.init();
00207    ce.run();
00208    if ( ce.x != 50000 )
00209    {
00210       *x = ce.x;
00211       *y = ce.y;
00212    }
00213    ce.done();
00214 }
00215 
00216 
00217 void selectFields( FieldAddressing::Fields& fields )
00218 {
00219    typedef vector<MapCoordinate>::iterator It;
00220    vector<MapCoordinate> backup = fields;
00221 
00222    actmap->cleartemps();
00223    for ( It i = fields.begin(); i != fields.end(); ++i )
00224       actmap->getField(*i)->a.temp = 1;
00225 
00226    displaymap();
00227    displaymessage("use space to select the fields\nfinish the selection by pressing enter",3);
00228    int res ;
00229    do {
00230       int x,y;
00231       res = selectfield(&x,&y);
00232       if ( res == 2 ) {
00233          It i = find ( fields.begin(), fields.end(), MapCoordinate (x,y) );
00234          if ( i != fields.end() ) {
00235             actmap->getField(*i)->a.temp = 0;
00236             fields.erase( i ); 
00237          } else {
00238             actmap->getField(x,y)->a.temp = 1;
00239             fields.push_back ( MapCoordinate(x,y));
00240          }
00241          displaymap();
00242       }
00243 
00244    } while ( res == 2 ); /* enddo */
00245 
00246    if ( res == 0 )
00247       fields = backup;
00248 
00249    actmap->cleartemps();
00250    displaymap();
00251 }
00252 
00253 
00254 // �S GetXYUnitSel
00255 
00256 class  tgetxyunit : public tgetxy {
00257           public :
00258               ASCString getTitle() { return "Select Unit"; };
00259               virtual int condition(void);
00260               //virtual bool container( ContainerBase* cnt );
00261               };
00262 
00263 
00264 int         tgetxyunit::condition(void)
00265 {
00266    if ( getfield( x, y ) )
00267       if ( getfield(x,y)->vehicle )
00268           return 1;
00269    return 0;
00270 }
00271 
00272 
00273 
00274 void         getxy_unit(int *x,int *y)
00275 { tgetxyunit       gu;
00276 
00277    gu.x = *x;
00278    gu.y = *y;
00279    gu.init();
00280    gu.run();
00281    *x = gu.x;
00282    *y = gu.y;
00283    gu.done();
00284 }
00285 
00286 class  tgetxybuilding : public tgetxy {
00287           public :
00288               virtual int condition(void);
00289               };
00290 
00291 
00292 // �S GetXYBuildingSel
00293 
00294 int         tgetxybuilding::condition(void)
00295 {
00296    if ( getfield( x, y ) )
00297       if ( getfield(x,y)->building ) 
00298           return 1;
00299    return 0;
00300 }
00301 
00302 void         getxy_building(int *x,int *y)
00303 { tgetxybuilding       gb;
00304 
00305    gb.x = *x ;
00306    gb.y = *y ;
00307    gb.init();
00308    gb.run();
00309    *x = gb.x;
00310    *y = gb.y;
00311    gb.done();
00312 } 
00313 
00314 
00315 #endif
00316 
00317 
00318 void         getxy_building(int *x,int *y)
00319 {
00320    SelectBuildingFromMap::CoordinateList list;
00321    list.push_back ( MapCoordinate( *x, *y ));
00322    
00323    SelectBuildingFromMap sbfm( list, actmap );
00324    sbfm.Show();
00325    sbfm.RunModal();
00326 
00327    if ( list.empty() ) {
00328       *x = -1;
00329       *y = -1;
00330    } else {
00331       *x = list.begin()->x;
00332       *y = list.begin()->y;
00333    }
00334 }
00335 
00336 void selectFields( FieldAddressing::Fields& fields )
00337 {
00338    SelectFromMap sbfm( fields, actmap );
00339    sbfm.Show();
00340    sbfm.RunModal();
00341 }
00342 
00343 
00344 
00345 NewVehicleTypeDetection::NewVehicleTypeDetection(  )
00346 {
00347    buf = new bool[ vehicleTypeRepository.getNum() ];
00348 
00349    for ( int i=0; i < vehicleTypeRepository.getNum() ; i++ )
00350       buf[i] = actmap->player[ actmap->actplayer ].research.vehicletypeavailable ( vehicleTypeRepository.getObject_byPos ( i ) );
00351 }
00352 
00353 
00354 
00355 void    NewVehicleTypeDetection::evalbuffer( void )
00356 {
00357    int num = 0;
00358    for ( int i=0; i < vehicleTypeRepository.getNum() ;i++ ) {
00359       if (buf[i] == 0) {
00360           buf[i] = actmap->player[ actmap->actplayer ].research.vehicletypeavailable ( vehicleTypeRepository.getObject_byPos ( i ) );
00361           if ( buf[i] )
00362              num++;
00363       } else
00364           buf[i] = 0;
00365 
00366    }
00367 
00368    if ( num ) {
00369       tshownewtanks snt;
00370       snt.init ( buf );
00371       snt.run  ();
00372       snt.done ();
00373    }
00374 
00375 }
00376 
00377 NewVehicleTypeDetection::~NewVehicleTypeDetection()
00378 {
00379    delete[] buf ;
00380 }
00381 
00382 #if 0
00383 
00384  class   tshowtechnology : public tdialogbox {
00385                public:
00386                   const Technology*       tech;
00387                   void              init( const Technology* acttech );
00388                   virtual void      run ( void );
00389                   void              showtec ( void );
00390          };
00391 
00392 
00393 void         tshowtechnology::init(  const Technology* acttech  )
00394 { 
00395    tdialogbox::init();
00396    title = "new technology";
00397    buildgraphics();
00398    tech = acttech;
00399 } 
00400 
00401 
00402 void         tshowtechnology::showtec(void)
00403 { 
00404    const char         *wort1, *wort2;
00405    const char         *pc, *w2;
00406    int          xp, yp, w;
00407 
00408    activefontsettings.font = schriften.large; 
00409    activefontsettings.justify = centertext;
00410    activefontsettings.length = xsize - 40;
00411    showtext2(tech->name,x1 + 20,y1 + starty + 10); 
00412    activefontsettings.justify = lefttext; 
00413 
00414    yp = 60; 
00415 
00416    if (tech->icon) {
00417       int xs,ys;
00418       getpicsize ( (trleheader*) tech->icon, xs, ys );
00419       putimage ( x1 + ( xsize - xs) / 2 , y1 + starty + 45 , tech->icon );
00420       yp += ys + 10;
00421    }
00422 
00423 
00424 
00425    wort1 = new char[100];
00426    wort2 = new char[100];
00427    strcpy( wort1, "research points: " );
00428    itoa ( tech->researchpoints, wort2, 10 );
00429    strcat( wort1, wort2 );
00430 
00431    activefontsettings.font = schriften.smallarial; 
00432    showtext2(wort1, x1 + 30,y1 + yp);
00433 
00434    if ( !tech->infotext.empty()) {
00435       activefontsettings.color = black; 
00436       xp = 0; 
00437       pc = tech->infotext.c_str();
00438       while (*pc ) {
00439          w2 = wort1;
00440          while ( *pc  && *pc != ' ' && *pc != '-' ) {
00441             *w2 = *pc;
00442             w2++;
00443             pc++;
00444          };
00445          *w2 = *pc;
00446          if (*pc) {
00447             w2++;
00448             pc++;
00449          }
00450          *w2=0;
00451          
00452          w = gettextwdth(wort1,NULL);
00453          if (xp + w > xsize - 40) { 
00454             yp = yp + 5 + activefontsettings.font->height; 
00455             xp = 0; 
00456          } 
00457          showtext2(wort1,x1 + xp + 20,y1 + starty + yp);
00458          xp += w;
00459       }
00460    }
00461    delete[] wort1 ;
00462    delete[] wort2 ;
00463 }
00464 
00465 
00466 
00467 void         tshowtechnology::run(void)
00468 {
00469    showtec();
00470    do {
00471       tdialogbox::run();
00472    }  while ( (taste != ct_esc) && (taste != ct_space) && (taste != ct_enter) );
00473 }
00474 
00475 #endif
00476 
00477 
00478 void         showtechnology(const Technology*  tech )
00479 {
00480    if ( tech ) {
00481       ASCString text = "#fontsize=18#Research completed#fontsize=12#\n";
00482 
00483       text = "Our scientists have mastered a new technology:\n#fontsize=18#";
00484 
00485       text += tech->name + "#fontsize=12#\n";
00486 
00487       if ( tech->relatedUnitID > 0 )
00488          text += "#vehicletype=" + ASCString::toString(tech->relatedUnitID) + "#\n\n";
00489 
00490       text += tech->infotext;
00491 
00492       ViewFormattedText tr ("Research", text, PG_Rect(-1,-1, 300,250) );
00493       tr.Show();
00494       tr.RunModal();
00495    }
00496 }
00497 
00498 
00499 void  tshownewtanks :: init ( bool*      buf2 )
00500 {
00501    tdialogbox::init();
00502 
00503    title = "new units available";
00504    xsize = 400;
00505    x1 = 120;
00506    y1 = 100;
00507    ysize = 280;
00508 
00509    addbutton("~o~k", 10, ysize - 35, xsize - 10, ysize - 10, 0, 1, 1 , true );
00510    addkey(1, ct_enter);
00511    addkey(1, ct_space);
00512 
00513    buildgraphics();
00514 
00515    activefontsettings.font = schriften.smallarial;
00516    activefontsettings.color = black;
00517    activefontsettings.background = 255;
00518    activefontsettings.justify = lefttext;
00519    activefontsettings.length = xsize - 80;
00520 
00521    buf = buf2;
00522    int i, num = 0;
00523    for (i=0; i < vehicleTypeRepository.getNum() ;i++ ) {
00524       if ( buf[i] ) {
00525          Vehicletype* tnk = vehicleTypeRepository.getObject_byPos ( i );
00526          if ( tnk ) {
00527             bar ( x1 + 25, y1 + 45 + num * 50, x1 + 65, y1 + 85 + num * 50, dblue );
00528             tnk->paint( getActiveSurface(), SPoint (  x1 + 30, y1 + 50 + num * 50), actmap->getCurrentPlayer().getPlayerColor() );
00529             showtext2( tnk -> name, x1 + 70, y1 + 45 + num * 50 );
00530             showtext2( tnk -> description, x1 + 70, y1 + 45 + 40 + num * 50 - activefontsettings.font->height );
00531             num++;
00532          }
00533       }
00534 
00535    } /* endfor */
00536 }
00537 
00538 void  tshownewtanks :: run ( void )
00539 {
00540    status = 0;
00541    mousevisible(true);
00542    do {
00543       tdialogbox :: run ();
00544    } while ( status == 0 ); /* enddo */
00545 }
00546 
00547 void  tshownewtanks :: buttonpressed ( int id )
00548 {
00549    if (id == 1)
00550       status = 1;
00551 }
00552 
00553 
00554 int selectunit ( int unitnetworkid )
00555 {
00556   SelectUnitFromMap::CoordinateList list;
00557 
00558   Vehicle* v = actmap->getUnit ( unitnetworkid );
00559   if ( v )
00560       list.push_back ( v->getPosition() );
00561 
00562   SelectUnitFromMap sufm ( list, actmap );
00563   sufm.Show();
00564   sufm.RunModal();
00565 
00566   if ( list.empty() )
00567      return 0;
00568   
00569   tfield* fld = actmap->getField( *list.begin() );
00570   if ( fld && fld->vehicle )
00571      return fld->vehicle->networkid;
00572   else
00573      return 0;
00574 }
00575 
00576 
00577 class  tplayerselall : public tdialogbox {
00578           public :
00579               int action;
00580               int bkgcolor;
00581               int playerbit;
00582               void init(void);
00583               virtual void run(void);
00584               virtual void buttonpressed(int id);
00585               void anzeige(void);
00586               };
00587 
00588 
00589 
00590 
00591 void         tplayerselall::init(void)
00592 {
00593    char *s1;
00594 
00595    tdialogbox::init(); 
00596    title = "Player Select";
00597    x1 = 50;
00598    xsize = 370;
00599    y1 = 50;
00600    ysize = 380;
00601    action = 0;
00602    bkgcolor = lightgray;
00603 
00604    windowstyle = windowstyle ^ dlg_in3d;
00605 
00606    int i;
00607    for (i=0;i<8 ;i++ ) {
00608       s1 = new(char[12]);
00609       strcpy(s1,"Player ~");
00610       strcat(s1,strrr(i+1));
00611       strcat(s1,"~");
00612       addbutton(s1,20,55+i*30,150,75+i*30,0,1,6+i,true);
00613       addkey(1,ct_1+i);
00614    }
00615 
00616 //   addbutton("~A~ll not allied",20,ysize - 40,170,ysize - 20,0,1,1,true);
00617 //   addkey(1,ct_enter);
00618    addbutton("~O~K",200,ysize - 40,350,ysize - 20,0,1,2,true);
00619 
00620    buildgraphics();
00621 
00622    for ( i=0; i<8 ;i++ )
00623       bar(x1 + 170,y1 + 60 + i*30 ,x1 + 190 ,y1 + 70 + i * 30,20 + ( i << 3 ));
00624 
00625    anzeige();
00626 
00627    mousevisible(true);
00628 }
00629 
00630 void         tplayerselall::anzeige(void)
00631 {
00632    mousevisible(false);
00633    for (int i=0;i<8 ;i++ ) {
00634       if ( playerbit & ( 1 << i ) ) 
00635          rectangle (x1 + 16,y1+51+i*30,x1+154,y1+79+i*30, 20 );
00636       else
00637          rectangle (x1 + 16,y1+51+i*30,x1+154,y1+79+i*30, bkgcolor );
00638    }
00639    mousevisible(true);
00640 }
00641 
00642 
00643 void         tplayerselall::run(void)
00644 {
00645 
00646    do {
00647       tdialogbox::run();
00648       // if (taste == ct_f1) help ( 1060 );
00649    }  while (!((taste == ct_esc) || ((action == 1) || (action ==2))));
00650    if ((action == 1) || (taste == ct_esc))
00651       playerbit = 1;
00652 }
00653 
00654 
00655 void         tplayerselall::buttonpressed(int         id)
00656 {
00657    tdialogbox::buttonpressed(id);
00658    switch (id) {
00659 
00660       case 1:
00661       case 2:   action = id;
00662         break;
00663       case 6:
00664       case 7:
00665       case 8:
00666       case 9:
00667       case 10:
00668       case 11:
00669       case 12:
00670       case 13: {
00671             playerbit ^=  1 << ( id-6 ) ;
00672          anzeige();
00673       }
00674    break; 
00675    } 
00676 } 
00677 
00678 
00679 void playerselall( int *playerbitmap)
00680 { tplayerselall       sc;
00681 
00682    sc.playerbit = *playerbitmap;
00683    sc.init();
00684    sc.run();
00685    sc.done();
00686    *playerbitmap = sc.playerbit;
00687 }
00688 
00689 
00690 
00691 bool ReinforcementSelector::mark()
00692 {
00693    MapCoordinate pos = actmap->getCursor();
00694    if  ( !accept(pos))
00695       return false;
00696 
00697    CoordinateList::iterator i = find( coordinateList.begin(), coordinateList.end(), pos );
00698    if ( i == coordinateList.end() )
00699       coordinateList.push_back ( pos );
00700 
00701    tfield* fld = actmap->getField( pos );
00702    if (!fld )
00703       return false;
00704 
00705    if ( fld->vehicle ) {
00706       tmemorystream stream ( &buf, tnstream::appending );
00707       stream.writeInt( Reinforcements::ReinfVehicle );
00708       fld->vehicle->write ( stream );
00709       objectNum++;
00710       delete fld->vehicle;
00711       fld->vehicle = NULL;
00712    } else
00713       if ( fld->building ) {
00714          tmemorystream stream ( &buf, tnstream::appending );
00715          stream.writeInt( Reinforcements::ReinfBuilding );
00716          fld->building->write ( stream );
00717          objectNum++;
00718          delete fld->building;
00719          fld->building = NULL;
00720       }
00721 
00722    showFieldMarking( coordinateList );
00723 
00724    updateList();
00725    return true;
00726 }
00727 
00728 
00729 
00730 
00731 bool BitMapEditor::ok()
00732 {
00733    reference = 0;
00734    propertyEditor->Apply();
00735    for ( int i = 0; i < bitCount; ++i ) 
00736       if ( values[i] )
00737          reference |= 1 << i;
00738 
00739    QuitModal();
00740    return true;
00741 }
00742 
00743 BitMapEditor::BitMapEditor( BitType& value, const ASCString& title, const vector<ASCString>& names ) : ASC_PG_Dialog(NULL, PG_Rect(-1,-1,300,500), title ), reference(value)
00744 {
00745    propertyEditor = new ASC_PropertyEditor( this, PG_Rect( 10, GetTitlebarHeight(), Width() - 20, Height() - GetTitlebarHeight() - 50 ), "PropertyEditor", 70 );
00746 
00747 
00748    bitCount = names.size();
00749    int counter = 0;
00750    for ( vector<ASCString>::const_iterator i = names.begin(); i != names.end(); ++i ) {
00751       bool v = value & (1 << counter );
00752       values[counter] = v;
00753       new PG_PropertyField_Checkbox<bool>( propertyEditor, *i, &(values[counter]) );
00754       ++counter;
00755    }
00756 
00757    PG_Button* ok = new PG_Button( this, PG_Rect( Width() - 100, Height() - 40, 90, 30), "OK" );
00758    ok->sigClick.connect( SigC::slot( *this, &BitMapEditor::ok ));
00759 }
00760 

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