Window类增加弹窗功能;修复Action重置时间处的Bug

This commit is contained in:
Nomango 2018-05-10 18:18:02 +08:00
parent 77d064a0c4
commit b5e6650566
11 changed files with 144 additions and 43 deletions

View File

@ -15,18 +15,6 @@ e2d::Action::~Action()
{
}
bool e2d::Action::_isDone()
{
return _done;
}
void e2d::Action::_startWithTarget(Node* target)
{
_target = target;
_running = true;
this->reset();
}
bool e2d::Action::isRunning()
{
return _running;
@ -74,10 +62,28 @@ void e2d::Action::onDestroy()
ActionManager::__remove(this);
}
void e2d::Action::reset()
{
_initialized = false;
_done = false;
_last = Time::getTotalTime();
}
bool e2d::Action::_isDone()
{
return _done;
}
void e2d::Action::_startWithTarget(Node* target)
{
_target = target;
_running = true;
this->reset();
}
void e2d::Action::_init()
{
_initialized = true;
// 记录当前时间
_last = Time::getTotalTime();
}
@ -89,14 +95,6 @@ void e2d::Action::_update()
}
}
void e2d::Action::reset()
{
_initialized = false;
_done = false;
_last = Time::getTotalTime();
}
void e2d::Action::_resetTime()
{
_last = Time::getTotalTime();
}

View File

@ -2,8 +2,14 @@
e2d::ActionGradual::ActionGradual(double duration)
: _delta(0)
, _duration(max(duration, 0))
{
_duration = max(duration, 0);
}
void e2d::ActionGradual::reset()
{
Action::reset();
_delta = 0;
}
void e2d::ActionGradual::_init()
@ -19,13 +25,20 @@ void e2d::ActionGradual::_update()
{
_delta = 1;
this->stop();
return;
}
_delta = min((Time::getTotalTime() - _last) / _duration, 1);
if (_delta >= 1)
else
{
this->stop();
_delta = min((Time::getTotalTime() - _last) / _duration, 1);
if (_delta >= 1)
{
this->stop();
}
}
}
void e2d::ActionGradual::_resetTime()
{
Action::_resetTime();
_last = Time::getTotalTime() - _delta * _duration;
}

View File

@ -64,8 +64,8 @@ void e2d::Animate::_update()
target->open(frames[_frameIndex]);
}
_last += _animation->getInterval();
_frameIndex++;
_last += _animation->getInterval();
if (_frameIndex == frames.size())
{
@ -75,6 +75,12 @@ void e2d::Animate::_update()
}
}
void e2d::Animate::_resetTime()
{
Action::_resetTime();
_last = Time::getTotalTime();
}
void e2d::Animate::reset()
{
Action::reset();

View File

@ -1,8 +1,9 @@
#include "..\e2daction.h"
e2d::Delay::Delay(double duration)
: _delta(0)
, _delay(max(duration, 0))
{
_delay = max(duration, 0);
}
e2d::Delay * e2d::Delay::clone() const
@ -10,6 +11,12 @@ e2d::Delay * e2d::Delay::clone() const
return new (std::nothrow) Delay(_delay);
}
void e2d::Delay::reset()
{
Action::reset();
_delta = 0;
}
void e2d::Delay::_init()
{
Action::_init();
@ -19,8 +26,16 @@ void e2d::Delay::_update()
{
Action::_update();
if ((Time::getTotalTime() - _last) >= _delay)
_delta = Time::getTotalTime() - _last;
if (_delta >= _delay)
{
this->stop();
}
}
void e2d::Delay::_resetTime()
{
Action::_resetTime();
_last = Time::getTotalTime() - _delta;
}

View File

@ -149,17 +149,22 @@ void e2d::Game::pause()
void e2d::Game::resume()
{
if (isPaused())
if (s_bInitialized && s_bPaused)
{
s_bPaused = false;
// 刷新当前时间
Time::__updateLast();
// 重置动作和定时器
ActionManager::__resetAll();
Timer::__resetAll();
Game::reset();
}
}
void e2d::Game::reset()
{
// 刷新当前时间
Time::__reset();
// 重置动作和定时器
ActionManager::__resetAll();
Timer::__resetAll();
}
bool e2d::Game::isPaused()
{
return s_bPaused;

View File

@ -55,8 +55,7 @@ bool Input::__init()
}
else
{
MessageBox(nullptr, L"Keyboard not found!", L"Error", MB_ICONERROR | MB_OK);
Game::quit();
Window::error(L"Keyboard not found!");
return false;
}
}
@ -75,7 +74,7 @@ bool Input::__init()
}
else
{
MessageBox(nullptr, L"Mouse not found!", L"Error", MB_ICONERROR | MB_OK);
Window::error(L"Mouse not found!");
return false;
}
}

View File

@ -73,6 +73,13 @@ void e2d::Time::__updateLast()
s_nTotalTime = static_cast<unsigned int>(duration_cast<milliseconds>(s_tNow - s_tStart).count());
}
void e2d::Time::__reset()
{
s_tLastUpdate = s_tFixedUpdate = s_tNow = steady_clock::now();
s_nInterval = 0;
s_nTotalTime = static_cast<unsigned int>(duration_cast<milliseconds>(s_tNow - s_tStart).count());
}
void e2d::Time::__sleep()
{
// 计算挂起时长

View File

@ -80,7 +80,7 @@ bool e2d::Window::__init()
if (FAILED(hr))
{
::MessageBox(nullptr, L"Create Window Failed!", L"Error", MB_OK);
Window::error(L"Create Window Failed!");
}
return SUCCEEDED(hr);
@ -257,7 +257,7 @@ void e2d::Window::showConsole(bool show)
}
else
{
MessageBox(nullptr, L"Alloc Console Failed!", L"Error", MB_OK);
Window::error(L"Alloc Console Failed!");
}
}
}
@ -291,6 +291,24 @@ void e2d::Window::setTypewritingEnable(bool enable)
}
}
void e2d::Window::prompt(const String & text, const String & title)
{
::MessageBox(s_HWnd, text, title, MB_ICONINFORMATION | MB_OK);
Game::reset();
}
void e2d::Window::warning(const String& title, const String& text)
{
::MessageBox(s_HWnd, text, title, MB_ICONWARNING | MB_OK);
Game::reset();
}
void e2d::Window::error(const String & text, const String & title)
{
::MessageBox(s_HWnd, text, title, MB_ICONERROR | MB_OK);
Game::reset();
}
LRESULT e2d::Window::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{

View File

@ -98,6 +98,9 @@ public:
double duration
);
// 重置动作
virtual void reset() override;
protected:
// 初始化动作
virtual void _init() override;
@ -105,6 +108,9 @@ protected:
// 更新动作
virtual void _update() override;
// 重置动作时间
virtual void _resetTime() override;
protected:
double _duration;
double _delta;
@ -443,6 +449,9 @@ public:
// 获取该动作的拷贝对象
virtual Delay * clone() const override;
// 重置动作
virtual void reset() override;
protected:
// 初始化动作
virtual void _init() override;
@ -450,8 +459,12 @@ protected:
// 更新动作
virtual void _update() override;
// 重置动作时间
virtual void _resetTime() override;
protected:
double _delay;
double _delta;
};
@ -666,6 +679,9 @@ protected:
// 更新动作
virtual void _update() override;
// 重置动作时间
virtual void _resetTime() override;
protected:
UINT _frameIndex;
Animation * _animation;

View File

@ -34,6 +34,9 @@ public:
// 回收游戏资源
static void destroy();
// 重置游戏内部计时
static void reset();
// 游戏是否暂停
static bool isPaused();
@ -100,6 +103,24 @@ public:
bool enable
);
// 弹出提示窗口
static void prompt(
const String& text, /* 内容 */
const String& title = L"Prompt" /* 窗口标题 */
);
// 弹出警告窗口
static void warning(
const String& text, /* 内容 */
const String& title = L"Warning" /* 窗口标题 */
);
// 弹出错误窗口
static void error(
const String& text, /* 内容 */
const String& title = L"Error" /* 窗口标题 */
);
private:
// 初始化窗口
static bool __init();
@ -149,6 +170,9 @@ private:
// 更新时间信息
static void __updateLast();
// 重置时间信息
static void __reset();
// 挂起线程
static void __sleep();
};

View File

@ -101,7 +101,7 @@
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>false</SDLCheck>
<DebugInformationFormat>None</DebugInformationFormat>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<MinimalRebuild>false</MinimalRebuild>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>