Skip to content

Commit

Permalink
Pet's name shows, QuestItems now are Liked, No Monster
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
M3ales committed Jul 21, 2018
1 parent 2295a67 commit 2f2f1ac
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 19 deletions.
75 changes: 60 additions & 15 deletions RelationshipTooltips/ModEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using StardewModdingAPI;
using StardewModdingAPI.Events;
using StardewValley;
using StardewValley.Quests;
using StardewValley.Menus;
namespace M3ales.RelationshipTooltips
{
Expand Down Expand Up @@ -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;
}
Expand All @@ -50,10 +51,12 @@ public override void Entry(IModHelper helper)
/// <param name="e"></param>
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);
}
Expand Down Expand Up @@ -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
/// </summary>
private const int NPC_GIFT_OPINION_UNKNOWN = -2;
private const int NPC_GIFT_OPINION_QUEST_ITEM = -3;
/// <summary>
/// The NPC's taste value towards an item, Null if = NPCGiftOpinionNull
/// </summary>
Expand All @@ -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;
}
/// <summary>
/// Checks for NPC under the mouse, if one is found a gift may also be cached if the player is holding an applicable item.
/// </summary>
Expand All @@ -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;
Expand All @@ -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}'");
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -260,14 +300,14 @@ private string GetHeartString(int level, int maxLevel, int amount)
}
}
return flavourText + level + "/" + maxLevel + " (" + amount + ")";
}
}
/// <summary>
/// Appends the gift info to a given string
/// </summary>
/// <param name="display">The string to append the giftinfo to</param>
private void AddGiftString(ref string display)
{
display += "\n" +config.gift + ": ";
display += "\n" + config.gift + ": ";
switch (selectedNPCGiftOpinion)
{
case NPC.gift_taste_love:
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion RelationshipTooltips/UI/Frame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions RelationshipTooltips/UI/ShadowText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion RelationshipTooltips/manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 2f2f1ac

Please sign in to comment.