controlsxbox.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. /*
  2. DEPRECATED CONTENT
  3. */
  4. class JsonControlMappingInfo
  5. {
  6. int m_TabID;
  7. int m_TextWidgetID;
  8. string m_ButtonName;
  9. string m_InfoText;
  10. }
  11. class ControlsXbox extends UIScriptedMenu
  12. {
  13. protected string m_BackButtonTextID;
  14. protected ButtonWidget m_Back;
  15. protected ImageWidget m_ControlsLayoutImage;
  16. protected const int TABS_COUNT = 4;
  17. protected ImageWidget m_tab_images[TABS_COUNT];
  18. protected TabberUI m_TabScript;
  19. //============================================
  20. // ControlsXbox
  21. //============================================
  22. void ControlsXbox()
  23. {
  24. }
  25. void ~ControlsXbox()
  26. {
  27. PPERequesterBank.GetRequester(PPERequester_ControlsBlur).Stop();
  28. }
  29. void Back()
  30. {
  31. GetGame().GetUIManager().Back();
  32. }
  33. void DrawConnectingLines(int index)
  34. {
  35. ref array<ref JsonControlMappingInfo> control_mapping_info = new array<ref JsonControlMappingInfo>;
  36. ref array<ref array <ref JsonControlMappingInfo>> tab_array = new array<ref array <ref JsonControlMappingInfo>>;
  37. map<string, ref array<int>> button_marker_groups_unflitred = new map<string, ref array<int>>;
  38. map<string, ref array<int>> button_marker_groups = new map<string, ref array<int>>;
  39. float text_widget_pos_x, text_widget_pos_y;
  40. float text_widget_width, text_widget_height;
  41. float dot_pos_x, dot_pos_y;
  42. float dot_width, dot_height;
  43. float draw_pos_x, draw_pos_y;
  44. CanvasWidget canvas_widget = CanvasWidget.Cast(layoutRoot.FindAnyWidget("CanvasWidget_" + index));
  45. canvas_widget.Clear();
  46. control_mapping_info = GetControlMappingInfo();
  47. for (int i = 0; i < m_TabScript.GetTabCount(); i++)
  48. {
  49. tab_array.Insert(new array<ref JsonControlMappingInfo>);
  50. for (int j = 0; j < 20; j++)
  51. {
  52. tab_array[i].Insert(null);
  53. }
  54. }
  55. // insert json info to array by index, so it is sorted
  56. for (i = 0; i < control_mapping_info.Count(); i++)
  57. {
  58. JsonControlMappingInfo info = control_mapping_info.Get(i);
  59. tab_array[info.m_TabID][info.m_TextWidgetID] = info;
  60. }
  61. // create group of buttons which are connected together with line
  62. for (int l = 0; l < control_mapping_info.Count(); l++)
  63. {
  64. JsonControlMappingInfo info1 = control_mapping_info[l];
  65. string button_name = info1.m_ButtonName;
  66. int text_widget_id = info1.m_TextWidgetID;
  67. if (info1.m_TabID != index)
  68. {
  69. continue;
  70. }
  71. if (!button_marker_groups_unflitred.Contains(button_name))
  72. {
  73. button_marker_groups_unflitred.Insert(button_name, new ref array<int>);
  74. button_marker_groups_unflitred.Get(button_name).Insert(text_widget_id);
  75. }
  76. else
  77. {
  78. button_marker_groups_unflitred.Get(button_name).Insert(text_widget_id);
  79. }
  80. }
  81. // we want groups which are bigger than 1
  82. for (l = 0; l < button_marker_groups_unflitred.Count(); l++)
  83. {
  84. if (button_marker_groups_unflitred.GetElement(l).Count() > 1)
  85. {
  86. string key = button_marker_groups_unflitred.GetKey(l);
  87. button_marker_groups.Insert(button_marker_groups_unflitred.GetKey(l), button_marker_groups_unflitred.Get(key));
  88. }
  89. }
  90. Widget controls_image;
  91. // hide all button markers
  92. #ifdef PLATFORM_XBOX
  93. controls_image = layoutRoot.FindAnyWidget("XboxControlsImage");
  94. #else
  95. #ifdef PLATFORM_PS4
  96. controls_image = layoutRoot.FindAnyWidget("PSControlsImage");
  97. #endif
  98. #endif
  99. Widget child = controls_image.GetChildren();
  100. child.Show(false);
  101. while (child.GetSibling())
  102. {
  103. child = child.GetSibling();
  104. child.Show(false);
  105. }
  106. Widget panel_widget;
  107. Widget button_marker_widget;
  108. for (l = 0; l < tab_array[index].Count(); l++)
  109. {
  110. panel_widget = layoutRoot.FindAnyWidget("PanelWidget" + l);
  111. if (tab_array[index][l] != null)
  112. {
  113. TextWidget text_widget = TextWidget.Cast(panel_widget.FindAnyWidget("TextWidget" + l));
  114. string key_prefix;
  115. #ifdef PLATFORM_XBOX
  116. key_prefix = "xb_button_marker_";
  117. #else
  118. #ifdef PLATFORM_PS4
  119. key_prefix = "ps_button_marker_";
  120. #endif
  121. #endif
  122. button_marker_widget = layoutRoot.FindAnyWidget(key_prefix + tab_array[index][l].m_ButtonName);
  123. text_widget.SetText(tab_array[index][l].m_InfoText);
  124. panel_widget.Show(true);
  125. button_marker_widget.Show(true);
  126. panel_widget.Update();
  127. if (!button_marker_groups.Contains(tab_array[index][l].m_ButtonName))
  128. {
  129. panel_widget.GetScreenPos(text_widget_pos_x, text_widget_pos_y);
  130. panel_widget.GetScreenSize(text_widget_width,text_widget_height);
  131. button_marker_widget.GetScreenPos(dot_pos_x, dot_pos_y);
  132. button_marker_widget.GetScreenSize(dot_width, dot_height);
  133. draw_pos_y = text_widget_pos_y + text_widget_height / 2;
  134. if (l < 10)
  135. {
  136. draw_pos_x = text_widget_pos_x + text_widget_width - 1;
  137. }
  138. else
  139. {
  140. draw_pos_x = text_widget_pos_x;
  141. }
  142. canvas_widget.DrawLine(draw_pos_x, draw_pos_y, dot_pos_x+dot_width/2, draw_pos_y, 2, ARGBF(0.6, 1, 1, 1));
  143. canvas_widget.DrawLine(dot_pos_x+dot_width/2, draw_pos_y, dot_pos_x+dot_width/2, dot_pos_y+dot_height/2, 2, ARGBF(0.6, 1, 1, 1));
  144. }
  145. }
  146. else
  147. {
  148. panel_widget.Show(false);
  149. }
  150. panel_widget.Update();
  151. }
  152. // draw connecting lines
  153. for (l = 0; l < button_marker_groups.Count(); l++)
  154. {
  155. text_widget_pos_x = 0;
  156. text_widget_pos_y = 0;
  157. text_widget_width = 0;
  158. text_widget_height = 0;
  159. float group_point_x = 0, group_point_y = 0;
  160. float first_x = 0, first_y = 0;
  161. ref array<int> element = button_marker_groups.GetElement(l);
  162. string key_name = button_marker_groups.GetKey(l);
  163. #ifdef PLATFORM_XBOX
  164. key_prefix = "xb_button_marker_";
  165. #else
  166. #ifdef PLATFORM_PS4
  167. key_prefix = "ps_button_marker_";
  168. #endif
  169. #endif
  170. button_marker_widget = layoutRoot.FindAnyWidget(key_prefix + key_name);
  171. for (int g = 0; g < element.Count(); g++)
  172. {
  173. panel_widget = layoutRoot.FindAnyWidget("PanelWidget" + element[g]);
  174. panel_widget.GetScreenPos(text_widget_pos_x, text_widget_pos_y);
  175. panel_widget.GetScreenSize(text_widget_width, text_widget_height);
  176. if (g == 0)
  177. {
  178. if (element[0] < 10)
  179. {
  180. first_x = text_widget_pos_x + text_widget_width +50;
  181. }
  182. else
  183. {
  184. first_x = text_widget_pos_x - 50;
  185. }
  186. first_y = text_widget_pos_y + text_widget_height/2;
  187. }
  188. group_point_x += text_widget_pos_x;
  189. group_point_y += text_widget_pos_y;
  190. if (element[0] < 10)
  191. {
  192. canvas_widget.DrawLine(text_widget_pos_x + text_widget_width - 1, text_widget_pos_y + text_widget_height/2, text_widget_pos_x + text_widget_width +50, text_widget_pos_y + text_widget_height/2, 2, ARGBF(0.6, 1, 1, 1));
  193. }
  194. else
  195. {
  196. canvas_widget.DrawLine(text_widget_pos_x, text_widget_pos_y + text_widget_height/2, text_widget_pos_x - 50, text_widget_pos_y + text_widget_height/2, 2, ARGBF(0.6, 1, 1, 1));
  197. }
  198. }
  199. if (element[0] < 10)
  200. {
  201. group_point_x = group_point_x/element.Count() + text_widget_width + 50;
  202. }
  203. else
  204. {
  205. group_point_x = group_point_x/element.Count() - 50;
  206. }
  207. if (element.Count() % 2 == 0)
  208. {
  209. group_point_y = ((text_widget_pos_y + text_widget_height/2) - first_y) / 2 + first_y;
  210. }
  211. else
  212. {
  213. float text_widget_pos_x_center, text_widget_pos_y_center;
  214. float text_widget_width_center, text_widget_height_center;
  215. panel_widget = layoutRoot.FindAnyWidget("PanelWidget" + element[1]);
  216. panel_widget.GetScreenPos(text_widget_pos_x_center, text_widget_pos_y_center);
  217. panel_widget.GetScreenSize(text_widget_width_center, text_widget_height_center);
  218. group_point_y = text_widget_pos_y_center + text_widget_height_center / 2;
  219. }
  220. button_marker_widget.GetScreenPos(dot_pos_x, dot_pos_y);
  221. button_marker_widget.GetScreenSize(dot_width, dot_height);
  222. canvas_widget.DrawLine(group_point_x, group_point_y, dot_pos_x+dot_width/2, group_point_y, 2, ARGBF(0.6, 1, 1, 1));
  223. canvas_widget.DrawLine(dot_pos_x+dot_width/2, group_point_y, dot_pos_x+dot_width/2, dot_pos_y, 2, ARGBF(0.6, 1, 1, 1));
  224. if (element[0] < 10)
  225. {
  226. canvas_widget.DrawLine(first_x, first_y, text_widget_pos_x + text_widget_width +50, text_widget_pos_y + text_widget_height/2, 2, ARGBF(0.6, 1, 1, 1));
  227. }
  228. else
  229. {
  230. canvas_widget.DrawLine(first_x, first_y, text_widget_pos_x - 50, text_widget_pos_y + text_widget_height/2, 2, ARGBF(0.6, 1, 1, 1));
  231. }
  232. }
  233. }
  234. protected array<ref JsonControlMappingInfo> GetControlMappingInfo()
  235. {
  236. array<ref JsonControlMappingInfo> control_mapping_info = new array<ref JsonControlMappingInfo>;
  237. string file_path = "xbox/pagedatacontroller.json";
  238. #ifdef PLATFORM_PS4
  239. file_path = "ps4/pagedatacontroller.json";
  240. #endif
  241. FileHandle file_handle = OpenFile(file_path, FileMode.READ);
  242. JsonSerializer js = new JsonSerializer();
  243. string js_error = "";
  244. string line_content = "";
  245. string content = "";
  246. if (file_handle)
  247. {
  248. while (FGets(file_handle, line_content) >= 0)
  249. {
  250. content += line_content;
  251. }
  252. CloseFile(file_handle);
  253. if (js.ReadFromString(control_mapping_info, content, js_error))
  254. {
  255. return control_mapping_info;
  256. }
  257. else
  258. {
  259. ErrorEx("JSON ERROR => [ControlMappingInfo.json]: "+ js_error,ErrorExSeverity.INFO);
  260. }
  261. }
  262. return control_mapping_info;
  263. }
  264. //============================================
  265. // Init
  266. //============================================
  267. override Widget Init()
  268. {
  269. layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/xbox/control_mapping_info_screen.layout");
  270. layoutRoot.FindAnyWidget("Tabber").GetScript(m_TabScript);
  271. m_TabScript.m_OnTabSwitch.Insert(DrawConnectingLines);
  272. m_Back = ButtonWidget.Cast(layoutRoot.FindAnyWidget("back"));
  273. #ifdef PLATFORM_CONSOLE
  274. RichTextWidget toolbar_switch = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ChangePresetIcon"));
  275. RichTextWidget toolbar_back = RichTextWidget.Cast(layoutRoot.FindAnyWidget("BackIcon"));
  276. toolbar_switch.SetText(InputUtils.GetRichtextButtonIconFromInputAction("UASwitchPreset", "", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  277. toolbar_back.SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUIBack", "", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  278. #endif
  279. #ifdef PLATFORM_XBOX
  280. layoutRoot.FindAnyWidget("XboxControlsImage").Show(true);
  281. #else
  282. #ifdef PLATFORM_PS4
  283. layoutRoot.FindAnyWidget("PSControlsImage").Show(true);
  284. #endif
  285. #endif
  286. m_tab_images[0] = ImageWidget.Cast(layoutRoot.FindAnyWidget("MovementTabBackdropImageWidget"));
  287. m_tab_images[1] = ImageWidget.Cast(layoutRoot.FindAnyWidget("WeaponsAndActionsBackdropImageWidget"));
  288. m_tab_images[2] = ImageWidget.Cast(layoutRoot.FindAnyWidget("InventoryTabBackdropImageWidget"));
  289. m_tab_images[3] = ImageWidget.Cast(layoutRoot.FindAnyWidget("MenusTabBackdropImageWidget"));
  290. PPERequester_MenuEffects requester;
  291. Class.CastTo(requester,PPERequesterBank.GetRequester(PPERequesterBank.REQ_MENUEFFECTS));
  292. requester.SetVignetteIntensity(0.6);
  293. DrawConnectingLines(0);
  294. return layoutRoot;
  295. }
  296. override void OnShow()
  297. {
  298. super.OnShow();
  299. #ifdef PLATFORM_CONSOLE
  300. //layoutRoot.FindAnyWidget("toolbar_bg").Show(!GetGame().GetInput().IsEnabledMouseAndKeyboard());
  301. layoutRoot.FindAnyWidget("toolbar_bg").Show(true);//TODO: temporarily always on for preset switching
  302. string preset_text;
  303. UAInputAPI inputAPI = GetUApi();
  304. TextWidget nameWidget;
  305. if (Class.CastTo(nameWidget,layoutRoot.FindAnyWidget("PresetText")));
  306. {
  307. preset_text = inputAPI.PresetName(inputAPI.PresetCurrent());
  308. nameWidget.SetText(preset_text);
  309. }
  310. #endif
  311. }
  312. override bool OnClick(Widget w, int x, int y, int button)
  313. {
  314. if (button == MouseState.LEFT)
  315. {
  316. if (w == m_Back)
  317. {
  318. Back();
  319. return true;
  320. }
  321. }
  322. return false;
  323. }
  324. override void Update(float timeslice)
  325. {
  326. if (GetUApi().GetInputByID(UAUITabLeft).LocalPress())
  327. {
  328. m_TabScript.PreviousTab();
  329. }
  330. if (GetUApi().GetInputByID(UAUITabRight).LocalPress())
  331. {
  332. m_TabScript.NextTab();
  333. }
  334. if (GetUApi().GetInputByID(UAUIBack).LocalPress())
  335. {
  336. Back();
  337. }
  338. if (GetUApi().GetInputByID(UASwitchPreset).LocalPress())
  339. {
  340. SwitchPreset();
  341. }
  342. }
  343. /// Initial texts load for the footer buttons
  344. protected void LoadFooterButtonTexts()
  345. {
  346. TextWidget uiBackText = TextWidget.Cast(layoutRoot.FindAnyWidget("BackText"));
  347. if (uiBackText)
  348. {
  349. uiBackText.SetText(m_BackButtonTextID);
  350. }
  351. }
  352. /// Set correct bottom button texts based on platform (ps4 vs xbox texts)
  353. protected void LoadTextStrings()
  354. {
  355. #ifdef PLATFORM_PS4
  356. m_BackButtonTextID = "ps4_ingame_menu_back";
  357. #else
  358. m_BackButtonTextID = "STR_rootFrame_toolbar_bg_ConsoleToolbar_Back_BackText0";
  359. #endif
  360. }
  361. protected void SwitchPreset()
  362. {
  363. int index;
  364. string preset_text;
  365. UAInputAPI inputAPI = GetUApi();
  366. TextWidget nameWidget;
  367. index = inputAPI.PresetCurrent() + 1;
  368. if (index >= inputAPI.PresetCount())
  369. {
  370. index = 0;
  371. }
  372. inputAPI.PresetSelect(index);
  373. if (Class.CastTo(nameWidget,layoutRoot.FindAnyWidget("PresetText")));
  374. {
  375. preset_text = inputAPI.PresetName(inputAPI.PresetCurrent());
  376. nameWidget.SetText(preset_text);
  377. }
  378. GetGame().GetInput().SetProfile(index);
  379. GetUApi().Export();
  380. GetGame().GetMission().GetOnInputPresetChanged().Invoke();
  381. }
  382. }