void MapTabbook::OnNotebookPageChanged(wxAuiNotebookEvent& evt) { gui.UpdateMinimap(); int32_t oldSelection = evt.GetOldSelection(); int32_t newSelection = evt.GetSelection(); MapTab* oldMapTab; if(oldSelection != -1) { oldMapTab = dynamic_cast<MapTab*>(GetTab(oldSelection)); } else { oldMapTab = nullptr; } MapTab* newMapTab; if(newSelection != -1) { newMapTab = dynamic_cast<MapTab*>(GetTab(newSelection)); } else { newMapTab = nullptr; } // std::cout << oldSelection << " " << newSelection; if(!newMapTab) { gui.RefreshPalettes(nullptr); } else if(!oldMapTab || !oldMapTab->HasSameReference(newMapTab)) { gui.RefreshPalettes(newMapTab->GetMap()); gui.UpdateMenus(); } }
double GUI::GetCurrentZoom() { MapTab* tab = GetCurrentMapTab(); if(tab) return tab->GetCanvas()->GetZoom(); return 1.0; }
bool GUI::LoadMap(FileName name) { if(GetCurrentEditor() && !GetCurrentMap().hasChanged() && !GetCurrentMap().hasFile()) g_gui.CloseCurrentEditor(); Editor* editor; try { editor = newd Editor(copybuffer, name); } catch(std::runtime_error& e) { PopupDialog(root, wxT("Error!"), wxString(e.what(), wxConvUTF8), wxOK); return false; } MapTab* mapTab = newd MapTab(tabbook, editor); mapTab->OnSwitchEditorMode(mode); root->AddRecentFile(name); mapTab->GetView()->FitToMap(); UpdateTitle(); ListDialog(wxT("Map loader errors"), mapTab->GetMap()->getWarnings()); root->DoQueryImportCreatures(); FitViewToMap(mapTab); root->UpdateMenubar(); return true; }
Editor* GUI::GetCurrentEditor() { MapTab* mapTab = GetCurrentMapTab(); if(mapTab) return mapTab->GetEditor(); return nullptr; }
void MapTabbook::OnNotebookPageClose(wxAuiNotebookEvent& evt) { EditorTab* editorTab = GetTab(evt.GetInt()); MapTab* mapTab = dynamic_cast<MapTab*>(editorTab); if(mapTab && mapTab->IsUniqueReference() && mapTab->GetMap()) { if(mapTab->GetEditor()->IsLive()) { if(mapTab->GetMap()->hasChanged()) { SetFocusedTab(evt.GetInt()); if(gui.root->DoQuerySave(false)) { gui.RefreshPalettes(nullptr, false); gui.UpdateMenus(); } else { evt.Veto(); } } else { gui.RefreshPalettes(nullptr, false); gui.UpdateMenus(); } } return; } LiveLogTab* lt = dynamic_cast<LiveLogTab*>(editorTab); if(lt && lt->IsConnected()) { evt.Veto(); } }
void GUI::ChangeFloor(int new_floor) { MapTab* tab = GetCurrentMapTab(); if(tab) { int old_floor = GetCurrentFloor(); if(new_floor < 0 || new_floor > MAP_MAX_LAYER) return; if(old_floor != new_floor) tab->GetCanvas()->ChangeFloor(new_floor); } }
int GUI::GetOpenMapCount() { std::set<Map*> open_maps; for(int i = 0; i < tabbook->GetTabCount(); ++i) { MapTab* tab = dynamic_cast<MapTab*>(tabbook->GetTab(i)); if(tab) open_maps.insert(open_maps.begin(), tab->GetMap()); } return open_maps.size(); }
void GUI::NewMapView() { MapTab* mapTab = GetCurrentMapTab(); if(mapTab) { MapTab* newMapTab = newd MapTab(mapTab); newMapTab->OnSwitchEditorMode(mode); SetStatusText(wxT("Created newd view")); UpdateTitle(); RefreshPalettes(); root->UpdateMenubar(); root->Refresh(); } }
bool GUI::CloseLiveEditors(LiveSocket* sock) { for(int i = 0; i < tabbook->GetTabCount(); ++i) { MapTab* mapTab = dynamic_cast<MapTab*>(tabbook->GetTab(i)); if(mapTab) { Editor* editor = mapTab->GetEditor(); if(editor->GetLiveClient() == sock) tabbook->DeleteTab(i--); } LiveLogTab* liveLogTab = dynamic_cast<LiveLogTab*>(tabbook->GetTab(i)); if(liveLogTab) { if(liveLogTab->GetSocket() == sock) { liveLogTab->Disconnect(); tabbook->DeleteTab(i--); } } } root->UpdateMenubar(); return true; }
void GUI::CreateLoadBar(wxString message, bool canCancel /* = false */ ) { progressText = message; progressFrom = 0; progressTo = 100; currentProgress = -1; progressBar = newd wxGenericProgressDialog(wxT("Loading"), progressText + wxT(" (0%)"), 100, root, wxPD_APP_MODAL | wxPD_SMOOTH | (canCancel ? wxPD_CAN_ABORT : 0) ); progressBar->SetSize(280, -1); progressBar->Show(true); for(int idx = 0; idx < tabbook->GetTabCount(); ++idx) { MapTab* mt = dynamic_cast<MapTab*>(tabbook->GetTab(idx)); if(mt && mt->GetEditor()->IsLiveServer()) mt->GetEditor()->GetLiveServer()->startOperation(progressText); } progressBar->Update(0); }
bool GUI::CloseAllEditors() { for(int i = 0; i < tabbook->GetTabCount(); ++i) { MapTab* mapTab = dynamic_cast<MapTab*>(tabbook->GetTab(i)); if(mapTab) { if(mapTab->IsUniqueReference() && mapTab->GetMap() && mapTab->GetMap()->hasChanged()) { tabbook->SetFocusedTab(i); if(!root->DoQuerySave(false)) { return false; } else { RefreshPalettes(); tabbook->DeleteTab(i--); } } else { tabbook->DeleteTab(i--); } } } if(root) root->UpdateMenubar(); return true; }
bool GUI::SetLoadDone(int32_t done, const wxString& newMessage) { if(done == 100) { DestroyLoadBar(); return true; } else if(done == currentProgress) { return true; } if(!newMessage.empty()) { progressText = newMessage; } int32_t newProgress = progressFrom + static_cast<int32_t>((done / 100.f) * (progressTo - progressFrom)); newProgress = std::max<int32_t>(0, std::min<int32_t>(100, newProgress)); bool skip = false; if(progressBar) { progressBar->Update( newProgress, wxString::Format(wxT("%s (%d%%)"), progressText, newProgress), &skip ); currentProgress = newProgress; } for(int32_t index = 0; index < tabbook->GetTabCount(); ++index) { MapTab* mapTab = dynamic_cast<MapTab*>(tabbook->GetTab(index)); if(mapTab && mapTab->GetEditor()) { LiveServer* server = mapTab->GetEditor()->GetLiveServer(); if(server) { server->updateOperation(newProgress); } } } return skip; }
bool GUI::NewMap() { Editor* editor; try { editor = newd Editor(copybuffer); } catch(std::runtime_error& e) { PopupDialog(root, wxT("Error!"), wxString(e.what(), wxConvUTF8), wxOK); return false; } MapTab* mapTab = newd MapTab(tabbook, editor); mapTab->OnSwitchEditorMode(mode); SetStatusText(wxT("Created new map")); UpdateTitle(); RefreshPalettes(); root->UpdateMenubar(); root->Refresh(); return true; }
void GUI::SetCurrentZoom(double zoom) { MapTab* tab = GetCurrentMapTab(); if(tab) tab->GetCanvas()->SetZoom(zoom); }
void GUI::AddPendingCanvasEvent(wxEvent& event) { MapTab* mapTab = GetCurrentMapTab(); if(mapTab) mapTab->GetCanvas()->GetEventHandler()->AddPendingEvent(event); }
void GUI::SetScreenCenterPosition(Position position) { MapTab* mapTab = GetCurrentMapTab(); if(mapTab) mapTab->SetScreenCenterPosition(position); }
void GUI::DoPaste() { MapTab* mapTab = GetCurrentMapTab(); if(mapTab) copybuffer.paste(*mapTab->GetEditor(), mapTab->GetCanvas()->GetCursorPosition()); }
int GUI::GetCurrentFloor() { MapTab* tab = GetCurrentMapTab(); ASSERT(tab); return tab->GetCanvas()->GetFloor(); }