//--------------------------------------------------------------------------------------
    // Initialization.
    //--------------------------------------------------------------------------------------
    private void Awake()
    {
        // set instance
        m_oInstance = this;

        // get the selected stack component
        m_oSelectedStack = GetComponentInChildren <SelectedStack>();

        // get the tooltip component
        m_oToolTip = GetComponentInChildren <Tooltip>();
    }
Exemple #2
0
    public Player m_gPlayer; // TEMP // NEEDS TO BE PRIVATE // TEMP
    // REMOVE // TEMP // REMOVE // POSSIBLTY //

    //--------------------------------------------------------------------------------------
    // Initialization.
    //--------------------------------------------------------------------------------------
    private void Awake()
    {
        // set instance
        m_gInstance = this;

        // get the selected stack component
        m_gSelectedStack = GetComponentInChildren <SelectedStack>();

        // get the tooltip component
        m_gToolTip = GetComponentInChildren <Tooltip>();

        // get the player object
        m_gPlayer = FindObjectOfType <Player>();
    }
        static ContainerRenderer()
        {
            ContainerBackground = AssetDatabase.GetAsset <Texture>("Resources/Textures/GUI/inventory_bg.png");
            ContainerSlot       = AssetDatabase.GetAsset <Texture>("Resources/Textures/GUI/inventory_slot.png");
            SlotNumberStyle     = new GUIStyle()
            {
                Font                = GUI.ButtonStyle.Font,
                FontSize            = 40,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                AlignmentOffset     = new Vector2(8, 0),
                Normal              = new GUIStyleOption()
                {
                    TextColor = Color4.White
                }
            };
            Input.Input.MouseDown += (sender, args) =>
            {
                if (args.Button == MouseButton.Left)
                {
                    if (SelectedStack != null)
                    {
                        for (int i = 0; i < toDraw.Count; i++)
                        {
                            if (toDraw[i].SelectedSlot == new Vector2(-1, -1))
                            {
                                continue;
                            }

                            if (toDraw[i].GetIsSlotFree(toDraw[i].SelectedSlot))
                            {
                                SelectedStack.LocationInContainer = toDraw[i].SelectedSlot;
                                toDraw[i].ItemsList.Add(SelectedStack);
                                toDraw[i].ItemDroppedIntoContainer(SelectedStack);
                                StackBlockedForSelection = SelectedStack;
                                SelectedStack            = null;
                                return;
                            }
                            else
                            {
                                var stackAtLocation = toDraw[i].GetItemStackByLocation(toDraw[i].SelectedSlot);
                                if (stackAtLocation.ItemKey == SelectedStack.ItemKey)
                                {
                                    int possibleNewSize =
                                        (stackAtLocation.StackSize + stackAtLocation.StackSize) -
                                        stackAtLocation.Item.MaxStackSize;
                                    if (stackAtLocation.AddToStack(SelectedStack.StackSize) == ItemStackState.Full)
                                    {
                                        SelectedStack.StackSize  = possibleNewSize;
                                        StackBlockedForSelection = stackAtLocation;
                                    }
                                    else
                                    {
                                        StackBlockedForSelection = SelectedStack;
                                        SelectedStack            = null;
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
                else if (args.Button == MouseButton.Right)
                {
                    if (SelectedStack != null)
                    {
                        for (int i = 0; i < toDraw.Count; i++)
                        {
                            if (toDraw[i].SelectedSlot == new Vector2(-1, -1))
                            {
                                continue;
                            }

                            if (toDraw[i].GetIsSlotFree(toDraw[i].SelectedSlot))
                            {
                                ItemStack newStack = new ItemStack(SelectedStack.ItemKey, 1, toDraw[i].SelectedSlot);
                                toDraw[i].ItemsList.Add(newStack);
                                toDraw[i].ItemDroppedIntoContainer(newStack);

                                if (SelectedStack.RemoveFromStack() == ItemStackState.Empty)
                                {
                                    SelectedStack = null;
                                }

                                return;
                            }
                            else
                            {
                                var stackAtLocation = toDraw[i].GetItemStackByLocation(toDraw[i].SelectedSlot);
                                if (stackAtLocation.ItemKey == SelectedStack.ItemKey && !stackAtLocation.IsStackFull())
                                {
                                    stackAtLocation.AddToStack();

                                    if (SelectedStack.RemoveFromStack() == ItemStackState.Empty)
                                    {
                                        SelectedStack = null;
                                    }
                                    return;
                                }
                            }
                        }
                    }
                }

                StackBlockedForSelection = null;
            };
        }