DataBool.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #include "DataBool.h"
  2. #include "..\..\icommon\memfile.h"
  3. #include "..\..\..\common_h\core.h"
  4. #include "..\..\TextFile.h"
  5. #ifndef _XBOX
  6. #include "..\..\..\common_h\tinyxml\tinyxml.h"
  7. #endif
  8. #include "fieldlist.h"
  9. #include "..\..\..\Common_h\data_swizzle.h"
  10. #pragma warning (disable : 4800)
  11. //конструктор/деструктор
  12. DataBool::DataBool (FieldList* pMaster)
  13. {
  14. szName = NULL;
  15. szEditorName = NULL;
  16. Master = pMaster;
  17. Value = false;
  18. }
  19. DataBool::~DataBool ()
  20. {
  21. }
  22. //Получить значение
  23. bool DataBool::GetValue ()
  24. {
  25. return Value;
  26. }
  27. //Установить значение
  28. void DataBool::SetValue (bool val)
  29. {
  30. Value = val;
  31. if (Master) Master->UpdateCache();
  32. }
  33. void DataBool::Load (MemFile* File)
  34. {
  35. dword dwValue = 0;
  36. File->ReadType(dwValue);
  37. XSwizzleDWord(dwValue);
  38. SetValue (dwValue);
  39. //static char AttribueName[128];
  40. dword NameLength = 0;
  41. File->ReadType(NameLength);
  42. XSwizzleDWord(NameLength);
  43. Assert (NameLength < 128);
  44. const char* AttribueName = File->GetPointerToString(NameLength);
  45. //File->Read(AttribueName, NameLength);
  46. SetName (AttribueName, "a");
  47. if (Master) Master->UpdateCache();
  48. }
  49. void DataBool::SetName (const char* szName, const char* szEditorName)
  50. {
  51. //api->Trace("DataBool::SetName - '%s'", szName);
  52. this->szName = szName;
  53. this->szEditorName = szEditorName;
  54. }
  55. const char* DataBool::GetName ()
  56. {
  57. return szName;
  58. }
  59. void DataBool::Write (MemFile* File)
  60. {
  61. DWORD dwValue = GetValue();
  62. File->WriteType(dwValue);
  63. //save name
  64. DWORD NameLength = crt_strlen (szName);
  65. DWORD NameLengthPlusZero = NameLength+1;
  66. File->WriteType(NameLengthPlusZero);
  67. Assert (NameLength < 128);
  68. File->Write(szName, NameLength);
  69. File->WriteZeroByte();
  70. }
  71. const char* DataBool::GetEditorName ()
  72. {
  73. return szEditorName;
  74. }
  75. #ifndef _XBOX
  76. void DataBool::WriteXML (TextFile* xmlFile, dword level)
  77. {
  78. xmlFile->Write((level+1), "<Name val = \"%s\" />\n", szName);
  79. xmlFile->Write((level+1), "<Value val = \"%d\" />\n", GetValue());
  80. }
  81. void DataBool::LoadXML (TiXmlElement* root)
  82. {
  83. TiXmlElement* name = root->FirstChildElement("Name");
  84. TiXmlElement* value = root->FirstChildElement("Value");
  85. if (name)
  86. {
  87. SetName (name->Attribute("val"), "a");
  88. }
  89. if (value)
  90. {
  91. SetValue (atoi (value->Attribute("val")));
  92. }
  93. }
  94. #endif