huddebugwinhorticulture.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. class HudDebugWinHorticulture : HudDebugWinBase
  2. {
  3. protected EditBoxWidget m_FullMaturityEditBox;
  4. protected EditBoxWidget m_SpoilEditBox;
  5. protected EditBoxWidget m_SpoilRemoveEditBox;
  6. protected EditBoxWidget m_DryRemoveEditBox;
  7. protected EditBoxWidget m_SetAllEditBox;
  8. protected EditBoxWidget m_SpeedEditBox;
  9. protected ButtonWidget m_ButtonUpdate;
  10. protected ButtonWidget m_ButtonUpdateTarget;
  11. protected ButtonWidget m_ButtonReset;
  12. protected ButtonWidget m_ButtonSetAll;
  13. protected ButtonWidget m_ButtonSpeed;
  14. protected PluginDeveloperSync m_DevSyncPlugin;
  15. void HudDebugWinHorticulture(Widget widget_root)
  16. {
  17. m_WgtRoot = widget_root;
  18. }
  19. override int GetType()
  20. {
  21. return HudDebug.HUD_WIN_HORTICULTURE;
  22. }
  23. override void Show()
  24. {
  25. super.Show();
  26. if (!m_DevSyncPlugin)
  27. m_DevSyncPlugin = PluginDeveloperSync.Cast( GetPlugin( PluginDeveloperSync ) );
  28. }
  29. //! Called from HudDebug.c
  30. bool OnClick( Widget w, int x, int y, int button )
  31. {
  32. if (!w)
  33. return false;
  34. if (!m_ButtonUpdate)
  35. {
  36. m_ButtonUpdate = ButtonWidget.Cast(m_WgtRoot.FindAnyWidget("ButtonUpdate"));
  37. m_ButtonUpdateTarget = ButtonWidget.Cast(m_WgtRoot.FindAnyWidget("ButtonUpdateTarget"));
  38. m_ButtonReset = ButtonWidget.Cast(m_WgtRoot.FindAnyWidget("ButtonReset"));
  39. m_ButtonSetAll = ButtonWidget.Cast(m_WgtRoot.FindAnyWidget("ButtonSetAll"));
  40. m_ButtonSpeed = ButtonWidget.Cast(m_WgtRoot.FindAnyWidget("ButtonSpeed"));
  41. m_SetAllEditBox = EditBoxWidget.Cast(m_WgtRoot.FindAnyWidget("SetAllEBox"));
  42. m_FullMaturityEditBox = EditBoxWidget.Cast(m_WgtRoot.FindAnyWidget("FullMaturityEBox"));
  43. m_SpoilEditBox = EditBoxWidget.Cast(m_WgtRoot.FindAnyWidget("SpoilEBox"));
  44. m_SpoilRemoveEditBox = EditBoxWidget.Cast(m_WgtRoot.FindAnyWidget("SpoilRemoveEBox"));
  45. m_DryRemoveEditBox = EditBoxWidget.Cast(m_WgtRoot.FindAnyWidget("DryRemoveEBox"));
  46. m_SpeedEditBox = EditBoxWidget.Cast(m_WgtRoot.FindAnyWidget("SpeedEBox"));
  47. }
  48. if (w == m_ButtonUpdate)
  49. {
  50. SendRPCUpdate(false);
  51. return true;
  52. }
  53. if (w == m_ButtonUpdateTarget)
  54. {
  55. SendRPCUpdate(true);
  56. return true;
  57. }
  58. if (w == m_ButtonSpeed)
  59. {
  60. float speedMult = m_SpeedEditBox.GetText().ToFloat();
  61. SendRPCSpeed(speedMult);
  62. return true;
  63. }
  64. if (w == m_ButtonSetAll)
  65. {
  66. int setAll = m_SetAllEditBox.GetText().ToInt();
  67. m_FullMaturityEditBox.SetText(setAll.ToString());
  68. m_SpoilEditBox.SetText(setAll.ToString());
  69. m_SpoilRemoveEditBox.SetText(setAll.ToString());
  70. m_DryRemoveEditBox.SetText(setAll.ToString());
  71. return true;
  72. }
  73. if (w == m_ButtonReset)
  74. {
  75. m_FullMaturityEditBox.SetText("0");
  76. m_SpoilEditBox.SetText("0");
  77. m_SpoilRemoveEditBox.SetText("0");
  78. m_DryRemoveEditBox.SetText("0");
  79. m_SpeedEditBox.SetText("1");
  80. SendRPCUpdate(false);
  81. SendRPCSpeed(1);
  82. return true;
  83. }
  84. return false;
  85. }
  86. protected void SendRPCSpeed(float multiplier)
  87. {
  88. multiplier = Math.Clamp(multiplier, 0.1, 1000);
  89. Param1<float> param = new Param1<float>(multiplier);
  90. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  91. if (!GetGame().IsMultiplayer())
  92. PlantBase.DebugSetTickSpeedMultiplier(multiplier);
  93. else
  94. player.RPCSingleParam(ERPCs.DEV_RPC_HORTICULTURE_SPEED, param, true);
  95. }
  96. protected void SendRPCUpdate(bool isTarget)
  97. {
  98. int slotID = -1;
  99. GardenBase garden;
  100. int maturity = m_FullMaturityEditBox.GetText().ToInt();
  101. int spoil = m_SpoilEditBox.GetText().ToInt();
  102. int spoilRemove = m_SpoilRemoveEditBox.GetText().ToInt();
  103. int dryRemove = m_DryRemoveEditBox.GetText().ToInt();
  104. Param6<int, GardenBase, int, int, int, int> params;
  105. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  106. if (isTarget && player && player.GetActionManager())
  107. {
  108. ActionTarget at = player.GetActionManager().FindActionTarget();
  109. if (at)
  110. garden = GardenBase.Cast(at.GetObject());
  111. if (garden)
  112. {
  113. array<string> selections = new array<string>;
  114. garden.GetActionComponentNameList(at.GetComponentIndex(), selections);
  115. for (int s = 0; s < selections.Count(); s++)
  116. {
  117. string selection = selections[s];
  118. Slot slot = garden.GetSlotBySelection( selection );
  119. if (slot && slot.GetPlant())
  120. {
  121. slotID = slot.GetSlotIndex();
  122. }
  123. }
  124. }
  125. }
  126. params = new Param6<int, GardenBase, int, int, int, int>(slotID, garden, maturity, spoil, spoilRemove, dryRemove);
  127. if (!GetGame().IsMultiplayer())
  128. {
  129. if (slotID != -1 && garden)
  130. {
  131. Slot gSlot = garden.GetSlotByIndex(slotID);
  132. if (gSlot && gSlot.GetPlant())
  133. gSlot.GetPlant().DebugSetTimes(maturity, spoil, spoilRemove, dryRemove);
  134. }
  135. else
  136. PlantBase.DebugSetGlobalTimes(params.param3, params.param4, params.param5, params.param6);
  137. }
  138. else if (player)
  139. player.RPCSingleParam(ERPCs.DEV_RPC_HORTICULTURE_UPDATE, params, true);
  140. }
  141. }