void Hotkey::ReadFromOptions(OptionsDB& db) { for (std::map<std::string, Hotkey>::iterator i = s_hotkeys->begin(); i != s_hotkeys->end(); i++) { Hotkey& hotkey = i->second; std::string options_db_name = "UI.hotkeys." + hotkey.m_name; if (!db.OptionExists(options_db_name)) { ErrorLogger() << "Hotkey::ReadFromOptions : no option for " << options_db_name; continue; } std::string option_string = db.Get<std::string>(options_db_name); std::pair<GG::Key, GG::Flags<GG::ModKey> > key_modkey_pair = HotkeyFromString(option_string); if (key_modkey_pair.first == GG::GGK_UNKNOWN) continue; if (key_modkey_pair.first == GG::EnumMap<GG::Key>::BAD_VALUE) { ErrorLogger() << "Hotkey::ReadFromOptions : Invalid key spec: '" << option_string << "' for hotkey " << hotkey.m_name; continue; } if (!IsTypingSafe(key_modkey_pair.first, key_modkey_pair.second)) { ErrorLogger() << "Hotkey::ReadFromOptions : Typing-unsafe key spec: '" << option_string << "' for hotkey " << hotkey.m_name; continue; } hotkey.m_key = key_modkey_pair.first; hotkey.m_mod_keys = key_modkey_pair.second; } }
void Hotkey::ReadFromOptions(OptionsDB & db) { for(std::map<std::string, Hotkey>::iterator i = s_hotkeys->begin(); i != s_hotkeys->end(); i++) { Hotkey * sb = &(i->second); std::string n = "UI.hotkeys."; n += sb->m_name; std::string s = db.Get<std::string>(n); try { std::pair<GG::Key, GG::Flags<GG::ModKey> > sc = HotkeyFromString(s); if(sc.first == GG::EnumMap<GG::Key>::BAD_VALUE) throw std::exception(); sb->m_key = sc.first; sb->m_mod_keys = sc.second; } catch(std::exception & e) { std::cerr << "Invalid key spec: '" << s << "', ignoring" << std::endl; } } }
void Hotkey::SetFromString(const std::string& str) { std::pair<GG::Key, GG::Flags<GG::ModKey> > km = HotkeyFromString(str); m_key = km.first; m_mod_keys = km.second; }