Exemple #1
0
 public static void LoadList(string filePath)
 {
     RenewList();
     GuiManager.UpdateGoodsView(); // clear
     try
     {
         var parser = new FileIniDataParser();
         var data   = parser.ReadFile(filePath, Globals.LocalEncoding);
         foreach (var sectionData in data.Sections)
         {
             int head;
             if (int.TryParse(sectionData.SectionName, out head))
             {
                 var section = data[sectionData.SectionName];
                 GoodsList[head] = new GoodsItemInfo(
                     section["IniFile"],
                     int.Parse(section["Number"]));
             }
         }
     }
     catch (Exception exception)
     {
         RenewList();
         Log.LogFileLoadError("Goods list", filePath, exception);
     }
     GuiManager.UpdateGoodsView();
 }
Exemple #2
0
        public static bool AddGoodToList(string fileName, out int index, out Good outGood)
        {
            index   = -1;
            outGood = null;
            for (var i = ListIndexBegin; i <= ListIndexEnd; i++)
            {
                var info = GoodsList[i];
                if (info != null && info.TheGood != null)
                {
                    if (Utils.EqualNoCase(info.TheGood.FileName, fileName))
                    {
                        info.Count += 1;
                        index       = i;
                        outGood     = info.TheGood;
                        return(true);
                    }
                }
            }

            for (var i = StoreIndexBegin; i <= StoreIndexEnd; i++)
            {
                var info = GoodsList[i];
                if (info == null)
                {
                    GoodsList[i] = new GoodsItemInfo(fileName, 1);
                    index        = i;
                    outGood      = GoodsList[i].TheGood;
                    return(true);
                }
            }

            return(false);
        }
Exemple #3
0
        public static bool AddGoodToList(string fileName, out int index, out Good outGood)
        {
            index   = -1;
            outGood = null;
            switch (Type)
            {
            case ListType.TypeByGoodType:
            {
                for (var i = ListIndexBegin; i <= ListIndexEnd; i++)
                {
                    var info = GoodsList[i];
                    if (info != null && info.TheGood != null)
                    {
                        if (Utils.EqualNoCase(info.TheGood.FileName, fileName))
                        {
                            info.Count += 1;
                            index       = i;
                            outGood     = info.TheGood;
                            return(true);
                        }
                    }
                }

                for (var i = StoreIndexBegin; i <= StoreIndexEnd; i++)
                {
                    var info = GoodsList[i];
                    if (info == null)
                    {
                        GoodsList[i] = new GoodsItemInfo(fileName, 1);
                        index        = i;
                        outGood      = GoodsList[i].TheGood;
                        return(true);
                    }
                }
            }
            break;

            case ListType.TypeByGoodItem:
            {
                for (var i = StoreIndexBegin; i <= StoreIndexEnd; i++)
                {
                    var info = GoodsList[i];
                    if (info == null)
                    {
                        GoodsList[i] = new GoodsItemInfo(fileName, 1);
                        index        = i;
                        outGood      = GoodsList[i].TheGood;
                        return(true);
                    }
                }

                for (var i = BottomIndexBegin; i <= BottomIndexEnd; i++)
                {
                    var info = GoodsList[i];
                    if (info == null)
                    {
                        GoodsList[i] = new GoodsItemInfo(fileName, 1);
                        index        = i;
                        outGood      = GoodsList[i].TheGood;
                        return(true);
                    }
                }
            }
            break;

            default:
                Log.LogMessage(@"GoodsListType 设置错误,请检查Content\ui\UI_Settings.ini文件");
                return(false);
            }

            GuiManager.ShowMessage("物品栏已满");

            return(false);
        }
Exemple #4
0
        public static bool AddGoodToList(string fileName, out int index, out Good outGood)
        {
            index = -1;
            outGood = null;
            var good = Utils.GetGood(fileName);
            var needSaveToGame = false;
            if (good.Kind == Good.GoodKind.Equipment && good.HasRandAttr)
            {
                good = good.GetOneNonRandom();
                needSaveToGame = true;
            }

            fileName = good.FileName;
            switch (Type)
            {
                case ListType.TypeByGoodType:
                {
                    for (var i = ListIndexBegin; i <= ListIndexEnd; i++)
                    {
                        var info = GoodsList[i];
                        if (info != null && info.TheGood != null)
                        {
                            if (Utils.EqualNoCase(info.TheGood.FileName, fileName))
                            {
                                info.Count += 1;
                                index = i;
                                outGood = info.TheGood;
                                CheckAddNoEquipGood(outGood);
                                return true;
                            }
                        }
                    }

                    for (var i = StoreIndexBegin; i <= StoreIndexEnd; i++)
                    {
                        var info = GoodsList[i];
                        if (info == null)
                        {
                            if (needSaveToGame)
                            {
                                good.Save(Path.Combine(StorageBase.SaveGameDirectory, good.FileName));
                            }
                            GoodsList[i] = new GoodsItemInfo(fileName, 1);
                            index = i;
                            outGood = GoodsList[i].TheGood;
                            CheckAddNoEquipGood(outGood);
                            return true;
                        }
                    }
                }
                    break;
                case ListType.TypeByGoodItem:
                {
                    for (var i = StoreIndexBegin; i <= StoreIndexEnd; i++)
                    {
                        var info = GoodsList[i];
                        if (info == null)
                        {
                            if (needSaveToGame)
                            {
                                good.Save(Path.Combine(StorageBase.SaveGameDirectory, good.FileName));
                            }
                            GoodsList[i] = new GoodsItemInfo(fileName, 1);
                            index = i;
                            outGood = GoodsList[i].TheGood;
                            CheckAddNoEquipGood(outGood);
                            return true;
                        }
                    }

                    for (var i = BottomIndexBegin; i <= BottomIndexEnd; i++)
                    {
                        var info = GoodsList[i];
                        if (info == null)
                        {
                            if (needSaveToGame)
                            {
                                good.Save(Path.Combine(StorageBase.SaveGameDirectory, good.FileName));
                            }
                            GoodsList[i] = new GoodsItemInfo(fileName, 1);
                            index = i;
                            outGood = GoodsList[i].TheGood;
                            CheckAddNoEquipGood(outGood);
                            return true;
                        }
                    }
                }
                    break;
                default:
                    Log.LogMessage(@"GoodsListType 设置错误,请检查Content\ui\UI_Settings.ini文件");
                    return false;
            }

            GuiManager.ShowMessage("物品栏已满");

            return false;
        }