2023-01-17 18:07:49 +08:00

88 lines
2.6 KiB
C#

using PolyAndCode.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
namespace Assets.Scripts.Scenes.VideoRide
{
public class ListItem : MonoBehaviour, ICell
{
//UI
public Text nameLabel;
public Text genderLabel;
public Text idLabel;
public Text powerLabel;
public GameObject master;
//Model
private ContactInfo _contactInfo;
private int _cellIndex;
public string Id;
public string Rank;
public string Name;
private VideoGameManager manager { get; set; }
private void Start()
{
manager = FindObjectOfType<VideoGameManager>();
if (manager._aRMode == VideoGameManager.ARMode.INSPECT)
{
GetComponent<Button>().onClick.AddListener(ButtonListener);
}
}
private float timer = 1f;
private void Update()
{
timer -= Time.deltaTime;
while (timer < 0)
{
if (manager != null)
{
var riders = manager.cyclingController?.riders;
if (riders != null)
{
var current = riders.Where(c => c.UserId.ToString() == Id).FirstOrDefault();
if (current == null)
{
gameObject.SetActive(false);
gameObject.Destroy();
}
}
}
timer += 1f;
}
}
//This is called from the SetCell method in DataSource
public void ConfigureCell(ContactInfo contactInfo, int cellIndex)
{
Id = contactInfo.id;
_cellIndex = cellIndex;
_contactInfo = contactInfo;
nameLabel.text = contactInfo.Name;
genderLabel.text = contactInfo.Gender;
idLabel.text = contactInfo.id;
powerLabel.text = contactInfo.Power.ToString("f0") + "W";
//master.SetActive(manager.CurrentPlayer.UserId.ToString() == contactInfo.id);
}
public void UpdateItem(string name,string gender,string id)
{
nameLabel.text = name;
genderLabel.text = gender;
idLabel.text = id;
master.SetActive(manager.CurrentPlayer?.UserId.ToString() == id);
}
private void ButtonListener()
{
manager.ChangePlayer(Convert.ToInt32(Id));
}
}
}