-- Addon: WoWTR Cataclysm-Bubbles v4.00 2024/05/03
-- Description: AddOn displays translated Bubbled of NPC.
-- Autor: Platine, Hakan YILMAZ
-- (e-mail: platine.wow@gmail.com)
-- WWW: https://www.wowtr.com.tr

local BB_version = GetAddOnMetadata("WoWTR_Cataclysm", "Version");
local BB_ctrFrame = CreateFrame("FRAME", "WoWTR Cataclysm-BubblesFrame");
local BB_Font = QTR_Font2;
local BB_name;
local BB_class;
local BB_race;
local BB_BubblesArray = {};
local p_race = {};
local p_class = {};
local player_race = {};
local player_class = {};
local BB_TRvisible= 0;
local BB_Zatrzask = 0;
local BB_name_NPC = "";
local BB_hash_Code= "";
local BB_bufor = {};
local BB_gotowe= {};
local BB_ile_got = 0;
local Y_Race1=UnitRace("player");
local Y_Race2=string.lower(UnitRace("player"));
local Y_Race3=string.upper(UnitRace("player"));
local Y_Class1=UnitClass("player");
local Y_Class2=string.lower(UnitClass("player"));
local Y_Class3=string.upper(UnitClass("player"));


local function StringHash(text)           -- funkcja tworząca Hash (32-bitowa liczba) podanego tekstu
  local counter = 1;
  local pomoc = 0;
  local dlug = string.len(text);
  for i = 1, dlug, 3 do 
    counter = math.fmod(counter*8161, 4294967279);  -- 2^32 - 17: Prime!
    pomoc = (string.byte(text,i)*16776193);
    counter = counter + pomoc;
    pomoc = ((string.byte(text,i+1) or (dlug-i+256))*8372226);
    counter = counter + pomoc;
    pomoc = ((string.byte(text,i+2) or (dlug-i+256))*3932164);
    counter = counter + pomoc;
  end
  return math.fmod(counter, 4294967291) -- 2^32 - 5: Prime (and different from the prime in the loop)
end


