int BattleroomListCtrl::GetItemColumnImage(long item, long column) const { if ( (item == -1) || (item >= (long)m_data.size()) || (m_battle == NULL) ) return -1; const User& user = *GetDataFromIndex( item ); bool is_bot = user.BattleStatus().IsBot(); bool is_spec = user.BattleStatus().spectator; if ( column == m_status_column_index ) { if ( !is_bot ) { if ( m_battle->IsFounder( user ) ) { return icons().GetHostIcon( is_spec ); } else { return icons().GetReadyIcon( is_spec, user.BattleStatus().ready, user.BattleStatus().sync, is_bot ); } } else return icons().ICON_BOT; } if ( column == m_ingame_column_index ) return user.GetStatusIconIndex(); if ( column == m_colour_column_index ) return is_spec ? -1 : icons().GetColourIcon( user.BattleStatus().colour ); if ( column == m_country_column_index ) return is_bot ? -1 : icons().GetFlagIcon( user.GetCountry() ); if ( column == m_rank_column_index ) return is_bot ? -1 : icons().GetRankIcon( user.GetStatus().rank ); if ( column == m_faction_column_index ) return is_spec ? -1 : user.GetSideiconIndex(); if ( column == m_nick_column_index ) return -1; else { const wxString msg = wxFormat(_("column oob in BattleroomListCtrl::OnGetItemColumnImage: %d" )) % column; wxLogWarning( msg); return -1; } }
wxListItemAttr * BattleroomListCtrl::GetItemAttr(long item) const { if ( item == -1 || item >= (long)m_data.size()) return NULL; const User& user = *GetDataFromIndex( item ); bool is_bot = user.BattleStatus().IsBot(); if ( !is_bot ) { return HighlightItemUser( user.GetNick() ); } return NULL; }
void BattleroomListCtrl::OnListRightClick( wxListEvent& event ) { wxLogDebugFunc( _T("") ); if ( m_ro ) return; int index = event.GetIndex(); if ( index == -1 || index >= (long)m_data.size()) return; User& user = *GetDataFromIndex( event.GetIndex() ); m_sel_user = &user; //this is set for event handlers if ( user.BattleStatus().IsBot() ) { wxLogMessage(_T("Bot")); int item = m_popup->FindItem( _("Spectator") ); m_popup->Enable( item, false ); m_popup->Check( item, false ); m_popup->Enable( m_popup->FindItem( _("Ring") ), false ); m_popup->Enable( m_popup->FindItem( _("Kick") ),true); } else { wxLogMessage(_T("User")); assert( m_popup ); int item = m_popup->FindItem( _("Spectator") ); m_popup->Check( item, m_sel_user->BattleStatus().spectator ); m_popup->Enable( item, true ); m_popup->Enable( m_popup->FindItem( _("Ring") ), true ); bool isSelUserMe = ( ui().IsThisMe(user) ); m_popup->Enable( m_popup->FindItem( _("Kick") ),!isSelUserMe); } wxLogMessage(_T("Popup")); m_popup->EnableItems( !user.BattleStatus().IsBot(), GetSelectedUserNick() );//this updates groups, therefore we need to update the connection to evt handlers too std::vector<int> groups_ids = m_popup->GetGroupIds(); for (std::vector<int>::const_iterator it = groups_ids.begin(); it != groups_ids.end(); ++it) { Connect( *it, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( BattleroomListCtrl::OnUserMenuAddToGroup ), 0, this ); } Connect( GROUP_ID_NEW, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( BattleroomListCtrl::OnUserMenuCreateGroup), 0, this ); PopupMenu( m_popup ); wxLogMessage(_T("Done")); }
wxString BattleroomListCtrl::GetItemText(long item, long column) const { if ( item == -1 || item >= (long)m_data.size()) return _T(""); const User& user = *GetDataFromIndex( item ); bool is_bot = user.BattleStatus().IsBot(); bool is_spec = user.BattleStatus().spectator; if ( column == m_faction_column_index ) { try { wxArrayString sides = usync().GetSides( m_battle->GetHostModName() ); ASSERT_EXCEPTION( user.BattleStatus().side < (long)sides.GetCount(), _T("Side index too high") ); } catch ( ... ) { return wxString::Format( _T("s%d"), user.BattleStatus().side + 1 ); } return _T(""); } if ( column == m_nick_column_index ) return is_bot ? user.GetNick() + _T(" (") + user.BattleStatus().owner + _T(")") : user.GetNick(); if ( column == m_team_column_index ) return is_spec ? _T("") : wxString::Format( _T("%d"), user.BattleStatus().team + 1 ); if ( column == m_ally_column_index ) return is_spec ? _T("") : wxString::Format( _T("%d"), user.BattleStatus().ally + 1 ); if ( column == m_cpu_column_index ) { if (!is_bot ) return wxString::Format( _T("%.1f GHz"), user.GetCpu() / 1000.0 ); else { //!TODO could prolly be cached wxString botname = user.BattleStatus().aishortname; if ( !user.BattleStatus().aiversion.IsEmpty() ) botname += _T(" ") + user.BattleStatus().aiversion; if ( !usync().VersionSupports( IUnitSync::USYNC_GetSkirmishAI ) ) { if ( botname.Find(_T('.')) != wxNOT_FOUND ) botname = botname.BeforeLast(_T('.')); if ( botname.Find(_T('/')) != wxNOT_FOUND ) botname = botname.AfterLast(_T('/')); if ( botname.Find(_T('\\')) != wxNOT_FOUND ) botname = botname.AfterLast(_T('\\')); if ( botname.Find(_T("LuaAI:")) != wxNOT_FOUND ) botname = botname.AfterFirst(_T(':')); } return botname; } } if ( column == m_resourcebonus_column_index ) return is_spec ? _T("") : wxString::Format( _T("%d%%"), user.BattleStatus().handicap ); if ( column == m_country_column_index ) return _T(""); return _T(""); }
wxString BattleroomListCtrl::GetItemText(long item, long column) const { if ( (item == -1) || (item >= (long)m_data.size()) || (m_battle == NULL)) return _T(""); const User& user = *GetDataFromIndex( item ); bool is_bot = user.BattleStatus().IsBot(); bool is_spec = user.BattleStatus().spectator; if ( column == m_faction_column_index ) { try { auto sides = LSL::usync().GetSides(STD_STRING(m_battle->GetHostModName())); ASSERT_EXCEPTION( user.BattleStatus().side < (long)sides.size(), _T("Side index too high") ); } catch ( ... ) { return wxFormat( _T("s%d") ) % (user.BattleStatus().side + 1); } return _T(""); } if ( column == m_nick_column_index ) { if ( is_bot ) { wxString botname = user.BattleStatus().aishortname; if ( !user.BattleStatus().aiversion.IsEmpty() ) botname += _T(" ") + user.BattleStatus().aiversion; if ( !LSL::usync().VersionSupports( LSL::USYNC_GetSkirmishAI ) ) { if ( botname.Find(_T('.')) != wxNOT_FOUND ) botname = botname.BeforeLast(_T('.')); if ( botname.Find(_T('/')) != wxNOT_FOUND ) botname = botname.AfterLast(_T('/')); if ( botname.Find(_T('\\')) != wxNOT_FOUND ) botname = botname.AfterLast(_T('\\')); if ( botname.Find(_T("LuaAI:")) != wxNOT_FOUND ) botname = botname.AfterFirst(_T(':')); } return (wxFormat(_T("%s - %s (%s)")) % user.GetNick() % botname % user.BattleStatus().owner); } else return user.GetNick(); } if ( column == m_team_column_index ) return is_spec ? _T("") : (wxFormat( _T("%d") ) % ( user.BattleStatus().team + 1 ) ).c_str(); if ( column == m_ally_column_index ) return is_spec ? _T("") : (wxFormat( _T("%d") ) % ( user.BattleStatus().ally + 1 ) ).c_str(); if ( column == m_resourcebonus_column_index ) return is_spec ? _T("") : (wxFormat( _T("%d%%") ) % user.BattleStatus().handicap ).c_str(); if ( column == m_country_column_index ) return _T(""); return _T(""); }
void PlaybackListCtrl<PlaybackType>::SetTipWindowText( const long item_hit, const wxPoint& position) { if ( item_hit < 0 || item_hit >= (long)m_data.size() ) return; const PlaybackType& replay = *GetDataFromIndex( item_hit ); int column = getColumnFromPosition( position ); if (column > (int)m_colinfovec.size() || column < 0) { m_tiptext = _T(""); } else { switch (column) { case 0: // date m_tiptext = replay.date_string; break; case 1: // modname m_tiptext = replay.ModName; break; case 2: // mapname m_tiptext = replay.MapName; break; case 3: //playernum m_tiptext = replay.ModName; break; case 4: // spring version m_tiptext = replay.SpringVersion; break; case 5: // filenam m_tiptext = replay.Filename; break; default: m_tiptext = _T(""); break; } } }
wxString BattleroomListCtrl::GetItemText(long item, long column) const { if ((item == -1) || (item >= (long)m_data.size()) || (m_battle == NULL)) return wxEmptyString; const User& user = *GetDataFromIndex(item); bool is_bot = user.BattleStatus().IsBot(); bool is_spec = user.BattleStatus().spectator; if (column == m_faction_column_index) { try { auto sides = LSL::usync().GetSides(m_battle->GetHostModName()); ASSERT_EXCEPTION(user.BattleStatus().side < (long)sides.size(), _T("Side index too high")); } catch (...) { return wxString::Format(_T("s%d"), user.BattleStatus().side + 1); } return wxEmptyString; } if (column == m_nick_column_index) { if (is_bot) { wxString botname = TowxString(user.BattleStatus().aishortname); if (!user.BattleStatus().aiversion.empty()) botname += _T(" ") + TowxString(user.BattleStatus().aiversion); return wxString::Format(_T("%s - %s (%s)"), TowxString(user.GetNick()).c_str(), botname.c_str(), TowxString(user.BattleStatus().owner).c_str()); } else return TowxString(user.GetNick()); } if (column == m_team_column_index) return is_spec ? wxString(wxEmptyString) : (wxString::Format(_T("%d"), user.BattleStatus().team + 1)); if (column == m_ally_column_index) return is_spec ? wxString(wxEmptyString) : (wxString::Format(_T("%d"), user.BattleStatus().ally + 1)); if (column == m_resourcebonus_column_index) return is_spec ? wxString(wxEmptyString) : (wxString::Format(_T("%d%%"), user.BattleStatus().handicap)); if (column == m_country_column_index) return wxEmptyString; return wxEmptyString; }
void BattleroomListCtrl::SetTipWindowText( const long item_hit, const wxPoint& position) { if ( item_hit < 0 || item_hit >= (long)m_data.size() ) return; if ( !m_battle ) return; const User& user = *GetDataFromIndex( item_hit ); int column = getColumnFromPosition( position ); if (column > (int)m_colinfovec.size() || column < 0) { m_tiptext = _T(""); } else { if ( column == m_status_column_index ) // is bot? { m_tiptext = _T(""); if ( user.BattleStatus().IsBot() ) { m_tiptext += _("AI (bot)\n"); } else { m_tiptext += _("Human\n"); } if ( user.BattleStatus().spectator ) { m_tiptext += _("Spectator\n"); } else { m_tiptext += _("Player\n"); } if ( m_battle->IsFounder( user ) ) { m_tiptext += _("Host\n"); } else { m_tiptext += _("Client\n"); } if ( user.BattleStatus().ready ) { m_tiptext += _("Ready\n"); } else { m_tiptext += _("Not ready\n"); } if ( user.BattleStatus().sync == SYNC_SYNCED ) { m_tiptext += _("In sync"); } else { m_tiptext += _("Not in sync"); } } else if ( column == m_faction_column_index ) // icon { m_tiptext = _T(""); if ( user.BattleStatus().spectator ) { m_tiptext = _T("Spectators have no side"); } else { try { const auto sides = LSL::usync().GetSides(STD_STRING(m_battle->GetHostModName())); const int side = user.BattleStatus().side; if ( side < (int)sides.size() ) m_tiptext = TowxString(sides[side]); } catch (...){} } } else if ( column == m_ingame_column_index ) // lobby status { m_tiptext = _T( "This " ); if ( user.GetStatus().bot ) { m_tiptext << _T( "bot " ); } else if ( user.GetStatus().moderator ) { m_tiptext << _T( "moderator " ); } else { m_tiptext << _T( "player " ); } if ( user.GetStatus().in_game ) { m_tiptext << _T( "is ingame" ); } else if ( user.GetStatus().away ) { m_tiptext << _T( "is away" ); } else { m_tiptext << _T( "is available" ); } } else if ( column == m_country_column_index ) // country { m_tiptext = user.BattleStatus().IsBot() ? _T("This bot is from nowhere particular") : GetFlagNameFromCountryCode(user.GetCountry()); } else if ( column == m_rank_column_index ) // rank { m_tiptext = user.BattleStatus().IsBot() ? _T("This bot has no rank") : user.GetRankName(user.GetStatus().rank); } else if ( column == m_nick_column_index ) //name { m_tiptext = user.BattleStatus().IsBot() ?user.GetNick() : user.GetNick(); } else m_tiptext = m_colinfovec[column].tip; } }
typename CustomVirtListCtrl<T,L>::DataType CustomVirtListCtrl<T,L>::GetSelectedData() { return GetDataFromIndex( m_selected_index ); }