head.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. class Head_Default extends Head
  2. {
  3. bool m_handling_exception = false;
  4. int m_beard_idx;
  5. int m_hair_idx;
  6. ref map<int,ref SelectionTranslation> m_HeadHairHidingStateMap;
  7. ref array<string> m_HeadHairSelectionArray;
  8. void Head_Default()
  9. {
  10. Init();
  11. }
  12. void Init()
  13. {
  14. m_HeadHairHidingStateMap = new map<int,ref SelectionTranslation>;
  15. m_HeadHairSelectionArray = new array<string>;
  16. ConfigGetTextArray("simpleHiddenSelections",m_HeadHairSelectionArray);
  17. m_beard_idx = m_HeadHairSelectionArray.Find("beard");
  18. m_hair_idx = m_HeadHairSelectionArray.Find("hair");
  19. if (!ConfigIsExisting("HairHiding"))
  20. m_handling_exception = true;
  21. InitSelectionTranslation();
  22. }
  23. void InitSelectionTranslation()
  24. {
  25. for (int i = 0; i < m_HeadHairSelectionArray.Count(); i++)
  26. {
  27. SelectionTranslation selTran = new SelectionTranslation(this,i);
  28. selTran.SetSelectionState(true);
  29. m_HeadHairHidingStateMap.Insert(i,selTran); //all considered "shown" on init
  30. }
  31. }
  32. bool GetHeadHideableSelections(out array<string> selections)
  33. {
  34. selections = m_HeadHairSelectionArray;
  35. return true;
  36. }
  37. int GetBeardIndex()
  38. {
  39. return m_beard_idx;
  40. }
  41. int GetHairIndex()
  42. {
  43. return m_hair_idx;
  44. }
  45. int GetSelectionIndex(string str)
  46. {
  47. return m_HeadHairSelectionArray.Find(str);
  48. }
  49. bool IsHandlingException()
  50. {
  51. return m_handling_exception;
  52. }
  53. };
  54. class SelectionTranslation
  55. {
  56. bool m_SelectionState;
  57. bool m_TranslationFinished = false;
  58. string m_BasePath;// = "cfgVehicles " + GetType() + " HairHiding";
  59. ref array<int> m_TranslatedSelections;
  60. Head_Default m_Head;
  61. void SelectionTranslation(Head_Default head, int idx)
  62. {
  63. m_Head = head;
  64. m_BasePath = "cfgVehicles " + m_Head.GetType() + " HairHiding";
  65. InitTranslatedSelections(idx);
  66. }
  67. void InitTranslatedSelections(int idx)
  68. {
  69. if ( !m_Head.ConfigIsExisting("HairHiding") )
  70. return;
  71. string path;
  72. int selectionIdx = -1;
  73. m_TranslatedSelections = new array<int>;
  74. //Hair
  75. path = m_BasePath + " Group_Hair";
  76. SearchAndTranslate(path,idx);
  77. //Beard
  78. path = m_BasePath + " Group_Beard";
  79. SearchAndTranslate(path,idx);
  80. //Hair + Beard
  81. path = m_BasePath + " Group_HairBeard";
  82. SearchAndTranslate(path,idx);
  83. //other
  84. for (int i = 0; !m_TranslationFinished; i++)
  85. {
  86. path = m_BasePath + " Group_" + i;
  87. if ( g_Game.ConfigIsExisting(path) )
  88. {
  89. SearchAndTranslate(path,idx);
  90. }
  91. else
  92. {
  93. m_TranslationFinished = true;
  94. }
  95. }
  96. }
  97. bool SearchAndTranslate(string path, int idx)
  98. {
  99. if (!g_Game.ConfigIsExisting(path))
  100. return false;
  101. array<string> tempArrayStr = new array<string>;
  102. g_Game.ConfigGetTextArray(path + " memberSelections", tempArrayStr);
  103. int indexInOriginalArray = -2;
  104. for (int i = 0; i < tempArrayStr.Count(); i++)
  105. {
  106. indexInOriginalArray = m_Head.m_HeadHairSelectionArray.Find(tempArrayStr.Get(i));
  107. if ( idx == indexInOriginalArray ) //found it
  108. {
  109. g_Game.ConfigGetTextArray(path + " simpleSelectionName", tempArrayStr);
  110. for (i = 0; i < tempArrayStr.Count(); i++)
  111. {
  112. m_TranslatedSelections.Insert(m_Head.m_HeadHairSelectionArray.Find(tempArrayStr.Get(i)));
  113. }
  114. m_TranslationFinished = true;
  115. return true;
  116. }
  117. }
  118. return false;
  119. }
  120. void SetSelectionState(bool state)
  121. {
  122. m_SelectionState = state;
  123. }
  124. bool GetSelectionState()
  125. {
  126. return m_SelectionState;
  127. }
  128. ref array<int> GetTranslatedSelections()
  129. {
  130. return m_TranslatedSelections;
  131. }
  132. };