Skip to content

Commit

Permalink
feat: give thumbs up after play
Browse files Browse the repository at this point in the history
  • Loading branch information
LingFeng-bbben committed Oct 22, 2024
1 parent 3d4a0f9 commit 808ba7d
Show file tree
Hide file tree
Showing 10 changed files with 608 additions and 40 deletions.
53 changes: 40 additions & 13 deletions Assets/Font/GenJyuuGothicScore.asset

Large diffs are not rendered by default.

119 changes: 94 additions & 25 deletions Assets/Font/GenJyuuGothicX-Medium SDF.asset

Large diffs are not rendered by default.

179 changes: 178 additions & 1 deletion Assets/Scenes/Result.unity
Original file line number Diff line number Diff line change
Expand Up @@ -2089,6 +2089,81 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 355472547}
m_CullTransparentMesh: 1
--- !u!1 &364490109
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 364490110}
- component: {fileID: 364490112}
- component: {fileID: 364490111}
m_Layer: 5
m_Name: Image (1)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &364490110
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 364490109}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1591627172}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -202.6, y: -437.5}
m_SizeDelta: {x: 90, y: 90}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &364490111
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 364490109}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: cea8bfbff6e3bcb4b85f42319e9283bb, type: 3}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!222 &364490112
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 364490109}
m_CullTransparentMesh: 1
--- !u!43 &442738576
Mesh:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -6099,7 +6174,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 213, y: -444}
m_AnchoredPosition: {x: 218.9, y: -438.8}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &940541982
Expand Down Expand Up @@ -7367,6 +7442,85 @@ Mesh:
offset: 0
size: 0
path:
--- !u!1 &1245790780
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1245790781}
- component: {fileID: 1245790783}
- component: {fileID: 1245790782}
m_Layer: 5
m_Name: Text (Legacy)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1245790781
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1245790780}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1591627172}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -253.9, y: -371.29}
m_SizeDelta: {x: 211.94, y: 42.42}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1245790782
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1245790780}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 12800000, guid: 8cb6273d740045b4aa08f9875bbd7601, type: 3}
m_FontSize: 29
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 10
m_MaxSize: 40
m_Alignment: 5
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: "\u597D\u73A9\u5C31\u70B9\u4E2A\u8D5E\u5427"
--- !u!222 &1245790783
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1245790780}
m_CullTransparentMesh: 1
--- !u!1 &1246178291
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -14648,10 +14802,19 @@ PrefabInstance:
- targetCorrespondingSourceObject: {fileID: 8053637610791840999, guid: 37bdf9fbdeb38224783acd28ed56b012, type: 3}
insertIndex: -1
addedObject: {fileID: 940541981}
- targetCorrespondingSourceObject: {fileID: 8053637610791840999, guid: 37bdf9fbdeb38224783acd28ed56b012, type: 3}
insertIndex: -1
addedObject: {fileID: 364490110}
- targetCorrespondingSourceObject: {fileID: 8053637610791840999, guid: 37bdf9fbdeb38224783acd28ed56b012, type: 3}
insertIndex: -1
addedObject: {fileID: 1245790781}
m_AddedComponents:
- targetCorrespondingSourceObject: {fileID: 5205452559665588105, guid: 37bdf9fbdeb38224783acd28ed56b012, type: 3}
insertIndex: -1
addedObject: {fileID: 3234089997214234526}
- targetCorrespondingSourceObject: {fileID: 5205452559665588105, guid: 37bdf9fbdeb38224783acd28ed56b012, type: 3}
insertIndex: -1
addedObject: {fileID: 3234089997214234527}
m_SourcePrefab: {fileID: 100100000, guid: 37bdf9fbdeb38224783acd28ed56b012, type: 3}
--- !u!1 &3234089997214234525 stripped
GameObject:
Expand Down Expand Up @@ -14688,6 +14851,20 @@ MonoBehaviour:
clearLogo: {fileID: 2008839068}
xxlb: {fileID: 1724301624}
coverImg: {fileID: 67220227}
--- !u!114 &3234089997214234527
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3234089997214234525}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 39acf61dc70e79c44a8a98c0b4fa7d95, type: 3}
m_Name:
m_EditorClassIdentifier:
infotext: {fileID: 1245790782}
thumb: {fileID: 364490111}
--- !u!1001 &6959415326676185805
PrefabInstance:
m_ObjectHideFlags: 0
Expand Down
2 changes: 1 addition & 1 deletion Assets/Script/DontDestroy/Managers/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public bool UseUnityTimer
void Awake()
{
Debug.Log($"Version: {MajInstances.GameVersion}");
HttpTransporter.Timeout = TimeSpan.FromMilliseconds(10000);
//HttpTransporter.Timeout = TimeSpan.FromMilliseconds(10000);
Application.logMessageReceived += (c, trace, type) =>
{
logQueue.Enqueue(new GameLog()
Expand Down
2 changes: 2 additions & 0 deletions Assets/Script/Game/GamePlayManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ await DownloadFile(videoUri, videoPath, r =>
}
song = await SongDetail.ParseAsync(dirInfo.GetFiles());
song.Hash = _songDetail.Hash;
song.OnlineId = _songDetail.OnlineId;
song.ApiEndpoint = _songDetail.ApiEndpoint;
_songDetail = song;
}
/*async UniTask<GetResult> DownloadFile(string uri,string savePath,Action<IHttpProgressReporter> onProgressChanged,int buffersize = 128*1024)
Expand Down
153 changes: 153 additions & 0 deletions Assets/Script/Result/OnlineInteractionSender.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
using Cysharp.Threading.Tasks;
using MajdataPlay.IO;
using MajdataPlay.Net;
using MajdataPlay.Types;
using MajdataPlay.Utils;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Security.Cryptography;
using System.Text;
using System.Text.Json;
using UnityEngine;
using UnityEngine.UI;

public class OnlineInteractionSender : MonoBehaviour
{
public Text infotext;
public Image thumb;

SongDetail SongDetail;

public bool Init(SongDetail song)
{
if (song.ApiEndpoint == null)
{
infotext.text = "";
thumb.gameObject.SetActive(false);
return false;
}
SongDetail = song;
MajInstances.InputManager.BindAnyArea(OnAreaDown);
LightManager.Instance.SetButtonLight(Color.yellow, 4);
return true;
}

private void OnAreaDown(object sender, InputEventArgs e)
{
if (e.IsClick && e.IsButton && e.Type == SensorType.A5)
{
MajInstances.InputManager.UnbindAnyArea(OnAreaDown);
SendInteraction(SongDetail);
}
}

private void OnDestroy()
{
MajInstances.InputManager.UnbindAnyArea(OnAreaDown);
}

public void SendInteraction(SongDetail song)
{
SendLike(song).Forget();
}

async UniTask SendLike(SongDetail song)
{
infotext.text = "稍等...";
LightManager.Instance.SetButtonLight(Color.blue, 4);
var client = HttpTransporter.ShareClient;
try
{
if (song.ApiEndpoint == null)
{
infotext.text = "";
LightManager.Instance.SetButtonLight(Color.red, 4);
return;
}

if (song.ApiEndpoint.Username == null || song.ApiEndpoint.Password == null)
{
infotext.text = "登录失败";
LightManager.Instance.SetButtonLight(Color.red, 4);
return;
}

var interactUrl = song.ApiEndpoint.Url + "/Interact/" + song.OnlineId;
var task = client.GetStringAsync(interactUrl);
while (!task.IsCompleted)
{
await UniTask.Yield();
}
var intjson = task.Result;

var intlist = JsonSerializer.Deserialize<MajNetSongInteract>(intjson);

if (intlist.LikeList.Any(o => o == song.ApiEndpoint.Username))
{
infotext.text = "你已经点过赞了!@!";
LightManager.Instance.SetButtonLight(Color.red, 4);
return;
}

var formData = new MultipartFormDataContent
{
{ new StringContent(song.ApiEndpoint.Username), "username" },
{ new StringContent(ComputeMD5(song.ApiEndpoint.Password)), "password" }
};

var tokentask = client.PostAsync(song.ApiEndpoint.Url + "/User/Login", formData);
while (!tokentask.IsCompleted)
{
await UniTask.Yield();
}
if (tokentask.Result.StatusCode != System.Net.HttpStatusCode.OK)
{
infotext.text = "登录失败";
return;
}
var readtask = tokentask.Result.Content.ReadAsStringAsync();
while (!readtask.IsCompleted)
{
await UniTask.Yield();
}
var token = readtask.Result;

formData = new MultipartFormDataContent
{
{ new StringContent(token), "token" },
{ new StringContent("like"), "type" },
{ new StringContent("..."), "content" },
};
var liketask = client.PostAsync(interactUrl, formData);
while (!liketask.IsCompleted)
{
await UniTask.Yield();
}

if (liketask.Result.StatusCode == System.Net.HttpStatusCode.OK)
{
infotext.text = "点赞成功";
LightManager.Instance.SetButtonLight(Color.green, 4);
}
}catch (Exception ex)
{
infotext.text = "点赞失败";
Debug.LogError(ex);
LightManager.Instance.SetButtonLight(Color.red, 4);
return;
}
}
public static string ComputeMD5(string input)
{
using (var md5 = MD5.Create())
{
var inputBytes = Encoding.UTF8.GetBytes(input);
var hashBytes = md5.ComputeHash(inputBytes);
return BitConverter.ToString(hashBytes).Replace("-", "").ToLower();
}
}

}
Loading

0 comments on commit 808ba7d

Please sign in to comment.