DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

MenuWidget_DynamicList.cpp (6917B)


      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 #pragma hdrstop
     29 #include "../../idLib/precompiled.h"
     30 #include "../Game_local.h"
     31 
     32 /*
     33 ========================
     34 idMenuWidget_DynamicList::Initialize
     35 ========================
     36 */
     37 void idMenuWidget_DynamicList::Initialize( idMenuHandler * data ) {
     38 	idMenuWidget::Initialize( data );
     39 }
     40 
     41 /*
     42 ========================
     43 idMenuWidget_DynamicList::Update
     44 ========================
     45 */
     46 void idMenuWidget_DynamicList::Update() {
     47 
     48 	if ( GetSWFObject() == NULL ) {
     49 		return;
     50 	}
     51 
     52 	idSWFScriptObject & root = GetSWFObject()->GetRootObject();
     53 
     54 	if ( !BindSprite( root ) ) {
     55 		return;
     56 	}
     57 
     58 	for ( int optionIndex = 0; optionIndex < GetNumVisibleOptions(); ++optionIndex ) {
     59 		
     60 		if ( optionIndex >= children.Num() ) {
     61 			idSWFSpriteInstance * item = GetSprite()->GetScriptObject()->GetNestedSprite( va( "item%d", optionIndex ) );
     62 			if ( item != NULL ) {
     63 				item->SetVisible( false );
     64 				continue;
     65 			}
     66 		}
     67 
     68 		idMenuWidget & child = GetChildByIndex( optionIndex );
     69 		const int childIndex = GetViewOffset() + optionIndex;
     70 		bool shown = false;
     71 		child.SetSpritePath( GetSpritePath(), va( "item%d", optionIndex ) );
     72 		if ( child.BindSprite( root ) ) {
     73 			
     74 			if ( optionIndex >= GetTotalNumberOfOptions() ) {
     75 				child.ClearSprite();
     76 				continue;
     77 			} else {
     78 				//const int controlIndex = GetNumVisibleOptions() - Min( GetNumVisibleOptions(), GetTotalNumberOfOptions() ) + optionIndex;
     79 				shown = PrepareListElement( child, childIndex );
     80 				child.Update();
     81 			}
     82 
     83 			if ( !shown ) {
     84 				child.SetState( WIDGET_STATE_HIDDEN );
     85 			} else {
     86 				if ( optionIndex == focusIndex ) {
     87 					child.SetState( WIDGET_STATE_SELECTING );
     88 				} else {
     89 					child.SetState( WIDGET_STATE_NORMAL );
     90 				}
     91 			}
     92 		}
     93 	}
     94 
     95 	idSWFSpriteInstance * const upSprite = GetSprite()->GetScriptObject()->GetSprite( "upIndicator" );
     96 	if ( upSprite != NULL ) {
     97 		upSprite->SetVisible( GetViewOffset() > 0 );
     98 	}
     99 
    100 	idSWFSpriteInstance * const downSprite = GetSprite()->GetScriptObject()->GetSprite( "downIndicator" );
    101 	if ( downSprite != NULL ) {
    102 		downSprite->SetVisible( GetViewOffset() + GetNumVisibleOptions() < GetTotalNumberOfOptions() );
    103 	}
    104 
    105 }
    106 
    107 /*
    108 ========================
    109 idMenuWidget_DynamicList::GetTotalNumberOfOptions
    110 ========================
    111 */
    112 int idMenuWidget_DynamicList::GetTotalNumberOfOptions() const {
    113 
    114 	if ( controlList ) {
    115 		return GetChildren().Num();
    116 	}
    117 
    118 	return listItemInfo.Num();
    119 }
    120 
    121 /*
    122 ========================
    123 idMenuWidget_DynamicList::PrepareListElement
    124 ========================
    125 */
    126 bool idMenuWidget_DynamicList::PrepareListElement( idMenuWidget & widget, const int childIndex ) {
    127 
    128 	idMenuWidget_ScoreboardButton * const sbButton = dynamic_cast< idMenuWidget_ScoreboardButton * >( &widget );
    129 	if ( sbButton != NULL ) {
    130 		return true;
    131 	}
    132 
    133 	if ( listItemInfo.Num() == 0 ) {
    134 		return true;
    135 	}
    136 
    137 	if ( childIndex > listItemInfo.Num() ) {
    138 		return false;
    139 	}
    140 
    141 	idMenuWidget_Button * const button = dynamic_cast< idMenuWidget_Button * >( &widget );
    142 	if ( button != NULL ) {
    143 		button->SetIgnoreColor( ignoreColor );
    144 		button->SetValues( listItemInfo[ childIndex ] );
    145 		if ( listItemInfo[ childIndex ].Num() > 0 ) {
    146 			return true;
    147 		} 
    148 	}
    149 	
    150 	return false;
    151 }
    152 
    153 /*
    154 ========================
    155 idMenuWidget_DynamicList::SetListData
    156 ========================
    157 */
    158 void idMenuWidget_DynamicList::SetListData( idList< idList< idStr, TAG_IDLIB_LIST_MENU >, TAG_IDLIB_LIST_MENU > & list ) {
    159 	listItemInfo.Clear();
    160 	for ( int i = 0; i < list.Num(); ++i ) {
    161 		idList< idStr > values;
    162 		for ( int j = 0; j < list[i].Num(); ++j ) {
    163 			values.Append( list[i][j] );
    164 		}
    165 		listItemInfo.Append( values );
    166 	}
    167 }
    168 
    169 /*
    170 ========================
    171 idMenuWidget_DynamicList::Recalculate
    172 ========================
    173 */
    174 void idMenuWidget_DynamicList::Recalculate() {
    175 
    176 	idSWF * swf = GetSWFObject();
    177 
    178 	if ( swf == NULL ) {
    179 		return;
    180 	}
    181 
    182 	idSWFScriptObject & root = swf->GetRootObject();
    183 	for ( int i = 0; i < GetChildren().Num(); ++i ) {
    184 		idMenuWidget & child = GetChildByIndex( i );
    185 		child.SetSpritePath( GetSpritePath(), "info", "list", va( "item%d", i ) );
    186 		if ( child.BindSprite( root ) ) {
    187 			child.SetState( WIDGET_STATE_NORMAL );
    188 			child.GetSprite()->StopFrame( 1 );
    189 		}
    190 	}
    191 }
    192 
    193 /*
    194 ========================
    195 idMenuWidget_ScoreboardList::Update
    196 ========================
    197 */
    198 void idMenuWidget_ScoreboardList::Update() {
    199 
    200 	if ( GetSWFObject() == NULL ) {
    201 		return;
    202 	}
    203 
    204 	idSWFScriptObject & root = GetSWFObject()->GetRootObject();
    205 
    206 	if ( !BindSprite( root ) ) {
    207 		return;
    208 	}
    209 
    210 	for ( int optionIndex = 0; optionIndex < GetNumVisibleOptions(); ++optionIndex ) {
    211 		idMenuWidget & child = GetChildByIndex( optionIndex );
    212 		const int childIndex = GetViewOffset() + optionIndex;
    213 		bool shown = false;
    214 		child.SetSpritePath( GetSpritePath(), va( "item%d", optionIndex ) );
    215 		if ( child.BindSprite( root ) ) {
    216 			shown = PrepareListElement( child, childIndex );
    217 
    218 			if ( optionIndex == focusIndex && child.GetState() != WIDGET_STATE_SELECTED && child.GetState() != WIDGET_STATE_SELECTING ) {
    219 				child.SetState( WIDGET_STATE_SELECTING );
    220 			} else if ( optionIndex != focusIndex && child.GetState() != WIDGET_STATE_NORMAL ) {
    221 				child.SetState( WIDGET_STATE_NORMAL );
    222 			}
    223 
    224 			child.Update();
    225 		}
    226 	}
    227 }
    228 
    229 /*
    230 ========================
    231 idMenuWidget_ScoreboardList::GetTotalNumberOfOptions
    232 ========================
    233 */
    234 int idMenuWidget_ScoreboardList::GetTotalNumberOfOptions() const {
    235 	return GetChildren().Num();
    236 }