New card UI, new visual config, new card definitions, new working editor window for authoring!
This commit is contained in:
@@ -22,15 +22,6 @@ namespace AppleHills.Data.CardSystem
|
||||
public CardZone Zone => _definition?.Zone ?? CardZone.AppleHills;
|
||||
public int CollectionIndex => _definition?.CollectionIndex ?? 0;
|
||||
public Sprite CardImage => _definition?.CardImage;
|
||||
|
||||
// Derived properties
|
||||
public Color BackgroundColor => _definition?.GetBackgroundColor() ?? Color.white;
|
||||
|
||||
// Get frame shape based on rarity
|
||||
public string GetFrameShapeName()
|
||||
{
|
||||
return $"Frame_{Rarity}";
|
||||
}
|
||||
|
||||
// Default constructor
|
||||
public CardData()
|
||||
@@ -97,11 +88,9 @@ namespace AppleHills.Data.CardSystem
|
||||
// Enums for card attributes
|
||||
public enum CardRarity
|
||||
{
|
||||
Common = 0,
|
||||
Uncommon = 1,
|
||||
Rare = 2,
|
||||
Epic = 3,
|
||||
Legendary = 4
|
||||
Normal = 0,
|
||||
Rare = 1,
|
||||
Legendary = 2
|
||||
}
|
||||
|
||||
public enum CardZone
|
||||
|
||||
@@ -16,6 +16,13 @@ namespace AppleHills.Data.CardSystem
|
||||
|
||||
[Header("Basic Info")]
|
||||
public string Name;
|
||||
|
||||
[Tooltip("Use a custom file name instead of the card name")]
|
||||
public bool UseCustomFileName = false;
|
||||
|
||||
[Tooltip("Custom file name (only used if UseCustomFileName is true)")]
|
||||
public string CustomFileName = "";
|
||||
|
||||
[TextArea(3, 5)]
|
||||
public string Description;
|
||||
public CardRarity Rarity;
|
||||
@@ -34,29 +41,6 @@ namespace AppleHills.Data.CardSystem
|
||||
{
|
||||
return new CardData(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the background color for this card based on its zone
|
||||
/// </summary>
|
||||
public Color GetBackgroundColor()
|
||||
{
|
||||
// Colors based on zone
|
||||
switch (Zone)
|
||||
{
|
||||
case CardZone.AppleHills:
|
||||
return new Color(0.8f, 0.9f, 0.8f); // Light green
|
||||
case CardZone.Quarry:
|
||||
return new Color(0.85f, 0.8f, 0.7f); // Sandy brown
|
||||
case CardZone.Forest:
|
||||
return new Color(0.6f, 0.8f, 0.6f); // Forest green
|
||||
case CardZone.Mountain:
|
||||
return new Color(0.7f, 0.7f, 0.9f); // Bluish
|
||||
case CardZone.Beach:
|
||||
return new Color(0.9f, 0.85f, 0.7f); // Sandy yellow
|
||||
default:
|
||||
return Color.white;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
|
||||
@@ -259,14 +259,12 @@ namespace Data.CardSystem
|
||||
/// </summary>
|
||||
private CardRarity DetermineRandomRarity()
|
||||
{
|
||||
// Simple weighted random - can be adjusted for better distribution
|
||||
// Weighted random for 3 rarities
|
||||
float rand = UnityEngine.Random.value;
|
||||
|
||||
if (rand < 0.6f) return CardRarity.Common;
|
||||
if (rand < 0.85f) return CardRarity.Uncommon;
|
||||
if (rand < 0.95f) return CardRarity.Rare;
|
||||
if (rand < 0.99f) return CardRarity.Epic;
|
||||
return CardRarity.Legendary;
|
||||
|
||||
if (rand < 0.70f) return CardRarity.Normal; // 70% chance
|
||||
if (rand < 0.95f) return CardRarity.Rare; // 25% chance
|
||||
return CardRarity.Legendary; // 5% chance
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,37 +7,47 @@ namespace AppleHills.Data.CardSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// ScriptableObject containing visual configuration for card display
|
||||
/// Maps card rarities to colors and zones to colors/shapes
|
||||
/// Maps card rarities to frames/overlays and zones to backgrounds/shapes
|
||||
/// </summary>
|
||||
[CreateAssetMenu(fileName = "CardVisualConfig", menuName = "AppleHills/Card System/Visual Config")]
|
||||
public class CardVisualConfig : ScriptableObject
|
||||
{
|
||||
[Serializable]
|
||||
public class RarityColorMapping
|
||||
public class RarityVisualMapping
|
||||
{
|
||||
public CardRarity rarity;
|
||||
public Color color = Color.white;
|
||||
[Tooltip("Frame image for this rarity")]
|
||||
public Sprite frame;
|
||||
[Tooltip("Overlay image for this rarity (can be null)")]
|
||||
public Sprite overlay;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class ZoneVisualMapping
|
||||
{
|
||||
public CardZone zone;
|
||||
public Color color = Color.white;
|
||||
public Sprite backgroundShape;
|
||||
[Tooltip("Background image for this zone")]
|
||||
public Sprite background;
|
||||
[Tooltip("Shape sprite for Normal rarity cards in this zone")]
|
||||
public Sprite shapeNormal;
|
||||
[Tooltip("Shape sprite for Rare rarity cards in this zone")]
|
||||
public Sprite shapeRare;
|
||||
}
|
||||
|
||||
[Header("Rarity Configuration")]
|
||||
[Tooltip("Color mappings for different card rarities")]
|
||||
[SerializeField] private List<RarityColorMapping> rarityColors = new List<RarityColorMapping>();
|
||||
[Tooltip("Visual mappings for different card rarities (frames and overlays)")]
|
||||
[SerializeField] private List<RarityVisualMapping> rarityVisuals = new List<RarityVisualMapping>();
|
||||
|
||||
[Header("Zone Configuration")]
|
||||
[Tooltip("Visual mappings for different card zones")]
|
||||
[Tooltip("Visual mappings for different card zones (backgrounds and shapes)")]
|
||||
[SerializeField] private List<ZoneVisualMapping> zoneVisuals = new List<ZoneVisualMapping>();
|
||||
|
||||
private Dictionary<CardRarity, Color> _rarityColorLookup;
|
||||
private Dictionary<CardZone, Color> _zoneColorLookup;
|
||||
private Dictionary<CardZone, Sprite> _zoneShapeLookup;
|
||||
[Header("Legendary Override")]
|
||||
[Tooltip("Background used for all Legendary cards, regardless of zone")]
|
||||
[SerializeField] private Sprite legendaryBackground;
|
||||
|
||||
private Dictionary<CardRarity, RarityVisualMapping> _rarityLookup;
|
||||
private Dictionary<CardZone, ZoneVisualMapping> _zoneLookup;
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the lookup dictionaries when the asset is loaded
|
||||
@@ -52,81 +62,94 @@ namespace AppleHills.Data.CardSystem
|
||||
/// </summary>
|
||||
private void InitializeLookups()
|
||||
{
|
||||
// Build rarity color lookup
|
||||
_rarityColorLookup = new Dictionary<CardRarity, Color>();
|
||||
foreach (var mapping in rarityColors)
|
||||
// Build rarity visual lookup
|
||||
_rarityLookup = new Dictionary<CardRarity, RarityVisualMapping>();
|
||||
foreach (var mapping in rarityVisuals)
|
||||
{
|
||||
_rarityColorLookup[mapping.rarity] = mapping.color;
|
||||
_rarityLookup[mapping.rarity] = mapping;
|
||||
}
|
||||
|
||||
// Build zone color and shape lookups
|
||||
_zoneColorLookup = new Dictionary<CardZone, Color>();
|
||||
_zoneShapeLookup = new Dictionary<CardZone, Sprite>();
|
||||
|
||||
// Build zone visual lookup
|
||||
_zoneLookup = new Dictionary<CardZone, ZoneVisualMapping>();
|
||||
foreach (var mapping in zoneVisuals)
|
||||
{
|
||||
_zoneColorLookup[mapping.zone] = mapping.color;
|
||||
_zoneShapeLookup[mapping.zone] = mapping.backgroundShape;
|
||||
_zoneLookup[mapping.zone] = mapping;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the color for a specific card rarity
|
||||
/// Get the frame sprite for a specific card rarity
|
||||
/// </summary>
|
||||
public Color GetRarityColor(CardRarity rarity)
|
||||
public Sprite GetRarityFrame(CardRarity rarity)
|
||||
{
|
||||
// Initialize lookups if needed
|
||||
if (_rarityColorLookup == null)
|
||||
if (_rarityLookup == null) InitializeLookups();
|
||||
|
||||
if (_rarityLookup.TryGetValue(rarity, out RarityVisualMapping mapping))
|
||||
{
|
||||
InitializeLookups();
|
||||
return mapping.frame;
|
||||
}
|
||||
|
||||
// Return the color if found, otherwise white
|
||||
if (_rarityColorLookup.TryGetValue(rarity, out Color color))
|
||||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
Logging.Warning($"[CardVisualConfig] No color mapping found for rarity {rarity}, using default");
|
||||
return Color.white;
|
||||
Logging.Warning($"[CardVisualConfig] No frame mapping found for rarity {rarity}");
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the color for a specific card zone
|
||||
/// Get the overlay sprite for a specific card rarity (can be null)
|
||||
/// </summary>
|
||||
public Color GetZoneColor(CardZone zone)
|
||||
public Sprite GetRarityOverlay(CardRarity rarity)
|
||||
{
|
||||
// Initialize lookups if needed
|
||||
if (_zoneColorLookup == null)
|
||||
if (_rarityLookup == null) InitializeLookups();
|
||||
|
||||
if (_rarityLookup.TryGetValue(rarity, out RarityVisualMapping mapping))
|
||||
{
|
||||
InitializeLookups();
|
||||
return mapping.overlay;
|
||||
}
|
||||
|
||||
// Return the color if found, otherwise white
|
||||
if (_zoneColorLookup.TryGetValue(zone, out Color color))
|
||||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
Logging.Warning($"[CardVisualConfig] No color mapping found for zone {zone}, using default");
|
||||
return Color.white;
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the background shape sprite for a specific zone
|
||||
/// Get the background sprite for a card based on zone and rarity
|
||||
/// Legendary cards always use the legendary background override
|
||||
/// </summary>
|
||||
public Sprite GetZoneShape(CardZone zone)
|
||||
public Sprite GetBackground(CardZone zone, CardRarity rarity)
|
||||
{
|
||||
// Initialize lookups if needed
|
||||
if (_zoneShapeLookup == null)
|
||||
if (_zoneLookup == null) InitializeLookups();
|
||||
|
||||
// Legendary cards use special background
|
||||
if (rarity == CardRarity.Legendary)
|
||||
{
|
||||
InitializeLookups();
|
||||
return legendaryBackground;
|
||||
}
|
||||
|
||||
// Return the sprite if found, otherwise null
|
||||
if (_zoneShapeLookup.TryGetValue(zone, out Sprite sprite))
|
||||
// Normal and Rare cards use zone background
|
||||
if (_zoneLookup.TryGetValue(zone, out ZoneVisualMapping mapping))
|
||||
{
|
||||
return sprite;
|
||||
return mapping.background;
|
||||
}
|
||||
|
||||
Logging.Warning($"[CardVisualConfig] No background mapping found for zone {zone}");
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the shape sprite for a card based on zone and rarity
|
||||
/// Legendary cards don't display shapes (returns null)
|
||||
/// </summary>
|
||||
public Sprite GetZoneShape(CardZone zone, CardRarity rarity)
|
||||
{
|
||||
if (_zoneLookup == null) InitializeLookups();
|
||||
|
||||
// Legendary cards don't have shapes
|
||||
if (rarity == CardRarity.Legendary)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (_zoneLookup.TryGetValue(zone, out ZoneVisualMapping mapping))
|
||||
{
|
||||
// Return shape based on rarity
|
||||
return rarity == CardRarity.Rare ? mapping.shapeRare : mapping.shapeNormal;
|
||||
}
|
||||
|
||||
Logging.Warning($"[CardVisualConfig] No shape mapping found for zone {zone}");
|
||||
@@ -135,47 +158,26 @@ namespace AppleHills.Data.CardSystem
|
||||
|
||||
#if UNITY_EDITOR
|
||||
/// <summary>
|
||||
/// Editor-only utility to reset the config with default values
|
||||
/// Editor-only utility to initialize the config with default structure
|
||||
/// </summary>
|
||||
public void ResetWithDefaults()
|
||||
public void InitializeDefaults()
|
||||
{
|
||||
// Clear existing mappings
|
||||
rarityColors.Clear();
|
||||
rarityVisuals.Clear();
|
||||
zoneVisuals.Clear();
|
||||
|
||||
// Add default rarity colors
|
||||
rarityColors.Add(new RarityColorMapping { rarity = CardRarity.Common, color = Color.gray });
|
||||
rarityColors.Add(new RarityColorMapping { rarity = CardRarity.Uncommon, color = Color.green });
|
||||
rarityColors.Add(new RarityColorMapping { rarity = CardRarity.Rare, color = Color.blue });
|
||||
rarityColors.Add(new RarityColorMapping { rarity = CardRarity.Epic, color = new Color(0.5f, 0, 0.5f) });
|
||||
rarityColors.Add(new RarityColorMapping { rarity = CardRarity.Legendary, color = Color.yellow });
|
||||
// Add entries for all rarities
|
||||
foreach (CardRarity rarity in Enum.GetValues(typeof(CardRarity)))
|
||||
{
|
||||
rarityVisuals.Add(new RarityVisualMapping { rarity = rarity });
|
||||
}
|
||||
|
||||
// Add entries for all zones
|
||||
foreach (CardZone zone in Enum.GetValues(typeof(CardZone)))
|
||||
{
|
||||
zoneVisuals.Add(new ZoneVisualMapping { zone = zone });
|
||||
}
|
||||
|
||||
// Add default zone colors
|
||||
zoneVisuals.Add(new ZoneVisualMapping {
|
||||
zone = CardZone.AppleHills,
|
||||
color = new Color(0.8f, 0.9f, 0.8f)
|
||||
});
|
||||
|
||||
zoneVisuals.Add(new ZoneVisualMapping {
|
||||
zone = CardZone.Quarry,
|
||||
color = new Color(0.85f, 0.8f, 0.7f)
|
||||
});
|
||||
|
||||
zoneVisuals.Add(new ZoneVisualMapping {
|
||||
zone = CardZone.Forest,
|
||||
color = new Color(0.6f, 0.8f, 0.6f)
|
||||
});
|
||||
|
||||
zoneVisuals.Add(new ZoneVisualMapping {
|
||||
zone = CardZone.Mountain,
|
||||
color = new Color(0.7f, 0.7f, 0.9f)
|
||||
});
|
||||
|
||||
zoneVisuals.Add(new ZoneVisualMapping {
|
||||
zone = CardZone.Beach,
|
||||
color = new Color(0.9f, 0.85f, 0.7f)
|
||||
});
|
||||
|
||||
// Initialize the lookups
|
||||
InitializeLookups();
|
||||
}
|
||||
@@ -193,9 +195,9 @@ namespace AppleHills.Data.CardSystem
|
||||
CardVisualConfig config = (CardVisualConfig)target;
|
||||
|
||||
UnityEditor.EditorGUILayout.Space();
|
||||
if (GUILayout.Button("Reset with Defaults"))
|
||||
if (GUILayout.Button("Initialize Default Structure"))
|
||||
{
|
||||
config.ResetWithDefaults();
|
||||
config.InitializeDefaults();
|
||||
UnityEditor.EditorUtility.SetDirty(config);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user