public static bool ShouldShowTerm(string Term, string Category, int nUses, ParsedTerm parsedTerm = null)
        {
            if (!string.IsNullOrEmpty(Category) && !mSelectedCategories.Contains(Category))
            {
                return(false);
            }

            if (!StringContainsFilter(Term, KeyList_Filter))
            {
                return(false);
            }

            if (!string.IsNullOrEmpty(Category) && Category != LanguageSource.EmptyCategory)
            {
                Term = Category + "/" + Term;
            }

            if (parsedTerm != null && parsedTerm.termData != null)
            {
                ShowTerm_termData = parsedTerm.termData;
            }
            else
            {
                ShowTerm_termData = mLanguageSource.GetTermData(Term);
                if (parsedTerm != null)
                {
                    parsedTerm.termData = ShowTerm_termData;
                }
            }
            bool bIsMissing = ShowTerm_termData == null;

            if (nUses < 0)
            {
                return(true);
            }

            if ((mFlagsViewKeys & (int)eFlagsViewKeys.Missing) > 0 && bIsMissing)
            {
                return(true);
            }
            if ((mFlagsViewKeys & (int)eFlagsViewKeys.Missing) == 0 && bIsMissing)
            {
                return(false);
            }

            if ((mFlagsViewKeys & (int)eFlagsViewKeys.Used) > 0 && nUses > 0)
            {
                return(true);
            }
            if ((mFlagsViewKeys & (int)eFlagsViewKeys.NotUsed) > 0 && nUses == 0)
            {
                return(true);
            }

            return(false);
        }
Пример #2
0
 void UpdateTermsToShownInList()
 {
     mShowableTerms.Clear();
     foreach (KeyValuePair <string, ParsedTerm> kvp in mParsedTerms)
     {
         ParsedTerm parsedTerm = kvp.Value;
         if (ShouldShowTerm(parsedTerm.Term, parsedTerm.Category, parsedTerm.Usage, parsedTerm))
         {
             mShowableTerms.Add(parsedTerm);
         }
     }
 }
        public static ParsedTerm GetParsedTerm(string Term)
        {
            ParsedTerm data;

            if (!mParsedTerms.TryGetValue(Term, out data))
            {
                data       = new ParsedTerm();
                data.Usage = 0;
                LanguageSource.DeserializeFullTerm(Term, out data.Term, out data.Category);
                mParsedCategories[data.Category] = 1;
                mParsedTerms[Term] = data;
            }
            return(data);
        }
Пример #4
0
        static void UpdateTermsToShownInList()
        {
            EditorApplication.update -= UpdateTermsToShownInList;

            mShowableTerms.Clear();
            foreach (KeyValuePair <string, ParsedTerm> kvp in mParsedTerms)
            {
                ParsedTerm parsedTerm = kvp.Value;
                if (ShouldShowTerm(parsedTerm.Term, parsedTerm.Category, parsedTerm.Usage, parsedTerm))
                {
                    mShowableTerms.Add(parsedTerm);
                }
            }
            EditorApplication.RepaintHierarchyWindow();
        }
        static ParsedTerm AddParsedTerm(string FullTerm, string TermKey, string Category, int Usage)
        {
            if (TermKey == null)
            {
                LanguageSourceData.DeserializeFullTerm(FullTerm, out TermKey, out Category);
            }

            var data = new ParsedTerm();

            data.Usage    = Usage;
            data.FullTerm = FullTerm;
            data.Term     = TermKey;
            data.Category = Category;

            mParsedTerms[FullTerm] = data;
            return(data);
        }
Пример #6
0
        static void UpdateTermsToShownInList()
        {
            EditorApplication.update  -= UpdateTermsToShownInList;
            mUpdateShowTermIsScheduled = false;

            mShowableTerms.Clear();
            foreach (KeyValuePair <string, ParsedTerm> kvp in mParsedTerms)
            {
                ParsedTerm parsedTerm = kvp.Value;
                if (ShouldShowTerm(parsedTerm.Term, parsedTerm.Category, parsedTerm.Usage, parsedTerm))
                {
                    mShowableTerms.Add(parsedTerm);
                }
            }
            GUITools.RepaintInspectors();
            GUITools.ScheduleRepaintInspectors();
        }
        public static void DecreaseParsedTerm(string Term)
        {
            ParsedTerm data = GetParsedTerm(Term);

            data.Usage = Mathf.Max(0, data.Usage - 1);
        }
