新增Config配置类
This commit is contained in:
parent
580278e869
commit
2c0f7c5178
|
|
@ -9,13 +9,15 @@ e2d::Game * e2d::Game::_instance = nullptr;
|
||||||
e2d::Game::Game()
|
e2d::Game::Game()
|
||||||
: _ended(false)
|
: _ended(false)
|
||||||
, _paused(false)
|
, _paused(false)
|
||||||
, _initialized(false)
|
, _config(nullptr)
|
||||||
{
|
{
|
||||||
CoInitialize(nullptr);
|
CoInitialize(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
e2d::Game::~Game()
|
e2d::Game::~Game()
|
||||||
{
|
{
|
||||||
|
GC::release(_config);
|
||||||
|
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -37,16 +39,10 @@ void e2d::Game::destroyInstance()
|
||||||
|
|
||||||
void e2d::Game::start(bool cleanup)
|
void e2d::Game::start(bool cleanup)
|
||||||
{
|
{
|
||||||
if (!_initialized)
|
|
||||||
{
|
|
||||||
throw Exception(L"开始游戏前未进行初始化");
|
|
||||||
}
|
|
||||||
|
|
||||||
auto gc = GC::getInstance();
|
auto gc = GC::getInstance();
|
||||||
auto input = Input::getInstance();
|
auto input = Input::getInstance();
|
||||||
auto window = Window::getInstance();
|
auto window = Window::getInstance();
|
||||||
auto renderer = Renderer::getInstance();
|
auto renderer = Renderer::getInstance();
|
||||||
|
|
||||||
|
|
||||||
// 初始化场景管理器
|
// 初始化场景管理器
|
||||||
SceneManager::__init();
|
SceneManager::__init();
|
||||||
|
|
@ -101,7 +97,7 @@ void e2d::Game::pause()
|
||||||
|
|
||||||
void e2d::Game::resume()
|
void e2d::Game::resume()
|
||||||
{
|
{
|
||||||
if (_initialized && _paused)
|
if (_paused)
|
||||||
{
|
{
|
||||||
Game::reset();
|
Game::reset();
|
||||||
}
|
}
|
||||||
|
|
@ -110,7 +106,7 @@ void e2d::Game::resume()
|
||||||
|
|
||||||
void e2d::Game::reset()
|
void e2d::Game::reset()
|
||||||
{
|
{
|
||||||
if (_initialized && !_ended)
|
if (!_ended)
|
||||||
{
|
{
|
||||||
Time::__reset();
|
Time::__reset();
|
||||||
ActionManager::__resetAll();
|
ActionManager::__resetAll();
|
||||||
|
|
@ -123,6 +119,23 @@ bool e2d::Game::isPaused()
|
||||||
return _paused;
|
return _paused;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void e2d::Game::setConfig(Config * config)
|
||||||
|
{
|
||||||
|
GC::release(_config);
|
||||||
|
_config = config;
|
||||||
|
GC::retain(_config);
|
||||||
|
}
|
||||||
|
|
||||||
|
e2d::Config * e2d::Game::getConfig()
|
||||||
|
{
|
||||||
|
if (!_config)
|
||||||
|
{
|
||||||
|
_config = Create<Config>();
|
||||||
|
GC::retain(_config);
|
||||||
|
}
|
||||||
|
return _config;
|
||||||
|
}
|
||||||
|
|
||||||
void e2d::Game::quit()
|
void e2d::Game::quit()
|
||||||
{
|
{
|
||||||
_ended = true; // 这个变量将控制游戏是否结束
|
_ended = true; // 这个变量将控制游戏是否结束
|
||||||
|
|
|
||||||
|
|
@ -156,7 +156,7 @@ HWND e2d::Window::__create()
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
// 禁用输入法
|
// 禁用输入法
|
||||||
this->setTypewritingEnable(false);
|
this->setTypewritingEnabled(false);
|
||||||
// 禁用控制台关闭按钮
|
// 禁用控制台关闭按钮
|
||||||
HWND consoleHWnd = ::GetConsoleWindow();
|
HWND consoleHWnd = ::GetConsoleWindow();
|
||||||
if (consoleHWnd)
|
if (consoleHWnd)
|
||||||
|
|
@ -336,11 +336,11 @@ void e2d::Window::showConsole(bool show)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::Window::setTypewritingEnable(bool enable)
|
void e2d::Window::setTypewritingEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
static HIMC hImc = nullptr;
|
static HIMC hImc = nullptr;
|
||||||
|
|
||||||
if (enable)
|
if (enabled)
|
||||||
{
|
{
|
||||||
if (hImc != nullptr)
|
if (hImc != nullptr)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ void e2d::CircleCollider::setCircle(Point center, double radius)
|
||||||
|
|
||||||
void e2d::CircleCollider::_resize()
|
void e2d::CircleCollider::_resize()
|
||||||
{
|
{
|
||||||
if (_parentNode && _enable)
|
if (_parentNode && _enabled)
|
||||||
{
|
{
|
||||||
double minSide = std::min(_parentNode->getRealWidth(), _parentNode->getRealHeight());
|
double minSide = std::min(_parentNode->getRealWidth(), _parentNode->getRealHeight());
|
||||||
this->setCircle(
|
this->setCircle(
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ e2d::Collider::Collider()
|
||||||
, _color(Color::Red, 0.7)
|
, _color(Color::Red, 0.7)
|
||||||
, _parentNode(nullptr)
|
, _parentNode(nullptr)
|
||||||
, _transformed(nullptr)
|
, _transformed(nullptr)
|
||||||
, _enable(true)
|
, _enabled(true)
|
||||||
, _autoResize(false)
|
, _autoResize(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -27,9 +27,9 @@ e2d::Color e2d::Collider::getColor() const
|
||||||
return _color;
|
return _color;
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::Collider::setEnable(bool enable)
|
void e2d::Collider::setEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
_enable = enable;
|
_enabled = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::Collider::setVisiable(bool bVisiable)
|
void e2d::Collider::setVisiable(bool bVisiable)
|
||||||
|
|
@ -42,14 +42,14 @@ void e2d::Collider::setColor(Color color)
|
||||||
_color = color;
|
_color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::Collider::setAutoResize(bool enable)
|
void e2d::Collider::setAutoResize(bool enabled)
|
||||||
{
|
{
|
||||||
_autoResize = enable;
|
_autoResize = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::Collider::_render()
|
void e2d::Collider::_render()
|
||||||
{
|
{
|
||||||
if (_transformed && _enable)
|
if (_transformed && _enabled)
|
||||||
{
|
{
|
||||||
auto renderer = Renderer::getInstance();
|
auto renderer = Renderer::getInstance();
|
||||||
// »ñÈ¡´¿É«»Ë¢
|
// »ñÈ¡´¿É«»Ë¢
|
||||||
|
|
@ -65,7 +65,7 @@ e2d::Collider::Relation e2d::Collider::getRelationWith(Collider * pCollider) con
|
||||||
{
|
{
|
||||||
if (_transformed && pCollider->_transformed)
|
if (_transformed && pCollider->_transformed)
|
||||||
{
|
{
|
||||||
if (_enable && pCollider->_enable)
|
if (_enabled && pCollider->_enabled)
|
||||||
{
|
{
|
||||||
D2D1_GEOMETRY_RELATION relation;
|
D2D1_GEOMETRY_RELATION relation;
|
||||||
|
|
||||||
|
|
@ -83,7 +83,7 @@ e2d::Collider::Relation e2d::Collider::getRelationWith(Collider * pCollider) con
|
||||||
|
|
||||||
void e2d::Collider::_transform()
|
void e2d::Collider::_transform()
|
||||||
{
|
{
|
||||||
if (_parentNode && _enable)
|
if (_parentNode && _enabled)
|
||||||
{
|
{
|
||||||
if (_autoResize)
|
if (_autoResize)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@
|
||||||
typedef std::pair<UINT, UINT> HashPair;
|
typedef std::pair<UINT, UINT> HashPair;
|
||||||
|
|
||||||
static std::vector<e2d::Listener*> s_vListeners; // 监听器容器
|
static std::vector<e2d::Listener*> s_vListeners; // 监听器容器
|
||||||
static bool s_bCollisionEnable = false; // 碰撞触发状态
|
|
||||||
static e2d::Node * s_pActiveNode = nullptr; // 主动碰撞体
|
static e2d::Node * s_pActiveNode = nullptr; // 主动碰撞体
|
||||||
static e2d::Node * s_pPassiveNode = nullptr; // 被动碰撞体
|
static e2d::Node * s_pPassiveNode = nullptr; // 被动碰撞体
|
||||||
static std::set<HashPair> s_sCollisionList; // 碰撞映射
|
static std::set<HashPair> s_sCollisionList; // 碰撞映射
|
||||||
|
|
@ -91,17 +90,6 @@ e2d::Node* e2d::Collision::isCausedBy(const String& name)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void e2d::Collision::setEnable(bool enable)
|
|
||||||
{
|
|
||||||
s_bCollisionEnable = enable;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool e2d::Collision::isEnable()
|
|
||||||
{
|
|
||||||
return s_bCollisionEnable;
|
|
||||||
}
|
|
||||||
|
|
||||||
void e2d::Collision::__update(Node * active, Node * passive)
|
void e2d::Collision::__update(Node * active, Node * passive)
|
||||||
{
|
{
|
||||||
if (s_vListeners.empty() || Game::getInstance()->isPaused())
|
if (s_vListeners.empty() || Game::getInstance()->isPaused())
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ void e2d::EllipseCollider::setEllipse(Point center, double radiusX, double radiu
|
||||||
|
|
||||||
void e2d::EllipseCollider::_resize()
|
void e2d::EllipseCollider::_resize()
|
||||||
{
|
{
|
||||||
if (_parentNode && _enable)
|
if (_parentNode && _enabled)
|
||||||
{
|
{
|
||||||
this->setEllipse(
|
this->setEllipse(
|
||||||
Point(
|
Point(
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ void e2d::RectCollider::setRect(double left, double top, double right, double bo
|
||||||
|
|
||||||
void e2d::RectCollider::_resize()
|
void e2d::RectCollider::_resize()
|
||||||
{
|
{
|
||||||
if (_parentNode && _enable)
|
if (_parentNode && _enabled)
|
||||||
{
|
{
|
||||||
this->setRect(0, 0, _parentNode->getRealWidth(), _parentNode->getRealHeight());
|
this->setRect(0, 0, _parentNode->getRealWidth(), _parentNode->getRealHeight());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
#include "..\e2dbase.h"
|
||||||
|
|
||||||
|
|
||||||
|
e2d::Config::Config()
|
||||||
|
: _gameName()
|
||||||
|
, _nodeDefPivot()
|
||||||
|
, _collisionEnabled(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
e2d::Config::~Config()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::Config::setGameName(const String & name)
|
||||||
|
{
|
||||||
|
_gameName = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::Config::setCollisionEnabled(bool enabled)
|
||||||
|
{
|
||||||
|
_collisionEnabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::Config::setNodeDefaultPivot(Point pivot)
|
||||||
|
{
|
||||||
|
_nodeDefPivot = Point(
|
||||||
|
std::min(std::max(pivot.x, 0.0), 1.0),
|
||||||
|
std::min(std::max(pivot.y, 0.0), 1.0)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
e2d::String e2d::Config::getGameName() const
|
||||||
|
{
|
||||||
|
return _gameName;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool e2d::Config::isCollisionEnabled() const
|
||||||
|
{
|
||||||
|
return _collisionEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
e2d::Point e2d::Config::getNodeDefaultPivot() const
|
||||||
|
{
|
||||||
|
return _nodeDefPivot;
|
||||||
|
}
|
||||||
|
|
@ -9,8 +9,8 @@ static std::vector<e2d::Collider*> s_vColliders;
|
||||||
|
|
||||||
void e2d::ColliderManager::__updateCollider(e2d::Collider * pActiveCollider)
|
void e2d::ColliderManager::__updateCollider(e2d::Collider * pActiveCollider)
|
||||||
{
|
{
|
||||||
// 判断碰撞触发是否打开
|
// 判断碰撞监听是否打开
|
||||||
if (!Collision::isEnable())
|
if (!Game::getInstance()->getConfig()->isCollisionEnabled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Node* pActiveNode = pActiveCollider->_parentNode;
|
Node* pActiveNode = pActiveCollider->_parentNode;
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
e2d::Button::Button()
|
e2d::Button::Button()
|
||||||
: _func(nullptr)
|
: _func(nullptr)
|
||||||
, _state(ButtonState::Normal)
|
, _state(ButtonState::Normal)
|
||||||
, _enable(true)
|
, _enabled(true)
|
||||||
, _isSelected(false)
|
, _isSelected(false)
|
||||||
, _normal(nullptr)
|
, _normal(nullptr)
|
||||||
, _mouseover(nullptr)
|
, _mouseover(nullptr)
|
||||||
|
|
@ -19,7 +19,7 @@ e2d::Button::Button()
|
||||||
e2d::Button::Button(Node * normal, const Function& func)
|
e2d::Button::Button(Node * normal, const Function& func)
|
||||||
: _func(nullptr)
|
: _func(nullptr)
|
||||||
, _state(ButtonState::Normal)
|
, _state(ButtonState::Normal)
|
||||||
, _enable(true)
|
, _enabled(true)
|
||||||
, _isSelected(false)
|
, _isSelected(false)
|
||||||
, _normal(nullptr)
|
, _normal(nullptr)
|
||||||
, _mouseover(nullptr)
|
, _mouseover(nullptr)
|
||||||
|
|
@ -33,7 +33,7 @@ e2d::Button::Button(Node * normal, const Function& func)
|
||||||
e2d::Button::Button(Node * normal, Node * selected, const Function& func)
|
e2d::Button::Button(Node * normal, Node * selected, const Function& func)
|
||||||
: _func(nullptr)
|
: _func(nullptr)
|
||||||
, _state(ButtonState::Normal)
|
, _state(ButtonState::Normal)
|
||||||
, _enable(true)
|
, _enabled(true)
|
||||||
, _isSelected(false)
|
, _isSelected(false)
|
||||||
, _normal(nullptr)
|
, _normal(nullptr)
|
||||||
, _mouseover(nullptr)
|
, _mouseover(nullptr)
|
||||||
|
|
@ -48,7 +48,7 @@ e2d::Button::Button(Node * normal, Node * selected, const Function& func)
|
||||||
e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, const Function& func)
|
e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, const Function& func)
|
||||||
: _func(nullptr)
|
: _func(nullptr)
|
||||||
, _state(ButtonState::Normal)
|
, _state(ButtonState::Normal)
|
||||||
, _enable(true)
|
, _enabled(true)
|
||||||
, _isSelected(false)
|
, _isSelected(false)
|
||||||
, _normal(nullptr)
|
, _normal(nullptr)
|
||||||
, _mouseover(nullptr)
|
, _mouseover(nullptr)
|
||||||
|
|
@ -64,7 +64,7 @@ e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, const Func
|
||||||
e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, Node * disabled, const Function& func)
|
e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, Node * disabled, const Function& func)
|
||||||
: _func(nullptr)
|
: _func(nullptr)
|
||||||
, _state(ButtonState::Normal)
|
, _state(ButtonState::Normal)
|
||||||
, _enable(true)
|
, _enabled(true)
|
||||||
, _isSelected(false)
|
, _isSelected(false)
|
||||||
, _normal(nullptr)
|
, _normal(nullptr)
|
||||||
, _mouseover(nullptr)
|
, _mouseover(nullptr)
|
||||||
|
|
@ -80,7 +80,7 @@ e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, Node * dis
|
||||||
|
|
||||||
bool e2d::Button::isEnable() const
|
bool e2d::Button::isEnable() const
|
||||||
{
|
{
|
||||||
return _enable;
|
return _enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::Button::setNormal(Node * normal)
|
void e2d::Button::setNormal(Node * normal)
|
||||||
|
|
@ -161,11 +161,11 @@ void e2d::Button::setDisabled(Node * disabled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::Button::setEnable(bool enable)
|
void e2d::Button::setEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
if (_enable != enable)
|
if (_enabled != enabled)
|
||||||
{
|
{
|
||||||
_enable = enable;
|
_enabled = enabled;
|
||||||
_updateVisiable();
|
_updateVisiable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -183,7 +183,7 @@ void e2d::Button::_fixedUpdate()
|
||||||
auto input = Input::getInstance();
|
auto input = Input::getInstance();
|
||||||
auto window = Window::getInstance();
|
auto window = Window::getInstance();
|
||||||
|
|
||||||
if (_enable && _visiable && _normal)
|
if (_enabled && _visiable && _normal)
|
||||||
{
|
{
|
||||||
if (input->isRelease(Input::Mouse::Left))
|
if (input->isRelease(Input::Mouse::Left))
|
||||||
{
|
{
|
||||||
|
|
@ -226,7 +226,7 @@ void e2d::Button::_fixedUpdate()
|
||||||
_setState(ButtonState::Normal);
|
_setState(ButtonState::Normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_visiable && !_enable && _normal && _normal->containsPoint(input->getMousePos()))
|
if (_visiable && !_enabled && _normal && _normal->containsPoint(input->getMousePos()))
|
||||||
{
|
{
|
||||||
window->setCursor(Window::Cursor::No);
|
window->setCursor(Window::Cursor::No);
|
||||||
}
|
}
|
||||||
|
|
@ -248,7 +248,7 @@ void e2d::Button::_updateVisiable()
|
||||||
SAFE_SET(_selected, setVisiable, false);
|
SAFE_SET(_selected, setVisiable, false);
|
||||||
SAFE_SET(_disabled, setVisiable, false);
|
SAFE_SET(_disabled, setVisiable, false);
|
||||||
|
|
||||||
if (_enable)
|
if (_enabled)
|
||||||
{
|
{
|
||||||
if (_state == ButtonState::Selected && _selected)
|
if (_state == ButtonState::Selected && _selected)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
#include "..\e2dnode.h"
|
#include "..\e2dnode.h"
|
||||||
|
|
||||||
e2d::Menu::Menu()
|
e2d::Menu::Menu()
|
||||||
: _enable(true)
|
: _enabled(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
e2d::Menu::Menu(const std::vector<Button*>& buttons)
|
e2d::Menu::Menu(const std::vector<Button*>& buttons)
|
||||||
: _enable(true)
|
: _enabled(true)
|
||||||
{
|
{
|
||||||
for (auto button : buttons)
|
for (auto button : buttons)
|
||||||
{
|
{
|
||||||
|
|
@ -16,7 +16,7 @@ e2d::Menu::Menu(const std::vector<Button*>& buttons)
|
||||||
|
|
||||||
bool e2d::Menu::isEnable() const
|
bool e2d::Menu::isEnable() const
|
||||||
{
|
{
|
||||||
return _enable;
|
return _enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t e2d::Menu::getButtonCount() const
|
size_t e2d::Menu::getButtonCount() const
|
||||||
|
|
@ -24,15 +24,15 @@ size_t e2d::Menu::getButtonCount() const
|
||||||
return _buttons.size();
|
return _buttons.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::Menu::setEnable(bool enable)
|
void e2d::Menu::setEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
if (_enable != enable)
|
if (_enabled != enabled)
|
||||||
{
|
{
|
||||||
_enable = enable;
|
_enabled = enabled;
|
||||||
|
|
||||||
for (auto button : _buttons)
|
for (auto button : _buttons)
|
||||||
{
|
{
|
||||||
button->setEnable(enable);
|
button->setEnabled(enabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -43,7 +43,7 @@ void e2d::Menu::addButton(Button * button)
|
||||||
{
|
{
|
||||||
this->addChild(button);
|
this->addChild(button);
|
||||||
_buttons.push_back(button);
|
_buttons.push_back(button);
|
||||||
button->setEnable(_enable);
|
button->setEnabled(_enabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,7 +64,7 @@ bool e2d::Menu::removeButton(Button * button)
|
||||||
if (_buttons[i] == button)
|
if (_buttons[i] == button)
|
||||||
{
|
{
|
||||||
// 移除按钮前,将它启用
|
// 移除按钮前,将它启用
|
||||||
button->setEnable(true);
|
button->setEnabled(true);
|
||||||
_buttons.erase(_buttons.begin() + i);
|
_buttons.erase(_buttons.begin() + i);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,6 @@
|
||||||
#include "..\e2daction.h"
|
#include "..\e2daction.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
// 默认中心点位置
|
|
||||||
static float s_fDefaultPiovtX = 0;
|
|
||||||
static float s_fDefaultPiovtY = 0;
|
|
||||||
static e2d::Collider::Type s_fDefaultColliderType = e2d::Collider::Type::None;
|
static e2d::Collider::Type s_fDefaultColliderType = e2d::Collider::Type::None;
|
||||||
|
|
||||||
e2d::Node::Node()
|
e2d::Node::Node()
|
||||||
|
|
@ -19,10 +16,10 @@ e2d::Node::Node()
|
||||||
, _rotation(0)
|
, _rotation(0)
|
||||||
, _skewAngleX(0)
|
, _skewAngleX(0)
|
||||||
, _skewAngleY(0)
|
, _skewAngleY(0)
|
||||||
, _displayOpacity(1.0f)
|
, _displayOpacity(1.f)
|
||||||
, _realOpacity(1.0f)
|
, _realOpacity(1.f)
|
||||||
, _pivotX(s_fDefaultPiovtX)
|
, _pivotX(0.f)
|
||||||
, _pivotY(s_fDefaultPiovtY)
|
, _pivotY(0.f)
|
||||||
, _initialMatri(D2D1::Matrix3x2F::Identity())
|
, _initialMatri(D2D1::Matrix3x2F::Identity())
|
||||||
, _finalMatri(D2D1::Matrix3x2F::Identity())
|
, _finalMatri(D2D1::Matrix3x2F::Identity())
|
||||||
, _visiable(true)
|
, _visiable(true)
|
||||||
|
|
@ -35,6 +32,10 @@ e2d::Node::Node()
|
||||||
, _autoUpdate(true)
|
, _autoUpdate(true)
|
||||||
, _positionFixed(false)
|
, _positionFixed(false)
|
||||||
{
|
{
|
||||||
|
Point defPivot = Game::getInstance()->getConfig()->getNodeDefaultPivot();
|
||||||
|
_pivotX = float(defPivot.x);
|
||||||
|
_pivotY = float(defPivot.y);
|
||||||
|
|
||||||
if (s_fDefaultColliderType != Collider::Type::None)
|
if (s_fDefaultColliderType != Collider::Type::None)
|
||||||
{
|
{
|
||||||
this->setCollider(s_fDefaultColliderType);
|
this->setCollider(s_fDefaultColliderType);
|
||||||
|
|
@ -911,12 +912,6 @@ void e2d::Node::setAutoUpdate(bool bAutoUpdate)
|
||||||
_autoUpdate = bAutoUpdate;
|
_autoUpdate = bAutoUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::Node::setDefaultPiovt(double defaultPiovtX, double defaultPiovtY)
|
|
||||||
{
|
|
||||||
s_fDefaultPiovtX = std::min(std::max(float(defaultPiovtX), 0.f), 1.f);
|
|
||||||
s_fDefaultPiovtY = std::min(std::max(float(defaultPiovtY), 0.f), 1.f);
|
|
||||||
}
|
|
||||||
|
|
||||||
void e2d::Node::setDefaultCollider(Collider::Type type)
|
void e2d::Node::setDefaultCollider(Collider::Type type)
|
||||||
{
|
{
|
||||||
s_fDefaultColliderType = type;
|
s_fDefaultColliderType = type;
|
||||||
|
|
|
||||||
|
|
@ -13,37 +13,6 @@ e2d::String e2d::Path::_dataPath;
|
||||||
std::list<e2d::String> e2d::Path::_paths;
|
std::list<e2d::String> e2d::Path::_paths;
|
||||||
|
|
||||||
|
|
||||||
void e2d::Path::setGameFolderName(const String & name)
|
|
||||||
{
|
|
||||||
if (name.isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
// 设置数据的默认保存路径
|
|
||||||
String localAppDataPath = Path::getLocalAppDataPath();
|
|
||||||
if (!localAppDataPath.isEmpty())
|
|
||||||
{
|
|
||||||
_dataPath = localAppDataPath + L"\\Easy2DGameData\\" << name << L"\\";
|
|
||||||
|
|
||||||
if (!Path::exists(_dataPath) && !Path::createFolder(_dataPath))
|
|
||||||
{
|
|
||||||
_dataPath = L"";
|
|
||||||
}
|
|
||||||
_dataPath << L"Data.ini";
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置临时文件保存路径
|
|
||||||
wchar_t path[_MAX_PATH];
|
|
||||||
if (0 != ::GetTempPath(_MAX_PATH, path))
|
|
||||||
{
|
|
||||||
_tempPath << path << L"\\Easy2DGameTemp\\" << name << L"\\";
|
|
||||||
|
|
||||||
if (!Path::exists(_tempPath) && !Path::createFolder(_tempPath))
|
|
||||||
{
|
|
||||||
_tempPath = L"";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void e2d::Path::addSearchPath(String path)
|
void e2d::Path::addSearchPath(String path)
|
||||||
{
|
{
|
||||||
path.replace(L"/", L"\\");
|
path.replace(L"/", L"\\");
|
||||||
|
|
@ -58,8 +27,45 @@ void e2d::Path::addSearchPath(String path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
e2d::String e2d::Path::getDataPath()
|
||||||
|
{
|
||||||
|
if (_dataPath.isEmpty())
|
||||||
|
{
|
||||||
|
// 设置数据的保存路径
|
||||||
|
String localAppDataPath = Path::getLocalAppDataPath();
|
||||||
|
String gameName = Game::getInstance()->getConfig()->getGameName();
|
||||||
|
if (!localAppDataPath.isEmpty() && !gameName.isEmpty())
|
||||||
|
{
|
||||||
|
_dataPath = localAppDataPath + L"\\Easy2DGameData\\" << gameName << L"\\";
|
||||||
|
|
||||||
|
if (!Path::exists(_dataPath) && !Path::createFolder(_dataPath))
|
||||||
|
{
|
||||||
|
_dataPath = L"";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_dataPath << L"Data.ini";
|
||||||
|
}
|
||||||
|
return _dataPath;
|
||||||
|
}
|
||||||
|
|
||||||
e2d::String e2d::Path::getTempPath()
|
e2d::String e2d::Path::getTempPath()
|
||||||
{
|
{
|
||||||
|
if (_tempPath.isEmpty())
|
||||||
|
{
|
||||||
|
// 设置临时文件保存路径
|
||||||
|
wchar_t path[_MAX_PATH];
|
||||||
|
String gameName = Game::getInstance()->getConfig()->getGameName();
|
||||||
|
|
||||||
|
if (0 != ::GetTempPath(_MAX_PATH, path) && !gameName.isEmpty())
|
||||||
|
{
|
||||||
|
_tempPath << path << L"\\Easy2DGameTemp\\" << gameName << L"\\";
|
||||||
|
|
||||||
|
if (!Path::exists(_tempPath) && !Path::createFolder(_tempPath))
|
||||||
|
{
|
||||||
|
_tempPath = L"";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return _tempPath;
|
return _tempPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -144,11 +150,6 @@ e2d::String e2d::Path::extractResource(int resNameId, const String & resType, co
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
e2d::String e2d::Path::getDataPath()
|
|
||||||
{
|
|
||||||
return _dataPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
e2d::String e2d::Path::getFileExtension(const String& filePath)
|
e2d::String e2d::Path::getFileExtension(const String& filePath)
|
||||||
{
|
{
|
||||||
String fileExtension;
|
String fileExtension;
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,14 @@ public:
|
||||||
// 游戏是否暂停
|
// 游戏是否暂停
|
||||||
bool isPaused();
|
bool isPaused();
|
||||||
|
|
||||||
|
// ÐÞ¸ÄÓÎÏ·ÅäÖÃ
|
||||||
|
void setConfig(
|
||||||
|
Config * config
|
||||||
|
);
|
||||||
|
|
||||||
|
// »ñÈ¡ÓÎÏ·ÅäÖÃ
|
||||||
|
Config * getConfig();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Game();
|
Game();
|
||||||
|
|
||||||
|
|
@ -53,7 +61,8 @@ private:
|
||||||
private:
|
private:
|
||||||
bool _ended;
|
bool _ended;
|
||||||
bool _paused;
|
bool _paused;
|
||||||
bool _initialized;
|
Config* _config;
|
||||||
|
|
||||||
static Game * _instance;
|
static Game * _instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -128,8 +137,8 @@ public:
|
||||||
);
|
);
|
||||||
|
|
||||||
// 是否允许响应输入法
|
// 是否允许响应输入法
|
||||||
void setTypewritingEnable(
|
void setTypewritingEnabled(
|
||||||
bool enable
|
bool enabled
|
||||||
);
|
);
|
||||||
|
|
||||||
// 弹出提示窗口
|
// 弹出提示窗口
|
||||||
|
|
|
||||||
|
|
@ -70,14 +70,6 @@ public:
|
||||||
Node * node
|
Node * node
|
||||||
);
|
);
|
||||||
|
|
||||||
// 开启或关闭物体碰撞监听功能(默认关闭)
|
|
||||||
static void setEnable(
|
|
||||||
bool enable
|
|
||||||
);
|
|
||||||
|
|
||||||
// 是否打开了物体碰撞监听
|
|
||||||
static bool isEnable();
|
|
||||||
|
|
||||||
// 添加碰撞监听
|
// 添加碰撞监听
|
||||||
static Listener * addListener(
|
static Listener * addListener(
|
||||||
const Function& func, /* 监听到碰撞时的执行函数 */
|
const Function& func, /* 监听到碰撞时的执行函数 */
|
||||||
|
|
@ -175,8 +167,8 @@ public:
|
||||||
Color getColor() const;
|
Color getColor() const;
|
||||||
|
|
||||||
// 启用或关闭该碰撞体
|
// 启用或关闭该碰撞体
|
||||||
virtual void setEnable(
|
virtual void setEnabled(
|
||||||
bool enable
|
bool enabled
|
||||||
);
|
);
|
||||||
|
|
||||||
// 设置碰撞体的可见性
|
// 设置碰撞体的可见性
|
||||||
|
|
@ -191,7 +183,7 @@ public:
|
||||||
|
|
||||||
// 设置大小跟随
|
// 设置大小跟随
|
||||||
void setAutoResize(
|
void setAutoResize(
|
||||||
bool enable
|
bool enabled
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取 ID2D1Geometry 对象
|
// 获取 ID2D1Geometry 对象
|
||||||
|
|
@ -208,7 +200,7 @@ protected:
|
||||||
virtual void _render();
|
virtual void _render();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool _enable;
|
bool _enabled;
|
||||||
bool _visiable;
|
bool _visiable;
|
||||||
bool _autoResize;
|
bool _autoResize;
|
||||||
Color _color;
|
Color _color;
|
||||||
|
|
|
||||||
|
|
@ -468,6 +468,46 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// 游戏配置
|
||||||
|
class Config :
|
||||||
|
public Object
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Config();
|
||||||
|
|
||||||
|
virtual ~Config();
|
||||||
|
|
||||||
|
// 修改游戏名称
|
||||||
|
void setGameName(
|
||||||
|
const String& name
|
||||||
|
);
|
||||||
|
|
||||||
|
// 打开或关闭碰撞监听(默认关闭)
|
||||||
|
void setCollisionEnabled(
|
||||||
|
bool enabled
|
||||||
|
);
|
||||||
|
|
||||||
|
// 设置节点的默认中心点位置
|
||||||
|
void setNodeDefaultPivot(
|
||||||
|
Point pivot
|
||||||
|
);
|
||||||
|
|
||||||
|
// 获取游戏名称
|
||||||
|
String getGameName() const;
|
||||||
|
|
||||||
|
// 获取碰撞监听状态
|
||||||
|
bool isCollisionEnabled() const;
|
||||||
|
|
||||||
|
// 获取节点的默认中心点位置
|
||||||
|
Point getNodeDefaultPivot() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
String _gameName;
|
||||||
|
Point _nodeDefPivot;
|
||||||
|
bool _collisionEnabled;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// ͼƬ
|
// ͼƬ
|
||||||
class Image :
|
class Image :
|
||||||
public Object
|
public Object
|
||||||
|
|
|
||||||
|
|
@ -385,13 +385,7 @@ public:
|
||||||
// 停止所有动作
|
// 停止所有动作
|
||||||
virtual void stopAllActions();
|
virtual void stopAllActions();
|
||||||
|
|
||||||
// 修改节点的默认中心点位置
|
// 设置节点的默认碰撞体类型(默认 None)
|
||||||
static void setDefaultPiovt(
|
|
||||||
double defaultPiovtX,
|
|
||||||
double defaultPiovtY
|
|
||||||
);
|
|
||||||
|
|
||||||
// 设置节点的默认碰撞体类型(默认无)
|
|
||||||
static void setDefaultCollider(
|
static void setDefaultCollider(
|
||||||
Collider::Type type
|
Collider::Type type
|
||||||
);
|
);
|
||||||
|
|
@ -775,8 +769,8 @@ public:
|
||||||
bool isEnable() const;
|
bool isEnable() const;
|
||||||
|
|
||||||
// 设置按钮启用或禁用
|
// 设置按钮启用或禁用
|
||||||
void setEnable(
|
void setEnabled(
|
||||||
bool enable
|
bool enabled
|
||||||
);
|
);
|
||||||
|
|
||||||
// 设置一般情况下显示的按钮
|
// 设置一般情况下显示的按钮
|
||||||
|
|
@ -825,7 +819,7 @@ protected:
|
||||||
Node * _mouseover;
|
Node * _mouseover;
|
||||||
Node * _selected;
|
Node * _selected;
|
||||||
Node * _disabled;
|
Node * _disabled;
|
||||||
bool _enable;
|
bool _enabled;
|
||||||
bool _isSelected;
|
bool _isSelected;
|
||||||
ButtonState _state;
|
ButtonState _state;
|
||||||
Function _func;
|
Function _func;
|
||||||
|
|
@ -955,8 +949,8 @@ public:
|
||||||
size_t getButtonCount() const;
|
size_t getButtonCount() const;
|
||||||
|
|
||||||
// 设置菜单启用或禁用
|
// 设置菜单启用或禁用
|
||||||
void setEnable(
|
void setEnabled(
|
||||||
bool enable
|
bool enabled
|
||||||
);
|
);
|
||||||
|
|
||||||
// 添加按钮
|
// 添加按钮
|
||||||
|
|
@ -973,7 +967,7 @@ public:
|
||||||
const std::vector<Button*>& getAllButtons() const;
|
const std::vector<Button*>& getAllButtons() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool _enable;
|
bool _enabled;
|
||||||
std::vector<Button*> _buttons;
|
std::vector<Button*> _buttons;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -454,11 +454,6 @@ class Path
|
||||||
friend class Game;
|
friend class Game;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// 设置游戏数据和临时文件保存路径名称
|
|
||||||
static void setGameFolderName(
|
|
||||||
const String& name
|
|
||||||
);
|
|
||||||
|
|
||||||
// Ìí¼Ó×ÊÔ´ËÑË÷·¾¶
|
// Ìí¼Ó×ÊÔ´ËÑË÷·¾¶
|
||||||
static void addSearchPath(
|
static void addSearchPath(
|
||||||
String path
|
String path
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,7 @@
|
||||||
<ClCompile Include="..\..\core\Collider\EllipseCollider.cpp" />
|
<ClCompile Include="..\..\core\Collider\EllipseCollider.cpp" />
|
||||||
<ClCompile Include="..\..\core\Collider\RectCollider.cpp" />
|
<ClCompile Include="..\..\core\Collider\RectCollider.cpp" />
|
||||||
<ClCompile Include="..\..\core\Common\Color.cpp" />
|
<ClCompile Include="..\..\core\Common\Color.cpp" />
|
||||||
|
<ClCompile Include="..\..\core\Common\Config.cpp" />
|
||||||
<ClCompile Include="..\..\core\Common\Font.cpp" />
|
<ClCompile Include="..\..\core\Common\Font.cpp" />
|
||||||
<ClCompile Include="..\..\core\Common\Function.cpp" />
|
<ClCompile Include="..\..\core\Common\Function.cpp" />
|
||||||
<ClCompile Include="..\..\core\Common\Image.cpp" />
|
<ClCompile Include="..\..\core\Common\Image.cpp" />
|
||||||
|
|
|
||||||
|
|
@ -140,6 +140,9 @@
|
||||||
<ClCompile Include="..\..\core\Common\Color.cpp">
|
<ClCompile Include="..\..\core\Common\Color.cpp">
|
||||||
<Filter>Common</Filter>
|
<Filter>Common</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\core\Common\Config.cpp">
|
||||||
|
<Filter>Common</Filter>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\core\Common\Font.cpp">
|
<ClCompile Include="..\..\core\Common\Font.cpp">
|
||||||
<Filter>Common</Filter>
|
<Filter>Common</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|
|
||||||
|
|
@ -208,6 +208,7 @@
|
||||||
<ClCompile Include="..\..\core\Collider\EllipseCollider.cpp" />
|
<ClCompile Include="..\..\core\Collider\EllipseCollider.cpp" />
|
||||||
<ClCompile Include="..\..\core\Collider\RectCollider.cpp" />
|
<ClCompile Include="..\..\core\Collider\RectCollider.cpp" />
|
||||||
<ClCompile Include="..\..\core\Common\Color.cpp" />
|
<ClCompile Include="..\..\core\Common\Color.cpp" />
|
||||||
|
<ClCompile Include="..\..\core\Common\Config.cpp" />
|
||||||
<ClCompile Include="..\..\core\Common\Font.cpp" />
|
<ClCompile Include="..\..\core\Common\Font.cpp" />
|
||||||
<ClCompile Include="..\..\core\Common\Function.cpp" />
|
<ClCompile Include="..\..\core\Common\Function.cpp" />
|
||||||
<ClCompile Include="..\..\core\Common\Image.cpp" />
|
<ClCompile Include="..\..\core\Common\Image.cpp" />
|
||||||
|
|
|
||||||
|
|
@ -140,6 +140,9 @@
|
||||||
<ClCompile Include="..\..\core\Common\Color.cpp">
|
<ClCompile Include="..\..\core\Common\Color.cpp">
|
||||||
<Filter>Common</Filter>
|
<Filter>Common</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\core\Common\Config.cpp">
|
||||||
|
<Filter>Common</Filter>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\core\Common\Font.cpp">
|
<ClCompile Include="..\..\core\Common\Font.cpp">
|
||||||
<Filter>Common</Filter>
|
<Filter>Common</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|
|
||||||
|
|
@ -227,6 +227,7 @@
|
||||||
<ClCompile Include="..\..\core\Collider\RectCollider.cpp" />
|
<ClCompile Include="..\..\core\Collider\RectCollider.cpp" />
|
||||||
<ClCompile Include="..\..\core\Collider\Collision.cpp" />
|
<ClCompile Include="..\..\core\Collider\Collision.cpp" />
|
||||||
<ClCompile Include="..\..\core\Common\Color.cpp" />
|
<ClCompile Include="..\..\core\Common\Color.cpp" />
|
||||||
|
<ClCompile Include="..\..\core\Common\Config.cpp" />
|
||||||
<ClCompile Include="..\..\core\Common\Font.cpp" />
|
<ClCompile Include="..\..\core\Common\Font.cpp" />
|
||||||
<ClCompile Include="..\..\core\Common\Function.cpp" />
|
<ClCompile Include="..\..\core\Common\Function.cpp" />
|
||||||
<ClCompile Include="..\..\core\Common\Object.cpp" />
|
<ClCompile Include="..\..\core\Common\Object.cpp" />
|
||||||
|
|
|
||||||
|
|
@ -243,6 +243,9 @@
|
||||||
<ClCompile Include="..\..\core\Custom\SystemException.cpp">
|
<ClCompile Include="..\..\core\Custom\SystemException.cpp">
|
||||||
<Filter>Custom</Filter>
|
<Filter>Custom</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\core\Common\Config.cpp">
|
||||||
|
<Filter>Common</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\core\easy2d.h" />
|
<ClInclude Include="..\..\core\easy2d.h" />
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue