Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 76 additions & 29 deletions Engine/source/T3D/assets/GameObjectAsset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
//-----------------------------------------------------------------------------
Expand All @@ -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");

const char* assetId = getData();

if (assetId == "")
{
mGameObjectEditButton->setText("Create Game Object");

mGameObjectEditButton->setDataField(StringTable->insert("tooltip"), NULL, "Convert this object into a reusable Game Object asset.");
}
else
{
GameObjectAsset* goAsset = AssetDatabase.acquireAsset< GameObjectAsset>(assetId);

if (goAsset)
{
mGameObjectEditButton->setText("Edit Game Object");

dSprintf(szBuffer, sizeof(szBuffer), "echo(\"Game Object Editor not implemented yet!\");", retCtrl->getId());
mSMEdButton->setField("Command", szBuffer);
mGameObjectEditButton->setDataField(StringTable->insert("tooltip"), NULL, "Edit this object instance or Game Object asset.");
}
else
{
mGameObjectEditButton->setText("Create Game Object");

char bitmapName[512] = "tools/worldEditor/images/toolbar/shape-editor";
mSMEdButton->setBitmap(bitmapName);
mGameObjectEditButton->setDataField(StringTable->insert("tooltip"), NULL, "Convert this object into a reusable Game Object asset.");
}
}

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->registerObject();
_registerEditControl(mGameObjectEditButton);

mSMEdButton->registerObject();
addObject(mSMEdButton);
addObject(mGameObjectEditButton);

return retCtrl;
return mGameObjectEditButton;
}

bool GuiInspectorTypeGameObjectAssetPtr::updateRects()
Expand All @@ -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)
{
mBrowseRect.set(fieldExtent.x - 32, 2, 14, fieldExtent.y - 4);
resized |= mBrowseButton->resize(mBrowseRect.point, mBrowseRect.extent);
}

