Skip to content

Commit

Permalink
restore hooking into shift-click interface
Browse files Browse the repository at this point in the history
  • Loading branch information
kaelonR committed Sep 13, 2024
1 parent 7b7f3d5 commit 13657a8
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 2,139 deletions.
102 changes: 58 additions & 44 deletions BulkBuyFrame/BulkBuyFrame.lua → BuyEmAll.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
local L = BuyEmAll.L;
-- BuyEmAll - Originally created and developed by Cogwheel up to version 2.8.4, Shinisuryu up to version 3.5.5, now developed by Jordy141.

BuyEmAll = {}

local L = BUYEMALL_LOCALS;

-- These are used for the text on the Max and Stack buttons. See BuyEmAll.xml.

BUYEMALL_MAX = L.MAX;
BUYEMALL_STACK = L.STACK;

function BuyEmAll:OnLoad()
-- Set up confirmation dialog.

StaticPopupDialogs["BUYEMALL_CONFIRM"] = {
preferredIndex = 3,
text = L.CONFIRM,
Expand All @@ -21,7 +26,7 @@ function BuyEmAll:OnLoad()
text = L.CONFIRM,
button1 = YES,
button2 = NO,
OnAccept = function() BuyMerchantItem(self.ConfirmNoItemLink) end,
OnAccept = function(dialog) BuyMerchantItem(self.ConfirmNoItemLink) end,
timeout = 0,
hideOnEscape = true,
};
Expand All @@ -35,6 +40,16 @@ function BuyEmAll:OnLoad()
BuyEmAllCurrencyAmt2:SetText();
BuyEmAllCurrencyAmt3:SetText();

self.OrigMerchantItemButton_OnModifiedClick = MerchantItemButton_OnModifiedClick;
MerchantItemButton_OnModifiedClick = function(frame, button)
self:MerchantItemButton_OnModifiedClick(frame, button);
end

self.OrigMerchantFrame_OnHide = MerchantFrame:GetScript("OnHide");
MerchantFrame:SetScript("OnHide", function(...)
return self:MerchantFrame_OnHide(...);
end)

SLASH_BUYEMALL1 = "/buyemall"
SlashCmdList["BUYEMALL"] = function(message, editbox)
BuyEmAll:SlashHandler(message);
Expand All @@ -58,8 +73,10 @@ function BuyEmAll:ItemIsUnique(itemIDOrLink)

local tooltip = C_TooltipInfo.GetItemByID(itemIDOrLink);
for _, line in ipairs(tooltip.lines) do
if line.leftText and line.leftText == 'Unique' then
return true
for _, arg in ipairs(line.args) do
if(arg.field == 'leftText' and arg.stringVal == 'Unique') then
return true;
end
end
end

Expand All @@ -82,6 +99,11 @@ BEAframe:SetScript("OnEvent", eventHandler);

-- Makes sure the BuyEmAll frame goes away when you leave a vendor.

function BuyEmAll:MerchantFrame_OnHide(...)
BuyEmAllFrame:Hide();
return self.OrigMerchantFrame_OnHide(...);
end

function BuyEmAll:HasBagEquippedInSlot(slotID)
local inventorySlotId = GetInventorySlotInfo("Bag" .. (slotID - 1) .. "Slot");
return GetInventoryItemID("player", inventorySlotId) ~= nil;
Expand Down Expand Up @@ -111,13 +133,20 @@ function BuyEmAll:GetFreeBagSpace(itemID)
return canFit, stackSize;
end

function BuyEmAll:ItemClicked(frame, button)
self.itemIndex = frame:GetID()
-- Hooks left-clicks on merchant item buttons.

function BuyEmAll:MerchantItemButton_OnModifiedClick(frame, button)
self.itemIndex = frame:GetID();

-- Don't think this is needed anymore.
--if ChatFrame1EditBox:HasFocus() then ChatFrame1EditBox:Insert(GetMerchantItemLink(frame:GetID()));


