Ticket #1392: template_name_for_selected_entities.4.diff

File template_name_for_selected_entities.4.diff, 9.1 KB (added by Adi, 10 years ago)
  • source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Object/Object.cpp

    diff --git source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Object/Object.cpp source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Object/Object.cpp
    index b29e8f2..de5bf82 100644
     
    1 /* Copyright (C) 2012 Wildfire Games.
     1/* Copyright (C) 2014 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
     
    2525#include "ScenarioEditor/Tools/Common/ObjectSettings.h"
    2626#include "ScenarioEditor/Tools/Common/MiscState.h"
    2727#include "VariationControl.h"
     28#include "SelectedTemplates.h"
    2829
    2930#include "GameInterface/Messages.h"
    3031
    ObjectBottomBar::ObjectBottomBar(  
    462463    variationSizer->Add(variationSelect, wxSizerFlags().Proportion(1).Expand());
    463464    playerVariationSizer->Add(variationSizer, wxSizerFlags().Proportion(1));
    464465
     466    /* selected templates panel */
     467    wxWindow* selectedTemplates = new SelectedTemplates(this, objectSettings);
     468    selectedTemplates->SetMinSize(wxSize(250, -1));
     469    wxSizer* selTemplatesSizer = new wxStaticBoxSizer(wxHORIZONTAL, this, _("Selected entity templates"));
     470    selTemplatesSizer->Add(selectedTemplates, wxSizerFlags().Proportion(1).Expand());
     471
    465472    mainSizer->AddSpacer(3);
    466473    mainSizer->Add(playerVariationSizer, wxSizerFlags().Expand());
     474    mainSizer->Add(selTemplatesSizer, wxSizerFlags().Expand());
    467475
    468476    // ----------------------------------------------------------------------------------
    469477
  • new file source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Object/SelectedTemplates.cpp

    diff --git source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Object/SelectedTemplates.cpp source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Object/SelectedTemplates.cpp
    new file mode 100644
    index 0000000..4ace5f4
    - +  
     1/* Copyright (C) 2014 Wildfire Games.
     2 * This file is part of 0 A.D.
     3 *
     4 * 0 A.D. is free software: you can redistribute it and/or modify
     5 * it under the terms of the GNU General Public License as published by
     6 * the Free Software Foundation, either version 2 of the License, or
     7 * (at your option) any later version.
     8 *
     9 * 0 A.D. is distributed in the hope that it will be useful,
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12 * GNU General Public License for more details.
     13 *
     14 * You should have received a copy of the GNU General Public License
     15 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
     16 */
     17
     18#include <sstream>
     19
     20#include "precompiled.h"
     21
     22#include "ScenarioEditor/Tools/Common/ObjectSettings.h"
     23
     24#include "SelectedTemplates.h"
     25#include "GameInterface/Messages.h"
     26
     27SelectedTemplates::SelectedTemplates(wxWindow* parent, Observable<ObjectSettings>& objectSettings)
     28    : wxScrolledWindow(parent, -1),
     29      m_ObjectSettings(objectSettings)
     30{
     31    m_Conn = m_ObjectSettings.RegisterObserver(1, &SelectedTemplates::OnSelectionChange, this);
     32
     33    SetScrollRate(0, 5);
     34
     35    m_Sizer = new wxBoxSizer(wxVERTICAL);
     36    SetSizer(m_Sizer);
     37}
     38
     39void SelectedTemplates::OnSelectionChange(const ObjectSettings& settings)
     40{
     41    Freeze();
     42
     43    const std::vector<AtlasMessage::ObjectID>& selections = settings.GetSelectedObjects();
     44
     45    // Get the list of selected objects from the game
     46    AtlasMessage::qGetSelectedObjectsTemplateNames qry(selections);
     47    qry.Post();
     48
     49    std::vector<std::string> names;
     50    names = *qry.names;
     51
     52    // calculate frequency for the template names
     53    typedef std::map<std::string, unsigned> counts_templates;
     54    counts_templates f_names;
     55
     56    for (std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); ++it)
     57        ++f_names[*it];
     58
     59    m_Sizer->Clear(true);
     60
     61    for (counts_templates::const_iterator it = f_names.begin(); it != f_names.end(); ++it)
     62    {
     63        double freq = static_cast<double>(it->second);
     64        std::stringstream ss_freq;
     65        ss_freq << freq;
     66        std::string s_freq = ss_freq.str();
     67
     68        std::string template_name = it->first;
     69
     70        template_name.append(" x ");
     71        template_name.append(s_freq);
     72        wxString tooltip(template_name.c_str());
     73        wxStaticText* label = new wxStaticText(this, wxID_ANY, _(template_name.c_str()));
     74        label->SetToolTip(tooltip);
     75        m_Sizer->Add(label, wxSizerFlags().Align(wxALIGN_LEFT));
     76    }
     77
     78    Thaw();
     79
     80    // Make the scrollbars appear when appropriate
     81    m_Sizer->FitInside(this);
     82}
  • new file source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Object/SelectedTemplates.h

    diff --git source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Object/SelectedTemplates.h source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Object/SelectedTemplates.h
    new file mode 100644
    index 0000000..44f22fa
    - +  
     1/* Copyright (C) 2014 Wildfire Games.
     2 * This file is part of 0 A.D.
     3 *
     4 * 0 A.D. is free software: you can redistribute it and/or modify
     5 * it under the terms of the GNU General Public License as published by
     6 * the Free Software Foundation, either version 2 of the License, or
     7 * (at your option) any later version.
     8 *
     9 * 0 A.D. is distributed in the hope that it will be useful,
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12 * GNU General Public License for more details.
     13 *
     14 * You should have received a copy of the GNU General Public License
     15 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
     16 */
     17
     18#ifndef INCLUDED_SELECTEDTEMPLATES
     19#define INCLUDED_SELECTEDTEMPLATES
     20
     21#include "General/Observable.h"
     22
     23class SelectedTemplates : public wxScrolledWindow
     24{
     25public:
     26    SelectedTemplates(wxWindow* parent, Observable<ObjectSettings>& objectSettings);
     27
     28private:
     29    void OnSelectionChange(const ObjectSettings& settings);
     30
     31    ObservableScopedConnection m_Conn;
     32
     33    Observable<ObjectSettings>& m_ObjectSettings;
     34    wxSizer* m_Sizer;
     35};
     36
     37#endif // INCLUDED_SELECTEDTEMPLATES
  • source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/ObjectSettings.cpp

    diff --git source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/ObjectSettings.cpp source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/ObjectSettings.cpp
    index 6bd0558..ba76bb8 100644
    const std::vector<ObjectSettings::Group> ObjectSettings::GetActorVariation() con  
    8686    return variation;
    8787}
    8888
     89const std::vector<AtlasMessage::ObjectID>& ObjectSettings::GetSelectedObjects() const
     90{
     91    return m_SelectedObjects;
     92}
     93
    8994AtlasMessage::sObjectSettings ObjectSettings::GetSettings() const
    9095{
    9196    AtlasMessage::sObjectSettings settings;
    void ObjectSettings::OnSelectionChange(const std::vector<AtlasMessage::ObjectID>  
    110115    // TODO: what would be the sensible action if nothing's selected?
    111116    // and if multiple objects are selected?
    112117
    113     if (selection.empty())
    114         return;
    115 
    116118    AtlasMessage::qGetObjectSettings qry (m_View, selection[0]);
    117119    qry.Post();
    118120
  • source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/ObjectSettings.h

    diff --git source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/ObjectSettings.h source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/ObjectSettings.h
    index e89c564..58adb50 100644
    public:  
    5252    const std::set<wxString>& GetActorSelections() const;
    5353    void SetActorSelections(const std::set<wxString>& selections);
    5454
     55    const std::vector<AtlasMessage::ObjectID>& GetSelectedObjects() const;
     56
    5557    // Constructs new sObjectSettings object from settings
    5658    AtlasMessage::sObjectSettings GetSettings() const;
    5759
  • source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp

    diff --git source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp
    index 4051464..470da7c 100644
     
    1 /* Copyright (C) 2013 Wildfire Games.
     1/* Copyright (C) 2014 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
    QUERYHANDLER(GetObjectsList)  
    9595}
    9696
    9797
     98QUERYHANDLER(GetSelectedObjectsTemplateNames)
     99{
     100    std::vector<entity_id_t> ids = *msg->ids;
     101    std::vector<std::string> names;
     102
     103    CmpPtr<ICmpTemplateManager> cmpTemplateManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
     104    ENSURE(cmpTemplateManager);
     105
     106    for (size_t i = 0; i < ids.size(); ++i)
     107    {
     108        entity_id_t id = (entity_id_t)ids[i];
     109        std::string templateName = cmpTemplateManager->GetCurrentTemplateName(id);
     110        names.push_back(templateName);
     111    }
     112
     113    msg->names = names;
     114}
     115
    98116static std::vector<entity_id_t> g_Selection;
    99117typedef std::map<player_id_t, CColor> PlayerColorMap;
    100118
  • source/tools/atlas/GameInterface/Messages.h

    diff --git source/tools/atlas/GameInterface/Messages.h source/tools/atlas/GameInterface/Messages.h
    index d7f1e60..e907cda 100644
    QUERY(GetObjectsList,  
    320320      ((std::vector<sObjectsListItem>, objects)) // sorted by .name
    321321      );
    322322
     323QUERY(GetSelectedObjectsTemplateNames,
     324        ((std::vector<ObjectID>, ids))
     325        ,
     326        ((std::vector<std::string>, names))
     327        );
     328
    323329#ifndef MESSAGES_SKIP_STRUCTS
    324330struct sObjectSettings
    325331{