MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / commonSetup

Method commonSetup

source/frontend/StarQuestInterface.cpp:292–327  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

290QuestPane::QuestPane(QuestPtr const& quest, PlayerPtr player) : Pane(), m_quest(quest), m_player(std::move(player)) {}
291
292void QuestPane::commonSetup(Json config, String bodyText, String const& portraitName) {
293 GuiReader reader;
294
295 reader.registerCallback("close", [=](Widget*) { close(); });
296 reader.registerCallback("btnDecline", [=](Widget*) { decline(); });
297 reader.registerCallback("btnAccept", [=](Widget*) { accept(); });
298 reader.construct(config.get("paneLayout"), this);
299
300 if (auto titleLabel = fetchChild<LabelWidget>("lblQuestTitle"))
301 titleLabel->setText(m_quest->title());
302 if (auto bodyLabel = fetchChild<LabelWidget>("lblQuestBody"))
303 bodyLabel->setText(bodyText);
304
305 if (auto portraitImage = fetchChild<ImageWidget>("portraitImage")) {
306 Maybe<List<Drawable>> portrait = m_quest->portrait(portraitName);
307 portraitImage->setDrawables(portrait.value({}));
308 }
309
310 if (auto portraitTitleLabel = fetchChild<LabelWidget>("portraitTitle")) {
311 Maybe<String> portraitTitle = m_quest->portraitTitle(portraitName);
312 String text = m_quest->portraitTitle(portraitName).value("");
313 Maybe<unsigned> charLimit = portraitTitleLabel->getTextCharLimit();
314 portraitTitleLabel->setText(text);
315 }
316
317 if (auto rewardItemsWidget = fetchChild<ItemGridWidget>("rewardItems")) {
318 auto rewardItems = make_shared<ItemBag>(5);
319 for (auto const& reward : m_quest->rewards())
320 rewardItems->addItems(reward->clone());
321 rewardItemsWidget->setItemBag(rewardItems);
322 }
323
324 auto sound = Random::randValueFrom(config.get("onShowSound").toArray(), "").toString();
325 if (!sound.empty())
326 context()->playAudio(sound);
327}
328
329void QuestPane::close() {
330 dismiss();

Callers

nothing calls this directly

Calls 15

setDrawablesMethod · 0.80
portraitTitleMethod · 0.80
getTextCharLimitMethod · 0.80
rewardsMethod · 0.80
setItemBagMethod · 0.80
toArrayMethod · 0.80
playAudioMethod · 0.80
registerCallbackMethod · 0.45
constructMethod · 0.45
getMethod · 0.45
setTextMethod · 0.45
titleMethod · 0.45

Tested by

no test coverage detected