Merge pull request #23 from Pathoschild/update-code

Update for SMAPI 3.0
This commit is contained in:
cdaragorn 2019-01-06 20:53:45 -07:00 committed by GitHub
commit ae8db24605
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 592 additions and 921 deletions

View File

@ -3,10 +3,6 @@ using StardewModdingAPI;
using StardewValley;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Resources;
using System.Text;
using System.Threading.Tasks;
namespace UIInfoSuite.Extensions
{
@ -77,31 +73,5 @@ namespace UIInfoSuite.Extensions
return result;
}
public static String SafeGetString(this ResourceManager manager, String key)
{
String result = string.Empty;
if (!String.IsNullOrEmpty(key))
{
try
{
result = manager.GetString(key, ModEntry.SpecificCulture);
}
catch
{
try
{
result = Properties.Resources.ResourceManager.GetString(key);
}
catch
{
}
}
}
return result ?? String.Empty;
}
}
}

View File

@ -1,9 +1,4 @@
using Microsoft.Xna.Framework.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StardewModdingAPI;
namespace UIInfoSuite
{
@ -11,7 +6,7 @@ namespace UIInfoSuite
{
public string[] KeysForBarrelAndCropTimes { get; set; } = new string[]
{
Keys.LeftShift.ToString()
SButton.LeftShift.ToString()
};
public bool CanRightClickForBarrelAndCropTimes { get; set; } = true;

View File

@ -3,56 +3,37 @@ using UIInfoSuite.UIElements;
using StardewModdingAPI;
using StardewModdingAPI.Events;
using StardewValley;
using StardewValley.Menus;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Globalization;
using static StardewValley.LocalizedContentManager;
using System.Resources;
using System.Reflection;
namespace UIInfoSuite
{
public class ModEntry : Mod
{
private readonly SkipIntro _skipIntro = new SkipIntro();
private SkipIntro _skipIntro;
private String _modDataFileName;
private readonly Dictionary<String, String> _options = new Dictionary<string, string>();
public static IMonitor MonitorObject { get; private set; }
public static CultureInfo SpecificCulture { get; private set; }
//public static ResourceManager Resources { get; private set; }
//public static IModHelper Helper { get; private set; }
private ModOptionsPageHandler _modOptionsPageHandler;
public ModEntry()
{
}
~ModEntry()
{
}
/// <summary>The mod entry point, called after the mod is first loaded.</summary>
/// <param name="helper">Provides simplified APIs for writing mods.</param>
public override void Entry(IModHelper helper)
{
//Helper = helper;
MonitorObject = Monitor;
_skipIntro = new SkipIntro(helper.Events);
Monitor.Log("starting.", LogLevel.Debug);
SaveEvents.AfterLoad += LoadModData;
SaveEvents.AfterSave += SaveModData;
SaveEvents.AfterReturnToTitle += ReturnToTitle;
GraphicsEvents.OnPreRenderEvent += IconHandler.Handler.Reset;
LocalizedContentManager.OnLanguageChange += LocalizedContentManager_OnLanguageChange;
LocalizedContentManager_OnLanguageChange(LocalizedContentManager.CurrentLanguageCode);
helper.Events.GameLoop.SaveLoaded += OnSaveLoaded;
helper.Events.GameLoop.Saved += OnSaved;
helper.Events.GameLoop.ReturnedToTitle += OnReturnedToTitle;
helper.Events.Display.Rendering += IconHandler.Handler.Reset;
//Resources = new ResourceManager("UIInfoSuite.Resource.strings", Assembly.GetAssembly(typeof(ModEntry)));
//try
@ -66,19 +47,18 @@ namespace UIInfoSuite
//}
}
private void LocalizedContentManager_OnLanguageChange(LanguageCode code)
{
String cultureString = code.ToString();
SpecificCulture = CultureInfo.CreateSpecificCulture(cultureString);
}
private void ReturnToTitle(object sender, EventArgs e)
/// <summary>Raised after the game returns to the title screen.</summary>
/// <param name="sender">The event sender.</param>
private void OnReturnedToTitle(object sender, ReturnedToTitleEventArgs e)
{
_modOptionsPageHandler?.Dispose();
_modOptionsPageHandler = null;
}
private void SaveModData(object sender, EventArgs e)
/// <summary>Raised after the game finishes writing data to the save file (except the initial save creation).</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnSaved(object sender, EventArgs e)
{
if (!String.IsNullOrWhiteSpace(_modDataFileName))
{
@ -103,9 +83,11 @@ namespace UIInfoSuite
}
}
private void LoadModData(object sender, EventArgs e)
/// <summary>Raised after the player loads a save slot and the world is initialised.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnSaveLoaded(object sender, SaveLoadedEventArgs e)
{
String playerName = Game1.player.Name;
try
{
try

View File

@ -4,9 +4,6 @@ using StardewValley;
using StardewValley.Menus;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework.Graphics;
using StardewModdingAPI.Events;
@ -27,7 +24,7 @@ namespace UIInfoSuite.Options
private ClickableTextureComponent _scrollBar;
private Rectangle _scrollBarRunner;
public ModOptionsPage(List<ModOptionsElement> options)
public ModOptionsPage(List<ModOptionsElement> options, IModEvents events)
: base(Game1.activeClickableMenu.xPositionOnScreen, Game1.activeClickableMenu.yPositionOnScreen + 10, Width, Game1.activeClickableMenu.height)
{
_options = options;
@ -75,12 +72,15 @@ namespace UIInfoSuite.Options
(height - Game1.tileSize * 2) / 7 + Game1.pixelZoom),
i.ToString()));
MenuEvents.MenuChanged += MenuEvents_MenuChanged;
events.Display.MenuChanged += OnMenuChanged;
}
private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e)
/// <summary>Raised after a game menu is opened, closed, or replaced.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnMenuChanged(object sender, MenuChangedEventArgs e)
{
if (Game1.activeClickableMenu is GameMenu)
if (e.NewMenu is GameMenu)
{
xPositionOnScreen = Game1.activeClickableMenu.xPositionOnScreen;
yPositionOnScreen = Game1.activeClickableMenu.yPositionOnScreen + 10;

View File

@ -1,13 +1,9 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using StardewModdingAPI;
using StardewModdingAPI.Events;
using StardewValley;
using StardewValley.Menus;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework.Graphics;
namespace UIInfoSuite.Options
@ -21,7 +17,7 @@ namespace UIInfoSuite.Options
public event EventHandler OnLeftClicked;
public ModOptionsPageButton()
public ModOptionsPageButton(IModEvents events)
{
//_optionsPageHandler = optionsPageHandler;
width = 64;
@ -31,39 +27,37 @@ namespace UIInfoSuite.Options
xPositionOnScreen = activeClickableMenu.xPositionOnScreen + activeClickableMenu.width - 200;
yPositionOnScreen = activeClickableMenu.yPositionOnScreen + 16;
Bounds = new Rectangle(xPositionOnScreen, yPositionOnScreen, width, height);
ControlEvents.MouseChanged += OnMouseChanged;
ControlEvents.ControllerButtonPressed += ControlEvents_ControllerButtonPressed;
MenuEvents.MenuChanged += MenuEvents_MenuChanged;
events.Input.ButtonPressed += OnButtonPressed;
events.Display.MenuChanged += OnMenuChanged;
}
private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e)
/// <summary>Raised after a game menu is opened, closed, or replaced.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnMenuChanged(object sender, MenuChangedEventArgs e)
{
if (Game1.activeClickableMenu is GameMenu)
if (e.NewMenu is GameMenu menu)
{
GameMenu menu = Game1.activeClickableMenu as GameMenu;
xPositionOnScreen = menu.xPositionOnScreen + menu.width - 200;
}
}
private void ControlEvents_ControllerButtonPressed(object sender, EventArgsControllerButtonPressed e)
/// <summary>Raised after the player presses a button on the keyboard, controller, or mouse.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
public void OnButtonPressed(object sender, ButtonPressedEventArgs e)
{
if (e.ButtonPressed == Buttons.A &&
isWithinBounds(Game1.getMouseX(), Game1.getMouseY()))
if (e.Button == SButton.MouseLeft || e.Button == SButton.ControllerA)
{
receiveLeftClick(Game1.getMouseX(), Game1.getMouseY());
OnLeftClicked?.Invoke(this, null);
int x = (int)e.Cursor.ScreenPixels.X;
int y = (int)e.Cursor.ScreenPixels.Y;
if (isWithinBounds(x, y))
{
receiveLeftClick(x, y);
OnLeftClicked?.Invoke(this, null);
}
}
}
public void OnMouseChanged(object sender, EventArgsMouseStateChanged e)
{
if (e.PriorState.LeftButton != ButtonState.Pressed &&
e.NewState.LeftButton == ButtonState.Pressed &&
isWithinBounds(e.NewPosition.X, e.NewPosition.Y))
{
receiveLeftClick(e.NewPosition.X, e.NewPosition.Y);
OnLeftClicked?.Invoke(this, null);
}
//if (e.NewState.LeftButton != ButtonState.Pressed || !(Game1.activeClickableMenu is GameMenu))
//{
// _hasClicked = false;
@ -73,7 +67,7 @@ namespace UIInfoSuite.Options
// !_hasClicked)
//{
// receiveLeftClick(e.NewPosition.X, e.NewPosition.Y);
//}
}

View File

@ -5,9 +5,6 @@ using StardewValley;
using StardewValley.Menus;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using UIInfoSuite.Extensions;
@ -25,15 +22,15 @@ namespace UIInfoSuite.Options
private int _modOptionsTabPageNumber;
private readonly LuckOfDay _luckOfDay;
private readonly ShowBirthdayIcon _showBirthdayIcon = new ShowBirthdayIcon();
private readonly ShowAccurateHearts _showAccurateHearts = new ShowAccurateHearts();
private readonly ShowBirthdayIcon _showBirthdayIcon;
private readonly ShowAccurateHearts _showAccurateHearts;
private readonly LocationOfTownsfolk _locationOfTownsfolk;
private readonly ShowWhenAnimalNeedsPet _showWhenAnimalNeedsPet;
private readonly ShowCalendarAndBillboardOnGameMenuButton _showCalendarAndBillboardOnGameMenuButton;
private readonly ShowCropAndBarrelTime _showCropAndBarrelTime;
private readonly ShowItemEffectRanges _showScarecrowAndSprinklerRange;
private readonly ExperienceBar _experienceBar;
private readonly ShowItemHoverInformation _showItemHoverInformation = new ShowItemHoverInformation();
private readonly ShowItemHoverInformation _showItemHoverInformation;
private readonly ShowTravelingMerchant _showTravelingMerchant;
private readonly ShopHarvestPrices _shopHarvestPrices;
private readonly ShowQueenOfSauceIcon _showQueenOfSauceIcon;
@ -42,16 +39,18 @@ namespace UIInfoSuite.Options
public ModOptionsPageHandler(IModHelper helper, IDictionary<String, String> options)
{
_options = options;
MenuEvents.MenuChanged += AddModOptionsToMenu;
MenuEvents.MenuClosed += RemoveModOptionsFromMenu;
helper.Events.Display.MenuChanged += ToggleModOptions;
_helper = helper;
ModConfig modConfig = _helper.ReadConfig<ModConfig>();
_luckOfDay = new LuckOfDay(helper);
_locationOfTownsfolk = new LocationOfTownsfolk(_helper, _options);
_showWhenAnimalNeedsPet = new ShowWhenAnimalNeedsPet(_helper);
_showBirthdayIcon = new ShowBirthdayIcon(helper.Events);
_showAccurateHearts = new ShowAccurateHearts(helper.Events);
_locationOfTownsfolk = new LocationOfTownsfolk(helper, _options);
_showWhenAnimalNeedsPet = new ShowWhenAnimalNeedsPet(helper);
_showCalendarAndBillboardOnGameMenuButton = new ShowCalendarAndBillboardOnGameMenuButton(helper);
_showScarecrowAndSprinklerRange = new ShowItemEffectRanges(modConfig);
_showScarecrowAndSprinklerRange = new ShowItemEffectRanges(modConfig, helper.Events);
_experienceBar = new ExperienceBar(helper);
_showItemHoverInformation = new ShowItemHoverInformation(helper.Events);
_shopHarvestPrices = new ShopHarvestPrices(helper);
_showQueenOfSauceIcon = new ShowQueenOfSauceIcon(helper);
_showTravelingMerchant = new ShowTravelingMerchant(helper);
@ -115,31 +114,37 @@ namespace UIInfoSuite.Options
}
}
private void RemoveModOptionsFromMenu(object sender, EventArgsClickableMenuClosed e)
/// <summary>Raised after a game menu is opened, closed, or replaced.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void ToggleModOptions(object sender, MenuChangedEventArgs e)
{
GraphicsEvents.OnPostRenderGuiEvent -= DrawButton;
if (_modOptionsPageButton != null)
_modOptionsPageButton.OnLeftClicked -= OnButtonLeftClicked;
if (Game1.activeClickableMenu is GameMenu)
// remove from old menu
if (e.OldMenu != null)
{
List<IClickableMenu> tabPages = _helper.Reflection.GetField<List<IClickableMenu>>(Game1.activeClickableMenu, "pages").GetValue();
tabPages.Remove(_modOptionsPage);
}
}
_helper.Events.Display.RenderedActiveMenu -= DrawButton;
if (_modOptionsPageButton != null)
_modOptionsPageButton.OnLeftClicked -= OnButtonLeftClicked;
private void AddModOptionsToMenu(object sender, EventArgsClickableMenuChanged e)
{
if (Game1.activeClickableMenu is GameMenu)
if (e.OldMenu is GameMenu)
{
List<IClickableMenu> tabPages = _helper.Reflection.GetField<List<IClickableMenu>>(e.OldMenu, "pages").GetValue();
tabPages.Remove(_modOptionsPage);
}
}
// add to new menu
if (e.NewMenu is GameMenu newMenu)
{
if (_modOptionsPageButton == null)
{
_modOptionsPage = new ModOptionsPage(_optionsElements);
_modOptionsPageButton = new ModOptionsPageButton();
_modOptionsPage = new ModOptionsPage(_optionsElements, _helper.Events);
_modOptionsPageButton = new ModOptionsPageButton(_helper.Events);
}
GraphicsEvents.OnPostRenderGuiEvent += DrawButton;
_helper.Events.Display.RenderedActiveMenu += DrawButton;
_modOptionsPageButton.OnLeftClicked += OnButtonLeftClicked;
List<IClickableMenu> tabPages = _helper.Reflection.GetField<List<IClickableMenu>>(Game1.activeClickableMenu, "pages").GetValue();
List<IClickableMenu> tabPages = _helper.Reflection.GetField<List<IClickableMenu>>(newMenu, "pages").GetValue();
_modOptionsTabPageNumber = tabPages.Count;
tabPages.Add(_modOptionsPage);

View File

@ -1,198 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace UIInfoSuite.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("UIInfoSuite.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to Billboard.
/// </summary>
internal static string Billboard {
get {
return ResourceManager.GetString("Billboard", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Calendar.
/// </summary>
internal static string Calendar {
get {
return ResourceManager.GetString("Calendar", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to days.
/// </summary>
internal static string Days {
get {
return ResourceManager.GetString("Days", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to days to mature.
/// </summary>
internal static string DaysToMature {
get {
return ResourceManager.GetString("DaysToMature", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to You&apos;re feelin&apos; lucky!!.
/// </summary>
internal static string FeelingLucky {
get {
return ResourceManager.GetString("FeelingLucky", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Harvest price.
/// </summary>
internal static string HarvestPrice {
get {
return ResourceManager.GetString("HarvestPrice", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to hours.
/// </summary>
internal static string Hours {
get {
return ResourceManager.GetString("Hours", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Level Up.
/// </summary>
internal static string LevelUp {
get {
return ResourceManager.GetString("LevelUp", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Feelin&apos; lucky... but not too lucky.
/// </summary>
internal static string LuckyButNotTooLucky {
get {
return ResourceManager.GetString("LuckyButNotTooLucky", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Maybe you should stay home today....
/// </summary>
internal static string MaybeStayHome {
get {
return ResourceManager.GetString("MaybeStayHome", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to minutes.
/// </summary>
internal static string Minutes {
get {
return ResourceManager.GetString("Minutes", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to You&apos;re not feeling lucky at all today....
/// </summary>
internal static string NotFeelingLuckyAtAll {
get {
return ResourceManager.GetString("NotFeelingLuckyAtAll", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Ready To Harvest!.
/// </summary>
internal static string ReadyToHarvest {
get {
return ResourceManager.GetString("ReadyToHarvest", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Today&apos;s Recipe: .
/// </summary>
internal static string TodaysRecipe {
get {
return ResourceManager.GetString("TodaysRecipe", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Traveling merchant is in town!.
/// </summary>
internal static string TravelingMerchantIsInTown {
get {
return ResourceManager.GetString("TravelingMerchantIsInTown", resourceCulture);
}
}
}
}

View File

@ -1,165 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Billboard" xml:space="preserve">
<value>Billboard</value>
</data>
<data name="Calendar" xml:space="preserve">
<value>Calendar</value>
</data>
<data name="Days" xml:space="preserve">
<value>days</value>
</data>
<data name="DaysToMature" xml:space="preserve">
<value>days to mature</value>
</data>
<data name="FeelingLucky" xml:space="preserve">
<value>You're feelin' lucky!!</value>
</data>
<data name="HarvestPrice" xml:space="preserve">
<value>Harvest price</value>
</data>
<data name="Hours" xml:space="preserve">
<value>hours</value>
</data>
<data name="LevelUp" xml:space="preserve">
<value>Level Up</value>
</data>
<data name="LuckyButNotTooLucky" xml:space="preserve">
<value>Feelin' lucky... but not too lucky</value>
</data>
<data name="MaybeStayHome" xml:space="preserve">
<value>Maybe you should stay home today...</value>
</data>
<data name="Minutes" xml:space="preserve">
<value>minutes</value>
</data>
<data name="NotFeelingLuckyAtAll" xml:space="preserve">
<value>You're not feeling lucky at all today...</value>
</data>
<data name="ReadyToHarvest" xml:space="preserve">
<value>Ready To Harvest!</value>
</data>
<data name="TodaysRecipe" xml:space="preserve">
<value>Today's Recipe: </value>
</data>
<data name="TravelingMerchantIsInTown" xml:space="preserve">
<value>Traveling merchant is in town!</value>
</data>
</root>

View File

@ -15,8 +15,6 @@
<AssemblyName>UIInfoSuite</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -35,8 +33,6 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DebugSymbols>true</DebugSymbols>
<DocumentationFile>
</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
@ -57,6 +53,9 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Pathoschild.Stardew.ModBuildConfig" Version="2.2.0" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
@ -78,11 +77,6 @@
<Compile Include="Options\ModOptionsPageButton.cs" />
<Compile Include="Options\ModOptionsPageHandler.cs" />
<Compile Include="Options\ModOptionsPageIcon.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Tools.cs" />
<Compile Include="Extensions\StringExtensions.cs" />
<Compile Include="ModEntry.cs" />
@ -109,34 +103,15 @@
<Compile Include="UIElements\SkipIntro.cs" />
</ItemGroup>
<ItemGroup>
<None Include="i18n\de.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="i18n\default.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="i18n\es.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="i18n\ja.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="i18n\pt.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="i18n\ru.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="i18n\th.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="i18n\zh.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="manifest.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
<None Include="i18n\de.json" />
<None Include="i18n\default.json" />
<None Include="i18n\es.json" />
<None Include="i18n\ja.json" />
<None Include="i18n\pt.json" />
<None Include="i18n\ru.json" />
<None Include="i18n\th.json" />
<None Include="i18n\zh.json" />
<None Include="manifest.json" />
</ItemGroup>
<ItemGroup>
<Content Include="LevelUp license.txt">
@ -146,30 +121,5 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\packages\Pathoschild.Stardew.ModBuildConfig.2.1.0\analyzers\dotnet\cs\StardewModdingAPI.ModBuildConfig.Analyzer.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="AfterBuild">
<PropertyGroup>
<ModPath>$(GamePath)\Mods\$(TargetName)</ModPath>
</PropertyGroup>
<Copy SourceFiles="$(TargetDir)\$(TargetName).dll" DestinationFolder="$(ModPath)" />
<Copy SourceFiles="$(TargetDir)\$(TargetName).pdb" DestinationFolder="$(ModPath)" Condition="Exists('$(TargetDir)\$(TargetName).pdb')" />
<Copy SourceFiles="$(TargetDir)\$(TargetName).dll.mdb" DestinationFolder="$(ModPath)" Condition="Exists('$(TargetDir)\$(TargetName).dll.mdb')" />
<Copy SourceFiles="$(ProjectDir)manifest.json" DestinationFolder="$(ModPath)" />
</Target>
<Import Project="..\packages\Pathoschild.Stardew.ModBuildConfig.2.1.0\build\Pathoschild.Stardew.ModBuildConfig.targets" Condition="Exists('..\packages\Pathoschild.Stardew.ModBuildConfig.2.1.0\build\Pathoschild.Stardew.ModBuildConfig.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Pathoschild.Stardew.ModBuildConfig.2.1.0\build\Pathoschild.Stardew.ModBuildConfig.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Pathoschild.Stardew.ModBuildConfig.2.1.0\build\Pathoschild.Stardew.ModBuildConfig.targets'))" />
</Target>
</Project>

View File

@ -1,7 +1,7 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;
using StardewModdingAPI;
using StardewModdingAPI.Enums;
using StardewModdingAPI.Events;
using StardewValley;
using StardewValley.Menus;
@ -9,10 +9,7 @@ using StardewValley.Tools;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Media;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
@ -75,8 +72,8 @@ namespace UIInfoSuite.UIElements
ModEntry.MonitorObject.Log("Error loading sound file from " + path + ": " + ex.Message + Environment.NewLine + ex.StackTrace, LogLevel.Error);
}
_timeToDisappear.Elapsed += StopTimerAndFadeBarOut;
GraphicsEvents.OnPreRenderHudEvent += OnPreRenderHudEvent;
PlayerEvents.Warped += RemoveAllExperiencePointDisplays;
helper.Events.Display.RenderingHud += OnRenderingHud;
helper.Events.Player.Warped += OnWarped_RemoveAllExperiencePointDisplays;
//var something = _helper.ModRegistry.GetApi("DevinLematty.LevelExtender");
try
@ -115,10 +112,10 @@ namespace UIInfoSuite.UIElements
public void Dispose()
{
PlayerEvents.LeveledUp -= OnLevelUp;
GraphicsEvents.OnPreRenderHudEvent -= OnPreRenderHudEvent;
PlayerEvents.Warped -= RemoveAllExperiencePointDisplays;
GameEvents.QuarterSecondTick -= DetermineIfExperienceHasBeenGained;
_helper.Events.Player.LevelChanged -= OnLevelChanged;
_helper.Events.Display.RenderingHud -= OnRenderingHud;
_helper.Events.Player.Warped -= OnWarped_RemoveAllExperiencePointDisplays;
_helper.Events.GameLoop.UpdateTicked -= OnUpdateTicked_DetermineIfExperienceHasBeenGained;
_timeToDisappear.Elapsed -= StopTimerAndFadeBarOut;
_timeToDisappear.Stop();
_timeToDisappear.Dispose();
@ -128,11 +125,11 @@ namespace UIInfoSuite.UIElements
public void ToggleLevelUpAnimation(bool showLevelUpAnimation)
{
_showLevelUpAnimation = showLevelUpAnimation;
PlayerEvents.LeveledUp -= OnLevelUp;
_helper.Events.Player.LevelChanged -= OnLevelChanged;
if (_showLevelUpAnimation)
{
PlayerEvents.LeveledUp += OnLevelUp;
_helper.Events.Player.LevelChanged += OnLevelChanged;
}
}
@ -143,20 +140,20 @@ namespace UIInfoSuite.UIElements
public void ToggleShowExperienceGain(bool showExperienceGain)
{
GameEvents.QuarterSecondTick -= DetermineIfExperienceHasBeenGained;
_helper.Events.GameLoop.UpdateTicked -= OnUpdateTicked_DetermineIfExperienceHasBeenGained;
for (int i = 0; i < _currentExperience.Length; ++i)
_currentExperience[i] = Game1.player.experiencePoints[i];
_showExperienceGain = showExperienceGain;
if (showExperienceGain)
{
GameEvents.QuarterSecondTick += DetermineIfExperienceHasBeenGained;
_helper.Events.GameLoop.UpdateTicked += OnUpdateTicked_DetermineIfExperienceHasBeenGained;
}
}
public void ToggleShowExperienceBar(bool showExperienceBar)
{
GameEvents.QuarterSecondTick -= DetermineIfExperienceHasBeenGained;
_helper.Events.GameLoop.UpdateTicked -= OnUpdateTicked_DetermineIfExperienceHasBeenGained;
//GraphicsEvents.OnPreRenderHudEvent -= OnPreRenderHudEvent;
//PlayerEvents.Warped -= RemoveAllExperiencePointDisplays;
_showExperienceBar = showExperienceBar;
@ -164,21 +161,24 @@ namespace UIInfoSuite.UIElements
{
//GraphicsEvents.OnPreRenderHudEvent += OnPreRenderHudEvent;
//PlayerEvents.Warped += RemoveAllExperiencePointDisplays;
GameEvents.QuarterSecondTick += DetermineIfExperienceHasBeenGained;
_helper.Events.GameLoop.UpdateTicked += OnUpdateTicked_DetermineIfExperienceHasBeenGained;
}
}
private void OnLevelUp(object sender, EventArgsLevelUp e)
/// <summary>Raised after a player skill level changes. This happens as soon as they level up, not when the game notifies the player after their character goes to bed.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnLevelChanged(object sender, LevelChangedEventArgs e)
{
if (_showLevelUpAnimation)
if (_showLevelUpAnimation && e.IsLocalPlayer)
{
switch (e.Type)
switch (e.Skill)
{
case EventArgsLevelUp.LevelType.Combat: _levelUpIconRectangle.X = 120; break;
case EventArgsLevelUp.LevelType.Farming: _levelUpIconRectangle.X = 10; break;
case EventArgsLevelUp.LevelType.Fishing: _levelUpIconRectangle.X = 20; break;
case EventArgsLevelUp.LevelType.Foraging: _levelUpIconRectangle.X = 60; break;
case EventArgsLevelUp.LevelType.Mining: _levelUpIconRectangle.X = 30; break;
case SkillType.Combat: _levelUpIconRectangle.X = 120; break;
case SkillType.Farming: _levelUpIconRectangle.X = 10; break;
case SkillType.Fishing: _levelUpIconRectangle.X = 20; break;
case SkillType.Foraging: _levelUpIconRectangle.X = 60; break;
case SkillType.Mining: _levelUpIconRectangle.X = 30; break;
}
_shouldDrawLevelUp = true;
ShowExperienceBar();
@ -220,13 +220,23 @@ namespace UIInfoSuite.UIElements
_experienceBarShouldBeVisible = false;
}
private void RemoveAllExperiencePointDisplays(object sender, EventArgsPlayerWarped e)
/// <summary>Raised after a player warps to a new location.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnWarped_RemoveAllExperiencePointDisplays(object sender, WarpedEventArgs e)
{
_experiencePointDisplays.Clear();
if (e.IsLocalPlayer)
_experiencePointDisplays.Clear();
}
private void DetermineIfExperienceHasBeenGained(object sender, EventArgs e)
/// <summary>Raised after the game state is updated (≈60 times per second).</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnUpdateTicked_DetermineIfExperienceHasBeenGained(object sender, UpdateTickedEventArgs e)
{
if (!e.IsMultipleOf(15)) // quarter second
return;
Item currentItem = Game1.player.CurrentItem;
int currentLevelIndex = -1;
@ -369,7 +379,10 @@ namespace UIInfoSuite.UIElements
}
private void OnPreRenderHudEvent(object sender, EventArgs e)
/// <summary>Raised before drawing the HUD (item toolbar, clock, etc) to the screen. The vanilla HUD may be hidden at this point (e.g. because a menu is open).</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnRenderingHud(object sender, RenderingHudEventArgs e)
{
if (!Game1.eventUp)
{

View File

@ -1,6 +1,5 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using UIInfoSuite.Extensions;
using StardewModdingAPI;
using StardewModdingAPI.Events;
@ -12,7 +11,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace UIInfoSuite.UIElements
{
@ -97,30 +95,30 @@ namespace UIInfoSuite.UIElements
public void ToggleShowNPCLocationsOnMap(bool showLocations)
{
OnMenuChange(null, null);
GraphicsEvents.OnPostRenderGuiEvent -= DrawSocialPageOptions;
GraphicsEvents.OnPostRenderGuiEvent -= DrawNPCLocationsOnMap;
ControlEvents.MouseChanged -= HandleClickForSocialPage;
ControlEvents.ControllerButtonPressed -= HandleGamepadPressForSocialPage;
MenuEvents.MenuChanged -= OnMenuChange;
ExtendMenuIfNeeded();
_helper.Events.Display.RenderedActiveMenu -= OnRenderedActiveMenu_DrawSocialPageOptions;
_helper.Events.Display.RenderedActiveMenu -= OnRenderedActiveMenu_DrawNPCLocationsOnMap;
_helper.Events.Input.ButtonPressed -= OnButtonPressed_ForSocialPage;
_helper.Events.Display.MenuChanged -= OnMenuChanged;
if (showLocations)
{
GraphicsEvents.OnPostRenderGuiEvent += DrawSocialPageOptions;
GraphicsEvents.OnPostRenderGuiEvent += DrawNPCLocationsOnMap;
ControlEvents.MouseChanged += HandleClickForSocialPage;
ControlEvents.ControllerButtonPressed += HandleGamepadPressForSocialPage;
MenuEvents.MenuChanged += OnMenuChange;
_helper.Events.Display.RenderedActiveMenu += OnRenderedActiveMenu_DrawSocialPageOptions;
_helper.Events.Display.RenderedActiveMenu += OnRenderedActiveMenu_DrawNPCLocationsOnMap;
_helper.Events.Input.ButtonPressed += OnButtonPressed_ForSocialPage;
_helper.Events.Display.MenuChanged += OnMenuChanged;
}
}
private void HandleGamepadPressForSocialPage(object sender, EventArgsControllerButtonPressed e)
/// <summary>Raised after a game menu is opened, closed, or replaced.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnMenuChanged(object sender, MenuChangedEventArgs e)
{
if (e.ButtonPressed == Buttons.A)
CheckSelectedBox();
ExtendMenuIfNeeded();
}
private void OnMenuChange(object sender, EventArgsClickableMenuChanged e)
private void ExtendMenuIfNeeded()
{
if (Game1.activeClickableMenu is GameMenu)
{
@ -180,11 +178,12 @@ namespace UIInfoSuite.UIElements
}
}
private void HandleClickForSocialPage(object sender, EventArgsMouseStateChanged e)
/// <summary>Raised after the player presses a button on the keyboard, controller, or mouse.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnButtonPressed_ForSocialPage(object sender, ButtonPressedEventArgs e)
{
if (Game1.activeClickableMenu is GameMenu &&
e.PriorState.LeftButton != ButtonState.Pressed &&
e.NewState.LeftButton == ButtonState.Pressed)
if (Game1.activeClickableMenu is GameMenu && (e.Button == SButton.MouseLeft || e.Button == SButton.ControllerA))
{
CheckSelectedBox();
}
@ -212,11 +211,13 @@ namespace UIInfoSuite.UIElements
}
}
private void DrawNPCLocationsOnMap(object sender, EventArgs e)
/// <summary>When a menu is open (<see cref="Game1.activeClickableMenu"/> isn't null), raised after that menu is drawn to the sprite batch but before it's rendered to the screen.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnRenderedActiveMenu_DrawNPCLocationsOnMap(object sender, RenderedActiveMenuEventArgs e)
{
if (Game1.activeClickableMenu is GameMenu)
if (Game1.activeClickableMenu is GameMenu gameMenu)
{
GameMenu gameMenu = Game1.activeClickableMenu as GameMenu;
if (gameMenu.currentTab == 3)
{
List<String> namesToShow = new List<string>();
@ -230,8 +231,7 @@ namespace UIInfoSuite.UIElements
if (drawCharacter)
{
KeyValuePair<int, int> location;
location = new KeyValuePair<int, int>((int)character.Position.X, (int)character.position.Y);
KeyValuePair<int, int> location = new KeyValuePair<int, int>((int)character.Position.X, (int)character.position.Y);
String locationName = character.currentLocation?.Name ?? character.DefaultMap;
switch (locationName)
@ -433,10 +433,12 @@ namespace UIInfoSuite.UIElements
}
}
private void DrawSocialPageOptions(object sender, EventArgs e)
/// <summary>When a menu is open (<see cref="Game1.activeClickableMenu"/> isn't null), raised after that menu is drawn to the sprite batch but before it's rendered to the screen.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnRenderedActiveMenu_DrawSocialPageOptions(object sender, RenderedActiveMenuEventArgs e)
{
if (Game1.activeClickableMenu is GameMenu &&
(Game1.activeClickableMenu as GameMenu).currentTab == 2)
if (Game1.activeClickableMenu is GameMenu gameMenu && gameMenu.currentTab == 2)
{
Game1.drawDialogueBox(
Game1.activeClickableMenu.xPositionOnScreen - SocialPanelXOffset,

View File

@ -4,10 +4,6 @@ using StardewModdingAPI.Events;
using StardewValley;
using StardewValley.Menus;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UIInfoSuite.Extensions;
namespace UIInfoSuite.UIElements
@ -21,18 +17,18 @@ namespace UIInfoSuite.UIElements
public void Toggle(bool showLuckOfDay)
{
PlayerEvents.Warped -= AdjustIconXToBlackBorder;
GraphicsEvents.OnPreRenderHudEvent -= DrawDiceIcon;
GraphicsEvents.OnPostRenderHudEvent -= DrawHoverTextOverEverything;
GameEvents.HalfSecondTick -= CalculateLuck;
_helper.Events.Player.Warped -= OnWarped;
_helper.Events.Display.RenderingHud -= OnRenderingHud;
_helper.Events.Display.RenderedHud -= OnRenderedHud;
_helper.Events.GameLoop.UpdateTicked -= OnUpdateTicked;
if (showLuckOfDay)
{
AdjustIconXToBlackBorder(null, null);
PlayerEvents.Warped += AdjustIconXToBlackBorder;
GameEvents.HalfSecondTick += CalculateLuck;
GraphicsEvents.OnPreRenderHudEvent += DrawDiceIcon;
GraphicsEvents.OnPostRenderHudEvent += DrawHoverTextOverEverything;
AdjustIconXToBlackBorder();
_helper.Events.Player.Warped += OnWarped;
_helper.Events.GameLoop.UpdateTicked += OnUpdateTicked;
_helper.Events.Display.RenderingHud += OnRenderingHud;
_helper.Events.Display.RenderedHud += OnRenderedHud;
}
}
@ -46,44 +42,59 @@ namespace UIInfoSuite.UIElements
Toggle(false);
}
private void CalculateLuck(object sender, EventArgs e)
/// <summary>Raised after the game state is updated (≈60 times per second).</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnUpdateTicked(object sender, UpdateTickedEventArgs e)
{
_color = new Color(Color.White.ToVector4());
// calculate luck
if (e.IsMultipleOf(30)) // half second
{
_color = new Color(Color.White.ToVector4());
if (Game1.dailyLuck < -0.04)
{
_hoverText = _helper.SafeGetString(LanguageKeys.MaybeStayHome);
_color.B = 155;
_color.G = 155;
}
else if (Game1.dailyLuck < 0)
{
_hoverText = _helper.SafeGetString(LanguageKeys.NotFeelingLuckyAtAll);
_color.B = 165;
_color.G = 165;
_color.R = 165;
_color *= 0.8f;
}
else if (Game1.dailyLuck <= 0.04)
{
_hoverText = _helper.SafeGetString(LanguageKeys.LuckyButNotTooLucky);
}
else
{
_hoverText = _helper.SafeGetString(LanguageKeys.FeelingLucky);
_color.B = 155;
_color.R = 155;
if (Game1.dailyLuck < -0.04)
{
_hoverText = _helper.SafeGetString(LanguageKeys.MaybeStayHome);
_color.B = 155;
_color.G = 155;
}
else if (Game1.dailyLuck < 0)
{
_hoverText = _helper.SafeGetString(LanguageKeys.NotFeelingLuckyAtAll);
_color.B = 165;
_color.G = 165;
_color.R = 165;
_color *= 0.8f;
}
else if (Game1.dailyLuck <= 0.04)
{
_hoverText = _helper.SafeGetString(LanguageKeys.LuckyButNotTooLucky);
}
else
{
_hoverText = _helper.SafeGetString(LanguageKeys.FeelingLucky);
_color.B = 155;
_color.R = 155;
}
}
}
private void DrawHoverTextOverEverything(object sender, EventArgs e)
/// <summary>Raised after drawing the HUD (item toolbar, clock, etc) to the sprite batch, but before it's rendered to the screen. The vanilla HUD may be hidden at this point (e.g. because a menu is open).</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnRenderedHud(object sender, RenderedHudEventArgs e)
{
// draw hover text
if (_icon.containsPoint(Game1.getMouseX(), Game1.getMouseY()))
IClickableMenu.drawHoverText(Game1.spriteBatch, _hoverText, Game1.dialogueFont);
}
private void DrawDiceIcon(object sender, EventArgs e)
/// <summary>Raised before drawing the HUD (item toolbar, clock, etc) to the screen. The vanilla HUD may be hidden at this point (e.g. because a menu is open).</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnRenderingHud(object sender, RenderingHudEventArgs e)
{
// draw dice icon
if (!Game1.eventUp)
{
Point iconPosition = IconHandler.Handler.GetNewIconPosition();
@ -93,18 +104,30 @@ namespace UIInfoSuite.UIElements
}
}
private void AdjustIconXToBlackBorder(object sender, EventArgsPlayerWarped e)
/// <summary>Raised after a player warps to a new location.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnWarped(object sender, WarpedEventArgs e)
{
_icon = new ClickableTextureComponent("",
new Rectangle(Tools.GetWidthInPlayArea() - 134,
290,
10 * Game1.pixelZoom,
10 * Game1.pixelZoom),
"",
"",
Game1.mouseCursors,
new Rectangle(50, 428, 10, 14),
Game1.pixelZoom,
// adjust icon X to black border
if (e.IsLocalPlayer)
{
AdjustIconXToBlackBorder();
}
}
private void AdjustIconXToBlackBorder()
{
_icon = new ClickableTextureComponent("",
new Rectangle(Tools.GetWidthInPlayArea() - 134,
290,
10 * Game1.pixelZoom,
10 * Game1.pixelZoom),
"",
"",
Game1.mouseCursors,
new Rectangle(50, 428, 10, 14),
Game1.pixelZoom,
false);
}
}

View File

@ -5,11 +5,7 @@ using StardewModdingAPI.Events;
using StardewValley;
using StardewValley.Menus;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using UIInfoSuite.Extensions;
namespace UIInfoSuite.UIElements
@ -25,11 +21,11 @@ namespace UIInfoSuite.UIElements
public void ToggleOption(bool shopHarvestPrices)
{
GraphicsEvents.OnPostRenderGuiEvent -= DrawShopHarvestPrices;
_helper.Events.Display.RenderedActiveMenu -= OnRenderedActiveMenu;
if (shopHarvestPrices)
{
GraphicsEvents.OnPostRenderGuiEvent += DrawShopHarvestPrices;
_helper.Events.Display.RenderedActiveMenu += OnRenderedActiveMenu;
}
}
@ -38,14 +34,15 @@ namespace UIInfoSuite.UIElements
ToggleOption(false);
}
private void DrawShopHarvestPrices(object sender, EventArgs e)
/// <summary>When a menu is open (<see cref="Game1.activeClickableMenu"/> isn't null), raised after that menu is drawn to the sprite batch but before it's rendered to the screen.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnRenderedActiveMenu(object sender, RenderedActiveMenuEventArgs e)
{
if (Game1.activeClickableMenu is ShopMenu)
// draw shop harvest prices
if (Game1.activeClickableMenu is ShopMenu menu)
{
ShopMenu menu = Game1.activeClickableMenu as ShopMenu;
Item hoverItem = typeof(ShopMenu).GetField("hoveredItem", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(menu) as Item;
if (hoverItem != null)
if (typeof(ShopMenu).GetField("hoveredItem", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(menu) is Item hoverItem)
{
String text = string.Empty;
bool itemHasPriceInfo = Tools.GetTruePrice(hoverItem) > 0;

View File

@ -1,5 +1,4 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using StardewModdingAPI.Events;
using StardewValley;
using StardewValley.Menus;
@ -7,8 +6,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace UIInfoSuite.UIElements
{
@ -16,6 +13,7 @@ namespace UIInfoSuite.UIElements
{
private String[] _friendNames;
private SocialPage _socialPage;
private IModEvents _events;
private readonly int[][] _numArray = new int[][]
{
@ -25,15 +23,20 @@ namespace UIInfoSuite.UIElements
new int[] { 0, 0, 1, 0, 0 }
};
public ShowAccurateHearts(IModEvents events)
{
_events = events;
}
public void ToggleOption(bool showAccurateHearts)
{
MenuEvents.MenuChanged -= OnMenuChange;
GraphicsEvents.OnPostRenderGuiEvent -= DrawHeartFills;
_events.Display.MenuChanged -= OnMenuChanged;
_events.Display.RenderedActiveMenu -= OnRenderedActiveMenu;
if (showAccurateHearts)
{
MenuEvents.MenuChanged += OnMenuChange;
GraphicsEvents.OnPostRenderGuiEvent += DrawHeartFills;
_events.Display.MenuChanged += OnMenuChanged;
_events.Display.RenderedActiveMenu += OnRenderedActiveMenu;
}
}
@ -42,12 +45,14 @@ namespace UIInfoSuite.UIElements
ToggleOption(false);
}
private void DrawHeartFills(object sender, EventArgs e)
/// <summary>When a menu is open (<see cref="Game1.activeClickableMenu"/> isn't null), raised after that menu is drawn to the sprite batch but before it's rendered to the screen.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnRenderedActiveMenu(object sender, RenderedActiveMenuEventArgs e)
{
if (Game1.activeClickableMenu is GameMenu)
// draw heart fills
if (Game1.activeClickableMenu is GameMenu gameMenu)
{
GameMenu gameMenu = Game1.activeClickableMenu as GameMenu;
if (gameMenu.currentTab == 2)
{
if (_socialPage != null)
@ -106,13 +111,21 @@ namespace UIInfoSuite.UIElements
}
else
{
OnMenuChange(sender, null);
ExtendMenuIfNeeded();
}
}
}
}
private void OnMenuChange(object sender, EventArgsClickableMenuChanged e)
/// <summary>Raised after a game menu is opened, closed, or replaced.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnMenuChanged(object sender, MenuChangedEventArgs e)
{
ExtendMenuIfNeeded();
}
private void ExtendMenuIfNeeded()
{
if (Game1.activeClickableMenu is GameMenu)
{
@ -120,9 +133,9 @@ namespace UIInfoSuite.UIElements
foreach (var menu in menuList)
{
if (menu is SocialPage)
if (menu is SocialPage page)
{
_socialPage = menu as SocialPage;
_socialPage = page;
_friendNames = (typeof(SocialPage).GetField("names", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(_socialPage) as List<object>)
.Select(name => name.ToString())
.ToArray();

View File

@ -5,11 +5,6 @@ using StardewModdingAPI.Events;
using StardewValley;
using StardewValley.Menus;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Netcode;
namespace UIInfoSuite.UIElements
{
@ -17,29 +12,37 @@ namespace UIInfoSuite.UIElements
{
private NPC _birthdayNPC;
private ClickableTextureComponent _birthdayIcon;
private readonly IModEvents _events;
public ShowBirthdayIcon(IModEvents events)
{
_events = events;
}
public void ToggleOption(bool showBirthdayIcon)
{
TimeEvents.AfterDayStarted -= CheckForBirthday;
GraphicsEvents.OnPreRenderHudEvent -= DrawBirthdayIcon;
GraphicsEvents.OnPostRenderHudEvent -= DrawHoverText;
GameEvents.HalfSecondTick -= CheckIfGiftHasBeenGiven;
_events.GameLoop.DayStarted -= OnDayStarted;
_events.Display.RenderingHud -= OnRenderingHud;
_events.Display.RenderedHud -= OnRenderedHud;
_events.GameLoop.UpdateTicked -= OnUpdateTicked;
if (showBirthdayIcon)
{
CheckForBirthday(null, null);
TimeEvents.AfterDayStarted += CheckForBirthday;
GraphicsEvents.OnPreRenderHudEvent += DrawBirthdayIcon;
GraphicsEvents.OnPostRenderHudEvent += DrawHoverText;
GameEvents.HalfSecondTick += CheckIfGiftHasBeenGiven;
CheckForBirthday();
_events.GameLoop.DayStarted += OnDayStarted;
_events.Display.RenderingHud += OnRenderingHud;
_events.Display.RenderedHud += OnRenderedHud;
_events.GameLoop.UpdateTicked += OnUpdateTicked;
}
}
private void CheckIfGiftHasBeenGiven(object sender, EventArgs e)
/// <summary>Raised after the game state is updated (≈60 times per second).</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnUpdateTicked(object sender, UpdateTickedEventArgs e)
{
if (_birthdayNPC != null &&
Game1.player != null &&
Game1.player.friendshipData != null)
// check if gift has been given
if (e.IsOneSecond && _birthdayNPC != null && Game1.player?.friendshipData != null)
{
Game1.player.friendshipData.FieldDict.TryGetValue(_birthdayNPC.Name, out var netRef);
//var birthdayNPCDetails = Game1.player.friendshipData.SafeGet(_birthdayNPC.name);
@ -57,7 +60,15 @@ namespace UIInfoSuite.UIElements
ToggleOption(false);
}
private void CheckForBirthday(object sender, EventArgs e)
/// <summary>Raised after the game begins a new day (including when the player loads a save).</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnDayStarted(object sender, DayStartedEventArgs e)
{
CheckForBirthday();
}
private void CheckForBirthday()
{
_birthdayNPC = null;
foreach (var location in Game1.locations)
@ -76,8 +87,12 @@ namespace UIInfoSuite.UIElements
}
}
private void DrawBirthdayIcon(object sender, EventArgs e)
/// <summary>Raised before drawing the HUD (item toolbar, clock, etc) to the screen.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnRenderingHud(object sender, EventArgs e)
{
// draw birthday icon
if (!Game1.eventUp)
{
if (_birthdayNPC != null)
@ -116,10 +131,13 @@ namespace UIInfoSuite.UIElements
}
}
private void DrawHoverText(object sender, EventArgs e)
/// <summary>Raised after drawing the HUD (item toolbar, clock, etc) to the sprite batch, but before it's rendered to the screen.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnRenderedHud(object sender, RenderedHudEventArgs e)
{
if (_birthdayNPC != null &&
_birthdayIcon.containsPoint(Game1.getMouseX(), Game1.getMouseY()))
// draw hover text
if (_birthdayNPC != null && _birthdayIcon.containsPoint(Game1.getMouseX(), Game1.getMouseY()))
{
String hoverText = String.Format("{0}'s Birthday", _birthdayNPC.Name);
IClickableMenu.drawHoverText(

View File

@ -1,18 +1,13 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using UIInfoSuite.Extensions;
using UIInfoSuite.Options;
using StardewModdingAPI.Events;
using StardewValley;
using StardewValley.Menus;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using StardewModdingAPI;
namespace UIInfoSuite.UIElements
@ -38,22 +33,24 @@ namespace UIInfoSuite.UIElements
public void ToggleOption(bool showCalendarAndBillboard)
{
GraphicsEvents.OnPostRenderGuiEvent -= RenderButtons;
ControlEvents.MouseChanged -= OnBillboardIconClick;
ControlEvents.ControllerButtonPressed -= OnBillboardIconPressed;
GameEvents.EighthUpdateTick -= GetHoverItem;
_helper.Events.Display.RenderedActiveMenu -= OnRenderedActiveMenu;
_helper.Events.Input.ButtonPressed -= OnButtonPressed;
_helper.Events.GameLoop.UpdateTicked -= OnUpdateTicked;
if (showCalendarAndBillboard)
{
GraphicsEvents.OnPostRenderGuiEvent += RenderButtons;
ControlEvents.MouseChanged += OnBillboardIconClick;
ControlEvents.ControllerButtonPressed += OnBillboardIconPressed;
GameEvents.EighthUpdateTick += GetHoverItem;
_helper.Events.Display.RenderedActiveMenu += OnRenderedActiveMenu;
_helper.Events.Input.ButtonPressed += OnButtonPressed;
_helper.Events.GameLoop.UpdateTicked += OnUpdateTicked;
}
}
private void GetHoverItem(object sender, EventArgs e)
/// <summary>Raised after the game state is updated (≈60 times per second).</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnUpdateTicked(object sender, EventArgs e)
{
// get hover item
_hoverItem = Tools.GetHoveredItem();
if (Game1.activeClickableMenu is GameMenu gameMenu)
{
@ -66,23 +63,20 @@ namespace UIInfoSuite.UIElements
}
}
private void OnBillboardIconPressed(object sender, EventArgsControllerButtonPressed e)
{
if (e.ButtonPressed == Buttons.A)
ActivateBillboard();
}
public void Dispose()
{
ToggleOption(false);
}
private void OnBillboardIconClick(object sender, EventArgsMouseStateChanged e)
/// <summary>Raised after the player presses a button on the keyboard, controller, or mouse.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnButtonPressed(object sender, ButtonPressedEventArgs e)
{
if (e.NewState.LeftButton == ButtonState.Pressed)
{
if (e.Button == SButton.MouseLeft)
ActivateBillboard();
else if (e.Button == SButton.ControllerA)
ActivateBillboard();
}
}
private void ActivateBillboard()
@ -102,11 +96,14 @@ namespace UIInfoSuite.UIElements
}
}
private void RenderButtons(object sender, EventArgs e)
/// <summary>When a menu is open (<see cref="Game1.activeClickableMenu"/> isn't null), raised after that menu is drawn to the sprite batch but before it's rendered to the screen.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnRenderedActiveMenu(object sender, EventArgs e)
{
if (_hoverItem == null &&
Game1.activeClickableMenu is GameMenu &&
(Game1.activeClickableMenu as GameMenu).currentTab == 0
Game1.activeClickableMenu is GameMenu gameMenu &&
gameMenu.currentTab == 0
&& _heldItem == null)
{
_showBillboardButton.bounds.X = Game1.activeClickableMenu.xPositionOnScreen + Game1.activeClickableMenu.width - 160;

View File

@ -6,12 +6,7 @@ using StardewValley.Menus;
using StardewValley.TerrainFeatures;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Resources;
using System.Reflection;
using System.Globalization;
using StardewValley.Objects;
using StardewModdingAPI;
using StardewValley.Locations;
@ -21,7 +16,7 @@ namespace UIInfoSuite.UIElements
{
class ShowCropAndBarrelTime : IDisposable
{
private Dictionary<int, String> _indexOfCropNames = new Dictionary<int, string>();
private readonly Dictionary<int, String> _indexOfCropNames = new Dictionary<int, string>();
private StardewValley.Object _currentTile;
private TerrainFeature _terrain;
private Building _currentTileBuilding = null;
@ -34,27 +29,28 @@ namespace UIInfoSuite.UIElements
public void ToggleOption(bool showCropAndBarrelTimes)
{
GraphicsEvents.OnPreRenderHudEvent -= DrawHoverTooltip;
GameEvents.FourthUpdateTick -= GetTileUnderCursor;
_helper.Events.Display.RenderingHud -= OnRenderingHud;
_helper.Events.GameLoop.UpdateTicked -= OnUpdateTicked;
if (showCropAndBarrelTimes)
{
GraphicsEvents.OnPreRenderHudEvent += DrawHoverTooltip;
GameEvents.FourthUpdateTick += GetTileUnderCursor;
_helper.Events.Display.RenderingHud += OnRenderingHud;
_helper.Events.GameLoop.UpdateTicked += OnUpdateTicked;
}
}
private void GetTileUnderCursor(object sender, EventArgs e)
/// <summary>Raised after the game state is updated (≈60 times per second).</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnUpdateTicked(object sender, UpdateTickedEventArgs e)
{
if (Game1.currentLocation is BuildableGameLocation buildableLocation)
{
_currentTileBuilding = buildableLocation.getBuildingAt(Game1.currentCursorTile);
}
else
{
_currentTileBuilding = null;
}
if (!e.IsMultipleOf(4))
return;
// get tile under cursor
_currentTileBuilding = Game1.currentLocation is BuildableGameLocation buildableLocation
? buildableLocation.getBuildingAt(Game1.currentCursorTile)
: null;
if (Game1.currentLocation != null)
{
if (Game1.currentLocation.Objects == null ||
@ -89,8 +85,12 @@ namespace UIInfoSuite.UIElements
ToggleOption(false);
}
private void DrawHoverTooltip(object sender, EventArgs e)
/// <summary>Raised before drawing the HUD (item toolbar, clock, etc) to the screen. The vanilla HUD may be hidden at this point (e.g. because a menu is open).</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnRenderingHud(object sender, RenderingHudEventArgs e)
{
// draw hover tooltip
if (_currentTileBuilding != null)
{
if (_currentTileBuilding is Mill millBuilding)

View File

@ -6,9 +6,6 @@ using StardewValley.Buildings;
using StardewValley.Locations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UIInfoSuite.UIElements
{
@ -16,6 +13,7 @@ namespace UIInfoSuite.UIElements
{
private readonly List<Point> _effectiveArea = new List<Point>();
private readonly ModConfig _modConfig;
private readonly IModEvents _events;
private static readonly int[][] _junimoHutArray = new int[17][]
{
@ -38,20 +36,21 @@ namespace UIInfoSuite.UIElements
new int[17] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
};
public ShowItemEffectRanges(ModConfig modConfig)
public ShowItemEffectRanges(ModConfig modConfig, IModEvents events)
{
_modConfig = modConfig;
_events = events;
}
public void ToggleOption(bool showItemEffectRanges)
{
GraphicsEvents.OnPostRenderEvent -= DrawTileOutlines;
GameEvents.FourthUpdateTick -= CheckDrawTileOutlines;
_events.Display.Rendered -= OnRendered;
_events.GameLoop.UpdateTicked -= OnUpdateTicked;
if (showItemEffectRanges)
{
GraphicsEvents.OnPostRenderEvent += DrawTileOutlines;
GameEvents.FourthUpdateTick += CheckDrawTileOutlines;
_events.Display.Rendered += OnRendered;
_events.GameLoop.UpdateTicked += OnUpdateTicked;
}
}
@ -60,10 +59,16 @@ namespace UIInfoSuite.UIElements
ToggleOption(false);
}
private void CheckDrawTileOutlines(object sender, EventArgs e)
/// <summary>Raised after the game state is updated (≈60 times per second).</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnUpdateTicked(object sender, UpdateTickedEventArgs e)
{
_effectiveArea.Clear();
if (!e.IsMultipleOf(4))
return;
// check draw tile outlines
_effectiveArea.Clear();
if (Game1.activeClickableMenu == null &&
!Game1.eventUp)
{
@ -163,8 +168,12 @@ namespace UIInfoSuite.UIElements
}
}
private void DrawTileOutlines(object sender, EventArgs e)
/// <summary>Raised after the game draws to the sprite patch in a draw tick, just before the final sprite batch is rendered to the screen.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnRendered(object sender, RenderedEventArgs e)
{
// draw tile outlines
foreach (Point point in _effectiveArea)
Game1.spriteBatch.Draw(
Game1.mouseCursors,

View File

@ -9,10 +9,6 @@ using StardewValley.Objects;
using StardewValley.Tools;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace UIInfoSuite.UIElements
{
@ -32,23 +28,30 @@ namespace UIInfoSuite.UIElements
private Item _hoverItem;
private CommunityCenter _communityCenter;
private Dictionary<String, String> _bundleData;
private readonly IModEvents _events;
public ShowItemHoverInformation(IModEvents events)
{
_events = events;
}
public void ToggleOption(bool showItemHoverInformation)
{
PlayerEvents.InventoryChanged -= PopulateRequiredBundles;
GraphicsEvents.OnPostRenderEvent -= DrawAdvancedTooltipForMenu;
GraphicsEvents.OnPostRenderHudEvent -= DrawAdvancedTooltipForToolbar;
GraphicsEvents.OnPreRenderEvent -= GetHoverItem;
_events.Player.InventoryChanged -= OnInventoryChanged;
_events.Display.Rendered -= OnRendered;
_events.Display.RenderedHud -= OnRenderedHud;
_events.Display.Rendering -= OnRendering;
if (showItemHoverInformation)
{
_communityCenter = Game1.getLocationFromName("CommunityCenter") as CommunityCenter;
_bundleData = Game1.content.Load<Dictionary<String, String>>("Data\\Bundles");
PopulateRequiredBundles(null, null);
PlayerEvents.InventoryChanged += PopulateRequiredBundles;
GraphicsEvents.OnPostRenderEvent += DrawAdvancedTooltipForMenu;
GraphicsEvents.OnPostRenderHudEvent += DrawAdvancedTooltipForToolbar;
GraphicsEvents.OnPreRenderEvent += GetHoverItem;
PopulateRequiredBundles();
_events.Player.InventoryChanged += OnInventoryChanged;
_events.Display.Rendered += OnRendered;
_events.Display.RenderedHud += OnRenderedHud;
_events.Display.Rendering += OnRendering;
}
}
@ -57,28 +60,46 @@ namespace UIInfoSuite.UIElements
ToggleOption(false);
}
private void GetHoverItem(object sender, EventArgs e)
/// <summary>Raised before the game draws anything to the screen in a draw tick, as soon as the sprite batch is opened.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnRendering(object sender, EventArgs e)
{
_hoverItem = Tools.GetHoveredItem();
}
private void DrawAdvancedTooltipForToolbar(object sender, EventArgs e)
/// <summary>Raised after drawing the HUD (item toolbar, clock, etc) to the sprite batch, but before it's rendered to the screen. The vanilla HUD may be hidden at this point (e.g. because a menu is open). Content drawn to the sprite batch at this point will appear over the HUD.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnRenderedHud(object sender, EventArgs e)
{
if (Game1.activeClickableMenu == null)
{
DrawAdvancedTooltip(sender, e);
DrawAdvancedTooltip();
}
}
private void DrawAdvancedTooltipForMenu(object sender, EventArgs e)
/// <summary>Raised after the game draws to the sprite patch in a draw tick, just before the final sprite batch is rendered to the screen.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnRendered(object sender, EventArgs e)
{
if (Game1.activeClickableMenu != null)
{
DrawAdvancedTooltip(sender, e);
DrawAdvancedTooltip();
}
}
private void PopulateRequiredBundles(object sender, EventArgsInventoryChanged e)
/// <summary>Raised after items are added or removed to a player's inventory. NOTE: this event is currently only raised for the current player.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnInventoryChanged(object sender, InventoryChangedEventArgs e)
{
if (e.IsLocalPlayer)
this.PopulateRequiredBundles();
}
private void PopulateRequiredBundles()
{
_prunedRequiredBundles.Clear();
foreach (var bundle in _bundleData)
@ -122,7 +143,7 @@ namespace UIInfoSuite.UIElements
}
}
private void DrawAdvancedTooltip(object sender, EventArgs e)
private void DrawAdvancedTooltip()
{
if (_hoverItem != null &&
_hoverItem.Name != "Scythe" &&

View File

@ -7,10 +7,7 @@ using StardewValley.Menus;
using StardewValley.Objects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using UIInfoSuite.Extensions;
namespace UIInfoSuite.UIElements
@ -28,26 +25,29 @@ namespace UIInfoSuite.UIElements
public void ToggleOption(bool showQueenOfSauceIcon)
{
GraphicsEvents.OnPreRenderHudEvent -= DrawIcon;
GraphicsEvents.OnPostRenderHudEvent -= DrawHoverText;
TimeEvents.AfterDayStarted -= CheckForNewRecipe;
GameEvents.OneSecondTick -= CheckIfLearnedRecipe;
_helper.Events.Display.RenderingHud -= OnRenderingHud;
_helper.Events.Display.RenderedHud -= OnRenderedHud;
_helper.Events.GameLoop.DayStarted -= OnDayStarted;
_helper.Events.GameLoop.UpdateTicked -= OnUpdateTicked;
if (showQueenOfSauceIcon)
{
LoadRecipes();
CheckForNewRecipe(null, null);
TimeEvents.AfterDayStarted += CheckForNewRecipe;
GraphicsEvents.OnPreRenderHudEvent += DrawIcon;
GraphicsEvents.OnPostRenderHudEvent += DrawHoverText;
GameEvents.OneSecondTick += CheckIfLearnedRecipe;
CheckForNewRecipe();
_helper.Events.GameLoop.DayStarted += OnDayStarted;
_helper.Events.Display.RenderingHud += OnRenderingHud;
_helper.Events.Display.RenderedHud += OnRenderedHud;
_helper.Events.GameLoop.UpdateTicked += OnUpdateTicked;
}
}
private void CheckIfLearnedRecipe(object sender, EventArgs e)
/// <summary>Raised after the game state is updated (≈60 times per second).</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnUpdateTicked(object sender, UpdateTickedEventArgs e)
{
if (_drawQueenOfSauceIcon &&
Game1.player.knowsRecipe(_todaysRecipe))
// check if learned recipe
if (e.IsOneSecond && _drawQueenOfSauceIcon && Game1.player.knowsRecipe(_todaysRecipe))
_drawQueenOfSauceIcon = false;
}
@ -121,7 +121,7 @@ namespace UIInfoSuite.UIElements
splitValues = craftingRecipesValue.Split('/');
}
string languageRecipeName = (LocalizedContentManager.CurrentLanguageCode == LocalizedContentManager.LanguageCode.en) ?
string languageRecipeName = (_helper.Content.CurrentLocaleConstant == LocalizedContentManager.LanguageCode.en) ?
key : splitValues[splitValues.Length - 1];
array1[1] = languageRecipeName;
@ -140,8 +140,12 @@ namespace UIInfoSuite.UIElements
return array1;
}
private void DrawIcon(object sender, EventArgs e)
/// <summary>Raised before drawing the HUD (item toolbar, clock, etc) to the screen. The vanilla HUD may be hidden at this point (e.g. because a menu is open).</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnRenderingHud(object sender, RenderingHudEventArgs e)
{
// draw icon
if (!Game1.eventUp)
{
if (_drawQueenOfSauceIcon)
@ -199,8 +203,12 @@ namespace UIInfoSuite.UIElements
}
}
private void DrawHoverText(object sender, EventArgs e)
/// <summary>Raised after drawing the HUD (item toolbar, clock, etc) to the sprite batch, but before it's rendered to the screen.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnRenderedHud(object sender, RenderedHudEventArgs e)
{
// draw hover text
if (_drawQueenOfSauceIcon &&
_queenOfSauceIcon.containsPoint(Game1.getMouseX(), Game1.getMouseY()))
{
@ -217,7 +225,15 @@ namespace UIInfoSuite.UIElements
ToggleOption(false);
}
private void CheckForNewRecipe(object sender, EventArgs e)
/// <summary>Raised after the game begins a new day (including when the player loads a save).</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnDayStarted(object sender, DayStartedEventArgs e)
{
this.CheckForNewRecipe();
}
private void CheckForNewRecipe()
{
TV tv = new TV();
int numRecipesKnown = Game1.player.cookingRecipes.Count();

View File

@ -1,14 +1,9 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using StardewModdingAPI;
using StardewModdingAPI.Events;
using StardewValley;
using StardewValley.Menus;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UIInfoSuite.Extensions;
namespace UIInfoSuite.UIElements
@ -28,29 +23,41 @@ namespace UIInfoSuite.UIElements
public void ToggleOption(bool showToolUpgradeStatus)
{
GraphicsEvents.OnPreRenderHudEvent -= DrawToolUpgradeStatus;
GraphicsEvents.OnPostRenderHudEvent -= DrawHoverText;
TimeEvents.AfterDayStarted -= DayChanged;
GameEvents.OneSecondTick -= CheckForMidDayChanges;
_helper.Events.Display.RenderingHud -= OnRenderingHud;
_helper.Events.Display.RenderedHud -= OnRenderedHud;
_helper.Events.GameLoop.DayStarted -= OnDayStarted;
_helper.Events.GameLoop.UpdateTicked -= OnUpdateTicked;
if (showToolUpgradeStatus)
{
DayChanged(null, new EventArgsIntChanged(0, Game1.dayOfMonth));
GraphicsEvents.OnPreRenderHudEvent += DrawToolUpgradeStatus;
GraphicsEvents.OnPostRenderHudEvent += DrawHoverText;
TimeEvents.AfterDayStarted += DayChanged;
GameEvents.OneSecondTick += CheckForMidDayChanges;
UpdateToolInfo();
_helper.Events.Display.RenderingHud += OnRenderingHud;
_helper.Events.Display.RenderedHud += OnRenderedHud;
_helper.Events.GameLoop.DayStarted += OnDayStarted;
_helper.Events.GameLoop.UpdateTicked += OnUpdateTicked;
}
}
private void CheckForMidDayChanges(object sender, EventArgs e)
/// <summary>Raised after the game state is updated (≈60 times per second).</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnUpdateTicked(object sender, UpdateTickedEventArgs e)
{
if (_toolBeingUpgraded != Game1.player.toolBeingUpgraded.Value)
DayChanged(null, null);
if (e.IsOneSecond && _toolBeingUpgraded != Game1.player.toolBeingUpgraded.Value)
UpdateToolInfo();
}
private void DayChanged(object sender, EventArgs e)
/// <summary>Raised after the game begins a new day (including when the player loads a save).</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnDayStarted(object sender, DayStartedEventArgs e)
{
this.UpdateToolInfo();
}
private void UpdateToolInfo()
{
//
if (Game1.player.toolBeingUpgraded.Value != null)
{
_toolBeingUpgraded = Game1.player.toolBeingUpgraded.Value;
@ -107,10 +114,13 @@ namespace UIInfoSuite.UIElements
}
private void DrawToolUpgradeStatus(object sender, EventArgs e)
/// <summary>Raised before drawing the HUD (item toolbar, clock, etc) to the screen. The vanilla HUD may be hidden at this point (e.g. because a menu is open). Content drawn to the sprite batch at this point will appear under the HUD.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnRenderingHud(object sender, RenderingHudEventArgs e)
{
if (!Game1.eventUp &&
_toolBeingUpgraded != null)
// draw tool upgrade status
if (!Game1.eventUp && _toolBeingUpgraded != null)
{
Point iconPosition = IconHandler.Handler.GetNewIconPosition();
_toolUpgradeIcon =
@ -123,10 +133,13 @@ namespace UIInfoSuite.UIElements
}
}
private void DrawHoverText(object sender, EventArgs e)
/// <summary>Raised after drawing the HUD (item toolbar, clock, etc) to the sprite batch, but before it's rendered to the screen.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnRenderedHud(object sender, RenderedHudEventArgs e)
{
if (_toolBeingUpgraded != null &&
_toolUpgradeIcon.containsPoint(Game1.getMouseX(), Game1.getMouseY()))
// draw hover text
if (_toolBeingUpgraded != null && _toolUpgradeIcon.containsPoint(Game1.getMouseX(), Game1.getMouseY()))
{
IClickableMenu.drawHoverText(
Game1.spriteBatch,

View File

@ -1,15 +1,9 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using StardewModdingAPI;
using StardewModdingAPI.Events;
using StardewValley;
using StardewValley.Menus;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UIInfoSuite.Extensions;
namespace UIInfoSuite.UIElements
@ -22,16 +16,16 @@ namespace UIInfoSuite.UIElements
public void ToggleOption(bool showTravelingMerchant)
{
GraphicsEvents.OnPreRenderHudEvent -= DrawTravelingMerchant;
GraphicsEvents.OnPostRenderHudEvent -= DrawHoverText;
TimeEvents.AfterDayStarted -= DayChanged;
_helper.Events.Display.RenderingHud -= OnRenderingHud;
_helper.Events.Display.RenderedHud -= OnRenderedHud;
_helper.Events.GameLoop.DayStarted -= OnDayStarted;
if (showTravelingMerchant)
{
DayChanged(null, new EventArgsIntChanged(0, Game1.dayOfMonth));
GraphicsEvents.OnPreRenderHudEvent += DrawTravelingMerchant;
GraphicsEvents.OnPostRenderHudEvent += DrawHoverText;
TimeEvents.AfterDayStarted += DayChanged;
UpdateTravelingMerchant();
_helper.Events.Display.RenderingHud -= OnRenderingHud;
_helper.Events.Display.RenderedHud -= OnRenderedHud;
_helper.Events.GameLoop.DayStarted -= OnDayStarted;
}
}
@ -46,18 +40,27 @@ namespace UIInfoSuite.UIElements
ToggleOption(false);
}
private void DayChanged(object sender, EventArgs e)
/// <summary>Raised after the game begins a new day (including when the player loads a save).</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnDayStarted(object sender, EventArgs e)
{
UpdateTravelingMerchant();
}
private void UpdateTravelingMerchant()
{
int dayOfWeek = Game1.dayOfMonth % 7;
_travelingMerchantIsHere = dayOfWeek == 0 || dayOfWeek == 5;
}
private void DrawTravelingMerchant(object sender, EventArgs e)
/// <summary>Raised before drawing the HUD (item toolbar, clock, etc) to the screen. The vanilla HUD may be hidden at this point (e.g. because a menu is open).</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnRenderingHud(object sender, RenderingHudEventArgs e)
{
if (!Game1.eventUp &&
_travelingMerchantIsHere)
// draw traveling merchant
if (!Game1.eventUp && _travelingMerchantIsHere)
{
Point iconPosition = IconHandler.Handler.GetNewIconPosition();
_travelingMerchantIcon =
@ -70,10 +73,13 @@ namespace UIInfoSuite.UIElements
}
}
private void DrawHoverText(object sender, EventArgs e)
/// <summary>Raised after drawing the HUD (item toolbar, clock, etc) to the sprite batch, but before it's rendered to the screen.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnRenderedHud(object sender, RenderedHudEventArgs e)
{
if (_travelingMerchantIsHere &&
_travelingMerchantIcon.containsPoint(Game1.getMouseX(), Game1.getMouseY()))
// draw hover text
if (_travelingMerchantIsHere && _travelingMerchantIcon.containsPoint(Game1.getMouseX(), Game1.getMouseY()))
{
string hoverText = _helper.SafeGetString(
LanguageKeys.TravelingMerchantIsInTown);

View File

@ -7,19 +7,13 @@ using StardewValley;
using StardewValley.Characters;
using StardewValley.Network;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
namespace UIInfoSuite.UIElements
{
class ShowWhenAnimalNeedsPet : IDisposable
{
private readonly StardewValley.Object _wool = new StardewValley.Object(440, 1);
private readonly Timer _timer = new Timer();
private float _scale;
private float _yMovementPerDraw;
private float _alpha;
private readonly IModHelper _helper;
@ -33,14 +27,14 @@ namespace UIInfoSuite.UIElements
public void ToggleOption(bool showWhenAnimalNeedsPet)
{
_timer.Stop();
PlayerEvents.Warped -= OnLocationChange;
GraphicsEvents.OnPreRenderHudEvent -= DrawAnimalHasProduct;
_helper.Events.Player.Warped -= OnWarped;
_helper.Events.Display.RenderingHud -= OnRenderingHud_DrawAnimalHasProduct;
if (showWhenAnimalNeedsPet)
{
_timer.Start();
PlayerEvents.Warped += OnLocationChange;
GraphicsEvents.OnPreRenderHudEvent += DrawAnimalHasProduct;
_helper.Events.Player.Warped += OnWarped;
_helper.Events.Display.RenderingHud += OnRenderingHud_DrawAnimalHasProduct;
}
}
@ -49,7 +43,10 @@ namespace UIInfoSuite.UIElements
ToggleOption(false);
}
private void DrawAnimalHasProduct(object sender, EventArgs e)
/// <summary>Raised before drawing the HUD (item toolbar, clock, etc) to the screen. The vanilla HUD may be hidden at this point (e.g. because a menu is open).</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnRenderingHud_DrawAnimalHasProduct(object sender, RenderingHudEventArgs e)
{
if (!Game1.eventUp &&
Game1.activeClickableMenu == null &&
@ -95,25 +92,32 @@ namespace UIInfoSuite.UIElements
}
}
private void OnLocationChange(object sender, EventArgsPlayerWarped e)
/// <summary>Raised after a player warps to a new location.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnWarped(object sender, WarpedEventArgs e)
{
if (e.NewLocation is AnimalHouse ||
e.NewLocation is Farm)
if (e.IsLocalPlayer)
{
_timer.Interval = 1000;
_timer.Start();
}
else
{
_timer.Stop();
StopDrawingPetNeeds();
if (e.NewLocation is AnimalHouse || e.NewLocation is Farm)
{
_timer.Interval = 1000;
_timer.Start();
}
else
{
_timer.Stop();
StopDrawingPetNeeds();
}
}
}
private void DrawNeedsPetTooltip(object sender, EventArgs e)
/// <summary>Raised before drawing the HUD (item toolbar, clock, etc) to the screen. The vanilla HUD may be hidden at this point (e.g. because a menu is open).</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnRenderingHud_DrawNeedsPetTooltip(object sender, RenderingHudEventArgs e)
{
if (!Game1.eventUp &&
Game1.activeClickableMenu == null)
if (!Game1.eventUp && Game1.activeClickableMenu == null)
{
DrawIconForFarmAnimals();
DrawIconForPets();
@ -123,28 +127,33 @@ namespace UIInfoSuite.UIElements
private void StartDrawingPetNeeds(object sender, ElapsedEventArgs e)
{
_timer.Stop();
GraphicsEvents.OnPreRenderHudEvent += DrawNeedsPetTooltip;
GameEvents.SecondUpdateTick += UpdatePetDraw;
_scale = 4f;
_helper.Events.Display.RenderingHud += OnRenderingHud_DrawNeedsPetTooltip;
_helper.Events.GameLoop.UpdateTicked += UpdateTicked;
_yMovementPerDraw = -3f;
_alpha = 1f;
}
private void StopDrawingPetNeeds()
{
GraphicsEvents.OnPreRenderHudEvent -= DrawNeedsPetTooltip;
GameEvents.SecondUpdateTick -= UpdatePetDraw;
_helper.Events.Display.RenderingHud -= OnRenderingHud_DrawNeedsPetTooltip;
_helper.Events.GameLoop.UpdateTicked -= UpdateTicked;
}
private void UpdatePetDraw(object sender, EventArgs e)
/// <summary>Raised after the game state is updated (≈60 times per second).</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void UpdateTicked(object sender, UpdateTickedEventArgs e)
{
_scale += 0.01f;
_yMovementPerDraw += 0.3f;
_alpha -= 0.014f;
if (_alpha < 0.1f)
// update pet draw
if (e.IsMultipleOf(2))
{
StopDrawingPetNeeds();
_timer.Start();
_yMovementPerDraw += 0.3f;
_alpha -= 0.014f;
if (_alpha < 0.1f)
{
StopDrawingPetNeeds();
_timer.Start();
}
}
}

View File

@ -1,40 +1,45 @@
using Microsoft.Xna.Framework.Input;
using StardewModdingAPI;
using StardewModdingAPI.Events;
using StardewValley;
using StardewValley.Menus;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UIInfoSuite.UIElements
{
class SkipIntro
{
private readonly IModEvents _events;
//private bool _skipIntro = false;
public SkipIntro()
public SkipIntro(IModEvents events)
{
_events = events;
//GameEvents.QuarterSecondTick += CheckForSkip;
ControlEvents.KeyPressed += ControlEvents_KeyPressed;
SaveEvents.AfterLoad += StopCheckingForSkipKey;
events.Input.ButtonPressed += OnButtonPressed;
events.GameLoop.SaveLoaded += OnSaveLoaded;
//MenuEvents.MenuChanged += SkipToTitleButtons;
}
private void StopCheckingForSkipKey(object sender, EventArgs e)
/// <summary>Raised after the player loads a save slot and the world is initialised.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnSaveLoaded(object sender, EventArgs e)
{
ControlEvents.KeyPressed -= ControlEvents_KeyPressed;
SaveEvents.AfterLoad -= StopCheckingForSkipKey;
// stop checking for skip key
_events.Input.ButtonPressed -= OnButtonPressed;
_events.GameLoop.SaveLoaded -= OnSaveLoaded;
}
private void ControlEvents_KeyPressed(object sender, EventArgsKeyPressed e)
/// <summary>Raised after the player presses a button on the keyboard, controller, or mouse.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnButtonPressed(object sender, ButtonPressedEventArgs e)
{
if (Game1.activeClickableMenu is TitleMenu &&
e.KeyPressed == Keys.Escape)
if (Game1.activeClickableMenu is TitleMenu menu && e.Button == SButton.Escape)
{
(Game1.activeClickableMenu as TitleMenu)?.skipToTitleButtons();
ControlEvents.KeyPressed -= ControlEvents_KeyPressed;
menu.skipToTitleButtons();
_events.Input.ButtonPressed -= OnButtonPressed;
}
}

View File

@ -5,6 +5,6 @@
"Description": "Adds a lot of useful information to the user interface. This is based on Demiacle's excellent UIModSuite.",
"UniqueID": "Cdaragorn.UiInfoSuite",
"EntryDll": "UIInfoSuite.dll",
"MinimumApiVersion" : "2.6",
"MinimumApiVersion" : "2.9.3",
"UpdateKeys": [ "Nexus:1150" ]
}
}

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Pathoschild.Stardew.ModBuildConfig" version="2.1.0" targetFramework="net45" />
</packages>