Exemplo n.º 1
0
        protected override void OnRefresh()
        {
            //create squares if we haven't already
            CreateSquares();
            //if the enabler is enabled that means it has a container and that the container has stacks
            //the enabler display only needs to drop its stack if the enabler has no item
            //otherwise it will just display the item as being incorrect
            bool setEnablerDisplayStack = (HasEnabler && UseVisualEnabler);
            bool setSquareStacks        = (HasEnabler && Enabler.IsEnabled);

            if (setEnablerDisplayStack)                                         //top item in the enabler? set the stack
            {
                EnablerDisplay.SetStack(Enabler.EnablerStack);
                EnablerDisplay.UpdateDisplay();
            }
            else if (UseVisualEnabler)                                          //no top item? drop the stack
            {
                EnablerDisplay.DropStack();
                EnablerDisplay.UpdateDisplay();
            }

            try {
                if (setSquareStacks)
                {
                    //IN THEORY this should never result in an out of bounds error
                    //because setSquareStacks can't be true unless it has the stacks
                    //but we'll see what happens...
                    List <WIStack> enablerStacks = Enabler.EnablerStacks;
                    for (int i = 0; i < InventorySquares.Count; i++)
                    {
                                                                                                #if UNITY_EDITOR
                        InventorySquares[i].name = DisplayName + " square " + i.ToString();
                                                                                                #endif
                        InventorySquares[i].Enabler = Enabler;
                        InventorySquares[i].SetStack(enablerStacks[i]);
                        InventorySquares[i].UpdateDisplay();
                    }
                }
                else
                {
                    //if we're not setting them, we're dropping them
                    for (int i = 0; i < InventorySquares.Count; i++)
                    {
                                                                                                #if UNITY_EDITOR
                        InventorySquares[i].name = DisplayName + " square " + i.ToString();
                                                                                                #endif
                        InventorySquares[i].DropStack();
                        InventorySquares[i].UpdateDisplay();
                    }
                }
            } catch (Exception e) {
                Debug.LogError("Error when setting stacks in stack container display, proceeding normally: " + e.ToString());
            }
        }
Exemplo n.º 2
0
        protected void CreateTwoRowSquares()
        {
            Vector2 squareDimensions = Vector2.zero;
            //int numberOfSquares = Globals.MaxStacksPerContainer;
            int squaresPerRow = Globals.MaxStacksPerContainer / 2;

            if (SquarePrefab == null)
            {
                SquarePrefab = GUIManager.Get.InventorySquare;
            }
            int currentRow    = 0;
            int currentSquare = 0;

            for (int y = 0; y < 2; y++)
            {
                for (int x = 0; x < squaresPerRow; x++)
                {
                    GameObject      instantiatedSquare = NGUITools.AddChild(InventorySlotsParent, SquarePrefab);
                    InventorySquare square             = instantiatedSquare.GetComponent <InventorySquare>();
                    if (square.Panel != null)
                    {
                        GameObject.Destroy(square.Panel);
                    }
                    square.NGUICamera              = NGUICamera;
                    squareDimensions               = square.Dimensions;
                    square.TargetPosition          = new Vector3(x * (square.Dimensions.x), currentRow * (-square.Dimensions.y), 0f);
                    square.transform.localPosition = square.TargetPosition;
                    square.Enabler = Enabler;
                    square.Index   = currentSquare;
                    InventorySquares.Add(square);
                    square.UpdateDisplay();
                    currentSquare++;
                }
                currentRow++;
            }
            FrameSprite.transform.localScale = new Vector3((squaresPerRow * squareDimensions.x) - mFramePadding, (2 * squareDimensions.y) - mFramePadding, 0f);
            if (UseVisualEnabler)
            {
                EnablerDisplay.NGUICamera = NGUICamera;
                                                                #if UNITY_EDITOR
                EnablerDisplay.name = DisplayName + " enabler ";
                                                                #endif
            }

            if (mOneSquareMode)
            {
                //set it to false so we can set it up
                mOneSquareMode = false;
                SetOneSquareMode(mOneSquareMode, mActiveSquare);
            }
        }