Advertisement
sMteX

Untitled

Aug 20th, 2015
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 76.19 KB | None | 0 0
  1. local GeneAssign = LibStub("AceAddon-3.0"):NewAddon("GenesisAssignments", "AceConsole-3.0", "AceEvent-3.0", "AceComm-3.0")
  2. local lwin = LibStub("LibWindow-1.1")
  3. local serializer = LibStub("AceSerializer-3.0")
  4. local AceGUI = LibStub("AceGUI-3.0")
  5. -- z nejakeho duvodu se obcas DestroyEvidence() volal dvakrat, tak staci to jednou..
  6. local goodbyeOnce = false
  7.  
  8. --[[ Globalni promenne v GeneAssign:
  9.     textWindow - pro frame, ve kterem je messageFrame
  10.         messageFrame - pro scrolling message frame, do ktereho pujdou zpravy
  11.         dragHandle - pro tahlo na zmenu velikosti textWindowu
  12.     interfaceWindow - pro frame, ktery je hlavnim framem v interface
  13.         buttonLock - tlacitko pro lock textWindowu (menim jeho text v ToggleLock())
  14.         buttonShow - tlacitko pro show/hide textWindowu (mozna jeho zmena v SendButtonClick)
  15.         buttonEdit - tlacitko pro otevreni Edit Windowu (zmena enable state v CheckPermissions)
  16.     editWindow - pro cele editacni okno (at ho muzu v interface zobrazit)
  17.         statusText - kratky fontstring co informuje o tom jestli jsme text ulozili nebo ne
  18.         editBox (GeneAssign.editWindow.editBox) - editbox, ve kterem se edituje stranka
  19.         buttonTogglePages
  20.         buttonAccept - asi self-explanatory
  21.         buttonRevert
  22.         buttonSend
  23.         buttonPreview
  24.         buttonClose
  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.  
  46. --GeneAssign.pages = {}
  47. --GeneAssign.numPages = 0
  48. --format pro stranky:
  49. -- self.db.char.pages[ID] = { [ID] = { ID = ID, Name = "Name", Content = "Content" } }
  50.  
  51. local defaultSettings = {
  52.     char = {
  53.         pages = {
  54.             --[1] = {   ID = 1, Name = "Sample page", Content = "This is a test page" }
  55.         },
  56.         numPages = 0,
  57.         locked = false,
  58.         shown = false,
  59.         fontSize = 16,
  60.         shownText = nil
  61.     }
  62. }
  63. local GeneAssign_Pages
  64.  
  65. function GeneAssign:UpdateEditWindow()
  66.     --[[
  67.         ok, takze kdyz si prohlidnu veci co muzou ovlivnovat co mame zpristupneno nebo ne:
  68.             numPages, potazmo GeneAssign_Pages
  69.             previewToggle
  70.             editace stranky samotne (jestli je ulozena nebo ne)
  71.             prijeti stranky
  72.             ulozeni stranky
  73.             vraceni zmen stranky
  74.                
  75.         zatim me nic vic moc nenapada, treba dal na neco prijdu
  76.        
  77.         zkusime si to trochu rozepsat
  78.             numPages
  79.                 kdyz nemame zadnou stranku, je zablokovano vsechno krome sipky a tlacitka zavrit
  80.             previewToggle
  81.                 kdyz je zapnuty preview, je vypnuty accept, revert, send, cele page window
  82.             editace stranky samotne (saved or not)
  83.                 kdyz je stranka ulozena, tak je zablokovany accept a revert
  84.             prijeti stranky
  85.                 pokud prijmeme stranku, a predtim zadnou nemame, tak nemenime nic (dokud se neotevre okno s strankama)
  86.                 pokud prijmeme stranku a mame predchozi verzi otevrenou, tak se zmeni samozrejme content, name atd., a timpadem se blokne accept a revert
  87.                 pokud prijmeme stranku a mame otevrenou jinou, tak v editwindow se nic nemenime
  88.             ulozeni stranky
  89.                 po ulozeni stranky se zablokuje accept a revert
  90.             vraceni zmen
  91.                 totez jako ulozeni prakticky
  92.        
  93.         tedka, ma to mit nejakou prioritu?.. interaguje spolu neco?.. mam cokoli resit zvlast a returnovat mezitim? mozna.. uvidime
  94.     ]]
  95.     if(self.db.char.numPages == 0) then
  96.         --nemame zadne stranky, zablokovat vsechno
  97.         self:EnableDisableEditWindow(false)
  98.         --krome sipky a zavrit
  99.         self.editWindow.buttonTogglePages:Enable()
  100.         self.editWindow.buttonClose:Enable()
  101.         return
  102.     else
  103.         --mame stranky, nejdrive vsechno zapnu, postupne podle potreby budu vypinat
  104.         self:EnableDisableEditWindow(true)
  105.     end
  106.     if(self.previewToggle) then
  107.         --kdyz je zapnuty toggle, vypnuty accept, revert, send, page window
  108.         self.editWindow.buttonAccept:Disable()
  109.         self.editWindow.buttonRevert:Disable()
  110.         self.editWindow.buttonSend:Disable()
  111.         self:EnableDisablePageWindow(false)
  112.         return
  113.     end
  114.     if not self.selectedPage then
  115.         --nemame zadnou vybranou stranku ale stranky mame (napr. kdyz jsme nemeli zadne, prijali jsme jednu ale jeste jsme neotevreli okno s strankama)
  116.         --zablokovat vsechno
  117.         self:EnableDisableEditWindow(false)
  118.         --krome sipky a zavrit
  119.         self.editWindow.buttonTogglePages:Enable()
  120.         self.editWindow.buttonClose:Enable()
  121.         return
  122.     end
  123.     if(self.selectedPage and (self.editWindow.editBox:GetText() == GeneAssign_Pages[self.selectedPage].Content)) then
  124.         --pokud mame vybranou stranku a mame ji nejak zmenenou
  125.         if not self.previewToggle then --toto by pravdepodobne melo projit vzdy, protoze na kladnej self.previewToggle mam podminku drive, ale pro jistotu
  126.             self.editWindow.buttonAccept:Disable()
  127.             self.editWindow.buttonRevert:Disable()
  128.             self.editWindow.statusText:SetText("Stranka |cff00ff00je |rulozena")
  129.         end
  130.         return
  131.     end
  132.     if(self.selectedPage and (self.editWindow.editBox:GetText() ~= GeneAssign_Pages[self.selectedPage].Content)) then
  133.         if not self.previewToggle then
  134.             self.editWindow.buttonAccept:Enable()
  135.             self.editWindow.buttonRevert:Enable()
  136.             self.editWindow.statusText:SetText("Stranka |cffff0000neni |rulozena")
  137.         end
  138.         return
  139.     end
  140. end
  141.  
  142. function GeneAssign:OnInitialize()
  143.  
  144. end
  145.  
  146. function GeneAssign:OnEnable()
  147.     -- podivny workaround na to aby to nikdo jiny pouzivat nemohl..
  148.     -- 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
  149.     -- 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
  150.     -- 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
  151.     self:AfterEnable()
  152.     --[[self:RegisterEvent("GUILD_ROSTER_UPDATE")
  153.     local isInGuild = IsInGuild()
  154.     if(isInGuild == 1) then
  155.         GuildRoster()
  156.     else
  157.         return
  158.     end]]
  159. end
  160.  
  161. function GeneAssign:AfterEnable()
  162.     -- INDEXACE V LUA TABULKACH
  163.     --[[
  164.     local x = {1, 2, 3, 4, 5}
  165.     local y = {[1] = 1, [2] = 2, [3] = 3, [4] = 4, [5] = 5}
  166.     local z = {ID = 1, Name = 2, Content = 3}
  167.     local a = {["ID"] = 1, ["Name"] = 2, ["Content"] = 3}
  168.    
  169.         -- podle netu, ktery rika ze
  170.        
  171.         The constructor
  172.             {x=0, y=0}
  173.         is equivalent to
  174.             {["x"]=0, ["y"]=0}
  175.         and the constructor
  176.             {"red", "green", "blue"}
  177.         is equivalent to
  178.             {[1]="red", [2]="green", [3]="blue"}
  179.        
  180.         -- z toho plynou nasledujici dusledky:
  181.             1) tabulka z se rovna tabulce a
  182.             2) pristupy
  183.                     z.ID, z.Name, z.Content
  184.                 se rovnaji
  185.                     z["ID"], z["Name"], z["Content"]
  186.             3) tabulka x se rovna tabulce y
  187.             4) pristupy
  188.                     x[1], x[2], x[3], x[4], x[5] (pole v lua se cisluji od 1)
  189.                 se rovnaji
  190.                     y[1] ... y[5]
  191.             5) moje tabulka GeneAssign_Pages co vypada cca takto:
  192.                     {  
  193.                         [1325] = { ID = 1325, Name = "Nefarian", Content = "..." },
  194.                         [12365] = { ID = 12365, Name = "Sinestra", Content = "..." }
  195.                     }
  196.                 je v podstate identicka k
  197.                     {  
  198.                         [1325] = { ["ID"] = 1325, ["Name"] = "Nefarian", ["Content"] = "..." },
  199.                         [12365] = { ["ID"] = 12365, ["Name"] = "Sinestra", ["Content"] = "..." }
  200.                     }
  201.                 a stejne jako pristupuju
  202.                     GeneAssign_Pages[id].Name
  203.                 muzu pristupovat
  204.                     GeneAssign_Pages[id]["Name"] (bohuzel [id] je povinne, jelikoz id je cislo v tomto pripade)
  205.     ]]
  206.    
  207.    
  208.  
  209.  
  210.     -- pokud probehne dobre ten workaround, a mame teda potvrzene ze jsme z The Genesis, pokracujeme s zbytkem nastaveni, vytvoreni oken atd.
  211.     self:RegisterChatCommand("ga", "ProcessSlashCommand")
  212.     GeneAssign.db = LibStub("AceDB-3.0"):New("TheGenesisAssignmentsDB11", defaultSettings, true)
  213.     StaticPopupDialogs["REVERT_CONFIRM"] = {
  214.         text = "Opravdu chcete obnovit posledni zalohu?",
  215.         button1 = "Ano",
  216.         button2 = "Ne",
  217.         OnShow = function()
  218.             GeneAssign:EnableDisableEditWindow(false)
  219.             GeneAssign:EnableDisablePageWindow(false)
  220.         end,
  221.         OnHide = function()
  222.             GeneAssign:EnableDisableEditWindow(true)
  223.             GeneAssign:EnableDisablePageWindow(true)
  224.         end,
  225.         OnAccept = function()
  226.             self:RevertChanges()
  227.         end,
  228.         timeout = 0,
  229.         whileDead = true,
  230.         hideOnEscape = true,
  231.         preferredIndex = 3,
  232.     }
  233.     StaticPopupDialogs["UNSAVED_PAGE_CHANGE"] = {
  234.         text = "Chcete pred zmenou stranky predchozi stranku ulozit?",
  235.         button1 = "Ano",
  236.         button2 = "Ne",
  237.         OnShow = function()
  238.             --zablokovat vsecky tlacitka v editwindowu, mozna i pagewindowu
  239.             GeneAssign:EnableDisableEditWindow(false)
  240.             GeneAssign:EnableDisablePageWindow(false)
  241.         end,
  242.         OnHide = function()
  243.             --odblokovat vsecky tlacitka v editwindowu, mozna i pagewindowu
  244.             GeneAssign:EnableDisableEditWindow(true)
  245.             GeneAssign:EnableDisablePageWindow(true)
  246.         end,
  247.         OnAccept = function(self)
  248.             --ulozit zmeny, pokracovat viz nize (oznacit nove tlacitko, odznacit ostatni atd.)
  249.             GeneAssign:AcceptChanges()
  250.             GeneAssign.selectedPage = self.button.value
  251.             self.button.selected = true
  252.             self.button:LockHighlight()
  253.             for _, otherButton in pairs(GeneAssign.buttons) do
  254.                 if(self.button ~= otherButton) then
  255.                     otherButton.selected = false
  256.                     otherButton:UnlockHighlight()
  257.                 end
  258.             end
  259.             GeneAssign.editWindow.pageNameLabel:SetText(GeneAssign_Pages[self.button.value].Name)
  260.             GeneAssign:DisplayPageInEditBox()
  261.             GeneAssign.editWindow.buttonAccept:Disable()
  262.             GeneAssign.editWindow.buttonRevert:Disable()
  263.         end,
  264.         OnCancel = function(self)
  265.             --neukladat zmeny, pokracovat viz nize
  266.             GeneAssign.selectedPage = self.button.value
  267.             self.button.selected = true
  268.             self.button:LockHighlight()
  269.             for _, otherButton in pairs(GeneAssign.buttons) do
  270.                 if(self.button ~= otherButton) then
  271.                     otherButton.selected = false
  272.                     otherButton:UnlockHighlight()
  273.                 end
  274.             end
  275.             GeneAssign.editWindow.pageNameLabel:SetText(GeneAssign_Pages[self.button.value].Name)
  276.             GeneAssign:DisplayPageInEditBox()
  277.             GeneAssign.editWindow.buttonAccept:Disable()
  278.             GeneAssign.editWindow.buttonRevert:Disable()
  279.  
  280.         end,
  281.         timeout = 0,
  282.         whileDead = true,
  283.         hideOnEscape = true,
  284.         preferredIndex = 3,
  285.     }
  286.     --self.db.char.pages = {}
  287.     --self.db.char.numPages = 0
  288.     --self.db.char.shownText = nil
  289.     --self.selectedPage = nil
  290.    
  291.     GeneAssign_Pages = self.db.char.pages
  292.     self:RegisterComm(self.addonPrefix, "ReceiveMessage")
  293.    
  294.     self:RegisterEvent("RAID_ROSTER_UPDATE")
  295.     self:RegisterEvent("PLAYER_GUILD_UPDATE")
  296.     --BuildFontPicker()
  297.    
  298.     self:BuildTextWindow()
  299.     self:BuildInterfaceWindow()
  300.     self:BuildEditWindow()
  301.     self:BuildTreeWindow()
  302.     self:CheckPermissions()
  303.    
  304.     -- toto je nejake divne.. jelikoz je to uz PO BuildTreeWindow(), tzn ze v self.selectedPage je bud nil v pripade ze neni zadna stranka, anebo je tam ID prvni abecedne serazene stranky, a my ji mame ukazat hned?
  305.     -- podle me by se mel spis zobrazit posledni zobrazeny text (resp. oznacit se ta stranka muze, i v editboxu muze byt, ale zobrazit by se mela ta posledni..)
  306.     if self.db.char.shownText then -- u koho nikdy drive nova verze spustena nebyla, ma shownText nil
  307.         self.textWindow.messageFrame:Clear()
  308.         local text = RecognizeFixPatterns(self.db.char.shownText)
  309.         local lines = { strsplit("\n", text) }
  310.         local lines_count = #lines
  311.         for i = 1, lines_count do
  312.             local line = lines[i]
  313.             if line == "" then line = " " end
  314.             self.textWindow.messageFrame:AddMessage(line)
  315.         end
  316.     end
  317. end
  318.  
  319. function GeneAssign:EnableDisableEditWindow(enable)
  320.     print("EnableDisableEditWindow, enable = " .. tostring(enable))
  321.     --error(debugstack())
  322.     local kids = { GeneAssign.editWindow:GetChildren() }
  323.     if enable then
  324.         --pokud sice mame prikaz na zapnuti, ALE nemame zadne stranky, stejne nechame vsecko zablokovane
  325.        
  326.         if(GeneAssign.db.char.numPages == 0) then
  327.             for k, v in pairs(kids) do
  328.                 if(v:IsObjectType("Button")) then
  329.                     v:Disable()
  330.                 end
  331.             end
  332.             GeneAssign.editWindow.editBox:Disable()
  333.             --nechame akorat zapnuty tlacitko pro vypnuti, popr. tlacitko na toggle
  334.             GeneAssign.editWindow.buttonClose:Enable()
  335.             GeneAssign.editWindow.buttonTogglePages:Enable()
  336.         else
  337.             for k, v in pairs(kids) do
  338.                 if(v:IsObjectType("Button")) then
  339.                     v:Enable()
  340.                 end
  341.             end
  342.             GeneAssign.editWindow.editBox:Enable()
  343.             EditBox_TextChanged()
  344.         end
  345.         -- potom, co se zapnou vsecky tlacitka je treba provest kontrolu, jestli nemaji nektere byt vypnute (priklad: mam ulozenou stranku (accept a revert blocked)
  346.         -- a vytvorim novou stranku, tohle mi vsechny tlacitka zapne i kdyz by accept a revert mely byt vypnute, EditBox_TextChanged by to mel poresit)
  347.     else
  348.         for k, v in pairs(kids) do
  349.             if(v:IsObjectType("Button")) then
  350.                 v:Disable()
  351.             end
  352.         end
  353.         GeneAssign.editWindow.editBox:Disable()
  354.     end
  355. end
  356.  
  357. function GeneAssign:EnableDisablePageWindow(enable)
  358.     local kids2 = { GeneAssign.pageWindow.treeFrame:GetChildren() }
  359.     local kids3 = { GeneAssign.pageWindow:GetChildren() }
  360.     -- page se vypne/zapne vzdycky, otazkou zbyva jestli se vypne i editwindow nebo ne
  361.     if enable then
  362.         for k, v in pairs(kids2) do
  363.             if(v:IsObjectType("Button")) then
  364.                 v:Enable()
  365.             end
  366.         end
  367.         for k, v in pairs(kids3) do
  368.             if(v:IsObjectType("Button")) then
  369.                 v:Enable()
  370.             end
  371.         end
  372.     else
  373.         for k, v in pairs(kids2) do
  374.             if(v:IsObjectType("Button")) then
  375.                 v:Disable()
  376.             end
  377.         end
  378.         for k, v in pairs(kids3) do
  379.             if(v:IsObjectType("Button")) then
  380.                 v:Disable()
  381.             end
  382.         end
  383.     end
  384. end
  385.  
  386. function GeneAssign:BuildTreeWindow()
  387.  
  388.  
  389.        
  390.         --[[
  391.         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
  392.         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)
  393.         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)      
  394.     ]] 
  395.     local pageWindow = CreateFrame("Frame", nil, UIParent)
  396.     pageWindow:SetBackdrop({
  397.         bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
  398.         edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
  399.         tile = true, tileSize = 32, edgeSize = 32,
  400.         insets = { left = 8, right = 8, top = 8, bottom = 8 }
  401.     })
  402.     pageWindow:SetSize(215, 380)
  403.     pageWindow:SetPoint("CENTER", 0, 0)
  404.     pageWindow:SetMovable(true)
  405.     pageWindow:SetFrameStrata("HIGH")
  406.     pageWindow:Hide()
  407.    
  408.    
  409.    
  410.     --treeFrame:SetBackdrop({   bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background", tile = true, tileSize = 32})
  411.    
  412.    
  413.     --[[local scrollFrame = CreateFrame("ScrollFrame", "SelectPageScrollFrame", container, "UIPanelScrollFrameTemplate")
  414.     scrollFrame:SetPoint("TOPLEFT", 18, -18)
  415.     scrollFrame:SetPoint("BOTTOMRIGHT", -32, 48) --18
  416.    
  417.     scrollFrame:SetBackdrop({
  418.         bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
  419.         edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
  420.         tile = true, tileSize = 16, edgeSize = 8,
  421.         insets = { left = 3, right = 3, top = 5, bottom = 3 }
  422.     })
  423.     scrollFrame:SetBackdropColor(0, 0, 0, 0.5)
  424.     scrollFrame:SetBackdropBorderColor(0.4, 0.4, 0.4)
  425.            
  426.     local treeFrame = CreateFrame("Frame", nil, scrollFrame)
  427.     treeFrame:SetWidth(170) --155
  428.     treeFrame:SetHeight(150)
  429.    
  430.     scrollFrame:SetScrollChild(treeFrame)
  431.    
  432.     local scrollBar = _G[scrollFrame:GetName().."ScrollBar"]
  433.     scrollBar.bg = scrollBar:CreateTexture(nil, "BACKGROUND")
  434.     scrollBar.bg:SetAllPoints(true)
  435.     scrollBar.bg:SetTexture(0, 0, 0, 0.5)]]
  436.    
  437.     local container = CreateFrame("Frame", nil, pageWindow)
  438.     container:SetPoint("TOPLEFT", 18, -18)
  439.     container:SetPoint("BOTTOMRIGHT", -32, 94) --48
  440.     container:SetBackdrop({
  441.         bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
  442.         edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
  443.         tile = true, tileSize = 16, edgeSize = 8,
  444.         insets = { left = 3, right = 3, top = 3, bottom = 3 }
  445.     })
  446.     container:SetBackdropColor(0, 0, 0, 0.5)
  447.     container:SetBackdropBorderColor(0.4, 0.4, 0.4)
  448.     local scrollFrame = CreateFrame("ScrollFrame", "SelectPageScrollFrame", container, "UIPanelScrollFrameTemplate")
  449.     scrollFrame:SetPoint("TOPLEFT", 5, -5)
  450.     scrollFrame:SetPoint("BOTTOMRIGHT", -5, 5) --18
  451.    
  452.     local treeFrame = CreateFrame("Frame", nil, container)
  453.     treeFrame:SetWidth(170) --155
  454.     treeFrame:SetHeight(150)
  455.    
  456.     scrollFrame:SetScrollChild(treeFrame)
  457.    
  458.     local scrollBar = _G[scrollFrame:GetName().."ScrollBar"]
  459.     scrollBar.bg = scrollBar:CreateTexture(nil, "BACKGROUND")
  460.     scrollBar.bg:SetAllPoints(true)
  461.     scrollBar.bg:SetTexture(0, 0, 0, 0.5)
  462.    
  463.    
  464.    
  465.     --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)
  466.     --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
  467.     --[[local testButton = CreateFrame("Button", "TestButton", frame, "OptionsListButtonTemplate")
  468.     testButton:SetPoint("CENTER", 0, 0)
  469.     testButton:SetText("Test text")
  470.     testButton.text:SetHeight(14)
  471.     --testButton:SetSize(100, 20)
  472.     testButton.value = 1
  473.     testButton.selected = true
  474.     --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)
  475.     testButton:LockHighlight()
  476.     local testButton1 = CreateFrame("Button", "TestButton1", frame, "OptionsListButtonTemplate")
  477.     testButton1:SetPoint("TOPLEFT", testButton, "BOTTOMLEFT", 0, 0)
  478.     testButton1:SetText("Test text2")
  479.     testButton1.text:SetHeight(14)
  480.     --testButton:SetSize(100, 20)
  481.     testButton1.value = 2
  482.     testButton1.selected = false
  483.     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)
  484.     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)
  485.     ]]
  486.     --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..
  487.     --jdeme zkusit vytvorit tlacitka z stromu
  488.    
  489.     --self:RenderTree() -- AddPage si RenderTree vola sama
  490.    
  491.     --[[ ok, vytvoreni tlacitek ze stromu taky mame, jdem k tomu pridat dalsi operace, tzn.
  492.         1) pridani dalsi stranky (a k tomu test re-renderu, jestli spravne skryva tlacitka atd.)
  493.         2) i takove obycejne operace jako vraceni prave vybrane stranky, popr. zmena vybrane stranky
  494.         3) odebrani prave vybrane stranky
  495.         4) prejmenovani stranky (a nasledny re-render)
  496.     ]]
  497.     --print(self:GetSelectedId())
  498.     StaticPopupDialogs["ADD_PAGE"] = {
  499.         button1 = OKAY,
  500.         button2 = CANCEL,
  501.         OnShow = function()
  502.             GeneAssign:EnableDisableEditWindow(false)
  503.             GeneAssign:EnableDisablePageWindow(false)
  504.         end,
  505.         OnHide = function()
  506.             GeneAssign:EnableDisableEditWindow(true)
  507.             GeneAssign:EnableDisablePageWindow(true)
  508.         end,
  509.         OnAccept = function(self)
  510.             local text = self.editBox:GetText()
  511.             if text ~= "" then GeneAssign:AddPage(text) end
  512.         end,
  513.         EditBoxOnEnterPressed = function(self)
  514.             local text = self:GetParent().editBox:GetText()
  515.             if text ~= "" then GeneAssign:AddPage(text) end
  516.             self:GetParent():Hide()
  517.         end,
  518.         text = "Zadejte jmeno stranky: ",
  519.         hasEditBox = true,
  520.         whileDead = true,
  521.         EditBoxOnEscapePressed = function(self) self:GetParent():Hide() end,
  522.         hideOnEscape = true,
  523.         timeout = 0,
  524.         preferredIndex = 3
  525.     }
  526.    
  527.     StaticPopupDialogs["RENAME_PAGE"] = {
  528.         button1 = OKAY,
  529.         button2 = CANCEL,
  530.         OnShow = function()
  531.             GeneAssign:EnableDisableEditWindow(false)
  532.             GeneAssign:EnableDisablePageWindow(false)
  533.         end,
  534.         OnHide = function()
  535.             GeneAssign:EnableDisableEditWindow(true)
  536.             GeneAssign:EnableDisablePageWindow(true)
  537.         end,
  538.         OnAccept = function(self)
  539.             local text = self.editBox:GetText()
  540.             if text ~= "" then GeneAssign:RenameSelectedPage(text) end
  541.         end,
  542.         EditBoxOnEnterPressed = function(self)
  543.             local text = self:GetParent().editBox:GetText()
  544.             if text ~= "" then GeneAssign:RenameSelectedPage(text) end
  545.             self:GetParent():Hide()
  546.         end,
  547.         text = "Zadejte nove jmeno stranky: ",
  548.         hasEditBox = true,
  549.         whileDead = true,
  550.         EditBoxOnEscapePressed = function(self) self:GetParent():Hide() end,
  551.         hideOnEscape = true,
  552.         timeout = 0,
  553.         preferredIndex = 3
  554.     }
  555.    
  556.     StaticPopupDialogs["REMOVE_PAGE"] = {
  557.         text = "Smazat vybranou stranku?",
  558.         button1 = OKAY,
  559.         button2 = CANCEL,
  560.         OnShow = function()
  561.             GeneAssign:EnableDisableEditWindow(false)
  562.             GeneAssign:EnableDisablePageWindow(false)
  563.         end,
  564.         OnHide = function()
  565.             GeneAssign:EnableDisableEditWindow(true)
  566.             GeneAssign:EnableDisablePageWindow(true)
  567.         end,
  568.         OnAccept = function()
  569.             self:RemoveSelectedPage()
  570.         end,
  571.         timeout = 0,
  572.         whileDead = true,
  573.         hideOnEscape = true,
  574.         preferredIndex = 3,
  575.     }
  576.    
  577.    
  578.    
  579.     local removeButton = CreateFrame("Button", "RemoveButton", pageWindow, "UIPanelButtonTemplate")
  580.     removeButton:SetText("Odstranit stranku")
  581.     removeButton:SetHeight(removeButton:GetTextHeight() + 10)
  582.     removeButton:SetPoint("BOTTOMLEFT", 20, 20)
  583.     removeButton:SetPoint("BOTTOMRIGHT", -20, 20)
  584.     removeButton:SetScript("OnClick", function()
  585.         if GeneAssign:GetSelectedId() then
  586.             StaticPopup_Show("REMOVE_PAGE")
  587.         end
  588.     end)
  589.    
  590.    
  591.     local renameButton = CreateFrame("Button", "RenameButton", pageWindow, "UIPanelButtonTemplate")
  592.     renameButton:SetText("Prejmenovat stranku")
  593.     renameButton:SetHeight(renameButton:GetTextHeight() + 10)
  594.     renameButton:SetPoint("BOTTOMLEFT", removeButton, "TOPLEFT", 0, 2)
  595.     renameButton:SetPoint("BOTTOMRIGHT", removeButton, "TOPRIGHT", 0, 2)
  596.     renameButton:SetScript("OnClick", function()
  597.         if GeneAssign:GetSelectedId() then
  598.             StaticPopup_Show("RENAME_PAGE")
  599.         end
  600.     end)
  601.    
  602.     local addButton = CreateFrame("Button", "AddButton", pageWindow, "UIPanelButtonTemplate")
  603.     addButton:SetText("Pridat stranku")
  604.     addButton:SetHeight(addButton:GetTextHeight() + 10)
  605.     addButton:SetPoint("BOTTOMLEFT", renameButton, "TOPLEFT", 0, 2)
  606.     addButton:SetPoint("BOTTOMRIGHT", renameButton, "TOPRIGHT", 0, 2)
  607.     addButton:SetScript("OnClick", function() StaticPopup_Show("ADD_PAGE") end)
  608.    
  609.     pageWindow.buttonRemove = removeButton
  610.     pageWindow.buttonRename = renameButton
  611.     pageWindow.treeFrame = treeFrame
  612.     self.pageWindow = pageWindow
  613.    
  614.     self:RenderTree() -- vykreslime pri konstrukci okna stranky co uz existuji
  615.     -- 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)
  616.     -- ok, timto bychom meli vicemene udelane stranky, umi je pridavat, odebirat, atd., vsecko co bylo zmineno drive
  617.    
  618.     --      ROZDIL PAIRS VS IPAIRS
  619.     --[[
  620.     local x = {1, 2, 5, 10, 16}
  621.     for k, v in pairs(x) do print("pairs, k = " .. k .. ", v = " .. v) end
  622.     for k, v in ipairs(x) do print("ipairs, k = " .. k .. ", v = " .. v) end
  623.    
  624.     --  oba vypisou to same
  625.     --  pairs, k = 1, v = 1
  626.     --  pairs, k = 2, v = 2
  627.     --  pairs, k = 3, v = 5
  628.     --  pairs, k = 4, v = 10
  629.     --  pairs, k = 5, v = 16
  630.    
  631.     print("y:")
  632.     local y = {[1] = 1, [2] = 2, [5] = 5, [10] = 10, [16] = 16}
  633.     for k, v in pairs(y) do print("pairs, k = " .. k .. ", v = " .. v) end
  634.     for k, v in ipairs(y) do print("ipairs, k = " .. k .. ", v = " .. v) end
  635.     --    vypise se toto:
  636.     --  pairs, k = 2, v = 2
  637.     --  pairs, k = 10, v = 10
  638.     --  pairs, k = 1, v = 1
  639.     --  pairs, k = 5, v = 5
  640.     --  pairs, k = 16, v = 16
  641.     --  ipairs, k = 1, v = 1
  642.     --  ipairs, k = 2, v = 2
  643.        
  644.     --  => 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
  645.     --     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
  646.          
  647.     --  => v praxi = pro self.pages pouzivame vlastni indexy = vzdy pairs
  648.     --               pro self.buttons taky pairs, taky mame vlastni indexy
  649.     --               pro GetSortedTree, table.insert podle testu pravdepodobne neindexuje (jako vyse v pripade pole x), protoze pairs i ipairs vraci stejne vysledky
  650.     --                  coz znamena ze pro hlavni cyklus v RenderTree() muzeme pouzit jakykoli iterator a vysledek je stejny
  651.     ]]
  652. end
  653.  
  654. function GeneAssign:GetSortedTree()
  655.     if not GeneAssign_Pages then return end
  656.     -- puvodni strom asi radit nebudu, nebudu ho menit, udelam kopii
  657.     local treeCopy = {}
  658.     for _, page in pairs(GeneAssign_Pages) do
  659.         table.insert(treeCopy, page)
  660.     end
  661.  
  662.     --for k, v in pairs(treeCopy) do print("GetSortedTree, pairs, k = " .. k .. ", v.ID = " .. v.ID .. ", v.Name = " .. v.Name .. ", v.Content = " .. v.Content) end
  663.     --for k, v in ipairs(treeCopy) do print("GetSortedTree, ipairs, k = " .. k .. ", v.value = " .. v.value .. ", v.text = " .. v.text) end
  664.     table.sort(treeCopy, function(a, b) return a.Name:lower() < b.Name:lower() end)
  665.     --print("Po serazeni")
  666.     --for k, v in pairs(treeCopy) do print("GetSortedTree, pairs, k = " .. k .. ", v.value = " .. v.value .. ", v.text = " .. v.text) end
  667.     --for k, v in ipairs(treeCopy) do print("GetSortedTree, ipairs, k = " .. k .. ", v.value = " .. v.value .. ", v.text = " .. v.text) end
  668.     return treeCopy
  669. end
  670.  
  671. function GeneAssign:RenderTree()
  672.     local tree = self:GetSortedTree()
  673.     -- ani nemusim nic vracet, kdyz tree nebude existovat, hlavni cyklus by to melo preskocit a aspon to poresi podminky potom s tim selectedPage
  674.     for k, button in pairs(self.buttons) do
  675.         --print("RenderTree delete loop, k = " .. k .. ", button value = " .. button.value)
  676.         button:Hide()
  677.         self.buttons[k] = nil
  678.     end
  679.     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)
  680.         --print("RenderTree loop, i = " .. i .. ", value = " .. page.value .. ", text = " .. page.text)
  681.         local button = CreateFrame("Button", "Page"..(page.ID), self.pageWindow.treeFrame, "OptionsListButtonTemplate")
  682.         self.buttons[page.ID] = button --i se pouzit neda, viz vyse
  683.         button:SetText(page.Name)
  684.         button.text:SetHeight(14)
  685.         button:SetWidth(self.pageWindow.treeFrame:GetWidth() - 3)
  686.         button.value = page.ID
  687.         button.selected = false
  688.         if self.previewToggle then button:Disable() end
  689.         button:SetScript("OnClick", function(self)
  690.             if not self.selected then
  691.                 if (GeneAssign.editWindow.editBox:GetText() ~= GeneAssign_Pages[GeneAssign.selectedPage].Content) then
  692.                     local dialog = StaticPopup_Show("UNSAVED_PAGE_CHANGE")
  693.                     if(dialog) then
  694.                         dialog.button = self --timto bych mel predat odkaz na tlacitko dovnitr toho dialogu (viz wowwiki http://wowwiki.wikia.com/wiki/Creating_simple_pop-up_dialog_boxes)
  695.                     end
  696.                 else
  697.                     GeneAssign.selectedPage = self.value
  698.                     self.selected = true
  699.                     self:LockHighlight()
  700.                     for _, otherButton in pairs(GeneAssign.buttons) do
  701.                         if(self ~= otherButton) then
  702.                             otherButton.selected = false
  703.                             otherButton:UnlockHighlight()
  704.                         end
  705.                     end
  706.                     GeneAssign.editWindow.pageNameLabel:SetText(GeneAssign_Pages[self.value].Name)
  707.                     GeneAssign:DisplayPageInEditBox()
  708.                 end
  709.             end
  710.         end)
  711.         --if (i == 1) then
  712.         button:SetPoint("TOPLEFT", 0, -3 - (i-1)*button:GetHeight())
  713.         --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)
  714.         --  button:SetPoint("TOPLEFT", )
  715.         --end
  716.     end
  717.     if not self.selectedPage then
  718.         if(self.db.char.numPages >= 1) then  -- jedna se sice o tlacitka ale stranky a tlacitka by mely odpovidat 1:1 takze muzu pouzit i toto
  719.             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
  720.                 self.buttons[page.ID].selected = true
  721.                 self.buttons[page.ID]:LockHighlight()
  722.                 self.selectedPage = page.ID
  723.                 self.editWindow.pageNameLabel:SetText(GeneAssign_Pages[self.selectedPage].Name)
  724.                 break
  725.             end
  726.             self:EnableDisableEditWindow(true)
  727.             self:DisplayPageInEditBox()
  728.         else -- neexistuji zadne stranky, vymazat editbox, page label, status text, vypnout tlacitka
  729.             --self:Print("No pages")
  730.             self.editWindow.editBox:SetText("")
  731.             self.editWindow.pageNameLabel:SetText("")
  732.             self.editWindow.statusText:SetText("")
  733.             --self.editWindow.buttonAccept:Disable()
  734.             --self.editWindow.buttonRevert:Disable()
  735.             --self.editWindow.buttonSend:Disable()
  736.             --self.editWindow.buttonPreview:Disable()
  737.         end
  738.     else -- pokud mame nejakou stranku vybranou, pak akorat vyberu to tlacitko
  739.         self.buttons[self.selectedPage].selected = true
  740.         self.buttons[self.selectedPage]:LockHighlight()
  741.     end
  742. end
  743.  
  744. function GeneAssign:GetSelectedId()
  745.     return self.selectedPage
  746. end
  747.  
  748. function GeneAssign:AddPage(content)
  749.  
  750.    
  751.     local randomID = math.random(1000000000)
  752.     while GeneAssign_Pages[randomID] do
  753.         randomID = math.random(1000000000)
  754.     end
  755.    
  756.     GeneAssign_Pages[randomID] = { ID = randomID, Name = content, Content = ""}
  757.     self.db.char.numPages = self.db.char.numPages + 1
  758.     --for k, v in pairs(self.pages) do print("AddPage text, k = " .. k .. ", value = " .. v.value .. ", text = " .. v.text) end
  759.  
  760.     --self.selectedPage = randomID
  761.     self:RenderTree()
  762. end
  763.  
  764. function GeneAssign:RemoveSelectedPage()
  765.     GeneAssign_Pages[self.selectedPage] = nil
  766.     self.db.char.numPages = self.db.char.numPages - 1
  767.     self.selectedPage = nil -- stejne se hned zmeni v RenderTree, netreba to delat znova tady
  768.     self:RenderTree()
  769. end
  770.  
  771. function GeneAssign:RenameSelectedPage(content)
  772.     GeneAssign_Pages[self.selectedPage].Name = content
  773.     self.editWindow.pageNameLabel:SetText(content)
  774.     self:RenderTree()
  775. end
  776.  
  777. function GeneAssign:DisplayPageInEditBox(id)
  778.     if not id then id = self.selectedPage end
  779.     local page = GeneAssign_Pages[id]
  780.     if not page then
  781.         self.editWindow.editBox:SetText("")
  782.     else
  783.         self.editWindow.editBox:SetText(page.Content)
  784.     end
  785. end
  786.  
  787. function GeneAssign:DisplayPageInTextWindow(id)
  788.     if not id then id = self.selectedPage end
  789.     local page = GeneAssign_Pages[id]
  790.     if not page then return end
  791.    
  792.     if(not self.textWindow:IsShown()) then self.textWindow:Show() end
  793.     self.textWindow.messageFrame:Clear()
  794.    
  795.     -- zobrazime text do textWindowu
  796.     self.db.char.shownText = page.Content
  797.     local text = RecognizeFixPatterns(page.Content)
  798.     local lines = { strsplit("\n", text) }
  799.     local lines_count = #lines
  800.     for i = 1, lines_count do
  801.         local line = lines[i]
  802.         if line == "" then line = " " end
  803.         self.textWindow.messageFrame:AddMessage(line)
  804.     end
  805.    
  806.    
  807. end
  808.  
  809. function GeneAssign:ReturnShownText()
  810.     return self.db.char.shownText
  811. end
  812.  
  813. --------------------------
  814. --      KOMUNIKACE
  815. --------------------------
  816. function GeneAssign:ReceiveMessage(prefix, data, channel, sender)
  817.     -- pokud probehlo DestroyEvidence() tak neprijimame dalsi zpravy
  818.     if not self.acceptMessages then return end
  819.    
  820.     if prefix ~= self.addonPrefix then return end
  821.    
  822.     local success, deserializedData = serializer:Deserialize(data)
  823.    
  824.     if not success then
  825.         self:Print("Chyba pri deserializaci dat")
  826.         return
  827.     end
  828.    
  829.     self:ProcessMessage(deserializedData, sender)
  830. end
  831.  
  832. function GeneAssign:ProcessMessage(data, sender)
  833.     -- k tomuto se pravdepodobne nedostane ale kdyby data byla prazdna, tak skoncime
  834.     if not data then return end
  835.    
  836.     -- ignorujeme vlastni zpravy
  837.     if(sender == UnitName("player")) then return end
  838.    
  839.     local PAGE_ID = 1
  840.     local PAGE_NAME = 2
  841.     local PAGE_CONTENT = 3
  842.    
  843.     if(not self.textWindow:IsShown()) then self.textWindow:Show() end
  844.    
  845.     -- zpracovani zpravy
  846.     --nejdrive se presvedcime, zda jiz existuje stranka s danym ID (v AA to rovnou prepisujou, coz je fajn pro me asi, ale nevim jestli pro ostatni.. spis uvazuju ze bych vygeneroval pro ni nove ID nez abych neco prepisoval)
  847.     --pokud ne, vytvorime novou, pokud ano (viz o radek vys), generujeme ID do te doby dokud nenajdem na nejake nepouzite
  848.     --kdyz nad tim tak uvazuju, tim se obesly veskere jejich jine podminky, protoze oni updatovali, my nebudem
  849.     --pokud nahodou editujeme, tak se stejne menit nic nebude, a pokud needitujeme, tak akorat pridame do stranek, a ono se to vyrenderuje potom samotny (pri kliknuti na zobrazeni stranek mam ten render)
  850.    
  851.    
  852.     -- FUCK THIS SHIT, AA meli pravdu.. updatovat stranky, protoze jinak se zbytecne budou vytvaret kopie a kopie co se od sebe skoro nelisi a pro ostatni leadry to bude delat bordel
  853.     local id = data[PAGE_ID]
  854.     -- nejdrive zjistim jestli existuje jiz stranka s tim ID, pokud ne, rovnou ji pridame
  855.     --pokud existuje, oni tam porovnavaji verze ale to moc resit nebudu asi
  856.     --stejne tak porovnavaji jestli se nezmenil content, to taky neresim, proste prepisu a cau
  857.     --a jinak prepisou jmeno, content, akorat potom jestli je ta stranka prijemcem momentalne vybrana, tak ji updatnu taky
  858.     local page = GeneAssign_Pages[id]
  859.     if page then
  860.         page.Name = data[PAGE_NAME]
  861.         page.Content = data[PAGE_CONTENT]
  862.         --v text okne se to zobrazi vzdycky, nas zajima akorat jestli mame otevrene nahodou edit okno s tou strankou tak at prepisu content toho..
  863.         if(self.selectedPage and self.selectedPage == id) then
  864.             --spravne bych tady mel asi resit zablokovani tlacitek jistych ale kdyz zmenim text v editboxu, pusti se EditBox_TextChanged, a tam se to uz osefuje (melo by)
  865.             --ovsem EditBox_TextChanged resi jenom accept a revert, a za jistych podminek (jmenovite smazane vsechny stranky, otevreny pageWindow a editwindow (a tedy zablokovane vsechno krome toggle page a close), a pak prijmu stranku)
  866.             -- se sice label, editbox, diky rendertree i selectedpage spravne nastavi, ale preview a send zustanou stale vypnute, dokonce i kdyz se okno vypne a zapne (fix dis)
  867.             self.editWindow.editBox:SetText(page.Content)
  868.             self.editWindow.pageNameLabel:SetText(page.Name)
  869.         end
  870.     else --neexistuje, je nova
  871.         GeneAssign_Pages[id] = { ID = data[PAGE_ID], Name = data[PAGE_NAME], Content = data[PAGE_CONTENT] }
  872.         self.db.char.numPages = self.db.char.numPages + 1
  873.     end
  874.    
  875.     if(self.pageWindow:IsShown()) then -- pokud je zrovna otevrene okno, tak do nej pridame tlacitko s novou strankou, pokud neni otevrene tak neni treba nic resit, vyrenderuje se pak samo
  876.         self:RenderTree()
  877.     end
  878.    
  879.     self:Print("Prijata nova stranka \"" .. data[PAGE_NAME] .. "\" od " .. sender)
  880.    
  881.     --ale bez ohledu na to, jestli editujeme nebo ne, nebo ani nemame prava, zobrazime danou stranku v text okne
  882.    
  883.     self:DisplayPageInTextWindow(id)
  884. end
  885.  
  886. function GeneAssign:SendPage(id)
  887.     local PAGE_ID = 1
  888.     local PAGE_NAME = 2
  889.     local PAGE_CONTENT = 3
  890.    
  891.     if(not IsInRaid()) then return end
  892.    
  893.     if not id then id = self.selectedPage end
  894.    
  895.     local page = GeneAssign_Pages[id]
  896.    
  897.     if not page then return end
  898.    
  899.     local dataToSend = {[PAGE_ID] = page.ID, [PAGE_NAME] = page.Name, [PAGE_CONTENT] = page.Content }
  900.    
  901.     local serializedData = serializer:Serialize(dataToSend)
  902.    
  903.     self:SendCommMessage(self.addonPrefix, serializedData, "RAID") 
  904. end
  905.  
  906. -------------------------
  907. --      TEXT OKNO
  908. -------------------------
  909. function GeneAssign:BuildTextWindow()
  910.     -- cele okno pro ten textWindow
  911.     local TextFrame = CreateFrame("Frame", "TextFrame", UIParent)
  912.     -- v LibWindow si registrujeme, ze chceme uchovavat pozici tohoto framu, a ulozime to do self.db.char (cili pro kazdy char zvlast)
  913.     lwin.RegisterConfig(TextFrame, self.db.char)
  914.     TextFrame:Hide()
  915.     TextFrame:SetToplevel(true)
  916.     TextFrame:EnableMouse(true)
  917.     TextFrame:SetMovable(true)
  918.     TextFrame:SetResizable(true)
  919.     TextFrame:SetMinResize(100, 100)
  920.     TextFrame:SetSize(200, 200)
  921.     TextFrame:SetPoint("CENTER", UIParent, "CENTER", 0, 0) -- ze zacatku ukotvime doprostred
  922.     lwin.RestorePosition(TextFrame) -- a ulozime (pozdeji nacteme) pozici a velikost framu
  923.     TextFrame:SetBackdrop({
  924.         bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
  925.         tile = true,
  926.         tileSize = 32,
  927.     })
  928.     TextFrame:SetScript("OnMouseDown", TextFrame_OnMouseDown)
  929.     TextFrame:SetScript("OnMouseUp", TextFrame_OnMouseUp)
  930.    
  931.     -- tahlo pro resize framu
  932.     local TextFrameDragHandle = CreateFrame("Frame", "TextFrameDragHandle", TextFrame)
  933.     TextFrameDragHandle:SetSize(16, 16)
  934.     TextFrameDragHandle:SetPoint("BOTTOMRIGHT", TextFrame, "BOTTOMRIGHT", 0, 0)
  935.     TextFrameDragHandle:SetScript("OnMouseDown", TextFrame_DragDown)
  936.     TextFrameDragHandle:SetScript("OnMouseUp", TextFrame_DragUp)
  937.     if self.db.char.locked then
  938.         TextFrameDragHandle:Hide()
  939.     end
  940.     TextFrame.dragHandle = TextFrameDragHandle
  941.    
  942.     -- nastavime texturu tomu tahlu
  943.     local texture = TextFrameDragHandle:CreateTexture("TextFrameDragHandleTexture", "OVERLAY")
  944.     texture:SetTexture("Interface\\AddOns\\TheGenesisAssignments11\\Textures\\draghandle")
  945.     texture:SetBlendMode("ADD")
  946.     texture:SetSize(16,16)
  947.     texture:SetPoint("TOPLEFT", TextFrameDragHandle, "TOPLEFT", 0, 0)
  948.    
  949.     -- scrolling frame do ktereho potom budeme psat
  950.     local scrollingFrame = CreateFrame("ScrollingMessageFrame", "ScrollingFrameTest", TextFrame)
  951.     scrollingFrame:SetSize(180, 180)
  952.     scrollingFrame:SetPoint("TOPLEFT", TextFrame, "TOPLEFT", 10, -10)
  953.     scrollingFrame:SetPoint("BOTTOMRIGHT", TextFrame, "BOTTOMRIGHT", -10, 10)
  954.     scrollingFrame:SetFading(false) -- at text nebledne casem
  955.     scrollingFrame:SetMaxLines(70)
  956.     scrollingFrame:SetJustifyH("LEFT")
  957.     scrollingFrame:SetJustifyV("TOP")
  958.     scrollingFrame:SetInsertMode("bottom")
  959.     scrollingFrame:SetFont(self.defaultFont, self.db.char.fontSize, nil)
  960.     scrollingFrame:EnableMouseWheel(true)
  961.     scrollingFrame:SetScript("OnMouseWheel", function(self, delta)
  962.           if (delta < 0) then
  963.             if(scrollingFrame:GetInsertMode() == "TOP") then
  964.                 scrollingFrame:ScrollUp()
  965.             else
  966.                 scrollingFrame:ScrollDown()
  967.             end
  968.           elseif (delta > 0) then
  969.             if(scrollingFrame:GetInsertMode() == "TOP") then
  970.                 scrollingFrame:ScrollDown()
  971.             else
  972.                 scrollingFrame:ScrollUp()
  973.             end
  974.           end
  975.     end)
  976.     TextFrame.messageFrame = scrollingFrame
  977.    
  978.     GeneAssign.textWindow = TextFrame
  979.    
  980.     if(self.db.char.shown) then
  981.         TextFrame:Show()
  982.     end
  983. end
  984.  
  985. function GeneAssign:ToggleLock()
  986.     self.db.char.locked = not self.db.char.locked
  987.     if self.db.char.locked then
  988.         self.interfaceWindow.buttonLock:SetText("Odemkni okno")
  989.         self.textWindow:SetMovable(false)
  990.         self.textWindow:SetResizable(false)
  991.         self.textWindow.dragHandle:Hide()
  992.     else
  993.         self.interfaceWindow.buttonLock:SetText("Zamkni okno")
  994.         self.textWindow:SetMovable(true)
  995.         self.textWindow:SetResizable(true)
  996.         self.textWindow.dragHandle:Show()
  997.     end
  998. end
  999.  
  1000. function GeneAssign:ToggleShow()
  1001.     if(self.textWindow:IsShown()) then
  1002.         self.textWindow:Hide()
  1003.         self.db.char.shown = false
  1004.         self.interfaceWindow.buttonShow:SetText("Zobraz okno")
  1005.     else
  1006.         self.textWindow:Show()
  1007.         self.db.char.shown = true
  1008.         self.interfaceWindow.buttonShow:SetText("Skryj okno")
  1009.     end
  1010. end
  1011.  
  1012. ------------------------------
  1013. --      INTERFACE OKNO
  1014. ------------------------------
  1015. function GeneAssign:BuildInterfaceWindow()
  1016.     -- cely frame
  1017.     local interfaceWindow = CreateFrame("Frame", "InterfaceWindow", UIParent)
  1018.     interfaceWindow.name = "The Genesis Assignments"
  1019.    
  1020.     -- titulek, nadpis okna nastaveni
  1021.     local title = interfaceWindow:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
  1022.     title:SetText("The Genesis Assignments")
  1023.     title:SetPoint("TOPLEFT", 20, -20)
  1024.    
  1025.     --font picker label jsem tady nechal, nastylovane to je, planuju to pridat v dalsi verzi tak at to nemusim vymyslet znova
  1026.     --[[local fontPickerLabel = interfaceWindow:CreateFontString(nil, "ARTWORK", "GameFontHighlightMedium")
  1027.     fontPickerLabel:SetText("Font:")
  1028.     fontPickerLabel:SetPoint("TOPLEFT", 25, -60)
  1029.     fontPickerLabel:SetWidth(fontPickerLabel:GetStringWidth())]]
  1030.    
  1031.     -- label k velikosti fontu
  1032.     local fontSizeLabel = interfaceWindow:CreateFontString(nil, "ARTWORK", "GameFontHighlightMedium")
  1033.     fontSizeLabel:SetText("Velikost pisma:")
  1034.     --fontSizeLabel:SetPoint("TOPLEFT", fontPickerLabel, "BOTTOMLEFT", 0, -30)
  1035.     fontSizeLabel:SetPoint("TOPLEFT", 25, -60)
  1036.     fontSizeLabel:SetWidth(fontSizeLabel:GetStringWidth())
  1037.    
  1038.     -- tlacitko k skryti/zobrazeni okna
  1039.     local toggleWindowBtn = CreateFrame("Button", nil, interfaceWindow, "UIPanelButtonTemplate")
  1040.     if(self.textWindow:IsShown()) then
  1041.         toggleWindowBtn:SetText("Skryj okno")
  1042.     else
  1043.         toggleWindowBtn:SetText("Zobraz okno")
  1044.     end
  1045.     toggleWindowBtn:SetSize(toggleWindowBtn:GetTextWidth()+40, toggleWindowBtn:GetTextHeight()+20)
  1046.     toggleWindowBtn:SetPoint("TOPLEFT", fontSizeLabel, "BOTTOMLEFT", 0, -40)
  1047.     toggleWindowBtn:SetScript("OnClick", function(self, button, down)
  1048.         if(GeneAssign.textWindow:IsShown()) then
  1049.             GeneAssign.textWindow:Hide()
  1050.             GeneAssign.db.char.shown = false
  1051.             toggleWindowBtn:SetText("Zobraz okno")
  1052.         else
  1053.             GeneAssign.textWindow:Show()
  1054.             GeneAssign.db.char.shown = true
  1055.             toggleWindowBtn:SetText("Skryj okno")
  1056.         end        
  1057.     end)
  1058.    
  1059.     -- tlacitko k uzamknuti/odemknuti okna
  1060.     local lockWindowBtn = CreateFrame("Button", nil, interfaceWindow, "UIPanelButtonTemplate")
  1061.     if self.db.char.locked then
  1062.         lockWindowBtn:SetText("Odemkni okno")
  1063.     else
  1064.         lockWindowBtn:SetText("Zamkni okno")
  1065.     end
  1066.     lockWindowBtn:SetSize(lockWindowBtn:GetTextWidth()+40, lockWindowBtn:GetTextHeight()+20)
  1067.     lockWindowBtn:SetPoint("TOPLEFT", toggleWindowBtn, "TOPRIGHT", 60, 0)
  1068.     lockWindowBtn:SetScript("OnClick", function(self, button, down)
  1069.         GeneAssign:ToggleLock()
  1070.     end)
  1071.    
  1072.     -- tlacitko k editaci stranky
  1073.     local editPageBtn = CreateFrame("Button", nil, interfaceWindow, "UIPanelButtonTemplate")
  1074.     editPageBtn:SetText("Edituj stranku")
  1075.     editPageBtn:SetSize(editPageBtn:GetTextWidth()+40, editPageBtn:GetTextHeight()+20)
  1076.     editPageBtn:SetPoint("TOPLEFT", lockWindowBtn, "TOPRIGHT", 60, 0)
  1077.     editPageBtn:SetScript("OnClick", function(self, button, down)
  1078.         if(IsInRaid() and (IsRaidLeader() or IsRaidOfficer())) then
  1079.             GeneAssign:ShowEditWindow()
  1080.         else
  1081.             GeneAssign:Print("Nemas dostatecna prava")
  1082.         end
  1083.     end)
  1084.    
  1085.     -- slider k zmene velikosti fontu
  1086.     local sizeSliderName = "SizeSlider"
  1087.     local sizeSlider = CreateFrame("Slider", sizeSliderName, interfaceWindow, "OptionsSliderTemplate")
  1088.     sizeSlider:SetPoint("TOPLEFT", fontSizeLabel, "TOPRIGHT", 60, 0)
  1089.     -- z _G se vytahne odkaz na fontstringy ktere jsou jako popisky k slideru (existujou protoze dedime z sablony OptionsSliderTemplate, ve kterych ty fontstringy jsou)
  1090.     sizeSlider.textLow = _G[sizeSliderName.."Low"]
  1091.     sizeSlider.textHigh = _G[sizeSliderName.."High"]
  1092.     sizeSlider.text = _G[sizeSliderName.."Text"]
  1093.     sizeSlider:SetMinMaxValues(12, 20)
  1094.     sizeSlider.minValue, sizeSlider.maxValue = sizeSlider:GetMinMaxValues()
  1095.     sizeSlider:SetValue(self.db.char.fontSize)
  1096.     sizeSlider:SetValueStep(1)
  1097.     sizeSlider.textLow:SetText(sizeSlider.minValue)
  1098.     sizeSlider.textHigh:SetText(sizeSlider.maxValue)
  1099.     sizeSlider.text:SetText(sizeSlider:GetValue())
  1100.     sizeSlider:SetScript("OnValueChanged", function(self,value)
  1101.         self.text:SetText(value)
  1102.         GeneAssign.textWindow.messageFrame:SetFont(GeneAssign.defaultFont, value, nil)
  1103.         GeneAssign.db.char.fontSize = value
  1104.     end)
  1105.    
  1106.     interfaceWindow.buttonShow = toggleWindowBtn
  1107.     interfaceWindow.buttonLock = lockWindowBtn
  1108.     interfaceWindow.buttonEdit = editPageBtn
  1109.     GeneAssign.interfaceWindow = interfaceWindow
  1110.     InterfaceOptions_AddCategory(interfaceWindow)
  1111. end
  1112.  
  1113. -------------------------
  1114. --      EDIT OKNO
  1115. -------------------------
  1116. function GeneAssign:BuildEditWindow()
  1117.     -- 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,
  1118.     -- 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
  1119.     -- 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
  1120.     -- 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
  1121.     -- cele okno
  1122.     local editWindow = CreateFrame("Frame", "EditPageWindow", UIParent)
  1123.     editWindow:Hide()
  1124.     editWindow:SetBackdrop({
  1125.         bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
  1126.         edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
  1127.         tile = true, tileSize = 32, edgeSize = 32,
  1128.         insets = { left = 8, right = 8, top = 8, bottom = 8 }
  1129.     })
  1130.     editWindow:SetSize(610, 380)
  1131.     editWindow:SetMovable(true)
  1132.     editWindow:EnableMouse(true)
  1133.     editWindow:SetFrameStrata("HIGH") -- FULLSCREEN_DIALOG
  1134.     editWindow:SetToplevel(true)
  1135.     editWindow:SetPoint("CENTER", 0, 0)
  1136.     editWindow:SetScript("OnMouseDown", function(self, button)
  1137.         self:StartMoving()
  1138.     end)
  1139.     editWindow:SetScript("OnMouseUp", function(self, button) self:StopMovingOrSizing() end)
  1140.     editWindow:SetScript("OnHide", function(self)
  1141.         GeneAssign:RevertChanges()
  1142.         if GeneAssign.pageSelectToggle then
  1143.             GeneAssign.pageWindow:Hide()
  1144.             GeneAssign.pageSelectToggle = false
  1145.         end
  1146.     end)
  1147.     -- pridame do specialni tabulky = okno se da zavrit escapem
  1148.     tinsert(UISpecialFrames, "EditPageWindow")
  1149.    
  1150.    
  1151.     -- 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
  1152.     local titlebg = editWindow:CreateTexture(nil, "OVERLAY")
  1153.     titlebg:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header")
  1154.     titlebg:SetTexCoord(0.31, 0.67, 0, 0.63)
  1155.     titlebg:SetPoint("TOP", 0, 12)
  1156.     titlebg:SetWidth(100)
  1157.     titlebg:SetHeight(40)
  1158.  
  1159.     local title = CreateFrame("Frame", nil, editWindow)
  1160.     title:EnableMouse(true)
  1161.     title:SetScript("OnMouseDown", function(self, button) self:GetParent():StartMoving() end)
  1162.     title:SetScript("OnMouseUp", function(self, button) self:GetParent():StopMovingOrSizing() end)
  1163.     title:SetAllPoints(titlebg)
  1164.  
  1165.     local titletext = title:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  1166.     titletext:SetPoint("TOP", titlebg, "TOP", 0, -14)
  1167.     titletext:SetText("Edituj stranku")
  1168.  
  1169.     local titlebg_l = editWindow:CreateTexture(nil, "OVERLAY")
  1170.     titlebg_l:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header")
  1171.     titlebg_l:SetTexCoord(0.21, 0.31, 0, 0.63)
  1172.     titlebg_l:SetPoint("RIGHT", titlebg, "LEFT")
  1173.     titlebg_l:SetWidth(30)
  1174.     titlebg_l:SetHeight(40)
  1175.  
  1176.     local titlebg_r = editWindow:CreateTexture(nil, "OVERLAY")
  1177.     titlebg_r:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header")
  1178.     titlebg_r:SetTexCoord(0.67, 0.77, 0, 0.63)
  1179.     titlebg_r:SetPoint("LEFT", titlebg, "RIGHT")
  1180.     titlebg_r:SetWidth(30)
  1181.     titlebg_r:SetHeight(40)
  1182.     --
  1183.     -- titulek k toolboxu
  1184.     local toolboxLabel = editWindow:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
  1185.     toolboxLabel:SetText("Toolbox")
  1186.     toolboxLabel:SetPoint("TOPLEFT", 20, -30)
  1187.     -- titulek ke strance
  1188.     local pageLabel = editWindow:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
  1189.     pageLabel:SetText("Stranka")
  1190.     pageLabel:SetPoint("TOPLEFT", 185, -30)
  1191.    
  1192.     local pageName = editWindow:CreateFontString(nil, "ARTWORK", "GameFontWhiteSmall")
  1193.    
  1194.     pageName:SetText((self.selectedPage and GeneAssign_Pages[self.selectedPage].Name) or "") -- mozna chyba, nwm, da se nahradit podminkama
  1195.     pageName:SetPoint("BOTTOMLEFT", pageLabel, "BOTTOMRIGHT", 4, 0)
  1196.     -- titulek se stavem zpravy
  1197.     local statusTextLabel = editWindow:CreateFontString(nil, "ARTWORK", "GameFontWhite")
  1198.     statusTextLabel:SetText("Stranka |cff00ff00je |rulozena")
  1199.     statusTextLabel:SetPoint("TOPRIGHT", -50, -30)
  1200.    
  1201.     -- 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
  1202.     local buttonData = {
  1203.         { text = "|credCervena",        size = {77,26}, anchorPoint = {"TOPLEFT", 22, -50},     altText = "|cred"},
  1204.         { text = "|corange Oranzova",   size = {77,26}, anchorPoint = {"TOPLEFT", 102, -50},    altText = "|corange"},
  1205.         { text = "|cyellowZluta",       size = {77,26}, anchorPoint = {"TOPLEFT", 22, -80},     altText = "|cyellow"},
  1206.         { text = "|cgreenZelena",       size = {77,26}, anchorPoint = {"TOPLEFT", 102, -80},    altText = "|cgreen"},
  1207.         { text = "|cblueModra",         size = {77,26}, anchorPoint = {"TOPLEFT", 22, -110},    altText = "|cblue"},
  1208.         { text = "|cpurpleFialova",     size = {77,26}, anchorPoint = {"TOPLEFT", 102, -110},   altText = "|cpurple"},
  1209.         { text = "|cpinkRuzova",        size = {77,26}, anchorPoint = {"TOPLEFT", 22, -140},    altText = "|cpink"},
  1210.         { text = "|cwhiteBila",         size = {77,26}, anchorPoint = {"TOPLEFT", 102, -140},   altText = "|cwhite"},
  1211.        
  1212.         { text = " {star}",     size = {26,26}, anchorPoint = {"TOPLEFT", 22, -170}},
  1213.         { text = " {circle}",   size = {26,26}, anchorPoint = {"TOPLEFT", 54, -170}},
  1214.         { text = " {diamond}",  size = {26,26}, anchorPoint = {"TOPLEFT", 86, -170}},
  1215.         { text = " {triangle}", size = {26,26}, anchorPoint = {"TOPLEFT", 118, -170}},
  1216.         { text = " {moon}",     size = {26,26}, anchorPoint = {"TOPLEFT", 150, -170}},
  1217.         { text = " {square}",   size = {26,26}, anchorPoint = {"TOPLEFT", 22, -200}},
  1218.         { text = " {cross}",    size = {26,26}, anchorPoint = {"TOPLEFT", 54, -200}},
  1219.         { text = " {skull}",    size = {26,26}, anchorPoint = {"TOPLEFT", 86, -200}},
  1220.        
  1221.         { text = " {healthstone}",  size = {26,26}, anchorPoint = {"TOPLEFT", 118, -200}},
  1222.         { text = " {bloodlust}",    size = {26,26}, anchorPoint = {"TOPLEFT", 150, -200}},
  1223.         { text = " {damage}",       size = {26,26}, anchorPoint = {"TOPLEFT", 22, -230}},
  1224.         { text = " {tank}",         size = {26,26}, anchorPoint = {"TOPLEFT", 54, -230}},
  1225.         { text = " {healer}",       size = {26,26}, anchorPoint = {"TOPLEFT", 86, -230}},
  1226.        
  1227.         { text = " {hunter}",       size = {26,26}, anchorPoint = {"TOPLEFT", 118, -230}},
  1228.         { text = " {warrior}",      size = {26,26}, anchorPoint = {"TOPLEFT", 150, -230}},
  1229.         { text = " {rogue}",        size = {26,26}, anchorPoint = {"TOPLEFT", 22, -260}},
  1230.         { text = " {mage}",         size = {26,26}, anchorPoint = {"TOPLEFT", 54, -260}},
  1231.         { text = " {priest}",       size = {26,26}, anchorPoint = {"TOPLEFT", 86, -260}},
  1232.         { text = " {warlock}",      size = {26,26}, anchorPoint = {"TOPLEFT", 118, -260}},
  1233.         { text = " {druid}",        size = {26,26}, anchorPoint = {"TOPLEFT", 150, -260}},
  1234.         { text = " {paladin}",      size = {26,26}, anchorPoint = {"TOPLEFT", 22, -290}},
  1235.         { text = " {deathknight}",  size = {26,26}, anchorPoint = {"TOPLEFT", 54, -290}},
  1236.         { text = " {shaman}",       size = {26,26}, anchorPoint = {"TOPLEFT", 86, -290}},
  1237.     }
  1238.     -- iteruju celym polem, a pro kazde tlacitko vezmu jeho detaily a predam do funkce, ktera to tlacitko vytvori a prida do toho framu
  1239.     for i, obj in ipairs(buttonData) do
  1240.         self:CreateToolboxButton(editWindow, obj.text, obj.size, obj.anchorPoint, obj.altText or nil)
  1241.     end
  1242.    
  1243.     local togglePagesButton = CreateFrame("Button", nil, editWindow)
  1244.     togglePagesButton:SetNormalTexture("Interface\\Buttons\\UI-SpellbookIcon-PrevPage-Up.blp")
  1245.     togglePagesButton:SetPushedTexture("Interface\\Buttons\\UI-SpellbookIcon-PrevPage-Down.blp")   
  1246.     togglePagesButton:SetHighlightTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Highlight.blp")
  1247.     togglePagesButton:SetWidth(30)
  1248.     togglePagesButton:SetHeight(30)
  1249.     togglePagesButton:SetPoint("BOTTOMLEFT", 15, 18)
  1250.     togglePagesButton:SetScript("OnClick", function(self, button, down)
  1251.         GeneAssign:TogglePagesButtonClick()
  1252.     end)
  1253.     -- tlacitko Ulozit zmeny
  1254.     local acceptButton = CreateFrame("Button", nil, editWindow, "UIPanelButtonTemplate")
  1255.     acceptButton:SetText("Ulozit zmeny")
  1256.     acceptButton:SetSize(acceptButton:GetTextWidth()+40, acceptButton:GetTextHeight()+20)
  1257.     acceptButton:SetPoint("TOPLEFT", togglePagesButton, "TOPRIGHT", 5, 0)
  1258.     acceptButton:SetScript("OnClick", function(self, button, down)
  1259.         GeneAssign:AcceptButtonClick()
  1260.     end)
  1261.    
  1262.     -- tlacitko Vratit zmeny
  1263.     local revertButton = CreateFrame("Button", nil, editWindow, "UIPanelButtonTemplate")
  1264.     revertButton:SetText("Vratit zmeny")
  1265.     revertButton:SetSize(revertButton:GetTextWidth()+40, revertButton:GetTextHeight()+20)
  1266.     revertButton:SetPoint("TOPLEFT", acceptButton, "TOPRIGHT", 0, 0)
  1267.     revertButton:SetScript("OnClick", function(self, button, down)
  1268.         GeneAssign.RevertButtonClick()
  1269.     end)
  1270.    
  1271.     -- tlacitko Nahled
  1272.     local previewButton = CreateFrame("Button", nil, editWindow, "UIPanelButtonTemplate")
  1273.     previewButton:SetText("Nahled")
  1274.     previewButton:SetSize(previewButton:GetTextWidth()+40, previewButton:GetTextHeight()+20)
  1275.     previewButton:SetPoint("TOPLEFT", revertButton, "TOPRIGHT", 5, 0)
  1276.     previewButton:SetScript("OnClick", function(self, button, down)
  1277.         GeneAssign:PreviewButtonClick()
  1278.     end)
  1279.    
  1280.     -- tlacitko Ulozit a poslat
  1281.     local sendButton = CreateFrame("Button", nil, editWindow, "UIPanelButtonTemplate")
  1282.     sendButton:SetText("Ulozit a poslat")
  1283.     sendButton:SetSize(sendButton:GetTextWidth()+40, sendButton:GetTextHeight()+20)
  1284.     sendButton:SetPoint("TOPLEFT", previewButton, "TOPRIGHT", 5, 0)
  1285.     sendButton:SetScript("OnClick", function(self, button, down)
  1286.         if(IsInRaid() and (IsRaidLeader() or IsRaidOfficer())) then
  1287.             GeneAssign:SendButtonClick()
  1288.         else
  1289.             GeneAssign:Print("Nemas dostatecna prava")
  1290.         end
  1291.     end)
  1292.    
  1293.     -- tlacitko Zavrit
  1294.     local closeButton = CreateFrame("Button", nil, editWindow, "UIPanelButtonTemplate")
  1295.     closeButton:SetText("Zavrit")
  1296.     closeButton:SetSize(closeButton:GetTextWidth()+40, closeButton:GetTextHeight()+20)
  1297.     closeButton:SetPoint("TOPLEFT", sendButton, "TOPRIGHT", 5, 0)
  1298.     closeButton:SetScript("OnClick", function(self, button, down)
  1299.         -- GeneAssign:RevertChanges() --tady neni asi treba, pridal sem OnHide event, ve kterem ty changes revertnu, at to zavru tlacitkem anebo escapem
  1300.         editWindow:Hide()
  1301.     end)
  1302.    
  1303.     -- frame jako kontejner pro EditBox, ScrollFrame a Slider (na samotny scroll)
  1304.     local editFrame = CreateFrame("Frame", "EditFrameContainer", editWindow)
  1305.     editFrame:SetSize(380, 270)
  1306.     editFrame:SetPoint("TOPLEFT", pageLabel, "BOTTOMLEFT", 8, -5)
  1307.     editFrame:SetBackdrop({
  1308.         bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
  1309.         edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
  1310.         edgeSize = 16,
  1311.         insets = { left = 4, right = 3, top = 4, bottom = 3 }
  1312.     })
  1313.     editFrame:SetBackdropColor(0, 0, 0)
  1314.     editFrame:SetBackdropBorderColor(0.4, 0.4, 0.4)
  1315.    
  1316.     local editBox = CreateFrame("EditBox", "EditPageEditBox", editFrame)
  1317.     editBox:SetMultiLine(true)
  1318.     editBox:SetAutoFocus(false)
  1319.     editBox:EnableMouse(true)
  1320.     editBox:SetFont(self.defaultFont, 16, nil)
  1321.     editBox:SetWidth(370)
  1322.     editBox:SetHeight(270)
  1323.     editBox:SetScript("OnEscapePressed", editBox.ClearFocus)
  1324.     editBox:SetScript("OnTextChanged", EditBox_TextChanged)
  1325.    
  1326.     local scrollFrame = CreateFrame("ScrollFrame", "EditPageScrollFrame", editFrame, "UIPanelScrollFrameTemplate")
  1327.     scrollFrame:SetPoint("TOPLEFT", 8, -8)
  1328.     scrollFrame:SetPoint("BOTTOMRIGHT", -8, 8)
  1329.     scrollFrame:SetScrollChild(editBox)
  1330.     local scrollBar = _G[scrollFrame:GetName().."ScrollBar"]
  1331.     scrollBar.bg = scrollBar:CreateTexture(nil, "BACKGROUND")
  1332.     scrollBar.bg:SetAllPoints(true)
  1333.     scrollBar.bg:SetTexture(0, 0, 0, 0.5)
  1334.     editBox:SetFocus()
  1335.    
  1336.     editWindow.statusText = statusTextLabel
  1337.     editWindow.editBox = editBox
  1338.     editWindow.buttonAccept = acceptButton
  1339.     editWindow.buttonRevert = revertButton
  1340.     editWindow.buttonSend = sendButton
  1341.     editWindow.buttonPreview = previewButton
  1342.     editWindow.buttonTogglePages = togglePagesButton
  1343.     editWindow.buttonClose = closeButton
  1344.     editWindow.pageNameLabel = pageName
  1345.     GeneAssign.editWindow = editWindow
  1346. end
  1347.  
  1348. function GeneAssign:RevertChanges()
  1349.     -- vratim do editboxu zalohu textu a zablokuju tlacitka
  1350.     if not self.selectedPage then return end
  1351.     if not GeneAssign_Pages[self.selectedPage].Content then self:Print("Neexistuje zadna zaloha k vraceni") return end
  1352.     self:DisplayPageInEditBox()
  1353.     self.editWindow.buttonAccept:Disable()
  1354.     self.editWindow.buttonRevert:Disable()
  1355. end
  1356.  
  1357. function GeneAssign:AcceptChanges()
  1358.     -- ulozim do zalohy aktualni text v editboxu
  1359.     local text = self.editWindow.editBox:GetText()
  1360.     if not text then text = "" end
  1361.     GeneAssign_Pages[self.selectedPage].Content = text
  1362.     self.editWindow.statusText:SetText("Stranka |cff00ff00je |rulozena")
  1363. end
  1364.  
  1365. function GeneAssign:ShowEditWindow()
  1366.     self.editWindow:Show()
  1367.     self:RevertChanges()
  1368.     self:RenderTree() -- kvuli zmeny textboxu a page name labelu
  1369.     self.editWindow.buttonAccept:Enable()
  1370.     self.editWindow.buttonRevert:Enable()
  1371.     --self.editWindow.buttonSend:Enable() -- ted ho zapnem, pokud je to spatne, tak to co jde potom ho zase vypne
  1372.     self.pageSelectToggle = false
  1373.     self.editWindow.buttonTogglePages:SetButtonState("NORMAL")
  1374.     EditBox_TextChanged()
  1375.     if(not self.selectedPage or self.db.char.numPages == 0) then -- pokud nemame zadne stranky, vsechno zablokovat
  1376.         print("No pages - ShowEditWindow")
  1377.         self:EnableDisableEditWindow(false)
  1378.         --krome tlacitka s vyberem stranek samozrejme a tlacitka pro zavreni
  1379.         self.editWindow.buttonTogglePages:Enable()
  1380.         self.editWindow.buttonClose:Enable()
  1381.     end -- :D treba s Acceptem a revertem se sachuje furt, ale kdy se spravne zapne preview nebo send, to netusim :D ale funguje to :D
  1382. end
  1383.  
  1384. function GeneAssign:CreateToolboxButton(frame, showText, size, anchorPoint, text)
  1385.     -- vytvorim tlacitko podle zadanych parametru
  1386.     local button = CreateFrame("Button", nil, frame)
  1387.     button:SetBackdrop({
  1388.         edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
  1389.         edgeSize = 8
  1390.     })
  1391.     button:SetBackdropBorderColor(1, 1, 1, 0.5)
  1392.     button:SetPushedTextOffset(1, -1)
  1393.     button:SetText(RecognizeFixPatterns(showText))
  1394.     button:SetSize(unpack(size))
  1395.     button:SetNormalFontObject(GameFontHighlightMedium)
  1396.     button:SetPoint(unpack(anchorPoint))
  1397.     button:SetScript("OnClick", function(self, button)
  1398.         local fixedText
  1399.         if text then            -- pokud je zadany posledni parametr text (ktery je jen u barevneho textu) tak pouziju ten
  1400.             fixedText = text
  1401.         else                    -- jinak smazu mezeru ktera je na zacatku (ta je pro vycentrovani ikonky doprostred tlacitka)
  1402.             fixedText = showText:gsub(" {", "{")
  1403.         end
  1404.         GeneAssign.editWindow.editBox:Insert(fixedText)
  1405.     end)
  1406. end
  1407.  
  1408. ------------------------------
  1409. --      POMOCNE FUNKCE
  1410. ------------------------------
  1411. function IsInRaid()
  1412.     local inInstance, instanceType = IsInInstance()
  1413.     local result = false
  1414.     if(GetRealNumRaidMembers() > 0 and instanceType ~= "pvp" and instanceType ~= "arena") then
  1415.         result = true
  1416.     end
  1417.     return result  
  1418. end
  1419.  
  1420. function ci_pattern(pattern)
  1421.     -- uprimne toto netusim jak funguje, ale funguje, je to zkopirovano z AA
  1422.     local p = pattern:gsub("(%%?)(.)", function(percent, letter)
  1423.         if percent ~= "" or not letter:match("%a") then
  1424.             return percent .. letter
  1425.         else
  1426.             return string.format("[%s%s]", letter:lower(), letter:upper())
  1427.         end
  1428.     end)
  1429.     return p
  1430. end
  1431.  
  1432. function RecognizeFixPatterns(text)
  1433.     -- nahradi znacky jejich spravnymi ikonkami/kody
  1434.     text = text:gsub("||", "|")
  1435.                 :gsub(ci_pattern('|cblue'), "|cff00cbf4")
  1436.                 :gsub(ci_pattern('|cgreen'), "|cff0adc00")
  1437.                 :gsub(ci_pattern('|cred'), "|cffeb310c")
  1438.                 :gsub(ci_pattern('|cyellow'), "|cfffaf318")
  1439.                 :gsub(ci_pattern('|corange'), "|cffff9d00")
  1440.                 :gsub(ci_pattern('|cpink'), "|cfff64c97")
  1441.                 :gsub(ci_pattern('|cpurple'), "|cffdc44eb")
  1442.                 :gsub(ci_pattern('|cwhite'), "|cffffffff")
  1443.                 :gsub(ci_pattern('{star}'), "{rt1}")
  1444.                 :gsub(ci_pattern('{circle}'), "{rt2}")
  1445.                 :gsub(ci_pattern('{diamond}'), "{rt3}")
  1446.                 :gsub(ci_pattern('{triangle}'), "{rt4}")
  1447.                 :gsub(ci_pattern('{moon}'), "{rt5}")
  1448.                 :gsub(ci_pattern('{square}'), "{rt6}")
  1449.                 :gsub(ci_pattern('{cross}'), "{rt7}")
  1450.                 :gsub(ci_pattern('{x}'), "{rt7}")
  1451.                 :gsub(ci_pattern('{skull}'), "{rt8}")
  1452.                 :gsub(ci_pattern('{rt([1-8])}'), "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_%1:0|t" )
  1453.                 :gsub(ci_pattern('{healthstone}'), "{hs}")
  1454.                 :gsub(ci_pattern('{hs}'), "|TInterface\\Icons\\INV_Stone_04:0|t")
  1455.                 :gsub(ci_pattern('{bloodlust}'), "{bl}")
  1456.                 :gsub(ci_pattern('{bl}'), "|TInterface\\Icons\\SPELL_Nature_Bloodlust:0|t")
  1457.                 :gsub(ci_pattern('{damage}'), "{dps}")
  1458.                 :gsub(ci_pattern('{tank}'), "|TInterface\\LFGFrame\\UI-LFG-ICON-PORTRAITROLES:0:0:0:0:64:64:0:19:22:41|t")
  1459.                 :gsub(ci_pattern('{healer}'), "|TInterface\\LFGFrame\\UI-LFG-ICON-PORTRAITROLES:0:0:0:0:64:64:20:39:1:20|t")
  1460.                 :gsub(ci_pattern('{dps}'), "|TInterface\\LFGFrame\\UI-LFG-ICON-PORTRAITROLES:0:0:0:0:64:64:20:39:22:41|t")
  1461.                 :gsub(ci_pattern('{hero}'), "{heroism}")
  1462.                 :gsub(ci_pattern('{heroism}'), "|TInterface\\Icons\\ABILITY_Shaman_Heroism:0|t")
  1463.                 :gsub(ci_pattern('{hunter}'), "|TInterface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES:0:0:0:0:64:64:0:16:16:32|t")
  1464.                 :gsub(ci_pattern('{warrior}'), "|TInterface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES:0:0:0:0:64:64:0:16:0:16|t")
  1465.                 :gsub(ci_pattern('{rogue}'), "|TInterface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES:0:0:0:0:64:64:32:48:0:16|t")
  1466.                 :gsub(ci_pattern('{mage}'), "|TInterface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES:0:0:0:0:64:64:16:32:0:16|t")
  1467.                 :gsub(ci_pattern('{priest}'), "|TInterface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES:0:0:0:0:64:64:32:48:16:32|t")
  1468.                 :gsub(ci_pattern('{warlock}'), "|TInterface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES:0:0:0:0:64:64:48:64:16:32|t")
  1469.                 :gsub(ci_pattern('{paladin}'), "|TInterface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES:0:0:0:0:64:64:0:16:32:48|t")
  1470.                 :gsub(ci_pattern('{deathknight}'), "|TInterface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES:0:0:0:0:64:64:16:32:32:48|t")
  1471.                 :gsub(ci_pattern('{druid}'), "|TInterface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES:0:0:0:0:64:64:48:64:0:16|t")
  1472.                 :gsub(ci_pattern('{shaman}'), "|TInterface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES:0:0:0:0:64:64:16:32:16:32|t")
  1473.         return text
  1474. end
  1475.  
  1476. ------------------------------
  1477. --      EVENT HANDLERY
  1478. ------------------------------
  1479. function TextFrame_OnMouseDown(self, button)
  1480.     -- pri posunu textWindow
  1481.     if not GeneAssign.db.char.locked then
  1482.         if(button == "LeftButton") then
  1483.             self:StartMoving()
  1484.             self.isMoving = true
  1485.         end
  1486.     end
  1487. end
  1488.  
  1489. function TextFrame_OnMouseUp(self, button)
  1490.     -- pri posunu textWindow
  1491.     if not GeneAssign.db.char.locked then
  1492.         if self.isMoving then
  1493.             self:StopMovingOrSizing()
  1494.             self.isMoving = false
  1495.             lwin.SavePosition(self)
  1496.         end
  1497.     end
  1498. end
  1499.  
  1500. function TextFrame_DragDown(self, button)
  1501.     -- pri resizu textWindow
  1502.     local par = self:GetParent()
  1503.     par:StartSizing()
  1504.     par.isMoving = true
  1505. end
  1506.  
  1507. function TextFrame_DragUp(self, button)
  1508.     -- pri resizu textWindow
  1509.     local par = self:GetParent()
  1510.     if par.isMoving then
  1511.         par:StopMovingOrSizing()
  1512.         par.isMoving = false
  1513.         lwin.SavePosition(par)
  1514.     end
  1515. end
  1516.  
  1517. function EditBox_TextChanged(self, userInput)
  1518.     -- pri zmene textu v EditBoxu, pokud se text rovna zaloze, pak zablokuje tlacitka, jinak je odblokuje
  1519.     if not GeneAssign.selectedPage then return end
  1520.     if(GeneAssign.editWindow.editBox:GetText() == GeneAssign_Pages[GeneAssign.selectedPage].Content) then
  1521.         GeneAssign.editWindow.buttonAccept:Disable()
  1522.         GeneAssign.editWindow.buttonRevert:Disable()
  1523.         GeneAssign.editWindow.statusText:SetText("Stranka |cff00ff00je |rulozena")
  1524.         return
  1525.     end
  1526.     -- pokud jsme v nahledovem modu, pak veskere zmeny ukazujeme v messageframu (a tlacitka neodblokovavame)
  1527.     if GeneAssign.previewToggle then
  1528.         --DisplayPageInTextWindow() nepouzivam, protoze stranka neni ulozena, zobrazuju ciste jen text
  1529.         GeneAssign.textWindow.messageFrame:Clear()
  1530.         local rawText = GeneAssign.editWindow.editBox:GetText()
  1531.         local text = RecognizeFixPatterns(rawText)
  1532.         local lines = { strsplit("\n", text) }
  1533.         local lines_count = #lines
  1534.         for i = 1, lines_count do
  1535.             local line = lines[i]
  1536.             if line == "" then line = " " end
  1537.             GeneAssign.textWindow.messageFrame:AddMessage(line)
  1538.         end
  1539.     else   
  1540.         if(not GeneAssign.editWindow.buttonAccept:IsEnabled()) then GeneAssign.editWindow.buttonAccept:Enable() end
  1541.         if(not GeneAssign.editWindow.buttonRevert:IsEnabled()) then GeneAssign.editWindow.buttonRevert:Enable() end
  1542.     end
  1543.     GeneAssign.editWindow.statusText:SetText("Stranka |cffff0000neni |rulozena")
  1544. end
  1545.  
  1546. function GeneAssign:TogglePagesButtonClick()
  1547.     if not self.pageSelectToggle then
  1548.         -- zobrazit vyber stranek a prilepit ho vlevo k oknu
  1549.         self.editWindow.buttonTogglePages:SetButtonState("PUSHED", true)
  1550.        
  1551.         self.pageWindow:ClearAllPoints()
  1552.         self.pageWindow:SetPoint("TOPRIGHT", self.editWindow, "TOPLEFT", 5, 0)
  1553.         self:RenderTree()
  1554.         self.pageWindow:Show()
  1555.     else
  1556.         -- skryt vyber stranek
  1557.         self.editWindow.buttonTogglePages:SetButtonState("NORMAL")
  1558.         self.pageWindow:Hide()
  1559.     end
  1560.     self.pageSelectToggle = not self.pageSelectToggle
  1561. end
  1562.  
  1563. function GeneAssign:AcceptButtonClick()
  1564.     self:AcceptChanges()
  1565.     self.editWindow.buttonAccept:Disable()
  1566.     self.editWindow.buttonRevert:Disable()
  1567. end
  1568.  
  1569. function GeneAssign:RevertButtonClick()
  1570.     StaticPopup_Show("REVERT_CONFIRM")
  1571. end
  1572.  
  1573. function GeneAssign:PreviewButtonClick()
  1574.     if not self.previewToggle then
  1575.         -- zobrazit nahled
  1576.         -- 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)
  1577.         -- 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
  1578.         self:EnableDisablePageWindow(false)
  1579.         self.editWindow.buttonAccept:Disable()
  1580.         self.editWindow.buttonRevert:Disable()
  1581.         self.editWindow.buttonSend:Disable()
  1582.         self.editWindow.buttonPreview:SetButtonState("PUSHED", true)
  1583.        
  1584.        
  1585.         self.textWindow.messageFrame:Clear()
  1586.         local rawText = self.editWindow.editBox:GetText()
  1587.         local text = RecognizeFixPatterns(rawText)
  1588.         local lines = { strsplit("\n", text) }
  1589.         local lines_count = #lines
  1590.         for i = 1, lines_count do
  1591.             local line = lines[i]
  1592.             if line == "" then line = " " end
  1593.             self.textWindow.messageFrame:AddMessage(line)
  1594.         end
  1595.     else
  1596.         -- skryt nahled
  1597.         -- do messageframu vratim posledni ulozeny text
  1598.         self:EnableDisablePageWindow(true)
  1599.         self.editWindow.buttonAccept:Enable()
  1600.         self.editWindow.buttonRevert:Enable()
  1601.         self.editWindow.buttonSend:Enable()
  1602.         self.editWindow.buttonPreview:SetButtonState("NORMAL")
  1603.         EditBox_TextChanged() -- opet provedu jakousi "korekci" tlacitek (protoze kdyz nic pri nahledu nezmenime a jen proklikneme nahled, tak se zpristupni tlacitka i kdyz by nemely)
  1604.         --pri skryti nahledu zobrazim posledni ulozenou verzi, cili uz pouzit funkci muzu
  1605.         -- po skryti nahledu zobrazime POSLEDNI ZOBRAZENY TEXT, nikoli ulozenou verzi, tim by se textwindow prepisoval kdyz nema proc (ten by se mel na stalo prepisovat nejspis pouze pri poslani stranky, pokud si chceme prohlidnout jak vypada stranka, slouzi pro to prave nahled)
  1606.         self.textWindow.messageFrame:Clear()
  1607.         local shownText = self.db.char.shownText or ""
  1608.         local text = RecognizeFixPatterns(shownText)
  1609.         local lines = { strsplit("\n", text) }
  1610.         local lines_count = #lines
  1611.         for i = 1, lines_count do
  1612.             local line = lines[i]
  1613.             if line == "" then line = " " end
  1614.             self.textWindow.messageFrame:AddMessage(line)
  1615.         end
  1616.     end
  1617.     self.previewToggle = not self.previewToggle
  1618. end
  1619.  
  1620. function GeneAssign:SendButtonClick()
  1621.     -- ulozi zmeny, zablokuje tlacitka, zobrazi zpravu nam a pak ji posle do raidu
  1622.     self:AcceptChanges()
  1623.     self.editWindow.buttonAccept:Disable()
  1624.     self.editWindow.buttonRevert:Disable()
  1625.    
  1626.     if(not self.textWindow:IsShown()) then
  1627.         self.textWindow:Show()
  1628.         self.db.char.shown = true
  1629.         self.interfaceWindow.buttonShow:SetText("Skryj okno")
  1630.     end
  1631.    
  1632.     self:DisplayPageInTextWindow()
  1633.    
  1634.     self:SendPage(self.selectedPage) -- TODO upravit - prijima ID stranky, nikoli text
  1635. end
  1636.  
  1637. function GeneAssign:RAID_ROSTER_UPDATE()
  1638.     -- 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)
  1639.     self:CheckPermissions()
  1640. end
  1641.  
  1642. function GeneAssign:PLAYER_GUILD_UPDATE()
  1643.     -- pokud dojde k nejake zmene a bud jsme bez guildy nebo jiz nejsme v The Genesis, znicime po sobe dukazy :D
  1644.     local isInGuild = IsInGuild()
  1645.     local guildName, _, _ = GetGuildInfo("player")
  1646.     if(not (isInGuild == 1 and guildName == "The Genesis")) then
  1647.         self:DestroyEvidence()
  1648.     end
  1649. end
  1650.  
  1651. function GeneAssign:GUILD_ROSTER_UPDATE()
  1652.     self:UnregisterEvent("GUILD_ROSTER_UPDATE")
  1653.     local guildName, _, _ = GetGuildInfo("player")
  1654.     if(guildName ~= "The Genesis") then
  1655.         return
  1656.     else
  1657.         self:AfterEnable()
  1658.     end
  1659. end
  1660.  
  1661. ------------------------------
  1662. --      OSTATNI FUNKCE
  1663. ------------------------------
  1664. function GeneAssign:CheckPermissions()
  1665.     -- zkontroluje zda jsme v raidu a jsme RL/assist, pokud ano, odemkne nam pristup k edit oknu
  1666.     local permission = IsInRaid() and (IsRaidLeader() or IsRaidOfficer())
  1667.     if permission then
  1668.         self.editWindow.buttonSend:Enable()
  1669.         self.interfaceWindow.buttonEdit:Enable()
  1670.     else
  1671.         if(self.editWindow:IsShown()) then self.editWindow:Hide() end
  1672.         self.editWindow.buttonSend:Disable()
  1673.         self.interfaceWindow.buttonEdit:Disable()
  1674.     end
  1675.     return permission
  1676. end
  1677.  
  1678. function GeneAssign:ProcessSlashCommand(input)
  1679.     -- pomocna funkce k tisku napovedy
  1680.     local function PrintCommand(cmd, desc)
  1681.         print(string.format(' - |cFF33FF99%s|r: %s', cmd, desc))
  1682.     end
  1683.    
  1684.     -- obsluhuje slash commandy, viz komentare
  1685.     if not input or input:trim() == "" then
  1686.         --/ga
  1687.         self:ToggleShow()  
  1688.     else
  1689.         input = input:trim():lower()
  1690.        
  1691.         if(input == "show") then
  1692.             --/ga show
  1693.             self:ToggleShow()
  1694.         elseif(input == "options") then
  1695.             --/ga options
  1696.             InterfaceOptionsFrame_OpenToCategory(self.interfaceWindow)
  1697.         elseif(input == "lock") then
  1698.             --/ga lock
  1699.             self:ToggleLock()
  1700.             if(self.db.char.locked) then
  1701.                 self:Print("Okno je |cffff0000zamknute")
  1702.             else
  1703.                 self:Print("Okno je |cff00ff00odemknute")
  1704.             end
  1705.         elseif(input == "help") then
  1706.             --/ga help
  1707.             self:Print("Dostupne prikazy:")
  1708.             PrintCommand("show", "Zobrazi nebo skryje okno")
  1709.             PrintCommand("options", "Otevre nastaveni v interface")
  1710.             PrintCommand("lock", "Uzamkne nebo odemkne okno")
  1711.             PrintCommand("help", "Zobrazi napovedu")
  1712.             PrintCommand("edit", "Otevre editacni okno")
  1713.         elseif(input == "edit") then
  1714.             --/ga edit
  1715.             if(IsInRaid() and (IsRaidLeader() or IsRaidOfficer())) then
  1716.                 self:ShowEditWindow()
  1717.             else
  1718.                 self:Print("Nemate dostatecna prava pro zapis")
  1719.             end
  1720.         else
  1721.             --neznamy prikaz, zobrazi se napoveda
  1722.             self:Print("Neznamy prikaz, dostupne prikazy:")
  1723.             PrintCommand("show", "Zobrazi nebo skryje okno")
  1724.             PrintCommand("options", "Otevre nastaveni v interface")
  1725.             PrintCommand("lock", "Uzamkne nebo odemkne okno")
  1726.             PrintCommand("help", "Zobrazi napovedu")
  1727.             PrintCommand("edit", "Otevre editacni okno")
  1728.         end    
  1729.     end
  1730. end
  1731.  
  1732. function GeneAssign:DestroyEvidence() -- :D
  1733.     -- v pripade ze jsme byli kicknuti, zablokujeme komunikaci, odebereme /ga z slash commandu, skryjeme vsechny okna,
  1734.     -- odstranime kategorii Genesis Assignments z interface okna a kdybychom ho meli nahodou otevrene, tak skryjeme frame abychom dale nemohli addon nijak pouzivat
  1735.     -- (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)
  1736.     if not goodbyeOnce then
  1737.         self:Print("Goodbye")
  1738.         self.acceptMessages = false
  1739.         self:UnregisterChatCommand("ga")
  1740.         self:UnregisterEvent("RAID_ROSTER_UPDATE")
  1741.         self:UnregisterEvent("PLAYER_GUILD_UPDATE")
  1742.         self.editWindow:Hide()
  1743.         self.textWindow:Hide()
  1744.         self.pageWindow:Hide()
  1745.         for k, v in pairs(INTERFACEOPTIONS_ADDONCATEGORIES) do
  1746.             if(v.name == self.interfaceWindow.name) then
  1747.                 INTERFACEOPTIONS_ADDONCATEGORIES[k] = nil
  1748.             end
  1749.         end
  1750.         InterfaceAddOnsList_Update()
  1751.         if(InterfaceOptionsFramePanelContainer.displayedPanel and InterfaceOptionsFramePanelContainer.displayedPanel:IsShown()) then
  1752.             InterfaceOptionsFramePanelContainer.displayedPanel:Hide()
  1753.         end
  1754.         goodbyeOnce = true
  1755.     end
  1756. end
  1757.  
  1758. function BuildFontPicker() -- pouze pomocna feature pri vyvoji, pak se smaze
  1759.  
  1760.     -- Create the parent frame that will contain the inner scroll child,
  1761.     -- all font strings, and the scroll bar slider.
  1762.     local fp = FPreviewFrame or CreateFrame("ScrollFrame", "FPreviewFrame")
  1763.      
  1764.     -- This is a bare-bones frame is used to encapsulate the contents of
  1765.     -- the scroll frame.  Each scrollframe can have one scroll child.
  1766.     local fpsc = FPreviewSC or CreateFrame("Frame", "FPreviewSC")
  1767.      
  1768.     -- Create the slider that will be used to scroll through the results
  1769.     local fpsb = FPreviewScrollBar or CreateFrame("Slider", "FPreviewScrollBar", fp)
  1770.      
  1771.     -- Set up internal textures for the scrollbar, background and thumb texture
  1772.     if not fpsb.bg then
  1773.        fpsb.bg = fpsb:CreateTexture(nil, "BACKGROUND")
  1774.        fpsb.bg:SetAllPoints(true)
  1775.        fpsb.bg:SetTexture(0, 0, 0, 0.5)
  1776.     end
  1777.      
  1778.     if not fpsb.thumb then
  1779.        fpsb.thumb = fpsb:CreateTexture(nil, "OVERLAY")
  1780.        fpsb.thumb:SetTexture("Interface\\Buttons\\UI-ScrollBar-Knob")
  1781.        fpsb.thumb:SetSize(25, 25)
  1782.        fpsb:SetThumbTexture(fpsb.thumb)
  1783.     end
  1784.      
  1785.     local genv = getfenv(0)
  1786.      
  1787.     -- Collect the names of all possible globally defined fonts
  1788.     local fonts = {}
  1789.     for k, v in pairs(genv) do
  1790.        if type(v) == "table" and type(v.GetObjectType) == "function" then
  1791.           local otype = v:GetObjectType()
  1792.           if otype == "Font" then
  1793.              table.insert(fonts, k)
  1794.           end
  1795.        end
  1796.     end
  1797.      
  1798.     -- Sort the list alphabetically
  1799.     table.sort(fonts)
  1800.      
  1801.     -- Create a table that will contain the font strings themselves
  1802.     fpsc.fstrings = fpsc.fstrings or {}
  1803.      
  1804.     -- This changes the padding between font strings vertically
  1805.     local PADDING = 5
  1806.      
  1807.     -- Store the max width and overall height of the scroll child
  1808.     local height = 0
  1809.     local width = 0
  1810.      
  1811.     -- Iterate the list of fonts collected
  1812.     for idx, fname in ipairs(fonts) do
  1813.        -- If the font string is not created, do so
  1814.        if not fpsc.fstrings[idx] then
  1815.           print(idx, fname)
  1816.           fpsc.fstrings[idx] = fpsc:CreateFontString("FPreviewFS" .. idx, "OVERLAY")
  1817.        end
  1818.        
  1819.        -- Set the font string to the correct font object, set the text to be the
  1820.        -- name of the font and set the height/width of the font string based on
  1821.        -- the size of the resulting 'string'.
  1822.        local fs = fpsc.fstrings[idx]
  1823.        fs:SetFontObject(genv[fname])
  1824.        fs:SetText(fname)
  1825.        local fwidth = fs:GetStringWidth()
  1826.        local fheight = fs:GetStringHeight()
  1827.        fs:SetSize(fwidth, fheight)
  1828.        
  1829.        -- Place the font strings in rows starting at the top-left
  1830.        if idx == 1 then
  1831.           fs:SetPoint("TOPLEFT", 0, 0)
  1832.           height = height + fheight
  1833.        else
  1834.           fs:SetPoint("TOPLEFT", fpsc.fstrings[idx - 1], "BOTTOMLEFT", 0, - PADDING)
  1835.           height = height + fheight + PADDING
  1836.        end
  1837.        
  1838.        -- Update the 'max' width of the frame
  1839.        width = (fwidth > width) and fwidth or width
  1840.     end
  1841.      
  1842.     -- Set the size of the scroll child
  1843.     fpsc:SetSize(width, height)
  1844.      
  1845.     -- Size and place the parent frame, and set the scrollchild to be the
  1846.     -- frame of font strings we've created
  1847.     fp:SetSize(width, 400)
  1848.     fp:SetPoint("CENTER", UIParent, 0, 0)
  1849.     fp:SetScrollChild(fpsc)
  1850.     fp:Show()
  1851.      
  1852.     fpsc:SetSize(width, height)
  1853.      
  1854.     -- Set up the scrollbar to work properly
  1855.     local scrollMax = height - 400
  1856.     fpsb:SetOrientation("VERTICAL");
  1857.     fpsb:SetSize(16, 400)
  1858.     fpsb:SetPoint("TOPLEFT", fp, "TOPRIGHT", 0, 0)
  1859.     fpsb:SetMinMaxValues(0, scrollMax)
  1860.     fpsb:SetValue(0)
  1861.     fpsb:SetScript("OnValueChanged", function(self)
  1862.           fp:SetVerticalScroll(self:GetValue())
  1863.     end)
  1864.      
  1865.     -- Enable mousewheel scrolling
  1866.     fp:EnableMouseWheel(true)
  1867.     fp:SetScript("OnMouseWheel", function(self, delta)
  1868.           local current = fpsb:GetValue()
  1869.            
  1870.           if IsShiftKeyDown() and (delta > 0) then
  1871.              fpsb:SetValue(0)
  1872.           elseif IsShiftKeyDown() and (delta < 0) then
  1873.              fpsb:SetValue(scrollMax)
  1874.           elseif (delta < 0) and (current < scrollMax) then
  1875.              fpsb:SetValue(current + 20)
  1876.           elseif (delta > 0) and (current > 1) then
  1877.              fpsb:SetValue(current - 20)
  1878.           end
  1879.     end)
  1880. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement