Author Topic: InControl + NGUI  (Read 10947 times)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
InControl + NGUI
« on: May 09, 2015, 04:06:31 AM »
I recently decided to add InControl plugin to Windward to handle different controller types. Although it doesn't seem to support NVidia Shield controller on Windows properly, it does seem to work quite well. If anyone else is doing something similar and wants an example of how to integrate it with NGUI, this script should help to give you an idea:
  1. using UnityEngine;
  2. using InControl;
  3.  
  4. [RequireComponent(typeof(InControlManager))]
  5. public class InControlNGUI : MonoBehaviour
  6. {
  7.         void OnEnable ()
  8.         {
  9.                 UICamera.GetKey = GetKey;
  10.                 UICamera.GetKeyDown = GetKeyDown;
  11.                 UICamera.GetKeyUp = GetKeyUp;
  12.                 UICamera.GetAxis = GetAxis;
  13.         }
  14.  
  15.         static bool GetKeyDown (KeyCode key)
  16.         {
  17.                 if (key >= KeyCode.JoystickButton0)
  18.                 {
  19.                         InputDevice dev = InputManager.ActiveDevice;
  20.  
  21.                         switch (key)
  22.                         {
  23.                                 case KeyCode.JoystickButton0: return dev.GetControl(InputControlType.Action1).WasPressed;
  24.                                 case KeyCode.JoystickButton1: return dev.GetControl(InputControlType.Action2).WasPressed;
  25.                                 case KeyCode.JoystickButton2: return dev.GetControl(InputControlType.Action3).WasPressed;
  26.                                 case KeyCode.JoystickButton3: return dev.GetControl(InputControlType.Action4).WasPressed;
  27.                                 case KeyCode.JoystickButton4: return dev.GetControl(InputControlType.LeftBumper).WasPressed;
  28.                                 case KeyCode.JoystickButton5: return dev.GetControl(InputControlType.RightBumper).WasPressed;
  29.                                 case KeyCode.JoystickButton6: return dev.GetControl(InputControlType.Back).WasPressed;
  30.                                 case KeyCode.JoystickButton7: return dev.GetControl(InputControlType.Start).WasPressed;
  31.                                 case KeyCode.JoystickButton8: return dev.GetControl(InputControlType.LeftStickButton).WasPressed;
  32.                                 case KeyCode.JoystickButton9: return dev.GetControl(InputControlType.RightStickButton).WasPressed;
  33.                         }
  34.                 }
  35.                 return Input.GetKeyDown(key);
  36.         }
  37.  
  38.         static bool GetKey (KeyCode key)
  39.         {
  40.                 if (key >= KeyCode.JoystickButton0)
  41.                 {
  42.                         InputDevice dev = InputManager.ActiveDevice;
  43.  
  44.                         switch (key)
  45.                         {
  46.                                 case KeyCode.JoystickButton0: return dev.GetControl(InputControlType.Action1).IsPressed;
  47.                                 case KeyCode.JoystickButton1: return dev.GetControl(InputControlType.Action2).IsPressed;
  48.                                 case KeyCode.JoystickButton2: return dev.GetControl(InputControlType.Action3).IsPressed;
  49.                                 case KeyCode.JoystickButton3: return dev.GetControl(InputControlType.Action4).IsPressed;
  50.                                 case KeyCode.JoystickButton4: return dev.GetControl(InputControlType.LeftBumper).IsPressed;
  51.                                 case KeyCode.JoystickButton5: return dev.GetControl(InputControlType.RightBumper).IsPressed;
  52.                                 case KeyCode.JoystickButton6: return dev.GetControl(InputControlType.Back).IsPressed;
  53.                                 case KeyCode.JoystickButton7: return dev.GetControl(InputControlType.Start).IsPressed;
  54.                                 case KeyCode.JoystickButton8: return dev.GetControl(InputControlType.LeftStickButton).IsPressed;
  55.                                 case KeyCode.JoystickButton9: return dev.GetControl(InputControlType.RightStickButton).IsPressed;
  56.                         }
  57.                 }
  58.                 return Input.GetKey(key);
  59.         }
  60.  
  61.         static bool GetKeyUp (KeyCode key)
  62.         {
  63.                 if (key >= KeyCode.JoystickButton0)
  64.                 {
  65.                         InputDevice dev = InputManager.ActiveDevice;
  66.  
  67.                         switch (key)
  68.                         {
  69.                                 case KeyCode.JoystickButton0: return dev.GetControl(InputControlType.Action1).WasReleased;
  70.                                 case KeyCode.JoystickButton1: return dev.GetControl(InputControlType.Action2).WasReleased;
  71.                                 case KeyCode.JoystickButton2: return dev.GetControl(InputControlType.Action3).WasReleased;
  72.                                 case KeyCode.JoystickButton3: return dev.GetControl(InputControlType.Action4).WasReleased;
  73.                                 case KeyCode.JoystickButton4: return dev.GetControl(InputControlType.LeftBumper).WasReleased;
  74.                                 case KeyCode.JoystickButton5: return dev.GetControl(InputControlType.RightBumper).WasReleased;
  75.                                 case KeyCode.JoystickButton6: return dev.GetControl(InputControlType.Back).WasReleased;
  76.                                 case KeyCode.JoystickButton7: return dev.GetControl(InputControlType.Start).WasReleased;
  77.                                 case KeyCode.JoystickButton8: return dev.GetControl(InputControlType.LeftStickButton).WasReleased;
  78.                                 case KeyCode.JoystickButton9: return dev.GetControl(InputControlType.RightStickButton).WasReleased;
  79.                         }
  80.                 }
  81.                 return Input.GetKeyUp(key);
  82.         }
  83.  
  84.         static float GetAxis (string name)
  85.         {
  86.                 InputDevice dev = InputManager.ActiveDevice;
  87.  
  88.                 switch (name)
  89.                 {
  90.                         case "LX": return dev.LeftStickX; // Match UICamera.horizontalAxisName
  91.                         case "LY": return dev.LeftStickY; // Match UICamera.verticalAxisName
  92.                         case "RX": return dev.RightStickX; // Match UICamera.horizontalPanAxisName
  93.                         case "RY": return dev.RightStickY; // Match UICamera.verticalPanAxisName
  94.                         case "DX": return dev.DPadX;
  95.                         case "DY": return dev.DPadY;
  96.                         case "TX": return dev.RightTrigger - dev.LeftTrigger;
  97.                 }
  98.                 return Input.GetAxis(name);
  99.         }
  100. }
  101.  
