CubemapAsset.cpp
Engine/source/T3D/assets/CubemapAsset.cpp
Public Functions
ConsoleDocClass(GuiInspectorTypeCubemapAssetPtr , "@brief Inspector field type <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Shapes\n\n</a>" "Editor use <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">only.\n\n</a>" "@internal" )
ConsoleSetType(TypeCubemapAssetPtr )
ConsoleType(CubemapAssetPtr , TypeCubemapAssetPtr , CubemapAsset , ASSET_ID_FIELD_PREFIX )
Detailed Description
Public Functions
ConsoleDocClass(GuiInspectorTypeCubemapAssetPtr , "@brief Inspector field type <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Shapes\n\n</a>" "Editor use <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">only.\n\n</a>" "@internal" )
ConsoleSetType(TypeCubemapAssetPtr )
ConsoleType(CubemapAssetPtr , TypeCubemapAssetPtr , CubemapAsset , ASSET_ID_FIELD_PREFIX )
IMPLEMENT_CONOBJECT(CubemapAsset )
IMPLEMENT_CONOBJECT(GuiInspectorTypeCubemapAssetPtr )
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 CUBEMAP_ASSET_H 25#include "CubemapAsset.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(CubemapAsset); 50 51ConsoleType(CubemapAssetPtr, TypeCubemapAssetPtr, CubemapAsset, ASSET_ID_FIELD_PREFIX) 52 53//----------------------------------------------------------------------------- 54 55ConsoleGetType(TypeCubemapAssetPtr) 56{ 57 // Fetch asset Id. 58 return (*((AssetPtr<CubemapAsset>*)dptr)).getAssetId(); 59} 60 61//----------------------------------------------------------------------------- 62 63ConsoleSetType(TypeCubemapAssetPtr) 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<CubemapAsset>* pAssetPtr = dynamic_cast<AssetPtr<CubemapAsset>*>((AssetPtrBase*)(dptr)); 73 74 // Is the asset pointer the correct type? 75 if (pAssetPtr == NULL) 76 { 77 // No, so fail. 78 //Con::warnf("(TypeCubemapAssetPtr) - 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("(TypeCubemapAssetPtr) - Cannot set multiple args to a single asset."); 90} 91 92//----------------------------------------------------------------------------- 93 94CubemapAsset::CubemapAsset() 95{ 96 mComponentName = StringTable->EmptyString(); 97 mComponentClass = StringTable->EmptyString(); 98 mFriendlyName = StringTable->EmptyString(); 99 mComponentType = StringTable->EmptyString(); 100 mDescription = StringTable->EmptyString(); 101 102 mScriptFile = StringTable->EmptyString(); 103} 104 105//----------------------------------------------------------------------------- 106 107CubemapAsset::~CubemapAsset() 108{ 109} 110 111//----------------------------------------------------------------------------- 112 113void CubemapAsset::initPersistFields() 114{ 115 // Call parent. 116 Parent::initPersistFields(); 117 118 addField("componentName", TypeString, Offset(mComponentName, CubemapAsset), "Unique Name of the component. Defines the namespace of the scripts for the component."); 119 addField("componentClass", TypeString, Offset(mComponentClass, CubemapAsset), "Class of object this component uses."); 120 addField("friendlyName", TypeString, Offset(mFriendlyName, CubemapAsset), "The human-readble name for the component."); 121 addField("componentType", TypeString, Offset(mComponentType, CubemapAsset), "The category of the component for organizing in the editor."); 122 addField("description", TypeString, Offset(mDescription, CubemapAsset), "Simple description of the component."); 123 124 addProtectedField("scriptFile", TypeAssetLooseFilePath, Offset(mScriptFile, CubemapAsset), 125 &setScriptFile, &getScriptFile, "A script file with additional scripted functionality for this component."); 126} 127 128//------------------------------------------------------------------------------ 129 130void CubemapAsset::copyTo(SimObject* object) 131{ 132 // Call to parent. 133 Parent::copyTo(object); 134} 135 136void CubemapAsset::initializeAsset() 137{ 138 mScriptFile = expandAssetFilePath(mScriptFile); 139 140 if(Platform::isFile(mScriptFile)) 141 Con::executeFile(mScriptFile, false, false); 142} 143 144void CubemapAsset::onAssetRefresh() 145{ 146 mScriptFile = expandAssetFilePath(mScriptFile); 147 148 if (Platform::isFile(mScriptFile)) 149 Con::executeFile(mScriptFile, false, false); 150} 151 152void CubemapAsset::setScriptFile(const char* pScriptFile) 153{ 154 // Sanity! 155 AssertFatal(pScriptFile != NULL, "Cannot use a NULL script file."); 156 157 // Fetch image file. 158 pScriptFile = StringTable->insert(pScriptFile); 159 160 // Ignore no change, 161 if (pScriptFile == mScriptFile) 162 return; 163 164 // Update. 165 mScriptFile = getOwned() ? expandAssetFilePath(pScriptFile) : StringTable->insert(pScriptFile); 166 167 // Refresh the asset. 168 refreshAsset(); 169} 170 171//----------------------------------------------------------------------------- 172// GuiInspectorTypeAssetId 173//----------------------------------------------------------------------------- 174 175IMPLEMENT_CONOBJECT(GuiInspectorTypeCubemapAssetPtr); 176 177ConsoleDocClass(GuiInspectorTypeCubemapAssetPtr, 178 "@brief Inspector field type for Shapes\n\n" 179 "Editor use only.\n\n" 180 "@internal" 181); 182 183void GuiInspectorTypeCubemapAssetPtr::consoleInit() 184{ 185 Parent::consoleInit(); 186 187 ConsoleBaseType::getType(TypeCubemapAssetPtr)->setInspectorFieldType("GuiInspectorTypeCubemapAssetPtr"); 188} 189 190GuiControl* GuiInspectorTypeCubemapAssetPtr::constructEditControl() 191{ 192 // Create base filename edit controls 193 GuiControl* retCtrl = Parent::constructEditControl(); 194 if (retCtrl == NULL) 195 return retCtrl; 196 197 // Change filespec 198 char szBuffer[512]; 199 dSprintf(szBuffer, sizeof(szBuffer), "AssetBrowser.showDialog(\"CubemapAsset\", \"AssetBrowser.changeAsset\", %d, %s);", 200 mInspector->getInspectObject(), mCaption); 201 mBrowseButton->setField("Command", szBuffer); 202 203 setDataField(StringTable->insert("object"), NULL, String::ToString(mInspector->getInspectObject()).c_str()); 204 205 // Create "Open in ShapeEditor" button 206 mShapeEdButton = new GuiBitmapButtonCtrl(); 207 208 dSprintf(szBuffer, sizeof(szBuffer), "CubemapEditor.openCubemapAsset(%d.getText());", retCtrl->getId()); 209 mShapeEdButton->setField("Command", szBuffer); 210 211 char bitmapName[512] = "tools/worldEditor/images/toolbar/shape-editor"; 212 mShapeEdButton->setBitmap(bitmapName); 213 214 mShapeEdButton->setDataField(StringTable->insert("Profile"), NULL, "GuiButtonProfile"); 215 mShapeEdButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile"); 216 mShapeEdButton->setDataField(StringTable->insert("hovertime"), NULL, "1000"); 217 mShapeEdButton->setDataField(StringTable->insert("tooltip"), NULL, "Open this file in the Shape Editor"); 218 219 mShapeEdButton->registerObject(); 220 addObject(mShapeEdButton); 221 222 return retCtrl; 223} 224 225bool GuiInspectorTypeCubemapAssetPtr::updateRects() 226{ 227 S32 dividerPos, dividerMargin; 228 mInspector->getDivider(dividerPos, dividerMargin); 229 Point2I fieldExtent = getExtent(); 230 Point2I fieldPos = getPosition(); 231 232 mCaptionRect.set(0, 0, fieldExtent.x - dividerPos - dividerMargin, fieldExtent.y); 233 mEditCtrlRect.set(fieldExtent.x - dividerPos + dividerMargin, 1, dividerPos - dividerMargin - 34, fieldExtent.y); 234 235 bool resized = mEdit->resize(mEditCtrlRect.point, mEditCtrlRect.extent); 236 if (mBrowseButton != NULL) 237 { 238 mBrowseRect.set(fieldExtent.x - 32, 2, 14, fieldExtent.y - 4); 239 resized |= mBrowseButton->resize(mBrowseRect.point, mBrowseRect.extent); 240 } 241 242 if (mShapeEdButton != NULL) 243 { 244 RectI shapeEdRect(fieldExtent.x - 16, 2, 14, fieldExtent.y - 4); 245 resized |= mShapeEdButton->resize(shapeEdRect.point, shapeEdRect.extent); 246 } 247 248 return resized; 249} 250