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

Method buildListsFromConfig

source/frontend/StarKeybindingsMenu.cpp:105–145  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103}
104
105void 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
147bool KeybindingsMenu::activateBinding(Widget* widget) {
148 exitActiveMode();

Callers

nothing calls this directly

Calls 15

singletonClass · 0.85
inputDescriptorFromJsonFunction · 0.85
StringListClass · 0.85
configurationMethod · 0.80
iterateArrayMethod · 0.80
addItemMethod · 0.80
getStringMethod · 0.80
assetsMethod · 0.80
jsonMethod · 0.80
clearMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected