2019-11-30 06:22:20 +08:00
using System ;
using System.IO ;
using Microsoft.Xna.Framework ;
using Microsoft.Xna.Framework.Graphics ;
2018-12-30 18:00:05 +08:00
using Omegasis.BillboardAnywhere.Framework ;
2017-07-28 08:28:39 +08:00
using StardewModdingAPI ;
2017-07-30 01:54:26 +08:00
using StardewModdingAPI.Events ;
2017-07-28 08:28:39 +08:00
using StardewValley ;
2017-07-30 01:54:26 +08:00
using StardewValley.Menus ;
2017-07-28 08:28:39 +08:00
namespace Omegasis.BillboardAnywhere
2016-10-20 15:15:14 +08:00
{
2017-07-30 01:54:26 +08:00
/// <summary>The mod entry point.</summary>
public class BillboardAnywhere : Mod
2016-10-20 15:15:14 +08:00
{
2017-07-30 01:54:26 +08:00
/ * * * * * * * * *
2019-01-06 15:23:07 +08:00
* * Fields
2017-07-30 01:54:26 +08:00
* * * * * * * * * /
2017-08-06 03:51:44 +08:00
/// <summary>The mod configuration.</summary>
private ModConfig Config ;
2016-10-20 15:15:14 +08:00
2019-11-30 06:22:20 +08:00
/// <summary>
/// The texture for the calendar button.
/// </summary>
private Texture2D calendarTexture ;
/// <summary>
/// The texture for the quest button.
/// </summary>
private Texture2D questTexture ;
/// <summary>
/// The button for the calendar menu.
/// </summary>
public ClickableTextureComponent billboardButton ;
/// <summary>
/// The button for the quest menu.
/// </summary>
public ClickableTextureComponent questButton ;
2017-07-30 01:54:26 +08:00
/ * * * * * * * * *
* * Public methods
* * * * * * * * * /
/// <summary>The mod entry point, called after the mod is first loaded.</summary>
/// <param name="helper">Provides simplified APIs for writing mods.</param>
2016-12-09 08:34:28 +08:00
public override void Entry ( IModHelper helper )
2016-10-20 15:15:14 +08:00
{
2017-08-06 03:51:44 +08:00
this . Config = helper . ReadConfig < ModConfig > ( ) ;
2019-11-30 06:22:20 +08:00
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" , "<int>Sets the x position for the calendar button in the game menu." , this . setcalendarButtonX ) ;
helper . ConsoleCommands . Add ( "Omegasis.BillboardAnywhere.SetcalendarButtonY" , "<int> Sets the y position for the calendar button in the game menu." , this . setcalendarButtonY ) ;
helper . ConsoleCommands . Add ( "Omegasis.BillboardAnywhere.SetcalendarButtonPosition" , "<int,int> Sets the position for the calendar button in the game menu." , this . setcalendarButtonPosition ) ;
helper . ConsoleCommands . Add ( "Omegasis.BillboardAnywhere.SetQuestButtonX" , "<int>Sets the x position for the quest button in the game menu." , this . setQuestButtonX ) ;
helper . ConsoleCommands . Add ( "Omegasis.BillboardAnywhere.SetQuestButtonY" , "<int> Sets the y position for the quest button in the game menu." , this . setQuestButtonX ) ;
helper . ConsoleCommands . Add ( "Omegasis.BillboardAnywhere.SetQuestButtonPosition" , "<int,int> Sets the position for the quest button in the game menu." , this . setQuestButtonPosition ) ;
helper . ConsoleCommands . Add ( "Omegasis.BillboardAnywhere.SetcalendarButtonVisibility" , "<bool> Sets the visibility for the billboard button in the game menu." , this . setcalendarButtonVisibility ) ;
helper . ConsoleCommands . Add ( "Omegasis.BillboardAnywhere.SetQuestButtonVisibility" , "<bool> Sets the visibility for the quest button in the game menu." , this . setQuestButtonVisibility ) ;
2019-01-06 15:21:06 +08:00
helper . Events . Input . ButtonPressed + = this . OnButtonPressed ;
2019-11-30 06:22:20 +08:00
helper . Events . Display . RenderedActiveMenu + = this . RenderBillboardMenuButton ;
helper . Events . Input . ButtonPressed + = this . Input_ButtonPressed ;
2016-10-20 15:15:14 +08:00
2019-11-30 06:22:20 +08:00
this . calendarTexture = helper . Content . Load < Texture2D > ( Path . Combine ( "Assets" , "Billboard.png" ) ) ;
this . questTexture = helper . Content . Load < Texture2D > ( 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 ) ;
}
2017-07-30 01:54:26 +08:00
/ * * * * * * * * *
* * Private methods
* * * * * * * * * /
2019-01-06 15:21:06 +08:00
/// <summary>Raised after the player presses a button on the keyboard, controller, or mouse.</summary>
2017-07-30 01:54:26 +08:00
/// <param name="sender">The event sender.</param>
2019-01-06 15:21:06 +08:00
/// <param name="e">The event arguments.</param>
public void OnButtonPressed ( object sender , ButtonPressedEventArgs e )
2016-10-20 15:15:14 +08:00
{
2017-07-30 01:54:26 +08:00
// load menu if key pressed
2019-11-30 06:22:20 +08:00
if ( Context . IsPlayerFree & & e . Button = = this . Config . CalendarKeyBinding )
2017-07-30 01:54:26 +08:00
Game1 . activeClickableMenu = new Billboard ( ) ;
2019-11-30 06:22:20 +08:00
if ( Context . IsPlayerFree & & e . Button = = this . Config . QuestBoardKeyBinding )
{
Game1 . RefreshQuestOfTheDay ( ) ;
Game1 . activeClickableMenu = new Billboard ( true ) ;
}
}
/// <summary>
/// Checks to see if the billboard button is clicked.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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 ) ;
}
}
}
}
/// <summary>
/// Renders the billboard button to the menu.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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 ) ;
}
}
}
}
/// <summary>
/// Checks to see if the current active menu is the game menu and the current page is the inventory page.
/// </summary>
/// <returns></returns>
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 ;
}
/// <summary>
/// Reloads the mod's config and repositions the menu button as necessary.
/// </summary>
private void reloadConfig ( string Name , string [ ] Params )
{
this . Config = this . Helper . ReadConfig < ModConfig > ( ) ;
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 ) ;
}
/// <summary>
/// Reloads the mod's config and repositions the menu button as necessary.
/// </summary>
private void reloadConfig ( )
{
this . Config = this . Helper . ReadConfig < ModConfig > ( ) ;
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 ) ;
}
/// <summary>
/// Sets the x position of the menu button.
/// </summary>
/// <param name="Name">The name of the command.</param>
/// <param name="Params">The parameters passed into the command.</param>
private void setcalendarButtonX ( string Name , string [ ] Params )
{
this . Config . CalendarOffsetFromMenu = new Vector2 ( Convert . ToInt32 ( Params [ 0 ] ) , this . Config . CalendarOffsetFromMenu . Y ) ;
this . Helper . WriteConfig < ModConfig > ( this . Config ) ;
this . reloadConfig ( ) ;
}
/// <summary>
/// Sets the y position of the menu button.
/// </summary>
/// <param name="Name">The name of the command.</param>
/// <param name="Params">The parameters passed into the command.</param>
private void setcalendarButtonY ( string Name , string [ ] Params )
{
this . Config . CalendarOffsetFromMenu = new Vector2 ( this . Config . CalendarOffsetFromMenu . X , Convert . ToInt32 ( Params [ 0 ] ) ) ;
this . Helper . WriteConfig < ModConfig > ( this . Config ) ;
this . reloadConfig ( ) ;
}
/// <summary>
/// Sets the position of the menu button.
/// </summary>
/// <param name="Name">The name of the command.</param>
/// <param name="Params">The parameters passed into the command.</param>
private void setcalendarButtonPosition ( string Name , string [ ] Params )
{
this . Config . CalendarOffsetFromMenu = new Vector2 ( Convert . ToInt32 ( Params [ 0 ] ) , Convert . ToInt32 ( Params [ 1 ] ) ) ;
this . Helper . WriteConfig < ModConfig > ( this . Config ) ;
this . reloadConfig ( ) ;
}
/// <summary>
/// Sets the x position of the quest menu button.
/// </summary>
/// <param name="Name">The name of the command.</param>
/// <param name="Params">The parameters passed into the command.</param>
private void setQuestButtonX ( string Name , string [ ] Params )
{
this . Config . QuestOffsetFromMenu = new Vector2 ( Convert . ToInt32 ( Params [ 0 ] ) , this . Config . QuestOffsetFromMenu . Y ) ;
this . Helper . WriteConfig < ModConfig > ( this . Config ) ;
this . reloadConfig ( ) ;
}
/// <summary>
/// Sets the y position of the quest menu button.
/// </summary>
/// <param name="Name">The name of the command.</param>
/// <param name="Params">The parameters passed into the command.</param>
private void setQuestButtonY ( string Name , string [ ] Params )
{
this . Config . QuestOffsetFromMenu = new Vector2 ( this . Config . QuestOffsetFromMenu . X , Convert . ToInt32 ( Params [ 0 ] ) ) ;
this . Helper . WriteConfig < ModConfig > ( this . Config ) ;
this . reloadConfig ( ) ;
}
/// <summary>
/// Sets the position of the quest menu button.
/// </summary>
/// <param name="Name">The name of the command.</param>
/// <param name="Params">The parameters passed into the command.</param>
private void setQuestButtonPosition ( string Name , string [ ] Params )
{
this . Config . QuestOffsetFromMenu = new Vector2 ( Convert . ToInt32 ( Params [ 0 ] ) , Convert . ToInt32 ( Params [ 1 ] ) ) ;
this . Helper . WriteConfig < ModConfig > ( this . Config ) ;
this . reloadConfig ( ) ;
}
/// <summary>
/// Sets the visibility and functionality of the billboard menu button.
/// </summary>
/// <param name="Name">The name of the command.</param>
/// <param name="Params">The parameters passed into the command.</param>
private void setcalendarButtonVisibility ( string Name , string [ ] Params )
{
this . Config . EnableInventoryCalendarButton = Convert . ToBoolean ( Params [ 0 ] ) ;
this . Helper . WriteConfig < ModConfig > ( this . Config ) ;
this . reloadConfig ( ) ;
}
/// <summary>
/// Sets the visibility and functionality of the quest menu button.
/// </summary>
/// <param name="Name">The name of the command.</param>
/// <param name="Params">The parameters passed into the command.</param>
private void setQuestButtonVisibility ( string Name , string [ ] Params )
{
this . Config . EnableInventoryQuestButton = Convert . ToBoolean ( Params [ 0 ] ) ;
this . Helper . WriteConfig < ModConfig > ( this . Config ) ;
this . reloadConfig ( ) ;
2016-10-20 15:15:14 +08:00
}
}
}