Esempio n. 1
0
        void Start()
        {
            key_infos = new Dictionary <Button, KeyInfo>();
            Button key_altgr    = null;
            bool   use_ctrl_alt = false;
            Dictionary <int, string[]> all_regular_scancodes = new Dictionary <int, string[]>();

            foreach (var btn in GetComponentsInChildren <Button>())
            {
                string name = btn.gameObject.name;
                int    scancode;
                string text0, text1, text2;

                if (name.StartsWith("S") && Int32.TryParse(name.Substring(1), out scancode))
                {
                    if (scancode == SCAN_BACKSPACE || scancode == SCAN_TAB || scancode == SCAN_ENTER ||
                        scancode == SCAN_ALTGR || scancode == SCAN_ESC)
                    {
                        if (scancode == SCAN_TAB && !enableTabKey ||
                            scancode == SCAN_ENTER && !enableEnterKey ||
                            scancode == SCAN_ESC && !enableEscKey)
                        {
                            Destroy(btn.gameObject);
                            continue;
                        }
                        text0 = text1 = text2 = btn.GetComponentInChildren <Text>().text;
                        if (scancode == SCAN_ALTGR)
                        {
                            key_altgr = btn;
                        }
                        if (scancode == SCAN_ENTER)
                        {
                            text2 = "";
                        }
                    }
                    else if (scancode == SCAN_SPACE)
                    {
                        text0 = text1 = text2 = " ";
                        all_regular_scancodes.Add(scancode, new string[] { text0, text1 });
                    }
                    else
                    {
                        text0 = GetCharsFromKeys(scancode, false, false);
                        text1 = GetCharsFromKeys(scancode, true, false);
                        text2 = GetCharsFromKeys(scancode, false, true);

                        if (scancode == SCAN_EXTRA && text0 == GetCharsFromKeys(SCAN_BACKSLASH, false, false) &&
                            text1 == GetCharsFromKeys(SCAN_BACKSLASH, true, false) &&
                            text2 == GetCharsFromKeys(SCAN_BACKSLASH, false, true))
                        {
                            text0 = "";    /* key SCAN_EXTRA is completely equivalent to SCAN_BACKSLASH, hide it */
                        }
                        if (text0 == "")
                        {
                            Destroy(btn.gameObject);
                            continue;
                        }
                        use_ctrl_alt |= (text2 != "");
                        all_regular_scancodes.Add(scancode, new string[] { text0, text1 });
                    }
                }
                else if (name.StartsWith("K-") && name.Length == 4)
                {
                    scancode = SCAN_UNKNOWN;
                    text0    = name[2].ToString();
                    text1    = name[3].ToString();
                    text2    = "";
                }
                else
                {
                    continue;
                }

                var info = new KeyInfo();
                info.scan_code    = scancode;
                info.current_text = text0;
                info.texts        = new string[] { text0, text1, text2 };
                info.image        = btn.GetComponent <Image>();
                info.text         = btn.GetComponentInChildren <Text>();
                info.Update();
                key_infos[btn] = info;
            }
            if (!use_ctrl_alt && key_altgr != null)
            {
                key_infos.Remove(key_altgr);
                Destroy(key_altgr.gameObject);
            }
            dead_keys_combinations = new Dictionary <string, Dictionary <string, string> >();
            foreach (var info in key_infos.Values)
            {
                AddDeadKeyCombination(all_regular_scancodes, info.texts[0], info.scan_code, false, false);
                AddDeadKeyCombination(all_regular_scancodes, info.texts[1], info.scan_code, true, false);
                AddDeadKeyCombination(all_regular_scancodes, info.texts[2], info.scan_code, false, true);
            }

            foreach (Canvas canvas in GetComponentsInChildren <Canvas>())
            {
                canvas.worldCamera = GetControllerCamera();
            }

            locals = new List <Local>();

            var ct = Controller.HoverTracker(this);

            ct.SetPriorityFromDistance(controllerPriority);
            ct.isConcurrent         = true;
            ct.onEnter             += OnEnter;
            ct.onControllersUpdate += OnControllersUpdate;
            ct.onLeave             += OnLeave;
            ct.onTouchDown         += (ctrl) => { }; /* needed to grab interest in the touchpad */
        }
