vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 -- **************************************************************************
2 -- * TitanSoulShardCounter.lua
3 -- **************************************************************************
4 -- * by Candar @ Darkspear <candar-at-fornander,com>
5 -- *
6 -- * Credits: based on code from evil.oz, Pieter Walsweer, Kefka D'Arden
7 -- **************************************************************************
8  
9  
10 -- ************************************* Const / defines *************************************
11 TITAN_SOULSHARDSCOUNTER_ID = "SoulShardCounter";
12 TITAN_SOULSHARDSCOUNTER_COUNT_FORMAT = "%d";
13 TITAN_SOULSHARDSCOUNTER_TOOLTIP = "SoulShardCounter Tooltip";
14 TITAN_SOULSHARDSCOUNTER_ICON = "Interface\\Icons\\INV_Misc_Gem_Amethyst_02.blp"
15  
16 -- ************************************* Variables *******************************************
17 numSoulShard = 0;
18 timer = 0;
19  
20  
21 -- ************************************* Functions *******************************************
22 -- *******************************************************************************************
23 -- Name: TitanPanelSoulShardCounterButton_OnLoad
24 -- Desc: This function registers SoulShardCounter Addon.
25 -- *******************************************************************************************
26 function TitanPanelSoulShardCounterButton_OnLoad()
27 this.registry = {
28 id = TITAN_SOULSHARDSCOUNTER_ID,
29 menuText = TITAN_SOULSHARDSCOUNTER_MENU_TEXT,
30 buttonTextFunction = "TitanPanelSoulShardCounterButton_GetButtonText",
31 tooltipTitle = TITAN_SOULSHARDSCOUTER_TOOLTIP,
32 category = "Information",
33 tooltipTextFunction = "TitanPanelSoulShardCounterButton_GetTooltipText",
34 icon = TITAN_SOULSHARDSCOUNTER_ICON,
35 iconWidth = 16,
36 frequency = 1,
37 savedVariables = {
38 ShowLabelText = 1,
39 ShowIcon = 1,
40 WarnWhenLow = 1,
41 WarnThreshold = 1,
42 WarnTimer = 60
43 }
44 };
45 this:RegisterEvent("BAG_UPDATE");
46 this:RegisterEvent("UNIT_INVENTORY_CHANGED");
47 this:RegisterEvent("VARIABLES_LOADED");
48 end
49  
50  
51 -- *******************************************************************************************
52 -- Name: TitanPanelSoulShardCounterButton_GetButtonText
53 -- Desc: Gets our button text, the text that appears on the actual bar, all the time.
54 -- *******************************************************************************************
55 function TitanPanelSoulShardCounterButton_GetButtonText(id)
56 -- Update timer
57 timer = timer + 1;
58  
59 -- If id not nil, return corresponding plugin button
60 -- Otherwise return this button and derive the real id
61 local button, id = TitanUtils_GetButton(id, true);
62  
63 -- Business logic goes here
64 numSoulShard = SoulShardCounter_CountSoulShard();
65  
66 -- Warn if low on shards
67 if ( TitanGetVar(TITAN_SOULSHARDSCOUNTER_ID, "WarnThreshold") >= numSoulShard and
68 TitanGetVar(TITAN_SOULSHARDSCOUNTER_ID, "WarnTimer") <= timer and
69 TitanGetVar(TITAN_SOULSHARDSCOUNTER_ID, "WarnWhenLow") )
70 then
71 TitanPanelSoulShardCounter_WarningFrame:AddMessage(TITAN_SOULSHARDSCOUNTER_ITEMNAME, 1.0, 0, 0, 1.0, 1);
72 PlaySoundFile("Sound\\interface\\mapping.wav")
73 timer = 0;
74 end
75  
76 local countText = format(TITAN_SOULSHARDSCOUNTER_COUNT_FORMAT, numSoulShard);
77 local richText;
78  
79 if ( TitanGetVar(TITAN_SOULSHARDSCOUNTER_ID, "WarnThreshold") >= numSoulShard ) then
80 richText = TitanUtils_GetColoredText(countText, RED_FONT_COLOR);
81 else
82 richText = countText;
83 end
84  
85 return TITAN_SOULSHARDSCOUNTER_BUTTON_LABEL, richText;
86 end
87  
88  
89 -- *******************************************************************************************
90 -- Name: TitanPanelSoulShardCounterButton_GetTooltipText
91 -- Desc: Gets our tool-tip text, what appears when we hover over our item on the Titan bar.
92 -- *******************************************************************************************
93 function TitanPanelSoulShardCounterButton_GetTooltipText()
94 return TITAN_SOULSHARDSCOUNTER_TOOLTIPTEXT;
95 end
96  
97  
98 -- *******************************************************************************************
99 -- Name: SoulShardCounter_CountSoulShard
100 -- Desc: Counts number of Sacred SoulShard currently in player's bag.
101 -- *******************************************************************************************
102 function SoulShardCounter_CountSoulShard()
103 local shards = 0;
104 local bag, slot = 0;
105 for bag = 0, NUM_BAG_FRAMES do
106 for slot = 1, GetContainerNumSlots(bag) do
107 local itemName = GetContainerItemLink(bag, slot);
108 if itemName then
109 if string.find(itemName, "%["..TITAN_SOULSHARDSCOUNTER_ITEMNAME.."%]") then
110 local texture, count = GetContainerItemInfo(bag, slot);
111 shards = shards + count;
112 end
113 end
114 end
115 end
116 return shards;
117 end
118  
119  
120 -- *******************************************************************************************
121 -- Name: TitanPanelRightClickMenu_PrepareSoulShardCounterMenu
122 -- Desc: Builds the config menu
123 -- *******************************************************************************************
124 function TitanPanelRightClickMenu_PrepareSoulShardCounterMenu()
125 -- Menu title
126 TitanPanelRightClickMenu_AddTitle(TITAN_SOULSHARDSCOUNTER_ITEMNAME);
127  
128 -- A blank line in the menu
129 TitanPanelRightClickMenu_AddSpacer();
130  
131 -- Low warning on or off
132 TitanPanelRightClickMenu_AddToggleVar(TITAN_SOULSHARDSCOUNTER_WARN_LOW, TITAN_SOULSHARDSCOUNTER_ID, "WarnWhenLow");
133  
134 -- A blank line in the menu
135 TitanPanelRightClickMenu_AddSpacer();
136  
137 -- Generic function to toggle and hide
138 TitanPanelRightClickMenu_AddToggleIcon(TITAN_SOULSHARDSCOUNTER_ID);
139 TitanPanelRightClickMenu_AddToggleLabelText(TITAN_SOULSHARDSCOUNTER_ID);
140 TitanPanelRightClickMenu_AddCommand(TITAN_PANEL_MENU_HIDE, TITAN_SOULSHARDSCOUNTER_ID, TITAN_PANEL_MENU_FUNC_HIDE);
141  
142  
143 end