StoreCategory.cs 3.2 KB

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