#ifndef __CONTROLLAYER_H__ #define __CONTROLLAYER_H__ #include "XWidget.h" class CMapDialog; class CXTimer; class CTowerDialog; class CControlLayer : public CXWidget { public: enum ControlLayerId { _IDD_ControLyaer = 102, }; public: CControlLayer(); ~CControlLayer(); virtual bool init(); virtual bool onMouseDown(CCTouch *pTouch, CCEvent *pEvent); virtual void onMouseUp(CCTouch *pTouch, CCEvent *pEvent); virtual void onMouseMove(CCTouch *pTouch, CCEvent *pEvent); void onTimerEnd(CCObject* obj); private: int m_nTimerCount; bool m_bDblclick; CCPoint m_tMoveDist; CMapDialog* m_pMapDlg; CXTimer* m_pTimer; CTowerDialog* m_pTowerDlg; }; #endif
#include "ControlLayer.h" #include "WidgetMgr.h" #include "GameLogic.h" #include "MapDialog.h" #include "XTimer.h" #include "Dispatcher.h" CControlLayer::CControlLayer() { m_tMoveDist.setPoint(0, 0); m_pMapDlg = NULL; m_bDblclick = false; m_pTimer = NULL; m_pTowerDlg = NULL; } CControlLayer::~CControlLayer() { } bool CControlLayer::init() { CWidgetMgr::getInstance()->loadWidget(this, _IDD_ControLyaer); CWidgetMgr::getInstance()->addWnd(this); this->setTouchEnabled(true); m_pTimer = new CXTimer(); m_pTimer->init(3, 0.1f); m_pTimer->autorelease(); this->addChild(m_pTimer); m_pTimer->setTimerEndListener(this, callfuncO_selector(CControlLayer::onTimerEnd)); return true; } bool CControlLayer::onMouseDown( CCTouch *pTouch, CCEvent *pEvent ) { CCPoint tMouseDownPos = pTouch->getLocationInView(); tMouseDownPos = CCDirector::sharedDirector()->convertToGL(tMouseDownPos); tMouseDownPos = this->convertToNodeSpace(tMouseDownPos); CDispatcher::getInstance()->onMoveDown(tMouseDownPos); if (m_bDblclick) {//双击 if (1.0f == CDispatcher::getInstance()->getWorldScale()) { CDispatcher::getInstance()->setWorldScale(1.5f); } else { CDispatcher::getInstance()->setWorldScale(1.0f); } } if (m_pTimer) { m_pTimer->setCount(3); m_pTimer->start(); m_bDblclick = true; } return true; } void CControlLayer::onMouseUp( CCTouch *pTouch, CCEvent *pEvent ) { CCPoint tMouseUpPos = pTouch->getLocationInView(); tMouseUpPos = CCDirector::sharedDirector()->convertToGL(tMouseUpPos); tMouseUpPos = this->convertToNodeSpace(tMouseUpPos); } void CControlLayer::onMouseMove( CCTouch *pTouch, CCEvent *pEvent ) { CCPoint moveCurPos = pTouch->getLocationInView(); moveCurPos = CCDirector::sharedDirector()->convertToGL(moveCurPos); moveCurPos = this->convertToNodeSpace(moveCurPos); CCPoint movePrevPos = pTouch->getPreviousLocationInView(); movePrevPos = CCDirector::sharedDirector()->convertToGL(movePrevPos); movePrevPos = this->convertToNodeSpace(movePrevPos); m_tMoveDist.setPoint(moveCurPos.x - movePrevPos.x, moveCurPos.y - movePrevPos.y); CDispatcher::getInstance()->onMoveDist(m_tMoveDist); } void CControlLayer::onTimerEnd( CCObject* obj ) { m_bDblclick = false; }