Inheritance: MonoBehaviour, IDropHandler
Exemplo n.º 1
0
        /// <summary>
        /// Removes the drawbox in the slot of the provided handler.
        /// </summary>
        /// <param name="handler"></param>
        protected void RemoveDrawBoxInSlot(SlotHandler handler)
        {
            DrawBox drawBox = Slots[handler].DrawBox;

            if (drawBox.Container != this)
            {
                Debug.AddExceptionInClass(this.GetType(), "RemoveDrawBoxFromSlot", "DrawBox does not have correct container.");
                return;
            }

            if (!drawBox.IsClosed)
            {
                drawBox.Close();
            }

            drawBox.Container = null;
            drawBox.Handler   = null;

            Slots[handler].DrawBox = null;
            drawBoxList.Remove(drawBox);

            DrawBoxHasBeenRemoved(drawBox, handler);

            UpdateSize();
        }
Exemplo n.º 2
0
        /**
         *  Draw an open inventory slot
         **/
        public static void Render(Rect position, GUIStyle guiStyle, SlotHandler handler, GUIContent guiContent)
        {
            //	create the rendering rect to serve as the rendering position
            //	and the event-receiving area
            GUI.Box(position, guiContent, guiStyle);

            //	if the mouse is over this element
            if (position.Contains(UnityEngine.Event.current.mousePosition))
            {
                //	fire the hover event on the handler
                if (draggedItem.item != null)
                {
                    handler.Hover();
                }

                //	fire the mouse-up event on the handler
                if (UnityEngine.Event.current.type == EventType.MouseUp && draggedItem.item != null)
                {
                    if (handler.ItemDropped(draggedItem.item))
                    {
                        draggedItem.item.PutDown();
                        draggedItem.item = null;
                    }
                    UnityEngine.Event.current.Use();
                }
            }
        }
Exemplo n.º 3
0
 void Awake()
 {
     inventoryObj = GameObject.Find("Inventory");
     inventory    = inventoryObj.GetComponent <Inventory> ();
     slots        = GameObject.Find("Slots");
     slotHandler  = transform.parent.GetComponent <SlotHandler> ();
     invRect      = inventoryObj.GetComponent <RectTransform> ();
 }
