Ticket #1392: template_name_for_selected_entities.diff

File template_name_for_selected_entities.diff, 9.2 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..b066d43 100644
     
    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..e7fd214
    - +  
     1/* Copyright (C) 2011 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),
     29m_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 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    //template names with frequency
     53    std::vector<templateNameFreq> f_names;
     54    for (std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); ++it)
     55    {
     56        std::string name = *it;
     57        bool found = false;
     58        for (std::vector<templateNameFreq>::iterator j = f_names.begin(); j != f_names.end(); ++j){
     59            if ((*j).name.compare(name) == 0){
     60                (*j).count++;
     61                found = true;
     62                break;
     63            }
     64        }
     65        if(!found){
     66            templateNameFreq template_name;
     67            template_name.count = 1;
     68            template_name.name = name;
     69            f_names.push_back(template_name);
     70        }
     71    }
     72
     73    m_Sizer->Clear(true);
     74
     75    for (std::vector<templateNameFreq>::const_iterator it = f_names.begin(); it != f_names.end(); ++it){
     76
     77        std::stringstream _count;
     78        _count << (*it).count;
     79        std::string templates_count = _count.str();
     80
     81        std::string template_name = (*it).name;
     82
     83        template_name.append(" x ");
     84        template_name.append(templates_count);
     85        wxStaticText *label = new wxStaticText(this, wxID_ANY, _(template_name.c_str()));
     86        m_Sizer->Add(label, wxSizerFlags().Align(wxALIGN_LEFT));
     87    }
     88
     89    Thaw();
     90
     91    // Make the scrollbars appear when appropriate
     92    m_Sizer->FitInside(this);
     93}
  • 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..0b19f4d
    - +  
     1/* Copyright (C) 2009 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
     23struct templateNameFreq{
     24    std::string name;
     25    int count;
     26};
     27
     28class SelectedTemplates : public wxScrolledWindow
     29{
     30public:
     31    SelectedTemplates(wxWindow* parent, Observable<ObjectSettings>& objectSettings);
     32
     33private:
     34    void OnSelectionChange(const ObjectSettings& settings);
     35    void RefreshObjectSettings();
     36
     37    ObservableScopedConnection m_Conn;
     38
     39    Observable<ObjectSettings>& m_ObjectSettings;
     40    wxSizer* m_Sizer;
     41};
     42
     43#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..898dad7 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;
     118/* Even if nothing is selected, the observers should still be notified */
     119//  if (selection.empty())
     120//      return;
    115121
    116122    AtlasMessage::qGetObjectSettings qry (m_View, selection[0]);
    117123    qry.Post();
  • 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..e47b882 100644
    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{