datablockField.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "console/simBase.h"
  23. #include "console/simDatablock.h"
  24. #include "gui/editor/guiInspector.h"
  25. #include "gui/editor/inspector/datablockField.h"
  26. #include "gui/editor/inspector/group.h"
  27. #include "gui/buttons/guiIconButtonCtrl.h"
  28. #include "gui/editor/inspector/datablockField.h"
  29. #include "sfx/sfxTypes.h"
  30. #include "sfx/sfxDescription.h"
  31. #include "sfx/sfxEnvironment.h"
  32. #include "sfx/sfxAmbience.h"
  33. #include "sfx/sfxTrack.h"
  34. //-----------------------------------------------------------------------------
  35. // GuiInspectorDatablockField
  36. // Field construction for datablock types
  37. //-----------------------------------------------------------------------------
  38. IMPLEMENT_CONOBJECT(GuiInspectorDatablockField);
  39. ConsoleDocClass( GuiInspectorDatablockField,
  40. "@brief Custom field type for datablock enumeration.\n\n"
  41. "Editor use only.\n\n"
  42. "@internal"
  43. );
  44. GuiInspectorDatablockField::GuiInspectorDatablockField( StringTableEntry className )
  45. {
  46. setClassName( className );
  47. }
  48. void GuiInspectorDatablockField::setClassName( StringTableEntry className )
  49. {
  50. if( !className || !className[ 0 ] )
  51. mDesiredClass = NULL;
  52. else
  53. {
  54. mDesiredClass = AbstractClassRep::findClassRep( className );
  55. if( !mDesiredClass )
  56. Con::errorf( "GuiInspectorDatablockField::setClassName - no class '%s' found!", className );
  57. }
  58. }
  59. void GuiInspectorDatablockField::_populateMenu( GuiPopUpMenuCtrl* menu )
  60. {
  61. menu->addScheme( 1, ColorI( 80, 0, 0, 255 ), ColorI( 80, 0, 0, 255 ), ColorI( 80, 0, 0, 255 ) ); // For client-only coloring.
  62. menu->addEntry( "", 0 ); // For unsetting.
  63. SimSet* set = _getDatablockSet();
  64. U32 id = 1;
  65. for( SimSet::iterator iter = set->begin(); iter != set->end(); ++ iter )
  66. {
  67. SimDataBlock* datablock = dynamic_cast< SimDataBlock* >( *iter );
  68. // Skip non-datablocks if we somehow encounter them.
  69. if( !datablock )
  70. continue;
  71. // Ok, now we have to figure inheritance info.
  72. if( datablock && ( !mDesiredClass || datablock->getClassRep()->isClass( mDesiredClass ) ) )
  73. menu->addEntry( datablock->getName(), id ++, datablock->isClientOnly() ? 1 : 0 );
  74. }
  75. menu->sort();
  76. }
  77. //-----------------------------------------------------------------------------
  78. // GuiInspectorTypeSFXDescriptionName
  79. //-----------------------------------------------------------------------------
  80. IMPLEMENT_CONOBJECT(GuiInspectorTypeSFXDescriptionName);
  81. ConsoleDocClass( GuiInspectorTypeSFXDescriptionName,
  82. "@brief Inspector field type for SFXDescriptionName\n\n"
  83. "Editor use only.\n\n"
  84. "@internal"
  85. );
  86. void GuiInspectorTypeSFXDescriptionName::consoleInit()
  87. {
  88. Parent::consoleInit();
  89. ConsoleBaseType::getType( TypeSFXDescriptionName )->setInspectorFieldType( "GuiInspectorTypeSFXDescriptionName" );
  90. }
  91. //-----------------------------------------------------------------------------
  92. // GuiInspectorTypeSFXTrackName
  93. //-----------------------------------------------------------------------------
  94. IMPLEMENT_CONOBJECT(GuiInspectorTypeSFXTrackName);
  95. ConsoleDocClass( GuiInspectorTypeSFXTrackName,
  96. "@brief Inspector field type for SFXTrackName\n\n"
  97. "Editor use only.\n\n"
  98. "@internal"
  99. );
  100. void GuiInspectorTypeSFXTrackName::consoleInit()
  101. {
  102. Parent::consoleInit();
  103. ConsoleBaseType::getType( TypeSFXTrackName )->setInspectorFieldType( "GuiInspectorTypeSFXTrackName" );
  104. }
  105. //-----------------------------------------------------------------------------
  106. // GuiInspectorTypeSFXEnvironmentName
  107. //-----------------------------------------------------------------------------
  108. IMPLEMENT_CONOBJECT(GuiInspectorTypeSFXEnvironmentName);
  109. ConsoleDocClass( GuiInspectorTypeSFXEnvironmentName,
  110. "@brief Inspector field type for SFXEnvironment\n\n"
  111. "Editor use only.\n\n"
  112. "@internal"
  113. );
  114. void GuiInspectorTypeSFXEnvironmentName::consoleInit()
  115. {
  116. Parent::consoleInit();
  117. ConsoleBaseType::getType( TypeSFXEnvironmentName )->setInspectorFieldType( "GuiInspectorTypeSFXEnvironmentName" );
  118. }
  119. //-----------------------------------------------------------------------------
  120. // GuiInspectorTypeSFXAmbienceName
  121. //-----------------------------------------------------------------------------
  122. IMPLEMENT_CONOBJECT(GuiInspectorTypeSFXAmbienceName);
  123. ConsoleDocClass( GuiInspectorTypeSFXAmbienceName,
  124. "@brief Inspector field type for SFXAmbience\n\n"
  125. "Editor use only.\n\n"
  126. "@internal"
  127. );
  128. void GuiInspectorTypeSFXAmbienceName::consoleInit()
  129. {
  130. Parent::consoleInit();
  131. ConsoleBaseType::getType( TypeSFXAmbienceName )->setInspectorFieldType( "GuiInspectorTypeSFXAmbienceName" );
  132. }