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

asc-mainscreen.cpp

Go to the documentation of this file.
00001 
00002 /***************************************************************************
00003  *                                                                         *
00004  *   This program is free software; you can redistribute it and/or modify  *
00005  *   it under the terms of the GNU General Public License as published by  *
00006  *   the Free Software Foundation; either version 2 of the License, or     *
00007  *   (at your option) any later version.                                   *
00008  *                                                                         *
00009  ***************************************************************************/
00010 
00011 
00012 #include "global.h"
00013 
00014 #include <stdio.h>
00015 #include <cstring>
00016 #include <stdlib.h>
00017 #include <new>
00018 #include <cstdlib>
00019 #include <ctype.h>
00020 #include <algorithm>
00021 #include <memory>
00022 #include <SDL_image.h>
00023 #include <SDL_mixer.h>
00024 
00025 #include <pgpopupmenu.h>
00026 #include <pgmenubar.h>
00027 
00028 #include "paradialog.h"
00029 
00030 #include "misc.h"
00031 #include "iconrepository.h"
00032 #include "dashboard.h"
00033 #include "asc-mainscreen.h"
00034 #include "guiiconhandler.h"
00035 #include "guifunctions.h"
00036 #include "graphics/blitter.h"
00037 #include "graphics/drawing.h"
00038 #include "overviewmappanel.h"
00039 #include "ai/ai.h"
00040 #include "itemrepository.h"
00041 #include "mapdisplay.h"
00042 #include "sg.h"
00043 #include "gameoptions.h"
00044 #include "dialog.h"
00045 #include "widgets/textrenderer-addons.h"
00046 
00047 ASC_MainScreenWidget*  mainScreenWidget = NULL ;
00048 
00049 
00050 MainScreenWidget* getMainScreenWidget()
00051 {
00052    return mainScreenWidget;
00053 }
00054 
00055 class Menu : public PG_MenuBar {
00056 
00057     PG_PopupMenu* currentMenu;
00058     typedef list<PG_PopupMenu*> Categories;
00059     Categories categories;
00060 
00061    public:
00062       Menu ( PG_Widget *parent, const PG_Rect &rect=PG_Rect::null);
00063       
00064    protected:
00065       void setup();   
00066       bool execAction  (PG_PopupMenu::MenuItem* menuItem );
00067 
00068    private:
00069       void addbutton(const char* name, int id );
00070       void addfield ( const char* name );
00071      
00072 };
00073 
00074 
00075 
00076 
00077 
00078 
00079 
00080 
00081 bool Menu::execAction  (PG_PopupMenu::MenuItem* menuItem )
00082 {
00083    execUserAction_ev( tuseractions( menuItem->getId() ) );
00084 
00085    return true;
00086 }
00087 
00088 
00089 #define HIGHLIGHT
00090 
00091 void Menu::addfield( const char* name )
00092 {
00093    currentMenu = new PG_PopupMenu( NULL, -1, -1, "" );
00094 
00095 #ifdef HIGHLIGHT
00096    categories.push_back ( currentMenu );
00097    Add ( name, currentMenu );
00098 #else
00099    ASCString s = name;
00100    while ( s.find ( "~") != ASCString::npos )
00101       s.erase( s.find( "~"),1 );
00102    Add ( s, currentMenu );
00103 #endif
00104 
00105    currentMenu->sigSelectMenuItem.connect( SigC::slot( *this, &Menu::execAction ));
00106 }
00107 
00108 void Menu::addbutton( const char* name, int id )
00109 {
00110 #ifdef HIGHLIGHT
00111    currentMenu->addMenuItem( name, id );
00112 #else
00113    ASCString s = name;
00114    while ( s.find ( "~") != ASCString::npos )
00115       s.erase( s.find( "~"),1 );
00116 
00117    currentMenu->addMenuItem( s, id );
00118 #endif
00119 
00120 }
00121 
00122 
00123 void Menu::setup()
00124 {
00125    addfield ( "Glo~b~al" );
00126    addbutton ( "~O~ptions", ua_gamepreferences );
00127    addbutton ( "~S~ound options", ua_soundDialog );
00128    addbutton ( "~E~mail options", ua_emailOptions );
00129    currentMenu->addSeparator();
00130    addbutton ( "~M~ain menu\tESC", ua_mainmenu );
00131    currentMenu->addSeparator();
00132    addbutton ( "~Q~uit\tctrl-q", ua_exitgame );
00133 
00134 
00135    addfield ("~G~ame");
00136    addbutton ( "~N~ew Game\tctrl-n", ua_newGame );
00137    currentMenu->addSeparator();
00138    addbutton ( "~L~oad game\tctrl-l", ua_loadgame );
00139    addbutton ( "Load most recent game\tctrl-shift-l", ua_loadrecentgame );
00140    addbutton ( "~S~ave game\tctrl-s", ua_savegame );
00141    currentMenu->addSeparator();
00142    addbutton ( "Continue network game\tF3", ua_continuenetworkgame);
00143    addbutton ( "Most recent network game\tShift-F3", ua_continuerecentnetworkgame);
00144    // addbutton ( "setup Net~w~ork", ua_setupnetwork );
00145    addbutton ( "Change Passw~o~rd", ua_changepassword );
00146    addbutton ( "supervise network game\tF4", ua_networksupervisor );
00147    currentMenu->addSeparator();
00148    addbutton ( "~D~iplomacy", ua_setupalliances);
00149    addbutton ( "transfer ~U~nit control", ua_giveunitaway );
00150    addbutton ( "~T~ransfer resources", ua_settribute);
00151    addbutton ( "~C~ancel Research", ua_cancelResearch );
00152    currentMenu->addSeparator();
00153    addbutton ( "~E~dit Player Data", ua_editPlayerData);
00154 
00155 
00156 
00157    addfield ( "~I~nfo" );
00158    addbutton ( "~V~ehicle types", ua_vehicleinfo );
00159    addbutton ( "Unit ~w~eapon range\t3", ua_viewunitweaponrange );
00160    addbutton ( "Unit ~m~ovement range\t4", ua_viewunitmovementrange );
00161    addbutton ( "~G~ame Time", ua_GameStatus );
00162    addbutton ( "unit ~S~et information", ua_UnitSetInfo );
00163    addbutton ( "~T~errain\t7", ua_viewterraininfo );
00164    addbutton ( "~U~nit weight\t8", ua_unitweightinfo );
00165    currentMenu->addSeparator();
00166    addbutton ( "~R~esearch", ua_researchinfo );
00167    addbutton ( "~P~lay time", ua_showPlayerSpeed );
00168    addbutton ( "~C~argo Summary\tctrl-c", ua_cargosummary );
00169    addbutton ( "Unit Summary\tctrl-f", ua_unitsummary );
00170    currentMenu->addSeparator();
00171    addbutton ( "Unit Production Analysis", ua_unitproductionanalysis );
00172    addbutton ( "Mining Station Analysis", ua_showMiningPower );
00173    
00174    // addbutton ( "~R~esearch status", ua_showResearchStatus );
00175 
00176    // addbutton ( "vehicle ~I~mprovement\tF7", ua_dispvehicleimprovement);
00177 
00178 
00179    // addfield ( "~S~tatistics" );
00180    
00181 //   addbutton ( "~R~esources ", ua_statisticdialog );
00182    // addbutton ( "seperator");
00183    // addbutton ( "~H~istory");
00184 
00185    addfield ( "~M~essage");
00186    addbutton ( "~n~ew message", ua_newmessage );
00187    addbutton ( "new reminder\tctrl-r", ua_createReminder );
00188    addbutton ( "view ~q~ueued messages", ua_viewqueuedmessages );
00189    addbutton ( "view ~s~ent messages", ua_viewsentmessages );
00190    addbutton ( "view ~r~eceived messages", ua_viewreceivedmessages);
00191    currentMenu->addSeparator();
00192    addbutton ( "view ~j~ournal", ua_viewjournal );
00193    addbutton ( "~a~ppend to journal", ua_editjournal );
00194 
00195    addfield ( "~T~ools" );
00196    addbutton ( "save ~M~ap as PNG", ua_writemaptopcx );
00197    addbutton ( "save ~S~creen as PCX", ua_writescreentopcx );
00198    addbutton ( "select graphic set", ua_selectgraphicset );
00199    currentMenu->addSeparator();
00200    addbutton ( "~G~oto coordinate\tctrl-g", ua_gotoPosition );
00201 
00202    addfield ( "~V~iew" );
00203    addbutton ( "toggle ~R~esourceview\t1", ua_changeresourceview );
00204    addbutton ( "toggle unit shading\t2", ua_toggleunitshading );
00205    addbutton ( "show ~P~ipeline net\t9", ua_viewPipeNet );
00206    addbutton ( "show ~V~isibility Range\t0", ua_visibilityInfo );
00207    currentMenu->addSeparator();
00208    addbutton ( "Button Panel", ua_viewButtonPanel );
00209    addbutton ( "Wind Panel", ua_viewWindPanel );
00210    addbutton ( "Unit Info Panel", ua_viewUnitInfoPanel );
00211    addbutton ( "Overview Map Panel", ua_viewOverviewMapPanel );
00212    addbutton ( "Map Control Panel", ua_viewMapControlPanel );
00213    // addbutton("Weathercast", ua_weathercast);
00214    currentMenu->addSeparator();
00215    addbutton ( "Increase Map Zoom\tKP+", ua_increase_zoom );
00216    addbutton ( "Decrease Map Zoom\tKP-", ua_decrease_zoom );
00217 
00218 
00219    addfield ( "~D~ebug" );
00220    addbutton ( "Show ASC search ~P~ath", ua_showsearchdirs );
00221    addbutton ( "SDL settings", ua_SDLinfo );
00222    addbutton ( "Locate File", ua_locatefile );
00223    addbutton ( "test messages", ua_testMessages );
00224    addbutton ( "view font", ua_viewfont );
00225    addbutton ( "memory footprint", ua_getMemoryFootprint );
00226    currentMenu->addSeparator();
00227    addbutton ( "clear image cache", ua_clearImageCache );
00228    addbutton ( "reload dialog theme", ua_reloadDlgTheme );
00229    currentMenu->addSeparator();
00230    addbutton ( "resource analysis", ua_resourceAnalysis );
00231    addbutton ( "show techadapter", ua_showTechAdapter );
00232    addbutton ( "calc airplane endurance", ua_showUnitEndurance );
00233    addbutton ( "show game ~P~arameters", ua_GameParameterInfo );
00234    currentMenu->addSeparator();
00235    addbutton ( "benchmark without view calc", ua_benchgamewov );
00236    addbutton ( "benchmark with view calc", ua_benchgamewv);
00237    addbutton ( "compiler benchmark (AI)", ua_aibench );
00238    // addbutton ( "test memory integrity", ua_heapcheck );
00239 
00240    addfield ( "~H~elp" );
00241    // addbutton ( "HowTo ~S~tart email games", ua_howtostartpbem );
00242    // addbutton ( "HowTo ~C~ontinue email games", ua_howtocontinuepbem );
00243    // currentMenu->addSeparator();
00244    addbutton ( "~K~eys", ua_help );
00245    addbutton ( "~M~ap Layer", ua_viewlayerhelp );
00246    currentMenu->addSeparator();
00247 
00248    addbutton ( "~A~bout", ua_viewaboutmessage );
00249 }
00250 
00251 
00252 Menu::Menu ( PG_Widget *parent, const PG_Rect &rect)
00253     : PG_MenuBar( parent, rect, "MenuBar"),
00254       currentMenu(NULL)
00255 {
00256    activateHotkey( KMOD_ALT );
00257    setup();
00258 }
00259 
00260 
00261 
00262 class UnitWeaponRangeLayer : public MapLayer {
00263    Surface& icon1;
00264    Surface& icon2;
00265    GameMap* gamemap;
00266 
00267    map<MapCoordinate,int> fields;
00268 
00269    void markField( const MapCoordinate& pos )
00270    {
00271       fields[pos] |= 1;
00272    }
00273 
00274       bool addUnit( Vehicle* veh )
00275       {
00276          if ( fieldvisiblenow ( getfield ( veh->xpos, veh->ypos ))) {
00277             int found = 0;
00278             for ( int i = 0; i < veh->typ->weapons.count; i++ ) {
00279                if ( veh->typ->weapons.weapon[i].shootable() ) {
00280                   circularFieldIterator( gamemap,veh->getPosition(), veh->typ->weapons.weapon[i].maxdistance/minmalq, (veh->typ->weapons.weapon[i].mindistance+maxmalq-1)/maxmalq, FieldIterationFunctor( this, &UnitWeaponRangeLayer::markField )  );
00281                   found++;
00282                }
00283             }
00284             if ( found )
00285                fields[veh->getPosition()] |= 2;
00286             
00287             return found;
00288          } else
00289             return false;
00290       };
00291 
00292       void reset()
00293       {
00294          fields.clear();
00295       }
00296    public:
00297 
00298       void operateField( GameMap* actmap, const MapCoordinate& pos )
00299       {
00300          if ( !pos.valid() )
00301             return;
00302          
00303          if ( gamemap && gamemap != actmap ) 
00304             reset();
00305 
00306          gamemap = actmap;
00307          
00308          if ( fields.find( pos ) != fields.end() ) {
00309             if ( fields[pos] & 2 ) {
00310                reset();
00311                setActive(false);
00312                statusMessage("Weapon range layer disabled");
00313                repaintMap();
00314                return;
00315             }
00316          }
00317          
00318          if ( actmap->getField( pos )->vehicle ) {
00319             if ( addUnit( actmap->getField( pos )->vehicle ) ) {
00320                setActive(true);
00321                statusMessage("Weapon range layer enabled");
00322                repaintMap();
00323             }
00324          }
00325       }
00326       
00327       UnitWeaponRangeLayer() : icon1 ( IconRepository::getIcon( "markedfield-red.png")), icon2 ( IconRepository::getIcon( "markedfield-red2.png")), gamemap(NULL) {
00328          // cursorMoved.connect( SigC::slot( *this, UnitWeaponRangeLayer::cursorMoved ));
00329       }
00330 
00331       bool onLayer( int layer ) { return layer == 17; };
00332       
00333       void paintSingleField( const MapRenderer::FieldRenderInfo& fieldInfo,  int layer, const SPoint& pos )
00334       {
00335          if ( fieldInfo.gamemap != gamemap && gamemap) {
00336             reset();
00337             gamemap = NULL;
00338             return;
00339          }
00340          
00341          if ( fieldInfo.visibility >= visible_ago) {
00342             if ( fields.find( fieldInfo.pos ) != fields.end() ) {
00343                int p = fields[fieldInfo.pos];
00344                if ( p & 1 )
00345                   fieldInfo.surface.Blit( icon1, pos );
00346                if ( p & 2 )
00347                   fieldInfo.surface.Blit( icon2, pos );
00348             }
00349          }
00350       }
00351 };
00352 
00353 
00354 
00355 class UnitMovementRangeLayer : public MapLayer, public SigC::Object {
00356    Surface& icon;
00357    GameMap* gamemap;
00358 
00359    map<MapCoordinate,int> fields;
00360 
00361    void markField( const MapCoordinate& pos )
00362    {
00363       fields[pos] |= 1;
00364    }
00365 
00366    bool addUnit( Vehicle* veh )
00367    {
00368 
00369       if ( fieldvisiblenow ( getfield ( veh->xpos, veh->ypos ))) {
00370          int counter = 0;
00371          VehicleMovement vm ( NULL, NULL );
00372 
00373 
00374          TemporaryContainerStorage tcs( veh );
00375          veh->setMovement( veh->maxMovement(), 0 );
00376          if ( vm.available ( veh )) {
00377 
00378             vm.execute ( veh, -1, -1, 0, -1, -1 );
00379             if ( vm.reachableFields.getFieldNum()) {
00380                for  ( int i = 0; i < vm.reachableFields.getFieldNum(); i++ )
00381                   if ( fieldvisiblenow ( vm.reachableFields.getField ( i ) )) {
00382                      ++counter;
00383                      markField( vm.reachableFields.getFieldCoordinates(i));
00384                   }
00385                for  ( int j = 0; j < vm.reachableFieldsIndirect.getFieldNum(); j++ )
00386                   if ( fieldvisiblenow ( vm.reachableFieldsIndirect.getField ( j ))) {
00387                      markField( vm.reachableFieldsIndirect.getFieldCoordinates(j));
00388                      ++counter;
00389                   }
00390    
00391             }
00392 
00393          }
00394          tcs.restore();
00395       
00396          if ( counter )
00397             fields[veh->getPosition()] |= 2;
00398             
00399          return counter;
00400       } else
00401          return false;
00402    };
00403 
00404    void reset()
00405    {
00406       fields.clear();
00407       if ( isActive() ) {
00408          setActive(false);
00409          statusMessage("Movement range layer disabled");
00410          repaintMap();
00411       }
00412    }
00413    public:
00414 
00415       void operateField( GameMap* actmap, const MapCoordinate& pos )
00416       {
00417          if ( !pos.valid() )
00418             return;
00419          
00420          if ( gamemap && gamemap != actmap )
00421             fields.clear();
00422 
00423          gamemap = actmap;
00424          
00425          if ( fields.find( pos ) != fields.end() ) {
00426             if ( fields[pos] & 2 ) {
00427                reset();
00428                return;
00429             }
00430          }
00431          
00432          if ( actmap->getField( pos )->vehicle ) {
00433             if ( addUnit( actmap->getField( pos )->vehicle ) ) {
00434                setActive(true);
00435                statusMessage("Movement range layer enabled");
00436                repaintMap();
00437             }
00438          }
00439       }
00440       
00441       UnitMovementRangeLayer() : icon ( IconRepository::getIcon( "markedfield-blue.png")), gamemap(NULL) {
00442          cursorMoved.connect( SigC::slot( *this, &UnitMovementRangeLayer::reset ));
00443       }
00444 
00445       bool onLayer( int layer ) { return layer == 17; };
00446       
00447       void paintSingleField( const MapRenderer::FieldRenderInfo& fieldInfo,  int layer, const SPoint& pos )
00448       {
00449          if ( fieldInfo.gamemap != gamemap && gamemap) {
00450             reset();
00451             gamemap = NULL;
00452             return;
00453          }
00454          
00455          if ( fieldInfo.visibility >= visible_ago) {
00456             if ( fields.find( fieldInfo.pos ) != fields.end() ) {
00457                int p = fields[fieldInfo.pos];
00458                if ( p )
00459                   fieldInfo.surface.Blit( icon, pos );
00460             }
00461          }
00462       }
00463 };
00464 
00465 
00466 class VisibilityLayer : public MapLayer {
00467      void renderText( const MapRenderer::FieldRenderInfo& fieldInfo, SPoint pos, const ASCString& text );
00468     public: 
00469       bool onLayer( int layer ) { return layer == 17; };
00470       void paintSingleField( const MapRenderer::FieldRenderInfo& fieldInfo,  int layer, const SPoint& pos );
00471 };
00472 
00473 void VisibilityLayer::paintSingleField( const MapRenderer::FieldRenderInfo& fieldInfo, int layer, const SPoint& pos )
00474 {
00475    if ( fieldvisiblenow( fieldInfo.fld, fieldInfo.gamemap->getPlayerView(), fieldInfo.gamemap )) {
00476 
00477       int view = 0;
00478       int jamming = 0;
00479       for ( int i = 0; i < fieldInfo.gamemap->getPlayerCount(); ++i ) 
00480          if ( fieldInfo.gamemap->getPlayer(i).diplomacy.sharesView( fieldInfo.gamemap->getPlayerView())) {
00481             view += fieldInfo.fld->view[i].view;
00482             jamming += fieldInfo.fld->view[i].jamming;
00483          }
00484 
00485 #if 0
00486       ASCString s;
00487       s.format( "%d/%d", view, jamming);
00488 
00489       font->SetColor( 0xffffff );
00490       PG_FontEngine::RenderText( fieldInfo.surface.getBaseSurface() , PG_Rect( pos.x, pos.y, fieldsizex, fieldsizey), pos.x+6, pos.y + 21, s, font );
00491 
00492       font->SetColor( 0 );
00493       PG_FontEngine::RenderText( fieldInfo.surface.getBaseSurface() , PG_Rect( pos.x, pos.y, fieldsizex, fieldsizey), pos.x+5, pos.y + 20, s, font );
00494 #else
00495 
00496       renderText( fieldInfo, SPoint(pos.x + 10, pos.y + 5), ASCString::toString( view ) + "V");
00497       renderText( fieldInfo, SPoint(pos.x + 10, pos.y + 18), ASCString::toString( jamming ) + "J");
00498       renderText( fieldInfo, SPoint(pos.x + 10, pos.y + 31), ASCString::toString( fieldInfo.fld->getjamming() ) + "T" );
00499 #endif
00500    }
00501 }
00502 
00503 void VisibilityLayer::renderText( const MapRenderer::FieldRenderInfo& fieldInfo, SPoint pos, const ASCString& text )
00504 {
00505    static PG_Font* font = NULL; 
00506    if ( !font ) {
00507       PG_Label l( NULL );
00508       font = new PG_Font( *(l.GetFont()));
00509       font->SetSize( 12 );
00510    }
00511 
00512    font->SetColor( 0xffffff );
00513    PG_FontEngine::RenderText( fieldInfo.surface.getBaseSurface() , PG_Rect( pos.x, pos.y, fieldsizex, fieldsizey), pos.x+1, pos.y + 13, text, font );
00514 
00515    font->SetColor( 0 );
00516    PG_FontEngine::RenderText( fieldInfo.surface.getBaseSurface() , PG_Rect( pos.x, pos.y, fieldsizex, fieldsizey), pos.x, pos.y+12, text, font );
00517 }
00518 
00519 
00520 ASC_MainScreenWidget::ASC_MainScreenWidget( PG_Application& application )
00521    : MainScreenWidget( application ), standardActionsLocked(0), guiHost(NULL), menu(NULL), unitInfoPanel(NULL), windInfoPanel(NULL), mapInfoPanel(NULL)
00522 {
00523 
00524    int mapWidth = Width() - 30;
00525 
00526    PG_Rect mapView(15,30,Width() - 200, Height() - 73);
00527 
00528    if ( CGameOptions::Instance()->panelColumns & 1 ) {
00529       mapView.x = 185;
00530       mapWidth -= 170;
00531    }
00532    if ( CGameOptions::Instance()->panelColumns & 2 ) {
00533       mapWidth -= 170;
00534    }
00535    mapView.my_width = mapWidth;
00536 
00537 
00538    setup( true, mapView );
00539 
00540    displayLogMessage ( 7, "done\n  Menu ");
00541    menu = new Menu(this, PG_Rect(15,0,Width()-200,20));
00542 
00543    dataLoaderTicker();
00544    SetID( ASC_PG_App::mainScreenID );
00545 
00546    
00547    weaponRangeLayer = new UnitWeaponRangeLayer();
00548    mapDisplay->addMapLayer( weaponRangeLayer, "weaprange" );
00549 
00550    movementRangeLayer = new UnitMovementRangeLayer();
00551    mapDisplay->addMapLayer( movementRangeLayer, "moverange" );
00552 
00553    mapDisplay->addMapLayer( new VisibilityLayer(), "visibilityvalue" );
00554 
00555    mapDisplay->layerChanged.connect( SigC::slot( *this, &ASC_MainScreenWidget :: mapLayerChanged));
00556 
00557    // making a copy, because the activateMapLayer will modify the visibleMapLayer object
00558    vector<ASCString> layer = CGameOptions::Instance()->visibleMapLayer;
00559    for ( vector<ASCString>::iterator i = layer.begin(); i != layer.end(); ++i ) 
00560       mapDisplay->activateMapLayer(*i,true);
00561    
00562 
00563 
00564    int counter = 0;
00565    for ( CGameOptions::PanelDataContainer::iterator i = CGameOptions::Instance()->panelData.begin(); i != CGameOptions::Instance()->panelData.end(); ++i ) {
00566       if ( i->second.visible ) {
00567          ++counter;
00568          spawnPanel( i->first );
00569       }
00570    }
00571 
00572    if ( !counter ) {
00573       spawnPanel( UnitInfo );
00574       spawnPanel( ButtonPanel );
00575       spawnPanel( OverviewMap );
00576    }
00577 
00578    // to persuade the linker to really link that file
00579    uselessCallToTextRenderAddons();
00580 }
00581 
00582 void ASC_MainScreenWidget :: mapLayerChanged(bool b, const ASCString& name )
00583 {
00584    mapDisplay->getActiveLayers( CGameOptions::Instance()->visibleMapLayer );
00585    CGameOptions::Instance()->setChanged();
00586 }
00587 
00588 
00589 
00590 void ASC_MainScreenWidget :: lockStandardActions( int dir, int options )
00591 {
00592    standardActionsLocked += dir;
00593    
00594    if( dir > 0 ) { 
00595       lockOptionStack.push_back( lockOptions );
00596       lockOptions = options;
00597       lockOptionsChanged( options );
00598    }
00599    if ( dir < 0 ) {
00600       lockOptions = lockOptionStack.back();
00601       lockOptionStack.pop_back();
00602       lockOptionsChanged( lockOptions );
00603    }
00604    
00605    if ( menu )
00606       if ( standardActionsLocked <= 0 )
00607          menu->Show();
00608       else
00609          menu->Hide();
00610 }
00611 
00612 
00613 
00614 
00615 
00616 void displaymessage2( const char* formatstring, ... )
00617 {
00618 
00619    ASCString s;
00620    
00621     std::va_list arg_ptr;
00622     va_start ( arg_ptr, formatstring );
00623 
00624     s.vaformat( formatstring, arg_ptr );
00625 
00626     va_end ( arg_ptr );
00627 
00628     if ( mainScreenWidget )
00629        mainScreenWidget->displayMessage(s);
00630 }
00631 
00632 
00633 
00634 void ASC_MainScreenWidget::spawnPanel ( const ASCString& panelName )
00635 {
00636    if ( panelName == "WindInfo" )
00637       spawnPanel ( WindInfo );
00638 
00639    if ( panelName == "UnitInfo" )
00640       spawnPanel ( UnitInfo );
00641    
00642    if ( panelName == "GuiIcons" )
00643       spawnPanel ( ButtonPanel );
00644 
00645    if ( panelName == "OverviewMap" )
00646       spawnPanel ( OverviewMap );
00647 
00648    if ( panelName == "MapInfo" )
00649       spawnPanel ( MapControl );
00650 
00651 }
00652 
00653 void ASC_MainScreenWidget::spawnPanel ( Panels panel )
00654 {
00655    if ( panel == WindInfo ) {
00656       if ( !windInfoPanel || !CGameOptions::Instance()->cacheASCGUI ) {
00657          delete windInfoPanel;
00658          windInfoPanel = new WindInfoPanel( this, PG_Rect(Width()-170, 480, 170, 114));
00659       }
00660       windInfoPanel->Show();
00661    }
00662    if ( panel == UnitInfo ) {
00663       if ( !unitInfoPanel || !CGameOptions::Instance()->cacheASCGUI ) {
00664          delete unitInfoPanel;
00665          unitInfoPanel = new UnitInfoPanel( this, PG_Rect(Width()-170, 160, 170, 320));
00666       }
00667       unitInfoPanel->Show();
00668    }
00669    if ( panel == ButtonPanel ) {
00670       if ( !guiHost || !CGameOptions::Instance()->cacheASCGUI ) {
00671          delete guiHost;
00672          guiHost = new NewGuiHost( this, mapDisplay, PG_Rect(Width()-170, Height()-200, 170, 200));
00673          guiHost->pushIconHandler( &GuiFunctions::primaryGuiIcons );
00674       }
00675       guiHost->Show();
00676    }
00677    
00678    if ( panel == OverviewMap ) 
00679       spawnOverviewMapPanel();
00680    
00681    if ( panel == MapControl ) {
00682       if ( !mapInfoPanel || !CGameOptions::Instance()->cacheASCGUI ) {
00683          delete mapInfoPanel;
00684          mapInfoPanel = new MapInfoPanel( this, PG_Rect(Width()-170, 0, 170, 160), mapDisplay );
00685       }
00686       mapInfoPanel->Show();
00687    }
00688 }
00689 
00690 
00691 void ASC_MainScreenWidget::showMovementRange( GameMap* gamemap, const MapCoordinate& pos )
00692 {
00693    movementRangeLayer->operateField( gamemap, pos );
00694 }
00695 
00696 void ASC_MainScreenWidget::showWeaponRange( GameMap* gamemap, const MapCoordinate& pos )
00697 {
00698    weaponRangeLayer->operateField( gamemap, pos );
00699 }
00700 
00701 
00702 
00703 bool ASC_MainScreenWidget::eventKeyDown(const SDL_KeyboardEvent* key)
00704 // bool Menu::eventKeyDown(const SDL_KeyboardEvent* key)
00705 {
00706    if ( standardActionsLocked > 0  )
00707       return false;
00708    
00709    int mod = SDL_GetModState() & ~(KMOD_NUM | KMOD_CAPS | KMOD_MODE);
00710 
00711    if ( !mod  ) {
00712       switch ( key->keysym.sym ) {
00713             case SDLK_ESCAPE:
00714                execUserAction_ev( ua_mainmenu );
00715                return true;
00716                
00717             case SDLK_F1:
00718                execUserAction_ev ( ua_help );
00719                return true;
00720 
00721             case SDLK_F3:
00722                execUserAction_ev ( ua_continuenetworkgame );
00723                return true;
00724 
00725             case SDLK_F4:
00726                execUserAction_ev ( ua_networksupervisor );
00727                return true;
00728 
00729             case SDLK_F8:
00730                {
00731                   int color = actmap->actplayer;
00732                   for ( int p = 0; p < 8; p++ )
00733                      if ( actmap->player[p].stat == Player::computer && actmap->player[p].exist() )
00734                         color = p;
00735 
00736                   if ( actmap->player[color].ai ) {
00737                      AI* ai = (AI*) actmap->player[color].ai;
00738                      ai->showFieldInformation ( actmap->getCursor().x, actmap->getCursor().y );
00739                   }
00740                }
00741                return true;
00742 
00743                case SDLK_F11: {
00744                   int sz = actmap->player[1].unreadmessage.size();
00745                   printf(" %d \n", sz );
00746                }
00747                return true;
00748                
00749             case SDLK_1:
00750                execUserAction_ev ( ua_changeresourceview );
00751                return true;
00752 
00753             case SDLK_2:
00754                execUserAction_ev ( ua_toggleunitshading );
00755                return true;
00756 
00757             case SDLK_3:
00758                execUserAction_ev( ua_viewunitweaponrange );
00759                return true;
00760 
00761             case SDLK_4:
00762                execUserAction_ev( ua_viewunitmovementrange );
00763                return true;
00764 
00765                /*
00766             case SDLK_5:
00767                execUserAction_ev ( ua_GameStatus );
00768                return true;
00769                */
00770 
00771             case SDLK_5: execUserAction_ev ( ua_showCargoLayer );
00772                return true;
00773 
00774                /*
00775             case SDLK_6:
00776                execUserAction_ev ( ua_UnitSetInfo );
00777                return true;
00778                */
00779 
00780             case SDLK_7:
00781                execUserAction_ev ( ua_viewterraininfo );
00782                return true;
00783 
00784             case SDLK_8:
00785                execUserAction_ev ( ua_unitweightinfo );
00786                return true;
00787 
00788             case SDLK_9:
00789                execUserAction_ev ( ua_viewPipeNet );
00790                return true;
00791 
00792             case SDLK_0: execUserAction_ev( ua_visibilityInfo );
00793                return true;
00794 
00795 
00796             case SDLK_PLUS:   
00797             case SDLK_KP_PLUS: execUserAction_ev( ua_increase_zoom );
00798                return true;
00799 
00800             case SDLK_MINUS:   
00801             case SDLK_KP_MINUS: execUserAction_ev( ua_decrease_zoom );
00802                return true;
00803                
00804                case SDLK_F10: {
00805                   
00806                   PG_ScrollBar* sb = new PG_ScrollBar( NULL, PG_Rect( 20, 50, 15, 400), PG_ScrollBar::VERTICAL, -1, "DLGScrollbar" );
00807                   sb->SetPageSize(10);
00808                   sb->SetRange(0, 100);
00809                   sb->Show();
00810                   
00811                }
00812             // testText();
00813             break;
00814                
00815             default:;
00816       }
00817    }
00818 
00819    if ( (mod & KMOD_SHIFT) && (mod & KMOD_CTRL)) {
00820       switch ( key->keysym.sym ) {
00821             case SDLK_F11: {
00822                tfield* fld = actmap->getField(actmap->getCursor() );
00823                if ( actmap && actmap->getCurrentPlayer().stat == Player::supervisor && fld && fld->vehicle )
00824                   fld->vehicle->fillMagically( true, false );
00825                return true;
00826             }
00827             case SDLK_l:
00828                execUserAction_ev ( ua_loadrecentgame );
00829                return true;
00830 
00831             default:;
00832       }
00833    }
00834 
00835    if ( mod & KMOD_CTRL ) {
00836       switch ( key->keysym.sym ) {
00837 
00838             case SDLK_f:
00839                execUserAction_ev ( ua_unitsummary );
00840                return true;
00841 
00842             case SDLK_c:
00843                execUserAction_ev ( ua_cargosummary );
00844                return true;
00845 
00846             case SDLK_g:
00847                execUserAction_ev( ua_gotoPosition );
00848                return true;
00849 
00850             case SDLK_l:
00851                execUserAction_ev ( ua_loadgame );
00852                return true;
00853 
00854             case SDLK_r:
00855                execUserAction_ev( ua_createReminder );
00856                return true;
00857                
00858             case SDLK_s:
00859                execUserAction_ev ( ua_savegame );
00860                return true;
00861 
00862 
00863             case SDLK_n:
00864                execUserAction_ev ( ua_newGame );
00865                return true;
00866 
00867             case SDLK_0: execUserAction_ev( ua_writescreentopcx );
00868                return true;
00869 
00870             case SDLK_F12:
00871                   execUserAction_ev ( ua_exportUnitToFile );
00872                return true;
00873 
00874             case SDLK_F10: {
00875                SDL_Surface* s = PG_Application::GetScreen();
00876                SDL_LockSurface( s );
00877                int* i = (int*) (s->pixels);
00878                for ( int x = 0; x < 100; ++x )
00879                   i[x * s->pitch/4 + x] = 0xffffff;
00880                SDL_UnlockSurface( s );
00881                SDL_UpdateRect(s,0,0,0,0);
00882                            }
00883 
00884             return true;
00885             
00886 
00887             case SDLK_q:
00888                execUserAction_ev ( ua_exitgame );
00889                return true;
00890             default:;
00891       }
00892    }
00893 
00894    if ( mod & KMOD_ALT ) {
00895       switch ( key->keysym.sym ) {
00896             case SDLK_RETURN:
00897                getPGApplication().toggleFullscreen();
00898                return true;
00899 
00900             default:;
00901       }
00902    }
00903 
00904    if ( mod & KMOD_SHIFT ) {
00905       switch ( key->keysym.sym ) {
00906             case SDLK_F3:
00907                execUserAction_ev ( ua_continuerecentnetworkgame );
00908                return true;
00909 
00910             default:;
00911       }
00912    }
00913    return false;
00914 }

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