-
Notifications
You must be signed in to change notification settings - Fork 363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: simplified escape menu #2395
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
167 changes: 167 additions & 0 deletions
167
Intersect.Client/Interface/Game/SimplifiedEscapeMenu.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
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.General; | ||
using Intersect.Client.Interface.Shared; | ||
using Intersect.Client.Localization; | ||
using Intersect.Utilities; | ||
|
||
namespace Intersect.Client.Interface.Game; | ||
|
||
public sealed partial class SimplifiedEscapeMenu : Framework.Gwen.Control.Menu | ||
{ | ||
private readonly SettingsWindow _settingsWindow; | ||
private readonly MenuItem _settings; | ||
private readonly MenuItem _character; | ||
private readonly MenuItem _logout; | ||
private readonly MenuItem _exit; | ||
|
||
public SimplifiedEscapeMenu(Canvas gameCanvas) : base(gameCanvas, nameof(SimplifiedEscapeMenu)) | ||
{ | ||
IsHidden = true; | ||
IconMarginDisabled = true; | ||
_settingsWindow = new SettingsWindow(gameCanvas, null, null); | ||
|
||
Children.Clear(); | ||
|
||
_settings = AddItem(Strings.EscapeMenu.Settings); | ||
_character = AddItem(Strings.EscapeMenu.CharacterSelect); | ||
_logout = AddItem(Strings.EscapeMenu.Logout); | ||
_exit = AddItem(Strings.EscapeMenu.ExitToDesktop); | ||
|
||
_settings.Clicked += OpenSettingsWindow; | ||
_character.Clicked += LogoutToCharacterSelectSelectClicked; | ||
_logout.Clicked += LogoutToMainToMainMenuClicked; | ||
_exit.Clicked += ExitToDesktopToDesktopClicked; | ||
|
||
LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer?.GetResolutionString()); | ||
} | ||
|
||
public void ToggleHidden(Button? target) | ||
{ | ||
if (!_settingsWindow.IsHidden || target == null) | ||
{ | ||
return; | ||
} | ||
|
||
if (this.IsHidden) | ||
{ | ||
// Position the context menu within the game canvas if near borders. | ||
var menuPosX = target.LocalPosToCanvas(new Point(0, 0)).X; | ||
var menuPosY = target.LocalPosToCanvas(new Point(0, 0)).Y; | ||
var newX = menuPosX; | ||
var newY = menuPosY + target.Height + 6; | ||
|
||
if (newX + Width >= Canvas?.Width) | ||
{ | ||
newX = menuPosX - Width + target.Width; | ||
} | ||
|
||
if (newY + Height >= Canvas?.Height) | ||
{ | ||
newY = menuPosY - Height - 6; | ||
} | ||
|
||
SizeToChildren(); | ||
Open(Pos.None); | ||
SetPosition(newX, newY); | ||
} | ||
else | ||
{ | ||
Close(); | ||
} | ||
} | ||
|
||
private void LogoutToCharacterSelectSelectClicked(Base sender, ClickedEventArgs arguments) | ||
{ | ||
if (Globals.Me?.CombatTimer > Timing.Global.Milliseconds) | ||
{ | ||
_ = new InputBox( | ||
title: Strings.Combat.WarningTitle, | ||
prompt: Strings.Combat.WarningCharacterSelect, | ||
inputType: InputBox.InputType.YesNo, | ||
onSuccess: LogoutToCharacterSelect | ||
); | ||
} | ||
else | ||
{ | ||
LogoutToCharacterSelect(null, null); | ||
} | ||
} | ||
|
||
private void LogoutToMainToMainMenuClicked(Base sender, ClickedEventArgs arguments) | ||
{ | ||
if (Globals.Me?.CombatTimer > Timing.Global.Milliseconds) | ||
{ | ||
_ = new InputBox( | ||
title: Strings.Combat.WarningTitle, | ||
prompt: Strings.Combat.WarningLogout, | ||
inputType: InputBox.InputType.YesNo, | ||
onSuccess: LogoutToMainMenu | ||
); | ||
} | ||
else | ||
{ | ||
LogoutToMainMenu(null, null); | ||
} | ||
} | ||
|
||
private void ExitToDesktopToDesktopClicked(Base sender, ClickedEventArgs arguments) | ||
{ | ||
if (Globals.Me?.CombatTimer > Timing.Global.Milliseconds) | ||
{ | ||
_ = new InputBox( | ||
title: Strings.Combat.WarningTitle, | ||
prompt: Strings.Combat.WarningExitDesktop, | ||
inputType: InputBox.InputType.YesNo, | ||
onSuccess: ExitToDesktop | ||
); | ||
} | ||
else | ||
{ | ||
ExitToDesktop(null, null); | ||
} | ||
} | ||
|
||
private void OpenSettingsWindow(object? sender, EventArgs? e) | ||
{ | ||
if (!_settingsWindow.IsHidden) | ||
{ | ||
return; | ||
} | ||
|
||
_settingsWindow.Show(); | ||
} | ||
|
||
private static void LogoutToCharacterSelect(object? sender, EventArgs? e) | ||
{ | ||
if (Globals.Me != null) | ||
{ | ||
Globals.Me.CombatTimer = 0; | ||
} | ||
|
||
Main.Logout(true); | ||
} | ||
|
||
private static void LogoutToMainMenu(object? sender, EventArgs? e) | ||
{ | ||
if (Globals.Me != null) | ||
{ | ||
Globals.Me.CombatTimer = 0; | ||
} | ||
|
||
Main.Logout(false); | ||
} | ||
|
||
private static void ExitToDesktop(object? sender, EventArgs? e) | ||
{ | ||
if (Globals.Me != null) | ||
{ | ||
Globals.Me.CombatTimer = 0; | ||
} | ||
|
||
Globals.IsRunning = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only set position if target wasn't null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added an early return within method if target is null already 👍🏽