StoreCategory.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //-----------------------------------------------------------------------------
  2. // StoreCategory.cs
  3. //
  4. // Microsoft XNA Community Game Platform
  5. // Copyright (C) Microsoft Corporation. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. using System;
  8. using System.Collections.Generic;
  9. using Microsoft.Xna.Framework.Content;
  10. namespace RolePlaying.Data
  11. {
  12. /// <summary>
  13. /// A category of gear for sale in a store.
  14. /// </summary>
  15. public class StoreCategory
  16. {
  17. /// <summary>
  18. /// The display name of this store category.
  19. /// </summary>
  20. private string name;
  21. /// <summary>
  22. /// The display name of this store category.
  23. /// </summary>
  24. public string Name
  25. {
  26. get { return name; }
  27. set { name = value; }
  28. }
  29. /// <summary>
  30. /// The content names for the gear available in this category.
  31. /// </summary>
  32. private List<string> availableContentNames = new List<string>();
  33. /// <summary>
  34. /// The content names for the gear available in this category.
  35. /// </summary>
  36. public List<string> AvailableContentNames
  37. {
  38. get { return availableContentNames; }
  39. set { availableContentNames = value; }
  40. }
  41. /// <summary>
  42. /// The gear available in this category.
  43. /// </summary>
  44. private List<Gear> availableGear = new List<Gear>();
  45. /// <summary>
  46. /// The gear available in this category.
  47. /// </summary>
  48. [ContentSerializerIgnore]
  49. public List<Gear> AvailableGear
  50. {
  51. get { return availableGear; }
  52. set { availableGear = value; }
  53. }
  54. /// <summary>
  55. /// Reads a StoreCategory object from the content pipeline.
  56. /// </summary>
  57. public class StoreCategoryReader : ContentTypeReader<StoreCategory>
  58. {
  59. /// <summary>
  60. /// Reads a StoreCategory object from the content pipeline.
  61. /// </summary>
  62. protected override StoreCategory Read(ContentReader input,
  63. StoreCategory existingInstance)
  64. {
  65. StoreCategory storeCategory = existingInstance;
  66. if (storeCategory == null)
  67. {
  68. storeCategory = new StoreCategory();
  69. }
  70. storeCategory.Name = input.ReadString();
  71. storeCategory.AvailableContentNames.AddRange(
  72. input.ReadObject<List<string>>());
  73. // populate the gear list based on the content names
  74. foreach (string gearName in storeCategory.AvailableContentNames)
  75. {
  76. storeCategory.AvailableGear.Add(input.ContentManager.Load<Gear>(
  77. System.IO.Path.Combine("Gear", gearName)));
  78. }
  79. return storeCategory;
  80. }
  81. }
  82. }
  83. }