Skip to content

Commit 8c94c29

Browse files
committed
Allow moving the sidebar to the inside of the talent frame (closes #38)
1 parent 7afa730 commit 8c94c29

File tree

1 file changed

+54
-24
lines changed

1 file changed

+54
-24
lines changed

modules/SideBarMixin.lua

Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ SideBarMixin.ShowShowInTTV = false;
2525
local LEVEL_CAP = 70;
2626
local SETTING_SUFFIX_COLLAPSED = "_Collapsed";
2727
local SETTING_SUFFIX_ANCHOR_LOCATION = "_AnchorLocation";
28-
local ANCHOR_LEFT = 0;
29-
local ANCHOR_RIGHT = 1;
28+
local ANCHOR_LEFT_OUTER = 0;
29+
local ANCHOR_RIGHT_OUTER = 1;
30+
local ANCHOR_LEFT_INNER = 2;
31+
local ANCHOR_RIGHT_INNER = 3;
3032
local LOCK_MARKUP = CreateAtlasMarkup("AdventureMapIcon-Lock", 16, 16) .. " ";
3133

3234
function SideBarMixin:OnInitialize()
@@ -350,7 +352,9 @@ function SideBarMixin:UpdatePosition(frame)
350352
if not Config:GetConfig('autoPosition') then return; end
351353
if frame:IsProtected() and InCombatLockdown() then return; end
352354

353-
local offsetDirection = self:GetAnchorLocation() == ANCHOR_LEFT and 1 or -1;
355+
local anchorLocation = self:GetAnchorLocation();
356+
357+
local offsetDirection = (anchorLocation == ANCHOR_LEFT_OUTER and 1) or (anchorLocation == ANCHOR_RIGHT_OUTER and -1) or 0;
354358
local replacePoint = true;
355359
local xOffset = (self.SideBar:GetWidth() / 2) * offsetDirection;
356360
local yOffset = -41;
@@ -514,24 +518,34 @@ function SideBarMixin:CreateImportDialog()
514518
return dialog;
515519
end
516520

517-
function SideBarMixin:OnToggleSideBarButtonClick()
521+
--- @param mouseButton MouseButton
522+
function SideBarMixin:OnToggleSideBarButtonClick(mouseButton)
518523
if IsShiftKeyDown() then
519-
self:ToggleAnchorLocation();
520-
return;
524+
local newAnchorMap = {
525+
[ANCHOR_LEFT_OUTER] = ANCHOR_RIGHT_OUTER,
526+
[ANCHOR_RIGHT_OUTER] = ANCHOR_LEFT_OUTER,
527+
[ANCHOR_LEFT_INNER] = ANCHOR_RIGHT_INNER,
528+
[ANCHOR_RIGHT_INNER] = ANCHOR_LEFT_INNER,
529+
};
530+
local anchorLocation = self:GetAnchorLocation();
531+
self:SetAnchorLocation(newAnchorMap[anchorLocation] or ANCHOR_LEFT_OUTER);
532+
elseif mouseButton == "RightButton" then
533+
local newAnchorMap = {
534+
[ANCHOR_LEFT_INNER] = ANCHOR_LEFT_OUTER,
535+
[ANCHOR_LEFT_OUTER] = ANCHOR_LEFT_INNER,
536+
[ANCHOR_RIGHT_INNER] = ANCHOR_RIGHT_OUTER,
537+
[ANCHOR_RIGHT_OUTER] = ANCHOR_RIGHT_INNER,
538+
};
539+
local anchorLocation = self:GetAnchorLocation();
540+
self:SetAnchorLocation(newAnchorMap[anchorLocation] or ANCHOR_LEFT_OUTER);
541+
else
542+
local collapsed = not self:GetCollapsed();
543+
Config:SetConfig(self.name .. SETTING_SUFFIX_COLLAPSED, collapsed);
544+
self:SetCollapsed(collapsed);
521545
end
522-
local collapsed = not self:GetCollapsed();
523-
Config:SetConfig(self.name .. SETTING_SUFFIX_COLLAPSED, collapsed);
524-
self:SetCollapsed(collapsed);
525546
end
526547

527-
function SideBarMixin:ToggleAnchorLocation()
528-
local anchorLocation = self:GetAnchorLocation();
529-
local newAnchorLocation;
530-
if ANCHOR_LEFT == anchorLocation then
531-
newAnchorLocation = ANCHOR_RIGHT;
532-
else
533-
newAnchorLocation = ANCHOR_LEFT;
534-
end
548+
function SideBarMixin:SetAnchorLocation(newAnchorLocation)
535549
Config:SetConfig(self.name .. SETTING_SUFFIX_ANCHOR_LOCATION, newAnchorLocation);
536550
self:UpdatePointsForAnchorLocation();
537551
end
@@ -540,27 +554,39 @@ function SideBarMixin:UpdatePointsForAnchorLocation()
540554
local talentsTab = self:GetTalentsTab();
541555
self.SideBar:ClearAllPoints();
542556
self.SideBar.ToggleSideBarButton:ClearAllPoints();
543-
if self:GetAnchorLocation() == ANCHOR_LEFT then
544-
self.SideBar:SetPoint('TOPRIGHT', talentsTab, 'TOPLEFT', 0, 0);
557+
local anchorLocation = self:GetAnchorLocation();
558+
local isLeftSide = anchorLocation == ANCHOR_LEFT_INNER or anchorLocation == ANCHOR_LEFT_OUTER;
559+
local isOuter = anchorLocation == ANCHOR_LEFT_OUTER or anchorLocation == ANCHOR_RIGHT_OUTER;
560+
561+
local sideBarPoint, sideBarRelativePoint;
562+
if isLeftSide then
545563
self.SideBar.ToggleSideBarButton:SetPoint('RIGHT', talentsTab, 'TOPLEFT', 10, -52);
564+
sideBarPoint = isOuter and 'TOPRIGHT' or 'TOPLEFT';
565+
sideBarRelativePoint = 'TOPLEFT';
546566
else
547-
self.SideBar:SetPoint('TOPLEFT', self:GetTalentsTab(), 'TOPRIGHT', 0, 0);
548567
self.SideBar.ToggleSideBarButton:SetPoint('LEFT', talentsTab, 'TOPRIGHT', -10, -52);
568+
sideBarPoint = isOuter and 'TOPLEFT' or 'TOPRIGHT';
569+
sideBarRelativePoint = 'TOPRIGHT';
549570
end
571+
572+
self.SideBar:SetPoint(sideBarPoint, talentsTab, sideBarRelativePoint, 0, 0);
550573
self:SetCollapsed(self:GetCollapsed());
551574

552575
self:UpdatePosition(talentsTab:GetParent());
553576
end
554577

555578
function SideBarMixin:GetAnchorLocation()
556-
return Config:GetConfig(self.name .. SETTING_SUFFIX_ANCHOR_LOCATION, ANCHOR_LEFT);
579+
return Config:GetConfig(self.name .. SETTING_SUFFIX_ANCHOR_LOCATION, ANCHOR_LEFT_OUTER);
557580
end
558581

559582
function SideBarMixin:SetCollapsed(collapsed)
560583
local sideBar = self.SideBar;
561584
sideBar:SetShown(not collapsed);
562585
local anchorLocation = self:GetAnchorLocation();
563-
if (not collapsed and ANCHOR_LEFT == anchorLocation) or (collapsed and ANCHOR_RIGHT == anchorLocation) then
586+
if
587+
(not collapsed and (ANCHOR_LEFT_OUTER == anchorLocation or ANCHOR_RIGHT_INNER == anchorLocation))
588+
or (collapsed and (ANCHOR_RIGHT_OUTER == anchorLocation or ANCHOR_LEFT_INNER == anchorLocation))
589+
then
564590
-- arrow pointing right
565591
sideBar.ToggleSideBarButton:GetNormalTexture():SetTexCoord(0.15625, 0.5, 0.84375, 0.5, 0.15625, 0, 0.84375, 0);
566592
sideBar.ToggleSideBarButton:GetHighlightTexture():SetTexCoord(0.15625, 1, 0.84375, 1, 0.15625, 0.5, 0.84375, 0.5);
@@ -581,6 +607,7 @@ function SideBarMixin:CreateSideBar()
581607
local sideBar = CreateFrame("Frame", nil, talentsTab);
582608
local width = 300;
583609

610+
sideBar:SetFrameStrata("HIGH");
584611
sideBar:SetHeight(talentsTab:GetHeight());
585612
sideBar:SetWidth(width);
586613
sideBar:SetPoint("TOPRIGHT", talentsTab, "TOPLEFT", 0, 0);
@@ -648,6 +675,7 @@ function SideBarMixin:CreateSideBar()
648675

649676
-- add a expand button
650677
sideBar.ToggleSideBarButton = CreateFrame("Button", nil, talentsTab, "UIPanelButtonTemplate, UIButtonTemplate");
678+
sideBar.ToggleSideBarButton:RegisterForClicks("AnyUp");
651679
sideBar.ToggleSideBarButton:SetSize(24, 38);
652680
sideBar.ToggleSideBarButton:SetFrameStrata("HIGH");
653681
sideBar.ToggleSideBarButton:SetNormalTexture("Interface\\PaperDollInfoFrame\\UI-GearManager-FlyoutButton");
@@ -659,10 +687,12 @@ function SideBarMixin:CreateSideBar()
659687
GameTooltip:SetOwner(sideBar.ToggleSideBarButton, "ANCHOR_RIGHT");
660688
GameTooltip:SetText("Toggle Sidebar");
661689
GameTooltip:AddLine("|cffeda55fShift + Click|r to move the side bar to the other side of the UI.", 1, 1, 1, true);
690+
GameTooltip:AddLine("|cffeda55fRight-Click|r to move the side bar to the inside side of the UI.", 1, 1, 1, true);
662691
GameTooltip:Show();
663692
end);
664-
sideBar.ToggleSideBarButton:SetScript("OnClick", function()
665-
self:OnToggleSideBarButtonClick();
693+
--- @param mouseButton MouseButton
694+
sideBar.ToggleSideBarButton:SetScript("OnClick", function(_, mouseButton)
695+
self:OnToggleSideBarButtonClick(mouseButton);
666696
end);
667697

668698
-- add a scrollbox frame

0 commit comments

Comments
 (0)