⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gamebody.cpp

📁 游戏框架
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// ***************************************************************
//  GameBody   version:  1.0
//  -------------------------------------------------------------
//	File Name:	GameBody.cpp
//	Created:	2007/07/18
//	Modified:	2007/07/18   17:26
//	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 ".\gamebody.h"
#include ".\GameSection.h"
#include ".\GameLayouter.h"
#include ".\GameLayouterSinkTexture.h"
#include ".\GameLayouterSinkSection.h"
#include ".\GameLayouterSinkObject.h"

//************************************
// <p>Description: 构造函数</p>
//************************************
CGameBody::CGameBody(void)
{
	m_pCurrentSection		= NULL;
	m_pQueueServiceEvent	= NULL;
	m_pGameLayouter			= NULL;
}

//************************************
// <p>Description: 析构函数</p>
//************************************
CGameBody::~CGameBody(void)
{
}

//************************************
// <p>Description: 设置游戏框架指针</p>
// <p>Parameters:  </p>
// <p>    LPFRAMEMANAGERHANDLE lpFMH</p>
//
// <p>Returns:   void</p>
//************************************
void CGameBody::SetFrameManagerHandles(LPFRAMEMANAGERHANDLE lpFMH){
	m_lpFMHandles = lpFMH;
}

//************************************
// <p>Description: 添加环节</p>
// <p>Parameters:  </p>
// <p>    IGameSection * pIGameSection</p>
// <p>    WORD wSectionID</p>
//
// <p>Returns:   bool</p>
//************************************
bool CGameBody::Add(IGameSection* pIGameSection, WORD wSectionID){
	m_pGameSections.Push(pIGameSection, wSectionID);
	pIGameSection->SetFrameManagerHandles(m_lpFMHandles);

	return pIGameSection->OnInitialize();
}

//************************************
// <p>Description: 切换环节</p>
// <p>Parameters:  </p>
// <p>    WORD wSectionID</p>
//
// <p>Returns:   bool</p>
//************************************
bool CGameBody::SwitchSection(WORD wSectionID){
	bool		bCanLeave = true;
	WORD		wCurrentSection = 0;

	//判断当前有否环节
	if(m_pCurrentSection){
		//调用当前环节的准备离开事件
		bCanLeave = m_pCurrentSection->OnSectionOut(wSectionID);
		//返回当前环节的ID
		wCurrentSection = m_pCurrentSection->GetSectionID();
	}

	//判断是否允许离开当前环节
	//默认是允许的,可由当前环节的离开事件返回值决定
	if(bCanLeave){
		//返回指定的环节
		m_pCurrentSection = m_pGameSections.GetBy(wSectionID);
		_ASSERT(m_pCurrentSection);
		//判断新的环节是否有效
		if(m_pCurrentSection){
			//执行新环节的进入事件
			m_pCurrentSection->OnSectionIn(wCurrentSection);
		}
	}

	return true;
}

//************************************
// <p>Description: 返回环节</p>
// <p>Parameters:  </p>
// <p>    WORD wSectionID</p>
//
// <p>Returns:   IGameSection*</p>
//************************************
IGameSection* CGameBody::GetSection(WORD wSectionID){
	return m_pGameSections.GetBy(wSectionID);
}

//************************************
// <p>Description: 返回当前环节</p>
//
// <p>Returns:   IGameSection*</p>
//************************************
IGameSection* CGameBody::GetCurrentSection(){
	return m_pCurrentSection;
}

