00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "global.h"
00012
00013 #include <stdio.h>
00014 #include <cstring>
00015 #include <stdlib.h>
00016 #include <new>
00017 #include <cstdlib>
00018 #include <ctype.h>
00019 #include <algorithm>
00020 #include <memory>
00021 #include <SDL_mixer.h>
00022 #include <iostream>
00023 #include <set>
00024
00025 #include "paradialog.h"
00026 #include "pgtooltiphelp.h"
00027 #include "pgpopupmenu.h"
00028 #include "pgmenubar.h"
00029
00030 #include "basegfx.h"
00031 #include "misc.h"
00032 #include "iconrepository.h"
00033 #include "maped-mainscreen.h"
00034 #include "graphics/blitter.h"
00035 #include "graphics/drawing.h"
00036 #include "edglobal.h"
00037 #include "mapdisplay.h"
00038 #include "spfst.h"
00039 #include "overviewmappanel.h"
00040 #include "edselfnt.h"
00041 #include "edmisc.h"
00042 #include "gameoptions.h"
00043 #include "widgets/dropdownselector.h"
00044
00045 Maped_MainScreenWidget* mainScreenWidget = NULL ;
00046
00047 MainScreenWidget* getMainScreenWidget()
00048 {
00049 return mainScreenWidget;
00050 }
00051
00052
00053 class Menu : public PG_MenuBar {
00054
00055 PG_PopupMenu* currentMenu;
00056 typedef list<PG_PopupMenu*> Categories;
00057 Categories categories;
00058
00059 public:
00060 Menu ( PG_Widget *parent, const PG_Rect &rect=PG_Rect::null);
00061
00062 protected:
00063 void setup();
00064 bool execAction (PG_PopupMenu::MenuItem* menuItem );
00065
00066 private:
00067 void addbutton(const char* name, int id );
00068 void addfield ( const char* name );
00069
00070 };
00071
00072
00073
00074 bool Menu::execAction (PG_PopupMenu::MenuItem* menuItem )
00075 {
00076 execaction_ev( tuseractions( menuItem->getId() ) );
00077
00078 return true;
00079 }
00080
00081
00082 void Menu::addfield( const char* name )
00083 {
00084 currentMenu = new PG_PopupMenu( NULL, -1, -1, "" );
00085 categories.push_back ( currentMenu );
00086 Add ( name, currentMenu );
00087 currentMenu->sigSelectMenuItem.connect( SigC::slot( *this, &Menu::execAction ));
00088
00089 }
00090
00091 void Menu::addbutton( const char* name, int id )
00092 {
00093 currentMenu->addMenuItem( name, id );
00094 }
00095
00096
00097 void Menu::setup()
00098 {
00099 addfield ( "~F~ile" );
00100 addbutton ( "~N~ew map\tctrl+N" , act_newmap );
00101 addbutton ( "~L~oad map\tctrl+L", act_loadmap );
00102 addbutton ( "~S~ave map\tS", act_savemap );
00103 addbutton ( "Save map ~a~s", act_savemapas );
00104 addbutton ( "Edit Map ~A~rchival Information", act_editArchivalInformation );
00105 currentMenu->addSeparator();
00106 addbutton ( "Load Clipboard", act_readClipBoard );
00107 addbutton ( "Save Clipboard", act_saveClipboard );
00108 currentMenu->addSeparator();
00109 addbutton ( "~W~rite map to PNG-File\tctrl+G", act_maptopcx);
00110 addbutton ( "~I~mport BI map\tctrl-i", act_import_bi_map );
00111 addbutton ( "Insert ~B~I map", act_insert_bi_map );
00112 currentMenu->addSeparator();
00113 addbutton ( "Increase Map Zoom\tKP+", act_increase_zoom );
00114 addbutton ( "Decrease Map Zoom\tKP-", act_decrease_zoom );
00115 currentMenu->addSeparator();
00116 addbutton( "Edit Preferences", act_editpreferences );
00117 currentMenu->addSeparator();
00118 addbutton ( "~Q~uit\tctrl-q", act_end);
00119
00120 addfield ("~E~dit");
00121 addbutton ( "~C~opy \tctrl+C", act_copyToClipboard );
00122 addbutton ( "Cu~t~\tctrl+X", act_cutToClipboard );
00123 addbutton ( "~P~aste \tctrl+V", act_pasteFromClipboard );
00124 currentMenu->addSeparator();
00125 addbutton ( "Resi~z~e map\tR", act_resizemap );
00126 addbutton ( "set global uniform ~w~eather\tctrl-W", act_setactweatherglobal );
00127
00128 addbutton ( "~C~reate regional ressources", act_createresources );
00129 addbutton ( "Create global ressources\tctrl+F", act_createresources2 );
00130 addbutton ( "Clear all mineral resources", act_clearresources );
00131 currentMenu->addSeparator();
00132 addbutton ( "~S~et turn number", act_setTurnNumber );
00133 currentMenu->addSeparator();
00134 addbutton ( "~S~etup Players", act_setupplayers );
00135 addbutton ( "Setup ~A~lliances", act_setupalliances );
00136 addbutton ( "~E~dit Research", act_editResearch );
00137 addbutton ( "edit ~R~esearch points", act_editResearchPoints );
00138 addbutton ( "edit ~T~ech adapter", act_editTechAdapter );
00139 addbutton ( "edit player data...", act_resetPlayerData );
00140
00141 addfield ("~S~elect");
00142 addbutton ( "Vehicle\tF2", act_selunit );
00143 addbutton ( "Terrain from map\tF3", act_selbodentyp );
00144 addbutton ( "Terrain from list\tctrl-F3", act_selbodentypAll );
00145 addbutton ( "Object from map \tF4", act_selbodentyp );
00146 addbutton ( "Object from list \tctrl-F4", act_selobjectAll );
00147 addbutton ( "Building Type\tF5", act_selbuilding );
00148 addbutton ( "Mine\tF6", act_selmine );
00149
00150
00151 addfield ("~T~ools");
00152
00153
00154
00155
00156 addbutton ( "~M~ap generator\tG", act_mapgenerator );
00157 addbutton ( "Sm~o~oth coasts", act_smoothcoasts );
00158 addbutton ( "~U~nitset transformation", act_unitsettransformation );
00159 addbutton ( "map ~t~ransformation", act_transformMap );
00160 addbutton ( "Com~p~are Resources ", act_displayResourceComparison );
00161 addbutton ( "Show Pipeline Net\t9", act_showPipeNet );
00162 addbutton ( "Generate Tech Tree", act_generateTechTree );
00163 addbutton ( "Mirror Map", act_mirrorMap );
00164 addbutton ( "Copy Area", act_copyArea );
00165 addbutton ( "Paste Area", act_pasteArea );
00166 currentMenu->addSeparator();
00167 addbutton ( "PBP Player Statistics", act_pbpstatistics );
00168
00169 addfield ("~O~ptions");
00170 addbutton ( "~M~ap values\tctrl+M", act_changemapvals );
00171 addbutton ( "~C~hange players\tO", act_changeplayers);
00172 addbutton ( "~E~dit events\tE", act_events );
00173
00174 currentMenu->addSeparator();
00175 addbutton ( "~T~oggle ResourceView\tctrl+B", act_toggleresourcemode);
00176 addbutton ( "~B~I ResourceMode", act_bi_resource );
00177 addbutton ( "~A~sc ResourceMode", act_asc_resource );
00178 addbutton ( "edit map ~P~arameters", act_setmapparameters );
00179 addbutton ( "setup item ~F~ilters\tctrl+h", act_setunitfilter );
00180 addbutton ( "select ~G~raphic set", act_selectgraphicset );
00181
00182 addfield ("~D~evelopment");
00183 addbutton ( "Dump ~B~uilding", act_dumpBuilding );
00184 addbutton ( "Dump all Buildings", act_dumpAllBuildings );
00185 addbutton ( "Dump ~V~ehicle", act_dumpVehicle );
00186 addbutton ( "Dump all Vehicles", act_dumpAllVehicleDefinitions );
00187 addbutton ( "Dump ~O~bject", act_dumpObject );
00188 addbutton ( "Locate Item by ~I~D", act_locateItemByID );
00189 currentMenu->addSeparator();
00190 addbutton ( "Exchange ~G~raphics", act_exchangeGraphics );
00191
00192
00193
00194
00195
00196 addfield ("~H~elp");
00197 addbutton ( "~U~nit Information\tctrl+U", act_unitinfo );
00198 addbutton ( "unit~S~et Information", act_unitSetInformation );
00199 addbutton ( "~T~errain Information\t7", act_terraininfo );
00200 currentMenu->addSeparator();
00201 addbutton ( "~H~elp System\tF1", act_help );
00202 addbutton ( "~A~bout", act_about );
00203 }
00204
00205
00206 Menu::Menu ( PG_Widget *parent, const PG_Rect &rect)
00207 : PG_MenuBar( parent, rect, "MenuBar"),
00208 currentMenu(NULL)
00209 {
00210 activateHotkey( KMOD_ALT );
00211 setup();
00212 }
00213
00214 namespace ContextMenu {
00215
00216 class AutoTextContextAction : public ContextAction {
00217 public:
00218 ASCString getText( const MapCoordinate& pos )
00219 {
00220 return execactionnames[getActionID()];
00221 };
00222 };
00223
00224 class ContainerProperties: public ContextAction {
00225 public:
00226 bool available( const MapCoordinate& pos )
00227 {
00228 return actmap->getField(pos)->getContainer();
00229 };
00230
00231 ASCString getText( const MapCoordinate& pos )
00232 {
00233 if ( actmap->getField(pos)->vehicle )
00234 return "edit unit properties";
00235 else
00236 return "edit building properties";
00237 };
00238
00239 int getActionID()
00240 {
00241 return act_changeunitvals ;
00242 }
00243 };
00244
00245 class ContainerCargo: public ContextAction {
00246 public:
00247 bool available( const MapCoordinate& pos )
00248 {
00249 return actmap->getField(pos)->getContainer() && actmap->getField(pos)->getContainer()->baseType->maxLoadableUnits > 0;
00250 };
00251
00252 ASCString getText( const MapCoordinate& pos )
00253 {
00254 if ( actmap->getField(pos)->vehicle )
00255 return "edit unit cargo";
00256 else
00257 return "edit building cargo";
00258 };
00259
00260 int getActionID()
00261 {
00262 return act_changecargo ;
00263 }
00264 };
00265
00266 class DeleteVehicle: public ContextAction {
00267 public:
00268 bool available( const MapCoordinate& pos )
00269 {
00270 return actmap->getField(pos)->vehicle;
00271 };
00272
00273 ASCString getText( const MapCoordinate& pos )
00274 {
00275 return "delete unit";
00276 };
00277
00278 int getActionID()
00279 {
00280 return act_deleteunit ;
00281 }
00282 };
00283
00284 class DeleteBuilding: public ContextAction {
00285 public:
00286 bool available( const MapCoordinate& pos )
00287 {
00288 return actmap->getField(pos)->building;
00289 };
00290
00291 ASCString getText( const MapCoordinate& pos )
00292 {
00293 return "delete building";
00294 };
00295
00296 int getActionID()
00297 {
00298 return act_deletebuilding;
00299 }
00300 };
00301
00302 class ContainerProduction: public AutoTextContextAction {
00303 public:
00304 bool available( const MapCoordinate& pos )
00305 {
00306 return actmap->getField(pos)->getContainer() && actmap->getField(pos)->getContainer()->baseType->hasFunction( ContainerBaseType::InternalVehicleProduction );
00307 };
00308
00309 int getActionID()
00310 {
00311 return act_changeproduction ;
00312 }
00313 };
00314
00315 class DeleteMine: public AutoTextContextAction {
00316 public:
00317 bool available( const MapCoordinate& pos )
00318 {
00319 return !actmap->getField(pos)->mines.empty() ;
00320 };
00321
00322 int getActionID()
00323 {
00324 return act_deletemine ;
00325 }
00326 };
00327
00328 class ChangeMineStrength: public AutoTextContextAction {
00329 public:
00330 bool available( const MapCoordinate& pos )
00331 {
00332 return !actmap->getField(pos)->mines.empty() ;
00333 };
00334
00335 int getActionID()
00336 {
00337 return act_changeminestrength ;
00338 }
00339 };
00340
00341 class FieldResources: public AutoTextContextAction {
00342 public:
00343 bool available( const MapCoordinate& pos )
00344 {
00345 return true;
00346 };
00347
00348 int getActionID()
00349 {
00350 return act_changeresources;
00351 }
00352 };
00353
00354 class DeleteTopObject: public AutoTextContextAction {
00355 public:
00356 bool available( const MapCoordinate& pos )
00357 {
00358 return !actmap->getField(pos)->objects.empty();
00359 };
00360
00361 int getActionID()
00362 {
00363 return act_deletetopmostobject;
00364 }
00365 };
00366
00367 class DeleteAllObjects: public AutoTextContextAction {
00368 public:
00369 bool available( const MapCoordinate& pos )
00370 {
00371 return !actmap->getField(pos)->objects.empty();
00372 };
00373
00374 int getActionID()
00375 {
00376 return act_deleteallobjects;
00377 }
00378 };
00379
00380
00381 }
00382
00383 Maped_MainScreenWidget::Maped_MainScreenWidget( PG_Application& application )
00384 : MainScreenWidget( application ),
00385 vehicleSelector( NULL ), buildingSelector( NULL ), objectSelector(NULL), terrainSelector(NULL), mineSelector(NULL),
00386 weatherSelector( NULL ), selectionName(NULL), selectionName2(NULL), coordinateDisplay(NULL), currentSelectionWidget(NULL), contextMenu(NULL)
00387 {
00388
00389 setup( false, PG_Rect(15,30,Width() - 200, Height() - 73) );
00390 mapDisplay->mouseButtonOnField.connect( SigC::slot( mousePressedOnField ));
00391 mapDisplay->mouseButtonOnField.connect( SigC::slot( *this, &Maped_MainScreenWidget::clickOnMap ));
00392 mapDisplay->mouseDraggedToField.connect( SigC::slot( mouseDraggedToField ));
00393
00394
00395
00396
00397 setupStatusBar();
00398
00399 menu = new Menu(this, PG_Rect(15,0,Width()-200,20));
00400
00401
00402 PG_Application::GetApp()->sigKeyDown.connect( SigC::slot( *this, &Maped_MainScreenWidget::eventKeyDown ));
00403
00404 int xpos = Width() - 150;
00405 int w = 140;
00406 int ypos = 180;
00407
00408 PG_Button* buttonC = new PG_Button( this, PG_Rect( xpos, ypos, w, 20), "Clear Selection" );
00409 buttonC->sigClick.connect( SigC::slot( *this, &Maped_MainScreenWidget::clearSelection ));
00410 ypos += 25;
00411
00412
00413 PG_Button* button = new PG_Button( this, PG_Rect( xpos, ypos, w, 20), "Select Vehicle" );
00414 button->sigClick.connect( SigC::slot( *this, &Maped_MainScreenWidget::selectVehicle ));
00415 ypos += 25;
00416
00417 PG_Button* button2 = new PG_Button( this, PG_Rect( xpos, ypos, w, 20), "Select Building" );
00418 button2->sigClick.connect( SigC::slot( *this, &Maped_MainScreenWidget::selectBuilding ));
00419 ypos += 25;
00420
00421 PG_Button* button3 = new PG_Button( this, PG_Rect( xpos, ypos, w - 50, 20), "Sel. Object" );
00422 button3->sigClick.connect( SigC::slot( *this, &Maped_MainScreenWidget::selectObject ));
00423
00424 PG_Button* button3b = new PG_Button( this, PG_Rect( xpos+ w - 45, ypos, 45, 20), "List" );
00425 button3b->sigClick.connect( SigC::slot( *this, &Maped_MainScreenWidget::selectObjectList ));
00426 ypos += 25;
00427
00428
00429 PG_Button* button4 = new PG_Button( this, PG_Rect( xpos, ypos, w - 50, 20), "Sel. Terrain" );
00430 button4->sigClick.connect( SigC::slot( *this, &Maped_MainScreenWidget::selectTerrain ));
00431
00432 PG_Button* button4b = new PG_Button( this, PG_Rect( xpos + w - 45, ypos, 45, 20), "List" );
00433 button4b->sigClick.connect( SigC::slot( *this, &Maped_MainScreenWidget::selectTerrainList ));
00434 ypos += 25;
00435
00436 PG_Button* button5 = new PG_Button( this, PG_Rect( xpos, ypos, w, 20), "Select Mine" );
00437 button5->sigClick.connect( SigC::slot( *this, &Maped_MainScreenWidget::selectMine ));
00438 ypos += 25;
00439
00440
00441 new PG_Label( this, PG_Rect( xpos, ypos, w/2 - 5, 20), "Brush:");
00442 brushSelector = new DropDownSelector( this, PG_Rect( xpos+w/2+5, ypos, w/2-5, 20));
00443 brushSelector->AddItem("1");
00444 brushSelector->AddItem("3");
00445 brushSelector->AddItem("5");
00446 brushSelector->selectionSignal.connect( SigC::slot( *this, &Maped_MainScreenWidget::brushChanged ));
00447 ypos += 25;
00448
00449
00450 weatherSelector = new DropDownSelector( this, PG_Rect( xpos, ypos, w, 20));
00451 for ( int i = 0; i < cwettertypennum; ++i )
00452 weatherSelector->AddItem( cwettertypen[i] );
00453 ypos += 25;
00454
00455 weatherSelector->selectionSignal.connect( SigC::slot( selection, &SelectionHolder::setWeather ) );
00456
00457
00458
00459 playerSelector = new DropDownSelector( this, PG_Rect( xpos, ypos, w, 20));
00460 for ( int i = 0; i < 9; ++i )
00461 playerSelector->AddItem( "Player " + ASCString::toString(i) );
00462 playerSelector->selectionSignal.connect( SigC::slot( selection, &SelectionHolder::setPlayer ) );
00463 ypos += 25;
00464
00465 selection.playerChanged.connect( SigC::slot( *this, &Maped_MainScreenWidget::playerChanged ));
00466
00467
00468 currentSelectionWidget = new SelectionItemWidget( this, PG_Rect( Width() - BuildingItem::Width() - 10, ypos, BuildingItem::Width(), BuildingItem::Height() ) );
00469 ypos += BuildingItem::Height() + 5;
00470
00471 selectionName = new PG_Label( this, PG_Rect( xpos, ypos, currentSelectionWidget->Width(), 20 ));
00472 ypos += 25;
00473 selectionName2 = new PG_Label( this, PG_Rect( xpos, ypos, currentSelectionWidget->Width(), 20 ));
00474 ypos += 25;
00475
00476 selection.selectionChanged.connect( SigC::slot( *currentSelectionWidget, &SelectionItemWidget::set ));
00477 selection.selectionChanged.connect( SigC::slot( *this, &Maped_MainScreenWidget::selectionChanged ));
00478
00479 spawnOverviewMapPanel( "Mapeditor_OverviewMap" );
00480
00481 addContextAction( new ContextMenu::ContainerProperties );
00482 addContextAction( new ContextMenu::ContainerCargo );
00483 addContextAction( new ContextMenu::ContainerProduction );
00484 addContextAction( new ContextMenu::DeleteVehicle );
00485 addContextAction( new ContextMenu::DeleteBuilding );
00486 addContextAction( new ContextMenu::ChangeMineStrength );
00487 addContextAction( new ContextMenu::DeleteMine );
00488 addContextAction( new ContextMenu::FieldResources );
00489 addContextAction( new ContextMenu::DeleteTopObject );
00490 addContextAction( new ContextMenu::DeleteAllObjects );
00491 }
00492
00493 void Maped_MainScreenWidget::playerChanged( int player )
00494 {
00495 static int recursionPreventer = 0;
00496 recursionPreventer++;
00497 if ( recursionPreventer == 1 )
00498 playerSelector->SelectItem( player );
00499 recursionPreventer--;
00500 }
00501
00502
00503
00504
00505
00506
00507 bool Maped_MainScreenWidget::eventMouseButtonDown (const SDL_MouseButtonEvent *button)
00508 {
00509 return false;
00510 }
00511
00512 void Maped_MainScreenWidget::setupStatusBar()
00513 {
00514 int x = mapDisplay->my_xpos;
00515 int y = mapDisplay->my_ypos + mapDisplay->Height() + 25;
00516 int height = 20;
00517
00518 messageLine = new PG_Label ( this, PG_Rect( x, y, 200, height ) );
00519 messageLine->SetFontSize(11);
00520 x += 210;
00521
00522
00523 coordinateDisplay = new PG_Label ( this, PG_Rect( x, y, 80, height ) );
00524 coordinateDisplay->SetFontSize(11);
00525
00526 updateFieldInfo.connect( SigC::slot( *this, &Maped_MainScreenWidget::updateStatusBar ));
00527 cursorMoved.connect( SigC::slot( *this, &Maped_MainScreenWidget::updateStatusBar ));
00528 }
00529
00530 void Maped_MainScreenWidget::updateStatusBar()
00531 {
00532 MapCoordinate pos = actmap->getCursor();
00533 coordinateDisplay->SetText( ASCString::toString( pos.x) + " / " + ASCString::toString( pos.y ));
00534 }
00535
00536 void Maped_MainScreenWidget::selectionChanged( const MapComponent* item )
00537 {
00538 if ( item ) {
00539 selectionName->SetText( item->getItemType()->getName() );
00540 selectionName2->SetText( "ID: " + ASCString::toString( item->getItemType()->getID() ) );
00541 } else {
00542 selectionName->SetText( "" );
00543 selectionName2->SetText( "" );
00544 }
00545 }
00546
00547
00548 void Maped_MainScreenWidget::brushChanged( int i )
00549 {
00550 selection.brushSize = i+1;
00551 if ( selection.brushSize < 1 )
00552 selection.brushSize = 1;
00553 }
00554
00555 void Maped_MainScreenWidget:: addContextAction( ContextAction* contextAction )
00556 {
00557 contextActions.push_back( contextAction );
00558 }
00559
00560
00561 bool Maped_MainScreenWidget::clickOnMap( const MapCoordinate& field, const SPoint& pos, bool changed, int button, int prio)
00562 {
00563 if ( prio > 1 )
00564 return false;
00565
00566 if( button == 3 ) {
00567
00568 mapDisplay->cursor.goTo( field );
00569
00570 int counter = 0;
00571 for ( deallocating_vector<ContextAction*>::iterator i = contextActions.begin(); i != contextActions.end(); ++i )
00572 if ( (*i)->available( field ))
00573 ++counter;
00574
00575 if ( contextMenu ) {
00576 delete contextMenu;
00577 contextMenu = NULL;
00578 return true;
00579 }
00580
00581 if ( !counter )
00582 return false;
00583
00584
00585 contextMenu = new PG_PopupMenu( this, pos.x, pos.y );
00586
00587 for ( deallocating_vector<ContextAction*>::iterator i = contextActions.begin(); i != contextActions.end(); ++i )
00588 if ( (*i)->available( field )) {
00589 MapCoordinate mc = field;
00590 contextMenu->addMenuItem( (*i)->getText( field ), (*i)->getActionID() );
00591 }
00592
00593 contextMenu->sigSelectMenuItem.connect( SigC::slot( *this, &Maped_MainScreenWidget::runContextAction ));
00594
00595 contextMenu->Show();
00596 return true;
00597 } else {
00598 if ( contextMenu ) {
00599 delete contextMenu;
00600 contextMenu = NULL;
00601 return true;
00602 }
00603 }
00604 return false;
00605 }
00606
00607 bool Maped_MainScreenWidget::runContextAction (PG_PopupMenu::MenuItem* menuItem )
00608 {
00609 execaction_ev( tuseractions( menuItem->getId() ) );
00610
00611 return true;
00612 }
00613
00614 #ifdef WIN32
00615 # include "win32/win32-errormsg.h"
00616 # include "win32/msvc/mdump.h"
00617 #endif
00618
00619
00620 bool Maped_MainScreenWidget::eventKeyUp(const SDL_KeyboardEvent* key)
00621 {
00622 if ( key->keysym.sym == SDLK_RCTRL || key->keysym.sym == SDLK_LCTRL ) {
00623 execaction_ev( act_releaseControlPanel );
00624 return true;
00625 }
00626 return false;
00627 }
00628
00629 void helperFunction()
00630 {
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654 }
00655
00656
00657 bool Maped_MainScreenWidget::eventKeyDown(const SDL_KeyboardEvent* key)
00658 {
00659 int mod = SDL_GetModState() & ~(KMOD_NUM | KMOD_CAPS | KMOD_MODE);
00660
00661 if ( key->keysym.sym == SDLK_RCTRL || key->keysym.sym == SDLK_LCTRL ) {
00662 execaction_ev( act_openControlPanel );
00663 return true;
00664 }
00665
00666 if ( !mod ) {
00667 switch ( key->keysym.sym ) {
00668 case SDLK_KP_ENTER:
00669 case SDLK_RETURN:
00670 case SDLK_SPACE: execaction_ev( act_primaryAction );
00671 return true;
00672
00673 case SDLK_F1: execaction_ev(act_help);
00674 return true;
00675 case SDLK_F2 : execaction_ev(act_selunit);
00676 return true;
00677 case SDLK_F3: execaction_ev(act_selbodentyp);
00678 return true;
00679 case SDLK_F4 : execaction_ev(act_selobject);
00680 return true;
00681 case SDLK_F5 : execaction_ev(act_selbuilding);
00682 return true;
00683 case SDLK_F6 : execaction_ev(act_selmine);
00684 return true;
00685
00686 case SDLK_F11: helperFunction();
00687 return true;
00688 case SDLK_a: execaction_ev(act_movebuilding);
00689 return true;
00690 case SDLK_b: execaction_ev(act_changeresources);
00691 return true;
00692 case SDLK_c: execaction_ev(act_changecargo);
00693 return true;
00694 case SDLK_d : execaction_ev(act_changeterraindir);
00695 return true;
00696 case SDLK_e: execaction_ev(act_events);
00697 return true;
00698 case SDLK_f: execaction_ev(act_changeproduction);
00699 return true;
00700 case SDLK_g: execaction_ev(act_mapgenerator);
00701 return true;
00702 case SDLK_h: execaction_ev(act_setactivefieldvals);
00703 return true;
00704 case SDLK_DELETE: execaction_ev(act_deletething);
00705 return true;
00706 case SDLK_l : execaction_ev(act_showpalette);
00707 return true;
00708 case SDLK_m : execaction_ev(act_changeminestrength);
00709 return true;
00710 case SDLK_o: execaction_ev(act_changeplayers);
00711 return true;
00712
00713 case SDLK_p: execaction_ev(act_changeunitvals);
00714 return true;
00715
00716 case SDLK_r: execaction_ev(act_resizemap);
00717 return true;
00718
00719 case SDLK_s : execaction_ev(act_savemap);
00720 return true;
00721
00722 case SDLK_v: execaction_ev(act_viewmap);
00723 return true;
00724
00725 case SDLK_x: execaction_ev(act_mirrorcursorx);
00726 return true;
00727
00728 case SDLK_y: execaction_ev(act_mirrorcursory);
00729 return true;
00730
00731 case SDLK_z: execaction_ev(act_setzoom );
00732 return true;
00733
00734 case SDLK_7 : execaction_ev(act_terraininfo);
00735 return true;
00736
00737 case SDLK_8 : execaction_ev(act_placemine);
00738 return true;
00739
00740 case SDLK_9: execaction_ev(act_showPipeNet);
00741 return true;
00742
00743
00744 case SDLK_TAB: execaction_ev(act_switchmaps );
00745 return true;
00746
00747 case SDLK_ESCAPE: execaction_ev(act_clearSelection);
00748 return true;
00749 case SDLK_PLUS:
00750 case SDLK_KP_PLUS: execaction_ev( act_increase_zoom );
00751 return true;
00752
00753 case SDLK_MINUS:
00754 case SDLK_KP_MINUS: execaction_ev( act_decrease_zoom );
00755 return true;
00756
00757 default:;
00758 }
00759 }
00760
00761 if ( mod & KMOD_CTRL ) {
00762 switch ( key->keysym.sym ) {
00763 case SDLK_F3 : execaction_ev(act_selbodentypAll);
00764 return true;
00765
00766 case SDLK_F4 : execaction_ev(act_selobjectAll);
00767 return true;
00768
00769 case SDLK_a: execaction_ev(act_setupalliances);
00770 return true;
00771
00772 case SDLK_b: execaction_ev(act_toggleresourcemode);
00773 return true;
00774
00775 case SDLK_c: execaction_ev(act_copyToClipboard);
00776 return true;
00777
00778 case SDLK_f: execaction_ev(act_createresources);
00779 return true;
00780
00781 case SDLK_g: execaction_ev(act_maptopcx);
00782 return true;
00783
00784 case SDLK_h: execaction_ev(act_setunitfilter);
00785 return true;
00786
00787 case SDLK_i: execaction_ev (act_import_bi_map );
00788 return true;
00789
00790 case SDLK_l: execaction_ev(act_loadmap);
00791 return true;
00792
00793 case SDLK_m: execaction_ev(act_changemapvals);
00794 return true;
00795
00796 case SDLK_n: execaction_ev(act_newmap);
00797 return true;
00798
00799 case SDLK_o: execaction_ev(act_polymode);
00800 return true;
00801
00802 case SDLK_p: execaction_ev(act_changeproduction);
00803 return true;
00804
00805 case SDLK_q: execaction_ev(act_end);
00806 return true;
00807
00808 case SDLK_r: execaction_ev(act_repaintdisplay);
00809 return true;
00810
00811 case SDLK_s : execaction_ev(act_savemap);
00812 return true;
00813
00814 case SDLK_u: execaction_ev(act_unitinfo);
00815 return true;
00816
00817 case SDLK_v: execaction_ev(act_pasteFromClipboard);
00818 return true;
00819
00820 case SDLK_w: execaction_ev(act_setactweatherglobal);
00821 return true;
00822
00823 case SDLK_x: execaction_ev(act_cutToClipboard);
00824 return true;
00825
00826 case SDLK_SPACE: execaction_ev( act_primaryAction );
00827 return true;
00828
00829
00830 default:;
00831
00832 }
00833 }
00834
00835 if ( mod & KMOD_SHIFT ) {
00836 switch ( key->keysym.sym ) {
00837 case SDLK_d: execaction_ev(act_changeunitdir);
00838 return true;
00839 case SDLK_F3 : execaction_ev(act_selbodentypAll);
00840 return true;
00841
00842 case SDLK_F4 : execaction_ev(act_selobjectAll);
00843 return true;
00844 default:;
00845 }
00846 }
00847
00848 if ( mod & KMOD_ALT ) {
00849 switch ( key->keysym.sym ) {
00850 case SDLK_RETURN:
00851 getPGApplication().toggleFullscreen();
00852 return true;
00853
00854 case SDLK_F11:
00855
00856
00857
00858
00859
00860
00861
00862
00863 { for ( Player::VehicleList::iterator i = actmap->player[1].vehicleList.begin(); i != actmap->player[1].vehicleList.end(); ++i )
00864 (*i)->direction = 3;
00865 }
00866 return true;
00867
00868 default:;
00869 }
00870 }
00871
00872 return false;
00873 }
00874
00875
00876
00877 class MapItemSelectionWindow : public ItemSelectorWindow {
00878 public:
00879 MapItemSelectionWindow( PG_Widget *parent, const PG_Rect &r , const ASCString& title, SelectionItemFactory* itemFactory )
00880 : ItemSelectorWindow( parent, r, title, itemFactory ) {};
00881
00882 void itemSelected( const SelectionWidget* )
00883 {
00884 if ( CGameOptions::Instance()->maped_modalSelectionWindow )
00885 Hide();
00886 QuitModal();
00887 }
00888
00889 };
00890
00891 typedef PG_Window* PG_WindowPointer;
00892
00893 template <class ItemType>
00894 void showSelectionWindow( PG_Widget* parent, PG_WindowPointer &selectionWindow, const ItemRepository<ItemType>& itemRepository )
00895 {
00896 if ( !selectionWindow ) {
00897 ItemSelectorWindow* sw = new MapItemSelectionWindow( parent, PG_Rect( parent->Width()-300, 100, 280, parent->Height()-150), "select item", new MapItemTypeWidgetFactory< MapItemTypeWidget<ItemType> >(itemRepository) );
00898
00899 filtersChangedSignal.connect( SigC::slot( *sw, &ItemSelectorWindow::reLoad ));
00900 selectionWindow = sw;
00901 }
00902
00903 selectionWindow->Show();
00904 selectionWindow->RunModal();
00905 if ( CGameOptions::Instance()->maped_modalSelectionWindow )
00906 selectionWindow->Hide();
00907
00908 }
00909
00910
00911 bool Maped_MainScreenWidget :: clearSelection()
00912 {
00913 selection.clear();
00914 return true;
00915 }
00916
00917
00918 bool Maped_MainScreenWidget :: selectVehicle()
00919 {
00920 showSelectionWindow( this, vehicleSelector, vehicleTypeRepository );
00921 return true;
00922 }
00923
00924
00925 bool Maped_MainScreenWidget :: selectBuilding()
00926 {
00927 showSelectionWindow( this, buildingSelector, buildingTypeRepository );
00928 return true;
00929 }
00930
00931 bool Maped_MainScreenWidget :: selectObject()
00932 {
00933 execaction_ev( act_switchmaps );
00934
00935 return true;
00936 }
00937
00938 bool Maped_MainScreenWidget :: selectObjectList()
00939 {
00940 showSelectionWindow( this, objectSelector, objectTypeRepository );
00941 return true;
00942 }
00943
00944
00945 bool Maped_MainScreenWidget :: selectTerrain()
00946 {
00947 execaction_ev( act_switchmaps );
00948
00949 return true;
00950 }
00951
00952 bool Maped_MainScreenWidget :: selectTerrainList()
00953 {
00954 showSelectionWindow( this, terrainSelector, terrainTypeRepository );
00955 return true;
00956 }
00957
00958
00959 bool Maped_MainScreenWidget :: selectMine()
00960 {
00961 showSelectionWindow( this, mineSelector, mineTypeRepository );
00962 return true;
00963 }
00964
00965
00966
00967 void displaymessage2( const char* formatstring, ... )
00968 {
00969
00970 ASCString s;
00971
00972 std::va_list arg_ptr;
00973 va_start ( arg_ptr, formatstring );
00974
00975 s.vaformat( formatstring, arg_ptr );
00976
00977 va_end ( arg_ptr );
00978
00979 if ( mainScreenWidget )
00980 mainScreenWidget->displayMessage(s);
00981 }
00982
00983
00984
00985