/* ======================== idMenuWidget_NavBar::PrepareListElement ======================== */ bool idMenuWidget_NavBar::PrepareListElement( idMenuWidget& widget, const int navIndex ) { if( navIndex >= GetNumVisibleOptions() || navIndex >= headings.Num() ) { return false; } idMenuWidget_NavButton* const button = dynamic_cast< idMenuWidget_NavButton* >( &widget ); if( button == NULL || button->GetSprite() == NULL ) { return false; } button->SetLabel( headings[navIndex] ); idSWFTextInstance* ti = button->GetSprite()->GetScriptObject()->GetNestedText( "txtVal" ); if( ti != NULL ) { ti->SetStrokeInfo( true, 0.7f, 1.25f ); if( navIndex < GetFocusIndex() ) { ti->SetText( headings[ navIndex ] ); buttonPos = buttonPos + ti->GetTextLength(); button->SetPosition( buttonPos ); button->SetNavIndex( navIndex, idMenuWidget_NavButton::NAV_WIDGET_LEFT ); buttonPos += leftSpacer; } else if( navIndex > GetFocusIndex() ) { ti->SetText( headings[ navIndex ] ); ti->SetStrokeInfo( true, 0.7f, 1.25f ); button->GetSprite()->SetXPos( buttonPos ); button->SetPosition( buttonPos ); button->SetNavIndex( navIndex, idMenuWidget_NavButton::NAV_WIDGET_RIGHT ); buttonPos = buttonPos + ti->GetTextLength() + rightSpacer; } else { ti->SetText( headings[ navIndex ] ); ti->SetStrokeInfo( true, 0.7f, 1.25f ); button->GetSprite()->SetXPos( buttonPos ); button->SetPosition( buttonPos ); button->SetNavIndex( navIndex, idMenuWidget_NavButton::NAV_WIDGET_SELECTED ); buttonPos = buttonPos + ti->GetTextLength() + selectedSpacer; } } return true; }
/* ======================== idMenuScreen::ShowScreen ======================== */ void idMenuScreen::ShowScreen( const mainMenuTransition_t transitionType ) { if( menuGUI == NULL ) { return; } if( !BindSprite( menuGUI->GetRootObject() ) ) { return; } GetSprite()->SetVisible( true ); if( transitionType == MENU_TRANSITION_SIMPLE ) { if( menuData != NULL && menuData->ActiveScreen() != -1 ) { menuData->PlaySound( GUI_SOUND_BUILD_ON ); } GetSprite()->PlayFrame( "rollOn" ); } else if( transitionType == MENU_TRANSITION_ADVANCE ) { if( menuData != NULL && menuData->ActiveScreen() != -1 ) { menuData->PlaySound( GUI_SOUND_BUILD_ON ); } GetSprite()->PlayFrame( "rollOnFront" ); } else { if( menuData != NULL ) { menuData->PlaySound( GUI_SOUND_BUILD_OFF ); } GetSprite()->PlayFrame( "rollOnBack" ); } Update(); SetFocusIndex( GetFocusIndex(), true ); }
/* ======================== idMenuWidget_DevList::NavigateForward ======================== */ void idMenuWidget_DevList::NavigateForward( const int optionIndex ) { if ( devMenuList == NULL ) { return; } const int focusedIndex = GetViewOffset() + optionIndex; const idDeclDevMenuList::idDevMenuOption & devOption = devMenuList->devMenuList[ focusedIndex ]; if ( ( devOption.devMenuDisplayName.Length() == 0 ) || ( devOption.devMenuDisplayName.Cmp( "..." ) == 0 ) ) { return; } if ( devOption.devMenuSubList != NULL ) { indexInfo_t & indexes = devMapListInfos.Alloc(); indexes.name = devOption.devMenuSubList->GetName(); indexes.focusIndex = GetFocusIndex(); indexes.viewIndex = GetViewIndex(); indexes.viewOffset = GetViewOffset(); RecalculateDevMenu(); SetViewIndex( 0 ); SetViewOffset( 0 ); Update(); // NOTE: This must be done after the Update() because it MAY change the sprites that // children refer to GetChildByIndex( 0 ).SetState( WIDGET_STATE_SELECTED ); ForceFocusIndex( 0 ); SetFocusIndex( 0 ); gameLocal->GetMainMenu()->ClearWidgetActionRepeater(); } else { cmdSystem->AppendCommandText( va( "loadDevMenuOption %s %d\n", devMapListInfos[ devMapListInfos.Num() - 1 ].name, focusedIndex ) ); } }
void CGUIDialog::Update( float elapsedTime ) { CMouseManager * mouse = GetMouse(); //鼠标悬停在的控件 CGUIControl * mouse_over = NULL; for (size_t i = 0; i < m_children.size(); i ++) { if (m_children[i]->GetVisible() && m_children[i]->IsInBound((float)mouse->GetX(), (float)mouse->GetY())) { mouse_over = m_children[i]; } m_children[i]->BeforeUpdate(elapsedTime); } //鼠标移动,更新焦点控件 if (mouse->MouseMoved()) { SetFocusedControl(mouse_over); } if (mouse_over) { if (mouse->IsJustPressed(0)) { SetFocusedControl(mouse_over); mouse_over->OnMouseDown(); }else if (mouse->IsJustReleased(0)) { SetFocusedControl(mouse_over); mouse_over->OnMouseUp(); } } if (! m_children.empty()) { if (GetKeyboard()->IsJustPressed(VK_DOWN)) { int f = GetFocusIndex() + 1; if (f == m_children.size()) f = 0; SetFocusedControl(m_children[f]); }else if (GetKeyboard()->IsJustPressed(VK_UP)) { int f = GetFocusIndex() - 1; if (f < 0) f = (int)m_children.size() - 1; SetFocusedControl(m_children[f]); }else if (GetKeyboard()->IsJustPressed(VK_RETURN) || GetKeyboard()->IsJustPressed(VK_SPACE)) { if (m_focusedCtrl) { m_focusedCtrl->OnMouseDown(); } }else if (GetKeyboard()->IsJustReleased(VK_RETURN) || GetKeyboard()->IsJustReleased(VK_SPACE)) { if (m_focusedCtrl) { m_focusedCtrl->OnMouseUp(); } } } for (size_t i = 0; i < m_children.size(); i ++) { m_children[i]->AfterUpdate(elapsedTime); } }
/* ======================== idMenuWidget_NavBar::PrepareListElement ======================== */ void idMenuWidget_NavBar::Update() { if( GetSWFObject() == NULL ) { return; } idSWFScriptObject& root = GetSWFObject()->GetRootObject(); if( !BindSprite( root ) ) { return; } int rightIndex = 0; buttonPos = initialPos; for( int index = 0; index < GetNumVisibleOptions() - 1; ++index ) { idSWFSpriteInstance* const rightOption = GetSprite()->GetScriptObject()->GetSprite( va( "optionRight%d", index ) ); rightOption->SetVisible( false ); idSWFSpriteInstance* const leftOption = GetSprite()->GetScriptObject()->GetSprite( va( "optionLeft%d", index ) ); leftOption->SetVisible( false ); } for( int index = 0; index < GetTotalNumberOfOptions(); ++index ) { idMenuWidget& child = GetChildByIndex( index ); idMenuWidget_NavButton* const button = dynamic_cast< idMenuWidget_NavButton* >( &child ); button->SetLabel( "" ); } for( int index = 0; index < GetNumVisibleOptions(); ++index ) { if( index < GetFocusIndex() ) { idMenuWidget& child = GetChildByIndex( index ); child.SetSpritePath( GetSpritePath(), va( "optionLeft%d", index ) ); if( child.BindSprite( root ) ) { PrepareListElement( child, index ); child.Update(); } } else if( index > GetFocusIndex() ) { int rightChildIndex = ( GetNumVisibleOptions() - 1 ) + ( index - 1 ); idMenuWidget& child = GetChildByIndex( rightChildIndex ); child.SetSpritePath( GetSpritePath(), va( "optionRight%d", rightIndex ) ); rightIndex++; if( child.BindSprite( root ) ) { PrepareListElement( child, index ); child.Update(); } } else { int mainIndex = GetTotalNumberOfOptions() - 1; idMenuWidget& child = GetChildByIndex( mainIndex ); child.SetSpritePath( GetSpritePath(), va( "option" ) ); if( child.BindSprite( root ) ) { PrepareListElement( child, index ); child.Update(); } } } }