Skip to content

Commit

Permalink
Use MouseDown events for click detection instead of MouseClick
Browse files Browse the repository at this point in the history
This more closely mirrors the behavior of the vanilla client and resolves issues with DoubleClick event detection causing Click events to not register
  • Loading branch information
ethanmoffat committed Nov 4, 2024
1 parent 18854ab commit 2fa374f
Show file tree
Hide file tree
Showing 46 changed files with 115 additions and 97 deletions.
15 changes: 9 additions & 6 deletions EOLib/Domain/Character/AttackValidationActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using EOLib.Domain.Extensions;
using EOLib.Domain.Map;
using EOLib.IO.Repositories;
using Optional;
using Optional.Collections;

namespace EOLib.Domain.Character
{
Expand Down Expand Up @@ -39,12 +41,13 @@ public AttackValidationError ValidateCharacterStateBeforeAttacking()

var rp = _characterProvider.MainCharacter.RenderProperties;

var isRangedWeapon = _eifFileProvider.EIFFile
.Where(x => x.Type == IO.ItemType.Weapon && x.SubType == IO.ItemSubType.Ranged)
.Any(x => x.DollGraphic == rp.WeaponGraphic);
var isArrows = _eifFileProvider.EIFFile
.Where(x => x.Type == IO.ItemType.Shield && x.SubType == IO.ItemSubType.Arrows)
.Any(x => x.DollGraphic == rp.ShieldGraphic);
var matchingWeapon = _eifFileProvider.EIFFile
.SingleOrNone(x => x.DollGraphic == rp.WeaponGraphic && x.Type == IO.ItemType.Weapon);
var matchingArrows = _eifFileProvider.EIFFile
.SingleOrNone(x => x.DollGraphic == rp.ShieldGraphic && x.Type == IO.ItemType.Shield);

var isRangedWeapon = matchingWeapon.Map(x => x.SubType == IO.ItemSubType.Ranged).ValueOr(false);
var isArrows = matchingArrows.Map(x => x.SubType == IO.ItemSubType.Arrows).ValueOr(false);

if (isRangedWeapon && (rp.ShieldGraphic == 0 || !isArrows))
return AttackValidationError.MissingArrows;
Expand Down
2 changes: 1 addition & 1 deletion EndlessClient/ControlSets/BackButtonControlSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private XNAButton GetBackButton()
DrawOrder = 100,
ClickArea = new Rectangle(4, 16, 16, 16)
};
button.OnClick += DoBackButtonClick;
button.OnMouseDown += DoBackButtonClick;

_clientWindowSizeRepository.GameWindowSizeChanged += (o, e) =>
{
Expand Down
4 changes: 2 additions & 2 deletions EndlessClient/ControlSets/CreateAccountControlSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private IXNAButton GetCreateAccountCancelButton()
new Vector2(481, 417),
new Rectangle(0, 40, 120, 40),
new Rectangle(120, 40, 120, 40));
button.OnClick += (o, e) => _mainButtonController.GoToInitialState();
button.OnMouseDown += (o, e) => _mainButtonController.GoToInitialState();
return button;
}

Expand All @@ -193,7 +193,7 @@ private IXNAPanel GetCreateAccountLabels()
protected override IXNAButton GetCreateButton()
{
var button = base.GetCreateButton();
button.OnClick += DoCreateAccount;
button.OnMouseDown += DoCreateAccount;
return button;
}

Expand Down
8 changes: 4 additions & 4 deletions EndlessClient/ControlSets/InitialControlSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,28 @@ public override IGameComponent FindComponentByControlIdentifier(GameControlIdent
private IXNAButton GetMainCreateAccountButton()
{
var button = MainButtonCreationHelper(GameControlIdentifier.InitialCreateAccount);
button.OnClick += (o, e) => AsyncMainButtonClick(_mainButtonController.ClickCreateAccount);
button.OnMouseDown += (o, e) => AsyncMainButtonClick(_mainButtonController.ClickCreateAccount);
return button;
}

private IXNAButton GetMainLoginButton()
{
var button = MainButtonCreationHelper(GameControlIdentifier.InitialLogin);
button.OnClick += (o, e) => AsyncMainButtonClick(_mainButtonController.ClickLogin);
button.OnMouseDown += (o, e) => AsyncMainButtonClick(_mainButtonController.ClickLogin);
return button;
}

private IXNAButton GetViewCreditsButton()
{
var button = MainButtonCreationHelper(GameControlIdentifier.InitialViewCredits);
button.OnClick += (o, e) => _mainButtonController.ClickViewCredits();
button.OnMouseDown += (o, e) => _mainButtonController.ClickViewCredits();
return button;
}

private IXNAButton GetExitButton()
{
var button = MainButtonCreationHelper(GameControlIdentifier.InitialExitGame);
button.OnClick += (o, e) => _mainButtonController.ClickExit();
button.OnMouseDown += (o, e) => _mainButtonController.ClickExit();
return button;
}

Expand Down
4 changes: 2 additions & 2 deletions EndlessClient/ControlSets/LoggedInControlSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ private IXNAButton GetPasswordButton()
new Vector2(454, 417),
new Rectangle(0, 120, 120, 40),
new Rectangle(120, 120, 120, 40));
button.OnClick += (o, e) => AsyncButtonAction(_accountController.ChangePassword);
button.OnMouseDown += (o, e) => AsyncButtonAction(_accountController.ChangePassword);
return button;
}

