1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
|
#include "CommandArgumentItem.h"
#include "ui/ianimationchooser.h"
#include "ui/idialogmanager.h"
#include "ui/iresourcechooser.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 "wxutil/Bitmap.h"
#include <wx/bmpbuttn.h>
#include "wxutil/ChoiceHelper.h"
#include <fmt/format.h>
#include "CommandEditor.h"
#include "ActorNodeFinder.h"
namespace ui
{
namespace
{
const char* const FOLDER_ICON = "folder16.png";
}
CommandArgumentItem::CommandArgumentItem(CommandEditor& owner, wxWindow* parent,
const conversation::ArgumentInfo& argInfo) :
_owner(owner),
_argInfo(argInfo)
{
// Pack the label into an eventbox
_labelBox = new wxStaticText(parent, wxID_ANY, _argInfo.title + ":");
_labelBox->SetToolTip(argInfo.description);
// Pack the description widget into an eventbox
_descBox = new wxStaticText(parent, wxID_ANY, "?");
_descBox->SetFont(_descBox->GetFont().Bold());
_descBox->SetToolTip(argInfo.description);
}
// Retrieve the label widget
wxWindow* CommandArgumentItem::getLabelWidget()
{
return _labelBox;
}
wxWindow* CommandArgumentItem::getHelpWidget()
{
return _descBox;
}
// StringArgument
StringArgument::StringArgument(CommandEditor& owner, wxWindow* parent,
const conversation::ArgumentInfo& argInfo) :
CommandArgumentItem(owner, parent, argInfo)
{
_entry = new wxTextCtrl(parent, wxID_ANY);
}
wxWindow* StringArgument::getEditWidget()
{
return _entry;
}
std::string StringArgument::getValue()
{
return _entry->GetValue().ToStdString();
}
void StringArgument::setValueFromString(const std::string& value)
{
_entry->SetValue(value);
}
// Boolean argument
BooleanArgument::BooleanArgument(CommandEditor& owner, wxWindow* parent, const conversation::ArgumentInfo& argInfo) :
CommandArgumentItem(owner, parent, argInfo)
{
_checkButton = new wxCheckBox(parent, wxID_ANY, argInfo.title);
}
wxWindow* BooleanArgument::getEditWidget()
{
return _checkButton;
}
std::string BooleanArgument::getValue()
{
return _checkButton->GetValue() ? "1" : "";
}
void BooleanArgument::setValueFromString(const std::string& value)
{
_checkButton->SetValue(value == "1");
}
// Actor Argument
ActorArgument::ActorArgument(CommandEditor& owner,
wxWindow* parent,
const conversation::ArgumentInfo& argInfo,
const conversation::Conversation::ActorMap& actors) :
CommandArgumentItem(owner, parent, argInfo)
{
_comboBox = new wxChoice(parent, wxID_ANY);
// Fill the actor list
conversation::Conversation::ActorMap dummy = actors;
for (conversation::Conversation::ActorMap::const_iterator i = dummy.begin();
i != dummy.end(); ++i)
{
std::string actorStr = fmt::format(_("Actor {0:d} ({1})"), i->first, i->second);
// Store the actor ID into a client data object and pass it along
_comboBox->Append(actorStr, new wxStringClientData(string::to_string(i->first)));
}
}
std::string ActorArgument::getValue()
{
return string::to_string(wxutil::ChoiceHelper::GetSelectionId(_comboBox));
}
void ActorArgument::setValueFromString(const std::string& value)
{
wxutil::ChoiceHelper::SelectItemByStoredId(_comboBox, string::convert<int>(value, wxNOT_FOUND));
}
wxWindow* ActorArgument::getEditWidget()
{
return _comboBox;
}
SoundShaderArgument::SoundShaderArgument(CommandEditor& owner,
wxWindow* parent, const conversation::ArgumentInfo& argInfo) :
StringArgument(owner, 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,
wxutil::GetLocalBitmap(FOLDER_ICON));
selectShaderButton->SetToolTip(_("Browse Sound Shaders"));
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();
}
AnimationArgument::AnimationArgument(CommandEditor& owner,
wxWindow* parent, const conversation::ArgumentInfo& argInfo) :
StringArgument(owner, parent, argInfo)
{
_animPanel = new wxPanel(parent);
wxBoxSizer* hbox = new wxBoxSizer(wxHORIZONTAL);
_animPanel->SetSizer(hbox);
_entry->SetMinSize(wxSize(100, -1));
_entry->Reparent(_animPanel);
hbox->Add(_entry, 1, wxEXPAND);
// Create the icon button to open the
wxButton* selectButton = new wxBitmapButton(_animPanel, wxID_ANY,
wxutil::GetLocalBitmap(FOLDER_ICON));
selectButton->SetToolTip(_("Browse Animations"));
selectButton->Bind(wxEVT_BUTTON, [&](wxCommandEvent& ev)
{
pickAnimation();
});
hbox->Add(selectButton, 0, wxLEFT, 6);
}
wxWindow* AnimationArgument::getEditWidget()
{
return _animPanel;
}
std::string AnimationArgument::getValue()
{
return _entry->GetValue().ToStdString();
}
void AnimationArgument::setValueFromString(const std::string& value)
{
_entry->SetValue(value);
}
void AnimationArgument::pickAnimation()
{
// Find out which actor we're talking about
int actorId = _owner.getCommand().actor;
std::string preselectModel = std::string();
if (actorId != -1 && _owner.getConversation().actors.find(actorId) != _owner.getConversation().actors.end())
{
std::string actorName = _owner.getConversation().actors.find(actorId)->second;
// Try to find the entity in the current map
scene::ActorNodeFinder finder(actorName);
GlobalSceneGraph().root()->traverse(finder);
if (finder.getFoundNode())
{
// Found the corresponding entity, get the model name
Entity* entity = Node_getEntity(finder.getFoundNode());
assert(entity != nullptr);
preselectModel = entity->getKeyValue("model");
}
}
IAnimationChooser* chooser = GlobalDialogManager().createAnimationChooser(wxGetTopLevelParent(_entry));
IAnimationChooser::Result result = chooser->runDialog(preselectModel, getValue());
if (!result.cancelled())
{
setValueFromString(result.anim);
}
chooser->destroyDialog();
}
} // namespace ui
|