Quantcast WoWInterface - View Single Post - Sorting Tooltip for money by Faction
View Single Post
12-29-18, 04:57 PM   #14
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,682
Originally Posted by cokedrivers View Post
so this is the code I use that hides or shows the Factions gold:
...
can it be condensed?
First, there should be no apostrophe in "Characters". Oh, and your totalAllianceGold variable was misspelled, but at least it matched everywhere.

Second, you're getting the gaps because you're adding the gaps. (Oh, and you also don't need to add a double-line to create a spacer, it can just be a regular line. This way you don't end up with more strings created in memory than necessary.)
Lua Code:
  1. local totalGold = 0;   
  2. local totalAlianceGold = 0;
  3. local totalHordeGold = 0;
  4. local totalNeutralGold = 0;
  5.  
  6. if db['Gold'][myPlayerRealm]['Alliance'] == nil then
  7.     GameTooltip:AddDoubleLine(" ", " ")     --no alliance characters, but let's add a line anyway
  8. else
  9.     GameTooltip:AddLine("Alliance Character's:")
  10.     for k,v in pairs(db['Gold'][myPlayerRealm]['Alliance']) do
  11.         GameTooltip:AddDoubleLine(iconAlliance..k, formatMoney(v), 1, 1, 1, 1, 1, 1)
  12.         totalAlianceGold = totalAlianceGold + v;
  13.     end
  14.     GameTooltip:AddDoubleLine("Total Alliance Gold", formatMoney(totalAlianceGold))
  15. end
  16.  
  17. GameTooltip:AddDoubleLine(" ", " ")     --now let's add a spacer between factions
  18.        
  19. if db['Gold'][myPlayerRealm]['Horde'] == nil then
  20.     GameTooltip:AddDoubleLine(" ", " ")     --no horde characters, but let's add a line anyway
  21. else
  22.     GameTooltip:AddLine("Horde Character's:")
  23.     for k,v in pairs(db['Gold'][myPlayerRealm]['Horde']) do
  24.         GameTooltip:AddDoubleLine(iconHorde..k, formatMoney(v), 1, 1, 1, 1, 1, 1)
  25.         totalHordeGold = totalHordeGold + v;
  26.     end
  27.     GameTooltip:AddDoubleLine("Total Horde Gold", formatMoney(totalHordeGold))
  28. end
  29.    
  30. GameTooltip:AddDoubleLine(" ", " ")     --now let's add a spacer
  31.            
  32. if db['Gold'][myPlayerRealm]['Neutral'] == nil then
  33.     GameTooltip:AddDoubleLine(" ", " ")
  34. else
  35.     GameTooltip:AddLine("Neutral Character's:")
  36.     for k,v in pairs(db['Gold'][myPlayerRealm]['Neutral']) do
  37.         GameTooltip:AddDoubleLine(iconNuetral..k, formatMoney(v), 1, 1, 1, 1, 1, 1)
  38.         totalNeutralGold = totalNeutralGold + v;
  39.     end
  40.     GameTooltip:AddDoubleLine("Total Neutral Gold", formatMoney(totalNeutralGold))
  41. end
  42.            
  43. local totalServerGold = totalAlianceGold + totalHordeGold + totalNeutralGold
  44.    
  45. GameTooltip:AddLine" "
  46. GameTooltip:AddDoubleLine("Total Gold for "..myPlayerRealm, formatMoney(totalServerGold))

For example, I've commented above how it is that you are getting 4 blank lines instead of one if you have only neutral characters on a server.

If you follow the logic of what you are trying to do, you want an empty line (a spacer) after every faction's section. This is even true for the last displayed faction in the tooltip, since you want a spacer before the total gold on the realm. If a faction's info will not be present in the tooltip, then you don't need the spacer. If you wish to keep your code formatted as is (rather than jlam's condensed version), then do this instead.
Lua Code:
  1. local totalGold = 0
  2. local totalAllianceGold = 0
  3. local totalHordeGold = 0
  4. local totalNeutralGold = 0
  5.  
  6. if db['Gold'][myPlayerRealm]['Alliance'] then     --so long as this will never have a value of false, you really only care if a value exists
  7.     GameTooltip:AddLine("Alliance Characters:")     --faction heading
  8.     for k,v in pairs(db['Gold'][myPlayerRealm]['Alliance']) do     --display all characters
  9.         GameTooltip:AddDoubleLine(iconAlliance..k, formatMoney(v), 1, 1, 1, 1, 1, 1)
  10.         totalAllianceGold = totalAllianceGold + v
  11.     end
  12.     GameTooltip:AddDoubleLine("Total Alliance Gold", formatMoney(totalAllianceGold))     --faction total
  13.         GameTooltip:AddLine("")     --add a spacer after this faction
  14. end
  15.  
  16. if db['Gold'][myPlayerRealm]['Horde'] then
  17.     GameTooltip:AddLine("Horde Characters:")     --faction heading
  18.     for k,v in pairs(db['Gold'][myPlayerRealm]['Horde']) do     --display all characters
  19.         GameTooltip:AddDoubleLine(iconHorde..k, formatMoney(v), 1, 1, 1, 1, 1, 1)
  20.         totalHordeGold = totalHordeGold + v
  21.     end
  22.     GameTooltip:AddDoubleLine("Total Horde Gold", formatMoney(totalHordeGold))     --faction total
  23.         GameTooltip:AddLine("")     --add a spacer after this faction
  24. end
  25.    
  26. if db['Gold'][myPlayerRealm]['Neutral'] then
  27.     GameTooltip:AddLine("Neutral Characters:")     --faction heading
  28.     for k,v in pairs(db['Gold'][myPlayerRealm]['Neutral']) do     --display all characters
  29.         GameTooltip:AddDoubleLine(iconNuetral..k, formatMoney(v), 1, 1, 1, 1, 1, 1)
  30.         totalNeutralGold = totalNeutralGold + v
  31.     end
  32.     GameTooltip:AddDoubleLine("Total Neutral Gold", formatMoney(totalNeutralGold))     --faction total
  33.         GameTooltip:AddLine("")     --add a spacer after this faction
  34. end
  35.            
  36. local totalServerGold = totalAlianceGold + totalHordeGold + totalNeutralGold
  37. GameTooltip:AddDoubleLine("Total Gold for "..myPlayerRealm, formatMoney(totalServerGold))     --server total
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote