|
|
@@ -25,6 +25,10 @@ public class PostBattleLootSystem : MonoBehaviour
|
|
|
[Header("Debug Settings")]
|
|
|
public bool showDebugLogs = true;
|
|
|
|
|
|
+ [Header("Item Distribution Settings")]
|
|
|
+ public bool enablePlayerItemSelection = true; // Allow manual item distribution
|
|
|
+ public bool autoDistributeItems = false; // If true, items are distributed automatically
|
|
|
+
|
|
|
// Events
|
|
|
public event System.Action OnLootingComplete;
|
|
|
|
|
|
@@ -32,6 +36,7 @@ public class PostBattleLootSystem : MonoBehaviour
|
|
|
private bool isLootingActive = false;
|
|
|
private VisualElement rootElement;
|
|
|
private bool takeAllPressed = false;
|
|
|
+ private Dictionary<string, int> selectedPlayerForItem = new Dictionary<string, int>(); // itemName -> playerIndex
|
|
|
|
|
|
/// <summary>
|
|
|
/// Gets whether the looting process is currently active
|
|
|
@@ -320,22 +325,30 @@ public class PostBattleLootSystem : MonoBehaviour
|
|
|
takeAllButton.clicked += () =>
|
|
|
{
|
|
|
takeAllPressed = true;
|
|
|
+
|
|
|
+ // Force auto-distribution and skip player selection
|
|
|
+ bool originalAutoDistribute = autoDistributeItems;
|
|
|
+ autoDistributeItems = true; // Temporarily force auto-distribution
|
|
|
+
|
|
|
AutoLootAll();
|
|
|
- CompleteLootingProcess();
|
|
|
+
|
|
|
+ // Restore original setting
|
|
|
+ autoDistributeItems = originalAutoDistribute;
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- // Set up Continue button
|
|
|
+ // Set up Continue button - this should return to map
|
|
|
var continueButton = rootElement.Q<Button>("ContinueButton");
|
|
|
if (continueButton != null)
|
|
|
{
|
|
|
+ continueButton.text = "Return to Map"; // Make it clear what this button does
|
|
|
continueButton.clicked += () =>
|
|
|
{
|
|
|
if (!takeAllPressed)
|
|
|
{
|
|
|
AutoLootAll(); // Auto-loot if not already done
|
|
|
}
|
|
|
- CompleteLootingProcess();
|
|
|
+ // CompleteLootingProcess is called by AutoLootAll, so scene transition will happen
|
|
|
};
|
|
|
}
|
|
|
|
|
|
@@ -356,9 +369,17 @@ public class PostBattleLootSystem : MonoBehaviour
|
|
|
{
|
|
|
if (!takeAllPressed)
|
|
|
{
|
|
|
+ takeAllPressed = true;
|
|
|
+
|
|
|
+ // Force auto-distribution and skip player selection
|
|
|
+ bool originalAutoDistribute = autoDistributeItems;
|
|
|
+ autoDistributeItems = true; // Temporarily force auto-distribution
|
|
|
+
|
|
|
AutoLootAll();
|
|
|
+
|
|
|
+ // Restore original setting
|
|
|
+ autoDistributeItems = originalAutoDistribute;
|
|
|
}
|
|
|
- CompleteLootingProcess();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -481,6 +502,10 @@ public class PostBattleLootSystem : MonoBehaviour
|
|
|
{
|
|
|
isLootingActive = false;
|
|
|
|
|
|
+ // Hide the loot UI
|
|
|
+ if (rootElement != null)
|
|
|
+ rootElement.style.display = DisplayStyle.None;
|
|
|
+
|
|
|
if (showDebugLogs)
|
|
|
Debug.Log("💰 Looting completed, triggering OnLootingComplete");
|
|
|
|
|
|
@@ -612,14 +637,68 @@ public class PostBattleLootSystem : MonoBehaviour
|
|
|
allItems.AddRange(enemy.dropItems);
|
|
|
}
|
|
|
|
|
|
- // Update currency displays
|
|
|
+ // Update currency displays with better formatting and tighter spacing
|
|
|
var goldLabel = rootElement.Q<Label>("GoldAmount");
|
|
|
var silverLabel = rootElement.Q<Label>("SilverAmount");
|
|
|
var copperLabel = rootElement.Q<Label>("CopperAmount");
|
|
|
|
|
|
- if (goldLabel != null) goldLabel.text = totalGold.ToString();
|
|
|
- if (silverLabel != null) silverLabel.text = totalSilver.ToString();
|
|
|
- if (copperLabel != null) copperLabel.text = totalCopper.ToString();
|
|
|
+ if (goldLabel != null)
|
|
|
+ {
|
|
|
+ goldLabel.text = totalGold.ToString();
|
|
|
+ goldLabel.style.fontSize = 18; // Slightly larger than before but not huge
|
|
|
+ goldLabel.style.unityFontStyleAndWeight = FontStyle.Bold;
|
|
|
+ goldLabel.style.marginBottom = 2; // Reduce spacing
|
|
|
+ goldLabel.style.marginTop = 2;
|
|
|
+ }
|
|
|
+ if (silverLabel != null)
|
|
|
+ {
|
|
|
+ silverLabel.text = totalSilver.ToString();
|
|
|
+ silverLabel.style.fontSize = 18;
|
|
|
+ silverLabel.style.unityFontStyleAndWeight = FontStyle.Bold;
|
|
|
+ silverLabel.style.marginBottom = 2;
|
|
|
+ silverLabel.style.marginTop = 2;
|
|
|
+ }
|
|
|
+ if (copperLabel != null)
|
|
|
+ {
|
|
|
+ copperLabel.text = totalCopper.ToString();
|
|
|
+ copperLabel.style.fontSize = 18;
|
|
|
+ copperLabel.style.unityFontStyleAndWeight = FontStyle.Bold;
|
|
|
+ copperLabel.style.marginBottom = 2;
|
|
|
+ copperLabel.style.marginTop = 2;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Style the currency text labels to be closer to the numbers
|
|
|
+ var goldText = rootElement.Q<Label>("GoldText");
|
|
|
+ var silverText = rootElement.Q<Label>("SilverText");
|
|
|
+ var copperText = rootElement.Q<Label>("CopperText");
|
|
|
+
|
|
|
+ if (goldText != null)
|
|
|
+ {
|
|
|
+ goldText.style.fontSize = 12;
|
|
|
+ goldText.style.marginTop = -2; // Move closer to number
|
|
|
+ goldText.style.marginBottom = 8; // Add space after currency section
|
|
|
+ }
|
|
|
+ if (silverText != null)
|
|
|
+ {
|
|
|
+ silverText.style.fontSize = 12;
|
|
|
+ silverText.style.marginTop = -2;
|
|
|
+ silverText.style.marginBottom = 8;
|
|
|
+ }
|
|
|
+ if (copperText != null)
|
|
|
+ {
|
|
|
+ copperText.style.fontSize = 12;
|
|
|
+ copperText.style.marginTop = -2;
|
|
|
+ copperText.style.marginBottom = 8;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Also style the currency icons to be smaller
|
|
|
+ var goldIcon = rootElement.Q<Label>("GoldIcon");
|
|
|
+ var silverIcon = rootElement.Q<Label>("SilverIcon");
|
|
|
+ var copperIcon = rootElement.Q<Label>("CopperIcon");
|
|
|
+
|
|
|
+ if (goldIcon != null) goldIcon.style.fontSize = 14;
|
|
|
+ if (silverIcon != null) silverIcon.style.fontSize = 14;
|
|
|
+ if (copperIcon != null) copperIcon.style.fontSize = 14;
|
|
|
|
|
|
// Update item count
|
|
|
var itemCountLabel = rootElement.Q<Label>("ItemCount");
|
|
|
@@ -691,10 +770,121 @@ public class PostBattleLootSystem : MonoBehaviour
|
|
|
enemyLootContainer.Add(enemySection);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // Populate the total items list scrollview with better visibility
|
|
|
+ var itemsListContainer = rootElement.Q<ScrollView>("ItemsList");
|
|
|
+ if (itemsListContainer != null)
|
|
|
+ {
|
|
|
+ itemsListContainer.Clear();
|
|
|
+
|
|
|
+ // Set scrollview properties for better visibility and containment
|
|
|
+ itemsListContainer.style.minHeight = 80;
|
|
|
+ itemsListContainer.style.maxHeight = 150;
|
|
|
+ itemsListContainer.style.backgroundColor = new Color(0.15f, 0.15f, 0.25f, 0.9f);
|
|
|
+ itemsListContainer.style.borderTopWidth = 2;
|
|
|
+ itemsListContainer.style.borderBottomWidth = 2;
|
|
|
+ itemsListContainer.style.borderLeftWidth = 2;
|
|
|
+ itemsListContainer.style.borderRightWidth = 2;
|
|
|
+ itemsListContainer.style.borderTopColor = new Color(0.6f, 0.6f, 0.8f, 0.8f);
|
|
|
+ itemsListContainer.style.borderBottomColor = new Color(0.6f, 0.6f, 0.8f, 0.8f);
|
|
|
+ itemsListContainer.style.borderLeftColor = new Color(0.6f, 0.6f, 0.8f, 0.8f);
|
|
|
+ itemsListContainer.style.borderRightColor = new Color(0.6f, 0.6f, 0.8f, 0.8f);
|
|
|
+ itemsListContainer.style.borderTopLeftRadius = 8;
|
|
|
+ itemsListContainer.style.borderTopRightRadius = 8;
|
|
|
+ itemsListContainer.style.borderBottomLeftRadius = 8;
|
|
|
+ itemsListContainer.style.borderBottomRightRadius = 8;
|
|
|
+ itemsListContainer.style.paddingTop = 8;
|
|
|
+ itemsListContainer.style.paddingBottom = 8;
|
|
|
+ itemsListContainer.style.paddingLeft = 8;
|
|
|
+ itemsListContainer.style.paddingRight = 8;
|
|
|
+ itemsListContainer.style.marginTop = 5;
|
|
|
+ itemsListContainer.style.marginBottom = 10;
|
|
|
+ itemsListContainer.style.marginLeft = 5;
|
|
|
+ itemsListContainer.style.marginRight = 5;
|
|
|
+
|
|
|
+ if (allItems.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (var item in allItems)
|
|
|
+ {
|
|
|
+ var itemEntry = new Label($"📦 {item}");
|
|
|
+ itemEntry.AddToClassList("total-item-entry");
|
|
|
+ itemEntry.style.fontSize = 14;
|
|
|
+ itemEntry.style.color = Color.white;
|
|
|
+ itemEntry.style.marginBottom = 2;
|
|
|
+ itemEntry.style.paddingLeft = 6;
|
|
|
+ itemEntry.style.paddingRight = 6;
|
|
|
+ itemEntry.style.paddingTop = 3;
|
|
|
+ itemEntry.style.paddingBottom = 3;
|
|
|
+ itemEntry.style.backgroundColor = new Color(0.25f, 0.35f, 0.45f, 0.8f);
|
|
|
+ itemEntry.style.borderTopLeftRadius = 4;
|
|
|
+ itemEntry.style.borderTopRightRadius = 4;
|
|
|
+ itemEntry.style.borderBottomLeftRadius = 4;
|
|
|
+ itemEntry.style.borderBottomRightRadius = 4;
|
|
|
+ itemEntry.style.borderTopWidth = 1;
|
|
|
+ itemEntry.style.borderBottomWidth = 1;
|
|
|
+ itemEntry.style.borderLeftWidth = 1;
|
|
|
+ itemEntry.style.borderRightWidth = 1;
|
|
|
+ itemEntry.style.borderTopColor = new Color(0.7f, 0.7f, 0.9f, 0.6f);
|
|
|
+ itemEntry.style.borderBottomColor = new Color(0.7f, 0.7f, 0.9f, 0.6f);
|
|
|
+ itemEntry.style.borderLeftColor = new Color(0.7f, 0.7f, 0.9f, 0.6f);
|
|
|
+ itemEntry.style.borderRightColor = new Color(0.7f, 0.7f, 0.9f, 0.6f);
|
|
|
+
|
|
|
+ itemsListContainer.Add(itemEntry);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var noItemsLabel = new Label("No items collected");
|
|
|
+ noItemsLabel.style.fontSize = 14;
|
|
|
+ noItemsLabel.style.color = new Color(0.7f, 0.7f, 0.7f, 1f);
|
|
|
+ noItemsLabel.style.unityTextAlign = TextAnchor.MiddleCenter;
|
|
|
+ noItemsLabel.style.paddingTop = 20;
|
|
|
+ itemsListContainer.Add(noItemsLabel);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Add informational message about item distribution
|
|
|
+ if (allItems.Count > 0)
|
|
|
+ {
|
|
|
+ var distributionHint = rootElement.Q<Label>("DistributionHint");
|
|
|
+ if (distributionHint == null)
|
|
|
+ {
|
|
|
+ distributionHint = new Label();
|
|
|
+ distributionHint.name = "DistributionHint";
|
|
|
+ // Find a good place to add it (after the items section)
|
|
|
+ var itemsSection = rootElement.Q<VisualElement>("ItemsSection");
|
|
|
+ if (itemsSection != null)
|
|
|
+ {
|
|
|
+ itemsSection.Add(distributionHint);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ rootElement.Add(distributionHint);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (enablePlayerItemSelection && !takeAllPressed)
|
|
|
+ {
|
|
|
+ distributionHint.text = "💡 Click individual items above to choose which character gets them, or use 'Take All' for automatic distribution.";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ distributionHint.text = "📋 Items will be distributed automatically among surviving party members.";
|
|
|
+ }
|
|
|
+
|
|
|
+ distributionHint.style.fontSize = 12;
|
|
|
+ distributionHint.style.color = new Color(0.8f, 0.8f, 0.9f, 0.9f);
|
|
|
+ distributionHint.style.unityTextAlign = TextAnchor.MiddleCenter;
|
|
|
+ distributionHint.style.marginTop = 10;
|
|
|
+ distributionHint.style.marginBottom = 5;
|
|
|
+ distributionHint.style.paddingLeft = 10;
|
|
|
+ distributionHint.style.paddingRight = 10;
|
|
|
+ distributionHint.style.whiteSpace = WhiteSpace.Normal;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Auto-loot all items and currency (temporary solution)
|
|
|
+ /// Auto-loot all items and currency with optional player selection
|
|
|
/// </summary>
|
|
|
private void AutoLootAll()
|
|
|
{
|
|
|
@@ -713,16 +903,31 @@ public class PostBattleLootSystem : MonoBehaviour
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // Distribute rewards to players
|
|
|
- DistributeRewards(totalGold, totalSilver, totalCopper, allItems);
|
|
|
+ // Always distribute currency automatically
|
|
|
+ DistributeCurrency(totalGold, totalSilver, totalCopper);
|
|
|
|
|
|
- if (showDebugLogs)
|
|
|
+ // Handle item distribution based on settings
|
|
|
+ // Show item distribution UI if:
|
|
|
+ // 1. Player item selection is enabled
|
|
|
+ // 2. There are items to distribute
|
|
|
+ // 3. We're NOT in "Take All" mode (which forces auto-distribution)
|
|
|
+ if (enablePlayerItemSelection && allItems.Count > 0 && !takeAllPressed)
|
|
|
{
|
|
|
- Debug.Log($"💰 Auto-looted: {totalGold}g {totalSilver}s {totalCopper}c and {allItems.Count} items");
|
|
|
+ ShowItemDistributionUI(allItems);
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // Auto-distribute items
|
|
|
+ DistributeItemsAutomatically(allItems);
|
|
|
|
|
|
- // End looting phase
|
|
|
- FinishLooting();
|
|
|
+ if (showDebugLogs)
|
|
|
+ {
|
|
|
+ Debug.Log($"💰 Auto-looted: {totalGold}g {totalSilver}s {totalCopper}c and {allItems.Count} items");
|
|
|
+ }
|
|
|
+
|
|
|
+ // End looting phase
|
|
|
+ FinishLooting();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -786,6 +991,373 @@ public class PostBattleLootSystem : MonoBehaviour
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Distribute currency to players (separated from items for flexibility)
|
|
|
+ /// </summary>
|
|
|
+ private void DistributeCurrency(int gold, int silver, int copper)
|
|
|
+ {
|
|
|
+ var survivingPlayers = GetSurvivingPlayers();
|
|
|
+ if (survivingPlayers.Count == 0)
|
|
|
+ {
|
|
|
+ Debug.LogWarning("💰 No surviving players to distribute currency to!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Distribute currency evenly
|
|
|
+ int goldPerPlayer = gold / survivingPlayers.Count;
|
|
|
+ int silverPerPlayer = silver / survivingPlayers.Count;
|
|
|
+ int copperPerPlayer = copper / survivingPlayers.Count;
|
|
|
+
|
|
|
+ // Handle remainder
|
|
|
+ int goldRemainder = gold % survivingPlayers.Count;
|
|
|
+ int silverRemainder = silver % survivingPlayers.Count;
|
|
|
+ int copperRemainder = copper % survivingPlayers.Count;
|
|
|
+
|
|
|
+ for (int i = 0; i < survivingPlayers.Count; i++)
|
|
|
+ {
|
|
|
+ var player = survivingPlayers[i];
|
|
|
+ Character playerCharacter = player.GetComponent<Character>();
|
|
|
+
|
|
|
+ if (playerCharacter == null) continue;
|
|
|
+
|
|
|
+ // Get player's bank
|
|
|
+ var bank = playerCharacter.GetComponent<Bank>();
|
|
|
+ if (bank != null)
|
|
|
+ {
|
|
|
+ bank.gold += goldPerPlayer + (i < goldRemainder ? 1 : 0);
|
|
|
+ bank.silver += silverPerPlayer + (i < silverRemainder ? 1 : 0);
|
|
|
+ bank.copper += copperPerPlayer + (i < copperRemainder ? 1 : 0);
|
|
|
+
|
|
|
+ if (showDebugLogs)
|
|
|
+ {
|
|
|
+ int finalGold = goldPerPlayer + (i < goldRemainder ? 1 : 0);
|
|
|
+ int finalSilver = silverPerPlayer + (i < silverRemainder ? 1 : 0);
|
|
|
+ int finalCopper = copperPerPlayer + (i < copperRemainder ? 1 : 0);
|
|
|
+ Debug.Log($"💰 {playerCharacter.CharacterName} received: {finalGold}g {finalSilver}s {finalCopper}c");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Show UI for manually assigning items to players
|
|
|
+ /// </summary>
|
|
|
+ private void ShowItemDistributionUI(List<string> items)
|
|
|
+ {
|
|
|
+ var survivingPlayers = GetSurvivingPlayers();
|
|
|
+ if (survivingPlayers.Count == 0)
|
|
|
+ {
|
|
|
+ Debug.LogWarning("💰 No surviving players for item distribution!");
|
|
|
+ FinishLooting();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // For now, create a simple distribution UI overlay
|
|
|
+ var distributionOverlay = new VisualElement();
|
|
|
+ distributionOverlay.name = "ItemDistributionOverlay";
|
|
|
+ distributionOverlay.style.position = Position.Absolute;
|
|
|
+ distributionOverlay.style.top = 0;
|
|
|
+ distributionOverlay.style.left = 0;
|
|
|
+ distributionOverlay.style.right = 0;
|
|
|
+ distributionOverlay.style.bottom = 0;
|
|
|
+ distributionOverlay.style.backgroundColor = new Color(0, 0, 0, 0.8f);
|
|
|
+ distributionOverlay.style.justifyContent = Justify.Center;
|
|
|
+ distributionOverlay.style.alignItems = Align.Center;
|
|
|
+
|
|
|
+ // Create distribution panel
|
|
|
+ var panel = new VisualElement();
|
|
|
+ panel.style.backgroundColor = new Color(0.15f, 0.15f, 0.25f, 0.95f);
|
|
|
+ panel.style.borderTopWidth = 2;
|
|
|
+ panel.style.borderBottomWidth = 2;
|
|
|
+ panel.style.borderLeftWidth = 2;
|
|
|
+ panel.style.borderRightWidth = 2;
|
|
|
+ panel.style.borderTopColor = Color.yellow;
|
|
|
+ panel.style.borderBottomColor = Color.yellow;
|
|
|
+ panel.style.borderLeftColor = Color.yellow;
|
|
|
+ panel.style.borderRightColor = Color.yellow;
|
|
|
+ panel.style.borderTopLeftRadius = 10;
|
|
|
+ panel.style.borderTopRightRadius = 10;
|
|
|
+ panel.style.borderBottomLeftRadius = 10;
|
|
|
+ panel.style.borderBottomRightRadius = 10;
|
|
|
+ panel.style.paddingTop = 20;
|
|
|
+ panel.style.paddingBottom = 20;
|
|
|
+ panel.style.paddingLeft = 20;
|
|
|
+ panel.style.paddingRight = 20;
|
|
|
+ panel.style.width = new Length(90, LengthUnit.Percent);
|
|
|
+ panel.style.maxWidth = 600;
|
|
|
+ panel.style.maxHeight = new Length(80, LengthUnit.Percent);
|
|
|
+
|
|
|
+ // Title
|
|
|
+ var title = new Label("Distribute Items to Players");
|
|
|
+ title.style.fontSize = 24;
|
|
|
+ title.style.color = Color.yellow;
|
|
|
+ title.style.unityTextAlign = TextAnchor.MiddleCenter;
|
|
|
+ title.style.marginBottom = 20;
|
|
|
+ panel.Add(title);
|
|
|
+
|
|
|
+ // Scroll view for items
|
|
|
+ var scrollView = new ScrollView();
|
|
|
+ scrollView.style.flexGrow = 1;
|
|
|
+ scrollView.style.marginBottom = 15;
|
|
|
+
|
|
|
+ // Create item distribution entries
|
|
|
+ foreach (var item in items)
|
|
|
+ {
|
|
|
+ var itemRow = CreateItemDistributionRow(item, survivingPlayers);
|
|
|
+ scrollView.Add(itemRow);
|
|
|
+ }
|
|
|
+
|
|
|
+ panel.Add(scrollView);
|
|
|
+
|
|
|
+ // Buttons
|
|
|
+ var buttonContainer = new VisualElement();
|
|
|
+ buttonContainer.style.flexDirection = FlexDirection.Row;
|
|
|
+ buttonContainer.style.justifyContent = Justify.SpaceAround;
|
|
|
+
|
|
|
+ var autoDistributeBtn = new Button(() =>
|
|
|
+ {
|
|
|
+ DistributeItemsAutomatically(items);
|
|
|
+ rootElement.Remove(distributionOverlay);
|
|
|
+ FinishLooting();
|
|
|
+ });
|
|
|
+ autoDistributeBtn.text = "Auto Distribute";
|
|
|
+ autoDistributeBtn.style.fontSize = 14;
|
|
|
+
|
|
|
+ var confirmBtn = new Button(() =>
|
|
|
+ {
|
|
|
+ DistributeItemsManually(items, survivingPlayers);
|
|
|
+ rootElement.Remove(distributionOverlay);
|
|
|
+ FinishLooting();
|
|
|
+ });
|
|
|
+ confirmBtn.text = "Confirm Distribution";
|
|
|
+ confirmBtn.style.fontSize = 14;
|
|
|
+
|
|
|
+ buttonContainer.Add(autoDistributeBtn);
|
|
|
+ buttonContainer.Add(confirmBtn);
|
|
|
+ panel.Add(buttonContainer);
|
|
|
+
|
|
|
+ distributionOverlay.Add(panel);
|
|
|
+ rootElement.Add(distributionOverlay);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Create a row for item distribution with player selection buttons
|
|
|
+ /// </summary>
|
|
|
+ private VisualElement CreateItemDistributionRow(string itemName, List<GameObject> players)
|
|
|
+ {
|
|
|
+ var row = new VisualElement();
|
|
|
+ row.style.flexDirection = FlexDirection.Row;
|
|
|
+ row.style.alignItems = Align.Center;
|
|
|
+ row.style.marginBottom = 10;
|
|
|
+ row.style.paddingTop = 8;
|
|
|
+ row.style.paddingBottom = 8;
|
|
|
+ row.style.paddingLeft = 12;
|
|
|
+ row.style.paddingRight = 12;
|
|
|
+ row.style.backgroundColor = new Color(0.2f, 0.2f, 0.3f, 0.9f);
|
|
|
+ row.style.borderTopLeftRadius = 8;
|
|
|
+ row.style.borderTopRightRadius = 8;
|
|
|
+ row.style.borderBottomLeftRadius = 8;
|
|
|
+ row.style.borderBottomRightRadius = 8;
|
|
|
+ row.style.borderTopWidth = 1;
|
|
|
+ row.style.borderBottomWidth = 1;
|
|
|
+ row.style.borderLeftWidth = 1;
|
|
|
+ row.style.borderRightWidth = 1;
|
|
|
+ row.style.borderTopColor = new Color(0.5f, 0.5f, 0.6f, 0.8f);
|
|
|
+ row.style.borderBottomColor = new Color(0.5f, 0.5f, 0.6f, 0.8f);
|
|
|
+ row.style.borderLeftColor = new Color(0.5f, 0.5f, 0.6f, 0.8f);
|
|
|
+ row.style.borderRightColor = new Color(0.5f, 0.5f, 0.6f, 0.8f);
|
|
|
+
|
|
|
+ // Item name with better styling
|
|
|
+ var itemLabel = new Label($"📦 {itemName}");
|
|
|
+ itemLabel.style.fontSize = 15;
|
|
|
+ itemLabel.style.color = Color.white;
|
|
|
+ itemLabel.style.unityFontStyleAndWeight = FontStyle.Bold;
|
|
|
+ itemLabel.style.width = new Length(35, LengthUnit.Percent);
|
|
|
+ itemLabel.style.unityTextAlign = TextAnchor.MiddleLeft;
|
|
|
+ row.Add(itemLabel);
|
|
|
+
|
|
|
+ // "Assign to:" label
|
|
|
+ var assignLabel = new Label("→");
|
|
|
+ assignLabel.style.fontSize = 14;
|
|
|
+ assignLabel.style.color = Color.yellow;
|
|
|
+ assignLabel.style.unityFontStyleAndWeight = FontStyle.Bold;
|
|
|
+ assignLabel.style.width = 20;
|
|
|
+ assignLabel.style.unityTextAlign = TextAnchor.MiddleCenter;
|
|
|
+ row.Add(assignLabel);
|
|
|
+
|
|
|
+ // Player selection buttons
|
|
|
+ var buttonContainer = new VisualElement();
|
|
|
+ buttonContainer.style.flexDirection = FlexDirection.Row;
|
|
|
+ buttonContainer.style.flexGrow = 1;
|
|
|
+ buttonContainer.style.justifyContent = Justify.SpaceAround;
|
|
|
+
|
|
|
+ int selectedPlayerIndex = selectedPlayerForItem.ContainsKey(itemName) ? selectedPlayerForItem[itemName] : -1;
|
|
|
+
|
|
|
+ // Store button references for updating
|
|
|
+ var playerButtons = new List<Button>();
|
|
|
+
|
|
|
+ for (int i = 0; i < players.Count; i++)
|
|
|
+ {
|
|
|
+ var player = players[i];
|
|
|
+ var character = player.GetComponent<Character>();
|
|
|
+ if (character == null) continue;
|
|
|
+
|
|
|
+ int playerIndex = i; // Capture for closure
|
|
|
+ var playerBtn = new Button(() =>
|
|
|
+ {
|
|
|
+ selectedPlayerForItem[itemName] = playerIndex;
|
|
|
+
|
|
|
+ // Update all buttons in this row to show selection
|
|
|
+ UpdatePlayerButtonVisuals(playerButtons, playerIndex);
|
|
|
+
|
|
|
+ Debug.Log($"💰 Assigned {itemName} to {character.CharacterName}");
|
|
|
+ });
|
|
|
+
|
|
|
+ playerBtn.text = character.CharacterName;
|
|
|
+ playerBtn.style.fontSize = 13;
|
|
|
+ playerBtn.style.flexGrow = 1;
|
|
|
+ playerBtn.style.marginLeft = 3;
|
|
|
+ playerBtn.style.marginRight = 3;
|
|
|
+ playerBtn.style.paddingTop = 8;
|
|
|
+ playerBtn.style.paddingBottom = 8;
|
|
|
+ playerBtn.style.paddingLeft = 6;
|
|
|
+ playerBtn.style.paddingRight = 6;
|
|
|
+ playerBtn.style.borderTopLeftRadius = 5;
|
|
|
+ playerBtn.style.borderTopRightRadius = 5;
|
|
|
+ playerBtn.style.borderBottomLeftRadius = 5;
|
|
|
+ playerBtn.style.borderBottomRightRadius = 5;
|
|
|
+ playerBtn.style.borderTopWidth = 2;
|
|
|
+ playerBtn.style.borderBottomWidth = 2;
|
|
|
+ playerBtn.style.borderLeftWidth = 2;
|
|
|
+ playerBtn.style.borderRightWidth = 2;
|
|
|
+
|
|
|
+ // Set initial visual state
|
|
|
+ if (i == selectedPlayerIndex)
|
|
|
+ {
|
|
|
+ // Selected state
|
|
|
+ playerBtn.style.backgroundColor = new Color(0.2f, 0.8f, 0.2f, 0.9f);
|
|
|
+ playerBtn.style.borderTopColor = Color.green;
|
|
|
+ playerBtn.style.borderBottomColor = Color.green;
|
|
|
+ playerBtn.style.borderLeftColor = Color.green;
|
|
|
+ playerBtn.style.borderRightColor = Color.green;
|
|
|
+ playerBtn.style.color = Color.white;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // Unselected state
|
|
|
+ playerBtn.style.backgroundColor = new Color(0.3f, 0.3f, 0.4f, 0.8f);
|
|
|
+ playerBtn.style.borderTopColor = new Color(0.6f, 0.6f, 0.7f, 0.8f);
|
|
|
+ playerBtn.style.borderBottomColor = new Color(0.6f, 0.6f, 0.7f, 0.8f);
|
|
|
+ playerBtn.style.borderLeftColor = new Color(0.6f, 0.6f, 0.7f, 0.8f);
|
|
|
+ playerBtn.style.borderRightColor = new Color(0.6f, 0.6f, 0.7f, 0.8f);
|
|
|
+ playerBtn.style.color = new Color(0.9f, 0.9f, 0.9f, 0.9f);
|
|
|
+ }
|
|
|
+
|
|
|
+ playerButtons.Add(playerBtn);
|
|
|
+ buttonContainer.Add(playerBtn);
|
|
|
+ }
|
|
|
+
|
|
|
+ row.Add(buttonContainer);
|
|
|
+ return row;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Update visual state of player selection buttons
|
|
|
+ /// </summary>
|
|
|
+ private void UpdatePlayerButtonVisuals(List<Button> buttons, int selectedIndex)
|
|
|
+ {
|
|
|
+ for (int i = 0; i < buttons.Count; i++)
|
|
|
+ {
|
|
|
+ var button = buttons[i];
|
|
|
+ if (i == selectedIndex)
|
|
|
+ {
|
|
|
+ // Selected state - green highlight
|
|
|
+ button.style.backgroundColor = new Color(0.2f, 0.8f, 0.2f, 0.9f);
|
|
|
+ button.style.borderTopColor = Color.green;
|
|
|
+ button.style.borderBottomColor = Color.green;
|
|
|
+ button.style.borderLeftColor = Color.green;
|
|
|
+ button.style.borderRightColor = Color.green;
|
|
|
+ button.style.color = Color.white;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // Unselected state - neutral gray
|
|
|
+ button.style.backgroundColor = new Color(0.3f, 0.3f, 0.4f, 0.8f);
|
|
|
+ button.style.borderTopColor = new Color(0.6f, 0.6f, 0.7f, 0.8f);
|
|
|
+ button.style.borderBottomColor = new Color(0.6f, 0.6f, 0.7f, 0.8f);
|
|
|
+ button.style.borderLeftColor = new Color(0.6f, 0.6f, 0.7f, 0.8f);
|
|
|
+ button.style.borderRightColor = new Color(0.6f, 0.6f, 0.7f, 0.8f);
|
|
|
+ button.style.color = new Color(0.9f, 0.9f, 0.9f, 0.9f);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Distribute items automatically using round-robin
|
|
|
+ /// </summary>
|
|
|
+ private void DistributeItemsAutomatically(List<string> items)
|
|
|
+ {
|
|
|
+ var survivingPlayers = GetSurvivingPlayers();
|
|
|
+ if (survivingPlayers.Count == 0) return;
|
|
|
+
|
|
|
+ for (int i = 0; i < items.Count; i++)
|
|
|
+ {
|
|
|
+ var player = survivingPlayers[i % survivingPlayers.Count];
|
|
|
+ var character = player.GetComponent<Character>();
|
|
|
+ if (character != null)
|
|
|
+ {
|
|
|
+ AddItemToPlayer(character, items[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (showDebugLogs)
|
|
|
+ {
|
|
|
+ Debug.Log($"💰 Auto-distributed {items.Count} items among {survivingPlayers.Count} players");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Distribute items based on manual player selection
|
|
|
+ /// </summary>
|
|
|
+ private void DistributeItemsManually(List<string> items, List<GameObject> players)
|
|
|
+ {
|
|
|
+ foreach (var item in items)
|
|
|
+ {
|
|
|
+ if (selectedPlayerForItem.ContainsKey(item))
|
|
|
+ {
|
|
|
+ int playerIndex = selectedPlayerForItem[item];
|
|
|
+ if (playerIndex >= 0 && playerIndex < players.Count)
|
|
|
+ {
|
|
|
+ var character = players[playerIndex].GetComponent<Character>();
|
|
|
+ if (character != null)
|
|
|
+ {
|
|
|
+ AddItemToPlayer(character, item);
|
|
|
+ if (showDebugLogs)
|
|
|
+ {
|
|
|
+ Debug.Log($"💰 Manually distributed {item} to {character.CharacterName}");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // If no selection was made, give to first player
|
|
|
+ var character = players[0].GetComponent<Character>();
|
|
|
+ if (character != null)
|
|
|
+ {
|
|
|
+ AddItemToPlayer(character, item);
|
|
|
+ if (showDebugLogs)
|
|
|
+ {
|
|
|
+ Debug.Log($"💰 {item} given to {character.CharacterName} (no selection made)");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Clear selections for next battle
|
|
|
+ selectedPlayerForItem.Clear();
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// Add an item to a player's inventory
|
|
|
/// </summary>
|