Advanced Strategic Command
gotoposition.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * This program is free software; you can redistribute it and/or modify *
4  * it under the terms of the GNU General Public License as published by *
5  * the Free Software Foundation; either version 2 of the License, or *
6  * (at your option) any later version. *
7  * *
8  ***************************************************************************/
9 
10 #include <boost/regex.hpp>
11 
12 #include "gotoposition.h"
13 #include "../gamemap.h"
14 #include "../mainscreenwidget.h"
15 #include "../mapdisplay.h"
16 
17 bool GotoPosition::ok()
18 {
19  static boost::regex numercial("\\d+");
20 
21  if( boost::regex_match( xfield->GetText(), numercial) &&
22  boost::regex_match( yfield->GetText(), numercial)) {
23  int xx = atoi( xfield->GetText() );
24  int yy = atoi( yfield->GetText() );
25  if ( xx >= 0 && yy >= 0 && xx < gamemap->xsize && yy < gamemap->ysize ) {
26  Hide();
28  md->cursor.goTo( MapCoordinate( xx, yy) );
29  QuitModal();
30  return true;
31  }
32  }
33  return false;
34 }
35 
36 bool GotoPosition::cancel()
37 {
38  QuitModal();
39  return true;
40 }
41 
42 bool GotoPosition::line1completed()
43 {
44  if ( yfield ) {
45  yfield->EditBegin();
46  return true;
47  } else
48  return false;
49 }
50 
51 GotoPosition::GotoPosition ( GameMap* gamemap ) : ASC_PG_Dialog( NULL, PG_Rect( -1, -1, 300, 120), "Enter Coordinates")
52 {
53  this->gamemap = gamemap;
54  int fieldwidth = (Width()-3*border)/2;
55  xfield = new PG_LineEdit( this, PG_Rect( border, 40, fieldwidth, 20));
56  // xfield->SetText( ASCString::toString( gamemap->getCursor().x ));
57  xfield->sigEditReturn.connect( sigc::mem_fun( *this, &GotoPosition::line1completed ));
58 
59  yfield = new PG_LineEdit( this, PG_Rect( (Width()+border)/2, 40, fieldwidth, 20));
60  // yfield->SetText( ASCString::toString( gamemap->getCursor().y ));
61  yfield->sigEditReturn.connect( sigc::mem_fun( *this, &GotoPosition::ok ));
62 
63  AddStandardButton( "~O~k" )->sigClick.connect( sigc::hide( sigc::mem_fun( *this, &GotoPosition::ok )));
64 };
65 
67 {
68  xfield->EditBegin();
69  return ASC_PG_Dialog::RunModal();
70 }
71 
struct MapDisplayPG::Cursor cursor
Coordinate on the twodimensional map.
Definition: typen.h:202
Adapter class for using Paragui Dialogs in ASC. This class transfers the event control from ASC to Pa...
Definition: paradialog.h:127
MapDisplayPG * getMapDisplay()
GotoPosition(GameMap *gamemap)
int atoi(const std::string &s)
Definition: misc.cpp:152
void goTo(const MapCoordinate &position)
MainScreenWidget * getMainScreenWidget()
PG_Button * AddStandardButton(const ASCString &name)
Definition: paradialog.cpp:516
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182