Advanced Strategic Command
maped-mainscreen.cpp
Go to the documentation of this file.
1 
2 /***************************************************************************
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 2 of the License, or *
7  * (at your option) any later version. *
8  * *
9  ***************************************************************************/
10 
11 #include "global.h"
12 
13 #include <stdio.h>
14 #include <cstring>
15 #include <stdlib.h>
16 #include <new>
17 #include <cstdlib>
18 #include <ctype.h>
19 #include <algorithm>
20 #include <memory>
21 #include <SDL_mixer.h>
22 #include <iostream>
23 #include <set>
24 
25 #include "paradialog.h"
26 #include "pgtooltiphelp.h"
27 #include "pgpopupmenu.h"
28 #include "pgmenubar.h"
29 
30 #include "basegfx.h"
31 #include "misc.h"
32 #include "iconrepository.h"
33 #include "maped-mainscreen.h"
34 #include "graphics/blitter.h"
35 #include "graphics/drawing.h"
36 #include "edglobal.h"
37 #include "mapdisplay.h"
38 #include "spfst.h"
39 #include "spfst-legacy.h"
40 #include "overviewmappanel.h"
41 #include "edselfnt.h"
42 #include "edmisc.h"
43 #include "gameoptions.h"
45 #include "dialogs/fileselector.h"
46 #include "weaponrangelayer.h"
47 
48 #include "mapdisplay.h"
49 
51 
53 {
54  return mainScreenWidget;
55 }
56 
57 
58 class Menu : public PG_MenuBar {
59 
60  PG_PopupMenu* currentMenu;
61  typedef list<PG_PopupMenu*> Categories;
62  Categories categories;
63 
64  public:
65  Menu ( PG_Widget *parent, const PG_Rect &rect=PG_Rect::null);
66 
67  protected:
68  void setup();
69  bool execAction (PG_PopupMenu::MenuItem* menuItem );
70 
71  private:
72  void addbutton(const char* name, int id );
73  void addfield ( const char* name );
74 
75 };
76 
77 
78 
79 bool Menu::execAction (PG_PopupMenu::MenuItem* menuItem )
80 {
81  execaction_ev( tuseractions( menuItem->getId() ) );
82 
83  return true;
84 }
85 
86 
87 void Menu::addfield( const char* name )
88 {
89  currentMenu = new PG_PopupMenu( NULL, -1, -1, "" );
90  categories.push_back ( currentMenu );
91  Add ( name, currentMenu );
92  currentMenu->sigSelectMenuItem.connect( sigc::mem_fun( *this, &Menu::execAction ));
93 
94 }
95 
96 void Menu::addbutton( const char* name, int id )
97 {
98  currentMenu->addMenuItem( name, id );
99 }
100 
101 
102 void Menu::setup()
103 {
104  addfield ( "~F~ile" );
105  addbutton ( "~N~ew map\tctrl+N" , act_newmap );
106  addbutton ( "~L~oad map\tctrl+L", act_loadmap );
107  addbutton ( "~S~ave map\tS", act_savemap );
108  addbutton ( "Save map ~a~s", act_savemapas );
109  addbutton ( "Edit Map ~A~rchival Information", act_editArchivalInformation );
110  currentMenu->addSeparator();
111  addbutton ( "Load Clipboard", act_readClipBoard );
112  addbutton ( "Save Clipboard", act_saveClipboard );
113  currentMenu->addSeparator();
114  addbutton ( "Run Script", act_runLuaScript );
115  addbutton ( "Run Translation Script", act_runTranslationScript );
116  currentMenu->addSeparator();
117  addbutton ( "~W~rite map to PNG-File\tctrl+G", act_maptopcx);
118  addbutton ( "~I~mport BI map\tctrl-i", act_import_bi_map );
119  addbutton ( "Insert ~B~I map", act_insert_bi_map );
120  currentMenu->addSeparator();
121  addbutton ( "Increase Map Zoom\tKP+", act_increase_zoom );
122  addbutton ( "Decrease Map Zoom\tKP-", act_decrease_zoom );
123  currentMenu->addSeparator();
124  addbutton( "Edit Preferences", act_editpreferences );
125  currentMenu->addSeparator();
126  addbutton ( "~Q~uit\tctrl-q", act_end);
127 
128  addfield ("~E~dit");
129  addbutton ( "~C~opy \tctrl+C", act_copyToClipboard );
130  addbutton ( "Cu~t~\tctrl+X", act_cutToClipboard );
131  addbutton ( "~P~aste \tctrl+V", act_pasteFromClipboard );
132  currentMenu->addSeparator();
133  addbutton ( "Resi~z~e map\tR", act_resizemap );
134  addbutton ( "set global uniform ~w~eather\tctrl-W", act_setactweatherglobal );
135  // addbutton ( "configure weather generator", act_setactnewweather );
136  addbutton ( "~C~reate regional resources", act_createresources );
137  addbutton ( "Create global resources\tctrl+F", act_createresources2 );
138  addbutton ( "Clear all mineral resources", act_clearresources );
139  currentMenu->addSeparator();
140  addbutton ( "~S~et turn number", act_setTurnNumber );
141  currentMenu->addSeparator();
142  addbutton ( "~S~etup Players", act_setupplayers );
143  addbutton ( "Setup ~A~lliances", act_setupalliances );
144  addbutton ( "~E~dit Research", act_editResearch );
145  addbutton ( "edit ~R~esearch points", act_editResearchPoints );
146  addbutton ( "edit ~T~ech adapter", act_editTechAdapter );
147  addbutton ( "edit player data...", act_resetPlayerData );
148 
149  addfield ("~S~elect");
150  addbutton ( "Vehicle\tF2", act_selunit );
151  addbutton ( "Terrain from map\tF3", act_selbodentyp );
152  addbutton ( "Terrain from list\tctrl-F3", act_selbodentypAll );
153  addbutton ( "Object from map \tF4", act_selbodentyp );
154  addbutton ( "Object from list \tctrl-F4", act_selobjectAll );
155  addbutton ( "Building Type\tF5", act_selbuilding );
156  addbutton ( "Mine\tF6", act_selmine );
157 
158 
159  addfield ("~T~ools");
160  // addbutton ( "~V~iew map\tV", act_viewmap );
161  // addbutton ( "~S~how palette", act_showpalette );
162  // addbutton ( "~R~ebuild display\tctrl+R", act_repaintdisplay );
163  // currentMenu->addSeparator();
164  addbutton ( "~M~ap generator\tG", act_mapgenerator );
165  addbutton ( "Sm~o~oth coasts", act_smoothcoasts );
166  addbutton ( "~U~nitset transformation", act_unitsettransformation );
167  addbutton ( "map ~t~ransformation", act_transformMap );
168  addbutton ( "Com~p~are Resources ", act_displayResourceComparison );
169  addbutton ( "Show Pipeline Net\t9", act_showPipeNet );
170  addbutton ( "Generate Tech Tree", act_generateTechTree );
171  addbutton ( "Mirror Map", act_mirrorMap );
172  addbutton ( "Copy Area", act_copyArea );
173  addbutton ( "Paste Area", act_pasteArea );
174  currentMenu->addSeparator();
175  addbutton ( "PBP Player Statistics", act_pbpstatistics );
176 
177  addfield ("~O~ptions");
178  addbutton ( "~M~ap properties\tctrl+M", act_changemapvals );
179  addbutton ( "~C~hange players\tO", act_changeplayers);
180  addbutton ( "~E~dit events\tE", act_events );
181 // addbutton ( "unit production ~L~imitation", act_specifyunitproduction );
182  currentMenu->addSeparator();
183  addbutton ( "~T~oggle ResourceView\tctrl+B", act_toggleresourcemode);
184  addbutton ( "~B~I ResourceMode", act_bi_resource );
185  addbutton ( "~A~sc ResourceMode", act_asc_resource );
186  addbutton ( "edit map ~P~arameters", act_setmapparameters );
187  addbutton ( "setup item ~F~ilters\tctrl+h", act_setunitfilter );
188  addbutton ( "select ~G~raphic set", act_selectgraphicset );
189  addbutton ( "show weapon range\tctrl+r", act_showweapnrange );
190 
191  addfield ("~D~evelopment");
192  addbutton ( "Dump ~B~uilding", act_dumpBuilding );
193  addbutton ( "Dump all Buildings", act_dumpAllBuildings );
194  addbutton ( "Dump ~V~ehicle", act_dumpVehicle );
195  addbutton ( "Dump all Vehicles", act_dumpAllVehicleDefinitions );
196  addbutton ( "Dump ~O~bject", act_dumpObject );
197  addbutton ( "Dump all Objects", act_dumpAllObjects );
198  addbutton ( "Dump all Terrain", act_dumpAllTerrain );
199  addbutton ( "Locate Item by ~I~D", act_locateItemByID );
200  currentMenu->addSeparator();
201  addbutton ( "Exchange ~G~raphics", act_exchangeGraphics );
202 /*
203  addfield("Debug");
204  addbutton ( "Crash map editor", asc_nullPointerCrash );
205  addbutton ( "TestFunctionHolder", asc_testFunction );
206 */
207  addfield ("~H~elp");
208  addbutton ( "~U~nit Information\tctrl+U", act_unitinfo );
209  addbutton ( "unit guide dialog", act_unitGuideDialog );
210  addbutton ( "unit~S~et Information", act_unitSetInformation );
211  addbutton ( "~T~errain Information\t7", act_terraininfo );
212  currentMenu->addSeparator();
213  addbutton ( "~H~elp System\tF1", act_help );
214  addbutton ( "~A~bout", act_about );
215 }
216 
217 
218 Menu::Menu ( PG_Widget *parent, const PG_Rect &rect)
219  : PG_MenuBar( parent, rect, "MenuBar"),
220  currentMenu(NULL)
221 {
222  activateHotkey( KMOD_ALT );
223  setup();
224 }
225 
226 namespace ContextMenu {
227 
229  public:
231  {
232  return execactionnames[getActionID()];
233  };
234  };
235 
237  public:
238  bool available( const MapCoordinate& pos )
239  {
240  return actmap->getField(pos)->getContainer();
241  };
242 
244  {
245  if ( actmap->getField(pos)->vehicle )
246  return "edit unit properties";
247  else
248  return "edit building properties";
249  };
250 
252  {
253  return act_changeunitvals ;
254  }
255 };
256 
258  public:
259  bool available( const MapCoordinate& pos )
260  {
262  };
263 
265  {
266  if ( actmap->getField(pos)->vehicle )
267  return "edit unit cargo";
268  else
269  return "edit building cargo";
270  };
271 
273  {
274  return act_changecargo ;
275  }
276 };
277 
279  public:
280  bool available( const MapCoordinate& pos )
281  {
282  return actmap->getField(pos)->vehicle;
283  };
284 
286  {
287  return "delete unit";
288  };
289 
291  {
292  return act_deleteunit ;
293  }
294 };
295 
297  public:
298  bool available( const MapCoordinate& pos )
299  {
300  return actmap->getField(pos)->building;
301  };
302 
304  {
305  return "delete building";
306  };
307 
309  {
310  return act_deletebuilding;
311  }
312 };
313 
315  public:
316  bool available( const MapCoordinate& pos )
317  {
319  };
320 
322  {
323  return act_changeproduction ;
324  }
325 };
326 
328  public:
329  bool available( const MapCoordinate& pos )
330  {
331  return !actmap->getField(pos)->mines.empty() ;
332  };
333 
335  {
336  return act_deletemine ;
337  }
338 };
339 
341  public:
342  bool available( const MapCoordinate& pos )
343  {
344  return !actmap->getField(pos)->mines.empty() ;
345  };
346 
348  {
349  return act_changeminestrength ;
350  }
351 };
352 
354  public:
355  bool available( const MapCoordinate& pos )
356  {
357  return true;
358  };
359 
361  {
362  return act_changeresources;
363  }
364 };
365 
367  public:
368  bool available( const MapCoordinate& pos )
369  {
370  return !actmap->getField(pos)->objects.empty();
371  };
372 
374  {
376  }
377 };
378 
380  public:
381  bool available( const MapCoordinate& pos )
382  {
383  return !actmap->getField(pos)->objects.empty();
384  };
385 
387  {
388  return act_deleteallobjects;
389  }
390 };
391 
392 
393 } // namespace ContextMenu
394 
396  : MainScreenWidget( application ),
397  vehicleSelector( NULL ), buildingSelector( NULL ), objectSelector(NULL), terrainSelector(NULL), mineSelector(NULL),
398  weatherSelector( NULL ), selectionName(NULL), selectionName2(NULL), coordinateDisplay(NULL), currentSelectionWidget(NULL), contextMenu(NULL)
399 {
400 
401  setup( false, PG_Rect(15,30,Width() - 200, Height() - 73) );
402  mapDisplay->mouseButtonOnField.connect( sigc::ptr_fun( &mousePressedOnField ));
403  mapDisplay->mouseButtonOnField.connect( sigc::mem_fun( *this, &Maped_MainScreenWidget::clickOnMap ));
404  mapDisplay->mouseDraggedToField.connect( sigc::ptr_fun( &mouseDraggedToField ));
405 
406 
407 
408 
409  setupStatusBar();
410 
411  menu = new Menu(this, PG_Rect(15,0,Width()-200,20));
412 
413 
414  PG_Application::GetApp()->sigKeyDown.connect( sigc::mem_fun( *this, &Maped_MainScreenWidget::eventKeyDown ));
415 
416  int xpos = Width() - 150;
417  int w = 140;
418  int ypos = 180;
419 
420  PG_Button* buttonC = new PG_Button( this, PG_Rect( xpos, ypos, w, 20), "Clear Selection" );
421  buttonC->sigClick.connect( sigc::hide( sigc::mem_fun( *this, &Maped_MainScreenWidget::clearSelection )));
422  ypos += 25;
423 
424 
425  PG_Button* button = new PG_Button( this, PG_Rect( xpos, ypos, w, 20), "Select Vehicle" );
426  button->sigClick.connect( sigc::hide( sigc::mem_fun( *this, &Maped_MainScreenWidget::selectVehicle )));
427  ypos += 25;
428 
429  PG_Button* button2 = new PG_Button( this, PG_Rect( xpos, ypos, w, 20), "Select Building" );
430  button2->sigClick.connect( sigc::hide( sigc::mem_fun( *this, &Maped_MainScreenWidget::selectBuilding )));
431  ypos += 25;
432 
433  PG_Button* button3 = new PG_Button( this, PG_Rect( xpos, ypos, w - 50, 20), "Sel. Object" );
434  button3->sigClick.connect( sigc::hide( sigc::mem_fun( *this, &Maped_MainScreenWidget::selectObject )));
435 
436  PG_Button* button3b = new PG_Button( this, PG_Rect( xpos+ w - 45, ypos, 45, 20), "List" );
437  button3b->sigClick.connect( sigc::hide( sigc::mem_fun( *this, &Maped_MainScreenWidget::selectObjectList )));
438  ypos += 25;
439 
440 
441  PG_Button* button4 = new PG_Button( this, PG_Rect( xpos, ypos, w - 50, 20), "Sel. Terrain" );
442  button4->sigClick.connect( sigc::hide( sigc::mem_fun( *this, &Maped_MainScreenWidget::selectTerrain )));
443 
444  PG_Button* button4b = new PG_Button( this, PG_Rect( xpos + w - 45, ypos, 45, 20), "List" );
445  button4b->sigClick.connect( sigc::hide( sigc::mem_fun( *this, &Maped_MainScreenWidget::selectTerrainList )));
446  ypos += 25;
447 
448  PG_Button* button5 = new PG_Button( this, PG_Rect( xpos, ypos, w, 20), "Select Mine" );
449  button5->sigClick.connect( sigc::hide( sigc::mem_fun( *this, &Maped_MainScreenWidget::selectMine )));
450  ypos += 25;
451 
452  PG_Button* button6 = new PG_Button( this, PG_Rect( xpos, ypos, w, 20), "Lua Brush" );
453  button6->sigClick.connect( sigc::hide( sigc::mem_fun( *this, &Maped_MainScreenWidget::selectLuaBrush )));
454  ypos += 25;
455 
456 
457  new PG_Label( this, PG_Rect( xpos, ypos, w/2 - 5, 20), "Brush:");
458  brushSelector = new DropDownSelector( this, PG_Rect( xpos+w/2+5, ypos, w/2-5, 20));
459  brushSelector->AddItem("1");
460  brushSelector->AddItem("3");
461  brushSelector->AddItem("5");
462  brushSelector->selectionSignal.connect( sigc::mem_fun( *this, &Maped_MainScreenWidget::brushChanged ));
463  ypos += 25;
464 
465 
466  weatherSelector = new DropDownSelector( this, PG_Rect( xpos, ypos, w, 20));
467  for ( int i = 0; i < cwettertypennum; ++i )
468  weatherSelector->AddItem( cwettertypen[i] );
469  ypos += 25;
470 
471  weatherSelector->selectionSignal.connect( sigc::mem_fun( selection, &SelectionHolder::setWeather ) );
472 // weatherSelector->selectionSignal.connect( sigc::mem_fun( *currentSelectionWidget, &SelectionItemWidget::Update ));
473 
474 
475  playerSelector = new DropDownSelector( this, PG_Rect( xpos, ypos, w, 20));
476  for ( int i = 0; i < 9; ++i )
477  playerSelector->AddItem( "Player " + ASCString::toString(i) );
478  playerSelector->selectionSignal.connect( sigc::mem_fun( selection, &SelectionHolder::setPlayer ) );
479  ypos += 25;
480 
481  selection.playerChanged.connect( sigc::mem_fun( *this, &Maped_MainScreenWidget::playerChanged ));
482 
483 
484  currentSelectionWidget = new SelectionItemWidget( this, PG_Rect( Width() - BuildingItem::Width() - 10, ypos, BuildingItem::Width(), BuildingItem::Height() ) );
485  ypos += BuildingItem::Height() + 5;
486 
487  selectionName = new PG_Label( this, PG_Rect( xpos, ypos, currentSelectionWidget->Width(), 20 ));
488  ypos += 25;
489  selectionName2 = new PG_Label( this, PG_Rect( xpos, ypos, currentSelectionWidget->Width(), 20 ));
490  ypos += 25;
491 
492  selection.selectionChanged.connect( sigc::mem_fun( *currentSelectionWidget, &SelectionItemWidget::set ));
493  selection.selectionChanged.connect( sigc::mem_fun( *this, &Maped_MainScreenWidget::selectionChanged ));
494 
495  spawnOverviewMapPanel( "Mapeditor_OverviewMap" );
496 
507 
508  weaponRangeLayer = new UnitWeaponRangeLayer();
509  mapDisplay->addMapLayer( weaponRangeLayer, "weaprange" );
510 
511 }
512 
514 {
515  weaponRangeLayer->operateField( gamemap, pos );
516 }
517 
518 
520 {
521  static int recursionPreventer = 0;
522  recursionPreventer++;
523  if ( recursionPreventer == 1 )
524  playerSelector->SelectItem( player );
525  recursionPreventer--;
526 }
527 
528 
529 
530 
531 
532 
533 bool Maped_MainScreenWidget::eventMouseButtonDown (const SDL_MouseButtonEvent *button)
534 {
535  return false;
536 }
537 
539 {
540  int x = mapDisplay->my_xpos;
541  int y = mapDisplay->my_ypos + mapDisplay->Height() + 25;
542  int height = 20;
543 
544  messageLine = new PG_Label ( this, PG_Rect( x, y, 200, height ) );
545  messageLine->SetFontSize(11);
546  x += 210;
547 
548 
549  coordinateDisplay = new PG_Label ( this, PG_Rect( x, y, 80, height ) );
550  coordinateDisplay->SetFontSize(11);
551 
552  updateFieldInfo.connect( sigc::mem_fun( *this, &Maped_MainScreenWidget::updateStatusBar ));
553  cursorMoved.connect( sigc::mem_fun( *this, &Maped_MainScreenWidget::updateStatusBar ));
554 }
555 
557 {
558  MapCoordinate pos = actmap->getCursor();
559  coordinateDisplay->SetText( ASCString::toString( pos.x) + " / " + ASCString::toString( pos.y ));
560 }
561 
563 {
564  if ( item ) {
565  selectionName->SetText( item->getName() );
566 
567  const MapComponent* mc = dynamic_cast<const MapComponent*>(item);
568  if ( mc )
569  selectionName2->SetText( "ID: " + ASCString::toString( mc->getItemType()->getID() ) );
570  else
571  selectionName2->SetText( "" );
572  } else {
573  selectionName->SetText( "" );
574  selectionName2->SetText( "" );
575  }
576 }
577 
578 
580 {
581  selection.brushSize = i+1;
582  if ( selection.brushSize < 1 )
583  selection.brushSize = 1;
584 }
585 
587 {
588  contextActions.push_back( contextAction );
589 }
590 
591 
592 bool Maped_MainScreenWidget::clickOnMap( const MapCoordinate& field, const SPoint& pos, bool changed, int button, int prio)
593 {
594  if ( prio > 1 )
595  return false;
596 
597  if( button == 3 ) {
598 
599  mapDisplay->cursor.goTo( field );
600 
601  int counter = 0;
602  for ( deallocating_vector<ContextAction*>::iterator i = contextActions.begin(); i != contextActions.end(); ++i )
603  if ( (*i)->available( field ))
604  ++counter;
605 
606  if ( contextMenu ) {
607  delete contextMenu;
608  contextMenu = NULL;
609  return true;
610  }
611 
612  if ( !counter )
613  return false;
614 
615 
616  contextMenu = new PG_PopupMenu( this, pos.x, pos.y );
617 
618  for ( deallocating_vector<ContextAction*>::iterator i = contextActions.begin(); i != contextActions.end(); ++i )
619  if ( (*i)->available( field )) {
620  contextMenu->addMenuItem( (*i)->getText( field ), (*i)->getActionID() );
621  }
622 
623  contextMenu->sigSelectMenuItem.connect( sigc::mem_fun( *this, &Maped_MainScreenWidget::runContextAction ));
624 
625  contextMenu->Show();
626  return true;
627  } else {
628  if ( contextMenu ) {
629  delete contextMenu;
630  contextMenu = NULL;
631  return true;
632  }
633  }
634  return false;
635 }
636 
637 bool Maped_MainScreenWidget::runContextAction (PG_PopupMenu::MenuItem* menuItem )
638 {
639  execaction_ev( tuseractions( menuItem->getId() ) );
640 
641  return true;
642 }
643 
644 #ifdef WIN32
645 # include "win32/win32-errormsg.h"
646 # include "win32/msvc/mdump.h"
647 #endif
648 
649 
650 bool Maped_MainScreenWidget::eventKeyUp(const PG_MessageObject* o, const SDL_KeyboardEvent* key)
651 {
652  if ( key->keysym.sym == SDLK_RCTRL || key->keysym.sym == SDLK_LCTRL ) {
654  return true;
655  }
656  return false;
657 }
658 
660 {
661  /*
662  set<int> s;
663  for ( int i = 0; i < 1083; ++i )
664  s.insert(i);
665  for ( int y = 0; y < actmap->ysize; ++y)
666  for ( int x = 0; x < actmap->xsize; ++x)
667  if ( s.find( actmap->getField(x,y)->typ->terraintype->id ) != s.end() )
668  s.erase( actmap->getField(x,y)->typ->terraintype->id );
669 
670  int start = -1;
671  for ( int i = 0; i <= 1083; ++i ) {
672  if ( s.find(i) != s.end() ) {
673  if ( start < 0 )
674  start = i;
675  } else {
676  if ( start >= 0 ) {
677  cout << start << "-" << i-1 << " ";
678  start = -1;
679  }
680  }
681  }
682  cout << "\n";
683  */
684 }
685 
686 
687 bool Maped_MainScreenWidget::eventKeyDown(const PG_MessageObject* o, const SDL_KeyboardEvent* key)
688 {
689  int mod = SDL_GetModState() & ~(KMOD_NUM | KMOD_CAPS | KMOD_MODE);
690 
691  if ( key->keysym.sym == SDLK_RCTRL || key->keysym.sym == SDLK_LCTRL ) {
693  return true;
694  }
695 
696  if ( !mod ) {
697  switch ( key->keysym.sym ) {
698  case SDLK_KP_ENTER:
699  case SDLK_RETURN:
700  case SDLK_SPACE: execaction_ev( act_primaryAction );
701  return true;
702 
703  case SDLK_F1: execaction_ev(act_help);
704  return true;
705  case SDLK_F2 : execaction_ev(act_selunit);
706  return true;
707  case SDLK_F3: execaction_ev(act_selbodentyp);
708  return true;
709  case SDLK_F4 : execaction_ev(act_selobject);
710  return true;
711  case SDLK_F5 : execaction_ev(act_selbuilding);
712  return true;
713  case SDLK_F6 : execaction_ev(act_selmine);
714  return true;
715 
716  case SDLK_F11: helperFunction();
717  return true;
718  case SDLK_a: execaction_ev(act_movebuilding);
719  return true;
720  case SDLK_b: execaction_ev(act_changeresources);
721  return true;
722  case SDLK_c: execaction_ev(act_changecargo);
723  return true;
724  case SDLK_d : execaction_ev(act_changeterraindir);
725  return true;
726  case SDLK_e: execaction_ev(act_events);
727  return true;
728  case SDLK_f: execaction_ev(act_changeproduction);
729  return true;
730  case SDLK_g: execaction_ev(act_mapgenerator);
731  return true;
733  return true;
734  case SDLK_DELETE: execaction_ev(act_deletething);
735  return true;
736  case SDLK_l : execaction_ev(act_showpalette);
737  return true;
738  case SDLK_m : execaction_ev(act_changeminestrength);
739  return true;
740  case SDLK_o: execaction_ev(act_changeplayers);
741  return true;
742 
743  case SDLK_p: execaction_ev(act_changeunitvals);
744  return true;
745 
746  case SDLK_r: execaction_ev(act_resizemap);
747  return true;
748 
749  case SDLK_s : execaction_ev(act_savemap);
750  return true;
751 
752  case SDLK_v: execaction_ev(act_viewmap);
753  return true;
754 
755  case SDLK_x: execaction_ev(act_mirrorcursorx);
756  return true;
757 
758  case SDLK_y: execaction_ev(act_mirrorcursory);
759  return true;
760 
761  case SDLK_z: execaction_ev(act_setzoom );
762  return true;
763 
764  case SDLK_7 : execaction_ev(act_terraininfo);
765  return true;
766 
767  case SDLK_8 : execaction_ev(act_placemine);
768  return true;
769 
770  case SDLK_9: execaction_ev(act_showPipeNet);
771  return true;
772 
773 
774  case SDLK_TAB: execaction_ev(act_switchmaps );
775  return true;
776 
777  case SDLK_ESCAPE: execaction_ev(act_clearSelection);
778  return true;
779  case SDLK_PLUS:
780  case SDLK_KP_PLUS: execaction_ev( act_increase_zoom );
781  return true;
782 
783  case SDLK_MINUS:
784  case SDLK_KP_MINUS: execaction_ev( act_decrease_zoom );
785  return true;
786 
787  default:;
788  }
789  }
790 
791  if ( mod & KMOD_CTRL ) {
792  switch ( key->keysym.sym ) {
793  case SDLK_F3 : execaction_ev(act_selbodentypAll);
794  return true;
795 
796  case SDLK_F4 : execaction_ev(act_selobjectAll);
797  return true;
798 
799  case SDLK_SPACE: execaction_ev( act_primaryAction );
800  return true;
801 
802  default:;
803 
804  }
805  switch ( key->keysym.unicode ) {
806  case 1: // A
808  return true;
809 
810  case 2: // B
812  return true;
813 
814  case 3: // C
816  return true;
817 
818  case 6: // F
820  return true;
821 
822  case 7: //G
824  return true;
825 
826  case 8: // H
828  return true;
829 
830  case 9: // I
832  return true;
833 
834  case 12: // L
836  return true;
837 
838  case 13: // M
840  return true;
841 
842  case 14: // N
844  return true;
845 
846  case 15: // O
848  return true;
849 
850  case 16: // P
852  return true;
853 
854  case 17: // Q
856  return true;
857 
858  case 18: // R
860  return true;
861 
862  case 19 : // S
864  return true;
865 
866  case 21: // U
868  return true;
869 
870  case 22: // V
872  return true;
873 
874  case 23: // W
876  return true;
877 
878  case 24: // X
880  return true;
881 
882  }
883  }
884 
885  if ( mod & KMOD_SHIFT ) {
886  switch ( key->keysym.sym ) {
887  case SDLK_d: execaction_ev(act_changeunitdir);
888  return true;
889  case SDLK_F3 : execaction_ev(act_selbodentypAll);
890  return true;
891 
892  case SDLK_F4 : execaction_ev(act_selobjectAll);
893  return true;
894  default:;
895  }
896  }
897 
898  if ( mod & KMOD_ALT ) {
899  switch ( key->keysym.sym ) {
900  case SDLK_RETURN:
902  return true;
903 
904  case SDLK_F11:
905  /*
906  if ( mod & KMOD_SHIFT ) {
907  if (choice_dlg("Do you really want to crash ASC ?","~y~es","~n~o") == 1) {
908  char* c = NULL;
909  *c = 1;
910  }
911  }
912  */
913  { for ( Player::VehicleList::iterator i = actmap->player[1].vehicleList.begin(); i != actmap->player[1].vehicleList.end(); ++i )
914  (*i)->direction = 3;
915  }
916  return true;
917 
918  default:;
919  }
920  }
921 
922  return false;
923 }
924 
925 
926 
928  public:
929  MapItemSelectionWindow( PG_Widget *parent, const PG_Rect &r , const ASCString& title, SelectionItemFactory* itemFactory )
930  : ItemSelectorWindow( parent, r, title, itemFactory ) {};
931 
933  {
934  if ( CGameOptions::Instance()->maped_modalSelectionWindow )
935  Hide();
936  QuitModal();
937  }
938 
939 };
940 
941 typedef PG_Window* PG_WindowPointer;
942 
943 template <class ItemType>
944 void showSelectionWindow( PG_Widget* parent, PG_WindowPointer &selectionWindow, const ItemRepository<ItemType>& itemRepository )
945 {
946  if ( !selectionWindow ) {
947  ItemSelectorWindow* sw = new MapItemSelectionWindow( parent, PG_Rect( parent->Width()-300, 100, 280, parent->Height()-150), "select item", new MapItemTypeWidgetFactory< MapItemTypeWidget<ItemType> >(itemRepository) );
948 
949  filtersChangedSignal.connect( sigc::mem_fun( *sw, &ItemSelectorWindow::reLoad ));
950  selectionWindow = sw;
951  }
952 
953  selectionWindow->Show();
954  selectionWindow->RunModal();
955  if ( CGameOptions::Instance()->maped_modalSelectionWindow )
956  selectionWindow->Hide();
957 
958 }
959 
960 
962 {
963  selection.clear();
964  return true;
965 }
966 
967 
969 {
970  showSelectionWindow( this, vehicleSelector, vehicleTypeRepository );
971  return true;
972 }
973 
974 
976 {
977  showSelectionWindow( this, buildingSelector, buildingTypeRepository );
978  return true;
979 }
980 
982 {
984  // showSelectionWindow( this, objectSelector, objectTypeRepository );
985  return true;
986 }
987 
989 {
990  showSelectionWindow( this, objectSelector, objectTypeRepository );
991  return true;
992 }
993 
994 
996 {
998  // showSelectionWindow( this, terrainSelector, terrainTypeRepository );
999  return true;
1000 }
1001 
1003 {
1004  showSelectionWindow( this, terrainSelector, terrainTypeRepository );
1005  return true;
1006 }
1007 
1008 
1010 {
1011  showSelectionWindow( this, mineSelector, mineTypeRepository );
1012  return true;
1013 }
1014 
1016 {
1017  ASCString file = selectFile( "*.brush.lua", true );
1018  if ( file.empty () )
1019  return true;
1020 
1021  LuaBrush brush ( file );
1022  selection.setSelection( brush );
1023 
1024 
1025  return true;
1026 }
1027 
1028 
1029 
1030 void displaymessage2( const char* formatstring, ... )
1031 {
1032 
1033  ASCString s;
1034 
1035  std::va_list arg_ptr;
1036  va_start ( arg_ptr, formatstring );
1037 
1038  s.vaformat( formatstring, arg_ptr );
1039 
1040  va_end ( arg_ptr );
1041 
1042  if ( mainScreenWidget )
1043  mainScreenWidget->displayMessage(s);
1044 }
1045 
1046 
1047 
1048 
bool mouseDraggedToField(const MapCoordinate &pos, const SPoint &mousePos, bool cursorChanged, int prio)
Definition: edmisc.cpp:103
MineTypeRepository mineTypeRepository
ItemRepositoryLoader< ObjectType > objectTypeRepository("objecttype")
bool available(const MapCoordinate &pos)
MapCoordinate & getCursor()
Definition: gamemap.cpp:933
sigc::signal< void > filtersChangedSignal
Definition: edselfnt.cpp:42
int maxLoadableUnits
the maximum number of units that can be loaded
map accessing and usage routines used by ASC and the mapeditor
miscellaneous functions which are used by ASC and all its tools
bool available(const MapCoordinate &pos)
MapItemSelectionWindow(PG_Widget *parent, const PG_Rect &r, const ASCString &title, SelectionItemFactory *itemFactory)
Vehicle * vehicle
Definition: mapfield.h:89
static int Height()
bool eventKeyUp(const PG_MessageObject *o, const SDL_KeyboardEvent *key)
ASCString & vaformat(const charT *pFormat, va_list ap)
Definition: ascstring.cpp:91
static int Width()
void displaymessage2(const char *formatstring,...)
displays a message in the status line of ASC
bool eventMouseButtonDown(const SDL_MouseButtonEvent *button)
const char * cwettertypen[cwettertypennum]
the names of the different weather
Definition: typen.cpp:78
bool available(const MapCoordinate &pos)
bool available(const MapCoordinate &pos)
void execaction_ev(int code)
Definition: edglobal.cpp:1026
Maped_MainScreenWidget * mainScreenWidget
bool hasFunction(ContainerFunctions function) const
void playerChanged(int player)
bool available(const MapCoordinate &pos)
sigc::signal< bool, const MapCoordinate &, const SPoint &, bool, int > mouseDraggedToField
Signal that is fired when the mouse is dragged onto a new field with mouse buttons pressed...
Definition: mapdisplay.h:322
sigc::signal< void, const Placeable * > selectionChanged
Definition: edglobal.h:174
bool available(const MapCoordinate &pos)
ItemRepositoryLoader< BuildingType > buildingTypeRepository("buildingtype")
ContainerBase * getContainer()
returns a pointer to the ContainerBase of the field or NULL if there is none
Definition: mapfield.cpp:331
Global platform dependant definitions. This file just branches to the platform specific files in thei...
sigc::signal< void, int > selectionSignal
virtual int getID() const =0
struct MapDisplayPG::Cursor cursor
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
bool available(const MapCoordinate &pos)
bool mousePressedOnField(const MapCoordinate &pos, const SPoint &mousePos, bool cursorChanged, int button, int prio)
Definition: edmisc.cpp:91
Maped_MainScreenWidget(PG_Application &application)
Menu(PG_Widget *parent, const PG_Rect &rect=PG_Rect::null)
void setSelection(const Placeable &component)
Definition: edglobal.cpp:191
ASCString getText(const MapCoordinate &pos)
void showWeaponRange(GameMap *gamemap, const MapCoordinate &pos)
void itemSelected(const SelectionWidget *)
static ASCString toString(int i)
converts the parameter to a String
Definition: ascstring.cpp:193
ASC_PG_App & getPGApplication()
Definition: paradialog.cpp:294
A MapComponent represents any kind of item that can be placed on the map by the user.
VehicleList vehicleList
a list of all units
Definition: player.h:135
ItemRepositoryLoader< VehicleType > vehicleTypeRepository("vehicletype")
ASCString getText(const MapCoordinate &pos)
void selectionChanged(const Placeable *item)
PG_Label * messageLine
bool available(const MapCoordinate &pos)
ItemRepositoryLoader< TerrainType > terrainTypeRepository("terraintype")
void helperFunction()
void set(const Placeable *item)
Coordinate on the twodimensional map.
Definition: typen.h:202
A MapItemTypeWidget show any kind of MapItemType in a SelectionWidget It is typically generated by a ...
Definition: edselfnt.h:56
MapDisplayPG * mapDisplay
Dialog classes based on the Paragui library.
void addContextAction(ContextAction *contextAction)
sigc::signal< void > updateFieldInfo
Definition: spfst.cpp:47
void setup()
tuseractions
Definition: edglobal.h:34
ASCString getText(const MapCoordinate &pos)
void showSelectionWindow(PG_Widget *parent, PG_WindowPointer &selectionWindow, const ItemRepository< ItemType > &itemRepository)
bool clickOnMap(const MapCoordinate &field, const SPoint &pos, bool changed, int button, int prio)
SDLmm::SPoint SPoint
Definition: surface.h:27
Player player[9]
Definition: gamemap.h:253
static CGameOptions * Instance()
returns the only Instance
Definition: gameoptions.cpp:38
bool eventKeyDown(const PG_MessageObject *o, const SDL_KeyboardEvent *key)
bool toggleFullscreen()
Definition: paradialog.cpp:258
void addMapLayer(MapLayer *layer, const ASCString &name)
MineContainer mines
Definition: mapfield.h:117
ASCString getText(const MapCoordinate &pos)
ASCString selectFile(const ASCString &ext, bool load, bool overwriteMessage)
SelectionHolder selection
Definition: edglobal.cpp:189
void displayMessage(const ASCString &message)
PG_Window * PG_WindowPointer
basegfx.h is the interface for the legacy graphic routines (of which some are platform dependent)...
void operateField(GameMap *actmap, const MapCoordinate &pos)
Adds selection logic to a BaseMapItemTypeWidgetFactory. Selected items are registered as being the ac...
Definition: edselfnt.h:142
sigc::signal< bool, const MapCoordinate &, const SPoint &, bool, int, int > mouseButtonOnField
Signal that is fired when the mouse is pressed on a valid field, after the cursor evaluation has been...
Definition: mapdisplay.h:314
ASCString getText(const MapCoordinate &pos)
Building * building
Definition: mapfield.h:102
void goTo(const MapCoordinate &position)
void AddItem(const std::string &text, void *userdata=NULL, Uint16 height=0)
void setPlayer(int player)
Definition: edglobal.cpp:198
const ContainerBaseType * baseType
the type descriping all non-instance specific properties of the container
Definition: containerbase.h:80
bool available(const MapCoordinate &pos)
a container that stores pointers and deletes the pointed-to objects on destruction ...
Definition: typen.h:314
sigc::signal< void > cursorMoved
Definition: spfst.cpp:48
sigc::signal< void, int > playerChanged
Definition: edglobal.h:164
GameMap * actmap
Definition: spfst.cpp:64
MainScreenWidget * getMainScreenWidget()
bool execAction(PG_PopupMenu::MenuItem *menuItem)
bool available(const MapCoordinate &pos)
void setWeather(int weather)
Definition: edglobal.cpp:212
const char * execactionnames[execactionscount]
Definition: edglobal.cpp:68
virtual ASCString getName() const =0
const MapItemType * getItemType() const
void spawnOverviewMapPanel(const ASCString &panelName="OverviewMap")
void setup(bool messageLine, const PG_Rect &mapView)
virtual int getActionID()=0
const int cwettertypennum
The number of different weather.
Definition: typen.h:61
ObjectContainer objects
Definition: mapfield.h:124
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182
MapField * getField(int x, int y)
Definition: gamemap.h:465