Skip to content

Commit

Permalink
chore: begin migration to new ScrollFrame API
Browse files Browse the repository at this point in the history
- TODO: `IconBrowser` migration
  • Loading branch information
paulbuechner committed May 12, 2023
1 parent da6f1c0 commit 7486931
Show file tree
Hide file tree
Showing 7 changed files with 365 additions and 120 deletions.
21 changes: 20 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,25 @@
"WorldFrame",
"class",
"QueryCastSequence",
"message"
"message",
"hooksecurefunc",
"tremove",
"SetMacroSpell",
"GetMacroItem",
"SetMacroItem",
"GetLooseMacroIcons",
"GetLooseMacroItemIcons",
"GetMacroIcons",
"GetMacroItemIcons",
"GetNumSpellTabs",
"GetSpellTabInfo",
"GetSpellBookItemInfo",
"GetSpellBookItemTexture",
"GetFlyoutInfo",
"GetFlyoutSlotInfo",
"UnitName",
"ceil",
"GetSpellBookItemName",
"IsPassiveSpell"
]
}
7 changes: 5 additions & 2 deletions MegaMacro.toc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Interface: 100007
## Interface: 100100
## Title: Mega Macro
## Author: Sellorio
## Version: 1.1.1
## Version: 1.2.1
## OptionalDeps: ElvUI

## SavedVariables: MegaMacroConfig, MegaMacroGlobalData
Expand All @@ -27,4 +27,7 @@ src/engine/parsing/conditions.lua
src/engine/mega-macro-parser.lua

src/main.xml
src/windows/mega-macro.input-scrollframe.lua
src/windows/mega-macro.input-scrollframe.xml
src/windows/mega-macro.scrollframe.xml
src/windows/mega-macro.window.xml
164 changes: 164 additions & 0 deletions src/windows/mega-macro.input-scrollframe.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
function MegaMacro_EditBox_OnTabPressed(self)
if (self.previousEditBox and IsShiftKeyDown()) then
self.previousEditBox:SetFocus();
elseif (self.nextEditBox) then
self.nextEditBox:SetFocus();
end
end

function MegaMacro_EditBox_ClearFocus(self)
self:ClearFocus();
end

function MegaMacro_EditBox_HighlightText(self)
self:HighlightText();
end

function MegaMacro_EditBox_ClearHighlight(self)
self:HighlightText(0, 0);
end

function MegaMacro_ScrollFrame_OnLoad(self)
if not self.noScrollBar then
local scrollBarTemplate = self.scrollBarTemplate or SCROLL_FRAME_SCROLL_BAR_TEMPLATE;
if not scrollBarTemplate then
error("SCROLL_FRAME_SCROLL_BAR_TEMPLATE undefined. Check ScrollDefine.lua")
end

local left = self.scrollBarX or SCROLL_FRAME_SCROLL_BAR_OFFSET_LEFT;
if not left then
error("SCROLL_FRAME_SCROLL_BAR_OFFSET_LEFT undefined. Check ScrollDefine.lua")
end

local top = self.scrollBarTopY or SCROLL_FRAME_SCROLL_BAR_OFFSET_TOP;
if not top then
error("SCROLL_FRAME_SCROLL_BAR_OFFSET_TOP undefined. Check ScrollDefine.lua")
end

local bottom = self.scrollBarBottomY or SCROLL_FRAME_SCROLL_BAR_OFFSET_BOTTOM;
if not bottom then
error("SCROLL_FRAME_SCROLL_BAR_OFFSET_BOTTOM undefined. Check ScrollDefine.lua")
end

self.ScrollBar = CreateFrame("EventFrame", nil, self, scrollBarTemplate);
self.ScrollBar:SetHideIfUnscrollable(self.scrollBarHideIfUnscrollable);
self.ScrollBar:SetHideTrackIfThumbExceedsTrack(self.scrollBarHideTrackIfThumbExceedsTrack);
self.ScrollBar:SetPoint("TOPLEFT", self, "TOPRIGHT", left, top);
self.ScrollBar:SetPoint("BOTTOMLEFT", self, "BOTTOMRIGHT", left, bottom);
self.ScrollBar:Show();

ScrollUtil.InitScrollFrameWithScrollBar(self, self.ScrollBar);

self.ScrollBar:Update();
end
end

function MegaMacro_ScrollingEdit_OnTextChanged(self, scrollFrame)
-- force an update when the text changes
self.handleCursorChange = true;
MegaMacro_ScrollingEdit_OnUpdate(self, 0, scrollFrame);
end

