Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -3443,7 +3449,7 @@ function(cc_apply_definations target)
$<IF:$<BOOL:${USE_GOOGLE_BILLING}>,CC_USE_GOOGLE_BILLING=1,CC_USE_GOOGLE_BILLING=0>
$<IF:$<BOOL:${USE_GOOGLE_PLAY_GAMES}>,CC_USE_GOOGLE_PLAY_GAMES=1,CC_USE_GOOGLE_PLAY_GAMES=0>
$<IF:$<BOOL:${USE_BOX2D_JSB}>,CC_USE_BOX2D_JSB=1,CC_USE_BOX2D_JSB=0>

$<IF:$<BOOL:${USE_GAMEPAD}>,CC_USE_GAMEPAD=1,CC_USE_GAMEPAD=0>
)
endfunction()

Expand Down Expand Up @@ -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()
Expand Down
16 changes: 0 additions & 16 deletions native/cocos/platform/openharmony/OpenHarmonyGamepad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));

Expand All @@ -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());
Expand All @@ -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());

Expand Down
27 changes: 7 additions & 20 deletions native/cocos/platform/openharmony/OpenHarmonyPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"

Expand Down Expand Up @@ -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<System>());
registerInterface(std::make_shared<Screen>());
Expand All @@ -376,7 +361,9 @@ OpenHarmonyPlatform::OpenHarmonyPlatform() {
_callback.OnSurfaceChanged = onSurfaceChangedCB;
_callback.OnSurfaceDestroyed = onSurfaceDestroyedCB;
_callback.DispatchTouchEvent = dispatchTouchEventCB;
_gamePad = std::make_unique<OpenHarmonyGamePad>();
#if CC_USE_GAMEPAD
_gamePad = std::make_unique<OpenHarmonyGamePad>();
#endif
}

OpenHarmonyPlatform::~OpenHarmonyPlatform() {
Expand Down
5 changes: 5 additions & 0 deletions native/cocos/platform/openharmony/OpenHarmonyPlatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
#include "platform/openharmony/WorkerMessageQueue.h"

namespace cc {
#if CC_USE_GAMEPAD
class OpenHarmonyGamePad;
#endif

class OpenHarmonyPlatform : public UniversalPlatform {
public:
OpenHarmonyPlatform();
Expand Down Expand Up @@ -91,7 +94,9 @@ class OpenHarmonyPlatform : public UniversalPlatform {
uv_async_t _messageSignal{};
bool _timerInited{false};
WorkerMessageQueue _messageQueue;
#if CC_USE_GAMEPAD
std::unique_ptr<OpenHarmonyGamePad> _gamePad;
#endif
// game started
bool g_started{false};
bool isMouseLeftActive{false};
Expand Down
5 changes: 2 additions & 3 deletions templates/harmonyos-next/build-profile.json5
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

还原模板参数,在最新的IDE是兼容之前的版本的

}
],
"buildModeSet": [
Expand Down
2 changes: 1 addition & 1 deletion templates/harmonyos-next/hvigor/hvigor-config.json5
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"modelVersion": "6.0.1",
"modelVersion": "5.0.0",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

还原模板参数,在最新的IDE是兼容之前的版本的。但是在最新的Deveco里会弹出一个对话框提示
image
但是不会做任何操作,关闭后,仍然可以编译运行

"dependencies": {
},
"execution": {
Expand Down
2 changes: 1 addition & 1 deletion templates/harmonyos-next/oh-package.json5
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
modelVersion: '6.0.1',
modelVersion: '5.0.0',
devDependencies: {
'@ohos/hypium': '1.0.21',
'@ohos/hamock': '1.0.0',
Expand Down
Loading