Skip to content

Commit

Permalink
Added 'NewFeature' label from retail
Browse files Browse the repository at this point in the history
  • Loading branch information
hizuro committed Jan 21, 2024
1 parent 065aaa1 commit d7264b0
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
11 changes: 11 additions & 0 deletions LibDropDownMenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ function UIDropDownMenuButton_OnEnter(self)
end

GetValueOrCallFunction(self, "funcOnEnter", self);
--self.NewFeature:Hide(); -- in retail, but why?
self.NewFeature:SetShown(self.showNewLabel);
end

function UIDropDownMenuButton_OnLeave(self)
Expand Down Expand Up @@ -666,6 +668,7 @@ function UIDropDownMenu_AddButton(info, level)
button.iconXOffset = info.iconXOffset;
button.mouseOverIcon = info.mouseOverIcon;
button.ignoreAsMenuSelection = info.ignoreAsMenuSelection;
button.showNewLabel = info.showNewLabel;

if ( info.value ~= nil) then
button.value = info.value;
Expand Down Expand Up @@ -795,6 +798,7 @@ function UIDropDownMenu_AddButton(info, level)
_G[listFrameName.."Button"..index.."UnCheck"]:Hide();
end
button.checked = info.checked;
button.NewFeature:SetShown(button.showNewLabel);

-- If has a colorswatch, show it and vertex color it
local colorSwatch = _G[listFrameName.."Button"..index.."ColorSwatch"];
Expand Down Expand Up @@ -895,6 +899,9 @@ function UIDropDownMenu_GetButtonWidth(button)
if ( button.hasArrow or button.hasColorSwatch ) then
width = width + 10;
end
if (button.showNewLabel) then
width = width + button.NewFeature.Label:GetUnboundedStringWidth();
end
if ( button.notCheckable ) then
width = width - 30;
end
Expand Down Expand Up @@ -967,6 +974,10 @@ function UIDropDownMenu_Refresh(frame, useValue, dropdownLevel)
end
end

local normalText = _G[button:GetName().."NormalText"];
button.NewFeature:SetShown(button.showNewLabel);
button.NewFeature:SetPoint("LEFT", normalText, "RIGHT", 20, 0);

if ( button:IsShown() ) then
local width = UIDropDownMenu_GetButtonWidth(button);
if ( width > maxWidth ) then
Expand Down
27 changes: 27 additions & 0 deletions LibDropDownMenuTemplates.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,30 @@ ColorSwatchMixin = {}
function ColorSwatchMixin:SetColor(color)
self.Color:SetVertexColor(color:GetRGB());
end

-- copied from SharedXML/NewFeatureLabel.lua; not present in classic
NewFeatureLabelMixin = {};

function NewFeatureLabelMixin:OnLoad()
self.BGLabel:SetText(self.label);
self.Label:SetText(self.label);
self.Label:SetJustifyH(self.justifyH);
self.BGLabel:SetJustifyH(self.justifyH);
end

function NewFeatureLabelMixin:ClearAlert()
-- derive
self:SetShown(false);
end

function NewFeatureLabelMixin:OnShow()
if self.animateGlow then
self.Fade:Play();
end
end

function NewFeatureLabelMixin:OnHide()
if self.animateGlow then
self.Fade:Stop();
end
end
68 changes: 68 additions & 0 deletions LibDropDownMenuTemplatesCreate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local Mixin,CreateFromMixins,CreateFrame,_G = Mixin,CreateFromMixins,CreateFrame
local TOOLTIP_DEFAULT_COLOR,select = TOOLTIP_DEFAULT_COLOR,select;
local TOOLTIP_DEFAULT_BACKGROUND_COLOR = TOOLTIP_DEFAULT_BACKGROUND_COLOR;
local NORMAL_FONT_COLOR,HIGHLIGHT_FONT_COLOR,BLACK_FONT_COLOR = NORMAL_FONT_COLOR,HIGHLIGHT_FONT_COLOR,BLACK_FONT_COLOR;
local NEW_FEATURE_SHADOW_COLOR,NEW_CAPS = NEW_FEATURE_SHADOW_COLOR,NEW_CAPS or NEW;
local BackdropTemplateMixin = BackdropTemplateMixin;
local GetPhysicalScreenSize = GetPhysicalScreenSize;
local Round,Lerp,min,max = Round,Lerp,min,max;
Expand Down Expand Up @@ -79,6 +80,63 @@ if not PixelUtil then -- classic compatibilty
end
end