protected override IXNAButton GetCreateButton()
{
var button = base.GetCreateButton();
button.OnClick += (o, e) => AsyncButtonAction(_characterManagementController.CreateCharacter);
button.OnMouseDown += (o, e) => AsyncButtonAction(_characterManagementController.CreateCharacter);
return button;
}

Expand Down
4 changes: 2 additions & 2 deletions EndlessClient/ControlSets/LoginPromptControlSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private XNAButton GetLoginAccountButton()
{
DrawOrder = _personPicture.DrawOrder + 2
};
button.OnClick += DoLogin;
button.OnMouseDown += DoLogin;
return button;
}

Expand All @@ -165,7 +165,7 @@ private XNAButton GetLoginCancelButton()
{
DrawOrder = _personPicture.DrawOrder + 2
};
button.OnClick += (o, e) => _mainButtonController.GoToInitialState();
button.OnMouseDown += (o, e) => _mainButtonController.GoToInitialState();
return button;
}
}
Expand Down
2 changes: 1 addition & 1 deletion EndlessClient/Dialogs/Actions/InGameDialogActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ private void UseDefaultDialogSounds(ScrollingListDialog dialog)
UseDefaultDialogSounds((BaseEODialog)dialog);

foreach (var button in dialog.ChildControls.OfType<IXNAButton>())
button.OnClick += Handler;
button.OnMouseDown += Handler;

void Handler(object sender, EventArgs e) => _sfxPlayer.PlaySfx(SoundEffectID.DialogButtonClick);
}
Expand Down
2 changes: 1 addition & 1 deletion EndlessClient/Dialogs/BarberDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private void InitializeCharacterControl()
private void InitializeDialogItems(IEODialogButtonService dialogButtonService)
{
var cancel = CreateButton(dialogButtonService, new Vector2(215, 151), SmallButton.Cancel);
cancel.OnClick += (_, _) => Close(XNADialogResult.Cancel);
cancel.OnMouseDown += (_, _) => Close(XNADialogResult.Cancel);

_changeHairItem = new ListDialogItem(this, ListDialogItem.ListItemStyle.Large, 0)
{
Expand Down
4 changes: 2 additions & 2 deletions EndlessClient/Dialogs/BardDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public BardDialog(INativeGraphicsManager nativeGraphicsManager,
dialogButtonService.GetSmallDialogButtonOverSource(SmallButton.Cancel));
cancel.Initialize();
cancel.SetParentControl(this);
cancel.OnClick += (_, _) => Close(XNADialogResult.Cancel);
cancel.OnMouseDown += (_, _) => Close(XNADialogResult.Cancel);

CenterInGameView();

Expand All @@ -63,7 +63,7 @@ protected override void OnDrawControl(GameTime gameTime)
});
}

