inventory.c 46 KB

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