[Add] Menu with configs and size fix

This commit is contained in:
2026-06-06 23:48:55 +07:00
parent 7104089c00
commit a9767c5301
29 changed files with 453 additions and 153 deletions
+20 -2
View File
@@ -12,9 +12,11 @@ namespace Minesweeper.Presentation.Views
{
private const string ContentImagePath = "Content/Image";
private const string ContentLabelPath = "Content/Text (TMP)";
private const string ContentPath = "Content";
[SerializeField] private Button button;
[SerializeField] private Image backgroundImage;
[SerializeField] private RectTransform contentRoot;
[SerializeField] private Image contentImage;
[SerializeField] private TMP_Text label;
@@ -28,10 +30,11 @@ namespace Minesweeper.Presentation.Views
public event Action PressStarted;
public event Action PressEnded;
public void Bind(Button button, Image backgroundImage, Image contentImage, TMP_Text label)
public void Bind(Button button, Image backgroundImage, RectTransform contentRoot, Image contentImage, TMP_Text label)
{
this.button = button;
this.backgroundImage = backgroundImage;
this.contentRoot = contentRoot;
this.contentImage = contentImage;
this.label = label;
}
@@ -48,6 +51,15 @@ namespace Minesweeper.Presentation.Views
backgroundImage = GetComponent<Image>();
}
if (contentRoot == null)
{
var contentTransform = transform.Find(ContentPath);
if (contentTransform != null)
{
contentRoot = contentTransform.GetComponent<RectTransform>();
}
}
if (contentImage == null)
{
var contentImageTransform = transform.Find(ContentImagePath);
@@ -82,12 +94,18 @@ namespace Minesweeper.Presentation.Views
}
}
public void Render(BoardCellData cell, MinesweeperUiConfig config, float pixelsPerUnitMultiplier, bool revealUnflaggedMines)
public void Render(BoardCellData cell, MinesweeperUiConfig config, float pixelsPerUnitMultiplier, float contentPadding, bool revealUnflaggedMines)
{
gameObject.name = $"bt_{cell.X}_{cell.Y}_{cell.DisplayValue}";
isOpened = cell.IsOpened;
var revealMine = revealUnflaggedMines && cell.IsMine && !cell.IsFlagged;
if (contentRoot != null)
{
contentRoot.offsetMin = new Vector2(contentPadding, contentPadding);
contentRoot.offsetMax = new Vector2(-contentPadding, -contentPadding);
}
if (backgroundImage != null)
{
backgroundImage.pixelsPerUnitMultiplier = pixelsPerUnitMultiplier;