From c125c1acc0b20c3e405dddb5c835d9734aa0472c Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 15 Mar 2015 19:08:46 -0400 Subject: Added ability to edit title in map editor --- tools/mapedit/src/frame.cpp | 49 +++++++++++++++++++++++++-------------- tools/mapedit/src/frame.h | 2 ++ tools/mapedit/src/map.cpp | 14 ++++++++--- tools/mapedit/src/map.h | 2 ++ tools/mapedit/src/tile_widget.cpp | 6 ++--- tools/mapedit/src/tile_widget.h | 2 +- 6 files changed, 50 insertions(+), 25 deletions(-) (limited to 'tools') diff --git a/tools/mapedit/src/frame.cpp b/tools/mapedit/src/frame.cpp index 3cd1c15..b3808e2 100644 --- a/tools/mapedit/src/frame.cpp +++ b/tools/mapedit/src/frame.cpp @@ -43,28 +43,36 @@ MapeditFrame::MapeditFrame(Map map, std::string filename) : wxFrame(NULL, wxID_A SetMenuBar(menuBar); - wxBoxSizer* sizermain = new wxBoxSizer(wxVERTICAL); - wxSplitterWindow* splitter = new wxSplitterWindow(this, wxID_ANY); - splitter->SetSashGravity(0.0); - splitter->SetMinimumPaneSize(50); - sizermain->Add(splitter, 1, wxEXPAND, 0); + // Layout 1: Splitter between map tree and layout 2 + // Layout 2: Non-splitter between layout 3 and tile chooser + // Layout 3: Splitter between map editor and properties editor - wxPanel* tileEditorPanel = new wxPanel(splitter, wxID_ANY); - tileEditor = new TileWidget(tileEditorPanel, wxID_ANY, 6, 6, wxPoint(0,0)); - wxBoxSizer* tileSizer = new wxBoxSizer(wxVERTICAL); - tileSizer->Add(tileEditor, 1, wxEXPAND, 0); - tileEditorPanel->SetSizer(tileSizer); + wxSplitterWindow* layout3 = new wxSplitterWindow(this, wxID_ANY); + layout3->SetSashGravity(1.0); + layout3->SetMinimumPaneSize(20); - wxPanel* mapEditorPanel = new wxPanel(splitter, wxID_ANY); - mapEditor = new MapeditWidget(mapEditorPanel, wxID_ANY, &this->map, tileEditor, wxPoint(0,0)); - wxBoxSizer* mapSizer = new wxBoxSizer(wxVERTICAL); - mapSizer->Add(mapEditor, 1, wxEXPAND, 0); - mapEditorPanel->SetSizer(mapSizer); + tileEditor = new TileWidget(this, wxID_ANY, 6, 6, wxPoint(0,0), wxSize(TILE_WIDTH*6*7,TILE_HEIGHT*10*6)); + mapEditor = new MapeditWidget(layout3, wxID_ANY, &this->map, tileEditor, wxPoint(0,0), wxSize(GAME_WIDTH*2, GAME_HEIGHT*2)); - splitter->SplitVertically(tileEditorPanel, mapEditorPanel); + wxPanel* propertyEditor = new wxPanel(layout3, wxID_ANY); + titleBox = new wxTextCtrl(propertyEditor, wxID_ANY, map.getTitle()); + titleBox->Bind(wxEVT_TEXT, &MapeditFrame::OnTitleChange, this); - this->SetSizer(sizermain); - sizermain->SetSizeHints(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); + propertyEditor->SetSizer(propertySizer); + propertySizer->SetSizeHints(propertyEditor); + + layout3->SplitHorizontally(mapEditor, propertyEditor); + + wxBoxSizer* sizer2 = new wxBoxSizer(wxHORIZONTAL); + sizer2->Add(layout3, 1, wxEXPAND, 0); + sizer2->Add(tileEditor, 0, wxALIGN_TOP | wxALIGN_CENTER_HORIZONTAL | wxLEFT, 2); + this->SetSizer(sizer2); + sizer2->SetSizeHints(this); } void MapeditFrame::OnExit(wxCloseEvent& event) @@ -156,3 +164,8 @@ void MapeditFrame::OnQuit(wxCommandEvent& event) { // TODO } + +void MapeditFrame::OnTitleChange(wxCommandEvent& event) +{ + map.setTitle(titleBox->GetLineText(0).ToStdString()); +} diff --git a/tools/mapedit/src/frame.h b/tools/mapedit/src/frame.h index 53d8998..11990b1 100644 --- a/tools/mapedit/src/frame.h +++ b/tools/mapedit/src/frame.h @@ -27,10 +27,12 @@ class MapeditFrame : public wxFrame { void OnClose(wxCommandEvent& event); void OnExit(wxCloseEvent& event); void OnQuit(wxCommandEvent& event); + void OnTitleChange(wxCommandEvent& event); Map map; MapeditWidget* mapEditor; TileWidget* tileEditor; + wxTextCtrl* titleBox; std::string filename; wxDECLARE_EVENT_TABLE(); diff --git a/tools/mapedit/src/map.cpp b/tools/mapedit/src/map.cpp index 7976419..3a24ace 100644 --- a/tools/mapedit/src/map.cpp +++ b/tools/mapedit/src/map.cpp @@ -6,7 +6,6 @@ Map::Map() { mapdata = (int*) calloc(MAP_WIDTH * MAP_HEIGHT, sizeof(int)); - dirty = true; } Map::Map(std::string filename) @@ -59,8 +58,6 @@ Map::Map(std::string filename) } xmlFreeDoc(doc); - - dirty = false; } Map::Map(const Map& map) @@ -172,3 +169,14 @@ int Map::getTileAt(int x, int y) const { return mapdata[x+y*MAP_WIDTH]; } + +std::string Map::getTitle() const +{ + return title; +} + +void Map::setTitle(std::string title) +{ + dirty = true; + this->title = title; +} diff --git a/tools/mapedit/src/map.h b/tools/mapedit/src/map.h index 66e4596..45ec7e1 100644 --- a/tools/mapedit/src/map.h +++ b/tools/mapedit/src/map.h @@ -49,6 +49,8 @@ class Map { Map& operator= (Map other); friend void swap(Map& first, Map& second); + std::string getTitle() const; + void setTitle(std::string title); void save(std::string name); bool hasUnsavedChanges() const; void setTileAt(int x, int y, int tile); diff --git a/tools/mapedit/src/tile_widget.cpp b/tools/mapedit/src/tile_widget.cpp index 3dccecb..3b00e59 100644 --- a/tools/mapedit/src/tile_widget.cpp +++ b/tools/mapedit/src/tile_widget.cpp @@ -1,9 +1,9 @@ #include "tile_widget.h" #include "map.h" -IMPLEMENT_DYNAMIC_CLASS(TileWidget,wxScrolledWindow) +IMPLEMENT_DYNAMIC_CLASS(TileWidget,wxScrolledCanvas) -BEGIN_EVENT_TABLE(TileWidget, wxScrolledWindow) +BEGIN_EVENT_TABLE(TileWidget, wxScrolledCanvas) EVT_PAINT(TileWidget::OnPaint) EVT_LEFT_DOWN(TileWidget::OnClick) END_EVENT_TABLE() @@ -14,7 +14,7 @@ TileWidget::TileWidget() } TileWidget::TileWidget(wxWindow* parent, wxWindowID winid, int width, int scale, const wxPoint& pos, const wxSize& size) - : wxScrolledWindow(parent, winid, pos, size), numTilesWidth(width), scale(scale) + : wxScrolledCanvas(parent, winid, pos, size), numTilesWidth(width), scale(scale) { Init(); } diff --git a/tools/mapedit/src/tile_widget.h b/tools/mapedit/src/tile_widget.h index f4bbc07..2f1872d 100644 --- a/tools/mapedit/src/tile_widget.h +++ b/tools/mapedit/src/tile_widget.h @@ -9,7 +9,7 @@ #include "map.h" -class TileWidget : public wxScrolledWindow { +class TileWidget : public wxScrolledCanvas { public: TileWidget(); TileWidget(wxWindow* parent, wxWindowID winid, int width, int scale, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize); -- cgit 1.4.1