예제 #1
0
    // Use this for initialization
    void Start()
    {
        coinDisp.GetComponent <Text>().text = coins.ToString();
        starDisp.GetComponent <Text>().text = stars.ToString();

        // set default of timescale.
        Time.timeScale = 1;
        // enable only portrait mode for menu screen.
        Screen.orientation = ScreenOrientation.Portrait;

        bc             = GetComponent <BoardCreatorController>();
        languageEditor = GetComponent <LanguageEditor>();


        // always initialize menu windows as inactive.
        settingsObj.SetActive(false);
        settingsFilter.SetActive(false);

        // get animation components from selectors.
        for (int a = 0; a < _selectors.Length; a++)
        {
            _selectAnim[a] = _selectors[a].GetComponent <Animator>();
        }

        int panLen = _pan.Length;

        distance = new float[panLen];

        // distance between first panel and second panel.
        panDistance = (int)Mathf.Abs(_pan[1].GetComponent <RectTransform>().anchoredPosition.x - _pan[0].GetComponent <RectTransform>().anchoredPosition.x);

        menuScroller = menuScrollerCont.GetComponent <ScrollRect>();
    }
예제 #2
0
    void OnGUI()
    {
        GUILayout.BeginVertical(GUILayout.Height(position.height));
        EditorGUILayout.Space();
        stringsTable();

        //GUILayout.FlexibleSpace();

        GUILayoutOption width  = GUILayout.Width(150);
        GUILayoutOption height = GUILayout.Height(25);

        // Bottom buttons
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Edit Languages", width, height))
        {
            LanguageEditor.ShowWindow();
        }
        GUILayout.FlexibleSpace();
        if (GUILayout.Button("OK", width, height))
        {
            Close();
        }
        GUILayout.EndHorizontal();

        GUILayout.EndVertical();
    }
예제 #3
0
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            var form = new LanguageEditor();

            form.ShowDialog();
            languagesTableAdapter.Fill(hotelDBDataSet.Languages);
            Refresh();
        }
예제 #4
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        LanguageEditor language = target as LanguageEditor;

        if (GUILayout.Button("Add at Language"))
        {
            language.AddLanguage();
        }
        if (GUILayout.Button("Add Content"))
        {
            language.AddContent();
        }
        if (GUILayout.Button("Edit Content"))
        {
            language.EditContent();
        }
        if (GUILayout.Button("Remove at Content"))
        {
            language.RemoveAtContent();
        }
    }
예제 #5
0
    static void Init()
    {
        LanguageEditor languageEditor = (LanguageEditor)EditorWindow.GetWindow(typeof(LanguageEditor), false, "LanguageEditor", false);

        languageEditor.Show();
    }
