/// <summary>
 /// initialize this for the given item
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="stackId"></param>
 public void initialize(ItemIconController parent, int stackId, Coordinate gridLocation, Player.InventoryTypes containingInventory)
 {
     parentController          = parent;
     this.stackId              = stackId;
     this.originalGridLocation = gridLocation;
     this.containingInventory  = containingInventory;
 }
 /// <summary>
 /// Clear this notification from the list
 /// </summary>
 void clearNotification()
 {
     if (icon != null)
     {
         Destroy(icon.gameObject);
         icon = null;
     }
     gameObject.SetActive(false);
     manager.notificationCleared(currentPosition);
 }
 /// <summary>
 /// Display the notification in the given slot
 /// </summary>
 /// <param name="notification">The notification</param>
 /// <param name="position">Which position to show it in, top is 0</param>
 public void displayNotification(Notification notification, int position)
 {
     icon = notification.icon as ItemIconController;
     // set timer
     notificationCanvas = notificationCanvas ?? GetComponent <CanvasGroup>();
     displayTimer       = notification.displayTime;
     // set the icon and text
     messageText.text = notification.message;
     icon.parentTo(iconParent);
     icon.resize(65);
     icon.setBGColor(new Color(0, 131, 200));
     // set active and begin animating.
     beginFadeIn();
     beginSliding(BottomPositionIndex, position);
     gameObject.SetActive(true);
 }
Beispiel #4
0
 /// <summary>
 /// Set the item on this slot
 /// </summary>
 /// <param name="item"></param>
 public void setDisplayedItem(Item item, int barSlotIndex, int barSlotCount)
 {
     if (item != null)
     {
         gameObject.SetActive(true);
         icon = item == null?ItemIconController.Make(null, transform) : ItemIconController.Make(
                        item,
                        transform,
                        true,
                        true,
                        barSlotIndex,
                        (barSlotIndex, 0),
                        World.Entities.Creatures.Player.InventoryTypes.HotBar
                        );
     }
     this.barSlotIndex = barSlotIndex;
     this.barSlotCount = barSlotCount;
     updateLocation();
 }
Beispiel #5
0
        /// <summary>
        /// Change the icon to a new item or no item
        /// </summary>
        /// <param name="newItem"></param>
        void changeIcon(Item newItem = null)
        {
            float currentAlpha = icon.currentOpacity;

            Destroy(icon.gameObject);
            icon = newItem == null
        ? ItemIconController.Make(null, transform)
        : ItemIconController.Make(
                newItem,
                transform,
                true,
                true,
                barSlotIndex,
                (barSlotIndex, 0), Player.InventoryTypes.HotBar
                );

            if (isSelected)
            {
                markSelected();
            }
            updateOpacity(currentAlpha);
        }
        /// <summary>
        /// Make a new item icon for the given item
        /// </summary>
        /// <returns></returns>
        public static ItemIconController Make(
            Item item,
            Transform parent        = null,
            bool loadShapedIcon     = false,
            bool isDraggable        = false,
            int stackIndex          = GridBasedInventory.EmptyGridSlot,
            Coordinate gridLocation = default,
            Player.InventoryTypes parentInventory = Player.InventoryTypes.None
            )
        {
            // make the icon under the given parent, or alone if we want
            GameObject icon = parent != null
        ? Instantiate(ItemDataMapper.ItemIconPrefab, parent)
        : Instantiate(ItemDataMapper.ItemIconPrefab);

            // move to the top
            if (parent != null)
            {
                icon.transform.SetAsFirstSibling();
            }

            ItemIconController iconController = icon.GetComponent <ItemIconController>();

            iconController.item            = item;
            iconController.backgroundImage = icon.transform.Find("Icon Background").GetComponent <Image>();

            /// add the drag controller.
            if (isDraggable)
            {
                iconController.dragController = icon.AddComponent <ItemInventoryDragController>();
                iconController.dragController.initialize(iconController, stackIndex, gridLocation, parentInventory);
            }

            // try to get the sprite
            if (item != null)
            {
                Sprite itemSprite = ItemDataMapper.GetIconFor(item);
                /// if we found a sprite
                if (itemSprite != null)
                {
                    /// load the regular icon
                    iconController.defaultIconScaler = icon.transform.Find("Small Icon Scaler").gameObject;
                    GameObject sprite = Instantiate(new GameObject(), iconController.defaultIconScaler.transform);
                    sprite.layer = 5;
                    SpriteRenderer spriteRenderer = sprite.AddComponent <SpriteRenderer>();
                    spriteRenderer.sprite = itemSprite;
                    // if we didn't, use the object as an icon.
                }
                else
                {
                    iconController.defaultIconScaler = icon.transform.Find("Model Icon Scaler").gameObject;
                    GameObject itemModel = Instantiate(ItemDataMapper.GetModelFor(item), iconController.defaultIconScaler.transform);
                    iconController.itemModelRenderers = itemModel.GetComponentsInChildren <Renderer>();
                }

                /// if we're also loading the shaped icon:
                if (loadShapedIcon)
                {
                    // get the shaped scaler
                    iconController.shapedIconScaler = icon.transform.Find("Shaped Icon Scaler").gameObject;

                    // make the prototype image object
                    GameObject imageObject = new GameObject {
                        layer = 5
                    };
                    imageObject.AddComponent <Image>();
                    // resize the sprite according to it's shape size.
                    RectTransform rectTransform = imageObject.GetComponent <RectTransform>();
                    rectTransform.anchorMax = (item.type.ShapeSize - item.type.ShapePivot).Vec2;
                    rectTransform.anchorMin = ((0, 0) - item.type.ShapePivot).Vec2;
                    rectTransform.SetLTRB(0);

                    // if we need a new icon for the shaped icon than the basic square icon, get it
                    if (item.type.ShapeSize > (1, 1))
                    {
                        Sprite shapedIcon      = ItemDataMapper.GetIconFor(item, true);
                        Image  shapedIconImage = Instantiate(imageObject, iconController.shapedIconScaler.transform).GetComponent <Image>();
                        shapedIconImage.sprite = shapedIcon;
                    }

                    // add the outline
                    Image outline = Instantiate(imageObject, iconController.shapedIconScaler.transform).GetComponent <Image>();
                    outline.sprite = ItemDataMapper.GetShapedOutlineFor(item);
                    outline.color  = new Color(1, 1, 0);
                }

                // set the correct icon scaler active
                iconController.defaultIconScaler.SetActive(true);

                /// set up the stack indicator
                iconController.itemStackSizeIndicator     = icon.transform.Find("Stack Quantity Indicator").GetComponent <RectTransform>();
                iconController.itemStackSizeIndicatorText = iconController.itemStackSizeIndicator.GetComponentInChildren <Text>();
                iconController.updateStackCount();
                if (item.type.StackSize > 1)
                {
                    iconController.itemStackSizeIndicator.gameObject.SetActive(true);
                }
            }
            else
            {
                iconController.itemStackSizeIndicator     = icon.transform.Find("Stack Quantity Indicator").GetComponent <RectTransform>();
                iconController.itemStackSizeIndicatorText = iconController.itemStackSizeIndicator.GetComponentInChildren <Text>();
                iconController.updateStackCount();
            }

            return(iconController);
        }