Skip to content

Commit

Permalink
Resolve part of #4377: Conversation commands using sound shaders now …
Browse files Browse the repository at this point in the history
…use the corresponding IResourceChooser
  • Loading branch information
codereader committed Dec 25, 2016
1 parent 81c101c commit 1853bfa
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 1 deletion.
66 changes: 66 additions & 0 deletions plugins/dm.conversation/CommandArgumentItem.cpp
@@ -1,11 +1,18 @@
#include "CommandArgumentItem.h"

#include "idialogmanager.h"
#include "iresourcechooser.h"
#include "iuimanager.h"
#include "i18n.h"
#include "string/convert.h"
#include <wx/checkbox.h>
#include <wx/choice.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
#include <wx/panel.h>
#include <wx/sizer.h>
#include <wx/artprov.h>
#include <wx/bmpbuttn.h>

#include "wxutil/ChoiceHelper.h"

Expand All @@ -14,6 +21,11 @@
namespace ui
{

namespace
{
const char* const FOLDER_ICON = "folder16.png";
}

CommandArgumentItem::CommandArgumentItem(wxWindow* parent,
const conversation::ArgumentInfo& argInfo) :
_argInfo(argInfo)
Expand Down Expand Up @@ -119,4 +131,58 @@ wxWindow* ActorArgument::getEditWidget()
return _comboBox;
}

SoundShaderArgument::SoundShaderArgument(wxWindow* parent, const conversation::ArgumentInfo& argInfo) :
StringArgument(parent, argInfo)
{
_soundShaderPanel = new wxPanel(parent);

wxBoxSizer* shaderHBox = new wxBoxSizer(wxHORIZONTAL);
_soundShaderPanel->SetSizer(shaderHBox);

_entry->SetMinSize(wxSize(100, -1));
_entry->Reparent(_soundShaderPanel);

shaderHBox->Add(_entry, 1, wxEXPAND);

// Create the icon button to open the ShaderChooser
wxButton* selectShaderButton = new wxBitmapButton(_soundShaderPanel, wxID_ANY,
wxArtProvider::GetBitmap(GlobalUIManager().ArtIdPrefix() + FOLDER_ICON));

selectShaderButton->Bind(wxEVT_BUTTON, [&](wxCommandEvent& ev)
{
pickSoundShader();
});

shaderHBox->Add(selectShaderButton, 0, wxLEFT, 6);
}

wxWindow* SoundShaderArgument::getEditWidget()
{
return _soundShaderPanel;
}

std::string SoundShaderArgument::getValue()
{
return _entry->GetValue().ToStdString();
}

void SoundShaderArgument::setValueFromString(const std::string& value)
{
_entry->SetValue(value);
}

void SoundShaderArgument::pickSoundShader()
{
IResourceChooser* chooser = GlobalDialogManager().createSoundShaderChooser(wxGetTopLevelParent(_entry));

std::string picked = chooser->chooseResource(getValue());

if (!picked.empty())
{
setValueFromString(picked);
}

chooser->destroyDialog();
}

} // namespace ui
21 changes: 21 additions & 0 deletions plugins/dm.conversation/CommandArgumentItem.h
Expand Up @@ -9,6 +9,7 @@ class wxStaticText;
class wxTextCtrl;
class wxCheckBox;
class wxChoice;
class wxPanel;

namespace ui
{
Expand Down Expand Up @@ -122,4 +123,24 @@ class ActorArgument :
virtual void setValueFromString(const std::string& value);
};

/**
* greebo: This is an item querying a sound shader
*/
class SoundShaderArgument :
public StringArgument
{
private:
wxPanel* _soundShaderPanel;

public:
SoundShaderArgument(wxWindow* parent, const conversation::ArgumentInfo& argInfo);

virtual wxWindow* getEditWidget() override;
virtual std::string getValue() override;
virtual void setValueFromString(const std::string& value) override;

private:
void pickSoundShader();
};

} // namespace ui
5 changes: 4 additions & 1 deletion plugins/dm.conversation/CommandEditor.cpp
Expand Up @@ -240,10 +240,13 @@ void CommandEditor::createArgumentWidgets(int commandTypeID)
item = CommandArgumentItemPtr(new StringArgument(argPanel, argInfo));
break;
case conversation::ArgumentInfo::ARGTYPE_VECTOR:
case conversation::ArgumentInfo::ARGTYPE_SOUNDSHADER:
// Create a new string argument item
item = CommandArgumentItemPtr(new StringArgument(argPanel, argInfo));
break;
case conversation::ArgumentInfo::ARGTYPE_SOUNDSHADER:
// Create a new sound shader argument item
item = CommandArgumentItemPtr(new SoundShaderArgument(argPanel, argInfo));
break;
case conversation::ArgumentInfo::ARGTYPE_ACTOR:
// Create a new actor argument item
item = CommandArgumentItemPtr(new ActorArgument(argPanel, argInfo, _conversation.actors));
Expand Down

0 comments on commit 1853bfa

Please sign in to comment.