コード例 #1
0
        /// <summary>
        /// Add list contains to ProtoSet
        /// </summary>
        private static void AddProtosToSet <T>(ProtoSet <T> protoSet, List <Proto> protos) where T : Proto
        {
            var array = protoSet.dataArray;

            protoSet.Init(array.Length + protos.Count);
            for (int i = 0; i < array.Length; i++)
            {
                protoSet.dataArray[i] = array[i];
            }

            for (int i = 0; i < protos.Count; i++)
            {
                protoSet.dataArray[array.Length + i] = protos[i] as T;

                if (protos[i] is ItemProto item)
                {
                    item.index = array.Length + i;
                }

                if (protos[i] is RecipeProto)
                {
                    RecipeProto proto = protos[i] as RecipeProto;
                    if (proto.preTech != null)
                    {
                        ArrayAddItem(ref proto.preTech.UnlockRecipes, proto.ID);
                        ArrayAddItem(ref proto.preTech.unlockRecipeArray, proto);
                    }
                }

                LDBToolPlugin.logger.LogInfo($"Add {protos[i].ID} {protos[i].Name.Translate()} to {protoSet.GetType().Name}.");
            }

            var dataIndices = new Dictionary <int, int>();

            for (int i = 0; i < protoSet.dataArray.Length; i++)
            {
                protoSet.dataArray[i].sid             = protoSet.dataArray[i].SID;
                dataIndices[protoSet.dataArray[i].ID] = i;
            }

            protoSet.dataIndices = dataIndices;
            if (protoSet is StringProtoSet stringProtoSet)
            {
                for (int i = array.Length; i < protoSet.dataArray.Length; i++)
                {
                    stringProtoSet.nameIndices[protoSet.dataArray[i].Name] = i;
                }
            }
        }
コード例 #2
0
 private static void SearchLDB <T>(ProtoSet <T> protoSet) where T : Proto
 {
     searchResultList.Clear();
     if (protoSet != null)
     {
         foreach (var proto in protoSet.dataArray)
         {
             if (Search == "" || proto.ID.ToString().Contains(Search) || proto.Name.Contains(Search) || proto.Name.Translate().Contains(Search))
             {
                 searchResultList.Add(proto);
             }
         }
     }
     needSearch = false;
 }
コード例 #3
0
        /// <summary>
        /// 添加多个数据到数据表
        /// </summary>
        private static void AddProtosToSet <T>(ProtoSet <T> protoSet, List <Proto> protos) where T : Proto
        {
            var array = protoSet.dataArray;

            protoSet.Init(array.Length + protos.Count);
            for (int i = 0; i < array.Length; i++)
            {
                protoSet.dataArray[i] = array[i];
            }
            for (int i = 0; i < protos.Count; i++)
            {
                protoSet.dataArray[array.Length + i] = protos[i] as T;

                if (protos[i] is ItemProto)
                {
                    Traverse.Create(protos[i]).Property("index").SetValue(array.Length + i);
                }
                if (protos[i] is RecipeProto)
                {
                    RecipeProto proto = protos[i] as RecipeProto;
                    if (proto.preTech != null)
                    {
                        ArrayAddItem <int>(ref proto.preTech.UnlockRecipes, proto.ID);
                        ArrayAddItem <RecipeProto>(ref proto.preTech.unlockRecipeArray, proto);
                    }
                }
                Debug.Log($"[LDBTool]Add {protos[i].ID} {protos[i].Name.Translate()} to {protoSet.GetType().Name}.");
            }
            var dataIndices = new Dictionary <int, int>();

            for (int i = 0; i < protoSet.dataArray.Length; i++)
            {
                protoSet.dataArray[i].sid             = protoSet.dataArray[i].SID;
                dataIndices[protoSet.dataArray[i].ID] = i;
            }
            Traverse.Create(protoSet).Field("dataIndices").SetValue(dataIndices);
            if (protoSet is ProtoSet <StringProto> )
            {
                var nameIndices = Traverse.Create(protoSet).Field("nameIndices").GetValue <Dictionary <string, int> >();
                for (int i = array.Length; i < protoSet.dataArray.Length; i++)
                {
                    nameIndices[protoSet.dataArray[i].Name] = i;
                }
                Traverse.Create(protoSet).Field("nameIndices").SetValue(nameIndices);
            }
        }
