forked from Pathoschild/StardewMods
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModEntry.cs
191 lines (163 loc) · 6.8 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
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
{
/*********
** Fields
*********/
/// <summary>The mod configuration.</summary>
private ModConfig Config;
/// <summary>Whether the game has launched.</summary>
private bool IsLaunched;
/// <summary>The current step in the mod logic.</summary>
private Stage CurrentStage = Stage.None;
/*********
** 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 = this.LoadConfig();
helper.Events.Display.MenuChanged += this.OnMenuChanged;
helper.Events.GameLoop.UpdateTicked += this.OnUpdateTicked;
}
/*********
** 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 OnMenuChanged(object sender, MenuChangedEventArgs e)
{
if (Constants.TargetPlatform == GamePlatform.Android)
return; // return to title doesn't replay intro on Android
if (e.NewMenu is TitleMenu)
this.CurrentStage = Stage.SkipIntro;
}
/// <summary>Receives an update tick.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnUpdateTicked(object sender, UpdateTickedEventArgs e)
{
try
{
// start intro skip on game launch
if (!this.IsLaunched)
{
if (!(Game1.activeClickableMenu is TitleMenu))
return;
this.IsLaunched = true;
this.CurrentStage = Stage.SkipIntro;
}
// apply skip logic
if (this.CurrentStage != Stage.None)
{
this.CurrentStage = Game1.activeClickableMenu is TitleMenu menu
? this.Skip(menu, this.CurrentStage)
: Stage.None;
}
}
catch (Exception ex)
{
this.Monitor.InterceptError(ex, "skipping the intro");
this.Helper.Events.GameLoop.UpdateTicked -= this.OnUpdateTicked;
}
}
/****
** Methods
****/
/// <summary>Load the mod configuration.</summary>
private ModConfig LoadConfig()
{
var config = this.Helper.ReadConfig<ModConfig>();
if (Constants.TargetPlatform == GamePlatform.Android)
{
if (this.Config.SkipTo == Screen.HostCoop || this.Config.SkipTo == Screen.JoinCoop)
this.Config.SkipTo = Screen.Title; // no co-op on Android
}
return config;
}
/// <summary>Skip the intro if the game is ready.</summary>
/// <param name="menu">The title menu whose intro to skip.</param>
/// <param name="currentStage">The current step in the mod logic.</param>
/// <returns>Returns the next step in the skip logic.</returns>
private Stage Skip(TitleMenu menu, Stage currentStage)
{
// wait until the game is ready
if (Game1.currentGameTime == null)
return currentStage;
// do nothing if a confirmation box is on-screen (e.g. multiplayer disconnect error)
if (TitleMenu.subMenu is ConfirmationDialog)
return Stage.None;
// main skip logic
if (currentStage == Stage.SkipIntro)
{
if (Constants.TargetPlatform == GamePlatform.Android)
{
// skip to title screen
menu.skipToTitleButtons();
// skip button transition
while (this.Helper.Reflection.GetField<bool>(menu, "isTransitioningButtons").GetValue())
menu.update(Game1.currentGameTime);
}
else
{
// skip to title screen
menu.receiveKeyPress(Keys.Escape);
menu.update(Game1.currentGameTime);
// skip button transition
while (this.Helper.Reflection.GetField<int>(menu, "buttonsToShow").GetValue() < TitleMenu.numberOfButtons)
menu.update(Game1.currentGameTime);
}
// skip to next screen
switch (this.Config.SkipTo)
{
case Screen.Title:
return Stage.None;
case Screen.Load:
// skip to load screen
menu.performButtonAction("Load");
while (TitleMenu.subMenu == null)
menu.update(Game1.currentGameTime);
return Stage.None;
case Screen.JoinCoop:
case Screen.HostCoop:
// skip to co-op screen
menu.performButtonAction("Co-op");
while (TitleMenu.subMenu == null)
menu.update(Game1.currentGameTime);
return this.Config.SkipTo == Screen.JoinCoop
? Stage.None
: Stage.WaitingForConnection;
}
}
// skip to host tab after connection is established
if (currentStage == Stage.WaitingForConnection)
{
// not applicable
if (this.Config.SkipTo != Screen.HostCoop || !(TitleMenu.subMenu is CoopMenu submenu))
return Stage.None;
// not connected yet
if (submenu.hostTab == null)
return currentStage;
// select host tab
submenu.receiveLeftClick(submenu.hostTab.bounds.X, submenu.hostTab.bounds.Y, playSound: false);
}
// ???
return Stage.None;
}
}
}