public PDialog(string name) { Body = new PPanel("Body") { Alignment = TextAnchor.UpperCenter, FlexSize = Vector2.one }; buttons = new List <DialogButton>(4); Name = name ?? "Dialog"; Parent = FrontEndManager.Instance.gameObject; Size = Vector2.zero; SortKey = 0.0f; Title = "Dialog"; }
public PDialog(string name) { Body = new PPanel("Body") { Alignment = TextAnchor.UpperCenter, FlexSize = Vector2.one, Margin = new RectOffset(6, 6, 6, 6) }; DialogBackColor = PUITuning.Colors.ButtonBlueStyle.inactiveColor; buttons = new List <DialogButton>(4); Name = name ?? "Dialog"; Parent = FrontEndManager.Instance.gameObject; Size = Vector2.zero; SortKey = 0.0f; Title = "Dialog"; }
public PDialog(string name) { Body = new PPanel("Body") { Alignment = TextAnchor.UpperCenter, FlexSize = Vector2.one, Margin = new RectOffset(6, 6, 6, 6) }; DialogBackColor = PUITuning.Colors.ButtonBlueStyle.inactiveColor; buttons = new List <DialogButton>(4); MaxSize = Vector2.zero; Name = name ?? "Dialog"; // First try the front end manager (menu), then the in-game (game) Parent = GetParentObject(); RoundToNearestEven = false; Size = Vector2.zero; SortKey = 0.0f; Title = "Dialog"; }
/// <summary> /// Creates the user buttons. /// </summary> /// <param name="layout">The location to add the buttons.</param> /// <param name="onPressed">The handler to call when any button is pressed.</param> private void CreateUserButtons(PGridLayoutGroup layout, PUIDelegates.OnButtonPressed onPressed) { var buttonPanel = new PPanel("Buttons") { Alignment = TextAnchor.LowerCenter, Spacing = 7, Direction = PanelDirection. Horizontal, Margin = new RectOffset(5, 5, 0, 10) }; int i = 0; // Add each user button foreach (var button in buttons) { string key = button.key; var bgColor = button.backColor; var fgColor = button.textColor ?? PUITuning.Fonts.UILightStyle; var db = new PButton(key) { Text = button.text, ToolTip = button.tooltip, Margin = BUTTON_MARGIN, OnClick = onPressed, Color = bgColor, TextStyle = fgColor }; // Last button is special and gets a pink color if (bgColor == null) { if (++i >= buttons.Count) { db.SetKleiPinkStyle(); } else { db.SetKleiBlueStyle(); } } buttonPanel.AddChild(db); } layout.AddComponent(buttonPanel.Build(), new GridComponentSpec(2, 0) { ColumnSpan = 2 }); }
public GameObject Build() { var flexW = new Vector2(1.0f, 0.0f); if (Parent == null) { throw new InvalidOperationException("Parent for dialog may not be null"); } var dialog = PUIElements.CreateUI(null, Name); var dComponent = dialog.AddComponent <PDialogComp>(); int i = 0; PUIElements.SetParent(dialog, Parent); // Background dialog.AddComponent <Image>().color = PUITuning.Colors.DialogBackground; dialog.AddComponent <Canvas>(); new PPanel("Header") { // Horizontal title bar Spacing = 3, Direction = PanelDirection.Horizontal, FlexSize = flexW }.SetKleiPinkColor().AddChild(new PLabel("Title") { // Title text, expand to width Text = Title, FlexSize = flexW, DynamicSize = true }).AddChild(new PButton(DIALOG_KEY_CLOSE) { // Close button Sprite = PUITuning.Images.Close, Margin = new RectOffset(3, 3, 3, 3), SpriteSize = new Vector2f(16.0f, 16.0f), OnClick = dComponent.DoButton }.SetKleiBlueStyle()).AddTo(dialog); // Buttons var buttonPanel = new PPanel("Buttons") { Alignment = TextAnchor.LowerCenter, Spacing = 5, Direction = PanelDirection. Horizontal, Margin = new RectOffset(5, 5, 5, 5) }; // Add each user button foreach (var button in buttons) { string key = button.key; var db = new PButton(key) { Text = button.text, ToolTip = button.tooltip, Margin = BUTTON_MARGIN, OnClick = dComponent.DoButton }; // Last button is special and gets a pink color if (++i >= buttons.Count) { db.SetKleiPinkStyle(); } else { db.SetKleiBlueStyle(); } buttonPanel.AddChild(db); } // Body, make it fill the flexible space new PPanel("BodyAndButtons") { Alignment = TextAnchor.MiddleCenter, Spacing = 5, Direction = PanelDirection. Vertical, Margin = new RectOffset(10, 10, 10, 5), FlexSize = Vector2.one, BackColor = DialogBackColor }.AddChild(Body).AddChild(buttonPanel).AddTo(dialog); // Lay out components vertically BoxLayoutGroup.LayoutNow(dialog, new BoxLayoutParams() { Alignment = TextAnchor.UpperCenter, Margin = new RectOffset(1, 1, 1, 1), Spacing = 1.0f, Direction = PanelDirection.Vertical }, Size); dialog.AddComponent <GraphicRaycaster>(); dComponent.dialog = this; dComponent.sortKey = SortKey; OnRealize?.Invoke(dialog); return(dialog); }