From babe93a6ce260dbcf3b5aaec0f40cb0c4e60f843 Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Thu, 12 Oct 2023 21:37:45 +0200 Subject: [PATCH] Clean up Twitch action * Allow filtering in action selection by typing * Add spacing between action type definitions to allow reordering in future --- .../twitch/macro-action-twitch.cpp | 23 +++++++++++++------ .../twitch/macro-action-twitch.hpp | 18 +++++++-------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/macro-external/twitch/macro-action-twitch.cpp b/src/macro-external/twitch/macro-action-twitch.cpp index 0b312c29..96addb5b 100644 --- a/src/macro-external/twitch/macro-action-twitch.cpp +++ b/src/macro-external/twitch/macro-action-twitch.cpp @@ -335,8 +335,9 @@ bool MacroActionTwitch::ActionIsSupportedByToken() static inline void populateActionSelection(QComboBox *list) { - for (const auto &[_, name] : actionTypes) { - list->addItem(obs_module_text(name.c_str())); + for (const auto &[action, name] : actionTypes) { + list->addItem(obs_module_text(name.c_str()), + static_cast(action)); } } @@ -351,7 +352,7 @@ MacroActionTwitchEdit::MacroActionTwitchEdit( QWidget *parent, std::shared_ptr entryData) : QWidget(parent), _layout(new QHBoxLayout()), - _actions(new QComboBox()), + _actions(new FilterComboBox()), _tokens(new TwitchConnectionSelection()), _tokenPermissionWarning(new QLabel(obs_module_text( "AdvSceneSwitcher.action.twitch.tokenPermissionsInsufficient"))), @@ -397,7 +398,7 @@ MacroActionTwitchEdit::MacroActionTwitchEdit( QWidget::connect(_markerDescription, SIGNAL(editingFinished()), this, SLOT(MarkerDescriptionChanged())); QObject::connect(_clipHasDelay, SIGNAL(stateChanged(int)), this, - SLOT(HasClipDelayChanged(int))); + SLOT(ClipHasDelayChanged(int))); QObject::connect(_duration, SIGNAL(DurationChanged(const Duration &)), this, SLOT(DurationChanged(const Duration &))); QWidget::connect(_announcementMessage, SIGNAL(textChanged()), this, @@ -587,7 +588,8 @@ void MacroActionTwitchEdit::UpdateEntryData() return; } - _actions->setCurrentIndex(static_cast(_entryData->_action)); + _actions->setCurrentIndex( + _actions->findData(static_cast(_entryData->_action))); _tokens->SetToken(_entryData->_token); _streamTitle->setText(_entryData->_streamTitle); _category->SetToken(_entryData->_token); @@ -604,14 +606,21 @@ void MacroActionTwitchEdit::UpdateEntryData() SetupWidgetVisibility(); } -void MacroActionTwitchEdit::ActionChanged(int value) +void MacroActionTwitchEdit::ActionChanged(int idx) { if (_loading || !_entryData) { return; } + if (idx == -1) { // Reset to previous selection + _actions->setCurrentIndex(_actions->findData( + static_cast(_entryData->_action))); + return; + } + auto lock = LockContext(); - _entryData->_action = static_cast(value); + _entryData->_action = static_cast( + _actions->itemData(idx).toInt()); SetupWidgetVisibility(); } diff --git a/src/macro-external/twitch/macro-action-twitch.hpp b/src/macro-external/twitch/macro-action-twitch.hpp index 5b35f766..d6688ec8 100644 --- a/src/macro-external/twitch/macro-action-twitch.hpp +++ b/src/macro-external/twitch/macro-action-twitch.hpp @@ -27,14 +27,14 @@ public: enum class Action { TITLE, - CATEGORY, - MARKER, - CLIP, - COMMERCIAL, - ANNOUNCEMENT, - ENABLE_EMOTE_ONLY, - DISABLE_EMOTE_ONLY, - RAID, + CATEGORY = 10, + MARKER = 20, + CLIP = 30, + COMMERCIAL = 40, + ANNOUNCEMENT = 50, + ENABLE_EMOTE_ONLY = 60, + DISABLE_EMOTE_ONLY = 70, + RAID = 80, }; enum class AnnouncementColor { @@ -113,7 +113,7 @@ private: void SetupWidgetVisibility(); QHBoxLayout *_layout; - QComboBox *_actions; + FilterComboBox *_actions; TwitchConnectionSelection *_tokens; QLabel *_tokenPermissionWarning; QTimer _tokenPermissionCheckTimer;