Ticket #2988: 2988.diff

File 2988.diff, 5.6 KB (added by trompetin17, 9 years ago)
  • source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Object/Object.cpp

     
    1 /* Copyright (C) 2014 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    9797struct ObjectSidebarImpl
    9898{
    9999    ObjectSidebarImpl(ScenarioEditor& scenarioEditor) :
    100         m_ObjectListBox(NULL), m_ActorViewerActive(false),
     100        m_ObjectListView(NULL), m_ActorViewerActive(false),
    101101        m_ActorViewerEntity(_T("actor|structures/fndn_1x1.xml")),
    102102        m_ActorViewerAnimation(_T("idle")), m_ActorViewerSpeed(0.f),
    103103        m_ObjectSettings(scenarioEditor.GetObjectSettings())
     
    104104    {
    105105    }
    106106
    107     wxListBox* m_ObjectListBox;
     107    wxListView* m_ObjectListView;
    108108    std::vector<AtlasMessage::sObjectsListItem> m_Objects;
    109109    ObservableScopedConnection m_ToolConn;
    110110
     
    152152   
    153153    // ------------------------------------------------------------------------------------------
    154154
    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());
    157159    m_MainSizer->AddSpacer(3);
    158160
    159161    // ------------------------------------------------------------------------------------------
     
    208210    FilterObjects();
    209211}
    210212
    211 void ObjectSidebar::FilterObjects()
     213int g_itemIdListView = 0;
     214struct filterObject
    212215{
    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    }
    215219
    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
    219221    {
    220         if (it->type == filterType)
     222        if (it.type == m_filterType)
    221223        {
    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();
    224226
    225             if (name.Lower().Find(filterName.Lower()) != wxNOT_FOUND)
     227            if (name.Lower().Find(m_filter) != wxNOT_FOUND)
    226228            {
    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);
    228236            }
    229237        }
    230238    }
    231     p->m_ObjectListBox->Thaw();
     239
     240private:
     241    wxString m_filter;
     242    int m_filterType;
     243    wxListView* m_listView;
     244};
     245
     246void 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();
    232257}
    233258
    234259void ObjectSidebar::OnToggleViewer(wxCommandEvent& WXUNUSED(evt))
     
    248273    FilterObjects();
    249274}
    250275
    251 void ObjectSidebar::OnSelectObject(wxCommandEvent& evt)
     276void ObjectSidebar::OnSelectObject(wxListEvent& evt)
    252277{
    253278    if (evt.GetInt() < 0)
    254279        return;
    255280
    256     wxString id = static_cast<wxStringClientData*>(evt.GetClientObject())->GetData();
     281    wxString id = reinterpret_cast<wxStringClientData*>(evt.GetData())->GetData();
    257282
    258283    // Always update the actor viewer's state even if it's inactive,
    259284    // so it will be correct when first enabled
     
    278303BEGIN_EVENT_TABLE(ObjectSidebar, Sidebar)
    279304    EVT_CHOICE(ID_ObjectType, ObjectSidebar::OnSelectType)
    280305    EVT_TEXT(ID_ObjectFilter, ObjectSidebar::OnSelectFilter)
    281     EVT_LISTBOX(ID_SelectObject, ObjectSidebar::OnSelectObject)
     306    EVT_LIST_ITEM_SELECTED(ID_SelectObject, ObjectSidebar::OnSelectObject)
    282307    EVT_BUTTON(ID_ToggleViewer, ObjectSidebar::OnToggleViewer)
    283308END_EVENT_TABLE();
    284309
  • source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Object/Object.h

     
    1 /* Copyright (C) 2011 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    1616 */
    1717
    1818#include "../Common/Sidebar.h"
     19#include <wx/listctrl.h>
    1920
    2021class ITool;
    2122
     
    3536    void OnToggleViewer(wxCommandEvent& evt);
    3637    void OnSelectType(wxCommandEvent& evt);
    3738    void OnSelectFilter(wxCommandEvent& evt);
    38     void OnSelectObject(wxCommandEvent& evt);
     39    void OnSelectObject(wxListEvent& evt);
    3940
    4041    ObjectSidebarImpl* p;