GUIAsset.cpp

Engine/source/T3D/assets/GUIAsset.cpp

More...

Public Functions

ConsoleDocClass(GuiInspectorTypeGUIAssetPtr , "@brief Inspector field type <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> GUI Asset <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Objects\n\n</a>" "Editor use <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">only.\n\n</a>" "@internal" )
ConsoleSetType(TypeGUIAssetPtr )
ConsoleType(GUIAssetPtr , TypeGUIAssetPtr , String , ASSET_ID_FIELD_PREFIX )

Detailed Description

Public Functions

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

ConsoleSetType(TypeGUIAssetPtr )

ConsoleType(GUIAssetPtr , TypeGUIAssetPtr , String , ASSET_ID_FIELD_PREFIX )

IMPLEMENT_CONOBJECT(GUIAsset )

IMPLEMENT_CONOBJECT(GuiInspectorTypeGUIAssetPtr )

  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 GUI_ASSET_H
 25#include "GUIAsset.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(GUIAsset);
 50
 51ConsoleType(GUIAssetPtr, TypeGUIAssetPtr, String, ASSET_ID_FIELD_PREFIX)
 52
 53//-----------------------------------------------------------------------------
 54
 55ConsoleGetType(TypeGUIAssetPtr)
 56{
 57   // Fetch asset Id.
 58   return *((StringTableEntry*)dptr);
 59}
 60
 61//-----------------------------------------------------------------------------
 62
 63ConsoleSetType(TypeGUIAssetPtr)
 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 Id.
 72      StringTableEntry* assetId = (StringTableEntry*)(dptr);
 73
 74      // Update asset value.
 75      *assetId = StringTable->insert(pFieldValue);
 76
 77      return;
 78   }
 79
 80   // Warn.
 81   Con::warnf("(TypeGUIAssetPtr) - Cannot set multiple args to a single asset.");
 82}
 83
 84//-----------------------------------------------------------------------------
 85
 86GUIAsset::GUIAsset()
 87{
 88   mScriptFile = StringTable->EmptyString();
 89   mGUIFile = StringTable->EmptyString();
 90
 91   mScriptPath = StringTable->EmptyString();
 92   mGUIPath = StringTable->EmptyString();
 93}
 94
 95//-----------------------------------------------------------------------------
 96
 97GUIAsset::~GUIAsset()
 98{
 99}