Пример #8
0
        public static bool ShouldShowTerm(string Term, string Category, int nUses, ParsedTerm parsedTerm = null)
        {
            if (!string.IsNullOrEmpty(Category) && !mSelectedCategories.Contains(Category))
            {
                return(false);
            }
            if (Term == "-")
            {
                return(false);
            }


            var fullTerm = Term;

            if (!string.IsNullOrEmpty(Category) && Category != LanguageSourceData.EmptyCategory)
            {
                fullTerm = Category + "/" + Term;
            }

            if (parsedTerm != null && parsedTerm.termData != null)
            {
                ShowTerm_termData = parsedTerm.termData;
            }
            else
            {
                ShowTerm_termData = mLanguageSource.GetTermData(fullTerm);
                if (parsedTerm != null)
                {
                    parsedTerm.termData = ShowTerm_termData;
                }
            }


            var  filter         = KeyList_Filter.Trim();
            bool useTranslation = filter.StartsWith("f ", System.StringComparison.OrdinalIgnoreCase);

            if (useTranslation)
            {
                if (ShowTerm_termData == null)
                {
                    return(false);
                }

                filter = filter.Substring(2).Trim();
                if (!string.IsNullOrEmpty(filter))
                {
                    bool hasFilter = false;
                    for (int i = 0; i < ShowTerm_termData.Languages.Length; ++i)
                    {
                        if (!string.IsNullOrEmpty(ShowTerm_termData.Languages[i]) && StringContainsFilter(ShowTerm_termData.Languages[i], filter))
                        {
                            hasFilter = true;
                            break;
                        }
                    }
                    if (!hasFilter)
                    {
                        return(false);
                    }
                }
            }
            else
            {
                bool onlyCategory = filter.StartsWith("c ", System.StringComparison.OrdinalIgnoreCase);
                if (onlyCategory)
                {
                    filter = filter.Substring(2).Trim();
                }

                if (!string.IsNullOrEmpty(filter))
                {
                    bool matchesCategory = StringContainsFilter(Category, filter);
                    bool matchesName     = !onlyCategory && StringContainsFilter(Term, filter);

                    if (!matchesCategory && !matchesName)
                    {
                        return(false);
                    }
                }
            }


            bool bIsMissing = ShowTerm_termData == null;

            if (nUses < 0)
            {
                return(true);
            }

            if ((mFlagsViewKeys & (int)eFlagsViewKeys.Missing) > 0 && bIsMissing)
            {
                return(true);
            }
            if ((mFlagsViewKeys & (int)eFlagsViewKeys.Missing) == 0 && bIsMissing)
            {
                return(false);
            }

            if ((mFlagsViewKeys & (int)eFlagsViewKeys.Used) > 0 && nUses > 0)
            {
                return(true);
            }
            if ((mFlagsViewKeys & (int)eFlagsViewKeys.NotUsed) > 0 && nUses == 0)
            {
                return(true);
            }

            return(false);
        }
