2012-11-26 18:58:24 +00:00
|
|
|
/*
|
|
|
|
===========================================================================
|
|
|
|
|
|
|
|
Doom 3 BFG Edition GPL Source Code
|
2012-11-28 15:47:07 +00:00
|
|
|
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
===========================================================================
|
|
|
|
*/
|
|
|
|
#pragma hdrstop
|
|
|
|
#include "../../idLib/precompiled.h"
|
|
|
|
#include "../Game_local.h"
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMenuWidget_Carousel::Initialize( idMenuHandler* data )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idMenuWidget::Initialize( data );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
class idCarouselRefresh : public idSWFScriptFunction_RefCounted
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
public:
|
2012-11-28 15:47:07 +00:00
|
|
|
idCarouselRefresh( idMenuWidget_Carousel* _widget ) :
|
|
|
|
widget( _widget )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
idSWFScriptVar Call( idSWFScriptObject* thisObject, const idSWFParmList& parms )
|
|
|
|
{
|
|
|
|
|
|
|
|
if( widget == NULL )
|
|
|
|
{
|
|
|
|
return idSWFScriptVar();
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( widget->GetMoveDiff() != 0 )
|
|
|
|
{
|
|
|
|
int diff = widget->GetMoveDiff();
|
|
|
|
diff--;
|
|
|
|
|
|
|
|
if( widget->GetScrollLeft() )
|
|
|
|
{
|
|
|
|
widget->SetViewIndex( widget->GetViewIndex() - 1 );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
widget->SetViewIndex( widget->GetViewIndex() + 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( diff > 0 )
|
|
|
|
{
|
|
|
|
if( widget->GetScrollLeft() )
|
|
|
|
{
|
|
|
|
widget->MoveToIndex( ( widget->GetNumVisibleOptions() / 2 ) + diff );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
widget->MoveToIndex( diff );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
widget->SetMoveDiff( 0 );
|
|
|
|
}
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
widget->Update();
|
|
|
|
return idSWFScriptVar();
|
|
|
|
}
|
2012-11-26 18:58:24 +00:00
|
|
|
private:
|
2012-11-28 15:47:07 +00:00
|
|
|
idMenuWidget_Carousel* widget;
|
|
|
|
};
|
|
|
|
|
|
|
|
if( GetSWFObject() != NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
GetSWFObject()->SetGlobal( "refreshCarousel", new idCarouselRefresh( this ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
idMenuWidget_Carousel::Update
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMenuWidget_Carousel::Update()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( GetSWFObject() == NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idSWFScriptObject& root = GetSWFObject()->GetRootObject();
|
|
|
|
|
|
|
|
if( !BindSprite( root ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int midPoint = GetNumVisibleOptions() / 2 + 1;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int optionIndex = 0; optionIndex < GetNumVisibleOptions(); ++optionIndex )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int listIndex = viewIndex + optionIndex;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( optionIndex >= midPoint )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
listIndex = viewIndex - ( optionIndex - ( midPoint - 1 ) );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idMenuWidget& child = GetChildByIndex( optionIndex );
|
2012-11-26 18:58:24 +00:00
|
|
|
child.SetSpritePath( GetSpritePath(), va( "item%d", optionIndex ) );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( child.BindSprite( root ) )
|
|
|
|
{
|
|
|
|
if( listIndex < 0 || listIndex >= GetTotalNumberOfOptions() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
child.SetState( WIDGET_STATE_HIDDEN );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
idMenuWidget_Button* const button = dynamic_cast< idMenuWidget_Button* >( &child );
|
2012-11-26 18:58:24 +00:00
|
|
|
button->SetImg( imgList[ listIndex ] );
|
|
|
|
child.Update();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( optionIndex == focusIndex )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
child.SetState( WIDGET_STATE_SELECTING );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
child.SetState( WIDGET_STATE_NORMAL );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
idMenuWidget_Carousel::SetListImages
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMenuWidget_Carousel::SetListImages( idList<const idMaterial*>& list )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
imgList.Clear();
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < list.Num(); ++i )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
imgList.Append( list[ i ] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
idMenuWidget_Carousel::Update
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idMenuWidget_Carousel::HandleAction( idWidgetAction& action, const idWidgetEvent& event, idMenuWidget* widget, bool forceHandled )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return idMenuWidget::HandleAction( action, event, widget, forceHandled );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
idMenuWidget_Carousel::MoveToFirstItem
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMenuWidget_Carousel::MoveToFirstItem( bool instant )
|
|
|
|
{
|
|
|
|
if( instant )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
moveDiff = 0;
|
|
|
|
viewIndex = 0;
|
|
|
|
moveToIndex = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idSWFScriptObject& root = GetSWFObject()->GetRootObject();
|
|
|
|
if( BindSprite( root ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
GetSprite()->StopFrame( 1 );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
Update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
idMenuWidget_Carousel::MoveToLastItem
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMenuWidget_Carousel::MoveToLastItem( bool instant )
|
|
|
|
{
|
|
|
|
if( instant )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
moveDiff = 0;
|
|
|
|
viewIndex = GetTotalNumberOfOptions() - 1;
|
|
|
|
moveToIndex = GetTotalNumberOfOptions() - 1;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idSWFScriptObject& root = GetSWFObject()->GetRootObject();
|
|
|
|
if( BindSprite( root ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
GetSprite()->StopFrame( 1 );
|
|
|
|
}
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
idMenuWidget_Carousel::Update
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMenuWidget_Carousel::MoveToIndex( int index, bool instant )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
idLib::Printf( "moveToIndex %i\n", index );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( instant )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
viewIndex = index;
|
|
|
|
moveDiff = 0;
|
|
|
|
moveToIndex = viewIndex;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idLib::Printf( "moveDiff = %i\n", moveDiff );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idSWFScriptObject& root = GetSWFObject()->GetRootObject();
|
|
|
|
if( BindSprite( root ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
GetSprite()->StopFrame( 1 );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
Update();
|
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( index == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
fastScroll = false;
|
|
|
|
moveDiff = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idLib::Printf( "moveDiff = %i\n", moveDiff );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
viewIndex = moveToIndex;
|
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int midPoint = GetNumVisibleOptions() / 2;
|
|
|
|
scrollLeft = false;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( index > midPoint )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
moveDiff = index - midPoint;
|
|
|
|
scrollLeft = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
moveDiff = index;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idLib::Printf( "moveDiff = %i\n", moveDiff );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( scrollLeft )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
moveToIndex = viewIndex - moveDiff;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( moveToIndex < 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
moveToIndex = 0;
|
|
|
|
int diff = 0 - moveToIndex;
|
|
|
|
moveDiff -= diff;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
moveToIndex = viewIndex + moveDiff;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( moveToIndex >= GetTotalNumberOfOptions() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
moveDiff = GetTotalNumberOfOptions() - GetViewIndex() - 1;
|
|
|
|
moveToIndex = GetTotalNumberOfOptions() - 1;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idLib::Printf( "moveDiff = %i\n", moveDiff );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( moveDiff != 0 )
|
|
|
|
{
|
|
|
|
if( moveDiff > 1 )
|
|
|
|
{
|
|
|
|
if( scrollLeft )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
GetSprite()->PlayFrame( "leftFast" );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
GetSprite()->PlayFrame( "rightFast" );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( scrollLeft )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
GetSprite()->PlayFrame( "left" );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
GetSprite()->PlayFrame( "right" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idLib::Printf( "moveDiff = %i\n", moveDiff );
|
|
|
|
}
|
|
|
|
|