コード例 #1
0
 public void AddItem(Item item) {
     //Looks to see if item exists in list
     for (int i = 0; i < inventoryList.Count; i++) {
         if (inventoryList[i].item.id == item.id) {
             //It exists already, just increment quantity by 1
             inventoryList[i].quantity++;
             return;
         }
     }
     //If there's no item like this in the list, create a new entry for it and set quantity to 1
     InventoryEntry inEntry = new InventoryEntry();
     inEntry.item = item;
     inEntry.quantity = 1;
     inEntry.invenID = lastInvenIDAssigned;
     lastInvenIDAssigned++;
     inventoryList.Add(inEntry);
     //If this is the first item player gets, select it automatically
     if (inventoryList.Count == 1) {
         SelectItem(0);
     }
     //If it's a permanent, use it immediately
     if (item.isPermanent) {
         UseItem(inEntry.invenID);
     }
     //Notify listeners
     inventoryChangeEvent.Invoke();
 }
コード例 #2
0
        private void btnItemAdd_Click(object sender, EventArgs e)
        {
            if (tbID.Text != "")
            {

                InventoryEntry invEntry;
                for (int i = 0; i < inventory.Count; i++)
                //foreach (InventoryEntry invEntry in inventory)
                {
                    if (inventory[i].item.id.ToString() == tbID.Text && inventory[i].quality == (float)nudQuality.Value)
                    {
                        invEntry = inventory[i];
                        invEntry.quantity++;
                        invEntry.gewichtGesamt = invEntry.item.gewicht * invEntry.quantity;
                        invEntry.wertGesamt = (invEntry.item.wert * invEntry.quantity)*((float)nudQuality.Value / 100.0f);
                        inventory[i] = invEntry;
                        RefreshInventoryView();
                        return;
                    }
                }

                Item item = itemList[int.Parse(tbID.Text)];
                invEntry = new InventoryEntry();
                invEntry.item = item;
                invEntry.quantity = 1;
                invEntry.gewichtGesamt = item.gewicht;
                invEntry.wertGesamt = item.wert *((float)nudQuality.Value/100.0f);
                invEntry.quality = (float)nudQuality.Value;
                inventory.Add(invEntry);

                //if (inventory.ContainsKey(tbID.Text + "#" + nudQuality.Value.ToString())) //Quantity + 1
                //{

                //    inventory[tbID.Text + "#" + nudQuality.Value.ToString()].quantity++;
                //}
                //else
                //{
                //    Item item = itemList[int.Parse(tbID.Text)];
                //    item.quality = (float)(nudQuality.Value);
                //    inventory.Add(tbID.Text + "#" + nudQuality.Value.ToString(), item);
                //}
                RefreshInventoryView();
            }
        }
コード例 #3
0
ファイル: Inventory.cs プロジェクト: JaromNorris/Retake-Game
 /*
  * Adds the given object to the inventory.
  * If there is already an instance of the item in the inventory, simply
  *   increments the count of the entry.
  * If there is no existing instance, will put the object in the first open
  *   slot in the inventory.
  * This will update the hotbar as needed.
  * Will do nothing if there are no more open spots for the object.
  */
 public void Add(InventoryEntry ie)
 {
     // see if an InventoryEntry of the same type and species is in the inventory
     foreach (InventoryEntry entry in inventory)
         if (entry != null && ie.type.Equals(entry.type) && ie.species.Equals(entry.species))
         {
             // if so, increment the count on the existing object
             entry.count++;
             return;
         }
     // if the inventory is full, don't add anything
     if (nextInventory == inventory.Length)
         return;
     // if nothing else, add it to the inventory at the first available spot
     inventory[nextInventory] = ie;
     inventoryPanels[nextInventory].gameObject.GetComponent<CanvasGroup>().alpha = 1;
     inventoryContainers[nextInventory].GetChild(0).gameObject.GetComponent<Image>().sprite = ie.sprite;
     // increment the indicator for the next open spot until it finds one
     //   or reaches the end of the inventory
     do
         nextInventory++;
     while (inventory[nextInventory] != null && nextInventory < inventory.Length);
     UpdateHotbar(hotbar, inventory);
 }