100
101//-----------------------------------------------------------------------------
102
103void GUIAsset::initPersistFields()
104{
105   // Call parent.
106   Parent::initPersistFields();
107
108   addProtectedField("scriptFile", TypeAssetLooseFilePath, Offset(mScriptFile, GUIAsset),
109      &setScriptFile, &getScriptFile, "Path to the script file for the gui");
110
111   addProtectedField("GUIFile", TypeAssetLooseFilePath, Offset(mGUIFile, GUIAsset),
112      &setScriptFile, &getScriptFile, "Path to the gui file");
113}
114
115//------------------------------------------------------------------------------
116
117void GUIAsset::copyTo(SimObject* object)
118{
119   // Call to parent.
120   Parent::copyTo(object);
121}
122
123void GUIAsset::initializeAsset()
124{
125   mGUIPath = expandAssetFilePath(mGUIFile);
126
127   if (Platform::isFile(mGUIPath))
128      Con::executeFile(mGUIPath, false, false);
129
130   mScriptPath = expandAssetFilePath(mScriptFile);
131
132   if (Platform::isFile(mScriptPath))
133      Con::executeFile(mScriptPath, false, false);
134}
135
136void GUIAsset::onAssetRefresh()
137{
138   mGUIPath = expandAssetFilePath(mGUIFile);
139
140   if (Platform::isFile(mGUIPath))
141      Con::executeFile(mGUIPath, false, false);
142
143   mScriptPath = expandAssetFilePath(mScriptFile);
144
145   if (Platform::isFile(mScriptPath))
146      Con::executeFile(mScriptPath, false, false);
147}
148
149void GUIAsset::setGUIFile(const char* pScriptFile)
150{
151   // Sanity!
152   AssertFatal(pScriptFile != NULL, "Cannot use a NULL gui file.");
153
154   // Fetch image file.
155   pScriptFile = StringTable->insert(pScriptFile);
156
157   // Ignore no change,
158   if (pScriptFile == mGUIFile)
159      return;
160
161   // Update.
162   mGUIFile = StringTable->insert(pScriptFile);
163
164   // Refresh the asset.
165   refreshAsset();
166}
167
168void GUIAsset::setScriptFile(const char* pScriptFile)
169{
170   // Sanity!
171   AssertFatal(pScriptFile != NULL, "Cannot use a NULL script file.");
172
173   // Fetch image file.
174   pScriptFile = StringTable->insert(pScriptFile);
175
176   // Ignore no change,
177   if (pScriptFile == mScriptFile)
178      return;
179
180   // Update.
181   mScriptFile = StringTable->insert(pScriptFile);
182
183   // Refresh the asset.
184   refreshAsset();
185}
186
187//-----------------------------------------------------------------------------
188// GuiInspectorTypeAssetId
189//-----------------------------------------------------------------------------
190
191IMPLEMENT_CONOBJECT(GuiInspectorTypeGUIAssetPtr);
192
193ConsoleDocClass(GuiInspectorTypeGUIAssetPtr,
194   "@brief Inspector field type for GUI Asset Objects\n\n"
195   "Editor use only.\n\n"
196   "@internal"
197);
198
199void GuiInspectorTypeGUIAssetPtr::consoleInit()
200{
201   Parent::consoleInit();
202
203   ConsoleBaseType::getType(TypeGUIAssetPtr)->setInspectorFieldType("GuiInspectorTypeGUIAssetPtr");
204}
205
206GuiControl* GuiInspectorTypeGUIAssetPtr::constructEditControl()
207{
208   // Create base filename edit controls
209   GuiControl *retCtrl = Parent::constructEditControl();
210   if (retCtrl == NULL)
211      return retCtrl;
212
213   // Change filespec
214   char szBuffer[512];
215   dSprintf(szBuffer, sizeof(szBuffer), "AssetBrowser.showDialog(\"GUIAsset\", \"AssetBrowser.changeAsset\", %d, %s);",
216      mInspector->getComponentGroupTargetId(), mCaption);
217   mBrowseButton->setField("Command", szBuffer);
218
219   // Create "Open in ShapeEditor" button
220   mSMEdButton = new GuiBitmapButtonCtrl();
221
222   dSprintf(szBuffer, sizeof(szBuffer), "echo(\"Game Object Editor not implemented yet!\");", retCtrl->getId());
223   mSMEdButton->setField("Command", szBuffer);
224
225   char bitmapName[512] = "tools/worldEditor/images/toolbar/shape-editor";
226   mSMEdButton->setBitmap(bitmapName);
227
228   mSMEdButton->setDataField(StringTable->insert("Profile"), NULL, "GuiButtonProfile");
229   mSMEdButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile");
230   mSMEdButton->setDataField(StringTable->insert("hovertime"), NULL, "1000");
231   mSMEdButton->setDataField(StringTable->insert("tooltip"), NULL, "Open this file in the State Machine Editor");
232
233   mSMEdButton->registerObject();
234   addObject(mSMEdButton);
235
236   return retCtrl;
237}
238
239bool GuiInspectorTypeGUIAssetPtr::updateRects()
240{
241   S32 dividerPos, dividerMargin;
242   mInspector->getDivider(dividerPos, dividerMargin);
243   Point2I fieldExtent = getExtent();
244   Point2I fieldPos = getPosition();
245
246   mCaptionRect.set(0, 0, fieldExtent.x - dividerPos - dividerMargin, fieldExtent.y);
247   mEditCtrlRect.set(fieldExtent.x - dividerPos + dividerMargin, 1, dividerPos - dividerMargin - 34, fieldExtent.y);
248
249   bool resized = mEdit->resize(mEditCtrlRect.point, mEditCtrlRect.extent);
250   if (mBrowseButton != NULL)
251   {
252      mBrowseRect.set(fieldExtent.x - 32, 2, 14, fieldExtent.y - 4);
253      resized |= mBrowseButton->resize(mBrowseRect.point, mBrowseRect.extent);
254   }
255
256   if (mSMEdButton != NULL)
257   {
258      RectI shapeEdRect(fieldExtent.x - 16, 2, 14, fieldExtent.y - 4);
259      resized |= mSMEdButton->resize(shapeEdRect.point, shapeEdRect.extent);
260   }
261
262   return resized;
263}
264