Exemplo n.º 1
0
        private void DrawKeyField(ref Rect rect, Dictionary <int, int> frequencyInLanguageAppearance)
        {
            // Hold onto the original rect position
            float originalX     = rect.x;
            float originalWidth = rect.width;

            // Adjust the values
            rect.height = EditorGUIUtility.singleLineHeight;
            rect.width  = KeyLength;

            // Draw the key label
            EditorGUI.LabelField(rect, "Language");

            // Draw the key text field
            rect.x    += rect.width + VerticalSpace;
            rect.width = originalWidth - (KeyLength + VerticalSpace);
            EditorGUI.BeginChangeCheck();
            int oldLanguageIndex = LanguageIndexProperty.intValue;

            LanguageIndexProperty.intValue = SupportedLanguagesEditor.DrawSupportedLanguages(rect, LanguageIndexProperty, SupportedLanguages);

            // Check if there's a difference
            if (LanguageIndexProperty.intValue != oldLanguageIndex)
            {
                // Update dictionary
                RemoveLanguageFromFrequencyDictionary(frequencyInLanguageAppearance, oldLanguageIndex);
                AddLanguageToFrequencyDictionary(frequencyInLanguageAppearance, LanguageIndexProperty.intValue);

                // Indicate this dictionary needs to be updated
                if ((Element != null) && (Element.serializedObject != null))
                {
                    if (Element.serializedObject.context != null)
                    {
                        EditorUtility.SetDirty(Element.serializedObject.context);
                    }
                    else if (Element.serializedObject.targetObject != null)
                    {
                        EditorUtility.SetDirty(Element.serializedObject.targetObject);
                    }
                }
            }

            // Re-adjust the rectangle, full-width for the next part
            rect.x      = originalX;
            rect.y     += rect.height;
            rect.height = EditorGUIUtility.singleLineHeight;
            rect.width  = originalWidth;
        }
        protected void DrawKeyField(ref Rect rect)
        {
            // Hold onto the original rect position
            float originalX     = rect.x;
            float originalWidth = rect.width;

            // Adjust the values
            rect.height = EditorGUIUtility.singleLineHeight;

            // Draw the key text field
            IsLanguageIndexChanged = false;
            int oldLanguageIndex = LanguageIndex;

            LanguageIndex = SupportedLanguagesEditor.DrawSupportedLanguages(rect, keyLabel, LanguageIndex, SupportedLanguages, true);

            // Re-adjust the rectangle, full-width for the next part
            rect.x      = originalX;
            rect.y     += rect.height;
            rect.height = EditorGUIUtility.singleLineHeight;
            rect.width  = originalWidth;
        }
Exemplo n.º 3
0
        private void DrawDefaultsWhenTranslationForLanguageIsNotFound()
        {
            EditorGUILayout.LabelField("When Translation For a Language Is Not Found...", EditorStyles.boldLabel);
            EditorGUILayout.PropertyField(defaultToWhenTranslationNotFound, DefaultTextToLabel);

            // Check if we want to show the Default Language field
            bool showField = false;

            if (supportedLanguages.objectReferenceValue != null)
            {
                switch (defaultToWhenTranslationNotFound.enumValueIndex)
                {
                case (int)TranslationDictionary.TranslationNotFoundDefaults.DefaultLanguageOrNull:
                case (int)TranslationDictionary.TranslationNotFoundDefaults.DefaultLanguageOrEmptyString:
                case (int)TranslationDictionary.TranslationNotFoundDefaults.DefaultLanguageOrPresetMessage:
                    showField = true;

                    break;
                }
            }
            showDefaultLanguageForTranslationNotFound.target = showField;

            // Draw the default language field
            using (EditorGUILayout.FadeGroupScope defaultLanguageGroup = new EditorGUILayout.FadeGroupScope(showDefaultLanguageForTranslationNotFound.faded))
            {
                if ((defaultLanguageGroup.visible == true) && (showField == true))
                {
                    // Show default language field
                    EditorGUI.BeginChangeCheck();
                    SupportedLanguagesEditor.DrawSupportedLanguages(DefaultLanguageLabel, defaultLanguageWhenTranslationNotFound, ((SupportedLanguages)supportedLanguages.objectReferenceValue));
                    if (EditorGUI.EndChangeCheck() == true)
                    {
                        SupportedLanguages newLanguage = ((SupportedLanguages)supportedLanguages.objectReferenceValue);
                        if (newLanguage != null)
                        {
                            foreach (TranslationCollectionEditor editor in translationStatus)
                            {
                                editor.SupportedLanguages = newLanguage;
                            }
                        }
                    }
                }
            }

            // Check if we want to show the Preset Message field
            showField = false;
            switch (defaultToWhenTranslationNotFound.enumValueIndex)
            {
            case (int)TranslationDictionary.TranslationNotFoundDefaults.PresetMessage:
            case (int)TranslationDictionary.TranslationNotFoundDefaults.DefaultLanguageOrPresetMessage:
                showField = true;
                break;
            }
            showPresetMessageForTranslationNotFound.target = showField;

            // Draw the preset message field
            using (EditorGUILayout.FadeGroupScope presetMessageGroup = new EditorGUILayout.FadeGroupScope(showPresetMessageForTranslationNotFound.faded))
            {
                if (presetMessageGroup.visible == true)
                {
                    // Show preset message field
                    EditorGUILayout.PropertyField(presetMessageWhenTranslationNotFound, PresetMessageLabel);
                }
            }

            // Draw the replace empty string field
            replaceEmptyStringWithDefaultText.boolValue = EditorGUILayout.ToggleLeft("Replace Empty String With Default Text", replaceEmptyStringWithDefaultText.boolValue);
        }