mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-26 02:02:28 +08:00
Finished scene explorer, lots of cleanups. Inspector and Search left now.
This commit is contained in:
@ -1,11 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ExplorerBeta.Config;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using ExplorerBeta.Config;
|
||||
|
||||
namespace ExplorerBeta.UI.Shared
|
||||
{
|
||||
@ -17,24 +13,45 @@ namespace ExplorerBeta.UI.Shared
|
||||
|
||||
public class PageHandler
|
||||
{
|
||||
public PageHandler(int listCount)
|
||||
public PageHandler()
|
||||
{
|
||||
ListCount = listCount;
|
||||
m_itemsPerPage = ModConfig.Instance?.Default_Page_Limit ?? 20;
|
||||
}
|
||||
|
||||
// callback for when the page is turned
|
||||
public event Action OnPageChanged;
|
||||
|
||||
// set and maintained by owner of list
|
||||
public int ListCount { get; set; }
|
||||
|
||||
// For now this is just set when the PageHandler is created, based on config.
|
||||
// At some point I might make it possible to change this after creation again.
|
||||
private readonly int m_itemsPerPage;
|
||||
public int ItemsPerPage => m_itemsPerPage;
|
||||
private int m_itemsPerPage;
|
||||
|
||||
private int m_currentPage;
|
||||
|
||||
private GameObject m_pageUIHolder;
|
||||
private Text m_currentPageLabel;
|
||||
|
||||
// set and maintained by owner of list
|
||||
private int m_listCount;
|
||||
public int ListCount
|
||||
{
|
||||
get => m_listCount;
|
||||
set
|
||||
{
|
||||
m_listCount = value;
|
||||
|
||||
if (LastPage <= 0 && m_pageUIHolder.activeSelf)
|
||||
{
|
||||
m_pageUIHolder.SetActive(false);
|
||||
}
|
||||
else if (LastPage > 0 && !m_pageUIHolder.activeSelf)
|
||||
{
|
||||
m_pageUIHolder.SetActive(true);
|
||||
}
|
||||
|
||||
RefreshUI();
|
||||
}
|
||||
}
|
||||
|
||||
// the last page index (not using "index" to avoid confusion with next property)
|
||||
public int LastPage => (int)Math.Ceiling(ListCount / (decimal)m_itemsPerPage) - 1;
|
||||
|
||||
@ -79,83 +96,74 @@ namespace ExplorerBeta.UI.Shared
|
||||
|
||||
#region UI
|
||||
|
||||
private GameObject m_pageUIHolder;
|
||||
private Text m_currentPageLabel;
|
||||
|
||||
public void Show() => m_pageUIHolder?.SetActive(true);
|
||||
|
||||
public void Hide() => m_pageUIHolder?.SetActive(false);
|
||||
|
||||
public void ConstructUI(GameObject parent)
|
||||
{
|
||||
m_pageUIHolder = UIFactory.CreateHorizontalGroup(parent);
|
||||
|
||||
var image = m_pageUIHolder.GetComponent<Image>();
|
||||
image.color = new Color(0f, 0f, 0f, 0f);
|
||||
|
||||
var parentGroup = m_pageUIHolder.GetComponent<HorizontalLayoutGroup>();
|
||||
parentGroup.childForceExpandHeight = true;
|
||||
parentGroup.childForceExpandWidth = false;
|
||||
parentGroup.childControlWidth = true;
|
||||
parentGroup.childControlHeight = true;
|
||||
|
||||
var parentLayout = m_pageUIHolder.AddComponent<LayoutElement>();
|
||||
parentLayout.minHeight = 45;
|
||||
parentLayout.preferredHeight = 45;
|
||||
parentLayout.flexibleHeight = 3;
|
||||
parentLayout.minWidth = 300;
|
||||
parentLayout.preferredWidth = 300;
|
||||
parentLayout.flexibleWidth = 0;
|
||||
|
||||
var leftBtnObj = UIFactory.CreateButton(m_pageUIHolder);
|
||||
var leftBtn = leftBtnObj.GetComponent<Button>();
|
||||
#if CPP
|
||||
leftBtn.onClick.AddListener(new Action(() => { TurnPage(Turn.Left); }));
|
||||
#else
|
||||
leftBtn.onClick.AddListener(() => { TurnPage(Turn.Left); });
|
||||
#endif
|
||||
var leftBtnText = leftBtnObj.GetComponentInChildren<Text>();
|
||||
leftBtnText.text = "<";
|
||||
var leftBtnLayout = leftBtnObj.AddComponent<LayoutElement>();
|
||||
leftBtnLayout.flexibleHeight = 0;
|
||||
leftBtnLayout.flexibleWidth = 0;
|
||||
leftBtnLayout.minWidth = 30;
|
||||
leftBtnLayout.preferredWidth = 30;
|
||||
leftBtnLayout.minHeight = 30;
|
||||
leftBtnLayout.preferredHeight = 30;
|
||||
|
||||
var labelObj = UIFactory.CreateLabel(m_pageUIHolder, TextAnchor.MiddleCenter);
|
||||
m_currentPageLabel = labelObj.GetComponent<Text>();
|
||||
m_currentPageLabel.text = "Page 1 / TODO";
|
||||
var textLayout = labelObj.AddComponent<LayoutElement>();
|
||||
textLayout.flexibleWidth = 1.5f;
|
||||
textLayout.preferredWidth = 200;
|
||||
|
||||
var rightBtnObj = UIFactory.CreateButton(m_pageUIHolder);
|
||||
var rightBtn = rightBtnObj.GetComponent<Button>();
|
||||
#if CPP
|
||||
rightBtn.onClick.AddListener(new Action(() => { TurnPage(Turn.Right); }));
|
||||
#else
|
||||
rightBtn.onClick.AddListener(() => { TurnPage(Turn.Right); });
|
||||
#endif
|
||||
var rightBtnText = rightBtnObj.GetComponentInChildren<Text>();
|
||||
rightBtnText.text = ">";
|
||||
var rightBtnLayout = rightBtnObj.AddComponent<LayoutElement>();
|
||||
rightBtnLayout.flexibleHeight = 0;
|
||||
rightBtnLayout.flexibleWidth = 0;
|
||||
rightBtnLayout.preferredWidth = 30;
|
||||
rightBtnLayout.minWidth = 30;
|
||||
rightBtnLayout.minHeight = 30;
|
||||
rightBtnLayout.preferredHeight = 30;
|
||||
|
||||
RefreshUI();
|
||||
}
|
||||
|
||||
public void RefreshUI()
|
||||
{
|
||||
m_currentPageLabel.text = $"Page {m_currentPage + 1} / {LastPage + 1}";
|
||||
}
|
||||
|
||||
#endregion
|
||||
public void ConstructUI(GameObject parent)
|
||||
{
|
||||
m_pageUIHolder = UIFactory.CreateHorizontalGroup(parent);
|
||||
|
||||
Image image = m_pageUIHolder.GetComponent<Image>();
|
||||
image.color = new Color(0f, 0f, 0f, 0f);
|
||||
|
||||
HorizontalLayoutGroup parentGroup = m_pageUIHolder.GetComponent<HorizontalLayoutGroup>();
|
||||
parentGroup.childForceExpandHeight = true;
|
||||
parentGroup.childForceExpandWidth = false;
|
||||
parentGroup.childControlWidth = true;
|
||||
parentGroup.childControlHeight = true;
|
||||
|
||||
LayoutElement parentLayout = m_pageUIHolder.AddComponent<LayoutElement>();
|
||||
parentLayout.minHeight = 20;
|
||||
parentLayout.flexibleHeight = 0;
|
||||
parentLayout.minWidth = 290;
|
||||
parentLayout.flexibleWidth = 30;
|
||||
|
||||
GameObject leftBtnObj = UIFactory.CreateButton(m_pageUIHolder);
|
||||
Button leftBtn = leftBtnObj.GetComponent<Button>();
|
||||
#if CPP
|
||||
leftBtn.onClick.AddListener(new Action(() => { TurnPage(Turn.Left); }));
|
||||
#else
|
||||
leftBtn.onClick.AddListener(() => { TurnPage(Turn.Left); });
|
||||
#endif
|
||||
Text leftBtnText = leftBtnObj.GetComponentInChildren<Text>();
|
||||
leftBtnText.text = "<";
|
||||
LayoutElement leftBtnLayout = leftBtnObj.AddComponent<LayoutElement>();
|
||||
leftBtnLayout.flexibleHeight = 0;
|
||||
leftBtnLayout.flexibleWidth = 0;
|
||||
leftBtnLayout.minWidth = 50;
|
||||
leftBtnLayout.minHeight = 20;
|
||||
|
||||
GameObject labelObj = UIFactory.CreateLabel(m_pageUIHolder, TextAnchor.MiddleCenter);
|
||||
m_currentPageLabel = labelObj.GetComponent<Text>();
|
||||
m_currentPageLabel.text = "Page 1 / TODO";
|
||||
LayoutElement textLayout = labelObj.AddComponent<LayoutElement>();
|
||||
textLayout.flexibleWidth = 1.5f;
|
||||
textLayout.preferredWidth = 200;
|
||||
|
||||
GameObject rightBtnObj = UIFactory.CreateButton(m_pageUIHolder);
|
||||
Button rightBtn = rightBtnObj.GetComponent<Button>();
|
||||
#if CPP
|
||||
rightBtn.onClick.AddListener(new Action(() => { TurnPage(Turn.Right); }));
|
||||
#else
|
||||
rightBtn.onClick.AddListener(() => { TurnPage(Turn.Right); });
|
||||
#endif
|
||||
Text rightBtnText = rightBtnObj.GetComponentInChildren<Text>();
|
||||
rightBtnText.text = ">";
|
||||
LayoutElement rightBtnLayout = rightBtnObj.AddComponent<LayoutElement>();
|
||||
rightBtnLayout.flexibleHeight = 0;
|
||||
rightBtnLayout.flexibleWidth = 0;
|
||||
rightBtnLayout.minWidth = 50;
|
||||
rightBtnLayout.minHeight = 20;
|
||||
|
||||
ListCount = 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user