function MegaMacro_ScrollingEdit_OnLoad(self)
MegaMacro_ScrollingEdit_SetCursorOffsets(self, 0, 0);
end

function MegaMacro_ScrollingEdit_SetCursorOffsets(self, offset, height)
self.cursorOffset = offset;
self.cursorHeight = height;
end

function MegaMacro_ScrollingEdit_OnCursorChanged(self, x, y, w, h)
MegaMacro_ScrollingEdit_SetCursorOffsets(self, y, h);
self.handleCursorChange = true;
end

-- NOTE: If your edit box never shows partial lines of text, then this function will not work when you use
-- your mouse to move the edit cursor. You need the edit box to cut lines of text so that you can use your
-- mouse to highlight those partially-seen lines; otherwise you won't be able to use the mouse to move the
-- cursor above or below the current scroll area of the edit box.
function MegaMacro_ScrollingEdit_OnUpdate(self, elapsed, scrollFrame)
if (not scrollFrame) then
scrollFrame = self:GetParent();
end

local hasScrollableExtent = scrollFrame.ScrollBar:HasScrollableExtent();
if (not hasScrollableExtent) then
-- Return if the scroll frame has no scroll bar or if the scroll bar has no scrollable extent.
return;
end

local formattedScrollFrame = _G["MegaMacro_FormattedFrameScrollFrame"];
if not formattedScrollFrame then
error("MegaMacro_FormattedFrameScrollFrame undefined. Check ScrollDefine.lua")
end

local scroll = scrollFrame:GetVerticalScroll();
local formattedScroll = formattedScrollFrame:GetVerticalScroll();

if (scroll ~= formattedScroll) then
formattedScrollFrame:SetVerticalScroll(scroll);
end

if (self.handleCursorChange) then
local height, range, size, cursorOffset;

height = scrollFrame:GetHeight();
range = scrollFrame:GetVerticalScrollRange();
size = height + range;
cursorOffset = -self.cursorOffset;

if (math.floor(height) <= 0 or math.floor(range) <= 0) then
--Frame has no area, nothing to calculate.
return;
end

while (cursorOffset < scroll) do
scroll = (scroll - (height / 2));
if (scroll < 0) then
scroll = 0;
end
scrollFrame:SetVerticalScroll(scroll);
formattedScrollFrame:SetVerticalScroll(scroll);
end

-- If the cursor is below the scroll area, scroll down until it's at the bottom of the scroll area.
while ((cursorOffset + self.cursorHeight) > (scroll + height) and scroll < range) do
scroll = (scroll + (height / 2));
-- Don't scroll past the end of the text
if (scroll > range) then
scroll = range;
end
scrollFrame:SetVerticalScroll(scroll);
formattedScrollFrame:SetVerticalScroll(scroll);
end

self.handleCursorChange = false;
end
end

function MegaMacro_InputScrollFrame_OnLoad(self)
-- self.scrollBarX = -10;
-- self.scrollBarTopY = -1;
-- self.scrollBarBottomY = -3;
-- self.scrollBarHideIfUnscrollable = true;

MegaMacro_ScrollFrame_OnLoad(self);

self.EditBox:SetWidth(self:GetWidth() - 18);
self.EditBox:SetMaxLetters(self.maxLetters);
end

function MegaMacro_InputScrollFrame_OnMouseDown(self)
self.EditBox:SetFocus();
end

MegaMacro_InputScrollFrame_OnTabPressed = MegaMacro_EditBox_OnTabPressed;

function MegaMacro_InputScrollFrame_OnUpdate(self, elapsed)
MegaMacro_ScrollingEdit_OnUpdate(self, elapsed, self:GetParent());
end

function MegaMacro_InputScrollFrame_OnEscapePressed(self)
self:ClearFocus();
end
32 changes: 32 additions & 0 deletions src/windows/mega-macro.input-scrollframe.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\..\FrameXML\UI_shared.xsd">
<Script file="mega-macro.input-scrollframe.lua"/>

<ScrollFrame name="MegaMacro_InputScrollFrameTemplate" inherits="ScrollFrameTemplate" virtual="true">
<KeyValues>
<KeyValue key="maxLetters" value="1023" type="number"/>
<KeyValue key="scrollBarX" value="2" type="number"/>
<KeyValue key="scrollBarTopY" value="-5" type="number"/>
<KeyValue key="scrollBarBottomY" value="5" type="number"/>
<KeyValue key="scrollBarHideIfUnscrollable" value="true" type="boolean"/>
</KeyValues>
<Scripts>
<OnLoad function="MegaMacro_InputScrollFrame_OnLoad"/>
<OnMouseDown function="MegaMacro_InputScrollFrame_OnMouseDown"/>
</Scripts>
<ScrollChild>
<EditBox parentKey="EditBox" multiLine="true" countInvisibleLetters="true" autoFocus="false">
<Size x="1" y="1" />
<Anchors>
<Anchor point="TOPLEFT"/>
</Anchors>
<Scripts>
<OnTabPressed function="MegaMacro_InputScrollFrame_OnTabPressed"/>
<OnEscapePressed function="MegaMacro_InputScrollFrame_OnEscapePressed"/>
</Scripts>
<FontString inherits="GameFontHighlightSmall"/>
</EditBox>
</ScrollChild>
</ScrollFrame>
</Ui>
22 changes: 22 additions & 0 deletions src/windows/mega-macro.scrollframe.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\..\FrameXML\UI_shared.xsd">
<ScrollFrame name="MegaMacro_FrameScrollFrameTemplate" inherits="ScrollFrameTemplate" virtual="true">
<KeyValues>
<KeyValue key="scrollBarX" value="2" type="number"/>
<KeyValue key="scrollBarTopY" value="-5" type="number"/>
<KeyValue key="scrollBarBottomY" value="5" type="number"/>
<KeyValue key="scrollBarHideIfUnscrollable" value="false" type="boolean"/>
</KeyValues>
</ScrollFrame>
</Ui>

<!-- https://wowpedia.fandom.com/wiki/Patch_10.1.0/API_changes#Scroll_Templates
noScrollBar If true, don't create a scrollbar when the template is loaded.
scrollBarBottomY Bottom anchor offest for the scroll bar.
scrollBarHideIfUnscrollable If true, hide the scrollbar automatically if the scrollframe contents cannot be scrolled.
scrollBarHideTrackIfThumbExceedsTrack If true, hide the scrollbar track and thumb if the thumb would be too large to fit in the scrollbar.
scrollBarTemplate The name of a template to instantiate for the scrollbar. Defaults to MinimalScrollBar.
scrollBarTopY Top anchor Vertical offset for the scroll bar.
scrollBarX Left anchor offset for the scroll bar.
-->
52 changes: 44 additions & 8 deletions src/windows/mega-macro.window.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
UIPanelWindows["MegaMacro_Frame"] = { area = "left", pushable = 1, whileDead = 1, width = PANEL_DEFAULT_WIDTH };

local rendering = {
MacrosPerRow = 12,
CharLimitMessageFormat = "%s/%s Characters Used"
Expand Down Expand Up @@ -90,7 +92,7 @@ local function InitializeTabs()
MegaMacro_FrameTab2:SetText(MegaMacroCachedClass)
MegaMacro_FrameTab4:SetText(playerName)

if MegaMacroCachedSpecialization == '' then
if MegaMacroCachedSpecialization == "" then
MegaMacro_FrameTab3:SetText("Locked")
MegaMacro_FrameTab5:SetText("Locked")
MegaMacro_FrameTab3:Disable()
Expand Down Expand Up @@ -194,6 +196,7 @@ local function SelectMacro(macro)
MegaMacro_FrameSelectedMacroName:SetText(macro.DisplayName)
MegaMacro_FrameSelectedMacroButtonIcon:SetTexture(buttonIcon:GetTexture())
MegaMacro_FrameText:SetText(macro.Code)
MegaMacro_FrameText:SetCursorPosition(0)
MegaMacro_EditButton:Enable();
MegaMacro_DeleteButton:Enable();
MegaMacro_FrameText:Enable()
Expand Down Expand Up @@ -408,7 +411,7 @@ MegaMacroWindow = {
else
local relativePoint, x, y = MegaMacroConfig_GetWindowPosition()
MegaMacro_Frame:SetMovable(true)
MegaMacro_Frame:SetSize(640, 524)
-- MegaMacro_Frame:SetSize(640, 524)
MegaMacro_Frame:ClearAllPoints()
MegaMacro_Frame:SetPoint(relativePoint, x, y)
MegaMacro_ToggleWindowModeButton:SetText("Lock")
Expand Down Expand Up @@ -485,7 +488,7 @@ function MegaMacro_FrameTab_OnClick(self)
MegaMacro_ButtonScrollFrame:SetVerticalScroll(0)

if tabIndex == 6 then
SelectedScope = 'config'
SelectedScope = "config"
MegaMacro_FrameTab_ShowConfig()
return
else
Expand All @@ -497,7 +500,6 @@ function MegaMacro_FrameTab_OnClick(self)
InitializeMacroSlots()
SetMacroItems()
InitializeTabs()

end
end

Expand Down Expand Up @@ -610,18 +612,21 @@ function MegaMacro_TextBox_TextChanged(self)
MegaMacro_FrameCharLimitText:SetFormattedText(
rendering.CharLimitMessageFormat,
MegaMacro_FrameText:GetNumLetters(),
MegaMacroConfig['MaxMacroLength'])
MegaMacroConfig["MaxMacroLength"])

MegaMacro_ScrollingEdit_OnTextChanged(self, self:GetParent())

ScrollingEdit_OnTextChanged(self, self:GetParent())
ScrollingEdit_OnTextChanged(MegaMacro_FormattedFrameText, MegaMacro_FormattedFrameText:GetParent())
MegaMacro_ScrollingEdit_OnTextChanged(MegaMacro_FormattedFrameText, MegaMacro_FormattedFrameText:GetParent())
MegaMacro_FormattedFrameText:SetText(MegaMacroParser.Parse(text))
MegaMacro_FormattedFrameText:SetCursorPosition(0)
end

function MegaMacro_CancelButton_OnClick()
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON)

