forked from Pathoschild/StardewMods
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModEntry.cs
74 lines (65 loc) · 2.69 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
using System.Linq;
using Pathoschild.Stardew.Common;
using Pathoschild.Stardew.RotateToolbar.Framework;
using StardewModdingAPI;
using StardewModdingAPI.Events;
using StardewValley;
namespace Pathoschild.Stardew.RotateToolbar
{
/// <summary>The mod entry point.</summary>
internal class ModEntry : Mod
{
/*********
** Fields
*********/
/// <summary>The mod configuration.</summary>
private ModConfig Config;
/// <summary>The configured key bindings.</summary>
private ModConfigKeys Keys;
/*********
** 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)
{
// read config
this.Config = helper.ReadConfig<ModConfig>();
this.Keys = this.Config.Controls.ParseControls(this.Monitor);
// hook events
helper.Events.Input.ButtonPressed += this.OnButtonPressed;
}
/*********
** Private methods
*********/
/****
** Event handlers
****/
/// <summary>The method invoked when the player presses a button.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnButtonPressed(object sender, ButtonPressedEventArgs e)
{
if (!Context.IsWorldReady)
return;
// perform bound action
this.Monitor.InterceptErrors("handling your input", $"handling input '{e.Button}'", () =>
{
ModConfigKeys keys = this.Keys;
if (keys.ShiftToNext.Contains(e.Button))
this.RotateToolbar(true, this.Config.DeselectItemOnRotate);
else if (keys.ShiftToPrevious.Contains(e.Button))
this.RotateToolbar(false, this.Config.DeselectItemOnRotate);
});
}
/// <summary>Rotate the row shown in the toolbar.</summary>
/// <param name="next">Whether to show the next inventory row (else the previous).</param>
/// <param name="deselectSlot">Whether to deselect the current slot.</param>
private void RotateToolbar(bool next, bool deselectSlot)
{
Game1.player.shiftToolbar(next);
if (deselectSlot)
Game1.player.CurrentToolIndex = int.MaxValue; // Farmer::CurrentItem/Tool ignore the index if it's higher than the inventory size
}
}
}