InterfaceObjectConfigurable.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. /*
  2. * InterfaceBuilder.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "InterfaceObjectConfigurable.h"
  12. #include "../CGameInfo.h"
  13. #include "../CPlayerInterface.h"
  14. #include "../gui/CGuiHandler.h"
  15. #include "../gui/ShortcutHandler.h"
  16. #include "../gui/Shortcut.h"
  17. #include "../widgets/CComponent.h"
  18. #include "../widgets/Buttons.h"
  19. #include "../widgets/MiscWidgets.h"
  20. #include "../widgets/ObjectLists.h"
  21. #include "../widgets/Slider.h"
  22. #include "../widgets/TextControls.h"
  23. #include "../windows/GUIClasses.h"
  24. #include "../windows/InfoWindows.h"
  25. #include "../../lib/CGeneralTextHandler.h"
  26. #include "../../lib/filesystem/ResourceID.h"
  27. InterfaceObjectConfigurable::InterfaceObjectConfigurable(const JsonNode & config, int used, Point offset):
  28. InterfaceObjectConfigurable(used, offset)
  29. {
  30. build(config);
  31. }
  32. InterfaceObjectConfigurable::InterfaceObjectConfigurable(int used, Point offset):
  33. CIntObject(used, offset)
  34. {
  35. REGISTER_BUILDER("picture", &InterfaceObjectConfigurable::buildPicture);
  36. REGISTER_BUILDER("image", &InterfaceObjectConfigurable::buildImage);
  37. REGISTER_BUILDER("texture", &InterfaceObjectConfigurable::buildTexture);
  38. REGISTER_BUILDER("animation", &InterfaceObjectConfigurable::buildAnimation);
  39. REGISTER_BUILDER("label", &InterfaceObjectConfigurable::buildLabel);
  40. REGISTER_BUILDER("toggleGroup", &InterfaceObjectConfigurable::buildToggleGroup);
  41. REGISTER_BUILDER("toggleButton", &InterfaceObjectConfigurable::buildToggleButton);
  42. REGISTER_BUILDER("button", &InterfaceObjectConfigurable::buildButton);
  43. REGISTER_BUILDER("labelGroup", &InterfaceObjectConfigurable::buildLabelGroup);
  44. REGISTER_BUILDER("slider", &InterfaceObjectConfigurable::buildSlider);
  45. REGISTER_BUILDER("layout", &InterfaceObjectConfigurable::buildLayout);
  46. }
  47. void InterfaceObjectConfigurable::registerBuilder(const std::string & type, BuilderFunction f)
  48. {
  49. builders[type] = f;
  50. }
  51. void InterfaceObjectConfigurable::addCallback(const std::string & callbackName, std::function<void(int)> callback)
  52. {
  53. callbacks[callbackName] = callback;
  54. }
  55. void InterfaceObjectConfigurable::deleteWidget(const std::string & name)
  56. {
  57. auto iter = widgets.find(name);
  58. if(iter != widgets.end())
  59. widgets.erase(iter);
  60. }
  61. void InterfaceObjectConfigurable::loadCustomBuilders(const JsonNode & config)
  62. {
  63. for(auto & item : config.Struct())
  64. {
  65. std::string typeName = item.first;
  66. JsonNode baseConfig = item.second;
  67. auto const & functor = [this, baseConfig](const JsonNode & widgetConfig) -> std::shared_ptr<CIntObject>
  68. {
  69. JsonNode actualConfig = widgetConfig;
  70. JsonUtils::mergeCopy(actualConfig, baseConfig);
  71. return this->buildWidget(actualConfig);
  72. };
  73. registerBuilder(typeName, functor);
  74. }
  75. }
  76. void InterfaceObjectConfigurable::build(const JsonNode &config)
  77. {
  78. OBJ_CONSTRUCTION;
  79. logGlobal->debug("Building configurable interface object");
  80. auto * items = &config;
  81. if(config.getType() == JsonNode::JsonType::DATA_STRUCT)
  82. {
  83. if (!config["library"].isNull())
  84. {
  85. const JsonNode library(ResourceID(config["library"].String()));
  86. loadCustomBuilders(library);
  87. }
  88. loadCustomBuilders(config["customTypes"]);
  89. for(auto & item : config["variables"].Struct())
  90. {
  91. logGlobal->debug("Read variable named %s", item.first);
  92. variables[item.first] = item.second;
  93. }
  94. items = &config["items"];
  95. }
  96. for(const auto & item : items->Vector())
  97. addWidget(item["name"].String(), buildWidget(item));
  98. }
  99. void InterfaceObjectConfigurable::addConditional(const std::string & name, bool active)
  100. {
  101. conditionals[name] = active;
  102. }
  103. void InterfaceObjectConfigurable::addWidget(const std::string & namePreferred, std::shared_ptr<CIntObject> widget)
  104. {
  105. static const std::string unnamedObjectPrefix = "__widget_";
  106. std::string nameActual;
  107. if (widgets.count(namePreferred) == 0)
  108. nameActual = namePreferred;
  109. else
  110. logGlobal->error("Duplicated widget name: '%s'", namePreferred);
  111. if (nameActual.empty())
  112. nameActual = unnamedObjectPrefix + std::to_string(unnamedObjectId++);
  113. logGlobal->debug("Building widget with name %s", nameActual);
  114. widgets[nameActual] = widget;
  115. }
  116. std::string InterfaceObjectConfigurable::readText(const JsonNode & config) const
  117. {
  118. if(config.isNull())
  119. return "";
  120. std::string s = config.String();
  121. logGlobal->debug("Reading text from translations by key: %s", s);
  122. return CGI->generaltexth->translate(s);
  123. }
  124. Point InterfaceObjectConfigurable::readPosition(const JsonNode & config) const
  125. {
  126. Point p;
  127. logGlobal->debug("Reading point");
  128. p.x = config["x"].Integer();
  129. p.y = config["y"].Integer();
  130. return p;
  131. }
  132. Rect InterfaceObjectConfigurable::readRect(const JsonNode & config) const
  133. {
  134. Rect p;
  135. logGlobal->debug("Reading rect");
  136. p.x = config["x"].Integer();
  137. p.y = config["y"].Integer();
  138. p.w = config["w"].Integer();
  139. p.h = config["h"].Integer();
  140. return p;
  141. }
  142. ETextAlignment InterfaceObjectConfigurable::readTextAlignment(const JsonNode & config) const
  143. {
  144. logGlobal->debug("Reading text alignment");
  145. if(!config.isNull())
  146. {
  147. if(config.String() == "center")
  148. return ETextAlignment::CENTER;
  149. if(config.String() == "left")
  150. return ETextAlignment::TOPLEFT;
  151. if(config.String() == "right")
  152. return ETextAlignment::BOTTOMRIGHT;
  153. }
  154. logGlobal->debug("Uknown text alignment attribute");
  155. return ETextAlignment::CENTER;
  156. }
  157. ColorRGBA InterfaceObjectConfigurable::readColor(const JsonNode & config) const
  158. {
  159. logGlobal->debug("Reading color");
  160. if(!config.isNull())
  161. {
  162. if(config.String() == "yellow")
  163. return Colors::YELLOW;
  164. if(config.String() == "white")
  165. return Colors::WHITE;
  166. if(config.String() == "gold")
  167. return Colors::METALLIC_GOLD;
  168. if(config.String() == "green")
  169. return Colors::GREEN;
  170. if(config.String() == "orange")
  171. return Colors::ORANGE;
  172. if(config.String() == "bright-yellow")
  173. return Colors::BRIGHT_YELLOW;
  174. }
  175. logGlobal->debug("Uknown color attribute");
  176. return Colors::DEFAULT_KEY_COLOR;
  177. }
  178. EFonts InterfaceObjectConfigurable::readFont(const JsonNode & config) const
  179. {
  180. logGlobal->debug("Reading font");
  181. if(!config.isNull())
  182. {
  183. if(config.String() == "big")
  184. return EFonts::FONT_BIG;
  185. if(config.String() == "medium")
  186. return EFonts::FONT_MEDIUM;
  187. if(config.String() == "small")
  188. return EFonts::FONT_SMALL;
  189. if(config.String() == "tiny")
  190. return EFonts::FONT_TINY;
  191. if(config.String() == "calisto")
  192. return EFonts::FONT_CALLI;
  193. }
  194. logGlobal->debug("Uknown font attribute");
  195. return EFonts::FONT_TIMES;
  196. }
  197. std::pair<std::string, std::string> InterfaceObjectConfigurable::readHintText(const JsonNode & config) const
  198. {
  199. logGlobal->debug("Reading hint text");
  200. std::pair<std::string, std::string> result;
  201. if(!config.isNull())
  202. {
  203. if(config.getType() == JsonNode::JsonType::DATA_STRUCT)
  204. {
  205. result.first = readText(config["hover"]);
  206. result.second = readText(config["help"]);
  207. return result;
  208. }
  209. if(config.getType() == JsonNode::JsonType::DATA_STRING)
  210. {
  211. logGlobal->debug("Reading hint text (help) from generaltext handler:%sd", config.String());
  212. result.first = CGI->generaltexth->translate( config.String(), "hover");
  213. result.second = CGI->generaltexth->translate( config.String(), "help");
  214. }
  215. }
  216. return result;
  217. }
  218. EShortcut InterfaceObjectConfigurable::readHotkey(const JsonNode & config) const
  219. {
  220. logGlobal->debug("Reading hotkey");
  221. if(config.getType() != JsonNode::JsonType::DATA_STRING)
  222. {
  223. logGlobal->error("Invalid hotket format in interface configuration! Expected string!", config.String());
  224. return EShortcut::NONE;
  225. }
  226. EShortcut result = GH.shortcuts().findShortcut(config.String());
  227. if (result == EShortcut::NONE)
  228. logGlobal->error("Invalid hotkey '%s' in interface configuration!", config.String());
  229. return result;;
  230. }
  231. std::shared_ptr<CPicture> InterfaceObjectConfigurable::buildPicture(const JsonNode & config) const
  232. {
  233. logGlobal->debug("Building widget CPicture");
  234. auto image = config["image"].String();
  235. auto position = readPosition(config["position"]);
  236. auto pic = std::make_shared<CPicture>(image, position.x, position.y);
  237. if(!config["visible"].isNull())
  238. pic->visible = config["visible"].Bool();
  239. if ( config["playerColored"].Bool() && LOCPLINT)
  240. pic->colorize(LOCPLINT->playerID);
  241. return pic;
  242. }
  243. std::shared_ptr<CLabel> InterfaceObjectConfigurable::buildLabel(const JsonNode & config) const
  244. {
  245. logGlobal->debug("Building widget CLabel");
  246. auto font = readFont(config["font"]);
  247. auto alignment = readTextAlignment(config["alignment"]);
  248. auto color = readColor(config["color"]);
  249. auto text = readText(config["text"]);
  250. auto position = readPosition(config["position"]);
  251. return std::make_shared<CLabel>(position.x, position.y, font, alignment, color, text);
  252. }
  253. std::shared_ptr<CToggleGroup> InterfaceObjectConfigurable::buildToggleGroup(const JsonNode & config) const
  254. {
  255. logGlobal->debug("Building widget CToggleGroup");
  256. auto position = readPosition(config["position"]);
  257. auto group = std::make_shared<CToggleGroup>(0);
  258. group->pos += position;
  259. if(!config["items"].isNull())
  260. {
  261. OBJ_CONSTRUCTION_TARGETED(group.get());
  262. int itemIdx = -1;
  263. for(const auto & item : config["items"].Vector())
  264. {
  265. itemIdx = item["index"].isNull() ? itemIdx + 1 : item["index"].Integer();
  266. auto newToggle = std::dynamic_pointer_cast<CToggleButton>(buildWidget(item));
  267. group->addToggle(itemIdx, newToggle);
  268. }
  269. }
  270. if(!config["selected"].isNull())
  271. group->setSelected(config["selected"].Integer());
  272. if(!config["callback"].isNull())
  273. group->addCallback(callbacks.at(config["callback"].String()));
  274. return group;
  275. }
  276. std::shared_ptr<CToggleButton> InterfaceObjectConfigurable::buildToggleButton(const JsonNode & config) const
  277. {
  278. logGlobal->debug("Building widget CToggleButton");
  279. auto position = readPosition(config["position"]);
  280. auto image = config["image"].String();
  281. auto help = readHintText(config["help"]);
  282. auto button = std::make_shared<CToggleButton>(position, image, help);
  283. if(!config["items"].isNull())
  284. {
  285. for(const auto & item : config["items"].Vector())
  286. {
  287. button->addOverlay(buildWidget(item));
  288. }
  289. }
  290. if(!config["selected"].isNull())
  291. button->setSelected(config["selected"].Bool());
  292. if(!config["imageOrder"].isNull())
  293. {
  294. auto imgOrder = config["imageOrder"].Vector();
  295. assert(imgOrder.size() >= 4);
  296. button->setImageOrder(imgOrder[0].Integer(), imgOrder[1].Integer(), imgOrder[2].Integer(), imgOrder[3].Integer());
  297. }
  298. loadToggleButtonCallback(button, config["callback"]);
  299. return button;
  300. }
  301. std::shared_ptr<CButton> InterfaceObjectConfigurable::buildButton(const JsonNode & config) const
  302. {
  303. logGlobal->debug("Building widget CButton");
  304. auto position = readPosition(config["position"]);
  305. auto image = config["image"].String();
  306. auto help = readHintText(config["help"]);
  307. auto button = std::make_shared<CButton>(position, image, help);
  308. if(!config["items"].isNull())
  309. {
  310. for(const auto & item : config["items"].Vector())
  311. {
  312. button->addOverlay(buildWidget(item));
  313. }
  314. }
  315. if(!config["imageOrder"].isNull())
  316. {
  317. auto imgOrder = config["imageOrder"].Vector();
  318. assert(imgOrder.size() >= 4);
  319. button->setImageOrder(imgOrder[0].Integer(), imgOrder[1].Integer(), imgOrder[2].Integer(), imgOrder[3].Integer());
  320. }
  321. loadButtonBorderColor(button, config["borderColor"]);
  322. loadButtonCallback(button, config["callback"]);
  323. loadButtonHotkey(button, config["hotkey"]);
  324. return button;
  325. }
  326. void InterfaceObjectConfigurable::loadButtonBorderColor(std::shared_ptr<CButton> button, const JsonNode & config) const
  327. {
  328. if (config.isNull())
  329. return;
  330. auto color = readColor(config);
  331. button->setBorderColor(color);
  332. }
  333. void InterfaceObjectConfigurable::loadToggleButtonCallback(std::shared_ptr<CToggleButton> button, const JsonNode & config) const
  334. {
  335. if(config.isNull())
  336. return;
  337. std::string callbackName = config.String();
  338. if (callbacks.count(callbackName) > 0)
  339. button->addCallback(callbacks.at(callbackName));
  340. else
  341. logGlobal->error("Invalid callback '%s' in widget", callbackName );
  342. }
  343. void InterfaceObjectConfigurable::loadButtonCallback(std::shared_ptr<CButton> button, const JsonNode & config) const
  344. {
  345. if(config.isNull())
  346. return;
  347. std::string callbackName = config.String();
  348. if (callbacks.count(callbackName) > 0)
  349. button->addCallback(std::bind(callbacks.at(callbackName), 0));
  350. else
  351. logGlobal->error("Invalid callback '%s' in widget", callbackName );
  352. }
  353. void InterfaceObjectConfigurable::loadButtonHotkey(std::shared_ptr<CButton> button, const JsonNode & config) const
  354. {
  355. if(config.isNull())
  356. return;
  357. if(config.getType() != JsonNode::JsonType::DATA_STRING)
  358. {
  359. logGlobal->error("Invalid shortcut format - string expected!");
  360. return;
  361. }
  362. button->assignedKey = readHotkey(config);
  363. auto target = shortcuts.find(button->assignedKey);
  364. if (target == shortcuts.end())
  365. return;
  366. button->addCallback(target->second.callback);
  367. target->second.assignedToButton = true;
  368. }
  369. std::shared_ptr<CLabelGroup> InterfaceObjectConfigurable::buildLabelGroup(const JsonNode & config) const
  370. {
  371. logGlobal->debug("Building widget CLabelGroup");
  372. auto font = readFont(config["font"]);
  373. auto alignment = readTextAlignment(config["alignment"]);
  374. auto color = readColor(config["color"]);
  375. auto group = std::make_shared<CLabelGroup>(font, alignment, color);
  376. if(!config["items"].isNull())
  377. {
  378. for(const auto & item : config["items"].Vector())
  379. {
  380. auto position = readPosition(item["position"]);
  381. auto text = readText(item["text"]);
  382. group->add(position.x, position.y, text);
  383. }
  384. }
  385. return group;
  386. }
  387. std::shared_ptr<CSlider> InterfaceObjectConfigurable::buildSlider(const JsonNode & config) const
  388. {
  389. logGlobal->debug("Building widget CSlider");
  390. auto position = readPosition(config["position"]);
  391. int length = config["size"].Integer();
  392. auto style = config["style"].String() == "brown" ? CSlider::BROWN : CSlider::BLUE;
  393. auto itemsVisible = config["itemsVisible"].Integer();
  394. auto itemsTotal = config["itemsTotal"].Integer();
  395. auto value = config["selected"].Integer();
  396. bool horizontal = config["orientation"].String() == "horizontal";
  397. const auto & result =
  398. std::make_shared<CSlider>(position, length, callbacks.at(config["callback"].String()), itemsVisible, itemsTotal, value, horizontal ? Orientation::HORIZONTAL : Orientation::VERTICAL, style);
  399. if (!config["scrollBounds"].isNull())
  400. {
  401. Rect bounds = readRect(config["scrollBounds"]);
  402. result->setScrollBounds(bounds);
  403. }
  404. return result;
  405. }
  406. std::shared_ptr<CAnimImage> InterfaceObjectConfigurable::buildImage(const JsonNode & config) const
  407. {
  408. logGlobal->debug("Building widget CAnimImage");
  409. auto position = readPosition(config["position"]);
  410. auto image = config["image"].String();
  411. int group = config["group"].isNull() ? 0 : config["group"].Integer();
  412. int frame = config["frame"].isNull() ? 0 : config["frame"].Integer();
  413. return std::make_shared<CAnimImage>(image, frame, group, position.x, position.y);
  414. }
  415. std::shared_ptr<CFilledTexture> InterfaceObjectConfigurable::buildTexture(const JsonNode & config) const
  416. {
  417. logGlobal->debug("Building widget CFilledTexture");
  418. auto image = config["image"].String();
  419. auto rect = readRect(config["rect"]);
  420. return std::make_shared<CFilledTexture>(image, rect);
  421. }
  422. /// Small helper class that provides ownership for shared_ptr's of child elements
  423. class InterfaceLayoutWidget : public CIntObject
  424. {
  425. public:
  426. std::vector<std::shared_ptr<CIntObject>> ownedChildren;
  427. InterfaceLayoutWidget();
  428. };
  429. InterfaceLayoutWidget::InterfaceLayoutWidget()
  430. :CIntObject()
  431. {
  432. setRedrawParent(true);
  433. }
  434. std::shared_ptr<CIntObject> InterfaceObjectConfigurable::buildLayout(const JsonNode & config)
  435. {
  436. logGlobal->debug("Building widget Layout");
  437. bool vertical = config["vertical"].Bool();
  438. bool horizontal = config["horizontal"].Bool();
  439. bool dynamic = config["dynamic"].Bool();
  440. int distance = config["distance"].Integer();
  441. std::string customType = config["customType"].String();
  442. auto position = readPosition(config["position"]);
  443. auto result = std::make_shared<InterfaceLayoutWidget>();
  444. result->moveBy(position);
  445. Point layoutPosition;
  446. for(auto item : config["items"].Vector())
  447. {
  448. if (item["type"].String().empty())
  449. item["type"].String() = customType;
  450. if (!item["created"].isNull())
  451. {
  452. std::string name = item["created"].String();
  453. if (conditionals.count(name) != 0)
  454. {
  455. if (!conditionals.at(name))
  456. continue;
  457. }
  458. else
  459. {
  460. logMod->warn("Unknown condition %s in widget!", name);
  461. }
  462. }
  463. auto widget = buildWidget(item);
  464. addWidget(item["name"].String(), widget);
  465. result->ownedChildren.push_back(widget);
  466. result->addChild(widget.get(), false);
  467. widget->moveBy(position + layoutPosition);
  468. if (dynamic && vertical)
  469. layoutPosition.y += widget->pos.h;
  470. if (dynamic && horizontal)
  471. layoutPosition.x += widget->pos.w;
  472. if (vertical)
  473. layoutPosition.y += distance;
  474. if (horizontal)
  475. layoutPosition.x += distance;
  476. }
  477. return result;
  478. }
  479. std::shared_ptr<CShowableAnim> InterfaceObjectConfigurable::buildAnimation(const JsonNode & config) const
  480. {
  481. logGlobal->debug("Building widget CShowableAnim");
  482. auto position = readPosition(config["position"]);
  483. auto image = config["image"].String();
  484. ui8 flags = 0;
  485. if(!config["repeat"].Bool())
  486. flags |= CShowableAnim::EFlags::PLAY_ONCE;
  487. int group = config["group"].isNull() ? 0 : config["group"].Integer();
  488. auto anim = std::make_shared<CShowableAnim>(position.x, position.y, image, flags, 4, group);
  489. if(!config["alpha"].isNull())
  490. anim->setAlpha(config["alpha"].Integer());
  491. if(!config["callback"].isNull())
  492. anim->callback = std::bind(callbacks.at(config["callback"].String()), 0);
  493. if(!config["frames"].isNull())
  494. {
  495. auto b = config["frames"]["start"].Integer();
  496. auto e = config["frames"]["end"].Integer();
  497. anim->set(group, b, e);
  498. }
  499. return anim;
  500. }
  501. std::shared_ptr<CIntObject> InterfaceObjectConfigurable::buildWidget(JsonNode config) const
  502. {
  503. assert(!config.isNull());
  504. logGlobal->debug("Building widget from config");
  505. //overrides from variables
  506. for(auto & item : config["overrides"].Struct())
  507. {
  508. logGlobal->debug("Config attribute %s was overriden by variable %s", item.first, item.second.String());
  509. config[item.first] = variables[item.second.String()];
  510. }
  511. auto type = config["type"].String();
  512. auto buildIterator = builders.find(type);
  513. if(buildIterator != builders.end())
  514. return (buildIterator->second)(config);
  515. logGlobal->error("Builder with type %s is not registered", type);
  516. return nullptr;
  517. }
  518. void InterfaceObjectConfigurable::setShortcutBlocked(EShortcut shortcut, bool isBlocked)
  519. {
  520. auto target = shortcuts.find(shortcut);
  521. if (target == shortcuts.end())
  522. return;
  523. target->second.blocked = isBlocked;
  524. for (auto & entry : widgets)
  525. {
  526. auto button = std::dynamic_pointer_cast<CButton>(entry.second);
  527. if (button && button->assignedKey == shortcut)
  528. button->block(isBlocked);
  529. }
  530. }
  531. void InterfaceObjectConfigurable::addShortcut(EShortcut shortcut, std::function<void()> callback)
  532. {
  533. assert(shortcuts.count(shortcut) == 0);
  534. shortcuts[shortcut].callback = callback;
  535. }
  536. void InterfaceObjectConfigurable::keyPressed(EShortcut key)
  537. {
  538. auto target = shortcuts.find(key);
  539. if (target == shortcuts.end())
  540. return;
  541. if (target->second.assignedToButton)
  542. return; // will be handled by button instance
  543. if (target->second.blocked)
  544. return;
  545. target->second.callback();
  546. }