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

Method setKeybinding

source/frontend/StarKeybindingsMenu.cpp:157–198  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

155}
156
157void KeybindingsMenu::setKeybinding(KeyChord desc) {
158 if (!m_activeKeybinding)
159 return;
160
161 auto out = inputDescriptorToJson(desc);
162
163 auto config = Root::singleton().configuration();
164 auto base = config->get("bindings");
165
166 auto action = m_childToAction.get(m_activeKeybinding);
167 auto key = InterfaceActionNames.getRight(action);
168
169 auto bindings = OrderedHashSet<Json>::from(base.get(key).toArray());
170
171 if (bindings.contains(out))
172 bindings.clear();
173
174 bindings.add(out);
175
176 if (bindings.size() > m_maxBindings)
177 bindings.removeFirst();
178
179 base = base.set(key, JsonArray::from(bindings));
180
181 config->set("bindings", base);
182
183 StringList buttonText;
184
185 for (auto const& entry : base.get(key).iterateArray()) {
186 try {
187 auto stored = inputDescriptorFromJson(entry);
188 buttonText.push_back(printInputDescriptor(stored));
189 } catch (StarException const& e) {
190 buttonText.push_back("unknown");
191 }
192 }
193
194 convert<ButtonWidget>(m_activeKeybinding)->setText(buttonText.join(", "));
195
196 apply();
197 exitActiveMode();
198}
199
200void KeybindingsMenu::clearActive() {
201 if (!m_activeKeybinding)

Callers

nothing calls this directly

Calls 15

inputDescriptorToJsonFunction · 0.85
singletonClass · 0.85
inputDescriptorFromJsonFunction · 0.85
printInputDescriptorFunction · 0.85
configurationMethod · 0.80
toArrayMethod · 0.80
iterateArrayMethod · 0.80
getMethod · 0.45
containsMethod · 0.45
clearMethod · 0.45
addMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected