Exemplo n.º 1
0
 public void OnEnable()
 {
     this.Setup();
     InputGroup.Load();
     if (!Proxy.IsPlaying())
     {
         return;
     }
     this.Validate();
     if (this.disabled)
     {
         return;
     }
     InputProfile.Load();
     InputInstance.Load();
     Console.AddKeyword("inputShowProfiles", this.ShowProfiles);
     Console.AddKeyword("inputAssignProfile", this.AssignProfile);
     Console.AddKeyword("inputCreateProfile", this.CreateProfile);
     Console.AddKeyword("inputEditProfile", this.EditProfile);
     Console.AddKeyword("inputRemoveProfile", this.RemoveProfile);
     Events.Register("On Profile Selected", this);
     Events.Register("On Profile Edited", this);
     Events.Add("On Update", this.Update);
     Events.Add("On Fixed Update", this.FixedUpdate);
     Events.Add("On GUI", this.OnGUI);
     this.DetectGamepads();
 }
Exemplo n.º 2
0
 public void ShowProfiles()
 {
     this.activeProfile   = null;
     this.selectionHeader = "";
     this.profiles.RemoveAll(x => !File.Exists(x.name + ".profile"));
     this.uiState = InputUIState.SelectProfile;
 }
Exemplo n.º 3
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);
         }
     }
 }
Exemplo n.º 4
0
 public void Setup()
 {
     InputManager.singleton = this;
     this.uiState           = 0;
     this.activeProfile     = null;
     this.devices.Clear();
     this.profiles.Clear();
     this.joystickNames = this.joystickNames.Clear();
 }
Exemplo n.º 5
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);
     }
 }
Exemplo n.º 6
0
 //===============
 // Unity
 //===============
 public override void Awake()
 {
     base.Awake();
     this.DefaultRate("Update");
     this.state.Setup("State", this);
     Events.Add("Hold Input", this.HoldInput, this);
     Events.Add("Release Input", this.ReleaseInput, this);
     if (Proxy.IsPlaying())
     {
         this.profile = InputManager.Get().GetInstanceProfile(this);
         if (this.profile.IsNull() || this.profile.name.IsEmpty())
         {
             Call.Delay(() => InputManager.Get().SelectProfile(this), 0.1f);
         }
     }
     Events.Add("On Validate", this.PrepareInput, InputManager.Get());
     this.PrepareInput();
 }
Exemplo n.º 7
0
 public static void Load()
 {
     foreach (var file in File.FindAll("*.profile", true))
     {
         var    profile = new InputProfile(file.name);
         var    text    = file.ReadText().GetLines();
         int    mode    = 0;
         string group   = "";
         foreach (var line in text)
         {
             if (line.IsEmpty())
             {
                 continue;
             }
             if (line.Contains("[Input-Devices]"))
             {
                 mode = 1;
             }
             else if (line.Contains("[InputGroup-"))
             {
                 mode  = 2;
                 group = line.Parse("-", "]");
             }
             else if (mode == 1)
             {
                 profile.requiredDevices.Add(line.Trim());
             }
             else if (mode == 2)
             {
                 var actionName = line.Parse("", " ");
                 var buttonName = line.Parse(" ");
                 profile.mappings[group + "-" + actionName] = buttonName;
             }
         }
         InputManager.Get().profiles.Add(profile);
     }
 }
Exemplo n.º 8
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);
                 }
             }
         }
     }
 }