Adds some in-progress gameObject recreation of various legacy game classes, such as PlayerObject, AIPlayerObject, Sound Emitter and Static Shape.

This commit is contained in:
Areloch 2019-03-04 21:44:00 -06:00
parent 775ca57047
commit 23182eb2a1
23 changed files with 792 additions and 35 deletions

View file

@ -139,6 +139,44 @@ void GameObjectAsset::onAssetRefresh()
Con::executeFile(mScriptFilePath, false, false);
}
const char* GameObjectAsset::create()
{
if (!Platform::isFile(mTAMLFilePath))
return "";
// Set the format mode.
Taml taml;
// Yes, so set it.
taml.setFormatMode(Taml::getFormatModeEnum("xml"));
// Turn-off auto-formatting.
taml.setAutoFormat(false);
// Read object.
SimObject* pSimObject = taml.read(mTAMLFilePath);
// Did we find the object?
if (pSimObject == NULL)
{
// No, so warn.
Con::warnf("GameObjectAsset::create() - Could not read object from file '%s'.", mTAMLFilePath);
return "";
}
//Flag it so we know where it came from
pSimObject->setDataField("GameObject", nullptr, getAssetId());
return pSimObject->getIdString();
}
DefineEngineMethod(GameObjectAsset, createObject, const char*, (),,
"Creates an instance of the given GameObject given the asset definition.\n"
"@return The GameObject entity created from the asset.")
{
return object->create();
}
//-----------------------------------------------------------------------------
// GuiInspectorTypeAssetId
//-----------------------------------------------------------------------------
@ -161,34 +199,50 @@ void GuiInspectorTypeGameObjectAssetPtr::consoleInit()
GuiControl* GuiInspectorTypeGameObjectAssetPtr::constructEditControl()
{
// Create base filename edit controls
GuiControl *retCtrl = Parent::constructEditControl();
if (retCtrl == NULL)
return retCtrl;
// Create "Open in ShapeEditor" button
mGameObjectEditButton = new GuiButtonCtrl();
// Change filespec
char szBuffer[512];
dSprintf(szBuffer, sizeof(szBuffer), "AssetBrowser.showDialog(\"GameObjectAsset\", \"AssetBrowser.changeAsset\", %d, %s);",
mInspector->getComponentGroupTargetId(), mCaption);
mBrowseButton->setField("Command", szBuffer);
dSprintf(szBuffer, sizeof(szBuffer), "%d.onClick(%s);", this->getId(), mCaption);
mGameObjectEditButton->setField("Command", szBuffer);
// Create "Open in ShapeEditor" button
mSMEdButton = new GuiBitmapButtonCtrl();
mGameObjectEditButton->setDataField(StringTable->insert("Profile"), NULL, "GuiButtonProfile");
mGameObjectEditButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile");
mGameObjectEditButton->setDataField(StringTable->insert("hovertime"), NULL, "1000");
dSprintf(szBuffer, sizeof(szBuffer), "echo(\"Game Object Editor not implemented yet!\");", retCtrl->getId());
mSMEdButton->setField("Command", szBuffer);
const char* assetId = getData();
char bitmapName[512] = "tools/worldEditor/images/toolbar/shape-editor";
mSMEdButton->setBitmap(bitmapName);
if (assetId == "")
{
mGameObjectEditButton->setText("Create Game Object");
mSMEdButton->setDataField(StringTable->insert("Profile"), NULL, "GuiButtonProfile");
mSMEdButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile");
mSMEdButton->setDataField(StringTable->insert("hovertime"), NULL, "1000");
mSMEdButton->setDataField(StringTable->insert("tooltip"), NULL, "Open this file in the State Machine Editor");
mGameObjectEditButton->setDataField(StringTable->insert("tooltip"), NULL, "Convert this object into a reusable Game Object asset.");
}
else
{
GameObjectAsset* goAsset = AssetDatabase.acquireAsset< GameObjectAsset>(assetId);
mSMEdButton->registerObject();
addObject(mSMEdButton);
if (goAsset)
{
mGameObjectEditButton->setText("Edit Game Object");
return retCtrl;
mGameObjectEditButton->setDataField(StringTable->insert("tooltip"), NULL, "Edit this object instance or Game Object asset.");
}
else
{
mGameObjectEditButton->setText("Create Game Object");
mGameObjectEditButton->setDataField(StringTable->insert("tooltip"), NULL, "Convert this object into a reusable Game Object asset.");
}
}
//mGameObjectEditButton->registerObject();
_registerEditControl(mGameObjectEditButton);
addObject(mGameObjectEditButton);
return mGameObjectEditButton;
}
bool GuiInspectorTypeGameObjectAssetPtr::updateRects()
@ -199,19 +253,12 @@ bool GuiInspectorTypeGameObjectAssetPtr::updateRects()
Point2I fieldPos = getPosition();
mCaptionRect.set(0, 0, fieldExtent.x - dividerPos - dividerMargin, fieldExtent.y);
mEditCtrlRect.set(fieldExtent.x - dividerPos + dividerMargin, 1, dividerPos - dividerMargin - 34, fieldExtent.y);
mEditCtrlRect.set(fieldExtent.x - dividerPos + dividerMargin, 1, dividerPos - dividerMargin, fieldExtent.y);
bool resized = mEdit->resize(mEditCtrlRect.point, mEditCtrlRect.extent);
if (mBrowseButton != NULL)
if (mGameObjectEditButton != NULL)
{
mBrowseRect.set(fieldExtent.x - 32, 2, 14, fieldExtent.y - 4);
resized |= mBrowseButton->resize(mBrowseRect.point, mBrowseRect.extent);
}
if (mSMEdButton != NULL)
{
RectI shapeEdRect(fieldExtent.x - 16, 2, 14, fieldExtent.y - 4);
resized |= mSMEdButton->resize(shapeEdRect.point, shapeEdRect.extent);
resized |= mGameObjectEditButton->resize(mEditCtrlRect.point, mEditCtrlRect.extent);
}
return resized;