controlmappingkeybinds.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. class TutorialKeybinds extends ScriptedWidgetEventHandler
  2. {
  3. protected Widget m_Root;
  4. protected Widget m_DetailsRoot;
  5. protected TutorialsMenu m_Menu;
  6. void TutorialKeybinds(Widget parent, TutorialsMenu menu)
  7. {
  8. m_Root = GetGame().GetWorkspace().CreateWidgets(GetLayoutName(), parent);
  9. m_Menu = menu;
  10. int actionCount;
  11. int actionMax = 80;
  12. int column_index = 0;
  13. int item_index;
  14. string output = "";
  15. string option_text = "";
  16. TIntArray actions = new TIntArray;
  17. GetUApi().GetActiveInputs(actions);
  18. actionCount = actions.Count();
  19. for (int i = 0; i < actionCount; i++)
  20. {
  21. UAInput input = GetUApi().GetInputByID(actions.Get(i));
  22. if (input)
  23. {
  24. if (item_index < actionMax)
  25. {
  26. output = "";
  27. option_text = "";
  28. GetGame().GetInput().GetActionDesc(actions.Get(i), option_text);
  29. if (SetElementTitle(input, EUAINPUT_DEVICE_KEYBOARDMOUSE, output))
  30. {
  31. column_index = Math.Floor(item_index / 21);
  32. Widget w = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/tutorials/xbox/keybindings_panels/keybinding_panel.layout", m_Root.FindAnyWidget("container" + column_index));
  33. Widget spacer = w.FindWidget("Spacer");
  34. TextWidget name = TextWidget.Cast(w.FindWidget("KeybindName"));
  35. TextWidget mod = TextWidget.Cast(spacer.FindWidget("KeybindModifier"));
  36. TextWidget value = TextWidget.Cast(spacer.FindWidget("KeybindButton"));
  37. string modifier_text = "";
  38. name.SetText(option_text);
  39. value.SetText(output);
  40. if (SetElementModifier(input, modifier_text))
  41. {
  42. mod.SetText(modifier_text);
  43. }
  44. name.Update();
  45. mod.Update();
  46. value.Update();
  47. spacer.Update();
  48. item_index++;
  49. }
  50. }
  51. else
  52. {
  53. option_text = "";
  54. GetGame().GetInput().GetActionDesc(actions[i], option_text);
  55. ErrorEx("input action " + option_text + " index out of bounds!",ErrorExSeverity.INFO);
  56. }
  57. }
  58. }
  59. m_Root.SetHandler(this);
  60. }
  61. //! assemble all active bindings at widget element
  62. bool SetElementTitle(UAInput pInput, int iDeviceFlags, out string output)
  63. {
  64. int a, i, countbind = 0;
  65. for (a = 0; a < pInput.AlternativeCount(); a++)
  66. {
  67. pInput.SelectAlternative(a);
  68. if (pInput.IsCombo())
  69. {
  70. if (pInput.BindingCount() > 0)
  71. {
  72. if (pInput.Binding(0) != 0 && pInput.CheckBindDevice(0,iDeviceFlags))
  73. {
  74. if (countbind > 0)
  75. output += ", ";
  76. output += GetUApi().GetButtonName(pInput.Binding(0));
  77. countbind++;
  78. for (i = 1; i < pInput.BindingCount(); i++)
  79. {
  80. if (pInput.Binding(i) != 0)
  81. {
  82. output += " + " + GetUApi().GetButtonName(pInput.Binding(i));
  83. countbind++;
  84. }
  85. }
  86. }
  87. }
  88. }
  89. else
  90. {
  91. if (pInput.BindingCount() > 0)
  92. {
  93. if (pInput.Binding(0) != 0 && pInput.CheckBindDevice(0,iDeviceFlags))
  94. {
  95. if (countbind > 0)
  96. output += ", ";
  97. output += GetUApi().GetButtonName(pInput.Binding(0));
  98. countbind++;
  99. }
  100. }
  101. }
  102. }
  103. return (countbind > 0);
  104. }
  105. //! Determine the active limiter of the bindings (currently unreliable, multiple limiters can be active on key combos!)
  106. bool SetElementModifier(UAInput pInput, out string output)
  107. {
  108. if (pInput.IsLimited())
  109. {
  110. if (pInput.IsPressLimit())
  111. {
  112. output = "#keybind_press";
  113. }
  114. if (pInput.IsReleaseLimit())
  115. {
  116. output = "#keybind_release";
  117. }
  118. if (pInput.IsHoldLimit())
  119. {
  120. output = "#keybind_hold";
  121. }
  122. if (pInput.IsHoldBeginLimit())
  123. {
  124. output = "#keybind_holdbegin";
  125. }
  126. if (pInput.IsClickLimit())
  127. {
  128. output = "#keybind_click";
  129. }
  130. if (pInput.IsDoubleClickLimit())
  131. {
  132. output = "#keybind_doubletap";
  133. }
  134. return true;
  135. }
  136. else
  137. {
  138. return false;
  139. }
  140. }
  141. void ~TutorialKeybinds()
  142. {
  143. }
  144. string GetLayoutName()
  145. {
  146. return "gui/layouts/new_ui/tutorials/xbox/keybinds_tab.layout";
  147. }
  148. }