public virtual float DrawItem() { Event eventCurrent = Event.current; switch (ContentType) { case GUI_Item_Type.NORMALBUTTON: case GUI_Item_Type.TOGGLEBUTTON: case GUI_Item_Type.TAB: if (GUI.Button(DrawingRect, Content, GUI_style.GetGuiStyle(this))) { return(eventCurrent.button); } break; case GUI_Item_Type.LABEL: case GUI_Item_Type.GROUPLABEL: GUI.Label(DrawingRect, Content.text, GUI_style.GetGuiStyle(this)); break; case GUI_Item_Type.TEXTFIELD: GUI.TextField(DrawingRect, Content.text, GUI_style.GetGuiStyle(this)); break; } return(-1); }
/// <summary> /// Draws the window. /// Call only inside 'GUIBase.OnGUI'! /// </summary> public void DrawWindow() { // Drawing is disabled when window is not enabled. if (!Enabled) { return; } // Disable drawing when ingame menu is active because the GUI crashing! if (IngameMenu.main != null && IngameMenu.main.isActiveAndEnabled) { return; } // If window is minimized draw the title box only. if (showWindow) { WindowRect.height = _windowrectOriginal.height; } else { WindowRect.height = _titleHeight; } // Initializing and setting the new GUI Skin. GUI.skin = GUI_style.GetSkin(); // Make a popup window. WindowRect = GUI.Window(ID, WindowRect, DoWindow, ""); if (showToolTipWindow && toolTipTimer > 0) { GUIStyle guiStyle = GUI_style.GetGuiStyle(GUI_Item_Type.TEXTAREA, GUI_Color.Green, align: TextAnchor.UpperLeft, wordWrap: true); Vector2 toolTipSize = guiStyle.CalcSize(ToolTip); toolTipRect.width = toolTipSize.x < 200 ? toolTipSize.x : 200; if (WindowRect.x < Screen.width / 2) { toolTipRect.x = WindowRect.x + WindowRect.width + 2; } else { toolTipRect.x = WindowRect.x - (toolTipRect.width + 2); } toolTipRect.y = Event.current.mousePosition.y; toolTipRect.height = guiStyle.CalcHeight(ToolTip, toolTipRect.width); GUI.Label(toolTipRect, ToolTip.text, guiStyle); } }
public override void DrawGroup() { if (_groupLabel != string.Empty) { GUI.Label(_groupLabelRect, _groupLabel, GUI_style.GetGuiStyle(GUI_Item_Type.LABEL, align: TextAnchor.MiddleLeft, colorNormal: GUI_Color.White)); } scrollPos = GUI.BeginScrollView(_drawRect, scrollPos, _clientRect); base.DrawGroup(); GUI.EndScrollView(); }
public override float DrawItem() { GUI.Box(DrawingRect, string.Empty); if (Content.text != "") { if (labelSize == Vector2.zero) { labelSize = GUI_style.GetGuiStyle(GUI_Item_Type.LABEL).CalcSize(Content); _labelRect.x = DrawingRect.x + 5; _labelRect.y = DrawingRect.y; _labelRect.width = labelSize.x; _labelRect.height = DrawingRect.height; } GUI.Label(_labelRect, Content, GUI_style.GetGuiStyle(GUI_Item_Type.LABEL, align: TextAnchor.MiddleLeft)); } if (valueSize == Vector2.zero) { valueSize = GUI_style.GetGuiStyle(GUI_Item_Type.LABEL).CalcSize(maxValueText); _valueRect.x = _labelRect.x + _labelRect.width + 5; _valueRect.y = DrawingRect.y; _valueRect.width = valueSize.x; _valueRect.height = DrawingRect.height; Debug.Log($"_valueRect: {_valueRect}"); _sliderRect.x = _valueRect.x + _valueRect.width + 5; _sliderRect.y = DrawingRect.y + (_labelRect.height - 19) / 2; _sliderRect.width = DrawingRect.width - _sliderRect.x; _sliderRect.height = DrawingRect.height; } GUI.Label(_valueRect, string.Format(decimals, _sliderContent.SliderValue), GUI_style.GetGuiStyle(GUI_Item_Type.LABEL, colorNormal: GUI_Color.Green, align: TextAnchor.MiddleLeft)); float value = GUI.HorizontalSlider(_sliderRect, _sliderContent.SliderValue, _sliderContent.LeftValue, _sliderContent.RightValue); if (value != _sliderContent.SliderValue) { _sliderContent.SliderValue = value; return(value); } return(-1); }
/// <summary> /// Internal method to draw and control the window base. /// </summary> private void DoWindow(int id) { // Drawing the title box. GUI.Box(_titleRect, "", GUI_style.GetGuiStyle(GUI_Item_Type.TITLEBOX)); // Drawing the title text. GUI.Label(_labelRect, TitleText, GUI_style.GetGuiStyle(GUI_Item_Type.TITLETEXT, align: TextAnchor.MiddleLeft)); // Drawing the system time in title box if need. if (_HasTimeInTitle) { GUI.Label(_timeRect, DateTime.Now.ToString("HH:mm:ss"), GUI_style.GetGuiStyle(GUI_Item_Type.TITLETEXT, align: TextAnchor.MiddleCenter)); } // Drawing the minimize button if need. if (_hasMinimizeButton) { if (GUI.Button(_minimizeButtonRect, showWindow ? "\u2582" : "\u25A0", GUI_style.GetGuiStyle(GUI_Item_Type.TITLEBUTTON, align: TextAnchor.UpperCenter))) { showWindow = !showWindow; if (!showToolTipWindow) { ToolTip.text = ""; } } } // Drawing the close button if need. if (_hasCloseButton) { if (GUI.Button(_closeButtonRect, "\u03A7", GUI_style.GetGuiStyle(GUI_Item_Type.TITLEBUTTON, align: TextAnchor.MiddleCenter))) { Enabled = false; CloseHandler(ID); } } if (showWindow) { // Showing tooltips if enabled. if (_hasToolTipButton) { if (GUI.Button(_toolTipButtonRect, "?", GUI_style.GetGuiStyle(GUI_Item_Type.TITLEBUTTON, align: TextAnchor.MiddleCenter, colorNormal: showToolTipWindow ? GUI_Color.Green : GUI_Color.White))) { showToolTipWindow = !showToolTipWindow; if (!showToolTipWindow) { ToolTip.text = ""; } } } // Calling base window control function. ControlHandler(ID); } // Calling Unity DragWindow function if window moveable. // Moving enabled only by grab the title bar rectangle. if (_hasMoveable) { GUI.DragWindow(_titleRect); } if (showToolTipWindow) { #if DEBUGMOUSE ToolTip.text = $"Mouse position (x: {Event.current.mousePosition.x}, y: {Event.current.mousePosition.y})"; #else if (GUI.tooltip != "") { ToolTip.text = GUI.tooltip; toolTipTimer = 0.2f; } if (toolTipTimer > 0) { toolTipTimer -= Time.deltaTime; } else { ToolTip.text = ""; } #endif } }
/// <summary> /// Draws the group. /// Call only from 'GUI_window.WindowControl' /// </summary> public virtual void DrawGroup() { if (isRefresh) { return; } if (_group.groupType != GUI_Group_type.Scroll && _groupLabel != string.Empty) { GUI.Label(_groupLabelRect, _groupLabel, GUI_style.GetGuiStyle(GUI_Item_Type.LABEL, align: TextAnchor.MiddleLeft, colorNormal: GUI_Color.White)); } for (int i = 0; i < _guiItems.Count; ++i) { if (!_guiItems[i].Enabled) { continue; } float result = _guiItems[i].DrawItem(); switch (_guiItems[i].ContentType) { case GUI_Item_Type.NORMALBUTTON: if (result != -1) { _eventHandler(new GUI_event(windowID, groupID, _guiItems[i], (int)result)); } break; case GUI_Item_Type.TOGGLEBUTTON: if (result != -1) { if (result == 0) { _guiItems[i].InvertState(); } _eventHandler(new GUI_event(windowID, groupID, _guiItems[i], (int)result)); } break; case GUI_Item_Type.TAB: if (result != -1) { if (result == 0) { SetTABState(_guiItems[i].ID); } _eventHandler(new GUI_event(windowID, groupID, _guiItems[i], (int)result)); } break; case GUI_Item_Type.HORIZONTALSLIDER: if (result != -1) { _eventHandler(new GUI_event(windowID, groupID, _guiItems[i], result)); } break; } } }