-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputManager.cs
More file actions
148 lines (135 loc) · 5.76 KB
/
InputManager.cs
File metadata and controls
148 lines (135 loc) · 5.76 KB
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
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using BepInEx.Logging;
using HarmonyLib;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
namespace BiggerSprayMod
{
public class InputManager
{
private readonly BiggerSprayMod _plugin;
public InputManager(BiggerSprayMod plugin)
{
_plugin = plugin;
}
public void ProcessInputs()
{
// Handle GIF mode toggle
if (Input.GetKeyDown(_plugin._configManager.ToggleGifModeKey.Value))
{
_plugin._gifManager.ToggleGifMode();
}
// Handle image selection based on current mode
if (_plugin._gifManager.IsGifMode)
{
// GIF mode navigation
if (Input.GetKeyDown(_plugin._configManager.PreviousSprayKey.Value))
{
_plugin._gifManager.SelectPreviousGif();
// Sync the config setting
if (!string.IsNullOrEmpty(_plugin._gifManager.CurrentGifName))
{
_plugin._configManager.SelectedGifName.Value = _plugin._gifManager.CurrentGifName;
}
}
else if (Input.GetKeyDown(_plugin._configManager.NextSprayKey.Value))
{
_plugin._gifManager.SelectNextGif();
// Sync the config setting
if (!string.IsNullOrEmpty(_plugin._gifManager.CurrentGifName))
{
_plugin._configManager.SelectedGifName.Value = _plugin._gifManager.CurrentGifName;
}
}
}
else
{
// Regular image navigation
if (Input.GetKeyDown(_plugin._configManager.PreviousSprayKey.Value))
{
SelectPreviousSpray();
}
else if (Input.GetKeyDown(_plugin._configManager.NextSprayKey.Value))
{
SelectNextSpray();
}
}
// Handle scaling mode
if (Input.GetKeyDown(_plugin._configManager.ScaleKey.Value))
{
ScalingUtils.StartScalingMode();
}
else if (Input.GetKeyUp(_plugin._configManager.ScaleKey.Value))
{
ScalingUtils.StopScalingMode();
}
// Handle key-based scale adjustments
if (Input.GetKeyDown(_plugin._configManager.IncreaseScaleKey.Value))
{
_plugin._scalingUtils.AdjustScale(_plugin._configManager.ScaleSpeed.Value);
}
else if (Input.GetKeyDown(_plugin._configManager.DecreaseScaleKey.Value))
{
_plugin._scalingUtils.AdjustScale(-_plugin._configManager.ScaleSpeed.Value);
}
// Handle scroll wheel for scaling
if (_plugin._isScaling && _plugin._configManager.UseScrollWheel.Value)
{
float scrollDelta = Input.mouseScrollDelta.y;
if (Mathf.Abs(scrollDelta) > 0.01f)
{
_plugin._scalingUtils.AdjustScale(scrollDelta * _plugin._configManager.ScaleSpeed.Value);
}
}
// Update scaling preview if active
if (_plugin._isScaling)
{
_plugin._scalingUtils.UpdateScalingPreview();
}
else if (Input.GetKeyDown(_plugin._configManager.SprayKey.Value))
{
PlayerAvatar? player;
// Check if we are currently in multiplayer mode
if (PhotonNetwork.InRoom)
{
// Get the PlayerAvatar component from the local player
List<PlayerAvatar> playerAvatars = SemiFunc.PlayerGetAll();
player = playerAvatars.FirstOrDefault(p => p.photonView.IsMine);
}
else
{
// In single-player mode, get the PlayerAvatar from the local player
player = SemiFunc.PlayerAvatarLocal();
}
if (player == null)
{
_plugin.LogMessage(LogLevel.Warning, "[BiggerSprayMod][" + (PhotonNetwork.InRoom ? "Multiplayer" : "Singleplayer") + "] No PlayerAvatar found.");
return;
}
// Make sure the player is still alive and the spray is available (BindingFlags.Instance | BindingFlags.NonPublic, check deadSet in PlayerAvatar)
bool isAlive = !(bool)(typeof(PlayerAvatar).GetField("deadSet", BindingFlags.Instance | BindingFlags.NonPublic)
?.GetValue(player) ?? false);
if (isAlive)
{
// Trigger the spray action
_plugin._sprayUtils.TrySpray();
}
}
}
private void SelectPreviousSpray()
{
int currentIndex = _plugin._availableImages.IndexOf(_plugin._configManager.SelectedSprayImage.Value);
int newIndex = (currentIndex - 1 + _plugin._availableImages.Count) % _plugin._availableImages.Count;
_plugin._configManager.SelectedSprayImage.Value = _plugin._availableImages[newIndex];
}
private void SelectNextSpray()
{
int currentIndex = _plugin._availableImages.IndexOf(_plugin._configManager.SelectedSprayImage.Value);
int newIndex = (currentIndex + 1) % _plugin._availableImages.Count;
_plugin._configManager.SelectedSprayImage.Value = _plugin._availableImages[newIndex];
}
}
}