修改弹窗函数

This commit is contained in:
Nomango 2018-07-17 00:35:27 +08:00
parent 767a5da6c1
commit 02bb68f21f
4 changed files with 40 additions and 37 deletions

View File

@ -102,8 +102,6 @@ void e2d::Game::resume()
if (_paused && !_ended) if (_paused && !_ended)
{ {
Time::__reset(); Time::__reset();
Timer::getInstance()->updateTime();
ActionManager::getInstance()->updateTime();
} }
_paused = false; _paused = false;
} }

View File

@ -1,4 +1,6 @@
#include "..\e2dbase.h" #include "..\e2dbase.h"
#include "..\e2dtool.h"
#include "..\e2dmanager.h"
#include <thread> #include <thread>
using namespace std::chrono; using namespace std::chrono;
@ -40,7 +42,6 @@ bool e2d::Time::__isReady()
void e2d::Time::__updateNow() void e2d::Time::__updateNow()
{ {
// 刷新时间
_now = steady_clock::now(); _now = steady_clock::now();
} }
@ -55,6 +56,8 @@ void e2d::Time::__updateLast()
void e2d::Time::__reset() void e2d::Time::__reset()
{ {
_last = _fixedLast = _now = steady_clock::now(); _last = _fixedLast = _now = steady_clock::now();
Timer::getInstance()->updateTime();
ActionManager::getInstance()->updateTime();
} }
void e2d::Time::__sleep() void e2d::Time::__sleep()

View File

@ -319,10 +319,6 @@ void e2d::Window::setConsoleEnabled(bool enabled)
HMENU hmenu = ::GetSystemMenu(hwnd, FALSE); HMENU hmenu = ::GetSystemMenu(hwnd, FALSE);
::RemoveMenu(hmenu, SC_CLOSE, MF_BYCOMMAND); ::RemoveMenu(hmenu, SC_CLOSE, MF_BYCOMMAND);
} }
else
{
this->error(L"Alloc Console Failed!");
}
} }
} }
else else
@ -355,25 +351,33 @@ void e2d::Window::setTypewritingEnabled(bool enabled)
} }
} }
void e2d::Window::info(const String & text, const String & title) bool e2d::Window::popup(const String & text, const String & title, PopupStyle style, bool hasCancel)
{ {
Game::getInstance()->pause(); UINT type = 0;
::MessageBox(_hWnd, (LPCWSTR)text, (LPCWSTR)title, MB_ICONINFORMATION | MB_OK); switch (style)
Game::getInstance()->resume(); {
case e2d::Window::PopupStyle::Information:
type = MB_ICONINFORMATION;
break;
case e2d::Window::PopupStyle::Warning:
type = MB_ICONWARNING;
break;
case e2d::Window::PopupStyle::Error:
type = MB_ICONERROR;
break;
default:
break;
} }
void e2d::Window::warning(const String& title, const String& text) if (hasCancel)
{ {
Game::getInstance()->pause(); type |= MB_OKCANCEL;
::MessageBox(_hWnd, (LPCWSTR)text, (LPCWSTR)title, MB_ICONWARNING | MB_OK);
Game::getInstance()->resume();
} }
void e2d::Window::error(const String & text, const String & title)
{
Game::getInstance()->pause(); Game::getInstance()->pause();
::MessageBox(_hWnd, (LPCWSTR)text, (LPCWSTR)title, MB_ICONERROR | MB_OK); int ret = ::MessageBox(_hWnd, (LPCWSTR)text, (LPCWSTR)title, type);
Game::getInstance()->resume(); Game::getInstance()->resume();
return ret == IDOK;
} }

View File

@ -78,6 +78,14 @@ public:
ArrowWait /* 默认指针和小沙漏 */ ArrowWait /* 默认指针和小沙漏 */
}; };
// 弹窗样式
enum class PopupStyle : int
{
Information, /* 信息 */
Warning, /* 警告 */
Error /* 错误 */
};
public: public:
// 获取窗体实例 // 获取窗体实例
static Window * getInstance(); static Window * getInstance();
@ -136,22 +144,12 @@ public:
bool enabled bool enabled
); );
// 弹出提示窗口 // 弹窗
void info( bool popup(
const String& text, /* 内容 */ const String& text, /* 窗口内容 */
const String& title = L"Infomation" /* 窗口标题 */ const String& title, /* 窗口标题 */
); PopupStyle style = PopupStyle::Information, /* 弹窗样式 */
bool hasCancel = false /* 包含取消按钮 */
// 弹出警告窗口
void warning(
const String& text, /* 内容 */
const String& title = L"Warning" /* 窗口标题 */
);
// 弹出错误窗口
void error(
const String& text, /* 内容 */
const String& title = L"Error" /* 窗口标题 */
); );
// 处理窗体消息 // 处理窗体消息