diff --git a/Changelog b/Changelog new file mode 100644 index 0000000..fe037e0 --- /dev/null +++ b/Changelog @@ -0,0 +1,7 @@ +Changelog + +v0.2 + - Fixed 'Research Trait from Item' window error + - Display integers, ignore fractions + - Minor cosmetic fixes + \ No newline at end of file diff --git a/MathUtils.lua b/MathUtils.lua index e7fc3a3..bdc8902 100644 --- a/MathUtils.lua +++ b/MathUtils.lua @@ -6,9 +6,11 @@ local MathUtils = {} PriceTracker.mathUtils = MathUtils function MathUtils:WeightedAverage(itemTable) - for item in itemTable do - sum = sum + item.purchasePrice - weight = weight + item.stackCount + local sum = 0 + local weight = 0 + for i = 1, #itemTable do + sum = sum + itemTable[i].purchasePrice + weight = weight + itemTable[i].stackCount end return math.floor(sum / weight) end diff --git a/PriceTracker.lua b/PriceTracker.lua index 7b84133..2e29ddd 100644 --- a/PriceTracker.lua +++ b/PriceTracker.lua @@ -6,7 +6,9 @@ PriceTracker = { queryDelay = 3000, isSearching = false, settingsVersion = 0.1, - mathUtils = MathUtils + icons = { + gold = "EsoUI/Art/currency/currency_gold.dds" + } } local PriceTracker = PriceTracker @@ -37,9 +39,6 @@ function PriceTracker:OnLoad(eventCode, addOnName) PriceTracker.button:SetParent(ZO_TradingHouseLeftPaneBrowseItemsCommon) PriceTracker.button:SetWidth(ZO_TradingHouseLeftPaneBrowseItemsCommonQuality:GetWidth()) - -- Create a money icon - -- PriceTracker.moneyIcon = ItemTooltip:CreateControl("moneyIcon", CT_TEXTURE) - end -- Handle slash commands @@ -77,8 +76,10 @@ function PriceTracker:OnUpdateTooltip(item) ZO_Tooltip_AddDivider(ItemTooltip) ItemTooltip:AddLine("Price Tracker", "ZoFontHeader2") local r, g, b = ZO_TOOLTIP_DEFAULT_COLOR:UnpackRGB() - ItemTooltip:AddLine("Suggested Price:", "ZoFontGame", r, g, b, TOPLEFT, MODIFY_TEXT_TYPE_NONE, LEFT, false) - ItemTooltip:AddLine(self:FormatTooltipLine(price, item.dataEntry.data.stackCount or item.dataEntry.data.stack), "ZoFontGame", r, g, b, LEFT, MODIFY_TEXT_TYPE_NONE, CENTER, false) + ItemTooltip:AddLine("Suggested Price: |r", "ZoFontGame", r, g, b, TOPLEFT, MODIFY_TEXT_TYPE_NONE, LEFT, false) + -- ItemTooltip:AddLine(self:FormatTooltipLine(price, item.dataEntry.data.stackCount or item.dataEntry.data.stack), "ZoFontGame", r, g, b, LEFT, MODIFY_TEXT_TYPE_NONE, CENTER, false) + ItemTooltip:AddLine(self:FormatTooltipLine("Item price: ", price, item.dataEntry.data.stackCount or item.dataEntry.data.stack), "ZoFontGame", r, g, b, LEFT, MODIFY_TEXT_TYPE_NONE, CENTER, false) + ItemTooltip:AddLine(self:FormatTooltipLine("Stack price: ", price * item.dataEntry.data.stackCount or item.dataEntry.data.stack), "ZoFontGame", r, g, b, LEFT, MODIFY_TEXT_TYPE_NONE, CENTER, false) end function PriceTracker:OnHideTooltip() @@ -171,19 +172,12 @@ function PriceTracker:SuggestPrice(itemName) end PriceTracker.matches = matches - - local sum = 0 - local weight = 0 - for i = 1, #matches do - sum = sum + matches[i].purchasePrice - weight = weight + matches[i].stackCount - end - return sum / weight - -- return PriceTracker.mathUtils:WeightedAverage(matches) + return PriceTracker.mathUtils:WeightedAverage(matches) end -function PriceTracker:FormatTooltipLine(price, stackCount) - return string.format("%7s|t16:16:%s|t %-25s %7s|t16:16:%s|t %-25s", price, "EsoUI/Art/currency/currency_gold.dds", "(per item)", price * stackCount, "EsoUI/Art/currency/currency_gold.dds", "(stack of " .. stackCount .. ")") +function PriceTracker:FormatTooltipLine(title, price, stackCount) + -- return string.format("%7s%s %-10s %7s%s %-10s", price, zo_iconFormat(PriceTracker.icons.gold, 16, 16), "(each)", price * stackCount, zo_iconFormat(PriceTracker.icons.gold, 16, 16), "(stack)") + return string.format("%-30s %7s%s", title, price, zo_iconFormat(PriceTracker.icons.gold, 16, 16)) end function PriceTracker:NormalizeName(name) diff --git a/PriceTracker.txt b/PriceTracker.txt index 597fc7c..06b6478 100644 --- a/PriceTracker.txt +++ b/PriceTracker.txt @@ -4,6 +4,6 @@ ## SavedVariables: PriceTrackerSettings ## APIVersion: 100004 -MathUtils.lua PriceTracker.lua PriceTracker.xml +MathUtils.lua