From ebf160d359a5497012fd4d19568ccd60ee421f1e Mon Sep 17 00:00:00 2001 From: urnati Date: Sat, 7 Sep 2019 21:31:27 -0400 Subject: [PATCH] - #9 Comment more order hall code - #5 Threshold update per ammo type - #7 pdated code to show ammo name, even for thrown --- TitanClassic/TitanClassicVariables.lua | 2 +- TitanClassic/TitanPanelClassic.lua | 10 +- TitanClassicAmmo/TitanClassicAmmo.lua | 263 ++++++++++++++++++-------------- 3 files changed, 155 insertions(+), 120 deletions(-) diff --git a/TitanClassic/TitanClassicVariables.lua b/TitanClassic/TitanClassicVariables.lua index 6592e63..e27f828 100644 --- a/TitanClassic/TitanClassicVariables.lua +++ b/TitanClassic/TitanClassicVariables.lua @@ -295,7 +295,7 @@ TITAN_ALL_SAVED_VARIABLES = { -- Silent Load Silenced = false, -- OrderHallCommandBar Status - OrderHall = true, + --OrderHall = true, }; -- The skins released with Titan diff --git a/TitanClassic/TitanPanelClassic.lua b/TitanClassic/TitanPanelClassic.lua index bc2f540..67b8ff4 100644 --- a/TitanClassic/TitanPanelClassic.lua +++ b/TitanClassic/TitanPanelClassic.lua @@ -370,7 +370,7 @@ function TitanPanel_PlayerEnteringWorld() elseif TitanGetVar(TITAN_CLOCK_ID, "Format") then ServerHourFormat[realmName] = TitanGetVar(TITAN_CLOCK_ID, "Format") end - +--[[ -- Check to see if we should kill off the OrderHallCommandBar if not TitanAllGetVar("OrderHall") then local TitanPanelAce = LibStub("AceAddon-3.0"):NewAddon("TitanPanelOHCB", "AceHook-3.0") @@ -387,7 +387,7 @@ function TitanPanel_PlayerEnteringWorld() local TitanPanelAce = LibStub("AceAddon-3.0"):NewAddon("TitanPanelOHCB", "AceHook-3.0") TitanPanelAce:Unhook("OrderHall_CheckCommandBar") end - +--]] end local _ = nil TitanSettings.Player,_,_ = TitanUtils_GetPlayer() @@ -650,10 +650,12 @@ local function handle_slash_help(cmd) TitanPrint(L["TITAN_PANEL_SLASH_SILENT_0"], "plain") TitanPrint(L["TITAN_PANEL_SLASH_SILENT_1"], "plain") end +--[[ if cmd == "orderhall" then TitanPrint(L["TITAN_PANEL_SLASH_ORDERHALL_0"], "plain") TitanPrint(L["TITAN_PANEL_SLASH_ORDERHALL_1"], "plain") end +--]] if cmd == "help" then TitanPrint(L["TITAN_PANEL_SLASH_HELP_0"], "plain") TitanPrint(L["TITAN_PANEL_SLASH_HELP_1"], "plain") @@ -879,8 +881,8 @@ local function TitanPanel_RegisterSlashCmd(cmd_str) handle_profile_cmds(cmd_list) elseif (cmd == "silent") then handle_silent_cmds(p1) - elseif (cmd == "orderhall") then - handle_orderhall_cmds(p1) +-- elseif (cmd == "orderhall") then +-- handle_orderhall_cmds(p1) elseif (cmd == "help") then handle_slash_help(p1) else diff --git a/TitanClassicAmmo/TitanClassicAmmo.lua b/TitanClassicAmmo/TitanClassicAmmo.lua index 74a6331..769d581 100644 --- a/TitanClassicAmmo/TitanClassicAmmo.lua +++ b/TitanClassicAmmo/TitanClassicAmmo.lua @@ -1,3 +1,4 @@ +--[[ -- ************************************************************************** -- * TitanAmmo.lua -- * @@ -5,33 +6,96 @@ -- ************************************************************************** -- 2019 Aug - reverted and updated for Classic -- --- This will track the number of ammo (bows and guns) or thrown (knives) the character --- has. +-- This will track the count of ammo (bows and guns) or thrown (knives) equipped. -- Ammo is placed in the 'ammo' slot where Blizzard counts ALL of that *type of ammo* -- regardless of where it is in your bags. --- Thrown is placed in the actual weapon slot where Blizzard counts ALL of that *type of thrown* --- as being in that slot. --- The difference forces a different routine to be used. This causes the routine to always check --- which is being used. +-- Thrown is placed in the actual weapon slot where Blizzard counts ALL of that *type of thrown*. +-- This forces a different routine to be used so the ammo must always be checked for type and count. +--]] -- ******************************** Constants ******************************* local _G = getfenv(0); local TITAN_AMMO_ID = "Ammo"; -local TITAN_AMMO_THRESHOLD_TABLE = { - Values = { 150, 300, 500 }, - Colors = { RED_FONT_COLOR, ORANGE_FONT_COLOR, NORMAL_FONT_COLOR, HIGHLIGHT_FONT_COLOR }, -} + +local SHOOT_STACK = 250 +local ARROW_STACK = 200 +local THROW_STACK = 100 + +local LIM_GOOD = 2 +local LIM_OK = 1.5 +local LIM_BAD = .5 + +local TITAN_AMMO_THRESHOLD_TABLE = { -- Use ammo stack and threshold limits above to calc colored text + ["INVTYPE_RANGEDRIGHT"] = { + Values = { SHOOT_STACK*LIM_BAD, SHOOT_STACK*LIM_OK, SHOOT_STACK*LIM_GOOD }, -- 125,375,500 + Colors = { RED_FONT_COLOR, ORANGE_FONT_COLOR, NORMAL_FONT_COLOR, HIGHLIGHT_FONT_COLOR }, + }, + ["INVTYPE_RANGED"] = { + Values = { ARROW_STACK*LIM_BAD, ARROW_STACK*LIM_OK, ARROW_STACK*LIM_GOOD }, -- 100,150,400 + Colors = { RED_FONT_COLOR, ORANGE_FONT_COLOR, NORMAL_FONT_COLOR, HIGHLIGHT_FONT_COLOR }, + }, + ["INVTYPE_THROWN"] = { + Values = { THROW_STACK*LIM_BAD, THROW_STACK*LIM_OK, THROW_STACK*LIM_GOOD }, -- 50,150,400 + Colors = { RED_FONT_COLOR, ORANGE_FONT_COLOR, NORMAL_FONT_COLOR, HIGHLIGHT_FONT_COLOR }, + }, +}; -- ******************************** Variables ******************************* local class = select(2, UnitClass("player")) local ammoSlotID = GetInventorySlotInfo("AmmoSlot") local rangedSlotID = GetInventorySlotInfo("RangedSlot") -local count = 0; -local isThrown = nil; -local isAmmo = nil; -local currentlink = ""; -local AmmoName = ""; +local ammo_count = 0; +local ammo_type = ""; +local ammo_name = "" +local ammo_link = ""; +local ammo_show = false -- show plugin based on class + local L = LibStub("AceLocale-3.0"):GetLocale("TitanClassic", true) -- ******************************** Functions ******************************* +local function ClrAmmoInfo() + ammo_count = 0; + ammo_type = ""; + ammo_name = "" + ammo_link = ""; + ammo_show = false +end +local function GetItemLink(rangedSlotID) + return GetInventoryItemLink("player", rangedSlotID) +end +local function IsThrown(loc) + local res = false + if loc == "INVTYPE_THROWN" then + res = true + end + return res +end +local function IsAmmo(loc) + local res = false + if loc == "INVTYPE_RANGED" or loc == "INVTYPE_RANGEDRIGHT" then + res = true + end + return res +end +local function GetAmmoItemInfo(rangedSlotID) + local loc = ""; + local itemlink = GetItemLink(rangedSlotID) + + if itemlink then + loc = select(9, GetItemInfo(itemlink)) + end + return itemlink, loc +end +local function GetAmmoCount(ammo_type) + if IsThrown(ammo_type) then + ammo_count = GetInventoryItemCount("player", rangedSlotID) or ammo_count + ammo_name = select(1, GetItemInfo(GetInventoryItemID("player", rangedSlotID))) or _G["UNKNOWN"] + elseif IsAmmo(ammo_type) then --and GetInventoryItemLink("player", ammoSlotID) + ammo_count = GetInventoryItemCount("player", ammoSlotID) or ammo_count + ammo_name = select(1, GetItemInfo(GetInventoryItemID("player", ammoSlotID))) or _G["UNKNOWN"] + else + ClrAmmoInfo() + end +end + -- ************************************************************************** -- NAME : TitanPanelAmmoButton_OnLoad() @@ -72,7 +136,7 @@ function TitanPanelAmmoButton_OnLoad(self) TitanPanelAmmoButton_UPDATE_INVENTORY_DURABILITY() elseif event == "MERCHANT_CLOSED" or event == "PLAYER_ENTERING_WORLD" then TitanPanelAmmoButton_MERCHANT_CLOSED() - elseif event == "ACTIONBAR_HIDEGRID" then + elseif event == "ACTIONBAR_HIDEGRID" then -- in case ammo is dropped into char slot TitanPanelAmmoButton_ACTIONBAR_HIDEGRID() end end) @@ -84,24 +148,28 @@ function TitanPanelAmmoButton_PLAYER_LOGIN() -- Class check if class ~= "ROGUE" and class ~= "WARRIOR" and class ~= "HUNTER" then TitanPanelAmmoButton_PLAYER_LOGIN = nil + ammo_show = true return end ---TitanDebug("TitanPanelAmmoButton_PLAYER_LOGIN") - local itemlink = GetInventoryItemLink("player", rangedSlotID) - currentlink = itemlink; - local loc = ""; - if itemlink then - loc = select(9, GetItemInfo(itemlink)) - end - if loc == "INVTYPE_THROWN" then + ammo_show = true + local itemlink, loc = GetAmmoItemInfo(rangedSlotID) + ammo_link = itemlink; + ammo_type = loc + GetAmmoCount(ammo_type) +--[[ +TitanDebug("TitanPanelAmmoButton_PLAYER_LOGIN" +.." "..tostring(ammo_type) +.." "..tostring(ammo_count) +.." "..tostring(IsThrown(ammo_type)) +.." "..tostring(IsAmmo(ammo_type)) +.." "..tostring(TITAN_AMMO_THRESHOLD_TABLE[ammo_type].Values[1]) +) +--]] + if IsThrown(ammo_type) then TitanPanelAmmoButton:RegisterEvent("UPDATE_INVENTORY_DURABILITY") - isThrown = true; - isAmmo = nil; - elseif loc == "INVTYPE_RANGED" or loc == "INVTYPE_RANGEDRIGHT" then + elseif IsAmmo(ammo_type) then TitanPanelAmmoButton:RegisterEvent("ACTIONBAR_HIDEGRID") - isAmmo = true; - isThrown = nil; end TitanPanelAmmoButton:RegisterEvent("UNIT_INVENTORY_CHANGED") TitanPanelAmmoButton:RegisterEvent("MERCHANT_CLOSED") @@ -109,108 +177,70 @@ function TitanPanelAmmoButton_PLAYER_LOGIN() TitanPanelAmmoButton_PLAYER_LOGIN = nil end - function TitanPanelAmmoButton_UNIT_INVENTORY_CHANGED(arg1, ...) - if arg1 == "player" then - TitanPanelAmmoUpdateDisplay(); - if isThrown then - count = GetInventoryItemCount("player", rangedSlotID) or count - elseif isAmmo then --and GetInventoryItemLink("player", ammoSlotID) - count = GetInventoryItemCount("player", ammoSlotID) or count - -- AmmoName = GetItemInfo(GetInventoryItemLink("player", ammoSlotID)) or _G["UNKNOWN"] - else - --isThrown = nil; - count = 0; - AmmoName = ""; + if arg1 == "player" then + TitanPanelAmmoUpdateDisplay(); + GetAmmoCount(ammo_type) + TitanPanelButton_UpdateButton(TITAN_AMMO_ID); end - TitanPanelButton_UpdateButton(TITAN_AMMO_ID); - end end function TitanPanelAmmoButton_UPDATE_INVENTORY_DURABILITY() - count = GetInventoryItemCount("player", rangedSlotID) or count -- GetInventoryItemDurability(rangedSlotID) or count + ammo_count = GetInventoryItemCount("player", rangedSlotID) or ammo_count -- GetInventoryItemDurability(rangedSlotID) or ammo_count TitanPanelButton_UpdateButton(TITAN_AMMO_ID); end function TitanPanelAmmoButton_MERCHANT_CLOSED() - if isThrown then - count = GetInventoryItemCount("player", rangedSlotID) or count - elseif isAmmo then --and GetInventoryItemLink("player", ammoSlotID) - count = GetInventoryItemCount("player", ammoSlotID) or count - -- AmmoName = GetItemInfo(GetInventoryItemLink("player", ammoSlotID)) or _G["UNKNOWN"] - else - count = 0; - AmmoName = ""; - end + GetAmmoCount(ammo_type) TitanPanelButton_UpdateButton(TITAN_AMMO_ID); end - function TitanPanelAmmoButton_ACTIONBAR_HIDEGRID() local prev = 0 TitanPanelAmmoButton:SetScript("OnUpdate", function(_, e) prev = prev + e if prev > 2 then TitanPanelAmmoButton:SetScript("OnUpdate", nil) - count = GetInventoryItemCount("player", ammoSlotID) or count + ammo_count = GetInventoryItemCount("player", ammoSlotID) or ammo_count TitanPanelButton_UpdateButton(TITAN_AMMO_ID); end end) end - function TitanPanelAmmoUpdateDisplay() -- Manual Display update in case the rangedSlot it switched - local itemlink = GetInventoryItemLink("player", rangedSlotID) - local loc = ""; + local itemlink, loc = GetAmmoItemInfo(rangedSlotID) - if itemlink == currentlink then + if itemlink == ammo_link then return else - currentlink = itemlink + ammo_link = itemlink end - if itemlink then - loc = select(9, GetItemInfo(itemlink)) - end - if loc == "INVTYPE_THROWN" then + ammo_type = loc + GetAmmoCount(ammo_type) - if TitanPanelAmmoButton:IsEventRegistered("ACTIONBAR_HIDEGRID") then - TitanPanelAmmoButton:UnregisterEvent("ACTIONBAR_HIDEGRID") - TitanPanelAmmoButton:SetScript("OnUpdate", nil) - end - - if not TitanPanelAmmoButton:IsEventRegistered("UPDATE_INVENTORY_DURABILITY") then + -- Setup the events based on ammo type + if IsThrown(ammo_type) then + if not TitanPanelAmmoButton:IsEventRegistered("UPDATE_INVENTORY_DURABILITY") then TitanPanelAmmoButton:RegisterEvent("UPDATE_INVENTORY_DURABILITY") end - - isThrown = true; - isAmmo = nil; - count = GetInventoryItemCount("player", rangedSlotID) or count --- count = GetInventoryItemDurability(rangedSlotID); - - elseif loc == "INVTYPE_RANGED" or loc == "INVTYPE_RANGEDRIGHT" then - + if TitanPanelAmmoButton:IsEventRegistered("ACTIONBAR_HIDEGRID") then + TitanPanelAmmoButton:UnregisterEvent("ACTIONBAR_HIDEGRID") + TitanPanelAmmoButton:SetScript("OnUpdate", nil) + end + elseif IsAmmo(ammo_type) then if TitanPanelAmmoButton:IsEventRegistered("UPDATE_INVENTORY_DURABILITY") then TitanPanelAmmoButton:UnregisterEvent("UPDATE_INVENTORY_DURABILITY") end - if not TitanPanelAmmoButton:IsEventRegistered("ACTIONBAR_HIDEGRID") then TitanPanelAmmoButton:RegisterEvent("ACTIONBAR_HIDEGRID") end - - isAmmo = true; - isThrown = nil; - count = GetInventoryItemCount("player", ammoSlotID) - else - count = 0; - AmmoName = ""; end TitanPanelButton_UpdateButton(TITAN_AMMO_ID); end - -- ************************************************************************** -- NAME : TitanPanelAmmoButton_GetButtonText(id) -- DESC : Calculate ammo/thrown logic then display data on button @@ -218,35 +248,38 @@ end -- ************************************************************************** function TitanPanelAmmoButton_GetButtonText(id) - local labelText, ammoText, ammoRichText, color; - - -- safeguard to prevent malformed labels - if not count then count = 0 end - - if (isThrown) then - labelText = L["TITAN_AMMO_BUTTON_LABEL_THROWN"]; - ammoText = format(L["TITAN_AMMO_FORMAT"], count); - elseif (isAmmo) then - labelText = L["TITAN_AMMO_BUTTON_LABEL_AMMO"]; - ammoText = format(L["TITAN_AMMO_FORMAT"], count); - if TitanGetVar(TITAN_AMMO_ID, "ShowAmmoName") and AmmoName ~= "" then - ammoText = ammoText.."|cffffff9a".." ("..AmmoName..")".."|r" - end - else - count = 0; - labelText = L["TITAN_AMMO_BUTTON_LABEL_AMMO_THROWN"]; - ammoText = L["TITAN_AMMO_BUTTON_NOAMMO"]; - end - - - if (TitanGetVar(TITAN_AMMO_ID, "ShowColoredText")) then - color = TitanUtils_GetThresholdColor(TITAN_AMMO_THRESHOLD_TABLE, count); - ammoRichText = TitanUtils_GetColoredText(ammoText, color); - else - ammoRichText = TitanUtils_GetHighlightText(ammoText); - end + local labelText, ammoText, ammoRichText, color; + + if not ammo_count then -- safeguard to prevent malformed labels + ClrAmmoInfo() + end + + if (IsThrown(ammo_type)) then + labelText = L["TITAN_AMMO_BUTTON_LABEL_THROWN"]; + ammoText = format(L["TITAN_AMMO_FORMAT"], ammo_count); + if TitanGetVar(TITAN_AMMO_ID, "ShowAmmoName") and ammo_name ~= "" then + ammoText = ammoText.."|cffffff9a".." ("..ammo_name..")".."|r" + end + elseif (IsAmmo(ammo_type)) then + labelText = L["TITAN_AMMO_BUTTON_LABEL_AMMO"]; + ammoText = format(L["TITAN_AMMO_FORMAT"], ammo_count); + if TitanGetVar(TITAN_AMMO_ID, "ShowAmmoName") and ammo_name ~= "" then + ammoText = ammoText.."|cffffff9a".." ("..ammo_name..")".."|r" + end + else + ClrAmmoInfo(); + labelText = L["TITAN_AMMO_BUTTON_LABEL_AMMO_THROWN"]; + ammoText = L["TITAN_AMMO_BUTTON_NOAMMO"]; + end + + if (TitanGetVar(TITAN_AMMO_ID, "ShowColoredText")) then + color = TitanUtils_GetThresholdColor(TITAN_AMMO_THRESHOLD_TABLE[ammo_type], ammo_count); + ammoRichText = TitanUtils_GetColoredText(ammoText, color); + else + ammoRichText = TitanUtils_GetHighlightText(ammoText); + end - return labelText, ammoRichText; + return labelText, ammoRichText; end -- ************************************************************************** -- 1.7.9.5