WoWInterface SVN ChatProfiles

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /trunk
    from Rev 6 to Rev 7
    Reverse comparison

Rev 6 → Rev 7

ChatProfiles.toc File deleted \ No newline at end of file
Bindings.xml File deleted \ No newline at end of file
ChatProfiles.lua File deleted \ No newline at end of file
ChatProfiles/Bindings.xml New file
0,0 → 1,11
<Bindings>
<Binding name="CHATPROFILES_AUTO_TOGGLE" header="CHATPROFILES_HEADER">
ChatProfiles_ToggleAuto();
</Binding>
<Binding name="CHATPROFILES_AUTO_ON">
ChatProfiles_AutoOn();
</Binding>
<Binding name="CHATPROFILES_AUTO_OFF">
ChatProfiles_AutoOff();
</Binding>
</Bindings>
\ No newline at end of file
ChatProfiles/ChatProfiles.lua New file
0,0 → 1,365
 
local ChatProfiles_Defaults = {
["ChatWindowProfiles"] = {
["default6"] = {
["messages"] = {
},
["channels"] = {
},
},
["default3"] = {
["messages"] = {
},
["channels"] = {
},
},
["default5"] = {
["messages"] = {
},
["channels"] = {
},
},
["default2"] = {
["messages"] = {
"OPENING", -- [1]
"TRADESKILLS", -- [2]
"PET_INFO", -- [3]
"COMBAT_XP_GAIN", -- [4]
"COMBAT_HONOR_GAIN", -- [5]
"COMBAT_MISC_INFO", -- [6]
},
["channels"] = {
},
},
["default4"] = {
["messages"] = {
},
["channels"] = {
},
},
["default7"] = {
["messages"] = {
},
["channels"] = {
},
},
["default1"] = {
["messages"] = {
"SYSTEM", -- [1]
"SYSTEM_NOMENU", -- [2]
"SAY", -- [3]
"EMOTE", -- [4]
"YELL", -- [5]
"WHISPER", -- [6]
"PARTY", -- [7]
"RAID", -- [8]
"RAID_LEADER", -- [9]
"RAID_WARNING", -- [10]
"BATTLEGROUND", -- [11]
"BATTLEGROUND_LEADER", -- [12]
"GUILD", -- [13]
"GUILD_OFFICER", -- [14]
"MONSTER_SAY", -- [15]
"MONSTER_YELL", -- [16]
"MONSTER_EMOTE", -- [17]
"MONSTER_WHISPER", -- [18]
"MONSTER_BOSS_EMOTE", -- [19]
"MONSTER_BOSS_WHISPER", -- [20]
"ERRORS", -- [21]
"AFK", -- [22]
"DND", -- [23]
"IGNORED", -- [24]
"BG_HORDE", -- [25]
"BG_ALLIANCE", -- [26]
"BG_NEUTRAL", -- [27]
"COMBAT_FACTION_CHANGE", -- [28]
"SKILL", -- [29]
"LOOT", -- [30]
"MONEY", -- [31]
"CHANNEL", -- [32]
"ACHIEVEMENT", -- [33]
"GUILD_ACHIEVEMENT", -- [34]
},
["channels"] = {
},
},
},
["auto"] = false,
["currentProfile"]="default",
["showChat"]=true,
["GlobalProfiles"] = {
["default"] = {
"default1", -- [1]
"default2", -- [2]
"default3", -- [3]
"default4", -- [4]
"default5", -- [5]
"default6", -- [6]
"default7", -- [7]
},
},
};
 
local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
 
local frame = CreateFrame("FRAME","ChatProfilesFrame")
frame:RegisterEvent("ADDON_LOADED")
frame:RegisterEvent("PARTY_MEMBERS_CHANGED")
 
local UnknownIconPath = "Interface\\Icons\\INV_Misc_QuestionMark"
local OnIconPath ="Interface\\Icons\\INV_Jewelry_Ring_64"
local OffIconPath ="Interface\\Icons\\INV_Jewelry_Ring_65"
 
local ldbstream = ldb:NewDataObject("ChatProfiles",{type = "data source", icon = UnknownIconPath, label="ChatProfiles", text = ""})
 
BINDING_HEADER_CHATPROFILES_HEADER = "ChatProfiles"
BINDING_NAME_CHATPROFILES_AUTO_TOGGLE = "Toggle Auto"
BINDING_NAME_CHATPROFILES_AUTO_ON = "Set Auto on"
BINDING_NAME_CHATPROFILES_AUTO_OFF = "Set Auto off"
 
 
CHATPROFILES_LOADED = false;
 
