2021-04-16 21:07:32 +10:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
namespace UnityExplorer.UI.Widgets
|
|
|
|
|
{
|
2021-04-19 20:08:07 +10:00
|
|
|
|
public class ButtonCell<T> : ICell
|
2021-04-16 21:07:32 +10:00
|
|
|
|
{
|
|
|
|
|
public bool Enabled => m_enabled;
|
|
|
|
|
private bool m_enabled;
|
|
|
|
|
|
2021-04-23 21:50:58 +10:00
|
|
|
|
public Action<int> OnClick;
|
|
|
|
|
public int CurrentDataIndex;
|
2021-04-16 21:07:32 +10:00
|
|
|
|
|
2021-04-19 23:47:25 +10:00
|
|
|
|
public ButtonListSource<T> list;
|
2021-04-16 21:07:32 +10:00
|
|
|
|
|
|
|
|
|
public GameObject uiRoot;
|
2021-04-21 23:07:15 +10:00
|
|
|
|
private RectTransform m_rect;
|
|
|
|
|
public RectTransform Rect => m_rect;
|
2021-04-16 21:07:32 +10:00
|
|
|
|
public Text buttonText;
|
|
|
|
|
public Button button;
|
|
|
|
|
|
2021-04-19 23:47:25 +10:00
|
|
|
|
public ButtonCell(ButtonListSource<T> list, GameObject uiRoot, Button button, Text text)
|
2021-04-16 21:07:32 +10:00
|
|
|
|
{
|
|
|
|
|
this.list = list;
|
|
|
|
|
this.uiRoot = uiRoot;
|
2021-04-21 23:07:15 +10:00
|
|
|
|
this.m_rect = uiRoot.GetComponent<RectTransform>();
|
2021-04-16 21:07:32 +10:00
|
|
|
|
this.buttonText = text;
|
|
|
|
|
this.button = button;
|
|
|
|
|
|
2021-04-23 21:50:58 +10:00
|
|
|
|
button.onClick.AddListener(() => { OnClick?.Invoke(CurrentDataIndex); });
|
2021-04-16 21:07:32 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Disable()
|
|
|
|
|
{
|
|
|
|
|
m_enabled = false;
|
|
|
|
|
uiRoot.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Enable()
|
|
|
|
|
{
|
|
|
|
|
m_enabled = true;
|
|
|
|
|
uiRoot.SetActive(true);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-21 21:04:26 +10:00
|
|
|
|
public static RectTransform CreatePrototypeCell(GameObject parent)
|
2021-04-16 21:07:32 +10:00
|
|
|
|
{
|
|
|
|
|
var prototype = UIFactory.CreateHorizontalGroup(parent, "PrototypeCell", true, true, true, true, 2, default,
|
|
|
|
|
new Color(0.15f, 0.15f, 0.15f), TextAnchor.MiddleCenter);
|
|
|
|
|
//var cell = prototype.AddComponent<TransformCell>();
|
|
|
|
|
var rect = prototype.GetComponent<RectTransform>();
|
|
|
|
|
rect.anchorMin = new Vector2(0, 1);
|
|
|
|
|
rect.anchorMax = new Vector2(0, 1);
|
|
|
|
|
rect.pivot = new Vector2(0.5f, 1);
|
|
|
|
|
rect.sizeDelta = new Vector2(25, 25);
|
|
|
|
|
UIFactory.SetLayoutElement(prototype, minWidth: 100, flexibleWidth: 9999, minHeight: 25, flexibleHeight: 0);
|
|
|
|
|
|
|
|
|
|
var nameButton = UIFactory.CreateButton(prototype, "NameButton", "Name", null);
|
|
|
|
|
UIFactory.SetLayoutElement(nameButton.gameObject, flexibleWidth: 9999, minHeight: 25, flexibleHeight: 0);
|
|
|
|
|
var nameLabel = nameButton.GetComponentInChildren<Text>();
|
|
|
|
|
nameLabel.horizontalOverflow = HorizontalWrapMode.Overflow;
|
|
|
|
|
nameLabel.alignment = TextAnchor.MiddleLeft;
|
|
|
|
|
|
|
|
|
|
Color normal = new Color(0.15f, 0.15f, 0.15f);
|
|
|
|
|
Color highlight = new Color(0.25f, 0.25f, 0.25f);
|
|
|
|
|
Color pressed = new Color(0.05f, 0.05f, 0.05f);
|
|
|
|
|
Color disabled = new Color(1, 1, 1, 0);
|
|
|
|
|
RuntimeProvider.Instance.SetColorBlock(nameButton, normal, highlight, pressed, disabled);
|
|
|
|
|
|
|
|
|
|
prototype.SetActive(false);
|
|
|
|
|
|
2021-04-21 21:04:26 +10:00
|
|
|
|
return rect;
|
2021-04-16 21:07:32 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|