if (IsShiftKeyDown())
and not (IsControlKeyDown())
and not ((C_AzeriteEmpoweredItem.IsAzeriteEmpoweredItemByID(GetMerchantItemLink(self.itemIndex))) and (button == "RightButton"))
and not (ChatFrame1EditBox:HasFocus()) then
if (MerchantFrame.selectedTab == 1)
and (IsShiftKeyDown())
and not (IsControlKeyDown())
and not ((C_AzeriteEmpoweredItem.IsAzeriteEmpoweredItemByID(GetMerchantItemLink(self.itemIndex))) and (button == "RightButton"))
and not (ChatFrame1EditBox:HasFocus()) then

-- Set up various data before showing the BuyEmAll frame.

Expand All @@ -127,7 +156,7 @@ function BuyEmAll:ItemClicked(frame, button)
self.AltCurrencyMode = false;
self.AtVendor = true; -- Currently at the vendor, for later purchase interruption.

local name, _, price, quantity, numAvailable, _, _, hasExtendedCostInfo =
local name, texture, price, quantity, numAvailable, _, _, hasExtendedCostInfo =
GetMerchantItemInfo(self.itemIndex);

self.itemName = name;
Expand Down Expand Up @@ -207,35 +236,12 @@ function BuyEmAll:ItemClicked(frame, button)

self:Show(frame);
else
local maxStack = GetMerchantItemMaxStack(frame:GetID());
local _, _, price, stackCount, _, _, _, extendedCost = GetMerchantItemInfo(frame:GetID());
StackSplitFrame:OpenStackSplitFrame(maxPurchasable, self, "BOTTOMLEFT", "TOPLEFT", stackCount);
local canAfford;
if (price and price > 0) then
canAfford = floor(GetMoney() / (price / stackCount));
else
canAfford = maxStack;
end

if (extendedCost) then
local itemCount = GetMerchantItemCostInfo(self:GetID());
for i = 1, MAX_ITEM_COST do
local itemTexture, itemValue, itemLink, currencyName = GetMerchantItemCostItem(self:GetID(), i);
if (itemLink and not currencyName) then
local myCount = C_Item.GetItemCount(itemLink, false, false, true);
canAfford = min(canAfford, floor(myCount / (itemValue / stackCount)));
end
end
end

if ( maxStack > 1 ) then
local maxPurchasable = min(maxStack, canAfford);
StackSplitFrame:OpenStackSplitFrame(maxPurchasable, self, "BOTTOMLEFT", "TOPLEFT", stackCount);
end
self.OrigMerchantItemButton_OnModifiedClick(frame, button);
end
end

-- Processor for Alternate Currencies. I think I got it compact as it can be.

function BuyEmAll:AltCurrencyHandling(itemIndex, frame)
self.AltCurrencyMode = true;

Expand Down Expand Up @@ -309,10 +315,10 @@ function BuyEmAll:Show(frame)
BuyEmAllStackButton:Disable();
end

BuyEmAllBulkBuyFrame:ClearAllPoints();
BuyEmAllBulkBuyFrame:SetPoint("BOTTOMLEFT", frame, "TOPLEFT", 0, 0);
BuyEmAllFrame:ClearAllPoints();
BuyEmAllFrame:SetPoint("BOTTOMLEFT", frame, "TOPLEFT", 0, 0);

BuyEmAllBulkBuyFrame:Show(frame);
BuyEmAllFrame:Show(frame);
self:UpdateDisplay();
end

Expand Down Expand Up @@ -364,9 +370,11 @@ function BuyEmAll:onUpdate(sinceLastUpdate)
end
end

-- End of code from Treeston.

-- Makes the actual purchase(s)
function BuyEmAll:DoPurchase(amount)
BuyEmAllBulkBuyFrame:Hide();
BuyEmAllFrame:Hide();
local numLoops, purchAmount, leftover;

