-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModEntry.cs
More file actions
599 lines (506 loc) · 27.5 KB
/
ModEntry.cs
File metadata and controls
599 lines (506 loc) · 27.5 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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using StardewModdingAPI;
using StardewModdingAPI.Events;
using StardewModdingAPI.Utilities;
using StardewValley;
using StardewValley.Menus;
using StardewValley.BellsAndWhistles;
using System;
using System.Collections.Generic;
using System.Linq;
namespace VaultMod // <<<< CORRIGIDO
{
/*************************************************************************
* 1. CONFIGURAÇÃO (ModConfig e Enums de Acesso)
*************************************************************************/
public enum VaultAccess
{
Todos,
ApenasHost
}
public class ModConfig
{
public SButton Hotkey { get; set; } = SButton.F5;
public bool CaptureShippingBinIncome { get; set; } = true;
public VaultAccess RequiredAccessLevel { get; set; } = VaultAccess.Todos;
public bool EnableHistoryMenu { get; set; } = true;
public bool EnableIncomeMenu { get; set; } = true;
public bool ShowNotifications { get; set; } = true;
public int HistoryLimit { get; set; } = 50;
}
/*************************************************************************
* 2. MODELOS DE DADOS
*************************************************************************/
public enum TransactionType
{
Deposito,
Saque,
RendaAcumulada,
RendaDistribuida
}
public class Transaction
{
public string Date { get; set; } = string.Empty;
public string PlayerName { get; set; } = string.Empty;
public long Amount { get; set; }
public TransactionType Type { get; set; }
public Transaction() { }
public string GetDescription()
{
string key = $"history.action.{Type.ToString().ToLower()}";
return ModEntry.FormatTranslation(key, Amount).Replace("{Player}", PlayerName).Replace("{player}", PlayerName);
}
}
public class VaultDataModel
{
public long Balance { get; set; } = 0;
public long IncomePool { get; set; } = 0;
public List<Transaction> History { get; set; } = new List<Transaction>();
}
/*************************************************************************
* 3. INTERFACE (MENUS)
*************************************************************************/
// --- Menu Principal do Cofre ---
public class VaultMainMenu : IClickableMenu
{
private TextBox inputAmount = null!;
private ClickableComponent amountClickable = null!;
private ClickableComponent btnDeposit = null!;
private ClickableComponent btnWithdraw = null!;
private ClickableComponent btnHistory = null!;
private ClickableComponent btnIncome = null!;
public VaultMainMenu()
: base((int)Utility.getTopLeftPositionForCenteringOnScreen(600, 500).X, (int)Utility.getTopLeftPositionForCenteringOnScreen(600, 500).Y, 600, 500, true)
{
Texture2D tex = null!;
try { tex = Game1.content.Load<Texture2D>("LooseSprites\\textBox"); } catch { tex = null!; }
inputAmount = new TextBox(tex, null, Game1.smallFont, Color.Black)
{ X = xPositionOnScreen + 200, Y = yPositionOnScreen + 150, Width = 192, numbersOnly = true };
amountClickable = new ClickableComponent(new Rectangle(inputAmount.X, inputAmount.Y, inputAmount.Width, 48), "");
inputAmount.Selected = true;
btnDeposit = new ClickableComponent(new Rectangle(xPositionOnScreen + 50, yPositionOnScreen + 220, 200, 64), ModEntry.I18n.Get("button.deposit"));
btnWithdraw = new ClickableComponent(new Rectangle(xPositionOnScreen + 350, yPositionOnScreen + 220, 200, 64), ModEntry.I18n.Get("button.withdraw"));
btnHistory = new ClickableComponent(new Rectangle(xPositionOnScreen + 50, yPositionOnScreen + 320, 200, 64), ModEntry.I18n.Get("tab.history"));
btnIncome = new ClickableComponent(new Rectangle(xPositionOnScreen + 350, yPositionOnScreen + 320, 200, 64), ModEntry.I18n.Get("tab.income"));
}
public override void receiveLeftClick(int x, int y, bool playSound = true)
{
if (amountClickable.containsPoint(x, y)) inputAmount.SelectMe();
else inputAmount.Selected = false;
if (ModEntry.Config.EnableHistoryMenu && btnHistory.containsPoint(x, y)) { Game1.activeClickableMenu = new HistoryMenu(); return; }
if (ModEntry.Config.EnableIncomeMenu && btnIncome.containsPoint(x, y)) { Game1.activeClickableMenu = new IncomeMenu(); return; }
if (long.TryParse(inputAmount.Text, out long amount) && amount > 0)
{
if (btnDeposit.containsPoint(x, y))
{
if (Game1.player.Money >= amount)
{
long depositAmount = Math.Min(amount, int.MaxValue);
Game1.player.Money -= (int)depositAmount;
ModEntry.AddTransaction(TransactionType.Deposito, depositAmount, Game1.player.Name);
Game1.playSound("purchase");
}
else Game1.addHUDMessage(new HUDMessage(ModEntry.I18n.Get("message.low_wallet")));
}
else if (btnWithdraw.containsPoint(x, y))
{
if (!ModEntry.HasRequiredPermission())
{
Game1.addHUDMessage(new HUDMessage(ModEntry.I18n.Get("message.permission_denied")));
return;
}
if (ModEntry.VaultData.Balance >= amount)
{
long withdrawAmount = amount;
if (amount > int.MaxValue)
{
withdrawAmount = int.MaxValue;
Game1.addHUDMessage(new HUDMessage(ModEntry.I18n.Get("message.withdraw_limit", new { Amount = int.MaxValue })));
}
Game1.player.Money += (int)withdrawAmount;
ModEntry.AddTransaction(TransactionType.Saque, withdrawAmount, Game1.player.Name);
Game1.playSound("coin");
}
else Game1.addHUDMessage(new HUDMessage(ModEntry.I18n.Get("message.low_vault")));
}
}
base.receiveLeftClick(x, y, playSound);
}
public override void receiveKeyPress(Keys key) { if (key == Keys.Escape || key == Keys.C) exitThisMenu(); }
public override void draw(SpriteBatch b)
{
b.Draw(Game1.fadeToBlackRect, Game1.graphics.GraphicsDevice.Viewport.Bounds, Color.Black * 0.75f);
IClickableMenu.drawTextureBox(b, xPositionOnScreen, yPositionOnScreen, width, height, Color.White);
string title = ModEntry.I18n.Get("menu.title");
SpriteText.drawStringHorizontallyCenteredAt(b, title, xPositionOnScreen + width / 2, yPositionOnScreen + 20);
string balance = ModEntry.FormatTranslation("menu.balance", ModEntry.VaultData.Balance);
Vector2 textSize = Game1.dialogueFont.MeasureString(balance);
Utility.drawTextWithShadow(b, balance, Game1.dialogueFont, new Vector2(xPositionOnScreen + width / 2 - textSize.X / 2f, yPositionOnScreen + 80), Color.Gold);
inputAmount.Draw(b);
DrawBtn(b, btnDeposit, Color.LightGreen);
DrawBtn(b, btnWithdraw, Color.Salmon);
if (ModEntry.Config.EnableHistoryMenu) DrawBtn(b, btnHistory, Color.LightGray);
if (ModEntry.Config.EnableIncomeMenu) DrawBtn(b, btnIncome, Color.LightBlue);
base.draw(b);
drawMouse(b);
}
private void DrawBtn(SpriteBatch b, ClickableComponent btn, Color c)
{
IClickableMenu.drawTextureBox(b, Game1.mouseCursors, new Rectangle(403, 373, 9, 9), btn.bounds.X, btn.bounds.Y, btn.bounds.Width, btn.bounds.Height, c, 4f, false);
Utility.drawTextWithShadow(b, btn.name, Game1.smallFont, new Vector2(btn.bounds.X + 30, btn.bounds.Y + 20), Game1.textColor);
}
}
// --- Menu de Extrato (History) ---
public class HistoryMenu : IClickableMenu
{
public HistoryMenu() : base((int)Utility.getTopLeftPositionForCenteringOnScreen(800, 600).X, (int)Utility.getTopLeftPositionForCenteringOnScreen(800, 600).Y, 800, 600, true) { }
public override void receiveKeyPress(Keys key) { if (key == Keys.Escape) Game1.activeClickableMenu = new VaultMainMenu(); }
public override void draw(SpriteBatch b)
{
b.Draw(Game1.fadeToBlackRect, Game1.graphics.GraphicsDevice.Viewport.Bounds, Color.Black * 0.75f);
IClickableMenu.drawTextureBox(b, xPositionOnScreen, yPositionOnScreen, width, height, Color.White);
string title = ModEntry.I18n.Get("history.title");
SpriteText.drawStringHorizontallyCenteredAt(b, title, xPositionOnScreen + width / 2, yPositionOnScreen + 30);
int y = yPositionOnScreen + 100;
if (ModEntry.VaultData.History.Count == 0)
Utility.drawTextWithShadow(b, ModEntry.I18n.Get("history.no_transactions"), Game1.smallFont, new Vector2(xPositionOnScreen + 100, y), Game1.textColor);
int limit = Math.Min(ModEntry.VaultData.History.Count, ModEntry.Config.HistoryLimit);
for (int i = 0; i < limit; i++)
{
var item = ModEntry.VaultData.History[i];
string text = $"{item.Date} - {item.GetDescription()}";
Color c = (item.Type == TransactionType.Saque) ? Color.Red : Color.Green;
Utility.drawTextWithShadow(b, text, Game1.smallFont, new Vector2(xPositionOnScreen + 50, y), c);
y += 40;
if (y > yPositionOnScreen + height - 50) break;
}
base.draw(b);
drawMouse(b);
}
}
// --- Menu de Renda (Income) ---
public class IncomeMenu : IClickableMenu
{
private TextBox splitCountBox = null!;
private ClickableComponent splitButton = null!;
private ClickableComponent confirmDistributeButton = null!;
private List<DistributionSlot> slots = new List<DistributionSlot>();
private List<Farmer> availableTargets = new List<Farmer>();
private int amountPerSlot = 0;
public IncomeMenu() : base((int)Utility.getTopLeftPositionForCenteringOnScreen(800, 600).X, (int)Utility.getTopLeftPositionForCenteringOnScreen(800, 600).Y, 800, 600, true)
{
availableTargets = Game1.getOnlineFarmers().ToList();
Texture2D tex = null!;
try { tex = Game1.content.Load<Texture2D>("LooseSprites\\textBox"); } catch { tex = null!; }
splitCountBox = new TextBox(tex, null, Game1.smallFont, Color.Black)
{
Width = 100,
numbersOnly = true,
Text = "2",
X = xPositionOnScreen + width - 360,
Y = yPositionOnScreen + 130
};
splitButton = new ClickableComponent(new Rectangle(splitCountBox.X + splitCountBox.Width + 12, splitCountBox.Y, 150, 48), ModEntry.I18n.Get("income.simulate"));
confirmDistributeButton = new ClickableComponent(new Rectangle(xPositionOnScreen + width - 250, yPositionOnScreen + height - 80, 200, 64), ModEntry.I18n.Get("income.distribute"));
}
public override void receiveLeftClick(int x, int y, bool playSound = true)
{
if (splitButton.containsPoint(x, y))
{
GenerateSlots();
Game1.playSound("bigDeSelect");
}
foreach (var slot in slots)
{
if (slot.ButtonBounds.Contains(x, y)) { slot.CycleTarget(availableTargets); Game1.playSound("drumkit6"); }
}
if (confirmDistributeButton.containsPoint(x, y) && slots.Count > 0)
{
DistributeMoney();
Game1.activeClickableMenu = new VaultMainMenu();
}
splitCountBox.Update();
base.receiveLeftClick(x, y, playSound);
}
public override void receiveKeyPress(Keys key) { if (key == Keys.Escape) Game1.activeClickableMenu = new VaultMainMenu(); }
private void GenerateSlots()
{
slots.Clear();
if (int.TryParse(splitCountBox.Text, out int divisions) && divisions > 0)
{
long totalIncome = ModEntry.VaultData.IncomePool;
if (totalIncome <= 0) { Game1.addHUDMessage(new HUDMessage(ModEntry.I18n.Get("income.no_funds"))); return; }
amountPerSlot = (int)(totalIncome / divisions);
for (int i = 0; i < divisions; i++) slots.Add(new DistributionSlot(i, xPositionOnScreen + 50, yPositionOnScreen + 200 + (i * 60)));
}
}
private void DistributeMoney()
{
long totalUsed = 0;
foreach (var slot in slots)
{
totalUsed += amountPerSlot;
if (slot.SelectedTarget != null)
{
slot.SelectedTarget.Money += amountPerSlot;
// Registra como distribuição no histórico (não chama AddTransaction para evitar alterar Balance)
ModEntry.VaultData.History.Insert(0, new Transaction
{
Date = Utility.getDateStringFor(Game1.Date.DayOfMonth, Game1.Date.SeasonIndex, Game1.Date.Year),
PlayerName = slot.SelectedTarget.Name,
Amount = amountPerSlot,
Type = TransactionType.RendaDistribuida
});
}
else
{
// De volta pro cofre (atualiza o balance diretamente)
ModEntry.VaultData.Balance += amountPerSlot;
ModEntry.VaultData.History.Insert(0, new Transaction
{
Date = Utility.getDateStringFor(Game1.Date.DayOfMonth, Game1.Date.SeasonIndex, Game1.Date.Year),
PlayerName = ModEntry.I18n.Get("income.target.vault"),
Amount = amountPerSlot,
Type = TransactionType.RendaDistribuida
});
}
}
ModEntry.VaultData.IncomePool -= totalUsed;
ModEntry.SaveData();
ModEntry.SyncData();
Game1.playSound("reward");
string msg = ModEntry.FormatTranslation("message.distributed", totalUsed);
if (ModEntry.Config.ShowNotifications) Game1.addHUDMessage(new HUDMessage(msg));
}
public override void draw(SpriteBatch b)
{
b.Draw(Game1.fadeToBlackRect, Game1.graphics.GraphicsDevice.Viewport.Bounds, Color.Black * 0.75f);
IClickableMenu.drawTextureBox(b, xPositionOnScreen, yPositionOnScreen, width, height, Color.White);
string title = ModEntry.I18n.Get("income.title");
SpriteText.drawStringHorizontallyCenteredAt(b, title, xPositionOnScreen + width / 2, yPositionOnScreen + 30);
string incomeBalance = ModEntry.FormatTranslation("income.balance", ModEntry.VaultData.IncomePool);
Utility.drawTextWithShadow(b, incomeBalance, Game1.dialogueFont, new Vector2(xPositionOnScreen + 50, yPositionOnScreen + 80), Color.LightGreen);
Utility.drawTextWithShadow(b, ModEntry.I18n.Get("income.split_label"), Game1.smallFont, new Vector2(xPositionOnScreen + 50, yPositionOnScreen + 140), Game1.textColor);
splitCountBox.Draw(b);
// Botão Simular
IClickableMenu.drawTextureBox(b, Game1.mouseCursors, new Rectangle(403, 373, 9, 9), splitButton.bounds.X, splitButton.bounds.Y, splitButton.bounds.Width, splitButton.bounds.Height, Color.White, 4f, false);
Utility.drawTextWithShadow(b, splitButton.name, Game1.smallFont, new Vector2(splitButton.bounds.X + 20, splitButton.bounds.Y + 12), Game1.textColor);
foreach (var slot in slots)
{
string slotLabel = ModEntry.I18n.Get("income.slot_label");
string label = string.Format("{0} {1}: {2}g -> ", slotLabel, slot.Index + 1, amountPerSlot);
Utility.drawTextWithShadow(b, label, Game1.smallFont, new Vector2(slot.X, slot.Y + 10), Game1.textColor);
IClickableMenu.drawTextureBox(b, Game1.mouseCursors, new Rectangle(403, 373, 9, 9), slot.ButtonBounds.X, slot.ButtonBounds.Y, slot.ButtonBounds.Width, slot.ButtonBounds.Height, Color.LightBlue, 4f, false);
string targetName = slot.SelectedTarget == null ? ModEntry.I18n.Get("income.target.vault") : slot.SelectedTarget.Name;
Utility.drawTextWithShadow(b, targetName, Game1.smallFont, new Vector2(slot.ButtonBounds.X + 15, slot.ButtonBounds.Y + 10), Color.Blue);
}
if (slots.Count > 0)
{
IClickableMenu.drawTextureBox(b, Game1.mouseCursors, new Rectangle(403, 373, 9, 9), confirmDistributeButton.bounds.X, confirmDistributeButton.bounds.Y, confirmDistributeButton.bounds.Width, confirmDistributeButton.bounds.Height, Color.LightGreen, 4f, false);
Utility.drawTextWithShadow(b, confirmDistributeButton.name, Game1.dialogueFont, new Vector2(confirmDistributeButton.bounds.X + 25, confirmDistributeButton.bounds.Y + 10), Color.White);
}
base.draw(b);
drawMouse(b);
}
}
public class DistributionSlot
{
public int Index;
public int X, Y;
public Rectangle ButtonBounds;
public Farmer? SelectedTarget;
public DistributionSlot(int index, int x, int y)
{
Index = index; X = x; Y = y;
ButtonBounds = new Rectangle(x + 250, y, 300, 48);
SelectedTarget = null;
}
public void CycleTarget(List<Farmer> players)
{
if (SelectedTarget == null)
{
if (players.Count > 0) SelectedTarget = players[0];
}
else
{
int currentIdx = players.IndexOf(SelectedTarget);
if (currentIdx == players.Count - 1) SelectedTarget = null;
else SelectedTarget = players[currentIdx + 1];
}
}
}
/*************************************************************************
* 4. MOD ENTRY (LÓGICA PRINCIPAL)
*************************************************************************/
public class ModEntry : Mod
{
internal static IModHelper StaticHelper = null!;
internal static string ModID = null!;
internal static ModConfig Config = null!;
internal static ITranslationHelper I18n = null!;
internal static IMonitor Logger = null!;
internal static VaultDataModel VaultData { get; private set; } = new VaultDataModel();
public override void Entry(IModHelper helper)
{
StaticHelper = helper;
Logger = this.Monitor;
ModID = ModManifest.UniqueID;
I18n = helper.Translation;
Config = helper.ReadConfig<ModConfig>();
helper.Events.Input.ButtonPressed += OnButtonPressed;
helper.Events.GameLoop.GameLaunched += OnGameLaunched;
helper.Events.GameLoop.SaveLoaded += OnSaveLoaded;
helper.Events.GameLoop.DayEnding += OnDayEnding;
helper.Events.Multiplayer.ModMessageReceived += OnModMessageReceived;
}
// --- Helpers ---
public static string FormatTranslation(string key, long amount)
{
string template = I18n.Get(key);
string amountN0 = amount.ToString("N0");
string result = template.Replace("{Amount:N0}", amountN0)
.Replace("{amount:N0}", amountN0)
.Replace("{Amount}", amountN0)
.Replace("{amount}", amountN0);
if (!result.Contains("g") && (template.Contains("{Amount") || template.Contains("{amount")))
{
result = result.Trim() + "g";
}
return result;
}
public static bool HasRequiredPermission()
{
if (Config.RequiredAccessLevel == VaultAccess.Todos) return true;
return Context.IsMainPlayer;
}
public static void AddTransaction(TransactionType type, long amount, string playerName)
{
if (!Context.IsWorldReady || (!Context.IsMainPlayer && Context.IsMultiplayer)) return;
switch (type)
{
case TransactionType.Deposito:
VaultData.Balance += amount; break;
case TransactionType.Saque:
VaultData.Balance -= amount; break;
}
VaultData.History.Insert(0, new Transaction
{
Date = Utility.getDateStringFor(Game1.Date.DayOfMonth, Game1.Date.SeasonIndex, Game1.Date.Year),
PlayerName = playerName,
Amount = amount,
Type = type
});
if (VaultData.History.Count > Config.HistoryLimit)
VaultData.History = VaultData.History.Take(Config.HistoryLimit).ToList();
long notifyAmt = (type == TransactionType.Saque) ? -amount : amount;
string msg = FormatTranslation($"message.{type.ToString().ToLower()}", notifyAmt);
if (Config.ShowNotifications) Game1.addHUDMessage(new HUDMessage(msg));
SaveData();
SyncData();
}
// CORREÇÃO FINAL: Usando WriteSaveData para salvar por mundo
public static void SaveData()
{
if (Context.IsMainPlayer) StaticHelper.Data.WriteSaveData(ModID, VaultData);
}
public static void SyncData()
{
if (!Context.IsMultiplayer) return;
StaticHelper.Multiplayer.SendMessage(VaultData, "SyncData", modIDs: new[] { ModID });
}
// --- Events ---
// CORREÇÃO FINAL: Usando ReadSaveData para carregar por mundo
private void OnSaveLoaded(object? sender, SaveLoadedEventArgs e)
{
if (Context.IsMainPlayer)
{
// Carrega dados específicos do save, resolvendo o problema do histórico compartilhado.
VaultData = StaticHelper.Data.ReadSaveData<VaultDataModel>(ModID) ?? new VaultDataModel();
if (Context.IsMultiplayer) SyncData();
}
else
{
VaultData = new VaultDataModel();
}
}
private void OnDayEnding(object? sender, DayEndingEventArgs e)
{
if (!Context.IsMainPlayer || !Config.CaptureShippingBinIncome) return;
long totalSales = 0;
var farm = Game1.getFarm();
var shippingBin = farm.getShippingBin(Game1.player);
Logger.Log($"[VaultMod] Processando fim do dia. Itens na caixa: {shippingBin.Count}", LogLevel.Debug);
foreach (Item item in shippingBin)
{
if (item != null)
{
int price = Utility.getSellToStorePriceOfItem(item);
totalSales += price;
}
}
if (totalSales > 0)
{
Logger.Log($"[VaultMod] Vendas totais calculadas: {totalSales}g. Adicionando ao cofre.", LogLevel.Info);
VaultData.IncomePool += totalSales;
VaultData.History.Insert(0, new Transaction
{
Date = Utility.getDateStringFor(Game1.Date.DayOfMonth, Game1.Date.SeasonIndex, Game1.Date.Year),
PlayerName = I18n.Get("history.player.farm_sales"),
Amount = totalSales,
Type = TransactionType.RendaAcumulada
});
string msg = FormatTranslation("message.rendaacumulada", totalSales);
if (Config.ShowNotifications) Game1.addHUDMessage(new HUDMessage(msg));
}
shippingBin.Clear();
SaveData();
SyncData();
}
private void OnButtonPressed(object? sender, ButtonPressedEventArgs e)
{
if (!Context.IsWorldReady || Game1.activeClickableMenu != null || Game1.player.UsingTool) return;
if (e.Button == Config.Hotkey)
{
Game1.activeClickableMenu = new VaultMainMenu();
StaticHelper.Input.Suppress(e.Button);
}
}
private void OnModMessageReceived(object? sender, ModMessageReceivedEventArgs e)
{
if (e.FromModID == ModID && e.Type == "SyncData" && !Context.IsMainPlayer)
{
VaultData = e.ReadAs<VaultDataModel>();
}
}
private void OnGameLaunched(object? sender, GameLaunchedEventArgs e)
{
var gmcm = StaticHelper.ModRegistry.GetApi<IGenericModConfigMenuApi>("spacechase0.GenericModConfigMenu");
if (gmcm == null) return;
gmcm.Register(ModManifest, () => Config = new ModConfig(), () => StaticHelper.WriteConfig(Config));
gmcm.AddSectionTitle(ModManifest, () => "Settings");
gmcm.AddKeybind(ModManifest, () => Config.Hotkey, (val) => Config.Hotkey = val, () => I18n.Get("config.hotkey.name"), () => I18n.Get("config.hotkey.desc"));
gmcm.AddBoolOption(ModManifest, () => Config.CaptureShippingBinIncome, (val) => Config.CaptureShippingBinIncome = val, () => I18n.Get("config.capture_bin.name"), () => I18n.Get("config.capture_bin.desc"));
gmcm.AddBoolOption(ModManifest, () => Config.ShowNotifications, (val) => Config.ShowNotifications = val, () => I18n.Get("config.show_notifications.name"), () => I18n.Get("config.show_notifications.desc"));
gmcm.AddSectionTitle(ModManifest, () => "Menu Features");
gmcm.AddBoolOption(ModManifest, () => Config.EnableHistoryMenu, (val) => Config.EnableHistoryMenu = val, () => I18n.Get("config.enable_history.name"), () => I18n.Get("config.enable_history.desc"));
gmcm.AddBoolOption(ModManifest, () => Config.EnableIncomeMenu, (val) => Config.EnableIncomeMenu = val, () => I18n.Get("config.enable_income.name"), () => I18n.Get("config.enable_income.desc"));
gmcm.AddTextOption(ModManifest,
() => Config.RequiredAccessLevel.ToString(),
(val) => Config.RequiredAccessLevel = (VaultAccess)Enum.Parse(typeof(VaultAccess), val),
() => I18n.Get("config.access_level.name"),
() => I18n.Get("config.access_level.desc"),
new string[] { VaultAccess.Todos.ToString(), VaultAccess.ApenasHost.ToString() }
);
}
}
public interface IGenericModConfigMenuApi
{
void Register(IManifest mod, Action reset, Action save, bool titleScreenOnly = false);
void AddSectionTitle(IManifest mod, Func<string> text, Func<string> tooltip = null);
void AddBoolOption(IManifest mod, Func<bool> getValue, Action<bool> setValue, Func<string> name, Func<string> tooltip = null, string fieldId = null);
void AddKeybind(IManifest mod, Func<SButton> getValue, Action<SButton> setValue, Func<string> name, Func<string> tooltip = null, string fieldId = null);
void AddTextOption(IManifest mod, Func<string> getValue, Action<string> setValue, Func<string> name, Func<string> tooltip = null, string[]? allowedValues = null, Func<string, string>? formatAllowedValue = null, string? fieldId = null);
}
}