refactor: merge emote element flags (#6511)
This commit is contained in:
@@ -416,8 +416,7 @@ EmotePtr makeSharedChatBadge(const QString &sourceName,
|
||||
});
|
||||
}
|
||||
|
||||
std::tuple<std::optional<EmotePtr>, MessageElementFlags> parseEmote(
|
||||
TwitchChannel *twitchChannel, const EmoteName &name)
|
||||
EmotePtr parseEmote(TwitchChannel *twitchChannel, const EmoteName &name)
|
||||
{
|
||||
// Emote order:
|
||||
// - FrankerFaceZ Channel
|
||||
@@ -440,19 +439,19 @@ std::tuple<std::optional<EmotePtr>, MessageElementFlags> parseEmote(
|
||||
emote = twitchChannel->ffzEmote(name);
|
||||
if (emote)
|
||||
{
|
||||
return {emote, MessageElementFlag::FfzEmote};
|
||||
return *emote;
|
||||
}
|
||||
|
||||
emote = twitchChannel->bttvEmote(name);
|
||||
if (emote)
|
||||
{
|
||||
return {emote, MessageElementFlag::BttvEmote};
|
||||
return *emote;
|
||||
}
|
||||
|
||||
emote = twitchChannel->seventvEmote(name);
|
||||
if (emote)
|
||||
{
|
||||
return {emote, MessageElementFlag::SevenTVEmote};
|
||||
return *emote;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -461,22 +460,22 @@ std::tuple<std::optional<EmotePtr>, MessageElementFlags> parseEmote(
|
||||
emote = globalFfzEmotes->emote(name);
|
||||
if (emote)
|
||||
{
|
||||
return {emote, MessageElementFlag::FfzEmote};
|
||||
return *emote;
|
||||
}
|
||||
|
||||
emote = globalBttvEmotes->emote(name);
|
||||
if (emote)
|
||||
{
|
||||
return {emote, MessageElementFlag::BttvEmote};
|
||||
return *emote;
|
||||
}
|
||||
|
||||
emote = globalSeventvEmotes->globalEmote(name);
|
||||
if (emote)
|
||||
{
|
||||
return {emote, MessageElementFlag::SevenTVEmote};
|
||||
return *emote;
|
||||
}
|
||||
|
||||
return {{}, {}};
|
||||
return {};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -2211,14 +2210,14 @@ void MessageBuilder::appendUsername(const QVariantMap &tags,
|
||||
Outcome MessageBuilder::tryAppendEmote(TwitchChannel *twitchChannel,
|
||||
const EmoteName &name)
|
||||
{
|
||||
auto [emote, flags] = parseEmote(twitchChannel, name);
|
||||
auto emote = parseEmote(twitchChannel, name);
|
||||
|
||||
if (!emote)
|
||||
{
|
||||
return Failure;
|
||||
}
|
||||
|
||||
if ((*emote)->zeroWidth && getSettings()->enableZeroWidthEmotes &&
|
||||
if (emote->zeroWidth && getSettings()->enableZeroWidthEmotes &&
|
||||
!this->isEmpty())
|
||||
{
|
||||
// Attempt to merge current zero-width emote into any previous emotes
|
||||
@@ -2231,9 +2230,12 @@ Outcome MessageBuilder::tryAppendEmote(TwitchChannel *twitchChannel,
|
||||
auto baseEmoteElement = this->releaseBack();
|
||||
|
||||
std::vector<LayeredEmoteElement::Emote> layers = {
|
||||
{baseEmote, baseEmoteElement->getFlags()}, {*emote, flags}};
|
||||
{baseEmote, baseEmoteElement->getFlags()},
|
||||
{emote, MessageElementFlag::Emote},
|
||||
};
|
||||
this->emplace<LayeredEmoteElement>(
|
||||
std::move(layers), baseEmoteElement->getFlags() | flags,
|
||||
std::move(layers),
|
||||
baseEmoteElement->getFlags() | MessageElementFlag::Emote,
|
||||
this->textColor_);
|
||||
return Success;
|
||||
}
|
||||
@@ -2241,15 +2243,16 @@ Outcome MessageBuilder::tryAppendEmote(TwitchChannel *twitchChannel,
|
||||
auto *asLayered = dynamic_cast<LayeredEmoteElement *>(&this->back());
|
||||
if (asLayered)
|
||||
{
|
||||
asLayered->addEmoteLayer({*emote, flags});
|
||||
asLayered->addFlags(flags);
|
||||
asLayered->addEmoteLayer({emote, MessageElementFlag::Emote});
|
||||
asLayered->addFlags(MessageElementFlag::Emote);
|
||||
return Success;
|
||||
}
|
||||
|
||||
// No emote to merge with, just show as regular emote
|
||||
}
|
||||
|
||||
this->emplace<EmoteElement>(*emote, flags, this->textColor_);
|
||||
this->emplace<EmoteElement>(emote, MessageElementFlag::Emote,
|
||||
this->textColor_);
|
||||
return Success;
|
||||
}
|
||||
|
||||
@@ -2278,7 +2281,7 @@ void MessageBuilder::addWords(
|
||||
{
|
||||
// This emote exists right at the start of the word!
|
||||
this->emplace<EmoteElement>(currentTwitchEmote.ptr,
|
||||
MessageElementFlag::TwitchEmote,
|
||||
MessageElementFlag::Emote,
|
||||
this->textColor_);
|
||||
|
||||
auto len = currentTwitchEmote.name.string.length();
|
||||
|
||||
@@ -200,7 +200,7 @@ void EmoteElement::addToContainer(MessageLayoutContainer &container,
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx.flags.has(MessageElementFlag::EmoteImages))
|
||||
if (ctx.flags.has(MessageElementFlag::EmoteImage))
|
||||
{
|
||||
auto image =
|
||||
this->emote_->images.getImageOrLoaded(container.getImageScale());
|
||||
@@ -286,7 +286,7 @@ void LayeredEmoteElement::addToContainer(MessageLayoutContainer &container,
|
||||
{
|
||||
if (ctx.flags.hasAny(this->getFlags()))
|
||||
{
|
||||
if (ctx.flags.has(MessageElementFlag::EmoteImages))
|
||||
if (ctx.flags.has(MessageElementFlag::EmoteImage))
|
||||
{
|
||||
auto images = this->getLoadedImages(container.getImageScale());
|
||||
if (images.empty())
|
||||
|
||||
@@ -40,29 +40,18 @@ enum class MessageElementFlag : int64_t {
|
||||
Username = (1LL << 2),
|
||||
Timestamp = (1LL << 3),
|
||||
|
||||
TwitchEmoteImage = (1LL << 4),
|
||||
TwitchEmoteText = (1LL << 5),
|
||||
TwitchEmote = TwitchEmoteImage | TwitchEmoteText,
|
||||
EmoteImage = (1LL << 4),
|
||||
EmoteText = (1LL << 5),
|
||||
Emote = EmoteImage | EmoteText,
|
||||
|
||||
BttvEmoteImage = (1LL << 6),
|
||||
BttvEmoteText = (1LL << 7),
|
||||
BttvEmote = BttvEmoteImage | BttvEmoteText,
|
||||
// unused: (1LL << 6),
|
||||
// unused: (1LL << 7),
|
||||
|
||||
ChannelPointReward = (1LL << 8),
|
||||
ChannelPointRewardImage = ChannelPointReward | TwitchEmoteImage,
|
||||
ChannelPointRewardImage = ChannelPointReward | EmoteImage,
|
||||
|
||||
FfzEmoteImage = (1LL << 9),
|
||||
FfzEmoteText = (1LL << 10),
|
||||
FfzEmote = FfzEmoteImage | FfzEmoteText,
|
||||
|
||||
SevenTVEmoteImage = (1LL << 34),
|
||||
SevenTVEmoteText = (1LL << 35),
|
||||
SevenTVEmote = SevenTVEmoteImage | SevenTVEmoteText,
|
||||
|
||||
EmoteImages =
|
||||
TwitchEmoteImage | BttvEmoteImage | FfzEmoteImage | SevenTVEmoteImage,
|
||||
EmoteText =
|
||||
TwitchEmoteText | BttvEmoteText | FfzEmoteText | SevenTVEmoteText,
|
||||
// unused: (1LL << 9),
|
||||
// unused: (1LL << 10),
|
||||
|
||||
BitsStatic = (1LL << 11),
|
||||
BitsAnimated = (1LL << 12),
|
||||
@@ -158,11 +147,9 @@ enum class MessageElementFlag : int64_t {
|
||||
// for the reply button element
|
||||
ReplyButton = (1LL << 33),
|
||||
|
||||
// (1LL << 34) through (1LL << 36) are occupied by
|
||||
// SevenTVEmoteImage, SevenTVEmoteText, and BadgeSevenTV,
|
||||
// (1LL << 36) is occupied by BadgeSevenTV
|
||||
|
||||
Default = Timestamp | Badges | Username | BitsStatic | FfzEmoteImage |
|
||||
BttvEmoteImage | SevenTVEmoteImage | TwitchEmoteImage |
|
||||
Default = Timestamp | Badges | Username | BitsStatic | EmoteImage |
|
||||
BitsAmount | Text | AlwaysShow,
|
||||
};
|
||||
using MessageElementFlags = FlagsEnum<MessageElementFlag>;
|
||||
|
||||
@@ -179,7 +179,7 @@ void MessageLayoutContainer::breakLine()
|
||||
bool isCompactEmote =
|
||||
!this->flags_.has(MessageFlag::DisableCompactEmotes) &&
|
||||
element->getCreator().getFlags().has(
|
||||
MessageElementFlag::EmoteImages);
|
||||
MessageElementFlag::EmoteImage);
|
||||
|
||||
qreal yExtra = 0;
|
||||
if (isCompactEmote)
|
||||
@@ -635,7 +635,7 @@ void MessageLayoutContainer::addElement(MessageLayoutElement *element,
|
||||
}
|
||||
|
||||
// Returns true if the last element was an emote image
|
||||
return lastElement->getFlags().has(MessageElementFlag::EmoteImages);
|
||||
return lastElement->getFlags().has(MessageElementFlag::EmoteImage);
|
||||
};
|
||||
|
||||
bool isRTLElement = element->getText().isRightToLeft();
|
||||
@@ -670,7 +670,7 @@ void MessageLayoutContainer::addElement(MessageLayoutElement *element,
|
||||
// compact emote offset
|
||||
bool isCompactEmote =
|
||||
!this->flags_.has(MessageFlag::DisableCompactEmotes) &&
|
||||
element->getCreator().getFlags().has(MessageElementFlag::EmoteImages);
|
||||
element->getCreator().getFlags().has(MessageElementFlag::EmoteImage);
|
||||
|
||||
if (isCompactEmote)
|
||||
{
|
||||
@@ -686,13 +686,13 @@ void MessageLayoutContainer::addElement(MessageLayoutElement *element,
|
||||
if (element->getCreator().getFlags().has(
|
||||
MessageElementFlag::ChannelPointReward) &&
|
||||
element->getCreator().getFlags().hasNone(
|
||||
{MessageElementFlag::TwitchEmoteImage}))
|
||||
{MessageElementFlag::EmoteImage}))
|
||||
{
|
||||
yOffset -= (MARGIN.top() * this->scale_);
|
||||
}
|
||||
|
||||
if (getSettings()->removeSpacesBetweenEmotes &&
|
||||
element->getFlags().hasAny({MessageElementFlag::EmoteImages}) &&
|
||||
element->getFlags().hasAny({MessageElementFlag::EmoteImage}) &&
|
||||
shouldRemoveSpaceBetweenEmotes())
|
||||
{
|
||||
// Move cursor one 'space width' to the left (right in case of RTL) to combine hug the previous emote
|
||||
|
||||
Reference in New Issue
Block a user