local function Create_NewFeature(parent)
local NewFeature = CreateFrame("Frame",nil,parent); -- ResizeLayoutFrame template unusable
NewFeature:Hide();
Mixin(NewFeature,NewFeatureLabelMixin);

-- <KeyValues>
NewFeature.animateFlow = true;
NewFeature.label = NEW_CAPS;
NewFeature.justifyH = "CENTER";
-- </KeyValues>
-- <Layers>
-- <Layer OVERLAY>
NewFeature.BGLabel = NewFeature:CreateFontString(nil,"OVERLAY","GameFontNormal_NoShadow",1);
NewFeature.BGLabel:SetMaxLines(1);
NewFeature.BGLabel:SetJustifyH("CENTER")
NewFeature.BGLabel:SetText(NEW_CAPS);
NewFeature.BGLabel:SetShadowColor(NEW_FEATURE_SHADOW_COLOR:GetRGBA())
NewFeature.BGLabel:SetPoint("CENTER",0.5,-0.5)
NewFeature.Label = NewFeature:CreateFontString(nil,"OVERLAY","GameFontHighlight",1);
NewFeature.Label:SetMaxLines(1)
NewFeature.Label:SetJustifyH("CENTER")
NewFeature.Label:SetText(NEW_CAPS)
NewFeature.Label:SetShadowColor(NEW_FEATURE_SHADOW_COLOR:GetRGBA())
NewFeature.Label:SetPoint("CENTER")
NewFeature.Glow = NewFeature:CreateTexture(nil,"OVERLAY",nil,1)
NewFeature.Glow:SetPoint("TOPLEFT",NewFeature.Label,-20,10)
NewFeature.Glow:SetPoint("BOTTOMRIGHT",NewFeature.Label,20,-10)
-- </Layer OVERLAY>
-- </Layers>

-- <Animations>
NewFeature.Fade = NewFeature:CreateAnimationGroup()
NewFeature.Fade:SetLooping("REPEAT")
local A1 = NewFeature.Fade:CreateAnimation("Alpha")
A1:SetTarget(NewFeature.Glow)
A1:SetDuration(1.0)
A1:SetOrder(1)
A1:SetFromAlpha(1)
A1:SetToAlpha(0.5)
local A2 = NewFeature.Fade:CreateAnimation("Alpha")
A2:SetTarget(NewFeature.Glow)
A2:SetDuration(1.0)
A2:SetOrder(2)
A2:SetFromAlpha(0.5)
A2:SetToAlpha(1)
-- </Animations>

-- <Scripts>
NewFeature:SetScript("OnShow",NewFeature.OnShow);
--NewFeature:SetScript("OnLoad",NewFeature.OnLoad);
NewFeature:SetScript("OnHide",NewFeature.OnHide);
-- </Scripts>


return NewFeature
end


-- lua replacement of UIDropDownCustomMenuEntryTemplate
function Create_DropDownCustomMenuEntry(name,parent,opts)
Expand Down Expand Up @@ -232,6 +290,14 @@ function Create_DropDownMenuButton(name,parent,opts)
button.invisibleButton:SetScript("OnEnter",UIDropDownMenuButtonInvisibleButton_OnEnter);
button.invisibleButton:SetScript("OnLeave",UIDropDownMenuButtonInvisibleButton_OnLeave);
-- </Button>
-- <Frame>
button.NewFeature = Create_NewFeature(button);
button.NewFeature:SetFrameStrata("HIGH");
button.NewFeature:SetScale(0.8);
button.NewFeature:SetFrameLevel(100);
button.NewFeature:SetSize(1,1);
button.NewFeature:Hide();
-- </Frame>
-- </Frames>

-- <Scripts>
Expand All @@ -248,6 +314,8 @@ function Create_DropDownMenuButton(name,parent,opts)
button:SetFontString(button.NormalText);
-- </ButtonText>

button.NewFeature:SetPoint("LEFT", button.NormalText, "RIGHT", 20, 0);

button:SetNormalFontObject("GameFontHighlightSmallLeft")
button:SetHighlightFontObject("GameFontHighlightSmallLeft");
button:SetDisabledFontObject("GameFontDisableSmallLeft");
Expand Down

0 comments on commit d7264b0

Please sign in to comment.