Skip to content

Commit

Permalink
#5406: Upgrade "Name of single entity" SpecifierEditor to a combo box…
Browse files Browse the repository at this point in the history
… listing all the map's entities.
  • Loading branch information
codereader committed Dec 25, 2020
1 parent c5e1cb5 commit 62a4ab7
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 5 deletions.
59 changes: 59 additions & 0 deletions plugins/dm.objectives/ce/specpanel/EntityNameSpecifierPanel.cpp
@@ -1,11 +1,70 @@
#include "EntityNameSpecifierPanel.h"

#include <wx/sizer.h>
#include "inode.h"
#include "imap.h"
#include "ientity.h"

namespace objectives
{

namespace ce
{

EntityNameSpecifierPanel::EntityNameSpecifierPanel() :
_editCombo(nullptr)
{}

EntityNameSpecifierPanel::EntityNameSpecifierPanel(wxWindow* parent) :
_editCombo(nullptr)
{
_editCombo = new wxComboBox(parent, wxID_ANY);

// Bind both events to the same callback
_editCombo->Bind(wxEVT_TEXT, &EntityNameSpecifierPanel::onComboBoxChanged, this);
_editCombo->Bind(wxEVT_COMBOBOX, &EntityNameSpecifierPanel::onComboBoxChanged, this);

// Collect all entity names in the scene
GlobalMapModule().getRoot()->foreachNode([&](const scene::INodePtr& node)
{
if (Node_isEntity(node))
{
_editCombo->AppendString(Node_getEntity(node)->getKeyValue("name"));
}

return true;
});
}

EntityNameSpecifierPanel::~EntityNameSpecifierPanel()
{
delete _editCombo;
_editCombo = nullptr;
}

wxWindow* EntityNameSpecifierPanel::getWidget()
{
return _editCombo;
}

void EntityNameSpecifierPanel::setValue(const std::string& value)
{
_editCombo->SetValue(value);
}

std::string EntityNameSpecifierPanel::getValue() const
{
return _editCombo->GetValue().ToStdString();
}

void EntityNameSpecifierPanel::onComboBoxChanged(wxCommandEvent& ev)
{
if (_valueChanged)
{
_valueChanged(); // usually points to the abstract ComponentEditor::writeToComponent
}
}

// Reg helper
EntityNameSpecifierPanel::RegHelper EntityNameSpecifierPanel::_regHelper;

Expand Down
45 changes: 40 additions & 5 deletions plugins/dm.objectives/ce/specpanel/EntityNameSpecifierPanel.h
@@ -1,7 +1,8 @@
#pragma once

#include "SpecifierPanel.h"
#include "TextSpecifierPanel.h"
#include "SpecifierPanelFactory.h"
#include <wx/combobox.h>

namespace objectives
{
Expand All @@ -13,12 +14,46 @@ namespace ce
* SpecifierPanel subclass for the SPEC_NAME (name of single entity) specifier
* type.
*/
class EntityNameSpecifierPanel
: public TextSpecifierPanel
class EntityNameSpecifierPanel :
public wxEvtHandler,
public SpecifierPanel
{
protected:
wxComboBox* _editCombo;

// The change callback, invoked when the text changes
std::function<void()> _valueChanged;

EntityNameSpecifierPanel();

public:
EntityNameSpecifierPanel(wxWindow* parent);

virtual ~EntityNameSpecifierPanel();

/* SpecifierPanel implementation */
virtual SpecifierPanelPtr create(wxWindow* parent) const override
{
return std::make_shared<EntityNameSpecifierPanel>(parent);
}

void setChangedCallback(const std::function<void()>& callback) override
{
_valueChanged = callback;
}

virtual wxWindow* getWidget() override;
void setValue(const std::string& value) override;
std::string getValue() const override;

private:
void onComboBoxChanged(wxCommandEvent& ev);

// Map registration
static struct RegHelper {
RegHelper() {
static struct RegHelper
{
RegHelper()
{
SpecifierPanelFactory::registerType(
SpecifierType::SPEC_NAME().getName(),
SpecifierPanelPtr(new EntityNameSpecifierPanel())
Expand Down

0 comments on commit 62a4ab7

Please sign in to comment.