diff options
Diffstat (limited to 'tools/mapedit')
-rw-r--r-- | tools/mapedit/CMakeLists.txt | 3 | ||||
-rw-r--r-- | tools/mapedit/src/frame.cpp | 30 | ||||
-rw-r--r-- | tools/mapedit/src/frame.h | 25 | ||||
-rw-r--r-- | tools/mapedit/src/main.cpp | 36 | ||||
-rw-r--r-- | tools/mapedit/src/tile_widget.cpp | 76 | ||||
-rw-r--r-- | tools/mapedit/src/tile_widget.h | 32 | ||||
-rw-r--r-- | tools/mapedit/src/widget.cpp | 91 | ||||
-rw-r--r-- | tools/mapedit/src/widget.h | 38 |
8 files changed, 298 insertions, 33 deletions
diff --git a/tools/mapedit/CMakeLists.txt b/tools/mapedit/CMakeLists.txt index 9a024c8..ffc9f05 100644 --- a/tools/mapedit/CMakeLists.txt +++ b/tools/mapedit/CMakeLists.txt | |||
@@ -40,6 +40,9 @@ set(CMAKE_BUILD_TYPE Debug) | |||
40 | add_executable(AromatherapyMapEditor | 40 | add_executable(AromatherapyMapEditor |
41 | src/main.cpp | 41 | src/main.cpp |
42 | src/map.cpp | 42 | src/map.cpp |
43 | src/frame.cpp | ||
44 | src/widget.cpp | ||
45 | src/tile_widget.cpp | ||
43 | ) | 46 | ) |
44 | target_link_libraries(AromatherapyMapEditor ${ALL_LIBS}) | 47 | target_link_libraries(AromatherapyMapEditor ${ALL_LIBS}) |
45 | install(TARGETS AromatherapyMapEditor RUNTIME DESTINATION ${BIN_DIR}) | 48 | install(TARGETS AromatherapyMapEditor RUNTIME DESTINATION ${BIN_DIR}) |
diff --git a/tools/mapedit/src/frame.cpp b/tools/mapedit/src/frame.cpp new file mode 100644 index 0000000..858620e --- /dev/null +++ b/tools/mapedit/src/frame.cpp | |||
@@ -0,0 +1,30 @@ | |||
1 | #include "frame.h" | ||
2 | #include "widget.h" | ||
3 | #include "tile_widget.h" | ||
4 | |||
5 | wxBEGIN_EVENT_TABLE(MapeditFrame, wxFrame) | ||
6 | EVT_MENU(wxID_EXIT, MapeditFrame::OnExit) | ||
7 | wxEND_EVENT_TABLE() | ||
8 | |||
9 | MapeditFrame::MapeditFrame(Map map) : wxFrame(NULL, wxID_ANY, "Map Editor", wxPoint(50, 50), wxSize(GAME_WIDTH*3, GAME_HEIGHT*2)), map(map) | ||
10 | { | ||
11 | wxMenu* menuFile = new wxMenu; | ||
12 | menuFile->Append(wxID_EXIT); | ||
13 | |||
14 | wxMenuBar* menuBar = new wxMenuBar; | ||
15 | menuBar->Append(menuFile, "&File"); | ||
16 | |||
17 | SetMenuBar(menuBar); | ||
18 | |||
19 | wxPanel* panel = new wxPanel(this, wxID_ANY); | ||
20 | int clientWidth, clientHeight; | ||
21 | GetClientSize(&clientWidth, &clientHeight); | ||
22 | |||
23 | TileWidget* tileEdit = new TileWidget(panel, wxID_ANY, 6, wxPoint(0,0), wxSize(TILE_WIDTH*3*6, clientHeight)); | ||
24 | MapeditWidget* wid = new MapeditWidget(panel, wxID_ANY, &this->map, tileEdit, wxPoint(TILE_WIDTH*3*6+8,0), wxSize(GAME_WIDTH*1.5, GAME_HEIGHT*1.5)); | ||
25 | } | ||
26 | |||
27 | void MapeditFrame::OnExit(wxCommandEvent& event) | ||
28 | { | ||
29 | Close(true); | ||
30 | } | ||
diff --git a/tools/mapedit/src/frame.h b/tools/mapedit/src/frame.h new file mode 100644 index 0000000..e5d8562 --- /dev/null +++ b/tools/mapedit/src/frame.h | |||
@@ -0,0 +1,25 @@ | |||
1 | #ifndef FRAME_H | ||
2 | #define FRAME_H | ||
3 | |||
4 | #include <wx/wxprec.h> | ||
5 | |||
6 | #ifndef WX_PRECOMP | ||
7 | #include <wx/wx.h> | ||
8 | #endif | ||
9 | |||
10 | #include "map.h" | ||
11 | |||
12 | class MapeditFrame : public wxFrame { | ||
13 | public: | ||
14 | MapeditFrame() : MapeditFrame(Map()) {} | ||
15 | MapeditFrame(Map map); | ||
16 | |||
17 | private: | ||
18 | void OnExit(wxCommandEvent& event); | ||
19 | |||
20 | Map map; | ||
21 | |||
22 | wxDECLARE_EVENT_TABLE(); | ||
23 | }; | ||
24 | |||
25 | #endif | ||
diff --git a/tools/mapedit/src/main.cpp b/tools/mapedit/src/main.cpp index 09be151..28fa010 100644 --- a/tools/mapedit/src/main.cpp +++ b/tools/mapedit/src/main.cpp | |||
@@ -5,50 +5,20 @@ | |||
5 | #endif | 5 | #endif |
6 | 6 | ||
7 | #include "map.h" | 7 | #include "map.h" |
8 | #include "frame.h" | ||
8 | 9 | ||
9 | class MapeditApp : public wxApp { | 10 | class MapeditApp : public wxApp { |
10 | public: | 11 | public: |
11 | virtual bool OnInit(); | 12 | virtual bool OnInit(); |
12 | }; | 13 | }; |
13 | 14 | ||
14 | class MapeditFrame : public wxFrame { | ||
15 | public: | ||
16 | MapeditFrame() : MapeditFrame(Map()) {} | ||
17 | MapeditFrame(Map map); | ||
18 | |||
19 | private: | ||
20 | void OnExit(wxCommandEvent& event); | ||
21 | |||
22 | Map map; | ||
23 | |||
24 | wxDECLARE_EVENT_TABLE(); | ||
25 | }; | ||
26 | |||
27 | wxBEGIN_EVENT_TABLE(MapeditFrame, wxFrame) | ||
28 | EVT_MENU(wxID_EXIT, MapeditFrame::OnExit) | ||
29 | wxEND_EVENT_TABLE() | ||
30 | |||
31 | wxIMPLEMENT_APP(MapeditApp); | 15 | wxIMPLEMENT_APP(MapeditApp); |
32 | 16 | ||
33 | bool MapeditApp::OnInit() | 17 | bool MapeditApp::OnInit() |
34 | { | 18 | { |
19 | wxInitAllImageHandlers(); | ||
20 | |||
35 | MapeditFrame* frame = new MapeditFrame(); | 21 | MapeditFrame* frame = new MapeditFrame(); |
36 | frame->Show(true); | 22 | frame->Show(true); |
37 | return true; | 23 | return true; |
38 | } | 24 | } |
39 | |||
40 | MapeditFrame::MapeditFrame(Map map) : wxFrame(NULL, wxID_ANY, "Map Editor", wxPoint(50, 50), wxSize(450, 340)), map(map) | ||
41 | { | ||
42 | wxMenu* menuFile = new wxMenu; | ||
43 | menuFile->Append(wxID_EXIT); | ||
44 | |||
45 | wxMenuBar* menuBar = new wxMenuBar; | ||
46 | menuBar->Append(menuFile, "&File"); | ||
47 | |||
48 | SetMenuBar(menuBar); | ||
49 | } | ||
50 | |||
51 | void MapeditFrame::OnExit(wxCommandEvent& event) | ||
52 | { | ||
53 | Close(true); | ||
54 | } | ||
diff --git a/tools/mapedit/src/tile_widget.cpp b/tools/mapedit/src/tile_widget.cpp new file mode 100644 index 0000000..423b7c0 --- /dev/null +++ b/tools/mapedit/src/tile_widget.cpp | |||
@@ -0,0 +1,76 @@ | |||
1 | #include "tile_widget.h" | ||
2 | #include "map.h" | ||
3 | |||
4 | IMPLEMENT_DYNAMIC_CLASS(TileWidget,wxControl) | ||
5 | |||
6 | BEGIN_EVENT_TABLE(TileWidget, wxControl) | ||
7 | EVT_PAINT(TileWidget::OnPaint) | ||
8 | EVT_LEFT_DOWN(TileWidget::OnClick) | ||
9 | END_EVENT_TABLE() | ||
10 | |||
11 | TileWidget::TileWidget() | ||
12 | { | ||
13 | Init(); | ||
14 | } | ||
15 | |||
16 | TileWidget::TileWidget(wxWindow* parent, wxWindowID winid, int numTilesWidth, const wxPoint& pos, const wxSize& size) | ||
17 | : wxControl(parent, winid, pos, size), numTilesWidth(numTilesWidth) | ||
18 | { | ||
19 | Init(); | ||
20 | } | ||
21 | |||
22 | int TileWidget::getSelected() | ||
23 | { | ||
24 | return selected; | ||
25 | } | ||
26 | |||
27 | void TileWidget::Init() | ||
28 | { | ||
29 | tiles = wxBitmap(wxImage("../../../res/tiles.png")); | ||
30 | numTiles = 50; | ||
31 | } | ||
32 | |||
33 | void TileWidget::OnPaint(wxPaintEvent& event) | ||
34 | { | ||
35 | wxPaintDC dc(this); | ||
36 | wxMemoryDC tiles_dc; | ||
37 | tiles_dc.SelectObject(tiles); | ||
38 | wxRegionIterator upd(GetUpdateRegion()); | ||
39 | int vW = upd.GetW(); | ||
40 | int vH = upd.GetH(); | ||
41 | |||
42 | wxPen pen(*wxGREEN, 2); | ||
43 | dc.SetPen(pen); | ||
44 | dc.SetBrush(*wxTRANSPARENT_BRUSH); | ||
45 | |||
46 | double endWidth = (double) vW / (double) numTilesWidth; | ||
47 | double endHeight = TILE_HEIGHT * (endWidth / (double) TILE_WIDTH); | ||
48 | |||
49 | for (int i=0; i<numTiles; i++) | ||
50 | { | ||
51 | dc.StretchBlit(i%numTilesWidth*endWidth, i/numTilesWidth*endHeight, endWidth, endHeight, &tiles_dc, i%8*TILE_WIDTH, i/8*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT); | ||
52 | |||
53 | if (i == selected) | ||
54 | { | ||
55 | dc.DrawRectangle(i%numTilesWidth*endWidth, i/numTilesWidth*endHeight, endWidth, endHeight); | ||
56 | } | ||
57 | } | ||
58 | } | ||
59 | |||
60 | void TileWidget::OnClick(wxMouseEvent& event) | ||
61 | { | ||
62 | wxRegionIterator upd(GetUpdateRegion()); | ||
63 | int vW = upd.GetW(); | ||
64 | int vH = upd.GetH(); | ||
65 | double endWidth = (double) vW / (double) numTilesWidth; | ||
66 | double endHeight = TILE_HEIGHT * (endWidth / (double) TILE_WIDTH); | ||
67 | |||
68 | wxPoint pos = event.GetPosition(); | ||
69 | int x = pos.x / endWidth; | ||
70 | int y = pos.y / endHeight; | ||
71 | |||
72 | selected = x+y*numTilesWidth; | ||
73 | |||
74 | Refresh(); | ||
75 | event.Skip(); | ||
76 | } | ||
diff --git a/tools/mapedit/src/tile_widget.h b/tools/mapedit/src/tile_widget.h new file mode 100644 index 0000000..6d65f7b --- /dev/null +++ b/tools/mapedit/src/tile_widget.h | |||
@@ -0,0 +1,32 @@ | |||
1 | #ifndef TILE_WIDGET_H | ||
2 | #define TILE_WIDGET_H | ||
3 | |||
4 | #include <wx/wxprec.h> | ||
5 | |||
6 | #ifndef WX_PRECOMP | ||
7 | #include <wx/wx.h> | ||
8 | #endif | ||
9 | |||
10 | class TileWidget : public wxControl { | ||
11 | public: | ||
12 | TileWidget(); | ||
13 | TileWidget(wxWindow* parent, wxWindowID winid, int numTilesWidth = 8, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize); | ||
14 | |||
15 | int getSelected(); | ||
16 | |||
17 | protected: | ||
18 | void Init(); | ||
19 | void OnPaint(wxPaintEvent& event); | ||
20 | void OnClick(wxMouseEvent& event); | ||
21 | |||
22 | private: | ||
23 | int numTilesWidth; | ||
24 | wxBitmap tiles; | ||
25 | int numTiles; | ||
26 | int selected = 0; | ||
27 | |||
28 | DECLARE_DYNAMIC_CLASS(MapeditWidget); | ||
29 | DECLARE_EVENT_TABLE(); | ||
30 | }; | ||
31 | |||
32 | #endif | ||
diff --git a/tools/mapedit/src/widget.cpp b/tools/mapedit/src/widget.cpp new file mode 100644 index 0000000..030e556 --- /dev/null +++ b/tools/mapedit/src/widget.cpp | |||
@@ -0,0 +1,91 @@ | |||
1 | #include "widget.h" | ||
2 | |||
3 | IMPLEMENT_DYNAMIC_CLASS(MapeditWidget,wxControl) | ||
4 | |||
5 | BEGIN_EVENT_TABLE(MapeditWidget, wxControl) | ||
6 | EVT_PAINT(MapeditWidget::OnPaint) | ||
7 | EVT_LEFT_DOWN(MapeditWidget::OnClick) | ||
8 | EVT_LEFT_UP(MapeditWidget::OnMouseUp) | ||
9 | EVT_MOTION(MapeditWidget::OnMouseMove) | ||
10 | END_EVENT_TABLE() | ||
11 | |||
12 | MapeditWidget::MapeditWidget() | ||
13 | { | ||
14 | Init(); | ||
15 | } | ||
16 | |||
17 | MapeditWidget::MapeditWidget(wxWindow* parent, wxWindowID winid, Map* map, TileWidget* tileWidget, const wxPoint& pos, const wxSize& size) | ||
18 | : wxControl(parent, winid, pos, size), map(map), tileWidget(tileWidget) | ||
19 | { | ||
20 | Init(); | ||
21 | } | ||
22 | |||
23 | void MapeditWidget::Init() | ||
24 | { | ||
25 | tiles = wxBitmap(wxImage("../../../res/tiles.png")); | ||
26 | } | ||
27 | |||
28 | wxSize MapeditWidget::DoGetBestSize() const | ||
29 | { | ||
30 | return {GAME_WIDTH*2, GAME_HEIGHT*2}; | ||
31 | } | ||
32 | |||
33 | void MapeditWidget::OnPaint(wxPaintEvent& event) | ||
34 | { | ||
35 | wxPaintDC dc(this); | ||
36 | wxMemoryDC tiles_dc; | ||
37 | tiles_dc.SelectObject(tiles); | ||
38 | wxRegionIterator upd(GetUpdateRegion()); | ||
39 | int vW = upd.GetW(); | ||
40 | int vH = upd.GetH(); | ||
41 | |||
42 | double endWidth = TILE_WIDTH * ((double) vW / (double) GAME_WIDTH); | ||
43 | double endHeight = TILE_HEIGHT * ((double) vH / (double) GAME_HEIGHT); | ||
44 | |||
45 | for (int y=0; y<MAP_HEIGHT; y++) | ||
46 | { | ||
47 | for (int x=0; x<MAP_WIDTH; x++) | ||
48 | { | ||
49 | int tile = map->mapdata[x+y*MAP_WIDTH]; | ||
50 | dc.StretchBlit(x*endWidth, y*endHeight, endWidth, endHeight, &tiles_dc, tile%8*TILE_WIDTH, tile/8*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT); | ||
51 | } | ||
52 | } | ||
53 | } | ||
54 | |||
55 | void MapeditWidget::SetTile(wxPoint pos) | ||
56 | { | ||
57 | wxRegionIterator upd(GetUpdateRegion()); | ||
58 | int vW = upd.GetW(); | ||
59 | int vH = upd.GetH(); | ||
60 | |||
61 | double endWidth = TILE_WIDTH * ((double) vW / (double) GAME_WIDTH); | ||
62 | double endHeight = TILE_HEIGHT * ((double) vH / (double) GAME_HEIGHT); | ||
63 | |||
64 | int x = pos.x / endWidth; | ||
65 | int y = pos.y / endHeight; | ||
66 | |||
67 | map->mapdata[x+y*MAP_WIDTH] = tileWidget->getSelected(); | ||
68 | Refresh(); | ||
69 | } | ||
70 | |||
71 | void MapeditWidget::OnClick(wxMouseEvent& event) | ||
72 | { | ||
73 | mouseIsDown = true; | ||
74 | |||
75 | SetTile(event.GetPosition()); | ||
76 | |||
77 | event.Skip(); | ||
78 | } | ||
79 | |||
80 | void MapeditWidget::OnMouseMove(wxMouseEvent& event) | ||
81 | { | ||
82 | if (mouseIsDown) | ||
83 | { | ||
84 | SetTile(event.GetPosition()); | ||
85 | } | ||
86 | } | ||
87 | |||
88 | void MapeditWidget::OnMouseUp(wxMouseEvent& event) | ||
89 | { | ||
90 | mouseIsDown = false; | ||
91 | } | ||
diff --git a/tools/mapedit/src/widget.h b/tools/mapedit/src/widget.h new file mode 100644 index 0000000..f2bfbbe --- /dev/null +++ b/tools/mapedit/src/widget.h | |||
@@ -0,0 +1,38 @@ | |||
1 | #ifndef WIDGET_H | ||
2 | #define WIDGET_H | ||
3 | |||
4 | #include <wx/wxprec.h> | ||
5 | |||
6 | #ifndef WX_PRECOMP | ||
7 | #include <wx/wx.h> | ||
8 | #endif | ||
9 | |||
10 | #include "map.h" | ||
11 | #include "tile_widget.h" | ||
12 | |||
13 | class MapeditWidget : public wxControl { | ||
14 | public: | ||
15 | MapeditWidget(); | ||
16 | MapeditWidget(wxWindow* parent, wxWindowID winid, Map* map, TileWidget* tileWidget, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize); | ||
17 | |||
18 | protected: | ||
19 | void Init(); | ||
20 | virtual wxSize DoGetBestSize() const; | ||
21 | void OnPaint(wxPaintEvent& event); | ||
22 | void OnClick(wxMouseEvent& event); | ||
23 | void OnMouseMove(wxMouseEvent& event); | ||
24 | void OnMouseUp(wxMouseEvent& event); | ||
25 | |||
26 | private: | ||
27 | void SetTile(wxPoint pos); | ||
28 | |||
29 | Map* const map = nullptr; | ||
30 | wxBitmap tiles; | ||
31 | TileWidget* tileWidget; | ||
32 | bool mouseIsDown = false; | ||
33 | |||
34 | DECLARE_DYNAMIC_CLASS(MapeditWidget); | ||
35 | DECLARE_EVENT_TABLE(); | ||
36 | }; | ||
37 | |||
38 | #endif | ||