Exemplo n.º 1
0
        public void LoadData()
        {
            if (!File.Exists(BindingsConfigPath))
            {
                TextWriter tw = new StreamWriter(BindingsConfigPath);
                tw.WriteLine("---- this is the key bindings configuration file for Procedural Objects ----");
                tw.WriteLine("You can put any key binding you want for each of those actions. Just be");
                tw.WriteLine("sure they are the right names. For example don't right 'Ctrl' but \"LeftControl\"");
                tw.WriteLine("Use the 'plus' symbol to create any key combination, works for any keys or any number of keys.");
                tw.WriteLine("It works for any keys or combination of keys, the list of the names you should use can be found here:");
                tw.WriteLine("https://docs.unity3d.com/ScriptReference/KeyCode.html");
                tw.WriteLine("");
                tw.WriteLine("generalShowHideUI = LeftControl+P+O");
                tw.WriteLine("convertToProcedural = LeftShift+P");
                tw.WriteLine("copy = LeftControl+C");
                tw.WriteLine("paste = LeftControl+V");
                tw.WriteLine("switchActionMode = LeftControl");
                tw.WriteLine("switchGeneralToVertexTools = Tab");
                tw.WriteLine("deleteObject = Delete");
                tw.WriteLine("");
                tw.WriteLine("edition_smoothMovements = LeftShift");
                tw.WriteLine("edition_smallMovements = LeftAlt");
                tw.WriteLine("");
                tw.WriteLine("position_moveUp = PageUp");
                tw.WriteLine("position_moveDown = PageDown");
                tw.WriteLine("position_moveRight = RightArrow");
                tw.WriteLine("position_moveLeft = LeftArrow");
                tw.WriteLine("position_moveForward = UpArrow");
                tw.WriteLine("position_moveBackward = DownArrow");
                tw.WriteLine("");
                tw.WriteLine("rotation_moveUp = PageUp");
                tw.WriteLine("rotation_moveDown = PageDown");
                tw.WriteLine("rotation_moveRight = RightArrow");
                tw.WriteLine("rotation_moveLeft = LeftArrow");
                tw.WriteLine("rotation_moveForward = UpArrow");
                tw.WriteLine("rotation_moveBackward = DownArrow");
                tw.WriteLine("");
                tw.WriteLine("scale_scaleUp = PageUp");
                tw.WriteLine("scale_scaleDown = PageDown");
                tw.WriteLine("");
                tw.WriteLine("snapStoredHeight = H");
                tw.WriteLine("undo = LeftControl+Z");
                tw.WriteLine("redo = LeftControl+Y");
                tw.Close();
            }
            m_keyBindings = new List <KeyBindingInfo>();
            var lines = File.ReadAllLines(BindingsConfigPath).ToList();

            if (!lines.Any(line => line.Contains("snapStoredHeight = ")))
            {
                if (File.Exists(BindingsConfigPath))
                {
                    File.Delete(BindingsConfigPath);
                }
                TextWriter tw = new StreamWriter(BindingsConfigPath);
                foreach (string line in lines)
                {
                    tw.WriteLine(line);
                }
                tw.WriteLine("");
                tw.WriteLine("snapStoredHeight = H");
                lines.Add("snapStoredHeight = H");
                tw.Close();
            }
            if (!lines.Any(line => line.Contains("undo = ")))
            {
                if (File.Exists(BindingsConfigPath))
                {
                    File.Delete(BindingsConfigPath);
                }
                TextWriter tw = new StreamWriter(BindingsConfigPath);
                foreach (string line in lines)
                {
                    tw.WriteLine(line);
                }
                tw.WriteLine("undo = LeftControl+Z");
                lines.Add("undo = LeftControl+Z");
                tw.Close();
            }
            if (!lines.Any(line => line.Contains("redo = ")))
            {
                if (File.Exists(BindingsConfigPath))
                {
                    File.Delete(BindingsConfigPath);
                }
                TextWriter tw = new StreamWriter(BindingsConfigPath);
                foreach (string line in lines)
                {
                    tw.WriteLine(line);
                }
                tw.WriteLine("redo = LeftControl+Y");
                lines.Add("redo = LeftControl+Y");
                tw.Close();
            }
            foreach (string line in lines)
            {
                if (line != string.Empty && line.Contains("="))
                {
                    KeyBindingInfo kbInfo = new KeyBindingInfo(line);
                    m_keyBindings.Add(kbInfo);
                }
            }

            keyBindingsDictionary = new Dictionary <string, KeyBindingInfo>();
            foreach (var kbInfo in m_keyBindings)
            {
                keyBindingsDictionary.Add(kbInfo.m_name, kbInfo);
            }
            Debug.Log("[ProceduralObjects] Key Bindings loading ended from " + BindingsConfigPath);
        }
        public void LoadData()
        {
            if (!File.Exists(BindingsConfigPath))
            {
                TextWriter tw = new StreamWriter(BindingsConfigPath);
                tw.WriteLine("---- this is the key bindings configuration file for Procedural Objects ----");
                tw.WriteLine("You can put any key binding you want for each of those actions. Just be");
                tw.WriteLine("sure they are the right names. For example don't right 'Ctrl' but \"LeftControl\"");
                tw.WriteLine("Use the 'plus' symbol to create any key combination, works for any keys or any number of keys.");
                tw.WriteLine("It works for any keys or combination of keys, the list of the names you should use can be found here:");
                tw.WriteLine("https://docs.unity3d.com/ScriptReference/KeyCode.html");
                tw.WriteLine("");
                tw.WriteLine("generalShowHideUI = LeftControl+P+O");
                tw.WriteLine("switchActionMode = LeftControl");
                tw.WriteLine("");
                tw.WriteLine("edition_smoothMovements = LeftShift");
                tw.WriteLine("edition_smallMovements = LeftAlt");
                tw.Close();
            }
            m_keyBindings = new List <KeyBindingInfo>();
            var lines = File.ReadAllLines(BindingsConfigPath).ToList();
            var keys  = ProceduralObjectsMod.SettingsFile.ListKeys().Where(s => s.StartsWith("KB_"));

            foreach (string line in new List <string>(lines))
            {
                if (line != string.Empty && line.Contains("="))
                {
                    var key = line.Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries)[0].Trim();
                    if (keys.Any(k => k.Contains("KB_" + key)))
                    {
                        lines.Remove(line);
                    }
                    else
                    {
                        KeyBindingInfo kbInfo = new KeyBindingInfo(line);
                        m_keyBindings.Add(kbInfo);
                    }
                }
            }

            RewriteCfgLines(lines);

            if (ProceduralObjectsMod.SettingsFile != null)
            {
                foreach (var key in keys)
                {
                    var k = key.Replace("KB_", "");
                    if (m_keyBindings.Any(kb => kb.m_name == k))
                    {
                        continue;
                    }
                    KeyBindingInfo kbInfo = new KeyBindingInfo(k, new SavedInputKey(key, ProceduralObjectsMod.SETTINGS_FILENAME));
                    m_keyBindings.Add(kbInfo);
                }
            }
            keyBindingsDictionary = new Dictionary <string, KeyBindingInfo>();
            foreach (var kbInfo in m_keyBindings)
            {
                keyBindingsDictionary.Add(kbInfo.m_name, kbInfo);
            }
            Debug.Log("[ProceduralObjects] Key Bindings loading ended from " + BindingsConfigPath);
        }