mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-19 14:52:40 +08:00
Add gamepad option (#19094)
This commit is contained in:
+14
-4
@@ -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)
|
||||
$<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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
@@ -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<System>());
|
||||
registerInterface(std::make_shared<Screen>());
|
||||
@@ -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() {
|
||||
|
||||
@@ -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 @@ public:
|
||||
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};
|
||||
|
||||
@@ -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": [
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"modelVersion": "6.0.1",
|
||||
"modelVersion": "5.0.0",
|
||||
"dependencies": {
|
||||
},
|
||||
"execution": {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
modelVersion: '6.0.1',
|
||||
modelVersion: '5.0.0',
|
||||
devDependencies: {
|
||||
'@ohos/hypium': '1.0.21',
|
||||
'@ohos/hamock': '1.0.0',
|
||||
|
||||
Reference in New Issue
Block a user