-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModEntry.cs
91 lines (71 loc) · 3.9 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
using StardewModdingAPI;
using StardewValley;
namespace QToDrop {
public class ModEntry : Mod {
/// <summary>The mod configuration from the player.</summary>
private ModConfig Config;
private bool IsDropItemKeybindPressedFirstSequence = false;
private bool IsDropItemKeybindPressedSecondSequence = false;
private bool IsCTRLPressed = false;
/// <summary>The mod entry point, called after the mod is first loaded.</summary>
/// <param name="helper">Provides simplified APIs for writing mods.</param>
public override void Entry(IModHelper helper) {
this.Config = this.Helper.ReadConfig<ModConfig>();
helper.ConsoleCommands.Add("qtodrop", "Set drop item keybind", this.SetDropItemKeybind);
helper.Events.Input.ButtonPressed += this.OnButtonPressed;
helper.Events.Input.ButtonReleased += this.OnButtonReleased;
helper.Events.GameLoop.UpdateTicked += this.OnUpdateTicked;
helper.Events.GameLoop.OneSecondUpdateTicked += this.OnOneSecondUpdateTicked;
}
private void OnOneSecondUpdateTicked(object sender, StardewModdingAPI.Events.OneSecondUpdateTickedEventArgs e) {
if (IsDropItemKeybindPressedFirstSequence) {
IsDropItemKeybindPressedSecondSequence = true;
}
}
private void OnUpdateTicked(object sender, StardewModdingAPI.Events.UpdateTickedEventArgs e) {
if (IsDropItemKeybindPressedSecondSequence) {
Game1.player.dropActiveItem();
}
}
private void SetDropItemKeybind(string command, string[] args) {
if (args == null || args.Length == 0) {
Monitor.Log("Invalid arguments. Usage: qtodrop [none|keybind]", LogLevel.Error);
return;
}
string keybind = args[0];
if (keybind == "none") {
this.Config.DropItemKeybind = null;
Monitor.Log("Drop item keybind disabled.", LogLevel.Info);
return;
}
this.Config.DropItemKeybind = keybind.ToLower();
Monitor.Log("Drop item keybind set to " + keybind.ToUpper() + "!", LogLevel.Info);
}
private void OnButtonPressed(object sender, StardewModdingAPI.Events.ButtonPressedEventArgs e) {
if (e.Button == SButton.LeftControl || e.Button == SButton.RightControl) {
IsCTRLPressed = true;
}
if (e.Button.ToString().ToLower().Equals(this.Config.DropItemKeybind.ToLower())) {
IsDropItemKeybindPressedFirstSequence = true;
if (IsCTRLPressed) {
if (Game1.player.CurrentItem == null || !Game1.player.CurrentItem.canBeDropped()) {
return;
}
Game1.createItemDebris(Game1.player.CurrentItem, Game1.player.getStandingPosition(), Game1.player.FacingDirection);
Game1.player.removeItemsFromInventory(Game1.player.CurrentItem.ParentSheetIndex, Game1.player.CurrentItem.Stack);
Game1.player.showNotCarrying();
}
Game1.player.dropActiveItem();
}
}
private void OnButtonReleased(object sender, StardewModdingAPI.Events.ButtonReleasedEventArgs e) {
if (e.Button == SButton.LeftControl || e.Button == SButton.RightControl) {
IsCTRLPressed = false;
}
if (e.Button.ToString().ToLower().Equals(this.Config.DropItemKeybind.ToLower())) {
IsDropItemKeybindPressedFirstSequence = false;
IsDropItemKeybindPressedSecondSequence = false;
}
}
}
}