doom3-bfg/neo/ui/ListGUI.cpp

208 lines
4.5 KiB
C++
Raw Normal View History

2012-11-26 18:58:24 +00:00
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
2012-11-26 18:58:24 +00:00
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
2012-11-26 18:58:24 +00:00
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#pragma hdrstop
#include "precompiled.h"
2012-11-26 18:58:24 +00:00
#include "ListGUILocal.h"
/*
====================
idListGUILocal::StateChanged
====================
*/
void idListGUILocal::StateChanged()
{
2012-11-26 18:58:24 +00:00
int i;
if( !m_stateUpdates )
{
2012-11-26 18:58:24 +00:00
return;
}
for( i = 0; i < Num(); i++ )
{
m_pGUI->SetStateString( va( "%s_item_%i", m_name.c_str(), i ), ( *this )[i].c_str() );
2012-11-26 18:58:24 +00:00
}
for( i = Num() ; i < m_water ; i++ )
{
2012-11-26 18:58:24 +00:00
m_pGUI->SetStateString( va( "%s_item_%i", m_name.c_str(), i ), "" );
}
m_water = Num();
m_pGUI->StateChanged( Sys_Milliseconds() );
}
/*
====================
idListGUILocal::GetNumSelections
====================
*/
int idListGUILocal::GetNumSelections()
{
2012-11-26 18:58:24 +00:00
return m_pGUI->State().GetInt( va( "%s_numsel", m_name.c_str() ) );
}
/*
====================
idListGUILocal::GetSelection
====================
*/
int idListGUILocal::GetSelection( char* s, int size, int _sel ) const
{
if( s )
{
2012-11-26 18:58:24 +00:00
s[ 0 ] = '\0';
}
int sel = m_pGUI->State().GetInt( va( "%s_sel_%i", m_name.c_str(), _sel ), "-1" );
if( sel == -1 || sel >= m_ids.Num() )
{
2012-11-26 18:58:24 +00:00
return -1;
}
if( s )
{
2012-11-26 18:58:24 +00:00
idStr::snPrintf( s, size, m_pGUI->State().GetString( va( "%s_item_%i", m_name.c_str(), sel ), "" ) );
}
// don't let overflow
if( sel >= m_ids.Num() )
{
2012-11-26 18:58:24 +00:00
sel = 0;
}
m_pGUI->SetStateInt( va( "%s_selid_0", m_name.c_str() ), m_ids[ sel ] );
2012-11-26 18:58:24 +00:00
return m_ids[ sel ];
}
/*
====================
idListGUILocal::SetSelection
====================
*/
void idListGUILocal::SetSelection( int sel )
{
2012-11-26 18:58:24 +00:00
m_pGUI->SetStateInt( va( "%s_sel_0", m_name.c_str() ), sel );
StateChanged();
}
/*
====================
idListGUILocal::Add
====================
*/
void idListGUILocal::Add( int id, const idStr& s )
{
2012-11-26 18:58:24 +00:00
int i = m_ids.FindIndex( id );
if( i == -1 )
{
2012-11-26 18:58:24 +00:00
Append( s );
m_ids.Append( id );
}
else
{
( *this )[ i ] = s;
2012-11-26 18:58:24 +00:00
}
StateChanged();
}
/*
====================
idListGUILocal::Push
====================
*/
void idListGUILocal::Push( const idStr& s )
{
2012-11-26 18:58:24 +00:00
Append( s );
m_ids.Append( m_ids.Num() );
StateChanged();
}
/*
====================
idListGUILocal::Del
====================
*/
bool idListGUILocal::Del( int id )
{
int i = m_ids.FindIndex( id );
if( i == -1 )
{
2012-11-26 18:58:24 +00:00
return false;
}
m_ids.RemoveIndex( i );
this->RemoveIndex( i );
StateChanged();
return true;
}
/*
====================
idListGUILocal::Clear
====================
*/
void idListGUILocal::Clear()
{
2012-11-26 18:58:24 +00:00
m_ids.Clear();
idList<idStr, TAG_OLD_UI>::Clear();
if( m_pGUI )
{
2012-11-26 18:58:24 +00:00
// will clear all the GUI variables and will set m_water back to 0
StateChanged();
}
}
/*
====================
idListGUILocal::IsConfigured
====================
*/
bool idListGUILocal::IsConfigured() const
{
2012-11-26 18:58:24 +00:00
return m_pGUI != NULL;
}
/*
====================
idListGUILocal::SetStateChanges
====================
*/
void idListGUILocal::SetStateChanges( bool enable )
{
2012-11-26 18:58:24 +00:00
m_stateUpdates = enable;
StateChanged();
}
/*
====================
idListGUILocal::Shutdown
====================
*/
void idListGUILocal::Shutdown()
{
2012-11-26 18:58:24 +00:00
m_pGUI = NULL;
m_name.Clear();
Clear();
}