コード例 #4
0
    /*
     * 1. push block to fastInventory with same geoCode
     * 2. push block to fastInventory empty entry
     * 3. push block to mainInvenotry with same geoCode
     * 4. pubh block to mainInventory with empty entry
     * return remain block num
     */
    public int AddBlockWithPickUp(int geoCode, int addNum)
    {
        // 1.Process
        foreach (KeyValuePair <int, InventoryEntry> elem in fastInventory)
        {
            InventoryEntry entry = elem.Value;
            if (addNum > 0 && entry.IsGeocode(geoCode) && !entry.IsFull())
            {
                int pushBlockCount = Mathf.Min(addNum, entry.GetCanPushItemNum());  //push count block

                entry.ItemAddNum(pushBlockCount);
                addNum -= pushBlockCount;   //want to add block num - push block num
            }

            if (addNum == 0)
            {
                break;
            }
        }
        // 2. Process
        foreach (KeyValuePair <int, InventoryEntry> elem in fastInventory)
        {
            InventoryEntry entry = elem.Value;
            if (addNum > 0 && entry.IsGeocode(0) && !entry.IsFull())
            {
                int pushBlockCount = Mathf.Min(addNum, entry.GetCanPushItemNum()); //push count block

                addNum -= pushBlockCount;                                          //want to add block num - push block num

                if (entry.IsEmpty())
                {
                    GameObject imageObj = ItemPool.instance.GetItemBlockGameObjectFromPool(geoCode);
                    imageObj.transform.SetParent(fastInventoryGameObject[elem.Key].transform, false);
                    entry.ItemAddNum(pushBlockCount, imageObj);
                }
                else
                {
                    entry.ItemAddNum(pushBlockCount);
                }

                entry.m_geoCode = geoCode;
            }

            if (addNum == 0)
            {
                break;
            }
        }

        foreach (KeyValuePair <int, InventoryEntry> elem in mainInventory)
        {
            InventoryEntry entry = elem.Value;
            if (addNum > 0 && entry.IsGeocode(geoCode) && !entry.IsFull())
            {
                int pushBlockCount = Mathf.Min(addNum, entry.GetCanPushItemNum()); //push count block

                addNum -= pushBlockCount;                                          //want to add block num - push block num
                entry.ItemAddNum(pushBlockCount);
            }

            if (addNum == 0)
            {
                break;
            }
        }

        foreach (KeyValuePair <int, InventoryEntry> elem in mainInventory)
        {
            InventoryEntry entry = elem.Value;
            if (addNum > 0 && entry.IsGeocode(0) && !entry.IsFull())
            {
                int pushBlockCount = Mathf.Min(addNum, entry.GetCanPushItemNum()); //push count block

                addNum -= pushBlockCount;                                          //want to add block num - push block num

                if (entry.IsEmpty())
                {
                    GameObject imageObj = ItemPool.instance.GetItemBlockGameObjectFromPool(geoCode);
                    imageObj.transform.SetParent(mainInventoryGameObject[elem.Key].transform, false);
                    entry.ItemAddNum(pushBlockCount, imageObj);
                }
                else
                {
                    entry.ItemAddNum(pushBlockCount);
                }
                entry.m_geoCode = geoCode;
            }

            if (addNum == 0)
            {
                break;
            }
        }
        return(addNum);
    }
コード例 #5
0
        private void equipmentPanel_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.SmoothingMode      = smoothingMode;
            e.Graphics.CompositingQuality = compositingQuality;
            e.Graphics.CompositingMode    = compositingMode;
            e.Graphics.InterpolationMode  = interpolationMode;
            e.Graphics.PixelOffsetMode    = pixelOffsetMode;
            e.Graphics.TextRenderingHint  = textRenderingHint;

            InventoryEntry inv = gameMemory.Player.Equipment;

            if (inv == default || inv.IsEmpty)
            {
                return;
            }

            int   imageX    = Program.INV_SLOT_WIDTH / 2;
            int   imageY    = 0;
            int   textX     = imageX + Program.INV_SLOT_WIDTH;
            int   textY     = imageY + Program.INV_SLOT_HEIGHT;
            Brush textBrush = Brushes.White;

            if (inv.Quantity == 0)
            {
                textBrush = Brushes.DarkRed;
            }
            else if (inv.IsAcid)
            {
                textBrush = Brushes.Yellow;
            }
            else if (inv.IsBOW)
            {
                textBrush = Brushes.Green;
            }
            else if (inv.IsFlame)
            {
                textBrush = Brushes.Red;
            }

            TextureBrush imageBrush;

            if (Program.ItemToImageTranslation.ContainsKey(inv.Type))
            {
                imageBrush = new TextureBrush(inventoryImage, Program.ItemToImageTranslation[inv.Type]);
            }
            else
            {
                imageBrush = new TextureBrush(inventoryError, new Rectangle(0, 0, Program.INV_SLOT_WIDTH, Program.INV_SLOT_HEIGHT));
            }

            imageBrush.TranslateTransform(Program.INV_SLOT_WIDTH / 2, 0);

            // Double-slot item.
            if (imageBrush.Image.Width == Program.INV_SLOT_WIDTH * 2)
            {
                imageBrush.TranslateTransform(Program.INV_SLOT_WIDTH / 3 + Program.INV_SLOT_WIDTH, 0);
                imageX -= Program.INV_SLOT_WIDTH / 2;
            }

            e.Graphics.FillRectangle(imageBrush, imageX, imageY, imageBrush.Image.Width, imageBrush.Image.Height);
            e.Graphics.DrawString(!inv.IsInfinite ? inv.Quantity.ToString() : "∞", new Font("Consolas", 14, FontStyle.Bold), textBrush, textX, textY, invStringFormat);
        }
