From 2f2f1ac39535ac671c4724514d4f3918f0e0fbf4 Mon Sep 17 00:00:00 2001 From: Mira Date: Sat, 21 Jul 2018 21:00:01 +0200 Subject: [PATCH] Pet's name shows, QuestItems now are Liked, No Monster If the current gift is a quest item it is by default set to Like. I'm unsure if it works because I dont have an easy to test save. Your pet name is shown. Monsters should now be ignored. --- RelationshipTooltips/ModEntry.cs | 75 +++++++++++++++++++++------ RelationshipTooltips/UI/Frame.cs | 2 +- RelationshipTooltips/UI/ShadowText.cs | 4 +- RelationshipTooltips/manifest.json | 2 +- 4 files changed, 64 insertions(+), 19 deletions(-) diff --git a/RelationshipTooltips/ModEntry.cs b/RelationshipTooltips/ModEntry.cs index 140e4b0..6aa4f3b 100644 --- a/RelationshipTooltips/ModEntry.cs +++ b/RelationshipTooltips/ModEntry.cs @@ -9,6 +9,7 @@ using StardewModdingAPI; using StardewModdingAPI.Events; using StardewValley; +using StardewValley.Quests; using StardewValley.Menus; namespace M3ales.RelationshipTooltips { @@ -39,7 +40,7 @@ public override void Entry(IModHelper helper) GameEvents.QuarterSecondTick += CheckForNPCUnderMouse; GraphicsEvents.OnPostRenderHudEvent += GraphicsEvents_OnPostRenderHudEvent; InputEvents.ButtonPressed += InputEvents_ButtonPressed; - t = new Tooltip(0, 0, Color.White, anchor:FrameAnchor.BottomLeft); + t = new Tooltip(0, 0, Color.White, anchor: FrameAnchor.BottomLeft); SaveEvents.AfterLoad += SaveEvents_AfterLoad; SaveEvents.AfterSave += SaveEvents_AfterSave; } @@ -50,10 +51,12 @@ public override void Entry(IModHelper helper) /// private void SaveEvents_AfterSave(object sender, EventArgs e) { - if (config.recordGiftInfo) { + if (config.recordGiftInfo) + { Helper.WriteJsonFile($"{Constants.CurrentSavePath}.json", giftSaveInfo); Monitor.Log($"Saved {Constants.CurrentSavePath}_RelationshipTooltips_GiftInfo.json"); - }else + } + else { Monitor.Log("Session data not saved, recordedGiftInfo: " + config.recordGiftInfo); } @@ -103,6 +106,7 @@ private void SaveEvents_AfterLoad(object sender, EventArgs e) /// If the player has never given the gift, and the feature is enabled then this represents an unknown gift response /// private const int NPC_GIFT_OPINION_UNKNOWN = -2; + private const int NPC_GIFT_OPINION_QUEST_ITEM = -3; /// /// The NPC's taste value towards an item, Null if = NPCGiftOpinionNull /// @@ -120,6 +124,23 @@ private bool FriendshipKnowsGifts(NPC npc) { return Game1.player.getFriendshipHeartLevelForNPC(npc.name) >= config.heartLevelToKnowAllGifts; } + public bool IsItemQuestGift(NPC target, Item heldItem) + { + foreach (Quest q in Game1.player.questLog) + { + if (q.questType == Quest.type_itemDelivery) + { + ItemDeliveryQuest quest = q as ItemDeliveryQuest; + if (quest == null) + break; + if (quest.target.Value == target.Name && quest.deliveryItem.Value.Name == heldItem.Name) + { + return true; + } + } + } + return false; + } /// /// Checks for NPC under the mouse, if one is found a gift may also be cached if the player is holding an applicable item. /// @@ -131,24 +152,41 @@ private void CheckForNPCUnderMouse(object sender, EventArgs e) { if (NPCUtils.TryGetNPCUnderCursor(out selectedNPC)) { - if (firstHoverTick) { + if (selectedNPC.IsMonster) + { + selectedNPC = null; + selectedGift = null; + selectedNPCGiftOpinion = NPC_GIFT_OPINION_NULL; + return; + } + if (firstHoverTick) + { Monitor.Log(String.Format("NPC '{0}' under cursor.", selectedNPC.Name)); } - if(config.displayGiftInfo && Game1.player.CurrentItem != null && Game1.player.CurrentItem.canBeGivenAsGift()) + if (config.displayGiftInfo && Game1.player.CurrentItem != null && Game1.player.CurrentItem.canBeGivenAsGift()) { selectedGift = Game1.player.CurrentItem; - if (config.playerKnowsAllGifts || (config.recordGiftInfo && giftSaveInfo.PlayerHasGifted(selectedNPC.name, selectedGift.Name)) || (config.recordGiftInfo && FriendshipKnowsGifts(selectedNPC))) + if (!IsItemQuestGift(selectedNPC, selectedGift)) { - selectedNPCGiftOpinion = selectedNPC.getGiftTasteForThisItem(selectedGift); - }else + if (config.playerKnowsAllGifts || (config.recordGiftInfo && giftSaveInfo.PlayerHasGifted(selectedNPC.name, selectedGift.Name)) || (config.recordGiftInfo && FriendshipKnowsGifts(selectedNPC))) + { + selectedNPCGiftOpinion = selectedNPC.getGiftTasteForThisItem(selectedGift); + } + else + { + selectedNPCGiftOpinion = NPC_GIFT_OPINION_UNKNOWN; + } + } + else { - selectedNPCGiftOpinion = NPC_GIFT_OPINION_UNKNOWN; + selectedNPCGiftOpinion = NPC_GIFT_OPINION_QUEST_ITEM; } if (firstHoverTick) { - Monitor.Log(String.Format("Gift '{0}' in player's hands. It's response is {1}. :: because of giftSaveInfo?{2}, because of heartlevel? {3}", Game1.player.CurrentItem.Name, selectedNPCGiftOpinion == NPC_GIFT_OPINION_UNKNOWN ? "unknown" : "known", giftSaveInfo.PlayerHasGifted(selectedNPC.name, selectedGift.Name), FriendshipKnowsGifts(selectedNPC))); + Monitor.Log(String.Format("Gift '{0}' in player's hands. It's response is {1}. :: giftSaveInfo?{2}, heartlevel? {3}", Game1.player.CurrentItem.Name, selectedNPCGiftOpinion == NPC_GIFT_OPINION_UNKNOWN ? "unknown" : "known", giftSaveInfo.PlayerHasGifted(selectedNPC.name, selectedGift.Name), FriendshipKnowsGifts(selectedNPC))); } - }else + } + else { selectedNPCGiftOpinion = NPC_GIFT_OPINION_NULL; selectedGift = null; @@ -171,7 +209,8 @@ private void InputEvents_ButtonPressed(object sender, EventArgsInput e) { if (config.recordGiftInfo && e.Button.IsActionButton() && selectedNPC != null && selectedGift != null) {//not great solution but these are conditions needed to work as far as I can see. - if (Game1.player.friendshipData.ContainsKey(selectedNPC.name)){ + if (Game1.player.friendshipData.ContainsKey(selectedNPC.name)) + { if (Game1.player.friendshipData[selectedNPC.name].GiftsToday == 0) { Monitor.Log($"Recorded gift '{selectedGift.Name}' to '{selectedNPC.Name}'"); @@ -199,7 +238,8 @@ private string GetHeartString(int level, int maxLevel, int amount) string flavourText = "null"; if (selectedNPC == null) return "null"; - if (Game1.player.friendshipData.TryGetValue(selectedNPC.name, out Friendship friendship)){ + if (Game1.player.friendshipData.TryGetValue(selectedNPC.name, out Friendship friendship)) + { FriendshipStatus status = friendship.Status; switch (status) { @@ -260,14 +300,14 @@ private string GetHeartString(int level, int maxLevel, int amount) } } return flavourText + level + "/" + maxLevel + " (" + amount + ")"; - } + } /// /// Appends the gift info to a given string /// /// The string to append the giftinfo to private void AddGiftString(ref string display) { - display += "\n" +config.gift + ": "; + display += "\n" + config.gift + ": "; switch (selectedNPCGiftOpinion) { case NPC.gift_taste_love: @@ -276,6 +316,7 @@ private void AddGiftString(ref string display) break; } case NPC.gift_taste_like: + case NPC_GIFT_OPINION_QUEST_ITEM: { display += config.giftLikes; break; @@ -345,6 +386,10 @@ private void GraphicsEvents_OnPostRenderHudEvent(object sender, EventArgs e) AddGiftString(ref display); } } + else if (selectedNPC.Name == Game1.player.getPetName()) + { + npcName = Game1.player.getPetDisplayName(); + } t.localX = Game1.getMouseX(); t.localY = Game1.getMouseY(); t.header.text = npcName; diff --git a/RelationshipTooltips/UI/Frame.cs b/RelationshipTooltips/UI/Frame.cs index d69fac6..fd94c81 100644 --- a/RelationshipTooltips/UI/Frame.cs +++ b/RelationshipTooltips/UI/Frame.cs @@ -123,7 +123,7 @@ public int Width { if (components != null) if (components.Count > 0) - return components.Sum(c => c.SizeX); + return components.Max(x=>x.SizeX); return 0; } } diff --git a/RelationshipTooltips/UI/ShadowText.cs b/RelationshipTooltips/UI/ShadowText.cs index c2477dc..98d322c 100644 --- a/RelationshipTooltips/UI/ShadowText.cs +++ b/RelationshipTooltips/UI/ShadowText.cs @@ -33,7 +33,7 @@ public int SizeX get { if (font != null) - return (int)(font == Game1.dialogueFont ? 0.25f* font.MeasureString(text).X : font.MeasureString(text).X) + (xPadding*2); + return (int)(font == Game1.dialogueFont ? 1f* font.MeasureString(text).X : font.MeasureString(text).X) + (xPadding*2); return 0; } } @@ -43,7 +43,7 @@ public int SizeY get { if (font != null) - return (int)(font == Game1.dialogueFont ? 0.1f* font.MeasureString(text).Y : font.MeasureString(text).Y) + (yPadding*2); + return (int)(font == Game1.dialogueFont ? 0.25f* font.MeasureString(text).Y : font.MeasureString(text).Y) + (yPadding*2); return 0; } } diff --git a/RelationshipTooltips/manifest.json b/RelationshipTooltips/manifest.json index ee14374..7e1cbc0 100644 --- a/RelationshipTooltips/manifest.json +++ b/RelationshipTooltips/manifest.json @@ -1,7 +1,7 @@ { "Name": "Relationship Tooltips", "Author": "M3ales", - "Version": "1.2.0-beta.3", + "Version": "1.2.0-beta.4", "Description": "Displays NPC relationship tooltip on mouseover, configurable", "UniqueID": "M3ales.RelationshipTooltips", "EntryDll": "RelationshipTooltips.dll",