actiontargetscursor.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343
  1. class ATCCachedObject
  2. {
  3. protected Object m_CachedObject;
  4. protected vector m_CursorWPos;
  5. protected vector m_ScreenPos;
  6. protected int m_CompIdx;
  7. void ATCCachedTarget()
  8. {
  9. m_CachedObject = null;
  10. m_ScreenPos = vector.Zero;
  11. m_CompIdx = -1;
  12. }
  13. //! cache object and its world pos
  14. void Store(Object obj, vector pos, int compIdx)
  15. {
  16. if (!m_CachedObject)
  17. {
  18. m_CachedObject = obj;
  19. m_CursorWPos = pos;
  20. m_CompIdx = compIdx;
  21. }
  22. }
  23. //! invalidate cached objec
  24. void Invalidate()
  25. {
  26. if (m_CachedObject)
  27. {
  28. m_CachedObject = null;
  29. m_CursorWPos = vector.Zero;
  30. m_CompIdx = -1;
  31. }
  32. }
  33. Object Get()
  34. {
  35. return m_CachedObject;
  36. }
  37. vector GetCursorWorldPos()
  38. {
  39. return m_CursorWPos;
  40. }
  41. int GetCursorCompIdx()
  42. {
  43. return m_CompIdx;
  44. }
  45. };
  46. class ActionTargetsCursor : ScriptedWidgetEventHandler
  47. {
  48. private const ref array<typename> VISION_OBSTRUCTION_PPEFFECTS_TYPES = {
  49. PPERequester_BurlapSackEffects,
  50. PPERequester_FlashbangEffects
  51. };
  52. protected PlayerBase m_Player;
  53. protected ActionTarget m_Target;
  54. protected ref ATCCachedObject m_CachedObject;
  55. protected Object m_DisplayInteractTarget;
  56. protected ActionBase m_Interact;
  57. protected ActionBase m_ContinuousInteract;
  58. protected ActionBase m_Single;
  59. protected ActionBase m_Continuous;
  60. protected ActionManagerClient m_AM;
  61. protected IngameHud m_Hud;
  62. protected UAIDWrapper m_UseActionWrapper;
  63. protected int m_InteractActionsNum;
  64. protected int m_ContinuousInteractActionsNum;
  65. protected int m_ItemActionsNum;
  66. protected int m_ContinuousItemActionsNum;
  67. protected typename m_SelectedActionCategory;
  68. protected bool m_HealthEnabled;
  69. protected bool m_QuantityEnabled;
  70. protected bool m_FixedOnPosition;
  71. protected bool m_Hidden;
  72. protected bool m_TargetItemFrozen;
  73. protected Widget m_Root;
  74. protected Widget m_Container;
  75. protected Widget m_ItemLeft;
  76. //! widget width
  77. protected float m_MaxWidthChild;
  78. protected float m_RootWidth;
  79. protected float m_RootHeight;
  80. void ActionTargetsCursor()
  81. {
  82. m_Interact = null;
  83. m_ContinuousInteract = null;
  84. m_Single = null;
  85. m_Continuous = null;
  86. m_AM = null;
  87. m_HealthEnabled = true;
  88. m_QuantityEnabled = true;
  89. m_CachedObject = new ATCCachedObject;
  90. m_Hidden = false;
  91. m_TargetItemFrozen = false;
  92. m_DisplayInteractTarget = null;
  93. m_Hud = GetHud();
  94. m_UseActionWrapper = GetUApi().GetInputByID(UAAction).GetPersistentWrapper();
  95. GetGame().GetMission().GetOnInputPresetChanged().Insert(OnInputPresetChanged);
  96. GetGame().GetMission().GetOnInputDeviceChanged().Insert(OnInputDeviceChanged);
  97. }
  98. void ~ActionTargetsCursor() {}
  99. // Controls appearance of the builded cursor
  100. void SetHealthVisibility(bool state)
  101. {
  102. m_HealthEnabled = state;
  103. }
  104. void SetQuantityVisibility(bool state)
  105. {
  106. m_QuantityEnabled = state;
  107. }
  108. //! DEPRECATED
  109. void SetInteractXboxIcon(string imageset_name, string image_name);
  110. void SetContinuousInteractXboxIcon(string imageset_name, string image_name);
  111. void SetSingleXboxIcon(string imageset_name, string image_name);
  112. void SetContinuousXboxIcon(string imageset_name, string image_name);
  113. protected void SetXboxIcon(string name, string imageset_name, string image_name);
  114. //! ---------
  115. protected void SetControllerIcon(string pWidgetName, string pInputName)
  116. {
  117. RichTextWidget w = RichTextWidget.Cast(m_Root.FindAnyWidget(pWidgetName + "_btn_icon_xbox"));
  118. w.SetText(InputUtils.GetRichtextButtonIconFromInputAction(pInputName, "", EUAINPUT_DEVICE_CONTROLLER));
  119. }
  120. protected void OnWidgetScriptInit(Widget w)
  121. {
  122. m_Root = w;
  123. m_Root.Show(false);
  124. m_Root.SetHandler(this);
  125. //! UA -> widget icon
  126. UpdateControllerInputIcons();
  127. UpdatePCIconsVisibility();
  128. m_Container = w.FindAnyWidget("container");
  129. m_ItemLeft = w.FindAnyWidget("item_left");
  130. m_Root.Update();
  131. }
  132. protected void OnInputPresetChanged()
  133. {
  134. #ifdef PLATFORM_CONSOLE
  135. UpdateControllerInputIcons();
  136. #endif
  137. }
  138. protected void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
  139. {
  140. UpdatePCIconsVisibility();
  141. }
  142. //! Loads icons from the latest keybinds
  143. private void UpdateControllerInputIcons()
  144. {
  145. SetControllerIcon("interact", "UAAction");
  146. SetControllerIcon("continuous_interact", "UAAction");
  147. SetControllerIcon("single", "UADefaultAction");
  148. SetControllerIcon("continuous", "UADefaultAction");
  149. }
  150. //! Contains logic for icon set switching (Gamepad/M&K)
  151. private void UpdatePCIconsVisibility()
  152. {
  153. bool showConsoleIcons = false;
  154. #ifdef PLATFORM_CONSOLE
  155. showConsoleIcons = GetGame().GetInput().GetCurrentInputDevice() == EInputDeviceType.CONTROLLER || !GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer();
  156. #endif
  157. ShowXboxHidePCIcons("interact", showConsoleIcons);
  158. ShowXboxHidePCIcons("continuous_interact", showConsoleIcons);
  159. ShowXboxHidePCIcons("continuous", showConsoleIcons);
  160. ShowXboxHidePCIcons("single", showConsoleIcons);
  161. }
  162. protected void PrepareCursorContent()
  163. {
  164. m_TargetItemFrozen = false;
  165. int health = -1;
  166. int cargoCount = 0;
  167. int q_type = 0;
  168. int q_min, q_max = -1;
  169. float q_cur = -1.0;
  170. //! item health
  171. m_TargetItemFrozen = GetItemFrozen();
  172. health = GetItemHealth();
  173. SetItemHealth(health, "item", "item_health_mark", m_HealthEnabled);
  174. //! quantity
  175. GetItemQuantity(q_type, q_cur, q_min, q_max);
  176. //! cargo in item
  177. GetItemCargoCount(cargoCount);
  178. //! fill the widget with data
  179. SetItemQuantity(q_type, q_cur, q_min, q_max, "item", "item_quantity_pb", "item_quantity_text", m_QuantityEnabled);
  180. SetInteractActionIcon("interact", "interact_icon_frame", "interact_btn_inner_icon", "interact_btn_text");
  181. SetItemDesc(GetItemDesc(m_Interact), cargoCount, "item", "item_desc");
  182. SetActionWidget(m_Interact, GetActionDesc(m_Interact), "interact", "interact_action_name");
  183. SetInteractActionIcon("continuous_interact", "continuous_interact_icon_frame", "continuous_interact_btn_inner_icon", "continuous_interact_btn_text");
  184. SetActionWidget(m_ContinuousInteract, GetActionDesc(m_ContinuousInteract), "continuous_interact", "continuous_interact_action_name");
  185. SetActionWidget(m_Single, GetActionDesc(m_Single), "single", "single_action_name");
  186. SetActionWidget(m_Continuous, GetActionDesc(m_Continuous), "continuous", "continuous_action_name");
  187. SetMultipleItemAction("single_mlt_wrapper", "single_mlt_wrapper_not_select");
  188. SetMultipleContinuousItemAction("continuous_mlt_wrapper", "continuous_mlt_wrapper_not_select");
  189. SetMultipleInteractAction("interact_mlt_wrapper", "interact_mlt_wrapper_not_select");
  190. SetMultipleContinuousInteractAction("continuous_interact_mlt_wrapper", "continuous_interact_mlt_wrapper_not_select");
  191. }
  192. protected void BuildFixedCursor()
  193. {
  194. int w, h, x, y;
  195. PrepareCursorContent();
  196. GetScreenSize(w, h);
  197. x = w/2 + 32;
  198. y = h/2 + 32;
  199. m_Root.SetPos(x, y);
  200. }
  201. protected void BuildFloatingCursor(bool forceRebuild)
  202. {
  203. float pos_x, pos_y = 0.0;
  204. PrepareCursorContent();
  205. //! Get OnScreenPos when forced or targeted component differs
  206. if (forceRebuild || m_Target.GetComponentIndex() != m_CachedObject.GetCursorCompIdx())
  207. {
  208. GetOnScreenPosition(pos_x, pos_y);
  209. }
  210. //! in case of cached item, all above is reused except the position
  211. else
  212. {
  213. vector screen_pos = TransformToScreenPos(m_CachedObject.GetCursorWorldPos());
  214. pos_x = screen_pos[0];
  215. pos_y = screen_pos[1];
  216. }
  217. pos_x = Math.Ceil(pos_x);
  218. pos_y = Math.Ceil(pos_y);
  219. Widget parentWdg = m_Root.GetParent();
  220. float screen_w = 0;
  221. float screen_h = 0;
  222. float wdg_w = 0;
  223. float wdg_h = 0;
  224. parentWdg.GetScreenSize(screen_w, screen_h);
  225. m_Root.GetSize(wdg_w, wdg_h);
  226. if (pos_x + wdg_w > screen_w)
  227. pos_x = screen_w - wdg_w;
  228. if (pos_y + wdg_h > screen_h)
  229. pos_y = screen_h - wdg_h;
  230. m_Root.SetPos(pos_x, pos_y);
  231. }
  232. override bool OnUpdate(Widget w)
  233. {
  234. if (m_Root == w)
  235. {
  236. Update();
  237. return true;
  238. }
  239. return false;
  240. }
  241. protected void HideWidget()
  242. {
  243. if (m_Root.IsVisible())
  244. {
  245. m_Root.Show(false);
  246. m_CachedObject.Invalidate();
  247. }
  248. }
  249. void Update()
  250. {
  251. if (m_Player && !m_Player.IsAlive()) // handle respawn
  252. {
  253. m_Player = null;
  254. m_AM = null;
  255. }
  256. if (!m_Player)
  257. GetPlayer();
  258. if (!m_AM)
  259. GetActionManager();
  260. if (m_Player.IsInVehicle() || m_AM.GetRunningAction())
  261. m_Hidden = true;
  262. /*
  263. #ifdef DIAG_DEVELOPER
  264. if (DeveloperFreeCamera.IsFreeCameraEnabled())
  265. HideWidget();
  266. return;
  267. #endif
  268. */
  269. bool isVisionObstructionActive = PPEManagerStatic.GetPPEManager().IsAnyRequesterRunning(VISION_OBSTRUCTION_PPEFFECTS_TYPES);
  270. //! don't show floating widget if it's disabled in profile or the player is unconscious
  271. if (isVisionObstructionActive || m_Hud.GetHudVisibility().IsContextFlagActive(IngameHudVisibility.HUD_HIDE_FLAGS))
  272. {
  273. HideWidget();
  274. return;
  275. }
  276. GetTarget();
  277. GetActions();
  278. //! check if action has target, otherwise don't show the widget
  279. bool showTarget = (m_Target && !m_Hidden) || m_Interact || m_ContinuousInteract;
  280. if (!showTarget)
  281. {
  282. if (m_Single)
  283. showTarget = m_Single.HasTarget();
  284. if (m_Continuous)
  285. showTarget = showTarget || m_Continuous.HasTarget();
  286. }
  287. if (showTarget)
  288. {
  289. //! cursor with fixed position (environment interaction mainly)
  290. if (m_Target.GetObject() == null && (m_Interact || m_ContinuousInteract || m_Single || m_Continuous))
  291. {
  292. //Print(">> fixed widget");
  293. m_CachedObject.Invalidate();
  294. BuildFixedCursor();
  295. m_Root.Show(true);
  296. m_FixedOnPosition = false;
  297. m_Hidden = false;
  298. return;
  299. }
  300. else if (m_Target.GetObject() != null && !m_Target.GetObject().IsHologram() && (!m_Target.GetParent() || m_Target.GetParent() && !m_Target.GetParent().IsHologram()))
  301. {
  302. CheckRefresherFlagVisibilityEx(m_Target);
  303. //! build cursor for new target
  304. if (m_Target.GetObject() != m_CachedObject.Get())
  305. {
  306. if (!m_FixedOnPosition)
  307. {
  308. //Print(">> non-cached widget");
  309. m_CachedObject.Invalidate();
  310. BuildFloatingCursor(true);
  311. m_Root.Show(true);
  312. m_Hidden = false;
  313. return;
  314. }
  315. else
  316. {
  317. //Print(">> non-cached widget (fixed)");
  318. m_CachedObject.Invalidate();
  319. BuildFixedCursor();
  320. m_Root.Show(true);
  321. m_FixedOnPosition = false;
  322. m_Hidden = false;
  323. return;
  324. }
  325. }
  326. //! use cached version for known target - recalculate onscreen pos only
  327. else if (m_Target.GetObject() == m_CachedObject.Get())
  328. {
  329. if (!m_FixedOnPosition)
  330. {
  331. //Print(">> cached widget");
  332. BuildFloatingCursor(false);
  333. m_Root.Show(true);
  334. m_Hidden = false;
  335. return;
  336. }
  337. else
  338. {
  339. //Print(">> cached widget (fixed)");
  340. m_CachedObject.Invalidate();
  341. BuildFixedCursor();
  342. m_Root.Show(true);
  343. m_FixedOnPosition = false;
  344. m_Hidden = false;
  345. return;
  346. }
  347. }
  348. }
  349. else
  350. {
  351. if (m_Root.IsVisible())
  352. {
  353. m_CachedObject.Invalidate();
  354. m_Root.Show(false);
  355. m_Hidden = false;
  356. // remove previous backlit
  357. GetDayZGame().GetBacklit().HintClear();
  358. }
  359. }
  360. }
  361. else
  362. {
  363. if (m_Root.IsVisible())
  364. {
  365. m_CachedObject.Invalidate();
  366. m_Root.Show(false);
  367. m_FixedOnPosition = false;
  368. // remove previous backlit
  369. GetDayZGame().GetBacklit().HintClear();
  370. }
  371. m_Hidden = false;
  372. }
  373. m_MaxWidthChild = 350;
  374. }
  375. protected void ShowXboxHidePCIcons(string widget, bool show_xbox_icon)
  376. {
  377. m_Root.FindAnyWidget(widget + "_btn_icon_xbox").Show(show_xbox_icon);
  378. m_Root.FindAnyWidget(widget + "_btn_icon").Show(!show_xbox_icon);
  379. }
  380. //! transform world pos to screen pos (related to parent widget size)
  381. protected vector TransformToScreenPos(vector pWorldPos)
  382. {
  383. float parent_width, parent_height;
  384. vector transformed_pos, screen_pos;
  385. //! get relative pos for screen from world pos vector
  386. screen_pos = GetGame().GetScreenPosRelative(pWorldPos);
  387. //! get size of parent widget
  388. m_Root.GetParent().GetScreenSize(parent_width, parent_height);
  389. //! calculate corrent position from relative pos and parent widget size
  390. transformed_pos[0] = screen_pos[0] * parent_width;
  391. transformed_pos[1] = screen_pos[1] * parent_height;
  392. return transformed_pos;
  393. }
  394. protected void GetOnScreenPosition(out float x, out float y)
  395. {
  396. const float DEFAULT_HANDLE_OFFSET = 0.2;
  397. const string CE_CENTER_COMP_NAME = "ce_center";
  398. const string MEM_LOD_NAME = LOD.NAME_MEMORY; //! kept for backward compatibility
  399. int compIdx;
  400. float pivotOffset = 0.0;
  401. float memOffset = 0.0;
  402. string compName;
  403. bool isTargetForced = false;
  404. vector worldPos;
  405. vector modelPos;
  406. LOD lod;
  407. array<Selection> memSelections = new array<Selection>();
  408. array<string> components = new array<string>; // for components with multiple selection
  409. Object object;
  410. if (m_Target)
  411. {
  412. object = m_Target.GetObject();
  413. compIdx = m_Target.GetComponentIndex();
  414. if (m_Target.GetCursorHitPos() == vector.Zero)
  415. isTargetForced = true;
  416. }
  417. else
  418. {
  419. return;
  420. }
  421. if (object)
  422. {
  423. if (!isTargetForced)
  424. {
  425. compName = object.GetActionComponentName(compIdx);
  426. object.GetActionComponentNameList(compIdx, components);
  427. if (!object.IsInventoryItem() && (object.HasFixedActionTargetCursorPosition() || object.GetActionComponentNameList(compIdx, components) == 0))
  428. {
  429. m_FixedOnPosition = true;
  430. return;
  431. }
  432. pivotOffset = object.ConfigGetFloat("actionTargetPivotOffsetY");
  433. memOffset = object.ConfigGetFloat("actionTargetMemOffsetY");
  434. //! Get memory LOD from p3d
  435. lod = object.GetLODByName(MEM_LOD_NAME);
  436. if (lod != null)
  437. {
  438. //! save selection from memory lod
  439. lod.GetSelections(memSelections);
  440. // items with CE_Center mem point
  441. if (MiscGameplayFunctions.IsComponentInSelection(memSelections, CE_CENTER_COMP_NAME))
  442. {
  443. for (int i2 = 0; i2 < memSelections.Count(); ++i2)
  444. {
  445. if (memSelections[i2].GetName() == CE_CENTER_COMP_NAME && memSelections[i2].GetVertexCount() == 1)
  446. {
  447. m_FixedOnPosition = false;
  448. modelPos = object.GetSelectionPositionMS(CE_CENTER_COMP_NAME);
  449. worldPos = object.ModelToWorld(modelPos);
  450. if (memOffset != 0.0)
  451. {
  452. worldPos[1] = worldPos[1] + memOffset;
  453. }
  454. else
  455. {
  456. worldPos[1] = worldPos[1] + DEFAULT_HANDLE_OFFSET;
  457. }
  458. }
  459. }
  460. //! cache current object and the widget world pos
  461. m_CachedObject.Store(object, worldPos, compIdx);
  462. }
  463. //! doors/handles
  464. else if (!compName.Contains("ladder") && IsComponentInSelection(memSelections, compName))
  465. {
  466. for (int i1 = 0; i1 < memSelections.Count(); ++i1)
  467. {
  468. //! single vertex in selection
  469. if (memSelections[i1].GetName() == compName && memSelections[i1].GetVertexCount() == 1)
  470. {
  471. modelPos = object.GetSelectionPositionMS(compName);
  472. worldPos = object.ModelToWorld(modelPos);
  473. m_FixedOnPosition = false;
  474. if (object.GetType() == "Fence" || object.GetType() == "Watchttower" || object.GetType() == "GardenPlot")
  475. m_FixedOnPosition = true;
  476. if (memOffset != 0.0)
  477. {
  478. worldPos[1] = worldPos[1] + memOffset;
  479. }
  480. else
  481. {
  482. worldPos[1] = worldPos[1] + DEFAULT_HANDLE_OFFSET;
  483. }
  484. }
  485. //! multiple vertices in selection
  486. if (memSelections[i1].GetName() == compName && memSelections[i1].GetVertexCount() > 1)
  487. {
  488. for (int j = 0; j < components.Count(); ++j)
  489. {
  490. if (IsComponentInSelection(memSelections, components[j]))
  491. {
  492. modelPos = object.GetSelectionPositionMS(components[j]);
  493. worldPos = object.ModelToWorld(modelPos);
  494. m_FixedOnPosition = false;
  495. if (memOffset != 0.0)
  496. {
  497. worldPos[1] = worldPos[1] + memOffset;
  498. }
  499. else
  500. {
  501. worldPos[1] = worldPos[1] + DEFAULT_HANDLE_OFFSET;
  502. }
  503. }
  504. }
  505. }
  506. }
  507. //! cache current object and the widget world pos
  508. m_CachedObject.Store(object, worldPos, -1); //! do not store component index for doors/handles
  509. }
  510. //! ladders handling
  511. else if (compName.Contains("ladder") && IsComponentInSelection(memSelections, compName))
  512. {
  513. vector ladderHandlePointLS, ladderHandlePointWS;
  514. vector closestHandlePos;
  515. float lastDistance = 0;
  516. for (int i3 = 0; i3 < memSelections.Count(); ++i3)
  517. {
  518. if (memSelections[i3].GetName() == compName && memSelections[i3].GetVertexCount() > 1)
  519. {
  520. ladderHandlePointLS = memSelections[i3].GetVertexPosition(lod, 0);
  521. ladderHandlePointWS = object.ModelToWorld(ladderHandlePointLS);
  522. closestHandlePos = ladderHandlePointWS;
  523. lastDistance = Math.AbsFloat(vector.DistanceSq(ladderHandlePointWS, m_Player.GetPosition()));
  524. for (int k = 1; k < memSelections[i3].GetVertexCount(); ++k)
  525. {
  526. ladderHandlePointLS = memSelections[i3].GetVertexPosition(lod, k);
  527. ladderHandlePointWS = object.ModelToWorld(ladderHandlePointLS);
  528. if (lastDistance > Math.AbsFloat(vector.DistanceSq(ladderHandlePointWS, m_Player.GetPosition())))
  529. {
  530. lastDistance = Math.AbsFloat(vector.DistanceSq(ladderHandlePointWS, m_Player.GetPosition()));
  531. closestHandlePos = ladderHandlePointWS;
  532. }
  533. }
  534. m_FixedOnPosition = false;
  535. worldPos = closestHandlePos;
  536. if (memOffset != 0.0)
  537. {
  538. worldPos[1] = worldPos[1] + memOffset;
  539. }
  540. else
  541. {
  542. worldPos[1] = worldPos[1] + DEFAULT_HANDLE_OFFSET;
  543. }
  544. }
  545. }
  546. //! cache current object and the widget world pos
  547. m_CachedObject.Store(object, worldPos, -1); //! do not store component index for ladders
  548. }
  549. else
  550. {
  551. m_FixedOnPosition = true;
  552. }
  553. }
  554. else
  555. {
  556. m_FixedOnPosition = true;
  557. }
  558. }
  559. else
  560. {
  561. m_FixedOnPosition = true;
  562. }
  563. vector pos = TransformToScreenPos(worldPos);
  564. x = pos[0];
  565. y = pos[1];
  566. }
  567. worldPos = vector.Zero;
  568. isTargetForced = false;
  569. }
  570. // kept for backward compatibility
  571. protected bool IsComponentInSelection(array<Selection> selection, string compName)
  572. {
  573. return MiscGameplayFunctions.IsComponentInSelection(selection, compName);
  574. }
  575. // getters
  576. protected void GetPlayer()
  577. {
  578. Class.CastTo(m_Player, GetGame().GetPlayer());
  579. }
  580. protected void GetActionManager()
  581. {
  582. if (m_Player && m_Player.IsPlayerSelected())
  583. {
  584. Class.CastTo(m_AM, m_Player.GetActionManager());
  585. }
  586. else
  587. {
  588. m_AM = null;
  589. }
  590. }
  591. //! get actions from Action Manager
  592. protected void GetActions()
  593. {
  594. m_Interact = null;
  595. m_ContinuousInteract = null;
  596. m_Single = null;
  597. m_Continuous = null;
  598. if (!m_AM) return;
  599. if (!m_Target) return;
  600. if (m_Player.IsSprinting()) return;
  601. if (m_Player.IsInVehicle()) return; // TODO: TMP: Car AM rework needed
  602. m_Interact = m_AM.GetPossibleAction(InteractActionInput);
  603. m_ContinuousInteract = m_AM.GetPossibleAction(ContinuousInteractActionInput);
  604. m_Single = m_AM.GetPossibleAction(DefaultActionInput);
  605. m_Continuous = m_AM.GetPossibleAction(ContinuousDefaultActionInput);
  606. m_InteractActionsNum = m_AM.GetPossibleActionCount(InteractActionInput);
  607. m_ContinuousInteractActionsNum = m_AM.GetPossibleActionCount(ContinuousInteractActionInput);
  608. m_ItemActionsNum = m_AM.GetPossibleActionCount(DefaultActionInput);
  609. m_ContinuousItemActionsNum = m_AM.GetPossibleActionCount(ContinuousDefaultActionInput);
  610. m_SelectedActionCategory = m_AM.GetSelectedActionCategory();
  611. if (m_Interact)
  612. {
  613. m_DisplayInteractTarget = m_Interact.GetDisplayInteractObject(m_Player, m_Target);
  614. }
  615. else if (m_Single)
  616. {
  617. m_DisplayInteractTarget = m_Single.GetDisplayInteractObject(m_Player, m_Target);
  618. }
  619. else if (m_ContinuousInteract)
  620. {
  621. m_DisplayInteractTarget = m_ContinuousInteract.GetDisplayInteractObject(m_Player, m_Target);
  622. }
  623. else
  624. {
  625. m_DisplayInteractTarget = null;
  626. }
  627. }
  628. protected void GetTarget()
  629. {
  630. if (!m_AM)
  631. return;
  632. m_Target = m_AM.FindActionTarget();
  633. if (m_Target && m_Target.GetObject() && m_Target.GetObject().IsItemBase())
  634. {
  635. ItemBase item = ItemBase.Cast(m_Target.GetObject());
  636. InventoryLocation invLocation = new InventoryLocation();
  637. item.GetInventory().GetCurrentInventoryLocation(invLocation);
  638. if ((!item.IsTakeable() && !item.IsActionTargetVisible()) || (m_Player && m_Player.IsInVehicle()) || invLocation.GetType() != InventoryLocationType.GROUND)
  639. m_Hidden = true;
  640. }
  641. }
  642. protected string GetActionDesc(ActionBase action)
  643. {
  644. string desc = "";
  645. if (action && action.GetText())
  646. {
  647. desc = action.GetText();
  648. if (desc && action.DisplayTargetInActionText())
  649. string extraDescription = action.GetTargetName(m_Player, m_Target);
  650. if (extraDescription)
  651. desc = string.Format("%1 (%2)", desc, extraDescription);
  652. }
  653. return desc;
  654. }
  655. //Getting NAME of the entity
  656. protected string GetItemDesc(ActionBase action)
  657. {
  658. string desc = "";
  659. Object tgObject = m_DisplayInteractTarget;
  660. if (!tgObject && m_Target)
  661. {
  662. tgObject = m_Target.GetObject();
  663. }
  664. if (tgObject)
  665. {
  666. //BreakOut if item is ruined
  667. Object tgParent = m_Target.GetParent();
  668. if (!tgObject.IsAlive())
  669. {
  670. //Fetch parent item name if one is present
  671. if (!tgParent || tgObject.DisplayNameRuinAttach())
  672. desc = tgObject.GetDisplayName();
  673. else
  674. desc = tgParent.GetDisplayName();
  675. return desc;
  676. }
  677. EntityAI targetEntity;
  678. if (tgParent && (tgParent.IsItemBase() || tgParent.IsTransport()))
  679. {
  680. targetEntity = EntityAI.Cast(tgParent);
  681. }
  682. if (tgObject.IsItemBase() || tgObject.IsTransport())
  683. {
  684. targetEntity = EntityAI.Cast(tgObject);
  685. }
  686. if (targetEntity && targetEntity.ShowZonesHealth())
  687. {
  688. string zone = "";
  689. array<string> selections = new array<string>();
  690. //NOTE: relevant fire geometry and view geometry selection names MUST match in order to get a valid damage zone
  691. if (targetEntity.IsInherited(TentBase) && TentBase.Cast(targetEntity).GetState() != TentBase.PACKED)
  692. {
  693. //This is really specific to tents, as they use proxies. Hence object must be used
  694. if (DamageSystem.GetDamageZoneFromComponentName(targetEntity, tgObject.GetActionComponentName(m_Target.GetComponentIndex(), LOD.NAME_FIRE), zone))
  695. {
  696. desc = DamageSystem.GetDamageDisplayName(targetEntity, zone);
  697. }
  698. }
  699. else
  700. {
  701. targetEntity.GetActionComponentNameList(m_Target.GetComponentIndex(), selections, LOD.NAME_VIEW);
  702. //Important to get display name from component tied to multiple selections
  703. for (int s = 0; s < selections.Count(); s++)
  704. {
  705. if (DamageSystem.GetDamageZoneFromComponentName(targetEntity, selections[s], zone))
  706. {
  707. desc = DamageSystem.GetDamageDisplayName(targetEntity, zone);
  708. }
  709. }
  710. }
  711. }
  712. //Safety check to output something to widget
  713. if (targetEntity && desc == "")
  714. desc = targetEntity.GetDisplayName();
  715. }
  716. return desc;
  717. }
  718. protected int GetItemHealth()
  719. {
  720. int health = -1;
  721. if (m_Interact && !m_Interact.HasTarget())
  722. {
  723. return health;
  724. }
  725. Object tgObject = m_DisplayInteractTarget;
  726. if (!tgObject && m_Target)
  727. {
  728. tgObject = m_Target.GetObject();
  729. }
  730. if (tgObject)
  731. {
  732. Object tgParent = m_Target.GetParent();
  733. EntityAI targetEntity;
  734. //Return specific part health, even if display name is from parent
  735. if (!tgObject.IsAlive())
  736. {
  737. EntityAI ent;
  738. if (m_TargetItemFrozen && Class.CastTo(ent,tgObject) && (ent.IsAnimal() || ent.IsMan() || ent.IsZombie()))
  739. health = -2; //frozen interaction later
  740. else
  741. health = tgObject.GetHealthLevel();
  742. return health;
  743. }
  744. if (tgParent && (tgParent.IsItemBase() || tgParent.IsTransport()))
  745. {
  746. targetEntity = EntityAI.Cast(tgParent);
  747. }
  748. if (tgObject.IsItemBase() || tgObject.IsTransport())
  749. {
  750. targetEntity = EntityAI.Cast(tgObject);
  751. }
  752. if (targetEntity)
  753. {
  754. if (!targetEntity.IsDamageDestroyed())
  755. {
  756. string zone = "";
  757. array<string> selections = new array<string>();
  758. if (targetEntity.IsInherited(TentBase) && TentBase.Cast(targetEntity).GetState() != TentBase.PACKED)
  759. {
  760. //This is really specific to tents, as they use proxies. Hence object must be used
  761. if (DamageSystem.GetDamageZoneFromComponentName(targetEntity, tgObject.GetActionComponentName(m_Target.GetComponentIndex(), LOD.NAME_FIRE), zone))
  762. {
  763. health = targetEntity.GetHealthLevel(zone);
  764. }
  765. }
  766. else
  767. {
  768. //NOTE: relevant view geometry and view geometry selection names MUST match in order to get a valid damage zone
  769. targetEntity.GetActionComponentNameList(m_Target.GetComponentIndex(), selections, LOD.NAME_VIEW);
  770. for (int s = 0; s < selections.Count(); s++)
  771. {
  772. if (DamageSystem.GetDamageZoneFromComponentName(targetEntity , selections[s], zone))
  773. {
  774. health = targetEntity.GetHealthLevel(zone);
  775. break;
  776. }
  777. }
  778. }
  779. if (zone == "")
  780. health = targetEntity.GetHealthLevel();
  781. }
  782. }
  783. else
  784. {
  785. health = tgObject.GetHealthLevel();
  786. }
  787. }
  788. return health;
  789. }
  790. protected bool GetItemFrozen()
  791. {
  792. Object tgObject = m_DisplayInteractTarget;
  793. if (!tgObject && m_Target)
  794. tgObject = m_Target.GetObject();
  795. if (tgObject)
  796. {
  797. Object tgParent = m_Target.GetParent();
  798. EntityAI targetEntity;
  799. if (tgParent)
  800. {
  801. targetEntity = EntityAI.Cast(tgParent);
  802. }
  803. else
  804. {
  805. targetEntity = EntityAI.Cast(tgObject);
  806. }
  807. return (targetEntity && targetEntity.GetIsFrozen());
  808. }
  809. return false;
  810. }
  811. protected void GetItemQuantity(out int q_type, out float q_cur, out int q_min, out int q_max)
  812. {
  813. InventoryItem item = null;
  814. if (m_Interact && !m_Interact.HasTarget())
  815. {
  816. return;
  817. }
  818. Object tgObject = m_DisplayInteractTarget;
  819. if (!tgObject && m_Target)
  820. {
  821. tgObject = m_Target.GetObject();
  822. }
  823. if (Class.CastTo(item, tgObject))
  824. {
  825. q_type = QuantityConversions.HasItemQuantity(item);
  826. if (q_type > 0)
  827. QuantityConversions.GetItemQuantity(item, q_cur, q_min, q_max);
  828. }
  829. }
  830. //! returns number of items in cargo for targeted entity
  831. protected void GetItemCargoCount(out int cargoCount)
  832. {
  833. EntityAI entity = null;
  834. Object tgObject = m_DisplayInteractTarget;
  835. if (!tgObject && m_Target)
  836. {
  837. tgObject = m_Target.GetObject();
  838. }
  839. if (Class.CastTo(entity, tgObject))
  840. {
  841. GameInventory inventory = entity.GetInventory();
  842. if (inventory)
  843. {
  844. cargoCount = AttachmentsWithInventoryOrCargoCount(inventory);
  845. return;
  846. }
  847. //! default cargo count
  848. cargoCount = 0;
  849. }
  850. }
  851. // setters
  852. protected void SetItemDesc(string descText, int cargoCount, string itemWidget, string descWidget)
  853. {
  854. Widget widget;
  855. widget = m_Root.FindAnyWidget(itemWidget);
  856. //! Last message from finished User Action on target (Thermometer, Blood Test Kit, etc.)
  857. PlayerBase playerT = PlayerBase.Cast(m_Target.GetObject());
  858. if (playerT)
  859. string msg = playerT.GetLastUAMessage();
  860. if (descText.Length() == 0 && msg.Length() == 0)
  861. {
  862. widget.Show(false);
  863. return;
  864. }
  865. descText.ToUpper();
  866. TextWidget itemName;
  867. Class.CastTo(itemName, widget.FindAnyWidget(descWidget));
  868. //! when cargo in container
  869. if (cargoCount > 0)
  870. descText = string.Format("[+] %1 %2", descText, msg);
  871. else
  872. descText = string.Format("%1 %2", descText, msg);
  873. itemName.SetText(descText);
  874. widget.Show(true);
  875. }
  876. protected void SetItemHealth(int health, string itemWidget, string healthWidget, bool enabled)
  877. {
  878. Widget widget = m_Root.FindAnyWidget(itemWidget);
  879. if (enabled)
  880. {
  881. ImageWidget healthMark;
  882. Class.CastTo(healthMark, widget.FindAnyWidget(healthWidget));
  883. if (health == -1)
  884. {
  885. healthMark.GetParent().Show(false);
  886. widget.Show(enabled);
  887. return;
  888. }
  889. int color = 0x00FFFFFF;
  890. if (m_TargetItemFrozen && (health != GameConstants.STATE_RUINED || health == -2))
  891. color = Colors.COLOR_FROZEN;
  892. else
  893. color = ItemManager.GetItemHealthColor(health);
  894. healthMark.SetColor(color);
  895. healthMark.SetAlpha(0.5);
  896. healthMark.GetParent().Show(true);
  897. }
  898. widget.Show(enabled);
  899. }
  900. protected void SetItemQuantity(int type, float current, int min, int max, string itemWidget, string quantityPBWidget, string quantityTextWidget, bool enabled)
  901. {
  902. Widget widget;
  903. widget = m_Root.FindAnyWidget(itemWidget);
  904. if (enabled)
  905. {
  906. ProgressBarWidget progressBar;
  907. TextWidget textWidget;
  908. Class.CastTo(progressBar, widget.FindAnyWidget(quantityPBWidget));
  909. Class.CastTo(textWidget, widget.FindAnyWidget(quantityTextWidget));
  910. //check for volume vs. count and display progressbar or "bubble" with exact count/max text
  911. switch (type)
  912. {
  913. case QUANTITY_HIDDEN :
  914. progressBar.Show(false);
  915. textWidget.Show(false);
  916. textWidget.GetParent().Show(false);
  917. break;
  918. case QUANTITY_COUNT :
  919. if (max > 1 || current > 1)
  920. {
  921. string qty_text = string.Format("%1/%2", Math.Round(current).ToString(), max.ToString());
  922. progressBar.Show(false);
  923. textWidget.SetText(qty_text);
  924. textWidget.Show(true);
  925. textWidget.GetParent().Show(true);
  926. }
  927. else
  928. {
  929. progressBar.Show(false);
  930. textWidget.Show(false);
  931. textWidget.GetParent().Show(false);
  932. }
  933. break;
  934. case QUANTITY_PROGRESS :
  935. float qty_num = Math.Round((current / max) * 100);
  936. textWidget.Show(false);
  937. progressBar.SetCurrent(qty_num);
  938. progressBar.Show(true);
  939. textWidget.GetParent().Show(true);
  940. break;
  941. }
  942. widget.Show(true);
  943. }
  944. else
  945. widget.Show(false);
  946. }
  947. protected void SetActionWidget(ActionBase action, string descText, string actionWidget, string descWidget)
  948. {
  949. Widget widget = m_Root.FindAnyWidget(actionWidget);
  950. if (action)
  951. {
  952. if (action.HasTarget() && m_AM.GetActionState() < 1) // targeted & action not performing
  953. {
  954. TextWidget actionName;
  955. Class.CastTo(actionName, widget.FindAnyWidget(descWidget));
  956. if (action.GetInput().GetInputType() == ActionInputType.AIT_CONTINUOUS)
  957. {
  958. descText = descText + " " + "#action_target_cursor_hold";
  959. actionName.SetText(descText);
  960. }
  961. else
  962. {
  963. actionName.SetText(descText);
  964. }
  965. widget.Show(true);
  966. int x, y;
  967. actionName.GetTextSize(x, y);
  968. if (x > m_MaxWidthChild);
  969. m_MaxWidthChild = x;
  970. }
  971. else
  972. {
  973. widget.Show(false);
  974. }
  975. }
  976. else
  977. {
  978. widget.Show(false);
  979. }
  980. }
  981. //! shows arrows near the interact action if there are more than one available
  982. protected void SetMultipleInteractAction(string multiActionsWidget, string multiActionsWidget_NotSelect)
  983. {
  984. Widget widget, widget_not_select;
  985. widget = m_Root.FindAnyWidget(multiActionsWidget);
  986. widget_not_select = m_Root.FindAnyWidget(multiActionsWidget_NotSelect);
  987. if (m_InteractActionsNum > 1)
  988. {
  989. if (m_SelectedActionCategory == InteractActionInput)
  990. {
  991. widget.Show(true);
  992. widget_not_select.Show(false);
  993. }
  994. else
  995. {
  996. widget.Show(false);
  997. widget_not_select.Show(true);
  998. }
  999. }
  1000. else
  1001. {
  1002. widget.Show(false);
  1003. widget_not_select.Show(false);
  1004. }
  1005. }
  1006. protected void SetMultipleContinuousInteractAction(string multiActionsWidget, string multiActionsWidget_NotSelect)
  1007. {
  1008. Widget widget, widget_not_select;
  1009. widget = m_Root.FindAnyWidget(multiActionsWidget);
  1010. widget_not_select = m_Root.FindAnyWidget(multiActionsWidget_NotSelect);
  1011. if (m_ContinuousInteractActionsNum > 1)
  1012. {
  1013. if (m_SelectedActionCategory == ContinuousInteractActionInput)
  1014. {
  1015. widget.Show(true);
  1016. widget_not_select.Show(false);
  1017. }
  1018. else
  1019. {
  1020. widget.Show(false);
  1021. widget_not_select.Show(true);
  1022. }
  1023. }
  1024. else
  1025. {
  1026. widget.Show(false);
  1027. widget_not_select.Show(false);
  1028. }
  1029. }
  1030. protected void SetMultipleItemAction(string multiActionsWidget, string multiActionsWidget_NotSelect)
  1031. {
  1032. Widget widget, widget_not_select;
  1033. widget = m_Root.FindAnyWidget(multiActionsWidget);
  1034. widget_not_select = m_Root.FindAnyWidget(multiActionsWidget_NotSelect);
  1035. if (m_ItemActionsNum > 1)
  1036. {
  1037. if (m_SelectedActionCategory == DefaultActionInput)
  1038. {
  1039. widget.Show(true);
  1040. widget_not_select.Show(false);
  1041. }
  1042. else
  1043. {
  1044. widget.Show(false);
  1045. widget_not_select.Show(true);
  1046. }
  1047. }
  1048. else
  1049. {
  1050. widget.Show(false);
  1051. widget_not_select.Show(false);
  1052. }
  1053. }
  1054. protected void SetMultipleContinuousItemAction(string multiActionsWidget, string multiActionsWidget_NotSelect)
  1055. {
  1056. Widget widget, widget_not_select;
  1057. widget = m_Root.FindAnyWidget(multiActionsWidget);
  1058. widget_not_select = m_Root.FindAnyWidget(multiActionsWidget_NotSelect);
  1059. if (m_ContinuousItemActionsNum > 1)
  1060. {
  1061. if (m_SelectedActionCategory == ContinuousDefaultActionInput)
  1062. {
  1063. widget.Show(true);
  1064. widget_not_select.Show(false);
  1065. }
  1066. else
  1067. {
  1068. widget.Show(false);
  1069. widget_not_select.Show(true);
  1070. }
  1071. }
  1072. else
  1073. {
  1074. widget.Show(false);
  1075. widget_not_select.Show(false);
  1076. }
  1077. }
  1078. protected void SetInteractActionIcon(string actionWidget, string actionIconFrameWidget, string actionIconWidget, string actionIconTextWidget)
  1079. {
  1080. Widget widget;
  1081. ImageWidget iconWidget;
  1082. TextWidget textWidget;
  1083. widget = m_Root.FindAnyWidget(actionWidget);
  1084. Class.CastTo(iconWidget, widget.FindAnyWidget(actionIconWidget));
  1085. Class.CastTo(textWidget, widget.FindAnyWidget(actionIconTextWidget));
  1086. GetDayZGame().GetBacklit().HintShow(m_UseActionWrapper.InputP());
  1087. // uses text in floating widget
  1088. iconWidget.Show(false);
  1089. textWidget.SetText(InputUtils.GetButtonNameFromInput("UAAction", EInputDeviceType.MOUSE_AND_KEYBOARD));
  1090. textWidget.Show(true);
  1091. }
  1092. protected void CheckRefresherFlagVisibilityEx(ActionTarget target)
  1093. {
  1094. EntityAI entity = EntityAI.Cast(target.GetObject());
  1095. if (!entity)
  1096. entity = EntityAI.Cast(target.GetParent());
  1097. if (!entity)
  1098. return;
  1099. Widget w = m_Root.FindAnyWidget("item_flag_icon");
  1100. if (w)
  1101. w.Show(entity.IsRefresherSignalingViable() && m_Player.IsTargetInActiveRefresherRange(entity));
  1102. }
  1103. protected int AttachmentsWithInventoryOrCargoCount(notnull GameInventory inventory)
  1104. {
  1105. int attachmentsWithInventory = 0;
  1106. CargoBase cargo = inventory.GetCargo();
  1107. if (cargo && cargo.GetItemCount() > 0)
  1108. {
  1109. return 1;
  1110. }
  1111. for (int i = 0; i < inventory.AttachmentCount(); i++)
  1112. {
  1113. EntityAI attachment = inventory.GetAttachmentFromIndex(i);
  1114. int attachmentSlotId = attachment.GetInventory().GetSlotId(0);
  1115. if (attachment.GetInventory())
  1116. {
  1117. attachmentsWithInventory += 1;
  1118. }
  1119. }
  1120. return attachmentsWithInventory;
  1121. }
  1122. protected IngameHud GetHud()
  1123. {
  1124. Mission mission = GetGame().GetMission();
  1125. if (mission)
  1126. {
  1127. IngameHud hud = IngameHud.Cast(mission.GetHud());
  1128. return hud;
  1129. }
  1130. return null;
  1131. }
  1132. // deprecated
  1133. protected void CheckRefresherFlagVisibility(Object object);
  1134. }