private void SaveExpandInfo(ExpandInfo expandInfo) { if (!expandInfos.TryGetValue(expandInfo.FileName, out Dictionary <int, ExpandInfo> dict)) { dict = new Dictionary <int, ExpandInfo>(); expandInfos.Add(expandInfo.FileName, dict); } dict[expandInfo.SourceId] = expandInfo; }
internal ExpandQueryOptions Clone() { var clone = new ExpandQueryOptions(ExpandInfo?.Clone(), _selects, IsRoot, Parent); foreach (var expand in Expands) { clone.AddExpand(expand.Clone()); } return(clone); }
protected override void ScrollRectListener(Vector2 value) { Vector3 contentP = m_ContentRectTrans.anchoredPosition; if (m_ExpandInfos == null) { return; } for (int k = 0, length = m_ExpandInfos.Length; k < length; k++) { ExpandInfo expandInfo = m_ExpandInfos[k]; if (!expandInfo.isExpand) { continue; } int count = expandInfo.cellCount; for (int i = 0; i < count; i++) { CellInfo cellInfo = expandInfo.cellInfos[i]; float rangePos = m_Direction == e_Direction.Vertical ? cellInfo.pos.y : cellInfo.pos.x; if (IsOutRange(rangePos)) { SetPoolsObj(cellInfo.obj); m_ExpandInfos[k].cellInfos[i].obj = null; } else { if (cellInfo.obj == null) { GameObject cell = GetPoolsObj(); cell.transform.GetComponent <RectTransform>().anchoredPosition = cellInfo.pos; cell.name = k + "-" + i; Button cellButtonComponent = cell.GetComponent <Button>(); if (!m_IsAddedListener.ContainsKey(cell) && cellButtonComponent != null) { m_IsAddedListener[cell] = true; cellButtonComponent.onClick.AddListener(delegate() { OnClickCell(cell); }); } cellInfo.obj = cell; m_ExpandInfos[k].cellInfos[i] = cellInfo; Func(m_FuncCallBackFunc, expandInfo.button, cell, expandInfo.isExpand); } } } } }
public void ChangeSource(string fileName, string text) { // save expand if (treeView1.Nodes.Count > 0 && !String.IsNullOrEmpty(FileName)) { var savedInfo = new ExpandInfo(treeView1.Nodes, FileName, SourceId); SaveExpandInfo(savedInfo); } treeView1.Nodes.Clear(); var document = XDocument.Parse(text); var sourceElem = document.Root.Element("Source"); var sourceId = sourceElem.Attribute("ID").Value; SourceId = int.Parse(sourceId); FileName = fileName; var sourceNode = new TreeNode(String.Format("Source(ID:{0})", sourceId)); treeView1.Nodes.Add(sourceNode); foreach (var elm in sourceElem.Elements("Property")) { ParseProperty(sourceNode, elm); } sourceNode.Expand(); var scopeElem = document.Root.Element("Scope"); var scopeNode = new TreeNode(String.Format("Scope(ID:{0})", scopeElem.Attribute("ID").Value)); treeView1.Nodes.Add(scopeNode); foreach (var elm in scopeElem.Elements("Property")) { ParseProperty(scopeNode, elm); } scopeNode.Expand(); var expandInfo = GetExpandInfo(FileName, SourceId); if (expandInfo != null) { expandInfo.Restore(treeView1.Nodes); } }
//展开时候的背景图 private void ExpandBackground(ExpandInfo expandInfo) { //收展时的 list尺寸变化 if (expandInfo.isExpand == false) { var background = expandInfo.button.transform.Find("background"); if (background != null) { RectTransform backgroundTransform = background.GetComponent <RectTransform>(); backgroundTransform.sizeDelta = m_BackgroundOriginSize; } } else { var background = expandInfo.button.transform.Find("background"); if (background != null) { RectTransform backgroundTransform = background.GetComponent <RectTransform>(); float total_h = expandInfo.size; if (m_Direction == e_Direction.Vertical) { if (total_h > 3) { backgroundTransform.sizeDelta = new Vector2(m_BackgroundOriginSize.x, m_BackgroundOriginSize.y + total_h + m_BackgroundMargin); } else { backgroundTransform.sizeDelta = new Vector2(m_BackgroundOriginSize.x, m_BackgroundOriginSize.y); } } else { backgroundTransform.sizeDelta = new Vector2(m_BackgroundOriginSize.x + total_h + m_BackgroundMargin, m_BackgroundOriginSize.y); } } } }
private void RestoreExpandInfo(ExpandInfo expandInfo) { expandInfo.Restore(treeView1.Nodes); }
public override void ShowList(string numStr) { ClearCell(); //清除所有Cell (非首次调Showlist时执行) int totalCount = 0; int beforeCellCount = 0; string[] numArray = numStr.Split('|'); int buttonCount = numArray.Length; bool isReset; if (m_IsInited && m_ExpandInfos.Length == buttonCount) { isReset = false; } else { m_ExpandInfos = new ExpandInfo[buttonCount]; isReset = true; } for (int k = 0; k < buttonCount; k++) { //-> Button 物体处理 GameObject button = GetPoolsButtonObj(); button.name = k.ToString(); Button buttonComponent = button.GetComponent <Button>(); if (!m_IsAddedListener.ContainsKey(button) && buttonComponent != null) { m_IsAddedListener[button] = true; buttonComponent.onClick.AddListener(delegate() { OnClickExpand(button); }); button.transform.SetSiblingIndex(0); } float pos = 0; //坐标( isVertical ? 记录Y : 记录X ) //-> 计算 Button 坐标 if (m_Direction == e_Direction.Vertical) { pos = m_ExpandButtonHeight * k + m_Spacing * (k + 1); pos += k > 0 ? (m_CellObjectHeight + m_Spacing) * Mathf.CeilToInt((float)beforeCellCount / m_Row) : 0; button.transform.GetComponent <RectTransform>().anchoredPosition = new Vector3(m_ExpandButtonX, -pos, 0); } else { pos = m_ExpandButtonWidth * k + m_Spacing * (k + 1); pos += k > 0 ? (m_CellObjectWidth + m_Spacing) * Mathf.CeilToInt((float)beforeCellCount / m_Row) : 0; button.transform.GetComponent <RectTransform>().anchoredPosition = new Vector3(pos, m_ExpandButtonY, 0); } int count = int.Parse(numArray[k]); totalCount += count; //-> 存储数据 ExpandInfo expandInfo = isReset ? new ExpandInfo() : m_ExpandInfos[k]; expandInfo.button = button; expandInfo.cellCount = count; expandInfo.cellInfos = new CellInfo[count]; expandInfo.isExpand = isReset ? m_IsExpand : expandInfo.isExpand; expandInfo.size = m_Direction == e_Direction.Vertical ? (m_CellObjectHeight + m_Spacing) * Mathf.CeilToInt((float)count / m_Row) : (m_CellObjectWidth + m_Spacing) * Mathf.CeilToInt((float)count / m_Row); //计算 需展开的尺寸 //-> 遍历每个按钮下的 Cell for (int i = 0; i < count; i++) { if (!expandInfo.isExpand) { break; } CellInfo cellInfo = new CellInfo(); float rowPos = 0; //计算每排里面的cell 坐标 //-> 计算Cell坐标 if (m_Direction == e_Direction.Vertical) { pos = m_CellObjectHeight * Mathf.FloorToInt(i / m_Row) + m_Spacing * (Mathf.FloorToInt(i / m_Row) + 1); pos += (m_ExpandButtonHeight + m_Spacing) * (k + 1); pos += (m_CellObjectHeight + m_Spacing) * Mathf.CeilToInt((float)beforeCellCount / m_Row); rowPos = m_CellObjectWidth * (i % m_Row) + m_Spacing * (i % m_Row); cellInfo.pos = new Vector3(rowPos, -pos, 0); } else { pos = m_CellObjectWidth * Mathf.FloorToInt(i / m_Row) + m_Spacing * (Mathf.FloorToInt(i / m_Row) + 1); pos += (m_ExpandButtonWidth + m_Spacing) * (k + 1); pos += (m_CellObjectHeight + m_Spacing) * Mathf.CeilToInt((float)beforeCellCount / m_Row); rowPos = m_CellObjectHeight * (i % m_Row) + m_Spacing * (i % m_Row); cellInfo.pos = new Vector3(pos, -rowPos, 0); } //-> 计算是否超出范围 float cellPos = m_Direction == e_Direction.Vertical ? cellInfo.pos.y : cellInfo.pos.x; if (IsOutRange(cellPos)) { cellInfo.obj = null; expandInfo.cellInfos[i] = cellInfo; continue; } //-> 取或创建 Cell GameObject cell = GetPoolsObj(); cell.transform.GetComponent <RectTransform>().anchoredPosition = cellInfo.pos; cell.gameObject.name = k + "-" + i.ToString(); Button cellButtonComponent = cell.GetComponent <Button>(); if (!m_IsAddedListener.ContainsKey(cell) && cellButtonComponent != null) { m_IsAddedListener[cell] = true; cellButtonComponent.onClick.AddListener(delegate() { OnClickCell(cell); }); } //-> 存数据 cellInfo.obj = cell; expandInfo.cellInfos[i] = cellInfo; //-> 回调 函数 Func(m_FuncCallBackFunc, button, cell, expandInfo.isExpand); } beforeCellCount += expandInfo.isExpand ? count : 0; m_ExpandInfos[k] = expandInfo; Func(m_FuncCallBackFunc, button, null, expandInfo.isExpand); } if (!m_IsInited) { //-> 计算 Content 尺寸 if (m_Direction == e_Direction.Vertical) { float contentSize = m_IsExpand ? (m_Spacing + m_CellObjectHeight) * Mathf.CeilToInt((float)totalCount / m_Row) : 0; contentSize += (m_Spacing + m_ExpandButtonHeight) * buttonCount; m_ContentRectTrans.sizeDelta = new Vector2(m_ContentRectTrans.sizeDelta.x, contentSize); } else { float contentSize = m_IsExpand ? (m_Spacing + m_CellObjectWidth) * Mathf.CeilToInt((float)totalCount / m_Row) : 0; contentSize += (m_Spacing + m_ExpandButtonWidth) * buttonCount; m_ContentRectTrans.sizeDelta = new Vector2(contentSize, m_ContentRectTrans.sizeDelta.y); } } m_IsInited = true; }
public override void OnClickExpand(int index) { index = index - 1; m_ExpandInfos[index].isExpand = !m_ExpandInfos[index].isExpand; //-> 计算 Contant Size Vector2 size = m_ContentRectTrans.sizeDelta; if (m_Direction == e_Direction.Vertical) { float height = m_ExpandInfos[index].isExpand ? size.y + m_ExpandInfos[index].size : size.y - m_ExpandInfos[index].size; m_ContentRectTrans.sizeDelta = new Vector2(size.x, height); } else { float width = m_ExpandInfos[index].isExpand ? size.x + m_ExpandInfos[index].size : size.x - m_ExpandInfos[index].size; m_ContentRectTrans.sizeDelta = new Vector2(width, size.y); } int beforeCellCount = 0; float pos = 0; float rowPos = 0; //-> 重新计算坐标 并 显示处理 for (int k = 0, length = m_ExpandInfos.Length; k < length; k++) { int count = m_ExpandInfos[k].cellCount; if (k >= index) { //-> 计算 按钮位置 GameObject button = m_ExpandInfos[k].button; if (m_Direction == e_Direction.Vertical) { pos = m_ExpandButtonHeight * k + m_Spacing * (k + 1); pos += (m_CellObjectHeight + m_Spacing) * Mathf.CeilToInt((float)beforeCellCount / m_Row); button.transform.GetComponent <RectTransform>().anchoredPosition = new Vector3(m_ExpandButtonX, -pos, 0); } else { pos = m_ExpandButtonWidth * k + m_Spacing * (k + 1); pos += (m_CellObjectWidth + m_Spacing) * Mathf.CeilToInt((float)beforeCellCount / m_Row); button.transform.GetComponent <RectTransform>().anchoredPosition = new Vector3(pos, m_ExpandButtonY, 0); } ExpandInfo expandInfo = m_ExpandInfos[k]; for (int i = 0; i < count; i++) { //-> 按钮 收 状态时 if (!expandInfo.isExpand) { if (expandInfo.cellInfos[i].obj != null) { SetPoolsObj(expandInfo.cellInfos[i].obj); m_ExpandInfos[k].cellInfos[i].obj = null; } continue; } CellInfo cellInfo = expandInfo.cellInfos[i]; // * -> 计算每个Cell坐标 if (m_Direction == e_Direction.Vertical) { pos = m_CellObjectHeight * Mathf.FloorToInt(i / m_Row) + m_Spacing * (Mathf.FloorToInt(i / m_Row) + 1); pos += (m_ExpandButtonHeight + m_Spacing) * (k + 1); pos += (m_CellObjectHeight + m_Spacing) * Mathf.CeilToInt((float)beforeCellCount / m_Row); rowPos = m_CellObjectWidth * (i % m_Row) + m_Spacing * (i % m_Row); cellInfo.pos = new Vector3(rowPos, -pos, 0); } else { pos = m_CellObjectWidth * Mathf.FloorToInt(i / m_Row) + m_Spacing * (Mathf.FloorToInt(i / m_Row) + 1); pos += (m_ExpandButtonWidth + m_Spacing) * (k + 1); pos += (m_CellObjectWidth + m_Spacing) * Mathf.CeilToInt((float)beforeCellCount / m_Row); rowPos = m_CellObjectHeight * (i % m_Row) + m_Spacing * (i % m_Row); cellInfo.pos = new Vector3(pos, -rowPos, 0); } //-> 计算是否超出范围 float cellPos = m_Direction == e_Direction.Vertical ? cellInfo.pos.y : cellInfo.pos.x; if (IsOutRange(cellPos)) { SetPoolsObj(cellInfo.obj); cellInfo.obj = null; m_ExpandInfos[k].cellInfos[i] = cellInfo; continue; } GameObject cell = cellInfo.obj != null ? cellInfo.obj : GetPoolsObj(); cell.transform.GetComponent <RectTransform>().anchoredPosition = cellInfo.pos; cell.gameObject.name = k + "-" + i.ToString(); //-> 回调 if (cellInfo.obj == null) { Func(m_FuncCallBackFunc, button, cell, expandInfo.isExpand); } //-> 添加按钮事件 Button cellButtonComponent = cell.GetComponent <Button>(); if (!m_IsAddedListener.ContainsKey(cell) && cellButtonComponent != null) { m_IsAddedListener[cell] = true; cellButtonComponent.onClick.AddListener(delegate() { OnClickCell(cell); }); } //-> 存数据 cellInfo.obj = cell; m_ExpandInfos[k].cellInfos[i] = cellInfo; } } if (m_ExpandInfos[k].isExpand) { beforeCellCount += count; } } //展开时候的背景图 ExpandBackground(m_ExpandInfos[index]); Func(m_FuncCallBackFunc, m_ExpandInfos[index].button, null, m_ExpandInfos[index].isExpand); }
public StripViewItemExpandStrategy(StripViewLayoutInfo info) { this.layoutInfo = info; this.expandInfo = new ExpandInfo(); }