Advertisement
sMteX

Untitled

Aug 17th, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 60.46 KB | None | 0 0
  1. -- Zaloha pred velkym page reworkem
  2. local GeneAssign = LibStub("AceAddon-3.0"):NewAddon("GenesisAssignments", "AceConsole-3.0", "AceEvent-3.0", "AceComm-3.0")
  3. local lwin = LibStub("LibWindow-1.1")
  4. local serializer = LibStub("AceSerializer-3.0")
  5. local AceGUI = LibStub("AceGUI-3.0")
  6. -- z nejakeho duvodu se obcas DestroyEvidence() volal dvakrat, tak staci to jednou..
  7. local goodbyeOnce = false
  8.  
  9. --[[ Globalni promenne v GeneAssign:
  10.     textWindow - pro frame, ve kterem je messageFrame
  11.         messageFrame - pro scrolling message frame, do ktereho pujdou zpravy
  12.         dragHandle - pro tahlo na zmenu velikosti textWindowu
  13.     interfaceWindow - pro frame, ktery je hlavnim framem v interface
  14.         buttonLock - tlacitko pro lock textWindowu (menim jeho text v ToggleLock())
  15.         buttonShow - tlacitko pro show/hide textWindowu (mozna jeho zmena v SendButtonClick)
  16.         buttonEdit - tlacitko pro otevreni Edit Windowu (zmena enable state v CheckPermissions)
  17.     editWindow - pro cele editacni okno (at ho muzu v interface zobrazit)
  18.         statusText - kratky fontstring co informuje o tom jestli jsme text ulozili nebo ne
  19.         editBox (GeneAssign.editWindow.editBox) - editbox, ve kterem se edituje stranka
  20.         buttonTogglePages
  21.         buttonAccept - asi self-explanatory
  22.         buttonRevert
  23.         buttonSend
  24.         buttonPreview
  25.         pageNameLabel - kratky label s nazvem prave editovane stranky
  26.     pageWindow - pro cele okno s strankami
  27.         treeFrame - frame uvnitr scrollFramu, pridavaji se do neho tlacitka/stranky
  28.         buttonRemove
  29.         buttonRename
  30.     defaultFont - defaultni font (pouze cesta) pro messageFrame
  31.     addonPrefix - prefix pro komunikaci mezi addony
  32.     acceptMessages - bool co znaci, jestli prijimame zpravy (pri DestroyEvidence se zmeni na false a zabrani prijmuti zprav)
  33.     db - databaze ktera se uchovava mezi relogy/reloady (struktura vic defaultSettings table)
  34.     previewToggle - bool, jestli mame zobrazeny nahled
  35. ]]--
  36.  
  37. GeneAssign.defaultFont = "Interface\\AddOns\\TheGenesisAssignments11\\Fonts\\ABF.ttf"
  38. GeneAssign.addonPrefix = "GeneAss"
  39. -- oznacuje, jestli se maji prijimat a zpracovavat prichozi stranky (v DestroyEvidence() se to zakazuje)
  40. GeneAssign.acceptMessages = true
  41. GeneAssign.previewToggle = false
  42. GeneAssign.buttons = {}
  43. GeneAssign.selectedPage = nil
  44. GeneAssign.pageSelectToggle = false
  45. -- backup - aktualne ulozena stranka
  46. -- locked, shown - popisuji stav textWindow
  47. -- fontSize - asi self-explanatory, aktualne ulozena velikost fontu
  48. GeneAssign.pages = {}
  49. GeneAssign.numPages = 0
  50. local startup = true --proto, aby se pri prvnim spusteni oznacila prvni stranka a ne posledni pridana, jak je tomu vzdy jindy
  51. local defaultSettings = {
  52.     char = {
  53.         backup = "This is a test page",
  54.         locked = false,
  55.         shown = false,
  56.         fontSize = 16,
  57.     }
  58. }
  59.  
  60. function GeneAssign:OnInitialize()
  61.  
  62. end
  63.  
  64. function GeneAssign:OnEnable()
  65.     -- podivny workaround na to aby to nikdo jiny pouzivat nemohl..
  66.     -- kdyz test byl na zacatku (jeste pred local GeneAssign = ...), tak pri PRVNIM lognuti IsInGuild i GetGuildInfo hazelo nil a tedy vyhodnotilo ze nejsme v guilde, ale kdyz se hodil reload, tak to pak slo
  67.     -- testoval jsem to, v OnInitialize IsInGuild stale hlasi nil, a funguje to az v OnEnable.. ovsem zde GetGuildInfo stale hlasi nil, proto jsem nasel na netu, ze kdyz si zazadam o Guild roster, tak potom se vyvola event
  68.     -- GUILD_ROSTER_UPDATE, pri kterem uz z GetGuildInfo vytahnu spravny nazev, pokud vsechno sedi, odvolam se na AfterEnable, ktery donastavi zbytek, pokud ne, tak jedine co mi staci zrusit je /ga slash command protoze zbytek se jeste nevytvoril
  69.     self:AfterEnable()
  70.     --[[self:RegisterEvent("GUILD_ROSTER_UPDATE")
  71.     local isInGuild = IsInGuild()
  72.     if(isInGuild == 1) then
  73.         GuildRoster()
  74.     else
  75.         return
  76.     end]]
  77. end
  78.  
  79. function GeneAssign:AfterEnable()
  80.     -- pokud probehne dobre ten workaround, a mame teda potvrzene ze jsme z The Genesis, pokracujeme s zbytkem nastaveni, vytvoreni oken atd.
  81.     self:RegisterChatCommand("ga", "ProcessSlashCommand")
  82.     GeneAssign.db = LibStub("AceDB-3.0"):New("TheGenesisAssignmentsDB11", defaultSettings, true)
  83.     StaticPopupDialogs["REVERT_CONFIRM"] = {
  84.         text = "Opravdu chcete obnovit posledni zalohu?",
  85.         button1 = "Ano",
  86.         button2 = "Ne",
  87.         OnAccept = function()
  88.             self:RevertChanges()
  89.         end,
  90.         timeout = 0,
  91.         whileDead = true,
  92.         hideOnEscape = true,
  93.         preferredIndex = 3,
  94.     }
  95.     StaticPopupDialogs["CLEAR_CONFIRM"] = {
  96.         text = "Opravdu chcete smazat stranku (zmeny se neulozi)?",
  97.         button1 = "Ano",
  98.         button2 = "Ne",
  99.         OnAccept = function()
  100.             self.editWindow.editBox:SetText("")
  101.         end,
  102.         timeout = 0,
  103.         whileDead = true,
  104.         hideOnEscape = true,
  105.         preferredIndex = 3,
  106.     }
  107.    
  108.     self:RegisterComm(self.addonPrefix, "ReceiveMessage")
  109.    
  110.     self:RegisterEvent("RAID_ROSTER_UPDATE")
  111.     self:RegisterEvent("PLAYER_GUILD_UPDATE")
  112.     --BuildFontPicker()
  113.     self:BuildTreeWindow()
  114.     self:BuildTextWindow()
  115.     self:BuildInterfaceWindow()
  116.     self:BuildEditWindow()
  117.     self:CheckPermissions()
  118.    
  119.    
  120.    
  121. end
  122.  
  123. function GeneAssign:BuildTreeWindow()
  124.  
  125.  
  126.        
  127.         --[[
  128.         ok, takze ocividne s tim nijak sibovat nemuzem, i kdyz se k framu proklikam, pravdepodobne kvuli tech jebnutych layoutu se to cele rozhazi.. tak zkusime to vytvorit podle sebe
  129.         zkoumal sem ten kod a vypada to ze jednotlive ty polozky jsou jakoby tlacitka, ktere se generujou z toho stromu (cemuz taky celkem logicky odpovidaji parametry co v tom stromu muzou byt - text, naka unikatni value, disabled, visible popr. ikona)
  130.         takze mohl bych teoreticky zkusit si udelat takovy tree group sam s tim ze to bude oklestene a nebude tam podpora vice vrstev aby to bylo jednodussi (coz by nemuselo vadit, mohlo by to byt klidne jako jednotlivi bossove a serazeni podle jmena treba)      
  131.     ]] 
  132.     local pageWindow = CreateFrame("Frame", nil, UIParent)
  133.     pageWindow:SetBackdrop({
  134.         bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
  135.         edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
  136.         tile = true, tileSize = 32, edgeSize = 32,
  137.         insets = { left = 8, right = 8, top = 8, bottom = 8 }
  138.     })
  139.     pageWindow:SetSize(215, 380)
  140.     pageWindow:SetPoint("CENTER", 0, 0)
  141.     pageWindow:SetMovable(true)
  142.     pageWindow:Hide()
  143.    
  144.    
  145.    
  146.     --treeFrame:SetBackdrop({   bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background", tile = true, tileSize = 32})
  147.    
  148.    
  149.     --[[local scrollFrame = CreateFrame("ScrollFrame", "SelectPageScrollFrame", container, "UIPanelScrollFrameTemplate")
  150.     scrollFrame:SetPoint("TOPLEFT", 18, -18)
  151.     scrollFrame:SetPoint("BOTTOMRIGHT", -32, 48) --18
  152.    
  153.     scrollFrame:SetBackdrop({
  154.         bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
  155.         edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
  156.         tile = true, tileSize = 16, edgeSize = 8,
  157.         insets = { left = 3, right = 3, top = 5, bottom = 3 }
  158.     })
  159.     scrollFrame:SetBackdropColor(0, 0, 0, 0.5)
  160.     scrollFrame:SetBackdropBorderColor(0.4, 0.4, 0.4)
  161.            
  162.     local treeFrame = CreateFrame("Frame", nil, scrollFrame)
  163.     treeFrame:SetWidth(170) --155
  164.     treeFrame:SetHeight(150)
  165.    
  166.     scrollFrame:SetScrollChild(treeFrame)
  167.    
  168.     local scrollBar = _G[scrollFrame:GetName().."ScrollBar"]
  169.     scrollBar.bg = scrollBar:CreateTexture(nil, "BACKGROUND")
  170.     scrollBar.bg:SetAllPoints(true)
  171.     scrollBar.bg:SetTexture(0, 0, 0, 0.5)]]
  172.    
  173.     local container = CreateFrame("Frame", nil, pageWindow)
  174.     container:SetPoint("TOPLEFT", 18, -18)
  175.     container:SetPoint("BOTTOMRIGHT", -32, 94) --48
  176.     container:SetBackdrop({
  177.         bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
  178.         edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
  179.         tile = true, tileSize = 16, edgeSize = 8,
  180.         insets = { left = 3, right = 3, top = 3, bottom = 3 }
  181.     })
  182.     container:SetBackdropColor(0, 0, 0, 0.5)
  183.     container:SetBackdropBorderColor(0.4, 0.4, 0.4)
  184.     local scrollFrame = CreateFrame("ScrollFrame", "SelectPageScrollFrame", container, "UIPanelScrollFrameTemplate")
  185.     scrollFrame:SetPoint("TOPLEFT", 5, -5)
  186.     scrollFrame:SetPoint("BOTTOMRIGHT", -5, 5) --18
  187.    
  188.     local treeFrame = CreateFrame("Frame", nil, container)
  189.     treeFrame:SetWidth(170) --155
  190.     treeFrame:SetHeight(150)
  191.    
  192.     scrollFrame:SetScrollChild(treeFrame)
  193.    
  194.     local scrollBar = _G[scrollFrame:GetName().."ScrollBar"]
  195.     scrollBar.bg = scrollBar:CreateTexture(nil, "BACKGROUND")
  196.     scrollBar.bg:SetAllPoints(true)
  197.     scrollBar.bg:SetTexture(0, 0, 0, 0.5)
  198.    
  199.    
  200.    
  201.     --bude treba si otestovat par veci, jmenovite "tlacitko" ktere bude slouzit jako jednotliva stranka, potom jisty "frame" co bude jako kontejner pro tu group, a idealni by bylo kdyby se tim dalo scrollovat (coz smrdi opet scrollframem, co je v edit windowu)
  202.     --k tlacitkum - bude treba otestovat jeho vytvoreni, jakysi "toggle" (aby bylo videt ze je vybrana), taky jeji prejmenovani, smazani, a pri pridani nove stranky jeji spravne zarazeni
  203.     --[[local testButton = CreateFrame("Button", "TestButton", frame, "OptionsListButtonTemplate")
  204.     testButton:SetPoint("CENTER", 0, 0)
  205.     testButton:SetText("Test text")
  206.     testButton.text:SetHeight(14)
  207.     --testButton:SetSize(100, 20)
  208.     testButton.value = 1
  209.     testButton.selected = true
  210.     --testButton:SetScript("OnClick", function(self) if not self.selected then self.selected = true self:LockHighlight() testButton1.selected = false testButton1:UnlockHighlight() end print("Click, value = " .. self.value) end)
  211.     testButton:LockHighlight()
  212.     local testButton1 = CreateFrame("Button", "TestButton1", frame, "OptionsListButtonTemplate")
  213.     testButton1:SetPoint("TOPLEFT", testButton, "BOTTOMLEFT", 0, 0)
  214.     testButton1:SetText("Test text2")
  215.     testButton1.text:SetHeight(14)
  216.     --testButton:SetSize(100, 20)
  217.     testButton1.value = 2
  218.     testButton1.selected = false
  219.     testButton:SetScript("OnClick", function(self) if not self.selected then self.selected = true self:LockHighlight() testButton1.selected = false testButton1:UnlockHighlight() end print("Click, value = " .. self.value) end)
  220.     testButton1:SetScript("OnClick", function(self) if not self.selected then self.selected = true self:LockHighlight() testButton.selected = false testButton:UnlockHighlight() end print("Click, value = " .. self.value) end)
  221.     ]]
  222.     --ok, takze jednotlive tlacitka na sebe muzou byt takhle nalepene, "toggle" mame vyreseny, a v handleru se da pracovat nejak i s tou value takze treba ID stranky z toho dostanem..
  223.     --jdeme zkusit vytvorit tlacitka z stromu
  224.    
  225.     --self:RenderTree() -- AddPage si RenderTree vola sama
  226.    
  227.     --[[ ok, vytvoreni tlacitek ze stromu taky mame, jdem k tomu pridat dalsi operace, tzn.
  228.         1) pridani dalsi stranky (a k tomu test re-renderu, jestli spravne skryva tlacitka atd.)
  229.         2) i takove obycejne operace jako vraceni prave vybrane stranky, popr. zmena vybrane stranky
  230.         3) odebrani prave vybrane stranky
  231.         4) prejmenovani stranky (a nasledny re-render)
  232.     ]]
  233.     --print(self:GetSelectedId())
  234.     StaticPopupDialogs["ADD_PAGE"] = {
  235.         button1 = OKAY,
  236.         button2 = CANCEL,
  237.         OnAccept = function(self)
  238.             local text = self.editBox:GetText()
  239.             if text ~= "" then GeneAssign:AddPage(text) end
  240.         end,
  241.         EditBoxOnEnterPressed = function(self)
  242.             local text = self:GetParent().editBox:GetText()
  243.             if text ~= "" then GeneAssign:AddPage(text) end
  244.             self:GetParent():Hide()
  245.         end,
  246.         text = "Zadejte jmeno stranky: ",
  247.         hasEditBox = true,
  248.         whileDead = true,
  249.         EditBoxOnEscapePressed = function(self) self:GetParent():Hide() end,
  250.         hideOnEscape = true,
  251.         timeout = 0,
  252.         preferredIndex = 3
  253.     }
  254.    
  255.     StaticPopupDialogs["RENAME_PAGE"] = {
  256.         button1 = OKAY,
  257.         button2 = CANCEL,
  258.         OnAccept = function(self)
  259.             local text = self.editBox:GetText()
  260.             if text ~= "" then GeneAssign:RenameSelectedPage(text) end
  261.         end,
  262.         EditBoxOnEnterPressed = function(self)
  263.             local text = self:GetParent().editBox:GetText()
  264.             if text ~= "" then GeneAssign:RenameSelectedPage(text) end
  265.             self:GetParent():Hide()
  266.         end,
  267.         text = "Zadejte nove jmeno stranky: ",
  268.         hasEditBox = true,
  269.         whileDead = true,
  270.         EditBoxOnEscapePressed = function(self) self:GetParent():Hide() end,
  271.         hideOnEscape = true,
  272.         timeout = 0,
  273.         preferredIndex = 3
  274.     }
  275.    
  276.     StaticPopupDialogs["REMOVE_PAGE"] = {
  277.         text = "Smazat vybranou stranku?",
  278.         button1 = OKAY,
  279.         button2 = CANCEL,
  280.         OnAccept = function()
  281.             self:RemoveSelectedPage()
  282.         end,
  283.         timeout = 0,
  284.         whileDead = true,
  285.         hideOnEscape = true,
  286.         preferredIndex = 3,
  287.     }
  288.    
  289.    
  290.    
  291.     local removeButton = CreateFrame("Button", "RemoveButton", pageWindow, "UIPanelButtonTemplate")
  292.     removeButton:SetText("Odstranit stranku")
  293.     removeButton:SetHeight(removeButton:GetTextHeight() + 10)
  294.     removeButton:SetPoint("BOTTOMLEFT", 20, 20)
  295.     removeButton:SetPoint("BOTTOMRIGHT", -20, 20)
  296.     removeButton:SetScript("OnClick", function()
  297.         if GeneAssign:GetSelectedId() then
  298.             StaticPopup_Show("REMOVE_PAGE")
  299.         end
  300.     end)
  301.    
  302.    
  303.     local renameButton = CreateFrame("Button", "RenameButton", pageWindow, "UIPanelButtonTemplate")
  304.     renameButton:SetText("Prejmenovat stranku")
  305.     renameButton:SetHeight(renameButton:GetTextHeight() + 10)
  306.     renameButton:SetPoint("BOTTOMLEFT", removeButton, "TOPLEFT", 0, 2)
  307.     renameButton:SetPoint("BOTTOMRIGHT", removeButton, "TOPRIGHT", 0, 2)
  308.     renameButton:SetScript("OnClick", function()
  309.         if GeneAssign:GetSelectedId() then
  310.             StaticPopup_Show("RENAME_PAGE")
  311.         end
  312.     end)
  313.    
  314.     local addButton = CreateFrame("Button", "AddButton", pageWindow, "UIPanelButtonTemplate")
  315.     addButton:SetText("Pridat stranku")
  316.     addButton:SetHeight(addButton:GetTextHeight() + 10)
  317.     addButton:SetPoint("BOTTOMLEFT", renameButton, "TOPLEFT", 0, 2)
  318.     addButton:SetPoint("BOTTOMRIGHT", renameButton, "TOPRIGHT", 0, 2)
  319.     addButton:SetScript("OnClick", function() StaticPopup_Show("ADD_PAGE") end)
  320.    
  321.     pageWindow.buttonRemove = removeButton
  322.     pageWindow.buttonRename = renameButton
  323.     pageWindow.treeFrame = treeFrame
  324.     self.pageWindow = pageWindow
  325.    
  326.     for i = 1, 16 do self:AddPage(string.format("Page %02d", i)) end
  327.     startup = false
  328.     -- pridani funguje spravne, pridava na spravne misto, a presto zachovava poradi (poradi pridani, cili ID) v tom stromu (zatim se mi to zda dobre ale mozna to bude chtit pak nejak reworknout cele)
  329.     -- ok, timto bychom meli vicemene udelane stranky, umi je pridavat, odebirat, atd., vsecko co bylo zmineno drive
  330.    
  331.     --      ROZDIL PAIRS VS IPAIRS
  332.     --[[
  333.     local x = {1, 2, 5, 10, 16}
  334.     for k, v in pairs(x) do print("pairs, k = " .. k .. ", v = " .. v) end
  335.     for k, v in ipairs(x) do print("ipairs, k = " .. k .. ", v = " .. v) end
  336.    
  337.     --  oba vypisou to same
  338.     --  pairs, k = 1, v = 1
  339.     --  pairs, k = 2, v = 2
  340.     --  pairs, k = 3, v = 5
  341.     --  pairs, k = 4, v = 10
  342.     --  pairs, k = 5, v = 16
  343.    
  344.     print("y:")
  345.     local y = {[1] = 1, [2] = 2, [5] = 5, [10] = 10, [16] = 16}
  346.     for k, v in pairs(y) do print("pairs, k = " .. k .. ", v = " .. v) end
  347.     for k, v in ipairs(y) do print("ipairs, k = " .. k .. ", v = " .. v) end
  348.     --    vypise se toto:
  349.     --  pairs, k = 2, v = 2
  350.     --  pairs, k = 10, v = 10
  351.     --  pairs, k = 1, v = 1
  352.     --  pairs, k = 5, v = 5
  353.     --  pairs, k = 16, v = 16
  354.     --  ipairs, k = 1, v = 1
  355.     --  ipairs, k = 2, v = 2
  356.        
  357.     --  => pokud mame prvky indexovane specificky, je dobre pouzit pairs, protoze i kdyz prvky nezpracovavaji jak jdou po sobe (misto 1,2,5,10,16 vypsaly 2,10,1,5,16), zpracuji je vsechny
  358.     --     kdezto ipairs jde postupne a jakmile nejdou prvky primo po sobe (3, 4 jsou vynechane), tak timpadem narazi jakoby na nil (y[3] a y[4] = nil) a tam cyklus skoncime
  359.          
  360.     --  => v praxi = pro self.pages pouzivame vlastni indexy = vzdy pairs
  361.     --               pro self.buttons taky pairs, taky mame vlastni indexy
  362.     --               pro GetSortedTree, table.insert podle testu pravdepodobne neindexuje (jako vyse v pripade pole x), protoze pairs i ipairs vraci stejne vysledky
  363.     --                  coz znamena ze pro hlavni cyklus v RenderTree() muzeme pouzit jakykoli iterator a vysledek je stejny
  364.     ]]
  365. end
  366.  
  367. function GeneAssign:GetSortedTree()
  368.     if not self.pages then return end
  369.     -- puvodni strom asi radit nebudu, nebudu ho menit, udelam kopii
  370.     local treeCopy = {}
  371.     for _, page in pairs(self.pages) do
  372.         table.insert(treeCopy, page)
  373.     end
  374.     --for k, v in pairs(treeCopy) do print("GetSortedTree, pairs, k = " .. k .. ", v.value = " .. v.value .. ", v.text = " .. v.text) end
  375.     --for k, v in ipairs(treeCopy) do print("GetSortedTree, ipairs, k = " .. k .. ", v.value = " .. v.value .. ", v.text = " .. v.text) end
  376.     table.sort(treeCopy, function(a, b) return a.text < b.text end)
  377.     --print("Po serazeni")
  378.     --for k, v in pairs(treeCopy) do print("GetSortedTree, pairs, k = " .. k .. ", v.value = " .. v.value .. ", v.text = " .. v.text) end
  379.     --for k, v in ipairs(treeCopy) do print("GetSortedTree, ipairs, k = " .. k .. ", v.value = " .. v.value .. ", v.text = " .. v.text) end
  380.     return treeCopy
  381. end
  382.  
  383. function GeneAssign:RenderTree()
  384.     local tree = self:GetSortedTree()
  385.     -- ani nemusim nic vracet, kdyz tree nebude existovat, hlavni cyklus by to melo preskocit a aspon to poresi podminky potom s tim selectedPage
  386.     for k, button in pairs(self.buttons) do
  387.         --print("RenderTree delete loop, k = " .. k .. ", button value = " .. button.value)
  388.         button:Hide()
  389.         self.buttons[k] = nil
  390.     end
  391.     for i, page in pairs(tree) do -- kdyz ten tree neni vyslovene indexovany (protoze delame serazenou kopii) tak i v tomto pripade ma hodnoty 1, 2... ANEBO je indexovany, ale prave v tomhletom poradi (nevim jak table.insert tohleto interne resi)
  392.         --print("RenderTree loop, i = " .. i .. ", value = " .. page.value .. ", text = " .. page.text)
  393.         local button = CreateFrame("Button", "Page"..(page.value), self.pageWindow.treeFrame, "OptionsListButtonTemplate")
  394.         self.buttons[page.value] = button --i se pouzit neda, viz vyse
  395.         button:SetText(page.text)
  396.         button.text:SetHeight(14)
  397.         button:SetWidth(self.pageWindow.treeFrame:GetWidth() - 3)
  398.         button.value = page.value
  399.         button.selected = false
  400.         button:SetScript("OnClick", function(self)
  401.             if not self.selected then
  402.                 GeneAssign.selectedPage = self.value
  403.                 self.selected = true
  404.                 self:LockHighlight()
  405.                 for _, otherButton in pairs(GeneAssign.buttons) do
  406.                     if(self ~= otherButton) then
  407.                         otherButton.selected = false
  408.                         otherButton:UnlockHighlight()
  409.                     end
  410.                 end
  411.                 GeneAssign.editWindow.pageNameLabel:SetText(GeneAssign.pages[self.value].text)
  412.             end
  413.         end)
  414.         --if (i == 1) then
  415.         button:SetPoint("TOPLEFT", 0, -3 - (i-1)*button:GetHeight())
  416.         --else --prvni tlacitko zacina na y = -15, k tomu se vzdycky pripocte vyska toho tlacitka, takze kdyz by bylo napriklad 15, tak by y = -15, -30, -45, cili -15 - (i-1)*GetHeight()  (tohle by melo platit dokonce i pro vsechny, kdyz i = 1 tak to zustane jen u -15, kdyz 2 a vic tak se to bude posouvat)
  417.         --  button:SetPoint("TOPLEFT", )
  418.         --end
  419.     end
  420.     if not self.selectedPage then
  421.         if(self.numPages >= 1) then  -- jedna se sice o tlacitka ale stranky a tlacitka by mely odpovidat 1:1 takze muzu pouzit i toto
  422.             for _, page in pairs(tree) do -- nelibi se mi to ale tim, ze budu mit ty tlacitka indexovane (self.buttons[id]) tak netusim, jaky je prvni index protoze je nahodny, proto projdu cyklem a po prvnim pruchodu to breaknu
  423.                 self.buttons[page.value].selected = true
  424.                 self.buttons[page.value]:LockHighlight()
  425.                 self.selectedPage = page.value
  426.                 break
  427.             end
  428.         end
  429.     else -- pokud mame nejakou stranku vybranou, pak akorat vyberu to tlacitko
  430.         self.buttons[self.selectedPage].selected = true
  431.         self.buttons[self.selectedPage]:LockHighlight()
  432.     end
  433. end
  434.  
  435. function GeneAssign:GetSelectedId()
  436.     return self.selectedPage
  437. end
  438.  
  439. function GeneAssign:AddPage(content)
  440.  
  441.    
  442.     local randomID = math.random(10000)
  443.     while self.pages[randomID] do
  444.         randomID = math.random(10000)
  445.     end
  446.    
  447.     self.pages[randomID] = { value = randomID, text = content }
  448.     self.numPages = self.numPages + 1
  449.     --for k, v in pairs(self.pages) do print("AddPage text, k = " .. k .. ", value = " .. v.value .. ", text = " .. v.text) end
  450.     if not startup then
  451.         self.selectedPage = randomID
  452.     end
  453.     self:RenderTree()
  454. end
  455.  
  456. function GeneAssign:RemoveSelectedPage()
  457.     self.pages[self.selectedPage] = nil
  458.     self.selectedPage = nil -- stejne se hned zmeni v RenderTree, netreba to delat znova tady
  459.     self:RenderTree()
  460. end
  461.  
  462. function GeneAssign:RenameSelectedPage(content)
  463.     self.pages[self.selectedPage].text = content
  464.     self:RenderTree()
  465. end
  466. --------------------------
  467. --      KOMUNIKACE
  468. --------------------------
  469. function GeneAssign:ReceiveMessage(prefix, data, channel, sender)
  470.     -- pokud probehlo DestroyEvidence() tak neprijimame dalsi zpravy
  471.     if not self.acceptMessages then return end
  472.    
  473.     if prefix ~= self.addonPrefix then return end
  474.    
  475.     local success, deserializedData = serializer:Deserialize(data)
  476.    
  477.     if not success then
  478.         self:Print("Chyba pri deserializaci dat")
  479.         return
  480.     end
  481.    
  482.     self:ProcessMessage(deserializedData, sender)
  483. end
  484.  
  485. function GeneAssign:ProcessMessage(data, sender)
  486.     -- k tomuto se pravdepodobne nedostane ale kdyby data byla prazdna, tak skoncime
  487.     if not data then return end
  488.    
  489.     -- ignorujeme vlastni zpravy
  490.     if(sender == UnitName("player")) then return end
  491.    
  492.     if(not self.textWindow:IsShown()) then self.textWindow:Show() end
  493.    
  494.     -- vycistime text okno, v pripade ze zrovna editujeme aktualizujeme text, ulozime do backup
  495.     self.textWindow.messageFrame:Clear()
  496.     self.db.char.backup = data
  497.     if(self.editWindow:IsShown()) then
  498.         self.editWindow.editBox:SetText(data)
  499.     end
  500.    
  501.     -- zobrazime text do textWindowu
  502.     local text = RecognizeFixPatterns(data)
  503.     local lines = { strsplit("\n", text) }
  504.     local lines_count = #lines
  505.     for i = 1, lines_count do
  506.         local line = lines[i]
  507.         if line == "" then line = " " end
  508.         self.textWindow.messageFrame:AddMessage(line)
  509.     end
  510. end
  511.  
  512. function GeneAssign:SendMessage(data)
  513.     if(not IsInRaid()) then return end
  514.    
  515.     local dataToSend = data or self.db.char.backup or ""
  516.    
  517.     local serializedData = serializer:Serialize(dataToSend)
  518.    
  519.     self:SendCommMessage(self.addonPrefix, serializedData, "RAID") 
  520. end
  521.  
  522. -------------------------
  523. --      TEXT OKNO
  524. -------------------------
  525. function GeneAssign:BuildTextWindow()
  526.     -- cele okno pro ten textWindow
  527.     local TextFrame = CreateFrame("Frame", "TextFrame", UIParent)
  528.     -- v LibWindow si registrujeme, ze chceme uchovavat pozici tohoto framu, a ulozime to do self.db.char (cili pro kazdy char zvlast)
  529.     lwin.RegisterConfig(TextFrame, self.db.char)
  530.     TextFrame:Hide()
  531.     TextFrame:SetToplevel(true)
  532.     TextFrame:EnableMouse(true)
  533.     TextFrame:SetMovable(true)
  534.     TextFrame:SetResizable(true)
  535.     TextFrame:SetMinResize(100, 100)
  536.     TextFrame:SetSize(200, 200)
  537.     TextFrame:SetPoint("CENTER", UIParent, "CENTER", 0, 0) -- ze zacatku ukotvime doprostred
  538.     lwin.RestorePosition(TextFrame) -- a ulozime (pozdeji nacteme) pozici a velikost framu
  539.     TextFrame:SetBackdrop({
  540.         bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
  541.         tile = true,
  542.         tileSize = 32,
  543.     })
  544.     TextFrame:SetScript("OnMouseDown", TextFrame_OnMouseDown)
  545.     TextFrame:SetScript("OnMouseUp", TextFrame_OnMouseUp)
  546.    
  547.     -- tahlo pro resize framu
  548.     local TextFrameDragHandle = CreateFrame("Frame", "TextFrameDragHandle", TextFrame)
  549.     TextFrameDragHandle:SetSize(16, 16)
  550.     TextFrameDragHandle:SetPoint("BOTTOMRIGHT", TextFrame, "BOTTOMRIGHT", 0, 0)
  551.     TextFrameDragHandle:SetScript("OnMouseDown", TextFrame_DragDown)
  552.     TextFrameDragHandle:SetScript("OnMouseUp", TextFrame_DragUp)
  553.     if self.db.char.locked then
  554.         TextFrameDragHandle:Hide()
  555.     end
  556.     TextFrame.dragHandle = TextFrameDragHandle
  557.    
  558.     -- nastavime texturu tomu tahlu
  559.     local texture = TextFrameDragHandle:CreateTexture("TextFrameDragHandleTexture", "OVERLAY")
  560.     texture:SetTexture("Interface\\AddOns\\TheGenesisAssignments11\\Textures\\draghandle")
  561.     texture:SetBlendMode("ADD")
  562.     texture:SetSize(16,16)
  563.     texture:SetPoint("TOPLEFT", TextFrameDragHandle, "TOPLEFT", 0, 0)
  564.    
  565.     -- scrolling frame do ktereho potom budeme psat
  566.     local scrollingFrame = CreateFrame("ScrollingMessageFrame", "ScrollingFrameTest", TextFrame)
  567.     scrollingFrame:SetSize(180, 180)
  568.     scrollingFrame:SetPoint("TOPLEFT", TextFrame, "TOPLEFT", 10, -10)
  569.     scrollingFrame:SetPoint("BOTTOMRIGHT", TextFrame, "BOTTOMRIGHT", -10, 10)
  570.     scrollingFrame:SetFading(false) -- at text nebledne casem
  571.     scrollingFrame:SetMaxLines(70)
  572.     scrollingFrame:SetJustifyH("LEFT")
  573.     scrollingFrame:SetJustifyV("TOP")
  574.     scrollingFrame:SetInsertMode("bottom")
  575.     scrollingFrame:SetFont(self.defaultFont, self.db.char.fontSize, nil)
  576.     scrollingFrame:EnableMouseWheel(true)
  577.     scrollingFrame:SetScript("OnMouseWheel", function(self, delta)
  578.           if (delta < 0) then
  579.             if(scrollingFrame:GetInsertMode() == "TOP") then
  580.                 scrollingFrame:ScrollUp()
  581.             else
  582.                 scrollingFrame:ScrollDown()
  583.             end
  584.           elseif (delta > 0) then
  585.             if(scrollingFrame:GetInsertMode() == "TOP") then
  586.                 scrollingFrame:ScrollDown()
  587.             else
  588.                 scrollingFrame:ScrollUp()
  589.             end
  590.           end
  591.     end)
  592.     TextFrame.messageFrame = scrollingFrame
  593.    
  594.     GeneAssign.textWindow = TextFrame
  595.        
  596.     local text = RecognizeFixPatterns(self.db.char.backup)
  597.     local lines = { strsplit("\n", text) }
  598.     local lines_count = #lines
  599.     for i = 1, lines_count do
  600.         local line = lines[i]
  601.         if line == "" then line = " " end
  602.         self.textWindow.messageFrame:AddMessage(line)
  603.     end
  604.    
  605.     if(self.db.char.shown) then
  606.         TextFrame:Show()
  607.     end
  608. end
  609.  
  610. function GeneAssign:ToggleLock()
  611.     self.db.char.locked = not self.db.char.locked
  612.     if self.db.char.locked then
  613.         self.interfaceWindow.buttonLock:SetText("Odemkni okno")
  614.         self.textWindow:SetMovable(false)
  615.         self.textWindow:SetResizable(false)
  616.         self.textWindow.dragHandle:Hide()
  617.     else
  618.         self.interfaceWindow.buttonLock:SetText("Zamkni okno")
  619.         self.textWindow:SetMovable(true)
  620.         self.textWindow:SetResizable(true)
  621.         self.textWindow.dragHandle:Show()
  622.     end
  623. end
  624.  
  625. function GeneAssign:ToggleShow()
  626.     if(self.textWindow:IsShown()) then
  627.         self.textWindow:Hide()
  628.         self.db.char.shown = false
  629.         self.interfaceWindow.buttonShow:SetText("Zobraz okno")
  630.     else
  631.         self.textWindow:Show()
  632.         self.db.char.shown = true
  633.         self.interfaceWindow.buttonShow:SetText("Skryj okno")
  634.     end
  635. end
  636.  
  637. ------------------------------
  638. --      INTERFACE OKNO
  639. ------------------------------
  640. function GeneAssign:BuildInterfaceWindow()
  641.     -- cely frame
  642.     local interfaceWindow = CreateFrame("Frame", "InterfaceWindow", UIParent)
  643.     interfaceWindow.name = "The Genesis Assignments"
  644.    
  645.     -- titulek, nadpis okna nastaveni
  646.     local title = interfaceWindow:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
  647.     title:SetText("The Genesis Assignments")
  648.     title:SetPoint("TOPLEFT", 20, -20)
  649.    
  650.     --font picker label jsem tady nechal, nastylovane to je, planuju to pridat v dalsi verzi tak at to nemusim vymyslet znova
  651.     --[[local fontPickerLabel = interfaceWindow:CreateFontString(nil, "ARTWORK", "GameFontHighlightMedium")
  652.     fontPickerLabel:SetText("Font:")
  653.     fontPickerLabel:SetPoint("TOPLEFT", 25, -60)
  654.     fontPickerLabel:SetWidth(fontPickerLabel:GetStringWidth())]]
  655.    
  656.     -- label k velikosti fontu
  657.     local fontSizeLabel = interfaceWindow:CreateFontString(nil, "ARTWORK", "GameFontHighlightMedium")
  658.     fontSizeLabel:SetText("Velikost pisma:")
  659.     --fontSizeLabel:SetPoint("TOPLEFT", fontPickerLabel, "BOTTOMLEFT", 0, -30)
  660.     fontSizeLabel:SetPoint("TOPLEFT", 25, -60)
  661.     fontSizeLabel:SetWidth(fontSizeLabel:GetStringWidth())
  662.    
  663.     -- tlacitko k skryti/zobrazeni okna
  664.     local toggleWindowBtn = CreateFrame("Button", nil, interfaceWindow, "UIPanelButtonTemplate")
  665.     if(self.textWindow:IsShown()) then
  666.         toggleWindowBtn:SetText("Skryj okno")
  667.     else
  668.         toggleWindowBtn:SetText("Zobraz okno")
  669.     end
  670.     toggleWindowBtn:SetSize(toggleWindowBtn:GetTextWidth()+40, toggleWindowBtn:GetTextHeight()+20)
  671.     toggleWindowBtn:SetPoint("TOPLEFT", fontSizeLabel, "BOTTOMLEFT", 0, -40)
  672.     toggleWindowBtn:SetScript("OnClick", function(self, button, down)
  673.         if(GeneAssign.textWindow:IsShown()) then
  674.             GeneAssign.textWindow:Hide()
  675.             GeneAssign.db.char.shown = false
  676.             toggleWindowBtn:SetText("Zobraz okno")
  677.         else
  678.             GeneAssign.textWindow:Show()
  679.             GeneAssign.db.char.shown = true
  680.             toggleWindowBtn:SetText("Skryj okno")
  681.         end        
  682.     end)
  683.    
  684.     -- tlacitko k uzamknuti/odemknuti okna
  685.     local lockWindowBtn = CreateFrame("Button", nil, interfaceWindow, "UIPanelButtonTemplate")
  686.     if self.db.char.locked then
  687.         lockWindowBtn:SetText("Odemkni okno")
  688.     else
  689.         lockWindowBtn:SetText("Zamkni okno")
  690.     end
  691.     lockWindowBtn:SetSize(lockWindowBtn:GetTextWidth()+40, lockWindowBtn:GetTextHeight()+20)
  692.     lockWindowBtn:SetPoint("TOPLEFT", toggleWindowBtn, "TOPRIGHT", 60, 0)
  693.     lockWindowBtn:SetScript("OnClick", function(self, button, down)
  694.         GeneAssign:ToggleLock()
  695.     end)
  696.    
  697.     -- tlacitko k editaci stranky
  698.     local editPageBtn = CreateFrame("Button", nil, interfaceWindow, "UIPanelButtonTemplate")
  699.     editPageBtn:SetText("Edituj stranku")
  700.     editPageBtn:SetSize(editPageBtn:GetTextWidth()+40, editPageBtn:GetTextHeight()+20)
  701.     editPageBtn:SetPoint("TOPLEFT", lockWindowBtn, "TOPRIGHT", 60, 0)
  702.     editPageBtn:SetScript("OnClick", function(self, button, down)
  703.         if(IsInRaid() and (IsRaidLeader() or IsRaidOfficer())) then
  704.             GeneAssign:ShowEditWindow()
  705.         else
  706.             GeneAssign:Print("Nemas dostatecna prava")
  707.         end
  708.     end)
  709.    
  710.     -- slider k zmene velikosti fontu
  711.     local sizeSliderName = "SizeSlider"
  712.     local sizeSlider = CreateFrame("Slider", sizeSliderName, interfaceWindow, "OptionsSliderTemplate")
  713.     sizeSlider:SetPoint("TOPLEFT", fontSizeLabel, "TOPRIGHT", 60, 0)
  714.     -- z _G se vytahne odkaz na fontstringy ktere jsou jako popisky k slideru (existujou protoze dedime z sablony OptionsSliderTemplate, ve kterych ty fontstringy jsou)
  715.     sizeSlider.textLow = _G[sizeSliderName.."Low"]
  716.     sizeSlider.textHigh = _G[sizeSliderName.."High"]
  717.     sizeSlider.text = _G[sizeSliderName.."Text"]
  718.     sizeSlider:SetMinMaxValues(12, 20)
  719.     sizeSlider.minValue, sizeSlider.maxValue = sizeSlider:GetMinMaxValues()
  720.     sizeSlider:SetValue(self.db.char.fontSize)
  721.     sizeSlider:SetValueStep(1)
  722.     sizeSlider.textLow:SetText(sizeSlider.minValue)
  723.     sizeSlider.textHigh:SetText(sizeSlider.maxValue)
  724.     sizeSlider.text:SetText(sizeSlider:GetValue())
  725.     sizeSlider:SetScript("OnValueChanged", function(self,value)
  726.         self.text:SetText(value)
  727.         GeneAssign.textWindow.messageFrame:SetFont(GeneAssign.defaultFont, value, nil)
  728.         GeneAssign.db.char.fontSize = value
  729.     end)
  730.    
  731.     interfaceWindow.buttonShow = toggleWindowBtn
  732.     interfaceWindow.buttonLock = lockWindowBtn
  733.     interfaceWindow.buttonEdit = editPageBtn
  734.     GeneAssign.interfaceWindow = interfaceWindow
  735.     InterfaceOptions_AddCategory(interfaceWindow)
  736. end
  737.  
  738. -------------------------
  739. --      EDIT OKNO
  740. -------------------------
  741. function GeneAssign:BuildEditWindow()
  742.     -- cele okno by bylo treba rozsirit o priblizne 200 - 250 px, aby se tam vlezly i ty stranky.. jedna moznost je to tam dat natvrdo, coz se mi ale trochu nelibi,
  743.     -- protoze uz tak je to okno docela siroke a bylo by jeste o tretinu sirsi.. anebo tam nekde vecpat tlacitko, ktere ty stranky zobrazi jakoby na toggle.. pokud bych se rozhodl pro tohle, bylo by vhodne
  744.     -- ukotvit veskere prvky co tam tedka jsou k prave strane, se kterou se hybat nebude, aby se nerozhasily, kdyz by se ten frame pridal.. OVSEM, ted tak uvazuju, kdybych to dal jako na toggle, pak bych pravdepodobne to pridal
  745.     -- jako zvlast frame a ukotvil tak, aby ty dotykajici se hrany se nejak prekryvaly a pak by se nic kotvit znova nemuselo.. to zni dobre
  746.     -- cele okno
  747.     local editWindow = CreateFrame("Frame", "EditPageWindow", UIParent)
  748.     editWindow:Hide()
  749.     editWindow:SetBackdrop({
  750.         bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
  751.         edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
  752.         tile = true, tileSize = 32, edgeSize = 32,
  753.         insets = { left = 8, right = 8, top = 8, bottom = 8 }
  754.     })
  755.     editWindow:SetSize(610, 380)
  756.     editWindow:SetMovable(true)
  757.     editWindow:EnableMouse(true)
  758.     editWindow:SetFrameStrata("FULLSCREEN_DIALOG")
  759.     editWindow:SetToplevel(true)
  760.     editWindow:SetPoint("CENTER", 0, 0)
  761.     editWindow:SetScript("OnMouseDown", function(self, button)
  762.         self:StartMoving()
  763.         --if GeneAssign.pageSelectToggle then
  764.         --  GeneAssign.pageWindow:StartMoving()
  765.         --end
  766.     end)
  767.     editWindow:SetScript("OnMouseUp", function(self, button) self:StopMovingOrSizing() end)
  768.     editWindow:SetScript("OnHide", function(self)
  769.         GeneAssign:RevertChanges()
  770.         if GeneAssign.pageSelectToggle then
  771.             GeneAssign.pageWindow:Hide()
  772.             GeneAssign.pageSelectToggle = false
  773.         end
  774.     end)
  775.     -- pridame do specialni tabulky = okno se da zavrit escapem
  776.     tinsert(UISpecialFrames, "EditPageWindow")
  777.    
  778.    
  779.     -- az po dalsi komentar se jedna o titulek co se zobrazi uprostred nad oknem - jedna se o frame, jeho texturu rozdelenou na 3 casti a samotny text v nem
  780.     local titlebg = editWindow:CreateTexture(nil, "OVERLAY")
  781.     titlebg:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header")
  782.     titlebg:SetTexCoord(0.31, 0.67, 0, 0.63)
  783.     titlebg:SetPoint("TOP", 0, 12)
  784.     titlebg:SetWidth(100)
  785.     titlebg:SetHeight(40)
  786.  
  787.     local title = CreateFrame("Frame", nil, editWindow)
  788.     title:EnableMouse(true)
  789.     title:SetScript("OnMouseDown", function(self, button) self:GetParent():StartMoving() end)
  790.     title:SetScript("OnMouseUp", function(self, button) self:GetParent():StopMovingOrSizing() end)
  791.     title:SetAllPoints(titlebg)
  792.  
  793.     local titletext = title:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  794.     titletext:SetPoint("TOP", titlebg, "TOP", 0, -14)
  795.     titletext:SetText("Edituj stranku")
  796.  
  797.     local titlebg_l = editWindow:CreateTexture(nil, "OVERLAY")
  798.     titlebg_l:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header")
  799.     titlebg_l:SetTexCoord(0.21, 0.31, 0, 0.63)
  800.     titlebg_l:SetPoint("RIGHT", titlebg, "LEFT")
  801.     titlebg_l:SetWidth(30)
  802.     titlebg_l:SetHeight(40)
  803.  
  804.     local titlebg_r = editWindow:CreateTexture(nil, "OVERLAY")
  805.     titlebg_r:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header")
  806.     titlebg_r:SetTexCoord(0.67, 0.77, 0, 0.63)
  807.     titlebg_r:SetPoint("LEFT", titlebg, "RIGHT")
  808.     titlebg_r:SetWidth(30)
  809.     titlebg_r:SetHeight(40)
  810.     --
  811.     -- titulek k toolboxu
  812.     local toolboxLabel = editWindow:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
  813.     toolboxLabel:SetText("Toolbox")
  814.     toolboxLabel:SetPoint("TOPLEFT", 20, -30)
  815.     -- titulek ke strance
  816.     local pageLabel = editWindow:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
  817.     pageLabel:SetText("Stranka")
  818.     pageLabel:SetPoint("TOPLEFT", 185, -30)
  819.    
  820.     local pageName = editWindow:CreateFontString(nil, "ARTWORK", "GameFontWhiteSmall")
  821.     pageName:SetText(self.pages[self.selectedPage].text)
  822.     pageName:SetPoint("BOTTOMLEFT", pageLabel, "BOTTOMRIGHT", 4, 0)
  823.     -- titulek se stavem zpravy
  824.     local statusTextLabel = editWindow:CreateFontString(nil, "ARTWORK", "GameFontWhite")
  825.     statusTextLabel:SetText("Stranka |cff00ff00je |rulozena")
  826.     statusTextLabel:SetPoint("TOPRIGHT", -50, -30)
  827.    
  828.     -- data o vsech malych tlacitcich v toolboxu - text co se ma zobrazit, velikost, umisteni a v pripade barvy textu i to co se ma vlozit po kliknuti
  829.     local buttonData = {
  830.         { text = "|credCervena",        size = {77,26}, anchorPoint = {"TOPLEFT", 22, -50},     altText = "|cred"},
  831.         { text = "|corange Oranzova",   size = {77,26}, anchorPoint = {"TOPLEFT", 102, -50},    altText = "|corange"},
  832.         { text = "|cyellowZluta",       size = {77,26}, anchorPoint = {"TOPLEFT", 22, -80},     altText = "|cyellow"},
  833.         { text = "|cgreenZelena",       size = {77,26}, anchorPoint = {"TOPLEFT", 102, -80},    altText = "|cgreen"},
  834.         { text = "|cblueModra",         size = {77,26}, anchorPoint = {"TOPLEFT", 22, -110},    altText = "|cblue"},
  835.         { text = "|cpurpleFialova",     size = {77,26}, anchorPoint = {"TOPLEFT", 102, -110},   altText = "|cpurple"},
  836.         { text = "|cpinkRuzova",        size = {77,26}, anchorPoint = {"TOPLEFT", 22, -140},    altText = "|cpink"},
  837.         { text = "|cwhiteBila",         size = {77,26}, anchorPoint = {"TOPLEFT", 102, -140},   altText = "|cwhite"},
  838.        
  839.         { text = " {star}",     size = {26,26}, anchorPoint = {"TOPLEFT", 22, -170}},
  840.         { text = " {circle}",   size = {26,26}, anchorPoint = {"TOPLEFT", 54, -170}},
  841.         { text = " {diamond}",  size = {26,26}, anchorPoint = {"TOPLEFT", 86, -170}},
  842.         { text = " {triangle}", size = {26,26}, anchorPoint = {"TOPLEFT", 118, -170}},
  843.         { text = " {moon}",     size = {26,26}, anchorPoint = {"TOPLEFT", 150, -170}},
  844.         { text = " {square}",   size = {26,26}, anchorPoint = {"TOPLEFT", 22, -200}},
  845.         { text = " {cross}",    size = {26,26}, anchorPoint = {"TOPLEFT", 54, -200}},
  846.         { text = " {skull}",    size = {26,26}, anchorPoint = {"TOPLEFT", 86, -200}},
  847.        
  848.         { text = " {healthstone}",  size = {26,26}, anchorPoint = {"TOPLEFT", 118, -200}},
  849.         { text = " {bloodlust}",    size = {26,26}, anchorPoint = {"TOPLEFT", 150, -200}},
  850.         { text = " {damage}",       size = {26,26}, anchorPoint = {"TOPLEFT", 22, -230}},
  851.         { text = " {tank}",         size = {26,26}, anchorPoint = {"TOPLEFT", 54, -230}},
  852.         { text = " {healer}",       size = {26,26}, anchorPoint = {"TOPLEFT", 86, -230}},
  853.        
  854.         { text = " {hunter}",       size = {26,26}, anchorPoint = {"TOPLEFT", 118, -230}},
  855.         { text = " {warrior}",      size = {26,26}, anchorPoint = {"TOPLEFT", 150, -230}},
  856.         { text = " {rogue}",        size = {26,26}, anchorPoint = {"TOPLEFT", 22, -260}},
  857.         { text = " {mage}",         size = {26,26}, anchorPoint = {"TOPLEFT", 54, -260}},
  858.         { text = " {priest}",       size = {26,26}, anchorPoint = {"TOPLEFT", 86, -260}},
  859.         { text = " {warlock}",      size = {26,26}, anchorPoint = {"TOPLEFT", 118, -260}},
  860.         { text = " {druid}",        size = {26,26}, anchorPoint = {"TOPLEFT", 150, -260}},
  861.         { text = " {paladin}",      size = {26,26}, anchorPoint = {"TOPLEFT", 22, -290}},
  862.         { text = " {deathknight}",  size = {26,26}, anchorPoint = {"TOPLEFT", 54, -290}},
  863.         { text = " {shaman}",       size = {26,26}, anchorPoint = {"TOPLEFT", 86, -290}},
  864.     }
  865.     -- iteruju celym polem, a pro kazde tlacitko vezmu jeho detaily a predam do funkce, ktera to tlacitko vytvori a prida do toho framu
  866.     for i, obj in ipairs(buttonData) do
  867.         self:CreateToolboxButton(editWindow, obj.text, obj.size, obj.anchorPoint, obj.altText or nil)
  868.     end
  869.    
  870.     local togglePagesButton = CreateFrame("Button", nil, editWindow)
  871.     togglePagesButton:SetNormalTexture("Interface\\Buttons\\UI-SpellbookIcon-PrevPage-Up.blp")
  872.     togglePagesButton:SetPushedTexture("Interface\\Buttons\\UI-SpellbookIcon-PrevPage-Down.blp")   
  873.     togglePagesButton:SetHighlightTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Highlight.blp")
  874.     togglePagesButton:SetWidth(30)
  875.     togglePagesButton:SetHeight(30)
  876.     togglePagesButton:SetPoint("BOTTOMLEFT", 15, 18)
  877.     togglePagesButton:SetScript("OnClick", function(self, button, down)
  878.         GeneAssign:TogglePagesButtonClick()
  879.     end)
  880.     -- tlacitko Ulozit zmeny
  881.     local acceptButton = CreateFrame("Button", nil, editWindow, "UIPanelButtonTemplate")
  882.     acceptButton:SetText("Ulozit zmeny")
  883.     acceptButton:SetSize(acceptButton:GetTextWidth()+40, acceptButton:GetTextHeight()+20)
  884.     acceptButton:SetPoint("TOPLEFT", togglePagesButton, "TOPRIGHT", 5, 0)
  885.     acceptButton:SetScript("OnClick", function(self, button, down)
  886.         GeneAssign:AcceptButtonClick()
  887.     end)
  888.    
  889.     -- tlacitko Vratit zmeny
  890.     local revertButton = CreateFrame("Button", nil, editWindow, "UIPanelButtonTemplate")
  891.     revertButton:SetText("Vratit zmeny")
  892.     revertButton:SetSize(revertButton:GetTextWidth()+40, revertButton:GetTextHeight()+20)
  893.     revertButton:SetPoint("TOPLEFT", acceptButton, "TOPRIGHT", 0, 0)
  894.     revertButton:SetScript("OnClick", function(self, button, down)
  895.         GeneAssign.RevertButtonClick()
  896.     end)
  897.    
  898.     -- tlacitko Nahled
  899.     local previewButton = CreateFrame("Button", nil, editWindow, "UIPanelButtonTemplate")
  900.     previewButton:SetText("Nahled")
  901.     previewButton:SetSize(previewButton:GetTextWidth()+40, previewButton:GetTextHeight()+20)
  902.     previewButton:SetPoint("TOPLEFT", revertButton, "TOPRIGHT", 5, 0)
  903.     previewButton:SetScript("OnClick", function(self, button, down)
  904.         GeneAssign:PreviewButtonClick()
  905.     end)
  906.    
  907.     -- tlacitko Ulozit a poslat
  908.     local sendButton = CreateFrame("Button", nil, editWindow, "UIPanelButtonTemplate")
  909.     sendButton:SetText("Ulozit a poslat")
  910.     sendButton:SetSize(sendButton:GetTextWidth()+40, sendButton:GetTextHeight()+20)
  911.     sendButton:SetPoint("TOPLEFT", previewButton, "TOPRIGHT", 5, 0)
  912.     sendButton:SetScript("OnClick", function(self, button, down)
  913.         if(IsInRaid() and (IsRaidLeader() or IsRaidOfficer())) then
  914.             GeneAssign:SendButtonClick()
  915.         else
  916.             GeneAssign:Print("Nemas dostatecna prava")
  917.         end
  918.     end)
  919.    
  920.     -- tlacitko Zavrit
  921.     local closeButton = CreateFrame("Button", nil, editWindow, "UIPanelButtonTemplate")
  922.     closeButton:SetText("Zavrit")
  923.     closeButton:SetSize(closeButton:GetTextWidth()+40, closeButton:GetTextHeight()+20)
  924.     closeButton:SetPoint("TOPLEFT", sendButton, "TOPRIGHT", 5, 0)
  925.     closeButton:SetScript("OnClick", function(self, button, down)
  926.         -- GeneAssign:RevertChanges() --tady neni asi treba, pridal sem OnHide event, ve kterem ty changes revertnu, at to zavru tlacitkem anebo escapem
  927.         editWindow:Hide()
  928.     end)
  929.    
  930.     -- frame jako kontejner pro EditBox, ScrollFrame a Slider (na samotny scroll)
  931.     local editFrame = CreateFrame("Frame", "EditFrameContainer", editWindow)
  932.     editFrame:SetSize(380, 270)
  933.     editFrame:SetPoint("TOPLEFT", pageLabel, "BOTTOMLEFT", 8, -5)
  934.     editFrame:SetBackdrop({
  935.         bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
  936.         edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
  937.         edgeSize = 16,
  938.         insets = { left = 4, right = 3, top = 4, bottom = 3 }
  939.     })
  940.     editFrame:SetBackdropColor(0, 0, 0)
  941.     editFrame:SetBackdropBorderColor(0.4, 0.4, 0.4)
  942.    
  943.     local editBox = CreateFrame("EditBox", "EditPageEditBox", editFrame)
  944.     editBox:SetMultiLine(true)
  945.     editBox:SetAutoFocus(false)
  946.     editBox:EnableMouse(true)
  947.     editBox:SetFont(self.defaultFont, 16, nil)
  948.     editBox:SetWidth(370)
  949.     editBox:SetHeight(270)
  950.     editBox:SetScript("OnEscapePressed", editBox.ClearFocus)
  951.     editBox:SetScript("OnTextChanged", EditBox_TextChanged)
  952.    
  953.     local scrollFrame = CreateFrame("ScrollFrame", "EditPageScrollFrame", editFrame, "UIPanelScrollFrameTemplate")
  954.     scrollFrame:SetPoint("TOPLEFT", 8, -8)
  955.     scrollFrame:SetPoint("BOTTOMRIGHT", -8, 8)
  956.     scrollFrame:SetScrollChild(editBox)
  957.     local scrollBar = _G[scrollFrame:GetName().."ScrollBar"]
  958.     scrollBar.bg = scrollBar:CreateTexture(nil, "BACKGROUND")
  959.     scrollBar.bg:SetAllPoints(true)
  960.     scrollBar.bg:SetTexture(0, 0, 0, 0.5)
  961.     editBox:SetFocus()
  962.    
  963.     editWindow.statusText = statusTextLabel
  964.     editWindow.editBox = editBox
  965.     editWindow.buttonAccept = acceptButton
  966.     editWindow.buttonRevert = revertButton
  967.     editWindow.buttonSend = sendButton
  968.     editWindow.buttonPreview = previewButton
  969.     editWindow.buttonTogglePages = togglePagesButton
  970.     editWindow.pageNameLabel = pageName
  971.     GeneAssign.editWindow = editWindow
  972. end
  973.  
  974. function GeneAssign:RevertChanges()
  975.     -- vratim do editboxu zalohu textu a zablokuju tlacitka
  976.     if not self.db.char.backup then self:Print("Neexistuje zadna zaloha k vraceni") return end
  977.     self.editWindow.editBox:SetText(self.db.char.backup)
  978.     self.editWindow.buttonAccept:Disable()
  979.     self.editWindow.buttonRevert:Disable()
  980. end
  981.  
  982. function GeneAssign:AcceptChanges()
  983.     -- ulozim do zalohy aktualni text v editboxu
  984.     local text = self.editWindow.editBox:GetText()
  985.     if not text then text = "" end
  986.     self.db.char.backup = text
  987.     self.editWindow.statusText:SetText("Stranka |cff00ff00je |rulozena")
  988. end
  989.  
  990. function GeneAssign:ShowEditWindow()
  991.     self.editWindow:Show()
  992.     self:RevertChanges()
  993.     self.editWindow.buttonAccept:Enable()
  994.     self.editWindow.buttonRevert:Enable()
  995.     self.pageSelectToggle = false
  996.     self.editWindow.buttonTogglePages:SetButtonState("NORMAL")
  997.     EditBox_TextChanged()
  998. end
  999.  
  1000. function GeneAssign:CreateToolboxButton(frame, showText, size, anchorPoint, text)
  1001.     -- vytvorim tlacitko podle zadanych parametru
  1002.     local button = CreateFrame("Button", nil, frame)
  1003.     button:SetBackdrop({
  1004.         edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
  1005.         edgeSize = 8
  1006.     })
  1007.     button:SetBackdropBorderColor(1, 1, 1, 0.5)
  1008.     button:SetPushedTextOffset(1, -1)
  1009.     button:SetText(RecognizeFixPatterns(showText))
  1010.     button:SetSize(unpack(size))
  1011.     button:SetNormalFontObject(GameFontHighlightMedium)
  1012.     button:SetPoint(unpack(anchorPoint))
  1013.     button:SetScript("OnClick", function(self, button)
  1014.         local fixedText
  1015.         if text then            -- pokud je zadany posledni parametr text (ktery je jen u barevneho textu) tak pouziju ten
  1016.             fixedText = text
  1017.         else                    -- jinak smazu mezeru ktera je na zacatku (ta je pro vycentrovani ikonky doprostred tlacitka)
  1018.             fixedText = showText:gsub(" {", "{")
  1019.         end
  1020.         GeneAssign.editWindow.editBox:Insert(fixedText)
  1021.     end)
  1022. end
  1023.  
  1024. ------------------------------
  1025. --      POMOCNE FUNKCE
  1026. ------------------------------
  1027. function IsInRaid()
  1028.     local inInstance, instanceType = IsInInstance()
  1029.     local result = false
  1030.     if(GetRealNumRaidMembers() > 0 and instanceType ~= "pvp" and instanceType ~= "arena") then
  1031.         result = true
  1032.     end
  1033.     return result  
  1034. end
  1035.  
  1036. function ci_pattern(pattern)
  1037.     -- uprimne toto netusim jak funguje, ale funguje, je to zkopirovano z AA
  1038.     local p = pattern:gsub("(%%?)(.)", function(percent, letter)
  1039.         if percent ~= "" or not letter:match("%a") then
  1040.             return percent .. letter
  1041.         else
  1042.             return string.format("[%s%s]", letter:lower(), letter:upper())
  1043.         end
  1044.     end)
  1045.     return p
  1046. end
  1047.  
  1048. function RecognizeFixPatterns(text)
  1049.     -- nahradi znacky jejich spravnymi ikonkami/kody
  1050.     text = text:gsub("||", "|")
  1051.                 :gsub(ci_pattern('|cblue'), "|cff00cbf4")
  1052.                 :gsub(ci_pattern('|cgreen'), "|cff0adc00")
  1053.                 :gsub(ci_pattern('|cred'), "|cffeb310c")
  1054.                 :gsub(ci_pattern('|cyellow'), "|cfffaf318")
  1055.                 :gsub(ci_pattern('|corange'), "|cffff9d00")
  1056.                 :gsub(ci_pattern('|cpink'), "|cfff64c97")
  1057.                 :gsub(ci_pattern('|cpurple'), "|cffdc44eb")
  1058.                 :gsub(ci_pattern('|cwhite'), "|cffffffff")
  1059.                 :gsub(ci_pattern('{star}'), "{rt1}")
  1060.                 :gsub(ci_pattern('{circle}'), "{rt2}")
  1061.                 :gsub(ci_pattern('{diamond}'), "{rt3}")
  1062.                 :gsub(ci_pattern('{triangle}'), "{rt4}")
  1063.                 :gsub(ci_pattern('{moon}'), "{rt5}")
  1064.                 :gsub(ci_pattern('{square}'), "{rt6}")
  1065.                 :gsub(ci_pattern('{cross}'), "{rt7}")
  1066.                 :gsub(ci_pattern('{x}'), "{rt7}")
  1067.                 :gsub(ci_pattern('{skull}'), "{rt8}")
  1068.                 :gsub(ci_pattern('{rt([1-8])}'), "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_%1:0|t" )
  1069.                 :gsub(ci_pattern('{healthstone}'), "{hs}")
  1070.                 :gsub(ci_pattern('{hs}'), "|TInterface\\Icons\\INV_Stone_04:0|t")
  1071.                 :gsub(ci_pattern('{bloodlust}'), "{bl}")
  1072.                 :gsub(ci_pattern('{bl}'), "|TInterface\\Icons\\SPELL_Nature_Bloodlust:0|t")
  1073.                 :gsub(ci_pattern('{damage}'), "{dps}")
  1074.                 :gsub(ci_pattern('{tank}'), "|TInterface\\LFGFrame\\UI-LFG-ICON-PORTRAITROLES:0:0:0:0:64:64:0:19:22:41|t")
  1075.                 :gsub(ci_pattern('{healer}'), "|TInterface\\LFGFrame\\UI-LFG-ICON-PORTRAITROLES:0:0:0:0:64:64:20:39:1:20|t")
  1076.                 :gsub(ci_pattern('{dps}'), "|TInterface\\LFGFrame\\UI-LFG-ICON-PORTRAITROLES:0:0:0:0:64:64:20:39:22:41|t")
  1077.                 :gsub(ci_pattern('{hero}'), "{heroism}")
  1078.                 :gsub(ci_pattern('{heroism}'), "|TInterface\\Icons\\ABILITY_Shaman_Heroism:0|t")
  1079.                 :gsub(ci_pattern('{hunter}'), "|TInterface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES:0:0:0:0:64:64:0:16:16:32|t")
  1080.                 :gsub(ci_pattern('{warrior}'), "|TInterface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES:0:0:0:0:64:64:0:16:0:16|t")
  1081.                 :gsub(ci_pattern('{rogue}'), "|TInterface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES:0:0:0:0:64:64:32:48:0:16|t")
  1082.                 :gsub(ci_pattern('{mage}'), "|TInterface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES:0:0:0:0:64:64:16:32:0:16|t")
  1083.                 :gsub(ci_pattern('{priest}'), "|TInterface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES:0:0:0:0:64:64:32:48:16:32|t")
  1084.                 :gsub(ci_pattern('{warlock}'), "|TInterface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES:0:0:0:0:64:64:48:64:16:32|t")
  1085.                 :gsub(ci_pattern('{paladin}'), "|TInterface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES:0:0:0:0:64:64:0:16:32:48|t")
  1086.                 :gsub(ci_pattern('{deathknight}'), "|TInterface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES:0:0:0:0:64:64:16:32:32:48|t")
  1087.                 :gsub(ci_pattern('{druid}'), "|TInterface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES:0:0:0:0:64:64:48:64:0:16|t")
  1088.                 :gsub(ci_pattern('{shaman}'), "|TInterface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES:0:0:0:0:64:64:16:32:16:32|t")
  1089.         return text
  1090. end
  1091.  
  1092. ------------------------------
  1093. --      EVENT HANDLERY
  1094. ------------------------------
  1095. function TextFrame_OnMouseDown(self, button)
  1096.     -- pri posunu textWindow
  1097.     if not GeneAssign.db.char.locked then
  1098.         if(button == "LeftButton") then
  1099.             self:StartMoving()
  1100.             self.isMoving = true
  1101.         end
  1102.     end
  1103. end
  1104.  
  1105. function TextFrame_OnMouseUp(self, button)
  1106.     -- pri posunu textWindow
  1107.     if not GeneAssign.db.char.locked then
  1108.         if self.isMoving then
  1109.             self:StopMovingOrSizing()
  1110.             self.isMoving = false
  1111.             lwin.SavePosition(self)
  1112.         end
  1113.     end
  1114. end
  1115.  
  1116. function TextFrame_DragDown(self, button)
  1117.     -- pri resizu textWindow
  1118.     local par = self:GetParent()
  1119.     par:StartSizing()
  1120.     par.isMoving = true
  1121. end
  1122.  
  1123. function TextFrame_DragUp(self, button)
  1124.     -- pri resizu textWindow
  1125.     local par = self:GetParent()
  1126.     if par.isMoving then
  1127.         par:StopMovingOrSizing()
  1128.         par.isMoving = false
  1129.         lwin.SavePosition(par)
  1130.     end
  1131. end
  1132.  
  1133. function EditBox_TextChanged(self, userInput)
  1134.     -- pri zmene textu v EditBoxu, pokud se text rovna zaloze, pak zablokuje tlacitka, jinak je odblokuje
  1135.     if(GeneAssign.editWindow.editBox:GetText() == GeneAssign.db.char.backup) then
  1136.         GeneAssign.editWindow.buttonAccept:Disable()
  1137.         GeneAssign.editWindow.buttonRevert:Disable()
  1138.         GeneAssign.editWindow.statusText:SetText("Stranka |cff00ff00je |rulozena")
  1139.         return
  1140.     end
  1141.     -- pokud jsme v nahledovem modu, pak veskere zmeny ukazujeme v messageframu (a tlacitka neodblokovavame)
  1142.     if GeneAssign.previewToggle then
  1143.         GeneAssign.textWindow.messageFrame:Clear()
  1144.         local rawText = GeneAssign.editWindow.editBox:GetText()
  1145.         local text = RecognizeFixPatterns(rawText)
  1146.         local lines = { strsplit("\n", text) }
  1147.         local lines_count = #lines
  1148.         for i = 1, lines_count do
  1149.             local line = lines[i]
  1150.             if line == "" then line = " " end
  1151.             GeneAssign.textWindow.messageFrame:AddMessage(line)
  1152.         end
  1153.     else   
  1154.         if(not GeneAssign.editWindow.buttonAccept:IsEnabled()) then GeneAssign.editWindow.buttonAccept:Enable() end
  1155.         if(not GeneAssign.editWindow.buttonRevert:IsEnabled()) then GeneAssign.editWindow.buttonRevert:Enable() end
  1156.     end
  1157.     GeneAssign.editWindow.statusText:SetText("Stranka |cffff0000neni |rulozena")
  1158. end
  1159.  
  1160. function GeneAssign:TogglePagesButtonClick()
  1161.     if not self.pageSelectToggle then
  1162.         -- zobrazit vyber stranek a prilepit ho vlevo k oknu
  1163.         self.editWindow.buttonTogglePages:SetButtonState("PUSHED", true)
  1164.        
  1165.         self.pageWindow:ClearAllPoints()
  1166.         self.pageWindow:SetPoint("TOPRIGHT", self.editWindow, "TOPLEFT", 5, 0)
  1167.         self.pageWindow:Show()
  1168.     else
  1169.         -- skryt vyber stranek
  1170.         self.editWindow.buttonTogglePages:SetButtonState("NORMAL")
  1171.         self.pageWindow:Hide()
  1172.     end
  1173.     self.pageSelectToggle = not self.pageSelectToggle
  1174. end
  1175.  
  1176. function GeneAssign:AcceptButtonClick()
  1177.     self:AcceptChanges()
  1178.     self.editWindow.buttonAccept:Disable()
  1179.     self.editWindow.buttonRevert:Disable()
  1180. end
  1181.  
  1182. function GeneAssign:RevertButtonClick()
  1183.     StaticPopup_Show("REVERT_CONFIRM")
  1184. end
  1185.  
  1186. function GeneAssign:PreviewButtonClick()
  1187.     if not self.previewToggle then
  1188.         -- zobrazit nahled
  1189.         -- vezmu aktualni text a pouze ho zobrazim do messageframu.. nebudu ukladat, zmeny v editwindowu to co je zobrazene asi nebudou ovlivnovat (aspon zatim, muzu to zkusit jak to bude vypadat)
  1190.         -- zablokovat ostatni tlacitka pritom? to zni divne ale prvne to tak zkusim, jake to bude - neni to tak zle.. muzes si prohlidnout jak to vypada a az to je hotove, zrusis nahled, ulozis
  1191.         self.editWindow.buttonAccept:Disable()
  1192.         self.editWindow.buttonRevert:Disable()
  1193.         self.editWindow.buttonSend:Disable()
  1194.         self.editWindow.buttonPreview:SetButtonState("PUSHED", true)
  1195.        
  1196.        
  1197.         self.textWindow.messageFrame:Clear()
  1198.         local rawText = self.editWindow.editBox:GetText()
  1199.         local text = RecognizeFixPatterns(rawText)
  1200.         local lines = { strsplit("\n", text) }
  1201.         local lines_count = #lines
  1202.         for i = 1, lines_count do
  1203.             local line = lines[i]
  1204.             if line == "" then line = " " end
  1205.             self.textWindow.messageFrame:AddMessage(line)
  1206.         end
  1207.     else
  1208.         -- skryt nahled
  1209.         -- do messageframu vratim posledni ulozeny text
  1210.         self.editWindow.buttonAccept:Enable()
  1211.         self.editWindow.buttonRevert:Enable()
  1212.         self.editWindow.buttonSend:Enable()
  1213.         self.editWindow.buttonPreview:SetButtonState("NORMAL")
  1214.        
  1215.        
  1216.         self.textWindow.messageFrame:Clear()
  1217.         local rawText = self.db.char.backup
  1218.         local text = RecognizeFixPatterns(rawText)
  1219.         local lines = { strsplit("\n", text) }
  1220.         local lines_count = #lines
  1221.         for i = 1, lines_count do
  1222.             local line = lines[i]
  1223.             if line == "" then line = " " end
  1224.             self.textWindow.messageFrame:AddMessage(line)
  1225.         end
  1226.     end
  1227.     self.previewToggle = not self.previewToggle
  1228. end
  1229.  
  1230. function GeneAssign:SendButtonClick()
  1231.     -- ulozi zmeny, zablokuje tlacitka, zobrazi zpravu nam a pak ji posle do raidu
  1232.     self:AcceptChanges()
  1233.     self.editWindow.buttonAccept:Disable()
  1234.     self.editWindow.buttonRevert:Disable()
  1235.    
  1236.     if(not self.textWindow:IsShown()) then
  1237.         self.textWindow:Show()
  1238.         self.db.char.shown = true
  1239.         self.interfaceWindow.buttonShow:SetText("Skryj okno")
  1240.     end
  1241.    
  1242.     self.textWindow.messageFrame:Clear()
  1243.     local rawText = self.editWindow.editBox:GetText()
  1244.     local text = RecognizeFixPatterns(rawText)
  1245.     local lines = { strsplit("\n", text) }
  1246.     local lines_count = #lines
  1247.     for i = 1, lines_count do
  1248.         local line = lines[i]
  1249.         if line == "" then line = " " end
  1250.         self.textWindow.messageFrame:AddMessage(line)
  1251.     end
  1252.    
  1253.     self:SendMessage(rawText)
  1254. end
  1255.  
  1256. function GeneAssign:RAID_ROSTER_UPDATE()
  1257.     -- pri jakekoli zmene v raidu (party->raid, raid->party, zmena RL/assista, demote, kick z raidu, join do raidu atd.) zkontroluje, zda mame prava k editaci stranek a jejich posilani (jestli jsme RL/assist)
  1258.     self:CheckPermissions()
  1259. end
  1260.  
  1261. function GeneAssign:PLAYER_GUILD_UPDATE()
  1262.     -- pokud dojde k nejake zmene a bud jsme bez guildy nebo jiz nejsme v The Genesis, znicime po sobe dukazy :D
  1263.     local isInGuild = IsInGuild()
  1264.     local guildName, _, _ = GetGuildInfo("player")
  1265.     if(not (isInGuild == 1 and guildName == "The Genesis")) then
  1266.         self:DestroyEvidence()
  1267.     end
  1268. end
  1269.  
  1270. function GeneAssign:GUILD_ROSTER_UPDATE()
  1271.     self:UnregisterEvent("GUILD_ROSTER_UPDATE")
  1272.     local guildName, _, _ = GetGuildInfo("player")
  1273.     if(guildName ~= "The Genesis") then
  1274.         return
  1275.     else
  1276.         self:AfterEnable()
  1277.     end
  1278. end
  1279.  
  1280. ------------------------------
  1281. --      OSTATNI FUNKCE
  1282. ------------------------------
  1283. function GeneAssign:CheckPermissions()
  1284.     -- zkontroluje zda jsme v raidu a jsme RL/assist, pokud ano, odemkne nam pristup k edit oknu
  1285.     local permission = IsInRaid() and (IsRaidLeader() or IsRaidOfficer())
  1286.     if permission then
  1287.         self.editWindow.buttonSend:Enable()
  1288.         self.interfaceWindow.buttonEdit:Enable()
  1289.     else
  1290.         if(self.editWindow:IsShown()) then self.editWindow:Hide() end
  1291.         self.editWindow.buttonSend:Disable()
  1292.         self.interfaceWindow.buttonEdit:Disable()
  1293.     end
  1294.     return permission
  1295. end
  1296.  
  1297. function GeneAssign:ProcessSlashCommand(input)
  1298.     -- pomocna funkce k tisku napovedy
  1299.     local function PrintCommand(cmd, desc)
  1300.         print(string.format(' - |cFF33FF99%s|r: %s', cmd, desc))
  1301.     end
  1302.    
  1303.     -- obsluhuje slash commandy, viz komentare
  1304.     if not input or input:trim() == "" then
  1305.         --/ga
  1306.         self:ToggleShow()  
  1307.     else
  1308.         input = input:trim():lower()
  1309.        
  1310.         if(input == "show") then
  1311.             --/ga show
  1312.             self:ToggleShow()
  1313.         elseif(input == "options") then
  1314.             --/ga options
  1315.             InterfaceOptionsFrame_OpenToCategory(self.interfaceWindow)
  1316.         elseif(input == "lock") then
  1317.             --/ga lock
  1318.             self:ToggleLock()
  1319.             if(self.db.char.locked) then
  1320.                 self:Print("Okno je |cffff0000zamknute")
  1321.             else
  1322.                 self:Print("Okno je |cff00ff00odemknute")
  1323.             end
  1324.         elseif(input == "help") then
  1325.             --/ga help
  1326.             self:Print("Dostupne prikazy:")
  1327.             PrintCommand("show", "Zobrazi nebo skryje okno")
  1328.             PrintCommand("options", "Otevre nastaveni v interface")
  1329.             PrintCommand("lock", "Uzamkne nebo odemkne okno")
  1330.             PrintCommand("help", "Zobrazi napovedu")
  1331.             PrintCommand("edit", "Otevre editacni okno")
  1332.         elseif(input == "edit") then
  1333.             --/ga edit
  1334.             if(IsInRaid() and (IsRaidLeader() or IsRaidOfficer())) then
  1335.                 self:ShowEditWindow()
  1336.             else
  1337.                 self:Print("Nemate dostatecna prava pro zapis")
  1338.             end
  1339.         else
  1340.             --neznamy prikaz, zobrazi se napoveda
  1341.             self:Print("Neznamy prikaz, dostupne prikazy:")
  1342.             PrintCommand("show", "Zobrazi nebo skryje okno")
  1343.             PrintCommand("options", "Otevre nastaveni v interface")
  1344.             PrintCommand("lock", "Uzamkne nebo odemkne okno")
  1345.             PrintCommand("help", "Zobrazi napovedu")
  1346.             PrintCommand("edit", "Otevre editacni okno")
  1347.         end    
  1348.     end
  1349. end
  1350.  
  1351. function GeneAssign:DestroyEvidence() -- :D
  1352.     -- v pripade ze jsme byli kicknuti, zablokujeme komunikaci, odebereme /ga z slash commandu, skryjeme vsechny okna,
  1353.     -- odstranime kategorii Genesis Assignments z interface okna a kdybychom ho meli nahodou otevrene, tak skryjeme frame abychom dale nemohli addon nijak pouzivat
  1354.     -- (teoreticky se muze stale vyvolavat event RAID_ROSTER_UPDATE, ktery stejne ale akorat kontroluje opravneni a pripadne odblokuje/zablokuje nejake tlacitka ke kterym stejne nemame pristup)
  1355.     if not goodbyeOnce then
  1356.         self:Print("Goodbye")
  1357.         self.acceptMessages = false
  1358.         self:UnregisterChatCommand("ga")
  1359.         self:UnregisterEvent("RAID_ROSTER_UPDATE")
  1360.         self:UnregisterEvent("PLAYER_GUILD_UPDATE")
  1361.         self.editWindow:Hide()
  1362.         self.textWindow:Hide()
  1363.        
  1364.         for k, v in pairs(INTERFACEOPTIONS_ADDONCATEGORIES) do
  1365.             if(v.name == self.interfaceWindow.name) then
  1366.                 INTERFACEOPTIONS_ADDONCATEGORIES[k] = nil
  1367.             end
  1368.         end
  1369.         InterfaceAddOnsList_Update()
  1370.         if(InterfaceOptionsFramePanelContainer.displayedPanel and InterfaceOptionsFramePanelContainer.displayedPanel:IsShown()) then
  1371.             InterfaceOptionsFramePanelContainer.displayedPanel:Hide()
  1372.         end
  1373.         goodbyeOnce = true
  1374.     end
  1375. end
  1376.  
  1377. function BuildFontPicker() -- pouze pomocna feature pri vyvoji, pak se smaze
  1378.  
  1379.     -- Create the parent frame that will contain the inner scroll child,
  1380.     -- all font strings, and the scroll bar slider.
  1381.     local fp = FPreviewFrame or CreateFrame("ScrollFrame", "FPreviewFrame")
  1382.      
  1383.     -- This is a bare-bones frame is used to encapsulate the contents of
  1384.     -- the scroll frame.  Each scrollframe can have one scroll child.
  1385.     local fpsc = FPreviewSC or CreateFrame("Frame", "FPreviewSC")
  1386.      
  1387.     -- Create the slider that will be used to scroll through the results
  1388.     local fpsb = FPreviewScrollBar or CreateFrame("Slider", "FPreviewScrollBar", fp)
  1389.      
  1390.     -- Set up internal textures for the scrollbar, background and thumb texture
  1391.     if not fpsb.bg then
  1392.        fpsb.bg = fpsb:CreateTexture(nil, "BACKGROUND")
  1393.        fpsb.bg:SetAllPoints(true)
  1394.        fpsb.bg:SetTexture(0, 0, 0, 0.5)
  1395.     end
  1396.      
  1397.     if not fpsb.thumb then
  1398.        fpsb.thumb = fpsb:CreateTexture(nil, "OVERLAY")
  1399.        fpsb.thumb:SetTexture("Interface\\Buttons\\UI-ScrollBar-Knob")
  1400.        fpsb.thumb:SetSize(25, 25)
  1401.        fpsb:SetThumbTexture(fpsb.thumb)
  1402.     end
  1403.      
  1404.     local genv = getfenv(0)
  1405.      
  1406.     -- Collect the names of all possible globally defined fonts
  1407.     local fonts = {}
  1408.     for k, v in pairs(genv) do
  1409.        if type(v) == "table" and type(v.GetObjectType) == "function" then
  1410.           local otype = v:GetObjectType()
  1411.           if otype == "Font" then
  1412.              table.insert(fonts, k)
  1413.           end
  1414.        end
  1415.     end
  1416.      
  1417.     -- Sort the list alphabetically
  1418.     table.sort(fonts)
  1419.      
  1420.     -- Create a table that will contain the font strings themselves
  1421.     fpsc.fstrings = fpsc.fstrings or {}
  1422.      
  1423.     -- This changes the padding between font strings vertically
  1424.     local PADDING = 5
  1425.      
  1426.     -- Store the max width and overall height of the scroll child
  1427.     local height = 0
  1428.     local width = 0
  1429.      
  1430.     -- Iterate the list of fonts collected
  1431.     for idx, fname in ipairs(fonts) do
  1432.        -- If the font string is not created, do so
  1433.        if not fpsc.fstrings[idx] then
  1434.           print(idx, fname)
  1435.           fpsc.fstrings[idx] = fpsc:CreateFontString("FPreviewFS" .. idx, "OVERLAY")
  1436.        end
  1437.        
  1438.        -- Set the font string to the correct font object, set the text to be the
  1439.        -- name of the font and set the height/width of the font string based on
  1440.        -- the size of the resulting 'string'.
  1441.        local fs = fpsc.fstrings[idx]
  1442.        fs:SetFontObject(genv[fname])
  1443.        fs:SetText(fname)
  1444.        local fwidth = fs:GetStringWidth()
  1445.        local fheight = fs:GetStringHeight()
  1446.        fs:SetSize(fwidth, fheight)
  1447.        
  1448.        -- Place the font strings in rows starting at the top-left
  1449.        if idx == 1 then
  1450.           fs:SetPoint("TOPLEFT", 0, 0)
  1451.           height = height + fheight
  1452.        else
  1453.           fs:SetPoint("TOPLEFT", fpsc.fstrings[idx - 1], "BOTTOMLEFT", 0, - PADDING)
  1454.           height = height + fheight + PADDING
  1455.        end
  1456.        
  1457.        -- Update the 'max' width of the frame
  1458.        width = (fwidth > width) and fwidth or width
  1459.     end
  1460.      
  1461.     -- Set the size of the scroll child
  1462.     fpsc:SetSize(width, height)
  1463.      
  1464.     -- Size and place the parent frame, and set the scrollchild to be the
  1465.     -- frame of font strings we've created
  1466.     fp:SetSize(width, 400)
  1467.     fp:SetPoint("CENTER", UIParent, 0, 0)
  1468.     fp:SetScrollChild(fpsc)
  1469.     fp:Show()
  1470.      
  1471.     fpsc:SetSize(width, height)
  1472.      
  1473.     -- Set up the scrollbar to work properly
  1474.     local scrollMax = height - 400
  1475.     fpsb:SetOrientation("VERTICAL");
  1476.     fpsb:SetSize(16, 400)
  1477.     fpsb:SetPoint("TOPLEFT", fp, "TOPRIGHT", 0, 0)
  1478.     fpsb:SetMinMaxValues(0, scrollMax)
  1479.     fpsb:SetValue(0)
  1480.     fpsb:SetScript("OnValueChanged", function(self)
  1481.           fp:SetVerticalScroll(self:GetValue())
  1482.     end)
  1483.      
  1484.     -- Enable mousewheel scrolling
  1485.     fp:EnableMouseWheel(true)
  1486.     fp:SetScript("OnMouseWheel", function(self, delta)
  1487.           local current = fpsb:GetValue()
  1488.            
  1489.           if IsShiftKeyDown() and (delta > 0) then
  1490.              fpsb:SetValue(0)
  1491.           elseif IsShiftKeyDown() and (delta < 0) then
  1492.              fpsb:SetValue(scrollMax)
  1493.           elseif (delta < 0) and (current < scrollMax) then
  1494.              fpsb:SetValue(current + 20)
  1495.           elseif (delta > 0) and (current > 1) then
  1496.              fpsb:SetValue(current - 20)
  1497.           end
  1498.     end)
  1499. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement