private static void Postfix(ref HotkeyBar __instance, ref Player player) { if (Configuration.Current.Hud.IsEnabled && Configuration.Current.Hud.displayBowAmmoCounts > 0) { DisplayAmmoCountsUnderBowHotbarIcon(__instance, player); } }
public static void Postfix(HotkeyBar __instance, List <HotkeyBar.ElementData> ___m_elements, List <ItemDrop.ItemData> ___m_items, Player player) { if (player == null || player.IsDead()) { return; } for (var index = 0; index < ___m_elements.Count; index++) { var element = ___m_elements[index]; var magicItem = ItemBackgroundHelper.CreateAndGetMagicItemBackgroundImage(element.m_go, element.m_equiped, false); magicItem.enabled = false; } for (var index = 0; index < ___m_items.Count; ++index) { var itemData = ___m_items[index]; var element = GetElementForItem(___m_elements, itemData); if (element == null) { EpicLoot.LogWarning($"Tried to get element for {itemData.m_shared.m_name} at {itemData.m_gridPos}, but element was null (total elements = {___m_elements.Count})"); continue; } var magicItem = ItemBackgroundHelper.CreateAndGetMagicItemBackgroundImage(element.m_go, element.m_equiped, false); if (itemData.UseMagicBackground()) { magicItem.enabled = true; magicItem.sprite = EpicLoot.GetMagicItemBgSprite(); magicItem.color = itemData.GetRarityColor(); } } }
private static void PatchHotkeyBar(ref HotkeyBar __instance, ref Player player) { if (!player || player.IsDead()) { return; } if (!Main.showDurabilityColor.Value) { return; } foreach (ItemDrop.ItemData itemData in __instance.m_items) { HotkeyBar.ElementData element = __instance.m_elements[itemData.m_gridPos.x]; if (element.m_icon.transform.localScale == Vector3.one) { element.m_icon.transform.localScale *= Mathf.Max(Main.iconScaleSize.Value, 0.1f); } if (itemData.m_shared.m_useDurability) { if (itemData.m_durability <= 0f) // Item has no durability, original code should do this { //element.m_durability.SetValue(1f); //element.m_durability.SetColor((Mathf.Sin(Time.time * 10f) > 0f) ? Color.red : new Color(0f, 0f, 0f, 0f)); } else // Item has durability left { Patches.DurabilityBar.UpdateColor(element, itemData.GetDurabilityPercentage()); } } } }
private void InitPages() { //** MAIN PAGE *********************************** HotkeyBarItem startStopKey = new HotkeyBarItem(ConsoleKey.F4, "Start / Stop", HotKeyEventHandler_StateToggle); HotkeyBarItem optinsKey = new HotkeyBarItem(ConsoleKey.F6, "Options", HotKeyEventHandler_Options); HotkeyBarItem exitKey = new HotkeyBarItem(ConsoleKey.F10, "Exit", HotKeyEventHandler_Exit, 3); HotkeyBar mainBar = new HotkeyBar(4); mainBar.Items.Add(startStopKey); mainBar.Items.Add(optinsKey); mainBar.Items.Add(exitKey); mainPage = new ConsolePage <Service>(MainPagePrintHandler, service, mainBar); //** OPTIONS PAGE ******************************** HotkeyBarItem escKey1 = new HotkeyBarItem(ConsoleKey.Escape, "ESC", "Back", HotKeyEventHandler_OptionsCancel); HotkeyBarItem addKey = new HotkeyBarItem(ConsoleKey.Insert, "INS", "Add", HotKeyEventHandler_ListAdd); HotkeyBarItem removeKey = new HotkeyBarItem(ConsoleKey.Delete, "DEL", "Remove", HotKeyEventHandler_ListRem); HotkeyBarItem upKey = new HotkeyBarItem(ConsoleKey.UpArrow, " ↑", "", HotKeyEventHandler_ListUp); HotkeyBarItem downKey = new HotkeyBarItem(ConsoleKey.DownArrow, " ↓", "", HotKeyEventHandler_ListDown); HotkeyBarItem homeKey = new HotkeyBarItem(ConsoleKey.Home, "HOME", "", HotKeyEventHandler_ListStart); homeKey.Visible = false; HotkeyBarItem endKey = new HotkeyBarItem(ConsoleKey.End, "END", "", HotKeyEventHandler_ListEnd); endKey.Visible = false; HotkeyBar optionsBar = new HotkeyBar(4); optionsBar.Items.Add(escKey1); optionsBar.Items.Add(addKey); optionsBar.Items.Add(removeKey); optionsBar.Items.Add(exitKey); optionsBar.Items.Add(upKey); optionsBar.Items.Add(downKey); optionsBar.Items.Add(homeKey); optionsBar.Items.Add(endKey); optionsPage = new ConsolePage <Service>(OptionsPagePrintHandler, service, optionsBar); //** ADD EXECUTABLE PAGE ************************* HotkeyBarItem escKey2 = new HotkeyBarItem(ConsoleKey.Escape, "ESC", "Cancel", HotKeyEventHandler_CaptureModeCancel); HotkeyBarItem okKey = new HotkeyBarItem(ConsoleKey.Enter, " ENTER", "Add Executable", HotKeyEventHandler_CaptureModeOK); HotkeyBar addExeBar = new HotkeyBar(4); addExeBar.Items.Add(escKey2); addExeBar.Items.Add(okKey); addExeBar.Items.Add(exitKey); addExePage = new ConsolePage <Service>(AddExePagePrintHandler, service, addExeBar); }
public static void UpdateHotkeyBarInput(HotkeyBar hotkeyBar) { var player = Player.m_localPlayer; if (hotkeyBar.m_selected >= 0 && player != null && !InventoryGui.IsVisible() && !Menu.IsVisible() && !GameCamera.InFreeFly()) { if (ZInput.GetButtonDown("JoyDPadLeft")) { if (hotkeyBar.m_selected == 0) { GotoHotkeyBar(SelectedHotkeyBarIndex - 1); } else { hotkeyBar.m_selected = Mathf.Max(0, hotkeyBar.m_selected - 1); } } else if (ZInput.GetButtonDown("JoyDPadRight")) { if (hotkeyBar.m_selected == hotkeyBar.m_elements.Count - 1) { GotoHotkeyBar(SelectedHotkeyBarIndex + 1); } else { hotkeyBar.m_selected = Mathf.Min(hotkeyBar.m_elements.Count - 1, hotkeyBar.m_selected + 1); } } if (ZInput.GetButtonDown("JoyDPadUp")) { if (hotkeyBar.name == "QuickSlotsHotkeyBar") { var quickSlotInventory = player.GetQuickSlotInventory(); var item = quickSlotInventory.GetItemAt(hotkeyBar.m_selected, 0); player.UseItem(null, item, false); } else { player.UseHotbarItem(hotkeyBar.m_selected + 1); } } } if (hotkeyBar.m_selected > hotkeyBar.m_elements.Count - 1) { hotkeyBar.m_selected = Mathf.Max(0, hotkeyBar.m_elements.Count - 1); } }
public static void Postfix(HotkeyBar __instance) { foreach (var itemData in __instance.m_items) { var elementIndex = itemData.m_gridPos.x; if (elementIndex >= 0 && elementIndex < __instance.m_elements.Count) { HotkeyBar.ElementData element = __instance.m_elements[elementIndex]; if (itemData.HasMagicEffect(MagicEffectType.Indestructible)) { element.m_durability.gameObject.SetActive(false); } } } }
static void Postfix(HotkeyBar __instance) { if (!modEnabled.Value || !hideNumbers.Value || __instance.name != "HotKeyBar") { return; } int count = __instance.transform.childCount; for (int i = 0; i < count; i++) { if (__instance.transform.GetChild(i).Find("binding")) { } __instance.transform.GetChild(i).Find("binding").GetComponent <Text>().text = showHotkeys.Value ? hotkeys[i].Value : ""; } }
static void Postfix(HotkeyBar __instance) { if (!modEnabled.Value || Player.m_localPlayer == null || __instance.name != "HotKeyBar") { return; } int count = __instance.transform.childCount; float scaledSize = __instance.m_elementSpace * toolbarItemScale.Value; for (int i = 0; i < count; i++) { int x = i % toolbarItemsPerRow.Value; int y = i / toolbarItemsPerRow.Value; Transform t = __instance.transform.GetChild(i); t.GetComponent <RectTransform>().anchoredPosition = new Vector2(scaledSize * x, -scaledSize * y); t.GetComponent <RectTransform>().localScale = new Vector3(toolbarItemScale.Value, toolbarItemScale.Value, 1); //Dbgl($"element {i}, position {t.GetComponent<RectTransform>().anchoredPosition}"); } }
private void Awake() { inventory = FindObjectOfType <Inventory>(); equipmentPanel = FindObjectOfType <EquipmentPanel>(); hotkeyBar = FindObjectOfType <HotkeyBar>(); //inventory.OnRightClickEvent += EquipFormInventory; //equipmentPanel.OnRightClickEvent += UnequipFromEquipPanel; //滑鼠游標移動物品 20190221 //Setup Events: //Right Click inventory.OnRightClickEvent += InventoryRightClick; equipmentPanel.OnRightClickEvent += EquipmentPanelRightClick; //Pointer Enter inventory.OnPointerEnterEvent += ShowTooltip; equipmentPanel.OnPointerEnterEvent += ShowTooltip; //Pointer Exit inventory.OnPointerExitEvent += HideTooltip; equipmentPanel.OnPointerExitEvent += HideTooltip; //Begin Drag inventory.OnBeginDragEvent += BeginDrag; equipmentPanel.OnBeginDragEvent += BeginDrag; hotkeyBar.OnBeginDragEvent += BeginDrag; //End Drag inventory.OnEndDragEvent += EndDrag; equipmentPanel.OnEndDragEvent += EndDrag; hotkeyBar.OnEndDragEvent += EndDrag; //Drag inventory.OnDragEvent += Drag; equipmentPanel.OnDragEvent += Drag; hotkeyBar.OnDragEvent += Drag; //Drop inventory.OnDropEvent += Drop; equipmentPanel.OnDropEvent += Drop; //20190227 hotkeyBar.OnDropEvent += Drop; }
public static void Postfix(HotkeyBar __instance, List <HotkeyBar.ElementData> ___m_elements, List <ItemDrop.ItemData> ___m_items, Player player) { if (player == null || player.IsDead()) { return; } Dictionary <int, ItemDrop.ItemData> itemPosition = new Dictionary <int, ItemDrop.ItemData>(); foreach (ItemDrop.ItemData itemData in ___m_items) { if (GetElementIndexForItem(___m_elements, itemData) is int elementIndex) { itemPosition[elementIndex] = itemData; } else { EpicLoot.LogWarning($"Tried to get element for {itemData.m_shared.m_name} at {itemData.m_gridPos}, but element was null (total elements = {___m_elements.Count})"); } } for (var index = 0; index < ___m_elements.Count; index++) { var element = ___m_elements[index]; var magicItem = ItemBackgroundHelper.CreateAndGetMagicItemBackgroundImage(element.m_go, element.m_equiped, false); if (itemPosition.TryGetValue(index, out ItemDrop.ItemData itemData) && itemData.UseMagicBackground()) { magicItem.enabled = true; magicItem.sprite = EpicLoot.GetMagicItemBgSprite(); magicItem.color = itemData.GetRarityColor(); } else { magicItem.enabled = false; } } }
private void Awake() { inventory = GetComponentInChildren <Inventory>(); equipmentPanel = GetComponentInChildren <EquipmentPanel>(); hotkeyBar = GetComponentInChildren <HotkeyBar>(); //滑鼠游標移動物品 20190221 //Setup Events: //Right Click inventory.OnRightClickEvent += InventoryRightClick; equipmentPanel.OnRightClickEvent += EquipmentPanelRightClick; //Pointer Enter inventory.OnPointerEnterEvent += ShowTooltip; equipmentPanel.OnPointerEnterEvent += ShowTooltip; hotkeyBar.OnPointerEnterEvent += ShowTooltip; //Pointer Exit inventory.OnPointerExitEvent += HideTooltip; equipmentPanel.OnPointerExitEvent += HideTooltip; hotkeyBar.OnPointerExitEvent += HideTooltip; //Begin Drag inventory.OnBeginDragEvent += BeginDrag; equipmentPanel.OnBeginDragEvent += BeginDrag; hotkeyBar.OnBeginDragEvent += BeginDrag; //End Drag inventory.OnEndDragEvent += EndDrag; equipmentPanel.OnEndDragEvent += EndDrag; hotkeyBar.OnEndDragEvent += EndDrag; //Drag inventory.OnDragEvent += Drag; equipmentPanel.OnDragEvent += Drag; hotkeyBar.OnDragEvent += Drag; //Drop inventory.OnDropEvent += Drop; equipmentPanel.OnDropEvent += Drop; //20190227 hotkeyBar.OnDropEvent += Drop; }
static void Postfix(HotkeyBar __instance) { if (!started) { defaultPosition = __instance.gameObject.GetComponent <RectTransform>().anchoredPosition; int count = __instance.transform.childCount; if (count > 0) { started = true; } for (int i = 0; i < count; i++) { int x = i % itemsPerRow.Value; int y = i / itemsPerRow.Value; Transform t = __instance.transform.GetChild(i); t.GetComponent <RectTransform>().anchoredPosition = new Vector2(70 * x, -70 * y); Dbgl($"element {i}, position {t.GetComponent<RectTransform>().anchoredPosition}"); } } Vector3 mousePos = Input.mousePosition; if (!modEnabled.Value) { lastMousePos = mousePos; return; } Vector2 position = __instance.gameObject.GetComponent <RectTransform>().anchoredPosition; if (toolbarX.Value < 0) { toolbarX.Value = __instance.gameObject.GetComponent <RectTransform>().anchorMin.x *Screen.width; } if (toolbarY.Value < 0) { toolbarY.Value = __instance.gameObject.GetComponent <RectTransform>().anchorMax.y *Screen.height; } __instance.gameObject.GetComponent <RectTransform>().anchorMax = new Vector2(__instance.gameObject.GetComponent <RectTransform>().anchorMax.x, toolbarY.Value / Screen.height); __instance.gameObject.GetComponent <RectTransform>().anchorMin = new Vector2(toolbarX.Value / Screen.width, __instance.gameObject.GetComponent <RectTransform>().anchorMin.y); if (lastMousePos == Vector3.zero) { lastMousePos = mousePos; } PointerEventData eventData = new PointerEventData(EventSystem.current) { position = Input.mousePosition }; if (CheckKeyHeld(modKeyOne.Value) && CheckKeyHeld(modKeyTwo.Value)) { Rect rect = new Rect(__instance.gameObject.GetComponent <RectTransform>().anchorMin.x *Screen.width + __instance.gameObject.GetComponent <RectTransform>().anchoredPosition.x + 5, __instance.gameObject.GetComponent <RectTransform>().anchorMax.y *Screen.height - Mathf.CeilToInt(8f / itemsPerRow.Value) * 75 + __instance.gameObject.GetComponent <RectTransform>().anchoredPosition.y, itemsPerRow.Value * 75, Mathf.CeilToInt(8f / itemsPerRow.Value) * 75 + __instance.gameObject.GetComponent <RectTransform>().anchoredPosition.y); Dbgl($"Rect {rect}, mouse {mousePos}"); if (rect.Contains(mousePos)) { Dbgl($"dragging"); toolbarX.Value += mousePos.x - lastMousePos.x; toolbarY.Value += mousePos.y - lastMousePos.y; } } lastMousePos = mousePos; }
static void Postfix(HotkeyBar __instance) { if (!Player.m_localPlayer) { return; } int count = __instance.transform.childCount; if (count != Player.m_localPlayer.GetInventory().GetWidth()) { return; } Vector3 mousePos = Input.mousePosition; if (!modEnabled.Value) { lastMousePos = mousePos; return; } float scaledSize = itemSize * itemScale.Value; for (int i = 0; i < count; i++) { int x = i % itemsPerRow.Value; int y = i / itemsPerRow.Value; Transform t = __instance.transform.GetChild(i); t.GetComponent <RectTransform>().anchoredPosition = new Vector2(scaledSize * x, -scaledSize * y); t.GetComponent <RectTransform>().localScale = new Vector3(itemScale.Value, itemScale.Value, 1); //Dbgl($"element {i}, position {t.GetComponent<RectTransform>().anchoredPosition}"); } if (toolbarX.Value == -9999) { toolbarX.Value = __instance.gameObject.GetComponent <RectTransform>().anchorMin.x *Screen.width; } if (toolbarY.Value == -9999) { toolbarY.Value = __instance.gameObject.GetComponent <RectTransform>().anchorMax.y *Screen.height; } __instance.gameObject.GetComponent <RectTransform>().anchorMax = new Vector2(__instance.gameObject.GetComponent <RectTransform>().anchorMax.x, toolbarY.Value / Screen.height); __instance.gameObject.GetComponent <RectTransform>().anchorMin = new Vector2(toolbarX.Value / Screen.width, __instance.gameObject.GetComponent <RectTransform>().anchorMin.y); if (lastMousePos == Vector3.zero) { lastMousePos = mousePos; } if (CheckKeyHeld(modKeyOne.Value) && CheckKeyHeld(modKeyTwo.Value)) { Rect rect = new Rect(__instance.gameObject.GetComponent <RectTransform>().anchorMin.x *Screen.width + 47, __instance.gameObject.GetComponent <RectTransform>().anchorMax.y *Screen.height - Mathf.CeilToInt(8f / itemsPerRow.Value) * scaledSize * 1.5f - 44, itemsPerRow.Value * scaledSize * 1.5f, Mathf.CeilToInt(8f / itemsPerRow.Value) * scaledSize * 1.5f); if (rect.Contains(lastMousePos)) { toolbarX.Value += mousePos.x - lastMousePos.x; toolbarY.Value += mousePos.y - lastMousePos.y; } } lastMousePos = mousePos; }
public static bool Prefix(HotkeyBar __instance) { // Everything controlled in above update return(false); }
public static bool Prefix(HotkeyBar __instance, Player player) { if (__instance.name != "QuickSlotsHotkeyBar") { return(true); } if (player == null || player.IsDead()) { foreach (var element in __instance.m_elements) { Object.Destroy(element.m_go); } __instance.m_elements.Clear(); } else { player.GetQuickSlotInventory().GetBoundItems(__instance.m_items); __instance.m_items.Sort((x, y) => x.m_gridPos.x.CompareTo(y.m_gridPos.x)); const int showElementCount = EquipmentAndQuickSlots.QuickSlotCount; if (__instance.m_elements.Count != showElementCount) { foreach (var element in __instance.m_elements) { Object.Destroy(element.m_go); } __instance.m_elements.Clear(); for (var index = 0; index < showElementCount; ++index) { var elementData = new HotkeyBar.ElementData() { m_go = Object.Instantiate(__instance.m_elementPrefab, __instance.transform) }; elementData.m_go.transform.localPosition = new Vector3(index * __instance.m_elementSpace, 0.0f, 0.0f); elementData.m_icon = elementData.m_go.transform.transform.Find("icon").GetComponent <Image>(); elementData.m_durability = elementData.m_go.transform.Find("durability").GetComponent <GuiBar>(); elementData.m_amount = elementData.m_go.transform.Find("amount").GetComponent <Text>(); elementData.m_equiped = elementData.m_go.transform.Find("equiped").gameObject; elementData.m_queued = elementData.m_go.transform.Find("queued").gameObject; elementData.m_selection = elementData.m_go.transform.Find("selected").gameObject; var bindingText = elementData.m_go.transform.Find("binding").GetComponent <Text>(); bindingText.enabled = true; bindingText.horizontalOverflow = HorizontalWrapMode.Overflow; bindingText.text = EquipmentAndQuickSlots.GetBindingLabel(index); __instance.m_elements.Add(elementData); } } foreach (var element in __instance.m_elements) { element.m_used = false; } var isGamepadActive = ZInput.IsGamepadActive(); foreach (var itemData in __instance.m_items) { var element = __instance.m_elements[itemData.m_gridPos.x]; element.m_used = true; element.m_icon.gameObject.SetActive(true); element.m_icon.sprite = itemData.GetIcon(); element.m_durability.gameObject.SetActive(itemData.m_shared.m_useDurability); if (itemData.m_shared.m_useDurability) { if (itemData.m_durability <= 0.0) { element.m_durability.SetValue(1f); element.m_durability.SetColor((double)Mathf.Sin(Time.time * 10f) > 0.0 ? Color.red : new Color(0.0f, 0.0f, 0.0f, 0.0f)); } else { element.m_durability.SetValue(itemData.GetDurabilityPercentage()); element.m_durability.ResetColor(); } } element.m_equiped.SetActive(itemData.m_equiped); element.m_queued.SetActive(player.IsItemQueued(itemData)); if (itemData.m_shared.m_maxStackSize > 1) { element.m_amount.gameObject.SetActive(true); element.m_amount.text = itemData.m_stack.ToString() + "/" + itemData.m_shared.m_maxStackSize.ToString(); } else { element.m_amount.gameObject.SetActive(false); } } for (var index = 0; index < __instance.m_elements.Count; ++index) { var element = __instance.m_elements[index]; element.m_selection.SetActive(isGamepadActive && index == __instance.m_selected); if (!element.m_used) { element.m_icon.gameObject.SetActive(false); element.m_durability.gameObject.SetActive(false); element.m_equiped.SetActive(false); element.m_queued.SetActive(false); element.m_amount.gameObject.SetActive(false); } } } return(false); }
public static bool Prefix(HotkeyBar __instance, Player player, List <HotkeyBar.ElementData> ___m_elements, List <ItemDrop.ItemData> ___m_items, int ___m_selected) { if (!EquipmentAndQuickSlots.QuickSlotsEnabled.Value) { return(true); } if (player == null || player.IsDead()) { foreach (HotkeyBar.ElementData element in ___m_elements) { UnityEngine.Object.Destroy((UnityEngine.Object)element.m_go); } ___m_elements.Clear(); } else { player.GetInventory().GetBoundItems(___m_items); ___m_items.Sort((Comparison <ItemDrop.ItemData>)((a, b) => a.m_gridPos.y == b.m_gridPos.y ? a.m_gridPos.x.CompareTo(b.m_gridPos.x) : a.m_gridPos.y.CompareTo(b.m_gridPos.y))); int num = player.GetInventory().m_width + EquipmentAndQuickSlots.QuickUseSlotCount; if (___m_elements.Count != num) { foreach (HotkeyBar.ElementData element in ___m_elements) { UnityEngine.Object.Destroy((UnityEngine.Object)element.m_go); } ___m_elements.Clear(); for (int index = 0; index < num; ++index) { var parent = __instance.transform; if (index >= 8) { parent = __instance.transform.parent.Find("healthpanel"); } HotkeyBar.ElementData elementData = new HotkeyBar.ElementData() { m_go = UnityEngine.Object.Instantiate <GameObject>(__instance.m_elementPrefab, parent) }; if (index < 8) { elementData.m_go.transform.localPosition = new Vector3(index * __instance.m_elementSpace, 0.0f, 0.0f); elementData.m_go.transform.Find("binding").GetComponent <Text>().text = (index + 1).ToString(); } else { var offset = new Vector2(100, -150); var quickSlotIndex = index - 8; elementData.m_go.transform.localPosition = new Vector3(offset.x, offset.y - quickSlotIndex * __instance.m_elementSpace, 0.0f); elementData.m_go.transform.localEulerAngles = new Vector3(0, 0, -90); string label = EquipmentAndQuickSlots.GetBindingLabel(quickSlotIndex); var bindingText = elementData.m_go.transform.Find("binding").GetComponent <Text>(); bindingText.text = label; bindingText.horizontalOverflow = HorizontalWrapMode.Overflow; } elementData.m_icon = elementData.m_go.transform.transform.Find("icon").GetComponent <Image>(); elementData.m_durability = elementData.m_go.transform.Find("durability").GetComponent <GuiBar>(); elementData.m_amount = elementData.m_go.transform.Find("amount").GetComponent <Text>(); elementData.m_equiped = elementData.m_go.transform.Find("equiped").gameObject; elementData.m_queued = elementData.m_go.transform.Find("queued").gameObject; elementData.m_selection = elementData.m_go.transform.Find("selected").gameObject; ___m_elements.Add(elementData); } } foreach (HotkeyBar.ElementData element in ___m_elements) { element.m_used = false; } bool isGamepadActive = ZInput.IsGamepadActive(); for (int index = 0; index < ___m_items.Count; ++index) { ItemDrop.ItemData itemData = ___m_items[index]; HotkeyBar.ElementData element = GetElementForItem(___m_elements, itemData); element.m_used = true; element.m_icon.gameObject.SetActive(true); element.m_icon.sprite = itemData.GetIcon(); element.m_durability.gameObject.SetActive(itemData.m_shared.m_useDurability); if (itemData.m_shared.m_useDurability) { if (itemData.m_durability <= 0.0f) { element.m_durability.SetValue(1.0f); element.m_durability.SetColor(Mathf.Sin(Time.time * 10.0f) > 0.0f ? Color.red : new Color(0.0f, 0.0f, 0.0f, 0.0f)); } else { element.m_durability.SetValue(itemData.GetDurabilityPercentage()); element.m_durability.ResetColor(); } } element.m_equiped.SetActive(itemData.m_equiped); element.m_queued.SetActive(player.IsItemQueued(itemData)); if (itemData.m_shared.m_maxStackSize > 1) { element.m_amount.gameObject.SetActive(true); element.m_amount.text = $"{itemData.m_stack}/{itemData.m_shared.m_maxStackSize}"; } else { element.m_amount.gameObject.SetActive(false); } } for (int index = 0; index < ___m_elements.Count; ++index) { HotkeyBar.ElementData element = ___m_elements[index]; element.m_selection.SetActive(isGamepadActive && index == ___m_selected); if (!element.m_used) { element.m_icon.gameObject.SetActive(false); element.m_durability.gameObject.SetActive(false); element.m_equiped.SetActive(false); element.m_queued.SetActive(false); element.m_amount.gameObject.SetActive(false); } } } return(false); }
private static void DisplayAmmoCountsUnderBowHotbarIcon(HotkeyBar __instance, Player player) { GameObject ammoCounter = GameObject.Find(hudObjectName); // Find the bow in the hotbar ItemDrop.ItemData bow = null; foreach (ItemDrop.ItemData item in __instance.m_items) { if (item.m_shared.m_itemType == ItemDrop.ItemData.ItemType.Bow) { if (bow == null || player.IsItemEquiped(item)) { bow = item; } } } // If there is no bow or it is not equipped, remove the text element if (bow == null || (Configuration.Current.Hud.displayBowAmmoCounts == 1 && !player.IsItemEquiped(bow))) { if (ammoCounter != null) { GameObject.Destroy(ammoCounter); ammoCounter = null; } return; } // Make sure we have a valid index if (__instance.m_elements.Count >= bow.m_gridPos.x && bow.m_gridPos.x >= 0) { // Create a new text element to display the ammo counts HotkeyBar.ElementData element = __instance.m_elements[bow.m_gridPos.x]; if (ammoCounter == null) { ammoCounter = GameObject.Instantiate(element.m_amount.gameObject, element.m_amount.gameObject.transform.parent, false); ammoCounter.name = hudObjectName; ammoCounter.SetActive(true); Vector3 offset = element.m_amount.gameObject.transform.position - element.m_icon.transform.position; ammoCounter.transform.Translate(offset); Text ammoText = ammoCounter.GetComponentInChildren <Text>(); ammoText.fontSize -= 2; } // Attach it to the hotbar icon ammoCounter.gameObject.transform.SetParent(element.m_amount.gameObject.transform.parent, false); // Find the active ammo being used for thebow ItemDrop.ItemData ammoItem = player.m_ammoItem; if (ammoItem == null) { ammoItem = player.GetInventory().GetAmmoItem(bow.m_shared.m_ammoType); } // Calculate totals to display for current ammo type and all types int currentAmmo = 0; int totalAmmo = 0; var inventoryItems = player.GetInventory().GetAllItems(); foreach (ItemDrop.ItemData inventoryItem in inventoryItems) { if (inventoryItem.m_shared.m_ammoType == bow.m_shared.m_ammoType && (inventoryItem.m_shared.m_itemType == ItemDrop.ItemData.ItemType.Ammo || inventoryItem.m_shared.m_itemType == ItemDrop.ItemData.ItemType.Consumable)) { totalAmmo += inventoryItem.m_stack; if (inventoryItem.m_shared.m_name == ammoItem.m_shared.m_name) { currentAmmo += inventoryItem.m_stack; } } } // Change the visual display text for the UI Text ammoCounterText = ammoCounter.GetComponentInChildren <Text>(); if (totalAmmo == 0) { ammoCounterText.text = noAmmoDisplay; } else { ammoCounterText.text = ammoItem.m_shared.m_name.Split('_').Last() + " " + currentAmmo + "/" + totalAmmo; } } }