if SelectedMacro ~= nil then
MegaMacro_FrameText:SetText(SelectedMacro.Code)
MegaMacro_FrameText:SetCursorPosition(0)
end

MegaMacro_PopupFrame:Hide()
Expand Down Expand Up @@ -655,7 +660,7 @@ function MegaMacro_BlizMacro_Toggle()
MegaMacro_FrameCharLimitText:SetFormattedText(
rendering.CharLimitMessageFormat,
MegaMacro_FrameText:GetNumLetters(),
MegaMacroConfig['MaxMacroLength'])
MegaMacroConfig["MaxMacroLength"])
end

function MegaMacro_EditOkButton_OnClick()
Expand Down Expand Up @@ -701,6 +706,10 @@ function MegaMacro_PopupFrame_OnUpdate()
local macroPopupOffset = FauxScrollFrame_GetOffset(MegaMacro_PopupScrollFrame);
local index;

-- print("MegaMacro_PopupFrame_OnUpdate")
-- print("numMacroIcons: " .. numMacroIcons)
-- print("macroPopupOffset: " .. macroPopupOffset)

-- Icon list
for i = 1, NUM_MACRO_ICONS_SHOWN do
macroPopupButton = _G["MegaMacro_PopupButton" .. i];
Expand All @@ -725,6 +734,33 @@ function MegaMacro_PopupFrame_OnUpdate()
FauxScrollFrame_Update(MegaMacro_PopupScrollFrame, ceil(numMacroIcons / NUM_ICONS_PER_ROW) + 1, NUM_ICON_ROWS, MACRO_ICON_ROW_HEIGHT);
end

-- function MegaMacro_PopupFrame_OnUpdate1(self)
-- local numMacroIcons = #IconList;
-- local macroPopupIcon, macroPopupButton;
-- local macroPopupOffset = self.cursorOffset;
-- local index;

-- -- Icon list
-- for i = 1, NUM_MACRO_ICONS_SHOWN do
-- macroPopupButton = _G["MegaMacro_PopupButton" .. i];
-- macroPopupIcon = _G["MegaMacro_PopupButton" .. i .. "Icon"];
-- index = (macroPopupOffset * NUM_ICONS_PER_ROW) + i;
-- local iconListData = IconList[index]

-- if index <= numMacroIcons and iconListData then
-- macroPopupIcon:SetTexture(iconListData.Icon);
-- macroPopupButton.SpellId = iconListData.SpellId
-- macroPopupButton:Show();
-- else
-- macroPopupIcon:SetTexture("");
-- macroPopupButton.SpellId = nil
-- macroPopupButton:Hide();
-- end

-- macroPopupButton:SetChecked(iconListData and SelectedIcon == iconListData.Icon)
-- end
-- end

function MegaMacro_PopupButton_OnClick(self)
local buttonIcon = _G[self:GetName() .. "Icon"]
SelectIcon(buttonIcon:GetTexture())
Expand Down
Loading

0 comments on commit 7486931

Please sign in to comment.