コード例 #6
0
    public void UpdateItemCounts(bool checkAllItems, int singleItemIndex = 0)
    {
        if (checkAllItems)
        {
            for (int i = 0; i < 14; i++)
            {
                if (i < equips.Count)
                {
                    ItemData id = equips[i];
                    try
                    {
                        int itemStock = Inventory.allItems[id.itemID];
                        if (itemStock > 0)
                        {
                            InventoryEntry ie = inventoryEntries[i];

                            //ie.itemName.text = ";
                            ie.itemNum.text = "" + itemStock;
                        }
                        else
                        {
                            InventoryEntry ie = inventoryEntries[i];
                            ie.itemNum.text  = "";
                            ie.itemName.text = "";
                            //listTexts[i].GetComponent<Text>().text += "";
                        }
                    } catch (KeyNotFoundException e)
                    {
                    }
                }
                else
                {
                    InventoryEntry ie = inventoryEntries[i];
                    ie.itemNum.text  = "";
                    ie.itemName.text = "";
                }
            }
        }
        else
        {
            Debug.Log("UPdate entry " + singleItemIndex);
            ItemData id = equips[singleItemIndex];

            if (id != null)
            {
                try {
                    int itemStock = Inventory.allItems[id.itemID];
                    if (itemStock > 0)
                    {
                        InventoryEntry ie = inventoryEntries[singleItemIndex];
                        ie.itemNum.text = "" + itemStock;
                    }
                    else
                    {
                        InventoryEntry ie = inventoryEntries[singleItemIndex];
                        ie.itemNum.text  = "";
                        ie.itemName.text = "";
                    }
                } catch (KeyNotFoundException e)
                {
                    e = null;
                    Debug.Log("Key not found");
                }
            }
        }
    }
コード例 #7
0
 public void Awake()
 {
     entry = GetComponent <InventoryEntry>();
 }
コード例 #8
0
ファイル: Inventory.cs プロジェクト: JaromNorris/Retake-Game
 private void UpdateHotbar(InventoryEntry[] hotbar, InventoryEntry[] inventory)
 {
     for (int i = 0; i < hotbarSize; i++)
     {
         hotbar[i] = inventory[i];
         hotbarPanels[i].sprite = inventoryPanels[i].sprite;
         hotbarPanels[i].gameObject.GetComponent<CanvasGroup>().alpha = inventoryPanels[i].gameObject.GetComponent<CanvasGroup>().alpha;
     }
     currentItem = inventory[currentIndex];
 }
コード例 #9
0
 public void RightClick_Hand_MadenInventory(int index, InventoryEntry handEntry)
 {
     //InventoryEntry.SwapInventoryEntry(UIManager.instance.cursorSlot.GetComponent<InventoryEntry>(), UIManager.instance.cursorSlot, madenInventory[index], madenInventoryGameObject[index]);
 }
