/// <summary> /// Sets the ping text and sprite color for a given <see cref="PingIndicator"/> /// </summary> /// <param name="pingIndicator">Target <see cref="PingIndicator"/></param> private void SetPingIndicatorColor(RoR2.UI.PingIndicator pingIndicator) { SpriteRenderer sprRenderer; Color textColor = new Color(0, 0, 0, 0); RoR2.UI.PingIndicator.PingType pingType = pingIndicator.GetObjectValue <RoR2.UI.PingIndicator.PingType>("pingType"); switch (pingType) { case RoR2.UI.PingIndicator.PingType.Default: textColor = _colors["DefaultPingColor"]; sprRenderer = pingIndicator.defaultPingGameObjects[0].GetComponent <SpriteRenderer>(); sprRenderer.color = _colors["DefaultPingSpriteColor"]; break; case RoR2.UI.PingIndicator.PingType.Enemy: textColor = _colors["EnemyPingColor"]; sprRenderer = pingIndicator.enemyPingGameObjects[0].GetComponent <SpriteRenderer>(); sprRenderer.color = _colors["EnemyPingSpriteColor"]; break; case RoR2.UI.PingIndicator.PingType.Interactable: textColor = _colors["InteractiblePingColor"]; sprRenderer = pingIndicator.interactablePingGameObjects[0].GetComponent <SpriteRenderer>(); sprRenderer.color = _colors["InteractiblePingSpriteColor"]; break; } pingIndicator.pingText.color = textColor; }
/// <summary> /// Adds text labels for various interactibles to a <see cref="PingIndicator"/> /// </summary> /// <param name="pingIndicator">Target <see cref="PingIndicator"/> that should have the text added</param> private static void AddLootText(RoR2.UI.PingIndicator pingIndicator) { const string textStart = "<size=70%>\n"; string price = GetPrice(pingIndicator.pingTarget); ShopTerminalBehavior shopTerminal = pingIndicator.pingTarget.GetComponent <ShopTerminalBehavior>(); if (shopTerminal && _config.ShowShopText.Value) { string text = textStart; PickupIndex pickupIndex = shopTerminal.CurrentPickupIndex(); PickupDef pickup = PickupCatalog.GetPickupDef(pickupIndex); text += shopTerminal.pickupIndexIsHidden ? "?" : $"{Language.GetString(pickup.nameToken)}"; pingIndicator.pingText.text += $"{text} ({price})"; return; } GenericPickupController pickupController = pingIndicator.pingTarget.GetComponent <GenericPickupController>(); if (pickupController && _config.ShowPickupText.Value) { PickupDef pickup = PickupCatalog.GetPickupDef(pickupController.pickupIndex); pingIndicator.pingText.text += $"{textStart}{Language.GetString(pickup.nameToken)}"; } ChestBehavior chest = pingIndicator.pingTarget.GetComponent <ChestBehavior>(); if (chest && _config.ShowChestText.Value) { pingIndicator.pingText.text += $"{textStart}{Util.GetBestBodyName(pingIndicator.pingTarget)} ({price})"; return; } string name = ""; PurchaseInteraction purchaseInteraction = pingIndicator.pingTarget.GetComponent <PurchaseInteraction>(); if (purchaseInteraction) { name = Language.GetString(purchaseInteraction.displayNameToken); } // Drones SummonMasterBehavior summonMaster = pingIndicator.pingTarget.GetComponent <SummonMasterBehavior>(); if (summonMaster && _config.ShowDroneText.Value) { pingIndicator.pingText.text += $"{textStart}{name} ({price})"; return; } if (_config.ShowShrineText.Value) { pingIndicator.pingText.text += $"{textStart}{name}"; } }
/// <summary> /// Adds name labels for targeted enemies to a <see cref="PingIndicator"/> /// </summary> /// <param name="pingIndicator">Target <see cref="PingIndicator"/> that should have the text added</param> private static void AddEnemyText(RoR2.UI.PingIndicator pingIndicator) { const string textStart = "<size=70%>\n"; string name = Util.GetBestBodyName(pingIndicator.pingTarget); if (_config.ShowEnemyText.Value) { pingIndicator.pingText.text += $"{textStart}{name}"; } }
/// <summary> /// Override method for RoR2.PingerController.SetCurrentPing /// </summary> public void SetCurrentPing(On.RoR2.PingerController.orig_SetCurrentPing orig, RoR2.PingerController self, RoR2.PingerController.PingInfo newPingInfo) { // For some reason, if you ping somewhere that is not pingable, it will create a // Ping at 0,0,0. If that happens, we just leave, since that isn't possible in the // regular game either, or if so, not at exactly those coordinates if (newPingInfo.origin == Vector3.zero) { return; } // If the targeted game object already has a ping, don't do anything // This is here to avoid stacking of different player pings on interactables if (newPingInfo.targetGameObject != null && _pingIndicators.Any(indicator => indicator && indicator.pingTarget == newPingInfo.targetGameObject)) { return; } self.NetworkcurrentPing = newPingInfo; // Here we create an instance of PingIndicator // since we're not jumping into PingerController.RebuildPing() to create one. GameObject go = (GameObject)Object.Instantiate(Resources.Load("Prefabs/PingIndicator")); RoR2.UI.PingIndicator pingIndicator = go.GetComponent <RoR2.UI.PingIndicator>(); pingIndicator.pingOwner = self.gameObject; pingIndicator.pingOrigin = newPingInfo.origin; pingIndicator.pingNormal = newPingInfo.normal; pingIndicator.pingTarget = newPingInfo.targetGameObject; pingIndicator.RebuildPing(); RoR2.UI.PingIndicator.PingType pingType = pingIndicator.GetObjectValue <RoR2.UI.PingIndicator.PingType>("pingType"); _painter.SetPingIndicatorColor(pingIndicator, pingType); _textBuilder.SetPingText(pingIndicator, pingType); SetPingTimer(pingIndicator, pingType); if (pingType == RoR2.UI.PingIndicator.PingType.Interactable) { _notificationBuilder.SetUnlockedItemNotification(pingIndicator); } // We add the ping indicator to our own local list _pingIndicators.Add(pingIndicator); if (self.hasAuthority) { self.CallCmdPing(self.currentPing); } }
public void SetUnlockedItemNotification(RoR2.UI.PingIndicator pingIndicator) { GenericPickupController pickupController = pingIndicator.pingTarget.GetComponent <GenericPickupController>(); if (pickupController && _config.ShowItemNotification.Value) { BuildNotification(pickupController.pickupIndex, pingIndicator); } PurchaseInteraction purchaseInteraction = pingIndicator.pingTarget.GetComponent <PurchaseInteraction>(); if (purchaseInteraction && _config.ShowItemNotification.Value) { ShopTerminalBehavior shopTerminalBehavior = purchaseInteraction.GetComponent <ShopTerminalBehavior>(); if (shopTerminalBehavior && !shopTerminalBehavior.pickupIndexIsHidden) { BuildNotification(shopTerminalBehavior.CurrentPickupIndex(), pingIndicator); } } }
private void SetPingTimer(RoR2.UI.PingIndicator pingIndicator, RoR2.UI.PingIndicator.PingType pingType) { float fixedTimer = 0f; switch (pingType) { case RoR2.UI.PingIndicator.PingType.Default: fixedTimer = _config.DefaultPingLifetime.Value; break; case RoR2.UI.PingIndicator.PingType.Enemy: fixedTimer = _config.EnemyPingLifetime.Value; break; case RoR2.UI.PingIndicator.PingType.Interactable: fixedTimer = _config.InteractablePingLifetime.Value; break; } pingIndicator.SetObjectValue("fixedTimer", fixedTimer); }
private void BuildNotification(PickupIndex pickupIndex, RoR2.UI.PingIndicator pingIndicator) { LocalUser localUser = LocalUserManager.GetFirstLocalUser(); if (localUser.currentNetworkUser.userName == Util.GetBestMasterName(pingIndicator.pingOwner.GetComponent <CharacterMaster>())) { if (localUser.userProfile.HasDiscoveredPickup(pickupIndex)) { PickupDef pickup = PickupCatalog.GetPickupDef(pickupIndex); ItemDef item = ItemCatalog.GetItemDef(pickup.itemIndex); EquipmentDef equip = EquipmentCatalog.GetEquipmentDef(pickup.equipmentIndex); ArtifactDef artifact = ArtifactCatalog.GetArtifactDef(pickup.artifactIndex); GenericNotification notification = Object .Instantiate(Resources.Load <GameObject>("Prefabs/NotificationPanel2")) .GetComponent <GenericNotification>(); if (item != null) { notification.SetItem(item); } else if (equip != null) { notification.SetEquipment(equip); } else if (artifact != null) { notification.SetArtifact(artifact); } notification.transform.SetParent(RoR2Application.instance.mainCanvas.transform, false); notification.transform.position = new Vector3(notification.transform.position.x + 2, 95, 0); } } }