📄 gamelayoutersinkobject.cpp
字号:
// ***************************************************************
// GameLayouterSinkObject version: 1.0
// -------------------------------------------------------------
// File Name: GameLayouterSinkObject.cpp
// Created: 2007/07/19
// Modified: 2007/07/19 16:22
// Author: William.Liang
// Msn: lwq49@msn.com
// Email: lwq49@21cn.com, lwq49@msn.com
// Description:
//
// Purpose:
// -------------------------------------------------------------
// license:
//
// The contents of this file are subject to the Mozilla Public
// License Version 1.1 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy
// of the License at http://www.mozilla.org/MPL/ Software dis-
// tributed under the License is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or im-
// plied. See the License for the specific language governing
// rights and limitations under the License.
//
// The Initial Developer of the Original Code is William.Liang .
// Copyright (C) 2007 - All Rights Reserved.
// ***************************************************************
#include "StdAfx.h"
#include ".\GameFrameDlg.h"
#include ".\ResourceLib.h"
#include ".\gamelayoutersinkobject.h"
//************************************
// <p>Description: 构造函数</p>
//************************************
CGameLayouterSinkObject::CGameLayouterSinkObject(void)
{
}
//************************************
// <p>Description: 析构函数</p>
//************************************
CGameLayouterSinkObject::~CGameLayouterSinkObject(void)
{
}
//************************************
// <p>Description: 回调处理方法</p>
// <p>Parameters: </p>
// <p> _CString szNodeName</p>
// <p> _CString szParentName</p>
// <p> LPVOID lpParam</p>
//
// <p>Returns: void</p>
//************************************
void CGameLayouterSinkObject::Processer(_CString szNodeName, _CString szParentName, LPVOID lpParam){
_CStringList* pList = NULL;
if(szNodeName == "Layer"){
//检查上层的结构格式
if(m_pIGameLayouter->ValidNodePath("Section.Scenes.Scene")){
//返回上层的对象名
LPVOID lpValue = NULL;
_CString szName;
//返回环节对象
m_pIGameLayouter->GetNodePath("Section.Scenes.Scene", &lpValue);
if(lpValue){
pList = ((_CStringList*)lpValue);
szName = pList->GetBy("ID");
WORD wSection = (int)szName;
m_pCurrentSection = m_lpFMHandles->pGameBody->GetSection(wSection);
if(m_pCurrentSection){
//返回视图
m_pCurrentView = m_pCurrentSection->GetGameView();
if(m_pCurrentView){
//返回场景
lpValue = NULL;
m_pIGameLayouter->GetNodePath("Scene", &lpValue);
if(lpValue){
pList = ((_CStringList*)lpValue);
szName = pList->GetBy("Name");
m_pCurrentScene = m_pCurrentView->GetBy(szName);
if(m_pCurrentScene){
pList = ((_CStringList*)lpParam);
szName = pList->GetBy("Name");
m_pCurrentLayer = m_pCurrentScene->GetBy(szName);
}
}
}
}
}
else{
m_pCurrentSection = NULL;
}
}
}
if(szNodeName == "Object"){
//上层的Section,View和Layer不能为空
if(m_pCurrentSection==NULL || m_pCurrentView==NULL || m_pCurrentScene==NULL || m_pCurrentLayer==NULL)
goto Push_Node_Stack;
//检查上层的结构格式
if(m_pIGameLayouter->ValidNodePath("Section.Scenes.Scene.Layer")){
//加载资源
pList = ((_CStringList*)lpParam);
_CString szName = pList->GetBy("Name");
//暂当为空字串时不作后继处理,以后应自动生成唯一名
if(szName.IsNull() || szName=="")
goto Push_Node_Stack;
_SIZE siSize;
bool bVisabledFlag;
bool bDisabledFlag;
siSize.cx = (float)pList->GetBy("Width");
siSize.cy = (float)pList->GetBy("Height");
bVisabledFlag = (bool)pList->GetBy("Visabled");
if(pList->GetBy("Disabled").IsNull())
bDisabledFlag = true;
else
bDisabledFlag = (bool)pList->GetBy("Disabled");
if(siSize.cx==0) siSize.cx = 0;
if(siSize.cy==0) siSize.cy = 0;
IGameObject* pIGameObject = m_pCurrentLayer->GetBy(szName);
if(pIGameObject==NULL){
_CString szType = pList->GetBy("Type");
if(szType=="Sprite"){
//检查资源ID是否有效
_CString szTextureKey = pList->GetBy("Texture");
if(szTextureKey.IsNull() || szTextureKey=="")
goto Push_Node_Stack;
CResource* pResource = m_lpFMHandles->pResourceLib->GetTexture(szTextureKey);
if(pResource==NULL)
goto Push_Node_Stack;
CGameObjectSprite* pGameObject = new CGameObjectSprite();
pGameObject->Create(szName, siSize, pResource);
pIGameObject = GET_OBJECTPTR_INTERFACE(pGameObject, IGameObject);
}
else{
if(szType=="Text"){
//检查资源ID是否有效
_CString szFontName = pList->GetBy("Font");
if(szFontName.IsNull() || szFontName=="")
goto Push_Node_Stack;
CGameObjectText* pGameObject = new CGameObjectText();
pGameObject->Create(szName, siSize, szFontName);
_CString szText = pList->GetBy("Text");
pGameObject->SetText(szText);
pIGameObject = GET_OBJECTPTR_INTERFACE(pGameObject, IGameObject);
}
else{
if(szType=="Anim"){
_CString szTextureKey= pList->GetBy("Texture");
_CString szTemp = pList->GetBy("Frames");
DWORD dwFrames = (DWORD)(int)szTemp;
szTemp = pList->GetBy("Cols");
DWORD dwCols = (DWORD)(int)szTemp;
szTemp = pList->GetBy("Rows");
DWORD dwRows = (DWORD)(int)szTemp;
szTemp = pList->GetBy("FPS");
float fFPS = (float)szTemp;
szTemp = pList->GetBy("CurrRow");
WORD wCurrRow = (WORD)(int)szTemp;
szTemp = pList->GetBy("Stopped");
bool bStopped = (bool)szTemp;
if(szTextureKey.IsNull() || szTextureKey=="")
goto Push_Node_Stack;
CResource* pResource = m_lpFMHandles->pResourceLib->GetTexture(szTextureKey);
if(pResource==NULL)
goto Push_Node_Stack;
if(dwFrames==0) dwFrames = 1;
if(dwCols==0) dwCols = 1;
if(dwRows==0) dwRows = 1;
if(fFPS==0) fFPS = 1;
CGameObjectAnim* pGameObject = new CGameObjectAnim();
pGameObject->Create(szName, siSize, pResource, dwFrames, fFPS, dwCols, dwRows);
if(!bStopped)
pGameObject->Play();
pGameObject->SetRow(wCurrRow);
pIGameObject = GET_OBJECTPTR_INTERFACE(pGameObject, IGameObject);
}
else{
if(szType=="Button"){
_CString szTextureKey = pList->GetBy("Texture");
if(szTextureKey.IsNull() || szTextureKey=="")
goto Push_Node_Stack;
_CString szCaption = pList->GetBy("Caption");
CResource* pResource = m_lpFMHandles->pResourceLib->GetTexture(szTextureKey);
if(pResource==NULL)
goto Push_Node_Stack;
CGameObjectButton* pGameObject = new CGameObjectButton();
pGameObject->Create(szName, siSize, pResource, szCaption);
pIGameObject = GET_OBJECTPTR_INTERFACE(pGameObject, IGameObject);
}
}
}
}
}
_POINT piPoint;
_CString szAlias = pList->GetBy("Alias");
if(szAlias.IsNull()) szAlias = szName;
piPoint.x = (float)pList->GetBy("Left");
piPoint.y = (float)pList->GetBy("Top");
m_pCurrentLayer->Add(pIGameObject, szAlias);
pIGameObject->MoveTo(piPoint);
//m_pCurrentScene->SetSize(siSize);
pIGameObject->SetVisabled(bVisabledFlag);
pIGameObject->SetDisabled(bDisabledFlag);
m_pCurrentObject = pIGameObject;
goto Push_Node_Stack;
}
}
if(szNodeName == "TextureSize"){
//上层的Section,View和Layer不能为空
if(m_pCurrentSection==NULL || m_pCurrentView==NULL || m_pCurrentScene==NULL || m_pCurrentLayer==NULL || m_pCurrentObject==NULL)
goto Push_Node_Stack;
//校验上层路径
if(m_pIGameLayouter->ValidNodePath("Section.Scenes.Scene.Layer.Object")){
LPVOID lpValue = NULL;
if(m_pIGameLayouter->GetNodePath("Object", &lpValue)){
if(lpValue){
pList = ((_CStringList*)lpValue);
if(pList){
_CString szTemp = pList->GetBy("Type");
if(szTemp == "Sprite"){
pList = ((_CStringList*)lpParam);
_RECT rcSize;
rcSize.left = (float)(pList->GetBy("Left"));
rcSize.top = (float)(pList->GetBy("Top"));
rcSize.right = (float)(pList->GetBy("Right"));
rcSize.bottom = (float)(pList->GetBy("Bottom"));
CGameObjectSprite* pGameObject = (CGameObjectSprite*)m_pCurrentObject;//GET_OBJECTPTR_INTERFACE(m_pCurrentObject, IGameObjectSprite);
pGameObject->SetTextureSize(rcSize);
}
}
}
}
//m_pCurrentObject->Set
}
}
Push_Node_Stack:
return;
}
//************************************
// <p>Description: 设置上级接口</p>
// <p>Parameters: </p>
// <p> IGameLayouter * pIGameLayouter</p>
// <p> LPFRAMEMANAGERHANDLE pFMHandles</p>
//
// <p>Returns: void</p>
//************************************
void CGameLayouterSinkObject::SetGameLayouter(IGameLayouter* pIGameLayouter, LPFRAMEMANAGERHANDLE pFMHandles){
m_pIGameLayouter = pIGameLayouter;
m_lpFMHandles = pFMHandles;
//返回屏幕大小
GAMEFRAMESETTING* pGameFrameSetting = m_lpFMHandles->pGameFrameDlg->GetGameFrameSetting();
}
//************************************
// <p>Description: 接口查询</p>
// <p>Parameters: </p>
// <p> const IID & Guid</p>
// <p> DWORD dwQueryVer</p>
//
// <p>Returns: void *</p>
//************************************
void * CGameLayouterSinkObject::QueryInterface(const IID & Guid, DWORD dwQueryVer){
QUERYINTERFACE(IGameLayouterSink,Guid,dwQueryVer);
QUERYINTERFACE_IUNKNOWNEX(IGameLayouterSink,Guid,dwQueryVer);
return NULL;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -