private void DrawSubstringNotLeftAligned() { TextAnchor originalAlignment = GuiStyle.alignment; GuiStyle.alignment = GetLeftAlignedVersion(GuiStyle.alignment); float lineHeight = GuiStyle.CalcSize(new GUIContent(text)).y; float y = rect.y; int start = 0; int charsLeft = substringLength; while (charsLeft > 0) { string line = GetNextLine(text, start); string subLine = line.Substring(0, Mathf.Min(line.Length, charsLeft)); start += line.Length; charsLeft -= line.Length; float lineWidth = GuiStyle.CalcSize(new GUIContent(line.Trim())).x; float x = IsCenterAligned(originalAlignment) ? Mathf.Ceil(rect.x + (0.5f * rect.width) - (0.5f * lineWidth)) + 0.5f : rect.x + rect.width - lineWidth; UnityGUITools.DrawText(new Rect(x, y, rect.width, lineHeight), GetRichTextClosedText(subLine.Trim()), GuiStyle, textStyle, textStyleColor); y += GuiStyle.lineHeight; } GuiStyle.alignment = originalAlignment; }
/// <summary> /// Makes sure the guiStyle property is up-to-date. /// </summary> protected void SetGUIStyle() { if (guiStyle == null) { guiStyle = UnityGUITools.GetGUIStyle(guiStyleName, DefaultGUIStyle); } }
private void DrawQuests() { if ((quests != null) && (scrollView != null)) { float contentY = padding; foreach (string quest in quests) { float headingHeight = QuestHeadingHeight(quest); if (GUI.Button(new Rect(padding, contentY, scrollView.contentWidth - (2 * padding), headingHeight), QuestHeading(quest), questHeadingStyle)) { openQuest = string.Equals(quest, openQuest) ? null : quest; } contentY += headingHeight; if (string.Equals(quest, openQuest)) { contentY = DrawQuestDescription(quest, contentY); contentY = DrawQuestEntries(quest, contentY); } } if (quests.Length == 0) { string description = (questStateToShow == QuestState.Active) ? noActiveQuestsMessage : noCompletedQuestsMessage; GUIStyle noQuestsStyle = UnityGUITools.GetGUIStyle(noQuestsGuiStyleName, GUI.skin.label); float descriptionHeight = noQuestsStyle.CalcHeight(new GUIContent(description), scrollView.contentWidth - 4); GUI.Label(new Rect(2, contentY, scrollView.contentWidth, descriptionHeight), description, noQuestsStyle); contentY += descriptionHeight; } } }
private void DrawQuests() { if ((scrollView != null)) { float contentY = padding; foreach (var questInfo in Quests) { bool isSelectedQuest = IsSelectedQuest(questInfo); float headingHeight = QuestHeadingHeight(questInfo); if (GUI.Button(new Rect(padding, contentY, scrollView.contentWidth - (2 * padding), headingHeight), questInfo.Heading.text, GetQuestHeadingStyle(isSelectedQuest))) { ClickQuest(questInfo.Title); } contentY += headingHeight; if (isSelectedQuest) { contentY = DrawQuestDescription(questInfo, contentY); contentY = DrawQuestEntries(questInfo, contentY); contentY = DrawQuestButtons(questInfo, contentY); } } if (Quests.Length == 0) { GUIStyle noQuestsStyle = UnityGUITools.GetGUIStyle(noQuestsGuiStyleName, GUI.skin.label); float descriptionHeight = noQuestsStyle.CalcHeight(new GUIContent(NoQuestsMessage), scrollView.contentWidth - 4); GUI.Label(new Rect(2, contentY, scrollView.contentWidth, descriptionHeight), NoQuestsMessage, noQuestsStyle); contentY += descriptionHeight; } } }
public void ApplyAlphaToGUIColor() { if (HasAlpha) { originalGUIColor = GUI.color; GUI.color = UnityGUITools.ColorWithAlpha(GUI.color, Alpha); } }
/// <summary> /// Applies the formatting recorded in formattingToApply by SetFormattedText(). /// SetFormattedText() can't apply the formatting directly because it needs to /// run in OnGUI. /// </summary> protected void ApplyFormatting() { SetGUIStyle(); if (!(isFormattingApplied || (formattingToApply == null))) { text = formattingToApply.text; guiStyle = UnityGUITools.ApplyFormatting(formattingToApply, guiStyle); isFormattingApplied = true; } }
private void DrawSubstring() { if (IsLeftAligned(GuiStyle.alignment)) { UnityGUITools.DrawText(rect, GetRichTextClosedText(text.Substring(0, substringLength)), GuiStyle, textStyle, textStyleColor); } else { DrawSubstringNotLeftAligned(); } }
private void DrawQuests() { if ((scrollView != null)) { float contentY = padding; string currentGroup = null; var isCurrentGroupCollapsed = false; foreach (var questInfo in quests) { // Check for new group: if (!string.Equals(questInfo.Group, currentGroup)) { currentGroup = questInfo.Group; if (!string.IsNullOrEmpty(currentGroup)) { isCurrentGroupCollapsed = collapsedGroups.Contains(currentGroup); var groupHeadingHeight = GroupHeadingHeight(currentGroup); //---Was: GUI.Label(new Rect(padding, contentY, scrollView.contentWidth - (2 * padding), groupHeadingHeight), currentGroup, GetGroupHeadingStyle()); if (GUI.Button(new Rect(padding, contentY, scrollView.contentWidth - (2 * padding), groupHeadingHeight), currentGroup, GetGroupHeadingStyle())) { ClickQuestGroup(currentGroup); } contentY += groupHeadingHeight; } } // Draw quest: if (!isCurrentGroupCollapsed) { bool isSelectedQuest = IsSelectedQuest(questInfo); float headingHeight = QuestHeadingHeight(questInfo); if (GUI.Button(new Rect(padding, contentY, scrollView.contentWidth - (2 * padding), headingHeight), questInfo.Heading.text, GetQuestHeadingStyle(isSelectedQuest))) { ClickQuest(questInfo.Title); } contentY += headingHeight; if (isSelectedQuest) { contentY = DrawQuestDescription(questInfo, contentY); contentY = DrawQuestEntries(questInfo, contentY); contentY = DrawQuestButtons(questInfo, contentY); } } } if (quests.Length == 0) { GUIStyle noQuestsStyle = UnityGUITools.GetGUIStyle(noQuestsGuiStyleName, GUI.skin.label); float descriptionHeight = noQuestsStyle.CalcHeight(new GUIContent(noQuestsMessage), scrollView.contentWidth - 4); GUI.Label(new Rect(2, contentY, scrollView.contentWidth, descriptionHeight), noQuestsMessage, noQuestsStyle); contentY += descriptionHeight; } } }
/// <summary> /// Draws the control, but not its children. /// </summary> /// <param name="relativeMousePosition">Relative mouse position within the window containing this control.</param> public override void DrawSelf(Vector2 relativeMousePosition) { ApplyAlphaToGUIColor(); if (image != null) { DrawImage(); } if (!string.IsNullOrEmpty(text)) { if (useSubstring) { DrawSubstring(); } else { UnityGUITools.DrawText(rect, text, GuiStyle, textStyle, textStyleColor); } } RestoreGUIColor(); }
/// <summary> /// Draws the bark text using Unity GUI. /// </summary> public virtual void OnGUI() { GUI.skin = UnityGUITools.GetValidGUISkin(guiSkin); if (guiStyle == null) { guiStyle = UnityGUITools.ApplyFormatting(formattingToApply, new GUIStyle(UnityGUITools.GetGUIStyle(guiStyleName, GUI.skin.label))); guiStyle.alignment = TextAnchor.UpperCenter; size = guiStyle.CalcSize(new GUIContent(message)); if ((maxWidth >= 1) && (size.x > maxWidth)) { size = new Vector2(maxWidth, guiStyle.CalcHeight(new GUIContent(message), maxWidth)); } } UpdateBarkPosition(); guiStyle.normal.textColor = UnityGUITools.ColorWithAlpha(guiStyle.normal.textColor, alpha); if (screenPos.z < 0) { return; } Rect rect = new Rect(screenPos.x - (size.x / 2), (Screen.height - screenPos.y) - (size.y / 2), size.x, size.y); UnityGUITools.DrawText(rect, message, guiStyle, textStyle, textStyleColor); }
private void DrawSubstringLeftAligned() { var currText = string.Empty; int start = 0; int charsLeft = substringLength; while (charsLeft > 0) { string line = GetNextLine(text, start); string subLine = line.Substring(0, Mathf.Min(line.Length, charsLeft)); start += line.Length; charsLeft -= line.Length; if (string.IsNullOrEmpty(currText)) { currText = subLine; } else { currText += "\n" + subLine; } } UnityGUITools.DrawText(rect, GetRichTextClosedText(currText), GuiStyle, textStyle, textStyleColor); }
private GUIStyle UseGUIStyle(GUIStyle guiStyle, string guiStyleName, GUIStyle defaultStyle) { return((guiStyle != null) ? guiStyle : UnityGUITools.GetGUIStyle(guiStyleName, defaultStyle)); }