00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "dlggoto.h"
00026 #include "app.h"
00027 #include "map.h"
00028 #include "profilemanager.h"
00029 #include "town.h"
00030
00031 #include <wx/notebook.h>
00032 #include <wx/panel.h>
00033 #include <wx/valtext.h>
00034
00035 namespace WDS
00036 {
00037
00038 BEGIN_EVENT_TABLE(CDlgGoTo, wxDialog)
00039 EVT_BUTTON( wxID_OK, CDlgGoTo::OnGoTo )
00040 EVT_BUTTON( wxID_CANCEL, CDlgGoTo::OnClose )
00041 EVT_BUTTON( IDC_REMOVE_BOOKMARKS, CDlgGoTo::OnDeleteBookmarks )
00042 EVT_BUTTON( IDC_REMOVE_RECENTS, CDlgGoTo::OnDeleteRecents )
00043 EVT_TEXT ( IDC_EDT_X, CDlgGoTo::OnPaste )
00044 EVT_LIST_ITEM_ACTIVATED( IDC_LIST_BOOKMARKS, CDlgGoTo::OnActivateBookmarkItem )
00045 EVT_LIST_ITEM_ACTIVATED( IDC_LIST_RECENTS, CDlgGoTo::OnActivateRecentItem )
00046 EVT_LIST_ITEM_SELECTED( IDC_LIST_BOOKMARKS, CDlgGoTo::OnSelectedBookmarkItem )
00047 EVT_LIST_ITEM_SELECTED( IDC_LIST_RECENTS, CDlgGoTo::OnSelectedRecentItem )
00048 END_EVENT_TABLE()
00049
00050
00051
00052
00053
00054 void CDlgGoTo::OnPaste( wxCommandEvent& event )
00055 {
00056 if( !m_pEdtPosX )
00057 return;
00058
00059
00060 wxString strTmp = m_pEdtPosX->GetValue();
00061 if( strTmp.Find( ':' ) != -1 )
00062 {
00063 strTmp.Trim( true );
00064 strTmp.Trim( false );
00065
00066
00067 m_pEdtPosX->SetValue( strTmp.BeforeFirst( ':' ) );
00068 m_pEdtPosY->SetValue( strTmp.AfterFirst ( ':' ) );
00069
00070 m_pEdtPosX->SetSelection( -1, -1 );
00071 m_pEdtPosY->SetFocus();
00072 }
00073 }
00074
00075 CDlgGoTo::CDlgGoTo( wxWindow *pParent )
00076 : wxDialog( pParent, -1, wxString("GoTo - WDSMap"), wxDefaultPosition,
00077 wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
00078 m_pEdtPosX(0L), m_pEdtPosY(0L)
00079 {
00080 wxBoxSizer* sTop = new wxBoxSizer( wxVERTICAL );
00081 wxNotebook* sTabs = new wxNotebook( this, -1 );
00082 wxBoxSizer* sBookmarks = new wxBoxSizer( wxVERTICAL );
00083 wxBoxSizer* sRecents = new wxBoxSizer( wxVERTICAL );
00084 wxBoxSizer* sGoToClose = new wxBoxSizer( wxHORIZONTAL );
00085 wxPanel* pBookmarks = new wxPanel( sTabs );
00086 wxPanel* pRecents = new wxPanel( sTabs );
00087
00088
00089 m_pLstBookmarks = new wxListCtrl( pBookmarks, IDC_LIST_BOOKMARKS, wxDefaultPosition, wxDefaultSize,
00090 wxLC_REPORT | wxLC_VRULES | wxLC_SINGLE_SEL );
00091 m_pLstBookmarks->InsertColumn( 0, "Position", wxLIST_FORMAT_LEFT, 80 );
00092 m_pLstBookmarks->InsertColumn( 1, "Stadt - [Gilde] Besitzer", wxLIST_FORMAT_LEFT, 200 );
00093 m_pLstBookmarks->InsertColumn( 3, "Beschreibung", wxLIST_FORMAT_LEFT, 150 );
00094
00095 wxButton* pBtnRemoveBookmarks = new wxButton( pBookmarks, IDC_REMOVE_BOOKMARKS, "Auswahl löschen" );
00096
00097 sBookmarks->Add( m_pLstBookmarks, 1, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 10 );
00098 sBookmarks->Add( pBtnRemoveBookmarks, 0, wxALIGN_RIGHT | wxALL, 10 );
00099
00100
00101
00102 m_pLstRecents = new wxListCtrl( pRecents, IDC_LIST_RECENTS, wxDefaultPosition, wxDefaultSize,
00103 wxLC_REPORT | wxLC_VRULES | wxLC_SINGLE_SEL );
00104 m_pLstRecents->InsertColumn( 0, "Position", wxLIST_FORMAT_LEFT, 80 );
00105 m_pLstRecents->InsertColumn( 1, "Stadt - [Gilde] Besitzer", wxLIST_FORMAT_LEFT, 250 );
00106
00107 wxButton* pBtnRemoveRecents = new wxButton( pRecents, IDC_REMOVE_RECENTS, "Auswahl löschen" );
00108
00109 sRecents->Add( m_pLstRecents, 1, wxEXPAND | wxALL, 10 );
00110 sRecents->Add( pBtnRemoveRecents, 0, wxALIGN_RIGHT | wxLEFT | wxRIGHT | wxBOTTOM, 10 );
00111
00112
00113
00114 wxStaticText* pTxtPosition = new wxStaticText( this, -1, "Position (x:y)" );
00115 m_pEdtPosX = new wxTextCtrl( this, IDC_EDT_X, "1", wxDefaultPosition, wxSize( 40, -1 ) );
00116 m_pEdtPosY = new wxTextCtrl( this, IDC_EDT_Y, "1", wxDefaultPosition, wxSize( 40, -1 ) );
00117
00118 wxButton* pBtnGoTo = new wxButton( this, wxID_OK, "GO!", wxDefaultPosition, wxSize( 40, -1 ) );
00119 wxStaticText* pTxtDummy = new wxStaticText( this, -1, "" );
00120 wxButton* pBtnClose = new wxButton( this, wxID_CANCEL, "Schließen" );
00121
00122 sGoToClose->Add( pTxtPosition, 0, wxALIGN_CENTER_VERTICAL | wxTOP | wxRIGHT, 5 );
00123 sGoToClose->Add( m_pEdtPosX, 0, wxALIGN_CENTER_VERTICAL | wxTOP | wxRIGHT, 5 );
00124 sGoToClose->Add( m_pEdtPosY, 0, wxALIGN_CENTER_VERTICAL | wxTOP | wxRIGHT, 5 );
00125 sGoToClose->Add( pBtnGoTo , 0, wxALIGN_CENTER_VERTICAL | wxTOP | wxRIGHT, 5 );
00126 sGoToClose->Add( pTxtDummy , 1, wxEXPAND, 0 );
00127 sGoToClose->Add( pBtnClose , 0, wxALIGN_CENTER_VERTICAL | wxTOP, 5 );
00128
00129
00130 sTop->Add( sTabs, 1, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 10);
00131 sTop->Add( sGoToClose, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 10);
00132
00133 sTabs->AddPage( pBookmarks, wxString("Bookmarks") );
00134 sTabs->AddPage( pRecents, wxString("Recents") );
00135
00136 pBookmarks->SetSizer( sBookmarks );
00137 pRecents ->SetSizer( sRecents );
00138
00139 SetAutoLayout( true );
00140 SetSizer( sTop );
00141
00142 sTop->SetSizeHints( this );
00143 SetClientSize( 500, 300 );
00144
00145 m_pEdtPosX->SetFocus();
00146 pBtnGoTo->SetDefault( );
00147
00148
00149 m_x = 0;
00150 m_y = 0;
00151
00152 FillListBoxes( );
00153 }
00154
00155 CDlgGoTo::~CDlgGoTo()
00156 {
00157 }
00158
00159
00160
00161
00162
00167 void CDlgGoTo::FillListBoxes( )
00168 {
00169 m_pLstBookmarks->DeleteAllItems();
00170 m_pLstRecents ->DeleteAllItems();
00171
00172 CProfile* profile = CProfileManager::GetCurrentProfile();
00173 CMap* pMap = wxGetApp().GetMap();
00174
00175 if ( profile && pMap ) {
00176
00177 GoToArray bookmarks = profile->GetBookmarks();
00178 GoToArray recents = profile->GetRecentGoTos();
00179
00180 int index;
00181 GoToArray::iterator it;
00182 wxListItem item;
00183
00184
00185 for ( index = 0, it = bookmarks.begin();
00186 it != bookmarks.end();
00187 it++, index++ )
00188 {
00189 CTown* pTown = pMap->GetTownAt( it->x, it->y );
00190 wxString infos = "-";
00191 if ( pTown ) {
00192 infos = pTown->GetName() + " - " + pTown->GetGuild() + " " + pTown->GetOwner();
00193 }
00194
00195 m_pLstBookmarks->InsertItem ( index, wxString::Format("%d:%d", it->x, it->y) );
00196 m_pLstBookmarks->SetItemData( index, index );
00197
00198 m_pLstBookmarks->SetItem( index, 1, infos );
00199 m_pLstBookmarks->SetItem( index, 2, it->comment );
00200
00201 if ( index & 1 ) {
00202 item.SetBackgroundColour( wxColor( 238, 246, 255) );
00203 } else {
00204 item.SetBackgroundColour( wxColor( 255, 255, 255) );
00205 }
00206
00207 item.m_itemId = index;
00208 m_pLstBookmarks->SetItem( item );
00209 }
00210
00211
00212 for ( index = 0, it = recents.begin();
00213 it != recents.end(); it++, index++ )
00214 {
00215 CTown* pTown = pMap->GetTownAt( it->x, it->y );
00216 wxString infos = "-";
00217 if ( pTown ) {
00218 infos = pTown->GetName() + " - " + pTown->GetGuild() + " " + pTown->GetOwner();
00219 }
00220
00221 m_pLstRecents->InsertItem ( 0, wxString::Format("%d:%d", it->x, it->y) );
00222 m_pLstRecents->SetItemData( 0, index );
00223
00224 m_pLstRecents->SetItem( 0, 1, infos );
00225
00226 if ( index & 1 ) {
00227 item.SetBackgroundColour( wxColor( 238, 246, 255) );
00228 } else {
00229 item.SetBackgroundColour( wxColor( 255, 255, 255) );
00230 }
00231
00232 item.m_itemId = 0;
00233 m_pLstRecents->SetItem( item );
00234 }
00235 }
00236 }
00237
00238 void CDlgGoTo::OnDeleteBookmarks( wxCommandEvent &event )
00239 {
00240 long result = m_pLstBookmarks->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
00241
00242 if( result == -1 ) {
00243 return;
00244 }
00245
00246 int nIndex = m_pLstBookmarks->GetItemData( result );
00247
00248 CProfile* profile = CProfileManager::GetCurrentProfile( );
00249 GoToArray& rgoto = profile->GetBookmarks( );
00250
00251 GoToArray::iterator it = rgoto.begin() + nIndex;
00252
00253 if ( it != rgoto.end() ) {
00254 rgoto.erase( it );
00255 }
00256
00257 FillListBoxes( );
00258 }
00259
00260 void CDlgGoTo::OnDeleteRecents( wxCommandEvent &event )
00261 {
00262 long result = m_pLstRecents->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
00263
00264 if( result == -1 ) {
00265 return;
00266 }
00267
00268 int nIndex = m_pLstRecents->GetItemData( result );
00269
00270 CProfile* profile = CProfileManager::GetCurrentProfile( );
00271 GoToArray& rgoto = profile->GetRecentGoTos( );
00272
00273 GoToArray::iterator it = rgoto.begin() + nIndex;
00274
00275 if ( it != rgoto.end() ) {
00276 rgoto.erase( it );
00277 }
00278
00279 FillListBoxes( );
00280 }
00281
00282 void CDlgGoTo::OnSelectedBookmarkItem( wxCommandEvent &event )
00283 {
00284 long result = m_pLstBookmarks->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
00285
00286 if( result == -1 ) {
00287 return;
00288 }
00289
00290 int nIndex = m_pLstBookmarks->GetItemData( result );
00291
00292 CProfile* profile = CProfileManager::GetCurrentProfile( );
00293 GoToArray& rgoto = profile->GetBookmarks( );
00294
00295 GoToArray::iterator it = rgoto.begin() + nIndex;
00296
00297 if ( it != rgoto.end() ) {
00298 m_pEdtPosX->SetValue( wxString::Format("%d", it->x) );
00299 m_pEdtPosY->SetValue( wxString::Format("%d", it->y) );
00300 }
00301 }
00302
00303 void CDlgGoTo::OnSelectedRecentItem( wxCommandEvent &event )
00304 {
00305 long result = m_pLstRecents->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
00306
00307 if( result == -1 ) {
00308 return;
00309 }
00310
00311 int nIndex = m_pLstRecents->GetItemData( result );
00312
00313 CProfile* profile = CProfileManager::GetCurrentProfile( );
00314 GoToArray& rgoto = profile->GetRecentGoTos( );
00315
00316 GoToArray::iterator it = rgoto.begin() + nIndex;
00317
00318 if ( it != rgoto.end() ) {
00319 m_pEdtPosX->SetValue( wxString::Format("%d", it->x) );
00320 m_pEdtPosY->SetValue( wxString::Format("%d", it->y) );
00321 }
00322 }
00323
00324 void CDlgGoTo::OnActivateBookmarkItem( wxListEvent& event )
00325 {
00326 CProfile* profile = CProfileManager::GetCurrentProfile();
00327 if ( !profile )
00328 return;
00329
00330 GoToArray& rgoto = profile->GetBookmarks();
00331
00332 int nIndex = event.GetData();
00333 if ( nIndex < 0 || nIndex >= int(rgoto.size()) )
00334 return;
00335
00336 CGoToEntry entry = rgoto[nIndex];
00337
00338 m_x = entry.x;
00339 m_y = entry.y;
00340
00341 EndModal( wxID_OK );
00342 }
00343
00344 void CDlgGoTo::OnActivateRecentItem( wxListEvent& event )
00345 {
00346 CProfile* profile = CProfileManager::GetCurrentProfile();
00347 if ( !profile )
00348 return;
00349
00350 GoToArray& rgoto = profile->GetRecentGoTos();
00351
00352 int nIndex = event.GetData();
00353 if ( nIndex < 0 || nIndex >= int(rgoto.size()) )
00354 return;
00355
00356 CGoToEntry entry = rgoto[nIndex];
00357
00358 m_x = entry.x;
00359 m_y = entry.y;
00360
00361 EndModal( wxID_OK );
00362 }
00363
00364 void CDlgGoTo::OnGoTo ( wxCommandEvent &event )
00365 {
00366 long x, y;
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381 wxString strX = m_pEdtPosX->GetValue();
00382 if( !strX.ToLong( &x ) )
00383 {
00384 wxMessageBox( wxString::Format("'%s' ist keine Zahl!", strX.c_str() ));
00385 return;
00386 }
00387
00388
00389 wxString strY = m_pEdtPosY->GetValue();
00390 if( !strY.ToLong( &y ) )
00391 {
00392 wxMessageBox( wxString::Format("'%s' ist keine Zahl!", strY.c_str() ));
00393 return;
00394 }
00395
00396
00397 m_x = x;
00398 m_y = y;
00399
00400 event.Skip( );
00401 }
00402
00403 void CDlgGoTo::OnClose( wxCommandEvent &event )
00404 {
00405 event.Skip( );
00406 }
00407
00408 }
00409
00410