public int Show(Rect rect, IList <GUIContent> listContent, int maxAvailableHeight, out int height, string caption = null, int offset = 0) { if (listStyle == null || listStyleUiTheme != AccountManager.Instance.Settings.uiThemeName) { listStyle = GUI.skin.customStyles[0]; listStyleUiTheme = AccountManager.Instance.Settings.uiThemeName; Color backgroundColor; if (AccountManager.Instance.Settings.uiThemeName == UiThemes.Phantasia.ToString()) { if (!ColorUtility.TryParseHtmlString("#00508c", out backgroundColor)) { backgroundColor = new Color(0, 0, 0, 1); } } else { backgroundColor = new Color(0, 0, 0, 1); } var normalTex = ResourceManager.TextureFromColor(backgroundColor); var hoverTex = ResourceManager.TextureFromColor(Color.white); listStyle.normal.textColor = Color.white; listStyle.normal.background = normalTex; listStyle.onHover.background = listStyle.hover.background = hoverTex; listStyle.padding.left = listStyle.padding.right = listStyle.padding.top = listStyle.padding.bottom = WalletGUI.Units(1); } if (forceToUnShow) { forceToUnShow = false; isClickedComboButton = false; } bool done = false; int controlID = GUIUtility.GetControlID(FocusType.Passive); var buttonContent = caption == null ? listContent[selectedItemIndex] : new GUIContent(caption); if (GUI.Button(rect, buttonContent, buttonStyle)) { if (isClickedComboButton) { done = true; } if (useControlID == -1) { useControlID = controlID; isClickedComboButton = false; } if (useControlID != controlID) { forceToUnShow = true; useControlID = controlID; } isClickedComboButton = true; } height = WalletGUI.Units(2); if (isClickedComboButton) { height += WalletGUI.Units(2) * (listContent.Count - offset); if (maxAvailableHeight > 0) { height = Math.Min(maxAvailableHeight, height); } var insideRect = new Rect(0, 0, rect.width, WalletGUI.Units(2) * (listContent.Count - offset)); var outsideRect = new Rect(rect.x, rect.y + WalletGUI.Units(2), rect.width, height); bool needsScroll = insideRect.height > outsideRect.height; if (needsScroll) { insideRect.width -= WalletGUI.Units(1); } Rect listRect = new Rect(rect.x, rect.y + WalletGUI.Units(2), rect.width, height); if (needsScroll) { ListScroll = GUI.BeginScrollView(outsideRect, ListScroll, insideRect); listRect = insideRect; } int newSelectedItemIndex = GUI.SelectionGrid(listRect, selectedItemIndex - offset, listContent.Skip(offset).ToArray(), 1, listStyle) + offset; if (newSelectedItemIndex != selectedItemIndex) { selectedItemIndex = newSelectedItemIndex; done = true; } if (needsScroll) { GUI.EndScrollView(); } height += WalletGUI.Units(2); } if (done) { isClickedComboButton = false; } return(selectedItemIndex); }
public int Show(Rect rect, IList <GUIContent> listContent, int maxAvailableHeight, out int height, string caption = null, int offset = 0) { if (listStyle == null) { listStyle = GUI.skin.customStyles[0]; var normalTex = ResourceManager.TextureFromColor(new Color(0, 0, 0, 1)); var hoverTex = ResourceManager.TextureFromColor(Color.white); listStyle.normal.textColor = Color.white; listStyle.normal.background = normalTex; listStyle.onHover.background = listStyle.hover.background = hoverTex; listStyle.padding.left = listStyle.padding.right = listStyle.padding.top = listStyle.padding.bottom = WalletGUI.Units(1); } if (forceToUnShow) { forceToUnShow = false; isClickedComboButton = false; } bool done = false; int controlID = GUIUtility.GetControlID(FocusType.Passive); switch (Event.current.GetTypeForControl(controlID)) { case EventType.MouseUp: { if (isClickedComboButton) { done = true; } } break; } var buttonContent = caption == null ? listContent[selectedItemIndex] : new GUIContent(caption); if (GUI.Button(rect, buttonContent, buttonStyle)) { if (useControlID == -1) { useControlID = controlID; isClickedComboButton = false; } if (useControlID != controlID) { forceToUnShow = true; useControlID = controlID; } isClickedComboButton = true; } height = WalletGUI.Units(2); if (isClickedComboButton) { height += WalletGUI.Units(2) * (listContent.Count - offset); if (maxAvailableHeight > 0) { height = Math.Min(maxAvailableHeight, height); } var insideRect = new Rect(0, 0, rect.width, WalletGUI.Units(2) * (listContent.Count - offset)); var outsideRect = new Rect(rect.x, rect.y + WalletGUI.Units(2), rect.width, height); bool needsScroll = insideRect.height > outsideRect.height; if (needsScroll) { insideRect.width -= WalletGUI.Units(1); } Rect listRect = new Rect(rect.x, rect.y + WalletGUI.Units(2), rect.width, height); if (needsScroll) { ListScroll = GUI.BeginScrollView(outsideRect, ListScroll, insideRect); listRect = insideRect; } int newSelectedItemIndex = GUI.SelectionGrid(listRect, selectedItemIndex - offset, listContent.Skip(offset).ToArray(), 1, listStyle) + offset; if (newSelectedItemIndex != selectedItemIndex) { selectedItemIndex = newSelectedItemIndex; } if (needsScroll) { GUI.EndScrollView(); } height += WalletGUI.Units(2); } if (done) { isClickedComboButton = false; } return(selectedItemIndex); }