📄 gamegroup.cpp
字号:
#include "StdAfx.h"
#include ".\gamegroup.h"
//************************************
// <p>Description: 构造函数</p>
//************************************
CGameGroup::CGameGroup(void) : CGameObject()
{
m_enGameType = Type_Group;
}
//************************************
// <p>Description: 析构函数</p>
//************************************
CGameGroup::~CGameGroup(void)
{
}
//************************************
// <p>Description: 设置名字</p>
// <p>Parameters: </p>
// <p> LPCTSTR lpName</p>
//
// <p>Returns: void</p>
//************************************
void CGameGroup::SetObjectName(LPCTSTR lpName){
memcpy(&m_szName, lpName, MAX_NAME);
}
//************************************
// <p>Description: 获取名字</p>
//
// <p>Returns: LPCTSTR</p>
//************************************
LPCTSTR CGameGroup::GetObjectName(){
return m_szName;
}
//************************************
// <p>Description: 对象创建</p>
// <p>Parameters: </p>
// <p> LPCTSTR lpName</p>
// <p> _SIZE siSize</p>
// <p> ...</p>
//
// <p>Returns: bool</p>
//************************************
bool CGameGroup::Create(LPCTSTR lpName, _SIZE siSize, enGameObjectType enType, ...){
__super::Create(lpName, siSize, enType);
return true;
}
//************************************
// <p>Description: 设置可视</p>
// <p>Parameters: </p>
// <p> bool bFlag</p>
//
// <p>Returns: void</p>
//************************************
void CGameGroup::SetVisabled(bool bFlag){
__super::SetVisabled(bFlag);
//IGameObject* pIGameObject = m_lstGameObjects.Iterators(true);
//while(pIGameObject){
// pIGameObject->SetVisabled(bFlag);
// pIGameObject = m_lstGameObjects.Iterators();
//}
}
//************************************
// <p>Description: 设置禁用</p>
// <p>Parameters: </p>
// <p> bool bFlag</p>
//
// <p>Returns: void</p>
//************************************
void CGameGroup::SetDisabled(bool bFlag){
__super::SetDisabled(bFlag);
IGameObject* pIGameObject = m_lstGameObjects.Iterators(true);
while(pIGameObject){
pIGameObject->SetDisabled(bFlag);
pIGameObject = m_lstGameObjects.Iterators();
}
}
//************************************
// <p>Description: 设置点击</p>
// <p>Parameters: </p>
// <p> bool bFlag</p>
//
// <p>Returns: void</p>
//************************************
void CGameGroup::SetClickabled(bool bFlag){
__super::SetClickabled(bFlag);
IGameObject* pIGameObject = m_lstGameObjects.Iterators(true);
while(pIGameObject){
pIGameObject->SetClickabled(bFlag);
pIGameObject = m_lstGameObjects.Iterators();
}
}
//************************************
// <p>Description: 设置角度</p>
// <p>Parameters: </p>
// <p> float fAngle</p>
//
// <p>Returns: void</p>
//************************************
void CGameGroup::SetAngle(float fAngle){
float fOffset = fAngle - m_GameBasalInfo.Angle*180.0f/M_PI;
SetAngleOffset(fOffset);
}
//************************************
// <p>Description: 设置角度</p>
// <p>Parameters: </p>
// <p> float fAngle</p>
//
// <p>Returns: void</p>
//************************************
void CGameGroup::SetAngleOffset(float fAngle){
__super::SetAngleOffset(fAngle);
IGameObject* pIGameObject = m_lstGameObjects.Iterators(true);
while(pIGameObject){
pIGameObject->SetAngleOffset(fAngle);
pIGameObject = m_lstGameObjects.Iterators();
}
}
//************************************
// <p>Description: 设置透明</p>
// <p>Parameters: </p>
// <p> WORD wAlpha</p>
//
// <p>Returns: void</p>
//************************************
void CGameGroup::SetAlpha(WORD wAlpha){
WORD wOffset = wAlpha - m_GameBasalInfo.Alpha;
SetAlphaOffset(wOffset);
}
//************************************
// <p>Description: 设置透明</p>
// <p>Parameters: </p>
// <p> WORD wAlpha</p>
//
// <p>Returns: void</p>
//************************************
void CGameGroup::SetAlphaOffset(WORD wAlpha){
__super::SetAlphaOffset(wAlpha);
IGameObject* pIGameObject = m_lstGameObjects.Iterators(true);
while(pIGameObject){
pIGameObject->SetAlphaOffset(wAlpha);
pIGameObject = m_lstGameObjects.Iterators();
}
}
//************************************
// <p>Description: 设置Z空间</p>
// <p>Parameters: </p>
// <p> WORD wZ</p>
//
// <p>Returns: void</p>
//************************************
void CGameGroup::SetZ(WORD wZ){
WORD wOffset = wZ - m_GameBasalInfo.Z;
SetZOffset(wOffset);
}
//************************************
// <p>Description: 设置Z空间</p>
// <p>Parameters: </p>
// <p> WORD wZ</p>
//
// <p>Returns: void</p>
//************************************
void CGameGroup::SetZOffset(WORD wZ){
__super::SetZOffset(wZ);
IGameObject* pIGameObject = m_lstGameObjects.Iterators(true);
while(pIGameObject){
pIGameObject->SetZOffset(wZ);
pIGameObject = m_lstGameObjects.Iterators();
}
}
//************************************
// <p>Description: 设置缩放</p>
// <p>Parameters: </p>
// <p> _SIZE siSize</p>
//
// <p>Returns: void</p>
//************************************
void CGameGroup::SetScaling(_SIZE siSize){
_SIZE siOffset;
siOffset.cx = siSize.cx - m_GameBasalInfo.Scaling.cx;
siOffset.cy = siSize.cy - m_GameBasalInfo.Scaling.cy;
SetScalingOffset(siOffset);
}
//************************************
// <p>Description: 设置缩放</p>
// <p>Parameters: </p>
// <p> _SIZE siSize</p>
//
// <p>Returns: void</p>
//************************************
void CGameGroup::SetScalingOffset(_SIZE siSize){
__super::SetScalingOffset(siSize);
IGameObject* pIGameObject = m_lstGameObjects.Iterators(true);
while(pIGameObject){
pIGameObject->SetScalingOffset(siSize);
pIGameObject = m_lstGameObjects.Iterators();
}
}
//************************************
// <p>Description: 设置深度</p>
// <p>Parameters: </p>
// <p> DWORD dwDepth</p>
//
// <p>Returns: void</p>
//************************************
void CGameGroup::SetDepth(DWORD dwDepth){
__super::SetDepth(dwDepth);
IGameObject* pIGameObject = m_lstGameObjects.Iterators(true);
while(pIGameObject){
pIGameObject->SetDepth(dwDepth);
pIGameObject = m_lstGameObjects.Iterators();
}
}
//************************************
// <p>Description: 设置中心</p>
// <p>Parameters: </p>
// <p> _POINT piPoint</p>
//
// <p>Returns: void</p>
//************************************
void CGameGroup::SetAnchorPosition(_POINT piPoint){
_POINT piOffset;
piOffset.x = piPoint.x - m_BasalInfo.AnchorPos.x;
piOffset.y = piPoint.y - m_BasalInfo.AnchorPos.y;
SetAnchorPosition(piOffset);
}
//************************************
// <p>Description: 设置中心</p>
// <p>Parameters: </p>
// <p> _POINT piPoint</p>
//
// <p>Returns: void</p>
//************************************
void CGameGroup::SetAnchorPositionOffset(_POINT piPoint){
__super::SetAnchorPositionOffset(piPoint);
IGameObject* pIGameObject = m_lstGameObjects.Iterators(true);
while(pIGameObject){
pIGameObject->SetAnchorPositionOffset(piPoint);
pIGameObject = m_lstGameObjects.Iterators();
}
}
//************************************
// <p>Description: 移动对象</p>
// <p>Parameters: </p>
// <p> _POINT piPoint</p>
//
// <p>Returns: void</p>
//************************************
void CGameGroup::MoveTo(_POINT piPoint){
_POINT piDiff;
piDiff.x = piPoint.x - m_BasalInfo.LocalPos.x;
piDiff.y = piPoint.y - m_BasalInfo.LocalPos.y;
MoveToOffset(piDiff);
}
//************************************
// <p>Description: 移动对象</p>
// <p>Parameters: </p>
// <p> _POINT piPoint</p>
//
// <p>Returns: void</p>
//************************************
void CGameGroup::MoveToOffset(_POINT piPoint){
__super::MoveToOffset(piPoint);
IGameObject* pIGameObject = m_lstGameObjects.Iterators(true);
while(pIGameObject){
//pIGameObject->MoveToOffset(piPoint);
//不需要移动子对象,只需通知子对象更新父对象的坐标即可
pIGameObject->CalcContainerPosition();
pIGameObject = m_lstGameObjects.Iterators();
}
}
//************************************
// <p>Description: 返回对象容器坐标</p>
// <p>Parameters: </p>
//
// <p>Returns: void</p>
//************************************
void CGameGroup::CalcContainerPosition(){
__super::CalcContainerPosition();
IGameObject* pIGameObject = m_lstGameObjects.Iterators(true);
while(pIGameObject){
pIGameObject->CalcContainerPosition();
pIGameObject = m_lstGameObjects.Iterators();
}
}
//************************************
// <p>Description: 返回管理元素列表长度</p>
// <p>Parameters: </p>
//
// <p>Returns: INT_PTR</p>
//************************************
INT_PTR CGameGroup::GetLength(){
return m_lstGameObjects.GetCount();
}
//************************************
// <p>Description: 返回元素</p>
// <p>Parameters: </p>
// <p> INT_PTR nIndex</p>
//
// <p>Returns: IGameObject*</p>
//************************************
IGameObject* CGameGroup::Get(INT_PTR nIndex){
return m_lstGameObjects.Get(nIndex);
}
//************************************
// <p>Description: 返回元素</p>
// <p>Parameters: </p>
// <p> LPCTSTR szKey</p>
//
// <p>Returns: IGameObject*</p>
//************************************
IGameObject* CGameGroup::GetBy(LPCTSTR szKey){
return m_lstGameObjects.GetBy(szKey);
}
//************************************
// <p>Description: 返回元素</p>
// <p>Parameters: </p>
// <p> INT_PTR nIndex</p>
//
// <p>Returns: IGameObject*</p>
//************************************
IGameObject* CGameGroup::operator[](INT_PTR nIndex){
return Get(nIndex);
}
//************************************
// <p>Description: 返回元素</p>
// <p>Parameters: </p>
// <p> LPCTSTR szKey</p>
//
// <p>Returns: IGameObject*</p>
//************************************
IGameObject* CGameGroup::operator[](LPCTSTR szKey){
return GetBy(szKey);
}
//************************************
// <p>Description: 添加元素</p>
// <p>Parameters: </p>
// <p> IGameObject * pIGameObject</p>
// <p> _CString szName</p>
// <p> INT_PTR nPosition</p>
//
// <p>Returns: bool</p>
//************************************
bool CGameGroup::Add(IGameObject* pIGameObject, _CString szName, INT_PTR nPosition){
if(nPosition==LISTTEMPLATE_LAST_ITEM)
m_lstGameObjects.Push(pIGameObject, szName);
else
m_lstGameObjects.Insert(pIGameObject, nPosition, szName);
//计算组的左上角坐标(求left,top最小值)
//计算组的右下角坐标(求right,bottom最大值)
_POINT piLeftTop, piRightBottom;
_SIZE siSize;
piLeftTop = pIGameObject->GetLocalPosition();
siSize = pIGameObject->GetSize();
//对象右下角坐标
piRightBottom.x = piLeftTop.x + siSize.cx;
piRightBottom.y = piLeftTop.y + siSize.cy;
//判断最小的左上角坐标
if(piLeftTop.x<m_BasalInfo.LocalPos.x) m_BasalInfo.LocalPos.x = piLeftTop.x;
if(piLeftTop.y<m_BasalInfo.LocalPos.y) m_BasalInfo.LocalPos.y = piLeftTop.y;
//判断最大的右下角坐标
if(piRightBottom.x*m_GameBasalInfo.Scaling.cx>m_BasalInfo.LocalPos.x+m_BasalInfo.Size.cx) m_BasalInfo.Size.cx = (piRightBottom.x - m_BasalInfo.LocalPos.x)*m_GameBasalInfo.Scaling.cx;
if(piRightBottom.y*m_GameBasalInfo.Scaling.cy>m_BasalInfo.LocalPos.y+m_BasalInfo.Size.cy) m_BasalInfo.Size.cy = (piRightBottom.y - m_BasalInfo.LocalPos.y)*m_GameBasalInfo.Scaling.cy;
//关联对象
pIGameObject->SetParent(GET_OBJECTPTR_INTERFACE(this, IUnknownEx));
pIGameObject->CalcContainerPosition();
return true;
}
//************************************
// <p>Description: 移除元素</p>
// <p>Parameters: </p>
// <p> INT_PTR nIndex</p>
//
// <p>Returns: bool</p>
//************************************
bool CGameGroup::Remove(INT_PTR nIndex){
m_lstGameObjects.Remove(nIndex);
return true;
}
//************************************
// <p>Description: 移除全部元素</p>
// <p>Parameters: </p>
// Randy 8-27
// <p>Returns: bool</p>
//************************************
bool CGameGroup::RemoveAll(){
m_lstGameObjects.RemoveAll();
return true;
}
//************************************
// <p>Description: 移除元素</p>
// <p>Parameters: </p>
// <p> _CString szKey</p>
//
// <p>Returns: bool</p>
//************************************
bool CGameGroup::Remove(_CString szKey){
m_lstGameObjects.RemoveBy(szKey);
return true;
}
//渲染场景
void CGameGroup::Render(WPARAM wParam){
IGameObject* pIGameObject = m_lstGameObjects.Iterators(true);
while(pIGameObject){
if(pIGameObject->IsVisabled()){
pIGameObject->Render(wParam);
}
pIGameObject = m_lstGameObjects.Iterators();
}
}
//************************************
// <p>Description: 接口查询</p>
// <p>Parameters: </p>
// <p> const IID & Guid</p>
// <p> DWORD dwQueryVer</p>
//
// <p>Returns: void*</p>
//************************************
void* CGameGroup::QueryInterface(const IID &Guid, DWORD dwQueryVer){
QUERYINTERFACE(IGameObject,Guid,dwQueryVer);
QUERYINTERFACE(IBaseObject,Guid,dwQueryVer);
QUERYINTERFACE_IUNKNOWNEX(IGameObject,Guid,dwQueryVer);
return NULL;
}
//************************************
// <p>Description: =操作重载</p>
// <p>Parameters: </p>
// <p> const CGameGroup & GameObject</p>
//
// <p>Returns: CGameGroup&</p>
//************************************
CGameGroup& CGameGroup::operator=(CGameGroup& GameObject){
CGameObject* pOtherBaseClass = static_cast<CGameObject *>(&GameObject);
CGameObject* pMySelfBaseClass = static_cast<CGameObject *>(this);
*pMySelfBaseClass = *pOtherBaseClass;
//m_lstGameObjects = GameObject.m_lstGameObjects;
//IGameObject* pIGameObject = m_lstGameObjects.Iterators(true);
//while(pIGameObject){
// pIGameObject->SetParent(GET_OBJECTPTR_INTERFACE(this, IUnknownEx));
// pIGameObject = m_lstGameObjects.Iterators();
//}
return *this;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -