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