MenuWidget_DynamicList.cpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition 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 BFG Edition 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 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. 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.
  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. #pragma hdrstop
  21. #include "../../idLib/precompiled.h"
  22. #include "../Game_local.h"
  23. /*
  24. ========================
  25. idMenuWidget_DynamicList::Initialize
  26. ========================
  27. */
  28. void idMenuWidget_DynamicList::Initialize( idMenuHandler * data ) {
  29. idMenuWidget::Initialize( data );
  30. }
  31. /*
  32. ========================
  33. idMenuWidget_DynamicList::Update
  34. ========================
  35. */
  36. void idMenuWidget_DynamicList::Update() {
  37. if ( GetSWFObject() == NULL ) {
  38. return;
  39. }
  40. idSWFScriptObject & root = GetSWFObject()->GetRootObject();
  41. if ( !BindSprite( root ) ) {
  42. return;
  43. }
  44. for ( int optionIndex = 0; optionIndex < GetNumVisibleOptions(); ++optionIndex ) {
  45. if ( optionIndex >= children.Num() ) {
  46. idSWFSpriteInstance * item = GetSprite()->GetScriptObject()->GetNestedSprite( va( "item%d", optionIndex ) );
  47. if ( item != NULL ) {
  48. item->SetVisible( false );
  49. continue;
  50. }
  51. }
  52. idMenuWidget & child = GetChildByIndex( optionIndex );
  53. const int childIndex = GetViewOffset() + optionIndex;
  54. bool shown = false;
  55. child.SetSpritePath( GetSpritePath(), va( "item%d", optionIndex ) );
  56. if ( child.BindSprite( root ) ) {
  57. if ( optionIndex >= GetTotalNumberOfOptions() ) {
  58. child.ClearSprite();
  59. continue;
  60. } else {
  61. //const int controlIndex = GetNumVisibleOptions() - Min( GetNumVisibleOptions(), GetTotalNumberOfOptions() ) + optionIndex;
  62. shown = PrepareListElement( child, childIndex );
  63. child.Update();
  64. }
  65. if ( !shown ) {
  66. child.SetState( WIDGET_STATE_HIDDEN );
  67. } else {
  68. if ( optionIndex == focusIndex ) {
  69. child.SetState( WIDGET_STATE_SELECTING );
  70. } else {
  71. child.SetState( WIDGET_STATE_NORMAL );
  72. }
  73. }
  74. }
  75. }
  76. idSWFSpriteInstance * const upSprite = GetSprite()->GetScriptObject()->GetSprite( "upIndicator" );
  77. if ( upSprite != NULL ) {
  78. upSprite->SetVisible( GetViewOffset() > 0 );
  79. }
  80. idSWFSpriteInstance * const downSprite = GetSprite()->GetScriptObject()->GetSprite( "downIndicator" );
  81. if ( downSprite != NULL ) {
  82. downSprite->SetVisible( GetViewOffset() + GetNumVisibleOptions() < GetTotalNumberOfOptions() );
  83. }
  84. }
  85. /*
  86. ========================
  87. idMenuWidget_DynamicList::GetTotalNumberOfOptions
  88. ========================
  89. */
  90. int idMenuWidget_DynamicList::GetTotalNumberOfOptions() const {
  91. if ( controlList ) {
  92. return GetChildren().Num();
  93. }
  94. return listItemInfo.Num();
  95. }
  96. /*
  97. ========================
  98. idMenuWidget_DynamicList::PrepareListElement
  99. ========================
  100. */
  101. bool idMenuWidget_DynamicList::PrepareListElement( idMenuWidget & widget, const int childIndex ) {
  102. idMenuWidget_ScoreboardButton * const sbButton = dynamic_cast< idMenuWidget_ScoreboardButton * >( &widget );
  103. if ( sbButton != NULL ) {
  104. return true;
  105. }
  106. if ( listItemInfo.Num() == 0 ) {
  107. return true;
  108. }
  109. if ( childIndex > listItemInfo.Num() ) {
  110. return false;
  111. }
  112. idMenuWidget_Button * const button = dynamic_cast< idMenuWidget_Button * >( &widget );
  113. if ( button != NULL ) {
  114. button->SetIgnoreColor( ignoreColor );
  115. button->SetValues( listItemInfo[ childIndex ] );
  116. if ( listItemInfo[ childIndex ].Num() > 0 ) {
  117. return true;
  118. }
  119. }
  120. return false;
  121. }
  122. /*
  123. ========================
  124. idMenuWidget_DynamicList::SetListData
  125. ========================
  126. */
  127. void idMenuWidget_DynamicList::SetListData( idList< idList< idStr, TAG_IDLIB_LIST_MENU >, TAG_IDLIB_LIST_MENU > & list ) {
  128. listItemInfo.Clear();
  129. for ( int i = 0; i < list.Num(); ++i ) {
  130. idList< idStr > values;
  131. for ( int j = 0; j < list[i].Num(); ++j ) {
  132. values.Append( list[i][j] );
  133. }
  134. listItemInfo.Append( values );
  135. }
  136. }
  137. /*
  138. ========================
  139. idMenuWidget_DynamicList::Recalculate
  140. ========================
  141. */
  142. void idMenuWidget_DynamicList::Recalculate() {
  143. idSWF * swf = GetSWFObject();
  144. if ( swf == NULL ) {
  145. return;
  146. }
  147. idSWFScriptObject & root = swf->GetRootObject();
  148. for ( int i = 0; i < GetChildren().Num(); ++i ) {
  149. idMenuWidget & child = GetChildByIndex( i );
  150. child.SetSpritePath( GetSpritePath(), "info", "list", va( "item%d", i ) );
  151. if ( child.BindSprite( root ) ) {
  152. child.SetState( WIDGET_STATE_NORMAL );
  153. child.GetSprite()->StopFrame( 1 );
  154. }
  155. }
  156. }
  157. /*
  158. ========================
  159. idMenuWidget_ScoreboardList::Update
  160. ========================
  161. */
  162. void idMenuWidget_ScoreboardList::Update() {
  163. if ( GetSWFObject() == NULL ) {
  164. return;
  165. }
  166. idSWFScriptObject & root = GetSWFObject()->GetRootObject();
  167. if ( !BindSprite( root ) ) {
  168. return;
  169. }
  170. for ( int optionIndex = 0; optionIndex < GetNumVisibleOptions(); ++optionIndex ) {
  171. idMenuWidget & child = GetChildByIndex( optionIndex );
  172. const int childIndex = GetViewOffset() + optionIndex;
  173. bool shown = false;
  174. child.SetSpritePath( GetSpritePath(), va( "item%d", optionIndex ) );
  175. if ( child.BindSprite( root ) ) {
  176. shown = PrepareListElement( child, childIndex );
  177. if ( optionIndex == focusIndex && child.GetState() != WIDGET_STATE_SELECTED && child.GetState() != WIDGET_STATE_SELECTING ) {
  178. child.SetState( WIDGET_STATE_SELECTING );
  179. } else if ( optionIndex != focusIndex && child.GetState() != WIDGET_STATE_NORMAL ) {
  180. child.SetState( WIDGET_STATE_NORMAL );
  181. }
  182. child.Update();
  183. }
  184. }
  185. }
  186. /*
  187. ========================
  188. idMenuWidget_ScoreboardList::GetTotalNumberOfOptions
  189. ========================
  190. */
  191. int idMenuWidget_ScoreboardList::GetTotalNumberOfOptions() const {
  192. return GetChildren().Num();
  193. }