inventory.c 44 KB

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