コード例 #10
0
        public override void LoadXML(XmlNode element, FileVersion version)
        {
            try {
                base.LoadXML(element, version);

                Race = (RaceID)Enum.Parse(typeof(RaceID), ReadElement(element, "Race"));
                Gfx  = ReadElement(element, "gfx");
                Sfx  = ReadElement(element, "sfx");

                string signs = ReadElement(element, "Signs");
                Flags = new CreatureFlags(signs);
                if (!signs.Equals(Flags.Signature))
                {
                    throw new Exception("CreatureSigns not equals " + Convert.ToString(GUID));
                }

                MinHP        = Convert.ToInt16(ReadElement(element, "minHP"));
                MaxHP        = Convert.ToInt16(ReadElement(element, "maxHP"));
                AC           = Convert.ToInt16(ReadElement(element, "AC"));
                Speed        = Convert.ToSByte(ReadElement(element, "Speed"));
                ToHit        = Convert.ToInt16(ReadElement(element, "ToHit"));
                Attacks      = Convert.ToSByte(ReadElement(element, "Attacks"));
                Constitution = Convert.ToInt16(ReadElement(element, "Constitution"));
                Strength     = Convert.ToInt16(ReadElement(element, "Strength"));
                MinDB        = Convert.ToInt16(ReadElement(element, "minDB"));
                MaxDB        = Convert.ToInt16(ReadElement(element, "maxDB"));
                Survey       = Convert.ToByte(ReadElement(element, "Survey"));
                Level        = Convert.ToSByte(ReadElement(element, "Level"));
                Alignment    = (Alignment)Enum.Parse(typeof(Alignment), ReadElement(element, "Alignment"));
                Weight       = (float)ConvertHelper.ParseFloat(ReadElement(element, "Weight"), 0.0f, true);
                Sex          = StaticData.GetSexBySign(ReadElement(element, "Sex"));

                FleshEffect  = Convert.ToInt32(ReadElement(element, "FleshEffect"));
                FleshSatiety = Convert.ToInt16(ReadElement(element, "FleshSatiety"));

                string sym = ReadElement(element, "Symbol");
                Symbol      = (string.IsNullOrEmpty(sym) ? '?' : sym[0]);
                Extinctable = Convert.ToBoolean(ReadElement(element, "Extinctable"));
                Dexterity   = Convert.ToUInt16(ReadElement(element, "Dexterity"));
                Hear        = Convert.ToByte(ReadElement(element, "Hear"));
                Smell       = Convert.ToByte(ReadElement(element, "Smell"));
                FramesCount = Convert.ToByte(ReadElement(element, "FramesCount"));

                XmlNodeList nl = element.SelectSingleNode("Lands").ChildNodes;
                Lands = new string[nl.Count];
                for (int i = 0; i < nl.Count; i++)
                {
                    XmlNode n = nl[i];
                    Lands[i] = n.Attributes["ID"].InnerText;
                }

                nl = element.SelectSingleNode("Abilities").ChildNodes;
                for (int i = 0; i < nl.Count; i++)
                {
                    XmlNode   n   = nl[i];
                    AbilityID ab  = (AbilityID)Enum.Parse(typeof(AbilityID), n.Attributes["ID"].InnerText);
                    int       val = Convert.ToInt32(n.Attributes["Value"].InnerText);
                    Abilities.Add((int)ab, val);
                }

                nl = element.SelectSingleNode("Skills").ChildNodes;
                for (int i = 0; i < nl.Count; i++)
                {
                    XmlNode n   = nl[i];
                    SkillID sk  = (SkillID)Enum.Parse(typeof(SkillID), n.Attributes["ID"].InnerText);
                    int     val = Convert.ToInt32(n.Attributes["Value"].InnerText);
                    Skills.Add((int)sk, val);
                }

                nl        = element.SelectSingleNode("Inventory").ChildNodes;
                Inventory = new InventoryEntry[nl.Count];
                for (int i = 0; i < nl.Count; i++)
                {
                    XmlNode n = nl[i];

                    InventoryEntry invEntry = new InventoryEntry();
                    Inventory[i]      = invEntry;
                    invEntry.ItemSign = n.Attributes["ID"].InnerText;
                    invEntry.CountMin = Convert.ToInt32(n.Attributes["CountMin"].InnerText);
                    invEntry.CountMax = Convert.ToInt32(n.Attributes["CountMax"].InnerText);

                    XmlAttribute stat = n.Attributes["Status"];
                    if (stat != null)
                    {
                        ParseStatus(invEntry, stat.InnerText);
                    }
                }

                XmlNodeList dnl = element.SelectNodes("Dialog");
                if (dnl.Count > 0)
                {
                    XmlNode dialogXmlNode = (XmlNode)dnl[0];
                    Dialog.LoadXML(dialogXmlNode, version, true);
                }
            } catch (Exception ex) {
                Logger.Write("CreatureEntry.loadXML(): " + ex.Message);
                throw ex;
            }
        }
コード例 #11
0
        private bool populate_inventory_rows(
            ObservableCollection <InventoryItemBaseRow> inv_rows, InventoryItemIdent parent, Inventory inv, InventoryItemIdent selected
            )
        {
            bool found_selected = false;

            if (parent is null)
            {
                inv_rows.Add(new InventoryItemHeaderRow());
            }
            foreach (Guid guid in inv.contents.Keys)
            {
                InventoryEntry ent = inv.contents[guid];
                if ((ent is SingleItem item) && (item.containers is not null))
                {
                    InventoryItemIdent ent_ident = new InventoryItemIdent(guid: guid);
                    InventoryItemRow   ent_row   = new InventoryItemRow(parent, ent_ident, ent.name, "", "");
                    bool ent_found_selected      = false;
                    ent_row._children = new ObservableCollection <InventoryItemBaseRow>();
                    for (int i = 0; i < item.containers.Length; i++)
                    {
                        Inventory          child_inv = item.containers[i];
                        InventoryItemIdent inv_ident = new InventoryItemIdent(guid: guid, idx: i);
                        decimal?           capacity  = item.item.containers[i].weight_capacity;
                        if (capacity is not null)
                        {
                            capacity -= item.containers[i].weight;
                            inventory_capacity[inv_ident] = capacity.Value;
                        }
                        InventoryItemRow inv_row = new InventoryItemRow(
                            ent_ident,
                            inv_ident,
                            child_inv.name,
                            "",
                            capacity.ToString(),
                            new ObservableCollection <InventoryItemBaseRow>()
                            );
                        bool child_found_selected = this.populate_inventory_rows(inv_row.children, inv_ident, child_inv, selected);
                        if (inv_ident == selected)
                        {
                            inv_row._is_selected = true;
                            child_found_selected = true;
                        }
                        else if (child_found_selected)
                        {
                            inv_row._is_expanded = true;
                        }
                        ent_found_selected = ent_found_selected || child_found_selected;
                        ent_row.children.Add(inv_row);
                        this.inventory_row_index[inv_ident] = inv_row;
                    }
                    if (ent_ident == selected)
                    {
                        ent_row._is_selected = true;
                        ent_found_selected   = true;
                    }
                    else if (ent_found_selected)
                    {
                        ent_row._is_expanded = true;
                    }
                    found_selected = found_selected || ent_found_selected;
                    inv_rows.Add(ent_row);
                    this.inventory_row_index[ent_ident] = ent_row;
                }
            }
            return(found_selected);
        }
