LocStringAttr.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #include "LocStringAttr.h"
  2. #include "..\strutil.h"
  3. #include "..\..\missioneditor.h"
  4. #include "..\AttributeList.h"
  5. #include "..\..\forms\globalParams.h"
  6. extern IGUIManager* igui;
  7. ILocStrings * pLocStr = NULL;
  8. LocStringAttribute & LocStringAttribute::operator = (const LocStringAttribute & source)
  9. {
  10. SetValue (source.GetValue());
  11. BaseAttribute::Copy(*this, source);
  12. return *this;
  13. }
  14. LocStringAttribute & LocStringAttribute::operator = (const IMOParams::LocString& source)
  15. {
  16. SetName (source.name);
  17. return *this;
  18. }
  19. LocStringAttribute::LocStringAttribute ()
  20. {
  21. pLocStr = (ILocStrings*)api->GetService("LocStrings");
  22. currentID = -1;
  23. Type = IMOParams::t_locstring;
  24. }
  25. LocStringAttribute::~LocStringAttribute ()
  26. {
  27. //api->Trace("string deleted\n");
  28. }
  29. void LocStringAttribute::SetValue (long strID)
  30. {
  31. currentID = strID;
  32. }
  33. long LocStringAttribute::GetValue () const
  34. {
  35. return currentID;
  36. }
  37. void LocStringAttribute::PopupEdit (int pX, int pY)
  38. {
  39. //GUIWindow* wnd = igui->FindWindow (STRINGEDIT_WINDOWNAME);
  40. //if (wnd) igui->Close (wnd);
  41. Form = NEW TLocStringEdit (0, 0);
  42. Form->SetPosition (pX, pY);
  43. // Form->lDescription->Caption = GetName ();
  44. Form->TextValue->Text = pLocStr->GetString(currentID);
  45. Form->TextValue->Hint = GetName ();
  46. Form->MasterAttrib = this;
  47. igui->ShowModal (Form);
  48. // Обязательно нужно сделать...
  49. pForm = Form;
  50. }
  51. void LocStringAttribute::AddToWriter (MOPWriter& wrt)
  52. {
  53. wrt.AddLocString(currentID);
  54. }
  55. void LocStringAttribute::WriteToFile (IFile* pFile)
  56. {
  57. }
  58. #pragma warning (disable : 4800)
  59. void LocStringAttribute::LoadFromFile (IFile* pFile, const char* ClassName)
  60. {
  61. }
  62. void LocStringAttribute::UpdateTree(GUITreeNode * node, string * v)
  63. {
  64. gp->__tmpText = GetName ();
  65. gp->__tmpText += "#c808080";
  66. const char* currentStr = pLocStr->GetString(currentID);
  67. gp->__tmpText += string (" '") + string(currentStr) + string ("'");
  68. if (v && currentStr && v->IsEmpty())
  69. {
  70. *v = currentStr;
  71. }
  72. node->Image->Load("meditor\\string");
  73. node->Tag = TAG_ATTRIBUTE;
  74. node->CanDrag = false;
  75. node->CanDrop = false;
  76. node->CanCopy = false;
  77. node->Data = this;
  78. if (gp->__tmpText.Size() > 120)
  79. {
  80. gp->__tmpText.Delete(120, gp->__tmpText.Size());
  81. gp->__tmpText += "...";
  82. }
  83. //nNode->Text = ;
  84. node->SetText(gp->__tmpText);
  85. }
  86. void LocStringAttribute::Add2Tree (GUITreeNodes* nodes, TreeNodesPool* nodesPool, string * v)
  87. {
  88. GUITreeNode* nNode = nodesPool->CreateNode();
  89. UpdateTree(nNode, v);
  90. nodes->Add(nNode);
  91. }
  92. void LocStringAttribute::WriteToXML (TextFile &file, int level)
  93. {
  94. file.Write(level, "<locstring val = \"%s\">\n", GetName ());
  95. file.Write(level+1, "<value val = \"%d\" />\n", currentID);
  96. file.Write(level, "</locstring>\n");
  97. }
  98. void LocStringAttribute::ReadXML (TiXmlElement* Root, const char* szMasterClass)
  99. {
  100. const char* objectName = Root->Attribute("val");
  101. SetName(objectName);
  102. TiXmlElement* node = Root->FirstChildElement("value");
  103. if (node) currentID = atoi (node->Attribute("val"));
  104. }