| 103 | } |
| 104 | |
| 105 | void KeybindingsMenu::buildListsFromConfig() { |
| 106 | m_playerList = fetchChild<ListWidget>("categories.tabs.player.scrollArea.keyList"); |
| 107 | m_toolBarList = fetchChild<ListWidget>("categories.tabs.toolbar.scrollArea.keyList"); |
| 108 | m_gameList = fetchChild<ListWidget>("categories.tabs.game.scrollArea.keyList"); |
| 109 | |
| 110 | m_childToAction.clear(); |
| 111 | |
| 112 | auto doKeybindingsFor = [&](ListWidgetPtr const& list, Json const& keybinds) { |
| 113 | list->clear(); |
| 114 | |
| 115 | list->registerMemberCallback("activateBinding", [this](Widget* widget) { activateBinding(widget); }); |
| 116 | |
| 117 | list->registerMemberCallback("deleteBinding", [this](Widget*) { clearActive(); }); |
| 118 | |
| 119 | auto config = Root::singleton().configuration(); |
| 120 | auto bindings = config->get("bindings"); |
| 121 | |
| 122 | for (auto const& keybind : keybinds.iterateArray()) { |
| 123 | auto newListMember = list->addItem(); |
| 124 | auto actionString = keybind.get("action").toString(); |
| 125 | auto action = InterfaceActionNames.getLeft(actionString); |
| 126 | List<KeyChord> inputDesc; |
| 127 | try { |
| 128 | for (auto const& bindingEntry : bindings.get(actionString).iterateArray()) |
| 129 | inputDesc.append(inputDescriptorFromJson(bindingEntry)); |
| 130 | } catch (StarException const& e) { |
| 131 | Logger::warn("Could not load keybinding for {}. {}\n", actionString, e.what()); |
| 132 | } |
| 133 | |
| 134 | m_childToAction.insert({newListMember->fetchChild<ButtonWidget>("boundKeys").get(), action}); |
| 135 | newListMember->fetchChild<LabelWidget>("actionName")->setText(keybind.getString("label")); |
| 136 | newListMember->fetchChild<ButtonWidget>("boundKeys")->setText(StringList(inputDesc.transformed(printInputDescriptor)).join(", ")); |
| 137 | newListMember->fetchChild<ButtonWidget>("deleteBinding")->hide(); |
| 138 | } |
| 139 | }; |
| 140 | |
| 141 | auto assets = Root::singleton().assets(); |
| 142 | doKeybindingsFor(m_playerList, assets->json("/interface/windowconfig/keybindingsmenu.config:keyActions.player")); |
| 143 | doKeybindingsFor(m_toolBarList, assets->json("/interface/windowconfig/keybindingsmenu.config:keyActions.toolbar")); |
| 144 | doKeybindingsFor(m_gameList, assets->json("/interface/windowconfig/keybindingsmenu.config:keyActions.game")); |
| 145 | } |
| 146 | |
| 147 | bool KeybindingsMenu::activateBinding(Widget* widget) { |
| 148 | exitActiveMode(); |
nothing calls this directly
no test coverage detected