Esempio n. 1
0
    //=============================================================================

    public void ShowPanel(bool bActive, List <TradingCardHeldItem> CardsInPack = null)
    {
        if (bActive)
        {
            m_bButtonPressed = false;
            m_MainPanel.SetActive(true);

            // Add card previews
            int   NumCards = CardsInPack.Count;
            float fWidth   = 17.0f + ((NumCards - 1) * 300.0f) + 240.0f + 17.0f;
            for (int Idx = 0; Idx < NumCards; Idx++)
            {
                GameObject NewCard = Instantiate(m_pfbCardFrame, new Vector3((float)Idx * 300.0f, 15.0f, 0.0f), Quaternion.identity) as GameObject;
                NewCard.transform.parent        = m_PreviewPanel.transform;
                NewCard.transform.localPosition = new Vector3(17.0f + ((float)Idx * 300.0f), -170.0f, 0.0f);

                // Setup card sprite image
                TradingCardSpreadsheetItem CurSpreadsheetCard = TradingCardItemsManager.GetTradingCardItem(CardsInPack[Idx].id);
                UnityEngine.UI.Image       RenderCardImage    = NewCard.transform.GetChild(0).gameObject.GetComponent(typeof(UnityEngine.UI.Image)) as UnityEngine.UI.Image;
                Sprite RenderSprite = (Sprite)Resources.Load("Cards/LargeGUITextures/" + CurSpreadsheetCard.largeGuiTexture2D, typeof(Sprite));

                RenderCardImage.sprite = RenderSprite;
            }

            //Rect NewRect = new Rect( m_PreviewPanel.GetComponent<RectTransform>().rect );
            //NewRect.width = fWidth;
            //m_PreviewPanel.GetComponent<RectTransform>().rect = NewRect;
            m_PreviewPanel.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, fWidth);
        }
        else
        {
            // Delete all child objects of preview panel
            for (int i = m_PreviewPanel.transform.childCount - 1; i >= 0; --i)
            {
                GameObject child = m_PreviewPanel.transform.GetChild(i).gameObject;
                Destroy(child);
            }

            m_MainPanel.SetActive(false);
        }
    }
Esempio n. 2
0
    //=====================================================

    private IEnumerator ShowPopup(float delay)
    {
        yield return(new WaitForSeconds(delay));

        // Setup card GUI texture
        var CurSpreadsheetCard = TradingCardItemsManager.GetTradingCardItem(_currentCard.id);
        var RenderSprite       = (Sprite)Resources.Load("Cards/SmallGUITextures/" + CurSpreadsheetCard.smallGuiTexture2D, typeof(Sprite));

        m_RenderCardImage.sprite  = RenderSprite;
        m_RenderCardPosition.text = (CurSpreadsheetCard.globalPosition + 1).ToString();

        if (_currentCard.condition == eTradingCardCondition.MINT)
        {
            m_RenderCardOverlayImage.enabled = false;
        }
        else
        {
            m_RenderCardOverlayImage.enabled = true;
        }

        m_GUICamera.SetActive(true);
    }
