diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-03-17 23:53:55 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-03-17 23:53:55 -0400 |
commit | f732cdaf7374fde737b503ec6966fb8cd8f4c32b (patch) | |
tree | f7fa3122f30ee98a5984cf7e5fb0260c6c6c1148 /tools/mapedit/src/mapselect_combo.cpp | |
parent | b2ad90fef0e31a1d8635b817940d9bf71320b588 (diff) | |
download | therapy-f732cdaf7374fde737b503ec6966fb8cd8f4c32b.tar.gz therapy-f732cdaf7374fde737b503ec6966fb8cd8f4c32b.tar.bz2 therapy-f732cdaf7374fde737b503ec6966fb8cd8f4c32b.zip |
Map editor can now define actions to occur when the player goes off a specified edge of the map
Diffstat (limited to 'tools/mapedit/src/mapselect_combo.cpp')
-rw-r--r-- | tools/mapedit/src/mapselect_combo.cpp | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/tools/mapedit/src/mapselect_combo.cpp b/tools/mapedit/src/mapselect_combo.cpp new file mode 100644 index 0000000..c8315b8 --- /dev/null +++ b/tools/mapedit/src/mapselect_combo.cpp | |||
@@ -0,0 +1,91 @@ | |||
1 | #include "mapselect_combo.h" | ||
2 | #include "map.h" | ||
3 | |||
4 | wxBEGIN_EVENT_TABLE(MapSelectComboPopup, wxTreeCtrl) | ||
5 | EVT_LEFT_UP(MapSelectComboPopup::OnMouseClick) | ||
6 | wxEND_EVENT_TABLE() | ||
7 | |||
8 | MapSelectComboPopup::MapSelectComboPopup(wxTreeCtrl* tree, int initial) | ||
9 | { | ||
10 | mapTree = tree; | ||
11 | lastSelected = initial; | ||
12 | |||
13 | Init(); | ||
14 | } | ||
15 | |||
16 | void MapSelectComboPopup::Init() | ||
17 | { | ||
18 | |||
19 | } | ||
20 | |||
21 | bool MapSelectComboPopup::Create(wxWindow* parent) | ||
22 | { | ||
23 | return wxTreeCtrl::Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTR_HIDE_ROOT); | ||
24 | } | ||
25 | |||
26 | wxWindow* MapSelectComboPopup::GetControl() | ||
27 | { | ||
28 | return this; | ||
29 | } | ||
30 | |||
31 | wxString MapSelectComboPopup::GetStringValue() const | ||
32 | { | ||
33 | return ((MapPtrCtr*) GetItemData(GetFocusedItem()))->map->getTitle(); | ||
34 | } | ||
35 | |||
36 | void MapSelectComboPopup::OnPopup() | ||
37 | { | ||
38 | DeleteAllItems(); | ||
39 | |||
40 | wxTreeItemId newRoot = AddRoot("root"); | ||
41 | wxTreeItemId oldRoot = mapTree->GetRootItem(); | ||
42 | wxTreeItemIdValue cookie; | ||
43 | for (wxTreeItemId it = mapTree->GetFirstChild(oldRoot, cookie); it.IsOk(); it = mapTree->GetNextChild(newRoot, cookie)) | ||
44 | { | ||
45 | CopyNodes(it, newRoot); | ||
46 | } | ||
47 | } | ||
48 | |||
49 | void MapSelectComboPopup::CopyNodes(wxTreeItemId from, wxTreeItemId to) | ||
50 | { | ||
51 | MapPtrCtr* ctl1 = (MapPtrCtr*) mapTree->GetItemData(from); | ||
52 | MapPtrCtr* ctl2 = nullptr; | ||
53 | if (ctl1 != nullptr) | ||
54 | { | ||
55 | ctl2 = new MapPtrCtr(ctl1->map); | ||
56 | } | ||
57 | |||
58 | wxTreeItemId copied = mapTree->AppendItem(to, mapTree->GetItemText(from), -1, -1, ctl2); | ||
59 | if (mapTree->ItemHasChildren(from)) | ||
60 | { | ||
61 | wxTreeItemIdValue cookie; | ||
62 | for (wxTreeItemId it = mapTree->GetFirstChild(from, cookie); it.IsOk(); it = mapTree->GetNextChild(from, cookie)) | ||
63 | { | ||
64 | CopyNodes(it, copied); | ||
65 | } | ||
66 | } | ||
67 | |||
68 | if (ctl1->map->getID() == lastSelected) | ||
69 | { | ||
70 | SelectItem(copied); | ||
71 | } | ||
72 | |||
73 | Expand(copied); | ||
74 | } | ||
75 | |||
76 | void MapSelectComboPopup::OnMouseClick(wxMouseEvent&) | ||
77 | { | ||
78 | lastSelected = ((MapPtrCtr*) GetItemData(GetFocusedItem()))->map->getID(); | ||
79 | |||
80 | Dismiss(); | ||
81 | } | ||
82 | |||
83 | int MapSelectComboPopup::GetSelectedMapID() const | ||
84 | { | ||
85 | return lastSelected; | ||
86 | } | ||
87 | |||
88 | void MapSelectComboPopup::SetSelectedMapID(int id) | ||
89 | { | ||
90 | lastSelected = id; | ||
91 | } | ||