variableGroup.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 "platform/platform.h"
  23. #include "gui/editor/inspector/variableGroup.h"
  24. #include "gui/editor/inspector/variableField.h"
  25. #include "gui/editor/guiInspector.h"
  26. #include "gui/buttons/guiIconButtonCtrl.h"
  27. #include "console/consoleInternal.h"
  28. extern ExprEvalState gEvalState;
  29. //-----------------------------------------------------------------------------
  30. // GuiInspectorVariableGroup
  31. //-----------------------------------------------------------------------------
  32. //
  33. //
  34. IMPLEMENT_CONOBJECT(GuiInspectorVariableGroup);
  35. ConsoleDocClass( GuiInspectorVariableGroup,
  36. "@brief Inspector support for variable groups in a GuiVariableInspector.\n\n"
  37. "Editor use only.\n\n"
  38. "@internal"
  39. );
  40. GuiInspectorVariableGroup::GuiInspectorVariableGroup()
  41. {
  42. }
  43. GuiInspectorVariableGroup::~GuiInspectorVariableGroup()
  44. {
  45. }
  46. GuiInspectorField* GuiInspectorVariableGroup::constructField( S32 fieldType )
  47. {
  48. return NULL;
  49. }
  50. bool GuiInspectorVariableGroup::inspectGroup()
  51. {
  52. // to prevent crazy resizing, we'll just freeze our stack for a sec..
  53. mStack->freeze(true);
  54. clearFields();
  55. Vector<String> names;
  56. gEvalState.globalVars.exportVariables( mSearchString, &names, NULL );
  57. bool bNewItems = false;
  58. for ( U32 i = 0; i < names.size(); i++ )
  59. {
  60. const String &varName = names[i];
  61. // If the field already exists, just update it
  62. GuiInspectorVariableField *field = dynamic_cast<GuiInspectorVariableField*>( findField( varName ) );
  63. if ( field != NULL )
  64. {
  65. field->updateValue();
  66. continue;
  67. }
  68. bNewItems = true;
  69. field = new GuiInspectorVariableField();
  70. field->init( mParent, this );
  71. field->setInspectorField( NULL, StringTable->insert( varName ) );
  72. if ( field->registerObject() )
  73. {
  74. mChildren.push_back( field );
  75. mStack->addObject( field );
  76. }
  77. else
  78. delete field;
  79. }
  80. mStack->freeze(false);
  81. mStack->updatePanes();
  82. // If we've no new items, there's no need to resize anything!
  83. if( bNewItems == false && !mChildren.empty() )
  84. return true;
  85. sizeToContents();
  86. setUpdate();
  87. return true;
  88. }