Skip to content

Commit

Permalink
Add more sizes to ScrollingListDialog (preparation for quest history/…
Browse files Browse the repository at this point in the history
…progress).

Update to XNAControls 1.4 and set dialog background source area as needed
  • Loading branch information
ethanmoffat committed Apr 7, 2022
1 parent 02583ae commit bf61e2d
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 50 deletions.
23 changes: 4 additions & 19 deletions EndlessClient/Dialogs/PaperdollDialog.cs
Expand Up @@ -40,7 +40,6 @@ public class PaperdollDialog : BaseEODialog
private readonly IStatusLabelSetter _statusLabelSetter;
private readonly bool _isMainCharacter;
private readonly Texture2D _characterIconSheet;
private readonly Texture2D _background;
private Option<Rectangle> _characterIconSourceRect;
private readonly InventoryPanel _inventoryPanel;

Expand Down Expand Up @@ -87,12 +86,8 @@ public class PaperdollDialog : BaseEODialog

_childItems = new List<PaperdollDialogItem>();

_background = _nativeGraphicsManager.TextureFromResource(GFXTypes.PostLoginUI, 49);
SetSize(_background.Width, _background.Height / 2);

// this needs to be set for CenterInGameView to work properly
// todo: fix
BackgroundTexture = new Texture2D(GraphicsDevice, DrawArea.Width, DrawArea.Height);
BackgroundTexture = _nativeGraphicsManager.TextureFromResource(GFXTypes.PostLoginUI, 49);
BackgroundTextureSource = new Rectangle(0, BackgroundTexture.Height / 2 * Character.RenderProperties.Gender, DrawArea.Width, BackgroundTexture.Height / 2);

var okButton = new XNAButton(eoDialogButtonService.SmallButtonSheet,
new Vector2(276, 253),
Expand Down Expand Up @@ -161,9 +156,9 @@ protected override void OnUpdateControl(GameTime gameTime)

protected override void OnDrawControl(GameTime gameTime)
{
_spriteBatch.Begin();
base.OnDrawControl(gameTime);

_spriteBatch.Draw(_background, DrawAreaWithParentOffset, new Rectangle(0, DrawArea.Height * Character.RenderProperties.Gender, DrawArea.Width, DrawArea.Height), Color.White);
_spriteBatch.Begin();

_characterIconSourceRect.MatchSome(sourceRect =>
{
Expand All @@ -176,16 +171,6 @@ protected override void OnDrawControl(GameTime gameTime)
});

_spriteBatch.End();

base.OnDrawControl(gameTime);
}

protected override void Dispose(bool disposing)
{
if (disposing)
BackgroundTexture.Dispose();

base.Dispose(disposing);
}

private void UpdateDisplayedData(IPaperdollData paperdollData)
Expand Down
2 changes: 1 addition & 1 deletion EndlessClient/Dialogs/QuestDialog.cs
Expand Up @@ -30,7 +30,7 @@ public class QuestDialog : ScrollingListDialog
IQuestDataProvider questDataProvider,
IENFFileProvider enfFileProvider,
IContentProvider contentProvider)
: base(nativeGraphicsManager, dialogButtonService, dialogSize: ScrollingListDialogSize.SmallDialog)
: base(nativeGraphicsManager, dialogButtonService, dialogSize: ScrollingListDialogSize.Small)
{
_questActions = questActions;
_questDataProvider = questDataProvider;
Expand Down
170 changes: 141 additions & 29 deletions EndlessClient/Dialogs/ScrollingListDialog.cs
Expand Up @@ -3,6 +3,7 @@
using EOLib;
using EOLib.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -13,25 +14,32 @@ namespace EndlessClient.Dialogs
[Flags]
public enum ScrollingListDialogButtons
{
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,
None = 0x00,
Add = 0x01,
Cancel = 0x02,
Back = 0x04,
Next = 0x08,
Ok = 0x10,
History = 0x20,
Progress = 0x40,
DualButtons = 0x80,

AddCancel = DualButtons | Add | Cancel,
BackCancel = DualButtons | Back | Cancel,
BackOk = DualButtons | Back | Ok,
CancelOk = DualButtons | Cancel | Ok,
BackNext = DualButtons | Back | Next,
CancelNext = DualButtons | Cancel | Next,
HistoryOk = DualButtons | History | Ok,
ProgressOk = DualButtons | Progress | Ok,
}

public enum ScrollingListDialogSize
{
LargeDialog,
SmallDialog,
Large, // standard dialog with large list items (chest, locker, shop)
Medium, // quest progress/history dialog
MediumWithHeader, // todo: implement boards
Small, // npc quest dialog
}

public class ScrollingListDialog : BaseEODialog
Expand All @@ -44,6 +52,7 @@ public class ScrollingListDialog : BaseEODialog

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

protected readonly Vector2 _button1Position, _button2Position, _buttonCenterPosition;

Expand All @@ -67,11 +76,11 @@ public ListDialogItem.ListItemStyle ListItemType
get => _listItemType;
set
{
if (value == ListDialogItem.ListItemStyle.Large && DialogSize == ScrollingListDialogSize.SmallDialog)
if (value == ListDialogItem.ListItemStyle.Large && DialogSize == ScrollingListDialogSize.Small)
throw new InvalidOperationException("Can't use large ListDialogItem with small scrolling dialog");

_listItemType = value;
ItemsToShow = _listItemType == ListDialogItem.ListItemStyle.Large ? 5 : DialogSize == ScrollingListDialogSize.SmallDialog ? 6 : 12;
ItemsToShow = _listItemType == ListDialogItem.ListItemStyle.Large ? 5 : DialogSize == ScrollingListDialogSize.Small ? 6 : 12;
_scrollBar.LinesToRender = ItemsToShow;
}
}
Expand All @@ -87,6 +96,8 @@ public ScrollingListDialogButtons Buttons
_next.Visible = Buttons.HasFlag(ScrollingListDialogButtons.Next);
_ok.Visible = Buttons.HasFlag(ScrollingListDialogButtons.Ok);
_cancel.Visible = Buttons.HasFlag(ScrollingListDialogButtons.Cancel);
_history.Visible = Buttons.HasFlag(ScrollingListDialogButtons.History);
_progress.Visible = Buttons.HasFlag(ScrollingListDialogButtons.Progress);

