Torque3D Documentation / _generateds / stateMachineAsset.cpp

stateMachineAsset.cpp

Engine/source/T3D/assets/stateMachineAsset.cpp

More...

Public Functions

ConsoleDocClass(GuiInspectorTypeStateMachineAssetPtr , "@brief Inspector field type <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> State <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Machines\n\n</a>" "Editor use <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">only.\n\n</a>" "@internal" )
ConsoleSetType(TypeStateMachineAssetPtr )
ConsoleType(StateMachineAssetPtr , TypeStateMachineAssetPtr , StateMachineAsset , ASSET_ID_FIELD_PREFIX )
DefineEngineMethod(StateMachineAsset , notifyAssetChanged , void , () , "" )

Detailed Description

Public Functions

ConsoleDocClass(GuiInspectorTypeStateMachineAssetPtr , "@brief Inspector field type <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> State <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Machines\n\n</a>" "Editor use <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">only.\n\n</a>" "@internal" )

ConsoleSetType(TypeStateMachineAssetPtr )

ConsoleType(StateMachineAssetPtr , TypeStateMachineAssetPtr , StateMachineAsset , ASSET_ID_FIELD_PREFIX )

DefineEngineMethod(StateMachineAsset , notifyAssetChanged , void , () , "" )

IMPLEMENT_CONOBJECT(GuiInspectorTypeStateMachineAssetPtr )

IMPLEMENT_CONOBJECT(StateMachineAsset )

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2013 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef STATE_MACHINE_ASSET_H
 25#include "stateMachineAsset.h"
 26#endif
 27
 28#ifndef _ASSET_MANAGER_H_
 29#include "assets/assetManager.h"
 30#endif
 31
 32#ifndef _CONSOLETYPES_H_
 33#include "console/consoleTypes.h"
 34#endif
 35
 36#ifndef _TAML_
 37#include "persistence/taml/taml.h"
 38#endif
 39
 40#ifndef _ASSET_PTR_H_
 41#include "assets/assetPtr.h"
 42#endif
 43
 44// Debug Profiling.
 45#include "platform/profiler.h"
 46
 47//-----------------------------------------------------------------------------
 48
 49IMPLEMENT_CONOBJECT(StateMachineAsset);
 50
 51ConsoleType(StateMachineAssetPtr, TypeStateMachineAssetPtr, StateMachineAsset, ASSET_ID_FIELD_PREFIX)
 52
 53//-----------------------------------------------------------------------------
 54
 55ConsoleGetType(TypeStateMachineAssetPtr)
 56{
 57   // Fetch asset Id.
 58   return (*((AssetPtr<StateMachineAsset>*)dptr)).getAssetId();
 59}
 60
 61//-----------------------------------------------------------------------------
 62
 63ConsoleSetType(TypeStateMachineAssetPtr)
 64{
 65   // Was a single argument specified?
 66   if (argc == 1)
 67   {
 68      // Yes, so fetch field value.
 69      const char* pFieldValue = argv[0];
 70
 71      // Fetch asset pointer.
 72      AssetPtr<StateMachineAsset>* pAssetPtr = dynamic_cast<AssetPtr<StateMachineAsset>*>((AssetPtrBase*)(dptr));
 73
 74      // Is the asset pointer the correct type?
 75      if (pAssetPtr == NULL)
 76      {
 77         // No, so fail.
 78         //Con::warnf("(TypeStateMachineAssetPtr) - Failed to set asset Id '%d'.", pFieldValue);
 79         return;
 80      }
 81
 82      // Set asset.
 83      pAssetPtr->setAssetId(pFieldValue);
 84
 85      return;
 86   }
 87
 88   // Warn.
 89   Con::warnf("(TypeStateMachineAssetPtr) - Cannot set multiple args to a single asset.");
 90}
 91
 92//-----------------------------------------------------------------------------
 93
 94StateMachineAsset::StateMachineAsset()
 95{
 96   mStateMachineFile = StringTable->EmptyString();
 97   mStateMachinePath = StringTable->EmptyString();
 98}
 99
100//-----------------------------------------------------------------------------
101
102StateMachineAsset::~StateMachineAsset()
103{
104}
105
106//-----------------------------------------------------------------------------
107
108void StateMachineAsset::initPersistFields()
109{
110   // Call parent.
111   Parent::initPersistFields();
112
113   addProtectedField("stateMachineFile", TypeAssetLooseFilePath, Offset(mStateMachineFile, StateMachineAsset),
114      &setStateMachineFile, &getStateMachineFile, "Path to the state machine file.");
115}
116
117//------------------------------------------------------------------------------
118
119void StateMachineAsset::copyTo(SimObject* object)
120{
121   // Call to parent.
122   Parent::copyTo(object);
123}
124
125void StateMachineAsset::setStateMachineFile(const char* pStateMachineFile)
126{
127   // Sanity!
128   AssertFatal(pStateMachineFile != NULL, "Cannot use a NULL state machine file.");
129
130   // Fetch image file.
131   pStateMachineFile = StringTable->insert(pStateMachineFile);
132
133   // Ignore no change,
134   if (pStateMachineFile == mStateMachineFile)
135      return;
136
137   // Update.
138   mStateMachineFile = StringTable->insert(pStateMachineFile);
139
140   // Refresh the asset.
141   refreshAsset();
142}
143
144void StateMachineAsset::initializeAsset()
145{
146   mStateMachinePath = expandAssetFilePath(mStateMachineFile);
147}
148
149void StateMachineAsset::onAssetRefresh()
150{
151   mStateMachinePath = expandAssetFilePath(mStateMachineFile);
152}
153
154
155
156DefineEngineMethod(StateMachineAsset, notifyAssetChanged, void, (),,"")
157{
158   ResourceManager::get().getChangedSignal().trigger(object->getStateMachineFile());
159}
160
161//-----------------------------------------------------------------------------
162// GuiInspectorTypeAssetId
163//-----------------------------------------------------------------------------
164
165IMPLEMENT_CONOBJECT(GuiInspectorTypeStateMachineAssetPtr);
166
167ConsoleDocClass(GuiInspectorTypeStateMachineAssetPtr,
168   "@brief Inspector field type for State Machines\n\n"
169   "Editor use only.\n\n"
170   "@internal"
171);
172
173void GuiInspectorTypeStateMachineAssetPtr::consoleInit()
174{
175   Parent::consoleInit();
176
177   ConsoleBaseType::getType(TypeStateMachineAssetPtr)->setInspectorFieldType("GuiInspectorTypeStateMachineAssetPtr");
178}
179
180GuiControl* GuiInspectorTypeStateMachineAssetPtr::constructEditControl()
181{
182   // Create base filename edit controls
183   GuiControl *retCtrl = Parent::constructEditControl();
184   if (retCtrl == NULL)
185      return retCtrl;
186
187   // Change filespec
188   char szBuffer[512];
189   dSprintf(szBuffer, sizeof(szBuffer), "AssetBrowser.showDialog(\"StateMachineAsset\", \"AssetBrowser.changeAsset\", %d, %s);",
190      mInspector->getComponentGroupTargetId(), mCaption);
191   mBrowseButton->setField("Command", szBuffer);
192
193   // Create "Open in ShapeEditor" button
194   mSMEdButton = new GuiBitmapButtonCtrl();
195
196   dSprintf(szBuffer, sizeof(szBuffer), "StateMachineEditor.loadStateMachineAsset(%d.getText()); Canvas.pushDialog(StateMachineEditor);", retCtrl->getId());
197   mSMEdButton->setField("Command", szBuffer);
198
199   char bitmapName[512] = "tools/worldEditor/images/toolbar/shape-editor";
200   mSMEdButton->setBitmap(bitmapName);
201
202   mSMEdButton->setDataField(StringTable->insert("Profile"), NULL, "GuiButtonProfile");
203   mSMEdButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile");
204   mSMEdButton->setDataField(StringTable->insert("hovertime"), NULL, "1000");
205   mSMEdButton->setDataField(StringTable->insert("tooltip"), NULL, "Open this file in the State Machine Editor");
206
207   mSMEdButton->registerObject();
208   addObject(mSMEdButton);
209
210   return retCtrl;
211}
212
213bool GuiInspectorTypeStateMachineAssetPtr::updateRects()
214{
215   S32 dividerPos, dividerMargin;
216   mInspector->getDivider(dividerPos, dividerMargin);
217   Point2I fieldExtent = getExtent();
218   Point2I fieldPos = getPosition();
219
220   mCaptionRect.set(0, 0, fieldExtent.x - dividerPos - dividerMargin, fieldExtent.y);
221   mEditCtrlRect.set(fieldExtent.x - dividerPos + dividerMargin, 1, dividerPos - dividerMargin - 34, fieldExtent.y);
222
223   bool resized = mEdit->resize(mEditCtrlRect.point, mEditCtrlRect.extent);
224   if (mBrowseButton != NULL)
225   {
226      mBrowseRect.set(fieldExtent.x - 32, 2, 14, fieldExtent.y - 4);
227      resized |= mBrowseButton->resize(mBrowseRect.point, mBrowseRect.extent);
228   }
229
230   if (mSMEdButton != NULL)
231   {
232      RectI shapeEdRect(fieldExtent.x - 16, 2, 14, fieldExtent.y - 4);
233      resized |= mSMEdButton->resize(shapeEdRect.point, shapeEdRect.extent);
234   }
235
236   return resized;
237}
238