Esempio n. 1
0
    // ------------------------------------------------------------------------------------------------------------
    // The inventory window
    public void InventoryWindow(int ID)
    {
        ModifiedStats stats = GetComponent <ModifiedStats>();

        int   lvlToDisplay   = stats.level;
        int   dexToDisplay   = stats.TotalDEX();
        int   strToDisplay   = stats.TotalSTR();
        int   intToDisplay   = stats.TotalINT();
        int   armorToDisplay = stats._armorClass;
        float dmgToDisplay   = stats._baseDamage;

        int cnt = 0;

        berserkerTex = Resources.Load("Character2D/Berzerker Sprite") as Texture2D;

        // Drawing the selection buttons to view different types of items in the inventory
        for (int topRow = 0; topRow < selectorRows; topRow++)
        {
            // Handle which selector button is pressed
            if (GUI.Button(new Rect(35 + (topRow * selectorWidth), 20, selectorWidth, selectorHeight), "" + Selector[topRow]))
            {
                if (Selector[topRow] == "Equipped")
                {
                    // Show the equipped items
                    bShowEquipped = true;

                    // Hide others
                    bShowArmor   = false;
                    bShowItems   = false;
                    bShowWeapons = false;
                }
                else if (Selector[topRow] == "Items")
                {
                    // Show the general items
                    bShowItems = true;

                    // Hide others
                    bShowArmor    = false;
                    bShowEquipped = false;
                    bShowWeapons  = false;
                }
                else if (Selector[topRow] == "Armor")
                {
                    // Show the armor items
                    bShowArmor = true;

                    // Hide others
                    bShowItems    = false;
                    bShowEquipped = false;
                    bShowWeapons  = false;
                }
                else if (Selector[topRow] == "Weapons")
                {
                    // Show the weapon items
                    bShowWeapons = true;

                    // Hide others
                    bShowItems    = false;
                    bShowEquipped = false;
                    bShowArmor    = false;
                }

                clickedItem   = null;
                displayDelete = false;
                //placeInList = null;
            }
        }

        // if we want to show the currently equipped items
        if (bShowEquipped)
        {
            GUI.Label(new Rect(22, 65, buttonWidth, buttonHeight), "Armor");
            GUI.Label(new Rect(200, 65, 50, buttonHeight), "Weapon");

            GUI.Label(new Rect(150, 145, 100, 25), "Player Stats", "box");
            GUI.Label(new Rect(25, 180, 100, 25), "Level: " + lvlToDisplay);
            GUI.Label(new Rect(25, 195, 100, 25), "Dex: " + dexToDisplay);
            GUI.Label(new Rect(25, 210, 100, 25), "Str: " + strToDisplay);
            GUI.Label(new Rect(25, 225, 100, 25), "Int: " + intToDisplay);
            GUI.Label(new Rect(25, 240, 100, 25), "Defense: " + armorToDisplay);
            GUI.Label(new Rect(25, 255, 100, 25), "Damage: " + dmgToDisplay);

            //GUI.DrawTexture ( new Rect ( 250, 180, berserkerTex.width, berserkerTex.height ), berserkerTex );

            for (int x = 0; x < equippedItems.Length; x++)
            {
                // if we have items to show
                if (equippedItems[x] != null)
                {
                    if (x == 3)
                    {
                        if (GUI.Button(new Rect(200, 85, buttonWidth, buttonHeight), x.ToString()))
                        {
                            clickedItem   = equippedItems[x];
                            placeInList   = x;
                            displayDelete = false;
                        }
                    }
                    else
                    {
                        if (GUI.Button(new Rect(20 + (x * buttonWidth), 85, buttonWidth, buttonHeight), x.ToString()))
                        {
                            clickedItem   = equippedItems[x];
                            placeInList   = x;
                            displayDelete = false;
                        }
                    }
                }
                // we dont have items to show
                else
                {
                    if (x == 3)
                    {
                        GUI.Label(new Rect(200, 85, buttonWidth, buttonHeight), "none", "box");
                    }
                    else
                    {
                        GUI.Label(new Rect(20 + (x * buttonWidth), 85, buttonWidth, buttonHeight), "none", "box");
                    }
                }
            }
        }

        // if we want to show the general items that arent currently equipped
        if (bShowItems)
        {
            for (int y = 0; y < inventoryRows; y++)
            {
                for (int x = 0; x < inventoryCols; x++)
                {
                    // if we have items to show
                    if (cnt < items.Count)
                    {
                        GUI.Button(new Rect(20 + (x * buttonWidth), 65 + (y * buttonHeight), buttonWidth, buttonHeight), (x + y * inventoryCols).ToString());
                    }
                    // we dont have items to show
                    else
                    {
                        GUI.Label(new Rect(20 + (x * buttonWidth), 65 + (y * buttonHeight), buttonWidth, buttonHeight), "none", "box");
                    }

                    cnt++;
                }
            }
        }

        // if we want to show the armor that is not equipped
        if (bShowArmor)
        {
            for (int y = 0; y < inventoryRows; y++)
            {
                for (int x = 0; x < inventoryCols; x++)
                {
                    // if we have items to show
                    if (cnt < armor.Count)
                    {
                        if (GUI.Button(new Rect(20 + (x * buttonWidth), 65 + (y * buttonHeight), buttonWidth, buttonHeight), (x + y * inventoryCols).ToString()))
                        {
                            clickedItem   = armor[x + y * inventoryCols];
                            placeInList   = x + y * inventoryCols;
                            displayDelete = false;
                            //print ( placeInList );
                        }
                    }
                    // we dont have items to show
                    else
                    {
                        GUI.Label(new Rect(20 + (x * buttonWidth), 65 + (y * buttonHeight), buttonWidth, buttonHeight), "none", "box");
                    }

                    cnt++;
                }
            }
        }

        // if we want to show the weapons that are not equipped
        if (bShowWeapons)
        {
            for (int y = 0; y < inventoryRows; y++)
            {
                for (int x = 0; x < inventoryCols; x++)
                {
                    // if we have items to show
                    if (cnt < weapons.Count)
                    {
                        if (GUI.Button(new Rect(20 + (x * buttonWidth), 65 + (y * buttonHeight), buttonWidth, buttonHeight), (x + y * inventoryCols).ToString()))
                        {
                            clickedItem   = weapons[x + y * inventoryCols];
                            placeInList   = x + y * inventoryCols;
                            displayDelete = false;
                        }
                    }
                    // we dont have items to show
                    else
                    {
                        GUI.Label(new Rect(20 + (x * buttonWidth), 65 + (y * buttonHeight), buttonWidth, buttonHeight), "none", "box");
                    }

                    cnt++;
                }
            }
        }
    }