Esempio n. 3
0
    //=====================================================

    void UpdateViewingBook()
    {
        // Update sprite that shows which page type we're on
        eTradingCardClassification VisibleClassification = TradingCardItemsManager.GetPageClassification(BookManager.instance.GetCurrentPage());

        foreach (GameObject sprClassification in m_sprPageTypes)
        {
            if (sprClassification != null)
            {
                sprClassification.SetActive(false);
            }
        }
        m_sprPageTypes[(int)VisibleClassification].SetActive(true);

        // Set the page shortcuts for this classification (prev/next)
        int PrevCategory = (int)VisibleClassification - 1;
        int NextCategory = (int)VisibleClassification + 1;

        // Skip 'story' class
        if (VisibleClassification == eTradingCardClassification.STANDARD)
        {
            PrevCategory--;
        }
        if (VisibleClassification == eTradingCardClassification.WILD)
        {
            NextCategory++;
        }

        //m_txtCategoryPrev.text = GetCategoryText( (eTradingCardClassification)PrevCategory );
        //m_txtCategoryNext.text = GetCategoryText( (eTradingCardClassification)NextCategory );

        // Check for swiping
        if (BookManager.instance.IsPageTurning())
        {
            return;
        }

        // Update area scrolling list position
        if (m_bSwiping)
        {
            m_SwipeTime      += Time.deltaTime;
            m_SwipeTimeAccum += Time.deltaTime;
            Vector3 WorldPos = m_BookCamera.ScreenToViewportPoint(Input.mousePosition);
            WorldPos *= 384.0f;
            float SwipingDeltaX = WorldPos.x - m_SwipingStartX;

            m_SwipingAccel = (WorldPos - m_LastWorldPos[3]).x;

            if (m_SwipeTimeAccum > (1.0f / 60.0f))
            {
                for (int MIdx = 3; MIdx > 0; MIdx--)
                {
                    m_LastWorldPos[MIdx] = m_LastWorldPos[MIdx - 1];
                }
                m_LastWorldPos[0] = WorldPos;
                m_SwipeTimeAccum -= (1.0f / 60.0f);
            }

            if (Input.GetMouseButtonUp(0))
            {
                m_bSwiping = false;

                m_SwipingAccel = Mathf.Clamp(m_SwipingAccel, -12.0f, 12.0f);

                bool bMinimumDistTravelled = true;

                if (Mathf.Abs(SwipingDeltaX) < 28.0f)
                {
                    bMinimumDistTravelled = false;
                }

                //Debug.Log( m_SwipingAccel + " " + bMinimumDistTravelled );
                if ((Mathf.Abs(m_SwipingAccel) < 7.0f) || (bMinimumDistTravelled == false))
                {
                    // No swipe - selection of a card?
                    m_SwipingAccel = 0.0f;
                    if ((m_SwipeTime < 0.25f) && (bMinimumDistTravelled == false))
                    {
                        // Selected card - check collision
                        int CurrentPage     = BookManager.instance.GetCurrentPage();
                        int CurrentPosition = BookManager.instance.GetPositionAtMouse();

                        // For first and last pages don't allow card selection
                        if (BookManager.instance.IsValidPage() == false)
                        {
                            CurrentPosition = -1;
                        }

                        if (CurrentPosition != -1)
                        {
                            // Valid card?
                            bool bValidCard = true;
                            TradingCardSpreadsheetItem CurSpreadsheetCard = TradingCardItemsManager.GetTradingCardItem(CurrentPage, CurrentPosition);
                            if (CurSpreadsheetCard == null)
                            {
                                bValidCard = false;
                            }

                            if (bValidCard)
                            {
                                // Set buy/sell mode based on whether we have the card or not
                                int NumMint    = 0;
                                int NumScuffed = 0;
                                TradingCardHeldItem CurHeldCard = GameDataManager.Instance.GetHeldTradingCard(CurSpreadsheetCard.id, ref NumMint, ref NumScuffed);

                                if (CurHeldCard != null)
                                {
                                    m_SelectedCardMode = eSelectedCardMode.Selling;
                                }
                                else
                                {
                                    m_SelectedCardMode = eSelectedCardMode.Buying;
                                }

                                // Show selected card panel
                                SelectedCardManager.instance.SetupPanel(m_SelectedCardMode, CurSpreadsheetCard, CurrentPosition, NumMint, NumScuffed);
                                SelectedCardManager.instance.ShowPanel(true);
                                SetRoomMode(eRoomMode.SelectedCard);

                                SoundFXManager.instance.PlaySound("CardSelect");


                                // Hide this card on the book so we can zoom into it
                                BookManager.instance.HideCard(CurrentPage, CurrentPosition);
                            }
                        }
                    }
                }
                else
                {
                    // Quick Swipe
                    if (m_SwipingAccel < 0.0f)
                    {
                        BookManager.instance.TurnPage(1);
                        SoundFXManager.instance.PlaySound("PageTurn");
                    }
                    else
                    {
                        BookManager.instance.TurnPage(-1);
                        SoundFXManager.instance.PlaySound("PageTurn");
                    }

                    m_SwipingAccel = 0.0f;
                }
            }
        }
        else
        {
            // Not swiping
            Vector3 WorldPos = m_BookCamera.ScreenToViewportPoint(Input.mousePosition);
            WorldPos *= 384.0f;
            for (int MIdx = 3; MIdx > 0; MIdx--)
            {
                m_LastWorldPos[MIdx] = WorldPos;
            }

            m_SwipingStartX  = WorldPos.x;
            m_SwipeTimeAccum = 0.0f;

            // Make sure pause menu or shop menu isn't active
            if ((PopupPause.Instance.IsActive == false) && (ShopManager.instance == false))
            {
                if (Input.GetMouseButtonDown(0))
                {
                    if ((WorldPos.y > 48.0f) && (WorldPos.y < 323.0f))
                    {
                        m_bSwiping     = true;
                        m_SwipingAccel = 0.0f;
                        m_SwipeTime    = 0.0f;
                    }
                }
            }
        }
    }