예제 #6
0
    void OnGUI()
    {
        if(!editor)
            editor = (LanguageEditor)EditorWindow.GetWindow (typeof (LanguageEditor));

        if(!LanguageManager.PackLoaded || !Directory.Exists(Application.dataPath + LanguageManager.LanguagePackDirectory) || !File.Exists(Application.dataPath + LanguageManager.LanguagePackDirectory + System.Enum.GetName(typeof(Language), currentLanguage) + ".txt"))
        {
            try
            {
                if (!Directory.Exists(Application.dataPath + LanguageManager.LanguagePackDirectory))
                    Directory.CreateDirectory(Application.dataPath + LanguageManager.LanguagePackDirectory);

                if (!File.Exists(Application.dataPath + LanguageManager.LanguagePackDirectory + System.Enum.GetName(typeof(Language), currentLanguage) + ".txt"))
                {
                    fs = File.Create(Application.dataPath + LanguageManager.LanguagePackDirectory + System.Enum.GetName(typeof(Language), currentLanguage) + ".txt");
                    fs.Close();
                }

                UnityEditor.AssetDatabase.Refresh();

                LanguageManager.LoadLanguageFile(currentLanguage);
            }
            catch
            {
                Debug.Log("Failed to create/load file");
                LanguageManager.PackLoaded = false;
            }
        }

        if(currentLanguage != LanguageManager.CurrentLanguage && !Application.isPlaying)
        {
            //Debug.Log("Switching Language Automatically");
            LanguageManager.LoadLanguageFile(currentLanguage);
        }

        window = editor.position;

        GUI.Label(new Rect(10,10,window.width-20,20),"Key:   #n = New Line");

        if(warningMessage.Length > 0)
        {
            GUI.color = Color.red;
            GUI.Box(new Rect(window.width - 320, 5, 310, 30),"");

            GUI.color = Color.yellow;
            GUI.Label(new Rect(window.width - 300, 10, 300, 20),warningMessage);
            GUI.color = Color.white;
        }

        GUI.Box(new Rect(10,40, window.width-20,37),"");
        newKey = EditorGUI.TextField(new Rect(20, 50, 200, 17),"Reference Key:", newKey);
        newString = EditorGUI.TextField(new Rect(200, 50, window.width - 320, 17),"  ------> Text:", newString);
        if(GUI.Button(new Rect(window.width - 110, 50, 90, 17),"Add")) { if(!LanguageManager.AddText(newKey, newString)) { warningMessage = "ERROR: KEY ALREADY EXISTS!"; } else { warningMessage = ""; } }

        GUI.Box(new Rect(10, 80, window.width - 20, window.height - 140),"");

        if(LanguageManager.CurrentLanguagePack != null)
        {
            scrollPosition = GUI.BeginScrollView(new Rect(0, 80, window.width - 10, window.height - 140), scrollPosition, new Rect(0,0,window.width - 50, 20 + (25*LanguageManager.CurrentLanguagePack.Keys.Count)));
                for(int i = 0; i < LanguageManager.CurrentLanguagePack.Keys.Count; i++)
                {
                    GUI.Box(new Rect(20, 10 + (i*25), window.width - 50 ,15), "");
                    GUI.Label(new Rect(25, 10 + (i*25), 110 ,17), LanguageManager.CurrentLanguagePack.Keys[i]);
                    LanguageManager.CurrentLanguagePack.Strings[i] = EditorGUI.TextField(new Rect(140, 10 + (i*25), window.width - 200 ,17),LanguageManager.CurrentLanguagePack.Strings[i]);
                    if(GUI.Button(new Rect(window.width - 50, 10 + (i*25), 20 ,17),"X")) { LanguageManager.DeleteText(LanguageManager.CurrentLanguagePack.Keys[i]); return; }
                }
        GUI.EndScrollView();
        }

        GUI.Box(new Rect(10, window.height - 55, window.width - 20, 50),"");

        currentLanguage = (Language)EditorGUI.EnumPopup(new Rect(20, window.height - 45, 200, 17),"Language File: ", currentLanguage);

        if(GUI.Button(new Rect(20, window.height - 25, 90, 17), "Add Language"))
        {
            string p = Application.dataPath + "/LanguageEditor/Language.cs";
            string[] languageFiles = Directory.GetFiles(Application.dataPath + LanguageManager.LanguagePackDirectory);

            if(newLang=="" || newLang.Contains(" "))
            {
                warningMessage = "WARNING: Language CANNOT Contain Spaces!";
                return;
            }

            for(int i = 0; i < languageFiles.Length; i++)
            {
                languageFiles[i] = languageFiles[i].Substring((Application.dataPath + LanguageManager.LanguagePackDirectory).Length);
                languageFiles[i] = languageFiles[i].TrimEnd((".txt").ToCharArray());

                if(newLang == languageFiles[i])
                {
                    warningMessage = "WARNING: Language Exists!";
                    return;
                }
            }

            File.Delete(p);

            StreamWriter sr = File.CreateText(p);

            sr.WriteLine("public enum Language {");

            for(int i = 0; i < languageFiles.Length; i++)
            {
                if(i==0 && languageFiles.Length > 1)
                    sr.WriteLine(languageFiles[i]);
                else if(i==0 && languageFiles.Length == 1)
                    sr.WriteLine(languageFiles[i]);
                else
                    sr.WriteLine("," + languageFiles[i]);
            }

            sr.WriteLine(","+newLang);

            sr.WriteLine("}");

            sr.Close();

            AssetDatabase.Refresh();
        }

        newLang = EditorGUI.TextField(new Rect(20, window.height - 25, 200, 17),"", newLang);

        if(GUI.Button(new Rect(250, window.height - 35, 90, 17), "Set Directory"))
        {
            LanguageManager.LanguagePackDirectory = EditorUtility.SaveFolderPanel("Save To Directory", Application.dataPath, "");
            LanguageManager.LanguagePackDirectory = LanguageManager.LanguagePackDirectory.Substring(Application.dataPath.Length) + "/";
        }
        EditorGUI.LabelField(new Rect(250, window.height - 35, 400, 17), "", LanguageManager.LanguagePackDirectory);

        GUI.Box(new Rect(window.width - 610, window.height - 45, 330, 33),"");
        masterLanguageFile = (Language)EditorGUI.EnumPopup(new Rect(window.width - 500,  window.height - 35, 200, 17),"            Master: ", masterLanguageFile);
        if(GUI.Button(new Rect(window.width - 600, window.height - 35, 100, 17),"Balance Keys") ) { LanguageManager.AddKeysFromMaster(masterLanguageFile, currentLanguage); }

        //if(GUI.Button(new Rect(window.width - 240, window.height - 55, 100, 17),"Convert File")) { LanguageManager.ConvertToNewFormat(currentLanguage); }
        if(GUI.Button(new Rect(window.width - 240, window.height - 35, 100, 17),"Save File") && EditorUtility.DisplayDialog("Saving "+ System.Enum.GetName(typeof(Language), currentLanguage).ToUpper() + "!","You are about to save over the file which stores the " + System.Enum.GetName(typeof(Language), currentLanguage) + " language. Are you sure you want to do this?" ,"Save","Cancel")) { LanguageManager.SaveLanguageFile(currentLanguage); AssetDatabase.Refresh();}
        if(GUI.Button(new Rect(window.width - 120, window.height - 35, 100, 17),"Load File") && EditorUtility.DisplayDialog("Loading "+ System.Enum.GetName(typeof(Language), currentLanguage).ToUpper() + "!","All settings will NOT be saved for the " + System.Enum.GetName(typeof(Language), currentLanguage) + " language. Are you sure you want to do this?" ,"Load","Cancel")) { LanguageManager.LoadLanguageFile(currentLanguage); }
    }
