Remove some BUI boilerplate (#28399)

* Remove some BUI boilerplate

- The disposals overrides got removed due to the helper method handling it.
- Replace window creation with CreateWindow helper.
- Fixed some stinky code which would cause exceptions.

* More

* moar

* weh

* done

* More BUIs

* More updates

* weh

* moar

* look who it is

* weh

* merge

* weh

* fixes
This commit is contained in:
metalgearsloth
2024-07-20 15:40:16 +10:00
committed by GitHub
parent 4aba9ec131
commit cbf329a82d
137 changed files with 1094 additions and 1753 deletions

View File

@@ -28,8 +28,6 @@ namespace Content.Client.Arcade
private static readonly Vector2 BlockSize = new(15, 15);
private readonly BlockGameBoundUserInterface _owner;
private readonly PanelContainer _mainPanel;
private readonly BoxContainer _gameRootContainer;
@@ -58,10 +56,11 @@ namespace Content.Client.Arcade
private bool _isPlayer = false;
private bool _gameOver = false;
public BlockGameMenu(BlockGameBoundUserInterface owner)
public event Action<BlockGamePlayerAction>? OnAction;
public BlockGameMenu()
{
Title = Loc.GetString("blockgame-menu-title");
_owner = owner;
MinSize = SetSize = new Vector2(410, 490);
@@ -176,7 +175,7 @@ namespace Content.Client.Arcade
};
_newGameButton.OnPressed += (e) =>
{
_owner.SendAction(BlockGamePlayerAction.NewGame);
OnAction?.Invoke(BlockGamePlayerAction.NewGame);
};
pauseMenuContainer.AddChild(_newGameButton);
pauseMenuContainer.AddChild(new Control { MinSize = new Vector2(1, 10) });
@@ -186,7 +185,10 @@ namespace Content.Client.Arcade
Text = Loc.GetString("blockgame-menu-button-scoreboard"),
TextAlign = Label.AlignMode.Center
};
_scoreBoardButton.OnPressed += (e) => _owner.SendAction(BlockGamePlayerAction.ShowHighscores);
_scoreBoardButton.OnPressed += (e) =>
{
OnAction?.Invoke(BlockGamePlayerAction.ShowHighscores);
};
pauseMenuContainer.AddChild(_scoreBoardButton);
_unpauseButtonMargin = new Control { MinSize = new Vector2(1, 10), Visible = false };
pauseMenuContainer.AddChild(_unpauseButtonMargin);
@@ -199,7 +201,7 @@ namespace Content.Client.Arcade
};
_unpauseButton.OnPressed += (e) =>
{
_owner.SendAction(BlockGamePlayerAction.Unpause);
OnAction?.Invoke(BlockGamePlayerAction.Unpause);
};
pauseMenuContainer.AddChild(_unpauseButton);
@@ -257,7 +259,7 @@ namespace Content.Client.Arcade
};
_finalNewGameButton.OnPressed += (e) =>
{
_owner.SendAction(BlockGamePlayerAction.NewGame);
OnAction?.Invoke(BlockGamePlayerAction.NewGame);
};
gameOverMenuContainer.AddChild(_finalNewGameButton);
@@ -327,7 +329,10 @@ namespace Content.Client.Arcade
Text = Loc.GetString("blockgame-menu-button-back"),
TextAlign = Label.AlignMode.Center
};
_highscoreBackButton.OnPressed += (e) => _owner.SendAction(BlockGamePlayerAction.Pause);
_highscoreBackButton.OnPressed += (e) =>
{
OnAction?.Invoke(BlockGamePlayerAction.Pause);
};
menuContainer.AddChild(_highscoreBackButton);
menuInnerPanel.AddChild(menuContainer);
@@ -473,7 +478,7 @@ namespace Content.Client.Arcade
private void TryPause()
{
_owner.SendAction(BlockGamePlayerAction.Pause);
OnAction?.Invoke(BlockGamePlayerAction.Pause);
}
public void SetStarted()
@@ -576,19 +581,19 @@ namespace Content.Client.Arcade
return;
else if (args.Function == ContentKeyFunctions.ArcadeLeft)
_owner.SendAction(BlockGamePlayerAction.StartLeft);
OnAction?.Invoke(BlockGamePlayerAction.StartLeft);
else if (args.Function == ContentKeyFunctions.ArcadeRight)
_owner.SendAction(BlockGamePlayerAction.StartRight);
OnAction?.Invoke(BlockGamePlayerAction.StartRight);
else if (args.Function == ContentKeyFunctions.ArcadeUp)
_owner.SendAction(BlockGamePlayerAction.Rotate);
OnAction?.Invoke(BlockGamePlayerAction.Rotate);
else if (args.Function == ContentKeyFunctions.Arcade3)
_owner.SendAction(BlockGamePlayerAction.CounterRotate);
OnAction?.Invoke(BlockGamePlayerAction.CounterRotate);
else if (args.Function == ContentKeyFunctions.ArcadeDown)
_owner.SendAction(BlockGamePlayerAction.SoftdropStart);
OnAction?.Invoke(BlockGamePlayerAction.SoftdropStart);
else if (args.Function == ContentKeyFunctions.Arcade2)
_owner.SendAction(BlockGamePlayerAction.Hold);
OnAction?.Invoke(BlockGamePlayerAction.Hold);
else if (args.Function == ContentKeyFunctions.Arcade1)
_owner.SendAction(BlockGamePlayerAction.Harddrop);
OnAction?.Invoke(BlockGamePlayerAction.Harddrop);
}
protected override void KeyBindUp(GUIBoundKeyEventArgs args)
@@ -599,11 +604,11 @@ namespace Content.Client.Arcade
return;
else if (args.Function == ContentKeyFunctions.ArcadeLeft)
_owner.SendAction(BlockGamePlayerAction.EndLeft);
OnAction?.Invoke(BlockGamePlayerAction.EndLeft);
else if (args.Function == ContentKeyFunctions.ArcadeRight)
_owner.SendAction(BlockGamePlayerAction.EndRight);
OnAction?.Invoke(BlockGamePlayerAction.EndRight);
else if (args.Function == ContentKeyFunctions.ArcadeDown)
_owner.SendAction(BlockGamePlayerAction.SoftdropEnd);
OnAction?.Invoke(BlockGamePlayerAction.SoftdropEnd);
}
public void UpdateNextBlock(BlockGameBlock[] blocks)