//************************************
// <p>Description: 注册布局管理器</p>
// <p>Parameters:  </p>
// <p>    IGameLayouterSink * pGameLayouterSink</p>
//
// <p>Returns:   bool</p>
//************************************
bool CGameBody::RegisterLayouter(IGameLayouterSink* pGameLayouterSink){
	//布局器为空则创建
	if(m_pGameLayouter==NULL){
		CGameLayouter*	pLayouter	= new CGameLayouter(m_lpFMHandles);
		m_pGameLayouter	= GET_OBJECTPTR_INTERFACE(pLayouter, IGameLayouter);
	}

	if(m_pGameLayouter){
		if(pGameLayouterSink){
			//注册指定的布局处理器
			m_pGameLayouter->RegisterLayouterSink(pGameLayouterSink);
		}
		else{
			//注册默认的布局处理器
			//纹理、环节、场景、层等
			CGameLayouterSinkTexture*	pGameLayouterSinkTexture = new CGameLayouterSinkTexture();
			m_pGameLayouter->RegisterLayouterSink(GET_OBJECTPTR_INTERFACE(pGameLayouterSinkTexture, IGameLayouterSink));
			CGameLayouterSinkSection*	pGameLayouterSinkSection = new CGameLayouterSinkSection();
			m_pGameLayouter->RegisterLayouterSink(GET_OBJECTPTR_INTERFACE(pGameLayouterSinkSection, IGameLayouterSink));
			CGameLayouterSinkObject*	pGameLayouterSinkObject = new CGameLayouterSinkObject();
			m_pGameLayouter->RegisterLayouterSink(GET_OBJECTPTR_INTERFACE(pGameLayouterSinkObject, IGameLayouterSink));
		}
	}
	return true;
}

//************************************
// <p>Description: 返回布局管理器</p>
// <p>Parameters:  </p>
//
// <p>Returns:   IGameLayouter*</p>
//************************************
IGameLayouter* CGameBody::GetLayouter(){
	return m_pGameLayouter;
}

//************************************
// <p>Description: 资源加载事件</p>
//
// <p>Returns:   void</p>
//************************************
void CGameBody::OnLoading(){
	//留待扩展,暂时没用
	if(m_pCurrentSection){
		m_pCurrentSection->OnLoading();
	}
}

//************************************
// <p>Description: 资源加载完毕</p>
//
// <p>Returns:   void</p>
//************************************
void CGameBody::OnLoadingFinish(){
	//留待扩展,暂时没用
}

//************************************
// <p>Description: 初始化事件</p>
//
// <p>Returns:   bool</p>
//************************************
bool CGameBody::OnInitialize(){

	if(m_lpFMHandles->pGameFrameDlg->GetGameFrameSetting()->bUsePropertiesManager)
		m_lpFMHandles->pIPropertiesManager = new CPropertiesManager();

	CGameSection*			pGameSection = new CGameSection();

	if(pGameSection){
		m_pCurrentSection = (IGameSection*)pGameSection->QueryInterface(IID_IGameSection, VER_IGameSection);
		Add(m_pCurrentSection, pGameSection->GetSectionID());

		return true;
	}

	return false;
}

//************************************
// <p>Description: 结束事件</p>
//
// <p>Returns:   bool</p>
//************************************
bool CGameBody::OnUnInitialize(){

	//关闭道具管理器
	if(m_lpFMHandles->pGameFrameDlg->GetGameFrameSetting()->bUsePropertiesManager)
		m_lpFMHandles->pIPropertiesManager->Release();

	IGameSection*		pIGameSection = m_pGameSections.Iterators(true);
	while(pIGameSection){
		pIGameSection->OnUnInitialize();
		pIGameSection->Release();
		pIGameSection = m_pGameSections.Iterators();
	}
	m_pGameSections.RemoveAll();

	Release();
	return true;
}

//************************************
// <p>Description: 环节切换进入前事件</p>
// <p>Parameters:  </p>
// <p>    WORD wBeforeSection</p>
//
// <p>Returns:   bool</p>
//************************************
bool CGameBody::OnSectionIn(WORD wBeforeSection){
	return true;
}

//************************************
// <p>Description: 环节切换离开事件</p>
// <p>Parameters:  </p>
// <p>    WORD wAfterSection</p>
//
// <p>Returns:   bool</p>
//************************************
bool CGameBody::OnSectionOut(WORD wAfterSection){
	return true;
}

//************************************
// <p>Description: 鼠标移动</p>
// <p>Parameters:  </p>
// <p>    float x</p>
// <p>    float y</p>
// <p>    int nType</p>
// <p>    int nKey</p>
//
// <p>Returns:   bool</p>
//************************************
bool CGameBody::OnMouseMove(float x, float y, UINT nComboKey){
	if(m_pCurrentSection)
		return m_pCurrentSection->OnMouseMove(x, y, nComboKey);
	return false;
}

