Exemple #1
0
        private void SaveCheckBoxListItemState()
        {
            savedSelected = new CompleteItemInfo();

            Dictionary<AttributeInfo, CSOEconItemAttribute> attibuteInfoWithCso = new Dictionary<AttributeInfo, CSOEconItemAttribute>();
            AttributeInfo attrInfo = new AttributeInfo();
            CSOEconItemAttribute csoAttr = new CSOEconItemAttribute();

            int stickerCount = 0;
            foreach (var item in tlpInventoryAttr.Controls)
            {
                if (item is ComboBox)
                {
                    if (((ComboBox)item).Name.Contains("cmbReadItemAttr"))
                    {
                        attrInfo = (AttributeInfo)((ComboBox)item).SelectedItem;
                        csoAttr = new CSOEconItemAttribute();
                    }

                    if (((ComboBox)item).Name.Contains("cmbSelectedItemAttr"))
                    {
                        csoAttr.def_index = (uint)attrInfo.CodedValue;
                        // paint kits
                        if (attrInfo.CodedValue == 6)
                        {
                            if (((ComboBox)item).SelectedItem != null)
                            {
                                savedSelected.PaintAttributeLookup = (PaintInfo)((ComboBox)item).SelectedItem;
                                csoAttr.value_bytes = BitConverter.GetBytes(Convert.ToSingle(savedSelected.PaintAttributeLookup.CodedValue));
                            }
                        }
                        // sticker
                        else if (attrInfo.CodedName.Contains("sticker slot "))
                        {
                            if (((ComboBox)item).SelectedItem != null)
                            {
                                savedSelected.StickerAttributeLookup.Add((StickerInfo)((ComboBox)item).SelectedItem);
                                csoAttr.value_bytes = BitConverter.GetBytes(savedSelected.StickerAttributeLookup[stickerCount].CodedValue);
                                stickerCount++;
                            }
                        }
                        // music
                        else if (attrInfo.CodedValue == 166)
                        {
                            if (((ComboBox)item).SelectedItem != null)
                            {
                                savedSelected.MusicAttributeLookup = (MusicInfo)((ComboBox)item).SelectedItem;
                                csoAttr.value_bytes = BitConverter.GetBytes(savedSelected.MusicAttributeLookup.CodedValue);
                            }
                        }
                    }
                }// wear
                else if (item is TrackBar)
                {
                    if (string.IsNullOrEmpty(savedSelected.PaintAttributeLookup.Name) == false)
                    {
                        csoAttr.def_index = Convert.ToUInt32(attrInfo.CodedValue);

                        float wearLevel = Convert.ToSingle((((TrackBar)item).Value / 100f));
                        csoAttr.value_bytes = BitConverter.GetBytes(wearLevel);
                    }
                }
                else if (item is TextBox)
                {
                    if (((TextBox)item).Name.Contains("tbAttrValue"))
                    {
                        csoAttr.def_index = Convert.ToUInt32(attrInfo.CodedValue);

                        if (attrInfo.IsInteger)
                        {
                            csoAttr.value_bytes = BitConverter.GetBytes(int.Parse(((TextBox)item).Text));
                        }
                        else if (attrInfo.IsString)
                        {
                            csoAttr.value = Convert.ToUInt32(int.Parse(((TextBox)item).Text));
                        }
                        else
                        {
                            csoAttr.value_bytes = BitConverter.GetBytes(float.Parse(((TextBox)item).Text));
                        }
                    }
                }
                else
                {
                    continue;
                }

                if (attrInfo.CodedValue > 0 && csoAttr.def_index > 0)
                {
                    savedSelected.CompleteAttributes.Add(attrInfo, csoAttr);
                }
            }

            foreach (var item in tlpInventoryDesc.Controls)
            {
                if (item is ComboBox)
                {
                    if (((ComboBox)item).Name.Contains("cmbSelectedItemType"))
                    {
                        savedSelected.Item = (ItemInfo)((ComboBox)item).SelectedItem;
                    }
                    else if (((ComboBox)item).Name.Contains("cmbSelectedItemQuality"))
                    {
                        savedSelected.Quality = (QualityInfo)((ComboBox)item).SelectedItem;
                    }
                    else if (((ComboBox)item).Name.Contains("cmbSelectedItemRarity"))
                    {
                        savedSelected.Rarity = (RarityInfo)((ComboBox)item).SelectedItem;
                    }
                }
                else if (item is TextBox)
                {
                    foreach (var attr in savedSelected.CompleteAttributes)
                    {
                        // it has name tag
                        if (attr.Key.CodedValue == 111)
                        {
                            if (((TextBox)item).Name.Contains("tbAttrNameTag"))
                            {
                                savedSelected.CustomName = ((TextBox)item).Text;
                            }
                        }
                    }
                }

                savedSelected.IsChanged = true;
            }

            if (clbInventories.SelectedIndex != currentSelectedItemIdx)
            {
                if (currentSelectedItemIdx != -1)
                {
                    oldSelectedItemIdx = currentSelectedItemIdx;
                    currentSelectedItemIdx = clbInventories.SelectedIndex;
                }

                if (savedSelected != null)
                {
                    if (savedSelected.Item.CodedValue > 0)
                    {
                        if (oldSelectedItemIdx < clbInventories.Items.Count)
                        {
                            clbInventories.SelectedIndexChanged -= clbInventories_SelectedIndexChanged;
                            clbInventories.Items[oldSelectedItemIdx] = savedSelected;
                            clbInventories.SelectedIndexChanged += clbInventories_SelectedIndexChanged;
                        }
                    }
                }
            }
            else
            {
                if (savedSelected != null)
                {
                    if (savedSelected.Item.CodedValue > 0)
                    {
                        clbInventories.SelectedIndexChanged -= clbInventories_SelectedIndexChanged;
                        clbInventories.Items[currentSelectedItemIdx] = savedSelected;
                        clbInventories.SelectedIndexChanged += clbInventories_SelectedIndexChanged;
                    }
                }
            }
        }
        public List<AttributeInfo> GetAllAttributeInfo()
        {
            KeyValue result = this.Read(AttributeInfo.KeyName);
            List<AttributeInfo> returnValue = new List<AttributeInfo>();
            AttributeInfo def;

            if (result != null)
            {
                foreach (var subChildKey in result.Children)
                {
                    def = new AttributeInfo();

                    //skip the first "default" subkey
                    if (subChildKey.Name.Equals("default", StringComparison.CurrentCultureIgnoreCase))
                    {
                        continue;
                    }
                    else
                        def.CodedValue = int.Parse(subChildKey.Name);

                    foreach (var itemSubChildKey in subChildKey.Children)
                    {
                        if (itemSubChildKey.Name.Equals(AttributeInfo.SubKeyCodedName, StringComparison.CurrentCultureIgnoreCase))
                        {
                            def.CodedName = itemSubChildKey.Value;
                        }
                        else if (itemSubChildKey.Name.Equals(AttributeInfo.SubKeyRealName, StringComparison.CurrentCultureIgnoreCase))
                        {
                            def.RealName = itemSubChildKey.Value;
                        }
                        else if (itemSubChildKey.Name.Equals(AttributeInfo.IsIntegerStr, StringComparison.CurrentCultureIgnoreCase))
                        {
                            if (itemSubChildKey.Value.Equals("1", StringComparison.CurrentCultureIgnoreCase))
                            {
                                def.IsInteger = true;
                            }
                            else
                            {
                                def.IsInteger = false;
                            }
                        }
                    }
                    returnValue.Add(def);
                }
            }

            return returnValue;
        }