Exemplo n.º 1
0
        public void OnGUI()
        {
            if (!Proxy.IsPlaying() || this.disabled)
            {
                return;
            }
            var current = Event.current;

            if (current.isKey || current.shift || current.alt || current.control || current.command)
            {
                if (!this.devices.Exists(x => x.name == "Keyboard"))
                {
                    this.devices.Add(new InputDevice("Keyboard"));
                }
            }
            bool uiActive = this.uiState != InputUIState.None;

            if (this.uiObject.IsNull())
            {
                this.uiObject = Locate.Find("@Main/InputUI");
                if (this.uiObject.IsNull())
                {
                    this.uiObject      = GameObject.Instantiate(this.uiPrefab);
                    this.uiObject.name = this.uiObject.name.Remove("(Clone)");
                    this.uiObject.transform.SetParent(Locate.GetScenePath("@Main").transform);
                    Locate.SetDirty();
                }
            }
            this.uiObject.SetActive(uiActive);
            Locate.Find("@Main/InputUI/ProfileCreate/").SetActive(false);
            Locate.Find("@Main/InputUI/ProfileSelect/").SetActive(false);
            if (uiActive)
            {
                Console.Close(true);
                InputState.disabled = true;
                this.DrawProfileSelect();
                this.DrawProfileEdit();
                bool hitEscape = Event.current.keyCode == KeyCode.Escape;
                if (Event.current.type == EventType.KeyDown && hitEscape)
                {
                    this.uiState        = InputUIState.None;
                    InputState.disabled = false;
                }
            }
        }
Exemplo n.º 2
0
 public void DrawProfileEdit()
 {
     if (this.uiState == InputUIState.EditProfile)
     {
         var profile = this.activeProfile;
         var group   = this.groups[this.uiGroupIndex];
         var action  = group.actions[this.uiIndex];
         var path    = "@Main/InputUI/ProfileCreate/";
         Locate.Find(path).SetActive(true);
         Locate.Find(path + "Text-Key").GetComponent <Text>().text     = action.name;
         Locate.Find(path + "Text-Profile").GetComponent <Text>().text = "<size=100><color=#888888FF>" + profile.name + "</color></size>\nProfile";
         Locate.Find(path + "Icon-Gamepad").SetActive(!action.helpImage.IsNull());
         Locate.Find(path + "Icon-Gamepad/" + action.helpImage).SetActive(!action.helpImage.IsNull());
         if (this.waitForRelease)
         {
             foreach (var key in this.lastInput.Keys.ToList())
             {
                 this.lastInput[key] = 0;
             }
             this.waitForRelease = this.waitForRelease && this.lastInput.Count != 0;
         }
         var progress    = Locate.Find(path + "Image-Timer");
         var highest     = this.lastInput.OrderBy(x => x.Value).FirstOrDefault();
         var timeHeld    = highest.Key.IsEmpty() ? Time.Get() + InputManager.registerTime : highest.Value;
         var targetInput = this.lastInput.Where(x => Time.Get() > x.Value).FirstOrDefault();
         progress.SetActive(highest.Value > 0);
         progress.GetComponent <Image>().fillAmount = InputManager.registerTime - (timeHeld - Time.Get());
         if (!this.waitForRelease && !targetInput.Key.IsEmpty())
         {
             this.waitForRelease = true;
             Locate.Find(path + "Icon-Gamepad/" + action.helpImage).SetActive(false);
             var    inputName  = targetInput.Key;
             string device     = "Keyboard";
             string groupName  = group.name.ToPascalCase();
             string actionName = action.name.ToPascalCase();
             if (inputName.Contains("Joystick"))
             {
                 int id = (int)Char.GetNumericValue(inputName.Remove("Joystick")[0]);
                 device    = this.joystickNames[id - 1];
                 inputName = inputName.ReplaceFirst(id.ToString(), "*");
             }
             else if (inputName.Contains("Mouse"))
             {
                 device = "Mouse";
             }
             var existsText = Locate.Find(path + "Text-Exists");
             var match      = profile.mappings.collection.Where(x => x.Key.Contains(groupName + "-", true) && x.Value.Matches(inputName, true)).FirstOrDefault();
             existsText.SetActive(!match.Key.IsEmpty());
             if (!match.Key.IsEmpty())
             {
                 existsText.GetComponent <Text>().text = inputName.Remove("*") + " already mapped to : <color=#FF9999FF>" + match.Key.Split("-")[1] + "</color>";
                 return;
             }
             profile.requiredDevices.AddNew(device);
             profile.mappings[groupName + "-" + actionName] = inputName;
             this.uiIndex += 1;
             if (this.uiIndex >= group.actions.Count)
             {
                 this.uiGroupIndex += 1;
                 if (this.uiGroupIndex >= this.groups.Count)
                 {
                     profile.Save();
                     this.activeProfile  = null;
                     this.uiState        = InputUIState.None;
                     InputState.disabled = false;
                     this.DelayEvent("On Profile Edited", 0);
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
        public void Search()
        {
            if (this.mode != TargetMode.Search)
            {
                return;
            }
            if (this.search.IsEmpty())
            {
                this.search = this.fallbackSearch;
            }
            if (this.search.IsEmpty())
            {
                return;
            }
            string search = this.search.Replace("\\", "/");

            if (!search.IsEmpty())
            {
                for (int index = 0; index < this.special.Count; ++index)
                {
                    string     specialName = this.specialNames[index];
                    GameObject special     = this.special[index];
                    if (!special.IsNull() && search.Contains(specialName, true))
                    {
                        string specialPath = special.GetPath();
                        search = search.Replace(specialName, specialPath, true);
                    }
                }
                if (search.ContainsAny("/", "."))
                {
                    string[]   parts   = search.Split("/");
                    string     total   = "";
                    GameObject current = null;
                    for (int index = 0; index < parts.Length; ++index)
                    {
                        string part = parts[index];
                        current = GameObject.Find(total);
                        if (part.IsEmpty())
                        {
                            continue;
                        }
                        if (part == ".." || part == ".")
                        {
                            if (total.IsEmpty())
                            {
                                int specialIndex = this.specialNames.FindIndex(x => x.Contains("[this]", true));
                                current = specialIndex != -1 ? this.special[index] : null;
                                if (!current.IsNull())
                                {
                                    if (part == "..")
                                    {
                                        total = current.GetParent().IsNull() ? "" : current.GetParent().GetPath();
                                    }
                                    else
                                    {
                                        total = current.GetPath();
                                    }
                                }
                                continue;
                            }
                            current = GameObject.Find(total);
                            if (!current.IsNull())
                            {
                                if (part == "..")
                                {
                                    total = current.GetParent().IsNull() ? "" : current.GetParent().GetPath();
                                }
                                continue;
                            }
                        }
                        GameObject next = GameObject.Find(total + part + "/");
                        if (next.IsNull() && !current.IsNull() && Attribute.lookup.ContainsKey(current))
                        {
                            var match = Attribute.lookup[current].Where(x => x.Value.info.name.Matches(part)).FirstOrDefault().Value;
                            if (match is AttributeGameObject)
                            {
                                next = match.As <AttributeGameObject>().Get();
                                if (!next.IsNull())
                                {
                                    total = next.GetPath();
                                }
                                continue;
                            }
                        }
                        total += part + "/";
                    }
                    search = total;
                }
                this.searchObject = Locate.Find(search);
            }
        }