1
0

objectactuator.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #include <precomp.h>
  2. #include "objectactuator.h"
  3. #include <api/console/console.h>
  4. #include <bfc/parse/paramparser.h>
  5. #include <api/script/scriptguid.h>
  6. XMLParamPair ObjectActuator::params[]=
  7. {
  8. {OBJECTACTUATOR_GROUP, L"GROUP"},
  9. {OBJECTACTUATOR_TARGET, L"TARGET"}
  10. };
  11. // -----------------------------------------------------------------------
  12. ObjectActuator::ObjectActuator()
  13. {
  14. myxuihandle = newXuiHandle();
  15. CreateXMLParameters(myxuihandle);
  16. }
  17. void ObjectActuator::CreateXMLParameters(int master_handle)
  18. {
  19. //OBJECTACTUATOR_PARENT::CreateXMLParameters(master_handle);
  20. int numParams = sizeof(params) / sizeof(params[0]);
  21. hintNumberOfParams(myxuihandle, numParams);
  22. for (int i = 0;i < numParams;i++)
  23. addParam(myxuihandle, params[i], XUI_ATTRIBUTE_IMPLIED);
  24. }
  25. // -----------------------------------------------------------------------
  26. ObjectActuator::~ObjectActuator() {
  27. }
  28. // -----------------------------------------------------------------------
  29. int ObjectActuator::setXuiParam(int xuihandle, int xmlattributeid, const wchar_t *xmlattributename, const wchar_t *value) {
  30. if (xuihandle != myxuihandle)
  31. return OBJECTACTUATOR_PARENT::setXuiParam(xuihandle, xmlattributeid, xmlattributename, value);
  32. switch (xmlattributeid) {
  33. case OBJECTACTUATOR_TARGET:
  34. if (actuator_wantTargetParam())
  35. actuator_setTarget(value);
  36. break;
  37. case OBJECTACTUATOR_GROUP:
  38. if (actuator_wantGroupParam())
  39. actuator_setGroup(value);
  40. break;
  41. default:
  42. return 0;
  43. }
  44. return 1;
  45. }
  46. // -----------------------------------------------------------------------
  47. void ObjectActuator::actuator_setTarget(const wchar_t *value) {
  48. objectsid = value;
  49. if (isInited() && actuator_wantAutoPerform())
  50. performActions();
  51. }
  52. // -----------------------------------------------------------------------
  53. void ObjectActuator::actuator_setGroup(const wchar_t *value) {
  54. groupid = value;
  55. }
  56. // -----------------------------------------------------------------------
  57. int ObjectActuator::onInit() {
  58. int rt = OBJECTACTUATOR_PARENT::onInit();
  59. if (actuator_wantAutoPerform()) performActions();
  60. return rt;
  61. }
  62. // -----------------------------------------------------------------------
  63. void ObjectActuator::performActions()
  64. {
  65. ifc_window *group = getParent();
  66. if (!groupid.isempty())
  67. {
  68. GuiObject *o = getGuiObject()->guiobject_findObject(groupid);
  69. if (o != NULL) {
  70. group = o->guiobject_getRootWnd();
  71. }
  72. }
  73. GuiObject *go = static_cast<GuiObject *>(group->getInterface(guiObjectGuid));
  74. if (go == NULL) {
  75. DebugStringW(L"%s:group:%s\n", getActuatorTag(), groupid.getValue());
  76. return;
  77. }
  78. ParamParser pp(objectsid);
  79. for (int i=0;i<pp.getNumItems();i++) {
  80. GuiObject *target = go->guiobject_findObject(pp.enumItem(i));
  81. if (target != NULL)
  82. actuator_onPerform(target);
  83. else
  84. DebugStringW(L"%s:%s/%s\n", getActuatorTag(), groupid.getValue(), objectsid.getValue());
  85. }
  86. }
  87. const wchar_t *ObjectActuator::getActuatorTag() {
  88. return L"ObjectActuator";
  89. }