void CUIVote::Update() { CUIDialogWnd::Update(); static string512 teaminfo; if (m_prev_upd_time > Device.dwTimeContinual - 1000) return; m_prev_upd_time = Device.dwTimeContinual; game_cl_GameState::PLAYERS_MAP_IT I=Game().players.begin(); game_cl_GameState::PLAYERS_MAP_IT E=Game().players.end(); DEFINE_VECTOR (game_PlayerState*,ItemVec,ItemIt); ItemVec items; for (;I!=E;++I) { items.push_back(I->second); }; std::sort(items.begin(), items.end(), DM_Compare_Players); list[0]->Clear(); list[1]->Clear(); list[2]->Clear(); for (u32 i = 0; i<items.size(); i++){ game_PlayerState* p = items[i]; if (p->m_bCurrentVoteAgreed == 1) list[0]->AddItem(p->name); else if (p->m_bCurrentVoteAgreed == 0) list[1]->AddItem(p->name); else list[2]->AddItem(p->name); } }
static void getIterators(const ItemVec& items, int start, int size, ItemVec::const_iterator& iterBegin, ItemVec::const_iterator& iterEnd) { if(start < 0) { start = 0; } if(start + size >= items.size()) { size = -1; } iterBegin = items.begin(); std::advance(iterBegin, start); iterEnd = iterBegin; if(size < 0) { iterEnd = items.end(); } else { std::advance(iterEnd, size); } }
void printItemVec (const ItemVec &vector) { cout << "Val\tWght\tratio" << endl; for (int i = 0; i < vector.size (); i++) { cout << vector[i].s_value << "\t" << vector[i].s_weight << "\t" << vector[i].s_ratio << endl; } }
void CUIStatsPlayerList::Update() { static string512 teaminfo; if (m_prev_upd_time > Device.dwTimeContinual - 100) return; DEFINE_VECTOR (game_PlayerState*,ItemVec,ItemIt); ItemVec items; m_prev_upd_time = Device.dwTimeContinual; game_cl_GameState::PLAYERS_MAP_IT I=Game().players.begin(); game_cl_GameState::PLAYERS_MAP_IT E=Game().players.end(); items.clear (); u32 pl_count = 0; int pl_frags = 0; u32 pl_artefacts = 0; for (;I!=E;++I) { game_PlayerState* p = (game_PlayerState*) I->second; if (!p || p->team != m_CurTeam) continue; if (m_bStatus_mode || m_bSpectator && p->testFlag(GAME_PLAYER_FLAG_SPECTATOR) || !m_bSpectator && !p->testFlag(GAME_PLAYER_FLAG_SPECTATOR)) { items.push_back(I->second); // add to team info pl_frags+=p->frags(); } }; pl_count = items.size(); CStringTable st; if (GameID() == eGameIDArtefactHunt && !m_bSpectator) { game_cl_ArtefactHunt* game = static_cast<game_cl_ArtefactHunt*>(&Game()); pl_artefacts = game->teams[m_CurTeam - 1].score; sprintf_s(teaminfo, "%s: %u, %s: %u, %s: %d",*st.translate("mp_artefacts_upcase"),pl_artefacts, *st.translate("mp_players"), pl_count, *st.translate("mp_frags_upcase"),pl_frags ); m_header_text->SetText(teaminfo); } else if (GameID() == eGameIDTeamDeathmatch && !m_bSpectator) { game_cl_TeamDeathmatch* game = static_cast<game_cl_TeamDeathmatch*>(&Game()); pl_frags = game->teams[m_CurTeam - 1].score; sprintf_s(teaminfo, "%s: %d, %s: %u", *st.translate("mp_frags_upcase"), pl_frags, *st.translate("mp_players"), pl_count); m_header_text->SetText(teaminfo); } if (m_bSpectator) { if(items.empty()) { Clear(); ShowHeader(false); return; } else ShowHeader(true); } std::sort(items.begin(), items.end(), DM_Compare_Players); int n = (int)items.size(); n -= m_pad->GetChildWndList().size(); if (n<0) { n = abs(n); for (int i = 0; i<n; i++) m_pad->DetachChild(*(m_pad->GetChildWndList().begin())); m_flags.set (eNeedRecalc,TRUE); } else { for (int i = 0; i<n; i++) { CUIStatsPlayerInfo* pi = new CUIStatsPlayerInfo(&m_field_info, m_i.f, m_i.c); pi->InitPlayerInfo( Fvector2().set(0,0), Fvector2().set(this->GetDesiredChildWidth(),m_i.h) ); CUIScrollView::AddWindow(pi, true); m_flags.set (eNeedRecalc,TRUE); } } R_ASSERT(items.size() == m_pad->GetChildWndList().size()); WINDOW_LIST_it it = m_pad->GetChildWndList().begin(); ItemIt itit = items.begin(); for (; it != m_pad->GetChildWndList().end(); it++, itit++) { CUIStatsPlayerInfo* pi = smart_cast<CUIStatsPlayerInfo*>(*it); R_ASSERT(pi); game_PlayerState* ps = static_cast<game_PlayerState*>(*itit); pi->SetInfo(ps); } // update player info CUIScrollView::Update(); }