コード例 #12
0
        public ItemAddWindow(CampaignSave save_state, CampaignState state, Guid?guid = null, InventoryItemIdent selected = null, InventoryEntry entry = null)
        {
            this.valid               = false;
            this.need_refresh        = false;
            this.state               = save_state;
            this.entry               = entry;
            this.item                = entry?.item;
            this.inventory_rows      = new ObservableCollection <InventoryItemBaseRow>();
            this.inventory_row_index = new Dictionary <InventoryItemIdent, InventoryItemRow>();
            this.inventory_capacity  = new Dictionary <InventoryItemIdent, decimal>();
            this.populate_inventories(state, guid, selected);
            InitializeComponent();
            Visibility item_visibility = (guid is null ? Visibility.Collapsed : Visibility.Visible);

            this.item_label.Visibility         = item_visibility;
            this.item_box.Visibility           = item_visibility;
            this.item_set_but.Visibility       = item_visibility;
            this.count_label.Visibility        = item_visibility;
            this.count_box.Visibility          = item_visibility;
            this.unidentified_label.Visibility = item_visibility;
            this.unidentified_box.Visibility   = item_visibility;
            this.inventory_list.ItemsSource    = this.inventory_rows;
        }
コード例 #13
0
ファイル: InventoryService.cs プロジェクト: sergik/Cardio
 public InventoryService()
 {
     Slots = new InventoryEntry[Capacity];
     SetDefaultAsset();
     _moneySlotIndex = Items.BloodElement.SlotIndex;
 }
コード例 #14
0
 public static void SetEntry(this TreeNodeAdv nodeAdv, InventoryEntry entry)
 {
     (nodeAdv.Tag as Node).Tag = entry;
 }
コード例 #15
0
 public void RightClick_Hand_FastInventory(int index, InventoryEntry handEntry)
 {
     InventoryEntry.RightClickEntry(fastInventory[index], fastInventoryGameObject[index], UIManager.instance.cursorSlot.GetComponent <InventoryEntry>(), UIManager.instance.cursorSlot);
     SceneManager.playerInstance.PlayerHandItemChange(SceneManager.playerInstance.curSelectedFastInventoryIndex);
 }
コード例 #16
0
 public void RightClick_Hand_MainInventory(int index, InventoryEntry handEntry)
 {
     InventoryEntry.RightClickEntry(mainInventory[index], mainInventoryGameObject[index], UIManager.instance.cursorSlot.GetComponent <InventoryEntry>(), UIManager.instance.cursorSlot);
 }
コード例 #17
0
        public static string WeaponInfo(InventoryEntry invEntry)
        {
            string WeaponInfo;

            string[] parts = invEntry.Parts.ToArray <string>();

            int Damage = db.GetWeaponDamage(parts, invEntry.QualityIndex, invEntry.LevelIndex);

            WeaponInfo = "Expected Damage: " + Damage;

            double statvalue = db.GetExtraStats(parts, "TechLevelIncrease");

            if (statvalue != 0)
            {
                WeaponInfo += "\r\nElemental Tech Level: " + statvalue;
            }

            statvalue = db.GetExtraStats(parts, "WeaponDamage");
            if (statvalue != 0)
            {
                WeaponInfo += "\r\n" + statvalue.ToString("P") + " Damage";
            }

            statvalue = db.GetExtraStats(parts, "WeaponFireRate");
            if (statvalue != 0)
            {
                WeaponInfo += "\r\n" + statvalue.ToString("P") + " Rate of Fire";
            }

            statvalue = db.GetExtraStats(parts, "WeaponCritBonus");
            if (statvalue != 0)
            {
                WeaponInfo += "\r\n" + statvalue.ToString("P") + " Critical Damage";
            }

            statvalue = db.GetExtraStats(parts, "WeaponReloadSpeed");
            if (statvalue != 0)
            {
                WeaponInfo += "\r\n" + statvalue.ToString("P") + " Reload Speed";
            }

            statvalue = db.GetExtraStats(parts, "WeaponSpread");
            if (statvalue != 0)
            {
                WeaponInfo += "\r\n" + statvalue.ToString("P") + " Spread";
            }

            statvalue = db.GetExtraStats(parts, "MaxAccuracy");
            if (statvalue != 0)
            {
                WeaponInfo += "\r\n" + statvalue.ToString("P") + " Max Accuracy";
            }

            statvalue = db.GetExtraStats(parts, "MinAccuracy");
            if (statvalue != 0)
            {
                WeaponInfo += "\r\n" + statvalue.ToString("P") + " Min Accuracy";
            }

            return(WeaponInfo);
        }
