SimpleTownShopUI.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using UnityEngine;
  2. using UnityEngine.UIElements;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System;
  6. public class SimpleTownShopUI : MonoBehaviour
  7. {
  8. private TownShop currentShop;
  9. private TeamCharacter[] currentTeam;
  10. private Action onCloseCallback;
  11. public void OpenShop(TownShop shop, TeamCharacter[] team, Action closeCallback)
  12. {
  13. currentShop = shop;
  14. currentTeam = team;
  15. onCloseCallback = closeCallback;
  16. Debug.Log($"Opening {shop.buildingName} - This is a simplified shop UI for testing");
  17. CreateSimpleUI();
  18. }
  19. private void CreateSimpleUI()
  20. {
  21. // Create UI Document
  22. var uiDocument = gameObject.AddComponent<UIDocument>();
  23. // Create a simple overlay UI
  24. var root = new VisualElement();
  25. root.style.width = Length.Percent(100);
  26. root.style.height = Length.Percent(100);
  27. root.style.position = Position.Absolute;
  28. root.style.backgroundColor = new Color(0, 0, 0, 0.8f);
  29. root.style.justifyContent = Justify.Center;
  30. root.style.alignItems = Align.Center;
  31. // Create shop dialog
  32. var dialog = new VisualElement();
  33. dialog.style.width = 400;
  34. dialog.style.height = 300;
  35. dialog.style.backgroundColor = new Color(0.2f, 0.15f, 0.1f, 1f);
  36. dialog.style.borderTopWidth = 3;
  37. dialog.style.borderBottomWidth = 3;
  38. dialog.style.borderLeftWidth = 3;
  39. dialog.style.borderRightWidth = 3;
  40. dialog.style.borderTopColor = new Color(0.8f, 0.6f, 0.2f, 1f);
  41. dialog.style.borderBottomColor = new Color(0.8f, 0.6f, 0.2f, 1f);
  42. dialog.style.borderLeftColor = new Color(0.8f, 0.6f, 0.2f, 1f);
  43. dialog.style.borderRightColor = new Color(0.8f, 0.6f, 0.2f, 1f);
  44. dialog.style.paddingTop = 20;
  45. dialog.style.paddingBottom = 20;
  46. dialog.style.paddingLeft = 20;
  47. dialog.style.paddingRight = 20;
  48. dialog.style.justifyContent = Justify.SpaceBetween;
  49. // Title
  50. var title = new Label(currentShop.buildingName);
  51. title.style.fontSize = 24;
  52. title.style.color = new Color(1f, 0.84f, 0f, 1f);
  53. title.style.unityFontStyleAndWeight = FontStyle.Bold;
  54. title.style.unityTextAlign = TextAnchor.MiddleCenter;
  55. // Content
  56. var content = new VisualElement();
  57. content.style.flexGrow = 1;
  58. content.style.justifyContent = Justify.Center;
  59. var welcomeText = new Label($"Welcome to {currentShop.buildingName}!");
  60. welcomeText.style.color = Color.white;
  61. welcomeText.style.fontSize = 16;
  62. welcomeText.style.unityTextAlign = TextAnchor.MiddleCenter;
  63. welcomeText.style.marginBottom = 10;
  64. var inventoryText = new Label($"Items in stock: {currentShop.currentInventory.Count}");
  65. inventoryText.style.color = Color.white;
  66. inventoryText.style.fontSize = 14;
  67. inventoryText.style.unityTextAlign = TextAnchor.MiddleCenter;
  68. inventoryText.style.marginBottom = 10;
  69. var playerMoney = "";
  70. if (currentTeam != null && currentTeam.Length > 0)
  71. {
  72. var player = currentTeam[0];
  73. playerMoney = $"Your money: {player.gold}g {player.silver}s {player.copper}c";
  74. }
  75. else
  76. {
  77. playerMoney = "Your money: 100g 50s 25c";
  78. }
  79. var moneyText = new Label(playerMoney);
  80. moneyText.style.color = new Color(1f, 0.84f, 0f, 1f);
  81. moneyText.style.fontSize = 14;
  82. moneyText.style.unityTextAlign = TextAnchor.MiddleCenter;
  83. moneyText.style.marginBottom = 20;
  84. var noteText = new Label("(This is a simplified shop UI for testing.\nFull shop functionality will be added later.)");
  85. noteText.style.color = new Color(0.8f, 0.8f, 0.8f, 1f);
  86. noteText.style.fontSize = 12;
  87. noteText.style.unityTextAlign = TextAnchor.MiddleCenter;
  88. content.Add(welcomeText);
  89. content.Add(inventoryText);
  90. content.Add(moneyText);
  91. content.Add(noteText);
  92. // Close button
  93. var closeButton = new Button(() => CloseShop()) { text = "Close Shop" };
  94. closeButton.style.backgroundColor = new Color(0.7f, 0.2f, 0.2f, 1f);
  95. closeButton.style.color = Color.white;
  96. closeButton.style.paddingTop = 10;
  97. closeButton.style.paddingBottom = 10;
  98. closeButton.style.fontSize = 16;
  99. dialog.Add(title);
  100. dialog.Add(content);
  101. dialog.Add(closeButton);
  102. root.Add(dialog);
  103. uiDocument.rootVisualElement.Clear();
  104. uiDocument.rootVisualElement.Add(root);
  105. Debug.Log("Simple shop UI created and displayed!");
  106. }
  107. private void CloseShop()
  108. {
  109. Debug.Log($"Closing {currentShop.buildingName}");
  110. onCloseCallback?.Invoke();
  111. }
  112. }