doom3-bfg/neo/d3xp/menus/MenuWidget_Carousel.cpp

325 lines
7 KiB
C++
Raw Normal View History

2012-11-26 18:58:24 +00:00
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
2012-11-26 18:58:24 +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"
void idMenuWidget_Carousel::Initialize( idMenuHandler* data )
{
2012-11-26 18:58:24 +00:00
idMenuWidget::Initialize( data );
class idCarouselRefresh : public idSWFScriptFunction_RefCounted
{
2012-11-26 18:58:24 +00:00
public:
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
}
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
}
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
}
else
{
widget->MoveToIndex( diff );
2012-11-26 18:58:24 +00:00
}
}
else
{
widget->SetMoveDiff( 0 );
}
2012-11-26 18:58:24 +00:00
}
widget->Update();
return idSWFScriptVar();
}
2012-11-26 18:58:24 +00:00
private:
idMenuWidget_Carousel* widget;
};
if( GetSWFObject() != NULL )
{
2012-11-26 18:58:24 +00:00
GetSWFObject()->SetGlobal( "refreshCarousel", new idCarouselRefresh( this ) );
}
}
/*
========================
idMenuWidget_Carousel::Update
========================
*/
void idMenuWidget_Carousel::Update()
{
2012-11-26 18:58:24 +00:00
if( GetSWFObject() == NULL )
{
2012-11-26 18:58:24 +00:00
return;
}
idSWFScriptObject& root = GetSWFObject()->GetRootObject();
if( !BindSprite( root ) )
{
2012-11-26 18:58:24 +00:00
return;
}
2012-11-26 18:58:24 +00:00
int midPoint = GetNumVisibleOptions() / 2 + 1;
for( int optionIndex = 0; optionIndex < GetNumVisibleOptions(); ++optionIndex )
{
2012-11-26 18:58:24 +00:00
int listIndex = viewIndex + optionIndex;
if( optionIndex >= midPoint )
{
2012-11-26 18:58:24 +00:00
listIndex = viewIndex - ( optionIndex - ( midPoint - 1 ) );
}
idMenuWidget& child = GetChildByIndex( optionIndex );
2012-11-26 18:58:24 +00:00
child.SetSpritePath( GetSpritePath(), va( "item%d", optionIndex ) );
if( child.BindSprite( root ) )
{
if( listIndex < 0 || listIndex >= GetTotalNumberOfOptions() )
{
2012-11-26 18:58:24 +00:00
child.SetState( WIDGET_STATE_HIDDEN );
}
else
{
idMenuWidget_Button* const button = dynamic_cast< idMenuWidget_Button* >( &child );
2012-11-26 18:58:24 +00:00
button->SetImg( imgList[ listIndex ] );
child.Update();
if( optionIndex == focusIndex )
{
2012-11-26 18:58:24 +00:00
child.SetState( WIDGET_STATE_SELECTING );
}
else
{
2012-11-26 18:58:24 +00:00
child.SetState( WIDGET_STATE_NORMAL );
}
}
}
}
}
/*
========================
idMenuWidget_Carousel::SetListImages
========================
*/
void idMenuWidget_Carousel::SetListImages( idList<const idMaterial*>& list )
{
2012-11-26 18:58:24 +00:00
imgList.Clear();
for( int i = 0; i < list.Num(); ++i )
{
2012-11-26 18:58:24 +00:00
imgList.Append( list[ i ] );
}
}
/*
========================
idMenuWidget_Carousel::Update
========================
*/
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
========================
*/
void idMenuWidget_Carousel::MoveToFirstItem( bool instant )
{
if( instant )
{
2012-11-26 18:58:24 +00:00
moveDiff = 0;
viewIndex = 0;
moveToIndex = 0;
idSWFScriptObject& root = GetSWFObject()->GetRootObject();
if( BindSprite( root ) )
{
2012-11-26 18:58:24 +00:00
GetSprite()->StopFrame( 1 );
}
2012-11-26 18:58:24 +00:00
Update();
}
}
/*
========================
idMenuWidget_Carousel::MoveToLastItem
========================
*/
void idMenuWidget_Carousel::MoveToLastItem( bool instant )
{
if( instant )
{
2012-11-26 18:58:24 +00:00
moveDiff = 0;
viewIndex = GetTotalNumberOfOptions() - 1;
moveToIndex = GetTotalNumberOfOptions() - 1;
idSWFScriptObject& root = GetSWFObject()->GetRootObject();
if( BindSprite( root ) )
{
2012-11-26 18:58:24 +00:00
GetSprite()->StopFrame( 1 );
}
Update();
}
}
/*
========================
idMenuWidget_Carousel::Update
========================
*/
void idMenuWidget_Carousel::MoveToIndex( int index, bool instant )
{
2012-11-26 18:58:24 +00:00
idLib::Printf( "moveToIndex %i\n", index );
if( instant )
{
2012-11-26 18:58:24 +00:00
viewIndex = index;
moveDiff = 0;
moveToIndex = viewIndex;
2012-11-26 18:58:24 +00:00
idLib::Printf( "moveDiff = %i\n", moveDiff );
idSWFScriptObject& root = GetSWFObject()->GetRootObject();
if( BindSprite( root ) )
{
2012-11-26 18:58:24 +00:00
GetSprite()->StopFrame( 1 );
}
2012-11-26 18:58:24 +00:00
Update();
return;
}
if( index == 0 )
{
2012-11-26 18:58:24 +00:00
fastScroll = false;
moveDiff = 0;
2012-11-26 18:58:24 +00:00
idLib::Printf( "moveDiff = %i\n", moveDiff );
2012-11-26 18:58:24 +00:00
viewIndex = moveToIndex;
return;
}
2012-11-26 18:58:24 +00:00
int midPoint = GetNumVisibleOptions() / 2;
scrollLeft = false;
if( index > midPoint )
{
2012-11-26 18:58:24 +00:00
moveDiff = index - midPoint;
scrollLeft = true;
}
else
{
2012-11-26 18:58:24 +00:00
moveDiff = index;
}
2012-11-26 18:58:24 +00:00
idLib::Printf( "moveDiff = %i\n", moveDiff );
if( scrollLeft )
{
2012-11-26 18:58:24 +00:00
moveToIndex = viewIndex - moveDiff;
if( moveToIndex < 0 )
{
2012-11-26 18:58:24 +00:00
moveToIndex = 0;
int diff = 0 - moveToIndex;
moveDiff -= diff;
}
}
else
{
2012-11-26 18:58:24 +00:00
moveToIndex = viewIndex + moveDiff;
if( moveToIndex >= GetTotalNumberOfOptions() )
{
2012-11-26 18:58:24 +00:00
moveDiff = GetTotalNumberOfOptions() - GetViewIndex() - 1;
moveToIndex = GetTotalNumberOfOptions() - 1;
}
}
2012-11-26 18:58:24 +00:00
idLib::Printf( "moveDiff = %i\n", moveDiff );
if( moveDiff != 0 )
{
if( moveDiff > 1 )
{
if( scrollLeft )
{
2012-11-26 18:58:24 +00:00
GetSprite()->PlayFrame( "leftFast" );
}
else
{
2012-11-26 18:58:24 +00:00
GetSprite()->PlayFrame( "rightFast" );
}
}
else
{
if( scrollLeft )
{
2012-11-26 18:58:24 +00:00
GetSprite()->PlayFrame( "left" );
}
else
{
2012-11-26 18:58:24 +00:00
GetSprite()->PlayFrame( "right" );
}
}
}
2012-11-26 18:58:24 +00:00
idLib::Printf( "moveDiff = %i\n", moveDiff );
}