コード例 #18
0
    private void Awake()
    {
        if (instance == null)
        {
            instance = this;
            DontDestroyOnLoad(instance);
        }
        else
        {
            Destroy(this.gameObject);
        }

        mainInventory            = new Dictionary <int, InventoryEntry>();
        fastInventory            = new Dictionary <int, InventoryEntry>();
        toolInventory            = new Dictionary <int, InventoryEntry>();
        madenInventory           = new Dictionary <int, InventoryEntry>();
        mainInventoryGameObject  = new Dictionary <int, GameObject>();
        fastInventoryGameObject  = new Dictionary <int, GameObject>();
        toolInventoryGameObject  = new Dictionary <int, GameObject>();
        madenInventoryGameObject = new Dictionary <int, GameObject>();

        int index = 0;

        foreach (GameObject entry in mainInventorySeriallized)
        {
            InventoryEntry invenEntry = entry.GetComponent <InventoryEntry>();
            invenEntry.m_index     = index;
            invenEntry.m_entryType = (int)ENUM_INVEN_TYPE.MAIN;

            mainInventory.Add(index, invenEntry);
            mainInventoryGameObject.Add(index, entry);
            index++;
        }

        index = 0;
        foreach (GameObject entry in fastInventorySeriallized)
        {
            InventoryEntry invenEntry = entry.GetComponent <InventoryEntry>();
            invenEntry.m_index     = index;
            invenEntry.m_entryType = (int)ENUM_INVEN_TYPE.FAST;

            fastInventory.Add(index, invenEntry);
            fastInventoryGameObject.Add(index, entry);
            index++;
        }

        index = 0;
        foreach (GameObject entry in toolInventorySeriallized)
        {
            InventoryEntry invenEntry = entry.GetComponent <InventoryEntry>();
            invenEntry.m_index     = index;
            invenEntry.m_entryType = (int)ENUM_INVEN_TYPE.TOOLBOX;

            toolInventory.Add(index, invenEntry);
            toolInventoryGameObject.Add(index, entry);
            index++;
        }

        index = 0;
        foreach (GameObject entry in madenInventorySeriallized)
        {
            InventoryEntry invenEntry = entry.GetComponent <InventoryEntry>();
            invenEntry.m_index     = index;
            invenEntry.m_entryType = (int)ENUM_INVEN_TYPE.MADENBOX;

            madenInventory.Add(index, invenEntry);
            madenInventoryGameObject.Add(index, entry);
            index++;
        }
    }