コード例 #4
0
        /// <summary>
        ///     Copy constructor to generate new Language data from in Game Data
        /// </summary>
        /// <param name="settings">Settings</param>
        /// <param name="stringProto">In game translations</param>
        public LanguageData(LanguageSettings settings, ProtoSet <StringProto> stringProto)
        {
            settings.VersionUpdate();
            TranslationTable = new List <TranslationProto>(stringProto.Length);
            var translationDelegate = GetOriginalTextDelegate <StringProto>(settings);

            for (var i = 0; i < stringProto.dataArray.Length; i++)
            {
                var proto = stringProto.dataArray[i];
                TranslationProto translationProto = new TranslationProto();
                translationProto.IsValid     = true;
                translationProto.Original    = translationDelegate(proto);
                translationProto.Translation = translationDelegate(proto);
                translationProto.Name        = proto.Name;
                TranslationTable.Add(translationProto);
            }
        }
コード例 #5
0
        private static void EditAllProtos <T>(ProtoSet <T> protoSet)
            where T : Proto
        {
            foreach (T proto in protoSet.dataArray)
            {
                if (proto == null)
                {
                    continue;
                }

                try
                {
                    LDBTool.EditDataAction(proto);
                }
                catch (Exception e)
                {
                    LDBToolPlugin.logger.LogWarning($"Edit Error: ID:{proto.ID} Type:{proto.GetType().Name} {e.Message}");
                }
            }
        }
コード例 #6
0
        //Finds first available id
        private static int findAvailableID <T>(int startIndex, ProtoSet <T> set, Dictionary <int, T> list) where T : Proto
        {
            int id = startIndex;

            while (true)
            {
                if (!set.dataIndices.ContainsKey(id) && !list.ContainsKey(id))
                {
                    break;
                }

                if (id > 12000)
                {
                    logger.LogError("Failed to find free index!");
                    throw new ArgumentException("No free indices available!");
                }
                id++;
            }

            return(id);
        }
コード例 #7
0
 public static void ShowSet <T>(this ProtoSet <T> protoSet) where T : Proto
 {
     if (protoSet.dataArray.Length > 100)
     {
         GUILayout.BeginHorizontal(GUI.skin.box);
         GUILayout.Label($"Page {selectPages[protoSet.GetType()] + 1} / {protoSet.dataArray.Length / 100 + 1}", GUILayout.Width(80));
         if (GUILayout.Button("-", GUILayout.Width(20)))
         {
             selectPages[protoSet.GetType()]--;
         }
         if (GUILayout.Button("+", GUILayout.Width(20)))
         {
             selectPages[protoSet.GetType()]++;
         }
         if (selectPages[protoSet.GetType()] < 0)
         {
             selectPages[protoSet.GetType()] = protoSet.dataArray.Length / 100;
         }
         else if (selectPages[protoSet.GetType()] > protoSet.dataArray.Length / 100)
         {
             selectPages[protoSet.GetType()] = 0;
         }
         GUILayout.EndHorizontal();
     }
     GUILayout.BeginHorizontal(GUI.skin.box);
     GUILayout.Label($"index", GUILayout.Width(40));
     GUILayout.Label($"ID", GUILayout.Width(40));
     GUILayout.Label($"Name");
     GUILayout.Label($"TranslateName");
     if (SupportsHelper.SupportsRuntimeUnityEditor)
     {
         GUILayout.Label($"Show Data", GUILayout.Width(100));
     }
     GUILayout.EndHorizontal();
     sv = GUILayout.BeginScrollView(sv, GUI.skin.box);
     for (int i = selectPages[protoSet.GetType()] * 100; i < Mathf.Min(selectPages[protoSet.GetType()] * 100 + 100, protoSet.dataArray.Length); i++)
     {
         GUILayout.BeginHorizontal();
         GUILayout.Label($"{i}", GUILayout.Width(40));
         if (protoSet.dataArray[i] != null)
         {
             GUILayout.Label($"{protoSet.dataArray[i].ID}", GUILayout.Width(40));
             GUILayout.Label($"{protoSet.dataArray[i].Name}");
             GUILayout.Label($"{protoSet.dataArray[i].name.Translate()}");
             if (SupportsHelper.SupportsRuntimeUnityEditor)
             {
                 if (GUILayout.Button($"Show Data", GUILayout.Width(100)))
                 {
                     ShowItem item = new ShowItem(protoSet.dataArray[i], $"{protoSet.dataArray[i].GetType().Name} {protoSet.dataArray[i].name.Translate()}");
                     RUEHelper.ShowData(item);
                 }
             }
         }
         else
         {
             GUILayout.Label("null");
         }
         GUILayout.EndHorizontal();
     }
     GUILayout.EndScrollView();
 }