if (Buttons.HasFlag(ScrollingListDialogButtons.DualButtons))
{
Expand All @@ -101,6 +112,8 @@ public ScrollingListDialogButtons Buttons
{
_back.DrawPosition = _button1Position;
_cancel.DrawPosition = _button1Position;
_history.DrawPosition = _button1Position;
_progress.DrawPosition = _button1Position;

_next.DrawPosition = _button2Position;
_ok.DrawPosition = _button2Position;
Expand All @@ -127,35 +140,40 @@ public ScrollingListDialogButtons Buttons

public event EventHandler NextAction;

public event EventHandler HistoryAction;

public event EventHandler ProgressAction;

public bool ChildControlClickHandled { get; set; }

public ScrollingListDialog(INativeGraphicsManager nativeGraphicsManager,
IEODialogButtonService dialogButtonService,
ScrollingListDialogSize dialogSize = ScrollingListDialogSize.LargeDialog)
ScrollingListDialogSize dialogSize = ScrollingListDialogSize.Large)
: base(isInGame: true)
{
// todo: implement boards
if (dialogSize == ScrollingListDialogSize.MediumWithHeader)
throw new NotImplementedException();

GraphicsManager = nativeGraphicsManager;
DialogSize = dialogSize;

var isLargeDialog = DialogSize == ScrollingListDialogSize.LargeDialog;

_listItems = new List<ListDialogItem>();

_titleText = new XNALabel(Constants.FontSize09)
{
DrawArea = isLargeDialog ? new Rectangle(16, 13, 253, 19) : new Rectangle(16, 16, 255, 18),
DrawArea = GetTitleDrawArea(DialogSize),
AutoSize = false,
TextAlign = LabelAlignment.MiddleLeft,
ForeColor = ColorConstants.LightGrayText
};
_titleText.SetParentControl(this);

_scrollBar = new ScrollBar(new Vector2(252, 44), new Vector2(16, isLargeDialog ? 199 : 99), ScrollBarColors.LightOnMed, GraphicsManager);
_scrollBar = new ScrollBar(new Vector2(DialogSize == ScrollingListDialogSize.Medium ? 449 : 252, 44), new Vector2(16, GetScrollBarHeight(DialogSize)), ScrollBarColors.LightOnMed, GraphicsManager);
_scrollBar.SetParentControl(this);

BackgroundTexture = GraphicsManager.TextureFromResource(GFXTypes.PostLoginUI, isLargeDialog ? 52 : 67);

var yCoord = isLargeDialog ? 252 : 152;
BackgroundTexture = GraphicsManager.TextureFromResource(GFXTypes.PostLoginUI, GetBackgroundTexture(DialogSize));
BackgroundTextureSource = GetBackgroundSourceRectangle(BackgroundTexture, DialogSize);

_add = new XNAButton(dialogButtonService.SmallButtonSheet, Vector2.Zero,
dialogButtonService.GetSmallDialogButtonOutSource(SmallButton.Add),
Expand Down Expand Up @@ -190,6 +208,28 @@ public ScrollingListDialogButtons Buttons
_next.OnClick += (o, e) => NextAction?.Invoke(o, e);
NextAction += (_, _) => _otherClicked = true;

_history = new XNAButton(dialogButtonService.SmallButtonSheet, Vector2.Zero,
dialogButtonService.GetSmallDialogButtonOutSource(SmallButton.History),
dialogButtonService.GetSmallDialogButtonOverSource(SmallButton.History))
{
Visible = false,
UpdateOrder = 1,
};
_history.SetParentControl(this);
_history.OnClick += (o, e) => HistoryAction?.Invoke(o, e);
HistoryAction += (_, _) => _otherClicked = true;

_progress = new XNAButton(dialogButtonService.SmallButtonSheet, Vector2.Zero,
dialogButtonService.GetSmallDialogButtonOutSource(SmallButton.Progress),
dialogButtonService.GetSmallDialogButtonOverSource(SmallButton.Progress))
{
Visible = false,
UpdateOrder = 1,
};
_progress.SetParentControl(this);
_progress.OnClick += (o, e) => ProgressAction?.Invoke(o, e);
ProgressAction += (_, _) => _otherClicked = true;

_ok = new XNAButton(dialogButtonService.SmallButtonSheet, Vector2.Zero,
dialogButtonService.GetSmallDialogButtonOutSource(SmallButton.Ok),
dialogButtonService.GetSmallDialogButtonOverSource(SmallButton.Ok))
Expand All @@ -210,11 +250,11 @@ public ScrollingListDialogButtons Buttons
_cancel.SetParentControl(this);
_cancel.OnClick += (_, _) => { if (!_otherClicked) { Close(XNADialogResult.Cancel); } };

ItemsToShow = ListItemType == ListDialogItem.ListItemStyle.Large ? 5 : DialogSize == ScrollingListDialogSize.SmallDialog ? 6 : 12;
ItemsToShow = ListItemType == ListDialogItem.ListItemStyle.Large ? 5 : DialogSize == ScrollingListDialogSize.Small ? 6 : 12;

_button1Position = new Vector2(isLargeDialog ? 48 : 89, yCoord);
_button2Position = new Vector2(isLargeDialog ? 144 : 183, yCoord);
_buttonCenterPosition = new Vector2(96, yCoord);
_button1Position = GetButton1Position(DialogSize);
_button2Position = GetButton2Position(DialogSize);
_buttonCenterPosition = GetButtonCenterPosition(DrawArea, _ok.DrawArea, DialogSize);

Buttons = ScrollingListDialogButtons.AddCancel;

Expand Down Expand Up @@ -334,5 +374,77 @@ protected override void OnUpdateControl(GameTime gameTime)

_otherClicked = false;
}

private static Rectangle GetTitleDrawArea(ScrollingListDialogSize size)
{
switch(size)
{
case ScrollingListDialogSize.Large: return new Rectangle(16, 13, 253, 19);
case ScrollingListDialogSize.Medium: return new Rectangle(18, 14, 452, 19);
case ScrollingListDialogSize.Small: return new Rectangle(16, 16, 255, 18);
default: throw new NotImplementedException();
}
}

private static int GetScrollBarHeight(ScrollingListDialogSize size)
{
switch (size)
{
case ScrollingListDialogSize.Large:
case ScrollingListDialogSize.Medium: return 199;
case ScrollingListDialogSize.Small: return 99;
default: throw new NotImplementedException();
}
}

private static int GetBackgroundTexture(ScrollingListDialogSize size)
{
switch (size)
{
case ScrollingListDialogSize.Large: return 52;
case ScrollingListDialogSize.Medium: return 59;
case ScrollingListDialogSize.Small: return 67;
default: throw new NotImplementedException();
}
}

private static Rectangle? GetBackgroundSourceRectangle(Texture2D backgroundTexture, ScrollingListDialogSize size)
{
switch (size)
{
case ScrollingListDialogSize.Large: return null;
case ScrollingListDialogSize.Medium: return new Rectangle(0, 0, backgroundTexture.Width, backgroundTexture.Height / 2);
case ScrollingListDialogSize.Small: return null;
default: throw new NotImplementedException();
}
}

private static Vector2 GetButton1Position(ScrollingListDialogSize size)
{
switch (size)
{
case ScrollingListDialogSize.Large: return new Vector2(48, 252);
case ScrollingListDialogSize.Medium: return new Vector2(288, 252);
case ScrollingListDialogSize.Small: return new Vector2(89, 152);
default: throw new NotImplementedException();
}
}

private static Vector2 GetButton2Position(ScrollingListDialogSize size)
{
switch (size)
{
case ScrollingListDialogSize.Large: return new Vector2(144, 252);
case ScrollingListDialogSize.Medium: return new Vector2(380, 252);
case ScrollingListDialogSize.Small: return new Vector2(183, 152);
default: throw new NotImplementedException();
}
}

private static Vector2 GetButtonCenterPosition(Rectangle dialogArea, Rectangle buttonArea, ScrollingListDialogSize size)
{
var yCoord = GetButton1Position(size).Y;
return new Vector2((dialogArea.Width - buttonArea.Width) / 2, yCoord);
}
}
}
2 changes: 1 addition & 1 deletion EndlessClient/EndlessClient.csproj
Expand Up @@ -60,6 +60,6 @@
<PackageReference Include="Monogame.Content.Builder.Task" Version="3.8.0.1641" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.0" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="6.0.0" />
<PackageReference Include="XNAControls" Version="1.3.5" />
<PackageReference Include="XNAControls" Version="1.4.0" />
</ItemGroup>
</Project>

0 comments on commit bf61e2d

Please sign in to comment.