Пример #1
0
 public void ShowProfiles()
 {
     this.activeProfile   = null;
     this.selectionHeader = "";
     this.profiles.RemoveAll(x => !File.Exists(x.name + ".profile"));
     this.uiState = InputUIState.SelectProfile;
 }
Пример #2
0
 public void DrawProfileSelect()
 {
     if (this.uiState == InputUIState.SelectProfile)
     {
         //var path = "@Main/InputUI/ProfileSelect/";
         //Locate.Find(path).SetActive(true);
         var buttonWidth  = Screen.width * 0.5f;
         var buttonHeight = Screen.height * 0.09f;
         var area         = new Rect((Screen.width / 2) - buttonWidth / 2, 10, buttonWidth, buttonHeight);
         var style        = GUI.skin.button.Font("Bombardier.otf").FontSize((int)(buttonHeight * 0.7f));
         GUI.Label(area, this.selectionHeader, style.Background(""));
         area = area.AddY(buttonHeight + 8);
         foreach (var profile in this.profiles.Copy())
         {
             bool usable = this.devices.Select(x => x.name).ContainsAll(profile.requiredDevices);
             if (!usable)
             {
                 GUI.enabled = false;
             }
             if (GUI.Button(area, profile.name, style))
             {
                 this.activeProfile  = profile;
                 this.uiState        = InputUIState.None;
                 InputState.disabled = false;
                 this.DelayEvent("On Profile Selected", 0);
             }
             GUI.enabled = true;
             area        = area.AddY(buttonHeight + 5);
         }
     }
 }
Пример #3
0
 public void Setup()
 {
     InputManager.singleton = this;
     this.uiState           = 0;
     this.activeProfile     = null;
     this.devices.Clear();
     this.profiles.Clear();
     this.joystickNames = this.joystickNames.Clear();
 }
Пример #4
0
 public void EditProfile(string name)
 {
     this.lastInput.Clear();
     this.uiState       = InputUIState.EditProfile;
     this.uiGroupIndex  = 0;
     this.uiIndex       = 0;
     this.activeProfile = this.profiles.Find(x => x.name == name);
     if (this.activeProfile.IsNull())
     {
         this.ShowProfiles();
         this.selectionHeader = "Edit Profile";
         Events.AddLimited("On Profile Selected", () => this.EditProfile(this.activeProfile.name), 1, this);
     }
 }
Пример #5
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;
                }
            }
        }
Пример #6
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);
                 }
             }
         }
     }
 }