예제 #7
0
 static void Init()
 {
     // Get existing open window or if none, make a new one:
     editor = (LanguageEditor)EditorWindow.GetWindow (typeof (LanguageEditor), true, "Language Editor");
 }
예제 #8
0
    void OnGUI()
    {
        if (!editor)
        {
            editor = (LanguageEditor)EditorWindow.GetWindow(typeof(LanguageEditor));
        }

        if (!LanguageManager.PackLoaded || !Directory.Exists(Application.dataPath + LanguageManager.LanguagePackDirectory) || !File.Exists(Application.dataPath + LanguageManager.LanguagePackDirectory + System.Enum.GetName(typeof(Language), currentLanguage) + ".txt"))
        {
            try
            {
                if (!Directory.Exists(Application.dataPath + LanguageManager.LanguagePackDirectory))
                {
                    Directory.CreateDirectory(Application.dataPath + LanguageManager.LanguagePackDirectory);
                }

                if (!File.Exists(Application.dataPath + LanguageManager.LanguagePackDirectory + System.Enum.GetName(typeof(Language), currentLanguage) + ".txt"))
                {
                    fs = File.Create(Application.dataPath + LanguageManager.LanguagePackDirectory + System.Enum.GetName(typeof(Language), currentLanguage) + ".txt");
                    fs.Close();
                }

                UnityEditor.AssetDatabase.Refresh();

                LanguageManager.LoadLanguageFile(currentLanguage);
            }
            catch
            {
                Debug.Log("Failed to create/load file");
                LanguageManager.PackLoaded = false;
            }
        }

        if (currentLanguage != LanguageManager.CurrentLanguage && !Application.isPlaying)
        {
            //Debug.Log("Switching Language Automatically");
            LanguageManager.LoadLanguageFile(currentLanguage);
        }

        window = editor.position;

        GUI.Label(new Rect(10, 10, window.width - 20, 20), "Key:   #n = New Line");

        if (warningMessage.Length > 0)
        {
            GUI.color = Color.red;
            GUI.Box(new Rect(window.width - 320, 5, 310, 30), "");

            GUI.color = Color.yellow;
            GUI.Label(new Rect(window.width - 300, 10, 300, 20), warningMessage);
            GUI.color = Color.white;
        }

        GUI.Box(new Rect(10, 40, window.width - 20, 37), "");
        newKey    = EditorGUI.TextField(new Rect(20, 50, 200, 17), "Reference Key:", newKey);
        newString = EditorGUI.TextField(new Rect(200, 50, window.width - 320, 17), "  ------> Text:", newString);
        if (GUI.Button(new Rect(window.width - 110, 50, 90, 17), "Add"))
        {
            if (!LanguageManager.AddText(newKey, newString))
            {
                warningMessage = "ERROR: KEY ALREADY EXISTS!";
            }
            else
            {
                warningMessage = "";
            }
        }

        GUI.Box(new Rect(10, 80, window.width - 20, window.height - 140), "");

        if (LanguageManager.CurrentLanguagePack != null)
        {
            scrollPosition = GUI.BeginScrollView(new Rect(0, 80, window.width - 10, window.height - 140), scrollPosition, new Rect(0, 0, window.width - 50, 20 + (25 * LanguageManager.CurrentLanguagePack.Keys.Count)));
            for (int i = 0; i < LanguageManager.CurrentLanguagePack.Keys.Count; i++)
            {
                GUI.Box(new Rect(20, 10 + (i * 25), window.width - 50, 15), "");
                GUI.Label(new Rect(25, 10 + (i * 25), 110, 17), LanguageManager.CurrentLanguagePack.Keys[i]);
                LanguageManager.CurrentLanguagePack.Strings[i] = EditorGUI.TextField(new Rect(140, 10 + (i * 25), window.width - 200, 17), LanguageManager.CurrentLanguagePack.Strings[i]);
                if (GUI.Button(new Rect(window.width - 50, 10 + (i * 25), 20, 17), "X"))
                {
                    LanguageManager.DeleteText(LanguageManager.CurrentLanguagePack.Keys[i]); return;
                }
            }
            GUI.EndScrollView();
        }

        GUI.Box(new Rect(10, window.height - 55, window.width - 20, 50), "");

        currentLanguage = (Language)EditorGUI.EnumPopup(new Rect(20, window.height - 45, 200, 17), "Language File: ", currentLanguage);

        if (GUI.Button(new Rect(20, window.height - 25, 90, 17), "Add Language"))
        {
            string   p             = Application.dataPath + "/LanguageEditor/Language.cs";
            string[] languageFiles = Directory.GetFiles(Application.dataPath + LanguageManager.LanguagePackDirectory);

            if (newLang == "" || newLang.Contains(" "))
            {
                warningMessage = "WARNING: Language CANNOT Contain Spaces!";
                return;
            }

            for (int i = 0; i < languageFiles.Length; i++)
            {
                languageFiles[i] = languageFiles[i].Substring((Application.dataPath + LanguageManager.LanguagePackDirectory).Length);
                languageFiles[i] = languageFiles[i].TrimEnd((".txt").ToCharArray());

                if (newLang == languageFiles[i])
                {
                    warningMessage = "WARNING: Language Exists!";
                    return;
                }
            }

            File.Delete(p);

            StreamWriter sr = File.CreateText(p);

            sr.WriteLine("public enum Language {");

            for (int i = 0; i < languageFiles.Length; i++)
            {
                if (i == 0 && languageFiles.Length > 1)
                {
                    sr.WriteLine(languageFiles[i]);
                }
                else if (i == 0 && languageFiles.Length == 1)
                {
                    sr.WriteLine(languageFiles[i]);
                }
                else
                {
                    sr.WriteLine("," + languageFiles[i]);
                }
            }

            sr.WriteLine("," + newLang);

            sr.WriteLine("}");

            sr.Close();

            AssetDatabase.Refresh();
        }

        newLang = EditorGUI.TextField(new Rect(20, window.height - 25, 200, 17), "", newLang);

        if (GUI.Button(new Rect(250, window.height - 35, 90, 17), "Set Directory"))
        {
            LanguageManager.LanguagePackDirectory = EditorUtility.SaveFolderPanel("Save To Directory", Application.dataPath, "");
            LanguageManager.LanguagePackDirectory = LanguageManager.LanguagePackDirectory.Substring(Application.dataPath.Length) + "/";
        }
        EditorGUI.LabelField(new Rect(250, window.height - 35, 400, 17), "", LanguageManager.LanguagePackDirectory);

        GUI.Box(new Rect(window.width - 610, window.height - 45, 330, 33), "");
        masterLanguageFile = (Language)EditorGUI.EnumPopup(new Rect(window.width - 500, window.height - 35, 200, 17), "            Master: ", masterLanguageFile);
        if (GUI.Button(new Rect(window.width - 600, window.height - 35, 100, 17), "Balance Keys"))
        {
            LanguageManager.AddKeysFromMaster(masterLanguageFile, currentLanguage);
        }

        //if(GUI.Button(new Rect(window.width - 240, window.height - 55, 100, 17),"Convert File")) { LanguageManager.ConvertToNewFormat(currentLanguage); }
        if (GUI.Button(new Rect(window.width - 240, window.height - 35, 100, 17), "Save File") && EditorUtility.DisplayDialog("Saving " + System.Enum.GetName(typeof(Language), currentLanguage).ToUpper() + "!", "You are about to save over the file which stores the " + System.Enum.GetName(typeof(Language), currentLanguage) + " language. Are you sure you want to do this?", "Save", "Cancel"))
        {
            LanguageManager.SaveLanguageFile(currentLanguage); AssetDatabase.Refresh();
        }
        if (GUI.Button(new Rect(window.width - 120, window.height - 35, 100, 17), "Load File") && EditorUtility.DisplayDialog("Loading " + System.Enum.GetName(typeof(Language), currentLanguage).ToUpper() + "!", "All settings will NOT be saved for the " + System.Enum.GetName(typeof(Language), currentLanguage) + " language. Are you sure you want to do this?", "Load", "Cancel"))
        {
            LanguageManager.LoadLanguageFile(currentLanguage);
        }
    }
