diff --git a/Intersect.Client.Framework/Gwen/Control/ResizableControl.cs b/Intersect.Client.Framework/Gwen/Control/ResizableControl.cs index 613da66596..f7419ecfca 100644 --- a/Intersect.Client.Framework/Gwen/Control/ResizableControl.cs +++ b/Intersect.Client.Framework/Gwen/Control/ResizableControl.cs @@ -1,4 +1,4 @@ -using Intersect.Client.Framework.Gwen.ControlInternal; +using Intersect.Client.Framework.Gwen.ControlInternal; using Newtonsoft.Json.Linq; @@ -20,7 +20,7 @@ public partial class ResizableControl : Base /// /// Parent control. /// name of this control - public ResizableControl(Base parent, string? name) : base(parent, name) + public ResizableControl(Base? parent, string? name) : base(parent, name) { mResizer = new Resizer[10]; MinimumSize = new Point(5, 5); diff --git a/Intersect.Client.Framework/Gwen/Control/WindowControl.cs b/Intersect.Client.Framework/Gwen/Control/WindowControl.cs index 210debfbf4..0580613057 100644 --- a/Intersect.Client.Framework/Gwen/Control/WindowControl.cs +++ b/Intersect.Client.Framework/Gwen/Control/WindowControl.cs @@ -72,7 +72,7 @@ public Padding InnerPanelPadding /// Window title. /// Determines whether the window should be modal. /// name of this control - public WindowControl(Base parent, string? title = default, bool modal = false, string? name = default) : base(parent, name) + public WindowControl(Base? parent, string? title = default, bool modal = false, string? name = default) : base(parent, name) { mTitleBar = new Dragger(this); mTitleBar.Height = 24; diff --git a/Intersect.Client/Core/Input.cs b/Intersect.Client/Core/Input.cs index 8a728fbcdc..2585675eb0 100644 --- a/Intersect.Client/Core/Input.cs +++ b/Intersect.Client/Core/Input.cs @@ -7,6 +7,7 @@ using Intersect.Client.General; using Intersect.Client.Interface; using Intersect.Client.Interface.Game; +using Intersect.Client.Interface.Shared; using Intersect.Client.Maps; using Intersect.Client.Networking; using Intersect.Configuration; @@ -82,12 +83,10 @@ public static void OnKeyPressed(Keys modifier, Keys key) { try { - var iBox = (InputBox)Interface.Interface.InputBlockingElements[i]; - if (iBox != null && !iBox.IsHidden) + if (Interface.Interface.InputBlockingElements[i] is InputBox inputBox && !inputBox.IsHidden) { - iBox.okayBtn_Clicked(null, null); + inputBox.SubmitInput(); canFocusChat = false; - break; } } diff --git a/Intersect.Client/Entities/Player.cs b/Intersect.Client/Entities/Player.cs index d84be76301..07d7d12385 100644 --- a/Intersect.Client/Entities/Player.cs +++ b/Intersect.Client/Entities/Player.cs @@ -6,9 +6,9 @@ using Intersect.Client.Framework.GenericClasses; using Intersect.Client.Framework.Items; using Intersect.Client.General; -using Intersect.Client.Interface.Game; using Intersect.Client.Interface.Game.Chat; using Intersect.Client.Interface.Game.EntityPanel; +using Intersect.Client.Interface.Shared; using Intersect.Client.Items; using Intersect.Client.Localization; using Intersect.Client.Maps; @@ -395,29 +395,25 @@ public void TryDropItem(int inventorySlotIndex) var canDropMultiple = quantity > 1; var inputType = canDropMultiple ? InputBox.InputType.NumericSliderInput : InputBox.InputType.YesNo; var prompt = canDropMultiple ? Strings.Inventory.DropItemPrompt : Strings.Inventory.DropPrompt; - InputBox.Open( + _ = new InputBox( title: Strings.Inventory.DropItemTitle, prompt: prompt.ToString(itemDescriptor.Name), - modal: true, inputType: inputType, - onSuccess: DropInputBoxOkay, - onCancel: default, - userData: inventorySlotIndex, quantity: quantity, - maxQuantity: quantity - ); - } - - private void DropInputBoxOkay(object? sender, EventArgs e) - { - if (sender is InputBox inputBox) - { - var value = (int)Math.Round(inputBox.Value); - if (value > 0) + maxQuantity: quantity, + userData: inventorySlotIndex, + onSuccess: (s, e) => { - PacketSender.SendDropItem((int)inputBox.UserData, value); + if (s is InputBox inputBox && inputBox.UserData is int invSlot) + { + var value = (int)Math.Round(inputBox.Value); + if (value > 0) + { + PacketSender.SendDropItem(invSlot, value); + } + } } - } + ); } public int FindItem(Guid itemId, int itemVal = 1) @@ -648,7 +644,13 @@ public void TrySellItem(int inventorySlotIndex) var prompt = Strings.Shop.SellPrompt; var inputType = InputBox.InputType.YesNo; - EventHandler? onSuccess = SellInputBoxOkay; + EventHandler? onSuccess = (s, e) => + { + if (s is InputBox inputBox && inputBox.UserData is int invSlot) + { + PacketSender.SendSellItem(invSlot, 1); + } + }; var userData = inventorySlotIndex; var slotQuantity = inventorySlot.Quantity; var maxQuantity = slotQuantity; @@ -668,21 +670,29 @@ public void TrySellItem(int inventorySlotIndex) maxQuantity = inventoryQuantity; prompt = Strings.Shop.SellItemPrompt; inputType = InputBox.InputType.NumericSliderInput; - onSuccess = SellItemInputBoxOkay; + onSuccess = (s, e) => + { + if (s is InputBox inputBox && inputBox.UserData is int invSlot) + { + var value = (int)Math.Round(inputBox.Value); + if (value > 0) + { + PacketSender.SendSellItem(invSlot, value); + } + } + }; userData = inventorySlotIndex; } } - InputBox.Open( + _ = new InputBox( title: Strings.Shop.SellItem, prompt: prompt.ToString(itemDescriptor.Name), - modal: true, inputType: inputType, - onSuccess: onSuccess, - onCancel: null, - userData: userData, quantity: slotQuantity, - maxQuantity: maxQuantity + maxQuantity: maxQuantity, + userData: userData, + onSuccess: onSuccess ); } @@ -719,49 +729,25 @@ public void TryBuyItem(int shopSlotIndex) return; } - InputBox.Open( + _ = new InputBox( title: Strings.Shop.BuyItem, prompt: Strings.Shop.BuyItemPrompt.ToString(itemDescriptor.Name), - modal: true, inputType: InputBox.InputType.NumericSliderInput, - onSuccess: BuyItemInputBoxOkay, - onCancel: null, - userData: shopSlotIndex, quantity: maxBuyAmount, - maxQuantity: maxBuyAmount - ); - } - - private void BuyItemInputBoxOkay(object? sender, EventArgs e) - { - if (sender is InputBox inputBox) - { - var value = (int)Math.Round(inputBox.Value); - if (value > 0) - { - PacketSender.SendBuyItem((int)inputBox.UserData, value); - } - } - } - - private void SellItemInputBoxOkay(object? sender, EventArgs e) - { - if (sender is InputBox inputBox) - { - var value = (int)Math.Round(inputBox.Value); - if (value > 0) + maxQuantity: maxBuyAmount, + userData: shopSlotIndex, + onSuccess: (s, e) => { - PacketSender.SendSellItem((int)inputBox.UserData, value); + if (s is InputBox inputBox && inputBox.UserData is int shopSlot) + { + var value = (int)Math.Round(inputBox.Value); + if (value > 0) + { + PacketSender.SendBuyItem(shopSlot, value); + } + } } - } - } - - private void SellInputBoxOkay(object? sender, EventArgs e) - { - if (sender is InputBox inputBox) - { - PacketSender.SendSellItem((int)inputBox.UserData, 1); - } + ); } /// @@ -853,16 +839,25 @@ public bool TryDepositItem( return true; } - InputBox.Open( + _ = new InputBox( title: Strings.Bank.DepositItem, prompt: Strings.Bank.DepositItemPrompt.ToString(itemDescriptor.Name), - modal: true, inputType: InputBox.InputType.NumericSliderInput, - onSuccess: DepositItemInputBoxOkay, - onCancel: null, - userData: new[] { inventorySlotIndex, bankSlotIndex }, quantity: movableQuantity, - maxQuantity: maximumQuantity + maxQuantity: maximumQuantity, + userData: new Tuple(inventorySlotIndex, bankSlotIndex), + onSuccess: (s, e) => + { + if (s is InputBox inputBox && inputBox.UserData is Tuple bankData) + { + var value = (int)Math.Round(inputBox.Value); + if (value > 0) + { + var (invSlot, bankSlot) = bankData; + PacketSender.SendDepositItem(invSlot, value, bankSlot); + } + } + } ); return true; @@ -874,20 +869,6 @@ private static bool IsGuildBankDepositAllowed() (Globals.Me?.GuildRank?.Permissions.BankDeposit == true || Globals.Me?.Rank == 0); } - private void DepositItemInputBoxOkay(object? sender, EventArgs e) - { - if (sender is InputBox inputBox) - { - var value = (int)Math.Round(inputBox.Value); - if (value > 0) - { - var userData = (int[])inputBox.UserData; - - PacketSender.SendDepositItem(userData[0], value, userData[1]); - } - } - } - /// /// Attempts to withdraw items from the bank into the inventory. /// @@ -976,16 +957,25 @@ public bool TryWithdrawItem( return true; } - InputBox.Open( + _ = new InputBox( title: Strings.Bank.WithdrawItem, prompt: Strings.Bank.WithdrawItemPrompt.ToString(itemDescriptor.Name), - modal: true, inputType: InputBox.InputType.NumericSliderInput, - onSuccess: WithdrawItemInputBoxOkay, - onCancel: null, - userData: new[] { bankSlotIndex, inventorySlotIndex }, quantity: movableQuantity, - maxQuantity: maximumQuantity + maxQuantity: maximumQuantity, + userData: new Tuple(bankSlotIndex, inventorySlotIndex), + onSuccess: (s, e) => + { + if (s is InputBox inputBox && inputBox.UserData is Tuple bankData) + { + var value = (int)Math.Round(inputBox.Value); + if (value > 0) + { + var (bankSlot, invSlot) = bankData; + PacketSender.SendWithdrawItem(bankSlot, value, invSlot); + } + } + } ); return true; @@ -997,19 +987,6 @@ private static bool IsGuildBankWithdrawAllowed() (Globals.Me?.GuildRank?.Permissions.BankRetrieve == true || Globals.Me?.Rank == 0); } - private void WithdrawItemInputBoxOkay(object? sender, EventArgs e) - { - if (sender is InputBox inputBox) - { - var value = (int)Math.Round(inputBox.Value); - if (value > 0) - { - int[] userData = (int[])inputBox.UserData; - PacketSender.SendWithdrawItem(userData[0], value, userData[1]); - } - } - } - //Bag public void TryStoreBagItem(int inventorySlotIndex, int bagSlotIndex) { @@ -1019,46 +996,35 @@ public void TryStoreBagItem(int inventorySlotIndex, int bagSlotIndex) return; } - int[] userData = [inventorySlotIndex, bagSlotIndex]; - var quantity = inventorySlot.Quantity; var maxQuantity = quantity; - // TODO: Refactor server bagging logic to allow transferring quantities from the entire inventory and not just the slot - //if (itemDescriptor.IsStackable) - //{ - // maxQuantity = GetQuantityOfItemInInventory(itemDescriptor.Id); - //} - if (maxQuantity < 2) { PacketSender.SendStoreBagItem(inventorySlotIndex, 1, bagSlotIndex); return; } - InputBox.Open( + _ = new InputBox( title: Strings.Bags.StoreItem, - prompt: Strings.Bags.StoreItemPrompt.ToString(itemDescriptor.Name), true, + prompt: Strings.Bags.StoreItemPrompt.ToString(itemDescriptor.Name), inputType: InputBox.InputType.NumericSliderInput, - onSuccess: StoreBagItemInputBoxOkay, - onCancel: null, - userData: userData, quantity: quantity, - maxQuantity: maxQuantity - ); - } - - private void StoreBagItemInputBoxOkay(object? sender, EventArgs e) - { - if (sender is InputBox inputBox) - { - var value = (int)Math.Round(inputBox.Value); - if (value > 0) + maxQuantity: maxQuantity, + userData: new Tuple(inventorySlotIndex, bagSlotIndex), + onSuccess: (s, e) => { - int[] userData = (int[])inputBox.UserData; - PacketSender.SendStoreBagItem(userData[0], value, userData[1]); + if (s is InputBox inputBox && inputBox.UserData is Tuple bagData) + { + var value = (int)Math.Round(inputBox.Value); + if (value > 0) + { + var (invSlot, bagSlot) = bagData; + PacketSender.SendStoreBagItem(invSlot, value, bagSlot); + } + } } - } + ); } public void TryRetreiveBagItem(int bagSlotIndex, int inventorySlotIndex) @@ -1074,47 +1040,35 @@ public void TryRetreiveBagItem(int bagSlotIndex, int inventorySlotIndex) return; } - var userData = new int[2] { bagSlotIndex, inventorySlotIndex }; - var quantity = bagSlot.Quantity; var maxQuantity = quantity; - // TODO: Refactor server bagging logic to allow transferring quantities from the entire inventory and not just the slot - //if (itemDescriptor.IsStackable) - //{ - // maxQuantity = GetQuantityOfItemInBag(itemDescriptor.Id); - //} - if (maxQuantity < 2) { PacketSender.SendRetrieveBagItem(bagSlotIndex, 1, inventorySlotIndex); return; } - InputBox.Open( + _ = new InputBox( title: Strings.Bags.RetrieveItem, prompt: Strings.Bags.RetrieveItemPrompt.ToString(itemDescriptor.Name), - modal: true, inputType: InputBox.InputType.NumericSliderInput, - onSuccess: RetreiveBagItemInputBoxOkay, - onCancel: null, - userData: userData, quantity: quantity, - maxQuantity: maxQuantity - ); - } - - private void RetreiveBagItemInputBoxOkay(object? sender, EventArgs e) - { - if (sender is InputBox inputBox) - { - var value = (int)Math.Round(inputBox.Value); - if (value > 0) + maxQuantity: maxQuantity, + userData: new Tuple(bagSlotIndex, inventorySlotIndex), + onSuccess: (s, e) => { - int[] userData = (int[])inputBox.UserData; - PacketSender.SendRetrieveBagItem(userData[0], value, userData[1]); + if (s is InputBox inputBox && inputBox.UserData is Tuple bagData) + { + var value = (int)Math.Round(inputBox.Value); + if (value > 0) + { + var (bagSlot, invSlot) = bagData; + PacketSender.SendRetrieveBagItem(bagSlot, value, invSlot); + } + } } - } + ); } //Trade @@ -1134,29 +1088,25 @@ public void TryTradeItem(int index) return; } - InputBox.Open( + _ = new InputBox( title: Strings.Trading.OfferItem, prompt: Strings.Trading.OfferItemPrompt.ToString(tradingItem.Name), - modal: true, inputType: InputBox.InputType.NumericSliderInput, - onSuccess: TradeItemInputBoxOkay, - onCancel: null, - userData: index, quantity: quantity, - maxQuantity: quantity - ); - } - - private void TradeItemInputBoxOkay(object? sender, EventArgs e) - { - if (sender is InputBox inputBox) - { - var value = (int)Math.Round(inputBox.Value); - if (value > 0) + maxQuantity: quantity, + userData: index, + onSuccess: (s, e) => { - PacketSender.SendOfferTradeItem((int)inputBox.UserData, value); + if (s is InputBox inputBox && inputBox.UserData is int slotIndex) + { + var value = (int)Math.Round(inputBox.Value); + if (value > 0) + { + PacketSender.SendOfferTradeItem(slotIndex, value); + } + } } - } + ); } public void TryRevokeItem(int index) @@ -1175,29 +1125,25 @@ public void TryRevokeItem(int index) return; } - InputBox.Open( + _ = new InputBox( title: Strings.Trading.RevokeItem, prompt: Strings.Trading.RevokeItemPrompt.ToString(revokedItem.Name), - modal: true, inputType: InputBox.InputType.NumericSliderInput, - onSuccess: RevokeItemInputBoxOkay, - onCancel: null, - userData: index, quantity: quantity, - maxQuantity: quantity - ); - } - - private void RevokeItemInputBoxOkay(object? sender, EventArgs? e) - { - if (sender is InputBox inputBox) - { - var value = (int)Math.Round(inputBox.Value); - if (value > 0) + maxQuantity: quantity, + userData: index, + onSuccess: (s, e) => { - PacketSender.SendRevokeTradeItem((int)inputBox.UserData, value); + if (s is InputBox inputBox && inputBox.UserData is int slotIndex) + { + var value = (int)Math.Round(inputBox.Value); + if (value > 0) + { + PacketSender.SendRevokeTradeItem(slotIndex, value); + } + } } - } + ); } //Spell Processing @@ -1212,26 +1158,22 @@ public void TryForgetSpell(int spellIndex) var spellSlot = Spells[spellIndex]; if (SpellBase.TryGet(spellSlot.Id, out var spellDescriptor)) { - InputBox.Open( + _ = new InputBox( title: Strings.Spells.ForgetSpell, prompt: Strings.Spells.ForgetSpellPrompt.ToString(spellDescriptor.Name), - modal: true, inputType: InputBox.InputType.YesNo, - onSuccess: ForgetSpellInputBoxOkay, - onCancel: null, - userData: spellIndex + userData: spellIndex, + onSuccess: (s, e) => + { + if (s is InputBox inputBox && inputBox.UserData != default) + { + PacketSender.SendForgetSpell((int)inputBox.UserData); + } + } ); } } - private void ForgetSpellInputBoxOkay(object? sender, EventArgs? e) - { - if (sender is InputBox inputBox) - { - PacketSender.SendForgetSpell((int)inputBox.UserData); - } - } - public void TryUseSpell(int index) { if (Spells[index].Id != Guid.Empty && diff --git a/Intersect.Client/Interface/Game/AdminWindow.cs b/Intersect.Client/Interface/Game/AdminWindow.cs index 1e51b54ab1..3a656e749d 100644 --- a/Intersect.Client/Interface/Game/AdminWindow.cs +++ b/Intersect.Client/Interface/Game/AdminWindow.cs @@ -1,9 +1,11 @@ +using System; using Intersect.Admin.Actions; using Intersect.Client.Core; using Intersect.Client.Framework.Gwen; using Intersect.Client.Framework.Gwen.Control; using Intersect.Client.Framework.Gwen.Control.EventArguments; using Intersect.Client.General; +using Intersect.Client.Interface.Shared; using Intersect.Client.Localization; using Intersect.Client.Networking; using Intersect.GameObjects.Maps.MapList; @@ -377,9 +379,12 @@ void _unmuteButton_Clicked(Base sender, ClickedEventArgs arguments) { if (TextboxName.Text.Trim().Length > 0) { - new InputBox(Strings.Admin.UnmuteCaption.ToString(TextboxName.Text), - Strings.Admin.UnmutePrompt.ToString(TextboxName.Text), true, InputBox.InputType.YesNo, UnmuteUser, - null, -1); + _ = new InputBox( + title: Strings.Admin.UnmuteCaption.ToString(TextboxName.Text), + prompt: Strings.Admin.UnmutePrompt.ToString(TextboxName.Text), + inputType: InputBox.InputType.YesNo, + onSuccess: (s, e) => PacketSender.SendAdminAction(new UnmuteAction(TextboxName.Text)) + ); } } @@ -387,22 +392,15 @@ void _unbanButton_Clicked(Base sender, ClickedEventArgs arguments) { if (TextboxName.Text.Trim().Length > 0) { - new InputBox(Strings.Admin.UnbanCaption.ToString(TextboxName.Text), - Strings.Admin.UnbanPrompt.ToString(TextboxName.Text), true, InputBox.InputType.YesNo, UnbanUser, - null, -1); + _ = new InputBox( + title: Strings.Admin.UnbanCaption.ToString(TextboxName.Text), + prompt: Strings.Admin.UnbanPrompt.ToString(TextboxName.Text), + inputType: InputBox.InputType.YesNo, + onSuccess: (s, e) => PacketSender.SendAdminAction(new UnbanAction(TextboxName.Text)) + ); } } - void UnmuteUser(object sender, EventArgs e) - { - PacketSender.SendAdminAction(new UnmuteAction(TextboxName.Text)); - } - - void UnbanUser(object sender, EventArgs e) - { - PacketSender.SendAdminAction(new UnbanAction(TextboxName.Text)); - } - void _setSpriteButton_Clicked(Base sender, ClickedEventArgs arguments) { if (TextboxName.Text.Trim().Length > 0) diff --git a/Intersect.Client/Interface/Game/EscapeMenu.cs b/Intersect.Client/Interface/Game/EscapeMenu.cs index 834759b0e6..d0aaa82ec4 100644 --- a/Intersect.Client/Interface/Game/EscapeMenu.cs +++ b/Intersect.Client/Interface/Game/EscapeMenu.cs @@ -1,4 +1,4 @@ -using Intersect.Client.Core; +using Intersect.Client.Core; using Intersect.Client.Framework.File_Management; using Intersect.Client.Framework.Gwen.Control; using Intersect.Client.Framework.Gwen.Control.EventArguments; @@ -140,7 +140,7 @@ public override void ToggleHidden() base.ToggleHidden(); } - private void LogoutToCharacterSelect(object sender, EventArgs e) + private void LogoutToCharacterSelect(object? sender, EventArgs? e) { if (Globals.Me != null) { @@ -150,7 +150,7 @@ private void LogoutToCharacterSelect(object sender, EventArgs e) Main.Logout(true); } - private void LogoutToMainMenu(object sender, EventArgs e) + private void LogoutToMainMenu(object? sender, EventArgs? e) { if (Globals.Me != null) { @@ -160,7 +160,7 @@ private void LogoutToMainMenu(object sender, EventArgs e) Main.Logout(false); } - private void ExitToDesktop(object sender, EventArgs e) + private void ExitToDesktop(object? sender, EventArgs? e) { if (Globals.Me != null) { @@ -176,9 +176,11 @@ private void GoToCharacterSelect_Clicked(Base sender, ClickedEventArgs arguments if (Globals.Me.CombatTimer > Timing.Global.Milliseconds) { //Show Logout in Combat Warning - var box = new InputBox( - Strings.Combat.WarningTitle, Strings.Combat.WarningCharacterSelect, true, InputBox.InputType.YesNo, - LogoutToCharacterSelect, null, null + _ = new InputBox( + title: Strings.Combat.WarningTitle, + prompt: Strings.Combat.WarningCharacterSelect, + inputType: InputBox.InputType.YesNo, + onSuccess: LogoutToCharacterSelect ); } else @@ -193,9 +195,11 @@ private void Logout_Clicked(Base sender, ClickedEventArgs arguments) if (Globals.Me.CombatTimer > Timing.Global.Milliseconds) { //Show Logout in Combat Warning - var box = new InputBox( - Strings.Combat.WarningTitle, Strings.Combat.WarningLogout, true, InputBox.InputType.YesNo, - LogoutToMainMenu, null, null + _ = new InputBox( + title: Strings.Combat.WarningTitle, + prompt: Strings.Combat.WarningLogout, + inputType: InputBox.InputType.YesNo, + onSuccess: LogoutToMainMenu ); } else @@ -210,9 +214,11 @@ private void ExitToDesktop_Clicked(Base sender, ClickedEventArgs arguments) if (Globals.Me.CombatTimer > Timing.Global.Milliseconds) { //Show Logout in Combat Warning - var box = new InputBox( - Strings.Combat.WarningTitle, Strings.Combat.WarningExitDesktop, true, InputBox.InputType.YesNo, - ExitToDesktop, null, null + _ = new InputBox( + title: Strings.Combat.WarningTitle, + prompt: Strings.Combat.WarningExitDesktop, + inputType: InputBox.InputType.YesNo, + onSuccess: ExitToDesktop ); } else diff --git a/Intersect.Client/Interface/Game/Friends/FriendsRow.cs b/Intersect.Client/Interface/Game/Friends/FriendsRow.cs index e32325aa6a..6efb71e97e 100644 --- a/Intersect.Client/Interface/Game/Friends/FriendsRow.cs +++ b/Intersect.Client/Interface/Game/Friends/FriendsRow.cs @@ -1,10 +1,11 @@ -using Intersect.Client.Core; +using Intersect.Client.Core; using Intersect.Client.Networking; using Intersect.Client.Localization; using Intersect.Client.Framework.Gwen.Control; using Intersect.Client.Framework.Gwen.Control.EventArguments; using Intersect.Client.Framework.File_Management; using Intersect.Client.Framework.GenericClasses; +using Intersect.Client.Interface.Shared; namespace Intersect.Client.Interface.Game; @@ -89,16 +90,13 @@ private void UpdateControls() private void MRemove_Clicked(Base sender, ClickedEventArgs arguments) { var iBox = new InputBox( - Strings.Friends.RemoveFriend, Strings.Friends.RemoveFriendPrompt.ToString(mMyName), true, - InputBox.InputType.YesNo, RemoveFriend, null, 0 + title: Strings.Friends.RemoveFriend, + prompt: Strings.Friends.RemoveFriendPrompt.ToString(mMyName), + inputType: InputBox.InputType.YesNo, + onSuccess: (s, e) => PacketSender.SendRemoveFriend(mMyName) ); } - private void RemoveFriend(Object sender, EventArgs e) - { - PacketSender.SendRemoveFriend(mMyName); - } - private void MTell_Clicked(Base sender, ClickedEventArgs arguments) { Interface.GameUi.SetChatboxText($"/pm {mMyName} "); diff --git a/Intersect.Client/Interface/Game/Friends/FriendsWindow.cs b/Intersect.Client/Interface/Game/Friends/FriendsWindow.cs index 27abfc5142..586730e45a 100644 --- a/Intersect.Client/Interface/Game/Friends/FriendsWindow.cs +++ b/Intersect.Client/Interface/Game/Friends/FriendsWindow.cs @@ -3,6 +3,7 @@ using Intersect.Client.Framework.Gwen.Control; using Intersect.Client.Framework.Gwen.Control.EventArguments; using Intersect.Client.General; +using Intersect.Client.Interface.Shared; using Intersect.Client.Localization; using Intersect.Client.Networking; using Intersect.Utilities; @@ -98,27 +99,24 @@ public void UpdateList() void addButton_Clicked(Base sender, ClickedEventArgs arguments) { - var iBox = new InputBox( - Strings.Friends.AddFriend, Strings.Friends.AddFriendPrompt, true, InputBox.InputType.TextInput, - AddFriend, null, 0 - ); - } - - - private void AddFriend(Object sender, EventArgs e) - { - var ibox = (InputBox) sender; - if (ibox.TextValue.Trim().Length >= 3) //Don't bother sending a packet less than the char limit - { - if (Globals.Me.CombatTimer < Timing.Global.Milliseconds) + _ = new InputBox( + title: Strings.Friends.AddFriend, + prompt: Strings.Friends.AddFriendPrompt, + inputType: InputBox.InputType.TextInput, + onSuccess: (s, e) => { - PacketSender.SendAddFriend(ibox.TextValue); + if (s is InputBox inputBox && inputBox.TextValue.Trim().Length >= 3) + { + if (Globals.Me?.CombatTimer < Timing.Global.Milliseconds) + { + PacketSender.SendAddFriend(inputBox.TextValue); + } + else + { + PacketSender.SendChatMsg(Strings.Friends.InFight.ToString(), 4); + } + } } - else - { - PacketSender.SendChatMsg(Strings.Friends.InFight.ToString(), 4); - } - } + ); } - } diff --git a/Intersect.Client/Interface/Game/GuildWindow.cs b/Intersect.Client/Interface/Game/GuildWindow.cs index 2bd3e180ac..aa175b25a8 100644 --- a/Intersect.Client/Interface/Game/GuildWindow.cs +++ b/Intersect.Client/Interface/Game/GuildWindow.cs @@ -1,8 +1,9 @@ -using Intersect.Client.Core; +using Intersect.Client.Core; using Intersect.Client.Framework.File_Management; using Intersect.Client.Framework.Gwen.Control; using Intersect.Client.Framework.Gwen.Control.EventArguments; using Intersect.Client.General; +using Intersect.Client.Interface.Shared; using Intersect.Client.Localization; using Intersect.Client.Networking; using Intersect.Network.Packets.Server; @@ -156,34 +157,30 @@ void addButton_Clicked(Base sender, ClickedEventArgs arguments) void addPopupButton_Clicked(Base sender, ClickedEventArgs arguments) { - var iBox = new InputBox( - Strings.Guilds.InviteMemberTitle, Strings.Guilds.InviteMemberPrompt.ToString(Globals.Me.Guild), true, InputBox.InputType.TextInput, - AddMember, null, 0 + _ = new InputBox( + title: Strings.Guilds.InviteMemberTitle, + prompt: Strings.Guilds.InviteMemberPrompt.ToString(Globals.Me?.Guild), + inputType: InputBox.InputType.TextInput, + onSuccess: (s, e) => + { + if (s is InputBox inputBox && inputBox.TextValue.Trim().Length >= 3) + { + PacketSender.SendInviteGuild(inputBox.TextValue); + } + } ); } private void leave_Clicked(Base sender, ClickedEventArgs arguments) { - var iBox = new InputBox( - Strings.Guilds.LeaveTitle, Strings.Guilds.LeavePrompt, true, InputBox.InputType.YesNo, - LeaveGuild, null, 0 + _ = new InputBox( + title: Strings.Guilds.LeaveTitle, + prompt: Strings.Guilds.LeavePrompt.ToString(Globals.Me?.Guild), + inputType: InputBox.InputType.YesNo, + onSuccess: (s, e) => PacketSender.SendLeaveGuild() ); } - private void LeaveGuild(object sender, EventArgs e) - { - PacketSender.SendLeaveGuild(); - } - - private void AddMember(Object sender, EventArgs e) - { - var ibox = (InputBox)sender; - if (ibox.TextValue.Trim().Length >= 3) //Don't bother sending a packet less than the char limit - { - PacketSender.SendInviteGuild(ibox.TextValue); - } - } - #endregion #region "Member List" @@ -310,20 +307,22 @@ private void kickOption_Clicked(Base sender, ClickedEventArgs arguments) var isOwner = rankIndex == 0; if (mSelectedMember != null && (rank.Permissions.Kick || isOwner) && mSelectedMember.Rank > rankIndex) { - var iBox = new InputBox( - Strings.Guilds.KickTitle, Strings.Guilds.KickPrompt.ToString(mSelectedMember?.Name), true, InputBox.InputType.YesNo, - KickMember, null, mSelectedMember + _ = new InputBox( + title: Strings.Guilds.KickTitle, + prompt: Strings.Guilds.KickPrompt.ToString(mSelectedMember?.Name), + inputType: InputBox.InputType.YesNo, + userData: mSelectedMember, + onSuccess: (s, e) => + { + if (s is InputBox inputBox && inputBox.UserData is GuildMember member) + { + PacketSender.SendKickGuildMember(member.Id); + } + } ); } } - private void KickMember(object sender, EventArgs e) - { - var input = (InputBox)sender; - var member = (GuildMember)input.UserData; - PacketSender.SendKickGuildMember(member.Id); - } - #endregion #region "Transferring" @@ -334,24 +333,21 @@ private void transferOption_Clicked(Base sender, ClickedEventArgs arguments) var isOwner = rankIndex == 0; if (mSelectedMember != null && (rank.Permissions.Kick || isOwner) && mSelectedMember.Rank > rankIndex) { - var iBox = new InputBox( - Strings.Guilds.TransferTitle, Strings.Guilds.TransferPrompt.ToString(mSelectedMember?.Name, rank.Title, Globals.Me?.Guild), true, InputBox.InputType.TextInput, - TransferGuild, null, mSelectedMember + _ = new InputBox( + title: Strings.Guilds.TransferTitle, + prompt: Strings.Guilds.TransferPrompt.ToString(mSelectedMember?.Name, rank.Title, Globals.Me?.Guild), + inputType: InputBox.InputType.TextInput, + userData: mSelectedMember, + onSuccess: (s, e) => + { + if (s is InputBox inputBox && inputBox.TextValue == Globals.Me?.Guild && inputBox.UserData is GuildMember member) + { + PacketSender.SendTransferGuild(member.Id); + } + } ); } } - - private void TransferGuild(object sender, EventArgs e) - { - var input = (InputBox)sender; - var member = (GuildMember)input.UserData; - var text = input.TextValue; - if (text == Globals.Me?.Guild) - { - PacketSender.SendTransferGuild(member.Id); - } - } - #endregion @@ -374,20 +370,22 @@ private void promoteOption_Clicked(Base sender, ClickedEventArgs arguments) var newRank = (int)sender.UserData; if (mSelectedMember != null && (rank.Permissions.Kick || isOwner) && mSelectedMember.Rank > rankIndex) { - var iBox = new InputBox( - Strings.Guilds.PromoteTitle, Strings.Guilds.PromotePrompt.ToString(mSelectedMember?.Name, Options.Instance.Guild.Ranks[newRank].Title), true, InputBox.InputType.YesNo, - PromoteMember, null, new KeyValuePair(mSelectedMember, newRank) + _ = new InputBox( + title: Strings.Guilds.PromoteTitle, + prompt: Strings.Guilds.PromotePrompt.ToString(mSelectedMember?.Name, Options.Instance.Guild.Ranks[newRank].Title), + inputType: InputBox.InputType.YesNo, + userData: new Tuple(mSelectedMember, newRank), + onSuccess: (s, e) => + { + if (s is InputBox inputBox && inputBox.UserData is Tuple memberRankPair) + { + var (member, newRank) = memberRankPair; + PacketSender.SendPromoteGuildMember(member?.Id ?? Guid.Empty, newRank); + } + } ); } } - - private void PromoteMember(object sender, EventArgs e) - { - var input = (InputBox)sender; - var memberRankPair = (KeyValuePair)input.UserData; - PacketSender.SendPromoteGuildMember(memberRankPair.Key?.Id ?? Guid.Empty, memberRankPair.Value); - } - #endregion @@ -400,20 +398,22 @@ private void demoteOption_Clicked(Base sender, ClickedEventArgs arguments) var newRank = (int)sender.UserData; if (mSelectedMember != null && (rank.Permissions.Kick || isOwner) && mSelectedMember.Rank > rankIndex) { - var iBox = new InputBox( - Strings.Guilds.DemoteTitle, Strings.Guilds.DemotePrompt.ToString(mSelectedMember?.Name, Options.Instance.Guild.Ranks[newRank].Title), true, InputBox.InputType.YesNo, - DemoteMember, null, new KeyValuePair(mSelectedMember, newRank) + _ = new InputBox( + title: Strings.Guilds.DemoteTitle, + prompt: Strings.Guilds.DemotePrompt.ToString(mSelectedMember?.Name, Options.Instance.Guild.Ranks[newRank].Title), + inputType: InputBox.InputType.YesNo, + userData: new Tuple(mSelectedMember, newRank), + onSuccess: (s, e) => + { + if (s is InputBox inputBox && inputBox.UserData is Tuple memberRankPair) + { + var (member, newRank) = memberRankPair; + PacketSender.SendDemoteGuildMember(member?.Id ?? Guid.Empty, newRank); + } + } ); } } - - private void DemoteMember(object sender, EventArgs e) - { - var input = (InputBox)sender; - var memberRankPair = (KeyValuePair)input.UserData; - PacketSender.SendDemoteGuildMember(memberRankPair.Key?.Id ?? Guid.Empty, memberRankPair.Value); - } - #endregion } diff --git a/Intersect.Client/Interface/Game/InputBox.cs b/Intersect.Client/Interface/Game/InputBox.cs deleted file mode 100644 index 557360dd66..0000000000 --- a/Intersect.Client/Interface/Game/InputBox.cs +++ /dev/null @@ -1,368 +0,0 @@ -using Intersect.Client.Core; -using Intersect.Client.Framework.File_Management; -using Intersect.Client.Framework.Gwen; -using Intersect.Client.Framework.Gwen.Control; -using Intersect.Client.Framework.Gwen.Control.EventArguments; -using Intersect.Client.Localization; - -namespace Intersect.Client.Interface.Game; - - -public partial class InputBox : Base -{ - public static void Open( - string title, - string prompt, - bool modal, - InputType inputType, - EventHandler? onSuccess, - EventHandler? onCancel, - object userData, - int quantity = 0, - int maxQuantity = int.MaxValue, - Base? parent = null, - GameContentManager.UI stage = GameContentManager.UI.InGame - ) => new InputBox( - title: title, - prompt: prompt, - modal: modal, - inputType: inputType, - onSuccess: onSuccess, - onCancel: onCancel, - userData: userData, - quantity: quantity, - maxQuantity: maxQuantity, - parent: parent, - stage: stage - ); - - public enum InputType - { - - OkayOnly, - - YesNo, - - NumericInput, - - TextInput, - - NumericSliderInput, - - } - - private GameContentManager.UI _uiStage; - - private bool mInitialized = false; - - private InputType mInputType; - - private WindowControl mMyWindow; - - private Button mNoButton; - - private TextBoxNumeric mNumericTextbox; - - private ImagePanel mNumericTextboxBg; - - private ImagePanel mNumericSliderboxBg; - - private HorizontalSlider mNumericSlider; - - private TextBoxNumeric mNumericSliderTextbox; - - private Button mOkayButton; - - private string mPrompt = ""; - - private Label mPromptLabel; - - private TextBox mTextbox; - - private ImagePanel mTextboxBg; - - private Button mYesButton; - - public string TextValue { get; set; } - - public object UserData { get; set; } - - public double Value { get; set; } - - public new string Name { get; set; } = "InputBox"; - - public InputBox( - string title, - string prompt, - bool modal, - InputType inputType, - EventHandler? onSuccess, - EventHandler? onCancel = default, - object? userData = default, - int quantity = 0, - int maxQuantity = Int32.MaxValue, - Base? parent = null, - GameContentManager.UI stage = GameContentManager.UI.InGame - ) : base(parent) - { - if (parent == null) - { - parent = Interface.GameUi.GameCanvas; - } - - OkayEventHandler = onSuccess; - CancelEventHandler = onCancel; - UserData = userData; - mInputType = inputType; - _uiStage = stage; - mPrompt = prompt; - - mMyWindow = new WindowControl(parent, title, modal, "InputBox"); - mMyWindow.BeforeDraw += _myWindow_BeforeDraw; - mMyWindow.DisableResizing(); - - mNumericTextboxBg = new ImagePanel(mMyWindow, "Textbox"); - mNumericTextbox = new TextBoxNumeric(mNumericTextboxBg, "TextboxText"); - mNumericTextbox.SubmitPressed += TextBox_SubmitPressed; - mNumericTextbox.Value = quantity; - - mTextboxBg = new ImagePanel(mMyWindow, "Textbox"); - mTextbox = new TextBox(mTextboxBg, "TextboxText"); - mTextbox.SubmitPressed += TextBox_SubmitPressed; - - mNumericSliderboxBg = new ImagePanel(mMyWindow, "Sliderbox"); - mNumericSlider = new HorizontalSlider(mNumericSliderboxBg, "Slider"); - mNumericSlider.SetRange(1, maxQuantity); - mNumericSlider.NotchCount = maxQuantity; - mNumericSlider.SnapToNotches = true; - mNumericSlider.Value = quantity; - mNumericSlider.ValueChanged += MNumericSlider_ValueChanged; - mNumericSliderTextbox = new TextBoxNumeric(mNumericSliderboxBg, "SliderboxText"); - mNumericSliderTextbox.Value = quantity; - mNumericSliderTextbox.TextChanged += MNumericSliderTextbox_TextChanged; - mNumericSliderTextbox.SubmitPressed += MNumericSliderTextbox_SubmitPressed; - - if (inputType == InputType.NumericInput) - { - mNumericTextbox.Focus(); - } - - if (inputType == InputType.TextInput) - { - mTextbox.Focus(); - } - - if (inputType != InputType.NumericInput) - { - mNumericTextboxBg.IsHidden = true; - } - - if (inputType == InputType.NumericSliderInput) - { - mNumericSliderTextbox.Focus(); - } - - if (inputType != InputType.NumericSliderInput) - { - mNumericSliderboxBg.Hide(); - } - - - if (inputType != InputType.TextInput) - { - mTextboxBg.IsHidden = true; - } - - mYesButton = new Button(mMyWindow, "YesButton"); - mYesButton.SetText(Strings.InputBox.Okay); - mYesButton.Clicked += okayBtn_Clicked; - - mNoButton = new Button(mMyWindow, "NoButton"); - mNoButton.SetText(Strings.InputBox.Cancel); - mNoButton.Clicked += cancelBtn_Clicked; - - mOkayButton = new Button(mMyWindow, "OkayButton"); - mOkayButton.SetText(Strings.InputBox.Okay); - mOkayButton.Clicked += okayBtn_Clicked; - - mPromptLabel = new Label(mMyWindow, "PromptLabel"); - Interface.InputBlockingElements.Add(this); - - Value = quantity; - } - - private void MNumericSliderTextbox_TextChanged(Base sender, EventArgs arguments) - { - if (sender is HorizontalSlider box && box == mNumericSlider) - { - return; - } - - mNumericSlider.Value = mNumericSliderTextbox.Value; - } - - private void MNumericSliderTextbox_SubmitPressed(Base sender, EventArgs arguments) - { - SubmitInput(); - } - - private void MNumericSlider_ValueChanged(Base sender, EventArgs arguments) - { - if (sender is TextBoxNumeric box && box == mNumericSliderTextbox) - { - return; - } - - var value = (int)Math.Round(mNumericSlider.Value); - mNumericSliderTextbox.Value = value; - } - - private void TextBox_SubmitPressed(Base sender, EventArgs arguments) - { - SubmitInput(); - } - - private void _myWindow_BeforeDraw(Base sender, EventArgs arguments) - { - if (!mInitialized) - { - mMyWindow.LoadJsonUi(_uiStage, Graphics.Renderer.GetResolutionString(), true); - var text = Interface.WrapText(mPrompt, mPromptLabel.Width, mPromptLabel.Font); - var y = mPromptLabel.Y; - foreach (var s in text) - { - var label = new Label(mMyWindow) - { - Text = s, - TextColorOverride = mPromptLabel.TextColor, - Font = mPromptLabel.Font - }; - - label.SetPosition(mPromptLabel.X, y); - y += label.Height; - Align.CenterHorizontally(label); - } - - switch (mInputType) - { - case InputType.YesNo: - mYesButton.Text = Strings.InputBox.Yes; - mNoButton.Text = Strings.InputBox.No; - mOkayButton.Hide(); - mYesButton.Show(); - mNoButton.Show(); - mNumericTextboxBg.Hide(); - mNumericSliderboxBg.Hide(); - mTextboxBg.Hide(); - - break; - case InputType.OkayOnly: - mOkayButton.Show(); - mYesButton.Hide(); - mNoButton.Hide(); - mNumericTextboxBg.Hide(); - mNumericSliderboxBg.Hide(); - mTextboxBg.Hide(); - - break; - case InputType.NumericInput: - mOkayButton.Hide(); - mYesButton.Show(); - mNoButton.Show(); - mNumericTextboxBg.Show(); - mNumericSliderboxBg.Hide(); - mTextboxBg.Hide(); - - break; - case InputType.NumericSliderInput: - mOkayButton.Hide(); - mYesButton.Show(); - mNoButton.Show(); - mNumericTextboxBg.Hide(); - mNumericSliderboxBg.Show(); - mTextboxBg.Hide(); - - break; - case InputType.TextInput: - mOkayButton.Hide(); - mYesButton.Show(); - mNoButton.Show(); - mNumericTextboxBg.Hide(); - mNumericSliderboxBg.Hide(); - mTextboxBg.Show(); - - break; - } - - mMyWindow.Show(); - mMyWindow.Focus(); - mInitialized = true; - } - } - - private event EventHandler OkayEventHandler; - - private event EventHandler CancelEventHandler; - - void cancelBtn_Clicked(Base sender, ClickedEventArgs arguments) - { - if (mInputType == InputType.NumericInput) - { - Value = mNumericTextbox.Value; - } - - if (mInputType == InputType.TextInput) - { - TextValue = mTextbox.Text; - } - - if (mInputType == InputType.NumericSliderInput) - { - Value = mNumericSlider.Value; - } - - if (CancelEventHandler != null) - { - CancelEventHandler(this, EventArgs.Empty); - } - - Dispose(); - } - - public void okayBtn_Clicked(Base? sender, ClickedEventArgs? arguments) - { - SubmitInput(); - } - - private void SubmitInput() - { - if (mInputType == InputType.NumericInput) - { - Value = mNumericTextbox.Value; - } - - if (mInputType == InputType.TextInput) - { - TextValue = mTextbox.Text; - } - - if (mInputType == InputType.NumericSliderInput) - { - Value = mNumericSlider.Value; - } - - OkayEventHandler?.Invoke(this, EventArgs.Empty); - - Dispose(); - } - - public void Dispose() - { - mMyWindow.Close(); - mMyWindow.Parent.RemoveChild(mMyWindow, false); - mMyWindow.Dispose(); - - base.Hide(); - } - -} diff --git a/Intersect.Client/Interface/Game/QuestsWindow.cs b/Intersect.Client/Interface/Game/QuestsWindow.cs index b052646833..f97ecad8bd 100644 --- a/Intersect.Client/Interface/Game/QuestsWindow.cs +++ b/Intersect.Client/Interface/Game/QuestsWindow.cs @@ -3,6 +3,7 @@ using Intersect.Client.Framework.Gwen.Control; using Intersect.Client.Framework.Gwen.Control.EventArguments; using Intersect.Client.General; +using Intersect.Client.Interface.Shared; using Intersect.Client.Localization; using Intersect.Client.Networking; using Intersect.Enums; @@ -72,10 +73,18 @@ private void _quitButton_Clicked(Base sender, ClickedEventArgs arguments) { if (mSelectedQuest != null) { - new InputBox( - Strings.QuestLog.AbandonTitle.ToString(mSelectedQuest.Name), - Strings.QuestLog.AbandonPrompt.ToString(mSelectedQuest.Name), true, InputBox.InputType.YesNo, - AbandonQuest, null, mSelectedQuest.Id + _ = new InputBox( + title: Strings.QuestLog.AbandonTitle.ToString(mSelectedQuest.Name), + prompt: Strings.QuestLog.AbandonPrompt.ToString(mSelectedQuest.Name), + inputType: InputBox.InputType.YesNo, + userData: mSelectedQuest.Id, + onSuccess: (s, e) => + { + if (s is InputBox inputBox && inputBox.UserData is Guid questId) + { + PacketSender.SendAbandonQuest(questId); + } + } ); } } diff --git a/Intersect.Client/Interface/Interface.cs b/Intersect.Client/Interface/Interface.cs index b88b7c1e4b..eb18dd4a8c 100644 --- a/Intersect.Client/Interface/Interface.cs +++ b/Intersect.Client/Interface/Interface.cs @@ -116,7 +116,7 @@ public static void InitGwen() FocusElements = new List(); InputBlockingElements = new List(); - ErrorMsgHandler = new ErrorHandler(sMenuCanvas, sGameCanvas); + ErrorMsgHandler = new ErrorHandler(); if (Globals.GameState == GameStates.Intro || Globals.GameState == GameStates.Menu) { diff --git a/Intersect.Client/Interface/Menu/SelectCharacterWindow.cs b/Intersect.Client/Interface/Menu/SelectCharacterWindow.cs index bb66c34af7..8578b677bd 100644 --- a/Intersect.Client/Interface/Menu/SelectCharacterWindow.cs +++ b/Intersect.Client/Interface/Menu/SelectCharacterWindow.cs @@ -5,6 +5,7 @@ using Intersect.Client.General; using Intersect.Client.Interface.Game; using Intersect.Client.Interface.Game.Chat; +using Intersect.Client.Interface.Shared; using Intersect.Client.Localization; using Intersect.Client.Networking; using Intersect.Network.Packets.Server; @@ -390,26 +391,30 @@ private void _deleteButton_Clicked(Base sender, ClickedEventArgs arguments) return; } - var iBox = new InputBox( - Strings.CharacterSelection.DeleteTitle.ToString(Characters[mSelectedChar].Name), - Strings.CharacterSelection.DeletePrompt.ToString(Characters[mSelectedChar].Name), true, - InputBox.InputType.YesNo, DeleteCharacter, null, Characters[mSelectedChar].Id, 0, 0, - mCharacterSelectionPanel.Parent, GameContentManager.UI.Menu + _ = new InputBox( + title: Strings.CharacterSelection.DeleteTitle.ToString(Characters[mSelectedChar].Name), + prompt: Strings.CharacterSelection.DeletePrompt.ToString(Characters[mSelectedChar].Name), + inputType: InputBox.InputType.YesNo, + userData: Characters[mSelectedChar].Id, + onSuccess: DeleteCharacter ); } - private void DeleteCharacter(Object sender, EventArgs e) + private void DeleteCharacter(Object? sender, EventArgs e) { - PacketSender.SendDeleteCharacter((Guid) ((InputBox) sender).UserData); + if (sender is InputBox inputBox && inputBox.UserData is Guid charId) + { + PacketSender.SendDeleteCharacter(charId); - Globals.WaitingOnServer = true; - mPlayButton.Disable(); - mNewButton.Disable(); - mDeleteButton.Disable(); - mLogoutButton.Disable(); + Globals.WaitingOnServer = true; + mPlayButton.Disable(); + mNewButton.Disable(); + mDeleteButton.Disable(); + mLogoutButton.Disable(); - mSelectedChar = 0; - UpdateDisplay(); + mSelectedChar = 0; + UpdateDisplay(); + } } private void _newButton_Clicked(Base sender, ClickedEventArgs arguments) diff --git a/Intersect.Client/Interface/Shared/ErrorWindow.cs b/Intersect.Client/Interface/Shared/ErrorWindow.cs index fc459358c8..6bf7a4c22e 100644 --- a/Intersect.Client/Interface/Shared/ErrorWindow.cs +++ b/Intersect.Client/Interface/Shared/ErrorWindow.cs @@ -1,69 +1,31 @@ -using Intersect.Client.Framework.File_Management; -using Intersect.Client.Framework.Gwen.Control; -using Intersect.Client.Interface.Game; using Intersect.Client.Localization; namespace Intersect.Client.Interface.Shared; -public partial class ErrorWindow -{ - private readonly List _errorWindows = []; - - public ErrorWindow(Canvas gameCanvas, Canvas menuCanvas, string error, string header) - { - CreateErrorWindow(gameCanvas, error, header, GameContentManager.UI.InGame); - CreateErrorWindow(menuCanvas, error, header, GameContentManager.UI.Menu); - } - - private void CreateErrorWindow(Canvas canvas, string error, string header, GameContentManager.UI stage) - { - var window = new InputBox( - title: header, - prompt: error, - modal: false, - inputType: InputBox.InputType.OkayOnly, - onSuccess: (sender, e) => - { - foreach (var window in _errorWindows) - { - window.Dispose(); - } - }, - maxQuantity: 0, - parent: canvas, - stage: stage - ); - - _errorWindows.Add(window); - } -} - public partial class ErrorHandler { - private readonly List _windows = []; - private readonly Canvas _gameCanvas; - private readonly Canvas _menuCanvas; - - public ErrorHandler(Canvas menuCanvas, Canvas gameCanvas) - { - _gameCanvas = gameCanvas; - _menuCanvas = menuCanvas; - } + private readonly List _windows = []; public void Update() { while (Interface.TryDequeueErrorMessage(out var message)) { _windows.Add( - new ErrorWindow( - _gameCanvas, - _menuCanvas, - message.Value, - string.IsNullOrWhiteSpace(message.Key) ? Strings.Errors.Title.ToString() : message.Key + _ = new InputBox( + title: string.IsNullOrWhiteSpace(message.Key) ? Strings.Errors.Title.ToString() : message.Key, + prompt: message.Value, + inputType: InputBox.InputType.OkayOnly, + onSuccess: (sender, e) => + { + foreach (var window in _windows) + { + window.Dispose(); + } + + _windows.Clear(); + } ) ); } - - _windows.Clear(); } } diff --git a/Intersect.Client/Interface/Shared/InputBox.cs b/Intersect.Client/Interface/Shared/InputBox.cs new file mode 100644 index 0000000000..07c5e05612 --- /dev/null +++ b/Intersect.Client/Interface/Shared/InputBox.cs @@ -0,0 +1,306 @@ +using Intersect.Client.Core; +using Intersect.Client.Framework.File_Management; +using Intersect.Client.Framework.Gwen; +using Intersect.Client.Framework.Gwen.Control; +using Intersect.Client.Framework.Gwen.Control.EventArguments; +using Intersect.Client.Localization; + +namespace Intersect.Client.Interface.Shared; + +public partial class InputBox : WindowControl +{ + public enum InputType + { + OkayOnly, + + YesNo, + + NumericInput, + + TextInput, + + NumericSliderInput, + } + + public string TextValue { get; set; } = string.Empty; + + public new object? UserData { get; set; } + + public double Value { get; set; } + + // Events + private event EventHandler? OkayEventHandler; + private event EventHandler? CancelEventHandler; + + // Types + private readonly InputType _inputType; + + // Controls + private readonly ImagePanel _txtNumericBg; + private readonly TextBoxNumeric _txtNumeric; + private readonly ImagePanel _textboxBg; + private readonly TextBox _textbox; + private readonly ImagePanel _numericSliderBg; + private readonly HorizontalSlider _numericSlider; + private readonly TextBoxNumeric _txtNumericSlider; + private readonly Button _btnYes; + private readonly Button _btnNo; + private readonly Button _btnOk; + private readonly Label _promptLabel; + + private readonly string _prompt = ""; + private bool _initialized = false; + + public InputBox( + string title, + string prompt, + InputType inputType, + EventHandler? onSuccess, + EventHandler? onCancel = default, + object? userData = default, + int quantity = 0, + int maxQuantity = int.MaxValue + ) : base(Interface.CurrentInterface.Root, title, true, "InputBox") + { + OkayEventHandler = onSuccess; + CancelEventHandler = onCancel; + UserData = userData; + _inputType = inputType; + _prompt = prompt; + + BeforeDraw += _beforeDraw; + DisableResizing(); + + _txtNumericBg = new ImagePanel(this, "Textbox"); + _txtNumeric = new TextBoxNumeric(_txtNumericBg, "TextboxText") + { + Value = quantity + }; + _txtNumeric.SubmitPressed += (sender, e) => SubmitInput(); + + _textboxBg = new ImagePanel(this, "Textbox"); + _textbox = new TextBox(_textboxBg, "TextboxText"); + _textbox.SubmitPressed += (sender, e) => SubmitInput(); + + _numericSliderBg = new ImagePanel(this, "Sliderbox"); + _numericSlider = new HorizontalSlider(_numericSliderBg, "Slider") + { + NotchCount = maxQuantity, + SnapToNotches = true, + Value = quantity + }; + _numericSlider.SetRange(1, maxQuantity); + _numericSlider.ValueChanged += _numericSlider_ValueChanged; + _txtNumericSlider = new TextBoxNumeric(_numericSliderBg, "SliderboxText") + { + Value = quantity + }; + _txtNumericSlider.TextChanged += _numericSliderTextbox_TextChanged; + _txtNumericSlider.SubmitPressed += (sender, e) => SubmitInput(); + + if (inputType == InputType.NumericInput) + { + _txtNumeric.Focus(); + } + + if (inputType == InputType.TextInput) + { + _textbox.Focus(); + } + + if (inputType != InputType.NumericInput) + { + _txtNumericBg.IsHidden = true; + } + + if (inputType == InputType.NumericSliderInput) + { + _txtNumericSlider.Focus(); + } + + if (inputType != InputType.NumericSliderInput) + { + _numericSliderBg.Hide(); + } + + if (inputType != InputType.TextInput) + { + _textboxBg.IsHidden = true; + } + + _btnYes = new Button(this, "YesButton") + { + Text = Strings.InputBox.Okay + }; + _btnYes.Clicked += (sender, e) => SubmitInput(); + + _btnNo = new Button(this, "NoButton") + { + Text = Strings.InputBox.Cancel + }; + _btnNo.Clicked += cancelBtn_Clicked; + + _btnOk = new Button(this, "OkayButton") + { + Text = Strings.InputBox.Okay + }; + _btnOk.Clicked += (sender, e) => SubmitInput(); + + _promptLabel = new Label(this, "PromptLabel"); + Interface.InputBlockingElements.Add(this); + + Value = quantity; + } + + private void _numericSliderTextbox_TextChanged(Base sender, EventArgs arguments) + { + if (sender is HorizontalSlider box && box == _numericSlider) + { + return; + } + + _numericSlider.Value = _txtNumericSlider.Value; + } + + private void _numericSlider_ValueChanged(Base sender, EventArgs arguments) + { + if (sender is TextBoxNumeric box && box == _txtNumericSlider) + { + return; + } + + var value = (int)Math.Round(_numericSlider.Value); + _txtNumericSlider.Value = value; + } + + private void _beforeDraw(Base sender, EventArgs arguments) + { + if (!_initialized) + { + LoadJsonUi(GameContentManager.UI.Shared, Graphics.Renderer?.GetResolutionString()); + + var text = Interface.WrapText(_prompt, _promptLabel.Width, _promptLabel.Font); + var y = _promptLabel.Y; + + foreach (var s in text) + { + var label = new Label(this) + { + Text = s, + TextColorOverride = _promptLabel.TextColor, + Font = _promptLabel.Font + }; + + label.SetPosition(_promptLabel.X, y); + y += label.Height; + Align.CenterHorizontally(label); + } + + switch (_inputType) + { + case InputType.YesNo: + _btnYes.Text = Strings.InputBox.Yes; + _btnNo.Text = Strings.InputBox.No; + _btnOk.Hide(); + _btnYes.Show(); + _btnNo.Show(); + _txtNumericBg.Hide(); + _numericSliderBg.Hide(); + _textboxBg.Hide(); + + break; + case InputType.OkayOnly: + _btnOk.Show(); + _btnYes.Hide(); + _btnNo.Hide(); + _txtNumericBg.Hide(); + _numericSliderBg.Hide(); + _textboxBg.Hide(); + + break; + case InputType.NumericInput: + _btnOk.Hide(); + _btnYes.Show(); + _btnNo.Show(); + _txtNumericBg.Show(); + _numericSliderBg.Hide(); + _textboxBg.Hide(); + + break; + case InputType.NumericSliderInput: + _btnOk.Hide(); + _btnYes.Show(); + _btnNo.Show(); + _txtNumericBg.Hide(); + _numericSliderBg.Show(); + _textboxBg.Hide(); + + break; + case InputType.TextInput: + _btnOk.Hide(); + _btnYes.Show(); + _btnNo.Show(); + _txtNumericBg.Hide(); + _numericSliderBg.Hide(); + _textboxBg.Show(); + + break; + } + + Show(); + Focus(); + _initialized = true; + } + } + + void cancelBtn_Clicked(Base sender, ClickedEventArgs arguments) + { + if (_inputType == InputType.NumericInput) + { + Value = _txtNumeric.Value; + } + + if (_inputType == InputType.TextInput) + { + TextValue = _textbox.Text; + } + + if (_inputType == InputType.NumericSliderInput) + { + Value = _numericSlider.Value; + } + + CancelEventHandler?.Invoke(this, EventArgs.Empty); + Dispose(); + } + + public void SubmitInput() + { + if (_inputType == InputType.NumericInput) + { + Value = _txtNumeric.Value; + } + + if (_inputType == InputType.TextInput) + { + TextValue = _textbox.Text; + } + + if (_inputType == InputType.NumericSliderInput) + { + Value = _numericSlider.Value; + } + + OkayEventHandler?.Invoke(this, EventArgs.Empty); + Dispose(); + } + + public override void Dispose() + { + base.Hide(); + Close(); + Parent?.RemoveChild(this, false); + base.Dispose(); + GC.SuppressFinalize(this); + } +} diff --git a/Intersect.Client/MonoGame/IntersectGame.cs b/Intersect.Client/MonoGame/IntersectGame.cs index 37fcc6ff79..b0df9d0ed9 100644 --- a/Intersect.Client/MonoGame/IntersectGame.cs +++ b/Intersect.Client/MonoGame/IntersectGame.cs @@ -24,6 +24,7 @@ using MainMenu = Intersect.Client.Interface.Menu.MainMenu; using Intersect.Logging; +using Intersect.Client.Interface.Shared; namespace Intersect.Client.MonoGame; @@ -330,16 +331,6 @@ protected override void Draw(GameTime gameTime) base.Draw(gameTime); } - private void ExitToDesktop(object sender, EventArgs e) - { - if (Globals.Me != null) - { - Globals.Me.CombatTimer = 0; - } - - Globals.IsRunning = false; - } - protected override void OnExiting(object sender, EventArgs args) { Log.Info("System window closing (due to user interaction most likely)."); @@ -368,9 +359,19 @@ protected override void OnExiting(object sender, EventArgs args) if (!exception) { //Show Message Getting Exit Confirmation From Player to Leave in Combat - var box = new InputBox( - Strings.Combat.WarningTitle, Strings.Combat.WarningCharacterSelect, true, - InputBox.InputType.YesNo, ExitToDesktop, null, null + _ = new InputBox( + title: Strings.Combat.WarningTitle, + prompt: Strings.Combat.WarningCharacterSelect, + inputType: InputBox.InputType.YesNo, + onSuccess: (s, e) => + { + if (Globals.Me != null) + { + Globals.Me.CombatTimer = 0; + } + + Globals.IsRunning = false; + } ); //Restart the MonoGame RunLoop diff --git a/Intersect.Client/Networking/PacketHandler.cs b/Intersect.Client/Networking/PacketHandler.cs index 9b8d356755..efb5c61e3f 100644 --- a/Intersect.Client/Networking/PacketHandler.cs +++ b/Intersect.Client/Networking/PacketHandler.cs @@ -5,7 +5,6 @@ using Intersect.Client.Framework.Entities; using Intersect.Client.Framework.Items; using Intersect.Client.General; -using Intersect.Client.Interface.Game; using Intersect.Client.Interface.Game.Chat; using Intersect.Client.Interface.Menu; using Intersect.Client.Items; @@ -25,6 +24,8 @@ using Intersect.Framework; using Intersect.Models; using MapAttribute = Intersect.Enums.MapAttribute; +using Intersect.Client.Interface.Shared; +using Intersect.Network.Packets.Client; namespace Intersect.Client.Networking; @@ -149,7 +150,7 @@ public bool HandlePacket(IPacket packet) } //PingPacket - public void HandlePacket(IPacketSender packetSender, PingPacket packet) + public void HandlePacket(IPacketSender packetSender, Intersect.Network.Packets.Server.PingPacket packet) { if (!packet.RequestingReply) { @@ -553,7 +554,7 @@ public void HandlePacket(IPacketSender packetSender, EntityLeftPacket packet) } //ChatMsgPacket - public void HandlePacket(IPacketSender packetSender, ChatMsgPacket packet) + public void HandlePacket(IPacketSender packetSender, Intersect.Network.Packets.Server.ChatMsgPacket packet) { ChatboxMsg.AddMessage( new ChatboxMsg( @@ -1182,9 +1183,13 @@ public void HandlePacket(IPacketSender packetSender, InputVariablePacket packet) break; } - var iBox = new InputBox( - packet.Title, packet.Prompt, true, type, PacketSender.SendEventInputVariable, - PacketSender.SendEventInputVariableCancel, packet.EventId + _ = new InputBox( + title: packet.Title, + prompt: packet.Prompt, + inputType: type, + userData: packet.EventId, + onSuccess: PacketSender.SendEventInputVariable, + onCancel: PacketSender.SendEventInputVariableCancel ); } @@ -1810,11 +1815,15 @@ public void HandlePacket(IPacketSender packetSender, PartyUpdatePacket packet) } //PartyInvitePacket - public void HandlePacket(IPacketSender packetSender, PartyInvitePacket packet) - { - var iBox = new InputBox( - Strings.Parties.PartyInvite, Strings.Parties.InvitePrompt.ToString(packet.LeaderName), true, - InputBox.InputType.YesNo, PacketSender.SendPartyAccept, PacketSender.SendPartyDecline, packet.LeaderId + public void HandlePacket(IPacketSender packetSender, Intersect.Network.Packets.Server.PartyInvitePacket packet) + { + _ = new InputBox( + title: Strings.Parties.PartyInvite, + prompt: Strings.Parties.InvitePrompt.ToString(packet.LeaderName), + inputType: InputBox.InputType.YesNo, + userData: packet.LeaderId, + onSuccess: PacketSender.SendPartyAccept, + onCancel: PacketSender.SendPartyDecline ); } @@ -1950,12 +1959,15 @@ public void HandlePacket(IPacketSender packetSender, TradeUpdatePacket packet) } //TradeRequestPacket - public void HandlePacket(IPacketSender packetSender, TradeRequestPacket packet) - { - var iBox = new InputBox( - Strings.Trading.TradeRequest, Strings.Trading.RequestPrompt.ToString(packet.PartnerName), true, - InputBox.InputType.YesNo, PacketSender.SendTradeRequestAccept, PacketSender.SendTradeRequestDecline, - packet.PartnerId + public void HandlePacket(IPacketSender packetSender, Intersect.Network.Packets.Server.TradeRequestPacket packet) + { + _ = new InputBox( + title: Strings.Trading.TradeRequest, + prompt: Strings.Trading.RequestPrompt.ToString(packet.PartnerName), + inputType: InputBox.InputType.YesNo, + userData: packet.PartnerId, + onSuccess: PacketSender.SendTradeRequestAccept, + onCancel: PacketSender.SendTradeRequestDecline ); } @@ -2057,10 +2069,13 @@ public void HandlePacket(IPacketSender packetSender, FriendsPacket packet) //FriendRequestPacket public void HandlePacket(IPacketSender packetSender, FriendRequestPacket packet) { - var iBox = new InputBox( - Strings.Friends.Request, Strings.Friends.RequestPrompt.ToString(packet.FriendName), true, - InputBox.InputType.YesNo, PacketSender.SendFriendRequestAccept, PacketSender.SendFriendRequestDecline, - packet.FriendId + _ = new InputBox( + title: Strings.Friends.Request, + prompt: Strings.Friends.RequestPrompt.ToString(packet.FriendName), + inputType: InputBox.InputType.YesNo, + userData: packet.FriendId, + onSuccess: PacketSender.SendFriendRequestAccept, + onCancel: PacketSender.SendFriendRequestDecline ); } @@ -2145,10 +2160,12 @@ public void HandlePacket(IPacketSender packetSender, GuildPacket packet) //GuildInvitePacket public void HandlePacket(IPacketSender packetSender, GuildInvitePacket packet) { - var iBox = new InputBox( - Strings.Guilds.InviteRequestTitle, Strings.Guilds.InviteRequestPrompt.ToString(packet.Inviter, packet.GuildName), true, - InputBox.InputType.YesNo, PacketSender.SendGuildInviteAccept, PacketSender.SendGuildInviteDecline, - null + _ = new InputBox( + title: Strings.Guilds.InviteRequestTitle, + prompt: Strings.Guilds.InviteRequestPrompt.ToString(packet.Inviter, packet.GuildName), + inputType: InputBox.InputType.YesNo, + onSuccess: PacketSender.SendGuildInviteAccept, + onCancel: PacketSender.SendGuildInviteDecline ); } diff --git a/Intersect.Client/Networking/PacketSender.cs b/Intersect.Client/Networking/PacketSender.cs index 902a36cdfe..4483e2c8c2 100644 --- a/Intersect.Client/Networking/PacketSender.cs +++ b/Intersect.Client/Networking/PacketSender.cs @@ -1,6 +1,7 @@ using Intersect.Client.Entities.Events; using Intersect.Client.General; using Intersect.Client.Interface.Game; +using Intersect.Client.Interface.Shared; using Intersect.Client.Maps; using Intersect.Enums; using Intersect.Framework; @@ -142,23 +143,20 @@ public static void SendEventResponse(byte response, Dialog ed) Network.SendPacket(new EventResponsePacket(ed.EventId, response)); } - public static void SendEventInputVariable(object sender, EventArgs e) + public static void SendEventInputVariable(object? sender, EventArgs e) { - Network.SendPacket( - new EventInputVariablePacket( - (Guid) ((InputBox) sender).UserData, (int) ((InputBox) sender).Value, ((InputBox) sender).TextValue - ) - ); + if (sender is InputBox inputBox && inputBox.UserData is Guid eventId) + { + Network.SendPacket(new EventInputVariablePacket(eventId, (int)inputBox.Value, inputBox.TextValue)); + } } - public static void SendEventInputVariableCancel(object sender, EventArgs e) + public static void SendEventInputVariableCancel(object? sender, EventArgs e) { - Network.SendPacket( - new EventInputVariablePacket( - (Guid) ((InputBox) sender).UserData, (int) ((InputBox) sender).Value, ((InputBox) sender).TextValue, - true - ) - ); + if (sender is InputBox inputBox && inputBox.UserData is Guid eventId) + { + Network.SendPacket(new EventInputVariablePacket(eventId, (int)inputBox.Value, inputBox.TextValue, true)); + } } public static void SendCreateAccount(string username, string password, string email) @@ -298,14 +296,20 @@ public static void SendPartyLeave() Network.SendPacket(new PartyLeavePacket()); } - public static void SendPartyAccept(object sender, EventArgs e) + public static void SendPartyAccept(object? sender, EventArgs e) { - Network.SendPacket(new PartyInviteResponsePacket((Guid) ((InputBox) sender).UserData, true)); + if (sender is InputBox inputBox && inputBox.UserData is Guid partyId) + { + Network.SendPacket(new PartyInviteResponsePacket(partyId, true)); + } } - public static void SendPartyDecline(object sender, EventArgs e) + public static void SendPartyDecline(object? sender, EventArgs e) { - Network.SendPacket(new PartyInviteResponsePacket((Guid) ((InputBox) sender).UserData, false)); + if (sender is InputBox inputBox && inputBox.UserData is Guid partyId) + { + Network.SendPacket(new PartyInviteResponsePacket(partyId, false)); + } } public static void SendAcceptQuest(Guid questId) @@ -348,14 +352,20 @@ public static void SendDeclineTrade() Network.SendPacket(new DeclineTradePacket()); } - public static void SendTradeRequestAccept(object sender, EventArgs e) + public static void SendTradeRequestAccept(object? sender, EventArgs e) { - Network.SendPacket(new TradeRequestResponsePacket((Guid) ((InputBox) sender).UserData, true)); + if (sender is InputBox inputBox && inputBox.UserData is Guid tradeId) + { + Network.SendPacket(new TradeRequestResponsePacket(tradeId, true)); + } } - public static void SendTradeRequestDecline(object sender, EventArgs e) + public static void SendTradeRequestDecline(object? sender, EventArgs e) { - Network.SendPacket(new TradeRequestResponsePacket((Guid) ((InputBox) sender).UserData, false)); + if (sender is InputBox inputBox && inputBox.UserData is Guid tradeId) + { + Network.SendPacket(new TradeRequestResponsePacket(tradeId, false)); + } } public static void SendStoreBagItem(int invSlot, int amount, int bagSlot) @@ -393,14 +403,20 @@ public static void SendRemoveFriend(string name) Network.SendPacket(new UpdateFriendsPacket(name, false)); } - public static void SendFriendRequestAccept(Object sender, EventArgs e) + public static void SendFriendRequestAccept(Object? sender, EventArgs e) { - Network.SendPacket(new FriendRequestResponsePacket((Guid) ((InputBox) sender).UserData, true)); + if (sender is InputBox inputBox && inputBox.UserData is Guid requestId) + { + Network.SendPacket(new FriendRequestResponsePacket(requestId, true)); + } } - public static void SendFriendRequestDecline(Object sender, EventArgs e) + public static void SendFriendRequestDecline(Object? sender, EventArgs e) { - Network.SendPacket(new FriendRequestResponsePacket((Guid) ((InputBox) sender).UserData, false)); + if (sender is InputBox inputBox && inputBox.UserData is Guid requestId) + { + Network.SendPacket(new FriendRequestResponsePacket(requestId, false)); + } } public static void SendSelectCharacter(Guid charId) @@ -443,12 +459,12 @@ public static void SendRequestGuild() Network.SendPacket(new RequestGuildPacket()); } - public static void SendGuildInviteAccept(Object sender, EventArgs e) + public static void SendGuildInviteAccept(Object? sender, EventArgs e) { Network.SendPacket(new GuildInviteAcceptPacket()); } - public static void SendGuildInviteDecline(Object sender, EventArgs e) + public static void SendGuildInviteDecline(Object? sender, EventArgs e) { Network.SendPacket(new GuildInviteDeclinePacket()); }