Exemplo n.º 4
0
        protected override void DrawBoxHasBeenRemoved(DrawBox box, SlotHandler handler)
        {
            RemoveSlot(handler);

            if (DrawBoxRemoved != null)
            {
                DrawBoxRemoved(this, box);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Removes the slot with the provided handler.
        /// </summary>
        /// <param name="handler"></param>
        public void RemoveSlot(SlotHandler handler)
        {
            Slot slot = Slots[handler];

            if (slot.DrawBox != null)
            {
                RemoveDrawBoxFromSlot(slot.DrawBox);
            }

            Slots.Remove(handler);
        }
Exemplo n.º 6
0
        protected override ViewRect GenerateSlotBoundaries(SlotHandler handler, int newWidth, int newHeight)
        {
            if (handler == topSlot)
            {
                return(new ViewRect(RealX, RealY, newWidth, BorderPositon - 1));
            }
            if (handler == bottomSlot)
            {
                return(new ViewRect(RealX, RealY + BorderPositon + BorderSize - 1, newWidth, newHeight - BorderPositon));
            }

            return(base.GenerateSlotBoundaries(handler, newWidth, newHeight));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Inserts the drawbox to the slot with the provided handler.
        /// </summary>
        /// <param name="box">The box to insert into the slot.</param>
        /// <param name="handler">The handler of the slot.</param>
        protected void PutDrawBoxInSlot(DrawBox box, SlotHandler handler)
        {
            if (box == this)
            {
                Debug.AddExceptionInClass(this.GetType(), "PutDrawBoxInSlot", "Can't add this to itself.");
                return;
            }

            if (handler.DrawBox != null)
            {
                Debug.AddExceptionInClass(this.GetType(), "PutDrawBoxInSlot", "Can't add point DrawBox to an occupied slot.");
                return;
            }

            if (DrawBoxList.Contains(box))
            {
                Debug.AddExceptionInClass(this.GetType(), "PutDrawBoxInSlot", "Can't add point DrawBox instance twice to the same container");
                return;
            }

            if (box.Container != null)
            {
                Debug.AddExceptionInClass(this.GetType(), "PutDrawBoxInSlot", "Can't add point DrawBox instance that already has point container.");
                return;
            }

            if (!box.IsInitialized)
            {
                Debug.AddExceptionInClass(this.GetType(), "PutDrawBoxInSlot", "Can't add point DrawBox that is not initialized.");
                return;
            }

            if (!Slots.ContainsKey(handler))
            {
                Debug.AddExceptionInClass(this.GetType(), "PutDrawBoxInSlot", "Tried to put drawbox in non-existing slot.");
                return;
            }

            Slots[handler].DrawBox = box;
            drawBoxList.Add(box);

            box.Parent    = Parent;
            box.Container = this;
            box.Handler   = handler;

            UpdateSize();

            box.ReloadAlignment();
            box.AddedToContainer();
            DrawBoxHasBeenAdded(box, handler);
        }
Exemplo n.º 8
0
    /// <summary>
    /// Wardrobe Button event handler
    /// </summary>
    public void WardrobeClick()
    {
        Cleanup();

        Dictionary <string, List <UMATextRecipe> > recipes = Avatar.AvailableRecipes;

        foreach (string s in recipes.Keys)
        {
            GameObject  go = GameObject.Instantiate(SlotPrefab);
            SlotHandler sh = go.GetComponent <SlotHandler>();
            sh.Setup(Avatar, s, WardrobePanel);
            Text txt = go.GetComponentInChildren <Text>();
            txt.text = s;
            go.transform.SetParent(SlotPanel.transform);
        }
    }
Exemplo n.º 9
0
        public override void AddedToContainer()
        {
            iconSlot = AddNewSlot();
            icon     = new IconButton();
            icon.Initialize(category + "." + IconButton.DefaultCategory, file);
            PutDrawBoxInSlot(icon, iconSlot);
            icon.SetSize(Height, Height);
            icon.X      = Width - icon.Width;
            icon.Y      = 0;
            icon.Click += new DefaultEvent(icon_Click);

            scrollbarSlot = AddNewSlot();
            scrollbar     = new VScrollbar();
            scrollbar.Initialize(category + "." + VScrollbar.DefaultCategory, file);
            PutDrawBoxInSlot(scrollbar, scrollbarSlot);
            scrollbar.X         = Width - scrollbar.Width;
            scrollbar.Y         = TextFieldHeight;
            scrollbar.Activated = false;
        }
Exemplo n.º 10
0
        public override void AddedToContainer()
        {
            Container.SizeChanged += new SizeChangedEvent(Container_SizeChanged);

            hSlot = AddNewSlot();
            HScrollbar hScrollbar = new HScrollbar();

            hScrollbar.Initialize(null, file);
            PutDrawBoxInSlot(hScrollbar, hSlot);
            hScrollbar.Activated = false;

            vSlot = AddNewSlot();
            VScrollbar vScrollbar = new VScrollbar();

            vScrollbar.Initialize(null, file);
            PutDrawBoxInSlot(vScrollbar, vSlot);
            vScrollbar.Activated = false;

            GoToDirectory(Environment.CurrentDirectory);
        }
Exemplo n.º 11
0
        public override void AddedToContainer()
        {
            topSlot = AddNewSlot();
            Panel topPanel = new Panel();

            topPanel.Initialize();
            PutDrawBoxInSlot(topPanel, topSlot);
            topPanel.X = 0;
            topPanel.Y = 0;
            topPanel.Fill();
            topPanel.Alignment = DrawBoxAlignment.GetFull();

            bottomSlot = AddNewSlot();
            Panel bottomPanel = new Panel();

            bottomPanel.Initialize();
            PutDrawBoxInSlot(bottomPanel, bottomSlot);
            bottomPanel.X = 0;
            bottomPanel.Y = 0;
            bottomPanel.Fill();
            bottomPanel.Alignment = DrawBoxAlignment.GetFull();
        }
Exemplo n.º 12
0
        public override void AddedToContainer()
        {
            leftSlot = AddNewSlot();
            Panel leftPanel = new Panel();

            leftPanel.Initialize();
            PutDrawBoxInSlot(leftPanel, leftSlot);
            leftPanel.X = 0;
            leftPanel.Y = 0;
            leftPanel.Fill();
            leftPanel.Alignment = DrawBoxAlignment.GetFull();

            rightSlot = AddNewSlot();
            Panel rightPanel = new Panel();

            rightPanel.Initialize();
            PutDrawBoxInSlot(rightPanel, rightSlot);
            rightPanel.X = 0;
            rightPanel.Y = 0;
            rightPanel.Fill();
            rightPanel.Alignment = DrawBoxAlignment.GetFull();
        }
Exemplo n.º 13
0
 protected virtual Origin GenerateChildOrigin(SlotHandler id)
 {
     return(new Origin(0, 0));
 }
Exemplo n.º 14
0
 protected ViewRect GenerateSlotBoundaries(SlotHandler slotId)
 {
     return(GenerateSlotBoundaries(slotId, Width, Height));
 }
Exemplo n.º 15
0
 public void OnPointerExit(PointerEventData eventData)
 {
     slothandler.isOverToolTip = false;
     slothandler = null;
     text.color  = cacheColor;
 }
Exemplo n.º 16
0
 /// <summary>
 /// Is called whenever a drawbox has been removed.
 /// </summary>
 /// <param name="box"></param>
 /// <param name="handler"></param>
 protected virtual void DrawBoxHasBeenRemoved(DrawBox box, SlotHandler handler)
 {
 }
Exemplo n.º 17
0
    private void SetOccupied(GameObject slot, bool b)
    {
        SlotHandler dropZone = slot.GetComponent <SlotHandler>();

        dropZone.SetOccupied(b);
    }
Exemplo n.º 18
0
    private bool IsOccupied(GameObject slot)
    {
        SlotHandler dropZone = slot.GetComponent <SlotHandler>();

        return(dropZone.GetOccupied());
    }
Exemplo n.º 19
0
 protected DrawBox GetDrawBoxInSlot(SlotHandler slotId)
 {
     return(Slots[slotId].DrawBox);
 }
Exemplo n.º 20
0
 public Slot()
 {
     Handler = new SlotHandler(this);
 }
Exemplo n.º 21
0
 public static void Slot(Rect position, GUIStyle guiStyle, SlotHandler handler, GUIContent guiContent)
 {
     Element.Slot.Render(position, guiStyle, handler, guiContent);
 }
Exemplo n.º 22
0
 protected virtual ViewRect GenerateSlotBoundaries(SlotHandler slotId, int newWidth, int newHeight)
 {
     return(new ViewRect(RealX, RealY, newWidth, newHeight));
 }