Esempio n. 2
0
        void Start()
        {
            key_infos = new Dictionary <Button, KeyInfo>();
            Button key_altgr    = null;
            bool   use_ctrl_alt = false;
            Dictionary <int, string[]> all_regular_scancodes = new Dictionary <int, string[]>();

            foreach (var btn in GetComponentsInChildren <Button>(includeInactive: true))
            {
                string name = btn.gameObject.name;
                int    scancode;
                char   scancodeextra = '\0';
                string text0, text1, text2;

                if (name.StartsWith("X") && name.Length > 2)
                {
                    scancodeextra = name[1];
                    name          = "S" + name.Substring(2);
                }
                if (name.StartsWith("S") && Int32.TryParse(name.Substring(1), out scancode))
                {
                    if (scancode == SCAN_BACKSPACE || scancode == SCAN_TAB || scancode == SCAN_ENTER ||
                        scancode == SCAN_ALTGR || scancode == SCAN_ESC)
                    {
                        if (scancode == SCAN_TAB && !enableTabKey ||
                            scancode == SCAN_ENTER && !enableEnterKey ||
                            scancode == SCAN_ESC && !enableEscKey)
                        {
                            Destroy(btn.gameObject);
                            continue;
                        }
                        text0 = text1 = text2 = btn.GetComponentInChildren <Text>().text;
                        if (scancode == SCAN_ALTGR)
                        {
                            key_altgr = btn;
                        }
                        if (scancode == SCAN_ENTER)
                        {
                            text2 = "";
                        }
                    }
                    else if (scancode == SCAN_SPACE)
                    {
                        text0 = text1 = text2 = " ";
                        all_regular_scancodes.Add(scancode, new string[] { text0, text1 });
                    }
                    else
                    {
                        text0 = GetCharsFromKeys(scancode, false, false);
                        text1 = GetCharsFromKeys(scancode, true, false);
                        text2 = GetCharsFromKeys(scancode, false, true);

                        if (scancode == SCAN_EXTRA && text0 == GetCharsFromKeys(SCAN_BACKSLASH, false, false) &&
                            text1 == GetCharsFromKeys(SCAN_BACKSLASH, true, false) &&
                            text2 == GetCharsFromKeys(SCAN_BACKSLASH, false, true))
                        {
                            text0 = "";    /* key SCAN_EXTRA is completely equivalent to SCAN_BACKSLASH, hide it */
                        }
                        if (text0 == "")
                        {
                            Destroy(btn.gameObject);
                            continue;
                        }
                        use_ctrl_alt |= (text2 != "");
                        all_regular_scancodes.Add(scancode, new string[] { text0, text1 });
                    }
                }
                else if (name.StartsWith("K-") && name.Length == 4)
                {
                    scancode = SCAN_UNKNOWN;
                    text0    = name[2].ToString();
                    text1    = name[3].ToString();
                    text2    = "";
                }
                else
                {
                    continue;
                }

                if (scancodeextra == '\0')
                {
                    switch (scancode)
                    {
                    case SCAN_ENTER: scancodeextra = '\n'; break;

                    case SCAN_TAB: scancodeextra = '\t'; break;
                    }
                }

                var info = new KeyInfo();
                info.scan_code       = scancode;
                info.scan_code_extra = scancodeextra;
                info.current_text    = text0;
                info.texts           = new string[] { text0, text1, text2 };
                info.image           = btn.GetComponent <Image>();
                info.text            = btn.GetComponentInChildren <Text>();
                info.Update();
                key_infos[btn] = info;
            }
            if (!use_ctrl_alt && key_altgr != null)
            {
                key_infos.Remove(key_altgr);
                Destroy(key_altgr.gameObject);
            }
            dead_keys_combinations = new Dictionary <string, Dictionary <string, string> >();
            foreach (var info in key_infos.Values)
            {
                AddDeadKeyCombination(all_regular_scancodes, info.texts[0], info.scan_code, false, false);
                AddDeadKeyCombination(all_regular_scancodes, info.texts[1], info.scan_code, true, false);
                AddDeadKeyCombination(all_regular_scancodes, info.texts[2], info.scan_code, false, true);
            }

            foreach (Canvas canvas in GetComponentsInChildren <Canvas>(includeInactive: true))
            {
                canvas.worldCamera = GetControllerCamera();
            }

            locals = new List <Local>();

            var ct = Controller.HoverTracker(this);

            ct.SetPriorityFromDistance(controllerPriority);
            ct.isConcurrent         = true;
            ct.onEnter             += OnEnter;
            ct.onControllersUpdate += OnControllersUpdate;
            ct.onLeave             += OnLeave;
            ct.onTouchDown         += (ctrl) => { };

            /* ^^^ needed in addition to next line: otherwise, touching "Enter" closes the keyboard,
             * and then finishing our movement and actually pressing---that message would be sent
             * wherever the controller is now, without the line above. */
            ct.onTouchPressDown += (ctrl) => { };   /* needed to grab interest in the touchpad / A button */
            bool is_oculus = Baroque.GetControllers().Any(ctrl => ctrl.controllerModel == Controller.Model.OculusTouch);

            if (is_oculus)
            {
                ct.onMenuClick += (ctrl) => { }
            }
            ;                                      /* needed to grab interest in the B button */
            if (reactToTriggerToo)
            {
                ct.onTriggerDown += (ctrl) => { }
            }
            ;
        }

        void AddDeadKeyCombination(Dictionary <int, string[]> all_regular_scancodes, string key_text,
                                   int scan_code, bool with_shift, bool with_altgr)
        {
            if (!key_text.StartsWith(DEAD_KEY))
            {
                return;
            }

            var k = key_text.Substring(DEAD_KEY.Length);

            dead_keys_combinations[k] = new Dictionary <string, string>();
            foreach (var kv in all_regular_scancodes)
            {
                for (int i = 1; i >= 0; i--)
                {
                    if (kv.Value[i].StartsWith(DEAD_KEY))
                    {
                        continue;
                    }
                    string combined = GetCharsFromKeys(scan_code, with_shift, with_altgr, next_scancode: kv.Key, next_shift: i == 1);
                    if (combined != k + kv.Value[i])
                    {
                        dead_keys_combinations[k][kv.Value[i]] = combined;
                    }
                }
            }
        }
