From 670c6641a3d03449473c33a0245b5f14900f8823 Mon Sep 17 00:00:00 2001 From: Rafael Araujo Lehmkuhl Date: Mon, 31 Jul 2023 18:29:25 -0300 Subject: [PATCH] Add cockpit-action to change to next view --- src/libs/joystick/protocols.ts | 1 + src/stores/widgetManager.ts | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/libs/joystick/protocols.ts b/src/libs/joystick/protocols.ts index 0b1233f6f..900586cf7 100644 --- a/src/libs/joystick/protocols.ts +++ b/src/libs/joystick/protocols.ts @@ -81,6 +81,7 @@ export class MavlinkControllerState extends ProtocolControllerState { * Possible Cockpit Actions */ export enum CockpitAction { + GO_TO_NEXT_VIEW = 'Go to next view', TOGGLE_FULL_SCREEN = 'Toggle full-screen', MAVLINK_ARM = 'Mavlink Command - Arm', MAVLINK_DISARM = 'Mavlink Command - Disarm', diff --git a/src/stores/widgetManager.ts b/src/stores/widgetManager.ts index 08e857e67..4c7919a6b 100644 --- a/src/stores/widgetManager.ts +++ b/src/stores/widgetManager.ts @@ -1,15 +1,16 @@ import '@/libs/cosmos' -import { useStorage } from '@vueuse/core' +import { useDebounceFn, useStorage } from '@vueuse/core' import { saveAs } from 'file-saver' import { defineStore } from 'pinia' import Swal from 'sweetalert2' import { v4 as uuid4 } from 'uuid' -import { computed, ref } from 'vue' +import { computed, onBeforeUnmount, ref } from 'vue' import { widgetProfile, widgetProfiles } from '@/assets/defaults' import { miniWidgetsProfile } from '@/assets/defaults' import * as Words from '@/libs/funny-name/words' +import { CockpitAction, registerActionCallback, unregisterActionCallback } from '@/libs/joystick/protocols' import { isEqual } from '@/libs/utils' import type { Point2D, SizeRect2D } from '@/types/general' import { type Profile, type View, type Widget, type WidgetType, isProfile, isView } from '@/types/widgets' @@ -253,6 +254,15 @@ export const useWidgetManagerStore = defineStore('widget-manager', () => { return isEqual(widget.position, fullScreenPosition) && isEqual(widget.size, fullScreenSize) } + const selectNextView = (): void => { + const newIndex = currentViewIndex.value === currentProfile.value.views.length - 1 ? 0 : currentViewIndex.value + 1 + selectView(currentProfile.value.views[newIndex]) + } + const debouncedSelectNextView = useDebounceFn(() => selectNextView(), 500) + const selectNextViewCallbackId = registerActionCallback(CockpitAction.GO_TO_NEXT_VIEW, debouncedSelectNextView) + onBeforeUnmount(() => unregisterActionCallback(selectNextViewCallbackId)) + + return { editingMode, showGrid,