protected override bool HandleClick(IXNAControl control, MouseEventArgs eventArgs)
protected override bool HandleMouseDown(IXNAControl control, MouseEventArgs eventArgs)
{
if (eventArgs.Button == MouseButton.Left && _currentTick > 8)
{
Expand Down
4 changes: 2 additions & 2 deletions EndlessClient/Dialogs/BoardDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ public BoardDialog(INativeGraphicsManager nativeGraphicsManager,
_message.SetScrollWheelHandler(_scrollBar);
_message.SetParentControl(this);

_add.OnClick += AddButton_Click;
_delete.OnClick += DeleteButton_Click;
_add.OnMouseDown += AddButton_Click;
_delete.OnMouseDown += DeleteButton_Click;
}

public override void Initialize()
Expand Down
4 changes: 2 additions & 2 deletions EndlessClient/Dialogs/ChangePasswordDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ public ChangePasswordDialog(INativeGraphicsManager nativeGraphicsManager,
new Vector2(157, 195),
dialogButtonService.GetSmallDialogButtonOutSource(SmallButton.Ok),
dialogButtonService.GetSmallDialogButtonOverSource(SmallButton.Ok));
_ok.OnClick += OnButtonPressed;
_ok.OnMouseDown += OnButtonPressed;

_cancel = new XNAButton(
dialogButtonService.SmallButtonSheet,
new Vector2(250, 195),
dialogButtonService.GetSmallDialogButtonOutSource(SmallButton.Cancel),
dialogButtonService.GetSmallDialogButtonOverSource(SmallButton.Cancel));
_cancel.OnClick += (s, e) => Close(XNADialogResult.Cancel);
_cancel.OnMouseDown += (s, e) => Close(XNADialogResult.Cancel);

CenterInGameView();
}
Expand Down
6 changes: 3 additions & 3 deletions EndlessClient/Dialogs/CreateCharacterDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public CreateCharacterDialog(
new Vector2(196, 85 + i * 26),
new Rectangle(185, 38, 19, 19),
new Rectangle(206, 38, 19, 19));
btn.OnClick += ArrowButtonClick;
btn.OnMouseDown += ArrowButtonClick;
btn.SetParentControl(this);
_arrowButtons[i] = btn;
}
Expand All @@ -94,14 +94,14 @@ public CreateCharacterDialog(
new Vector2(157, 195),
eoDialogButtonService.GetSmallDialogButtonOutSource(SmallButton.Ok),
eoDialogButtonService.GetSmallDialogButtonOverSource(SmallButton.Ok));
_ok.OnClick += (s, e) => ClickOk();
_ok.OnMouseDown += (s, e) => ClickOk();
_ok.SetParentControl(this);

_cancel = new XNAButton(eoDialogButtonService.SmallButtonSheet,
new Vector2(250, 195),
eoDialogButtonService.GetSmallDialogButtonOutSource(SmallButton.Cancel),
eoDialogButtonService.GetSmallDialogButtonOverSource(SmallButton.Cancel));
_cancel.OnClick += (s, e) => Close(XNADialogResult.Cancel);
_cancel.OnMouseDown += (s, e) => Close(XNADialogResult.Cancel);
_cancel.SetParentControl(this);