예제 #9
0
 static void Init()
 {
     // Get existing open window or if none, make a new one:
     editor = (LanguageEditor)EditorWindow.GetWindow(typeof(LanguageEditor), true, "Language Editor");
 }
예제 #10
0
    // Draw a table to display strings.dict(). The columns represent languages, and the rows translated strings.dict().
    private void stringsTable()
    {
        List <string> languages = LanguageEditor.loadAllLanguages();

        int   removeButtonWidth = 80;
        int   rowHeight         = 20;
        float minimumColWidth   = 256;
        // first column is smaller than the others
        float firstColWidth = (position.width - removeButtonWidth) / (languages.Count + 1) / 2;

        if (firstColWidth < minimumColWidth / 1.5f)
        {
            firstColWidth = minimumColWidth / 1.5f;
        }
        // rest of the columns take up remaining space evenly. -50 stops overflow out the right side when scrolling
        float subseqColWidth = (position.width - firstColWidth - removeButtonWidth - 50) / languages.Count;

        if (subseqColWidth < minimumColWidth)
        {
            subseqColWidth = minimumColWidth;
        }

        _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos);

        // Top row - Titles
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("", GUILayout.Width(removeButtonWidth));
        EditorGUILayout.LabelField("String Name", GUILayout.Width(firstColWidth));
        foreach (string lang in languages)
        {
            EditorGUILayout.LabelField(lang, GUILayout.Width(subseqColWidth));
        }
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Space();

        // In the stringsTable loop that draws the translated strings, this dictionary tracks strings that
        // want to be renamed. This is so that  we can rename (ie, delete and re-add) those entries after the loop finishes.
        Dictionary <string, string> stringsToRename = new Dictionary <string, string>();

        int originalFontsize = GUI.skin.textField.fontSize;

        // Loop over strings, and put the string name + the corresponding translated strings into the table as rows
        foreach (KeyValuePair <string, Dictionary <string, string> > entry in _strings.dict())
        {
            string stringName = entry.Key;
            Dictionary <string, string> stringValues = entry.Value;

            GUI.skin.textField.fontSize = 14;

            EditorGUILayout.BeginHorizontal();
            // a Remove button for each string
            if (GUILayout.Button("Remove", GUILayout.Width(removeButtonWidth), GUILayout.Height(rowHeight)))
            {
                if (EditorUtility.DisplayDialog("Remove String", "Are you ABSOLUTELY sure you want to remove "
                                                + stringName + "?\nThis WILL DELETE all translations of this string.",
                                                "OK", "Cancel"))
                {
                    // A stringToRename with a null new name means a string to delete
                    stringsToRename.Add(stringName, null);
                }
            }

            // It would be better to make this a Delayed field since we don't have to store values while user is typing
            // But then if a user closes the window without deselecting the textfield, the changes will not be saved.
            string newStringName = EditorGUILayout.TextField(stringName, GUILayout.Width(firstColWidth),
                                                             GUILayout.Height(rowHeight));
            if (newStringName != stringName)
            {
                if (stringsToRename.ContainsKey(stringName))
                {
                    stringsToRename.Remove(stringName);
                }
                stringsToRename.Add(stringName, newStringName);
            }

            foreach (string lang in languages)
            {
                // Get this language's version of the current string
                string translated;
                if (!stringValues.TryGetValue(lang, out translated))
                {
                    translated = "String N/A";
                }
                // Should be a delayed text field as discussed above
                string newTranslated = EditorGUILayout.TextField(translated, GUILayout.Width(subseqColWidth),
                                                                 GUILayout.Height(rowHeight));

                if (newTranslated != translated)
                {
                    stringValues.Remove(lang);
                    stringValues.Add(lang, newTranslated);
                    //Debug.Log("changed " + lang + " " + stringName + " to " + newTranslated);
                }
            }
            EditorGUILayout.EndHorizontal();
        }
        GUI.skin.textField.fontSize = originalFontsize;

        // Rename any keys that were changed - we can't edit these above because it would change the dictionary
        // being iterated over
        foreach (KeyValuePair <string, string> entry in stringsToRename)
        {
            Dictionary <string, string> translations;
            if (!_strings.dict().TryGetValue(entry.Key, out translations))
            {
                Debug.LogError("Failed to get stringToRename: " + entry.Key);
            }
            else
            {
                _strings.dict().Remove(entry.Key);
                if (entry.Value != null)
                {
                    _strings.dict().Add(entry.Value, translations);
                }
                //Debug.Log("Renamed " + entry.Key + " to " + entry.Value);
            }
        }
        stringsToRename.Clear();

        string defaultStringBaseName = "NewString";
        string defaultStringName     = defaultStringBaseName;
        int    defaultStringIndex    = 1;

        if (GUILayout.Button("Add String", GUILayout.Width(firstColWidth), GUILayout.Height(30)))
        {
            // Add an index to the new string names to prevent collision
            // eg. UnnamedString, UnnamedString1, UnnamedString2 ...
            while (_strings.dict().ContainsKey(defaultStringName))
            {
                defaultStringName = defaultStringBaseName + defaultStringIndex++;
            }
            _strings.dict().Add(defaultStringName, new Dictionary <string, string>());
        }

        GUILayout.FlexibleSpace();
        EditorGUILayout.EndScrollView();
    }