107 lines
3.9 KiB
C#
107 lines
3.9 KiB
C#
using Assets.Scripts;
|
|
using Assets.Scripts.Apis;
|
|
using Assets.Scripts.Apis.Models;
|
|
using DG.Tweening;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
|
|
public class QuickLoginUser : MonoBehaviour
|
|
{
|
|
QUserInfo user;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
}
|
|
public void Initial(QUserInfo user)
|
|
{
|
|
if (user ==null) return;
|
|
transform.GetComponent<Button>().onClick.AddListener(() =>
|
|
{
|
|
ApiBase.SetCookie(user.Cookie);
|
|
var r = ConfigHelper.userApi.GetUserInfo();
|
|
if (r.result)
|
|
{
|
|
//ConfigHelper.CurrentUser = r.data.Value<UserResultModel>("user");
|
|
//ConfigHelper.CurrentUser = re;
|
|
var usermodel = r.data.Value<JObject>("user");
|
|
App.CurrentUser = new UserModel
|
|
{
|
|
NickName = usermodel.Value<string>("NickName"),
|
|
Ftp = usermodel.Value<int>("FTP"),
|
|
Weight = usermodel.Value<double>("Weight"),
|
|
BicycleWeight = usermodel.Value<double>("BicycleWeight"),
|
|
Carlories = "",
|
|
Avatar = usermodel.Value<string>("WxHeadImg"),
|
|
Distance = 0,
|
|
Climb = "",
|
|
};
|
|
SceneManager.LoadScene("MainScene");
|
|
}
|
|
else
|
|
{
|
|
Utils.showToast(gameObject, r.errMsg);
|
|
}
|
|
});
|
|
this.user = user;
|
|
Utils.DisplayImage(StartCoroutine, transform.Find("Avatar").GetComponent<RawImage>(),user.Avatar);
|
|
transform.Find("NickNameText").GetComponent<Text>().text = user.NickName;
|
|
transform.Find("BtnDelete").GetComponent<Button>().onClick.AddListener(DestroySelf);
|
|
}
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
}
|
|
void DestroySelf()
|
|
{
|
|
var content = transform.parent;
|
|
var index = transform.GetSiblingIndex() - 1;
|
|
DestroyImmediate(gameObject);
|
|
//if (content.childCount == 2)
|
|
//{
|
|
// var info = Instantiate(Resources.Load<GameObject>("UI/Prefab/Login/QuickUserInfo")).transform;
|
|
// info.GetComponent<QuickLoginUser>().Initial(null);
|
|
// info.parent = content;
|
|
// info.localScale = new Vector3(1, 1, 1);
|
|
// content.Find("empty1").transform.SetSiblingIndex(0);
|
|
// content.Find("empty2").transform.SetSiblingIndex(content.childCount - 1);
|
|
//}
|
|
content.parent.parent.GetComponent<QuickLoginScroll>().Initial();
|
|
DeleteList(index);
|
|
}
|
|
|
|
private void DeleteList(int index)
|
|
{
|
|
var userInfosJson = PlayerPrefs.GetString("UserInfos");
|
|
var userInfos = JsonConvert.DeserializeObject<List<QUserInfo>>(userInfosJson);
|
|
userInfos.RemoveAt(index);
|
|
PlayerPrefs.SetString("UserInfos", JsonConvert.SerializeObject(userInfos));
|
|
}
|
|
|
|
public void setActive()
|
|
{
|
|
//ColorUtility.TryParseHtmlString("#ffffffff", out Color color);
|
|
//transform.Find("Avatar").GetComponent<RawImage>().color = color;
|
|
transform.Find("Avatar").GetComponent<RawImage>().DOFade(1f, 0.3f);
|
|
transform.GetComponent<Button>().enabled = true;
|
|
transform.Find("NickNameText").GetComponent<Text>().enabled = true;
|
|
}
|
|
public void setNoActive()
|
|
{
|
|
//ColorUtility.TryParseHtmlString("#ffffff80", out Color color);
|
|
//transform.Find("Avatar").GetComponent<RawImage>().color = color;
|
|
transform.Find("Avatar").GetComponent<RawImage>().DOFade(0.5f, 0.3f);
|
|
transform.GetComponent<Button>().enabled = false;
|
|
transform.Find("NickNameText").GetComponent<Text>().enabled = false;
|
|
}
|
|
}
|