[Fix] Board Optimization, Fix Screen Loading
This commit is contained in:
@@ -39,6 +39,7 @@ namespace Minesweeper.Presentation.Views
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
gameObject.name = $"bt_{x}_{y}";
|
||||
}
|
||||
|
||||
public void SetInputEnabled(bool enabled)
|
||||
@@ -52,7 +53,6 @@ namespace Minesweeper.Presentation.Views
|
||||
|
||||
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;
|
||||
|
||||
@@ -90,14 +90,14 @@ namespace Minesweeper.Presentation.Views
|
||||
|
||||
if (contentImage != null)
|
||||
{
|
||||
contentImage.gameObject.SetActive(showFlag || (showMine && !showMineAsText));
|
||||
SetActiveIfChanged(contentImage.gameObject, showFlag || (showMine && !showMineAsText));
|
||||
if (showFlag)
|
||||
{
|
||||
contentImage.sprite = config.FlagSprite;
|
||||
SetSpriteIfChanged(contentImage, config.FlagSprite);
|
||||
}
|
||||
else if (showMine)
|
||||
{
|
||||
contentImage.sprite = config.MineSprite;
|
||||
SetSpriteIfChanged(contentImage, config.MineSprite);
|
||||
}
|
||||
|
||||
contentImage.color = Color.white;
|
||||
@@ -105,12 +105,36 @@ namespace Minesweeper.Presentation.Views
|
||||
|
||||
if (label != null)
|
||||
{
|
||||
label.gameObject.SetActive(showNumber || showMineAsText);
|
||||
label.text = showMineAsText ? "M" : showNumber ? cell.NeighborMines.ToString() : string.Empty;
|
||||
SetActiveIfChanged(label.gameObject, showNumber || showMineAsText);
|
||||
SetTextIfChanged(label, showMineAsText ? "M" : showNumber ? cell.NeighborMines.ToString() : string.Empty);
|
||||
label.color = config.GetNumberTextColor(cell.NeighborMines);
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetActiveIfChanged(GameObject target, bool active)
|
||||
{
|
||||
if (target.activeSelf != active)
|
||||
{
|
||||
target.SetActive(active);
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetSpriteIfChanged(Image image, Sprite sprite)
|
||||
{
|
||||
if (image.sprite != sprite)
|
||||
{
|
||||
image.sprite = sprite;
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetTextIfChanged(TMP_Text text, string value)
|
||||
{
|
||||
if (text.text != value)
|
||||
{
|
||||
text.text = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
if (!inputEnabled)
|
||||
|
||||
Reference in New Issue
Block a user