Skip to content

Commit

Permalink
Update ScrollingListDialog to support more buttons/sizes. Preparation…
Browse files Browse the repository at this point in the history
… for supporting smaller scrolling list dialog size.
  • Loading branch information
ethanmoffat committed Apr 6, 2022
1 parent 6397611 commit 722530a
Showing 1 changed file with 104 additions and 28 deletions.
132 changes: 104 additions & 28 deletions EndlessClient/Dialogs/ScrollingListDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,42 @@

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<ListDialogItem> _listItems;
protected readonly ScrollBar _scrollBar;

protected readonly IXNALabel _titleText;
private ListDialogItem.ListItemStyle _listItemType;

protected readonly XNAButton _add, _back, _cancel;
protected readonly XNAButton _next, _ok;

protected readonly Vector2 _button1Position, _button2Position, _buttonCenterPosition;

private ScrollingListDialogButtons _buttons;

Expand Down Expand Up @@ -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<ListDialogItem>();

_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))
{
Expand All @@ -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))
{
Expand All @@ -125,24 +176,47 @@ 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);
_cancel.OnClick += (_, _) => { if (!_otherClicked) { Close(XNADialogResult.Cancel); } };

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<ListDialogItem> itemList)
Expand Down Expand Up @@ -213,6 +287,8 @@ public override void Initialize()
{
_add.Initialize();
_back.Initialize();
_next.Initialize();
_ok.Initialize();
_cancel.Initialize();
_scrollBar.Initialize();
_titleText.Initialize();
Expand Down

0 comments on commit 722530a

Please sign in to comment.