2017-07-20 11:51:05 +08:00
|
|
|
|
using UIInfoSuite.UIElements;
|
|
|
|
|
using StardewModdingAPI;
|
|
|
|
|
using StardewModdingAPI.Events;
|
|
|
|
|
using StardewValley;
|
|
|
|
|
using StardewValley.Menus;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Reflection;
|
2017-11-28 13:27:52 +08:00
|
|
|
|
using UIInfoSuite.Extensions;
|
2017-07-20 11:51:05 +08:00
|
|
|
|
|
|
|
|
|
namespace UIInfoSuite.Options
|
|
|
|
|
{
|
|
|
|
|
class ModOptionsPageHandler : IDisposable
|
|
|
|
|
{
|
|
|
|
|
private List<ModOptionsElement> _optionsElements = new List<ModOptionsElement>();
|
|
|
|
|
private readonly List<IDisposable> _elementsToDispose;
|
|
|
|
|
private readonly IDictionary<string, String> _options;
|
|
|
|
|
private ModOptionsPageButton _modOptionsPageButton;
|
|
|
|
|
private ModOptionsPage _modOptionsPage;
|
|
|
|
|
private readonly IModHelper _helper;
|
|
|
|
|
|
|
|
|
|
private int _modOptionsTabPageNumber;
|
|
|
|
|
|
|
|
|
|
private readonly LuckOfDay _luckOfDay;
|
2018-12-25 12:36:39 +08:00
|
|
|
|
private readonly ShowBirthdayIcon _showBirthdayIcon;
|
|
|
|
|
private readonly ShowAccurateHearts _showAccurateHearts;
|
2017-07-20 11:51:05 +08:00
|
|
|
|
private readonly LocationOfTownsfolk _locationOfTownsfolk;
|
|
|
|
|
private readonly ShowWhenAnimalNeedsPet _showWhenAnimalNeedsPet;
|
|
|
|
|
private readonly ShowCalendarAndBillboardOnGameMenuButton _showCalendarAndBillboardOnGameMenuButton;
|
|
|
|
|
private readonly ShowCropAndBarrelTime _showCropAndBarrelTime;
|
|
|
|
|
private readonly ShowItemEffectRanges _showScarecrowAndSprinklerRange;
|
|
|
|
|
private readonly ExperienceBar _experienceBar;
|
2018-12-25 12:36:39 +08:00
|
|
|
|
private readonly ShowItemHoverInformation _showItemHoverInformation;
|
2017-07-20 11:51:05 +08:00
|
|
|
|
private readonly ShowTravelingMerchant _showTravelingMerchant;
|
|
|
|
|
private readonly ShopHarvestPrices _shopHarvestPrices;
|
|
|
|
|
private readonly ShowQueenOfSauceIcon _showQueenOfSauceIcon;
|
2017-11-28 13:27:52 +08:00
|
|
|
|
private readonly ShowToolUpgradeStatus _showToolUpgradeStatus;
|
2017-07-20 11:51:05 +08:00
|
|
|
|
|
|
|
|
|
public ModOptionsPageHandler(IModHelper helper, IDictionary<String, String> options)
|
|
|
|
|
{
|
|
|
|
|
_options = options;
|
2018-12-25 12:36:39 +08:00
|
|
|
|
helper.Events.Display.MenuChanged += ToggleModOptions;
|
2017-07-20 11:51:05 +08:00
|
|
|
|
_helper = helper;
|
|
|
|
|
ModConfig modConfig = _helper.ReadConfig<ModConfig>();
|
|
|
|
|
_luckOfDay = new LuckOfDay(helper);
|
2018-12-25 12:36:39 +08:00
|
|
|
|
_showBirthdayIcon = new ShowBirthdayIcon(helper.Events);
|
|
|
|
|
_showAccurateHearts = new ShowAccurateHearts(helper.Events);
|
|
|
|
|
_locationOfTownsfolk = new LocationOfTownsfolk(helper, _options);
|
|
|
|
|
_showWhenAnimalNeedsPet = new ShowWhenAnimalNeedsPet(helper);
|
2017-11-28 13:27:52 +08:00
|
|
|
|
_showCalendarAndBillboardOnGameMenuButton = new ShowCalendarAndBillboardOnGameMenuButton(helper);
|
2018-12-25 12:36:39 +08:00
|
|
|
|
_showScarecrowAndSprinklerRange = new ShowItemEffectRanges(modConfig, helper.Events);
|
2017-07-20 11:51:05 +08:00
|
|
|
|
_experienceBar = new ExperienceBar(helper);
|
2018-12-25 12:36:39 +08:00
|
|
|
|
_showItemHoverInformation = new ShowItemHoverInformation(helper.Events);
|
2017-07-20 11:51:05 +08:00
|
|
|
|
_shopHarvestPrices = new ShopHarvestPrices(helper);
|
|
|
|
|
_showQueenOfSauceIcon = new ShowQueenOfSauceIcon(helper);
|
|
|
|
|
_showTravelingMerchant = new ShowTravelingMerchant(helper);
|
|
|
|
|
_showCropAndBarrelTime = new ShowCropAndBarrelTime(helper);
|
2017-11-28 13:27:52 +08:00
|
|
|
|
_showToolUpgradeStatus = new ShowToolUpgradeStatus(helper);
|
2017-07-20 11:51:05 +08:00
|
|
|
|
|
|
|
|
|
_elementsToDispose = new List<IDisposable>()
|
|
|
|
|
{
|
|
|
|
|
_luckOfDay,
|
|
|
|
|
_showBirthdayIcon,
|
|
|
|
|
_showAccurateHearts,
|
|
|
|
|
_locationOfTownsfolk,
|
|
|
|
|
_showWhenAnimalNeedsPet,
|
|
|
|
|
_showCalendarAndBillboardOnGameMenuButton,
|
|
|
|
|
_showCropAndBarrelTime,
|
|
|
|
|
_experienceBar,
|
|
|
|
|
_showItemHoverInformation,
|
|
|
|
|
_showTravelingMerchant,
|
|
|
|
|
_shopHarvestPrices,
|
2017-11-28 13:27:52 +08:00
|
|
|
|
_showQueenOfSauceIcon,
|
|
|
|
|
_showToolUpgradeStatus
|
2017-07-20 11:51:05 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int whichOption = 1;
|
|
|
|
|
Version thisVersion = Assembly.GetAssembly(this.GetType()).GetName().Version;
|
|
|
|
|
_optionsElements.Add(new ModOptionsElement("UI Info Suite v" +
|
|
|
|
|
thisVersion.Major + "." + thisVersion.Minor + "." + thisVersion.Build));
|
2017-11-28 13:27:52 +08:00
|
|
|
|
_optionsElements.Add(new ModOptionsCheckbox(_helper.SafeGetString(OptionKeys.ShowLuckIcon), whichOption++, _luckOfDay.Toggle, _options, OptionKeys.ShowLuckIcon));
|
|
|
|
|
_optionsElements.Add(new ModOptionsCheckbox(_helper.SafeGetString(OptionKeys.ShowLevelUpAnimation), whichOption++, _experienceBar.ToggleLevelUpAnimation, _options, OptionKeys.ShowLevelUpAnimation));
|
|
|
|
|
_optionsElements.Add(new ModOptionsCheckbox(_helper.SafeGetString(OptionKeys.ShowExperienceBar), whichOption++, _experienceBar.ToggleShowExperienceBar, _options, OptionKeys.ShowExperienceBar));
|
|
|
|
|
_optionsElements.Add(new ModOptionsCheckbox(_helper.SafeGetString(OptionKeys.AllowExperienceBarToFadeOut), whichOption++, _experienceBar.ToggleExperienceBarFade, _options, OptionKeys.AllowExperienceBarToFadeOut));
|
|
|
|
|
_optionsElements.Add(new ModOptionsCheckbox(_helper.SafeGetString(OptionKeys.ShowExperienceGain), whichOption++, _experienceBar.ToggleShowExperienceGain, _options, OptionKeys.ShowExperienceGain));
|
|
|
|
|
_optionsElements.Add(new ModOptionsCheckbox(_helper.SafeGetString(OptionKeys.ShowLocationOfTownsPeople), whichOption++, _locationOfTownsfolk.ToggleShowNPCLocationsOnMap, _options, OptionKeys.ShowLocationOfTownsPeople));
|
|
|
|
|
_optionsElements.Add(new ModOptionsCheckbox(_helper.SafeGetString(OptionKeys.ShowBirthdayIcon), whichOption++, _showBirthdayIcon.ToggleOption, _options, OptionKeys.ShowBirthdayIcon));
|
|
|
|
|
_optionsElements.Add(new ModOptionsCheckbox(_helper.SafeGetString(OptionKeys.ShowHeartFills), whichOption++, _showAccurateHearts.ToggleOption, _options, OptionKeys.ShowHeartFills));
|
|
|
|
|
_optionsElements.Add(new ModOptionsCheckbox(_helper.SafeGetString(OptionKeys.ShowAnimalsNeedPets), whichOption++, _showWhenAnimalNeedsPet.ToggleOption, _options, OptionKeys.ShowAnimalsNeedPets));
|
|
|
|
|
_optionsElements.Add(new ModOptionsCheckbox(_helper.SafeGetString(OptionKeys.DisplayCalendarAndBillboard), whichOption++, _showCalendarAndBillboardOnGameMenuButton.ToggleOption, _options, OptionKeys.DisplayCalendarAndBillboard));
|
|
|
|
|
_optionsElements.Add(new ModOptionsCheckbox(_helper.SafeGetString(OptionKeys.ShowCropAndBarrelTooltip), whichOption++, _showCropAndBarrelTime.ToggleOption, _options, OptionKeys.ShowCropAndBarrelTooltip));
|
|
|
|
|
_optionsElements.Add(new ModOptionsCheckbox(_helper.SafeGetString(OptionKeys.ShowItemEffectRanges), whichOption++, _showScarecrowAndSprinklerRange.ToggleOption, _options, OptionKeys.ShowItemEffectRanges));
|
|
|
|
|
_optionsElements.Add(new ModOptionsCheckbox(_helper.SafeGetString(OptionKeys.ShowExtraItemInformation), whichOption++, _showItemHoverInformation.ToggleOption, _options, OptionKeys.ShowExtraItemInformation));
|
|
|
|
|
_optionsElements.Add(new ModOptionsCheckbox(_helper.SafeGetString(OptionKeys.ShowTravelingMerchant), whichOption++, _showTravelingMerchant.ToggleOption, _options, OptionKeys.ShowTravelingMerchant));
|
|
|
|
|
_optionsElements.Add(new ModOptionsCheckbox(_helper.SafeGetString(OptionKeys.ShowHarvestPricesInShop), whichOption++, _shopHarvestPrices.ToggleOption, _options, OptionKeys.ShowHarvestPricesInShop));
|
|
|
|
|
_optionsElements.Add(new ModOptionsCheckbox(_helper.SafeGetString(OptionKeys.ShowWhenNewRecipesAreAvailable), whichOption++, _showQueenOfSauceIcon.ToggleOption, _options, OptionKeys.ShowWhenNewRecipesAreAvailable));
|
|
|
|
|
_optionsElements.Add(new ModOptionsCheckbox(_helper.SafeGetString(OptionKeys.ShowToolUpgradeStatus), whichOption++, _showToolUpgradeStatus.ToggleOption, _options, OptionKeys.ShowToolUpgradeStatus));
|
2017-07-20 11:51:05 +08:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-16 00:50:29 +08:00
|
|
|
|
|
2017-07-20 11:51:05 +08:00
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in _elementsToDispose)
|
|
|
|
|
item.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnButtonLeftClicked(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (Game1.activeClickableMenu is GameMenu)
|
|
|
|
|
{
|
|
|
|
|
SetActiveClickableMenuToModOptionsPage();
|
|
|
|
|
Game1.playSound("smallSelect");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-25 12:36:39 +08:00
|
|
|
|
/// <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)
|
2017-07-20 11:51:05 +08:00
|
|
|
|
{
|
2018-12-25 12:36:39 +08:00
|
|
|
|
// remove from old menu
|
|
|
|
|
if (e.OldMenu != null)
|
2017-07-20 11:51:05 +08:00
|
|
|
|
{
|
2018-12-25 12:36:39 +08:00
|
|
|
|
_helper.Events.Display.RenderedActiveMenu -= DrawButton;
|
|
|
|
|
if (_modOptionsPageButton != null)
|
|
|
|
|
_modOptionsPageButton.OnLeftClicked -= OnButtonLeftClicked;
|
|
|
|
|
|
|
|
|
|
if (e.OldMenu is GameMenu)
|
|
|
|
|
{
|
|
|
|
|
List<IClickableMenu> tabPages = _helper.Reflection.GetField<List<IClickableMenu>>(e.OldMenu, "pages").GetValue();
|
|
|
|
|
tabPages.Remove(_modOptionsPage);
|
|
|
|
|
}
|
2017-07-20 11:51:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-25 12:36:39 +08:00
|
|
|
|
// add to new menu
|
|
|
|
|
if (e.NewMenu is GameMenu newMenu)
|
2017-07-20 11:51:05 +08:00
|
|
|
|
{
|
|
|
|
|
if (_modOptionsPageButton == null)
|
|
|
|
|
{
|
2018-12-25 12:36:39 +08:00
|
|
|
|
_modOptionsPage = new ModOptionsPage(_optionsElements, _helper.Events);
|
|
|
|
|
_modOptionsPageButton = new ModOptionsPageButton(_helper.Events);
|
2017-07-20 11:51:05 +08:00
|
|
|
|
}
|
2018-12-25 12:36:39 +08:00
|
|
|
|
|
|
|
|
|
_helper.Events.Display.RenderedActiveMenu += DrawButton;
|
2017-07-20 11:51:05 +08:00
|
|
|
|
_modOptionsPageButton.OnLeftClicked += OnButtonLeftClicked;
|
2018-12-25 12:36:39 +08:00
|
|
|
|
List<IClickableMenu> tabPages = _helper.Reflection.GetField<List<IClickableMenu>>(newMenu, "pages").GetValue();
|
2018-05-06 12:21:18 +08:00
|
|
|
|
|
2017-07-20 11:51:05 +08:00
|
|
|
|
_modOptionsTabPageNumber = tabPages.Count;
|
|
|
|
|
tabPages.Add(_modOptionsPage);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetActiveClickableMenuToModOptionsPage()
|
|
|
|
|
{
|
2018-07-16 00:50:29 +08:00
|
|
|
|
if (Game1.activeClickableMenu is GameMenu menu)
|
2017-07-20 11:51:05 +08:00
|
|
|
|
menu.currentTab = _modOptionsTabPageNumber;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DrawButton(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (Game1.activeClickableMenu is GameMenu &&
|
|
|
|
|
(Game1.activeClickableMenu as GameMenu).currentTab != 3) //don't render when the map is showing
|
|
|
|
|
{
|
|
|
|
|
if ((Game1.activeClickableMenu as GameMenu).currentTab == _modOptionsTabPageNumber)
|
|
|
|
|
{
|
|
|
|
|
_modOptionsPageButton.yPositionOnScreen = Game1.activeClickableMenu.yPositionOnScreen + 24;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_modOptionsPageButton.yPositionOnScreen = Game1.activeClickableMenu.yPositionOnScreen + 16;
|
|
|
|
|
}
|
|
|
|
|
_modOptionsPageButton.draw(Game1.spriteBatch);
|
|
|
|
|
|
|
|
|
|
//Might need to render hover text here
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|