feat: 完成作业点赞功能

This commit is contained in:
MistEO
2023-03-05 15:34:58 +08:00
parent c71768e113
commit bf761a8367
4 changed files with 58 additions and 24 deletions

View File

@@ -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<int> _recentlyRatedCopilotId = new List<int>();
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/";

View File

@@ -367,6 +367,8 @@
<system:String x:Key="CopilotLocation">Task file / url</system:String>
<system:String x:Key="SelectTheFile">Select task file</system:String>
<system:String x:Key="SelectTheFileTip">Task files can be directly dragged in with the mouse (o゚v゚)</system:String>
<system:String x:Key="DoYouLikeThisWebJson">Do you like this task file?</system:String>
<system:String x:Key="ThanksForLikeWebJson">Thanks for the review!\nThe comment section will be opened soon on the web page, so stay tuned!</system:String>
<system:String x:Key="AutoSquad">Auto squad</system:String>
<system:String x:Key="AutoSquadTip">The operator of &quot;special focus&quot; cannot be identified at this time</system:String>
<system:String x:Key="LoopTimes">LoopTimes</system:String>

View File

@@ -369,6 +369,8 @@
<system:String x:Key="CopilotLocation">作业路径/神秘代码</system:String>
<system:String x:Key="SelectTheFile">选择作业</system:String>
<system:String x:Key="SelectTheFileTip">作业文件可以直接用鼠标拖进来哦 (o゚v゚)</system:String>
<system:String x:Key="DoYouLikeThisWebJson">作业怎么样?评价下吧!</system:String>
<system:String x:Key="ThanksForLikeWebJson">感谢评价!\n网页端即将开放评论区敬请期待</system:String>
<system:String x:Key="AutoSquad">自动编队</system:String>
<system:String x:Key="LoopTimes">循环次数</system:String>
<system:String x:Key="AutoSquadTip">自动编队暂时无法识别“特别关注”的干员</system:String>

View File

@@ -130,7 +130,12 @@
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
Orientation="Horizontal"
Visibility="{c:Binding IsDataFromWeb and (CopilotId > 0)}">
Visibility="{c:Binding CouldLikeWebJson}">
<maa:TextBlock
Margin="10"
VerticalAlignment="Center"
Block.TextAlignment="Center"
Text="{DynamicResource DoYouLikeThisWebJson}" />
<Button
Width="50"
Height="30"