--taken from http://www.wowwiki.com/Extracting_info_from_a_slash_command#Parsing_Into_Tables, 2009-04-01
local function MsgToTable( msg )
if not msg then return end
local t = {};
gsub( msg, "%S+", function(w)
tinsert( t, w )
end)
return t;
end
 
 
local function ChatMessage(msg, show)
show = show or false
if ChatProfiles.showChat or show then
DEFAULT_CHAT_FRAME:AddMessage("|cff99BBEEChatProfiles:|r "..msg)
end
end
 
local function LDBAutoChanged()
if ChatProfiles.auto then
ldbstream.icon = OnIconPath
else
ldbstream.icon = OffIconPath
end
end
 
local function LDBProfileChanged()
ldbstream.text = ChatProfiles.currentProfile
end
 
local function DisableAuto()
ChatProfiles.auto = false;
ChatMessage("Auto is now |cffAA0033off|r")
LDBAutoChanged()
end
 
function LoadChatWindowProfile(chatFrame, profile)
ChatFrame_RemoveAllMessageGroups(chatFrame);
ChatFrame_RemoveAllChannels(chatFrame);
for i=1,#profile["messages"] do
ChatFrame_AddMessageGroup(chatFrame, profile["messages"][i]);
end
for i=1,#profile["channels"] do
ChatFrame_AddChannel(chatFrame, profile["channels"][i]);
end
end
 
local function CreateGlobalProfile(profileName)
ChatProfiles.GlobalProfiles[profileName]={};
for i=1,7 do
local messages = { GetChatWindowMessages(i)};
local channels = { GetChatWindowChannels(i)};
local channels2={};
for i=1,#channels do
if i%2==1 then
local value = floor(i/2)+1;
channels2[value] = channels[i];
end
end
ChatProfiles.ChatWindowProfiles[profileName..i]={["messages"]=messages,["channels"]=channels2};
ChatProfiles.GlobalProfiles[profileName][i] = profileName..i;
end
if profileName ~= "lastprofile" then ChatMessage("A profile named '"..profileName.."' has been created",true) end
end
 
local function LoadGlobalProfile(profileName)
if ChatProfiles.GlobalProfiles[profileName]==nil then
ChatMessage("No profile named '"..profileName.."' loading 'default' instead",true);
LoadGlobalProfile("default");
DisableAuto();
else
if profileName ~= "lastprofile" then CreateGlobalProfile("lastprofile") end
for i in pairs(ChatProfiles.GlobalProfiles[profileName]) do
LoadChatWindowProfile(getglobal("ChatFrame"..i),ChatProfiles.ChatWindowProfiles[ChatProfiles.GlobalProfiles[profileName][i]]);
end
if profileName ~= "lastprofile" then ChatMessage("Profile '"..profileName.."' has been loaded, get last profile with /cp last")
else ChatMessage("Last profile has been loaded") end
ChatProfiles.currentProfile=profileName;
end
end
 
local function UpdateGlobalProfile()
if ChatProfiles.auto then
if GetNumRaidMembers()>0 then
if ChatProfiles.currentProfile ~="raid" then
LoadGlobalProfile("raid");
end
elseif GetNumPartyMembers()>0 then
if ChatProfiles.currentProfile ~="party" then
LoadGlobalProfile("party");
end
else
if ChatProfiles.currentProfile ~="solo" then
LoadGlobalProfile("solo");
end
end
end
LDBAutoChanged()
LDBProfileChanged()
end
 
-- local function DeleteGlobalProfile(profileName)
-- if (profileName == "default" or profileName == "lastprofile") then
-- ChatMessage("You can't delete profile '"..profileName.."'");
-- else
-- tremove(ChatProfiles.GlobalProfiles,profileName);
-- for i=1,7 do
-- tremove(ChatProfiles.ChatWindowProfiles,profileName..i);
-- end
-- ChatMessage("Profile '"..profileName.."' has been deleted");
-- end
-- end
 
local function SetAuto(state)
ChatProfiles.auto = state;
ChatMessage("Auto is now "..(state and "|cff339911on|r" or "|cffAA0033off|r"));
UpdateGlobalProfile();
end
 
local function ToggleAuto()
SetAuto(not ChatProfiles.auto)
end
 
local function ChatProfiles_SlashCommandHandler(msg)
if msg == "auto" then
ChatMessage("Auto is "..(ChatProfiles.auto and "|cff339911on|r" or "|cffAA0033off|r"),true)
elseif msg == "auto on" then
SetAuto(true);
elseif msg == "auto off" then
SetAuto(false);
elseif msg == "auto toggle" then
ToggleAuto();
 
