MultiIconValueIndicator::MultiIconValueIndicator(GG::X w, const std::vector<int>& object_ids, const std::vector<std::pair<MeterType, MeterType>>& meter_types) : GG::Wnd(GG::X0, GG::Y0, w, GG::Y1, GG::INTERACTIVE), m_icons(), m_meter_types(meter_types), m_object_ids(object_ids) { SetName("MultiIconValueIndicator"); GG::X x(EDGE_PAD); for (const std::pair<MeterType, MeterType>& meter_type : m_meter_types) { const MeterType PRIMARY_METER_TYPE = meter_type.first; // get icon texture. std::shared_ptr<GG::Texture> texture = ClientUI::MeterIcon(PRIMARY_METER_TYPE); // special case for population meter for an indicator showing only a // single popcenter: icon is species icon, rather than generic pop icon if (PRIMARY_METER_TYPE == METER_POPULATION && m_object_ids.size() == 1) { if (std::shared_ptr<const PopCenter> pc = GetPopCenter(*m_object_ids.begin())) texture = ClientUI::SpeciesIcon(pc->SpeciesName()); } m_icons.push_back(new StatisticIcon(texture, 0.0, 3, false, GG::X0, GG::Y0, IconWidth(), IconHeight())); GG::Pt icon_ul(x, GG::Y(EDGE_PAD)); GG::Pt icon_lr = icon_ul + GG::Pt(IconWidth(), IconHeight() + ClientUI::Pts()*3/2); m_icons.back()->SizeMove(icon_ul, icon_lr); m_icons.back()->InstallEventFilter(this); AttachChild(m_icons.back()); x += IconWidth() + IconSpacing(); } if (!m_icons.empty()) Resize(GG::Pt(Width(), EDGE_PAD + IconHeight() + ClientUI::Pts()*3/2)); Update(); }
void ResourcePanel::DoLayout() { AccordionPanel::DoLayout(); for (std::vector<std::pair<MeterType, StatisticIcon*> >::iterator it = m_meter_stats.begin(); it != m_meter_stats.end(); ++it) { DetachChild(it->second); } // detach / hide meter bars and large resource indicators DetachChild(m_multi_meter_status_bar); DetachChild(m_multi_icon_value_indicator); // update size of panel and position and visibility of widgets if (!s_expanded_map[m_rescenter_id]) { // position and reattach icons to be shown int n = 0; for (std::vector<std::pair<MeterType, StatisticIcon*> >::iterator it = m_meter_stats.begin(); it != m_meter_stats.end(); ++it) { GG::X x = MeterIconSize().x*n*7/2; if (x > Width() - m_expand_button->Width() - MeterIconSize().x*5/2) break; // ensure icon doesn't extend past right edge of panel StatisticIcon* icon = it->second; AttachChild(icon); GG::Pt icon_ul(x, GG::Y0); GG::Pt icon_lr = icon_ul + MeterIconSize(); icon->SizeMove(icon_ul, icon_lr); icon->Show(); n++; } Resize(GG::Pt(Width(), std::max(MeterIconSize().y, m_expand_button->Height()))); } else { // attach and show meter bars and large resource indicators GG::Y top = GG::Y0; AttachChild(m_multi_icon_value_indicator); m_multi_icon_value_indicator->MoveTo(GG::Pt(GG::X(EDGE_PAD), top)); m_multi_icon_value_indicator->Resize(GG::Pt(Width() - 2*EDGE_PAD, m_multi_icon_value_indicator->Height())); top += m_multi_icon_value_indicator->Height() + EDGE_PAD; AttachChild(m_multi_meter_status_bar); m_multi_meter_status_bar->MoveTo(GG::Pt(GG::X(EDGE_PAD), top)); m_multi_meter_status_bar->Resize(GG::Pt(Width() - 2*EDGE_PAD, m_multi_meter_status_bar->Height())); top += m_multi_icon_value_indicator->Height() + EDGE_PAD; MoveChildUp(m_expand_button); Resize(GG::Pt(Width(), top)); } m_expand_button->MoveTo(GG::Pt(Width() - m_expand_button->Width(), GG::Y0)); SetCollapsed(!s_expanded_map[m_rescenter_id]); }
void ResourcePanel::DoLayout() { AccordionPanel::DoLayout(); for (auto& meter_stat : m_meter_stats) { DetachChild(meter_stat.second); } // detach / hide meter bars and large resource indicators DetachChild(m_multi_meter_status_bar); DetachChild(m_multi_icon_value_indicator); // update size of panel and position and visibility of widgets if (!s_expanded_map[m_rescenter_id]) { // position and reattach icons to be shown int n = 0; GG::X stride = MeterIconSize().x * 7/2; for (auto& meter_stat : m_meter_stats) { GG::X x = n * stride; auto& icon = meter_stat.second; GG::Pt icon_ul(x, GG::Y0); GG::Pt icon_lr = icon_ul + MeterIconSize(); icon->SizeMove(icon_ul, icon_lr); if (x + icon->MinUsableSize().x >= ClientWidth()) break; AttachChild(icon); icon->Show(); n++; } Resize(GG::Pt(Width(), std::max(MeterIconSize().y, m_expand_button->Height()))); } else { // attach and show meter bars and large resource indicators GG::Y top = Top(); AttachChild(m_multi_icon_value_indicator); m_multi_icon_value_indicator->MoveTo(GG::Pt(GG::X(EDGE_PAD), GG::Y(EDGE_PAD))); m_multi_icon_value_indicator->Resize(GG::Pt(Width() - 2*EDGE_PAD, m_multi_icon_value_indicator->Height())); AttachChild(m_multi_meter_status_bar); m_multi_meter_status_bar->MoveTo(GG::Pt(GG::X(EDGE_PAD), m_multi_icon_value_indicator->Bottom() + EDGE_PAD - top)); m_multi_meter_status_bar->Resize(GG::Pt(Width() - 2*EDGE_PAD, m_multi_meter_status_bar->Height())); MoveChildUp(m_expand_button); Resize(GG::Pt(Width(), m_multi_meter_status_bar->Bottom() + EDGE_PAD - top)); } SetCollapsed(!s_expanded_map[m_rescenter_id]); }