Esempio n. 4
0
    //=====================================================

    public void Update()
    {
        /*
         * // Randomly move cards around to show it's rendering
         * m_Angle += Time.deltaTime * 90.0f;
         *
         * int Idx = 0;
         * foreach( GameObject Obj in m_Cards )
         * {
         *      float Angle = m_Angle + ( Idx * 40 );
         *      float XOff = Mathf.Sin( Angle * Mathf.Deg2Rad ) * 30.0f;
         *      float YOff = Mathf.Cos( Angle * Mathf.Deg2Rad ) * 30.0f;
         *
         *      Vector3 NewVec = m_CardStartPositions[ Idx ];
         *      NewVec.x += XOff;
         *      NewVec.y += YOff;
         *      //Obj.transform.localPosition = NewVec;
         *      Idx++;
         * }
         */

        // Find out which page we're on and render the appropriate cards on that page
        int CurrentPage = m_CurrentBook.GetCurrentPage();

        //Debug.Log( m_CurrentBook.GetCurrentPage() );

        // Retrieve cards
        //int NumCards = GameDataManager.Instance.TradingCardDataList.Count;

        // Render if page has changed
        bool bUpdateResources = false;

        if (CurrentPage != m_LastPageRendered)
        {
            bUpdateResources = true;
        }

        {
            m_LastPageRendered = CurrentPage;

            for (int RenderTexturePage = 0; RenderTexturePage < 2; RenderTexturePage++)
            {
                int CurRenderTexturePage = RenderTexturePage;
                if ((CurrentPage & 1) == 1)
                {
                    CurRenderTexturePage++;
                }

                if (CurRenderTexturePage > 1)
                {
                    CurRenderTexturePage = 0;
                }

                // Setup cards for this render texture page
                for (int CurCardOffset = 0; CurCardOffset < m_CardsPerPage; CurCardOffset++)
                {
                    int ListCardOffset = CurCardOffset;
                    ListCardOffset += RenderTexturePage * m_CardsPerPage;
                    ListCardOffset += CurrentPage * m_CardsPerPage;

                    // Valid card?
                    bool bValidCard = true;
                    TradingCardSpreadsheetItem CurSpreadsheetCard = TradingCardItemsManager.GetTradingCardItem(CurrentPage + RenderTexturePage, CurCardOffset);
                    if (CurSpreadsheetCard == null)
                    {
                        bValidCard = false;
                    }

                    GameObject           RenderCard = m_Cards[CurCardOffset + (CurRenderTexturePage * m_CardsPerPage)];
                    GameObject           RenderCardScuffedOverlay      = RenderCard.transform.parent.gameObject.transform.GetChild(1).gameObject;
                    UnityEngine.UI.Image RenderCardImage               = RenderCard.GetComponent(typeof(UnityEngine.UI.Image)) as UnityEngine.UI.Image;
                    UnityEngine.UI.Image RenderCardScuffedOverlayImage = RenderCardScuffedOverlay.GetComponent(typeof(UnityEngine.UI.Image)) as UnityEngine.UI.Image;

                    if (bValidCard)
                    {
                        //Debug.Log( CurSpreadsheetCard.page + " " + CurSpreadsheetCard.position );
                        RenderCard.transform.parent.gameObject.SetActive(true);

                        //TradingCardHeldItem CurHeldCard = GameDataManager.Instance.TradingCardDataList[ ListCardOffset ];
                        //TradingCardSpreadsheetItem CurSpreadsheetCard = TradingCardItemsManager.GetTradingCardItem( CurHeldCard.id );

                        // Does the player have this card?
                        TradingCardHeldItem CurHeldCard = null;

                        int NumMint    = 0;
                        int NumScuffed = 0;

                        if (GameDataManager.Instance != null)
                        {
                            CurHeldCard = GameDataManager.Instance.GetHeldTradingCard(CurSpreadsheetCard.id, ref NumMint, ref NumScuffed);
                        }

                        if (CurHeldCard != null)
                        {
                            CurHeldCard.notifyTimer -= Time.deltaTime;
                            CurHeldCard.notifyTimer  = Mathf.Clamp(CurHeldCard.notifyTimer, 0.0f, 100.0f);

                            float fScale = (Mathf.Sin(CurHeldCard.notifyTimer * 5.0256f) * 0.1f) + 1.0f;
                            RenderCardImage.gameObject.transform.localScale = new Vector3(fScale, fScale, 1.0f);
                            RenderCardScuffedOverlayImage.gameObject.transform.localScale = new Vector3(fScale, fScale, 1.0f);

                            if (bUpdateResources)
                            {
                                Sprite RenderSprite = (Sprite)Resources.Load("Cards/SmallGUITextures/" + CurSpreadsheetCard.smallGuiTexture2D, typeof(Sprite));
                                RenderCardImage.sprite  = RenderSprite;
                                RenderCardImage.enabled = true;
                                RenderCardScuffedOverlayImage.enabled = true;
                            }
                        }
                        else
                        {
                            RenderCardImage.sprite = m_HiddenCardImage;
                            if (bUpdateResources)
                            {
                                RenderCardImage.enabled = true;
                                RenderCardScuffedOverlayImage.enabled = true;
                            }
                        }

                        // Show/hide number of cards
                        GameObject sprNumCards       = RenderCard.transform.parent.gameObject.transform.GetChild(2).gameObject;
                        GameObject sprScuffedOverlay = RenderCard.transform.parent.gameObject.transform.GetChild(1).gameObject;
                        GameObject sprNumCardsText   = sprNumCards.transform.GetChild(0).gameObject;
                        Text       txtNumCards       = sprNumCardsText.GetComponent(typeof(Text)) as Text;

                        int TotalCards = NumMint + NumScuffed;

                        // For now use the card number instead of 'number of cards'
                        TotalCards = CurSpreadsheetCard.globalPosition + 1; //( ListCardOffset + 1 );

                        if (1 == 1)                                         //TotalCards > 1 )
                        {
                            sprNumCardsText.SetActive(true);
                            txtNumCards.text = TotalCards.ToString();
                        }
                        else
                        {
                            sprNumCardsText.SetActive(false);
                        }

                        // Show scuffed overlay?
                        if ((NumMint <= 0) && (NumScuffed > 0))
                        {
                            sprScuffedOverlay.SetActive(true);
                        }
                        else
                        {
                            sprScuffedOverlay.SetActive(false);
                        }
                    }
                    else
                    {
                        RenderCard.transform.parent.gameObject.SetActive(false);
                        //RenderCardImage.enabled = false;
                    }
                }
            }
        }
    }