inventory.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651
  1. #ifdef PLATFORM_CONSOLE
  2. enum ConsoleActionToolbarMask
  3. {
  4. EMPTY = 0,
  5. TO_HANDS_SWAP_VICINITY = 1,
  6. TO_HANDS_SWAP_INVENTORY = 2,
  7. DROP = 4,
  8. EQUIP = 8,
  9. SPLIT = 16,
  10. TO_INVENTORY = 32,
  11. OPEN_CLOSE_CONTAINER = 64,
  12. MICROMANAGMENT = 128,
  13. QUICKSLOT = 256,
  14. COMBINE = 512,
  15. }
  16. #endif
  17. enum Direction
  18. {
  19. RIGHT,
  20. LEFT,
  21. UP,
  22. DOWN
  23. }
  24. class Inventory: LayoutHolder
  25. {
  26. protected ref LeftArea m_LeftArea;
  27. protected ref RightArea m_RightArea;
  28. protected ref HandsArea m_HandsArea;
  29. protected ref PlayerPreview m_PlayerPreview;
  30. protected ref InventoryQuickbar m_Quickbar;
  31. protected Widget m_QuickbarWidget;
  32. protected Widget m_SpecializationPanel;
  33. protected Widget m_SpecializationIcon;
  34. protected Widget m_TopConsoleToolbarVicinity;
  35. protected Widget m_TopConsoleToolbarHands;
  36. protected Widget m_TopConsoleToolbarEquipment;
  37. protected Widget m_BottomConsoleToolbar;
  38. protected RichTextWidget m_BottomConsoleToolbarRichText;
  39. protected ref ContextMenu m_ContextMenu;
  40. protected static ref map<string, int> m_PlayerAttachmentsIndexes;
  41. protected bool m_HadFastTransferred;
  42. protected bool m_HadInspected;
  43. protected bool m_NeedUpdateConsoleToolbar;
  44. protected static Inventory m_Instance;
  45. protected int m_ControllerAngle;
  46. protected int m_ControllerTilt;
  47. protected bool m_ControllerRightStickTimerEnd = true;
  48. protected ref Timer m_ControllerRightStickTimer;
  49. protected bool m_HoldingQB;
  50. protected InventoryItem m_QBHoveredItems;
  51. ////////////////////
  52. const float BT_REPEAT_DELAY = 0.35; //delay from first press to begin tick repeat state
  53. const float BT_REPEAT_TIME = 0.09; //tick repeat frequency time
  54. const float BT_THRESHOLD_VALUE = 0.8; //threshold values for analog inputs
  55. const int INV_MOV_LEFT = 0;
  56. const int INV_MOV_RIGHT = 1;
  57. const int INV_MOV_UP = 2;
  58. const int INV_MOV_DOWN = 3;
  59. protected ref array<string> m_InvInputNames = {"UAUILeftInventory","UAUIRightInventory","UAUIUpInventory","UAUIDownInventory"};
  60. protected ref array<UAIDWrapper> m_InvInputWrappers;
  61. protected ref array<float> m_InvInputTimes;
  62. protected int m_InvInputWrappersCount;
  63. protected float m_SensitivityThreshold = 0.0;
  64. UAInput m_InvUAInput;
  65. int m_InvInputActive = 0;
  66. void Inventory(LayoutHolder parent)
  67. {
  68. m_Instance = this;
  69. LoadPlayerAttachmentIndexes();
  70. m_ControllerRightStickTimer = new Timer();
  71. new ItemManager(GetMainWidget());
  72. new ColorManager();
  73. m_LeftArea = new LeftArea(this);
  74. m_RightArea = new RightArea(this);
  75. m_HandsArea = new HandsArea(this);
  76. m_PlayerPreview = new PlayerPreview(this);
  77. m_QuickbarWidget = GetMainWidget().FindAnyWidget("QuickbarGrid");
  78. m_Quickbar = new InventoryQuickbar(m_QuickbarWidget);
  79. m_Quickbar.UpdateItems(m_QuickbarWidget);
  80. m_SpecializationPanel = GetMainWidget().FindAnyWidget("SpecializationPanelPanel");
  81. m_SpecializationIcon = GetMainWidget().FindAnyWidget("SpecializationIcon");
  82. WidgetEventHandler.GetInstance().RegisterOnDropReceived(GetMainWidget().FindAnyWidget("LeftBackground"), this, "OnLeftPanelDropReceived");
  83. WidgetEventHandler.GetInstance().RegisterOnDraggingOver(GetMainWidget().FindAnyWidget("LeftBackground"), this, "DraggingOverLeftPanel");
  84. WidgetEventHandler.GetInstance().RegisterOnDropReceived(GetMainWidget().FindAnyWidget("LeftPanel").FindAnyWidget("Scroller"), this, "OnLeftPanelDropReceived");
  85. WidgetEventHandler.GetInstance().RegisterOnDraggingOver(GetMainWidget().FindAnyWidget("LeftPanel").FindAnyWidget("Scroller"), this, "DraggingOverLeftPanel");
  86. WidgetEventHandler.GetInstance().RegisterOnDropReceived(GetMainWidget().FindAnyWidget("RightBackground"), this, "OnRightPanelDropReceived");
  87. WidgetEventHandler.GetInstance().RegisterOnDraggingOver(GetMainWidget().FindAnyWidget("RightBackground"), this, "DraggingOverRightPanel");
  88. WidgetEventHandler.GetInstance().RegisterOnDropReceived(GetMainWidget().FindAnyWidget("RightPanel").FindAnyWidget("Scroller"), this, "OnRightPanelDropReceived");
  89. WidgetEventHandler.GetInstance().RegisterOnDraggingOver(GetMainWidget().FindAnyWidget("RightPanel").FindAnyWidget("Scroller"), this, "DraggingOverRightPanel");
  90. WidgetEventHandler.GetInstance().RegisterOnDropReceived(GetMainWidget().FindAnyWidget("CharacterPanel"), this, "OnCenterPanelDropReceived");
  91. WidgetEventHandler.GetInstance().RegisterOnDraggingOver(GetMainWidget().FindAnyWidget("CharacterPanel"), this, "DraggingOverCenterPanel");
  92. WidgetEventHandler.GetInstance().RegisterOnDropReceived(GetMainWidget().FindAnyWidget("HandsPanel"), this, "OnHandsPanelDropReceived");
  93. WidgetEventHandler.GetInstance().RegisterOnDraggingOver(GetMainWidget().FindAnyWidget("HandsPanel"), this, "DraggingOverHandsPanel");
  94. #ifdef PLATFORM_CONSOLE
  95. PluginDiagMenu plugin_diag_menu = PluginDiagMenu.Cast(GetPlugin(PluginDiagMenu));
  96. GetGame().GetUIManager().ShowUICursor(false);
  97. ResetFocusedContainers();
  98. GetMainWidget().FindAnyWidget("CursorCharacter").Show(false);
  99. //console inventory toolbar
  100. m_TopConsoleToolbarVicinity = GetRootWidget().FindAnyWidget("LBRB_Vicinity");
  101. m_TopConsoleToolbarHands = GetRootWidget().FindAnyWidget("LBRB_Hands");
  102. m_TopConsoleToolbarEquipment = GetRootWidget().FindAnyWidget("LBRB_Equipment");
  103. RichTextWidget.Cast(m_TopConsoleToolbarVicinity.FindAnyWidget("LBRB_Vicinity_LBIcon")).SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUIInventoryTabLeft", "", EUAINPUT_DEVICE_CONTROLLER));
  104. RichTextWidget.Cast(m_TopConsoleToolbarVicinity.FindAnyWidget("LBRB_Vicinity_RBIcon")).SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUIInventoryTabRight", "", EUAINPUT_DEVICE_CONTROLLER));
  105. RichTextWidget.Cast(m_TopConsoleToolbarHands.FindAnyWidget("LBRB_Hands_LBIcon")).SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUIInventoryTabLeft", "", EUAINPUT_DEVICE_CONTROLLER));
  106. RichTextWidget.Cast(m_TopConsoleToolbarHands.FindAnyWidget("LBRB_Hands_RBIcon")).SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUIInventoryTabRight", "", EUAINPUT_DEVICE_CONTROLLER));
  107. RichTextWidget.Cast(m_TopConsoleToolbarEquipment.FindAnyWidget("LBRB_Equipment_LBIcon")).SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUIInventoryTabLeft", "", EUAINPUT_DEVICE_CONTROLLER));
  108. RichTextWidget.Cast(m_TopConsoleToolbarEquipment.FindAnyWidget("LBRB_Equipment_RBIcon")).SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUIInventoryTabRight", "", EUAINPUT_DEVICE_CONTROLLER));
  109. m_BottomConsoleToolbar = GetRootWidget().FindAnyWidget("BottomConsoleToolbar");
  110. m_BottomConsoleToolbarRichText = RichTextWidget.Cast(GetRootWidget().FindAnyWidget("ContextToolbarText"));
  111. m_NeedUpdateConsoleToolbar = false;
  112. GetGame().GetMission().GetOnInputPresetChanged().Insert(OnInputPresetChanged);
  113. GetGame().GetMission().GetOnInputDeviceChanged().Insert(OnInputDeviceChanged);
  114. m_SpecializationPanel.Show(false);
  115. UpdateConsoleToolbar();
  116. InitInputWrapperData();
  117. #endif
  118. }
  119. void InitInputWrapperData()
  120. {
  121. int namesCount = m_InvInputNames.Count();
  122. m_InvInputWrappers = new array<UAIDWrapper>;
  123. m_InvInputTimes = new array<float>;
  124. for (int i = 0; i < namesCount; i++)
  125. {
  126. m_InvInputWrappers.Insert(GetUApi().GetInputByName(m_InvInputNames[i]).GetPersistentWrapper());
  127. m_InvInputTimes.Insert(0);
  128. }
  129. m_InvInputWrappersCount = m_InvInputWrappers.Count();
  130. }
  131. protected void OnInputPresetChanged()
  132. {
  133. #ifdef PLATFORM_CONSOLE
  134. UpdateConsoleToolbar();
  135. #endif
  136. }
  137. protected void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
  138. {
  139. switch (pInputDeviceType)
  140. {
  141. case EInputDeviceType.CONTROLLER:
  142. m_BottomConsoleToolbar.Show(true);
  143. UpdateConsoleToolbar();
  144. break;
  145. default:
  146. if (GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer())
  147. {
  148. m_BottomConsoleToolbar.Show(false);
  149. m_TopConsoleToolbarVicinity.Show(false);
  150. m_TopConsoleToolbarHands.Show(false);
  151. m_TopConsoleToolbarEquipment.Show(false);
  152. }
  153. break;
  154. }
  155. }
  156. static Inventory GetInstance()
  157. {
  158. return m_Instance;
  159. }
  160. void Serialize()
  161. {
  162. ItemManager.GetInstance().SerializeDefaultOpenStates();
  163. ItemManager.GetInstance().SerializeDefaultHeaderOpenStates();
  164. }
  165. void Deserialize()
  166. {
  167. ItemManager.GetInstance().DeserializeDefaultOpenStates();
  168. ItemManager.GetInstance().DeserializeDefaultHeaderOpenStates();
  169. }
  170. static int GetPlayerAttachmentIndex(string slot_name)
  171. {
  172. return m_PlayerAttachmentsIndexes[slot_name];
  173. }
  174. static int GetPlayerAttachmentIndex(int slot_id)
  175. {
  176. return GetPlayerAttachmentIndex(InventorySlots.GetSlotName(slot_id));
  177. }
  178. protected void LoadPlayerAttachmentIndexes()
  179. {
  180. int i;
  181. string data, errorMessage;
  182. m_PlayerAttachmentsIndexes = new map<string, int>();
  183. if (GetGame().GetProfileString("INV_AttIndexes", data))
  184. {
  185. if (!JsonFileLoader<map<string, int>>.LoadData(data, m_PlayerAttachmentsIndexes, errorMessage))
  186. ErrorEx(errorMessage);
  187. }
  188. string configPathGhostSlots = "CfgVehicles SurvivorBase InventoryEquipment playerSlots";
  189. array<string> playerGhostSlots = new array<string>();
  190. GetGame().ConfigGetTextArray(configPathGhostSlots, playerGhostSlots);
  191. foreach (string slotName : playerGhostSlots)
  192. {
  193. slotName.Replace("Slot_", "");
  194. if (!m_PlayerAttachmentsIndexes.Contains(slotName) && InventorySlots.GetSlotIdFromString(slotName) != -1)
  195. {
  196. m_PlayerAttachmentsIndexes.Insert(slotName, m_PlayerAttachmentsIndexes.Count());
  197. }
  198. }
  199. if (!JsonFileLoader<map<string, int>>.MakeData(m_PlayerAttachmentsIndexes, data, errorMessage))
  200. ErrorEx(errorMessage);
  201. GetGame().SetProfileString("INV_AttIndexes", data);
  202. }
  203. static void MoveAttachmentUp(int slot_id)
  204. {
  205. int curr = GetPlayerAttachmentIndex(slot_id);
  206. int next_offset = 0;
  207. string next_item = "init";
  208. int next_id;
  209. EntityAI next_ent;
  210. while(!next_ent && next_item != "")
  211. {
  212. next_item = m_PlayerAttachmentsIndexes.GetKeyByValue(curr + --next_offset);
  213. next_id = InventorySlots.GetSlotIdFromString(next_item);
  214. next_ent = GetGame().GetPlayer().GetInventory().FindAttachment(next_id);
  215. if (next_ent && !m_Instance.m_RightArea.HasEntityContainerVisible(next_ent))
  216. next_ent = null;
  217. }
  218. if (next_item != "" && next_ent)
  219. {
  220. int next = GetPlayerAttachmentIndex(next_item);
  221. m_PlayerAttachmentsIndexes.Set(InventorySlots.GetSlotName(slot_id), next);
  222. m_PlayerAttachmentsIndexes.Set(next_item, curr);
  223. if (m_Instance)
  224. m_Instance.m_RightArea.SwapItemsInOrder(next_id, slot_id);
  225. }
  226. }
  227. static void MoveAttachmentDown(int slot_id)
  228. {
  229. int curr = GetPlayerAttachmentIndex(slot_id);
  230. int next_offset = 0;
  231. string next_item = "init";
  232. int next_id;
  233. EntityAI next_ent;
  234. while(!next_ent && next_item != "")
  235. {
  236. next_item = m_PlayerAttachmentsIndexes.GetKeyByValue(curr + ++next_offset);
  237. next_id = InventorySlots.GetSlotIdFromString(next_item);
  238. next_ent = GetGame().GetPlayer().GetInventory().FindAttachment(next_id);
  239. if (next_ent && !m_Instance.m_RightArea.HasEntityContainerVisible(next_ent))
  240. next_ent = null;
  241. }
  242. if (next_item != "" && next_ent)
  243. {
  244. int next = GetPlayerAttachmentIndex(next_item);
  245. m_PlayerAttachmentsIndexes.Set(InventorySlots.GetSlotName(slot_id), next);
  246. m_PlayerAttachmentsIndexes.Set(next_item, curr);
  247. if (m_Instance)
  248. m_Instance.m_RightArea.SwapItemsInOrder(next_id, slot_id);
  249. }
  250. }
  251. protected int GetProperControllerStickAngle(int angle)
  252. {
  253. int proper_angle = (360 - angle) % 360;
  254. return proper_angle;
  255. }
  256. protected int AngleToDirection(int angle)
  257. {
  258. if (angle < 45 || angle > 315)
  259. {
  260. return Direction.RIGHT;
  261. }
  262. else if (angle < 135 && angle > 45)
  263. {
  264. return Direction.DOWN;
  265. }
  266. else if (angle < 225 && angle > 135)
  267. {
  268. return Direction.LEFT;
  269. }
  270. else if (angle < 315 && angle > 225)
  271. {
  272. return Direction.UP;
  273. }
  274. return -1;
  275. }
  276. void TimerEnd()
  277. {
  278. m_ControllerRightStickTimerEnd = true;
  279. m_ControllerRightStickTimer.Stop();
  280. }
  281. bool Controller(Widget w, int control, int value)
  282. {
  283. #ifdef PLATFORM_CONSOLE
  284. //Right stick
  285. if (control == ControlID.CID_RADIALMENU)
  286. {
  287. m_ControllerAngle = value >> 4; // <0,360>
  288. m_ControllerTilt = value & 0xF; // <0,10>
  289. m_ControllerAngle = GetProperControllerStickAngle(m_ControllerAngle);
  290. m_ControllerAngle = AngleToDirection(m_ControllerAngle);
  291. if (m_ControllerTilt>5)
  292. {
  293. if (m_ControllerRightStickTimerEnd)
  294. {
  295. m_ControllerRightStickTimerEnd = false;
  296. m_ControllerRightStickTimer.Run(0.1, this, "TimerEnd");
  297. }
  298. }
  299. return true;
  300. }
  301. UpdateConsoleToolbar();
  302. #endif
  303. return false;
  304. }
  305. void DraggingOverHandsPanel(Widget w, int x, int y, Widget receiver)
  306. {
  307. ItemManager.GetInstance().HideDropzones();
  308. m_HandsArea.DraggingOverHandsPanel(w, x, y, receiver);
  309. }
  310. void OnHandsPanelDropReceived(Widget w, int x, int y, Widget receiver)
  311. {
  312. m_HandsArea.OnHandsPanelDropReceived(w, x, y, receiver);
  313. }
  314. void OnLeftPanelDropReceived(Widget w, int x, int y, Widget receiver)
  315. {
  316. m_LeftArea.OnLeftPanelDropReceived(w, x, y, receiver);
  317. }
  318. void OnRightPanelDropReceived(Widget w, int x, int y, Widget receiver)
  319. {
  320. if (w)
  321. {
  322. ItemPreviewWidget ipw = ItemPreviewWidget.Cast(w.FindAnyWidget("Render"));
  323. if (!ipw)
  324. {
  325. string name = w.GetName();
  326. name.Replace("PanelWidget", "Render");
  327. ipw = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
  328. if (!ipw)
  329. {
  330. ipw = ItemPreviewWidget.Cast(w);
  331. if (!ipw)
  332. {
  333. return;
  334. }
  335. }
  336. }
  337. EntityAI item = ipw.GetItem();
  338. if (item)
  339. {
  340. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  341. InventoryLocation il = new InventoryLocation;
  342. if (player && player.GetInventory().FindFreeLocationFor(item, FindInventoryLocationType.CARGO | FindInventoryLocationType.ATTACHMENT, il))
  343. {
  344. SplitItemUtils.TakeOrSplitToInventory(player, player, item);
  345. }
  346. }
  347. }
  348. }
  349. void OnCenterPanelDropReceived(Widget w, int x, int y, Widget receiver)
  350. {
  351. if (w)
  352. {
  353. ItemPreviewWidget ipw = ItemPreviewWidget.Cast(w.FindAnyWidget("Render"));
  354. if (!ipw)
  355. {
  356. string name = w.GetName();
  357. name.Replace("PanelWidget", "Render");
  358. ipw = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
  359. if (!ipw)
  360. {
  361. ipw = ItemPreviewWidget.Cast(w);
  362. if (!ipw)
  363. {
  364. return;
  365. }
  366. }
  367. }
  368. EntityAI item = ipw.GetItem();
  369. if (item)
  370. {
  371. if (!item.GetInventory().CanRemoveEntity())
  372. return;
  373. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  374. bool found = false;
  375. InventoryLocation inv_loc = new InventoryLocation;
  376. if (player)
  377. {
  378. int index = player.GetHumanInventory().FindUserReservedLocationIndex(item);
  379. if (index>=0)
  380. {
  381. player.GetHumanInventory().GetUserReservedLocation(index, inv_loc);
  382. if (player.GetInventory().LocationCanAddEntity(inv_loc))
  383. {
  384. SplitItemUtils.TakeOrSplitToInventoryLocation(player, inv_loc);
  385. }
  386. return;
  387. }
  388. }
  389. if (player && (player.GetInventory().CanAddAttachment(item)))
  390. {
  391. float stackable = item.GetTargetQuantityMax(-1);
  392. if (stackable == 0 || stackable >= item.GetQuantity())
  393. {
  394. player.PredictiveTakeEntityAsAttachment(item);
  395. }
  396. else
  397. {
  398. InventoryLocation il = new InventoryLocation;
  399. player.GetInventory().FindFreeLocationFor(item, FindInventoryLocationType.ATTACHMENT, il);
  400. ItemBase.Cast(item).SplitIntoStackMaxToInventoryLocationClient(il);
  401. }
  402. }
  403. else
  404. {
  405. int slot_id = item.GetInventory().GetSlotId(0);
  406. EntityAI slot_item = player.GetInventory().FindAttachment(slot_id);
  407. if (slot_item && player.GetInventory().CanSwapEntitiesEx(item, slot_item))
  408. {
  409. player.PredictiveSwapEntities(item, slot_item);
  410. }
  411. else if (player.CanReceiveItemIntoCargo(item))
  412. {
  413. InventoryLocation dst = new InventoryLocation;
  414. player.GetInventory().FindFreeLocationFor(item, FindInventoryLocationType.ANY, dst);
  415. if (dst.IsValid())
  416. {
  417. if (dst.GetType() == InventoryLocationType.HANDS && item.IsHeavyBehaviour())
  418. {
  419. ActionManagerClient mngr_client;
  420. CastTo(mngr_client, player.GetActionManager());
  421. ActionTarget atrg = new ActionTarget(item, null, -1, vector.Zero, -1.0);
  422. if (mngr_client.GetAction(ActionTakeItemToHands).Can(player, atrg, null))
  423. mngr_client.PerformActionStart(mngr_client.GetAction(ActionTakeItemToHands), atrg, null);
  424. return;
  425. }
  426. SplitItemUtils.TakeOrSplitToInventoryLocation(player, dst);
  427. }
  428. }
  429. }
  430. }
  431. }
  432. }
  433. void DraggingOverLeftPanel(Widget w, int x, int y, Widget receiver)
  434. {
  435. m_LeftArea.DraggingOverHeader(w, x, y, receiver);
  436. }
  437. void DraggingOverRightPanel(Widget w, int x, int y, Widget receiver)
  438. {
  439. m_RightArea.DraggingOverHeader(w, x, y, receiver);
  440. }
  441. void DraggingOverCenterPanel(Widget w, int x, int y, Widget receiver)
  442. {
  443. if (w)
  444. {
  445. ItemPreviewWidget ipw = ItemPreviewWidget.Cast(w.FindAnyWidget("Render"));
  446. if (!ipw)
  447. {
  448. string name = w.GetName();
  449. name.Replace("PanelWidget", "Render");
  450. ipw = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
  451. if (!ipw)
  452. {
  453. ipw = ItemPreviewWidget.Cast(w);
  454. if (!ipw)
  455. {
  456. return;
  457. }
  458. }
  459. }
  460. EntityAI item = ipw.GetItem();
  461. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  462. if (player && item)
  463. {
  464. int slot_id = item.GetInventory().GetSlotId(0);
  465. EntityAI slot_item = player.GetInventory().FindAttachment(slot_id);
  466. bool found = false;
  467. InventoryLocation inv_loc = new InventoryLocation;
  468. int index = player.GetHumanInventory().FindUserReservedLocationIndex(item);
  469. if (index>=0)
  470. {
  471. player.GetHumanInventory().GetUserReservedLocation(index, inv_loc);
  472. if (player.GetInventory().LocationCanAddEntity(inv_loc))
  473. found = true;
  474. }
  475. if (!found)
  476. {
  477. player.GetInventory().FindFreeLocationFor(item, FindInventoryLocationType.ANY, inv_loc);
  478. }
  479. if (inv_loc.IsValid())
  480. {
  481. ItemManager.GetInstance().HideDropzones();
  482. GetMainWidget().FindAnyWidget("RightPanel").FindAnyWidget("DropzoneX").SetAlpha(1);
  483. if (inv_loc.GetType() == 4)
  484. {
  485. ItemManager.GetInstance().HideDropzones();
  486. GetMainWidget().FindAnyWidget("HandsPanel").FindAnyWidget("DropzoneX").SetAlpha(1);
  487. }
  488. ColorManager.GetInstance().SetColor(w, ColorManager.GREEN_COLOR);
  489. }
  490. else
  491. {
  492. ItemManager.GetInstance().ShowSourceDropzone(item);
  493. ColorManager.GetInstance().SetColor(w, ColorManager.RED_COLOR);
  494. }
  495. }
  496. else
  497. {
  498. ColorManager.GetInstance().SetColor(w, ColorManager.RED_COLOR);
  499. }
  500. }
  501. }
  502. void Update(float timeslice)
  503. {
  504. #ifdef PLATFORM_CONSOLE
  505. //inventory grid movement
  506. InventoryMovementButtonTickHandler(timeslice);
  507. if (m_InvInputActive & (1 << INV_MOV_RIGHT))
  508. {
  509. if (GetUApi().GetInputByID(UAUIDragNDrop).LocalValue())
  510. {
  511. EnableMicromanagement();
  512. }
  513. if (!GetUApi().GetInputByID(UAUIInventoryTabRight).LocalValue())
  514. {
  515. if (m_RightArea.IsActive())
  516. m_RightArea.MoveGridCursor(Direction.RIGHT);
  517. if (m_LeftArea.IsActive())
  518. m_LeftArea.MoveGridCursor(Direction.RIGHT);
  519. if (m_HandsArea.IsActive())
  520. m_HandsArea.MoveGridCursor(Direction.RIGHT);
  521. }
  522. }
  523. else if (m_InvInputActive & (1 << INV_MOV_LEFT))
  524. {
  525. if (GetUApi().GetInputByID(UAUIDragNDrop).LocalValue())
  526. {
  527. EnableMicromanagement();
  528. }
  529. if (!GetUApi().GetInputByID(UAUIInventoryTabLeft).LocalValue())
  530. {
  531. if (m_RightArea.IsActive())
  532. m_RightArea.MoveGridCursor(Direction.LEFT);
  533. if (m_LeftArea.IsActive())
  534. m_LeftArea.MoveGridCursor(Direction.LEFT);
  535. if (m_HandsArea.IsActive())
  536. m_HandsArea.MoveGridCursor(Direction.LEFT);
  537. }
  538. }
  539. else if (m_InvInputActive & (1 << INV_MOV_UP))
  540. {
  541. if (GetUApi().GetInputByID(UAUIDragNDrop).LocalValue())
  542. {
  543. EnableMicromanagement();
  544. }
  545. if (!GetUApi().GetInputByID(UAUIInventoryContainerUp).LocalValue())
  546. {
  547. if (m_RightArea.IsActive())
  548. m_RightArea.MoveGridCursor(Direction.UP);
  549. if (m_LeftArea.IsActive())
  550. m_LeftArea.MoveGridCursor(Direction.UP);
  551. if (m_HandsArea.IsActive())
  552. m_HandsArea.MoveGridCursor(Direction.UP);
  553. }
  554. }
  555. else if (m_InvInputActive & (1 << INV_MOV_DOWN))
  556. {
  557. if (GetUApi().GetInputByID(UAUIDragNDrop).LocalValue())
  558. {
  559. EnableMicromanagement();
  560. }
  561. if (!GetUApi().GetInputByID(UAUIInventoryContainerDown).LocalValue())
  562. {
  563. if (m_RightArea.IsActive())
  564. m_RightArea.MoveGridCursor(Direction.DOWN);
  565. if (m_LeftArea.IsActive())
  566. m_LeftArea.MoveGridCursor(Direction.DOWN);
  567. if (m_HandsArea.IsActive())
  568. m_HandsArea.MoveGridCursor(Direction.DOWN);
  569. }
  570. }
  571. m_InvInputActive = 0;
  572. #endif
  573. UpdateInterval();
  574. }
  575. UAInput m_InpInp = null;
  576. override void UpdateInterval()
  577. {
  578. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  579. InventoryItem item;
  580. if (GetUApi().GetInputByID(UAUIRotateInventory).LocalPress())
  581. {
  582. item = InventoryItem.Cast(ItemManager.GetInstance().GetDraggedItem());
  583. if (item)
  584. {
  585. int size_x, size_y;
  586. GetGame().GetInventoryItemSize(item, size_x, size_y);
  587. if (size_x != size_y)
  588. {
  589. item.GetInventory().FlipCargo();
  590. item.GetOnItemFlipped().Invoke(item.GetInventory().GetFlipCargo());
  591. }
  592. }
  593. }
  594. #ifdef PLATFORM_CONSOLE
  595. DayZPlayerInventory dpi;
  596. if (player)
  597. dpi = player.GetDayZPlayerInventory();
  598. // There's a second one a bit below
  599. if (dpi && !dpi.IsProcessing())
  600. {
  601. if (GetUApi().GetInputByID(UAUIExpandCollapseContainer).LocalPress())
  602. {
  603. if (m_RightArea.IsActive())
  604. {
  605. m_RightArea.ExpandCollapseContainer();
  606. }
  607. else if (m_LeftArea.IsActive())
  608. {
  609. m_LeftArea.ExpandCollapseContainer();
  610. }
  611. }
  612. if (GetUApi().GetInputByID(UAUIDragNDrop).LocalHoldBegin())
  613. {
  614. EnableMicromanagement();
  615. }
  616. if (GetUApi().GetInputByID(UAUISplit).LocalPress())
  617. {
  618. if (m_HandsArea.IsActive())
  619. {
  620. if (m_HandsArea.SplitItem())
  621. {
  622. m_HandsArea.SetActive(false);
  623. m_HandsArea.UnfocusGrid();
  624. m_RightArea.SetActive(true);
  625. }
  626. }
  627. else if (m_RightArea.IsActive())
  628. {
  629. m_RightArea.SplitItem();
  630. }
  631. else if (m_LeftArea.IsActive())
  632. {
  633. m_LeftArea.SplitItem();
  634. }
  635. HideOwnedTooltip();
  636. }
  637. if (GetUApi().GetInputByID(UAUIFastEquip).LocalPress())
  638. {
  639. if (m_HandsArea.IsActive())
  640. {
  641. if (m_HandsArea.EquipItem())
  642. {
  643. m_HandsArea.SetActive(false);
  644. m_HandsArea.UnfocusGrid();
  645. m_RightArea.SetActive(true);
  646. }
  647. }
  648. else if (m_RightArea.IsActive())
  649. {
  650. m_RightArea.EquipItem();
  651. }
  652. else if (m_LeftArea.IsActive())
  653. {
  654. m_LeftArea.EquipItem();
  655. }
  656. UpdateConsoleToolbar();
  657. HideOwnedTooltip();
  658. }
  659. if (ItemManager.GetInstance().IsMicromanagmentMode() && GetUApi().GetInputByID(UAUIDragNDrop).LocalRelease())
  660. {
  661. if (m_RightArea.IsActive())
  662. {
  663. m_RightArea.Select();
  664. }
  665. else if (m_LeftArea.IsActive())
  666. {
  667. m_LeftArea.Select();
  668. }
  669. else if (m_HandsArea.IsActive())
  670. {
  671. m_HandsArea.Select();
  672. }
  673. DisableMicromanagement();
  674. UpdateConsoleToolbar();
  675. }
  676. if (GetUApi().GetInputByID(UAUIPutInHandsFromVicinity).LocalPress())
  677. {
  678. if (m_LeftArea.IsActive())
  679. {
  680. if (m_LeftArea.Select())
  681. {
  682. m_LeftArea.SetActive(false);
  683. m_LeftArea.UnfocusGrid();
  684. m_HandsArea.SetActive(true);
  685. UpdateConsoleToolbar();
  686. }
  687. }
  688. }
  689. if (GetUApi().GetInputByID(UAUIPutInHandsFromInventory).LocalPress())
  690. {
  691. if (m_RightArea.IsActive())
  692. {
  693. if (m_RightArea.Select())
  694. {
  695. m_RightArea.SetActive(false);
  696. m_RightArea.UnfocusGrid();
  697. m_HandsArea.SetActive(true);
  698. UpdateConsoleToolbar();
  699. }
  700. }
  701. }
  702. if (GetUApi().GetInputByID(UAUIFastTransferToVicinity).LocalPress()) //item drop
  703. {
  704. if (m_HandsArea.IsActive())
  705. {
  706. item = InventoryItem.Cast(m_HandsArea.GetFocusedItem());
  707. if (item && item.GetInventory().CanRemoveEntity())
  708. {
  709. if (m_HandsArea.TransferItemToVicinity())
  710. {
  711. m_HandsArea.SetActive(false);
  712. m_HandsArea.UnfocusGrid();
  713. m_LeftArea.SetActive(true);
  714. m_HadFastTransferred = true;
  715. }
  716. }
  717. }
  718. else if (m_RightArea.IsActive())
  719. {
  720. item = InventoryItem.Cast(m_RightArea.GetFocusedItem());
  721. if (item && item.GetInventory().CanRemoveEntity())
  722. {
  723. if (m_RightArea.TransferItemToVicinity())
  724. m_HadFastTransferred = true;
  725. }
  726. }
  727. UpdateConsoleToolbar();
  728. HideOwnedTooltip();
  729. }
  730. }
  731. if (GetUApi().GetInputByID(UAUIInspectItem).LocalPress())
  732. {
  733. if (m_HandsArea.IsActive())
  734. {
  735. if (m_HandsArea.InspectItem())
  736. {
  737. m_HadInspected = true;
  738. }
  739. }
  740. else if (m_RightArea.IsActive())
  741. {
  742. if (m_RightArea.InspectItem())
  743. {
  744. m_HadInspected = true;
  745. }
  746. }
  747. else if (m_LeftArea.IsActive())
  748. {
  749. if (m_LeftArea.InspectItem())
  750. {
  751. m_HadInspected = true;
  752. }
  753. }
  754. UpdateConsoleToolbar();
  755. }
  756. if (GetUApi().GetInputByID(UAUIFastTransferItem).LocalPress())
  757. m_HadFastTransferred = false;
  758. if (GetUApi().GetInputByID(UAUIInspectItem).LocalPress())
  759. m_HadInspected = false;
  760. if (dpi && !dpi.IsProcessing())
  761. {
  762. if (!m_HadFastTransferred && GetUApi().GetInputByID(UAUIFastTransferItem).LocalPress()) //transfers item to inventory (not hands, or hands last?)
  763. {
  764. if (m_LeftArea.IsActive())
  765. {
  766. item = InventoryItem.Cast(m_LeftArea.GetFocusedItem());
  767. if (item && item.GetInventory().CanRemoveEntity())
  768. {
  769. m_LeftArea.TransferItem();
  770. }
  771. }
  772. else if (m_HandsArea.IsActive())
  773. {
  774. item = InventoryItem.Cast(m_HandsArea.GetFocusedItem());
  775. if (item && item.GetInventory().CanRemoveEntity())
  776. {
  777. if (m_HandsArea.TransferItem())
  778. {
  779. m_HandsArea.SetActive(false);
  780. m_HandsArea.UnfocusGrid();
  781. m_RightArea.SetActive(true);
  782. }
  783. }
  784. }
  785. UpdateConsoleToolbar();
  786. HideOwnedTooltip();
  787. }
  788. }
  789. if (GetUApi().GetInputByID(UAUIInventoryContainerUp).LocalPress())
  790. {
  791. if (GetUApi().GetInputByID(UAUIDragNDrop).LocalValue())
  792. {
  793. EnableMicromanagement();
  794. }
  795. MoveFocusByContainer(Direction.UP);
  796. }
  797. if (GetUApi().GetInputByID(UAUIInventoryContainerDown).LocalPress())
  798. {
  799. if (GetUApi().GetInputByID(UAUIDragNDrop).LocalValue())
  800. {
  801. EnableMicromanagement();
  802. }
  803. MoveFocusByContainer(Direction.DOWN);
  804. }
  805. if (GetUApi().GetInputByID(UAUIInventoryTabLeft).LocalPress())
  806. {
  807. if (GetUApi().GetInputByID(UAUIDragNDrop).LocalValue())
  808. {
  809. EnableMicromanagement();
  810. }
  811. MoveFocusByArea(Direction.LEFT);
  812. }
  813. if (GetUApi().GetInputByID(UAUIInventoryTabRight).LocalPress())
  814. {
  815. if (GetUApi().GetInputByID(UAUIDragNDrop).LocalValue())
  816. {
  817. EnableMicromanagement();
  818. }
  819. MoveFocusByArea(Direction.RIGHT);
  820. }
  821. //Open Quickbar radial menu
  822. if (GetUApi().GetInputByID(UAUIQuickbarRadialInventoryOpen).LocalPress())
  823. {
  824. //assign item
  825. EntityAI item_to_assign;
  826. if (m_HandsArea.IsActive())
  827. {
  828. player = PlayerBase.Cast(GetGame().GetPlayer());
  829. item_to_assign = m_HandsArea.GetFocusedItem();
  830. m_HandsArea.AddItemToQuickbarRadial(item_to_assign);
  831. }
  832. else if (m_RightArea.IsActive())
  833. {
  834. item_to_assign = m_RightArea.GetFocusedItem();
  835. m_RightArea.AddItemToQuickbarRadial(item_to_assign);
  836. }
  837. }
  838. #endif
  839. MissionGameplay mission = MissionGameplay.Cast(GetGame().GetMission());
  840. if (!m_HadInspected && GetUApi().GetInputByID(UAUICombine).LocalPress())
  841. {
  842. if (GetMainWidget().IsVisible())
  843. {
  844. #ifdef PLATFORM_CONSOLE
  845. //DisableMicromanagement();
  846. if (m_RightArea.IsActive())
  847. {
  848. if (m_RightArea.CanCombine())
  849. {
  850. if (m_RightArea.Combine())
  851. {
  852. mission.HideInventory();
  853. }
  854. }
  855. }
  856. else if (m_LeftArea.IsActive())
  857. {
  858. if (m_LeftArea.CanCombine())
  859. {
  860. if (m_LeftArea.Combine())
  861. {
  862. mission.HideInventory();
  863. }
  864. }
  865. }
  866. #endif
  867. }
  868. }
  869. // controller close inventory using back action
  870. if (!m_HadInspected && GetUApi().GetInputByID(UAUIBack).LocalPress() && GetGame().GetInput().GetCurrentInputDevice() == EInputDeviceType.CONTROLLER)
  871. {
  872. mission.HideInventory();
  873. }
  874. for (int i = 0; i < 10; i++)
  875. {
  876. if (!m_HoldingQB && GetUApi().GetInputByName("UAItem" + i).LocalPress())
  877. {
  878. m_QBHoveredItems = InventoryItem.Cast(ItemManager.GetInstance().GetHoveredItem());
  879. m_HoldingQB = true;
  880. }
  881. if (m_HoldingQB && GetUApi().GetInputByName("UAItem" + i).LocalHold())
  882. {
  883. AddQuickbarItem(m_QBHoveredItems, i);
  884. m_QBHoveredItems = null;
  885. m_HoldingQB = false;
  886. }
  887. }
  888. m_LeftArea.UpdateInterval();
  889. m_RightArea.UpdateInterval();
  890. m_HandsArea.UpdateInterval();
  891. m_PlayerPreview.UpdateInterval();
  892. #ifdef PLATFORM_CONSOLE
  893. UpdateConsoleToolbarCheck();
  894. #endif
  895. }
  896. void AddQuickbarItem(InventoryItem item, int index)
  897. {
  898. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  899. if (item && item.GetInventory().CanRemoveEntity())
  900. {
  901. player.SetQuickBarEntityShortcut(item, index) ;
  902. }
  903. InventoryMenu menu = InventoryMenu.Cast(GetGame().GetUIManager().FindMenu(MENU_INVENTORY));
  904. if (menu)
  905. {
  906. menu.RefreshQuickbar();
  907. }
  908. }
  909. void EnableMicromanagement()
  910. {
  911. if (!ItemManager.GetInstance().IsMicromanagmentMode())
  912. {
  913. ItemManager.GetInstance().SetItemMicromanagmentMode(true);
  914. if (m_RightArea.IsActive())
  915. {
  916. m_RightArea.SelectItem();
  917. }
  918. else if (m_LeftArea.IsActive())
  919. {
  920. m_LeftArea.SelectItem();
  921. }
  922. else if (m_HandsArea.IsActive())
  923. {
  924. m_HandsArea.SelectItem();
  925. }
  926. UpdateConsoleToolbar();
  927. HideOwnedTooltip();
  928. }
  929. }
  930. void DisableMicromanagement()
  931. {
  932. if (ItemManager.GetInstance().IsMicromanagmentMode())
  933. {
  934. ItemManager.GetInstance().SetItemMicromanagmentMode(false);
  935. ItemManager.GetInstance().SetSelectedItemEx(null, null, null);
  936. UpdateConsoleToolbar();
  937. HideOwnedTooltip();
  938. }
  939. }
  940. override void SetLayoutName()
  941. {
  942. #ifdef PLATFORM_CONSOLE
  943. m_LayoutName = WidgetLayoutName.InventoryXbox;
  944. #else
  945. switch (InventoryMenu.GetWidthType())
  946. {
  947. case ScreenWidthType.NARROW:
  948. {
  949. m_LayoutName = WidgetLayoutName.InventoryNarrow;
  950. break;
  951. }
  952. case ScreenWidthType.MEDIUM:
  953. {
  954. m_LayoutName = WidgetLayoutName.InventoryMedium;
  955. break;
  956. }
  957. case ScreenWidthType.WIDE:
  958. {
  959. m_LayoutName = WidgetLayoutName.InventoryWide;
  960. break;
  961. }
  962. }
  963. #endif
  964. }
  965. void Init() {}
  966. void Reset()
  967. {
  968. m_LeftArea.Refresh();
  969. m_RightArea.Refresh();
  970. m_HandsArea.Refresh();
  971. }
  972. void ResetFocusedContainers()
  973. {
  974. #ifdef PLATFORM_CONSOLE
  975. m_RightArea.UnfocusGrid();
  976. m_LeftArea.UnfocusGrid();
  977. m_HandsArea.UnfocusGrid();
  978. m_LeftArea.SetActive(false);
  979. m_HandsArea.SetActive(false);
  980. m_RightArea.SetActive(false);
  981. m_RightArea.ResetFocusedContainer();
  982. m_LeftArea.ResetFocusedContainer();
  983. m_RightArea.SetActive(true);
  984. #endif
  985. }
  986. override void OnShow()
  987. {
  988. SetFocus(GetMainWidget());
  989. Deserialize();
  990. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  991. if (player && player.IsPlacingLocal())
  992. {
  993. GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Call(player.TogglePlacingLocal);
  994. }
  995. Mission mission = GetGame().GetMission();
  996. if (mission)
  997. {
  998. IngameHud hud = IngameHud.Cast(mission.GetHud());
  999. if (hud)
  1000. {
  1001. hud.ShowQuickbarUI(false);
  1002. hud.ShowHudInventory(true);
  1003. }
  1004. }
  1005. m_SpecializationPanel.Show(false);
  1006. #ifdef PLATFORM_CONSOLE
  1007. ResetFocusedContainers();
  1008. #endif
  1009. RefreshQuickbar();
  1010. UpdateInterval();
  1011. UpdateConsoleToolbar();
  1012. m_HadFastTransferred = false;
  1013. m_HadInspected = false;
  1014. m_PlayerPreview.RefreshPlayerPreview();
  1015. }
  1016. override void OnHide()
  1017. {
  1018. Serialize();
  1019. HideOwnedTooltip();
  1020. Mission mission = GetGame().GetMission();
  1021. if (mission)
  1022. {
  1023. IngameHud hud = IngameHud.Cast(mission.GetHud());
  1024. if (hud)
  1025. {
  1026. hud.ShowQuickbarUI(true);
  1027. hud.ShowHudInventory(false);
  1028. }
  1029. }
  1030. ItemManager.GetInstance().SetSelectedItemEx(null, null, null);
  1031. }
  1032. void UpdateSpecialtyMeter()
  1033. {
  1034. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  1035. if (player && player.GetSoftSkillsManager())
  1036. {
  1037. float x = player.GetSoftSkillsManager().GetSpecialtyLevel() / 2;
  1038. float y = -0.75;
  1039. #ifndef PLATFORM_CONSOLE
  1040. m_SpecializationIcon.SetPos(x, y, true);
  1041. #else
  1042. Mission mission = GetGame().GetMission();
  1043. IngameHud hud = IngameHud.Cast(mission.GetHud());
  1044. if (hud)
  1045. {
  1046. hud.UpdateSpecialtyMeter(x,y);
  1047. }
  1048. #endif
  1049. }
  1050. }
  1051. override void Refresh()
  1052. {
  1053. m_LeftArea.Refresh();
  1054. m_HandsArea.Refresh();
  1055. m_RightArea.Refresh();
  1056. RefreshQuickbar();
  1057. UpdateConsoleToolbar();
  1058. }
  1059. void RefreshQuickbar()
  1060. {
  1061. #ifndef PLATFORM_CONSOLE
  1062. m_QuickbarWidget.Show(true);
  1063. #else
  1064. m_QuickbarWidget.Show(GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer());
  1065. #endif
  1066. #ifndef PLATFORM_CONSOLE
  1067. if (m_Quickbar)
  1068. #else
  1069. if (m_Quickbar && GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer())
  1070. #endif
  1071. {
  1072. m_Quickbar.UpdateItems(m_QuickbarWidget);
  1073. }
  1074. }
  1075. #ifdef PLATFORM_CONSOLE
  1076. protected string GetConsoleToolbarText(int mask)
  1077. {
  1078. string result = "";
  1079. string toHandsSwapVicinity = string.Format(" %1", InputUtils.GetRichtextButtonIconFromInputAction("UAUIPutInHandsFromVicinity", GetStringVariant("UAUIPutInHandsFromVicinity",{"#STR_Controls_TakeInHandsSwap","#STR_USRACT_HoldToHandSwap",""}), EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  1080. string toHandsSwapInv = string.Format(" %1", InputUtils.GetRichtextButtonIconFromInputAction("UAUIPutInHandsFromInventory", GetStringVariant("UAUIPutInHandsFromInventory",{"#STR_Controls_TakeInHandsSwap","#STR_USRACT_HoldToHandSwap",""}), EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  1081. string drop = string.Format(" %1", InputUtils.GetRichtextButtonIconFromInputAction("UAUIFastTransferToVicinity", "#dayz_context_menu_drop", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  1082. string equip = string.Format(" %1", InputUtils.GetRichtextButtonIconFromInputAction("UAUIFastEquip", "#dayz_context_menu_equip", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  1083. string split = string.Format(" %1", InputUtils.GetRichtextButtonIconFromInputAction("UAUISplit", GetStringVariant("UAUISplit",{"#dayz_context_menu_split","#STR_Controls_HoldSplit",""}), EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  1084. string toInventory = string.Format(" %1", InputUtils.GetRichtextButtonIconFromInputAction("UAUIFastTransferItem", "#dayz_context_menu_to_inventory", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  1085. string openCloseContainer = string.Format(" %1", InputUtils.GetRichtextButtonIconFromInputAction("UAUIExpandCollapseContainer", "#dayz_context_menu_open_close", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  1086. string micromanagment = string.Format(" %1", InputUtils.GetRichtextButtonIconFromInputAction("UAUIDragNDrop", "#dayz_context_menu_micro", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  1087. string quickslot = string.Format(" %1", InputUtils.GetRichtextButtonIconFromInputAction("UAUIQuickbarRadialInventoryOpen", "#ps4_dayz_context_menu_quickslot", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  1088. string combine = string.Format(" %1", InputUtils.GetRichtextButtonIconFromInputAction("UAUICombine", GetStringVariant("UAUICombine",{"#dayz_context_menu_combine","#dayz_context_menu_combine_hold",""}), EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  1089. if (mask & ConsoleActionToolbarMask.OPEN_CLOSE_CONTAINER)
  1090. {
  1091. result += openCloseContainer;
  1092. }
  1093. if (mask & ConsoleActionToolbarMask.TO_HANDS_SWAP_VICINITY)
  1094. {
  1095. result += toHandsSwapVicinity;
  1096. }
  1097. if (mask & ConsoleActionToolbarMask.TO_HANDS_SWAP_INVENTORY)
  1098. {
  1099. result += toHandsSwapInv;
  1100. }
  1101. if (mask & ConsoleActionToolbarMask.TO_INVENTORY)
  1102. {
  1103. result += toInventory;
  1104. }
  1105. if (mask & ConsoleActionToolbarMask.DROP)
  1106. {
  1107. result += drop;
  1108. }
  1109. if (mask & ConsoleActionToolbarMask.SPLIT)
  1110. {
  1111. result += split;
  1112. }
  1113. if (mask & ConsoleActionToolbarMask.EQUIP)
  1114. {
  1115. result += equip;
  1116. }
  1117. if (mask & ConsoleActionToolbarMask.COMBINE)
  1118. {
  1119. result += combine;
  1120. }
  1121. if (mask & ConsoleActionToolbarMask.MICROMANAGMENT)
  1122. {
  1123. result += micromanagment;
  1124. }
  1125. if (mask & ConsoleActionToolbarMask.QUICKSLOT)
  1126. {
  1127. result += quickslot;
  1128. }
  1129. return result;
  1130. }
  1131. #endif
  1132. Container GetFocusedArea()
  1133. {
  1134. if (m_LeftArea && m_LeftArea.IsActive())
  1135. {
  1136. return m_LeftArea;
  1137. }
  1138. else if (m_RightArea && m_RightArea.IsActive())
  1139. {
  1140. return m_RightArea;
  1141. }
  1142. else if (m_HandsArea && m_HandsArea.IsActive())
  1143. {
  1144. return m_HandsArea;
  1145. }
  1146. return null;
  1147. }
  1148. #ifdef PLATFORM_CONSOLE
  1149. void UpdateConsoleToolbarCheck()
  1150. {
  1151. if ( m_NeedUpdateConsoleToolbar )
  1152. {
  1153. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  1154. if (player.GetInventory().GetAnyInventoryReservationCount() == 0)
  1155. {
  1156. m_NeedUpdateConsoleToolbar = false;
  1157. UpdateConsoleToolbar();
  1158. }
  1159. }
  1160. }
  1161. #endif
  1162. //Console toolbar
  1163. void UpdateConsoleToolbar()
  1164. {
  1165. #ifdef PLATFORM_CONSOLE
  1166. int combinationFlag = 0;
  1167. string contextualText;
  1168. InventoryLocation il;
  1169. Container focusedArea = GetFocusedArea();
  1170. if (focusedArea)
  1171. {
  1172. Container focusedContainer = GetFocusedArea().GetFocusedContainer();
  1173. EntityAI focusedItem = GetFocusedArea().GetFocusedItem();
  1174. if (!(focusedItem && focusedItem.IsSetForDeletion()))
  1175. {
  1176. if (focusedContainer)
  1177. {
  1178. if (focusedItem)
  1179. {
  1180. il = new InventoryLocation;
  1181. focusedItem.GetInventory().GetCurrentInventoryLocation( il );
  1182. }
  1183. bool canBeManipulated = false;
  1184. PlayerBase player;
  1185. PlayerBase itemPlayerOwner;
  1186. player = PlayerBase.Cast(GetGame().GetPlayer());
  1187. m_NeedUpdateConsoleToolbar = player.GetInventory().GetAnyInventoryReservationCount() > 0;
  1188. if (focusedItem)
  1189. {
  1190. itemPlayerOwner = PlayerBase.Cast(focusedItem.GetHierarchyRootPlayer());
  1191. il = new InventoryLocation;
  1192. focusedItem.GetInventory().GetCurrentInventoryLocation( il );
  1193. canBeManipulated = !player.GetInventory().HasInventoryReservation( focusedItem, null ) && !player.GetInventory().IsInventoryLocked() && !player.IsItemsToDelete();
  1194. m_NeedUpdateConsoleToolbar |= !canBeManipulated;
  1195. canBeManipulated = canBeManipulated && focusedItem.CanPutIntoHands(null);
  1196. canBeManipulated = canBeManipulated && focusedItem.GetInventory().CanRemoveEntity();
  1197. EntityAI parent = il.GetParent();
  1198. if ( parent && il.GetType() == InventoryLocationType.ATTACHMENT )
  1199. {
  1200. canBeManipulated = canBeManipulated && AttachmentsOutOfReach.IsAttachmentReachable( parent, "", il.GetSlot() );
  1201. canBeManipulated = canBeManipulated && !parent.GetInventory().GetSlotLock( il.GetSlot() );
  1202. }
  1203. if (canBeManipulated)
  1204. {
  1205. if (!ItemManager.GetInstance().IsMicromanagmentMode())
  1206. {
  1207. combinationFlag |= ConsoleActionToolbarMask.MICROMANAGMENT;
  1208. }
  1209. if (focusedContainer.CanEquipEx(focusedItem))
  1210. {
  1211. combinationFlag |= ConsoleActionToolbarMask.EQUIP;
  1212. }
  1213. if (player!= null && player == itemPlayerOwner)
  1214. {
  1215. if (focusedContainer.CanSwapOrTakeToHandsEx(focusedItem))
  1216. {
  1217. combinationFlag |= ConsoleActionToolbarMask.TO_HANDS_SWAP_INVENTORY;
  1218. }
  1219. if (focusedContainer.CanDropEx(focusedItem))
  1220. {
  1221. combinationFlag |= ConsoleActionToolbarMask.DROP;
  1222. }
  1223. }
  1224. else
  1225. {
  1226. if (focusedContainer.CanSwapOrTakeToHandsEx(focusedItem))
  1227. {
  1228. combinationFlag |= ConsoleActionToolbarMask.TO_HANDS_SWAP_VICINITY;
  1229. }
  1230. }
  1231. if (focusedContainer.CanCombineEx(focusedItem))
  1232. {
  1233. combinationFlag |= ConsoleActionToolbarMask.COMBINE;
  1234. }
  1235. if (focusedContainer.CanSplitEx(focusedItem))
  1236. {
  1237. combinationFlag |= ConsoleActionToolbarMask.SPLIT;
  1238. }
  1239. if (focusedArea.CanTakeToInventoryEx(focusedItem))
  1240. {
  1241. combinationFlag |= ConsoleActionToolbarMask.TO_INVENTORY;
  1242. }
  1243. }
  1244. }
  1245. if (focusedContainer.CanOpenCloseContainerEx(focusedItem))
  1246. {
  1247. combinationFlag |= ConsoleActionToolbarMask.OPEN_CLOSE_CONTAINER;
  1248. }
  1249. if (player!= null && focusedContainer.CanAddToQuickbarEx(focusedItem))
  1250. {
  1251. combinationFlag |= ConsoleActionToolbarMask.QUICKSLOT;
  1252. }
  1253. }
  1254. }
  1255. contextualText = GetConsoleToolbarText(combinationFlag);
  1256. if (m_TopConsoleToolbarVicinity)
  1257. m_TopConsoleToolbarVicinity.Show(m_LeftArea.IsActive());
  1258. if (m_TopConsoleToolbarHands)
  1259. m_TopConsoleToolbarHands.Show(m_HandsArea.IsActive());
  1260. if (m_TopConsoleToolbarEquipment)
  1261. m_TopConsoleToolbarEquipment.Show(m_RightArea.IsActive());
  1262. if (m_BottomConsoleToolbarRichText)
  1263. m_BottomConsoleToolbarRichText.SetText(contextualText + " ");
  1264. }
  1265. #endif
  1266. }
  1267. //! Picks from the strings by active input limiter variant in order: {click,hold,doubleclick}. Intended for inputs that check 'LocalPress' exclusively!!
  1268. string GetStringVariant(string pInputAction, notnull array<string> variants)
  1269. {
  1270. if (variants.Count() != 3)
  1271. {
  1272. ErrorEx("wrong array count!");
  1273. return "";
  1274. }
  1275. UAInput inp = GetUApi().GetInputByName(pInputAction);
  1276. if (!inp.IsLimited() || inp.IsClickLimit()) //returns 'click' (no extension) variant as default
  1277. {
  1278. return variants[0];
  1279. }
  1280. if (inp.IsHoldLimit() || inp.IsHoldBeginLimit())
  1281. {
  1282. return variants[1];
  1283. }
  1284. if (inp.IsDoubleClickLimit())
  1285. {
  1286. return variants[2];
  1287. }
  1288. ErrorEx("Unhandled limiter exception!");
  1289. return "";
  1290. }
  1291. //! Shifts between containers vertically
  1292. void MoveFocusByContainer(int direction)
  1293. {
  1294. HideOwnedTooltip();
  1295. if (direction == Direction.UP)
  1296. {
  1297. if ( m_LeftArea.IsActive() )
  1298. {
  1299. m_LeftArea.SetSameLevelPreviousActive();
  1300. }
  1301. else if ( m_RightArea.IsActive() )
  1302. {
  1303. m_RightArea.SetSameLevelPreviousActive();
  1304. }
  1305. else if ( m_HandsArea.IsActive() )
  1306. {
  1307. m_HandsArea.SetSameLevelPreviousActive();
  1308. }
  1309. UpdateConsoleToolbar();
  1310. }
  1311. else if (direction == Direction.DOWN)
  1312. {
  1313. if ( m_LeftArea.IsActive() )
  1314. {
  1315. m_LeftArea.SetSameLevelNextActive();
  1316. }
  1317. else if ( m_RightArea.IsActive() )
  1318. {
  1319. m_RightArea.SetSameLevelNextActive();
  1320. }
  1321. else if ( m_HandsArea.IsActive() )
  1322. {
  1323. m_HandsArea.SetSameLevelNextActive();
  1324. }
  1325. UpdateConsoleToolbar();
  1326. }
  1327. }
  1328. //! Shifts between vicinity-hands-player
  1329. void MoveFocusByArea(int direction)
  1330. {
  1331. HideOwnedTooltip();
  1332. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  1333. if (direction == Direction.LEFT)
  1334. {
  1335. if (m_LeftArea.IsActive())
  1336. {
  1337. if (!ItemManager.GetInstance().IsMicromanagmentMode())
  1338. {
  1339. m_LeftArea.UnfocusGrid();
  1340. }
  1341. m_LeftArea.SetActive(false);
  1342. m_RightArea.SetActive(true);
  1343. UpdateConsoleToolbar();
  1344. }
  1345. else if (m_RightArea.IsActive())
  1346. {
  1347. if (!ItemManager.GetInstance().IsMicromanagmentMode())
  1348. {
  1349. m_RightArea.UnfocusGrid();
  1350. }
  1351. m_RightArea.SetActive(false);
  1352. player = PlayerBase.Cast(GetGame().GetPlayer());
  1353. EntityAI item_in_hands = player.GetItemInHands();
  1354. m_HandsArea.SetActive(true);
  1355. UpdateConsoleToolbar();
  1356. }
  1357. else if (m_HandsArea.IsActive())
  1358. {
  1359. m_HandsArea.UnfocusGrid();
  1360. m_HandsArea.SetActive(false);
  1361. m_LeftArea.SetActive(true);
  1362. UpdateConsoleToolbar();
  1363. }
  1364. }
  1365. else if (direction == Direction.RIGHT)
  1366. {
  1367. if (m_LeftArea.IsActive())
  1368. {
  1369. if (!ItemManager.GetInstance().IsMicromanagmentMode())
  1370. {
  1371. m_LeftArea.UnfocusGrid();
  1372. }
  1373. m_LeftArea.SetActive(false);
  1374. player = PlayerBase.Cast(GetGame().GetPlayer());
  1375. item_in_hands = player.GetItemInHands();
  1376. m_HandsArea.SetActive(true);
  1377. UpdateConsoleToolbar();
  1378. }
  1379. else if (m_RightArea.IsActive())
  1380. {
  1381. if (!ItemManager.GetInstance().IsMicromanagmentMode())
  1382. {
  1383. m_RightArea.UnfocusGrid();
  1384. }
  1385. m_RightArea.SetActive(false);
  1386. m_LeftArea.SetActive(true);
  1387. UpdateConsoleToolbar();
  1388. }
  1389. else if (m_HandsArea.IsActive())
  1390. {
  1391. m_HandsArea.UnfocusGrid();
  1392. m_HandsArea.SetActive(false);
  1393. m_RightArea.SetActive(true);
  1394. UpdateConsoleToolbar();
  1395. }
  1396. }
  1397. }
  1398. void InventoryMovementButtonTickHandler(float timeslice)
  1399. {
  1400. float tickvalue = 0;
  1401. if (m_SensitivityThreshold > 0.0)
  1402. {
  1403. if (m_SensitivityThreshold < BT_REPEAT_TIME) //sensitivity solution...
  1404. {
  1405. m_SensitivityThreshold += timeslice;
  1406. return;
  1407. }
  1408. else
  1409. {
  1410. m_SensitivityThreshold = 0.0;
  1411. }
  1412. }
  1413. for (int i = 0; i < m_InvInputWrappersCount; i++)
  1414. {
  1415. m_InvUAInput = m_InvInputWrappers[i].InputP();
  1416. if (m_InvUAInput.LocalValue() > BT_THRESHOLD_VALUE)
  1417. {
  1418. tickvalue = m_InvInputTimes[i];
  1419. tickvalue += timeslice;
  1420. }
  1421. else
  1422. {
  1423. tickvalue = 0.0;
  1424. }
  1425. if (tickvalue < BT_REPEAT_DELAY && m_InvUAInput.LocalPress())
  1426. {
  1427. m_InvInputActive |= (1 << i);
  1428. m_SensitivityThreshold += timeslice;
  1429. }
  1430. else if (tickvalue > (BT_REPEAT_DELAY + BT_REPEAT_TIME))
  1431. {
  1432. while (tickvalue > (BT_REPEAT_DELAY + BT_REPEAT_TIME))
  1433. {
  1434. tickvalue -= BT_REPEAT_TIME;
  1435. }
  1436. m_InvInputActive |= (1 << i);
  1437. m_SensitivityThreshold += timeslice;
  1438. }
  1439. else
  1440. {
  1441. m_InvInputActive &= ~(1 << i);
  1442. }
  1443. m_InvInputTimes[i] = tickvalue;
  1444. }
  1445. }
  1446. }