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