示例#1
0
char CZombie::RecalculateIA(Vect3f hisPosition)
{
  Vect3f myPosition( GetInstance()->GetPosition() );

  switch(GetState())
  { 
    case (char)IDLE:
      GoIdle(hisPosition,myPosition);
    break;
    case (char)OLIENDO:
      GoOliendo(hisPosition,myPosition);
    break;
    case (char)MIRANDO:
      GoMirando(hisPosition,myPosition);
    break;
    case (char)ANDANDO:
//      m_pRenderableAnimatedInstanceModel->GetAnimatedInstanceModel()->BlendCycle(MIRANDO,elapsedTime);
      GoAndando(hisPosition,myPosition);
    break;
    case (char)ATACANDO:
      GoAtacando(hisPosition,myPosition);
    break;
    case (char)RECIBIENDOGOLPE:
      GoRecibiendoGolpe(hisPosition,myPosition);
    break;
    case (char)VOLVIENDOINICIO:
      GoVolviendoInicio(hisPosition,myPosition);
    break;
    case (char)MURIENDO:
      GoMuriendo();
    break;
  }
  return GetState();
}
示例#2
0
	void UIAnimatedButton::AfterInitialized()
	{
		GoIdle();

		UIUserElement::AfterInitialized();
	}
示例#3
0
//-----------------------------------------------------------------------------
//! Handle GetMenuItem in response to prior SendGetMenuItem().
//! 
//! Create a tNASWidget and accumulate it in m_WidgetItemList.  
//! When all have arrived, use the list to update m_pListWidget and go idle.
//! Otherwise get the next item.
//-----------------------------------------------------------------------------
void tNASVirtualHead::OnMenuItem( quint8 /*sourceId*/, quint32 index, quint8 flags, QString name )
{
    // Ignore menu items that we don't expect.  E.g. maybe we sent SetMenuAction while we were still waiting for a MenuItem.
    // We can also ignore the items we requested while idle, although we expect them we don't need or want them.
    if (m_State == eWaitingForMenuItems)
    {
        // Received the response, don't timeout.
        m_StateTimer->stop();

        // Restart inactivity timer.
        m_CloseOnUserInactivityTimer->start();

        // if there are a couple of devices requesting items at the same time, we can have duplicates. Just ignore them.
        for( int i = 0; i < m_WidgetItemList.count(); i++ )
        {
            tNASWidgetItem* pItem = static_cast< tNASWidgetItem* >( m_WidgetItemList.value( i, 0 ) );
            if( ( pItem != 0 ) && ( pItem->Index() == index ) )
            {
                return;
            }
        }

        m_WidgetItemList << new tNASWidgetItem( index, flags, name );

        // Have we just received the last item to complete the range of [m_FirstIndexInList, m_LastIndexInList]?
        if ( ( m_FillingDown && (static_cast<int>(index) == m_LastIndexInList) ) || 
             ( !m_FillingDown && (static_cast<int>(index) == m_FirstIndexInList) ) )
        {
            // Move the list of the accumulated items to the list widget.
            for( int i = 0; i < m_WidgetItemList.count(); ++i )
            {
                if (m_FillingDown)
                {
                    m_pListWidget->addItem( m_WidgetItemList.at( i ) );
                }
                else
                {
                    m_pListWidget->insertItem( 0, m_WidgetItemList.at( i ) );
                }
            }
            m_WidgetItemList.clear();

            // We can't calculate m_NumItemsNew properly until there are 
            // actually some items in the list and we can ask for a valid sizeHintForRow.
            // That is why we do it here instead of in resizeEvent().
            // Only need to calculate it once.
            int moreItemsNeeded = 0;
            if ( m_CheckHeight )
            {
                // Calculate m_NumItemsNew = number of items that can be visible in the list plus m_NewItemsNext,
                // but not less than its original value (from constructor).
                int itemHeight = m_pListWidget->sizeHintForRow( 0 );
                if ( (itemHeight * m_NumItemsNew) < m_pListWidget->viewport()->height() )
                {
                    // the height of the m_NumItemsNew to grab will be to short for the window, 
                    // find out what it will be for m_NewItemsNext items taller than the window
                    // + (itemHeight - 1) is for rounding up.
                    int oldNumItemsNew = m_NumItemsNew;
                    m_NumItemsNew = ( m_pListWidget->viewport()->height() + ( itemHeight * m_NewItemsNext ) + (itemHeight - 1) ) / itemHeight;
                    moreItemsNeeded = m_NumItemsNew - oldNumItemsNew;
                    if (moreItemsNeeded < 0)
                    {
                        Assert(false);
                        moreItemsNeeded = 0;
                    }
                    // Be careful not to go past end of menu.
                    if ( (m_LastIndexInList + moreItemsNeeded) > (m_MenuItemCount - 1) )
                    {
                         moreItemsNeeded = (m_MenuItemCount - 1) - m_LastIndexInList;
                    }
                }

                m_CheckHeight = false;
            }

            // Keep the list from growing too big.
            // Remove a page of items from above if there is more than 3.
            if ( (m_ItemIndex - m_FirstIndexInList) > (m_NumItemsNew * 3) )
            {
                for( int count = 0; count < m_NumItemsNew; ++count )
                {
                    delete m_pListWidget->takeItem( 0 );
                }

                m_FirstIndexInList += m_NumItemsNew;
            }
            // Remove a page of items from below if there is more than 3.
            if ( (m_LastIndexInList + 1 - m_ItemIndex) > (m_NumItemsNew * 3) )
            {
                for( int count = 0; count < m_NumItemsNew; ++count )
                {
                    delete m_pListWidget->takeItem( m_pListWidget->count()-1 );
                }

                m_LastIndexInList -= m_NumItemsNew;
            }

            // Adjust the selection to match and scroll to the top/bottom as appropriate for the direction of travel.
            m_pListWidget->setCurrentRow( m_ItemIndex - m_FirstIndexInList );
            //m_pListWidget->scrollToItem( m_pListWidget->currentItem(), ( m_FillingDown ? QAbstractItemView::PositionAtTop : QAbstractItemView::PositionAtBottom ) ); TODO_MCB ?
            m_pListWidget->scrollToItem( m_pListWidget->currentItem(), ( m_FillingDown ? QAbstractItemView::PositionAtBottom : QAbstractItemView::PositionAtTop ) );

            // Check if we need to get some more items, because (maybe) we recalculated m_NumItemsNew (see above).
            if (moreItemsNeeded > 0)
            {
                m_NextIndex = m_LastIndexInList + 1;
                m_LastIndexInList += moreItemsNeeded;
                m_FillingDown = true;
                SendGetMenuItem();
            }
            else
            {
                GoIdle();
            }
        }
        else
        {
            // Not yet complete, get the next item.
            if ( m_FillingDown )
            {
                ++m_NextIndex;
            }
            else
            {
                --m_NextIndex;
            }
            SendGetMenuItem();
        }
    }
}
示例#4
0
//-----------------------------------------------------------------------------
//! Handle MenuItemCount in response to prior SendGetMenuItemCount().
//-----------------------------------------------------------------------------
void tNASVirtualHead::OnMenuItemCount( quint8 /*sourceId*/, quint32 count )
{
    // Received the response, don't timeout.
    m_StateTimer->stop();

    // Restart inactivity timer.
    m_CloseOnUserInactivityTimer->start();

    // Qt uses int, not quint32, for list indices and so on.
    // Limit count to MAX_INT to keep things safe.
    if (count > INT_MAX)
    {
        m_MenuItemCount = INT_MAX;
    }
    else
    {
        m_MenuItemCount = count;
    }

    // Sanity check.
    if ( m_ItemIndex > (m_MenuItemCount - 1) )
    {
        m_ItemIndex = m_MenuItemCount - 1;
    }

    // New menu, start with empty list.
    m_pListWidget->clear();
    m_WidgetItemList.clear();

    if( m_MenuItemCount != 0 )
    {
        // Load enough items to fill the screen plus m_NewItemsNext for scrolling down,
        // resizeEvent() already calculated that as m_NumItemsNew.
        // Plus load m_NewItemsNext extra items above for scrolling up.
        // We want m_ItemIndex to appear at top of screen.
        // 
        // Thus:
        // m_FirstIndexInList is 
        // Want m_NewItemsNext items preloaded above the top of the screen.
        // Want m_NewItemsNext items preloaded below the bottom of the screen.
        // The screen can show m_NumItemsNew
        // Don't need to load all items, just the ones near m_ItemIndex.
        // Need to be careful about keeping the window within [0, MenuItemCount-1].
        // 
        // Begin with m_FirstIndexInList being m_NewItemsNext above top.
        m_FirstIndexInList = m_ItemIndex - m_NewItemsNext;
        if (m_FirstIndexInList < 0)
        {
            m_FirstIndexInList = 0;
        }
        //
        // and m_LastIndexInList being m_NewItemsNext below the bottom.
        m_LastIndexInList = m_ItemIndex + m_NumItemsNew - 1;
        if (m_LastIndexInList > m_MenuItemCount - 1)
        {
            m_LastIndexInList = m_MenuItemCount - 1;

            // we chose something near the end of the list, back up to show a full screen.
            m_FirstIndexInList = m_LastIndexInList + 1 - m_NumItemsNew;
            if (m_FirstIndexInList < 0)
            {
                m_FirstIndexInList = 0;
            }
        }

        m_FillingDown = true;
        m_NextIndex = m_FirstIndexInList;

        // Request from server
        SendGetMenuItem();
    }
    else 
    {
        // No items to load.  Go idle and wait for user input.
        m_FirstIndexInList = 0;
        m_LastIndexInList = 0;
        m_NextIndex = 0;

        GoIdle();
    }
}