mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-05-17 10:43:23 +02:00
Now UserManagers have a register_as_global property. A manager will only try to set itself as the global manager if it's set to true (default).
This commit is contained in:
parent
4016579f23
commit
a2309aa272
@ -36,6 +36,13 @@
|
||||
#include "../singleton/user_db.h"
|
||||
#include "../users/user.h"
|
||||
|
||||
bool UserManager::get_register_as_global() const {
|
||||
return _register_as_global;
|
||||
}
|
||||
void UserManager::set_register_as_global(const bool p_global) {
|
||||
_register_as_global = p_global;
|
||||
}
|
||||
|
||||
Ref<User> UserManager::get_user(const int id) {
|
||||
return call("_get_user", id);
|
||||
}
|
||||
@ -106,20 +113,32 @@ Array UserManager::_get_all_users() {
|
||||
}
|
||||
|
||||
UserManager::UserManager() {
|
||||
_register_as_global = true;
|
||||
}
|
||||
|
||||
UserManager::~UserManager() {
|
||||
}
|
||||
|
||||
void UserManager::_notification(int p_what) {
|
||||
if (p_what == NOTIFICATION_POST_ENTER_TREE) {
|
||||
if (!Engine::get_singleton()->is_editor_hint()) {
|
||||
UserDB::get_singleton()->set_user_manager(this);
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_POST_ENTER_TREE: {
|
||||
if (_register_as_global && !Engine::get_singleton()->is_editor_hint()) {
|
||||
UserDB::get_singleton()->set_user_manager(this);
|
||||
}
|
||||
}
|
||||
case NOTIFICATION_EXIT_TREE: {
|
||||
if (_register_as_global && !Engine::get_singleton()->is_editor_hint()) {
|
||||
UserDB::get_singleton()->unset_user_manager(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UserManager::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_register_as_global"), &UserManager::get_register_as_global);
|
||||
ClassDB::bind_method(D_METHOD("set_register_as_global", "global"), &UserManager::set_register_as_global);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "register_as_global"), "set_register_as_global", "get_register_as_global");
|
||||
|
||||
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "ret", PROPERTY_HINT_RESOURCE_TYPE, "User"), "_get_user", PropertyInfo(Variant::INT, "id")));
|
||||
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "ret", PROPERTY_HINT_RESOURCE_TYPE, "User"), "_get_user_name", PropertyInfo(Variant::STRING, "user_name")));
|
||||
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "ret", PROPERTY_HINT_RESOURCE_TYPE, "User"), "_get_user_email", PropertyInfo(Variant::STRING, "user_email")));
|
||||
|
@ -44,6 +44,9 @@ class UserManager : public Node {
|
||||
GDCLASS(UserManager, Node);
|
||||
|
||||
public:
|
||||
bool get_register_as_global() const;
|
||||
void set_register_as_global(const bool p_global);
|
||||
|
||||
Ref<User> get_user(const int id);
|
||||
Ref<User> get_user_name(const String &user_name);
|
||||
Ref<User> get_user_email(const String &user_email);
|
||||
@ -78,6 +81,8 @@ protected:
|
||||
void _notification(int p_what);
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
bool _register_as_global;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -84,6 +84,11 @@ UserManager *UserDB::get_user_manager() {
|
||||
void UserDB::set_user_manager(UserManager *um) {
|
||||
_user_manager = um;
|
||||
}
|
||||
void UserDB::unset_user_manager(UserManager *um) {
|
||||
if (_user_manager == um) {
|
||||
_user_manager = NULL;
|
||||
}
|
||||
}
|
||||
Node *UserDB::get_user_manager_bind() {
|
||||
return _user_manager;
|
||||
}
|
||||
|
@ -71,6 +71,7 @@ public:
|
||||
|
||||
UserManager *get_user_manager();
|
||||
void set_user_manager(UserManager *um);
|
||||
void unset_user_manager(UserManager *um);
|
||||
|
||||
static UserDB *get_singleton();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user