From 722530a1140376ad601cad5fdb08df2b787671f0 Mon Sep 17 00:00:00 2001 From: Ethan Moffat Date: Tue, 5 Apr 2022 18:07:09 -0700 Subject: [PATCH] Update ScrollingListDialog to support more buttons/sizes. Preparation for supporting smaller scrolling list dialog size. --- EndlessClient/Dialogs/ScrollingListDialog.cs | 132 +++++++++++++++---- 1 file changed, 104 insertions(+), 28 deletions(-) diff --git a/EndlessClient/Dialogs/ScrollingListDialog.cs b/EndlessClient/Dialogs/ScrollingListDialog.cs index 3fbf7e08a..e9a1a8afa 100644 --- a/EndlessClient/Dialogs/ScrollingListDialog.cs +++ b/EndlessClient/Dialogs/ScrollingListDialog.cs @@ -10,17 +10,32 @@ namespace EndlessClient.Dialogs { + [Flags] public enum ScrollingListDialogButtons { - AddCancel, - Cancel, - BackCancel, + Add = 1, + Cancel = 2, + Back = 4, + Next = 8, + Ok = 16, + DualButtons = 32, + // todo: if enum values are ever added to this, the logic in ScrollingListDialog.Buttons needs to be updated + AddCancel = DualButtons | Add | Cancel, + BackCancel = DualButtons | Back | Cancel, + BackOk = DualButtons | Back | Ok, + CancelOk = DualButtons | Cancel | Ok, + BackNext = DualButtons | Back | Next, + CancelNext = DualButtons | Cancel | Next, } - public class ScrollingListDialog : BaseEODialog + public enum ScrollingListDialogSize { - private static readonly Vector2 _cancelButtonRightPosition, _cancelButtonCenteredPosition; + LargeDialog, + SmallDialog, + } + public class ScrollingListDialog : BaseEODialog + { private readonly List _listItems; protected readonly ScrollBar _scrollBar; @@ -28,6 +43,9 @@ public class ScrollingListDialog : BaseEODialog private ListDialogItem.ListItemStyle _listItemType; protected readonly XNAButton _add, _back, _cancel; + protected readonly XNAButton _next, _ok; + + protected readonly Vector2 _button1Position, _button2Position, _buttonCenterPosition; private ScrollingListDialogButtons _buttons; @@ -61,48 +79,82 @@ public ScrollingListDialogButtons Buttons set { _buttons = value; - _add.Visible = Buttons == ScrollingListDialogButtons.AddCancel; - _back.Visible = Buttons == ScrollingListDialogButtons.BackCancel; - _cancel.DrawPosition = Buttons == ScrollingListDialogButtons.Cancel - ? _cancelButtonCenteredPosition - : _cancelButtonRightPosition; + _add.Visible = Buttons.HasFlag(ScrollingListDialogButtons.Add); + _back.Visible = Buttons.HasFlag(ScrollingListDialogButtons.Back); + _next.Visible = Buttons.HasFlag(ScrollingListDialogButtons.Next); + _ok.Visible = Buttons.HasFlag(ScrollingListDialogButtons.Ok); + _cancel.Visible = Buttons.HasFlag(ScrollingListDialogButtons.Cancel); + + if (Buttons.HasFlag(ScrollingListDialogButtons.DualButtons)) + { + if (Buttons == ScrollingListDialogButtons.BackCancel || + Buttons == ScrollingListDialogButtons.AddCancel) + { + _add.DrawPosition = _button1Position; + _back.DrawPosition = _button1Position; + _cancel.DrawPosition = _button2Position; + } + else + { + _back.DrawPosition = _button1Position; + _cancel.DrawPosition = _button1Position; + + _next.DrawPosition = _button2Position; + _ok.DrawPosition = _button2Position; + } + } + else + { + _add.DrawPosition = _buttonCenterPosition; + _back.DrawPosition = _buttonCenterPosition; + _next.DrawPosition = _buttonCenterPosition; + _ok.DrawPosition = _buttonCenterPosition; + _cancel.DrawPosition = _buttonCenterPosition; + } } } public INativeGraphicsManager GraphicsManager { get; } + public ScrollingListDialogSize DialogSize { get; } + public event EventHandler AddAction; public event EventHandler BackAction; - public bool ChildControlClickHandled { get; set; } + public event EventHandler NextAction; - static ScrollingListDialog() - { - _cancelButtonRightPosition = new Vector2(144, 252); - _cancelButtonCenteredPosition = new Vector2(96, 252); - } + public bool ChildControlClickHandled { get; set; } public ScrollingListDialog(INativeGraphicsManager nativeGraphicsManager, - IEODialogButtonService dialogButtonService) + IEODialogButtonService dialogButtonService, + ScrollingListDialogSize dialogSize = ScrollingListDialogSize.LargeDialog) : base(isInGame: true) { + GraphicsManager = nativeGraphicsManager; + DialogSize = dialogSize; + + var isLargeDialog = DialogSize == ScrollingListDialogSize.LargeDialog; + _listItems = new List(); _titleText = new XNALabel(Constants.FontSize09) { - DrawArea = new Rectangle(16, 13, 253, 19), + DrawArea = new Rectangle(16, 13, 253, 19), // todo: might need to use (16, 16, 255, 18) for SmallDialog AutoSize = false, TextAlign = LabelAlignment.MiddleLeft, ForeColor = ColorConstants.LightGrayText }; _titleText.SetParentControl(this); - _scrollBar = new ScrollBar(new Vector2(252, 44), new Vector2(16, 199), ScrollBarColors.LightOnMed, nativeGraphicsManager); + _scrollBar = new ScrollBar(new Vector2(252, 44), new Vector2(16, isLargeDialog ? 199 : 99), ScrollBarColors.LightOnMed, GraphicsManager); _scrollBar.SetParentControl(this); - _add = new XNAButton(dialogButtonService.SmallButtonSheet, - new Vector2(48, 252), + BackgroundTexture = GraphicsManager.TextureFromResource(GFXTypes.PostLoginUI, isLargeDialog ? 52 : 67); + + var yCoord = isLargeDialog ? 252 : 152; + + _add = new XNAButton(dialogButtonService.SmallButtonSheet, Vector2.Zero, dialogButtonService.GetSmallDialogButtonOutSource(SmallButton.Add), dialogButtonService.GetSmallDialogButtonOverSource(SmallButton.Add)) { @@ -113,8 +165,7 @@ public ScrollingListDialog(INativeGraphicsManager nativeGraphicsManager, _add.OnClick += (o, e) => AddAction?.Invoke(o, e); AddAction += (_, _) => _otherClicked = true; - _back = new XNAButton(dialogButtonService.SmallButtonSheet, - new Vector2(48, 252), + _back = new XNAButton(dialogButtonService.SmallButtonSheet, Vector2.Zero, dialogButtonService.GetSmallDialogButtonOutSource(SmallButton.Back), dialogButtonService.GetSmallDialogButtonOverSource(SmallButton.Back)) { @@ -125,12 +176,32 @@ public ScrollingListDialog(INativeGraphicsManager nativeGraphicsManager, _back.OnClick += (o, e) => BackAction?.Invoke(o, e); BackAction += (_, _) => _otherClicked = true; - _cancel = new XNAButton(dialogButtonService.SmallButtonSheet, - _cancelButtonRightPosition, + _next = new XNAButton(dialogButtonService.SmallButtonSheet, Vector2.Zero, + dialogButtonService.GetSmallDialogButtonOutSource(SmallButton.Next), + dialogButtonService.GetSmallDialogButtonOverSource(SmallButton.Next)) + { + Visible = false, + UpdateOrder = 1, + }; + _next.SetParentControl(this); + _next.OnClick += (o, e) => NextAction?.Invoke(o, e); + NextAction += (_, _) => _otherClicked = true; + + _ok = new XNAButton(dialogButtonService.SmallButtonSheet, Vector2.Zero, + dialogButtonService.GetSmallDialogButtonOutSource(SmallButton.Ok), + dialogButtonService.GetSmallDialogButtonOverSource(SmallButton.Ok)) + { + Visible = false, + UpdateOrder = 2, + }; + _ok.SetParentControl(this); + _ok.OnClick += (_, _) => { if (!_otherClicked) { Close(XNADialogResult.OK); } }; + + _cancel = new XNAButton(dialogButtonService.SmallButtonSheet, Vector2.Zero, dialogButtonService.GetSmallDialogButtonOutSource(SmallButton.Cancel), dialogButtonService.GetSmallDialogButtonOverSource(SmallButton.Cancel)) { - Visible = true, + Visible = false, UpdateOrder = 2, }; _cancel.SetParentControl(this); @@ -138,11 +209,14 @@ public ScrollingListDialog(INativeGraphicsManager nativeGraphicsManager, ItemsToShow = ListItemType == ListDialogItem.ListItemStyle.Large ? 5 : 12; - BackgroundTexture = nativeGraphicsManager.TextureFromResource(GFXTypes.PostLoginUI, 52); + _button1Position = new Vector2(isLargeDialog ? 48 : 89, yCoord); + _button2Position = new Vector2(isLargeDialog ? 144 : 183, yCoord); + _buttonCenterPosition = new Vector2(96, yCoord); + + Buttons = ScrollingListDialogButtons.AddCancel; CenterInGameView(); DrawPosition = new Vector2(DrawPosition.X, 15); - GraphicsManager = nativeGraphicsManager; } public void SetItemList(List itemList) @@ -213,6 +287,8 @@ public override void Initialize() { _add.Initialize(); _back.Initialize(); + _next.Initialize(); + _ok.Initialize(); _cancel.Initialize(); _scrollBar.Initialize(); _titleText.Initialize();