forked from Pathoschild/StardewMods
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModEntry.cs
110 lines (97 loc) · 3.63 KB
/
ModEntry.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using System;
using Microsoft.Xna.Framework.Input;
using Pathoschild.Stardew.Common;
using Pathoschild.Stardew.SkipIntro.Framework;
using StardewModdingAPI;
using StardewModdingAPI.Events;
using StardewValley;
using StardewValley.Menus;
namespace Pathoschild.Stardew.SkipIntro
{
/// <summary>The mod entry point.</summary>
internal class ModEntry : Mod
{
/*********
** Properties
*********/
/// <summary>The mod configuration.</summary>
private ModConfig Config;
/*********
** Public methods
*********/
/// <summary>The mod entry point, called after the mod is first loaded.</summary>
/// <param name="helper">Provides methods for interacting with the mod directory, such as read/writing a config file or custom JSON files.</param>
public override void Entry(IModHelper helper)
{
this.Config = helper.ReadConfig<ModConfig>();
MenuEvents.MenuChanged += this.MenuEvents_MenuChanged;
}
/*********
** Private methods
*********/
/****
** Event handlers
****/
/// <summary>The method called when the player returns to the title screen.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e)
{
if (e.NewMenu is TitleMenu)
GameEvents.UpdateTick += this.GameEvents_UpdateTick;
}
/// <summary>Receives an update tick.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void GameEvents_UpdateTick(object sender, EventArgs e)
{
try
{
// get open title screen
TitleMenu menu = Game1.activeClickableMenu as TitleMenu;
if (menu == null)
{
GameEvents.UpdateTick -= this.GameEvents_UpdateTick;
return;
}
// skip intro
if (this.TrySkipIntro(menu))
GameEvents.UpdateTick -= this.GameEvents_UpdateTick;
}
catch (Exception ex)
{
this.Monitor.InterceptError(ex, "skipping the intro");
GameEvents.UpdateTick -= this.GameEvents_UpdateTick;
}
}
/****
** Methods
****/
/// <summary>Skip the intro if the game is ready.</summary>
/// <param name="menu">The title menu whose intro to skip.</param>
/// <returns>Returns whether the intro was skipped successfully.</returns>
private bool TrySkipIntro(TitleMenu menu)
{
// wait until the game is ready
if (Game1.currentGameTime == null)
return false;
// skip to title screen
menu.receiveKeyPress(Keys.Escape);
menu.update(Game1.currentGameTime);
// skip button transition
if (!this.Config.SkipToLoadScreen)
{
while (this.Helper.Reflection.GetField<int>(menu, "buttonsToShow").GetValue() < TitleMenu.numberOfButtons)
menu.update(Game1.currentGameTime);
}
// skip to load screen
if (this.Config.SkipToLoadScreen)
{
menu.performButtonAction("Load");
while (TitleMenu.subMenu == null)
menu.update(Game1.currentGameTime);
}
return true;
}
}
}