diff options
Diffstat (limited to 'tools/mapedit/src/frame.cpp')
| -rw-r--r-- | tools/mapedit/src/frame.cpp | 129 |
1 files changed, 115 insertions, 14 deletions
| 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 | |||
| 47 | SetMenuBar(menuBar); | 47 | SetMenuBar(menuBar); |
| 48 | 48 | ||
| 49 | // Layout 1: Splitter between map tree and layout 2 | 49 | // Layout 1: Splitter between map tree and layout 2 |
| 50 | // Layout 2: Non-splitter between layout 3 and tile chooser | 50 | // Layout 2: Non-splitter between layout 3 and notebook |
| 51 | // Layout 3: Splitter between map editor and properties editor | 51 | // Layout 3: Splitter between map editor and properties editor |
| 52 | 52 | ||
| 53 | wxSplitterWindow* layout3 = new wxSplitterWindow(this, wxID_ANY); | 53 | wxSplitterWindow* layout3 = new wxSplitterWindow(this, wxID_ANY); |
| 54 | layout3->SetSashGravity(1.0); | 54 | layout3->SetSashGravity(1.0); |
| 55 | layout3->SetMinimumPaneSize(20); | 55 | layout3->SetMinimumPaneSize(20); |
| 56 | 56 | ||
| 57 | tileEditor = new TileWidget(this, wxID_ANY, 6, 6, wxPoint(0,0), wxSize(TILE_WIDTH*6*7,TILE_HEIGHT*10*6)); | 57 | notebook = new wxNotebook(this, wxID_ANY); |
| 58 | |||
| 59 | tileEditor = new TileWidget(notebook, wxID_ANY, 6, 6, wxPoint(0,0), wxSize(TILE_WIDTH*6*6,TILE_HEIGHT*10*6)); | ||
| 60 | notebook->AddPage(tileEditor, "Tile Chooser", true); | ||
| 61 | |||
| 58 | mapEditor = new MapeditWidget(layout3, wxID_ANY, &this->map, tileEditor, wxPoint(0,0), wxSize(GAME_WIDTH*2, GAME_HEIGHT*2)); | 62 | mapEditor = new MapeditWidget(layout3, wxID_ANY, &this->map, tileEditor, wxPoint(0,0), wxSize(GAME_WIDTH*2, GAME_HEIGHT*2)); |
| 63 | mapEditor->frame = this; | ||
| 59 | 64 | ||
| 65 | // Set up property editor | ||
| 60 | wxPanel* propertyEditor = new wxPanel(layout3, wxID_ANY); | 66 | wxPanel* propertyEditor = new wxPanel(layout3, wxID_ANY); |
| 61 | titleBox = new wxTextCtrl(propertyEditor, wxID_ANY, map.getTitle()); | 67 | titleBox = new wxTextCtrl(propertyEditor, wxID_ANY, map.getTitle()); |
| 62 | titleBox->Bind(wxEVT_TEXT, &MapeditFrame::OnTitleChange, this); | 68 | titleBox->Bind(wxEVT_TEXT, &MapeditFrame::OnTitleChange, this); |
| 63 | 69 | ||
| 64 | wxStaticText* titleLabel = new wxStaticText(propertyEditor, wxID_ANY, "Title:"); | 70 | wxStaticText* titleLabel = new wxStaticText(propertyEditor, wxID_ANY, "Title:"); |
| 65 | 71 | ||
| 66 | wxFlexGridSizer* propertySizer = new wxFlexGridSizer(1, 2, 9, 25); | 72 | wxBoxSizer* propertySizer = new wxBoxSizer(wxVERTICAL); |
| 67 | propertySizer->Add(titleLabel); | 73 | wxBoxSizer* propertySizer1 = new wxBoxSizer(wxHORIZONTAL); |
| 68 | propertySizer->Add(titleBox, 1, wxEXPAND); | 74 | propertySizer1->Add(titleLabel, 0, wxALIGN_RIGHT | wxLEFT, 10); |
| 75 | propertySizer1->Add(titleBox, 1, wxALIGN_LEFT | wxLEFT | wxRIGHT, 10); | ||
| 76 | propertySizer->Add(propertySizer1, 1, wxEXPAND | wxTOP, 10); | ||
| 69 | propertyEditor->SetSizer(propertySizer); | 77 | propertyEditor->SetSizer(propertySizer); |
| 70 | propertySizer->SetSizeHints(propertyEditor); | 78 | propertySizer->SetSizeHints(propertyEditor); |
| 71 | 79 | ||
| 80 | // Set up entity editor | ||
| 81 | wxPanel* entityEditor = new wxPanel(notebook, wxID_ANY); | ||
| 82 | notebook->AddPage(entityEditor, "Entity Manager", false); | ||
| 83 | |||
| 84 | wxStaticText* entityHeader = new wxStaticText(entityEditor, wxID_ANY, "Add Entity"); | ||
| 85 | wxFont font = entityHeader->GetFont(); | ||
| 86 | font.SetWeight(wxFONTWEIGHT_BOLD); | ||
| 87 | entityHeader->SetFont(font); | ||
| 88 | |||
| 89 | wxStaticText* entityTypeLabel = new wxStaticText(entityEditor, wxID_ANY, "Entity Type:"); | ||
| 90 | |||
| 91 | entityTypeBox = new wxChoice(entityEditor, wxID_ANY); | ||
| 92 | for (auto entry : MapObject::getAllObjects()) | ||
| 93 | { | ||
| 94 | entityTypeBox->Append(entry.second->getType(), entry.second.get()); | ||
| 95 | } | ||
| 96 | |||
| 97 | addEntityButton = new wxButton(entityEditor, wxID_ANY, "Add Entity"); | ||
| 98 | addEntityButton->Bind(wxEVT_BUTTON, &MapeditFrame::OnAddEntity, this); | ||
| 99 | |||
| 100 | cancelEntityButton = new wxButton(entityEditor, wxID_ANY, "Cancel"); | ||
| 101 | cancelEntityButton->Disable(); | ||
| 102 | cancelEntityButton->Bind(wxEVT_BUTTON, &MapeditFrame::OnCancelAddEntity, this); | ||
| 103 | |||
| 104 | wxBoxSizer* entitySizer = new wxBoxSizer(wxVERTICAL); | ||
| 105 | entitySizer->Add(entityHeader, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5); | ||
| 106 | wxBoxSizer* entitySizer1 = new wxBoxSizer(wxHORIZONTAL); | ||
| 107 | entitySizer1->Add(entityTypeLabel, 0, wxALIGN_LEFT | wxRIGHT, 5); | ||
| 108 | entitySizer1->Add(entityTypeBox, 1, wxALIGN_LEFT, 0); | ||
| 109 | entitySizer->Add(entitySizer1, 0, wxEXPAND | wxALIGN_CENTER_HORIZONTAL | wxALL, 5); | ||
| 110 | wxBoxSizer* entitySizer2 = new wxBoxSizer(wxHORIZONTAL); | ||
| 111 | entitySizer2->Add(addEntityButton, 1, wxEXPAND | wxRIGHT, 2); | ||
| 112 | entitySizer2->Add(cancelEntityButton, 1, wxEXPAND | wxLEFT, 2); | ||
| 113 | entitySizer->Add(entitySizer2, 0, wxEXPAND | wxALIGN_CENTER_HORIZONTAL | wxALL, 5); | ||
| 114 | entityEditor->SetSizer(entitySizer); | ||
| 115 | entitySizer->SetSizeHints(entityEditor); | ||
| 116 | |||
| 117 | // Finish setting up the layouts | ||
| 72 | layout3->SplitHorizontally(mapEditor, propertyEditor); | 118 | layout3->SplitHorizontally(mapEditor, propertyEditor); |
| 73 | 119 | ||
| 120 | notebook->Bind(wxEVT_NOTEBOOK_PAGE_CHANGED, &MapeditFrame::OnTabChange, this); | ||
| 121 | notebook->Bind(wxEVT_NOTEBOOK_PAGE_CHANGING, &MapeditFrame::OnTabChanging, this); | ||
| 122 | |||
| 74 | wxBoxSizer* sizer2 = new wxBoxSizer(wxHORIZONTAL); | 123 | wxBoxSizer* sizer2 = new wxBoxSizer(wxHORIZONTAL); |
| 75 | sizer2->Add(layout3, 1, wxEXPAND, 0); | 124 | sizer2->Add(layout3, 1, wxEXPAND, 0); |
| 76 | sizer2->Add(tileEditor, 0, wxALIGN_TOP | wxALIGN_CENTER_HORIZONTAL | wxLEFT, 2); | 125 | sizer2->Add(notebook, 0, wxALIGN_TOP | wxALIGN_CENTER_HORIZONTAL | wxLEFT, 2); |
| 77 | this->SetSizer(sizer2); | 126 | this->SetSizer(sizer2); |
| 78 | sizer2->SetSizeHints(this); | 127 | sizer2->SetSizeHints(this); |
| 79 | } | 128 | } |
| @@ -115,22 +164,22 @@ MapeditWidget* MapeditFrame::GetMapEditor() | |||
| 115 | return mapEditor; | 164 | return mapEditor; |
| 116 | } | 165 | } |
| 117 | 166 | ||
| 118 | void MapeditFrame::ZoomIn(wxCommandEvent& event) | 167 | void MapeditFrame::ZoomIn(wxCommandEvent&) |
| 119 | { | 168 | { |
| 120 | mapEditor->ZoomIn(); | 169 | mapEditor->ZoomIn(); |
| 121 | } | 170 | } |
| 122 | 171 | ||
| 123 | void MapeditFrame::ZoomOut(wxCommandEvent& event) | 172 | void MapeditFrame::ZoomOut(wxCommandEvent&) |
| 124 | { | 173 | { |
| 125 | mapEditor->ZoomOut(); | 174 | mapEditor->ZoomOut(); |
| 126 | } | 175 | } |
| 127 | 176 | ||
| 128 | void MapeditFrame::OnNew(wxCommandEvent& event) | 177 | void MapeditFrame::OnNew(wxCommandEvent&) |
| 129 | { | 178 | { |
| 130 | NewMap(); | 179 | NewMap(); |
| 131 | } | 180 | } |
| 132 | 181 | ||
| 133 | void MapeditFrame::OnOpen(wxCommandEvent& event) | 182 | void MapeditFrame::OnOpen(wxCommandEvent&) |
| 134 | { | 183 | { |
| 135 | wxFileDialog openFileDialog(this, "Open map", "", "", "XML files (*.xml)|*.xml", wxFD_OPEN|wxFD_FILE_MUST_EXIST); | 184 | wxFileDialog openFileDialog(this, "Open map", "", "", "XML files (*.xml)|*.xml", wxFD_OPEN|wxFD_FILE_MUST_EXIST); |
| 136 | if (openFileDialog.ShowModal() == wxID_CANCEL) | 185 | if (openFileDialog.ShowModal() == wxID_CANCEL) |
| @@ -141,7 +190,7 @@ void MapeditFrame::OnOpen(wxCommandEvent& event) | |||
| 141 | OpenMap(openFileDialog.GetPath().c_str()); | 190 | OpenMap(openFileDialog.GetPath().c_str()); |
| 142 | } | 191 | } |
| 143 | 192 | ||
| 144 | void MapeditFrame::OnSave(wxCommandEvent& event) | 193 | void MapeditFrame::OnSave(wxCommandEvent&) |
| 145 | { | 194 | { |
| 146 | if (filename == "") | 195 | if (filename == "") |
| 147 | { | 196 | { |
| @@ -157,12 +206,12 @@ void MapeditFrame::OnSave(wxCommandEvent& event) | |||
| 157 | map.save(filename); | 206 | map.save(filename); |
| 158 | } | 207 | } |
| 159 | 208 | ||
| 160 | void MapeditFrame::OnClose(wxCommandEvent& event) | 209 | void MapeditFrame::OnClose(wxCommandEvent&) |
| 161 | { | 210 | { |
| 162 | Close(false); | 211 | Close(false); |
| 163 | } | 212 | } |
| 164 | 213 | ||
| 165 | void MapeditFrame::OnQuit(wxCommandEvent& event) | 214 | void MapeditFrame::OnQuit(wxCommandEvent&) |
| 166 | { | 215 | { |
| 167 | for (auto window : openWindows) | 216 | for (auto window : openWindows) |
| 168 | { | 217 | { |
| @@ -173,7 +222,7 @@ void MapeditFrame::OnQuit(wxCommandEvent& event) | |||
| 173 | } | 222 | } |
| 174 | } | 223 | } |
| 175 | 224 | ||
| 176 | void MapeditFrame::OnTitleChange(wxCommandEvent& event) | 225 | void MapeditFrame::OnTitleChange(wxCommandEvent&) |
| 177 | { | 226 | { |
| 178 | map.setTitle(titleBox->GetLineText(0).ToStdString()); | 227 | map.setTitle(titleBox->GetLineText(0).ToStdString()); |
| 179 | } | 228 | } |
| @@ -194,3 +243,55 @@ void MapeditFrame::LaunchWindow(Map map, const char* filename) | |||
| 194 | frame->closer = openWindows.insert(end(openWindows), frame); | 243 | frame->closer = openWindows.insert(end(openWindows), frame); |
| 195 | frame->Show(true); | 244 | frame->Show(true); |
| 196 | } | 245 | } |
| 246 | |||
| 247 | void MapeditFrame::OnTabChange(wxBookCtrlEvent& event) | ||
| 248 | { | ||
| 249 | switch (event.GetSelection()) | ||
| 250 | { | ||
| 251 | case 0: | ||
| 252 | mapEditor->SetEditMode(EditTiles); | ||
| 253 | break; | ||
| 254 | |||
| 255 | case 1: | ||
| 256 | mapEditor->SetEditMode(EditEntities); | ||
| 257 | break; | ||
| 258 | } | ||
| 259 | |||
| 260 | event.Skip(); | ||
| 261 | } | ||
| 262 | |||
| 263 | void MapeditFrame::OnTabChanging(wxBookCtrlEvent& event) | ||
| 264 | { | ||
| 265 | if (addingEntity) | ||
| 266 | { | ||
| 267 | event.Veto(); | ||
| 268 | return; | ||
| 269 | } | ||
| 270 | |||
| 271 | event.Skip(); | ||
| 272 | } | ||
| 273 | |||
| 274 | void MapeditFrame::OnAddEntity(wxCommandEvent&) | ||
| 275 | { | ||
| 276 | addingEntity = true; | ||
| 277 | addEntityButton->Disable(); | ||
| 278 | cancelEntityButton->Enable(); | ||
| 279 | |||
| 280 | mapEditor->StartAddingEntity((MapObject*) entityTypeBox->GetClientData(entityTypeBox->GetSelection())); | ||
| 281 | } | ||
| 282 | |||
| 283 | void MapeditFrame::OnCancelAddEntity(wxCommandEvent&) | ||
| 284 | { | ||
| 285 | addingEntity = false; | ||
| 286 | addEntityButton->Enable(); | ||
| 287 | cancelEntityButton->Disable(); | ||
| 288 | |||
| 289 | mapEditor->CancelAddingEntity(); | ||
| 290 | } | ||
| 291 | |||
| 292 | void MapeditFrame::FinishAddingEntity() | ||
| 293 | { | ||
| 294 | addingEntity = false; | ||
| 295 | addEntityButton->Enable(); | ||
| 296 | cancelEntityButton->Disable(); | ||
| 297 | } | ||
