-
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,7 @@ public partial class Menu | |
|
||
private readonly ImagePanel mMenuBackground; | ||
|
||
private readonly Button mMenuButton; | ||
public readonly Button mMenuButton; | ||
|
||
//Menu Container | ||
private readonly ImagePanel mMenuContainer; | ||
|
@@ -357,7 +357,16 @@ public bool HasWindowsOpen() | |
//Input Handlers | ||
private static void MenuButtonClicked(Base sender, ClickedEventArgs arguments) | ||
{ | ||
Interface.GameUi?.EscapeMenu?.ToggleHidden(); | ||
var simplifiedEscapeMenuSetting = Globals.Database.SimplifiedEscapeMenu; | ||
|
||
if (simplifiedEscapeMenuSetting) | ||
{ | ||
Interface.GameUi?.SimplifiedEscapeMenu?.ToggleHidden(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead I think the button should be passed as a parameter here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. private void MenuButtonClicked(Base sender, ClickedEventArgs arguments)
{
var simplifiedEscapeMenuSetting = Globals.Database.SimplifiedEscapeMenu;
if (simplifiedEscapeMenuSetting)
{
Interface.GameUi?.SimplifiedEscapeMenu?.ToggleHidden(mMenuButton);
}
else
{
Interface.GameUi?.EscapeMenu?.ToggleHidden();
}
} |
||
} | ||
else | ||
{ | ||
Interface.GameUi?.EscapeMenu?.ToggleHidden(); | ||
} | ||
} | ||
|
||
private void PartyBtn_Clicked(Base sender, ClickedEventArgs arguments) | ||
|
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 override void ToggleHidden() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the override version should call this should become There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. used 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();
}
} |
||
{ | ||
if (!_settingsWindow.IsHidden) | ||
{ | ||
return; | ||
} | ||
|
||
if (this.IsHidden) | ||
{ | ||
// Position the context menu within the game canvas if near borders. | ||
var menuPosX = Interface.GameUi.GameMenu.mMenuButton.LocalPosToCanvas(new Point(0, 0)).X; | ||
var menuPosY = Interface.GameUi.GameMenu.mMenuButton.LocalPosToCanvas(new Point(0, 0)).Y; | ||
var newX = menuPosX; | ||
var newY = menuPosY + Interface.GameUi.GameMenu.mMenuButton.Height + 6; | ||
|
||
if (newX + Width >= Canvas?.Width) | ||
{ | ||
newX = menuPosX - Width + Interface.GameUi.GameMenu.mMenuButton.Width; | ||
} | ||
|
||
if (newY + Height >= Canvas?.Height) | ||
{ | ||
newY = menuPosY - Height - 6; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Position calculations should only happen if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
||
SizeToChildren(); | ||
Open(Pos.None); | ||
SetPosition(newX, newY); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. added an early return within method if target is null already 👍🏽 |
||
} | ||
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; | ||
} | ||
} |
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.
I don't think this should be done