feat: adapted to GMLIB version and remove some shit
This commit is contained in:
+56
-104
@@ -1,28 +1,23 @@
|
||||
#include "Global.h"
|
||||
|
||||
using namespace GMLIB::Server::Form;
|
||||
using namespace ll::hash_utils;
|
||||
|
||||
class LegacyScriptFormManager {
|
||||
private:
|
||||
int64 mNextFormCallbackId = 0;
|
||||
// std::unordered_map<int64, ll::event::ListenerPtr> mEventListeners;
|
||||
// class LegacyScriptFormManager {
|
||||
// private:
|
||||
// int64 mNextFormCallbackId = 0;
|
||||
|
||||
public:
|
||||
std::string getNextFormCallbackId() {
|
||||
mNextFormCallbackId++;
|
||||
return "GMLIB_EVENT_" + std::to_string(mNextFormCallbackId);
|
||||
}
|
||||
// public:
|
||||
// std::string getNextFormCallbackId() {
|
||||
// return "GMLIB_FormApi_" + std::to_string(mNextFormCallbackId++);
|
||||
// }
|
||||
|
||||
public:
|
||||
static LegacyScriptFormManager& getInstance() {
|
||||
static std::unique_ptr<LegacyScriptFormManager> instance;
|
||||
if (!instance) {
|
||||
instance = std::make_unique<LegacyScriptFormManager>();
|
||||
}
|
||||
return *instance;
|
||||
}
|
||||
};
|
||||
// public:
|
||||
// static LegacyScriptFormManager& getInstance() {
|
||||
// static std::unique_ptr<LegacyScriptFormManager> instance;
|
||||
// if (!instance) instance = std::make_unique<LegacyScriptFormManager>();
|
||||
// return *instance;
|
||||
// }
|
||||
// };
|
||||
|
||||
#define PLAYER_DETECROR \
|
||||
[detectorId, result](Player& pl) -> bool { \
|
||||
@@ -31,107 +26,64 @@ public:
|
||||
auto const& detector = RemoteCall::importAs<bool(Player*)>("GMLIB_FORM_CALLBACK", detectorId); \
|
||||
return detector(&pl); \
|
||||
} else { \
|
||||
ServerSettingForm::removeElement(result); \
|
||||
gmlib::form::ServerSettingForm::removeElement(result); \
|
||||
} \
|
||||
} catch (...) {} \
|
||||
return false; \
|
||||
}
|
||||
|
||||
#define CALLBACK_TYPE_STRING \
|
||||
[callbackId, result](Player& pl, std::string const& data) { \
|
||||
#define CALLBACK_TYPE(type) \
|
||||
[callbackId, result](Player& pl, type data) { \
|
||||
try { \
|
||||
if (RemoteCall::hasFunc("GMLIB_FORM_CALLBACK", callbackId)) { \
|
||||
auto const& callback = \
|
||||
RemoteCall::importAs<void(Player*, std::string const&)>("GMLIB_FORM_CALLBACK", callbackId); \
|
||||
auto const& callback = RemoteCall::importAs<void(Player*, type)>("GMLIB_FORM_CALLBACK", callbackId); \
|
||||
callback(&pl, data); \
|
||||
} else { \
|
||||
ServerSettingForm::removeElement(result); \
|
||||
gmlib::form::ServerSettingForm::removeElement(result); \
|
||||
} \
|
||||
} catch (...) {} \
|
||||
}
|
||||
|
||||
#define CALLBACK_TYPE_BOOL \
|
||||
[callbackId, result](Player& pl, bool data) { \
|
||||
try { \
|
||||
if (RemoteCall::hasFunc("GMLIB_FORM_CALLBACK", callbackId)) { \
|
||||
auto const& callback = RemoteCall::importAs<void(Player*, bool)>("GMLIB_FORM_CALLBACK", callbackId); \
|
||||
callback(&pl, data); \
|
||||
} else { \
|
||||
ServerSettingForm::removeElement(result); \
|
||||
} \
|
||||
} catch (...) {} \
|
||||
}
|
||||
|
||||
#define CALLBACK_TYPE_DOUBLE \
|
||||
[callbackId, result](Player& pl, double data) { \
|
||||
try { \
|
||||
if (RemoteCall::hasFunc("GMLIB_FORM_CALLBACK", callbackId)) { \
|
||||
auto const& callback = RemoteCall::importAs<void(Player*, double)>("GMLIB_FORM_CALLBACK", callbackId); \
|
||||
callback(&pl, data); \
|
||||
} else { \
|
||||
ServerSettingForm::removeElement(result); \
|
||||
} \
|
||||
} catch (...) {} \
|
||||
}
|
||||
|
||||
|
||||
#define CALLBACK_TYPE_LONG \
|
||||
[callbackId, result](Player& pl, int64 data) { \
|
||||
try { \
|
||||
if (RemoteCall::hasFunc("GMLIB_FORM_CALLBACK", callbackId)) { \
|
||||
auto const& callback = RemoteCall::importAs<void(Player*, int64)>("GMLIB_FORM_CALLBACK", callbackId); \
|
||||
callback(&pl, data); \
|
||||
} else { \
|
||||
ServerSettingForm::removeElement(result); \
|
||||
} \
|
||||
} catch (...) {} \
|
||||
}
|
||||
|
||||
|
||||
void Export_Form_API() {
|
||||
RemoteCall::exportAs("GMLIB_ServerSettingForm", "getDefaultPriority", []() -> int {
|
||||
return ServerSettingForm::getDefaultPriority();
|
||||
RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "getDefaultPriority", []() -> int {
|
||||
return gmlib::form::ServerSettingForm::getDefaultPriority();
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_FormAPI", "getNextFormCallbackId", []() -> std::string {
|
||||
return LegacyScriptFormManager::getInstance().getNextFormCallbackId();
|
||||
// RemoteCall::exportAs("GMLIB_FormAPI", "getNextFormCallbackId", []() -> std::string {
|
||||
// return LegacyScriptFormManager::getInstance().getNextFormCallbackId();
|
||||
// });
|
||||
RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "hasTitle", []() -> bool { return gmlib::form::ServerSettingForm::hasTitle(); });
|
||||
RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "getTitle", []() -> std::string {
|
||||
return gmlib::form::ServerSettingForm::getTitle();
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_ServerSettingForm", "hasTitle", []() -> bool { return ServerSettingForm::hasTitle(); });
|
||||
RemoteCall::exportAs("GMLIB_ServerSettingForm", "getTitle", []() -> std::string {
|
||||
return ServerSettingForm::getTitle();
|
||||
RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "setTitle", [](std::string const& title, bool forceModify) -> bool {
|
||||
return gmlib::form::ServerSettingForm::setTitle(title, forceModify);
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_ServerSettingForm", "setTitle", [](std::string const& title, bool forceModify) -> bool {
|
||||
return ServerSettingForm::setTitle(title, forceModify);
|
||||
RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "hasIcon", []() -> bool { return gmlib::form::ServerSettingForm::hasIcon(); });
|
||||
RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "getIconData", []() -> std::string {
|
||||
return gmlib::form::ServerSettingForm::getIconData().value_or("");
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_ServerSettingForm", "hasIcon", []() -> bool { return ServerSettingForm::hasIcon(); });
|
||||
RemoteCall::exportAs("GMLIB_ServerSettingForm", "getIconData", []() -> std::string {
|
||||
if (auto data = ServerSettingForm::getIconData()) {
|
||||
return data.value();
|
||||
}
|
||||
return "";
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_ServerSettingForm", "getIconType", []() -> int {
|
||||
if (auto type = ServerSettingForm::getIconType()) {
|
||||
return (int)type.value();
|
||||
}
|
||||
return -1;
|
||||
RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "getIconType", []() -> int {
|
||||
return gmlib::form::ServerSettingForm::getIconType()
|
||||
.transform([](gmlib::form::IconType&& type) -> int { return (int)type; })
|
||||
.value_or(-1);
|
||||
});
|
||||
RemoteCall::exportAs(
|
||||
"GMLIB_ServerSettingForm",
|
||||
"GMLIB_gmlib::form::ServerSettingForm",
|
||||
"setIcon",
|
||||
[](std::string const& title, uchar type, bool forceModify) -> bool {
|
||||
return ServerSettingForm::setIcon(title, IconType(type), forceModify);
|
||||
return gmlib::form::ServerSettingForm::setIcon(title, gmlib::form::IconType(type), forceModify);
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
"GMLIB_ServerSettingForm",
|
||||
"GMLIB_gmlib::form::ServerSettingForm",
|
||||
"addLabel",
|
||||
[](std::string const& text, std::string const& detectorId, int priority) -> uint {
|
||||
uint result = ServerSettingForm::addLabel(text, PLAYER_DETECROR, priority);
|
||||
uint result = gmlib::form::ServerSettingForm::addLabel(text, PLAYER_DETECROR, priority);
|
||||
return result;
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
"GMLIB_ServerSettingForm",
|
||||
"GMLIB_gmlib::form::ServerSettingForm",
|
||||
"addInput",
|
||||
[](std::string const& text,
|
||||
std::string const& placeholder,
|
||||
@@ -139,11 +91,11 @@ void Export_Form_API() {
|
||||
std::string const& callbackId,
|
||||
std::string const& detectorId,
|
||||
int priority) -> uint {
|
||||
uint result = ServerSettingForm::addInput(
|
||||
uint result = gmlib::form::ServerSettingForm::addInput(
|
||||
text,
|
||||
placeholder,
|
||||
defaultVal,
|
||||
CALLBACK_TYPE_STRING,
|
||||
CALLBACK_TYPE(std::string const&),
|
||||
PLAYER_DETECROR,
|
||||
priority
|
||||
);
|
||||
@@ -151,19 +103,19 @@ void Export_Form_API() {
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
"GMLIB_ServerSettingForm",
|
||||
"GMLIB_gmlib::form::ServerSettingForm",
|
||||
"addToggle",
|
||||
[](std::string const& text,
|
||||
bool defaultVal,
|
||||
std::string const& callbackId,
|
||||
std::string const& detectorId,
|
||||
int priority) -> uint {
|
||||
uint result = ServerSettingForm::addToggle(text, defaultVal, CALLBACK_TYPE_BOOL, PLAYER_DETECROR, priority);
|
||||
uint result = gmlib::form::ServerSettingForm::addToggle(text, defaultVal, CALLBACK_TYPE(bool), PLAYER_DETECROR, priority);
|
||||
return result;
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
"GMLIB_ServerSettingForm",
|
||||
"GMLIB_gmlib::form::ServerSettingForm",
|
||||
"addDropdown",
|
||||
[](std::string const& text,
|
||||
std::vector<std::string> options,
|
||||
@@ -171,11 +123,11 @@ void Export_Form_API() {
|
||||
std::string const& callbackId,
|
||||
std::string const& detectorId,
|
||||
int priority) -> uint {
|
||||
uint result = ServerSettingForm::addDropdown(
|
||||
uint result = gmlib::form::ServerSettingForm::addDropdown(
|
||||
text,
|
||||
options,
|
||||
defaultVal,
|
||||
CALLBACK_TYPE_LONG,
|
||||
CALLBACK_TYPE(int64),
|
||||
PLAYER_DETECROR,
|
||||
priority
|
||||
);
|
||||
@@ -183,7 +135,7 @@ void Export_Form_API() {
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
"GMLIB_ServerSettingForm",
|
||||
"GMLIB_gmlib::form::ServerSettingForm",
|
||||
"addSlider",
|
||||
[](std::string const& text,
|
||||
double min,
|
||||
@@ -193,13 +145,13 @@ void Export_Form_API() {
|
||||
std::string const& callbackId,
|
||||
std::string const& detectorId,
|
||||
int priority) -> uint {
|
||||
uint result = ServerSettingForm::addSlider(
|
||||
uint result = gmlib::form::ServerSettingForm::addSlider(
|
||||
text,
|
||||
min,
|
||||
max,
|
||||
step,
|
||||
defaultVal,
|
||||
CALLBACK_TYPE_DOUBLE,
|
||||
CALLBACK_TYPE(double),
|
||||
PLAYER_DETECROR,
|
||||
priority
|
||||
);
|
||||
@@ -207,7 +159,7 @@ void Export_Form_API() {
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
"GMLIB_ServerSettingForm",
|
||||
"GMLIB_gmlib::form::ServerSettingForm",
|
||||
"addStepSlider",
|
||||
[](std::string const& text,
|
||||
std::vector<std::string> steps,
|
||||
@@ -215,18 +167,18 @@ void Export_Form_API() {
|
||||
std::string const& callbackId,
|
||||
std::string const& detectorId,
|
||||
int priority) -> uint {
|
||||
uint result = ServerSettingForm::addStepSlider(
|
||||
uint result = gmlib::form::ServerSettingForm::addStepSlider(
|
||||
text,
|
||||
steps,
|
||||
defaultVal,
|
||||
CALLBACK_TYPE_LONG,
|
||||
CALLBACK_TYPE(int64),
|
||||
PLAYER_DETECROR,
|
||||
priority
|
||||
);
|
||||
return result;
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs("GMLIB_ServerSettingForm", "removeElement", [](uint id) -> bool {
|
||||
return ServerSettingForm::removeElement(id);
|
||||
RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "removeElement", [](uint id) -> bool {
|
||||
return gmlib::form::ServerSettingForm::removeElement(id);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user