From 213cab3c04b81428ab715f340bd7c12438fdb980 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 15 Mar 2015 23:24:22 -0400 Subject: Map editor can now add entities to maps Also fixed a big bug regarding scrolling --- tools/mapedit/src/frame.cpp | 129 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 115 insertions(+), 14 deletions(-) (limited to 'tools/mapedit/src/frame.cpp') diff --git a/tools/mapedit/src/frame.cpp b/tools/mapedit/src/frame.cpp index e0df030..aa77f1f 100644 --- a/tools/mapedit/src/frame.cpp +++ b/tools/mapedit/src/frame.cpp @@ -47,33 +47,82 @@ MapeditFrame::MapeditFrame(Map map, std::string filename) : wxFrame(NULL, wxID_A SetMenuBar(menuBar); // Layout 1: Splitter between map tree and layout 2 - // Layout 2: Non-splitter between layout 3 and tile chooser + // Layout 2: Non-splitter between layout 3 and notebook // Layout 3: Splitter between map editor and properties editor wxSplitterWindow* layout3 = new wxSplitterWindow(this, wxID_ANY); layout3->SetSashGravity(1.0); layout3->SetMinimumPaneSize(20); - tileEditor = new TileWidget(this, wxID_ANY, 6, 6, wxPoint(0,0), wxSize(TILE_WIDTH*6*7,TILE_HEIGHT*10*6)); + notebook = new wxNotebook(this, wxID_ANY); + + tileEditor = new TileWidget(notebook, wxID_ANY, 6, 6, wxPoint(0,0), wxSize(TILE_WIDTH*6*6,TILE_HEIGHT*10*6)); + notebook->AddPage(tileEditor, "Tile Chooser", true); + mapEditor = new MapeditWidget(layout3, wxID_ANY, &this->map, tileEditor, wxPoint(0,0), wxSize(GAME_WIDTH*2, GAME_HEIGHT*2)); + mapEditor->frame = this; + // Set up property editor wxPanel* propertyEditor = new wxPanel(layout3, wxID_ANY); titleBox = new wxTextCtrl(propertyEditor, wxID_ANY, map.getTitle()); titleBox->Bind(wxEVT_TEXT, &MapeditFrame::OnTitleChange, this); wxStaticText* titleLabel = new wxStaticText(propertyEditor, wxID_ANY, "Title:"); - wxFlexGridSizer* propertySizer = new wxFlexGridSizer(1, 2, 9, 25); - propertySizer->Add(titleLabel); - propertySizer->Add(titleBox, 1, wxEXPAND); + wxBoxSizer* propertySizer = new wxBoxSizer(wxVERTICAL); + wxBoxSizer* propertySizer1 = new wxBoxSizer(wxHORIZONTAL); + propertySizer1->Add(titleLabel, 0, wxALIGN_RIGHT | wxLEFT, 10); + propertySizer1->Add(titleBox, 1, wxALIGN_LEFT | wxLEFT | wxRIGHT, 10); + propertySizer->Add(propertySizer1, 1, wxEXPAND | wxTOP, 10); propertyEditor->SetSizer(propertySizer); propertySizer->SetSizeHints(propertyEditor); + // Set up entity editor + wxPanel* entityEditor = new wxPanel(notebook, wxID_ANY); + notebook->AddPage(entityEditor, "Entity Manager", false); + + wxStaticText* entityHeader = new wxStaticText(entityEditor, wxID_ANY, "Add Entity"); + wxFont font = entityHeader->GetFont(); + font.SetWeight(wxFONTWEIGHT_BOLD); + entityHeader->SetFont(font); + + wxStaticText* entityTypeLabel = new wxStaticText(entityEditor, wxID_ANY, "Entity Type:"); + + entityTypeBox = new wxChoice(entityEditor, wxID_ANY); + for (auto entry : MapObject::getAllObjects()) + { + entityTypeBox->Append(entry.second->getType(), entry.second.get()); + } + + addEntityButton = new wxButton(entityEditor, wxID_ANY, "Add Entity"); + addEntityButton->Bind(wxEVT_BUTTON, &MapeditFrame::OnAddEntity, this); + + cancelEntityButton = new wxButton(entityEditor, wxID_ANY, "Cancel"); + cancelEntityButton->Disable(); + cancelEntityButton->Bind(wxEVT_BUTTON, &MapeditFrame::OnCancelAddEntity, this); + + wxBoxSizer* entitySizer = new wxBoxSizer(wxVERTICAL); + entitySizer->Add(entityHeader, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5); + wxBoxSizer* entitySizer1 = new wxBoxSizer(wxHORIZONTAL); + entitySizer1->Add(entityTypeLabel, 0, wxALIGN_LEFT | wxRIGHT, 5); + entitySizer1->Add(entityTypeBox, 1, wxALIGN_LEFT, 0); + entitySizer->Add(entitySizer1, 0, wxEXPAND | wxALIGN_CENTER_HORIZONTAL | wxALL, 5); + wxBoxSizer* entitySizer2 = new wxBoxSizer(wxHORIZONTAL); + entitySizer2->Add(addEntityButton, 1, wxEXPAND | wxRIGHT, 2); + entitySizer2->Add(cancelEntityButton, 1, wxEXPAND | wxLEFT, 2); + entitySizer->Add(entitySizer2, 0, wxEXPAND | wxALIGN_CENTER_HORIZONTAL | wxALL, 5); + entityEditor->SetSizer(entitySizer); + entitySizer->SetSizeHints(entityEditor); + + // Finish setting up the layouts layout3->SplitHorizontally(mapEditor, propertyEditor); + notebook->Bind(wxEVT_NOTEBOOK_PAGE_CHANGED, &MapeditFrame::OnTabChange, this); + notebook->Bind(wxEVT_NOTEBOOK_PAGE_CHANGING, &MapeditFrame::OnTabChanging, this); + wxBoxSizer* sizer2 = new wxBoxSizer(wxHORIZONTAL); sizer2->Add(layout3, 1, wxEXPAND, 0); - sizer2->Add(tileEditor, 0, wxALIGN_TOP | wxALIGN_CENTER_HORIZONTAL | wxLEFT, 2); + sizer2->Add(notebook, 0, wxALIGN_TOP | wxALIGN_CENTER_HORIZONTAL | wxLEFT, 2); this->SetSizer(sizer2); sizer2->SetSizeHints(this); } @@ -115,22 +164,22 @@ MapeditWidget* MapeditFrame::GetMapEditor() return mapEditor; } -void MapeditFrame::ZoomIn(wxCommandEvent& event) +void MapeditFrame::ZoomIn(wxCommandEvent&) { mapEditor->ZoomIn(); } -void MapeditFrame::ZoomOut(wxCommandEvent& event) +void MapeditFrame::ZoomOut(wxCommandEvent&) { mapEditor->ZoomOut(); } -void MapeditFrame::OnNew(wxCommandEvent& event) +void MapeditFrame::OnNew(wxCommandEvent&) { NewMap(); } -void MapeditFrame::OnOpen(wxCommandEvent& event) +void MapeditFrame::OnOpen(wxCommandEvent&) { wxFileDialog openFileDialog(this, "Open map", "", "", "XML files (*.xml)|*.xml", wxFD_OPEN|wxFD_FILE_MUST_EXIST); if (openFileDialog.ShowModal() == wxID_CANCEL) @@ -141,7 +190,7 @@ void MapeditFrame::OnOpen(wxCommandEvent& event) OpenMap(openFileDialog.GetPath().c_str()); } -void MapeditFrame::OnSave(wxCommandEvent& event) +void MapeditFrame::OnSave(wxCommandEvent&) { if (filename == "") { @@ -157,12 +206,12 @@ void MapeditFrame::OnSave(wxCommandEvent& event) map.save(filename); } -void MapeditFrame::OnClose(wxCommandEvent& event) +void MapeditFrame::OnClose(wxCommandEvent&) { Close(false); } -void MapeditFrame::OnQuit(wxCommandEvent& event) +void MapeditFrame::OnQuit(wxCommandEvent&) { for (auto window : openWindows) { @@ -173,7 +222,7 @@ void MapeditFrame::OnQuit(wxCommandEvent& event) } } -void MapeditFrame::OnTitleChange(wxCommandEvent& event) +void MapeditFrame::OnTitleChange(wxCommandEvent&) { map.setTitle(titleBox->GetLineText(0).ToStdString()); } @@ -194,3 +243,55 @@ void MapeditFrame::LaunchWindow(Map map, const char* filename) frame->closer = openWindows.insert(end(openWindows), frame); frame->Show(true); } + +void MapeditFrame::OnTabChange(wxBookCtrlEvent& event) +{ + switch (event.GetSelection()) + { + case 0: + mapEditor->SetEditMode(EditTiles); + break; + + case 1: + mapEditor->SetEditMode(EditEntities); + break; + } + + event.Skip(); +} + +void MapeditFrame::OnTabChanging(wxBookCtrlEvent& event) +{ + if (addingEntity) + { + event.Veto(); + return; + } + + event.Skip(); +} + +void MapeditFrame::OnAddEntity(wxCommandEvent&) +{ + addingEntity = true; + addEntityButton->Disable(); + cancelEntityButton->Enable(); + + mapEditor->StartAddingEntity((MapObject*) entityTypeBox->GetClientData(entityTypeBox->GetSelection())); +} + +void MapeditFrame::OnCancelAddEntity(wxCommandEvent&) +{ + addingEntity = false; + addEntityButton->Enable(); + cancelEntityButton->Disable(); + + mapEditor->CancelAddingEntity(); +} + +void MapeditFrame::FinishAddingEntity() +{ + addingEntity = false; + addEntityButton->Enable(); + cancelEntityButton->Disable(); +} -- cgit 1.4.1