//************************************
// <p>Description: 鼠标点击</p>
// <p>Parameters:  </p>
// <p>    IGameObject * pGameObject</p>
// <p>    float x</p>
// <p>    float y</p>
// <p>    int nType</p>
// <p>    int nKey</p>
//
// <p>Returns:   bool</p>
//************************************
bool CGameBody::OnMouseClick(IGameObject* pGameObject, float x, float y, int nType, UINT nMessage, UINT nComboKey){
	if(m_pCurrentSection){
		if(nType==INPUT_MOUSE_DOWN)
			OnMouseDown(pGameObject, x, y, nMessage, nComboKey);
		else{
			OnMouseUp(pGameObject, x, y, nMessage, nComboKey);
		}

		return m_pCurrentSection->OnMouseClick(pGameObject, x, y, nType, nMessage, nComboKey);
	}
	return false;
}

//************************************
// <p>Description: 鼠标双击</p>
// <p>Parameters:  </p>
// <p>    IGameObject * pGameObject</p>
// <p>    float x</p>
// <p>    float y</p>
// <p>    UINT nComboKey</p>
//
// <p>Returns:   bool</p>
//************************************
bool CGameBody::OnMouseDBClick(IGameObject* pGameObject, float x, float y, UINT nMessage, UINT nComboKey){
	if(m_pCurrentSection)
		return m_pCurrentSection->OnMouseDBClick(pGameObject, x, y, nMessage, nComboKey);
	return false;
}

//************************************
// <p>Description: 鼠标点击</p>
// <p>Parameters:  </p>
// <p>    IGameObject * pGameObject</p>
// <p>    float x</p>
// <p>    float y</p>
// <p>    int nKey</p>
//
// <p>Returns:   bool</p>
//************************************
bool CGameBody::OnMouseUp(IGameObject* pGameObject, float x, float y, UINT nMessage, UINT nComboKey){
	if(m_pCurrentSection)
		return m_pCurrentSection->OnMouseUp(pGameObject, x, y, nMessage, nComboKey);
	return false;
}

//************************************
// <p>Description: 鼠标点击</p>
// <p>Parameters:  </p>
// <p>    IGameObject * pGameObject</p>
// <p>    float x</p>
// <p>    float y</p>
// <p>    int nKey</p>
//
// <p>Returns:   bool</p>
//************************************
bool CGameBody::OnMouseDown(IGameObject* pGameObject, float x, float y, UINT nMessage, UINT nComboKey){
	if(m_pCurrentSection)
		return m_pCurrentSection->OnMouseDown(pGameObject, x, y, nMessage, nComboKey);
	return false;
}

//************************************
// <p>Description: 鼠标移入</p>
// <p>Parameters:  </p>
// <p>    IGameObject * pGameObject</p>
// <p>    float x</p>
// <p>    float y</p>
// <p>    int nType</p>
// <p>    int nKey</p>
//
// <p>Returns:   bool</p>
//************************************
bool CGameBody::OnMouseIn(IGameObject* pGameObject, float x, float y, int nType, UINT nMessage, UINT nComboKey){
	if(m_pCurrentSection)
		return m_pCurrentSection->OnMouseIn(pGameObject, x, y, nType, nMessage, nComboKey);
	return false;
}

//************************************
// <p>Description: 鼠标移出</p>
// <p>Parameters:  </p>
// <p>    IGameObject * pGameObject</p>
// <p>    float x</p>
// <p>    float y</p>
// <p>    int nType</p>
// <p>    int nKey</p>
//
// <p>Returns:   bool</p>
//************************************
bool CGameBody::OnMouseOut(IGameObject* pGameObject, float x, float y, int nType, UINT nMessage, UINT nComboKey){
	if(m_pCurrentSection)
		return m_pCurrentSection->OnMouseOut(pGameObject, x, y, nType, nMessage, nComboKey);
	return false;
}

//************************************
// <p>Description: 鼠标移过</p>
// <p>Parameters:  </p>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -