| 353 | } |
| 354 | |
| 355 | LuaCallbacks Pane::makePaneCallbacks() { |
| 356 | LuaCallbacks callbacks; |
| 357 | |
| 358 | callbacks.registerCallback("toWidget", [this]() -> LuaCallbacks { |
| 359 | return LuaBindings::makeWidgetCallbacks(this, reader()); |
| 360 | }); |
| 361 | |
| 362 | callbacks.registerCallback("dismiss", [this]() { dismiss(); }); |
| 363 | |
| 364 | callbacks.registerCallback("playSound", |
| 365 | [this](String const& audio, Maybe<int> loops, Maybe<float> volume) { |
| 366 | auto assets = Root::singleton().assets(); |
| 367 | auto config = Root::singleton().configuration(); |
| 368 | auto audioInstance = make_shared<AudioInstance>(*assets->audio(audio)); |
| 369 | audioInstance->setVolume(volume.value(1.0)); |
| 370 | audioInstance->setLoops(loops.value(0)); |
| 371 | auto& guiContext = GuiContext::singleton(); |
| 372 | guiContext.playAudio(audioInstance); |
| 373 | m_playingSounds.append({audio, std::move(audioInstance)}); |
| 374 | }); |
| 375 | |
| 376 | callbacks.registerCallback("stopAllSounds", [this](Maybe<String> const& audio) { |
| 377 | m_playingSounds.filter([audio](pair<String, AudioInstancePtr> const& p) { |
| 378 | if (!audio || p.first == *audio) { |
| 379 | p.second->stop(); |
| 380 | return false; |
| 381 | } |
| 382 | return true; |
| 383 | }); |
| 384 | }); |
| 385 | |
| 386 | callbacks.registerCallback("setTitle", [this](String const& title, String const& subTitle) { |
| 387 | setTitleString(title, subTitle); |
| 388 | }); |
| 389 | |
| 390 | callbacks.registerCallback("setTitleIcon", [this](String const& image) { |
| 391 | if (auto icon = as<ImageWidget>(titleIcon())) |
| 392 | icon->setImage(image); |
| 393 | }); |
| 394 | |
| 395 | callbacks.registerCallback("getPosition", [this]() -> Vec2I { return relativePosition(); }); |
| 396 | callbacks.registerCallback("setPosition", [this](Vec2I const& position) { setPosition(position); }); |
| 397 | callbacks.registerCallback("getSize", [this]() -> Vec2I { return size(); }); |
| 398 | callbacks.registerCallback("setSize", [this](Vec2I const& size) { setSize(size); }); |
| 399 | |
| 400 | callbacks.registerCallback("addWidget", [this](Json const& newWidgetConfig, Maybe<String> const& newWidgetName) -> LuaCallbacks { |
| 401 | String name = newWidgetName.value(toString(Random::randu64())); |
| 402 | WidgetPtr newWidget = reader()->makeSingle(name, newWidgetConfig); |
| 403 | this->addChild(name, newWidget); |
| 404 | return LuaBindings::makeWidgetCallbacks(newWidget.get(), reader()); |
| 405 | }); |
| 406 | |
| 407 | callbacks.registerCallback("removeWidget", [this](String const& widgetName) -> bool |
| 408 | { return this->removeChild(widgetName); }); |
| 409 | |
| 410 | callbacks.registerCallback("scale", []() -> int { return GuiContext::singleton().interfaceScale(); }); |
| 411 | callbacks.registerCallback("isDisplayed", [this]() { return isDisplayed(); }); |
| 412 | callbacks.registerCallback("hasFocus", [this]() { return hasFocus(); }); |
nothing calls this directly
no test coverage detected