Keep in mind it's easier if you started with InControl to begin with, but if you didn't (like me) and instead used XBox controller mappings, then you'll need to do what I did above. Everywhere I need to poll an axis in the code I use UICamera.GetAxis rather than Input.GetAxis.

hellobard

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: InControl + NGUI
« Reply #1 on: August 05, 2015, 06:30:13 AM »
Thanks for posting this setup, it works very well with InControl.
I was just wondering, I can select menu items with the analogue stick but I can't seem to get the D-Pad to do the same (using a 360 controller on a Mac). The D-Pad works fine during gameplay, so I guess I just have to make NGUI read it.  Is there something I can do to modify this script to make it work?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: InControl + NGUI
« Reply #2 on: August 05, 2015, 07:36:25 AM »
Check the end of the script I posted, the GetAxis function. If you want your D-Pad to behave like your thumbstick, you will need to modify that function.

hellobard

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: InControl + NGUI
« Reply #3 on: August 05, 2015, 08:04:58 AM »
Check the end of the script I posted, the GetAxis function. If you want your D-Pad to behave like your thumbstick, you will need to modify that function.

Thanks for the quick reply!
At the risk of sounding like a total programming newbie, but how exactly would it be modified?
I see there are references to the Dpad in that section, but I don't quite understand how to connect with how the analog is controlling the UICamera.GetAxis.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: InControl + NGUI
« Reply #4 on: August 05, 2015, 09:26:44 AM »
Change
  1.            case "LX": return dev.LeftStickX; // Match UICamera.horizontalAxisName
  2.             case "LY": return dev.LeftStickY; // Match UICamera.verticalAxisName
to
  1.            case "LX": return dev.LeftStickX + dev.DPadX; // Match UICamera.horizontalAxisName
  2.             case "LY": return dev.LeftStickY + dev.DPadY; // Match UICamera.verticalAxisName

hellobard

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: InControl + NGUI
« Reply #5 on: August 05, 2015, 03:35:54 PM »
Wonderful, thank you very much for taking the time to write the code!

