Ticket #2988: 2988.diff
File 2988.diff, 5.6 KB (added by , 9 years ago) |
---|
-
source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Object/Object.cpp
1 /* Copyright (C) 201 4Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 97 97 struct ObjectSidebarImpl 98 98 { 99 99 ObjectSidebarImpl(ScenarioEditor& scenarioEditor) : 100 m_ObjectList Box(NULL), m_ActorViewerActive(false),100 m_ObjectListView(NULL), m_ActorViewerActive(false), 101 101 m_ActorViewerEntity(_T("actor|structures/fndn_1x1.xml")), 102 102 m_ActorViewerAnimation(_T("idle")), m_ActorViewerSpeed(0.f), 103 103 m_ObjectSettings(scenarioEditor.GetObjectSettings()) … … 104 104 { 105 105 } 106 106 107 wxList Box* m_ObjectListBox;107 wxListView* m_ObjectListView; 108 108 std::vector<AtlasMessage::sObjectsListItem> m_Objects; 109 109 ObservableScopedConnection m_ToolConn; 110 110 … … 152 152 153 153 // ------------------------------------------------------------------------------------------ 154 154 155 p->m_ObjectListBox = new wxListBox(this, ID_SelectObject, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_SINGLE|wxLB_HSCROLL); 156 m_MainSizer->Add(p->m_ObjectListBox, wxSizerFlags().Proportion(1).Expand()); 155 p->m_ObjectListView = new wxListView(this, ID_SelectObject, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_SINGLE_SEL | wxLC_NO_HEADER); 156 p->m_ObjectListView->AppendColumn(_("Template Name"), wxLIST_FORMAT_LEFT, wxLIST_AUTOSIZE); 157 158 m_MainSizer->Add(p->m_ObjectListView, wxSizerFlags().Proportion(1).Expand()); 157 159 m_MainSizer->AddSpacer(3); 158 160 159 161 // ------------------------------------------------------------------------------------------ … … 208 210 FilterObjects(); 209 211 } 210 212 211 void ObjectSidebar::FilterObjects() 213 int g_itemIdListView = 0; 214 struct filterObject 212 215 { 213 int filterType = wxDynamicCast(FindWindow(ID_ObjectType), wxChoice)->GetSelection(); 214 wxString filterName = wxDynamicCast(FindWindow(ID_ObjectFilter), wxTextCtrl)->GetValue(); 216 filterObject(const wxString filter, int filterType, wxListView* listView):m_filter(filter.Lower()), m_filterType(filterType),m_listView(listView) 217 { 218 } 215 219 216 p->m_ObjectListBox->Freeze(); 217 p->m_ObjectListBox->Clear(); 218 for (std::vector<AtlasMessage::sObjectsListItem>::iterator it = p->m_Objects.begin(); it != p->m_Objects.end(); ++it) 220 void operator()(const AtlasMessage::sObjectsListItem& it) const 219 221 { 220 if (it ->type ==filterType)222 if (it.type == m_filterType) 221 223 { 222 wxString id = it ->id.c_str();223 wxString name = it ->name.c_str();224 wxString id = it.id.c_str(); 225 wxString name = it.name.c_str(); 224 226 225 if (name.Lower().Find( filterName.Lower()) != wxNOT_FOUND)227 if (name.Lower().Find(m_filter) != wxNOT_FOUND) 226 228 { 227 p->m_ObjectListBox->Append(name, new wxStringClientData(id)); 229 wxListItem item; 230 item.SetColumn(0); 231 item.SetText(name); 232 item.SetId(++g_itemIdListView); 233 item.SetWidth(wxLIST_AUTOSIZE); 234 item.SetData(new wxStringClientData(id)); 235 m_listView->InsertItem(item); 228 236 } 229 237 } 230 238 } 231 p->m_ObjectListBox->Thaw(); 239 240 private: 241 wxString m_filter; 242 int m_filterType; 243 wxListView* m_listView; 244 }; 245 246 void ObjectSidebar::FilterObjects() 247 { 248 int filterType = wxDynamicCast(FindWindow(ID_ObjectType), wxChoice)->GetSelection(); 249 wxString filterName = wxDynamicCast(FindWindow(ID_ObjectFilter), wxTextCtrl)->GetValue(); 250 251 p->m_ObjectListView->Freeze(); 252 p->m_ObjectListView->DeleteAllItems(); 253 g_itemIdListView = -1; 254 std::for_each(p->m_Objects.begin(), p->m_Objects.end(), filterObject(filterName, filterType, p->m_ObjectListView)); 255 p->m_ObjectListView->SetColumnWidth(0, wxLIST_AUTOSIZE); 256 p->m_ObjectListView->Thaw(); 232 257 } 233 258 234 259 void ObjectSidebar::OnToggleViewer(wxCommandEvent& WXUNUSED(evt)) … … 248 273 FilterObjects(); 249 274 } 250 275 251 void ObjectSidebar::OnSelectObject(wx CommandEvent& evt)276 void ObjectSidebar::OnSelectObject(wxListEvent& evt) 252 277 { 253 278 if (evt.GetInt() < 0) 254 279 return; 255 280 256 wxString id = static_cast<wxStringClientData*>(evt.GetClientObject())->GetData();281 wxString id = reinterpret_cast<wxStringClientData*>(evt.GetData())->GetData(); 257 282 258 283 // Always update the actor viewer's state even if it's inactive, 259 284 // so it will be correct when first enabled … … 278 303 BEGIN_EVENT_TABLE(ObjectSidebar, Sidebar) 279 304 EVT_CHOICE(ID_ObjectType, ObjectSidebar::OnSelectType) 280 305 EVT_TEXT(ID_ObjectFilter, ObjectSidebar::OnSelectFilter) 281 EVT_LIST BOX(ID_SelectObject, ObjectSidebar::OnSelectObject)306 EVT_LIST_ITEM_SELECTED(ID_SelectObject, ObjectSidebar::OnSelectObject) 282 307 EVT_BUTTON(ID_ToggleViewer, ObjectSidebar::OnToggleViewer) 283 308 END_EVENT_TABLE(); 284 309 -
source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Object/Object.h
1 /* Copyright (C) 201 1Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 16 16 */ 17 17 18 18 #include "../Common/Sidebar.h" 19 #include <wx/listctrl.h> 19 20 20 21 class ITool; 21 22 … … 35 36 void OnToggleViewer(wxCommandEvent& evt); 36 37 void OnSelectType(wxCommandEvent& evt); 37 38 void OnSelectFilter(wxCommandEvent& evt); 38 void OnSelectObject(wx CommandEvent& evt);39 void OnSelectObject(wxListEvent& evt); 39 40 40 41 ObjectSidebarImpl* p;