protected GUIComponent CreateInfoFrame(string text, bool hasButton = false) { int width = 300; int height = hasButton ? 110 : 80; string wrappedText = ToolBox.WrapText(text, width, GUI.Font); height += wrappedText.Split('\n').Length * 25; var infoBlock = new GUIFrame(new RectTransform(new Point(width, height), GUI.Canvas, Anchor.TopRight) { AbsoluteOffset = new Point(20) }); infoBlock.Flash(Color.Green); var textBlock = new GUITextBlock(new RectTransform(new Vector2(0.9f, 0.7f), infoBlock.RectTransform, Anchor.Center), text, wrap: true); if (hasButton) { var okButton = new GUIButton(new RectTransform(new Point(80, 25), infoBlock.RectTransform, Anchor.BottomCenter) { AbsoluteOffset = new Point(0, 5) }, TextManager.Get("OK")) { OnClicked = CloseInfoFrame }; } GUI.PlayUISound(GUISoundType.Message); return(infoBlock); }
protected GUIComponent CreateInfoFrame(string text, bool hasButton = false) { int width = 300; int height = hasButton ? 110 : 80; string wrappedText = ToolBox.WrapText(text, width, GUI.Font); height += wrappedText.Split('\n').Length * 25; var infoBlock = new GUIFrame(new Rectangle(-20, 20, width, height), null, Alignment.TopRight, ""); //infoBlock.Color = infoBlock.Color * 0.8f; infoBlock.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f); infoBlock.Flash(Color.Green); var textBlock = new GUITextBlock(new Rectangle(10, 10, width - 40, height), text, "", infoBlock, true); if (hasButton) { var okButton = new GUIButton(new Rectangle(0, -40, 80, 25), "OK", Alignment.BottomCenter, "", textBlock); okButton.OnClicked = CloseInfoFrame; } GUI.PlayUISound(GUISoundType.Message); return(infoBlock); }
protected GUIComponent CreateInfoFrame(string title, string text, int width, int height, string anchorStr, bool hasButton = false, Action callback = null) { if (hasButton) { height += 30; } string wrappedText = ToolBox.WrapText(text, width, GUI.Font); height += wrappedText.Split('\n').Length * 25; if (title.Length > 0) { height += 35; } Anchor anchor = Anchor.TopRight; Enum.TryParse(anchorStr, out anchor); var infoBlock = new GUIFrame(new RectTransform(new Point((int)(width * GUI.Scale), (int)(height * GUI.Scale)), GUI.Canvas, anchor) { AbsoluteOffset = new Point(20) }); infoBlock.Flash(Color.Green); if (title.Length > 0) { var titleBlock = new GUITextBlock(new RectTransform(new Vector2(1f, .35f), infoBlock.RectTransform, Anchor.TopCenter, Pivot.TopCenter), title, font: GUI.VideoTitleFont, textAlignment: Alignment.Center, textColor: new Color(253, 174, 0)); titleBlock.TextScale = GUI.Scale; } var textBlock = new GUITextBlock(new RectTransform(new Vector2(0.9f, 1f), infoBlock.RectTransform, Anchor.BottomCenter), text, wrap: true); textBlock.TextScale = GUI.Scale; infoBoxClosedCallback = callback; if (hasButton) { var okButton = new GUIButton(new RectTransform(new Point(160, 50), infoBlock.RectTransform, Anchor.BottomCenter, Pivot.TopCenter) { AbsoluteOffset = new Point(0, -10) }, TextManager.Get("OK")) { OnClicked = CloseInfoFrame }; } GUI.PlayUISound(GUISoundType.UIMessage); return(infoBlock); }
protected GUIComponent CreateInfoFrame(string title, string text, int width = 300, int height = 80, string anchorStr = "", bool hasButton = false, Action callback = null, Action showVideo = null) { if (hasButton) { height += 60; } string wrappedText = ToolBox.WrapText(text, width, GUI.Font); height += (int)(GUI.Font.MeasureString(wrappedText).Y + 50); if (title.Length > 0) { height += 35; } Anchor anchor = Anchor.TopRight; if (anchorStr != string.Empty) { Enum.TryParse(anchorStr, out anchor); } var background = new GUIFrame(new RectTransform(new Point(GameMain.GraphicsWidth, GameMain.GraphicsHeight), GUI.Canvas, Anchor.Center), "InnerFrame", new Color(0, 0, 0, 1f)); var infoBlock = new GUIFrame(new RectTransform(new Point((int)(width * GUI.Scale), (int)(height * GUI.Scale)), background.RectTransform, anchor) { AbsoluteOffset = new Point(20) }); infoBlock.Flash(Color.Green); var infoContent = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.8f), infoBlock.RectTransform, Anchor.Center)) { Stretch = true, AbsoluteSpacing = 5 }; if (title.Length > 0) { var titleBlock = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), infoContent.RectTransform), title, font: GUI.VideoTitleFont, textAlignment: Alignment.Center, textColor: new Color(253, 174, 0)); titleBlock.RectTransform.IsFixedSize = true; } var textBlock = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), infoContent.RectTransform), " " + text, wrap: true); textBlock.RectTransform.IsFixedSize = true; infoBoxClosedCallback = callback; if (hasButton) { var buttonContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.3f), infoContent.RectTransform) { MinSize = new Point(0, 30), MaxSize = new Point((int)infoContent.Rect.X, 60) }, isHorizontal: true) { Stretch = true, RelativeSpacing = 0.1f }; buttonContainer.RectTransform.IsFixedSize = true; if (showVideo != null) { var videoButton = new GUIButton(new RectTransform(new Vector2(0.4f, 1.0f), buttonContainer.RectTransform), TextManager.Get("Video"), style: "GUIButtonLarge") { OnClicked = (GUIButton button, object obj) => { showVideo(); return(true); } }; } var okButton = new GUIButton(new RectTransform(new Vector2(0.6f, 1.0f), buttonContainer.RectTransform), TextManager.Get("OK"), style: "GUIButtonLarge") { OnClicked = CloseInfoFrame }; } infoBlock.RectTransform.NonScaledSize = new Point(infoBlock.Rect.Width, (int)(infoContent.Children.Sum(c => c.Rect.Height + infoContent.AbsoluteSpacing) / infoContent.RectTransform.RelativeSize.Y)); GUI.PlayUISound(GUISoundType.UIMessage); return(background); }
protected GUIComponent CreateInfoFrame(string title, string text, int width = 300, int height = 80, string anchorStr = "", bool hasButton = false, Action callback = null, Action showVideo = null) { if (hasButton) { height += 60; } Anchor anchor = Anchor.TopRight; if (anchorStr != string.Empty) { Enum.TryParse(anchorStr, out anchor); } width = (int)(width * GUI.Scale); height = (int)(height * GUI.Scale); string wrappedText = ToolBox.WrapText(text, width, GUI.Font); height += (int)GUI.Font.MeasureString(wrappedText).Y; if (title.Length > 0) { height += (int)GUI.Font.MeasureString(title).Y + (int)(150 * GUI.Scale); } var background = new GUIFrame(new RectTransform(new Point(GameMain.GraphicsWidth, GameMain.GraphicsHeight), GUI.Canvas, Anchor.Center), style: null, Color.Black * 0.5f); var infoBlock = new GUIFrame(new RectTransform(new Point(width, height), background.RectTransform, anchor)); infoBlock.Flash(GUI.Style.Green); var infoContent = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.9f), infoBlock.RectTransform, Anchor.Center)) { Stretch = true, AbsoluteSpacing = 5 }; if (title.Length > 0) { var titleBlock = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), infoContent.RectTransform), title, font: GUI.LargeFont, textAlignment: Alignment.Center, textColor: new Color(253, 174, 0)); titleBlock.RectTransform.IsFixedSize = true; } List <RichTextData> richTextData = RichTextData.GetRichTextData(text, out text); GUITextBlock textBlock; if (richTextData == null) { textBlock = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), infoContent.RectTransform), " " + text, wrap: true); } else { textBlock = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), infoContent.RectTransform), richTextData, " " + text, wrap: true); } textBlock.RectTransform.IsFixedSize = true; infoBoxClosedCallback = callback; if (hasButton) { var buttonContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.15f), infoContent.RectTransform), isHorizontal: true) { RelativeSpacing = 0.1f }; buttonContainer.RectTransform.IsFixedSize = true; if (showVideo != null) { buttonContainer.Stretch = true; var videoButton = new GUIButton(new RectTransform(new Vector2(0.4f, 1.0f), buttonContainer.RectTransform), TextManager.Get("Video"), style: "GUIButtonLarge") { OnClicked = (GUIButton button, object obj) => { showVideo(); return(true); } }; } else { buttonContainer.Stretch = false; buttonContainer.ChildAnchor = Anchor.Center; } var okButton = new GUIButton(new RectTransform(new Vector2(0.4f, 1.0f), buttonContainer.RectTransform), TextManager.Get("OK"), style: "GUIButtonLarge") { OnClicked = CloseInfoFrame }; } infoBlock.RectTransform.NonScaledSize = new Point(infoBlock.Rect.Width, (int)(infoContent.Children.Sum(c => c.Rect.Height + infoContent.AbsoluteSpacing) / infoContent.RectTransform.RelativeSize.Y)); GUI.PlayUISound(GUISoundType.UIMessage); return(background); }