elseif msg == "auto chat" then
ChatProfiles.showChat = not ChatProfiles.showChat
ChatMessage(ChatProfiles.showChat and "Now sending text to chat" or "No longer sending text to chat, type '/cp auto chat' to revert",true)
 
elseif msg == "last" then
LoadGlobalProfile("lastprofile");
SetAuto(false);
 
elseif msg == "profiles" then
local text="Profiles\n";
for v in pairs(ChatProfiles.GlobalProfiles) do
if v == ChatProfiles.currentProfile then
text=text.."|cff77BBEE"..v.."|r\n"
else
text=text..v.."\n"
end
end
ChatMessage(text,true);
elseif msg == "current" then
ChatMessage("Current profile is '"..ChatProfiles.currentProfile.."'",true);
 
elseif msg == "frames" then
local text ="Frame Name : #\n";
for i=1,7 do text=text..GetChatWindowInfo(i)..": "..i.."\n" end
ChatMessage(text,true);
elseif msg == "store" then
ChatMessage("/cp store profileName",true);
elseif msg == "load" then
ChatMessage("/cp load profileName",true);
else
msg = MsgToTable(msg);
if #msg==2 then
if msg[1] == "store" then
CreateGlobalProfile(msg[2]);
elseif msg[1] == "load" then
LoadGlobalProfile(msg[2]);
SetAuto(false);
-- elseif msg[1] == "delete" then
-- DeleteGlobalProfile(msg[2]);
end
else
--No match found, return standard phrase
ChatMessage("/cp <command>\n<command>: auto [/on/off/toggle/chat], last, current, profiles, frames, store, load",true);
end
end
end
 
--Public Functions
 
function ChatProfiles_ToggleAuto()
ToggleAuto()
end
function ChatProfiles_AutoOn()
SetAuto(true)
end
function ChatProfiles_AutoOff()
SetAuto(false)
end
 
 
function ldbstream:OnTooltipShow()
self:AddLine("Profiles:")
local text="";
for v in pairs(ChatProfiles.GlobalProfiles) do
if v == ChatProfiles.currentProfile then
text=text.."|cff77BBEE"..v.."|r\n"
else
text=text.."|cffffffff"..v.."|r\n"
end
end
self:AddLine(text)
self:AddLine("Auto: "..(ChatProfiles.auto and "|cff339911on|r" or "|cffAA0033off|r"));
end
 
function ldbstream:OnEnter()
GameTooltip:SetOwner(self, "ANCHOR_NONE")
GameTooltip:SetPoint("TOPLEFT", self, "BOTTOMLEFT")
GameTooltip:ClearLines()
ldbstream.OnTooltipShow(GameTooltip)
GameTooltip:Show()
end
 
function ldbstream:OnLeave()
GameTooltip:Hide()
end
 
function ldbstream:OnClick(self, button)
ToggleAuto()
end
 
 
local function OnEvent(self, event, ...)
if event=="ADDON_LOADED" and arg1 == "ChatProfiles" then
if ChatProfiles == nil then
ChatProfiles = ChatProfiles_Defaults;
end
CHATPROFILES_LOADED = true;
DEFAULT_CHAT_FRAME:AddMessage("|cff99BBEEChatProfiles|r loaded successfully! Auto is "..(ChatProfiles.auto and "|cff339911on|r" or "|cffAA0033off|r"));
UpdateGlobalProfile();
elseif event=="PARTY_MEMBERS_CHANGED" and CHATPROFILES_LOADED then
--ChatMessage("Party!");
UpdateGlobalProfile();
end
end
 
frame:SetScript("OnEvent", OnEvent);
 
SLASH_CHATPROFILES1 = "/chatprofiles";
SLASH_CHATPROFILES2 = "/cp";
SlashCmdList["CHATPROFILES"] = function (msg) ChatProfiles_SlashCommandHandler(msg) end;
\ No newline at end of file
ChatProfiles/ChatProfiles.toc New file
0,0 → 1,16
## Interface: 30000
## Title: ChatProfiles
## Notes: Changes chat profiles based on events.
## Author: Nitra - Nagrand (EU)
## X-eMail: niteniten58@gmail.com
## X-Embeds: CallbackHandler-1.0, LibStub
## Version: 0.3
## DefaultState: Enabled
## LoadOnDemand: 0
## SavedVariablesPerCharacter: ChatProfiles
 
libs\LibStub\LibStub.lua
libs\CallbackHandler-1.0\CallbackHandler-1.0.lua
libs\LibDataBroker-1.1\LibDataBroker-1.1.lua
 
ChatProfiles.lua
\ No newline at end of file