Ticket #1392: template_name_for_selected_entities.4.diff
File template_name_for_selected_entities.4.diff, 9.1 KB (added by , 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) 201 2Wildfire Games.1 /* Copyright (C) 2014 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 … … 25 25 #include "ScenarioEditor/Tools/Common/ObjectSettings.h" 26 26 #include "ScenarioEditor/Tools/Common/MiscState.h" 27 27 #include "VariationControl.h" 28 #include "SelectedTemplates.h" 28 29 29 30 #include "GameInterface/Messages.h" 30 31 … … ObjectBottomBar::ObjectBottomBar( 462 463 variationSizer->Add(variationSelect, wxSizerFlags().Proportion(1).Expand()); 463 464 playerVariationSizer->Add(variationSizer, wxSizerFlags().Proportion(1)); 464 465 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 465 472 mainSizer->AddSpacer(3); 466 473 mainSizer->Add(playerVariationSizer, wxSizerFlags().Expand()); 474 mainSizer->Add(selTemplatesSizer, wxSizerFlags().Expand()); 467 475 468 476 // ---------------------------------------------------------------------------------- 469 477 -
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 27 SelectedTemplates::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 39 void 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 23 class SelectedTemplates : public wxScrolledWindow 24 { 25 public: 26 SelectedTemplates(wxWindow* parent, Observable<ObjectSettings>& objectSettings); 27 28 private: 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 86 86 return variation; 87 87 } 88 88 89 const std::vector<AtlasMessage::ObjectID>& ObjectSettings::GetSelectedObjects() const 90 { 91 return m_SelectedObjects; 92 } 93 89 94 AtlasMessage::sObjectSettings ObjectSettings::GetSettings() const 90 95 { 91 96 AtlasMessage::sObjectSettings settings; … … void ObjectSettings::OnSelectionChange(const std::vector<AtlasMessage::ObjectID> 110 115 // TODO: what would be the sensible action if nothing's selected? 111 116 // and if multiple objects are selected? 112 117 113 if (selection.empty())114 return;115 116 118 AtlasMessage::qGetObjectSettings qry (m_View, selection[0]); 117 119 qry.Post(); 118 120 -
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: 52 52 const std::set<wxString>& GetActorSelections() const; 53 53 void SetActorSelections(const std::set<wxString>& selections); 54 54 55 const std::vector<AtlasMessage::ObjectID>& GetSelectedObjects() const; 56 55 57 // Constructs new sObjectSettings object from settings 56 58 AtlasMessage::sObjectSettings GetSettings() const; 57 59 -
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) 201 3Wildfire Games.1 /* Copyright (C) 2014 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 … … QUERYHANDLER(GetObjectsList) 95 95 } 96 96 97 97 98 QUERYHANDLER(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 98 116 static std::vector<entity_id_t> g_Selection; 99 117 typedef std::map<player_id_t, CColor> PlayerColorMap; 100 118 -
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, 320 320 ((std::vector<sObjectsListItem>, objects)) // sorted by .name 321 321 ); 322 322 323 QUERY(GetSelectedObjectsTemplateNames, 324 ((std::vector<ObjectID>, ids)) 325 , 326 ((std::vector<std::string>, names)) 327 ); 328 323 329 #ifndef MESSAGES_SKIP_STRUCTS 324 330 struct sObjectSettings 325 331 {