ListGUI.cpp 4.6 KB

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