219 lines
6.3 KiB
C#
219 lines
6.3 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Text;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using UnityEngine.Networking;
|
||
using TMPro;
|
||
using System;
|
||
using Unity.VisualScripting;
|
||
using UnityEngine.SceneManagement;
|
||
|
||
public class UIPeopleProgress : UIBase
|
||
{
|
||
private RowsItem currentItem;
|
||
private StudentTestDataItem studentTestData;
|
||
|
||
public Image bg;
|
||
public Image head;
|
||
public TextMeshProUGUI nameTxt;
|
||
public TextMeshProUGUI descriptionTxt;
|
||
public Button close;
|
||
public TextMeshProUGUI hintTxt;
|
||
|
||
public Image progressImg;
|
||
public TextMeshProUGUI progressTxt;
|
||
public Button resetBtn;
|
||
public TextMeshProUGUI progressHintTxt;
|
||
|
||
string imgurl;
|
||
|
||
public Transform content;
|
||
|
||
public List<UIProgressItem> listP;
|
||
|
||
|
||
public List<DataItem> currentData;
|
||
|
||
|
||
public Button loadNewScene;
|
||
private void Awake()
|
||
{
|
||
if (DataManager.Instance.showMode == ShowMode.StudentTest)
|
||
{
|
||
studentTestData = DataManager.Instance.currentSelectTest;
|
||
if (studentTestData != null)
|
||
{
|
||
var allpeople = DataManager.Instance.peoples;
|
||
foreach (var people in allpeople)
|
||
{
|
||
if (people.id == studentTestData.casesId)
|
||
{
|
||
currentItem = people;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
currentItem = DataManager.Instance.currentSelectPeople;
|
||
}
|
||
|
||
close.onClick.AddListener(DestroyThisUI);
|
||
resetBtn.onClick.AddListener(ResetProgress);
|
||
EventCenter.dispatcher.AddListener(MsgType.OnGetCurrentPeopleProgress, OnGetCurrentData);
|
||
|
||
DataManager.Instance.NextScene = 2;
|
||
loadNewScene.onClick.AddListener(() => { SceneManager.LoadScene(1); });
|
||
|
||
GetPeopleInfo();
|
||
}
|
||
|
||
private void ResetProgress()
|
||
{
|
||
int id = DataManager.Instance.currentSelectPeople.id;
|
||
var list = DataManager.Instance.peopleDisProgress;
|
||
if (list.ContainsKey(id))
|
||
{
|
||
list[id] = new List<int>(1) { 0 };
|
||
}
|
||
RefreshProgressState();
|
||
}
|
||
|
||
private void DestroyThisUI()
|
||
{
|
||
UIManager.Instance.DestoryUI(UIType.UIPeopleProgress);
|
||
}
|
||
|
||
private void OnDestroy()
|
||
{
|
||
EventCenter.dispatcher.RemoveListener(MsgType.OnGetCurrentPeopleProgress, OnGetCurrentData);
|
||
}
|
||
|
||
public void SetProgress()
|
||
{
|
||
float count = listP.Count;
|
||
float current = 0;
|
||
int id = DataManager.Instance.currentSelectPeople.id;
|
||
var list = DataManager.Instance.peopleDisProgress;
|
||
if (list.ContainsKey(id))
|
||
{
|
||
current = list[id].Count - 1;
|
||
}
|
||
float p = current / count;
|
||
progressImg.fillAmount = p;
|
||
progressTxt.text = p * 100 + "%";
|
||
}
|
||
|
||
private void OnGetCurrentData(Message evt)
|
||
{
|
||
imgurl = currentItem.image;
|
||
nameTxt.text = currentItem.name + "-" + currentItem.specialty;
|
||
descriptionTxt.text = currentItem.languageType;
|
||
//<2F>ж<EFBFBD><D0B6>ٸ<EFBFBD><D9B8><EFBFBD><EFBFBD><EFBFBD>
|
||
currentData = DataManager.Instance.currentPeoplesProgress;
|
||
StartCoroutine(DownSprite());
|
||
|
||
if (currentData != null)
|
||
{
|
||
listP = new List<UIProgressItem>();
|
||
GameObject Prefab = (GameObject)Resources.Load("UIPrefabs/UIProgressItem");
|
||
for (int i = 0; i < currentData.Count; i++)
|
||
{
|
||
UIProgressItem item = Instantiate(Prefab, content).GetComponent<UIProgressItem>();
|
||
listP.Add(item);
|
||
if (i == 0)
|
||
{
|
||
item.CloseBG();
|
||
}
|
||
}
|
||
RefreshProgressState();
|
||
}
|
||
}
|
||
|
||
public void RefreshProgressState()
|
||
{
|
||
var list = DataManager.Instance.peopleDisProgress;
|
||
var peopleid = DataManager.Instance.currentSelectPeople.id;
|
||
|
||
for (int i = 0; i < currentData.Count; i++)
|
||
{
|
||
listP[i].SetTitle(currentData[i].title);
|
||
listP[i].SetData(currentData[i]);
|
||
if (list.ContainsKey(peopleid))
|
||
{
|
||
if (list[peopleid].Contains(i))
|
||
{
|
||
listP[i].SetCantClick(false);
|
||
}
|
||
else
|
||
{
|
||
listP[i].SetCantClick(true);
|
||
}
|
||
}
|
||
}
|
||
SetProgress();
|
||
|
||
}
|
||
|
||
IEnumerator DownSprite()
|
||
{
|
||
UnityWebRequest wr = new UnityWebRequest(imgurl);
|
||
DownloadHandlerTexture texD1 = new DownloadHandlerTexture(true);
|
||
wr.downloadHandler = texD1;
|
||
yield return wr.SendWebRequest();
|
||
int width = 280;
|
||
int high = 100;
|
||
if (!wr.isNetworkError)
|
||
{
|
||
Texture2D tex = new Texture2D(width, high);
|
||
tex = texD1.texture;
|
||
//<2F><><EFBFBD>汾<EFBFBD><E6B1BE>
|
||
//Byte[] bytes = tex.EncodeToPNG();
|
||
//File.WriteAllBytes(Application.dataPath + "/" + data.name + ".png", bytes);
|
||
|
||
Sprite sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f));
|
||
bg.sprite = sprite;
|
||
head.sprite = sprite;
|
||
//transform.GetComponent<Image>().sprite = sprite;
|
||
}
|
||
}
|
||
|
||
public void GetPeopleInfo()
|
||
{
|
||
string url;
|
||
if (DataManager.Instance.showMode == ShowMode.StudentTest)
|
||
{
|
||
|
||
url = "http://122.112.171.137:85/api/diagnosis/info/list?casesId=" + DataManager.Instance.currentSelectTest.casesId;
|
||
}
|
||
else
|
||
{
|
||
url = "http://122.112.171.137:85/api/diagnosis/info/list?casesId=" + currentItem.id;
|
||
|
||
}
|
||
StartCoroutine(Get(url));
|
||
}
|
||
|
||
IEnumerator Get(string url)
|
||
{
|
||
UnityWebRequest request = UnityWebRequest.Get(url);
|
||
yield return request.SendWebRequest();
|
||
if (request.isHttpError || request.isNetworkError)
|
||
{
|
||
Debug.LogError(request.error);
|
||
}
|
||
else
|
||
{
|
||
string receiveContent = request.downloadHandler.text;
|
||
byte[] datas = Encoding.UTF8.GetBytes(receiveContent);
|
||
receiveContent = Encoding.UTF8.GetString(datas, 0, datas.Length);
|
||
//JsonInfo jsonInfo = JsonMapper.ToObject<JsonInfo>(receiveContent);
|
||
DataParse.Instance.ParsePeopleList(receiveContent);
|
||
|
||
}
|
||
}
|
||
|
||
|
||
}
|