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

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