ui基本完毕,修了一大把的bug
This commit is contained in:
@@ -7,6 +7,8 @@ public class materialPrefab : MonoBehaviour
|
||||
{
|
||||
[Header("imgs")]
|
||||
public Image boarder;
|
||||
public Image qualityBorder;
|
||||
public Sprite[] qualityBorderSprites;
|
||||
public Image materialImg;
|
||||
public Button materialButton;
|
||||
public TextMeshProUGUI materialAmount;
|
||||
@@ -23,7 +25,7 @@ public class materialPrefab : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void Bind(Sprite sprite, string displayName, string amountText, bool selected, bool interactable, Action onClick)
|
||||
public void Bind(Sprite sprite, string displayName, string amountText, ItemRarity rarity, bool selected, bool interactable, Action onClick)
|
||||
{
|
||||
clickAction = onClick;
|
||||
|
||||
@@ -43,6 +45,7 @@ public class materialPrefab : MonoBehaviour
|
||||
materialAmount.text = amountText ?? string.Empty;
|
||||
}
|
||||
|
||||
ApplyQualityBorder(rarity);
|
||||
SetSelected(selected);
|
||||
|
||||
if (materialButton != null)
|
||||
@@ -51,13 +54,23 @@ public class materialPrefab : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void BindOwnedRequired(Sprite sprite, string displayName, int ownedAmount, int requiredAmount, bool selected, bool interactable, Action onClick)
|
||||
public void Bind(Sprite sprite, string displayName, string amountText, bool selected, bool interactable, Action onClick)
|
||||
{
|
||||
Bind(sprite, displayName, amountText, ItemRarity.None, selected, interactable, onClick);
|
||||
}
|
||||
|
||||
public void BindOwnedRequired(Sprite sprite, string displayName, int ownedAmount, int requiredAmount, ItemRarity rarity, bool selected, bool interactable, Action onClick)
|
||||
{
|
||||
string ownedText = ownedAmount < requiredAmount
|
||||
? $"<color=#FF4D4D>{Mathf.Max(0, ownedAmount)}</color>"
|
||||
: Mathf.Max(0, ownedAmount).ToString();
|
||||
string amountText = $"{ownedText}/{Mathf.Max(0, requiredAmount)}";
|
||||
Bind(sprite, displayName, amountText, selected, interactable, onClick);
|
||||
Bind(sprite, displayName, amountText, rarity, selected, interactable, onClick);
|
||||
}
|
||||
|
||||
public void BindOwnedRequired(Sprite sprite, string displayName, int ownedAmount, int requiredAmount, bool selected, bool interactable, Action onClick)
|
||||
{
|
||||
BindOwnedRequired(sprite, displayName, ownedAmount, requiredAmount, ItemRarity.None, selected, interactable, onClick);
|
||||
}
|
||||
|
||||
public void SetSelected(bool selected)
|
||||
@@ -68,6 +81,41 @@ public class materialPrefab : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyQualityBorder(ItemRarity rarity)
|
||||
{
|
||||
if (qualityBorder == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Sprite sprite = ResolveQualityBorderSprite(rarity);
|
||||
qualityBorder.sprite = sprite;
|
||||
qualityBorder.enabled = sprite != null;
|
||||
}
|
||||
|
||||
private Sprite ResolveQualityBorderSprite(ItemRarity rarity)
|
||||
{
|
||||
if (qualityBorderSprites != null && qualityBorderSprites.Length > 0)
|
||||
{
|
||||
int enumIndex = (int)rarity;
|
||||
if (enumIndex >= 0 && enumIndex < qualityBorderSprites.Length)
|
||||
{
|
||||
Sprite sprite = qualityBorderSprites[enumIndex];
|
||||
if (sprite != null)
|
||||
{
|
||||
return sprite;
|
||||
}
|
||||
}
|
||||
|
||||
if (qualityBorderSprites[0] != null)
|
||||
{
|
||||
return qualityBorderSprites[0];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void HandleClick()
|
||||
{
|
||||
if (materialButton != null && !materialButton.interactable)
|
||||
|
||||
Reference in New Issue
Block a user