hellobard

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: InControl + NGUI
« Reply #6 on: August 06, 2015, 01:43:08 AM »
I just tested this with my UI and it doesn't seem to work with a 360 controller at least, just the left analogue stick working.
Have you tested this on your setup, ArenMook?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: InControl + NGUI
« Reply #7 on: August 08, 2015, 11:23:30 PM »
Yes, the code I pasted works as-is in Windward. With the lines replaced either the left thumbstick or the D-Pad control UI navigation. Just make sure your UICamera is set to use "LX" and "LY" as the Navigation axes. It's set to "Horizontal" and "Vertical" by default,  but that's not what the script I pasted uses. Alternatively you can change "LX" and "LY" to be "Horizontal" and "Vertical" in the script.

hellobard

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: InControl + NGUI
« Reply #8 on: August 09, 2015, 01:56:25 AM »
Ah of course, now I understand how the script works.
Wonderful, thanks for taking the time to explain it further.

vivalavida

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: InControl + NGUI
« Reply #9 on: October 22, 2015, 06:57:34 AM »
Hi Aren,
I'm starting out on a new project.
What would be the best way to setup NGUI to work with Rewired, completely bypassing Unity's Input System.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: InControl + NGUI
« Reply #10 on: October 24, 2015, 04:34:28 AM »
I haven't used Rewired, so I can't answer that.