if (mSMEdButton != NULL)
if (mGameObjectEditButton != 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;
Expand Down
8 changes: 5 additions & 3 deletions Engine/source/T3D/assets/GameObjectAsset.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class GameObjectAsset : public AssetBase
static void initPersistFields();
virtual void copyTo(SimObject* object);

const char* create();

/// Declare Console Object.
DECLARE_CONOBJECT(GameObjectAsset);

Expand All @@ -73,12 +75,12 @@ DefineConsoleType(TypeGameObjectAssetPtr, GameObjectAsset)
//-----------------------------------------------------------------------------
// TypeAssetId GuiInspectorField Class
//-----------------------------------------------------------------------------
class GuiInspectorTypeGameObjectAssetPtr : public GuiInspectorTypeFileName
class GuiInspectorTypeGameObjectAssetPtr : public GuiInspectorField
{
typedef GuiInspectorTypeFileName Parent;
typedef GuiInspectorField Parent;
public:

GuiBitmapButtonCtrl *mSMEdButton;
GuiButtonCtrl *mGameObjectEditButton;

DECLARE_CONOBJECT(GuiInspectorTypeGameObjectAssetPtr);
static void consoleInit();
Expand Down
42 changes: 42 additions & 0 deletions Engine/source/T3D/gameObjects/aiPlayerObject.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "aiPlayerObject.h"

IMPLEMENT_CO_NETOBJECT_V1(AIPlayerObject);

AIPlayerObject::AIPlayerObject()
: mAIControllerComponent(nullptr)
{

}
AIPlayerObject::~AIPlayerObject()
{

}

bool AIPlayerObject::onAdd()
{
if (!Parent::onAdd())
return false;

//If we don't delinate from the template, just spawn as apropos here
if (!mDirtyGameObject)
{
//AI Controller
mAIControllerComponent = new AIControllerComponent();
if (!mAIControllerComponent->registerObject())
{
Con::errorf("PlayerObject::onAdd - unable to add mAIControllerComponent!");
return false;
}

mAIControllerComponent->setInternalName("aiControllerComponent");

addComponent(mAIControllerComponent);
}

return true;
}

void AIPlayerObject::onRemove()
{
Parent::onRemove();
}
20 changes: 20 additions & 0 deletions Engine/source/T3D/gameObjects/aiPlayerObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once
#include "playerObject.h"

#include "T3D/components/ai/aiControllerComponent.h"

class AIPlayerObject : public PlayerObject
{
typedef PlayerObject Parent;

AIControllerComponent* mAIControllerComponent;

public:
AIPlayerObject();
~AIPlayerObject();

virtual bool onAdd();
virtual void onRemove();

DECLARE_CONOBJECT(AIPlayerObject);
};
165 changes: 165 additions & 0 deletions Engine/source/T3D/gameObjects/playerObject.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
#include "playerObject.h"

IMPLEMENT_CO_NETOBJECT_V1(PlayerObject);

PlayerObject::PlayerObject()
: mMeshComponent(nullptr),
mCollisionComponent(nullptr),
mAnimationComponent(nullptr),
mPhysicsComponent(nullptr)
{

}
PlayerObject::~PlayerObject()
{

}

bool PlayerObject::onAdd()
{
if (!Parent::onAdd())
return false;

//If we don't delinate from the template, just spawn as apropos here
if (!mDirtyGameObject)
{
//Mesh
mMeshComponent = new MeshComponent();
if (!mMeshComponent->registerObject())
{
Con::errorf("PlayerObject::onAdd - unable to add MeshComponent!");
return false;
}

mMeshComponent->setInternalName("meshComponent");

addComponent(mMeshComponent);

//Collision
mCollisionComponent = new ShapeCollisionComponent();
if (!mCollisionComponent->registerObject())
{
Con::errorf("PlayerObject::onAdd - unable to add ShapeCollisionComponent!");
return false;
}

mCollisionComponent->setInternalName("collisionComponent");

addComponent(mCollisionComponent);

//Animation
mAnimationComponent = new ActionAnimationComponent();
if (!mAnimationComponent->registerObject())
{
Con::errorf("PlayerObject::onAdd - unable to add ActionAnimationComponent!");
return false;
}

mAnimationComponent->setInternalName("animationComponent");

addComponent(mAnimationComponent);

//Arm Animation
mArmAnimationComponent = new ArmAnimationComponent();
if (!mArmAnimationComponent->registerObject())
{
Con::errorf("PlayerObject::onAdd - unable to add ArmAnimationComponent!");
return false;
}

mArmAnimationComponent->setInternalName("armAnimationComponent");

addComponent(mArmAnimationComponent);

//Physics control
mPhysicsComponent = new PlayerControllerComponent();
if (!mPhysicsComponent->registerObject())
{
Con::errorf("PlayerObject::onAdd - unable to add PhysicsComponent!");
return false;
}

mPhysicsComponent->setInternalName("physicsComponent");

addComponent(mPhysicsComponent);

//State Machine
mStateMachineComponent = new StateMachineComponent();
if (!mStateMachineComponent->registerObject())
{
Con::errorf("PlayerObject::onAdd - unable to add StateMachineComponent!");
return false;
}

mStateMachineComponent->setInternalName("stateMachineComponent");

addComponent(mStateMachineComponent);

//Camera
mCameraComponent = new CameraComponent();
if (!mCameraComponent->registerObject())
{
Con::errorf("PlayerObject::onAdd - unable to add CameraComponent!");
return false;
}

mCameraComponent->setInternalName("cameraComponent");

addComponent(mCameraComponent);

//Camera Orbiter
mCameraOrbiterComponent = new CameraOrbiterComponent();
if (!mCameraOrbiterComponent->registerObject())
{
Con::errorf("PlayerObject::onAdd - unable to add CameraOrbiterComponent!");
return false;
}

mCameraOrbiterComponent->setInternalName("cameraOrbiterComponent");

addComponent(mCameraOrbiterComponent);

//Control Object
mControlObjectComponent = new ControlObjectComponent();
if (!mControlObjectComponent->registerObject())
{
Con::errorf("PlayerObject::onAdd - unable to add ControlObjectComponent!");
return false;
}

mControlObjectComponent->setInternalName("controlObjectComponent");

addComponent(mControlObjectComponent);

//Sound
mSoundComponent = new SoundComponent();
if (!mSoundComponent->registerObject())
{
Con::errorf("PlayerObject::onAdd - unable to add SoundComponent!");
return false;
}

mSoundComponent->setInternalName("soundComponent");

addComponent(mSoundComponent);

//Interaction
mInteractComponent = new InteractComponent();
if (!mInteractComponent->registerObject())
{
Con::errorf("PlayerObject::onAdd - unable to add InteractComponent!");
return false;
}

mInteractComponent->setInternalName("interactComponent");

addComponent(mInteractComponent);
}

return true;
}

void PlayerObject::onRemove()
{
Parent::onRemove();
}
Loading