コード例 #8
0
        public static void ShowSet <T>(this ProtoSet <T> protoSet) where T : Proto
        {
            if (ProtoDataUI.Skin != null)
            {
                GUI.skin = ProtoDataUI.Skin.GetSkin();
            }
            GUILayout.BeginHorizontal(GUI.skin.box);
            Search = GUILayout.TextField(Search, GUILayout.Width(200));
            if (needSearch)
            {
                SearchLDB(protoSet);
            }
            GUILayout.Label($"Page {selectPages[protoSet.GetType()] + 1} / {searchResultList.Count / 100 + 1}", GUILayout.Width(80));
            if (GUILayout.Button("-", GUILayout.Width(20)))
            {
                selectPages[protoSet.GetType()]--;
            }
            if (GUILayout.Button("+", GUILayout.Width(20)))
            {
                selectPages[protoSet.GetType()]++;
            }
            if (selectPages[protoSet.GetType()] < 0)
            {
                selectPages[protoSet.GetType()] = searchResultList.Count / 100;
            }
            else if (selectPages[protoSet.GetType()] > searchResultList.Count / 100)
            {
                selectPages[protoSet.GetType()] = 0;
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginVertical(GUI.skin.box);
            GUILayout.BeginHorizontal();
            GUILayout.Label($"index", GUILayout.Width(40));
            GUILayout.Label($"ID", GUILayout.Width(40));
            GUILayout.Label($"Name");
            GUILayout.Label($"TranslateName");
            if (SupportsHelper.SupportsRuntimeUnityEditor)
            {
                GUILayout.Label($"Show Data", GUILayout.Width(100));
            }
            GUILayout.EndHorizontal();
            sv = GUILayout.BeginScrollView(sv);
            for (int i = selectPages[protoSet.GetType()] * 100; i < Mathf.Min(selectPages[protoSet.GetType()] * 100 + 100, searchResultList.Count); i++)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label($"{i}", GUILayout.Width(40));
                if (searchResultList[i] != null)
                {
                    GUILayout.Label($"{searchResultList[i].ID}", GUILayout.Width(40));
                    GUILayout.Label($"{searchResultList[i].Name}");
                    GUILayout.Label($"{searchResultList[i].name.Translate()}");
                    if (SupportsHelper.SupportsRuntimeUnityEditor)
                    {
                        if (GUILayout.Button($"Show Data", GUILayout.Width(100)))
                        {
                            ShowItem item = new ShowItem(searchResultList[i], $"{searchResultList[i].GetType().Name} {searchResultList[i].Name.Translate()}");
                            RUEHelper.ShowData(item);
                        }
                    }
                }
                else
                {
                    GUILayout.Label("null");
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndScrollView();
            GUILayout.EndVertical();
        }