local function BB_bubblizeText()
   for _, bubble in pairs(C_ChatBubbles.GetAllChatBubbles()) do
   -- Iterate the children, as the actual bubble content 
   -- has been placed in a nameless subframe in 9.0.1.
      for i = 1, bubble:GetNumChildren() do
         local child = select(i, select(i, bubble:GetChildren()))
         if not child:IsForbidden() then                       -- czy ramka nie jest zabroniona?
            if (child:GetObjectType() == "Frame") and (child.String) and (child.Center) then
            -- This is hopefully the frame with the content
               for i = 1, child:GetNumRegions() do
                  local region = select(i, child:GetRegions());
                  for idx, iArray in ipairs(BB_BubblesArray) do      -- sprawdź, czy dane są właściwe (tekst oryg. się zgadza z zapisaną w tablicy)
                     if region and not region:GetName() and region:IsVisible() and region.GetText and region:GetText() == iArray[1] then
                        local oldTextWidth = region:GetStringWidth() -- dotychczasowa szerokość okna dymku
                        region:SetText(iArray[2]);                   -- wpisz tu nasze tłumaczenie
                        local _font1, _size1, _3 = region:GetFont(); -- odczytaj aktualną czcionkę i rozmiar
                        region:SetFont(BB_Font, _size1);             -- ustaw polską czcionkę oraz niezmienioną wielkość (13)
                        -- region:SetWidth(region:GetWidth()+(region:GetStringWidth() - oldTextWidth));  -- określ nową szer. okna
                        tremove(BB_BubblesArray, idx);               -- usuń zapamiętane dane z tablicy
                     end
                  end
               end
            end
         end
      end
   end
  for idx, iArray in ipairs(BB_BubblesArray) do            -- przeszukaj jeszcze raz tablicę
     if (iArray[3] >= 100) then                            -- licznik osiągnął 100
        tremove(BB_BubblesArray, idx);                     -- usuń zapamiętane dane z tablicy
     else
        iArray[3] = iArray[3]+1;                           -- zwiększ licznik (nie pokazał się dymek?)
     end;
  end;
  if (#(BB_BubblesArray) == 0) then
     BB_ctrFrame:SetScript("OnUpdate", nil);               -- wyłącz metodę Update, bo tablica pusta
  end;
end;


local function ChatFilter(self, event, arg1, arg2, arg3, _, arg5, ...)     -- wywoływana, gdy na chat ma pojawić się tekst od NPC
   local changeBubble = false;
   local colorText = "";
   local original_txt = strtrim(arg1);
   local name_NPC = string.gsub(arg2, " says:", "");
   local target = arg5;
	
   if (event == "CHAT_MSG_MONSTER_SAY") then          -- określ kolor tekstu do okna chat
      colorText = "|cFFFFFF9F";
      if (GetCVar("ChatBubbles")) then
         changeBubble = true;
      end
   elseif (event == "CHAT_MSG_MONSTER_PARTY") then
      colorText = "|cFFAAAAFF";
   elseif (event == "CHAT_MSG_MONSTER_YELL") then
      colorText = "|cFFFF4040";
      if (GetCVar("ChatBubbles")) then
         changeBubble = true;
      end
   elseif (event == "CHAT_MSG_MONSTER_WHISPER") then
      colorText = "|cFFFFB5EB";
   elseif (event == "CHAT_MSG_MONSTER_EMOTE") then
      colorText = "|cFFFF8040";
   end

   BB_is_translation="0";      
   if (BB_PM["active"] == "1") then                       -- dodatek aktywny - szukaj tłumaczenia
      if (arg5 ~= "") then
         original_txt = string.gsub(original_txt, arg5, "");        -- usuń osobę ($target) z tekstu oryginalnego
      end
      original_txt = string.gsub(original_txt, Y_Race1, "");        -- usuń rasę z tekstu
      original_txt = string.gsub(original_txt, Y_Race2, "");
      original_txt = string.gsub(original_txt, Y_Race3, "");
      original_txt = string.gsub(original_txt, Y_Class1, "");       -- usuń klasę z tekstu
      original_txt = string.gsub(original_txt, Y_Class2, "");
      original_txt = string.gsub(original_txt, Y_Class3, "");
      local HashCode = StringHash(original_txt);
      if (BB_Bubbles[HashCode]) then         -- jest tłumaczenie polskie
         newMessage = BB_Bubbles[HashCode];
		 newMessage = BB_ZmienKody(newMessage,arg5);
         BB_is_translation="1";      
         nr_poz=BB_FindProS(newMessage,1);
         if (BB_PM["chat-pl"] == "1") then                -- wyświetlaj tłumaczenie w linii czatu
            if (nr_poz>0) then           -- mamy formę opisową dymku %s np. NPC_name wpada w szał!
               if (nr_poz==1) then
                  newMessage = name_NPC..strsub(newMessage, 3);
               else
                  newMessage = strsub(newMessage,1,nr_poz-1)..name_NPC..strsub(newMessage, nr_poz+2);
               end
               DEFAULT_CHAT_FRAME:AddMessage(colorText..newMessage);
            elseif (strsub(newMessage,1,2)=="%o") then         -- jest forma '%o'
               newMessage = strsub(newMessage, 3);
               DEFAULT_CHAT_FRAME:AddMessage(colorText..newMessage:gsub("^%s*", "")); -- usuń białe spacje na początku
            else
               DEFAULT_CHAT_FRAME:AddMessage(colorText..name_NPC..": "..newMessage);
            end
         else   
            if (nr_poz>0) then        -- mamy formę opisową dymku np. NPC_name coś robi.
               if (nr_poz==1) then
                  newMessage = name_NPC..strsub(newMessage, 3);
               else
                  newMessage = strsub(newMessage,1,nr_poz-1)..name_NPC..strsub(newMessage, nr_poz+2);
               end
            elseif (strsub(newMessage,1,2)=="%o") then         -- jest forma '%o'
               newMessage = strsub(newMessage, 3);
            end
         end
         if (changeBubble) then                          -- wyświetlaj dymek po polsku (jeśli istnieje)
            tinsert(BB_BubblesArray, { [1] = arg1, [2] = newMessage, [3] = 1 });
            BB_ctrFrame:SetScript("OnUpdate", BB_bubblizeText);
         end
      else                                               -- nie mamy tłumaczenia
         if (BB_PM["saveNB"] == "1") then                -- zapisz oryginalny tekst
            original_txt = strtrim(arg1);
            BB_PS[name_NPC..":"..tostring(HashCode)] = original_txt.."@"..target;
         end
         if (BB_PM["TRonline"] == "1") then              -- tłumaczenie online
            local pomoc = name_NPC.."@"..tostring(HashCode).."@"..original_txt;
            local jest = 0;
            for ind=1,BB_ile_got,1 do             -- sprawdź czy taki dymek jest już w gotowych
               if (BB_gotowe[ind] == pomoc) then
                  jest = 1;
               end
            end
            if (jest == 0) then
               if (BB_Zatrzask == 0) then                   -- bufor pusty
                  BB_Input1:SetText(original_txt);
                  BB_Input2:SetText("");
                  BB_Zatrzask = 1;
                  BB_ButtonZatrz:SetText("X");
                  BB_name_NPC = name_NPC;
                  BB_hash_Code= tostring(HashCode);
                  BB_bufor[BB_Zatrzask] = name_NPC.."@"..tostring(HashCode).."@"..original_txt;
               else
                  for ind=1,BB_Zatrzask,1 do             -- sprawdź czy jest już taki dymek w buforze
                     if (BB_bufor[ind] == pomoc) then
                        jest = 1;
                     end
                  end
                  if (jest == 0) then        -- nie ma jeszcze w buforze
                     BB_Zatrzask = BB_Zatrzask + 1;
                     BB_bufor[BB_Zatrzask] = pomoc;
                     BB_ButtonZatrz:SetText(tostring(BB_Zatrzask));
                  end
               end
            end
         end
      end
   end

   if ((BB_PM["chat-en"] == "1") or (BB_is_translation ~= "1")) then     -- gdy nie ma także tłumaczenia                 
      return false;     -- wyświetlaj tekst oryginalny w oknie czatu
   else
      return true;      -- nie wyświetla oryginalnego tekstu
   end   
   
end


   function BB_ZmienKody(message,target)
   if ((target == nil) or (target == "")) then                     -- może być zmienna $target w tłumaczeniu
      target = BB_name;
   end
   message = string.gsub(message, "$n$", string.upper(target));    -- i trzeba ją zamienić na nazwę gracza
   message = string.gsub(message, "$N$", string.upper(target));    -- tu jeszcze pisane DUŻYMI LITERAMI
   message = string.gsub(message, "$n", target);
   message = string.gsub(message, "$N", target);
   message = string.gsub(message, "$target", target);
   message = string.gsub(message, "$TARGET", target);
   
   message = string.gsub(message, "$g", "$G");     -- obsługa kodu $g(m;ż)
   local BB_forma = "";
   local nr_1, nr_2, nr_3 = 0;
   local nr_poz = string.find(message, "$G");    -- gdy nie znalazł, jest: nil; liczy od 1
   while (nr_poz and nr_poz>0) do
      nr_1 = nr_poz + 1;   
      while (string.sub(message, nr_1, nr_1) ~= "(") do   -- szukaj nawiasu otwierającego
         nr_1 = nr_1 + 1;
      end
      if (string.sub(message, nr_1, nr_1) == "(") then
         nr_2 =  nr_1 + 1;
         while (string.sub(message, nr_2, nr_2) ~= ";") do   -- szukaj średnika oddzielającego
            nr_2 = nr_2 + 1;
         end
         if (string.sub(message, nr_2, nr_2) == ";") then
            nr_3 = nr_2 + 1;
            while (string.sub(message, nr_3, nr_3) ~= ")") do   -- szukaj nawiasu zamykającego
               nr_3 = nr_3 + 1;
            end
            if (string.sub(message, nr_3, nr_3) == ")") then
               if (target==BB_name) then          -- wypowiedź kierowana do gracza
                  if (BB_PM["sex"]=="4") then         -- wypowiedzi wyświetlaj w formie zależnej od płci postaci
                     if (player_sex==3) then          -- postać płci żeńskiej
                        BB_forma = string.sub(message,nr_2+1,nr_3-1);
                     else                             -- postać płci męskiej
                        BB_forma = string.sub(message,nr_1+1,nr_2-1);
                     end
                  elseif (BB_PM["sex"]=="3") then         -- wypowiedzi wyświetlaj w formie żeńskiej
                     BB_forma = string.sub(message,nr_2+1,nr_3-1);
                  else                                -- wypowiedzi wyświetlaj w formie męskiej
                     BB_forma = string.sub(message,nr_1+1,nr_2-1);
                  end
               else
                  BB_forma = string.sub(message,nr_1+1,nr_2-1);    -- wypowiedź do kogoś innego - forma męska
               end
               message = string.sub(message,1,nr_poz-1) .. BB_forma .. string.sub(message,nr_3+1);
            end   
         end
      end
      nr_poz = string.find(message, "$G");
   end
   
   message = string.gsub(message, "$r", "$R");  
   message = string.gsub(message, "$c", "$C");    
   if ((BB_PM["sex"]=="3") or ((BB_PM["sex"]=="4") and (player_sex=="3"))) then       -- gracz gra kobietą lub postać jest żeńska
      message = string.gsub(message, "$R1", player_race.M2);
      message = string.gsub(message, "$R2", player_race.D2);
      message = string.gsub(message, "$R3", player_race.C2);
      message = string.gsub(message, "$R4", player_race.B2);
      message = string.gsub(message, "$R5", player_race.N2);
      message = string.gsub(message, "$R6", player_race.K2);
      message = string.gsub(message, "$R7", player_race.W2);
      message = string.gsub(message, "$R", player_race.M2);
      message = string.gsub(message, "$C1", player_class.M2);
      message = string.gsub(message, "$C2", player_class.D2);
      message = string.gsub(message, "$C3", player_class.C2);
      message = string.gsub(message, "$C4", player_class.B2);
      message = string.gsub(message, "$C5", player_class.N2);
      message = string.gsub(message, "$C6", player_class.K2);
      message = string.gsub(message, "$C7", player_class.W2);
      message = string.gsub(message, "$C", player_class.M2);
   else                          -- gracz gra facetem
      message = string.gsub(message, "$R1", player_race.M1);
      message = string.gsub(message, "$R2", player_race.D1);
      message = string.gsub(message, "$R3", player_race.C1);
      message = string.gsub(message, "$R4", player_race.B1);
      message = string.gsub(message, "$R5", player_race.N1);
      message = string.gsub(message, "$R6", player_race.K1);
      message = string.gsub(message, "$R7", player_race.W1);
      message = string.gsub(message, "$R", player_race.M1);
      message = string.gsub(message, "$C1", player_class.M1);
      message = string.gsub(message, "$C2", player_class.D1);
      message = string.gsub(message, "$C3", player_class.C1);
      message = string.gsub(message, "$C4", player_class.B1);
      message = string.gsub(message, "$C5", player_class.N1);
      message = string.gsub(message, "$C6", player_class.K1);
      message = string.gsub(message, "$C7", player_class.W1);
      message = string.gsub(message, "$C", player_class.M1);
   end
   return message;   
end


function BB_FindProS(text)                 -- znajdź, czy jest tekst '%s' w podanym tłumaczeniu
   local dl_txt = string.len(text)-1;
   for i_j=1,dl_txt,1 do
      if (strsub(text,i_j,i_j+1)=="%s") then       
         return i_j;
      end
   end
   return 0;
end


function BB_CheckVars()
  if (not BB_PM) then
     BB_PM = {};
  end
  if (not BB_PS) then
     BB_PS = {};
  end
  if (not BB_TR) then
     BB_TR = {};
  end
  -- initialize check options
  if (not BB_PM["active"] ) then    -- dodatek aktywny
     BB_PM["active"] = "1";   
  end
  if (not BB_PM["chat-en"] ) then   -- pokaż tekst angielski w oknie czatu
     BB_PM["chat-en"] = "0";   
  end
  if (not BB_PM["chat-pl"] ) then   -- pokaż tekst polski w oknie czatu
     BB_PM["chat-pl"] = "1";   
  end
  if (not BB_PM["saveNB"] ) then    -- zapisz nieprzetłumaczone dymki
     BB_PM["saveNB"] = "1";   
  end
  if (not BB_PM["setsize"] ) then   -- uaktywnij zmiany wielkości czcionki
     BB_PM["setsize"] = "0";   
  end
  if (not BB_PM["fontsize"] ) then  -- wielkość czcionki
     BB_PM["fontsize"] = "13";   
  end
  if (not BB_PM["TRonline"] ) then  -- przycisk okna tłumaczenia on-line
     BB_PM["TRonline"] = "0";   
  end
end
  

function BB_SetCheckButtonState()
  BBCheckButton1:SetChecked(BB_PM["active"]=="1");
  BBCheckButton2:SetChecked(BB_PM["chat-en"]=="1");
  BBCheckButton3:SetChecked(BB_PM["chat-pl"]=="1");
  -- BBCheckButton5:SetChecked(BB_PM["saveNB"]=="1");
  -- BBCheckButton8:SetChecked(BB_PM["TRonline"]=="1");
  -- BBCheckSize:SetChecked(BB_PM["setsize"]=="1");
  -- local fontsize = tonumber(BB_PM["fontsize"]);
  -- BBslider:SetValue(fontsize);
  -- if (BB_PM["setsize"]=="1") then
     -- BBOpis1:SetFont(BB_Font, fontsize);
  -- else   
     -- BBOpis1:SetFont(BB_Font, 13);
  -- end
end


function BB_BlizzardOptions()

-- Create main frame for information text
local BBOptions = CreateFrame("FRAME", "WoWTRBubblesOptions");
BBOptions.name = "WoWTR Cataclysm-Bubbles";
BBOptions.refresh = function (self) BB_SetCheckButtonState() end;
BBOptions:SetScript("OnShow", function (self) BB_SetCheckButtonState() end);

  -- Yeni ekleme yöntemi
  if Settings and Settings.RegisterCanvasLayoutCategory then
    local Category = Settings.RegisterCanvasLayoutCategory(BBOptions, "WoWTR Cataclysm-Bubbles")
    Settings.RegisterAddOnCategory(Category)
  elseif InterfaceOptions_AddCategory then
    InterfaceOptions_AddCategory(BBOptions);
  end

local BBOptionsHeader = BBOptions:CreateFontString(nil, "ARTWORK");
BBOptionsHeader:SetFontObject(GameFontNormalLarge);
BBOptionsHeader:SetJustifyH("LEFT"); 
BBOptionsHeader:SetJustifyV("TOP");
BBOptionsHeader:ClearAllPoints();
BBOptionsHeader:SetPoint("TOPLEFT", 16, -16);
BBOptionsHeader:SetText("WoWTR Cataclysm Bubbles, ver. "..BB_version.." by Platine, hknylmz © 2024");



local BBCheckButton1 = CreateFrame("CheckButton", "BBCheckButton1", BBOptions, "UICheckButtonTemplate");
BBCheckButton1:SetPoint("TOPLEFT", BBOptionsHeader, "BOTTOMLEFT", 0, -30);
BBCheckButton1:SetScript("OnClick", function(self) if (BB_PM["active"]=="1") then BB_PM["active"]="0" else BB_PM["active"]="1" end; end);
BBCheckButton1Text:SetText("Eklentiyi etkinleştir");     -- dodatek aktywny
BBCheckButton1Text:SetFont(BB_Font, 13);

local BBCheckButton2 = CreateFrame("CheckButton", "BBCheckButton2", BBOptions, "UICheckButtonTemplate");
BBCheckButton2:SetPoint("TOPLEFT", BBCheckButton1, "BOTTOMLEFT", 0, -5);
BBCheckButton2:SetScript("OnClick", function(self) if (BB_PM["chat-en"]=="1") then BB_PM["chat-en"]="0" else BB_PM["chat-en"]="1" end; end);
BBCheckButton2Text:SetText("Sohbet penceresinde orijinal metni görüntüle");
BBCheckButton2Text:SetFont(BB_Font, 13);

local BBCheckButton3 = CreateFrame("CheckButton", "BBCheckButton3", BBOptions, "UICheckButtonTemplate");
BBCheckButton3:SetPoint("TOPLEFT", BBCheckButton2, "BOTTOMLEFT", 0, 0);
BBCheckButton3:SetScript("OnClick", function(self) if (BB_PM["chat-pl"]=="1") then BB_PM["chat-pl"]="0" else BB_PM["chat-pl"]="1" end; end);
BBCheckButton3Text:SetText("Çeviri metnini sohbet penceresinde görüntüle"); 
BBCheckButton3Text:SetFont(BB_Font, 13);

  local BBDISCORD = BBOptions:CreateFontString(nil, "ARTWORK");
  BBDISCORD:SetFontObject(GameFontWhite);
  BBDISCORD:SetJustifyH("LEFT");
  BBDISCORD:SetJustifyV("TOP");
  BBDISCORD:ClearAllPoints();
  BBDISCORD:SetPoint("TOPLEFT", BBOptionsHeader, "BOTTOMLEFT", 0, -450);
  BBDISCORD:SetFont(QTR_Font2, 13);
  BBDISCORD:SetText("Discord Adresimiz:");
  
  local BBDISCORD2 = CreateFrame("EditBox", "BBDISCORD2", BBOptions, "InputBoxTemplate");
  BBDISCORD2:ClearAllPoints();
  BBDISCORD2:SetPoint("TOPLEFT", BBDISCORD, "LEFT", 5, -10);
  BBDISCORD2:SetHeight(20);
  BBDISCORD2:SetWidth(210);
  BBDISCORD2:SetAutoFocus(false);
  BBDISCORD2:SetFontObject(GameFontGreen);
  BBDISCORD2:SetText("https://discord.gg/PEknRSqEQ7");
  BBDISCORD2:SetCursorPosition(0);
  BBDISCORD2:SetScript("OnEnter", function(self)
	  GameTooltip:SetOwner(self, "ANCHOR_TOPRIGHT")
      getglobal("GameTooltipTextLeft1"):SetFont(QTR_Font2, 13);
  	  GameTooltip:SetText(QTR_Reklama.WWW3, nil, nil, nil, nil, true)
	  GameTooltip:Show() --Show the tooltip
     end);
  BBDISCORD2:SetScript("OnLeave", function(self)
      getglobal("GameTooltipTextLeft1"):SetFont(Original_Font2, 13);
	  GameTooltip:Hide() --Hide the tooltip
     end);
  BBDISCORD2:SetScript("OnTextChanged", function(self) BBDISCORD2:SetText("https://discord.gg/PEknRSqEQ7"); end);


local BBWWW1 = BBOptions:CreateFontString(nil, "ARTWORK");
BBWWW1:SetFontObject(GameFontWhite);
BBWWW1:SetJustifyH("LEFT");
BBWWW1:SetJustifyV("TOP");
BBWWW1:ClearAllPoints();
BBWWW1:SetPoint("TOPLEFT", BBDISCORD, "BOTTOMLEFT", 0, -40);
BBWWW1:SetFont(BB_Font, 13);
BBWWW1:SetText("WoWTR Web Sayfamız:");
  
local BBWWW2 = CreateFrame("EditBox", "BBWWW2", BBOptions, "InputBoxTemplate");
BBWWW2:ClearAllPoints();
BBWWW2:SetPoint("TOPLEFT", BBWWW1, "LEFT", 5, -10);
BBWWW2:SetHeight(20);
BBWWW2:SetWidth(210);
BBWWW2:SetAutoFocus(false);
BBWWW2:SetFontObject(GameFontGreen);
BBWWW2:SetText("https://www.wowtr.com.tr");
BBWWW2:SetCursorPosition(0);
BBWWW2:SetScript("OnEnter", function(self)
   GameTooltip:SetOwner(self, "ANCHOR_TOPRIGHT")
   getglobal("GameTooltipTextLeft1"):SetFont(BB_Font, 13);
   GameTooltip:SetText("tıklayın ve panoya kopyalamak için Ctrl+C tuşlarına basın", nil, nil, nil, nil, true)
   GameTooltip:Show() --Show the tooltip
   end);
BBWWW2:SetScript("OnLeave", function(self)
   GameTooltip:Hide() --Hide the tooltip
   end);
BBWWW2:SetScript("OnTextChanged", function(self) BBWWW2:SetText("https://www.wowtr.com.tr"); end);
end


function BB_SlashCommand(msg)
  -- check the command
  if (msg) then
     local BB_command = string.lower(msg);                -- normalizacja, tylko małe litery
     if ((BB_command=="on") or (BB_command=="1")) then    -- włącz przełącznik aktywności
        BB_PM["active"]="1";
        DEFAULT_CHAT_FRAME:AddMessage("|cffffff00WoWTR Cataclysm-Bubbles şimdi aktif");
     elseif ((BB_command=="off") or (BB_command=="0")) then
        BB_PM["active"]="0";
        DEFAULT_CHAT_FRAME:AddMessage("|cffffff00WoWTR Cataclysm-Bubbles artık etkin değil");
     else
        InterfaceOptionsFrame_Show();
        InterfaceOptionsFrame_OpenToCategory("WoWTR Cataclysm-Bubbles");
     end   
  end
end


function BB_ShowTRonline()
   if (BB_TRvisible == 0) then
      BB_TRvisible = 1;
      BB_Button8Save:Show();
      BB_Input1:Show();
      BB_Input2:Show();
      BB_ButtonZatrz:Show();
   else
      BB_TRvisible = 0;
      BB_Button8Save:Hide();
      BB_Input1:Hide();
      BB_Input2:Hide();
      BB_ButtonZatrz:Hide();
   end   
end


function BB_TRzatrzask()                  -- wciśnięto przycisk zwolnienia zatrzasku
   if (BB_Zatrzask > 0) then
      BB_Zatrzask = BB_Zatrzask - 1;
      if (BB_Zatrzask == 0) then
         BB_ButtonZatrz:SetText("O");
      else
         for ind=1,BB_Zatrzask,1 do
            BB_bufor[ind] = BB_bufor[ind+1];
         end
         BB_bufor[BB_Zatrzask+1] = "";
         local p1,p2,p3 = strsplit("@",BB_bufor[1]);
         BB_Input1:SetText(p3);
         if (BB_Zatrzask == 1) then
            BB_ButtonZatrz:SetText("X");
         else
            BB_ButtonZatrz:SetText(tostring(BB_Zatrzask));
         end
      end
   else   
      BB_Input1:SetText("Tercüme edilmemiş balondan orijinal metni bekliyorum");
   end
   BB_Input2:SetText("");
end
  

function BB_ShowTRsave()
   if (BB_Input2:GetText() == "") then
      BB_Input2:SetText("?? - ve çeviri nerede - ??");
   else
      local p1,p2,p3 = strsplit("@",BB_bufor[1]);
      BB_TR[p1.."@"..p2] = BB_Input1:GetText().."@"..BB_Input2:GetText();
      BB_Input2:SetText("Tamam - çeviri kaydedildi");
      BB_Input1:SetText("Tercüme edilmemiş balondan orijinal metni bekliyorum");
      BB_ile_got = BB_ile_got + 1;
      BB_gotowe[BB_ile_got] = BB_bufor[1];
      BB_TRzatrzask();
   end
end

  
function BB_OknoTRonline()
  BB_TRframe = CreateFrame("Frame","DragFrame1", UIParent);
  BB_TRframe:SetMovable(true);
  BB_TRframe:EnableMouse(true);
  BB_TRframe:RegisterForDrag("LeftButton");
  BB_TRframe:SetScript("OnDragStart", BB_TRframe.StartMoving);
  BB_TRframe:SetScript("OnDragStop", BB_TRframe.StopMovingOrSizing);

  BB_TRframe:SetWidth(500);
  BB_TRframe:SetHeight(46);
  BB_TRframe:ClearAllPoints();
  BB_TRframe:SetPoint("TOPLEFT", UIParent, "TOPLEFT", 250, 0);
  if (BB_PM["TRonline"] == "1") then
     BB_TRframe:Show();
  else
     BB_TRframe:Hide();
  end;
--local tex = BB_TRframe:CreateTexture("ARTWORK");
--tex:SetAllPoints();
--tex:SetTexture(1.0,0.5,0); tex:SetAlpha(0.5);

  BB_Button8 = CreateFrame("Button",nil, BB_TRframe, "UIPanelButtonTemplate");
  BB_Button8:SetWidth(60);
  BB_Button8:SetHeight(20);
  BB_Button8:SetText("BBTR");
  BB_Button8:ClearAllPoints();
  BB_Button8:SetPoint("TOPLEFT", BB_TRframe, "TOPLEFT", 3, -3);
  BB_Button8:SetScript("OnClick", BB_ShowTRonline);
  if (BB_PM["TRonline"] == "1") then
     BB_Button8:Show();
  end;

  BB_Button8Save = CreateFrame("Button",nil, BB_TRframe, "UIPanelButtonTemplate");
  BB_Button8Save:SetWidth(60);
  BB_Button8Save:SetHeight(20);
  BB_Button8Save:SetText("Zapisz");
  BB_Button8Save:ClearAllPoints();
  BB_Button8Save:SetPoint("TOPLEFT", BB_Button8, "BOTTOMLEFT", 0, 1);
  BB_Button8Save:SetScript("OnClick", BB_ShowTRsave);
  BB_Button8Save:Hide();

  BB_Input1 = CreateFrame("EditBox", "BB_Input1", BB_TRframe, "InputBoxTemplate");
  BB_Input1:ClearAllPoints();
  BB_Input1:SetPoint("TOPLEFT", BB_Button8, "TOPRIGHT", 4, 0);
  BB_Input1:SetHeight(20);
  BB_Input1:SetWidth(400);
  BB_Input1:SetAutoFocus(false);
  BB_Input1:SetFontObject(GameFontGreen);
  BB_Input1:SetText("işte orijinal metin");
  BB_Input1:SetCursorPosition(0);
  BB_Input1:Hide();
  
  BB_Input2 = CreateFrame("EditBox", "BB_Input2", BB_TRframe, "InputBoxTemplate");
  BB_Input2:ClearAllPoints();
  BB_Input2:SetPoint("TOPLEFT", BB_Button8Save, "TOPRIGHT", 4, 0);
  BB_Input2:SetHeight(20);
  BB_Input2:SetWidth(400);
  BB_Input2:SetAutoFocus(false);
  BB_Input2:SetFontObject(GameFontWhite);
  BB_Input2:SetText("ve işte Türkçe çevirisi");
  BB_Input2:SetCursorPosition(0);
  BB_Input2:Hide();
  
  BB_ButtonZatrz = CreateFrame("Button",nil, BB_TRframe, "UIPanelButtonTemplate");
  BB_ButtonZatrz:SetWidth(30);
  BB_ButtonZatrz:SetHeight(20);
  BB_ButtonZatrz:SetText("O");
  BB_ButtonZatrz:ClearAllPoints();
  BB_ButtonZatrz:SetPoint("TOPLEFT", BB_Input1, "TOPRIGHT", -1, 0);
  BB_ButtonZatrz:SetScript("OnClick", BB_TRzatrzask);
  BB_ButtonZatrz:Hide();

end

  
function BB_ExpandUnitInfo(msg)
   local target = UnitName("player");
   message = string.gsub(msg, "$n$", string.upper(target));        -- i trzeba ją zamienić na nazwę gracza
   message = string.gsub(message, "$N$", string.upper(target));    -- tu jeszcze pisane DUŻYMI LITERAMI
   message = string.gsub(message, "$n", target);
   message = string.gsub(message, "$N", target);
   message = string.gsub(message, "$target", target);
   message = string.gsub(message, "$TARGET", target);
   
   message = string.gsub(message, "$g", "$G");     -- obsługa kodu $g(m;ż)
   local BB_forma = "";
   local nr_1, nr_2, nr_3 = 0;
   local nr_poz = string.find(message, "$G");    -- gdy nie znalazł, jest: nil; liczy od 1
   while (nr_poz and nr_poz>0) do
      nr_1 = nr_poz + 1;   
      while (string.sub(message, nr_1, nr_1) ~= "(") do   -- szukaj nawiasu otwierającego
         nr_1 = nr_1 + 1;
      end
      if (string.sub(message, nr_1, nr_1) == "(") then
         nr_2 =  nr_1 + 1;
         while (string.sub(message, nr_2, nr_2) ~= ";") do   -- szukaj średnika oddzielającego
            nr_2 = nr_2 + 1;
         end
         if (string.sub(message, nr_2, nr_2) == ";") then
            nr_3 = nr_2 + 1;
            while (string.sub(message, nr_3, nr_3) ~= ")") do   -- szukaj nawiasu zamykającego
               nr_3 = nr_3 + 1;
            end
            if (string.sub(message, nr_3, nr_3) == ")") then
               if (target==player_name) then          -- wypowiedź kierowana do gracza
                  if (BB_PM["sex"]=="4") then         -- wypowiedzi wyświetlaj w formie zależnej od płci postaci
                     if (player_sex==3) then          -- postać płci żeńskiej
                        BB_forma = string.sub(message,nr_2+1,nr_3-1);
                     else                             -- postać płci męskiej
                        BB_forma = string.sub(message,nr_1+1,nr_2-1);
                     end
                  elseif (BB_PM["sex"]=="3") then         -- wypowiedzi wyświetlaj w formie żeńskiej
                     BB_forma = string.sub(message,nr_2+1,nr_3-1);
                  else                                -- wypowiedzi wyświetlaj w formie męskiej
                     BB_forma = string.sub(message,nr_1+1,nr_2-1);
                  end
               else
                  BB_forma = string.sub(message,nr_1+1,nr_2-1);    -- wypowiedź do kogoś innego - forma męska
               end
               message = string.sub(message,1,nr_poz-1) .. BB_forma .. string.sub(message,nr_3+1);
            end   
         end
      end
      nr_poz = string.find(message, "$G");
   end
   
-- jeszcze obsłużyć nazwy własne $O(EN;PL)
   message = string.gsub(message, "$o", "$O");   -- obsługa kodu $o(EN;PL)
   local nr_1, nr_2, nr_3 = 0;
   local BB_forma = "";
   local nr_poz = string.find(message, "$O");    -- gdy nie znalazł, jest: nil
   while (nr_poz and nr_poz>0) do
      nr_1 = nr_poz + 1;   
      while (string.sub(message, nr_1, nr_1) ~= "(") do
         nr_1 = nr_1 + 1;
      end
      if (string.sub(message, nr_1, nr_1) == "(") then
         nr_2 =  nr_1 + 1;
         while (string.sub(message, nr_2, nr_2) ~= ";") do
            nr_2 = nr_2 + 1;
         end
         if (string.sub(message, nr_2, nr_2) == ";") then
            nr_3 = nr_2 + 1;
            while (string.sub(message, nr_3, nr_3) ~= ")") do
               nr_3 = nr_3 + 1;
            end
            if (string.sub(message, nr_3, nr_3) == ")") then
--               if (BB_PM["ownname"] == "1") then        -- forma polska
--                  BB_forma = string.sub(message,nr_2+1,nr_3-1);
--               else                                     -- forma angielska
                  BB_forma = string.sub(message,nr_1+1,nr_2-1);
--               end
               message = string.sub(message,1,nr_poz-1) .. BB_forma .. string.sub(message,nr_3+1);
            end   
         end
      end
      nr_poz = string.find(message, "$O");
   end

   message = string.gsub(message, "$r", "$R");  
   message = string.gsub(message, "$c", "$C");    
   local player_sex = UnitSex("player");     -- 1:neutral,  2:męski,  3:żeński
   if ((player_sex=="3") or (player_sex=="4")) then       -- gracz gra kobietą lub postać jest żeńska
      message = string.gsub(message, "$R1", player_race.M2);
      message = string.gsub(message, "$R2", player_race.D2);
      message = string.gsub(message, "$R3", player_race.C2);
      message = string.gsub(message, "$R4", player_race.B2);
      message = string.gsub(message, "$R5", player_race.N2);
      message = string.gsub(message, "$R6", player_race.K2);
      message = string.gsub(message, "$R7", player_race.W2);
      message = string.gsub(message, "$R", player_race.M2);
      message = string.gsub(message, "$C1", player_class.M2);
      message = string.gsub(message, "$C2", player_class.D2);
      message = string.gsub(message, "$C3", player_class.C2);
      message = string.gsub(message, "$C4", player_class.B2);
      message = string.gsub(message, "$C5", player_class.N2);
      message = string.gsub(message, "$C6", player_class.K2);
      message = string.gsub(message, "$C7", player_class.W2);
      message = string.gsub(message, "$C", player_class.M2);
   else                          -- gracz gra facetem
      message = string.gsub(message, "$R1", player_race.M1);
      message = string.gsub(message, "$R2", player_race.D1);
      message = string.gsub(message, "$R3", player_race.C1);
      message = string.gsub(message, "$R4", player_race.B1);
      message = string.gsub(message, "$R5", player_race.N1);
      message = string.gsub(message, "$R6", player_race.K1);
      message = string.gsub(message, "$R7", player_race.W1);
      message = string.gsub(message, "$R", player_race.M1);
      message = string.gsub(message, "$C1", player_class.M1);
      message = string.gsub(message, "$C2", player_class.D1);
      message = string.gsub(message, "$C3", player_class.C1);
      message = string.gsub(message, "$C4", player_class.B1);
      message = string.gsub(message, "$C5", player_class.N1);
      message = string.gsub(message, "$C6", player_class.K1);
      message = string.gsub(message, "$C7", player_class.W1);
      message = string.gsub(message, "$C", player_class.M1);
   end

   return message;   
end


function BBTR_onEvent(self, event, name, ...)
   if (event == "ADDON_LOADED") then
      self:UnregisterEvent("ADDON_LOADED");
      ChatFrame_AddMessageEventFilter("CHAT_MSG_MONSTER_SAY", ChatFilter)
      ChatFrame_AddMessageEventFilter("CHAT_MSG_MONSTER_PARTY", ChatFilter)
      ChatFrame_AddMessageEventFilter("CHAT_MSG_MONSTER_YELL", ChatFilter)
      ChatFrame_AddMessageEventFilter("CHAT_MSG_MONSTER_WHISPER", ChatFilter)
      ChatFrame_AddMessageEventFilter("CHAT_MSG_MONSTER_EMOTE", ChatFilter)
      SlashCmdList["WoWTR_Cataclysm"] = function(msg) BB_SlashCommand(msg); end
      SLASH_WoWTR_Cataclysm1 = "/WoWTR Cataclysm-Bubbles";
      SLASH_WoWTR_Cataclysm2 = "/bbtr";
      BB_CheckVars();
      BB_BlizzardOptions();
	  BB_OknoTRonline();
--      DEFAULT_CHAT_FRAME:AddMessage("|cffffff00WoWTR Cataclysm-Bubbles ver. "..BB_version);
      BB_name = UnitName("player");
      BB_class= UnitClass("player");
      BB_race = UnitRace("player");
      BB_BubblesArray = {};
      p_race = {
      ["Blood Elf"] = { M1="Blood Elf", D1="Blood Elf", C1="Blood Elf", B1="Blood Elf", N1="Blood Elf", K1="Blood Elf", W1="Blood Elf", M2="Blood Elf", D2="Blood Elf", C2="Blood Elf", B2="Blood Elf", N2="Blood Elf", K2="Blood Elf", W2="Blood Elf" }, 
      ["Dark Iron Dwarf"] = { M1="Dark Iron Dwarf", D1="Dark Iron Dwarf", C1="Dark Iron Dwarf", B1="Dark Iron Dwarf", N1="Dark Iron Dwarf", K1="Dark Iron Dwarf", W1="Dark Iron Dwarf", M2="Dark Iron Dwarf", D2="Dark Iron Dwarf", C2="Dark Iron Dwarf", B2="Dark Iron Dwarf", N2="Dark Iron Dwarf", K2="Dark Iron Dwarf", W2="Dark Iron Dwarf" }, 
      ["Dracthyr"] = { M1="Dracthyr", D1="Dracthyr", C1="Dracthyr", B1="Dracthyr", N1="Dracthyr", K1="Dracthyr", W1="Dracthyr", M2="Dracthyr", D2="Dracthyr", C2="Dracthyr", B2="Dracthyr", N2="Dracthyr", K2="Dracthyr", W2="Dracthyr" }, 
      ["Draenei"] = { M1="Draenei", D1="Draenei", C1="Draenei", B1="Draenei", N1="Draenei", K1="Draenei", W1="Draenei", M2="Draenei", D2="Draenei", C2="Draenei", B2="Draenei", N2="Draenei", K2="Draenei", W2="Draenei" }, 
      ["Dwarf"] = { M1="Dwarf", D1="Dwarf", C1="Dwarf", B1="Dwarf", N1="Dwarf", K1="Dwarf", W1="Dwarf", M2="Dwarf", D2="Dwarf", C2="Dwarf", B2="Dwarf", N2="Dwarf", K2="Dwarf", W2="Dwarf" }, 
      ["Gnome"] = { M1="Gnome", D1="Gnome", C1="Gnome", B1="Gnome", N1="Gnome", K1="Gnome", W1="Gnome", M2="Gnome", D2="Gnome", C2="Gnome", B2="Gnome", N2="Gnome", K2="Gnome", W2="Gnome" }, 
      ["Goblin"] = { M1="Goblin", D1="Goblin", C1="Goblin", B1="Goblin", N1="Goblin", K1="Goblin", W1="Goblin", M2="Goblin", D2="Goblin", C2="Goblin", B2="Goblin", N2="Goblin", K2="Goblin", W2="Goblin" }, 
      ["Highmountain Tauren"] = { M1="Highmountain Tauren", D1="Highmountain Tauren", C1="Highmountain Tauren", B1="Highmountain Tauren", N1="Highmountain Tauren", K1="Highmountain Tauren", W1="Highmountain Tauren", M2="Highmountain Tauren", D2="Highmountain Tauren", C2="Highmountain Tauren", B2="Highmountain Tauren", N2="Highmountain Tauren", K2="Highmountain Tauren", W2="Highmountain Tauren" }, 
      ["Human"] = { M1="Human", D1="Human", C1="Human", B1="Human", N1="Human", K1="Human", W1="Human", M2="Human", D2="Human", C2="Human", B2="Human", N2="Human", K2="Human", W2="Human" }, 
      ["Kul Tiran"] = { M1="Kul Tiran", D1="Kul Tiran", C1="Kul Tiran", B1="Kul Tiran", N1="Kul Tiran", K1="Kul Tiran", W1="Kul Tiran", M2="Kul Tiran", D2="Kul Tiran", C2="Kul Tiran", B2="Kul Tiran", N2="Kul Tiran", K2="Kul Tiran", W2="Kul Tiran" }, 
      ["Lightforged Draenei"] = { M1="Lightforged Draenei", D1="Lightforged Draenei", C1="Lightforged Draenei", B1="Lightforged Draenei", N1="Lightforged Draenei", K1="Lightforged Draenei", W1="Lightforged Draenei", M2="Lightforged Draenei", D2="Lightforged Draenei", C2="Lightforged Draenei", B2="Lightforged Draenei", N2="Lightforged Draenei", K2="Lightforged Draenei", W2="Lightforged Draenei" }, 
      ["Mag'har Orc"] = { M1="Mag'har Orc", D1="Mag'har Orc", C1="Mag'har Orc", B1="Mag'har Orc", N1="Mag'har Orc", K1="Mag'har Orc", W1="Mag'har Orc", M2="Mag'har Orc", D2="Mag'har Orc", C2="Mag'har Orc", B2="Mag'har Orc", N2="Mag'har Orc", K2="Mag'har Orc", W2="Mag'har Orc" }, 
      ["Mechagnome"] = { M1="Mechagnome", D1="Mechagnome", C1="Mechagnome", B1="Mechagnome", N1="Mechagnome", K1="Mechagnome", W1="Mechagnome", M2="Mechagnome", D2="Mechagnome", C2="Mechagnome", B2="Mechagnome", N2="Mechagnome", K2="Mechagnome", W2="Mechagnome" }, 
      ["Nightborne"] = { M1="Nightborne", D1="Nightborne", C1="Nightborne", B1="Nightborne", N1="Nightborne", K1="Nightborne", W1="Nightborne", M2="Nightborne", D2="Nightborne", C2="Nightborne", B2="Nightborne", N2="Nightborne", K2="Nightborne", W2="Nightborne" }, 
      ["Night Elf"] = { M1="Night Elf", D1="Night Elf", C1="Night Elf", B1="Night Elf", N1="Night Elf", K1="Night Elf", W1="Night Elf", M2="Night Elf", D2="Night Elf", C2="Night Elf", B2="Night Elf", N2="Night Elf", K2="Night Elf", W2="Night Elf" }, 
      ["Orc"] = { M1="Orc", D1="Orc", C1="Orc", B1="Orc", N1="Orc", K1="Orc", W1="Orc", M2="Orc", D2="Orc", C2="Orc", B2="Orc", N2="Orc", K2="Orc", W2="Orc" }, 
      ["Pandaren"] = { M1="Pandaren", D1="Pandaren", C1="Pandaren", B1="Pandaren", N1="Pandaren", K1="Pandaren", W1="Pandaren", M2="Pandaren", D2="Pandaren", C2="Pandaren", B2="Pandaren", N2="Pandaren", K2="Pandaren", W2="Pandaren" }, 
      ["Tauren"] = { M1="Tauren", D1="Tauren", C1="Tauren", B1="Tauren", N1="Tauren", K1="Tauren", W1="Tauren", M2="Tauren", D2="Tauren", C2="Tauren", B2="Tauren", N2="Tauren", K2="Tauren", W2="Tauren" }, 
      ["Troll"] = { M1="Troll", D1="Troll", C1="Troll", B1="Troll", N1="Troll", K1="Troll", W1="Troll", M2="Troll", D2="Troll", C2="Troll", B2="Troll", N2="Troll", K2="Troll", W2="Troll" }, 
      ["Undead"] = { M1="Undead", D1="Undead", C1="Undead", B1="Undead", N1="Undead", K1="Undead", W1="Undead", M2="Undead", D2="Undead", C2="Undead", B2="Undead", N2="Undead", K2="Undead", W2="Undead" }, 
      ["Void Elf"] = { M1="Void Elf", D1="Void Elf", C1="Void Elf", B1="Void Elf", N1="Void Elf", K1="Void Elf", W1="Void Elf", M2="Void Elf", D2="Void Elf", C2="Void Elf", B2="Void Elf", N2="Void Elf", K2="Void Elf", W2="Void Elf" }, 
      ["Vulpera"] = { M1="Vulpera", D1="Vulpera", C1="Vulpera", B1="Vulpera", N1="Vulpera", K1="Vulpera", W1="Vulpera", M2="Vulpera", D2="Vulpera", C2="Vulpera", B2="Vulpera", N2="Vulpera", K2="Vulpera", W2="Vulpera" }, 
      ["Worgen"] = { M1="Worgen", D1="Worgen", C1="Worgen", B1="Worgen", N1="Worgen", K1="Worgen", W1="Worgen", M2="Worgen", D2="Worgen", C2="Worgen", B2="Worgen", N2="Worgen", K2="Worgen", W2="Worgen" }, 
      ["Zandalari Troll"] = { M1="Zandalari Troll", D1="Zandalari Troll", C1="Zandalari Troll", B1="Zandalari Troll", N1="Zandalari Troll", K1="Zandalari Troll", W1="Zandalari Troll", M2="Zandalari Troll", D2="Zandalari Troll", C2="Zandalari Troll", B2="Zandalari Troll", N2="Zandalari Troll", K2="Zandalari Troll", W2="Zandalari Troll" }, }
      p_class = {
      ["Death Knight"] = { M1="Death Knight", D1="Death Knight", C1="Death Knight", B1="Death Knight", N1="Death Knight", K1="Death Knight", W1="Death Knight", M2="Death Knight", D2="Death Knight", C2="Death Knight", B2="Death Knight", N2="Death Knight", K2="Death Knight", W2="Death Knight" }, 
      ["Demon Hunter"] = { M1="Demon Hunter", D1="Demon Hunter", C1="Demon Hunter", B1="Demon Hunter", N1="Demon Hunter", K1="Demon Hunter", W1="Demon Hunter", M2="Demon Hunter", D2="Demon Hunter", C2="Demon Hunter", B2="Demon Hunter", N2="Demon Hunter", K2="Demon Hunter", W2="Demon Hunter" }, 
      ["Druid"] = { M1="Druid", D1="Druid", C1="Druid", B1="Druid", N1="Druid", K1="Druid", W1="Druid", M2="Druid", D2="Druid", C2="Druid", B2="Druid", N2="Druid", K2="Druid", W2="Druid" }, 
      ["Evoker"] = { M1="Evoker", D1="Evoker", C1="Evoker", B1="Evoker", N1="Evoker", K1="Evoker", W1="Evoker", M2="Evoker", D2="Evoker", C2="Evoker", B2="Evoker", N2="Evoker", K2="Evoker", W2="Evoker" }, 
      ["Hunter"] = { M1="Hunter", D1="Hunter", C1="Hunter", B1="Hunter", N1="Hunter", K1="Hunter", W1="Hunter", M2="Hunter", D2="Hunter", C2="Hunter", B2="Hunter", N2="Hunter", K2="Hunter", W2="Hunter" }, 
      ["Mage"] = { M1="Mage", D1="Mage", C1="Mage", B1="Mage", N1="Mage", K1="Mage", W1="Mage", M2="Mage", D2="Mage", C2="Mage", B2="Mage", N2="Mage", K2="Mage", W2="Mage" }, 
      ["Monk"] = { M1="Monk", D1="Monk", C1="Monk", B1="Monk", N1="Monk", K1="Monk", W1="Monk", M2="Monk", D2="Monk", C2="Monk", B2="Monk", N2="Monk", K2="Monk", W2="Monk" }, 
      ["Paladin"] = { M1="Paladin", D1="Paladin", C1="Paladin", B1="Paladin", N1="Paladin", K1="Paladin", W1="Paladin", M2="Paladin", D2="Paladin", C2="Paladin", B2="Paladin", N2="Paladin", K2="Paladin", W2="Paladin" }, 
      ["Priest"] = { M1="Priest", D1="Priest", C1="Priest", B1="Priest", N1="Priest", K1="Priest", W1="Priest", M2="Priest", D2="Priest", C2="Priest", B2="Priest", N2="Priest", K2="Priest", W2="Priest" }, 
      ["Rogue"] = { M1="Rogue", D1="Rogue", C1="Rogue", B1="Rogue", N1="Rogue", K1="Rogue", W1="Rogue", M2="Rogue", D2="Rogue", C2="Rogue", B2="Rogue", N2="Rogue", K2="Rogue", W2="Rogue" }, 
      ["Shaman"] = { M1="Shaman", D1="Shaman", C1="Shaman", B1="Shaman", N1="Shaman", K1="Shaman", W1="Shaman", M2="Shaman", D2="Shaman", C2="Shaman", B2="Shaman", N2="Shaman", K2="Shaman", W2="Shaman" }, 
      ["Warlock"] = { M1="Warlock", D1="Warlock", C1="Warlock", B1="Warlock", N1="Warlock", K1="Warlock", W1="Warlock", M2="Warlock", D2="Warlock", C2="Warlock", B2="Warlock", N2="Warlock", K2="Warlock", W2="Warlock" }, 
      ["Warrior"] = { M1="Warrior", D1="Warrior", C1="Warrior", B1="Warrior", N1="Warrior", K1="Warrior", W1="Warrior", M2="Warrior", D2="Warrior", C2="Warrior", B2="Warrior", N2="Warrior", K2="Warrior", W2="Warrior" }, }
      if (p_race[BB_race]) then      
         player_race = { M1=p_race[BB_race].M1, D1=p_race[BB_race].D1, C1=p_race[BB_race].C1, B1=p_race[BB_race].B1, N1=p_race[BB_race].N1, K1=p_race[BB_race].K1, W1=p_race[BB_race].W1, M2=p_race[BB_race].M2, D2=p_race[BB_race].D2, C2=p_race[BB_race].C2, B2=p_race[BB_race].B2, N2=p_race[BB_race].N2, K2=p_race[BB_race].K2, W2=p_race[BB_race].W2 };
      else   
         player_race = { M1=BB_race, D1=BB_race, C1=BB_race, B1=BB_race, N1=BB_race, K1=BB_race, W1=BB_race, M2=BB_race, D2=BB_race, C2=BB_race, B2=BB_race, N2=BB_race, K2=BB_race, W2=BB_race };
         print ("|cff55ff00BBTR - yeni ırk: "..BB_race);
      end
      if (p_class[BB_class]) then
         player_class = { M1=p_class[BB_class].M1, D1=p_class[BB_class].D1, C1=p_class[BB_class].C1, B1=p_class[BB_class].B1, N1=p_class[BB_class].N1, K1=p_class[BB_class].K1, W1=p_class[BB_class].W1, M2=p_class[BB_class].M2, D2=p_class[BB_class].D2, C2=p_class[BB_class].C2, B2=p_class[BB_class].B2, N2=p_class[BB_class].N2, K2=p_class[BB_class].K2, W2=p_class[BB_class].W2 };
      else
         player_class = { M1=BB_class, D1=BB_class, C1=BB_class, B1=BB_class, N1=BB_class, K1=BB_class, W1=BB_class, M2=BB_class, D2=BB_class, C2=BB_class, B2=BB_class, N2=BB_class, K2=BB_class, W2=BB_class };
         print ("|cff55ff00BBTR - yeni sınıf: "..BB_class);
      end
   end
end


local BBTR_f = CreateFrame("Frame");
BBTR_f:RegisterEvent("ADDON_LOADED");
BBTR_f:SetScript("OnEvent", BBTR_onEvent);