Esempio n. 3
0
    void Start()
    {
        key_infos = new Dictionary <Button, KeyInfo>();
        Button key_altgr    = null;
        bool   use_ctrl_alt = false;
        Dictionary <int, string[]> all_regular_scancodes = new Dictionary <int, string[]>();

        foreach (var btn in GetComponentsInChildren <Button>())
        {
            string name = btn.gameObject.name;
            int    scancode;
            if (name.StartsWith("S") && Int32.TryParse(name.Substring(1), out scancode))
            {
                string text0, text1, text2;

                if (scancode == SCAN_BACKSPACE || scancode == SCAN_TAB || scancode == SCAN_ENTER ||
                    scancode == SCAN_ALTGR || scancode == SCAN_ESC)
                {
                    if (scancode == SCAN_TAB && !enableTabKey ||
                        scancode == SCAN_ENTER && !enableEnterKey ||
                        scancode == SCAN_ESC && !enableEscKey)
                    {
                        Destroy(btn.gameObject);
                        continue;
                    }
                    text0 = text1 = text2 = btn.GetComponentInChildren <Text>().text;
                    if (scancode == SCAN_ALTGR)
                    {
                        key_altgr = btn;
                    }
                    if (scancode == SCAN_ENTER)
                    {
                        text2 = "";
                    }
                }
                else if (scancode == SCAN_SPACE)
                {
                    text0 = text1 = text2 = " ";
                    all_regular_scancodes.Add(scancode, new string[] { text0, text1 });
                }
                else
                {
                    text0 = GetCharsFromKeys(scancode, false, false);
                    text1 = GetCharsFromKeys(scancode, true, false);
                    text2 = GetCharsFromKeys(scancode, false, true);

                    if (scancode == SCAN_EXTRA && text0 == GetCharsFromKeys(SCAN_BACKSLASH, false, false) &&
                        text1 == GetCharsFromKeys(SCAN_BACKSLASH, true, false) &&
                        text2 == GetCharsFromKeys(SCAN_BACKSLASH, false, true))
                    {
                        text0 = "";    /* key SCAN_EXTRA is completely equivalent to SCAN_BACKSLASH, hide it */
                    }
                    if (text0 == "")
                    {
                        Destroy(btn.gameObject);
                        continue;
                    }
                    use_ctrl_alt |= (text2 != "");
                    all_regular_scancodes.Add(scancode, new string[] { text0, text1 });
                }
                var info = new KeyInfo();
                info.scan_code    = scancode;
                info.current_text = text0;
                info.texts        = new string[] { text0, text1, text2 };
                info.image        = btn.GetComponent <Image>();
                info.text         = btn.GetComponentInChildren <Text>();
                info.Update();
                key_infos[btn] = info;
            }
        }
        if (!use_ctrl_alt)
        {
            key_infos.Remove(key_altgr);
            Destroy(key_altgr.gameObject);
        }
        dead_keys_combinations = new Dictionary <string, Dictionary <string, string> >();
        foreach (var info in key_infos.Values)
        {
            AddDeadKeyCombination(all_regular_scancodes, info.texts[0], info.scan_code, false, false);
            AddDeadKeyCombination(all_regular_scancodes, info.texts[1], info.scan_code, true, false);
            AddDeadKeyCombination(all_regular_scancodes, info.texts[2], info.scan_code, false, true);
        }

        foreach (Canvas canvas in GetComponentsInChildren <Canvas>())
        {
            canvas.worldCamera = BaroqueUI.BaroqueUI.GetControllerCamera();
        }

        locals = new List <Local>();
    }