DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

MenuWidget_Help.cpp (4791B)


      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_Help
     35 
     36 Shows a help tooltip message based on observed events.  It's expected that the widgets being
     37 observed are all buttons, and therefore have a GetDescription() call to get the help message.
     38 
     39 SWF object structure
     40 --------------------
     41 HELPTOOLTIP (Frames: shown, shown, hide, hidden)
     42 	txtOption
     43 		txtValue (Text)
     44 Note: Frame 1 should, effectively, be a "hidden" state.
     45 
     46 Future work:
     47 - Make this act more like a help tooltip when on PC?
     48 ================================================================================================
     49 */
     50 
     51 /*
     52 ========================
     53 idMenuWidget_Help::Update
     54 ========================
     55 */
     56 void idMenuWidget_Help::Update() {
     57 	
     58 	if ( GetSWFObject() == NULL ) {
     59 		return;
     60 	}
     61 
     62 	idSWFScriptObject & root = GetSWFObject()->GetRootObject();
     63 
     64 	if ( !BindSprite( root ) ) {
     65 		return;
     66 	}
     67 
     68 	const idStr & msg = ( lastHoveredMessage.Length() > 0 ) ? lastHoveredMessage : lastFocusedMessage;
     69 	if ( msg.Length() > 0 && !hideMessage ) {
     70 		// try to show it if...
     71 		//		- we are on the first frame
     72 		//		- we aren't still animating while being between the "show" and "shown" frames
     73 		// 
     74 		if ( GetSprite()->GetCurrentFrame() != GetSprite()->FindFrame( "shown" )
     75 			&& ( GetSprite()->GetCurrentFrame() == 1 || !( GetSprite()->IsPlaying() && GetSprite()->IsBetweenFrames( "show", "shown" ) ) ) ) {
     76 			GetSprite()->PlayFrame( "show" );
     77 		}
     78 
     79 		idSWFScriptObject * const textObject = GetSprite()->GetScriptObject()->GetNestedObj( "txtOption", "txtValue" );
     80 		if ( textObject != NULL ) {
     81 			idSWFTextInstance * const text = textObject->GetText();
     82 			text->SetText( msg );
     83 			text->SetStrokeInfo( true, 0.75f, 2.0f );
     84 		}
     85 	} else {
     86 		// try to hide it
     87 		if ( GetSprite()->GetCurrentFrame() != 1 
     88 				&& GetSprite()->GetCurrentFrame() != GetSprite()->FindFrame( "hidden" )
     89 					&& !GetSprite()->IsBetweenFrames( "hide", "hidden" ) ) {
     90 			GetSprite()->PlayFrame( "hide" );
     91 		}
     92 	}
     93 }
     94 
     95 /*
     96 ========================
     97 idMenuWidget_Help::ObserveEvent
     98 ========================
     99 */
    100 void idMenuWidget_Help::ObserveEvent( const idMenuWidget & widget, const idWidgetEvent & event ) {
    101 	const idMenuWidget_Button * const button = dynamic_cast< const idMenuWidget_Button * >( &widget );
    102 	if ( button == NULL ) {
    103 		return;
    104 	}
    105 
    106 	switch ( event.type ) {
    107 		case WIDGET_EVENT_FOCUS_ON: {
    108 			hideMessage = false;
    109 			lastFocusedMessage = button->GetDescription();
    110 			lastHoveredMessage.Clear();
    111 			Update();
    112 			break;
    113 		}
    114 		case WIDGET_EVENT_FOCUS_OFF: {
    115 			// Don't do anything when losing focus. Focus updates come in pairs, so we can
    116 			// skip doing anything on the "lost focus" event, and instead do updates on the
    117 			// "got focus" event.
    118 			break;
    119 		}
    120 		case WIDGET_EVENT_ROLL_OVER: {
    121 			idStr desc = button->GetDescription();
    122 			if ( desc.IsEmpty() ) {
    123 				hideMessage = true;
    124 			} else {
    125 				hideMessage = false;
    126 				lastHoveredMessage = button->GetDescription();
    127 			}
    128 			Update();
    129 			break;
    130 		}
    131 		case WIDGET_EVENT_ROLL_OUT: {
    132 			hideMessage = false;
    133 			lastHoveredMessage.Clear();
    134 			Update();
    135 			break;
    136 		}
    137 	}
    138 }
    139