std::set<int> PlayerListWnd::SelectedPlayerIDs() const { std::set<int> retval; for (GG::ListBox::iterator it = m_player_list->begin(); it != m_player_list->end(); ++it) { if (!m_player_list->Selected(it)) continue; int selected_player_id = PlayerInRow(it); if (selected_player_id != Networking::INVALID_PLAYER_ID) retval.insert(selected_player_id); } return retval; }
void PlayerListWnd::PlayerRightClicked(GG::ListBox::iterator it, const GG::Pt& pt, const GG::Flags<GG::ModKey>& modkeys) { // check that a valid player was clicked and that it wasn't this client's own player int clicked_player_id = PlayerInRow(it); if (clicked_player_id == Networking::INVALID_PLAYER_ID) return; const ClientApp* app = ClientApp::GetApp(); if (!app) { ErrorLogger() << "PlayerListWnd::PlayerRightClicked couldn't get client app!"; return; } int client_player_id = app->PlayerID(); if (client_player_id == Networking::INVALID_PLAYER_ID) return; int client_empire_id = app->EmpireID(); // get empire id of clicked player const std::map<int, PlayerInfo>& players = app->Players(); std::map<int, PlayerInfo>::const_iterator clicked_player_it = players.find(clicked_player_id); if (clicked_player_it == players.end()) { ErrorLogger() << "PlayerListWnd::PlayerRightClicked couldn't find player with id " << clicked_player_id; return; } const PlayerInfo& clicked_player_info = clicked_player_it->second; int clicked_empire_id = clicked_player_info.empire_id; if (!GetEmpire(clicked_empire_id)) { ErrorLogger() << "PlayerListWnd::PlayerRightClicked tried to look up empire id " << clicked_empire_id << " for player " << clicked_player_id << " but couldn't find such an empire"; return; } // Actions auto war_declaration_action = MakeSendDiplomaticAction( client_empire_id, clicked_empire_id, WarDeclarationDiplomaticMessage); auto peace_proposal_action = MakeSendDiplomaticAction( client_empire_id, clicked_empire_id, PeaceProposalDiplomaticMessage); auto peace_accept_action = MakeSendDiplomaticAction( client_empire_id, clicked_empire_id, AcceptPeaceDiplomaticMessage); auto allies_proposal_action = MakeSendDiplomaticAction( client_empire_id, clicked_empire_id, AlliesProposalDiplomaticMessage); auto allies_accept_action = MakeSendDiplomaticAction( client_empire_id, clicked_empire_id, AcceptAlliesDiplomaticMessage); auto end_alliance_declaration_action = MakeSendDiplomaticAction( client_empire_id, clicked_empire_id, EndAllianceDiplomaticMessage); auto proposal_cancel_action = MakeSendDiplomaticAction( client_empire_id, clicked_empire_id, CancelDiplomaticMessage); auto proposal_reject_action = MakeSendDiplomaticAction( client_empire_id, clicked_empire_id, RejectProposalDiplomaticMessage); auto pedia_lookup_action = [clicked_empire_id]() { ClientUI::GetClientUI()->ZoomToEmpire(clicked_empire_id); }; CUIPopupMenu popup(pt.x, pt.y); if (app->GetClientType() == Networking::CLIENT_TYPE_HUMAN_PLAYER && client_empire_id != ALL_EMPIRES && clicked_empire_id != ALL_EMPIRES) { // get diplomatic status between client and clicked empires DiplomaticStatus diplo_status = Empires().GetDiplomaticStatus(clicked_empire_id, client_empire_id); if (diplo_status == INVALID_DIPLOMATIC_STATUS && clicked_player_id != client_player_id) { ErrorLogger() << "PlayerListWnd::PlayerRightClicked found invalid diplomatic status between client and clicked empires."; return; } const DiplomaticMessage& existing_message_from_clicked_empire_to_this_player = Empires().GetDiplomaticMessage(clicked_empire_id, client_empire_id); const DiplomaticMessage& existing_message_from_this_player_to_clicked_empire = Empires().GetDiplomaticMessage(client_empire_id, clicked_empire_id); // decide what diplomatic commands to show in popup menu bool show_peace_propose = false; bool show_peace_cancel = false; bool show_peace_reject = false; bool show_peace_accept = false; bool show_allies_end = false; bool show_allies_propose = false; bool show_allies_cancel = false; bool show_allies_reject = false; bool show_allies_accept = false; bool show_declare_war = false; if (existing_message_from_this_player_to_clicked_empire.GetType() == DiplomaticMessage::PEACE_PROPOSAL) show_peace_cancel = true; else if (existing_message_from_this_player_to_clicked_empire.GetType() == DiplomaticMessage::ALLIES_PROPOSAL) show_allies_cancel = true; if (existing_message_from_clicked_empire_to_this_player.GetType() == DiplomaticMessage::PEACE_PROPOSAL) { show_peace_accept = true; show_peace_reject = true; } else if (existing_message_from_clicked_empire_to_this_player.GetType() == DiplomaticMessage::ALLIES_PROPOSAL) { show_allies_accept = true; show_allies_reject = true; } if (diplo_status == DIPLO_WAR) { if (!show_peace_accept) show_peace_propose = true; } else if (diplo_status == DIPLO_PEACE) { if (!show_allies_accept) show_allies_propose = true; show_declare_war = true; } else if (diplo_status == DIPLO_ALLIED) { show_allies_end = true; } if (show_peace_propose) popup.AddMenuItem(GG::MenuItem(UserString("PEACE_PROPOSAL"), false, false, peace_proposal_action)); if (show_peace_cancel) popup.AddMenuItem(GG::MenuItem(UserString("PEACE_PROPOSAL_CANCEL"), false, false, proposal_cancel_action)); if (show_peace_accept) popup.AddMenuItem(GG::MenuItem(UserString("PEACE_ACCEPT"), false, false, peace_accept_action)); if (show_peace_reject) popup.AddMenuItem(GG::MenuItem(UserString("PEACE_REJECT"), false, false, proposal_reject_action)); if (show_allies_end) popup.AddMenuItem(GG::MenuItem(UserString("END_ALLIANCE_DECLARATION"), false, false, end_alliance_declaration_action)); if (show_allies_propose) popup.AddMenuItem(GG::MenuItem(UserString("ALLIES_PROPOSAL"), false, false, allies_proposal_action)); if (show_allies_accept) popup.AddMenuItem(GG::MenuItem(UserString("ALLIES_ACCEPT"), false, false, allies_accept_action)); if (show_allies_cancel) popup.AddMenuItem(GG::MenuItem(UserString("ALLIES_PROPOSAL_CANCEL"), false, false, proposal_cancel_action)); if (show_allies_reject) popup.AddMenuItem(GG::MenuItem(UserString("ALLIES_REJECT"), false, false, proposal_reject_action)); if (show_declare_war) popup.AddMenuItem(GG::MenuItem(UserString("WAR_DECLARATION"), false, false, war_declaration_action)); } popup.AddMenuItem(GG::MenuItem(str(FlexibleFormat(UserString("ENC_LOOKUP")) % GetEmpire(clicked_empire_id)->Name()), false, false, pedia_lookup_action)); popup.Run(); }
void PlayerListWnd::PlayerDoubleClicked(GG::ListBox::iterator it, const GG::Pt& pt, const GG::Flags<GG::ModKey>& modkeys) { int player_id = PlayerInRow(it); if (player_id != Networking::INVALID_PLAYER_ID) PlayerDoubleClickedSignal(player_id); }
void PlayerListWnd::PlayerRightClicked(GG::ListBox::iterator it, const GG::Pt& pt) { // check that a valid player was clicked and that it wasn't this client's own player int clicked_player_id = PlayerInRow(it); if (clicked_player_id == Networking::INVALID_PLAYER_ID) return; const ClientApp* app = ClientApp::GetApp(); if (!app) { Logger().errorStream() << "PlayerListWnd::PlayerRightClicked couldn't get client app!"; return; } int client_player_id = app->PlayerID(); if (client_player_id == Networking::INVALID_PLAYER_ID) return; int client_empire_id = app->EmpireID(); // get empire id of clicked player const std::map<int, PlayerInfo>& players = app->Players(); std::map<int, PlayerInfo>::const_iterator clicked_player_it = players.find(clicked_player_id); if (clicked_player_it == players.end()) { Logger().errorStream() << "PlayerListWnd::PlayerRightClicked couldn't find player with id " << clicked_player_id; return; } const PlayerInfo& clicked_player_info = clicked_player_it->second; int clicked_empire_id = clicked_player_info.empire_id; if (!Empires().Lookup(clicked_empire_id)) { Logger().errorStream() << "PlayerListWnd::PlayerRightClicked tried to look up empire id " << clicked_empire_id << " for player " << clicked_player_id << " but couldn't find such an empire"; return; } GG::MenuItem menu_contents; if (app->GetClientType() == Networking::CLIENT_TYPE_HUMAN_PLAYER) { // get diplomatic status between client and clicked empires DiplomaticStatus diplo_status = Empires().GetDiplomaticStatus(clicked_empire_id, client_empire_id); if (diplo_status == INVALID_DIPLOMATIC_STATUS && clicked_player_id != client_player_id) { Logger().errorStream() << "PlayerListWnd::PlayerRightClicked found invalid diplomatic status between client and clicked empires."; return; } DiplomaticMessage existing_message = Empires().GetDiplomaticMessage(clicked_empire_id, client_empire_id); // create popup menu with diplomacy options in it if ( client_empire_id != ALL_EMPIRES) { if (diplo_status == DIPLO_WAR) { if (existing_message.GetType() == DiplomaticMessage::PEACE_PROPOSAL) { // who sent message? if (existing_message.SenderEmpireID() == client_empire_id) menu_contents.next_level.push_back(GG::MenuItem(UserString("PEACE_PROPOSAL_CANEL"), 4, false, false)); else if (existing_message.SenderEmpireID() == clicked_empire_id) menu_contents.next_level.push_back(GG::MenuItem(UserString("PEACE_ACCEPT"), 3, false, false)); } else if (existing_message.GetType() == DiplomaticMessage::INVALID_DIPLOMATIC_MESSAGE_TYPE) { menu_contents.next_level.push_back(GG::MenuItem(UserString("PEACE_PROPOSAL"), 2, false, false)); } } else if (diplo_status == DIPLO_PEACE) { if (existing_message.GetType() == DiplomaticMessage::INVALID_DIPLOMATIC_MESSAGE_TYPE) menu_contents.next_level.push_back(GG::MenuItem(UserString("WAR_DECLARATION"), 1, false, false)); } } } menu_contents.next_level.push_back(GG::MenuItem(str(FlexibleFormat(UserString("ENC_LOOKUP")) % Empires().Lookup(clicked_empire_id)->Name()), 5, false, false)); ClientNetworking& net = HumanClientApp::GetApp()->Networking(); GG::PopupMenu popup(pt.x, pt.y, ClientUI::GetFont(), menu_contents, ClientUI::TextColor(), ClientUI::WndOuterBorderColor(), ClientUI::WndColor(), ClientUI::EditHiliteColor()); if (popup.Run()) { switch (popup.MenuID()) { case 1: { // WAR_DECLARATION net.SendMessage(DiplomacyMessage(client_player_id, clicked_player_id, WarDeclarationDiplomaticMessage(client_empire_id, clicked_empire_id))); break; } case 2: { // PEACE_PROPOSAL net.SendMessage(DiplomacyMessage(client_player_id, clicked_player_id, PeaceProposalDiplomaticMessage(client_empire_id, clicked_empire_id))); break; } case 3: { // PEACE_ACCEPT net.SendMessage(DiplomacyMessage(client_player_id, clicked_player_id, AcceptDiplomaticMessage(client_empire_id, clicked_empire_id))); break; } case 4: { // PEACE_PROPOSAL_CANEL net.SendMessage(DiplomacyMessage(client_player_id, clicked_player_id, CancelDiplomaticMessage(client_empire_id, clicked_empire_id))); break; } case 5: { // Pedia lookup ClientUI::GetClientUI()->ZoomToEmpire(clicked_empire_id); break; } default: break; } } }
void PlayerListWnd::PlayerDoubleClicked(GG::ListBox::iterator it) { int player_id = PlayerInRow(it); if (player_id != Networking::INVALID_PLAYER_ID) PlayerDoubleClickedSignal(player_id); }