diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index 21cc43e1413..5749bc1e781 100644 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -55,6 +55,7 @@ cc_set_if_undefined(USE_REMOTE_LOG OFF) cc_set_if_undefined(USE_ADPF OFF) cc_set_if_undefined(USE_GOOGLE_BILLING OFF) cc_set_if_undefined(USE_GOOGLE_PLAY_GAMES OFF) +cc_set_if_undefined(USE_GAMEPAD ON) if(ANDROID AND NOT DEFINED USE_CCACHE) if("$ENV{COCOS_USE_CCACHE}" STREQUAL "1") @@ -589,9 +590,14 @@ elseif(OPENHARMONY) cocos/platform/openharmony/WorkerMessageQueue.h cocos/platform/openharmony/OpenHarmonyPlatform.cpp cocos/platform/openharmony/OpenHarmonyPlatform.h - cocos/platform/openharmony/OpenHarmonyGamepad.cpp - cocos/platform/openharmony/OpenHarmonyGamepad.h ) + if(USE_GAMEPAD) + cocos_source_files( + cocos/platform/openharmony/OpenHarmonyGamepad.cpp + cocos/platform/openharmony/OpenHarmonyGamepad.h + ) + endif() + elseif(OHOS) cocos_source_files( cocos/platform/ohos/OhosPlatform.cpp @@ -3443,7 +3449,7 @@ function(cc_apply_definations target) $,CC_USE_GOOGLE_BILLING=1,CC_USE_GOOGLE_BILLING=0> $,CC_USE_GOOGLE_PLAY_GAMES=1,CC_USE_GOOGLE_PLAY_GAMES=0> $,CC_USE_BOX2D_JSB=1,CC_USE_BOX2D_JSB=0> - + $,CC_USE_GAMEPAD=1,CC_USE_GAMEPAD=0> ) endfunction() @@ -3675,13 +3681,17 @@ if(OPENHARMONY) libbundle_ndk.z.so libace_napi.z.so libace_ndk.z.so - libohgame_controller.z.so libz.so librawfile.z.so libdeviceinfo_ndk.z.so libohsensor.so ${CC_EXTERNAL_LIBS} ) + + if(USE_GAMEPAD) + list(APPEND LIBS libohgame_controller.z.so) + endif() + if(USE_SE_JSVM) list(APPEND LIBS libjsvm.so) endif() diff --git a/native/cocos/platform/openharmony/OpenHarmonyGamepad.cpp b/native/cocos/platform/openharmony/OpenHarmonyGamepad.cpp index 356efd6fa52..f56907640b5 100644 --- a/native/cocos/platform/openharmony/OpenHarmonyGamepad.cpp +++ b/native/cocos/platform/openharmony/OpenHarmonyGamepad.cpp @@ -284,9 +284,6 @@ OpenHarmonyGamePad::OpenHarmonyGamePad() { CALL_OH_GAMEPAD(OH_GamePad_LeftShoulder_RegisterButtonInputMonitor(OnButtonEvent)); CALL_OH_GAMEPAD(OH_GamePad_RightShoulder_RegisterButtonInputMonitor(OnButtonEvent)); - // CALL_OH_GAMEPAD(OH_GamePad_LeftTrigger_RegisterButtonInputMonitor(OnButtonEvent)); - // CALL_OH_GAMEPAD(OH_GamePad_RightTrigger_RegisterButtonInputMonitor(OnButtonEvent)); - CALL_OH_GAMEPAD(OH_GamePad_ButtonMenu_RegisterButtonInputMonitor(OnButtonEvent)); CALL_OH_GAMEPAD(OH_GamePad_ButtonHome_RegisterButtonInputMonitor(OnButtonEvent)); CALL_OH_GAMEPAD(OH_GamePad_ButtonC_RegisterButtonInputMonitor(OnButtonEvent)); @@ -296,11 +293,6 @@ OpenHarmonyGamePad::OpenHarmonyGamePad() { CALL_OH_GAMEPAD(OH_GamePad_ButtonX_RegisterButtonInputMonitor(OnButtonEvent)); CALL_OH_GAMEPAD(OH_GamePad_ButtonY_RegisterButtonInputMonitor(OnButtonEvent)); - // CALL_OH_GAMEPAD(OH_GamePad_Dpad_LeftButton_RegisterButtonInputMonitor(OnButtonEvent)); - // CALL_OH_GAMEPAD(OH_GamePad_Dpad_RightButton_RegisterButtonInputMonitor(OnButtonEvent)); - // CALL_OH_GAMEPAD(OH_GamePad_Dpad_UpButton_RegisterButtonInputMonitor(OnButtonEvent)); - // CALL_OH_GAMEPAD(OH_GamePad_Dpad_DownButton_RegisterButtonInputMonitor(OnButtonEvent)); - CALL_OH_GAMEPAD(OH_GamePad_LeftThumbstick_RegisterButtonInputMonitor(OnButtonEvent)); CALL_OH_GAMEPAD(OH_GamePad_RightThumbstick_RegisterButtonInputMonitor(OnButtonEvent)); @@ -317,9 +309,6 @@ OpenHarmonyGamePad::~OpenHarmonyGamePad() { CALL_OH_GAMEPAD(OH_GamePad_LeftShoulder_UnregisterButtonInputMonitor()); CALL_OH_GAMEPAD(OH_GamePad_RightShoulder_UnregisterButtonInputMonitor()); - // CALL_OH_GAMEPAD(OH_GamePad_LeftTrigger_UnregisterButtonInputMonitor()); - // CALL_OH_GAMEPAD(OH_GamePad_RightTrigger_UnregisterButtonInputMonitor()); - CALL_OH_GAMEPAD(OH_GamePad_ButtonMenu_UnregisterButtonInputMonitor()); CALL_OH_GAMEPAD(OH_GamePad_ButtonHome_UnregisterButtonInputMonitor()); CALL_OH_GAMEPAD(OH_GamePad_ButtonC_UnregisterButtonInputMonitor()); @@ -329,11 +318,6 @@ OpenHarmonyGamePad::~OpenHarmonyGamePad() { CALL_OH_GAMEPAD(OH_GamePad_ButtonX_UnregisterButtonInputMonitor()); CALL_OH_GAMEPAD(OH_GamePad_ButtonY_UnregisterButtonInputMonitor()); - // CALL_OH_GAMEPAD(OH_GamePad_Dpad_LeftButton_UnregisterButtonInputMonitor()); - // CALL_OH_GAMEPAD(OH_GamePad_Dpad_RightButton_UnregisterButtonInputMonitor()); - // CALL_OH_GAMEPAD(OH_GamePad_Dpad_UpButton_UnregisterButtonInputMonitor()); - // CALL_OH_GAMEPAD(OH_GamePad_Dpad_DownButton_UnregisterButtonInputMonitor()); - CALL_OH_GAMEPAD(OH_GamePad_LeftThumbstick_UnregisterButtonInputMonitor()); CALL_OH_GAMEPAD(OH_GamePad_RightThumbstick_UnregisterButtonInputMonitor()); diff --git a/native/cocos/platform/openharmony/OpenHarmonyPlatform.cpp b/native/cocos/platform/openharmony/OpenHarmonyPlatform.cpp index 413701a446b..a1dc1598fb6 100644 --- a/native/cocos/platform/openharmony/OpenHarmonyPlatform.cpp +++ b/native/cocos/platform/openharmony/OpenHarmonyPlatform.cpp @@ -30,7 +30,6 @@ #include "application/ApplicationManager.h" #include "application/CocosApplication.h" -#include "openharmony/OpenHarmonyGamepad.h" #include "platform/UniversalPlatform.h" #include "platform/openharmony/modules/SystemWindow.h" @@ -42,7 +41,10 @@ #include "platform/empty/modules/Screen.h" #include "platform/empty/modules/Vibrator.h" #include "platform/openharmony/modules/System.h" -#include "platform/openharmony/OpenHarmonyGamepad.h" + +#if CC_USE_GAMEPAD + #include "platform/openharmony/OpenHarmonyGamepad.h" +#endif #include "cocos/engine/EngineEvents.h" @@ -346,23 +348,6 @@ void onSurfaceDestroyedCB(OH_NativeXComponent* component, void* window) { namespace cc { -// struct ControllerKeyRemap { -// ButtonCode ohButtonCode; -// StickKeyCode actionCode{StickKeyCode::UNDEFINE}; -// const char *name; -// }; -// -// #def ine REMAP_WITH_NAME(btn, key) \ -// { btn, key, #btn } -// -// static const ControllerKeyRemap PADDLEBOAT_MAPKEY[] = { -// REMAP_WITH_NAME(ButtonCode::OH_LeftShoulder, StickKeyCode::L1), -// REMAP_WITH_NAME(ButtonCode::OH_RightShoulder, StickKeyCode::R1), -// }; -// #undef REMAP_WITH_NAME - -// cc::KeyboardEvent keyboardEvent; - OpenHarmonyPlatform::OpenHarmonyPlatform() { registerInterface(std::make_shared()); registerInterface(std::make_shared()); @@ -376,7 +361,9 @@ OpenHarmonyPlatform::OpenHarmonyPlatform() { _callback.OnSurfaceChanged = onSurfaceChangedCB; _callback.OnSurfaceDestroyed = onSurfaceDestroyedCB; _callback.DispatchTouchEvent = dispatchTouchEventCB; - _gamePad = std::make_unique(); + #if CC_USE_GAMEPAD + _gamePad = std::make_unique(); + #endif } OpenHarmonyPlatform::~OpenHarmonyPlatform() { diff --git a/native/cocos/platform/openharmony/OpenHarmonyPlatform.h b/native/cocos/platform/openharmony/OpenHarmonyPlatform.h index 8c99eef81c6..f6557bb21ec 100644 --- a/native/cocos/platform/openharmony/OpenHarmonyPlatform.h +++ b/native/cocos/platform/openharmony/OpenHarmonyPlatform.h @@ -37,7 +37,10 @@ #include "platform/openharmony/WorkerMessageQueue.h" namespace cc { +#if CC_USE_GAMEPAD class OpenHarmonyGamePad; +#endif + class OpenHarmonyPlatform : public UniversalPlatform { public: OpenHarmonyPlatform(); @@ -91,7 +94,9 @@ class OpenHarmonyPlatform : public UniversalPlatform { uv_async_t _messageSignal{}; bool _timerInited{false}; WorkerMessageQueue _messageQueue; + #if CC_USE_GAMEPAD std::unique_ptr _gamePad; + #endif // game started bool g_started{false}; bool isMouseLeftActive{false}; diff --git a/templates/harmonyos-next/build-profile.json5 b/templates/harmonyos-next/build-profile.json5 index 3c624eb9f06..0a0e87b988d 100644 --- a/templates/harmonyos-next/build-profile.json5 +++ b/templates/harmonyos-next/build-profile.json5 @@ -6,9 +6,8 @@ { "name": "default", "signingConfig": "default", - "compatibleSdkVersion": "5.1.1(19)", - "runtimeOS": "HarmonyOS", - "targetSdkVersion": "6.0.0(20)" + "compatibleSdkVersion": "5.0.3(15)", + "runtimeOS": "HarmonyOS" } ], "buildModeSet": [ diff --git a/templates/harmonyos-next/hvigor/hvigor-config.json5 b/templates/harmonyos-next/hvigor/hvigor-config.json5 index b7dab8baa84..bb1ad53359e 100644 --- a/templates/harmonyos-next/hvigor/hvigor-config.json5 +++ b/templates/harmonyos-next/hvigor/hvigor-config.json5 @@ -1,5 +1,5 @@ { - "modelVersion": "6.0.1", + "modelVersion": "5.0.0", "dependencies": { }, "execution": { diff --git a/templates/harmonyos-next/oh-package.json5 b/templates/harmonyos-next/oh-package.json5 index 5c2a0f2c8c0..ceadee95c03 100644 --- a/templates/harmonyos-next/oh-package.json5 +++ b/templates/harmonyos-next/oh-package.json5 @@ -1,5 +1,5 @@ { - modelVersion: '6.0.1', + modelVersion: '5.0.0', devDependencies: { '@ohos/hypium': '1.0.21', '@ohos/hamock': '1.0.0',