-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigManager.cs
More file actions
325 lines (289 loc) · 12.6 KB
/
ConfigManager.cs
File metadata and controls
325 lines (289 loc) · 12.6 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
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
using BepInEx.Configuration;
using BepInEx.Logging;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Photon.Realtime;
namespace BiggerSprayMod
{
public class ConfigManager
{
private readonly BiggerSprayMod _plugin;
// Config Entries
public ConfigEntry<KeyCode> SprayKey;
public ConfigEntry<KeyCode> PreviousSprayKey;
public ConfigEntry<KeyCode> NextSprayKey;
public ConfigEntry<KeyCode> ScaleKey;
public ConfigEntry<KeyCode> IncreaseScaleKey;
public ConfigEntry<KeyCode> DecreaseScaleKey;
public ConfigEntry<KeyCode> ToggleGifModeKey;
public ConfigEntry<float> SprayScale;
public ConfigEntry<float> SprayLifetimeSeconds;
public ConfigEntry<int> MaxSpraysAllowed;
public ConfigEntry<string> SelectedSprayImage;
public ConfigEntry<string> SelectedGifName;
public ConfigEntry<bool> RefreshSpraysButton;
public ConfigEntry<bool> RefreshGifsButton;
public ConfigEntry<bool> OpenGifConfigFolderButton;
public ConfigEntry<bool> OpenImagesFolderButton;
public ConfigEntry<Color> ScalePreviewColor;
public ConfigEntry<float> MinScaleSize;
public ConfigEntry<float> MaxScaleSize;
public ConfigEntry<float> ScaleSpeed;
public ConfigEntry<bool> UseScrollWheel;
public ConfigEntry<bool> ShowSprayIfLarge;
public ConfigEntry<float> GifAnimationFps;
public ConfigEntry<bool> AnimateGifsInWorld;
public ConfigEntry<bool> myEyesOnly;
public ConfigManager(BiggerSprayMod plugin)
{
_plugin = plugin;
}
public void Initialize()
{
if (_plugin._availableImages.Count == 0)
{
// Add a default image if none are available
_plugin._availableImages.Add("DefaultSpray.png");
}
SprayLifetimeSeconds = _plugin.Config.Bind(
"Host Settings",
"Spray Lifetime (Seconds)",
60f,
new ConfigDescription(
"How long the spray should last. Set to 0 for permanent sprays.",
new AcceptableValueRange<float>(0f, 300f)
)
);
// Add handler for when spray lifetime is changed
SprayLifetimeSeconds.SettingChanged += (_, _) =>
{
// Only hosts can control spray lifetimes
if (Photon.Pun.PhotonNetwork.IsMasterClient && Photon.Pun.PhotonNetwork.IsConnected)
{
_plugin.UpdateAllSprayLifetimes();
}
};
MaxSpraysAllowed = _plugin.Config.Bind(
"Host Settings",
"Max Sprays",
10,
new ConfigDescription(
"Maximum number of sprays before the oldest is deleted.",
new AcceptableValueRange<int>(1, 100)
)
);
SelectedSprayImage = _plugin.Config.Bind(
"Spray Settings",
"Selected Spray Image",
_plugin._availableImages.FirstOrDefault() ?? "DefaultSpray.png",
new ConfigDescription(
"The image used for spraying.",
new AcceptableValueList<string>(_plugin._availableImages.ToArray())
)
);
SelectedSprayImage.SettingChanged += (_, _) =>
{
_plugin.LogMessage(LogLevel.Info, "[BiggerSprayMod] Image selection changed. Reloading texture...");
string path = System.IO.Path.Combine(_plugin._imagesFolderPath, SelectedSprayImage.Value);
_plugin._cachedSprayTexture = _plugin._imageUtils.LoadTexture(path);
if (_plugin._cachedSprayTexture != null)
{
_plugin._originalImageDimensions = new Vector2(_plugin._cachedSprayTexture.width, _plugin._cachedSprayTexture.height);
}
};
RefreshSpraysButton = _plugin.Config.Bind(
"Spray Settings",
"Refresh Sprays",
false,
new ConfigDescription("Set to TRUE to refresh the list of available sprays.")
);
SprayKey = _plugin.Config.Bind(
"Spray Settings",
"Spray Key",
KeyCode.F,
new ConfigDescription("The key used to spray.")
);
PreviousSprayKey = _plugin.Config.Bind(
"Spray Settings",
"Previous Spray/GIF Key",
KeyCode.LeftArrow,
new ConfigDescription("The key used to select the previous spray image or GIF.")
);
NextSprayKey = _plugin.Config.Bind(
"Spray Settings",
"Next Spray/GIF Key",
KeyCode.RightArrow,
new ConfigDescription("The key used to select the next spray image or GIF.")
);
ShowSprayIfLarge = _plugin.Config.Bind(
"Spray Settings",
"Show spray if it exceeds the size limit locally",
true,
new ConfigDescription("Show the spray even if the image is large (Locally).")
);
OpenImagesFolderButton = _plugin.Config.Bind(
"Spray Settings",
"Open Images Folder",
false,
new ConfigDescription("Set to TRUE to open the folder containing the spray images.")
);
myEyesOnly = _plugin.Config.Bind(
"Spray Settings",
"My Eyes Only",
false,
new ConfigDescription("Enable privacy mode (Don't send sprays over network).")
);
ToggleGifModeKey = _plugin.Config.Bind(
"GIF Settings",
"Toggle GIF Mode Key",
KeyCode.G,
new ConfigDescription("The key used to toggle between regular spray and GIF mode.")
);
RefreshGifsButton = _plugin.Config.Bind(
"GIF Settings",
"Refresh GIFs",
false,
new ConfigDescription("Set to TRUE to refresh the list of available GIFs from configuration file.")
);
OpenGifConfigFolderButton = _plugin.Config.Bind(
"GIF Settings",
"Open GIF Config Folder",
false,
new ConfigDescription("Set to TRUE to open the folder containing the GIF configuration file.")
);
GifAnimationFps = _plugin.Config.Bind(
"GIF Settings",
"GIF Animation FPS",
30.0f,
new ConfigDescription(
"The frames per second rate for GIF animations in the world.",
new AcceptableValueRange<float>(1.0f, 60.0f)
)
);
AnimateGifsInWorld = _plugin.Config.Bind(
"GIF Settings",
"Animate GIFs In World",
true,
new ConfigDescription("When enabled, GIF sprays will be animated in the world. Disable for performance.")
);
// Add a handler for the AnimateGifsInWorld setting
AnimateGifsInWorld.SettingChanged += (_, _) =>
{
// When the setting changes, update all existing GIF animators
_plugin._gifAssetManager.SetAllAnimatorsPaused(!AnimateGifsInWorld.Value);
};
// Add the GIF selection setting
SelectedGifName = _plugin.Config.Bind(
"GIF Settings",
"Selected GIF",
_plugin._gifManager.AvailableGifs.Count > 0 ? _plugin._gifManager.AvailableGifs[0] : "No GIFs Available",
new ConfigDescription(
"The GIF used for spraying when in GIF mode.",
new AcceptableValueList<string>(_plugin._gifManager.AvailableGifs.ToArray())
)
);
SelectedGifName.SettingChanged += (_, _) =>
{
if (_plugin._gifManager.IsGifMode && SelectedGifName.Value != _plugin._gifManager.CurrentGifName)
{
_plugin.LogMessage(LogLevel.Info, $"[BiggerSprayMod] GIF selection changed to: {SelectedGifName.Value}");
_plugin._gifManager.SelectGif(SelectedGifName.Value);
}
};
ScaleKey = _plugin.Config.Bind(
"Scale Settings",
"Scale Preview Key",
KeyCode.LeftAlt,
new ConfigDescription("Hold this key to preview the scale.")
);
IncreaseScaleKey = _plugin.Config.Bind(
"Scale Settings",
"Increase Scale Key",
KeyCode.Equals, // + key
new ConfigDescription("Press this key to increase the spray scale (+ key by default).")
);
DecreaseScaleKey = _plugin.Config.Bind(
"Scale Settings",
"Decrease Scale Key",
KeyCode.Minus, // - key
new ConfigDescription("Press this key to decrease the spray scale (- key by default).")
);
UseScrollWheel = _plugin.Config.Bind(
"Scale Settings",
"Use Scroll Wheel",
true,
new ConfigDescription("Enable scroll wheel to adjust scale while holding the Scale Preview Key.")
);
SprayScale = _plugin.Config.Bind(
"Scale Settings",
"Spray Scale",
1.0f,
new ConfigDescription(
"The size of the spray.",
new AcceptableValueRange<float>(0.1f, 5.0f)
)
);
MinScaleSize = _plugin.Config.Bind(
"Scale Settings",
"Minimum Scale",
0.1f,
new ConfigDescription(
"The minimum allowed scale size.",
new AcceptableValueRange<float>(0.1f, 1.0f)
)
);
MaxScaleSize = _plugin.Config.Bind(
"Scale Settings",
"Maximum Scale",
5.0f,
new ConfigDescription(
"The maximum allowed scale size.",
new AcceptableValueRange<float>(1.0f, 10.0f)
)
);
ScaleSpeed = _plugin.Config.Bind(
"Scale Settings",
"Scale Speed",
0.1f,
new ConfigDescription(
"How quickly the spray scales when adjusting.",
new AcceptableValueRange<float>(0.01f, 1.0f)
)
);
ScalePreviewColor = _plugin.Config.Bind(
"Scale Settings",
"Scale Preview Color",
new Color(0.0f, 1.0f, 0.0f, 0.5f), // Semi-transparent green
new ConfigDescription("The color of the scale preview.")
);
}
public void UpdateImageListConfig()
{
if (_plugin._availableImages.Count == 0)
{
_plugin._availableImages.Add("No Images Available");
}
// Rebind the selected image config with updated list
_plugin.Config.Remove(SelectedSprayImage.Definition);
SelectedSprayImage = _plugin.Config.Bind(
"Spray Settings",
"Selected Spray Image",
_plugin._availableImages.Contains(SelectedSprayImage.Value) ? SelectedSprayImage.Value : _plugin._availableImages[0],
new ConfigDescription(
"The image used for spraying.",
new AcceptableValueList<string>(_plugin._availableImages.ToArray())
)
);
SelectedSprayImage.SettingChanged += (_, _) =>
{
string path = System.IO.Path.Combine(_plugin._imagesFolderPath, SelectedSprayImage.Value);
_plugin._cachedSprayTexture = _plugin._imageUtils.LoadTexture(path);
if (_plugin._cachedSprayTexture != null)
{
_plugin._originalImageDimensions = new Vector2(_plugin._cachedSprayTexture.width, _plugin._cachedSprayTexture.height);
}
};
}
}
}