using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Omegasis.BillboardAnywhere.Framework;
using StardewModdingAPI;
using StardewModdingAPI.Events;
using StardewValley;
using StardewValley.Menus;
namespace Omegasis.BillboardAnywhere
{
/// The mod entry point.
public class BillboardAnywhere : Mod
{
/*********
** Fields
*********/
/// The mod configuration.
private ModConfig Config;
///
/// The texture for the calendar button.
///
private Texture2D calendarTexture;
///
/// The texture for the quest button.
///
private Texture2D questTexture;
///
/// The button for the calendar menu.
///
public ClickableTextureComponent billboardButton;
///
/// The button for the quest menu.
///
public ClickableTextureComponent questButton;
/*********
** Public methods
*********/
/// The mod entry point, called after the mod is first loaded.
/// Provides simplified APIs for writing mods.
public override void Entry(IModHelper helper)
{
this.Config = helper.ReadConfig();
helper.ConsoleCommands.Add("Omegasis.BillboardAnywhere.ReloadConfig", "Reloads the config file for BillboardAnywhere to reposition the button for the inventory menu page.", this.reloadConfig);
helper.ConsoleCommands.Add("Omegasis.BillboardAnywhere.SetcalendarButtonX", "Sets the x position for the calendar button in the game menu.", this.setcalendarButtonX);
helper.ConsoleCommands.Add("Omegasis.BillboardAnywhere.SetcalendarButtonY", " Sets the y position for the calendar button in the game menu.", this.setcalendarButtonY);
helper.ConsoleCommands.Add("Omegasis.BillboardAnywhere.SetcalendarButtonPosition", " Sets the position for the calendar button in the game menu.", this.setcalendarButtonPosition);
helper.ConsoleCommands.Add("Omegasis.BillboardAnywhere.SetQuestButtonX", "Sets the x position for the quest button in the game menu.", this.setQuestButtonX);
helper.ConsoleCommands.Add("Omegasis.BillboardAnywhere.SetQuestButtonY", " Sets the y position for the quest button in the game menu.", this.setQuestButtonX);
helper.ConsoleCommands.Add("Omegasis.BillboardAnywhere.SetQuestButtonPosition", " Sets the position for the quest button in the game menu.", this.setQuestButtonPosition);
helper.ConsoleCommands.Add("Omegasis.BillboardAnywhere.SetcalendarButtonVisibility", " Sets the visibility for the billboard button in the game menu.", this.setcalendarButtonVisibility);
helper.ConsoleCommands.Add("Omegasis.BillboardAnywhere.SetQuestButtonVisibility", " Sets the visibility for the quest button in the game menu.", this.setQuestButtonVisibility);
helper.Events.Input.ButtonPressed += this.OnButtonPressed;
helper.Events.Display.RenderedActiveMenu += this.RenderBillboardMenuButton;
helper.Events.Input.ButtonPressed += this.Input_ButtonPressed;
this.calendarTexture = helper.Content.Load(Path.Combine("Assets", "Billboard.png"));
this.questTexture= helper.Content.Load(Path.Combine("Assets", "Quest.png"));
this.billboardButton = new ClickableTextureComponent(new Rectangle((int)this.Config.CalendarOffsetFromMenu.X, (int)this.Config.CalendarOffsetFromMenu.Y, this.calendarTexture.Width, this.calendarTexture.Height), this.calendarTexture, new Rectangle(0, 0, this.calendarTexture.Width, this.calendarTexture.Height), 1f, false);
this.questButton = new ClickableTextureComponent(new Rectangle((int)this.Config.QuestOffsetFromMenu.X, (int)this.Config.QuestOffsetFromMenu.Y, this.questTexture.Width, this.questTexture.Height), this.questTexture, new Rectangle(0, 0, this.questTexture.Width, this.questTexture.Height), 1f, false);
}
/*********
** Private methods
*********/
/// Raised after the player presses a button on the keyboard, controller, or mouse.
/// The event sender.
/// The event arguments.
public void OnButtonPressed(object sender, ButtonPressedEventArgs e)
{
// load menu if key pressed
if (Context.IsPlayerFree && e.Button == this.Config.CalendarKeyBinding)
Game1.activeClickableMenu = new Billboard();
if (Context.IsPlayerFree && e.Button == this.Config.QuestBoardKeyBinding)
{
Game1.RefreshQuestOfTheDay();
Game1.activeClickableMenu = new Billboard(true);
}
}
///
/// Checks to see if the billboard button is clicked.
///
///
///
private void Input_ButtonPressed(object sender, ButtonPressedEventArgs e)
{
if (Game1.activeClickableMenu == null) return;
if (e.Button == SButton.MouseLeft)
{
if (this.isInventoryPage())
{
if (this.billboardButton.containsPoint(Game1.getMousePosition().X, Game1.getMousePosition().Y))
{
if (this.Config.EnableInventoryCalendarButton == false) return;
Game1.activeClickableMenu = new Billboard(false);
}
if (this.questButton.containsPoint(Game1.getMousePosition().X, Game1.getMousePosition().Y))
{
if (this.Config.EnableInventoryQuestButton == false) return;
Game1.activeClickableMenu = new Billboard(true);
}
}
}
}
///
/// Renders the billboard button to the menu.
///
///
///
private void RenderBillboardMenuButton(object sender, RenderedActiveMenuEventArgs e)
{
if (this.isInventoryPage())
{
this.billboardButton.bounds = new Rectangle(Game1.activeClickableMenu.xPositionOnScreen + (int)this.Config.CalendarOffsetFromMenu.X, Game1.activeClickableMenu.yPositionOnScreen + (int)this.Config.CalendarOffsetFromMenu.Y, this.calendarTexture.Width, this.calendarTexture.Height);
this.questButton.bounds = new Rectangle(Game1.activeClickableMenu.xPositionOnScreen + (int)this.Config.QuestOffsetFromMenu.X, Game1.activeClickableMenu.yPositionOnScreen + (int)this.Config.QuestOffsetFromMenu.Y, this.calendarTexture.Width, this.calendarTexture.Height);
if(this.Config.EnableInventoryQuestButton) this.questButton.draw(Game1.spriteBatch);
if (this.Config.EnableInventoryCalendarButton) this.billboardButton.draw(Game1.spriteBatch);
GameMenu activeMenu = (Game1.activeClickableMenu as GameMenu);
activeMenu.drawMouse(Game1.spriteBatch);
if (this.billboardButton.containsPoint(Game1.getMousePosition().X, Game1.getMousePosition().Y))
{
//My deepest appologies for not being able to personally translate more text.
if (Game1.content.GetCurrentLanguage() == LocalizedContentManager.LanguageCode.en)
{
if (this.Config.EnableInventoryCalendarButton == false) return;
IClickableMenu.drawHoverText(Game1.spriteBatch, "Open Billboard Menu", Game1.smallFont);
}
}
if (this.questButton.containsPoint(Game1.getMousePosition().X, Game1.getMousePosition().Y))
{
//My deepest appologies once again for not being able to personally translate more text.
if (Game1.content.GetCurrentLanguage() == LocalizedContentManager.LanguageCode.en)
{
if (this.Config.EnableInventoryQuestButton == false) return;
IClickableMenu.drawHoverText(Game1.spriteBatch, "Open Quest Menu", Game1.smallFont);
}
}
}
}
///
/// Checks to see if the current active menu is the game menu and the current page is the inventory page.
///
///
private bool isInventoryPage()
{
if (Game1.activeClickableMenu == null) return false;
if (Game1.activeClickableMenu is StardewValley.Menus.GameMenu)
{
GameMenu activeMenu = (Game1.activeClickableMenu as GameMenu);
IClickableMenu currentTab = activeMenu.GetCurrentPage();
if (currentTab is InventoryPage)
{
return true;
}
}
return false;
}
///
/// Reloads the mod's config and repositions the menu button as necessary.
///
private void reloadConfig(string Name, string[] Params)
{
this.Config = this.Helper.ReadConfig();
this.billboardButton = new ClickableTextureComponent(new Rectangle((int)this.Config.CalendarOffsetFromMenu.X, (int)this.Config.CalendarOffsetFromMenu.Y, this.calendarTexture.Width, this.calendarTexture.Height), this.calendarTexture, new Rectangle(0, 0, this.calendarTexture.Width, this.calendarTexture.Height), 1f, false);
this.questButton = new ClickableTextureComponent(new Rectangle((int)this.Config.QuestOffsetFromMenu.X, (int)this.Config.QuestOffsetFromMenu.Y, this.questTexture.Width, this.questTexture.Height), this.questTexture, new Rectangle(0, 0, this.questTexture.Width, this.questTexture.Height), 1f, false);
}
///
/// Reloads the mod's config and repositions the menu button as necessary.
///
private void reloadConfig()
{
this.Config = this.Helper.ReadConfig();
this.billboardButton = new ClickableTextureComponent(new Rectangle((int)this.Config.CalendarOffsetFromMenu.X, (int)this.Config.CalendarOffsetFromMenu.Y, this.calendarTexture.Width, this.calendarTexture.Height), this.calendarTexture, new Rectangle(0, 0, this.calendarTexture.Width, this.calendarTexture.Height), 1f, false);
this.questButton = new ClickableTextureComponent(new Rectangle((int)this.Config.QuestOffsetFromMenu.X, (int)this.Config.QuestOffsetFromMenu.Y, this.questTexture.Width, this.questTexture.Height), this.questTexture, new Rectangle(0, 0, this.questTexture.Width, this.questTexture.Height), 1f, false);
}
///
/// Sets the x position of the menu button.
///
/// The name of the command.
/// The parameters passed into the command.
private void setcalendarButtonX(string Name, string[] Params)
{
this.Config.CalendarOffsetFromMenu = new Vector2(Convert.ToInt32(Params[0]), this.Config.CalendarOffsetFromMenu.Y);
this.Helper.WriteConfig(this.Config);
this.reloadConfig();
}
///
/// Sets the y position of the menu button.
///
/// The name of the command.
/// The parameters passed into the command.
private void setcalendarButtonY(string Name, string[] Params)
{
this.Config.CalendarOffsetFromMenu = new Vector2(this.Config.CalendarOffsetFromMenu.X, Convert.ToInt32(Params[0]));
this.Helper.WriteConfig(this.Config);
this.reloadConfig();
}
///
/// Sets the position of the menu button.
///
/// The name of the command.
/// The parameters passed into the command.
private void setcalendarButtonPosition(string Name, string[] Params)
{
this.Config.CalendarOffsetFromMenu = new Vector2(Convert.ToInt32(Params[0]), Convert.ToInt32(Params[1]));
this.Helper.WriteConfig(this.Config);
this.reloadConfig();
}
///
/// Sets the x position of the quest menu button.
///
/// The name of the command.
/// The parameters passed into the command.
private void setQuestButtonX(string Name, string[] Params)
{
this.Config.QuestOffsetFromMenu = new Vector2(Convert.ToInt32(Params[0]), this.Config.QuestOffsetFromMenu.Y);
this.Helper.WriteConfig(this.Config);
this.reloadConfig();
}
///
/// Sets the y position of the quest menu button.
///
/// The name of the command.
/// The parameters passed into the command.
private void setQuestButtonY(string Name, string[] Params)
{
this.Config.QuestOffsetFromMenu = new Vector2(this.Config.QuestOffsetFromMenu.X, Convert.ToInt32(Params[0]));
this.Helper.WriteConfig(this.Config);
this.reloadConfig();
}
///
/// Sets the position of the quest menu button.
///
/// The name of the command.
/// The parameters passed into the command.
private void setQuestButtonPosition(string Name, string[] Params)
{
this.Config.QuestOffsetFromMenu = new Vector2(Convert.ToInt32(Params[0]), Convert.ToInt32(Params[1]));
this.Helper.WriteConfig(this.Config);
this.reloadConfig();
}
///
/// Sets the visibility and functionality of the billboard menu button.
///
/// The name of the command.
/// The parameters passed into the command.
private void setcalendarButtonVisibility(string Name, string[] Params)
{
this.Config.EnableInventoryCalendarButton = Convert.ToBoolean(Params[0]);
this.Helper.WriteConfig(this.Config);
this.reloadConfig();
}
///
/// Sets the visibility and functionality of the quest menu button.
///
/// The name of the command.
/// The parameters passed into the command.
private void setQuestButtonVisibility(string Name, string[] Params)
{
this.Config.EnableInventoryQuestButton = Convert.ToBoolean(Params[0]);
this.Helper.WriteConfig(this.Config);
this.reloadConfig();
}
}
}