if(strmatch(self.itemLink, "currency")) then --if item being purchased is a currency, then skip the loop logic and buy everything at once.
Expand Down Expand Up @@ -505,7 +513,7 @@ function BuyEmAll:OnClick(frame, button)
local amount = tonumber(BuyEmAllText:GetText());
self:VerifyPurchase(amount);
elseif (frame == BuyEmAllCancelButton) then
BuyEmAllBulkBuyFrame:Hide();
BuyEmAllFrame:Hide();
elseif (frame == BuyEmAllStackButton) then
if (button == "LeftButton") then
self.split = self.stackClick;
Expand Down Expand Up @@ -582,7 +590,7 @@ function BuyEmAll:OnKeyDown(key)
elseif (key == "ENTER") then
self:VerifyPurchase();
elseif (key == "ESCAPE") then
BuyEmAllBulkBuyFrame:Hide();
BuyEmAllFrame:Hide();
elseif (key == "LEFT") or (key == "DOWN") then
BuyEmAll:Left_Click();
elseif (key == "RIGHT") or (key == "UP") then
Expand Down Expand Up @@ -678,11 +686,18 @@ function BuyEmAll:CreateTooltip(frame, lines)
GameTooltip:Show();
end


-- Hides the tooltip.

function BuyEmAll:OnLeave()
GameTooltip:Hide();

--GameTooltip_ClearMoney(GameTooltip);
-- Not needed because of previous commenting out.
end

-- When the BuyEmAll frame is closed, close any confirmations waiting for a response as well as clear the currencies.

function BuyEmAll:OnHide()
BuyEmAllCurrency1:SetTexture();
BuyEmAllCurrency2:SetTexture();
Expand All @@ -691,5 +706,4 @@ function BuyEmAll:OnHide()
BuyEmAllCurrencyAmt2:SetText();
BuyEmAllCurrencyAmt3:SetText();
StaticPopup_Hide("BUYEMALL_CONFIRM");
StaticPopup_Hide("BUYEMALL_CONFIRM2");
end
25 changes: 6 additions & 19 deletions BuyEmAll.toc
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
## Interface: 110002
## Author: Jordy141
## Notes: Replaces merchant's shift-click UIs, making it easier to buy large amounts of items at once.
## Notes: Replaces shift-click interface at vendors, making it easier to buy large amounts of items at once.
## Title: BuyEmAll
## Version: 4.0.5
## Version: 4.1.0
## SavedVariablesPerCharacter: BEAConfirmToggle
## LoadManagers: AddonLoader
## IconTexture: 132763
## X-Build-Type: Release
## X-Curse-Project-ID: 2590
## X-WoWI-ID: 5217
## X-Wago-ID: kRNLnQKo

libs/main.xml

init.lua
## X-LoadOn-Merchant: true
## X-LoadOn-Slash: /buyemall

localisation/index.xml

BulkBuyFrame/BulkBuyFrame.lua
BulkBuyFrame/BulkBuyFrame.xml

#code copied over from Blizzard's own MerchantFrame, but renamed to BuyEmAllFrame
MerchantFrame/BuyEmAllFrame.lua
MerchantFrame/BuyEmAllFrame.xml
MerchantFrame/glue.lua
BuyEmAll.lua
BuyEmAll.xml
2 changes: 1 addition & 1 deletion BulkBuyFrame/BulkBuyFrame.xml → BuyEmAll.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</OnLeave>
</Scripts>
</Button>
<Frame name="BuyEmAllBulkBuyFrame" hidden="true" parent="UIParent" toplevel="true" frameStrata="HIGH" enableMouse="true" enableKeyboard="true">
<Frame name="BuyEmAllFrame" hidden="true" parent="UIParent" toplevel="true" frameStrata="HIGH" enableMouse="true" enableKeyboard="true">
<Size>
<AbsDimension x="230" y="134" />
</Size>
Expand Down
5 changes: 4 additions & 1 deletion Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
v4.0.5
v4.1.0
- Restore modification of the shift-click frame, hopefully restoring compatibility with most addons

v4.0.5
- Fix error that would pop up when the vendor window was reopened after being moved by BlizzMove.

v4.0.4
Expand Down
Loading

0 comments on commit 13657a8

Please sign in to comment.