13 using namespace bl::gui;
17 bool validFile(
const std::string& f) {
return !f.empty() && bl::util::FileUtil::exists(f); }
25 constexpr
const char* DefaultAnim =
"1/down.anim";
27 window = Window::create(LinePacker::create(LinePacker::Vertical, 4),
"Animation Picker");
28 window->getSignal(Event::Closed).willAlwaysCall([
this](
const Event&, Element*) {
hide(); });
30 Box::Ptr row = Box::create(LinePacker::create(LinePacker::Horizontal, 4));
31 Button::Ptr pickBut = Button::create(
"Choose Animation");
32 pickBut->getSignal(Event::LeftClicked).willAlwaysCall([
this](
const Event&, Element*) {
33 filePicker.emplace(path,
34 std::vector<std::string>{
"anim"},
35 std::bind(&AnimationWindow::packAnim,
this, std::placeholders::_1),
37 filePicker.value().close();
39 window->setForceFocus(
true);
41 window->setForceFocus(
false);
42 filePicker.value().open(FilePicker::PickExisting,
"Select Animation", parent);
44 fileLabel = Label::create(DefaultAnim);
45 fileLabel->setColor(sf::Color::Cyan, sf::Color::Transparent);
46 row->pack(pickBut,
false,
true);
47 row->pack(fileLabel,
true,
true);
50 Button::Ptr editBut = Button::create(
"Open Editor");
51 editBut->getSignal(Event::LeftClicked).willAlwaysCall([](
const Event&, Element*) {
54 window->pack(editBut,
false,
false);
56 row = Box::create(LinePacker::create(LinePacker::Horizontal, 4));
57 auto src = AnimationManager::load(
59 animation = Animation::create(src);
60 row->pack(animation,
true,
true);
61 window->pack(row,
true,
true);
63 row = Box::create(LinePacker::create(LinePacker::Horizontal, 4));
64 Button::Ptr chooseBut = Button::create(
"Use Animation");
65 chooseBut->getSignal(Event::LeftClicked).willAlwaysCall([
this](
const Event&, Element*) {
66 if (validFile(fileLabel->getText())) {
67 bl::dialog::tinyfd_messageBox(
68 "No File",
"Please select an animation",
"ok",
"error", 1);
72 chooseCb(fileLabel->getText());
75 chooseBut->setColor(sf::Color::Green, sf::Color::Black);
76 Button::Ptr cancelBut = Button::create(
"Cancel");
77 cancelBut->getSignal(Event::LeftClicked).willAlwaysCall([
this](
const Event&, Element*) {
80 cancelBut->setColor(sf::Color::Red, sf::Color::Black);
81 row->pack(chooseBut,
false,
true);
82 row->pack(cancelBut,
false,
true);
90 if (file !=
"<no anim selected>") { packAnim(file); }
91 window->setForceFocus(
true);
94 void AnimationWindow::packAnim(
const std::string& f) {
95 const std::string af = characterMode ? bl::util::FileUtil::getPath(f) : f;
96 const std::string vf = characterMode ? bl::util::FileUtil::joinPath(af,
"down.anim") : af;
97 fileLabel->setText(af);
98 animSrc = AnimationManager::load(bl::util::FileUtil::joinPath(path, vf));
101 sf::Vector2f size = animSrc->getMaxSize();
102 if (size.x > 400.f) {
103 size.y *= 400.f / size.x;
105 animation->scaleToSize(size);
107 if (size.y > 400.f) {
108 size.x *= 400.f / size.y;
110 animation->scaleToSize(size);
112 animation->setAnimation(animSrc);
114 if (filePicker.has_value()) {
115 filePicker.value().close();
117 window->setForceFocus(
true);
123 window->setForceFocus(
false);
125 if (filePicker.has_value()) {
126 filePicker.value().close();
All classes and functionality used for implementing the game editor.
void openAnimationEditor()
static const std::string & CharacterAnimationPath()
std::function< void()> CloseCb
Called when the window is closed.
std::function< void(const std::string &)> ChooseCb
Called when an animation is chosen.
AnimationWindow(bool characterMode, const ChooseCb &chooseCb, const CloseCb &closeCb)
Construct a new Animation Window.
void open(bl::gui::GUI *parent, const std::string &path, const std::string &file)
Opens the animation picker window.
void hide()
Removes the window from view.