vivalavida

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: InControl + NGUI
« Reply #11 on: October 24, 2015, 05:54:09 AM »
Hi Aren,
Even in the case of InControl, how would a remapping of keys be handled,
In the example script that you posted above,
You check which Unity Input Keycode has been pressed, and then send the corresponding button value from InControl via the switch-case.
Now if suppose Action1 initially corresponds to 'A' button on the joystick, but if I go and reassign the Action1 to button 'B', then  I'll have to go back to the script or UICamera and make changes.
(correct me if I'm wrong)

Any way to avoid this?
Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: InControl + NGUI
« Reply #12 on: October 27, 2015, 12:19:08 AM »
I do key bindings through a custom script in Windward that extends the UIKeyBinding script. Key bindings are stored in the player file, player file is sync'd and saved with TNet. On start up the game key binding script restores the key binding, and has logic in it for rebinding it. I'm attaching the script I wrote in case you need an example.
  1. using UnityEngine;
  2. using TNet;
  3. using System.Collections;
  4.  
  5. public class UIGameKeyBinding : UIKeyBinding
  6. {
  7.         static public UIGameKeyBinding rebind;
  8.         static KeyCode cancelKey = KeyCode.None;
  9.  
  10.         /// <summary>
  11.         /// Optional caption showing the key.
  12.         /// </summary>
  13.  
  14.         public UILabel caption;
  15.  
  16.         /// <summary>
  17.         /// Optional name of the key binding, such as "Volley".
  18.         /// </summary>
  19.  
  20.         [System.NonSerialized] public string visibleName;
  21.  
  22.         public string regularBinding;
  23.         public string controllerBinding;
  24.  
  25.         [System.NonSerialized] UISkillIcon mIcon;
  26.         [System.NonSerialized] bool mLoaded = false;
  27.         [System.NonSerialized] KeyCode mKey0 = KeyCode.None;
  28.         [System.NonSerialized] KeyCode mKey1 = KeyCode.None;
  29.         [System.NonSerialized] int mStartFrame = 0;
  30.  
  31.         public delegate void OnChange();
  32.         public OnChange onChange;
  33.  
  34.         /// <summary>
  35.         /// Key used for the binding, such as "SkillVolley"
  36.         /// </summary>
  37.  
  38.         public string bindingName
  39.         {
  40.                 set
  41.                 {
  42.                         regularBinding = value;
  43.                         controllerBinding = value + " Controller";
  44.                 }
  45.         }
  46.  
  47.         /// <summary>
  48.         /// Active binding, letting you have different key binds depending on the control method.
  49.         /// </summary>
  50.  
  51.         string activeBindingName
  52.         {
  53.                 get
  54.                 {
  55.                         return (UICamera.currentScheme != UICamera.ControlScheme.Controller || string.IsNullOrEmpty(controllerBinding)) ?
  56.                                 regularBinding : controllerBinding;
  57.                 }
  58.         }
  59.  
  60.         /// <summary>
  61.         /// Key binding associated with this skill.
  62.         /// </summary>
  63.  
  64.         public KeyCode savedKeyBinding
  65.         {
  66.                 get
  67.                 {
  68.                         if (!mLoaded)
  69.                         {
  70.                                 mLoaded = true;
  71.                                 UpdateKeyBindings();
  72.                         }
  73.                         return (UICamera.currentScheme != UICamera.ControlScheme.Controller) ? mKey0 : mKey1;
  74.                 }
  75.                 set
  76.                 {
  77.                         if (!mLoaded)
  78.                         {
  79.                                 mLoaded = true;
  80.                                 UpdateKeyBindings();
  81.                         }
  82.  
  83.                         if (value == KeyCode.None)
  84.                         {
  85.                                 DataNode node = TNManager.playerDataNode.GetChild("Keybindings", false);
  86.                                 if (node != null) node.RemoveChild(activeBindingName);
  87.                         }
  88.                         else
  89.                         {
  90.                                 DataNode node = TNManager.playerDataNode.GetChild("Keybindings", true);
  91.                                 node.SetChild(activeBindingName, value.ToString());
  92.                         }
  93.  
  94.                         Cache();
  95.                         MyPlayer.syncNeeded = true;
  96.                         MyPlayer.saveNeeded = true;
  97.                         UpdateSelf();
  98.                 }
  99.         }
  100.  
  101.         /// <summary>
  102.         /// Automatically load the key bindings.
  103.         /// </summary>
  104.  
  105.         protected override void Start ()
  106.         {
  107.                 base.Start();
  108.                 mIcon = GetComponent<UISkillIcon>();
  109.  
  110.                 if (!mLoaded)
  111.                 {
  112.                         mLoaded = true;
  113.                         UpdateKeyBindings();
  114.                 }
  115.         }
  116.  
  117.         /// <summary>
  118.         /// Update the skill's keybindings.
  119.         /// </summary>
  120.  
  121.         public void UpdateKeyBindings ()
  122.         {
  123.                 mKey0 = KeyCode.None;
  124.                 mKey1 = KeyCode.None;
  125.  
  126.                 DataNode node = TNManager.playerDataNode.GetChild("Keybindings", false);
  127.  
  128.                 if (node == null)
  129.                 {
  130.                         node = TNManager.playerDataNode.GetChild("Keybindings", true);
  131.                         node.AddMissingChild("SkillRepair", "R");
  132.                         node.AddMissingChild("SkillNormalVolley", "V");
  133.                         node.AddMissingChild("SkillAimedVolley", "V");
  134.                         node.AddMissingChild("SkillRecklessVolley", "V");
  135.                         node.AddMissingChild("SkillHaste", "H");
  136.                         node.AddMissingChild("SkillChainShot", "C");
  137.                         node.AddMissingChild("SkillInferno", "Q");
  138.                         node.AddMissingChild("SkillPoison", "E");
  139.                         node.AddMissingChild("SkillFog", "F");
  140.                         node.AddMissingChild("SkillDeflect", "G");
  141.                         node.AddMissingChild("SkillImprove", "B");
  142.                         MyPlayer.saveNeeded = true;
  143.                 }
  144.  
  145.                 // Auto-upgrade
  146.                 if (node.GetChild("Map") == null)
  147.                 {
  148.                         node.AddMissingChild("Map", "M");
  149.                         node.AddMissingChild("Inventory", "I");
  150.                         node.AddMissingChild("Talents", "K");
  151.                         node.AddMissingChild("Fast Travel", "T");
  152.                         node.AddMissingChild("Players", "Tab");
  153.                         MyPlayer.saveNeeded = true;
  154.                 }
  155.  
  156.                 // Controller binds
  157.                 if (node.GetChild("SkillRepair Controller") == null)
  158.                 {
  159.                         node.AddMissingChild("SkillRepair Controller", "JoystickButton0");
  160.                         node.AddMissingChild("SkillNormalVolley Controller", "JoystickButton1");
  161.                         node.AddMissingChild("SkillAimedVolley Controller", "JoystickButton1");
  162.                         node.AddMissingChild("SkillRecklessVolley Controller", "JoystickButton1");
  163.                         node.AddMissingChild("SkillInferno Controller", "JoystickButton2");
  164.                         node.AddMissingChild("SkillPoison Controller", "JoystickButton3");
  165.                         MyPlayer.saveNeeded = true;
  166.                 }
  167.  
  168.                 // Restore the key bindings
  169.                 if (node != null)
  170.                 {
  171.                         Cache();
  172.                         UpdateSelf();
  173.                 }
  174.         }
  175.  
  176.         void Cache ()
  177.         {
  178.                 DataNode node = TNManager.playerDataNode.GetChild("Keybindings", false);
  179.  
  180.                 if (node != null)
  181.                 {
  182.                         mKey0 = GetKeyCode(node, regularBinding);
  183.                         mKey1 = !string.IsNullOrEmpty(controllerBinding) ? GetKeyCode(node, controllerBinding) : mKey0;
  184.                 }
  185.         }
  186.  
  187.         static KeyCode GetKeyCode (DataNode node, string bindingName)
  188.         {
  189.                 node = node.GetChild(bindingName);
  190.  
  191.                 if (node != null && node.value is string)
  192.                 {
  193.                         try { return (KeyCode)System.Enum.Parse(typeof(KeyCode), (string)node.value); }
  194.                         catch (System.Exception) { }
  195.                 }
  196.                 return KeyCode.None;
  197.         }
  198.  
  199.         protected override void OnEnable () { base.OnEnable(); UICamera.onSchemeChange += UpdateSelf; }
  200.         protected override void OnDisable () { base.OnDisable(); UICamera.onSchemeChange -= UpdateSelf; }
  201.  
  202.         /// <summary>
  203.         /// Update the caption and the bound key code.
  204.         /// </summary>
  205.  
  206.         void UpdateSelf ()
  207.         {
  208.                 KeyCode saved = savedKeyBinding;
  209.  
  210.                 // Skill bar will have a skill selected when editing the layout
  211.                 if (UISkillBar.isEditing && UICamera.currentScheme == UICamera.ControlScheme.Controller)
  212.                 {
  213.                         keyCode = KeyCode.None;
  214.  
  215.                         if (saved != KeyCode.None)
  216.                         {
  217.                                 if (caption != null)
  218.                                 {
  219.                                         caption.text = NGUITools.KeyToCaption(saved);
  220.                                         caption.color = new Color(0.35f, 0.35f, 0.35f);
  221.                                         caption.symbolStyle = NGUIText.SymbolStyle.Colored;
  222.                                 }
  223.                         }
  224.                         else if (caption != null) caption.text = "";
  225.                 }
  226.                 else if (saved != KeyCode.None)
  227.                 {
  228.                         keyCode = KeyCode.None;
  229.                         StartCoroutine(DelayedKeyChange(saved));
  230.  
  231.                         if (caption != null)
  232.                         {
  233.                                 caption.text = NGUITools.KeyToCaption(saved);
  234.                                 caption.color = Color.white;
  235.                                 caption.symbolStyle = NGUIText.SymbolStyle.Normal;
  236.                         }
  237.                 }
  238.                 else
  239.                 {
  240.                         keyCode = KeyCode.None;
  241.                         if (caption != null) caption.text = "";
  242.                 }
  243.         }
  244.  
  245.         /// <summary>
  246.         /// Coroutine is used so that the key binding doesn't trigger in the same frame.
  247.         /// </summary>
  248.  
  249.         IEnumerator DelayedKeyChange (KeyCode key)
  250.         {
  251.                 yield return null;
  252.                 keyCode = key;
  253.         }
  254.  
  255.         /// <summary>
  256.         /// Cancel the rebinding operation.
  257.         /// </summary>
  258.  
  259.         void CancelRebind ()
  260.         {
  261.                 rebind = null;
  262.                 cancelKey = KeyCode.None;
  263.         }
  264.  
  265.         /// <summary>
  266.         /// Update the highlight and the cooldown timer.
  267.         /// </summary>
  268.  
  269.         protected override void Update ()
  270.         {
  271.                 if (rebind == this && cancelKey != KeyCode.None)
  272.                 {
  273.                         if (UICamera.GetKeyUp(cancelKey))
  274.                         {
  275.                                 Invoke("CancelRebind", 0.001f);
  276.                                 return;
  277.                         }
  278.                 }
  279.  
  280.                 if (rebind == this && mStartFrame != Time.frameCount && Input.anyKeyDown)
  281.                 {
  282.                         string s = visibleName ?? Localization.Get(regularBinding);
  283.  
  284.                         if (UICamera.GetKeyDown(KeyCode.Escape) ||
  285.                                 UICamera.GetKeyDown(KeyCode.Mouse1) ||
  286.                                 UICamera.GetKeyDown(KeyCode.JoystickButton4) ||
  287.                                 UICamera.GetKeyDown(KeyCode.JoystickButton5))
  288.                         {
  289.                                 rebind = null;
  290.                                 savedKeyBinding = KeyCode.None;
  291.                                 if (onChange != null) onChange();
  292.                                 string text = Localization.Format("Key Binding Cleared", "[ffcc00]" + s + "[-]");
  293.                                 UIStatusBar.Show(text, 2f);
  294.                         }
  295.                         else if (!UICamera.GetKeyDown(KeyCode.Mouse0))
  296.                         {
  297.                                 for (int i = 0, imax = NGUITools.keys.Length; i < imax; ++i)
  298.                                 {
  299.                                         KeyCode key = NGUITools.keys[i];
  300.  
  301.                                         if (UICamera.GetKeyDown(key))
  302.                                         {
  303.                                                 savedKeyBinding = key;
  304.                                                 if (onChange != null) onChange();
  305.                                                 string text = Localization.Format("Key Binding Set",
  306.                                                         "[ffcc00]" + NGUITools.KeyToCaption(key) + "[-]",
  307.                                                         "[ffcc00]" + s + "[-]");
  308.                                                 UIStatusBar.Show(text, 2f);
  309.                                                 cancelKey = key;
  310.                                                 break;
  311.                                         }
  312.                                 }
  313.                         }
  314.                 }
  315.                 else if (!UICamera.inputHasFocus && (UICamera.disableController || keyCode < KeyCode.JoystickButton0) && !UISkillBar.isEditing)
  316.                         base.Update();
  317.         }
  318.  
  319.  
  320.  
  321.         /// <summary>
  322.         /// Releasing the controller button should activate the skill.
  323.         /// </summary>
  324.  
  325.         protected override void OnBindingPress (bool isPressed)
  326.         {
  327.                 UIProTip.Show(33);
  328.                 base.OnBindingPress(isPressed);
  329.         }
  330.  
  331.         /// <summary>
  332.         /// Right-click rebind option.
  333.         /// </summary>
  334.  
  335.         void OnClick ()
  336.         {
  337.                 if (UICamera.currentTouchID == -2 && mIcon == null)
  338.                 {
  339.                         NGUITools.PlaySound(GameAudio.instance.tap);
  340.                         ShowRebindOption();
  341.                 }
  342.         }
  343.  
  344.         /// <summary>
  345.         /// Show a simple "Rebind" popup list option.
  346.         /// </summary>
  347.  
  348.         public void ShowRebindOption ()
  349.         {
  350.                 UIPopupList popup = UIGameWindow.popupList;
  351.  
  352.                 if (popup != null)
  353.                 {
  354.                         popup.Clear();
  355.                         popup.AddItem(Localization.Get("Key Binding"), "Rebind");
  356.                         EventDelegate.Set(popup.onChange, OnPopupItem);
  357.                         popup.Show();
  358.                 }
  359.         }
  360.  
  361.         /// <summary>
  362.         /// Change options on popup selection.
  363.         /// </summary>
  364.  
  365.         void OnPopupItem ()
  366.         {
  367.                 string data = UIPopupList.current.data as string;
  368.                 if (data == "Rebind") Rebind();
  369.                 UICamera.selectedObject = null;
  370.         }
  371.  
  372.         /// <summary>
  373.         /// Start the rebinding process.
  374.         /// </summary>
  375.  
  376.         public void Rebind ()
  377.         {
  378.                 UIProTip.Hide(33);
  379.                 rebind = this;
  380.                 mStartFrame = Time.frameCount;
  381.                 string s = visibleName ?? regularBinding;
  382.                 UIStatusBar.Show(Localization.Format("Key Binding Info", "[ffcc00]" + s + "[-]"));
  383.         }
  384. }
  385.