[engine] [cocos2d-x] [jsb-adapter] 适配引擎 v2.4.12 版本

This commit is contained in:
SmallMain
2023-10-30 22:32:32 +08:00
parent 2508616ad9
commit 0092eb9f05
787 changed files with 206249 additions and 422 deletions

View File

@@ -0,0 +1,115 @@
/****************************************************************************
Copyright (c) 2022-2023 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "EditBox.h"
#include "EditBox-openharmony.h"
#include "cocos/platform/CCApplication.h"
#include "platform/openharmony/napi/NapiHelper.h"
#include "cocos/scripting/js-bindings/jswrapper/SeApi.h"
namespace cocos2d
{
/*************************************************************************
Global variables and functions.
************************************************************************/
namespace {
se::Value g_textInputCallback;
void getTextInputCallback() {
if (!g_textInputCallback.isUndefined())
return;
auto global = se::ScriptEngine::getInstance()->getGlobalObject();
se::Value jsbVal;
if (global->getProperty("jsb", &jsbVal) && jsbVal.isObject()) {
jsbVal.toObject()->getProperty("onTextInput", &g_textInputCallback);
// free globle se::Value before ScriptEngine clean up
se::ScriptEngine::getInstance()->addBeforeCleanupHook([]() {
g_textInputCallback.setUndefined();
});
}
}
void callJSFunc(const std::string &type, const std::string &text) {
getTextInputCallback();
se::AutoHandleScope scope;
se::ValueArray args;
args.push_back(se::Value(type));
args.push_back(se::Value(text));
g_textInputCallback.toObject()->call(args, nullptr);
}
} // namespace
/*************************************************************************
Implementation of EditBox.
************************************************************************/
void EditBox::show(const EditBox::ShowInfo &showInfo) {
NapiHelper::postStringMessageToUIThread("showEditBox", showInfo.defaultValue.c_str());
}
void EditBox::hide() {
NapiHelper::postStringMessageToUIThread("hideEditBox", "");
}
void EditBox::complete() {
callJSFunc("complete", "");
}
void EditBox::updateRect(int x, int y, int width, int height) {
// not supported ...
}
void OpenHarmonyEditBox::GetInterfaces(std::vector<napi_property_descriptor> &descriptors) {
descriptors = {
DECLARE_NAPI_FUNCTION("onTextChange", OpenHarmonyEditBox::napiOnTextChange),
DECLARE_NAPI_FUNCTION("onComplete", OpenHarmonyEditBox::napiOnComplete),
};
}
napi_value OpenHarmonyEditBox::napiOnComplete(napi_env env, napi_callback_info info) {
EditBox::complete();
return nullptr;
}
napi_value OpenHarmonyEditBox::napiOnTextChange(napi_env env, napi_callback_info info) {
size_t argc = 1;
napi_value args[1];
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr));
napi_status status;
char buffer[512];
size_t result = 0;
NODE_API_CALL(status, env, napi_get_value_string_utf8(env, args[0], buffer, 512, &result));
callJSFunc("input", std::string(buffer));
return nullptr;
}
} // namespace cocos2d

View File

@@ -0,0 +1,50 @@
/****************************************************************************
Copyright (c) 2022-2023 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "EditBox.h"
#include "cocos/platform/CCApplication.h"
#include "platform/openharmony/napi/NapiHelper.h"
#include "cocos/scripting/js-bindings/jswrapper/SeApi.h"
namespace cocos2d {
class OpenHarmonyEditBox : public EditBox {
public:
static void GetInterfaces(std::vector<napi_property_descriptor>& descriptors);
static napi_value napiOnComplete(napi_env env, napi_callback_info info);
static napi_value napiOnTextChange(napi_env env, napi_callback_info info);
static napi_value show(const std::string& inputMessage);
static napi_value hide();
private:
static napi_ref showEditBoxFunction;
static napi_ref hideEditBoxFunction;
};
} // namespace cc