コード例 #19
0
ファイル: LevelEditorGUI.cs プロジェクト: minimalgeek/Gravity
    // Called when updating the Scene view
    void OnSceneGUI(SceneView sceneview)
    {
        if (root == null)
        {
            CreateLevelRoot();
        }

        Event e = Event.current;

        #region KeyDown
        //if (e.type == EventType.KeyDown)
        //{
        //    switch (e.keyCode)
        //    {
        //        case KeyCode.Alpha0:
        //            PlacingMode = PlacingModes.Off;
        //            break;
        //        case KeyCode.Alpha1:
        //            PlacingMode = PlacingModes.Single;
        //            break;
        //        case KeyCode.Alpha2:
        //            PlacingMode = PlacingModes.Arc;
        //            break;
        //        case KeyCode.Alpha3:
        //            PlacingMode = PlacingModes.Wall;
        //            break;
        //        case KeyCode.Alpha4:
        //            PlacingMode = PlacingModes.Ring;
        //            break;
        //        default:
        //            break;
        //    }
        //}
        #endregion KeyDown


        #region MouseMove
        if (e.type == EventType.MouseMove)
        {
            switch (PlacingMode)
            {
            case PlacingModes.Off:
                if (ghost != null)
                {
                    RemoveGhosts();
                }
                break;

            case PlacingModes.Single:
                // Place or move ghost
                if (ghost == null)
                {
                    RemoveGhosts();
                    PlaceSingleGhost(ScreenToWorldSnap(e.mousePosition));
                }
                else
                {
                    UpdateSingleGhost(ScreenToWorldSnap(e.mousePosition));
                }
                break;

            case PlacingModes.Arc:
                if (arcPlacingStarted)
                {
                    if (ghost == null)
                    {
                        arcPlacingStarted = false;
                    }
                    else
                    {
                        UpdateArcGhost(ScreenToWorldSnap(e.mousePosition));

                        if (drawGuides)
                        {
                            Handles.DrawWireDisc(Vector3.zero, Vector3.forward, arcRadius);
                        }
                    }
                }
                else
                {
                    if (ghost == null)
                    {
                        RemoveGhosts();
                        PlaceSingleGhost(ScreenToWorldSnap(e.mousePosition));
                    }
                    else
                    {
                        UpdateSingleGhost(ScreenToWorldSnap(e.mousePosition));
                    }
                }
                break;

            case PlacingModes.Wall:
                if (wallPlacingStarted)
                {
                    if (ghost == null)
                    {
                        wallPlacingStarted = false;
                    }
                    else
                    {
                        UpdateWallGhost(ScreenToWorldSnap(e.mousePosition));
                    }
                }
                else
                {
                    if (ghost == null)
                    {
                        RemoveGhosts();
                        PlaceSingleGhost(ScreenToWorldSnap(e.mousePosition));
                    }
                    else
                    {
                        UpdateSingleGhost(ScreenToWorldSnap(e.mousePosition));
                    }
                }
                break;

            case PlacingModes.Ring:
                if (ghost == null)
                {
                    RemoveGhosts();
                    PlaceSingleGhost(ScreenToWorldSnap(e.mousePosition));
                }
                else
                {
                    UpdateSingleGhost(ScreenToWorldSnap(e.mousePosition));
                }
                break;

            default:
                break;
            }
        }
        #endregion KeyDown


        #region MouseDown
        if (e.type == EventType.MouseDown)
        {
            if (e.button == 0)
            {
                switch (PlacingMode)
                {
                case PlacingModes.Off:
                    break;

                case PlacingModes.Single:
                {
                    InventoryEntry entry     = inventory[selectedItem];
                    Vector3        pos       = ScreenToWorldSnap(e.mousePosition);
                    GameObject     newObject = Instantiate(entry.prefab, pos, GetRotator(pos), rootTransform);
                    if (entry.isArc)
                    {
                        float rad = pos.magnitude;
                        try
                        {
                            newObject.GetComponent <ArcMesh>().SetParams(rad - radialThickness, rad, 1, GetAngularGridDensity(rad), 768, 0);
                        }
                        catch { }
                        Undo.RegisterCreatedObjectUndo(newObject, "Place Segment");
                    }
                    else
                    {
                        Undo.RegisterCreatedObjectUndo(newObject, "Place " + entry.displayName);
                    }
                    break;
                }

                case PlacingModes.Arc:
                {
                    if (arcPlacingStarted)
                    {
                        arcPlacingStarted = false;
                        DestroyImmediate(ghost.GetComponent <GhostPlaceholder>());
                        ghost.hideFlags        = 0;
                        ghost.transform.parent = rootTransform;
                        Undo.RegisterCreatedObjectUndo(ghost, "Place Arc");
                        ghost = null;
                    }
                    else
                    {
                        DestroyImmediate(ghost);
                        RemoveGhosts();

                        arcFirstPosition  = ScreenToWorldSnap(e.mousePosition);
                        arcRadius         = arcFirstPosition.magnitude;
                        arcPlacingStarted = true;
                        PlaceArcGhost();

                        if (drawGuides)
                        {
                            Handles.DrawWireDisc(Vector3.zero, Vector3.back, arcRadius);
                        }
                    }
                    break;
                }

                case PlacingModes.Wall:
                {
                    if (wallPlacingStarted)
                    {
                        // TODO:
                        //PlaceWall(wallFirstPosition, ScreenToWorldSnap(e.mousePosition));
                        wallPlacingStarted = false;
                        DestroyImmediate(ghost.GetComponent <GhostPlaceholder>());
                        ghost.hideFlags        = 0;
                        ghost.transform.parent = rootTransform;
                        Undo.RegisterCreatedObjectUndo(ghost, "Place Wall");
                        ghost = null;
                    }
                    else
                    {
                        DestroyImmediate(ghost);
                        RemoveGhosts();

                        wallFirstPosition  = ScreenToWorldSnap(e.mousePosition);
                        wallFirstRadius    = wallFirstPosition.magnitude;
                        wallPlacingStarted = true;
                        PlaceWallGhost();
                    }
                    break;
                }

                case PlacingModes.Ring:
                    PlaceRing(ScreenToWorldSnap(e.mousePosition));
                    break;

                default:
                    break;
                }
            }
        }
        #endregion MouseDown


        #region Guides
        switch (PlacingMode)
        {
        case PlacingModes.Off:
            break;

        case PlacingModes.Single:
            if (ghost != null)
            {
                float rad = ghost.transform.position.magnitude;
                if (drawGuides)
                {
                    Handles.DrawWireDisc(Vector3.back * 2f, Vector3.back, rad);
                }
                if (drawGuides)
                {
                    Handles.DrawWireDisc(Vector3.back * 2f, Vector3.back, rad - radialThickness);
                }
            }
            break;

        case PlacingModes.Arc:
            if (ghost != null)
            {
                float rad = ghost.transform.position.magnitude;
                if (drawGuides)
                {
                    Handles.DrawWireDisc(Vector3.back * 2f, Vector3.back, rad);
                }
                if (drawGuides)
                {
                    Handles.DrawWireDisc(Vector3.back * 2f, Vector3.back, rad - radialThickness);
                }
            }
            break;

        case PlacingModes.Wall:
            if (ghost != null)
            {
                if (wallPlacingStarted)
                {
                    if (drawGuides)
                    {
                        Handles.DrawWireDisc(Vector3.back * 2f, Vector3.back, wallOuterRadius);
                    }
                    if (drawGuides)
                    {
                        Handles.DrawWireDisc(Vector3.back * 2f, Vector3.back, wallInnerRadius);
                    }
                }
                else
                {
                    float rad = ghost.transform.position.magnitude;
                    if (drawGuides)
                    {
                        Handles.DrawWireDisc(Vector3.back * 2f, Vector3.back, rad);
                    }
                    if (drawGuides)
                    {
                        Handles.DrawWireDisc(Vector3.back * 2f, Vector3.back, rad - radialThickness);
                    }
                }
            }
            break;

        case PlacingModes.Ring:
            if (ghost != null)
            {
                float rad = ghost.transform.position.magnitude;
                if (drawGuides)
                {
                    Handles.DrawWireDisc(Vector3.back * 2f, Vector3.back, rad);
                }
                if (drawGuides)
                {
                    Handles.DrawWireDisc(Vector3.back * 2f, Vector3.back, rad - radialThickness);
                }
            }
            break;

        default:
            break;
        }
        #endregion Guides


        #region Handles
        if (PlacingMode == PlacingModes.Off && Tools.current != Tool.View)
        {
            Object[] objects = Selection.GetFiltered(typeof(GameObject), SelectionMode.Editable | SelectionMode.Deep | SelectionMode.ExcludePrefab);
            if (objects.Length > 0)
            {
                float   tangentialDiscRadius = 0;
                Vector3 centerPosition       = Vector3.zero;
                foreach (GameObject obj in objects)
                {
                    float objRadius = obj.transform.position.magnitude;
                    if (objRadius > tangentialDiscRadius)
                    {
                        tangentialDiscRadius = objRadius;
                    }
                    centerPosition += obj.transform.position.WithZ(0f);
                }
                Vector3 centerDirection = Vector3.Normalize(centerPosition);
                if (tangentialDiscRadius == 0)
                {
                    tangentialDiscRadius = 1;
                    centerDirection      = Vector3.down;
                }
                centerPosition = centerDirection * tangentialDiscRadius;

                Color defColor = Handles.color;
                Handles.color = Color.magenta;

                #region Tangential handle
                EditorGUI.BeginChangeCheck();
                tangentialDiscCurrentRotation = Handles.Disc(tangentialDiscCurrentRotation, Vector3.back * 2f, Vector3.back, tangentialDiscRadius, false, 360f / GetAngularGridDensity(tangentialDiscRadius));
                if (EditorGUI.EndChangeCheck())
                {
                    float angle = tangentialDiscPreviousRotation.eulerAngles.z - tangentialDiscCurrentRotation.eulerAngles.z;
                    MoveSelectionTangential(angle);
                    tangentialDiscPreviousRotation = tangentialDiscCurrentRotation;
                }
                #endregion Tangential handle

                #region Radial handle
                EditorGUI.BeginChangeCheck();
                Vector3 newCenterPosition = Handles.Slider(centerPosition, -centerDirection, HandleUtility.GetHandleSize(centerPosition) * 1.4f, Handles.ArrowHandleCap, radialThickness);
                if (EditorGUI.EndChangeCheck())
                {
                    float deltaRadius = (newCenterPosition - centerPosition).Dot(centerDirection);
                    MoveSelectionRadial(deltaRadius);
                }
                #endregion Radial handle

                Handles.color = defColor;
            }
        }
        #endregion Handles

        //radiusTest = Handles.RadiusHandle(Quaternion.identity, Vector3.zero, radiusTest);
        //doPositionTest = Handles.DoPositionHandle(doPositionTest, FaceAxis.GetRotator(doPositionTest));
        //freeMoveTest = Handles.FreeMoveHandle(freeMoveTest, FaceAxis.GetRotator(freeMoveTest),0.5f, Vector3.one*0.6f, Handles.CylinderHandleCap);
        //positionTest = Handles.PositionHandle(positionTest, FaceAxis.GetRotator(positionTest));
    }
コード例 #20
0
 private void AddItemToHotBar(InventoryEntry itemForHotBar)
 {
 }
コード例 #21
0
 public void RemoveFromInventoryItems(InventoryEntry itemToRemove)
 {
     _inventoryItems.Remove(itemToRemove);
 }