DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

ListGUI.cpp (4584B)


      1 /*
      2 ===========================================================================
      3 
      4 Doom 3 BFG Edition GPL Source Code
      5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 
      6 
      7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").  
      8 
      9 Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
     10 it under the terms of the GNU General Public License as published by
     11 the Free Software Foundation, either version 3 of the License, or
     12 (at your option) any later version.
     13 
     14 Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
     15 but WITHOUT ANY WARRANTY; without even the implied warranty of
     16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17 GNU General Public License for more details.
     18 
     19 You should have received a copy of the GNU General Public License
     20 along with Doom 3 BFG Edition Source Code.  If not, see <http://www.gnu.org/licenses/>.
     21 
     22 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.
     23 
     24 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.
     25 
     26 ===========================================================================
     27 */
     28 
     29 #pragma hdrstop
     30 #include "../idlib/precompiled.h"
     31 
     32 #include "ListGUILocal.h"
     33 
     34 /*
     35 ====================
     36 idListGUILocal::StateChanged
     37 ====================
     38 */
     39 void idListGUILocal::StateChanged() {
     40 	int i;
     41 
     42 	if ( !m_stateUpdates ) {
     43 		return;
     44 	}
     45 
     46 	for( i = 0; i < Num(); i++ ) {
     47 		m_pGUI->SetStateString( va( "%s_item_%i", m_name.c_str(), i ), (*this)[i].c_str() ); 
     48 	}
     49 	for( i = Num() ; i < m_water ; i++ ) {
     50 		m_pGUI->SetStateString( va( "%s_item_%i", m_name.c_str(), i ), "" );
     51 	}
     52 	m_water = Num();
     53 	m_pGUI->StateChanged( Sys_Milliseconds() );
     54 }
     55 
     56 /*
     57 ====================
     58 idListGUILocal::GetNumSelections
     59 ====================
     60 */
     61 int idListGUILocal::GetNumSelections() {
     62 	return m_pGUI->State().GetInt( va( "%s_numsel", m_name.c_str() ) );
     63 }
     64 
     65 /*
     66 ====================
     67 idListGUILocal::GetSelection
     68 ====================
     69 */
     70 int idListGUILocal::GetSelection( char *s, int size, int _sel ) const {
     71 	if ( s ) {		
     72 		s[ 0 ] = '\0';
     73 	}
     74 	int sel = m_pGUI->State().GetInt( va( "%s_sel_%i", m_name.c_str(), _sel ), "-1" );
     75 	if ( sel == -1 || sel >= m_ids.Num() ) {
     76 		return -1;
     77 	}
     78 	if ( s ) {
     79 		idStr::snPrintf( s, size, m_pGUI->State().GetString( va( "%s_item_%i", m_name.c_str(), sel ), "" ) );
     80 	}
     81 	// don't let overflow
     82 	if ( sel >= m_ids.Num() ) {
     83 		sel = 0;
     84 	}
     85 	m_pGUI->SetStateInt( va( "%s_selid_0", m_name.c_str() ), m_ids[ sel ] ); 
     86 	return m_ids[ sel ];
     87 }
     88 
     89 /*
     90 ====================
     91 idListGUILocal::SetSelection
     92 ====================
     93 */
     94 void idListGUILocal::SetSelection( int sel ) {
     95 	m_pGUI->SetStateInt( va( "%s_sel_0", m_name.c_str() ), sel );
     96 	StateChanged();
     97 }
     98 
     99 /*
    100 ====================
    101 idListGUILocal::Add
    102 ====================
    103 */
    104 void idListGUILocal::Add( int id, const idStr &s ) {
    105 	int i = m_ids.FindIndex( id );
    106 	if ( i == -1 ) {
    107 		Append( s );
    108 		m_ids.Append( id );
    109 	} else {
    110 		(*this)[ i ] = s;
    111 	}
    112 	StateChanged();
    113 }
    114 
    115 /*
    116 ====================
    117 idListGUILocal::Push
    118 ====================
    119 */
    120 void idListGUILocal::Push( const idStr& s ) {
    121 	Append( s );
    122 	m_ids.Append( m_ids.Num() );
    123 	StateChanged();
    124 }
    125 
    126 /*
    127 ====================
    128 idListGUILocal::Del
    129 ====================
    130 */
    131 bool idListGUILocal::Del(int id) {
    132 	int i = m_ids.FindIndex(id);
    133 	if ( i == -1 ) {
    134 		return false;
    135 	}
    136 	m_ids.RemoveIndex( i );
    137 	this->RemoveIndex( i );
    138 	StateChanged();
    139 	return true;
    140 }
    141 
    142 /*
    143 ====================
    144 idListGUILocal::Clear
    145 ====================
    146 */
    147 void idListGUILocal::Clear() {
    148 	m_ids.Clear();
    149 	idList<idStr, TAG_OLD_UI>::Clear();
    150 	if ( m_pGUI ) {
    151 		// will clear all the GUI variables and will set m_water back to 0
    152 		StateChanged();
    153 	}
    154 }
    155 
    156 /*
    157 ====================
    158 idListGUILocal::IsConfigured
    159 ====================
    160 */
    161 bool idListGUILocal::IsConfigured() const {
    162 	return m_pGUI != NULL;
    163 }
    164 
    165 /*
    166 ====================
    167 idListGUILocal::SetStateChanges
    168 ====================
    169 */
    170 void idListGUILocal::SetStateChanges( bool enable ) {
    171 	m_stateUpdates = enable;
    172 	StateChanged();
    173 }
    174 
    175 /*
    176 ====================
    177 idListGUILocal::Shutdown
    178 ====================
    179 */
    180 void idListGUILocal::Shutdown() {
    181 	m_pGUI = NULL;
    182 	m_name.Clear();
    183 	Clear();
    184 }