00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <boost/regex.hpp>
00011
00012 #include "gotoposition.h"
00013 #include "../gamemap.h"
00014 #include "../mainscreenwidget.h"
00015 #include "../mapdisplay.h"
00016
00017 bool GotoPosition::ok()
00018 {
00019 static boost::regex numercial("\\d+");
00020
00021 if( boost::regex_match( xfield->GetText(), numercial) &&
00022 boost::regex_match( yfield->GetText(), numercial)) {
00023 int xx = atoi( xfield->GetText() );
00024 int yy = atoi( yfield->GetText() );
00025 if ( xx >= 0 && yy >= 0 && xx < gamemap->xsize && yy < gamemap->ysize ) {
00026 Hide();
00027 MapDisplayPG* md = getMainScreenWidget()->getMapDisplay();
00028 md->cursor.goTo( MapCoordinate( xx, yy) );
00029 QuitModal();
00030 return true;
00031 }
00032 }
00033 return false;
00034 }
00035
00036 bool GotoPosition::cancel()
00037 {
00038 QuitModal();
00039 return true;
00040 }
00041
00042 bool GotoPosition::line1completed()
00043 {
00044 if ( yfield ) {
00045 yfield->EditBegin();
00046 return true;
00047 } else
00048 return false;
00049 }
00050
00051 GotoPosition::GotoPosition ( GameMap* gamemap ) : ASC_PG_Dialog( NULL, PG_Rect( -1, -1, 300, 120), "Enter Coordinates")
00052 {
00053 this->gamemap = gamemap;
00054 int fieldwidth = (Width()-3*border)/2;
00055 xfield = new PG_LineEdit( this, PG_Rect( border, 40, fieldwidth, 20));
00056
00057 xfield->sigEditReturn.connect( SigC::slot( *this, &GotoPosition::line1completed ));
00058
00059 yfield = new PG_LineEdit( this, PG_Rect( (Width()+border)/2, 40, fieldwidth, 20));
00060
00061 yfield->sigEditReturn.connect( SigC::slot( *this, &GotoPosition::ok ));
00062
00063 AddStandardButton( "~O~k" )->sigClick.connect( SigC::slot( *this, &GotoPosition::ok ));
00064 };
00065
00066 int GotoPosition::RunModal()
00067 {
00068 xfield->EditBegin();
00069 return ASC_PG_Dialog::RunModal();
00070 }
00071