From 48edfd7bd57d9dd76fca468111d0943732eeae45 Mon Sep 17 00:00:00 2001 From: LegoFigure11 <24732684+LegoFigure11@users.noreply.github.com> Date: Wed, 18 Oct 2023 16:58:21 +1100 Subject: [PATCH] Add manual date reset button --- .../Connection/ConnectionWrapper.cs | 2 +- RaidCrawler.WinForms/MainWindow.Designer.cs | 16 +++++++++- RaidCrawler.WinForms/MainWindow.cs | 31 +++++++++++++++++-- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/RaidCrawler.Core/Connection/ConnectionWrapper.cs b/RaidCrawler.Core/Connection/ConnectionWrapper.cs index f385911..3580f75 100644 --- a/RaidCrawler.Core/Connection/ConnectionWrapper.cs +++ b/RaidCrawler.Core/Connection/ConnectionWrapper.cs @@ -238,7 +238,7 @@ private async Task SkipHour(int hours, int delay, CancellationToken token) } } - private async Task ResetTime(CancellationToken token) + public async Task ResetTime(CancellationToken token) { var command = Encoding.ASCII.GetBytes($"resetTime{(CRLF ? "\r\n" : "")}"); await Connection.SendAsync(command, token).ConfigureAwait(false); diff --git a/RaidCrawler.WinForms/MainWindow.Designer.cs b/RaidCrawler.WinForms/MainWindow.Designer.cs index bdd6ada..0935e60 100644 --- a/RaidCrawler.WinForms/MainWindow.Designer.cs +++ b/RaidCrawler.WinForms/MainWindow.Designer.cs @@ -90,6 +90,7 @@ private void InitializeComponent() USB_Port_label = new Label(); USB_Port_TB = new TextBox(); StopAdvance_Button = new Button(); + B_ResetTime = new Button(); ((System.ComponentModel.ISupportInitialize)Sprite).BeginInit(); ((System.ComponentModel.ISupportInitialize)GemIcon).BeginInit(); ((System.ComponentModel.ISupportInitialize)SearchTimer).BeginInit(); @@ -554,7 +555,7 @@ private void InitializeComponent() // ConfigSettings.Location = new Point(12, 302); ConfigSettings.Name = "ConfigSettings"; - ConfigSettings.Size = new Size(200, 23); + ConfigSettings.Size = new Size(97, 23); ConfigSettings.TabIndex = 115; ConfigSettings.Text = "Open Settings"; ConfigSettings.UseVisualStyleBackColor = true; @@ -703,11 +704,23 @@ private void InitializeComponent() StopAdvance_Button.Visible = false; StopAdvance_Button.Click += StopAdvanceButton_Click; // + // B_ResetTime + // + B_ResetTime.Enabled = false; + B_ResetTime.Location = new Point(117, 302); + B_ResetTime.Name = "B_ResetTime"; + B_ResetTime.Size = new Size(97, 23); + B_ResetTime.TabIndex = 130; + B_ResetTime.Text = "Reset Date"; + B_ResetTime.UseVisualStyleBackColor = true; + B_ResetTime.Click += B_ResetTime_Click; + // // MainWindow // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(580, 357); + Controls.Add(B_ResetTime); Controls.Add(StopAdvance_Button); Controls.Add(USB_Port_TB); Controls.Add(USB_Port_label); @@ -835,5 +848,6 @@ private void InitializeComponent() private TextBox USB_Port_TB; private Button StopAdvance_Button; private ToolStripStatusLabel Label_DayAdvance; + private Button B_ResetTime; } } \ No newline at end of file diff --git a/RaidCrawler.WinForms/MainWindow.cs b/RaidCrawler.WinForms/MainWindow.cs index 3038d59..fbe6234 100644 --- a/RaidCrawler.WinForms/MainWindow.cs +++ b/RaidCrawler.WinForms/MainWindow.cs @@ -380,7 +380,8 @@ await ErrorHandler ButtonDownloadEvents, SendScreenshot, btnOpenMap, - Rewards + Rewards, + B_ResetTime }, true ); @@ -423,7 +424,8 @@ private void Disconnect(CancellationToken token) ButtonDisconnect, ButtonViewRAM, ButtonDownloadEvents, - SendScreenshot + SendScreenshot, + B_ResetTime }, false ); @@ -2201,5 +2203,30 @@ private static string GetSpriteNameForUrl(PK9 pk, bool shiny) )[1..]; return spriteName.Replace('_', '-').Insert(0, "_"); } + + private void B_ResetTime_Click(object sender, EventArgs e) + { + Task.Run(async () => + { + try + { + UpdateStatus("Resetting date..."); + await ConnectionWrapper.ResetTime(Source.Token).ConfigureAwait(false); + UpdateStatus("Date reset!"); + } + catch (Exception ex) + { + await ErrorHandler + .DisplayMessageBox( + this, + Webhook, + $"Could not reset the date: {ex.Message}", + Source.Token + ) + .ConfigureAwait(false); + return; + } + }); + } } }