CenterInGameView();
Expand Down
8 changes: 4 additions & 4 deletions EndlessClient/Dialogs/EOMessageBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,23 @@ public EOMessageBox(INativeGraphicsManager graphicsManager,
{
case EODialogButtons.Ok:
_ok = new XNAButton(smallButtonSheet, new Vector2(181, 113), okOut, okOver);
_ok.OnClick += (sender, e) => Close(XNADialogResult.OK);
_ok.OnMouseDown += (sender, e) => Close(XNADialogResult.OK);
_ok.SetParentControl(this);
break;
case EODialogButtons.Cancel:
_cancel = new XNAButton(smallButtonSheet, new Vector2(181, 113), cancelOut, cancelOver);
_cancel.OnClick += (sender, e) => Close(XNADialogResult.Cancel);
_cancel.OnMouseDown += (sender, e) => Close(XNADialogResult.Cancel);
_cancel.SetParentControl(this);
break;
case EODialogButtons.OkCancel:
//implement this more fully when it is needed
//update draw location of ok button to be on left?
_ok = new XNAButton(smallButtonSheet, new Vector2(89, 113), okOut, okOver);
_ok.OnClick += (sender, e) => Close(XNADialogResult.OK);
_ok.OnMouseDown += (sender, e) => Close(XNADialogResult.OK);
_ok.SetParentControl(this);

_cancel = new XNAButton(smallButtonSheet, new Vector2(181, 113), cancelOut, cancelOver);
_cancel.OnClick += (s, e) => Close(XNADialogResult.Cancel);
_cancel.OnMouseDown += (s, e) => Close(XNADialogResult.Cancel);
_cancel.SetParentControl(this);
break;
}
Expand Down
4 changes: 2 additions & 2 deletions EndlessClient/Dialogs/ItemTransferDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public ItemTransferDialog(INativeGraphicsManager nativeGraphicsManager,
{
Visible = true
};
_okButton.OnClick += (s, e) => Close(XNADialogResult.OK);
_okButton.OnMouseDown += (s, e) => Close(XNADialogResult.OK);

_cancelButton = new XNAButton(eoDialogButtonService.SmallButtonSheet,
new Vector2(153, 125),
Expand All @@ -84,7 +84,7 @@ public ItemTransferDialog(INativeGraphicsManager nativeGraphicsManager,
{
Visible = true
};
_cancelButton.OnClick += (s, e) => Close(XNADialogResult.Cancel);
_cancelButton.OnMouseDown += (s, e) => Close(XNADialogResult.Cancel);

_descLabel = new XNALabel(Constants.FontSize10)
{
Expand Down
6 changes: 3 additions & 3 deletions EndlessClient/Dialogs/ListDialogItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void SetPrimaryClickAction(EventHandler<MouseEventArgs> onClickAction)
Underline = UnderlineLinks
};

((XNAHyperLink)_primaryText).OnClick += onClickAction;
((XNAHyperLink)_primaryText).OnMouseDown += onClickAction;

_primaryText.SetParentControl(this);
_primaryText.Initialize();
Expand Down Expand Up @@ -223,7 +223,7 @@ public void SetSubtextClickAction(EventHandler<MouseEventArgs> onClickAction)
Underline = UnderlineLinks
};

((XNAHyperLink)_subText).OnClick += onClickAction;
((XNAHyperLink)_subText).OnMouseDown += onClickAction;

_subText.SetParentControl(this);
_subText.Initialize();
Expand Down Expand Up @@ -270,7 +270,7 @@ protected override void OnDrawControl(GameTime gameTime)
_spriteBatch.End();
}

protected override bool HandleClick(IXNAControl control, MouseEventArgs eventArgs)
protected override bool HandleMouseDown(IXNAControl control, MouseEventArgs eventArgs)
{
if (eventArgs.Button == MouseButton.Left)
{
Expand Down
2 changes: 1 addition & 1 deletion EndlessClient/Dialogs/PaperdollDialogItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public PaperdollDialogItem(INativeGraphicsManager nativeGraphicsManager,
StretchMode = StretchMode.CenterInFrame;
}

protected override bool HandleClick(IXNAControl control, MouseEventArgs eventArgs)
protected override bool HandleMouseDown(IXNAControl control, MouseEventArgs eventArgs)
{
if (!_isMainCharacter || !_itemInfo.HasValue)
return false;
Expand Down
2 changes: 1 addition & 1 deletion EndlessClient/Dialogs/PlayerInfoDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public PlayerInfoDialog(INativeGraphicsManager graphicsManager,
new Vector2(276, 253),
eoDialogButtonService.GetSmallDialogButtonOutSource(SmallButton.Ok),
eoDialogButtonService.GetSmallDialogButtonOverSource(SmallButton.Ok));
okButton.OnClick += (_, _) => Close(XNADialogResult.OK);
okButton.OnMouseDown += (_, _) => Close(XNADialogResult.OK);
okButton.Initialize();
okButton.SetParentControl(this);

Expand Down
2 changes: 1 addition & 1 deletion EndlessClient/Dialogs/ProgressDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public ProgressDialog(INativeGraphicsManager nativeGraphicsManager,
new Vector2(181, 113),
eoDialogButtonService.GetSmallDialogButtonOutSource(SmallButton.Cancel),
eoDialogButtonService.GetSmallDialogButtonOverSource(SmallButton.Cancel));
_cancelButton.OnClick += DoCancel;
_cancelButton.OnMouseDown += DoCancel;
_cancelButton.SetParentControl(this);

_pbBackgroundTexture = GraphicsManager.TextureFromResource(GFXTypes.PreLoginUI, 19);
Expand Down
4 changes: 2 additions & 2 deletions EndlessClient/Dialogs/QuestDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public QuestDialog(INativeGraphicsManager nativeGraphicsManager,
{
Visible = false,
};
_questSwitcher.OnClick += (_, _) => ToggleSwitcherState();
_questSwitcher.OnClick += (_, _) => ClickSoundEffect?.Invoke(this, EventArgs.Empty);
_questSwitcher.OnMouseDown += (_, _) => ToggleSwitcherState();
_questSwitcher.OnMouseDown += (_, _) => ClickSoundEffect?.Invoke(this, EventArgs.Empty);
_questSwitcher.SetParentControl(this);
}

Expand Down
16 changes: 8 additions & 8 deletions EndlessClient/Dialogs/ScrollingListDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public ScrollingListDialog(INativeGraphicsManager nativeGraphicsManager,
UpdateOrder = 1,
};
_add.SetParentControl(this);
_add.OnClick += (o, e) => AddAction?.Invoke(o, e);
_add.OnMouseDown += (o, e) => AddAction?.Invoke(o, e);

_back = new XNAButton(dialogButtonService.SmallButtonSheet, Vector2.Zero,
dialogButtonService.GetSmallDialogButtonOutSource(SmallButton.Back),
Expand All @@ -241,7 +241,7 @@ public ScrollingListDialog(INativeGraphicsManager nativeGraphicsManager,
UpdateOrder = 1,
};
_back.SetParentControl(this);
_back.OnClick += (o, e) => BackAction?.Invoke(o, e);
_back.OnMouseDown += (o, e) => BackAction?.Invoke(o, e);

_next = new XNAButton(dialogButtonService.SmallButtonSheet, Vector2.Zero,
dialogButtonService.GetSmallDialogButtonOutSource(SmallButton.Next),
Expand All @@ -251,7 +251,7 @@ public ScrollingListDialog(INativeGraphicsManager nativeGraphicsManager,
UpdateOrder = 1,
};
_next.SetParentControl(this);
_next.OnClick += (o, e) => NextAction?.Invoke(o, e);
_next.OnMouseDown += (o, e) => NextAction?.Invoke(o, e);

_history = new XNAButton(dialogButtonService.SmallButtonSheet, Vector2.Zero,
dialogButtonService.GetSmallDialogButtonOutSource(SmallButton.History),
Expand All @@ -261,7 +261,7 @@ public ScrollingListDialog(INativeGraphicsManager nativeGraphicsManager,
UpdateOrder = 1,
};
_history.SetParentControl(this);
_history.OnClick += (o, e) => HistoryAction?.Invoke(o, e);
_history.OnMouseDown += (o, e) => HistoryAction?.Invoke(o, e);

_progress = new XNAButton(dialogButtonService.SmallButtonSheet, Vector2.Zero,
dialogButtonService.GetSmallDialogButtonOutSource(SmallButton.Progress),
Expand All @@ -271,7 +271,7 @@ public ScrollingListDialog(INativeGraphicsManager nativeGraphicsManager,
UpdateOrder = 1,
};
_progress.SetParentControl(this);
_progress.OnClick += (o, e) => ProgressAction?.Invoke(o, e);
_progress.OnMouseDown += (o, e) => ProgressAction?.Invoke(o, e);

_delete = new XNAButton(dialogButtonService.SmallButtonSheet, Vector2.Zero,
dialogButtonService.GetSmallDialogButtonOutSource(SmallButton.Delete),
Expand All @@ -281,7 +281,7 @@ public ScrollingListDialog(INativeGraphicsManager nativeGraphicsManager,
UpdateOrder = 1,
};
_delete.SetParentControl(this);
_delete.OnClick += (o, e) => ProgressAction?.Invoke(o, e);
_delete.OnMouseDown += (o, e) => ProgressAction?.Invoke(o, e);

_ok = new XNAButton(dialogButtonService.SmallButtonSheet, Vector2.Zero,
dialogButtonService.GetSmallDialogButtonOutSource(SmallButton.Ok),
Expand All @@ -291,7 +291,7 @@ public ScrollingListDialog(INativeGraphicsManager nativeGraphicsManager,
UpdateOrder = 2,
};
_ok.SetParentControl(this);
_ok.OnClick += CloseButton_Click;
_ok.OnMouseDown += CloseButton_Click;

_cancel = new XNAButton(dialogButtonService.SmallButtonSheet, Vector2.Zero,
dialogButtonService.GetSmallDialogButtonOutSource(SmallButton.Cancel),
Expand All @@ -301,7 +301,7 @@ public ScrollingListDialog(INativeGraphicsManager nativeGraphicsManager,
UpdateOrder = 2,
};
_cancel.SetParentControl(this);
_cancel.OnClick += CloseButton_Click;
_cancel.OnMouseDown += CloseButton_Click;

_button1Position = GetButton1Position(DrawArea, _ok.DrawArea, DialogType);
_button2Position = GetButton2Position(DrawArea, _ok.DrawArea, DialogType);
Expand Down
Loading

0 comments on commit 2fa374f

Please sign in to comment.