dialog.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 
00026 #include <stdio.h>
00027 #include <cstring>
00028 #include <ctype.h>
00029 #include <stdlib.h>
00030 #include <stdarg.h>
00031 
00032 #include "typen.h"
00033 #include "buildingtype.h"
00034 #include "vehicletype.h"
00035 #include "basegfx.h"
00036 #include "newfont.h"
00037 #include "spfst.h"
00038 #include "loaders.h"
00039 #include "misc.h"
00040 #include "events.h"
00041 #include "stack.h"
00042 #include "dlg_box.h"
00043 #include "dialog.h"
00044 #include "sgstream.h"
00045 #include "attack.h"
00046 #include "gameoptions.h"
00047 #include "errors.h"
00048 // #include "password_dialog.h"
00049 #include "itemrepository.h"
00050 #include "mapdisplay.h"
00051 #include "graphicset.h"
00052 #include "viewcalculation.h"
00053 #include "paradialog.h"
00054 #include "cannedmessages.h"
00055 
00056 #include "dialogs/messagedialog.h"
00057 #include "dialogs/fileselector.h"
00058 #include "widgets/textrenderer.h"
00059 #include "unitset.h"
00060 
00061 #include "spfst-legacy.h"
00062 
00063 
00064 #define markedlettercolor red
00065 
00066 
00067 #if 0
00068 
00069 
00070 void         doubleline(int x1, int y1, int x2, int y2)
00071 { 
00072    line(x1,y1,x2,y2,white);          
00073    line(x1 + 1,y1 + 1,x2 + 1,y2 + 1,dbluedark); 
00074 } 
00075 
00076 
00077 class  tstatistics : public tdialogbox {
00078               public:
00079                    int          linelength;
00080                    char         categories;
00081                    int          l[3][4];
00082                    int          m[3][9];
00083                    char         paintmode;
00084                    char         color1,color2,color3,color4;
00085                    char         action;
00086 
00087                    void         init ( void );
00088                    void         paintgraph ( void );
00089                    virtual void buttonpressed( int id );
00090                 };
00091                                     
00092 class  tstatisticbuildings : public tstatistics {
00093                 public:
00094                    void         init ( void );
00095                    virtual void run ( void );
00096                    void         count ( void );
00097                };
00098 
00099 class  tstatisticarmies : public tstatistics {
00100                    char         jk;
00101                 public:
00102                    void         init ( void );
00103                    virtual void run ( void );
00104                    void         count ( void );
00105                    void         newknopfdruck ( integer      xx1,
00106                                                 integer      yy1,
00107                                                 integer      xx2,
00108                                                 integer      yy2 );
00109                };
00110 
00111 
00112 
00113 
00114 void         tstatisticarmies ::newknopfdruck(integer      xx1,
00115                            integer      yy1,
00116                            integer      xx2,
00117                            integer      yy2)
00118 { 
00119     char*      p; 
00120     bool      kn; 
00121     integer      mt; 
00122     {
00123         collategraphicoperations cgo ( xx1, yy1, xx2, yy2 );
00124         mt = mouseparams.taste;
00125         mousevisible(false);
00126         p = new char [ imagesize ( xx1 + 1,yy1 + 1,xx2 - 2,yy2 - 2 )];
00127         getimage(xx1 + 1,yy1 + 1,xx2 - 2,yy2 - 2, p);
00128         putimage(xx1 + 3,yy1 + 3, p);
00129 
00130         line(xx1 - 1,yy1 - 1,xx2 + 1,yy1 - 1, 8);
00131         line(xx1 - 1,yy1 - 1,xx1 - 1,yy2 + 1, 8);
00132 
00133         line(xx2 + 1,yy1 - 1,xx2 + 1,yy2 + 1, 15);
00134         line(xx1 - 1,yy2 + 1,xx2 + 1,yy2 + 1, 15);
00135 
00136         line(xx1,yy1,xx2,yy1, 8);
00137         line(xx1,yy1,xx1,yy2, 8);
00138 
00139         line(xx2,yy1,xx2,yy2, 15);
00140         line(xx1,yy2,xx2,yy2, 15);
00141         mousevisible(true);
00142 
00143         knopfsuccessful = true;
00144         kn = true;
00145      }
00146      do { 
00147            if ((mouseparams.x > xx2) || (mouseparams.x < xx1) || (mouseparams.y > yy2) || (mouseparams.y < yy1)) { 
00148               knopfsuccessful = false; 
00149               kn = false; 
00150            } 
00151            if (mouseparams.taste != mt)
00152               kn = false;
00153 
00154            releasetimeslice();
00155      }  while (kn == true);
00156 
00157      {
00158         collategraphicoperations cgo ( xx1, yy1, xx2, yy2 );
00159 
00160         mousevisible(false);
00161         putimage(xx1 + 1,yy1 + 1,p);
00162         delete[] p  ;
00163 
00164         line(xx1 - 1,yy1 - 1,xx2 + 1,yy1 - 1, 8);
00165         line(xx1 - 1,yy1 - 1,xx1 - 1,yy2 + 1, 8);
00166 
00167         line(xx2 + 1,yy1 - 1,xx2 + 1,yy2 + 1, 15);
00168         line(xx1 - 1,yy2 + 1,xx2 + 1,yy2 + 1, 15);
00169 
00170         line(xx1,yy1,xx2,yy1, 15);
00171         line(xx1,yy1,xx1,yy2, 15);
00172 
00173         line(xx2,yy1,xx2,yy2, 8);
00174         line(xx1,yy2,xx2,yy2, 8);
00175 
00176         mousevisible(true);
00177      }
00178 } 
00179 
00180 
00181 
00182 void         tstatistics::init(void)
00183 { 
00184    tdialogbox::init();
00185    paintmode = 1; 
00186    color1 = 23 + actmap->actplayer * 8; 
00187    color2 = 19 + actmap->actplayer * 8; 
00188    color3 = 14; 
00189    color4 = darkgray; 
00190    x1 = 70; 
00191    xsize = 640 - 2 * x1; 
00192    linelength = (xsize - 95 - 20 - 10); 
00193 
00194    memset( l, 0, sizeof(l) );
00195    memset( m, 0, sizeof(m) );
00196 
00197    windowstyle = windowstyle ^ dlg_in3d; 
00198 } 
00199 
00200 
00201 void         tstatisticarmies::init(void)
00202 { 
00203   int         i;
00204 
00205    tstatistics::init();
00206    categories = 3; 
00207    y1 = 25; 
00208    ysize = 490 - 2 * y1; 
00209    title = "army statistics";
00210    action = 0; 
00211    jk = 0; 
00212 
00213    addbutton("e~x~it",10,ysize - 35,xsize - 10,ysize - 10,0,1,2,true); 
00214    addbutton("~c~hange display mode",10,ysize - 65,xsize - 10,ysize - 40,0,1,1,true); 
00215    
00216    buildgraphics();
00217    rahmen(true,x1 + 10,y1 + 50,x1 + xsize - 10,y1 + ysize - 70); 
00218    for (i = 0; i <= 2; i++) 
00219       putimage(x1 + 20,y1 + 75 + i * 90,icons.statarmy[i]); 
00220 
00221 } 
00222 
00223 
00224 void         tstatisticbuildings::init(void)
00225 { 
00226 
00227    tstatistics::init();
00228    categories = 1; 
00229    y1 = 115; 
00230    ysize = 490 - 2 * y1; 
00231    title = "building statistics";
00232 
00233    action = 0; 
00234 
00235    addbutton("e~x~it",10,ysize - 35,xsize - 10,ysize - 10,0,1,2,true); 
00236    addbutton("~c~hange display mode",10,ysize - 65,xsize - 10,ysize - 40,0,1,1,true); 
00237 
00238    buildgraphics();
00239    rahmen(true,x1 + 10,y1 + 50,x1 + xsize - 10,y1 + ysize - 70); 
00240 } 
00241 
00242 
00243 
00244 void         tstatisticarmies::count(void)
00245 { 
00246   integer      j, b; 
00247 
00248    for (j = 0; j <= 8; j++) { 
00249       if (j == 8) 
00250          b = 3; 
00251       else 
00252          if (j == actmap->actplayer) 
00253             b = 0; 
00254          else 
00255             if ( actmap->player[actmap->actplayer].diplomacy.getState(j) >= PEACE ) 
00256                b = 1; 
00257             else 
00258                b = 2;
00259 
00260       for ( Player::VehicleList::iterator i = actmap->player[j].vehicleList.begin(); i != actmap->player[j].vehicleList.end(); i++ ) {
00261          Vehicle* actvehicle = *i;
00262          if (fieldvisiblenow(getfield(actvehicle->xpos,actvehicle->ypos))) {
00263             if (actvehicle->typ->height & (chtieffliegend | chfliegend | chhochfliegend | chsatellit)) { 
00264                l[0][b]++; 
00265                m[0][j]++; 
00266             } 
00267             else 
00268                if (actvehicle->typ->height & (chschwimmend | chgetaucht | chtiefgetaucht) ) { 
00269                   l[2][b]++; 
00270                   m[2][j]++; 
00271                } 
00272                else { 
00273                   l[1][b]++; 
00274                   m[1][j]++; 
00275                } 
00276          } 
00277       }
00278    } 
00279 } 
00280 
00281 
00282 void         tstatisticbuildings::count(void)
00283 { 
00284    integer      j, b;
00285    for (j = 0; j <= 8; j++) {
00286       if (j == 8) 
00287          b = 3; 
00288       else 
00289          if (j == actmap->actplayer) 
00290             b = 0; 
00291          else 
00292             if ( actmap->player[actmap->actplayer].diplomacy.getState(j) >= PEACE ) 
00293                b = 1; 
00294             else 
00295                b = 2; 
00296       for ( Player::BuildingList::iterator i = actmap->player[j].buildingList.begin(); i != actmap->player[j].buildingList.end(); i++ ) {
00297          Building* actbuilding = *i;
00298          if (fieldvisiblenow( actbuilding->getEntryField() )) {
00299             l[0][b]++; 
00300             m[0][j]++; 
00301          } 
00302       }
00303    } 
00304 } 
00305 
00306 
00307 void         tstatistics::paintgraph(void)
00308 { 
00309    collategraphicoperations cgo ( x1, y1, x1 + xsize, y1 + ysize );
00310    int    linestart = x1 + 95;
00311 
00312   int      max; 
00313   integer      b, i, j, y; 
00314 
00315    max = 0; 
00316    if (paintmode == 0) { 
00317       for (i = 0; i <= categories - 1; i++) 
00318          for (j = 0; j <= 3; j++) 
00319             if (l[i][j] > max) max = l[i][j]; 
00320    } 
00321    else 
00322       for (i = 0; i <= categories - 1; i++) 
00323          for (j = 0; j <= 8; j++) 
00324             if (m[i][j] > max) max = m[i][j]; 
00325 
00326    if (max > 0) 
00327       for (i = 0; i <= categories - 1; i++) { 
00328          y = y1 + 60 + i * 90; 
00329 
00330          rahmen(true,x1 + 90,y,x1 + xsize - 20,y + 60); 
00331          if (paintmode == 0) { 
00332             bar(linestart,y + 5,linestart + linelength * l[i][0] / max,y + 15,color1); 
00333             bar(linestart,y + 17,linestart + linelength * l[i][1] / max,y + 27,color2); 
00334             bar(linestart,y + 29,linestart + linelength * l[i][2] / max,y + 39,color3); 
00335             bar(linestart,y + 41,linestart + linelength * l[i][3] / max,y + 51,color4); 
00336          } 
00337          else 
00338             for (j = 0; j <= 8; j++) 
00339                bar(linestart,y + 3 + j * 6,linestart + linelength * m[i][j] / max,y + 8 + j * 6,21 + j * 8); 
00340 
00341       } 
00342    else 
00343       y = y1 + 60 + (categories - 1) * 90; 
00344 
00345    doubleline(linestart,y + 80,linestart + linelength,y + 80); 
00346    activefontsettings.font = schriften.smallsystem;
00347    activefontsettings.length = 10;
00348    
00349    if ((max & 3) == 0)
00350      b = 4;
00351    else 
00352       if ((max % 3) == 0)
00353         b = 3;
00354       else 
00355         b = 2;
00356 
00357    activefontsettings.background = 255; 
00358    activefontsettings.color = color1; 
00359    for (i = 0; i <= b; i++) { 
00360       doubleline(linestart + linelength * i / b,y + 75,linestart + linelength * i / b,y + 85); 
00361       showtext2(strr(max * i / b),linestart + linelength * i / b - 5,y + 87); 
00362    } 
00363    activefontsettings.font = schriften.smallarial;
00364    activefontsettings.length = 80; 
00365    activefontsettings.color = white; 
00366    activefontsettings.background = color1; 
00367            
00368    if (paintmode == 0) { 
00369       showtext2("own units",linestart,y + 110);
00370 
00371       activefontsettings.background = color2; 
00372       showtext2("allies", linestart + linelength / 4,y + 110);
00373 
00374       activefontsettings.background = color3; 
00375       activefontsettings.color = black; 
00376       showtext2("enemys", linestart + linelength * 2 / 4,y + 110);
00377 
00378       activefontsettings.background = color4; 
00379       activefontsettings.color = white; 
00380       showtext2("neutral", linestart + linelength * 3 / 4,y + 110);
00381    } 
00382    else 
00383       paintsurface2(linestart,y + 110,linestart + linelength,y + 110 + schriften.smallarial->height);
00384 } 
00385 
00386 
00387 void         tstatisticarmies::run(void)
00388 { 
00389    count(); 
00390    paintgraph(); 
00391    mousevisible(true); 
00392    do { 
00393       tstatistics::run();
00394       if (taste == ct_esc) 
00395          action = 2; 
00396       if (taste == ct_f1) 
00397          help(11); 
00398       if ((mouseparams.taste == 1) && (mouseparams.x > x1 + 10) && (mouseparams.y > y1 + 50) && (mouseparams.x < x1 + xsize - 10) && (mouseparams.y < y1 + ysize - 70)) { 
00399          jk++; 
00400          newknopfdruck( (int) (x1 + 10) , (int) (y1 + 50) , (int) (x1 + xsize - 10) , (int) (y1 + ysize - 70)); 
00401          if (jk > 3) { 
00402             displaymessage("that makes fun, doesn't it ?  \n this will be released as a seperate game soon ! ",1);
00403          } 
00404       } 
00405    }  while (action < 2);
00406 } 
00407 
00408 
00409 void         tstatisticbuildings::run(void)
00410 { 
00411    count(); 
00412    paintgraph(); 
00413    mousevisible(true); 
00414    do { 
00415       tstatistics::run();
00416       if (taste == ct_esc) 
00417          action = 2; 
00418       if (taste == ct_f1) 
00419          help(10); 
00420    }  while (action < 2);
00421 } 
00422 
00423 
00424 void         tstatistics::buttonpressed( int id )
00425 { 
00426    if (id == 1) { 
00427       paintmode = 1 - paintmode; 
00428       mousevisible(false); 
00429       paintsurface ( 81, 51, xsize - 11, ysize - 72 );
00430       paintgraph(); 
00431       mousevisible(true); 
00432    } 
00433    if (id == 2) 
00434       action = 2; 
00435 } 
00436 
00437 
00438 void         statisticarmies(void)
00439 { 
00440   tstatisticarmies sta; 
00441 
00442    sta.init(); 
00443    sta.run(); 
00444    sta.done(); 
00445 } 
00446 
00447 
00448 void         statisticbuildings(void)
00449 { 
00450   tstatisticbuildings stb; 
00451 
00452    stb.init(); 
00453    stb.run(); 
00454    stb.done(); 
00455 } 
00456 
00457 
00458 #endif
00459 
00460 
00461 
00462 #define klickconst 100
00463 #define delayconst 10
00464 
00465 
00466 void  dispmessage2( const ActionResult& result )
00467 {
00468    dispmessage2( result.getCode(), result.getMessage().c_str() );  
00469 }
00470 
00471 
00472 void         dispmessage2(int          id,
00473                           const char *       st)
00474 {
00475    char          *s2;
00476 
00477    const char* sp = getmessage(id);
00478    const char* s1 = sp;
00479    if (sp != NULL) {
00480       char s[200];
00481       s2 = s;
00482       while (*s1 !=0) {
00483         if ( *s1 != 35 /* # */ ) {
00484            *s2 = *s1;
00485            s2++;
00486            s1++;
00487         } else {
00488            if (st != NULL) {
00489               while (*st != 0) {
00490                  *s2 = *st;
00491                  s2++;
00492                  st++;
00493               } /* endwhile */
00494            } /* endif */
00495         } /* endif */
00496       } /* endwhile */
00497       *s2 = 0;
00498 
00499       displaymessage2(s); 
00500    }
00501 } 
00502 
00503 
00504   /* type
00505   tmemoryinfo = object(tdialogbox)
00506                    procedure init;
00507                    procedure run;
00508                 end;
00509 
00510 procedure tmemoryinfoinit;
00511 var
00512   l:int;
00513 begin
00514   x1:=80;
00515   y1:=50;
00516   xsize:=640-2*x1;
00517   ysize:=480-2*y1;
00518   buildgraphics;
00519   activefontsettings.font:=schriften.smallarial;
00520   activefontsettings.color:=lightblue;
00521   activefontsettings.background:=255;
00522   activefontsettings.justify:=lefttext;
00523   showtext2('vehicletypeen : '+strr(sizeof(tvehicletype)*vehicletypeenanz+
00524 end;  */ 
00525 
00526 
00527 
00528 
00529 class  tchoice_dlg : public tdialogbox {
00530                public:
00531                   int      result;
00532                   void      init( const char* a, const char* b, const char* c );
00533                   virtual void buttonpressed( int id );
00534                   virtual void run( void );
00535                 };
00536 
00537 
00538 void         tchoice_dlg::init( const char* a, const char* b, const char* c )
00539 {
00540   tdialogbox::init();
00541   windowstyle |= dlg_notitle;
00542   int wdth = gettextwdth ( a, schriften.arial8 ) ;
00543   if ( wdth > 280 )
00544      xsize = wdth + 20;
00545   else
00546      xsize = 300; 
00547 
00548   ysize = 100; 
00549   addbutton(b,10,60,xsize/2-5,90,0,1,1,true); 
00550   addbutton(c,xsize/2+5,60,xsize-10,90,0,1,2,true);
00551 
00552   x1 = (640 - xsize) / 2;
00553   y1 = (480 - ysize) / 2;
00554 
00555   buildgraphics();
00556   activefontsettings.font = schriften.arial8; 
00557   activefontsettings.justify = centertext; 
00558   activefontsettings.length = xsize - 20;
00559   activefontsettings.background = 255;
00560   if ( actmap && actmap->actplayer >= 0 )
00561      activefontsettings.color = actmap->actplayer * 8 + 20;
00562   else
00563      activefontsettings.color = 20;
00564   mousevisible ( false );
00565   showtext2(a,x1 + 10,y1 + 15);
00566   mousevisible ( true );
00567   result = 0; 
00568 } 
00569 
00570 
00571 void         tchoice_dlg::buttonpressed( int id )
00572 { 
00573   if (id == 1) result = 1; 
00574   if (id == 2) result = 2; 
00575 } 
00576 
00577 
00578 void         tchoice_dlg::run(void)
00579 { 
00580   while ( mouseparams.taste )
00581      releasetimeslice();
00582   mousevisible(true); 
00583   do { 
00584     tdialogbox::run();
00585   }  while (result  == 0);
00586 } 
00587 
00588 
00589 int         legacy_choice_dlg( const char *       title,
00590                         const char *       s1,
00591                         const char *       s2,
00592                         ... )
00593 { 
00594 
00595    va_list paramlist;
00596    va_start ( paramlist, s2 );
00597 
00598    char tempbuf[1000];
00599 
00600    int lng = vsprintf( tempbuf, title, paramlist );
00601    va_end ( paramlist );
00602    if ( lng >= 1000 )
00603       displaymessage ( "dialog.cpp / choice_dlg:   string to long !\nPlease report this error",1 );
00604 
00605   tchoice_dlg  c;
00606   int a;
00607 
00608   c.init(tempbuf,s1,s2);
00609   c.run();
00610   a = c.result;
00611   c.done(); 
00612   return a;
00613 } 
00614 
00615 
00616 int  choice_dlg(const ASCString& title, const ASCString& leftButton, const ASCString& rightButton )
00617 {
00618    if ( legacyEventSystemActive() ) {
00619       return legacy_choice_dlg( title.c_str(), leftButton.c_str(), rightButton.c_str() );
00620    } else {
00621       return new_choice_dlg( title, leftButton, rightButton );
00622    }
00623    return 0;
00624 }
00625 
00626 
00627 
00628 /*********************************************************************************************/
00629 /* unpack_date :  entpackt das datum (von zb dateien)                                        */
00630 /*********************************************************************************************/
00631 void        unpack_date (unsigned short packed, int &day, int &month, int &year)
00632 {
00633    year = packed >> 9;
00634    month = (packed - year*512) >> 5;
00635    day = packed - year*512 - month*32;
00636    year +=1980;
00637 }
00638 
00639 
00640 
00641 
00642 /*********************************************************************************************/
00643 /* unpack_time :  entpackt die zeit (von zb dateien)                                         */
00644 /*********************************************************************************************/
00645 void        unpack_time (unsigned short packed, int &sec, int &min, int &hour)
00646 {
00647    hour = packed >> 11;
00648    min = (packed - hour*2048) >> 5;
00649    sec = packed - hour*2048 - min*32;       // sekunden sind noch nicht getestet !!!
00650 }
00651 
00652 
00653 
00654 
00655 
00656 
00657 /*
00658 void testdisptext ( void )
00659 {
00660    tnfilestream stream ("tst.txt",1 );
00661     char *cct;
00662     stream.readpnchar ( &cct );
00663 
00664     if ( cct ) {
00665        tviewtext vt;
00666        vt.setparams ( 10, 10, 630, 470, cct, white, black );
00667        vt.tvt_dispactive = 1;
00668        vt.displaytext ();
00669    
00670    
00671        delete[] cct;
00672     }
00673 }
00674 
00675 
00676 void tenterfiledescription::init ( char* descrip )
00677 {
00678 
00679    tdialogbox::init();
00680    xsize = 350;
00681    ysize = 145;
00682    x1 = 170;
00683    y1 = 100;
00684    title = "enter description";
00685    description =  new char [ 100 ];
00686 
00687    if ( descrip )
00688       strcpy ( description, descrip );
00689    else
00690       description[0] = 0;
00691 
00692    addbutton( NULL, 15, starty + 10, xsize - 15, starty + 35 , 1, 0, 1, true );
00693    addeingabe ( 1, (void*) description, 0, 100 );
00694    addbutton( "~O~K", 15, ysize - 35, xsize - 15, ysize - 10, 0,1,2,true);
00695    addkey( 2, ct_enter);
00696 
00697    buildgraphics();
00698    status = 0;
00699 }
00700 
00701 void tenterfiledescription::buttonpressed ( int id )
00702 {
00703    tdialogbox::buttonpressed ( id );
00704    if (id == 2)
00705       status = 1;
00706 };
00707 
00708 
00709 void tenterfiledescription::run ( void )
00710 {
00711    tdialogbox::run();
00712    pbutton pb = firstbutton;
00713    while (pb->id != 1) 
00714       pb = pb->next;
00715    execbutton( pb , false );
00716 
00717 
00718    mousevisible(true);
00719    do {
00720       tdialogbox::run();
00721    } while ( status == 0 ); 
00722 
00723 }
00724 
00725 */
00726 
00727 
00728 
00729 #if 0
00730 
00731 
00732 
00733 typedef string* tnamestrings[9];
00734 
00735 class  tenternamestrings : public tdialogbox {
00736                      typedef tdialogbox inherited;
00737                      ASCString dlgtitle;
00738                   public:
00739                        char             status;
00740                        char             playerexist;
00741                        tnamestrings&    orgnames;
00742                        char             names[9][100];
00743                        char             buttonnames[9][100];
00744 
00745                        void             init( char plyexistyte, int md);
00746                        virtual void     run ( void );
00747                        virtual void     buttonpressed( int id );
00748                        void             done ( void );
00749                        virtual int      getcapabilities ( void );
00750 
00751                        tenternamestrings ( tnamestrings& n ) : orgnames ( n ) {};
00752                     };
00753 
00754 
00755 class  tsetalliances : public tdialogbox {
00756                      typedef tdialogbox inherited;
00757                protected:
00758                      virtual void redraw ( void );       
00759                      tmap::Shareview     sv;
00760                public:
00761                      char                status;
00762                      char                alliancedata[8][8];
00763                      char                location[8];
00764                      int                 playerpos[8];  // Beispiel: Es existieren Spieler 0 und Spieler 6; dann ist playerpos[0] = 0 und playerpos[1] = 6
00765                      // int                 playermode[8];    /*  0: player
00766                      //                                          1: ai
00767                      //                                          2: off  */
00768 
00769                      char                playernum;
00770                      char                playerexist;
00771                      char                lastplayer;
00772                      int                 oninit;
00773                      int                 supervisor;
00774                      bool                mapeditor;
00775                      bool                  shareview_changeable;
00776                      int                 xp,yp,xa,ya,bx;  /* position der tastatur-markierungsrechtecke  */
00777 
00778                      void                init ( int supervis );
00779                      virtual void        buttonpressed( int id);
00780                      virtual void        run ( void );
00781                      virtual int         getcapabilities ( void );
00782                      void                click( char bxx, char x, char y);
00783                      void                paintkeybar ( void );
00784                      void                buildhlgraphics ( void );
00785                      void                displayplayernamesintable( void );
00786                      #ifndef karteneditor
00787                      void                checkfornetwork ( void );
00788                      #endif
00789                      void                setparams ( void );
00790                 };
00791 
00792 static const char*    cens[]  = { "player", "alliance", "computer" };
00793 
00794 
00795 void         tenternamestrings::init(  char plyexist, int md )
00796 { 
00797 
00798   char         i, j;
00799 
00800   tdialogbox::init();
00801   playerexist = plyexist;
00802   j = 0; 
00803   for (i = 0; i <= 7; i++) 
00804     if (playerexist & (1 << i)) 
00805       j++;
00806 
00807   dlgtitle = "enter ";
00808   dlgtitle += cens[md];
00809   dlgtitle += " names" ;
00810   title = dlgtitle.c_str();
00811 
00812   xsize = 350; 
00813   x1 = (640 - xsize) / 2; 
00814   ysize = 140 + j * 45; 
00815   y1 = (480 - ysize) / 2; 
00816 
00817 
00818   for (i=0;i<8 ;i++ ) {
00819      strcpy ( names[i], orgnames[i]->c_str() );
00820      strcpy( buttonnames [i], cens[md] );
00821      strcat( buttonnames [i], digit[i] );
00822   } /* endfor */
00823 
00824   j = 0;
00825   for (i = 0; i <= 7; i++) 
00826     if ( (playerexist & (1 << i)) && names[i] ) { 
00827       j++;
00828       addbutton(buttonnames[i],20,30 + j * 45,xsize - 20,52 + j * 45,1,0,i + 1,true);
00829       addeingabe(i + 1, names[i], 1, 99);
00830     } 
00831   addbutton("~o~k",20,ysize - 40,xsize / 2 - 5,ysize - 10,0,1,30,true); 
00832   addbutton("~c~ancel",xsize / 2 + 5,ysize - 40,xsize - 20,ysize - 10,0,1,31,true); 
00833   buildgraphics(); 
00834   status = 0; 
00835 } 
00836 
00837 void         tenternamestrings::done ( void ) 
00838 {
00839   tdialogbox::done();
00840 }
00841 
00842 
00843 void         tenternamestrings::buttonpressed( int id )
00844 { 
00845   inherited::buttonpressed(id);
00846   if (id == 30) status = 2; 
00847   if (id == 31) status = 1; 
00848 } 
00849 
00850 
00851 void         tenternamestrings::run(void)
00852 { 
00853   mousevisible(true); 
00854   do { 
00855     tdialogbox::run();
00856   }  while (status == 0);
00857 
00858   if (status == 2)
00859      for (int i=0;i<8 ;i++ )
00860         *orgnames[i] = names[i];
00861 
00862 } 
00863 
00864 
00865 
00866 int               tenternamestrings::getcapabilities ( void )
00867 {
00868   return 1;
00869 }
00870 
00871 #endif
00872 
00873 
00874 void viewVisibilityStatistics()
00875 {
00876 /*
00877    ASCString msg;
00878 
00879    tmap::Shareview* sv = actmap->shareview;
00880    actmap->shareview = NULL;
00881    computeview ( actmap );
00882 
00883    for ( int i = 0; i < 8; i++ )
00884       if ( actmap->player[i].exist() ) {
00885          msg += ASCString("#font02#Player ") + strrr ( i ) + "#font01#\n" ;
00886          int notVisible = 0;
00887          int fogOfWar = 0;
00888          int visible = 0;
00889          for ( int x = 0; x < actmap->xsize; x++ )
00890             for ( int y = 0; y < actmap->ysize; y++ ) {
00891                 VisibilityStates vs = fieldVisibility  ( actmap->getField ( x, y ), i );
00892                 switch ( vs ) {
00893                    case visible_not: ++notVisible;
00894                    break;
00895                    case visible_ago: ++fogOfWar;
00896                    break;
00897                    default: ++visible;
00898                 }
00899             }
00900          msg += ASCString("  not visible: ") + strrr(notVisible ) + " fields\n";
00901          msg += ASCString("  fog of war: ") + strrr(fogOfWar ) + " fields\n";
00902          msg += ASCString("  visible: ") + strrr(visible ) + " fields\n\n";
00903       }
00904 
00905 
00906    actmap->shareview = sv;
00907    computeview ( actmap );
00908 
00909 */
00910    tviewanytext vat;
00911    vat.init ( "Visibility Statistics", "Sorry, not available in ASC2 " );
00912    vat.run();
00913    vat.done();
00914 }
00915 
00916 
00917 
00918 
00919 
00920 void         tviewanytext:: init( const char* _title, const char* text , int xx1 , int yy1  , int xxsize , int yysize  )
00921 { 
00922 
00923    // dialogbox initialisieren
00924 
00925    tdialogbox::init();
00926    x1 = xx1; 
00927    y1 = yy1; 
00928    xsize = xxsize; 
00929    ysize = yysize; 
00930    textstart = 42 ; 
00931    textsizey = (ysize - textstart - 40); 
00932    starty = starty + 10; 
00933    title = _title;
00934    windowstyle ^= dlg_in3d;
00935    action=0;
00936 
00937 
00938    txt = text;
00939                        
00940    setparams ( x1 + 13, y1 + textstart, x1 + xsize - 41, y1 + ysize - 40, txt, black, dblue);
00941    addbutton ( "~O~K", 10, ysize - 30, xsize - 10, ysize - 10, 0, 1, 10, true );
00942    addkey ( 10, ct_space );
00943    addkey ( 10, ct_enter );
00944    addkey ( 10, ct_esc );
00945    tvt_dispactive = 0;
00946    displaytext(  );
00947    textsizeycomplete = tvt_yp;
00948    tvt_dispactive = 1;
00949 
00950 
00951    if (textsizeycomplete >= textsizey) {
00952       scrollbarvisible = true; 
00953 
00954       addscrollbar(xsize - 30,starty,xsize - 15,ysize - 35,&textsizeycomplete, textsizey, &tvt_starty,1,0);
00955       setscrollspeed ( 1 , 1 );
00956 
00957       rightspace = 40;
00958    }                                                                                       
00959    else {
00960       rightspace = 10;
00961       scrollbarvisible = false; 
00962    }
00963 
00964    tvt_starty = 0; 
00965    buildgraphics();
00966 } 
00967 
00968 
00969 void         tviewanytext::repaintscrollbar ( void )
00970 {
00971    enablebutton( 1 );
00972 }
00973 
00974 
00975 void         tviewanytext::redraw(void)
00976 { 
00977   collategraphicoperations cgo ( x1, y1, x1 + xsize, y1 + ysize);
00978 
00979    tdialogbox::redraw();
00980    rahmen(true,x1 + 10,y1 + textstart - 2,x1 + xsize - rightspace,y1 + textstart + textsizey + 2); 
00981 
00982 
00983    activefontsettings.font = schriften.smallarial; 
00984    activefontsettings.justify = lefttext; 
00985    activefontsettings.background = dblue; 
00986    activefontsettings.length =0;
00987 
00988    activefontsettings.color = black; 
00989    activefontsettings.height = textsizey / linesshown; 
00990 
00991    int xd = 15 - (rightspace - 10) / 2;
00992 
00993    setpos ( x1 + 13 + xd, y1 + textstart, x1 + xsize - 41 + xd, y1 + ysize - 40 );
00994    displaytext(); 
00995 
00996 } 
00997 
00998 
00999 void         tviewanytext::buttonpressed( int id )
01000 {     
01001    tdialogbox::buttonpressed(id);
01002    if (id == 1) 
01003       displaytext();
01004    if ( id== 10 )
01005       action = 11;
01006 } 
01007 
01008 
01009 void         tviewanytext::run(void)
01010 { 
01011    mousevisible(true);
01012    do { 
01013       tdialogbox::run();
01014       checkscrolling ( );
01015       if ( prntkey == 's' )
01016          printf("%s", txt);
01017    }  while (action < 10);
01018 } 
01019 
01020 
01021 
01022 
01023 
01024 class tbi3preferences : public tdialogbox {
01025                         CGameOptions actoptions;
01026                         int status;
01027                         tmouserect delta, r1, r2, r3, r4, r5, r6, r7, r8;
01028                         tmouserect dlgoffset;
01029 
01030                      public:
01031                         void init ( void );
01032                         void buttonpressed ( int id );
01033                         void run ( void );
01034                         tbi3preferences ( ) : actoptions ( *CGameOptions::Instance() ) {};
01035                     };
01036 
01037 
01038 void tbi3preferences :: init ( void )
01039 {
01040    tdialogbox::init();
01041    title = "BattleIsle options";
01042 
01043    xsize = 600;
01044    ysize = 460;
01045 
01046    x1 = -1;
01047    y1 = -1;
01048 
01049    addbutton ( "~O~K", 10, ysize - 35, xsize / 2 - 5, ysize - 10, 0, 1, 1, true );
01050    addbutton ( "~C~ancel", xsize / 2 + 5, ysize - 35, xsize - 10, ysize - 10, 0, 1, 2, true );
01051 
01052    r1.x1 = xsize - 150;
01053    r1.y1 = starty + 20;
01054    r1.x2 = xsize - 20;
01055    r1.y2 = starty + 35;
01056 
01057    delta.x1 = 0;
01058    delta.x2 = 0;
01059    delta.y1 = 30;
01060    delta.y2 = 30;
01061 
01062    addbutton ( "", r1, 3, 0, 3, true );
01063 //   addeingabe ( 3, &actoptions.bi3.interpolate.terrain, 0, dblue );
01064 
01065    r2 = r1 + delta;
01066 
01067    addbutton ( "", r2,  3, 0, 4, true  );
01068   // addeingabe ( 4, &actoptions.bi3.interpolate.units, 0, dblue );
01069 
01070    r3 = r2 + delta;
01071 
01072    addbutton ( "", r3,  3, 0, 5, true  );
01073  //  addeingabe ( 5, &actoptions.bi3.interpolate.buildings, 0, dblue );
01074    
01075    r4 = r3 + delta;
01076 
01077    addbutton ( "", r4,  3, 0, 6, true  );
01078 //   addeingabe ( 6, &actoptions.bi3.interpolate.objects, 0, dblue );
01079 
01080    buildgraphics(); 
01081 
01082    activefontsettings.font = schriften.smallarial; 
01083    activefontsettings.justify = lefttext; 
01084    activefontsettings.length = 0;
01085    activefontsettings.background = 255;
01086 
01087    dlgoffset.x1 = x1;
01088    dlgoffset.y1 = y1;
01089    dlgoffset.x2 = x1;
01090    dlgoffset.y2 = y1;
01091 
01092    showtext2 ( "interpolate terrain",   x1 + 25, y1 + r1.y1 );
01093    showtext2 ( "interpolate units",     x1 + 25, y1 + r2.y1 );
01094    showtext2 ( "interpolate buildings", x1 + 25, y1 + r3.y1 );
01095    showtext2 ( "interpolate objects",   x1 + 25, y1 + r4.y1 );
01096 
01097    status = 0;
01098 
01099 
01100 }
01101 
01102 void tbi3preferences :: buttonpressed ( int id )
01103 {
01104    tdialogbox :: buttonpressed ( id );
01105 
01106    if ( id == 1 ) {
01107       *CGameOptions::Instance() = actoptions;
01108       status = 10;
01109    }
01110 
01111    if ( id == 2 ) 
01112       status = 10;
01113 }
01114 
01115 
01116 void tbi3preferences :: run ( void )
01117 {
01118    mousevisible ( true );
01119    do {
01120       tdialogbox::run();
01121    } while ( status < 10 ); /* enddo */
01122 }
01123 
01124 void bi3preferences  ( void )
01125 {
01126    tbi3preferences prefs;
01127    prefs.init();
01128    prefs.run();
01129    prefs.done();
01130 }
01131 
01132 
01133 
01134 
01135 class ResizeMap : public tdialogbox {
01136                         int status;
01137                         int top, bottom, left, right;
01138 
01139                      public:
01140                         void init ( void );
01141                         void buttonpressed ( int id );
01142                         void run ( void );
01143                         char checkvalue( int         id, void*      p);
01144                     };
01145 
01146 
01147 char ResizeMap :: checkvalue(int         id, void*      p)  
01148 {
01149    if ( id >= 3 && id <= 6 ) {
01150       int* wp = (int*) p;
01151 
01152       if ( id == 3 && id == 6 ) 
01153          if ( *wp & 1 ) {
01154             displaymessage ( "values must be even !", 1 );
01155             return 0;
01156          }
01157          /*
01158       if ( (id == 3   &&  - ( *wp + bottom ) > actmap->ysize - idisplaymap.getscreenysize(1) ) ||
01159            (id == 6   &&  - ( top + *wp )    > actmap->ysize - idisplaymap.getscreenysize(1) ) ||
01160            (id == 4   &&  - ( *wp + right  ) > actmap->xsize - idisplaymap.getscreenxsize(1) ) ||
01161            (id == 5   &&  - ( left + *wp   ) > actmap->xsize - idisplaymap.getscreenxsize(1) ) ) {
01162          displaymessage ( "remaining size too small !", 1 );
01163          return 0;
01164       }    */
01165 
01166       if ( (id == 3   &&   ( *wp + bottom ) + actmap->ysize > 32000 ) ||
01167            (id == 6   &&   ( top + *wp )    + actmap->ysize > 32000 ) ||
01168            (id == 4   &&   ( *wp + right  ) + actmap->xsize > 32000 ) ||
01169            (id == 5   &&   ( left + *wp   ) + actmap->xsize > 32000 ) ) {
01170          displaymessage ( "new map too large !", 1 );
01171          return 0;
01172       }
01173 
01174    }
01175    return 1;
01176 }
01177 
01178 void ResizeMap :: init ( void )
01179 {
01180 
01181    top = 0;
01182    bottom = 0;
01183    left = 0;
01184    right = 0;
01185 
01186    tdialogbox::init();
01187    title = "Resize Map";
01188 
01189    xsize = 400;
01190    ysize = 300;
01191 
01192    x1 = -1;
01193    y1 = -1;
01194 
01195    addbutton ( "~O~K", 10, ysize - 35, xsize / 2 - 5, ysize - 10, 0, 1, 1, true );
01196    addkey ( 1, ct_enter );
01197 
01198    addbutton ( "~C~ancel", xsize / 2 + 5, ysize - 35, xsize - 10, ysize - 10, 0, 1, 2, true );
01199    addkey ( 2, ct_esc );
01200 
01201    addbutton ( "~T~op", xsize/2 - 30, 70, xsize/2 + 30, 90, 2, 0, 3, true );
01202    addeingabe ( 3, &top, -actmap->ysize, 70000 );
01203    addkey ( 3, ct_t );
01204 
01205    addbutton ( "~L~eft", 20, 120, 80, 140, 2, 0, 4, true );
01206    addeingabe ( 4, &left, -actmap->xsize, 70000 );
01207    addkey ( 4, ct_l );
01208 
01209    addbutton ( "~R~ight", xsize - 80, 120, xsize - 20, 140, 2, 0, 5, true );
01210    addeingabe ( 5, &right, -actmap->xsize, 70000 );
01211    addkey ( 5, ct_r );
01212 
01213    addbutton ( "~B~ottom", xsize/2 - 30, 150, xsize/2 + 30, 170, 2, 0, 6, true );
01214    addeingabe ( 6, &bottom, -actmap->ysize, 70000 );
01215    addkey ( 6, ct_b );
01216 
01217    buildgraphics(); 
01218 
01219    activefontsettings.font = schriften.smallarial; 
01220    activefontsettings.justify = lefttext; 
01221    activefontsettings.length = 0;
01222    activefontsettings.background = 255;
01223 
01224    showtext2 ( "positive values: enlarge map",   x1 + 25, y1 + 220 );
01225    showtext2 ( "negative values: shrink map",   x1 + 25, y1 + 240 );
01226 
01227    status = 0;
01228 }
01229 
01230 void ResizeMap :: buttonpressed ( int id )
01231 {
01232    tdialogbox :: buttonpressed ( id );
01233 
01234    if ( id == 1 ) 
01235       status = 12;
01236 
01237    if ( id == 2 ) 
01238       status = 10;
01239 
01240 }
01241 
01242 
01243 void ResizeMap :: run ( void )
01244 {
01245    mousevisible ( true );
01246    do {
01247       tdialogbox::run();
01248    } while ( status < 10 ); /* enddo */
01249    if ( status >= 12 ) {
01250       int result = actmap->resize ( top, bottom, left, right );
01251       if ( result )
01252         displaymessage ( "resizing failed" , 1 );
01253    }
01254 }
01255 
01256 void resizemap ( void )
01257 {
01258    ResizeMap rm;
01259    rm.init();
01260    rm.run();
01261    rm.done();
01262    displaymap();
01263 }
01264 
01265 
01266 
01267 
01268 
01269 
01270 
01271 
01272 class tchoosezoomlevel : public tdialogbox {
01273              protected:
01274                 int zoom;
01275                 int ok;
01276              public:
01277                 void init ( void );
01278                 void buttonpressed ( int id );
01279                 void run ( void );
01280          };
01281 
01282 void tchoosezoomlevel :: init ( void )
01283 {
01284    tdialogbox :: init ( );
01285    title = "choose zoomlevel";
01286    xsize = 200;
01287    ysize = 150;
01288 //   zoom = zoomlevel.getzoomlevel();
01289    ok = 0;
01290 
01291    addbutton ( "~O~k", 10, ysize - 30, xsize - 10, ysize - 10 , 0, 1, 1, true );
01292    addkey ( 1, ct_enter );
01293 
01294    addbutton ( "", 10, 60, xsize - 10, 85                     , 2, 1, 2, true );
01295    // addeingabe ( 2, &zoom, zoomlevel.getminzoom(), zoomlevel.getmaxzoom() );
01296    addkey ( 1, ct_space );
01297 
01298    buildgraphics();
01299 }
01300 
01301 void tchoosezoomlevel :: buttonpressed ( int id )
01302 {
01303    tdialogbox:: buttonpressed ( id );
01304    if ( id == 1 )
01305       ok = 1;
01306 }
01307 
01308 void tchoosezoomlevel :: run ( void )
01309 {
01310    if ( pcgo ) {
01311       delete pcgo;
01312       pcgo = NULL;
01313    }
01314    editfield ( 2 );
01315    ok = 1;
01316    mousevisible ( true );
01317    do {
01318       tdialogbox::run();
01319    } while ( !ok ); 
01320 //   zoomlevel.setzoomlevel ( zoom );
01321 
01322 };
01323 
01324 void choosezoomlevel ( void )
01325 {
01326    tchoosezoomlevel ctl;
01327    ctl.init();
01328    ctl.run();
01329    ctl.done();
01330    displaymap();
01331 }
01332 
01333 
01334 
01335 
01336 
01337 void showbdtbits( void )
01338 {
01339    MapField* fld = actmap->getField(actmap->getCursor());
01340    char m[200];
01341    m[0] = 0;
01342    for (int i = 0; i < terrainPropertyNum ; i++) {
01343       TerrainBits bts;
01344       bts.set ( i );
01345 
01346       if ( (fld->bdt & bts).any() ) {
01347          strcat ( m, terrainProperty[i] );
01348          strcat ( m, "\n" );
01349       }
01350    } /* endfor */
01351    displaymessage( m, 3 );
01352 }
01353 
01354 void appendTerrainBits ( char* text, const TerrainBits* bdt )
01355 {
01356    for (int i = 0; i < terrainPropertyNum ; i++) {
01357       TerrainBits bts;
01358       bts.set ( i );
01359 
01360       if ( (*bdt & bts).any() ) {
01361          strcat ( text, "    " );
01362          strcat ( text, terrainProperty[i] );
01363          strcat  ( text, "\n" );
01364       }
01365    } /* endfor */
01366 }
01367 
01368 
01369 void viewUnitSetinfo ( void )
01370 {
01371    ASCString s;
01372    MapField* fld = actmap->getField( actmap->getCursor() );
01373    if ( fld && fieldvisiblenow  ( fld ) && fld->vehicle ) {
01374 
01375          s += "#fontsize=18#Unit Information:#fontsize=14##aeinzug20##eeinzug20##crtp20#" ;
01376 
01377          const VehicleType* typ = fld->vehicle->typ;
01378 /*
01379          s += "\nreactionfire.Status: ";
01380          s += strrr( getactfield()->vehicle->reactionfire.status );
01381          s += "\nreactionfire.enemiesattackable: ";
01382          s += strrr ( getactfield()->vehicle->reactionfire.enemiesAttackable );
01383 */
01384          s += "Unit name: " ;
01385          if ( !typ->name.empty() )
01386             s += typ->name ;
01387          else
01388             s += typ->description;
01389 
01390          s += "\nUnit owner: " + ASCString::toString( fld->vehicle->getOwner() ) + " - " + actmap->getPlayer(fld->vehicle).getName();
01391 
01392          s += "\nUnit ID: " + ASCString::toString( typ->id );
01393 
01394          if ( !typ->location.empty() ) 
01395             s += typ->location;
01396 
01397          if ( unitSets.size() > 0 )
01398             for ( unsigned int i = 0; i < unitSets.size(); i++ )
01399                if ( unitSets[i]->isMember ( typ->id,SingleUnitSet::unit )) {
01400                   s += "Unit is part of this unit set:";
01401                   if ( unitSets[i]->name.length()) {
01402                      s += "#aeinzug20##eeinzug20#\nName: #aeinzug60##eeinzug60#\n";
01403                      s += unitSets[i]->name;
01404                   }
01405                   if ( unitSets[i]->maintainer.length()) {
01406                      s += "#aeinzug20##eeinzug20#\nMaintainer: #aeinzug60##eeinzug60#\n";
01407                      s += unitSets[i]->maintainer;
01408                   }
01409                   if ( unitSets[i]->information.length()) {
01410                      s += "#aeinzug20##eeinzug20#\nInformation: #aeinzug60##eeinzug60#\n";
01411                      s += unitSets[i]->information;
01412                   }
01413                   s += "#aeinzug0##eeinzug0#\n";
01414                }
01415 
01416 
01417    } else
01418       s += "\nNo unit selected";
01419 
01420    ViewFormattedText vft( "Unit information", s, PG_Rect( -1, -1, 400, 350) );
01421    vft.Show();
01422    vft.RunModal();
01423 }
01424 
01425 
01426 
01427 
01428 
01429 
01430 #define blocksize 256
01431 
01432 
01433 int tparagraph :: winy1;
01434 int tparagraph :: winy2;
01435 int tparagraph :: winx1;
01436 int tparagraph :: maxlinenum;
01437 
01438 tparagraph :: tparagraph ( void )
01439 {
01440    text = new char [ blocksize ];
01441    text[0] = 0;
01442    size = 1;
01443    allocated = blocksize;
01444 
01445    next = NULL;
01446    prev = NULL;
01447    cursor = -1;
01448    cursorstat = 0;
01449    ps.line1num = 0;
01450    linenum = -1;
01451    searchcursorpos = 0;
01452 }
01453 
01454 tparagraph :: tparagraph ( pparagraph prv )
01455 {
01456    searchcursorpos = 0;
01457    linenum = -1;
01458    text = new char [ blocksize ];
01459    text[0] = 0;
01460    size = 1;
01461    allocated = blocksize;
01462    cursorstat = 0;
01463    cursor = -1;
01464 
01465    prev = prv;
01466 
01467    if ( prv ) {
01468       next = prv->next;
01469       if ( next )
01470          next->prev = this;
01471       prv->next = this;
01472 
01473       ps.line1num = prv->ps.line1num + 1 + prv->linenum;
01474    } else {
01475       next = NULL;
01476       ps.line1num = 0;
01477    }
01478 }
01479 
01480 
01481 
01482 tparagraph :: ~tparagraph ()
01483 {
01484    if ( text ) {
01485       delete[] text;
01486       text = NULL;
01487    }
01488 
01489    if ( prev )
01490       prev->next = next;
01491 
01492    if ( next )
01493       next->prev = prev;
01494 
01495 }
01496 
01497 
01498 void tparagraph :: changesize ( int newsize )
01499 {
01500    newsize = (newsize / blocksize + 1) * blocksize;
01501    char* temp = new char[newsize];
01502    if ( text ) {
01503       strcpy ( temp, text );
01504       delete[] text;
01505    } else
01506       temp[0] = 0;
01507 
01508    allocated = newsize;
01509    size = strlen ( temp )+1;
01510    text = temp;
01511 }
01512 
01513 
01514 void tparagraph :: join ( void )
01515 {
01516    cursor = size-1;
01517    addtext ( next->text );
01518    delete next;
01519    if ( reflow() ) {
01520        display();
01521        if ( checkcursorpos() ) {
01522           checkscrollup();
01523           checkscrolldown();
01524        }
01525    }
01526 
01527 
01528 }
01529 
01530 
01531 
01532 void tparagraph :: addtext ( const ASCString& txt )
01533 {
01534     int nsize = txt.length();
01535     if ( allocated < nsize + size )
01536        changesize ( nsize + size );
01537 
01538     strcat ( text, txt.c_str() );
01539     size = strlen ( text ) + 1;
01540 }
01541 
01542 void tparagraph :: checkcursor( void )
01543 {
01544    if ( cursor != -1 ) {
01545       if ( cursor >= size )
01546          cursor = size-1;
01547       if ( cursor < 0 )
01548          cursor = 0;
01549    } else
01550       displaymessage ( " void tparagraph :: checkcursor ( void ) \ncursor not in paragraph !\n text is : %s", 2, text );
01551 }
01552 
01553 
01554 
01555 void tparagraph :: addchar ( char c )
01556 {
01557    checkcursor();
01558    if ( size + 1 > allocated )
01559       changesize ( size + 1 );
01560 
01561     for ( int i = size; i > cursor; i--)
01562        text[i] = text[i-1];
01563 
01564     text[cursor] = c;
01565     cursor++;
01566     size++;
01567 
01568     if ( reflow() ) {
01569        display();
01570        checkcursorpos();
01571     }
01572 }
01573 
01574 
01575 pparagraph tparagraph :: erasechar ( int c )
01576 {
01577    checkcursor();
01578    if ( c == 1 ) {     // backspace
01579       if ( cursor ) {
01580          for ( int i = cursor-1; i < size; i++)
01581             text[i] = text[i+1];
01582          cursor--;
01583          size--;
01584          if ( reflow() )
01585             display();
01586       } else
01587          if ( prev ) {
01588             pparagraph temp = prev;
01589             prev->join();
01590             return temp;              //  !!!###!!!   gef�llt mir eigentlich ?berhauptnicht, wird aber wohl laufen. Sonst m?�te ich halt erasechar von au�en managen
01591          }
01592 
01593    }
01594    if ( c == 2 ) {     // del
01595       if ( cursor < size-1 ) {
01596          for ( int i = cursor; i < size; i++)
01597             text[i] = text[i+1];
01598          size--;
01599          if ( reflow() )
01600             display();
01601       } else
01602          if ( next )
01603             join ( );
01604    }
01605    return this;
01606 }
01607 
01608 int  tparagraph :: checkcursorpos ( void )
01609 {
01610    if ( cursor >= 0 ) {
01611       checkcursor();
01612       if ( ps.line1num + cursory >= maxlinenum ) {
01613          ps.line1num = maxlinenum - cursory - 1;
01614          display();
01615          checkscrollup();
01616          checkscrolldown();
01617          return 0;
01618       }
01619 
01620       if( ps.line1num + cursory < 0 ) {
01621          ps.line1num = -cursory;
01622          display();
01623          checkscrollup();
01624          checkscrolldown();
01625          return 0;
01626       }
01627    }
01628    return 1;
01629 }
01630 
01631 pparagraph tparagraph :: cut ( void )
01632 {
01633    checkcursor();
01634    displaycursor();
01635    char* tempbuf = strdup ( &text[cursor] );
01636    text[cursor] = 0;
01637    size = strlen ( text ) + 1;
01638    reflow ( 0 );
01639    new tparagraph ( this );
01640    if ( tempbuf[0] )
01641       next->addtext ( tempbuf );
01642 
01643    free ( tempbuf );
01644    cursor = -1;
01645    next->cursor = 0;
01646    reflow( 0 );
01647    display();
01648    if ( next->reflow() )
01649       next->display();
01650 
01651    return next;
01652 }
01653 
01654 void tparagraph :: checkscrollup ( void )
01655 {
01656    if ( prev ) {
01657       if ( prev->ps.line1num + prev->linenum + 1 != ps.line1num ) {
01658            prev->ps.line1num = ps.line1num - 1 - prev->linenum ;
01659            prev->display();
01660            prev->checkscrollup();
01661       }
01662    }
01663 }
01664 
01665 void tparagraph :: checkscrolldown ( void )
01666 {
01667    if ( next ) {
01668       if ( ps.line1num + linenum + 1 != next->ps.line1num ) {
01669          next->ps.line1num = ps.line1num + linenum + 1;
01670          next->display();
01671          next->checkscrolldown ();
01672       }
01673    } else {
01674       if ( ps.line1num + linenum < maxlinenum )
01675          bar ( winx1, winy1 + (ps.line1num + linenum + 1) * activefontsettings.height, winx1 + activefontsettings.length, winy1 + maxlinenum * activefontsettings.height, dblue );
01676 
01677    }
01678 }
01679 
01680 
01681 int  tparagraph :: reflow( int all  )
01682 {
01683    int oldlinenum = linenum;
01684 
01685    pfont font = activefontsettings.font;
01686    linenum = 0;
01687    int pos = 0;
01688    linestart [ linenum ] = text;
01689    int length = 0;
01690 
01691    do {
01692 
01693      if ( font->character[int(text[pos])].size ) {
01694         length += font->character[int(text[pos])].width + 2 ;
01695         if ( pos )
01696            length += font->kerning[int(text[pos])][int(text[pos-1])];
01697      }
01698 
01699      if ( length > activefontsettings.length ) {
01700         int pos2 = pos;
01701         while ( ( text[pos2] != ' ' )  &&  ( &text[pos2] - linestart[linenum] )  )
01702            pos2--;
01703 
01704         if ( &text[pos2] == linestart[linenum] )
01705            pos2 = pos;
01706         else
01707            pos2++;
01708 
01709         linelength[linenum] = &text[pos2] - linestart[linenum];
01710         if ( linelength[linenum] > 200 ) {
01711            printf("\a");
01712         }
01713         linenum++;
01714         linestart[linenum] = &text[pos2];
01715         length = 0;
01716         pos = pos2;
01717      } else
01718         pos++;
01719    } while ( pos <= size ); /* enddo */
01720 
01721    linelength[linenum] = &text[pos] - linestart[linenum];
01722         if ( linelength[linenum] > 200 ) {
01723            printf("\a");
01724         }
01725 
01726 
01727    int oldlength = 0;
01728    for (int i = 0; i <= linenum; i++) {
01729       length = 0;
01730       for ( int j = 0; j < linelength[i]; j++ ) {
01731          pos = linestart[i] - text + j;
01732 
01733          if ( pos == cursor  && !searchcursorpos ) {
01734              cursorx = length;
01735              normcursorx = cursorx;
01736              cursory = i;
01737          }
01738 
01739          if ( searchcursorpos ) {
01740             if ( i == cursory )
01741                if ( length >= normcursorx ) {
01742                   cursorx = length;
01743                   cursor = pos;
01744                   searchcursorpos = 0;
01745                }
01746             if ( i > cursory ) {
01747                cursorx = oldlength;
01748                cursor = pos-1;
01749                searchcursorpos = 0;
01750             }
01751         }
01752 
01753         if ( font->character[int(text[pos])].size ) {
01754              length += font->character[int(text[pos])].width + 2 ;
01755              if ( pos )
01756                 length += font->kerning[int(text[pos])][int(text[pos-1])];
01757         }
01758 
01759      }
01760      oldlength = length;
01761    } /* endfor */
01762 
01763 
01764    if ( searchcursorpos ) {
01765       cursorx = length;
01766       cursor = size-1;
01767       searchcursorpos = 0;
01768    }
01769 
01770 
01771    if ( all ) {
01772       if ( linenum != oldlinenum ) {
01773          display ( );
01774          if ( checkcursorpos() ) {
01775             checkscrollup();
01776             checkscrolldown();
01777          }
01778          return 0;
01779       }
01780    }
01781    return 1;
01782 
01783 }
01784 
01785 
01786 pparagraph tparagraph :: movecursor ( int dx, int dy )
01787 {
01788    pparagraph newcursorpos = this;
01789 
01790    if ( cursorstat )
01791       displaycursor();
01792 
01793    if ( dx == -1 ) {
01794       if ( cursor > 0 )
01795          cursor--;
01796       else
01797          if ( prev ) {
01798             cursor = -1;
01799             newcursorpos = prev;
01800             prev->cursor = prev->size - 1;
01801          }
01802    }
01803    
01804    if ( dx == 1 ) {
01805       if ( cursor < size-1 )
01806          cursor++;
01807       else
01808          if ( next ) {
01809             cursor = -1;
01810             next->cursor = 0;
01811             newcursorpos = next;
01812          }
01813    }
01814 
01815    if ( dy == 1 ) {
01816       if ( cursory < linenum ) {
01817          cursory++;
01818          searchcursorpos++;
01819       } else
01820         if ( next ) {
01821            cursor = -1;
01822            next->cursor = 0;
01823            next->normcursorx = normcursorx;
01824            next->cursorx = normcursorx;
01825            next->cursory = 0;
01826            next->searchcursorpos = 1;
01827            newcursorpos = next;
01828         }
01829    }
01830 
01831    if ( dy == -1 ) {
01832       if ( cursory > 0 ) {
01833          cursory--;
01834          searchcursorpos++;
01835       } else
01836         if ( prev ) {
01837            cursor = -1;
01838            prev->cursor = 0;
01839            prev->normcursorx = normcursorx;
01840            prev->cursorx = normcursorx;
01841            prev->cursory = prev->linenum;
01842            prev->searchcursorpos = 1;
01843            newcursorpos = prev;
01844         }
01845    }
01846 
01847    newcursorpos->reflow( 0 );
01848    newcursorpos->checkcursorpos();
01849    newcursorpos->displaycursor();
01850    return newcursorpos;
01851 }
01852 
01853 
01854 void tparagraph :: displaycursor ( void )
01855 {
01856    if ( cursor >= 0 ) {
01857       int starty;
01858       if ( ps.line1num < 0 ) {
01859          starty = winy1 + (ps.line1num + cursory) * activefontsettings.height;
01860          // startline = -ps.line1num;
01861       } else {
01862          starty = winy1 + (ps.line1num + cursory) * activefontsettings.height;
01863          // startline = 0;
01864       }
01865 
01866       if ( starty  < winy2 ) {
01867          collategraphicoperations cgo ( winx1 + cursorx-2,   starty, winx1 + cursorx+2,   starty + activefontsettings.height );
01868          xorline ( winx1 + cursorx,   starty+1, winx1 + cursorx,   starty + activefontsettings.height - 1, blue  );
01869          if ( cursorx )
01870            xorline ( winx1 + cursorx-1, starty+1, winx1 + cursorx-1, starty + activefontsettings.height - 1, blue  );
01871          cursorstat = !cursorstat;
01872       }
01873    }
01874 }
01875 
01876 void tparagraph :: setpos ( int x1, int y1, int y2, int linepos, int linenum  )
01877 {
01878    winx1 = x1;
01879    winy1 = y1;
01880    winy2 = y2;
01881    ps.line1num = linepos;
01882    maxlinenum = linenum;
01883 }
01884 
01885 void tparagraph :: display ( void )
01886 {
01887    if ( cursorstat )
01888       displaycursor();
01889    cursorstat = 0;
01890 
01891    int startline;
01892    int starty;
01893    if ( ps.line1num < 0 ) {
01894       starty = winy1;
01895       startline = -ps.line1num;
01896    } else {
01897       starty = winy1 + ps.line1num * activefontsettings.height;
01898       startline = 0;
01899    }
01900 
01901    while ( startline <= linenum  && starty < winy2 ) {
01902       char *c = &linestart[ startline ] [ linelength [ startline ]] ;
01903       char d = *c;
01904       *c = 0;
01905 
01906       showtext2 ( linestart[ startline ], winx1, starty );
01907 
01908       *c = d;
01909       starty += activefontsettings.height;
01910       startline++;
01911    } ; /* enddo */
01912 
01913    if ( cursor >= 0 )
01914       displaycursor();
01915 }
01916 
01917 
01918 
01919 
01920 tmessagedlg :: tmessagedlg ( void )
01921 {
01922     firstparagraph = NULL;
01923     lastcursortick = 0;
01924     blinkspeed = 80;
01925 }
01926 
01927 void tmessagedlg :: inserttext ( const ASCString& txt )
01928 {
01929    if ( txt.empty() )
01930       firstparagraph = new tparagraph;
01931    else {
01932       firstparagraph = NULL;
01933       actparagraph = NULL;
01934       int pos = 0;
01935       int start = 0;
01936       const char* c = txt.c_str();
01937       while ( c[pos] ) {
01938          int sz = 0;
01939          if ( strnicmp(&c[pos], "#CRT#" , 5 ) == 0 )
01940             sz = 5;
01941          if ( strnicmp(&c[pos], "\r\n" , 2 ) == 0 )
01942             sz = 2;
01943          if ( strnicmp(&c[pos], "\n" , 2 ) == 0 )
01944             sz = 1;
01945          if ( sz ) {
01946             ASCString s = txt;
01947             if ( start ) {
01948                s.erase ( 0, start );
01949                s.erase ( pos-start );
01950             } else
01951                s.erase ( pos );
01952             actparagraph = new tparagraph ( actparagraph );
01953             if ( !firstparagraph )
01954                firstparagraph = actparagraph;
01955 
01956             actparagraph->addtext ( s );
01957             pos+=sz;
01958             start = pos;
01959          } else
01960             pos++;
01961       } /* endwhile */
01962 
01963       if ( start < txt.length() ) {
01964          actparagraph = new tparagraph ( actparagraph );
01965          if ( !firstparagraph )
01966              firstparagraph = actparagraph;
01967          actparagraph->addtext ( &(txt.c_str()[start]) );
01968       }
01969 
01970    }
01971 }
01972 
01973 void tmessagedlg :: run ( void )
01974 {
01975    tdialogbox::run ( );
01976    if ( prntkey != cto_invvalue ) {
01977       if ( prntkey == cto_bspace )
01978          actparagraph = actparagraph->erasechar ( 1 );
01979       else
01980       if ( taste == cto_entf )
01981          actparagraph->erasechar ( 2 );
01982       else
01983       if ( taste == cto_left )
01984          actparagraph = actparagraph->movecursor ( -1, 0 );
01985       else
01986       if ( taste == cto_right )
01987          actparagraph = actparagraph->movecursor ( 1, 0 );
01988       else
01989       if ( taste == cto_up )
01990          actparagraph = actparagraph->movecursor ( 0, -1 );
01991       else
01992       if ( taste == cto_down )
01993          actparagraph = actparagraph->movecursor ( 0, 1 );
01994       else
01995       if ( taste == cto_enter )
01996          actparagraph = actparagraph->cut ( );
01997       else
01998       if ( taste == cto_esc )
01999          printf("\a");
02000       else
02001       if ( prntkey > 31 && prntkey < 256 )
02002          actparagraph->addchar ( prntkey );
02003    }
02004    if ( lastcursortick + blinkspeed < ticker ) {
02005       actparagraph->displaycursor();
02006       lastcursortick = ticker;
02007    }
02008 }
02009 
02010 ASCString tmessagedlg :: extracttext ()
02011 {
02012    tparagraph text;
02013 
02014    actparagraph = firstparagraph;
02015    while ( actparagraph ) {
02016       text.addtext ( actparagraph->text );
02017       text.addtext ( "#crt#" );
02018       actparagraph = actparagraph->next;
02019    }
02020    return text.text;
02021 
02022 }
02023 
02024 tmessagedlg :: ~tmessagedlg ( )
02025 {
02026    actparagraph = firstparagraph;
02027    while ( actparagraph ) {
02028       pparagraph temp = actparagraph->next;
02029       delete actparagraph;
02030       actparagraph = temp;
02031    }
02032 }
02033 
02034 void tmessagedlg :: setup ( void )
02035 {
02036    xsize = 500;
02037    ysize = 450;
02038    ok = 0;
02039    tx1 = 20;
02040    ty1 = starty + 10;
02041    tx2 = xsize - 40;
02042    ty2 = ysize - ty1 - 80;
02043 
02044    addbutton ( "~S~end", 10, ysize - 30, xsize / 2 - 5, ysize - 10 , 0, 1, 1, true );
02045    clearkey ( 1 );
02046    addkey ( 1, cto_stp + cto_s );
02047 
02048    addbutton ( "~C~ancel", xsize / 2 + 5, ysize - 30, xsize - 10, ysize - 10 , 0, 1, 2, true );
02049    clearkey ( 2 );
02050    addkey ( 2, cto_stp + cto_c );
02051 
02052    int num = 0;
02053    for ( int i = 0; i < 8; i++ ) {
02054       if ( actmap->player[i].exist() )
02055          if ( actmap->actplayer != i ) {
02056             int x = 20 + ( num % 2 ) * 200;
02057             int y = ty2 + 10 + ( num / 2 ) * 20;
02058             // this is a leak! As this dialog will be scrapped before the ASC2 release,  I don't care :->
02059             addbutton ( strdup( actmap->player[i].getName().c_str()), x, y, x+ 180, y+15, 3, 0, num+3, true );
02060             addeingabe ( num+3, &to[i], 0, dblue );
02061             num++;
02062          }
02063    }
02064 
02065 
02066 }
02067 
02068 
02069 
02070 
02071 void MultilineEdit :: init ( void )
02072 {
02073    tdialogbox :: init ( );
02074    title = dlg_title.c_str();
02075 
02076    setup();
02077    buildgraphics();
02078 
02079 
02080    rectangle ( x1 + tx1 - 2, y1 + ty1 - 2, x1 + tx2 + 2, y1 + ty2 + 2 ,black );
02081 
02082 
02083    activefontsettings.font = schriften.smallarial;
02084    activefontsettings.length = tx2 - tx1 -1 ;
02085    activefontsettings.height = activefontsettings.font->height+5;
02086    activefontsettings.background = dblue;
02087    activefontsettings.color = black;
02088    activefontsettings.justify = lefttext;
02089 
02090    inserttext ( text.c_str() );
02091    actparagraph = firstparagraph;
02092    actparagraph->cursor = 0;
02093    actparagraph->setpos( x1 + tx1, y1 + ty1, y1 + ty2, 0, 13 );
02094 
02095    while ( actparagraph ) {
02096       actparagraph->reflow( 0 );
02097       actparagraph = actparagraph->next;
02098    }
02099    actparagraph = firstparagraph;
02100    actparagraph->checkscrolldown();
02101    actparagraph->display();
02102 
02103 
02104 }
02105 
02106 
02107 void MultilineEdit :: setup ( void )
02108 {
02109    xsize = 500;
02110    ysize = 400;
02111    ok = 0;
02112    tx1 = 20;
02113    ty1 = starty + 10;
02114    tx2 = xsize - 40;
02115    ty2 = ysize - ty1 - 40;
02116 
02117    addbutton ( "~O~k", 10, ysize - 30, xsize / 2 - 5, ysize - 10 , 0, 1, 1, true );
02118    clearkey ( 1 );
02119    addkey ( 1, cto_stp + cto_o );
02120 
02121    addbutton ( "~C~ancel", xsize / 2 + 5, ysize - 30, xsize - 10, ysize - 10 , 0, 1, 2, true );
02122    clearkey ( 2 );
02123    addkey ( 2, cto_stp + cto_c );
02124 
02125 }
02126 
02127 
02128 void MultilineEdit :: buttonpressed ( int id )
02129 {
02130    tmessagedlg :: buttonpressed ( id );
02131    if ( id == 1 )
02132       ok = 1;
02133    if ( id == 2 )
02134       ok = 2;
02135 }
02136 
02137 
02138 void MultilineEdit :: run ( void )
02139 {
02140    mousevisible ( true );
02141    do {
02142       tmessagedlg::run ( );
02143    } while ( !ok );
02144 
02145    if ( ok == 1 ) {
02146       text = extracttext();
02147       textchanged =  true;
02148    }
02149 }
02150 
02151 
02152 
02153 void selectgraphicset ( void )
02154 {
02155    ASCString filename = selectFile( "*.gfx", true );
02156    if ( !filename.empty() ) {
02157       int id = getGraphicSetIdFromFilename ( filename.c_str() );
02158       if ( id != actmap->graphicset ) {
02159          actmap->graphicset = id;
02160          displaymap();
02161       }
02162    }
02163 }
02164 
02165 int editInt( const ASCString& title, int defaultValue, int minValue, int maxValue )
02166 {
02167    return getid( title.c_str(), defaultValue, minValue, maxValue );
02168 }
02169 
02170 void displayActionError( const ActionResult& result, const ASCString& additionalInfo  )
02171 {
02172    ASCString s = getmessage(result.getCode());
02173    s += "\n" + result.getMessage();
02174    if ( !additionalInfo.empty() )
02175       s += "\n" + additionalInfo;
02176    
02177    errorMessage( s );  
02178 }
02179 
02180 
02181 
02182 
02183 

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