From bf761a83670fac92a1379feb9fd8ddaafbbb833f Mon Sep 17 00:00:00 2001 From: MistEO Date: Sun, 5 Mar 2023 15:34:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E6=88=90=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E7=82=B9=E8=B5=9E=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MaaWpfGui/Main/CopilotViewModel.cs | 71 +++++++++++++++------- src/MaaWpfGui/Res/Localizations/en-us.xaml | 2 + src/MaaWpfGui/Res/Localizations/zh-cn.xaml | 2 + src/MaaWpfGui/Views/CopilotView.xaml | 7 ++- 4 files changed, 58 insertions(+), 24 deletions(-) diff --git a/src/MaaWpfGui/Main/CopilotViewModel.cs b/src/MaaWpfGui/Main/CopilotViewModel.cs index 31315668e7..18a46bcfd1 100644 --- a/src/MaaWpfGui/Main/CopilotViewModel.cs +++ b/src/MaaWpfGui/Main/CopilotViewModel.cs @@ -172,16 +172,24 @@ namespace MaaWpfGui { var copilotIdStr = filename.ToLower().Remove(0, CopilotIdPrefix.Length); int.TryParse(copilotIdStr, out var numberStyles); - CopilotId = numberStyles; - jsonStr = RequestCopilotServer(CopilotId); - IsDataFromWeb = true; + int tempCopilotId = numberStyles; + jsonStr = RequestCopilotServer(tempCopilotId); + if (!string.IsNullOrEmpty(jsonStr)) + { + IsDataFromWeb = true; + CopilotId = tempCopilotId; + } } else if (int.TryParse(filename, out _)) { int.TryParse(filename, out var numberStyles); - CopilotId = numberStyles; - jsonStr = RequestCopilotServer(CopilotId); - IsDataFromWeb = true; + int tempCopilotId = numberStyles; + jsonStr = RequestCopilotServer(tempCopilotId); + if (!string.IsNullOrEmpty(jsonStr)) + { + IsDataFromWeb = true; + CopilotId = tempCopilotId; + } } else { @@ -504,43 +512,57 @@ namespace MaaWpfGui } private readonly string _copilotRatingUrl = "https://prts.maa.plus/copilot/rating"; + private readonly List _recentlyRatedCopilotId = new List(); - public bool CouldLikeWebJson() + private bool _couldLikeWebJson = false; + + public bool CouldLikeWebJson { // TODO: 还要加个限制,如果点过赞了就不让再点了 - return IsDataFromWeb && CopilotId != 0; + get => _couldLikeWebJson; + set => SetAndNotify(ref _couldLikeWebJson, value); + } + + private void UpdateCouldLikeWebJson() + { + CouldLikeWebJson = IsDataFromWeb && + CopilotId > 0 && + _recentlyRatedCopilotId.IndexOf(CopilotId) == -1; } public bool IsDataFromWeb { get => _isDataFromWeb; - set => SetAndNotify(ref _isDataFromWeb, value); + set + { + SetAndNotify(ref _isDataFromWeb, value); + UpdateCouldLikeWebJson(); + } } public int CopilotId { get => _copilotId; - set => SetAndNotify(ref _copilotId, value); + set + { + SetAndNotify(ref _copilotId, value); + UpdateCouldLikeWebJson(); + } } public void LikeWebJson() { - if (!CouldLikeWebJson()) - { - return; - } - - string jsonParam = JsonConvert.SerializeObject(new - { - id = CopilotId, - rating = "Like", - }); - WebService.RequestPost(_copilotRatingUrl, jsonParam); + RateWebJson("Like"); } public void DislikeWebJson() { - if (!CouldLikeWebJson()) + RateWebJson("Dislike"); + } + + private void RateWebJson(string rating) + { + if (!CouldLikeWebJson) { return; } @@ -548,9 +570,12 @@ namespace MaaWpfGui string jsonParam = JsonConvert.SerializeObject(new { id = CopilotId, - rating = "Dislike", + rating = rating, }); WebService.RequestPost(_copilotRatingUrl, jsonParam); + _recentlyRatedCopilotId.Add(CopilotId); + CouldLikeWebJson = false; + AddLog(Localization.GetString("ThanksForLikeWebJson"), UILogColor.Info); } private const string CopilotUiUrl = "https://www.prts.plus/"; diff --git a/src/MaaWpfGui/Res/Localizations/en-us.xaml b/src/MaaWpfGui/Res/Localizations/en-us.xaml index cc32a70553..c7dbbebc2a 100644 --- a/src/MaaWpfGui/Res/Localizations/en-us.xaml +++ b/src/MaaWpfGui/Res/Localizations/en-us.xaml @@ -367,6 +367,8 @@ Task file / url Select task file Task files can be directly dragged in with the mouse (o゚v゚)ノ + Do you like this task file? + Thanks for the review!\nThe comment section will be opened soon on the web page, so stay tuned! Auto squad The operator of "special focus" cannot be identified at this time LoopTimes diff --git a/src/MaaWpfGui/Res/Localizations/zh-cn.xaml b/src/MaaWpfGui/Res/Localizations/zh-cn.xaml index 3f6e4a0fde..4785aa7069 100644 --- a/src/MaaWpfGui/Res/Localizations/zh-cn.xaml +++ b/src/MaaWpfGui/Res/Localizations/zh-cn.xaml @@ -369,6 +369,8 @@ 作业路径/神秘代码 选择作业 作业文件可以直接用鼠标拖进来哦 (o゚v゚)ノ + 作业怎么样?评价下吧! + 感谢评价!\n网页端即将开放评论区,敬请期待! 自动编队 循环次数 自动编队暂时无法识别“特别关注”的干员 diff --git a/src/MaaWpfGui/Views/CopilotView.xaml b/src/MaaWpfGui/Views/CopilotView.xaml index 3e2f785dbc..9924a55645 100644 --- a/src/MaaWpfGui/Views/CopilotView.xaml +++ b/src/MaaWpfGui/Views/CopilotView.xaml @@ -130,7 +130,12 @@ HorizontalAlignment="Center" VerticalAlignment="Bottom" Orientation="Horizontal" - Visibility="{c:Binding IsDataFromWeb and (CopilotId > 0)}"> + Visibility="{c:Binding CouldLikeWebJson}"> +