huddebugwincharstomach.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. class HudDebugWinCharStomach extends HudDebugWinBase
  2. {
  3. TextListboxWidget m_WgtValues;
  4. TextWidget m_WgtOverall;
  5. //============================================
  6. // Constructor
  7. //============================================
  8. void HudDebugWinCharStomach(Widget widget_root)
  9. {
  10. m_WgtValues = TextListboxWidget.Cast( widget_root.FindAnyWidget("txl_StomachContents") );
  11. m_WgtOverall = TextWidget.Cast( widget_root.FindAnyWidget("InfoOverall") );
  12. //FitWindow();
  13. }
  14. //============================================
  15. // Destructor
  16. //============================================
  17. void ~HudDebugWinCharStomach()
  18. {
  19. SetUpdate( false );
  20. }
  21. //============================================
  22. // GetWinType
  23. //============================================
  24. override int GetType()
  25. {
  26. return HudDebug.HUD_WIN_CHAR_STOMACH;
  27. }
  28. //============================================
  29. // Show
  30. //============================================
  31. override void Show()
  32. {
  33. super.Show();
  34. //Print("Show()");
  35. SetUpdate( true );
  36. }
  37. //============================================
  38. // Hide
  39. //============================================
  40. override void Hide()
  41. {
  42. super.Hide();
  43. //Print("Hide()");
  44. SetUpdate( false );
  45. }
  46. //============================================
  47. // SetUpdate
  48. //============================================
  49. override void SetUpdate( bool state )
  50. {
  51. //Disable update on server (PluginDeveloperSync)
  52. PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
  53. PluginDeveloperSync developer_sync = PluginDeveloperSync.Cast( GetPlugin( PluginDeveloperSync ) );
  54. //if client, send RPC
  55. if ( GetGame().IsClient() )
  56. {
  57. ref Param1<bool> params = new Param1<bool>( state );
  58. if ( player )
  59. {
  60. player.RPCSingleParam( ERPCs.DEV_STOMACH_UPDATE, params, true );
  61. SetRPCSent();
  62. }
  63. }
  64. //else set directly
  65. else
  66. {
  67. if ( developer_sync )
  68. {
  69. developer_sync.EnableUpdate( state, ERPCs.DEV_STOMACH_UPDATE, player );
  70. }
  71. }
  72. }
  73. override void Update()
  74. {
  75. super.Update();
  76. //Print("Update()");
  77. //refresh notifiers
  78. SetContentValues();
  79. }
  80. void SetContentValues()
  81. {
  82. PluginDeveloperSync developer_sync = PluginDeveloperSync.Cast( GetPlugin( PluginDeveloperSync ) );
  83. //clear window
  84. ClearValues();
  85. int count = developer_sync.m_PlayerStomachSynced.Count() - 2; // dont iterate appended params (stomach volume and temperature)
  86. for ( int i = 0; i < count; i++ )
  87. {
  88. //new Param5<int,int,int,float,float>(id, food_stage, agents, amount,temperature);
  89. Param5<int,int,int,float, float> p5 = Param5<int,int,int,float,float>.Cast(developer_sync.m_PlayerStomachSynced.Get(i));
  90. AddValue( PlayerStomach.GetClassnameFromID(p5.param1), p5.param2, p5.param3, p5.param4, p5.param5);
  91. }
  92. if( developer_sync.m_PlayerStomachSynced.Count() )
  93. {
  94. int last_index = developer_sync.m_PlayerStomachSynced.Count() - 2;
  95. Param1<float> p1 = Param1<float>.Cast(developer_sync.m_PlayerStomachSynced.Get(last_index));
  96. last_index = developer_sync.m_PlayerStomachSynced.Count() - 1;
  97. Param1<float> paramTemp = Param1<float>.Cast(developer_sync.m_PlayerStomachSynced.Get(last_index));
  98. m_WgtOverall.SetText("Overall volume:" + p1.param1.ToString() + " " + "Average temperature:" + paramTemp.param1.ToString());
  99. }
  100. else
  101. {
  102. m_WgtOverall.SetText("Overall volume: 0" + " " + "Average temperature: 0");
  103. }
  104. //fit to screen
  105. //FitWindow();
  106. }
  107. void AddValue( string classname, int food_stage, int agents, float amount, float temperature)
  108. {
  109. int index = m_WgtValues.AddItem( classname, NULL, 0 );
  110. string stage = typename.EnumToString(FoodStageType, food_stage) + "(" + food_stage.ToString()+")";;
  111. m_WgtValues.SetItem( index, amount.ToString(), NULL, 1 );
  112. m_WgtValues.SetItem( index,stage , NULL, 2 );
  113. m_WgtValues.SetItem( index, temperature.ToString() , NULL, 3 );
  114. array<string> agent_list = GetAgentsArray(agents);
  115. string agent_line = "("+agents.ToString()+") ";
  116. for(int i = 0; i < agent_list.Count();i++)
  117. {
  118. agent_line += "," +agent_list.Get(i);
  119. }
  120. m_WgtValues.SetItem( index, agent_line , NULL, 4);
  121. }
  122. array<string> GetAgentsArray(int agents)
  123. {
  124. array<string> list = new array<string>;
  125. for(int i = 0; i < 32; i++)
  126. {
  127. int agent = agents & (1 << i);
  128. if(agent)
  129. {
  130. list.Insert(PluginTransmissionAgents.GetNameByID(agent));
  131. }
  132. }
  133. return list;
  134. }
  135. void ClearValues()
  136. {
  137. m_WgtValues.ClearItems();
  138. }
  139. void FitWindow()
  140. {
  141. FitWindowByContent( m_WgtValues );
  142. }
  143. }