GUIEventWatcher.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #include "GUIEventWatcher.h"
  2. #include "../utils/InterfaceUtils.h"
  3. GUIEventWatcher:: GUIEventWatcher(void)
  4. {
  5. m_target.Reset();
  6. m_showState = false;
  7. m_activeState = false;
  8. m_focusState = false;
  9. m_fadeState = BaseGUIElement::FadingFinished;
  10. m_active = false;
  11. }
  12. GUIEventWatcher::~GUIEventWatcher(void)
  13. {
  14. }
  15. void GUIEventWatcher::Restart()
  16. {
  17. Show(true);
  18. Activate(m_active);
  19. }
  20. void GUIEventWatcher::ReadMOPs(MOPReader &reader)
  21. {
  22. m_params.subject = reader.String();
  23. m_params.watchShowOn = reader.Bool();
  24. m_params.watchShowOff = reader.Bool();
  25. m_params.watchActivate = reader.Bool();
  26. m_params.watchDeactivate = reader.Bool();
  27. m_params.watchFocusOn = reader.Bool();
  28. m_params.watchFocusOff = reader.Bool();
  29. m_params.watchFadeOn = reader.Bool();
  30. m_params.watchFadeOff = reader.Bool();
  31. m_params.eventWorker.Init(reader);
  32. Activate(m_active = reader.Bool());
  33. }
  34. bool GUIEventWatcher::Create(MOPReader &reader)
  35. {
  36. return EditMode_Update(reader);
  37. }
  38. bool GUIEventWatcher::EditMode_Update(MOPReader &reader)
  39. {
  40. ReadMOPs(reader);
  41. if( FindObject(m_params.subject,m_target))
  42. {
  43. if( m_target.Ptr()->Is(InterfaceUtils::GetBaseId()))
  44. {
  45. BaseGUIElement *p = (BaseGUIElement *)m_target.Ptr();
  46. m_showState = p->IsShow();
  47. m_activeState = p->IsActive();
  48. m_focusState = p->HaveFocus();
  49. m_fadeState = p->GetFadeState();
  50. }
  51. else
  52. m_target.Reset();
  53. }
  54. return true;
  55. }
  56. void GUIEventWatcher::Activate(bool isActive)
  57. {
  58. MissionObject::Activate(isActive);
  59. DelUpdate(&GUIEventWatcher::Work);
  60. if( isActive )
  61. SetUpdate(&GUIEventWatcher::Work,ML_EXECUTE_END);
  62. }
  63. void GUIEventWatcher::Work(float deltaTime, long)
  64. {
  65. if( EditMode_IsOn())
  66. {
  67. m_target.Validate();
  68. }
  69. BaseGUIElement *target = (BaseGUIElement *)m_target.Ptr();
  70. if( !target )
  71. return;
  72. if( m_params.watchShowOn && target->IsShow() && !m_showState)
  73. {
  74. m_params.eventWorker.Activate(Mission(),false);
  75. }
  76. if( m_params.watchShowOff && !target->IsShow() && m_showState )
  77. {
  78. m_params.eventWorker.Activate(Mission(),false);
  79. }
  80. if( m_params.watchActivate && target->IsActive() && !m_activeState )
  81. {
  82. m_params.eventWorker.Activate(Mission(),false);
  83. }
  84. if( m_params.watchDeactivate && !target->IsActive() && m_activeState )
  85. {
  86. m_params.eventWorker.Activate(Mission(),false);
  87. }
  88. if (m_params.watchFocusOn && target->HaveFocus() && !m_focusState)
  89. {
  90. m_params.eventWorker.Activate(Mission(),false);
  91. }
  92. if( m_params.watchFocusOff && !target->HaveFocus() && m_focusState )
  93. {
  94. m_params.eventWorker.Activate(Mission(),false);
  95. }
  96. if( m_params.watchFadeOn &&
  97. (target->GetFadeState() == BaseGUIElement::FadingIn || target->GetFadeState() == BaseGUIElement::FadingOut) &&
  98. m_fadeState == BaseGUIElement::FadingFinished )
  99. {
  100. m_params.eventWorker.Activate(Mission(),false);
  101. }
  102. if( m_params.watchFadeOff &&
  103. target->GetFadeState() == BaseGUIElement::FadingFinished &&
  104. (m_fadeState == BaseGUIElement::FadingIn || m_fadeState == BaseGUIElement::FadingOut))
  105. {
  106. m_params.eventWorker.Activate(Mission(),false);
  107. }
  108. m_showState = target->IsShow();
  109. m_activeState = target->IsActive();
  110. m_focusState = target->HaveFocus();
  111. m_fadeState = target->GetFadeState();
  112. }
  113. static char GUIDescription[] =
  114. "GUI Event watcher.\n\n"
  115. "Monitors GUI element and triggers on state change.";
  116. MOP_BEGINLISTCG(GUIEventWatcher, "GUI Event Watcher", '1.00', 10000, GUIDescription, "Interface")
  117. MOP_STRING("Object id", "")
  118. MOP_BOOL("Watch visible on" , false)
  119. MOP_BOOL("Watch visible off", false)
  120. MOP_BOOL("Watch activate" , false)
  121. MOP_BOOL("Watch deactivate" , false)
  122. MOP_BOOL("Watch get focus" , false)
  123. MOP_BOOL("Watch loose focus", false)
  124. MOP_BOOL("Watch begin fade" , false)
  125. MOP_BOOL("Watch end fade" , false)
  126. MOP_MISSIONTRIGGER("")
  127. MOP_BOOL("Active", true)
  128. MOP_ENDLIST(GUIEventWatcher)