Пример #9
0
        void OnGUI_KeysList(bool AllowExpandKey = true, float Height = 300.0f, bool ShowTools = true)
        {
            if (mTermList_MaxWidth <= 0)
            {
                CalculateTermsListMaxWidth();
            }

            //--[ List Filters ]--------------------------------------
            OnGUI_ShowMsg();

            GUILayout.BeginHorizontal();
            GUIStyle bstyle = new GUIStyle("toolbarbutton");

            bstyle.fontSize = 15;
            if (GUILayout.Button(new GUIContent("\u21bb", "Parse Scene and update terms list with missing and unused terms"), bstyle, GUILayout.Width(25)))
            {
                EditorApplication.update += DoParseTermsInCurrentScene;
            }
            GUILayout.Space(1);
            mFlagsViewKeys = OnGUI_FlagToogle("Used", "Shows All Terms referenced in the parsed scenes", mFlagsViewKeys, (int)eFlagsViewKeys.Used);
            mFlagsViewKeys = OnGUI_FlagToogle("Not Used", "Shows all Terms from the Source that are not been used", mFlagsViewKeys, (int)eFlagsViewKeys.NotUsed);
            mFlagsViewKeys = OnGUI_FlagToogle("Missing", "Shows all Terms Used but not defined in the Source", mFlagsViewKeys, (int)eFlagsViewKeys.Missing);

            OnGUI_SelectedCategories();

            GUILayout.EndHorizontal();

            //--[ Keys List ]-----------------------------------------
            mScrollPos_Keys = GUILayout.BeginScrollView(mScrollPos_Keys, false, false, "horizontalScrollbar", "verticalScrollbar", "AS TextArea", GUILayout.MinHeight(Height), GUILayout.MaxHeight(Screen.height), GUILayout.ExpandHeight(false));

            bool bAnyValidUsage = false;

            mRowSize = EditorStyles.toolbar.fixedHeight;
            if (Event.current != null && Event.current.type == EventType.Layout)
            {
                ScrollHeight = mScrollPos_Keys.y;
            }

            float YPosMin = -ScrollHeight;
            int   nSkip   = 0;
            int   nDraw   = 0;

            if (TermsListHeight <= 0)
            {
                TermsListHeight = Screen.height;
            }

            float SkipSize = 0;

            foreach (KeyValuePair <string, ParsedTerm> kvp in mParsedTerms)
            {
                ParsedTerm parsedTerm = kvp.Value;
                string     sKey       = parsedTerm.Term;
                string     sCategory  = parsedTerm.Category;
                string     FullKey    = kvp.Key;

                int nUses = parsedTerm.Usage;
                bAnyValidUsage = bAnyValidUsage | (nUses >= 0);

                ShowTerm_termData = null;                       // as an optimization this value is filled on ShouldShowTerm and later used in in OnGUI_KeyHeader
                if (!ShouldShowTerm(sKey, sCategory, nUses))
                {
                    continue;
                }

                // Skip lines outside the view -----------------------
                YPosMin  += mRowSize;
                SkipSize += mRowSize;
                float YPosMax    = YPosMin + mRowSize;
                bool  isExpanded = (AllowExpandKey && mKeyToExplore == FullKey);
                if (!isExpanded && (YPosMax < -2 * mRowSize || YPosMin > /*Screen.height*/ TermsListHeight + mRowSize))
                {
                    nSkip++;
                    continue;
                }
                nDraw++;

                //------------------------------------------------------

                OnGUI_KeyHeader(sKey, sCategory, FullKey, nUses, YPosMin - mRowSize + mScrollPos_Keys.y);

                //--[ Key Details ]-------------------------------

                if (isExpanded)
                {
                    GUILayout.Space(SkipSize);
                    SkipSize = 0;
                    OnGUI_KeyList_ShowKeyDetails();
                    Rect rect = GUILayoutUtility.GetLastRect();
                    if (rect.height > 5)
                    {
                        ExpandedViewHeight = rect.height;
                    }
                    YPosMin += ExpandedViewHeight;
                }
            }
            GUILayout.Space(SkipSize);
            OnGUI_KeysList_AddKey();

            GUILayout.Label("", GUILayout.Width(mTermList_MaxWidth + 10 + 30), GUILayout.Height(1));

            GUILayout.EndScrollView();

            Rect ListRect = GUILayoutUtility.GetLastRect();

            if (ListRect.height > 5)
            {
                TermsListHeight = ListRect.height;
            }

            OnGUI_Keys_ListSelection();                // Selection Buttons

//			if (!bAnyValidUsage)
//				EditorGUILayout.HelpBox("Use (Tools\\Parse Terms) to find how many times each of the Terms are used", UnityEditor.MessageType.Info);

            if (ShowTools)
            {
                GUILayout.BeginHorizontal();
                GUI.enabled = (mSelectedKeys.Count > 0 || !string.IsNullOrEmpty(mKeyToExplore));
                if (GUILayout.Button(new GUIContent("Add Terms", "Add terms to Source")))
                {
                    AddTermsToSource();
                }
                if (GUILayout.Button(new GUIContent("Remove Terms", "Remove Terms from Source")))
                {
                    RemoveTermsFromSource();
                }

                GUILayout.FlexibleSpace();

                if (GUILayout.Button("Change Category"))
                {
                    OpenTool_ChangeCategoryOfSelectedTerms();
                }
                GUI.enabled = true;
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                bool newBool = GUILayout.Toggle(mLanguageSource.CaseInsensitiveTerms, "Case Insensitive Terms");
                if (newBool != mLanguageSource.CaseInsensitiveTerms)
                {
                    mProp_CaseInsensitiveTerms.boolValue = newBool;
                }
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
            }
            //Debug.Log ("Draw: " + nDraw + " Skip: " + nSkip);
        }