123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- //-----------------------------------------------------------------------------
- // Copyright (c) 2012 GarageGames, LLC
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to
- // deal in the Software without restriction, including without limitation the
- // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- // sell copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- // IN THE SOFTWARE.
- //-----------------------------------------------------------------------------
- #include "platform/platform.h"
- #include "gui/editor/inspector/variableGroup.h"
- #include "gui/editor/inspector/variableField.h"
- #include "gui/editor/guiInspector.h"
- #include "gui/buttons/guiIconButtonCtrl.h"
- #include "console/consoleInternal.h"
- extern ExprEvalState gEvalState;
- //-----------------------------------------------------------------------------
- // GuiInspectorVariableGroup
- //-----------------------------------------------------------------------------
- //
- //
- IMPLEMENT_CONOBJECT(GuiInspectorVariableGroup);
- ConsoleDocClass( GuiInspectorVariableGroup,
- "@brief Inspector support for variable groups in a GuiVariableInspector.\n\n"
- "Editor use only.\n\n"
- "@internal"
- );
- GuiInspectorVariableGroup::GuiInspectorVariableGroup()
- {
- }
- GuiInspectorVariableGroup::~GuiInspectorVariableGroup()
- {
- }
- GuiInspectorField* GuiInspectorVariableGroup::constructField( S32 fieldType )
- {
- return Parent::constructField(fieldType);
- }
- bool GuiInspectorVariableGroup::inspectGroup()
- {
- // to prevent crazy resizing, we'll just freeze our stack for a sec..
- mStack->freeze(true);
- bool bNewItems = false;
- if (!mSearchString.equal(""))
- {
- Vector<String> names;
- gEvalState.globalVars.exportVariables(mSearchString, &names, NULL);
- for (U32 i = 0; i < names.size(); i++)
- {
- const String &varName = names[i];
- // If the field already exists, just update it
- GuiInspectorVariableField *field = dynamic_cast<GuiInspectorVariableField*>(findField(varName));
- if (field != NULL)
- {
- field->updateValue();
- continue;
- }
- bNewItems = true;
- field = new GuiInspectorVariableField();
- field->init(mParent, this);
- field->setInspectorField(NULL, StringTable->insert(varName));
- if (field->registerObject())
- {
- mChildren.push_back(field);
- mStack->addObject(field);
- }
- else
- delete field;
- }
- }
- for (U32 i = 0; i < mFields.size(); i++)
- {
- bNewItems = true;
- GuiInspectorField *fieldGui = findField(mFields[i]->mFieldName);
- if (fieldGui != NULL)
- {
- fieldGui->updateValue();
- continue;
- }
- //first and foremost, nab the field type and check if it's a custom field or not.
- //If it's not a custom field, proceed below, if it is, hand it off to script to be handled by the component
- if (mFields[i]->mFieldType == -1)
- {
- if (isMethod("onConstructField"))
- {
- //ensure our stack variable is bound if we need it
- Con::evaluatef("%d.stack = %d;", this->getId(), mStack->getId());
- Con::executef(this, "onConstructField", mFields[i]->mFieldName,
- mFields[i]->mFieldLabel, mFields[i]->mFieldTypeName, mFields[i]->mFieldDescription,
- mFields[i]->mDefaultValue, mFields[i]->mDataValues, mFields[i]->mSetCallbackName, mFields[i]->mOwnerObject);
- }
- continue;
- }
- bNewItems = true;
- fieldGui = constructField(mFields[i]->mFieldType);
- if (fieldGui == NULL)
- fieldGui = new GuiInspectorField();
- fieldGui->init(mParent, this);
- fieldGui->setSpecialEditField(true);
- if (mFields[i]->mOwnerObject)
- {
- fieldGui->setTargetObject(mFields[i]->mOwnerObject);
- }
- else
- {
- //check if we're binding to a global var first, if we have no owner
- if (mFields[i]->mFieldName[0] != '$')
- {
- fieldGui->setTargetObject(mParent);
- }
- }
- fieldGui->setSpecialEditVariableName(mFields[i]->mFieldName);
- fieldGui->setSpecialEditCallbackName(mFields[i]->mSetCallbackName);
- fieldGui->setInspectorField(NULL, mFields[i]->mFieldLabel);
- fieldGui->setDocs(mFields[i]->mFieldDescription);
- if(mFields[i]->mSetCallbackName != StringTable->EmptyString())
- fieldGui->setSpecialEditCallbackName(mFields[i]->mSetCallbackName);
- /*if (mFields[i]->mSetCallbackName != StringTable->EmptyString())
- {
- fieldGui->on.notify()
- }*/
-
- if (fieldGui->registerObject())
- {
- #ifdef DEBUG_SPEW
- Platform::outputDebugString("[GuiInspectorVariableGroup] Adding field '%s'",
- field->pFieldname);
- #endif
- if (mFields[i]->mOwnerObject)
- {
- String val = mFields[i]->mOwnerObject->getDataField(mFields[i]->mFieldName, NULL);
- if(val.isEmpty())
- fieldGui->setValue(mFields[i]->mDefaultValue);
- else
- fieldGui->setValue(val);
- }
- else
- {
- fieldGui->setValue(mFields[i]->mDefaultValue);
- }
- fieldGui->setActive(mFields[i]->mEnabled);
- mChildren.push_back(fieldGui);
- mStack->addObject(fieldGui);
- }
- else
- {
- SAFE_DELETE(fieldGui);
- }
- }
-
- mStack->freeze(false);
- mStack->updatePanes();
- // If we've no new items, there's no need to resize anything!
- if( bNewItems == false && !mChildren.empty() )
- return true;
- sizeToContents();
- setUpdate();
- return true;
- }
- void GuiInspectorVariableGroup::clearFields()
- {
- mFields.clear();
- }
- void GuiInspectorVariableGroup::addField(VariableField* field)
- {
- bool found = false;
- for (U32 i = 0; i < mFields.size(); i++)
- {
- if (mFields[i]->mFieldName == field->mFieldName)
- {
- found = true;
- break;
- }
- }
- if(!found)
- mFields.push_back(field);
- }
- void GuiInspectorVariableGroup::addInspectorField(GuiInspectorField* field)
- {
- mStack->addObject(field);
- mChildren.push_back(field);
- mStack->updatePanes();
- }
- GuiInspectorField* GuiInspectorVariableGroup::createInspectorField()
- {
- GuiInspectorField* newField = new GuiInspectorField();
- newField->init(mParent, this);
- newField->setSpecialEditField(true);
- if (newField->registerObject())
- {
- return newField;
- }
- return NULL;
- }
- DefineEngineMethod(GuiInspectorVariableGroup, createInspectorField, GuiInspectorField*, (),, "createInspectorField()")
- {
- return object->createInspectorField();
- }
- DefineEngineMethod(GuiInspectorVariableGroup, addInspectorField, void, (GuiInspectorField* field), (nullAsType<GuiInspectorField*>()), "addInspectorField( GuiInspectorFieldObject )")
- {
- object->addInspectorField(field);
- }
|