Skip to content
This repository has been archived by the owner on Jul 25, 2023. It is now read-only.

Commit

Permalink
[+] New Addon: Colored Item Names
Browse files Browse the repository at this point in the history
Colorizes item names everywhere based on the item's grade/rarity (not stars). Also colors any set pieces green and colors any recipes by their crafted item's rarity instead of their own rarity.
  • Loading branch information
TehSeph committed May 12, 2016
1 parent 6048226 commit 6485c1b
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 0 deletions.
96 changes: 96 additions & 0 deletions addons/coloreditemnames/coloreditemnames.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
function COLOREDITEMNAMES.getItemRarityColor(itemObj)

local itemProp = geItemTable.GetProp(itemObj.ClassID);
local grade = itemObj.ItemGrade;

if (itemObj.ItemType == "Recipe") then
-- Thank you Mie for these next four lines. Great suggestion! :)
local recipeGrade = string.match(itemObj.Icon, "misc(%d)");
if recipeGrade ~= nil then
grade = tonumber(recipeGrade) - 1;
end
end

if (itemProp.setInfo ~= nil) then return "00FF00"; -- set piece
elseif (grade == 1) then return "FFFFFF"; -- common
elseif (grade == 2) then return "108CFF"; -- rare
elseif (grade == 3) then return "9F30FF"; -- epic
elseif (grade == 4) then return "FF4F00"; -- legendary
end

return "FFFFFF"; -- no grade (non-equipment items)

end

function COLOREDITEMNAMES.getColoredName(itemClass, ...)

local nameString = _G["GET_FULL_NAME_OLD"](itemClass, ...);
local itemColor = COLOREDITEMNAMES.getItemRarityColor(itemClass);

return string.format("{#%s}{ol}%s{/}{/}", itemColor, nameString);

end

function COLOREDITEMNAMES.linkItem(invItem)
-- Same as the original, with `GET_FULL_NAME` kept to use `GET_FULL_NAME_OLD`.
-- Shortend a few lines, but mostly still IMC's code. Blame them if it breaks. :P

local chatFrame = GET_CHATFRAME();
local editCtrl = GET_CHILD(chatFrame, "mainchat", "ui::CEditControl");

local itemObj = GetIES(invItem:GetObject());
local itemClassID = itemObj.ClassID;

local itemName = _G["GET_FULL_NAME_OLD"](itemObj);

local imgName = GET_ITEM_ICON_IMAGE(itemObj);
local imgTag = string.format("{img %s %d %d}", imgName, editCtrl:GetHeight(), editCtrl:GetHeight());

local properties = "";

if (itemObj.ClassName == "Scroll_SkillItem") then
local skillClass = GetClassByType("Skill", itemObj.SkillType)
itemName = itemName .. "(" .. skillClass.Name ..")";
properties = GetSkillItemProperiesString(itemObj);
else
properties = GetModifiedProperiesString(itemObj);
end

if (properties == "") then properties = 'nullval'; end

local linkString = string.format("{a SLI %s %d}{#0000FF}%s%s{/}{/}{/}", properties, itemClassID, imgTag, itemName);
SET_LINK_TEXT(linkString);

end

function COLOREDITEMNAMES.setHooks(newFunction, oldFunction)
-- This is the SET_HOOK function directly from Excrulon's utility.lua

local storedFunction = oldFunction .. "_OLD";

if _G[storedFunction] == nil then
_G[storedFunction] = _G[oldFunction];
_G[oldFunction] = newFunction;
else
_G[oldFunction] = newFunction;
end

end

function COLOREDITEMNAMES.init()

if (COLOREDITEMNAMES.isLoaded ~= true) then

COLOREDITEMNAMES.setHooks(COLOREDITEMNAMES.getColoredName, "GET_FULL_NAME");
COLOREDITEMNAMES.setHooks(COLOREDITEMNAMES.linkItem, "LINK_ITEM_TEXT");

COLOREDITEMNAMES.frame:ShowWindow(1);
COLOREDITEMNAMES.isLoaded = true;

ui.SysMsg("[ADDON] Colored Item Names loaded!");

end

end

COLOREDITEMNAMES.init();
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
if _G["ADDONS"] == nil then _G["ADDONS"] = {}; end

_G["ADDONS"]["COLOREDITEMNAMES"] = {};
COLOREDITEMNAMES = _G["ADDONS"]["COLOREDITEMNAMES"];

function COLOREDITEMNAMES_ON_INIT(addon, frame)

COLOREDITEMNAMES.addon = addon;
COLOREDITEMNAMES.frame = frame;

dofile("../addons/coloreditemnames/coloreditemnames.lua");

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<uiframe name="coloreditemnames" x="420" y="30" width="280" height="100" create="open">
<frame title="Reload Addon" snapclient="true" snapframe="true" layout_gravity="top left" margin="420 30 0 0"/>
<option visible="true" closebutton="false" useimageitem="true" piptype="right" autoopen="true" hideable="false"/>
<input hittestframe="true"/>
<layer layerlevel="31"/>
<draw blend="100" drawtitlebar="false" drawframe="false"/>
<controls>
<button name="open_changejobui" rect="0 0 240 80" margin="0 0 0 0" layout_gravity="center center" MouseOffAnim="btn_mouseoff" MouseOnAnim="btn_mouseover" caption="{@st43}Reload Addon" clicksound="button_click_3" oversound="button_cursor_over_2" skin="btn_lv3" LBtnDownScp="dofile(&apos;..\\addons\\coloreditemnames.lua&apos;);">
<uieffect effect="I_screen_button" scale="63" overlab="No" sound="None" offset="0 0" playtime="1" duration="1" conditon="active" event="LBUTTONDOWN"/>
</button>
</controls>
</uiframe>

0 comments on commit 6485c1b

Please sign in to comment.