View Single Post
11-21-16, 01:59 PM   #48
_Max_Cavalera_
A Fallenroot Satyr
 
_Max_Cavalera_'s Avatar
Join Date: Dec 2007
Posts: 28
ok, yeah that seems like a good idea, it's not like I'm using the Frame specifically for anything other than to define a space/anchor for everything else, right? So making it a button would allow me to use the OnClick and continue to do everything I'm already using it for.

edit:. ok..... i'm stupid..... damn....

After trying a million things before and after Lombra's post and not getting any results I realized it was actually working, what wasn't working was what I made it do, I made it open the artifact weapon window and that wasn't working, but the click was being registered and working, I just added a chat message to test (yes I should have done this in the first place xD) and the chat message shows.

edit:. ok, making the frame a button like Lombra first suggested and then doing

Lua Code:
  1. frame:SetScript("OnMouseUp", function(self, button)
  2.     if button == "LeftButton" then
  3.         ArtifactFrame_LoadUI()
  4.         if (ArtifactFrame:IsVisible()) then
  5.             HideUIPanel(ArtifactFrame)
  6.         else
  7.             SocketInventoryItem(16);
  8.         end
  9.     end
  10. end);

Seems to be enough, didn't even need the registerforclicks, tries with and without, seems to be the same.

Here's my full code so far.

Lua Code:
  1. local akMulti = {
  2.     25, 50, 90, 140, 200,
  3.     275, 375, 500, 650, 850,
  4.     1100, 1400, 1775, 2250, 2850,
  5.     3600, 4550, 5700, 7200, 9000,
  6.     11300, 14200, 17800, 22300, 24900
  7. };
  8.  
  9. local frame = CreateFrame("Button", "m4xArtifactFrame", UIParent);
  10. local text = frame:CreateFontString(nil, "ARTWORK");
  11. text:SetFont("Fonts\\FRIZQT__.TTF", 15, "OUTLINE");
  12. text:SetJustifyH("LEFT");
  13. text:SetTextColor(1, 0.82, 0);
  14. text:SetPoint("TOPLEFT", UIParent, "TOPLEFT");
  15.  
  16. frame:SetAllPoints(text);
  17.  
  18. frame:RegisterEvent("PLAYER_LOGIN");
  19. frame:RegisterEvent("PLAYER_ENTERING_WORLD");
  20. frame:RegisterEvent("PLAYER_EQUIPMENT_CHANGED");
  21. frame:RegisterEvent("ARTIFACT_CLOSE");
  22. frame:RegisterEvent("ARTIFACT_RESPEC_PROMPT");
  23. frame:RegisterEvent("ARTIFACT_XP_UPDATE");
  24.  
  25. frame:SetScript("OnEvent", function(self, event, ...)
  26.     local itemID, _, _, _, totalXP, pointsSpent = C_ArtifactUI.GetEquippedArtifactInfo()
  27.    
  28.     if itemID then
  29.         local pointsFree, xpToNextPoint = 0, C_ArtifactUI.GetCostForPointAtRank(pointsSpent);
  30.        
  31.         while totalXP >= xpToNextPoint do
  32.             totalXP, pointsSpent, pointsFree, xpToNextPoint = totalXP - xpToNextPoint, pointsSpent + 1, pointsFree + 1, C_ArtifactUI.GetCostForPointAtRank(pointsSpent + 1);
  33.         end
  34.  
  35.         text:SetFormattedText("AP |cff00ff00%d/%d (%.1f%%)|r" .. (pointsFree > 0 and " (+%d)" or ""), totalXP, xpToNextPoint, 100 * totalXP / xpToNextPoint, pointsFree);
  36.     end
  37.  
  38.     frame:SetShown(itemID and true or false);
  39. end);
  40.  
  41. local function OnEnter(self)
  42.     local _, akLevel = GetCurrencyInfo(1171);
  43.     local _, _, itemName, itemIcon, _, pointsSpent = C_ArtifactUI.GetEquippedArtifactInfo()
  44.     local _, effectiveStat = UnitStat("player", 3);
  45.  
  46.     GameTooltip:SetOwner(self, "ANCHOR_BOTTOM");
  47.     GameTooltip:SetText(string.format("|T%d:0|t %s", itemIcon, itemName));
  48.     GameTooltip:AddLine(" ");
  49.     GameTooltip:AddLine(string.format("Artifact Knowledge Level: |cff00ff00%d (+%d%%)|r", akLevel, akMulti[akLevel] or 0));
  50.     GameTooltip:AddLine(string.format("Next Artifact Knowledge: |cff00ff00%d (+%d%%)|r", akLevel + 1, akMulti[akLevel + 1]));
  51.     GameTooltip:AddLine(" ");
  52.     GameTooltip:AddLine(string.format("Stamina from points: |cff00ff00+%g%% (+%d)|r", pointsSpent * 0.75, effectiveStat - (effectiveStat / ((pointsSpent * 0.75 / 100) + 1))));
  53.     GameTooltip:Show();
  54. end
  55.  
  56. local function OnLeave(self)
  57.     GameTooltip:Hide();
  58. end
  59.  
  60. frame:SetScript("OnMouseUp", function(self, button)
  61.     if button == "LeftButton" then
  62.         if ArtifactFrame and ArtifactFrame:IsVisible() then
  63.             HideUIPanel(ArtifactFrame);
  64.         else
  65.             SocketInventoryItem(16);
  66.         end
  67.     end
  68. end);
  69.  
  70. frame:SetScript("OnEnter", OnEnter);
  71. frame:SetScript("OnLeave", OnLeave);

I'm still trying out events for the initial load, because I have a few times that the text wasn't becoming visible with PLAYER_ENTERING_WORLD, we talked about this, I think it was SDPhantom that said the addon didn't have the artifact info available at that point.
I donno, is there any other events that happen once at start bu after that one? The PLAYER_LOGIN one is probably not doing anything tbh.
I just need to get this to load at start every time and for some reason, some times it doesn't, it IS rare but it happens.

Last edited by _Max_Cavalera_ : 11-21-16 at 02:31 PM.
  Reply With Quote