bool ResourcePanel::EventFilter(GG::Wnd* w, const GG::WndEvent& event) { if (event.Type() != GG::WndEvent::RClick) return false; const GG::Pt& pt = event.Point(); MeterType meter_type = INVALID_METER_TYPE; for (const auto& meter_stat : m_meter_stats) { if (meter_stat.second.get() == w) { meter_type = meter_stat.first; break; } } if (meter_type == INVALID_METER_TYPE) return false; std::string meter_string = boost::lexical_cast<std::string>(meter_type); std::string meter_title; if (UserStringExists(meter_string)) meter_title = UserString(meter_string); if (meter_title.empty()) return false; bool retval = false; auto pedia_zoom_to_article_action = [&meter_string, &retval]() { retval = ClientUI::GetClientUI()->ZoomToMeterTypeArticle(meter_string); }; auto popup = GG::Wnd::Create<CUIPopupMenu>(pt.x, pt.y); std::string popup_label = boost::io::str(FlexibleFormat(UserString("ENC_LOOKUP")) % meter_title); popup->AddMenuItem(GG::MenuItem(popup_label, false, false, pedia_zoom_to_article_action)); popup->Run(); return retval; }
bool PopulationPanel::EventFilter(GG::Wnd* w, const GG::WndEvent& event) { if (event.Type() != GG::WndEvent::RClick) return false; const GG::Pt& pt = event.Point(); MeterType meter_type = INVALID_METER_TYPE; for (const std::pair<MeterType, StatisticIcon*>& meter_stat : m_meter_stats) { if (meter_stat.second == w) { meter_type = meter_stat.first; break; } } if (meter_type == INVALID_METER_TYPE) return false; std::string meter_string = boost::lexical_cast<std::string>(meter_type); std::string meter_title; if (UserStringExists(meter_string)) meter_title = UserString(meter_string); std::string species_name; bool retval = false; CUIPopupMenu popup(pt.x, pt.y); std::shared_ptr<const PopCenter> pc = GetPopCenter(); if (meter_type == METER_POPULATION && pc) { species_name = pc->SpeciesName(); if (!species_name.empty()) { auto zoom_species_action = [&retval, &species_name]() { retval = ClientUI::GetClientUI()->ZoomToSpecies(species_name); }; std::string species_label = boost::io::str(FlexibleFormat(UserString("ENC_LOOKUP")) % UserString(species_name)); popup.AddMenuItem(GG::MenuItem(species_label, false, false, zoom_species_action)); } } if (!meter_title.empty()) { auto pedia_meter_type_action = [&retval, &meter_string]() { retval = ClientUI::GetClientUI()->ZoomToMeterTypeArticle(meter_string); }; std::string popup_label = boost::io::str(FlexibleFormat(UserString("ENC_LOOKUP")) % meter_title); popup.AddMenuItem(GG::MenuItem(popup_label, false, false, pedia_meter_type_action)); } popup.Run(); return retval; }
bool MultiIconValueIndicator::EventFilter(GG::Wnd* w, const GG::WndEvent& event) { if (event.Type() != GG::WndEvent::RClick) return false; const GG::Pt& pt = event.Point(); MeterType meter_type = INVALID_METER_TYPE; for (unsigned int i = 0; i < m_icons.size(); ++i) { try { if (m_icons.at(i) == w) { meter_type = m_meter_types.at(i).first; break; } } catch(std::out_of_range &e) { ErrorLogger() << e.what(); return false; } } if (meter_type == INVALID_METER_TYPE) return false; std::string meter_string = boost::lexical_cast<std::string>(meter_type); std::string meter_title; if (UserStringExists(meter_string)) meter_title = UserString(meter_string); GG::MenuItem menu_contents; std::string species_name; std::shared_ptr<const PopCenter> pc = GetPopCenter(*m_object_ids.begin()); if (meter_type == METER_POPULATION && pc && m_object_ids.size() == 1) { species_name = pc->SpeciesName(); if (!species_name.empty()) { std::string species_label = boost::io::str(FlexibleFormat(UserString("ENC_LOOKUP")) % UserString(species_name)); menu_contents.next_level.push_back(GG::MenuItem(species_label, 1, false, false)); } } if (!meter_title.empty()) { std::string popup_label = boost::io::str(FlexibleFormat(UserString("ENC_LOOKUP")) % meter_title); menu_contents.next_level.push_back(GG::MenuItem(popup_label, 2, false, false)); } CUIPopupMenu popup(pt.x, pt.y, menu_contents); bool retval = false; if (popup.Run()) { switch (popup.MenuID()) { case 1: { retval = ClientUI::GetClientUI()->ZoomToSpecies(species_name); break; } case 2: { retval = ClientUI::GetClientUI()->ZoomToMeterTypeArticle(meter_string); break; } default: break; } } return retval; }