修复了EMenu禁用后,EButton仍然可以自行启用的bug
This commit is contained in:
		
							parent
							
								
									1ac6f0a33d
								
							
						
					
					
						commit
						a7b29bbdf9
					
				|  | @ -214,6 +214,7 @@ | ||||||
|     <ClCompile Include="Common\EMouseMsg.cpp" /> |     <ClCompile Include="Common\EMouseMsg.cpp" /> | ||||||
|     <ClCompile Include="Common\EObject.cpp" /> |     <ClCompile Include="Common\EObject.cpp" /> | ||||||
|     <ClCompile Include="Common\EPhysicsMsg.cpp" /> |     <ClCompile Include="Common\EPhysicsMsg.cpp" /> | ||||||
|  |     <ClCompile Include="Common\ESpriteFrame.cpp" /> | ||||||
|     <ClCompile Include="Common\ETexture.cpp" /> |     <ClCompile Include="Common\ETexture.cpp" /> | ||||||
|     <ClCompile Include="Geometry\ECircle.cpp" /> |     <ClCompile Include="Geometry\ECircle.cpp" /> | ||||||
|     <ClCompile Include="Geometry\EEllipse.cpp" /> |     <ClCompile Include="Geometry\EEllipse.cpp" /> | ||||||
|  |  | ||||||
|  | @ -213,6 +213,9 @@ | ||||||
|     <ClCompile Include="Common\EPhysicsMsg.cpp"> |     <ClCompile Include="Common\EPhysicsMsg.cpp"> | ||||||
|       <Filter>Common</Filter> |       <Filter>Common</Filter> | ||||||
|     </ClCompile> |     </ClCompile> | ||||||
|  |     <ClCompile Include="Common\ESpriteFrame.cpp"> | ||||||
|  |       <Filter>Common</Filter> | ||||||
|  |     </ClCompile> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <ClInclude Include="Win\winbase.h"> |     <ClInclude Include="Win\winbase.h"> | ||||||
|  |  | ||||||
|  | @ -14,6 +14,9 @@ e2d::EButton::EButton() | ||||||
| 	, m_pDisabled(nullptr) | 	, m_pDisabled(nullptr) | ||||||
| 	, m_pListener(nullptr) | 	, m_pListener(nullptr) | ||||||
| { | { | ||||||
|  | 	m_pListener = new EListenerMouse(std::bind(&EButton::_updateStatus, this)); | ||||||
|  | 	m_pListener->setAlwaysWorking(true); | ||||||
|  | 	EMsgManager::bindListener(m_pListener, this); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| e2d::EButton::EButton(ENode * normal, const BUTTON_CLICK_CALLBACK & callback) | e2d::EButton::EButton(ENode * normal, const BUTTON_CLICK_CALLBACK & callback) | ||||||
|  | @ -145,13 +148,6 @@ void e2d::EButton::setCallback(const BUTTON_CLICK_CALLBACK & callback) | ||||||
| 	WARN_IF(m_pNormal == nullptr, "EButton cannot work without something to show. Please set its normal displayed."); | 	WARN_IF(m_pNormal == nullptr, "EButton cannot work without something to show. Please set its normal displayed."); | ||||||
| 	 | 	 | ||||||
| 	m_Callback = callback; | 	m_Callback = callback; | ||||||
| 
 |  | ||||||
| 	if (m_pListener == nullptr) |  | ||||||
| 	{ |  | ||||||
| 		m_pListener = new EListenerMouse(std::bind(&EButton::_updateStatus, this)); |  | ||||||
| 		m_pListener->setAlwaysWorking(true); |  | ||||||
| 		EMsgManager::bindListener(m_pListener, this); |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void e2d::EButton::_setStatus(STATUS status) | void e2d::EButton::_setStatus(STATUS status) | ||||||
|  |  | ||||||
|  | @ -1,4 +1,5 @@ | ||||||
| #include "..\enodes.h" | #include "..\enodes.h" | ||||||
|  | #include "..\elisteners.h" | ||||||
| 
 | 
 | ||||||
| e2d::EMenu::EMenu() | e2d::EMenu::EMenu() | ||||||
| 	: m_bEnable(true) | 	: m_bEnable(true) | ||||||
|  | @ -30,18 +31,40 @@ size_t e2d::EMenu::getButtonCount() const | ||||||
| 
 | 
 | ||||||
| void e2d::EMenu::setEnable(bool enable) | void e2d::EMenu::setEnable(bool enable) | ||||||
| { | { | ||||||
| 	m_bEnable = enable; | 	if (m_bEnable != enable) | ||||||
| 
 |  | ||||||
| 	for (auto &buttons : m_vButtons) |  | ||||||
| 	{ | 	{ | ||||||
| 		buttons->setEnable(enable); | 		m_bEnable = enable; | ||||||
|  | 
 | ||||||
|  | 		for (auto &button : m_vButtons) | ||||||
|  | 		{ | ||||||
|  | 			if (enable) | ||||||
|  | 			{ | ||||||
|  | 				button->m_pListener->start(); | ||||||
|  | 			} | ||||||
|  | 			else | ||||||
|  | 			{ | ||||||
|  | 				button->m_pListener->stop(); | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void e2d::EMenu::addButton(EButton * button) | void e2d::EMenu::addButton(EButton * button) | ||||||
| { | { | ||||||
| 	this->addChild(button); | 	if (button) | ||||||
| 	m_vButtons.push_back(button); | 	{ | ||||||
|  | 		this->addChild(button); | ||||||
|  | 		m_vButtons.push_back(button); | ||||||
|  | 
 | ||||||
|  | 		if (m_bEnable) | ||||||
|  | 		{ | ||||||
|  | 			button->m_pListener->start(); | ||||||
|  | 		} | ||||||
|  | 		else | ||||||
|  | 		{ | ||||||
|  | 			button->m_pListener->stop(); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool e2d::EMenu::removeButton(EButton * button) | bool e2d::EMenu::removeButton(EButton * button) | ||||||
|  | @ -60,6 +83,8 @@ bool e2d::EMenu::removeButton(EButton * button) | ||||||
| 		{ | 		{ | ||||||
| 			if (m_vButtons[i] == button) | 			if (m_vButtons[i] == button) | ||||||
| 			{ | 			{ | ||||||
|  | 				// 移除按钮前,将它的监听器启用
 | ||||||
|  | 				button->m_pListener->start(); | ||||||
| 				m_vButtons.erase(m_vButtons.begin() + i); | 				m_vButtons.erase(m_vButtons.begin() + i); | ||||||
| 				return true; | 				return true; | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
|  | @ -10,6 +10,7 @@ class EAction; | ||||||
| class EButton; | class EButton; | ||||||
| class EButtonToggle; | class EButtonToggle; | ||||||
| class EGeometry; | class EGeometry; | ||||||
|  | class EMenu; | ||||||
| 
 | 
 | ||||||
| class ENode : | class ENode : | ||||||
| 	public EObject | 	public EObject | ||||||
|  | @ -570,6 +571,8 @@ protected: | ||||||
| class EButton : | class EButton : | ||||||
| 	public ENode | 	public ENode | ||||||
| { | { | ||||||
|  | 	friend EMenu; | ||||||
|  | 
 | ||||||
| public: | public: | ||||||
| 	// 创建一个空按钮
 | 	// 创建一个空按钮
 | ||||||
| 	EButton(); | 	EButton(); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue