修复切换场景时按钮回调函数执行两次的BUG

This commit is contained in:
Nomango 2018-07-22 21:49:14 +08:00
parent 26ed76ae2b
commit f5752252a2
6 changed files with 13 additions and 13 deletions

View File

@ -46,7 +46,7 @@ e2d::Image::~Image()
bool e2d::Image::open(const Resource& res)
{
if (!res.isResource())
if (res.isFile())
{
WARN_IF(res.getFileName().isEmpty(), "Image open failed! Invalid file name.");
@ -162,7 +162,7 @@ bool e2d::Image::preload(const Resource& res)
ID2D1Bitmap *pBitmap = nullptr;
IWICImagingFactory *pImagingFactory = Renderer::getImagingFactory();
if (res.isResource())
if (!res.isFile())
{
HRSRC imageResHandle = nullptr;
HGLOBAL imageResDataHandle = nullptr;

View File

@ -1,7 +1,7 @@
#include "..\e2dtool.h"
e2d::Resource::Resource(const String & fileName)
: _isResource(false)
: _isFile(true)
, _fileName(fileName)
, _resNameId(0)
, _resType()
@ -9,16 +9,16 @@ e2d::Resource::Resource(const String & fileName)
}
e2d::Resource::Resource(size_t resNameId, const String & resType)
: _isResource(true)
: _isFile(false)
, _fileName()
, _resNameId(resNameId)
, _resType(resType)
{
}
bool e2d::Resource::isResource() const
bool e2d::Resource::isFile() const
{
return _isResource;
return _isFile;
}
const e2d::String & e2d::Resource::getFileName() const
@ -38,7 +38,7 @@ const e2d::String & e2d::Resource::getResType() const
size_t e2d::Resource::getKey() const
{
return _isResource ? _resNameId : _fileName.getHashCode();
return _isFile ? _fileName.getHashCode() : _resNameId;
}
bool e2d::Resource::operator>(const Resource &res) const

View File

@ -40,6 +40,7 @@ void e2d::SceneManager::push(Scene * scene, Transition * transition /* = nullptr
return;
// 保存下一场景的指针
if (_nextScene) _nextScene->release();
_nextScene = scene;
_nextScene->retain();

View File

@ -191,10 +191,9 @@ void e2d::Button::_fixedUpdate()
if (_isSelected &&
_normal->containsPoint(input->getMousePos()))
{
_isSelected = false;
_runCallback();
}
// 标记 _isSelected 为 false
_isSelected = false;
}
if (input->isPress(MouseCode::Left))

View File

@ -81,7 +81,7 @@ bool e2d::Music::open(const Resource& res)
return false;
}
if (res.isResource())
if (!res.isFile())
{
HRSRC hResInfo;
HGLOBAL hResData;

View File

@ -803,8 +803,8 @@ public:
const String& resType /* ×ÊÔ´ÀàÐÍ */
);
// 是否是资源类型
bool isResource() const;
// 是否是本地文件
bool isFile() const;
const String& getFileName() const;
@ -821,7 +821,7 @@ public:
bool operator<= (const Resource &) const;
protected:
bool _isResource;
bool _isFile;
size_t _resNameId;
String _resType;
String _fileName;