Ejemplo n.º 1
0
        /// <summary>
        /// Works like 'AddNewClothingItem' except it doesn't create a new copy of the texture
        /// </summary>
        public void PutItemInGui(ClothingItem newClothing)
        {
            PushButton newPrototype = (PushButton)mClothingButtonPrototype.Clone();

            IGuiStyle style = GetNamedStyle(newClothing.StyleName);

            newPrototype.Image = newClothing.NormalTexture;
            newPrototype.Style = style;

            bool placed = false;
            Pair <ClothingItem, PushButton> newPair = new Pair <ClothingItem, PushButton>(newClothing, newPrototype);

            foreach (List <Pair <ClothingItem, PushButton> > stack in mActiveClothes)
            {
                if (stack.Count == 0 || stack[0].First.ItemId == newClothing.ItemId)
                {
                    stack.Add(newPair);

                    newPrototype.AddOnPressedAction
                    (
                        delegate()
                    {
                        // TODO: change how this filters so that momentary mouse presses work (like tapping a touchpad)
                        if (mMouseUp && IsWithin(Time.frameCount, mMouseDownFrame, 2))
                        {
                            mMouseUp = false;
                            mInput.ClothingSelected(RemoveClothingItemFromGui(newClothing.ItemId));
                        }
                    }
                    );

                    placed = true;
                    break;
                }
            }

            if (placed == false)
            {
                throw new Exception("Unable to place ClothingItem(" + newClothing.ItemId + ") in the GUI. (Are there more pieces of clothing in this level than fit in the clothing frame?)");
            }

            mClothingButtonPrototypes.Add(newPair);
            LayoutStacks();
        }