ECS Arcade Machines (#16791)

This commit is contained in:
TemporalOroboros
2023-06-15 04:25:25 -07:00
committed by GitHub
parent b72ab3b00c
commit bc3f42d822
23 changed files with 2116 additions and 1521 deletions

View File

@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -20,16 +21,16 @@ namespace Content.Client.Arcade
{
public sealed class BlockGameMenu : DefaultWindow
{
private static readonly Color OverlayBackgroundColor = new(74,74,81,180);
private static readonly Color OverlayShadowColor = new(0,0,0,83);
private static readonly Color OverlayBackgroundColor = new(74, 74, 81, 180);
private static readonly Color OverlayShadowColor = new(0, 0, 0, 83);
private static readonly Vector2 BlockSize = new(15,15);
private static readonly Vector2 BlockSize = new(15, 15);
private readonly BlockGameBoundUserInterface _owner;
private readonly PanelContainer _mainPanel;
private BoxContainer _gameRootContainer;
private readonly BoxContainer _gameRootContainer;
private GridContainer _gameGrid = default!;
private GridContainer _nextBlockGrid = default!;
private GridContainer _holdBlockGrid = default!;
@@ -82,7 +83,7 @@ namespace Content.Client.Arcade
_gameRootContainer.AddChild(_levelLabel);
_gameRootContainer.AddChild(new Control
{
MinSize = new Vector2(1,5)
MinSize = new Vector2(1, 5)
});
_pointsLabel = new Label
@@ -93,7 +94,7 @@ namespace Content.Client.Arcade
_gameRootContainer.AddChild(_pointsLabel);
_gameRootContainer.AddChild(new Control
{
MinSize = new Vector2(1,10)
MinSize = new Vector2(1, 10)
});
var gameBox = new BoxContainer
@@ -103,12 +104,12 @@ namespace Content.Client.Arcade
gameBox.AddChild(SetupHoldBox(backgroundTexture));
gameBox.AddChild(new Control
{
MinSize = new Vector2(10,1)
MinSize = new Vector2(10, 1)
});
gameBox.AddChild(SetupGameGrid(backgroundTexture));
gameBox.AddChild(new Control
{
MinSize = new Vector2(10,1)
MinSize = new Vector2(10, 1)
});
gameBox.AddChild(SetupNextBox(backgroundTexture));
@@ -116,7 +117,7 @@ namespace Content.Client.Arcade
_gameRootContainer.AddChild(new Control
{
MinSize = new Vector2(1,10)
MinSize = new Vector2(1, 10)
});
_pauseButton = new Button
@@ -176,7 +177,7 @@ namespace Content.Client.Arcade
_owner.SendAction(BlockGamePlayerAction.NewGame);
};
pauseMenuContainer.AddChild(_newGameButton);
pauseMenuContainer.AddChild(new Control{MinSize = new Vector2(1,10)});
pauseMenuContainer.AddChild(new Control { MinSize = new Vector2(1, 10) });
_scoreBoardButton = new Button
{
@@ -185,7 +186,7 @@ namespace Content.Client.Arcade
};
_scoreBoardButton.OnPressed += (e) => _owner.SendAction(BlockGamePlayerAction.ShowHighscores);
pauseMenuContainer.AddChild(_scoreBoardButton);
_unpauseButtonMargin = new Control {MinSize = new Vector2(1, 10), Visible = false};
_unpauseButtonMargin = new Control { MinSize = new Vector2(1, 10), Visible = false };
pauseMenuContainer.AddChild(_unpauseButtonMargin);
_unpauseButton = new Button
@@ -239,13 +240,13 @@ namespace Content.Client.Arcade
VerticalAlignment = VAlignment.Center
};
gameOverMenuContainer.AddChild(new Label{Text = Loc.GetString("blockgame-menu-msg-game-over"),Align = Label.AlignMode.Center});
gameOverMenuContainer.AddChild(new Control{MinSize = new Vector2(1,10)});
gameOverMenuContainer.AddChild(new Label { Text = Loc.GetString("blockgame-menu-msg-game-over"), Align = Label.AlignMode.Center });
gameOverMenuContainer.AddChild(new Control { MinSize = new Vector2(1, 10) });
_finalScoreLabel = new Label{Align = Label.AlignMode.Center};
_finalScoreLabel = new Label { Align = Label.AlignMode.Center };
gameOverMenuContainer.AddChild(_finalScoreLabel);
gameOverMenuContainer.AddChild(new Control{MinSize = new Vector2(1,10)});
gameOverMenuContainer.AddChild(new Control { MinSize = new Vector2(1, 10) });
_finalNewGameButton = new Button
{
@@ -275,7 +276,7 @@ namespace Content.Client.Arcade
HorizontalAlignment = HAlignment.Center
};
var c = new Color(OverlayBackgroundColor.R,OverlayBackgroundColor.G,OverlayBackgroundColor.B,220);
var c = new Color(OverlayBackgroundColor.R, OverlayBackgroundColor.G, OverlayBackgroundColor.B, 220);
var innerBack = new StyleBoxTexture
{
Texture = backgroundTexture,
@@ -298,8 +299,8 @@ namespace Content.Client.Arcade
VerticalAlignment = VAlignment.Center
};
menuContainer.AddChild(new Label{Text = Loc.GetString("blockgame-menu-label-highscores")});
menuContainer.AddChild(new Control{MinSize = new Vector2(1,10)});
menuContainer.AddChild(new Label { Text = Loc.GetString("blockgame-menu-label-highscores") });
menuContainer.AddChild(new Control { MinSize = new Vector2(1, 10) });
var highScoreBox = new BoxContainer
{
@@ -311,14 +312,14 @@ namespace Content.Client.Arcade
Align = Label.AlignMode.Center
};
highScoreBox.AddChild(_localHighscoresLabel);
highScoreBox.AddChild(new Control{MinSize = new Vector2(40,1)});
highScoreBox.AddChild(new Control { MinSize = new Vector2(40, 1) });
_globalHighscoresLabel = new Label
{
Align = Label.AlignMode.Center
};
highScoreBox.AddChild(_globalHighscoresLabel);
menuContainer.AddChild(highScoreBox);
menuContainer.AddChild(new Control{MinSize = new Vector2(1,10)});
menuContainer.AddChild(new Control { MinSize = new Vector2(1, 10) });
_highscoreBackButton = new Button
{
Text = Loc.GetString("blockgame-menu-button-back"),
@@ -359,7 +360,7 @@ namespace Content.Client.Arcade
HSeparationOverride = 1,
VSeparationOverride = 1
};
UpdateBlocks(new BlockGameBlock[0]);
UpdateBlocks(Array.Empty<BlockGameBlock>());
var back = new StyleBoxTexture
{
@@ -376,7 +377,7 @@ namespace Content.Client.Arcade
};
var backgroundPanel = new PanelContainer
{
PanelOverride = new StyleBoxFlat{BackgroundColor = Color.FromHex("#86868d")}
PanelOverride = new StyleBoxFlat { BackgroundColor = Color.FromHex("#86868d") }
};
backgroundPanel.AddChild(_gameGrid);
gamePanel.AddChild(backgroundPanel);
@@ -416,7 +417,7 @@ namespace Content.Client.Arcade
nextBlockPanel.AddChild(nextCenterContainer);
grid.AddChild(nextBlockPanel);
grid.AddChild(new Label{Text = Loc.GetString("blockgame-menu-label-next"), Align = Label.AlignMode.Center});
grid.AddChild(new Label { Text = Loc.GetString("blockgame-menu-label-next"), Align = Label.AlignMode.Center });
return grid;
}
@@ -454,15 +455,17 @@ namespace Content.Client.Arcade
holdBlockPanel.AddChild(holdCenterContainer);
grid.AddChild(holdBlockPanel);
grid.AddChild(new Label{Text = Loc.GetString("blockgame-menu-label-hold"), Align = Label.AlignMode.Center});
grid.AddChild(new Label { Text = Loc.GetString("blockgame-menu-label-hold"), Align = Label.AlignMode.Center });
return grid;
}
protected override void KeyboardFocusExited()
{
if (!IsOpen) return;
if(_gameOver) return;
if (!IsOpen)
return;
if (_gameOver)
return;
TryPause();
}
@@ -480,7 +483,8 @@ namespace Content.Client.Arcade
public void SetScreen(BlockGameMessages.BlockGameScreen screen)
{
if (_gameOver) return;
if (_gameOver)
return;
switch (screen)
{
@@ -512,9 +516,12 @@ namespace Content.Client.Arcade
private void CloseMenus()
{
if(_mainPanel.Children.Contains(_menuRootContainer)) _mainPanel.RemoveChild(_menuRootContainer);
if(_mainPanel.Children.Contains(_gameOverRootContainer)) _mainPanel.RemoveChild(_gameOverRootContainer);
if(_mainPanel.Children.Contains(_highscoresRootContainer)) _mainPanel.RemoveChild(_highscoresRootContainer);
if (_mainPanel.Children.Contains(_menuRootContainer))
_mainPanel.RemoveChild(_menuRootContainer);
if (_mainPanel.Children.Contains(_gameOverRootContainer))
_mainPanel.RemoveChild(_gameOverRootContainer);
if (_mainPanel.Children.Contains(_highscoresRootContainer))
_mainPanel.RemoveChild(_highscoresRootContainer);
}
public void SetGameoverInfo(int amount, int? localPlacement, int? globalPlacement)
@@ -563,72 +570,56 @@ namespace Content.Client.Arcade
{
base.KeyBindDown(args);
if(!_isPlayer || args.Handled) return;
if (!_isPlayer || args.Handled)
return;
if (args.Function == ContentKeyFunctions.ArcadeLeft)
{
else if (args.Function == ContentKeyFunctions.ArcadeLeft)
_owner.SendAction(BlockGamePlayerAction.StartLeft);
}
else if (args.Function == ContentKeyFunctions.ArcadeRight)
{
_owner.SendAction(BlockGamePlayerAction.StartRight);
}
else if (args.Function == ContentKeyFunctions.ArcadeUp)
{
_owner.SendAction(BlockGamePlayerAction.Rotate);
}
else if (args.Function == ContentKeyFunctions.Arcade3)
{
_owner.SendAction(BlockGamePlayerAction.CounterRotate);
}
else if (args.Function == ContentKeyFunctions.ArcadeDown)
{
_owner.SendAction(BlockGamePlayerAction.SoftdropStart);
}
else if (args.Function == ContentKeyFunctions.Arcade2)
{
_owner.SendAction(BlockGamePlayerAction.Hold);
}
else if (args.Function == ContentKeyFunctions.Arcade1)
{
_owner.SendAction(BlockGamePlayerAction.Harddrop);
}
}
protected override void KeyBindUp(GUIBoundKeyEventArgs args)
{
base.KeyBindUp(args);
if(!_isPlayer || args.Handled) return;
if (!_isPlayer || args.Handled)
return;
if (args.Function == ContentKeyFunctions.ArcadeLeft)
{
else if (args.Function == ContentKeyFunctions.ArcadeLeft)
_owner.SendAction(BlockGamePlayerAction.EndLeft);
}
else if (args.Function == ContentKeyFunctions.ArcadeRight)
{
_owner.SendAction(BlockGamePlayerAction.EndRight);
}else if (args.Function == ContentKeyFunctions.ArcadeDown)
{
else if (args.Function == ContentKeyFunctions.ArcadeDown)
_owner.SendAction(BlockGamePlayerAction.SoftdropEnd);
}
}
public void UpdateNextBlock(BlockGameBlock[] blocks)
{
_nextBlockGrid.RemoveAllChildren();
if (blocks.Length == 0) return;
if (blocks.Length == 0)
return;
var columnCount = blocks.Max(b => b.Position.X) + 1;
var rowCount = blocks.Max(b => b.Position.Y) + 1;
_nextBlockGrid.Columns = columnCount;
for (int y = 0; y < rowCount; y++)
for (var y = 0; y < rowCount; y++)
{
for (int x = 0; x < columnCount; x++)
for (var x = 0; x < columnCount; x++)
{
var c = GetColorForPosition(blocks, x, y);
_nextBlockGrid.AddChild(new PanelContainer
{
PanelOverride = new StyleBoxFlat {BackgroundColor = c},
PanelOverride = new StyleBoxFlat { BackgroundColor = c },
MinSize = BlockSize,
RectDrawClipMargin = 0
});
@@ -639,18 +630,19 @@ namespace Content.Client.Arcade
public void UpdateHeldBlock(BlockGameBlock[] blocks)
{
_holdBlockGrid.RemoveAllChildren();
if (blocks.Length == 0) return;
if (blocks.Length == 0)
return;
var columnCount = blocks.Max(b => b.Position.X) + 1;
var rowCount = blocks.Max(b => b.Position.Y) + 1;
_holdBlockGrid.Columns = columnCount;
for (int y = 0; y < rowCount; y++)
for (var y = 0; y < rowCount; y++)
{
for (int x = 0; x < columnCount; x++)
for (var x = 0; x < columnCount; x++)
{
var c = GetColorForPosition(blocks, x, y);
_holdBlockGrid.AddChild(new PanelContainer
{
PanelOverride = new StyleBoxFlat {BackgroundColor = c},
PanelOverride = new StyleBoxFlat { BackgroundColor = c },
MinSize = BlockSize,
RectDrawClipMargin = 0
});
@@ -661,14 +653,14 @@ namespace Content.Client.Arcade
public void UpdateBlocks(BlockGameBlock[] blocks)
{
_gameGrid.RemoveAllChildren();
for (int y = 0; y < 20; y++)
for (var y = 0; y < 20; y++)
{
for (int x = 0; x < 10; x++)
for (var x = 0; x < 10; x++)
{
var c = GetColorForPosition(blocks, x, y);
_gameGrid.AddChild(new PanelContainer
{
PanelOverride = new StyleBoxFlat {BackgroundColor = c},
PanelOverride = new StyleBoxFlat { BackgroundColor = c },
MinSize = BlockSize,
RectDrawClipMargin = 0
});
@@ -676,9 +668,9 @@ namespace Content.Client.Arcade
}
}
private Color GetColorForPosition(BlockGameBlock[] blocks, int x, int y)
private static Color GetColorForPosition(BlockGameBlock[] blocks, int x, int y)
{
Color c = Color.Transparent;
var c = Color.Transparent;
var matchingBlock = blocks.FirstOrNull(b => b.Position.X == x && b.Position.Y == y);
if (matchingBlock.HasValue)
{