DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

MenuWidget_NavBar.cpp (5916B)


      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_NavBar::Initialize
     35 ========================
     36 */
     37 void idMenuWidget_NavBar::Initialize( idMenuHandler * data ) {
     38 	idMenuWidget::Initialize( data );
     39 }
     40 
     41 /*
     42 ========================
     43 idMenuWidget_NavBar::PrepareListElement
     44 ========================
     45 */
     46 void idMenuWidget_NavBar::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 	int rightIndex = 0;	
     59 
     60 	buttonPos = initialPos;
     61 
     62 	for ( int index = 0; index < GetNumVisibleOptions() - 1; ++index ) {
     63 		idSWFSpriteInstance * const rightOption = GetSprite()->GetScriptObject()->GetSprite( va( "optionRight%d", index ) );
     64 		rightOption->SetVisible( false );
     65 		idSWFSpriteInstance * const leftOption = GetSprite()->GetScriptObject()->GetSprite( va( "optionLeft%d", index ) );
     66 		leftOption->SetVisible( false );
     67 	}
     68 
     69 	for ( int index = 0; index < GetTotalNumberOfOptions(); ++index ) {
     70 		idMenuWidget & child = GetChildByIndex( index );
     71 		idMenuWidget_NavButton * const button = dynamic_cast< idMenuWidget_NavButton * >( &child );
     72 		button->SetLabel( "" );
     73 	}
     74 
     75 	for ( int index = 0; index < GetNumVisibleOptions(); ++index ) {
     76 		if ( index < GetFocusIndex() ) {
     77 			idMenuWidget & child = GetChildByIndex( index );
     78 			child.SetSpritePath( GetSpritePath(), va( "optionLeft%d", index ) );
     79 
     80 			if ( child.BindSprite( root ) ) {
     81 				PrepareListElement( child, index );
     82 				child.Update();
     83 			}
     84 
     85 		} else if ( index > GetFocusIndex() ) {			
     86 			int rightChildIndex = ( GetNumVisibleOptions() - 1 ) + ( index - 1 );
     87 			idMenuWidget & child = GetChildByIndex( rightChildIndex );
     88 			child.SetSpritePath( GetSpritePath(), va( "optionRight%d", rightIndex ) );
     89 			rightIndex++;
     90 
     91 			if ( child.BindSprite( root ) ) {
     92 				PrepareListElement( child, index );
     93 				child.Update();
     94 			}
     95 
     96 		} else {
     97 			int mainIndex = GetTotalNumberOfOptions() - 1;
     98 			idMenuWidget & child = GetChildByIndex( mainIndex );
     99 			child.SetSpritePath( GetSpritePath(), va( "option" ) );
    100 
    101 			if ( child.BindSprite( root ) ) {
    102 				PrepareListElement( child, index );
    103 				child.Update();
    104 			}
    105 		}		
    106 	}
    107 }
    108 
    109 /*
    110 ========================
    111 idMenuWidget_NavBar::SetListHeadings
    112 ========================
    113 */
    114 void idMenuWidget_NavBar::SetListHeadings( idList< idStr > & list ) {
    115 	headings.Clear();
    116 	for ( int index = 0; index < list.Num(); ++index ) {
    117 		headings.Append( list[ index ] );
    118 	}
    119 }
    120 
    121 /*
    122 ========================
    123 idMenuWidget_NavBar::GetTotalNumberOfOptions
    124 ========================
    125 */
    126 int idMenuWidget_NavBar::GetTotalNumberOfOptions() const { 
    127 	return GetChildren().Num(); 
    128 }
    129 
    130 /*
    131 ========================
    132 idMenuWidget_NavBar::PrepareListElement
    133 ========================
    134 */
    135 bool idMenuWidget_NavBar::PrepareListElement( idMenuWidget & widget, const int navIndex ) {
    136 
    137 	if ( navIndex >= GetNumVisibleOptions() || navIndex >= headings.Num() ) {
    138 		return false;
    139 	}
    140 
    141 	idMenuWidget_NavButton * const button = dynamic_cast< idMenuWidget_NavButton * >( &widget );
    142 	if ( button == NULL || button->GetSprite() == NULL ) {
    143 		return false;
    144 	}
    145 
    146 	button->SetLabel( headings[navIndex] );
    147 	idSWFTextInstance * ti = button->GetSprite()->GetScriptObject()->GetNestedText( "txtVal" );
    148 	if ( ti != NULL ) {
    149 		ti->SetStrokeInfo( true, 0.7f, 1.25f );
    150 		if ( navIndex < GetFocusIndex() ) {
    151 			ti->SetText( headings[ navIndex ] );			
    152 			buttonPos = buttonPos + ti->GetTextLength();
    153 			button->SetPosition( buttonPos );
    154 			button->SetNavIndex( navIndex, idMenuWidget_NavButton::NAV_WIDGET_LEFT );
    155 			buttonPos += leftSpacer;
    156 		} else if ( navIndex > GetFocusIndex() ) {
    157 			ti->SetText( headings[ navIndex ] );
    158 			ti->SetStrokeInfo( true, 0.7f, 1.25f );
    159 			button->GetSprite()->SetXPos( buttonPos );
    160 			button->SetPosition( buttonPos );
    161 			button->SetNavIndex( navIndex, idMenuWidget_NavButton::NAV_WIDGET_RIGHT );
    162 			buttonPos = buttonPos + ti->GetTextLength() + rightSpacer;			
    163 		} else {
    164 			ti->SetText( headings[ navIndex ] );
    165 			ti->SetStrokeInfo( true, 0.7f, 1.25f );
    166 			button->GetSprite()->SetXPos( buttonPos );
    167 			button->SetPosition( buttonPos );
    168 			button->SetNavIndex( navIndex, idMenuWidget_NavButton::NAV_WIDGET_SELECTED );
    169 			buttonPos = buttonPos + ti->GetTextLength() + selectedSpacer;
    170 		}
    171 	}
    172 
    173 	return true;
    174 
    175 }