Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Zaloha pred velkym page reworkem
- local GeneAssign = LibStub("AceAddon-3.0"):NewAddon("GenesisAssignments", "AceConsole-3.0", "AceEvent-3.0", "AceComm-3.0")
- local lwin = LibStub("LibWindow-1.1")
- local serializer = LibStub("AceSerializer-3.0")
- local AceGUI = LibStub("AceGUI-3.0")
- -- z nejakeho duvodu se obcas DestroyEvidence() volal dvakrat, tak staci to jednou..
- local goodbyeOnce = false
- --[[ Globalni promenne v GeneAssign:
- textWindow - pro frame, ve kterem je messageFrame
- messageFrame - pro scrolling message frame, do ktereho pujdou zpravy
- dragHandle - pro tahlo na zmenu velikosti textWindowu
- interfaceWindow - pro frame, ktery je hlavnim framem v interface
- buttonLock - tlacitko pro lock textWindowu (menim jeho text v ToggleLock())
- buttonShow - tlacitko pro show/hide textWindowu (mozna jeho zmena v SendButtonClick)
- buttonEdit - tlacitko pro otevreni Edit Windowu (zmena enable state v CheckPermissions)
- editWindow - pro cele editacni okno (at ho muzu v interface zobrazit)
- statusText - kratky fontstring co informuje o tom jestli jsme text ulozili nebo ne
- editBox (GeneAssign.editWindow.editBox) - editbox, ve kterem se edituje stranka
- buttonTogglePages
- buttonAccept - asi self-explanatory
- buttonRevert
- buttonSend
- buttonPreview
- pageNameLabel - kratky label s nazvem prave editovane stranky
- pageWindow - pro cele okno s strankami
- treeFrame - frame uvnitr scrollFramu, pridavaji se do neho tlacitka/stranky
- buttonRemove
- buttonRename
- defaultFont - defaultni font (pouze cesta) pro messageFrame
- addonPrefix - prefix pro komunikaci mezi addony
- acceptMessages - bool co znaci, jestli prijimame zpravy (pri DestroyEvidence se zmeni na false a zabrani prijmuti zprav)
- db - databaze ktera se uchovava mezi relogy/reloady (struktura vic defaultSettings table)
- previewToggle - bool, jestli mame zobrazeny nahled
- ]]--
- GeneAssign.defaultFont = "Interface\\AddOns\\TheGenesisAssignments11\\Fonts\\ABF.ttf"
- GeneAssign.addonPrefix = "GeneAss"
- -- oznacuje, jestli se maji prijimat a zpracovavat prichozi stranky (v DestroyEvidence() se to zakazuje)
- GeneAssign.acceptMessages = true
- GeneAssign.previewToggle = false
- GeneAssign.buttons = {}
- GeneAssign.selectedPage = nil
- GeneAssign.pageSelectToggle = false
- -- backup - aktualne ulozena stranka
- -- locked, shown - popisuji stav textWindow
- -- fontSize - asi self-explanatory, aktualne ulozena velikost fontu
- GeneAssign.pages = {}
- GeneAssign.numPages = 0
- local startup = true --proto, aby se pri prvnim spusteni oznacila prvni stranka a ne posledni pridana, jak je tomu vzdy jindy
- local defaultSettings = {
- char = {
- backup = "This is a test page",
- locked = false,
- shown = false,
- fontSize = 16,
- }
- }
- function GeneAssign:OnInitialize()
- end
- function GeneAssign:OnEnable()
- -- podivny workaround na to aby to nikdo jiny pouzivat nemohl..
- -- 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
- -- 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
- -- 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
- self:AfterEnable()
- --[[self:RegisterEvent("GUILD_ROSTER_UPDATE")
- local isInGuild = IsInGuild()
- if(isInGuild == 1) then
- GuildRoster()
- else
- return
- end]]
- end
- function GeneAssign:AfterEnable()
- -- pokud probehne dobre ten workaround, a mame teda potvrzene ze jsme z The Genesis, pokracujeme s zbytkem nastaveni, vytvoreni oken atd.
- self:RegisterChatCommand("ga", "ProcessSlashCommand")
- GeneAssign.db = LibStub("AceDB-3.0"):New("TheGenesisAssignmentsDB11", defaultSettings, true)
- StaticPopupDialogs["REVERT_CONFIRM"] = {
- text = "Opravdu chcete obnovit posledni zalohu?",
- button1 = "Ano",
- button2 = "Ne",
- OnAccept = function()
- self:RevertChanges()
- end,
- timeout = 0,
- whileDead = true,
- hideOnEscape = true,
- preferredIndex = 3,
- }
- StaticPopupDialogs["CLEAR_CONFIRM"] = {
- text = "Opravdu chcete smazat stranku (zmeny se neulozi)?",
- button1 = "Ano",
- button2 = "Ne",
- OnAccept = function()
- self.editWindow.editBox:SetText("")
- end,
- timeout = 0,
- whileDead = true,
- hideOnEscape = true,
- preferredIndex = 3,
- }
- self:RegisterComm(self.addonPrefix, "ReceiveMessage")
- self:RegisterEvent("RAID_ROSTER_UPDATE")
- self:RegisterEvent("PLAYER_GUILD_UPDATE")
- --BuildFontPicker()
- self:BuildTreeWindow()
- self:BuildTextWindow()
- self:BuildInterfaceWindow()
- self:BuildEditWindow()
- self:CheckPermissions()
- end
- function GeneAssign:BuildTreeWindow()
- --[[
- 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
- 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)
- 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)
- ]]
- local pageWindow = CreateFrame("Frame", nil, UIParent)
- pageWindow:SetBackdrop({
- bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
- edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
- tile = true, tileSize = 32, edgeSize = 32,
- insets = { left = 8, right = 8, top = 8, bottom = 8 }
- })
- pageWindow:SetSize(215, 380)
- pageWindow:SetPoint("CENTER", 0, 0)
- pageWindow:SetMovable(true)
- pageWindow:Hide()
- --treeFrame:SetBackdrop({ bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background", tile = true, tileSize = 32})
- --[[local scrollFrame = CreateFrame("ScrollFrame", "SelectPageScrollFrame", container, "UIPanelScrollFrameTemplate")
- scrollFrame:SetPoint("TOPLEFT", 18, -18)
- scrollFrame:SetPoint("BOTTOMRIGHT", -32, 48) --18
- scrollFrame:SetBackdrop({
- bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
- edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
- tile = true, tileSize = 16, edgeSize = 8,
- insets = { left = 3, right = 3, top = 5, bottom = 3 }
- })
- scrollFrame:SetBackdropColor(0, 0, 0, 0.5)
- scrollFrame:SetBackdropBorderColor(0.4, 0.4, 0.4)
- local treeFrame = CreateFrame("Frame", nil, scrollFrame)
- treeFrame:SetWidth(170) --155
- treeFrame:SetHeight(150)
- scrollFrame:SetScrollChild(treeFrame)
- local scrollBar = _G[scrollFrame:GetName().."ScrollBar"]
- scrollBar.bg = scrollBar:CreateTexture(nil, "BACKGROUND")
- scrollBar.bg:SetAllPoints(true)
- scrollBar.bg:SetTexture(0, 0, 0, 0.5)]]
- local container = CreateFrame("Frame", nil, pageWindow)
- container:SetPoint("TOPLEFT", 18, -18)
- container:SetPoint("BOTTOMRIGHT", -32, 94) --48
- container:SetBackdrop({
- bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
- edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
- tile = true, tileSize = 16, edgeSize = 8,
- insets = { left = 3, right = 3, top = 3, bottom = 3 }
- })
- container:SetBackdropColor(0, 0, 0, 0.5)
- container:SetBackdropBorderColor(0.4, 0.4, 0.4)
- local scrollFrame = CreateFrame("ScrollFrame", "SelectPageScrollFrame", container, "UIPanelScrollFrameTemplate")
- scrollFrame:SetPoint("TOPLEFT", 5, -5)
- scrollFrame:SetPoint("BOTTOMRIGHT", -5, 5) --18
- local treeFrame = CreateFrame("Frame", nil, container)
- treeFrame:SetWidth(170) --155
- treeFrame:SetHeight(150)
- scrollFrame:SetScrollChild(treeFrame)
- local scrollBar = _G[scrollFrame:GetName().."ScrollBar"]
- scrollBar.bg = scrollBar:CreateTexture(nil, "BACKGROUND")
- scrollBar.bg:SetAllPoints(true)
- scrollBar.bg:SetTexture(0, 0, 0, 0.5)
- --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)
- --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
- --[[local testButton = CreateFrame("Button", "TestButton", frame, "OptionsListButtonTemplate")
- testButton:SetPoint("CENTER", 0, 0)
- testButton:SetText("Test text")
- testButton.text:SetHeight(14)
- --testButton:SetSize(100, 20)
- testButton.value = 1
- testButton.selected = true
- --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)
- testButton:LockHighlight()
- local testButton1 = CreateFrame("Button", "TestButton1", frame, "OptionsListButtonTemplate")
- testButton1:SetPoint("TOPLEFT", testButton, "BOTTOMLEFT", 0, 0)
- testButton1:SetText("Test text2")
- testButton1.text:SetHeight(14)
- --testButton:SetSize(100, 20)
- testButton1.value = 2
- testButton1.selected = false
- 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)
- 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)
- ]]
- --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..
- --jdeme zkusit vytvorit tlacitka z stromu
- --self:RenderTree() -- AddPage si RenderTree vola sama
- --[[ ok, vytvoreni tlacitek ze stromu taky mame, jdem k tomu pridat dalsi operace, tzn.
- 1) pridani dalsi stranky (a k tomu test re-renderu, jestli spravne skryva tlacitka atd.)
- 2) i takove obycejne operace jako vraceni prave vybrane stranky, popr. zmena vybrane stranky
- 3) odebrani prave vybrane stranky
- 4) prejmenovani stranky (a nasledny re-render)
- ]]
- --print(self:GetSelectedId())
- StaticPopupDialogs["ADD_PAGE"] = {
- button1 = OKAY,
- button2 = CANCEL,
- OnAccept = function(self)
- local text = self.editBox:GetText()
- if text ~= "" then GeneAssign:AddPage(text) end
- end,
- EditBoxOnEnterPressed = function(self)
- local text = self:GetParent().editBox:GetText()
- if text ~= "" then GeneAssign:AddPage(text) end
- self:GetParent():Hide()
- end,
- text = "Zadejte jmeno stranky: ",
- hasEditBox = true,
- whileDead = true,
- EditBoxOnEscapePressed = function(self) self:GetParent():Hide() end,
- hideOnEscape = true,
- timeout = 0,
- preferredIndex = 3
- }
- StaticPopupDialogs["RENAME_PAGE"] = {
- button1 = OKAY,
- button2 = CANCEL,
- OnAccept = function(self)
- local text = self.editBox:GetText()
- if text ~= "" then GeneAssign:RenameSelectedPage(text) end
- end,
- EditBoxOnEnterPressed = function(self)
- local text = self:GetParent().editBox:GetText()
- if text ~= "" then GeneAssign:RenameSelectedPage(text) end
- self:GetParent():Hide()
- end,
- text = "Zadejte nove jmeno stranky: ",
- hasEditBox = true,
- whileDead = true,
- EditBoxOnEscapePressed = function(self) self:GetParent():Hide() end,
- hideOnEscape = true,
- timeout = 0,
- preferredIndex = 3
- }
- StaticPopupDialogs["REMOVE_PAGE"] = {
- text = "Smazat vybranou stranku?",
- button1 = OKAY,
- button2 = CANCEL,
- OnAccept = function()
- self:RemoveSelectedPage()
- end,
- timeout = 0,
- whileDead = true,
- hideOnEscape = true,
- preferredIndex = 3,
- }
- local removeButton = CreateFrame("Button", "RemoveButton", pageWindow, "UIPanelButtonTemplate")
- removeButton:SetText("Odstranit stranku")
- removeButton:SetHeight(removeButton:GetTextHeight() + 10)
- removeButton:SetPoint("BOTTOMLEFT", 20, 20)
- removeButton:SetPoint("BOTTOMRIGHT", -20, 20)
- removeButton:SetScript("OnClick", function()
- if GeneAssign:GetSelectedId() then
- StaticPopup_Show("REMOVE_PAGE")
- end
- end)
- local renameButton = CreateFrame("Button", "RenameButton", pageWindow, "UIPanelButtonTemplate")
- renameButton:SetText("Prejmenovat stranku")
- renameButton:SetHeight(renameButton:GetTextHeight() + 10)
- renameButton:SetPoint("BOTTOMLEFT", removeButton, "TOPLEFT", 0, 2)
- renameButton:SetPoint("BOTTOMRIGHT", removeButton, "TOPRIGHT", 0, 2)
- renameButton:SetScript("OnClick", function()
- if GeneAssign:GetSelectedId() then
- StaticPopup_Show("RENAME_PAGE")
- end
- end)
- local addButton = CreateFrame("Button", "AddButton", pageWindow, "UIPanelButtonTemplate")
- addButton:SetText("Pridat stranku")
- addButton:SetHeight(addButton:GetTextHeight() + 10)
- addButton:SetPoint("BOTTOMLEFT", renameButton, "TOPLEFT", 0, 2)
- addButton:SetPoint("BOTTOMRIGHT", renameButton, "TOPRIGHT", 0, 2)
- addButton:SetScript("OnClick", function() StaticPopup_Show("ADD_PAGE") end)
- pageWindow.buttonRemove = removeButton
- pageWindow.buttonRename = renameButton
- pageWindow.treeFrame = treeFrame
- self.pageWindow = pageWindow
- for i = 1, 16 do self:AddPage(string.format("Page %02d", i)) end
- startup = false
- -- 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)
- -- ok, timto bychom meli vicemene udelane stranky, umi je pridavat, odebirat, atd., vsecko co bylo zmineno drive
- -- ROZDIL PAIRS VS IPAIRS
- --[[
- local x = {1, 2, 5, 10, 16}
- for k, v in pairs(x) do print("pairs, k = " .. k .. ", v = " .. v) end
- for k, v in ipairs(x) do print("ipairs, k = " .. k .. ", v = " .. v) end
- -- oba vypisou to same
- -- pairs, k = 1, v = 1
- -- pairs, k = 2, v = 2
- -- pairs, k = 3, v = 5
- -- pairs, k = 4, v = 10
- -- pairs, k = 5, v = 16
- print("y:")
- local y = {[1] = 1, [2] = 2, [5] = 5, [10] = 10, [16] = 16}
- for k, v in pairs(y) do print("pairs, k = " .. k .. ", v = " .. v) end
- for k, v in ipairs(y) do print("ipairs, k = " .. k .. ", v = " .. v) end
- -- vypise se toto:
- -- pairs, k = 2, v = 2
- -- pairs, k = 10, v = 10
- -- pairs, k = 1, v = 1
- -- pairs, k = 5, v = 5
- -- pairs, k = 16, v = 16
- -- ipairs, k = 1, v = 1
- -- ipairs, k = 2, v = 2
- -- => 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
- -- 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
- -- => v praxi = pro self.pages pouzivame vlastni indexy = vzdy pairs
- -- pro self.buttons taky pairs, taky mame vlastni indexy
- -- pro GetSortedTree, table.insert podle testu pravdepodobne neindexuje (jako vyse v pripade pole x), protoze pairs i ipairs vraci stejne vysledky
- -- coz znamena ze pro hlavni cyklus v RenderTree() muzeme pouzit jakykoli iterator a vysledek je stejny
- ]]
- end
- function GeneAssign:GetSortedTree()
- if not self.pages then return end
- -- puvodni strom asi radit nebudu, nebudu ho menit, udelam kopii
- local treeCopy = {}
- for _, page in pairs(self.pages) do
- table.insert(treeCopy, page)
- end
- --for k, v in pairs(treeCopy) do print("GetSortedTree, pairs, k = " .. k .. ", v.value = " .. v.value .. ", v.text = " .. v.text) end
- --for k, v in ipairs(treeCopy) do print("GetSortedTree, ipairs, k = " .. k .. ", v.value = " .. v.value .. ", v.text = " .. v.text) end
- table.sort(treeCopy, function(a, b) return a.text < b.text end)
- --print("Po serazeni")
- --for k, v in pairs(treeCopy) do print("GetSortedTree, pairs, k = " .. k .. ", v.value = " .. v.value .. ", v.text = " .. v.text) end
- --for k, v in ipairs(treeCopy) do print("GetSortedTree, ipairs, k = " .. k .. ", v.value = " .. v.value .. ", v.text = " .. v.text) end
- return treeCopy
- end
- function GeneAssign:RenderTree()
- local tree = self:GetSortedTree()
- -- ani nemusim nic vracet, kdyz tree nebude existovat, hlavni cyklus by to melo preskocit a aspon to poresi podminky potom s tim selectedPage
- for k, button in pairs(self.buttons) do
- --print("RenderTree delete loop, k = " .. k .. ", button value = " .. button.value)
- button:Hide()
- self.buttons[k] = nil
- end
- 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)
- --print("RenderTree loop, i = " .. i .. ", value = " .. page.value .. ", text = " .. page.text)
- local button = CreateFrame("Button", "Page"..(page.value), self.pageWindow.treeFrame, "OptionsListButtonTemplate")
- self.buttons[page.value] = button --i se pouzit neda, viz vyse
- button:SetText(page.text)
- button.text:SetHeight(14)
- button:SetWidth(self.pageWindow.treeFrame:GetWidth() - 3)
- button.value = page.value
- button.selected = false
- button:SetScript("OnClick", function(self)
- if not self.selected then
- GeneAssign.selectedPage = self.value
- self.selected = true
- self:LockHighlight()
- for _, otherButton in pairs(GeneAssign.buttons) do
- if(self ~= otherButton) then
- otherButton.selected = false
- otherButton:UnlockHighlight()
- end
- end
- GeneAssign.editWindow.pageNameLabel:SetText(GeneAssign.pages[self.value].text)
- end
- end)
- --if (i == 1) then
- button:SetPoint("TOPLEFT", 0, -3 - (i-1)*button:GetHeight())
- --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)
- -- button:SetPoint("TOPLEFT", )
- --end
- end
- if not self.selectedPage then
- if(self.numPages >= 1) then -- jedna se sice o tlacitka ale stranky a tlacitka by mely odpovidat 1:1 takze muzu pouzit i toto
- 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
- self.buttons[page.value].selected = true
- self.buttons[page.value]:LockHighlight()
- self.selectedPage = page.value
- break
- end
- end
- else -- pokud mame nejakou stranku vybranou, pak akorat vyberu to tlacitko
- self.buttons[self.selectedPage].selected = true
- self.buttons[self.selectedPage]:LockHighlight()
- end
- end
- function GeneAssign:GetSelectedId()
- return self.selectedPage
- end
- function GeneAssign:AddPage(content)
- local randomID = math.random(10000)
- while self.pages[randomID] do
- randomID = math.random(10000)
- end
- self.pages[randomID] = { value = randomID, text = content }
- self.numPages = self.numPages + 1
- --for k, v in pairs(self.pages) do print("AddPage text, k = " .. k .. ", value = " .. v.value .. ", text = " .. v.text) end
- if not startup then
- self.selectedPage = randomID
- end
- self:RenderTree()
- end
- function GeneAssign:RemoveSelectedPage()
- self.pages[self.selectedPage] = nil
- self.selectedPage = nil -- stejne se hned zmeni v RenderTree, netreba to delat znova tady
- self:RenderTree()
- end
- function GeneAssign:RenameSelectedPage(content)
- self.pages[self.selectedPage].text = content
- self:RenderTree()
- end
- --------------------------
- -- KOMUNIKACE
- --------------------------
- function GeneAssign:ReceiveMessage(prefix, data, channel, sender)
- -- pokud probehlo DestroyEvidence() tak neprijimame dalsi zpravy
- if not self.acceptMessages then return end
- if prefix ~= self.addonPrefix then return end
- local success, deserializedData = serializer:Deserialize(data)
- if not success then
- self:Print("Chyba pri deserializaci dat")
- return
- end
- self:ProcessMessage(deserializedData, sender)
- end
- function GeneAssign:ProcessMessage(data, sender)
- -- k tomuto se pravdepodobne nedostane ale kdyby data byla prazdna, tak skoncime
- if not data then return end
- -- ignorujeme vlastni zpravy
- if(sender == UnitName("player")) then return end
- if(not self.textWindow:IsShown()) then self.textWindow:Show() end
- -- vycistime text okno, v pripade ze zrovna editujeme aktualizujeme text, ulozime do backup
- self.textWindow.messageFrame:Clear()
- self.db.char.backup = data
- if(self.editWindow:IsShown()) then
- self.editWindow.editBox:SetText(data)
- end
- -- zobrazime text do textWindowu
- local text = RecognizeFixPatterns(data)
- local lines = { strsplit("\n", text) }
- local lines_count = #lines
- for i = 1, lines_count do
- local line = lines[i]
- if line == "" then line = " " end
- self.textWindow.messageFrame:AddMessage(line)
- end
- end
- function GeneAssign:SendMessage(data)
- if(not IsInRaid()) then return end
- local dataToSend = data or self.db.char.backup or ""
- local serializedData = serializer:Serialize(dataToSend)
- self:SendCommMessage(self.addonPrefix, serializedData, "RAID")
- end
- -------------------------
- -- TEXT OKNO
- -------------------------
- function GeneAssign:BuildTextWindow()
- -- cele okno pro ten textWindow
- local TextFrame = CreateFrame("Frame", "TextFrame", UIParent)
- -- v LibWindow si registrujeme, ze chceme uchovavat pozici tohoto framu, a ulozime to do self.db.char (cili pro kazdy char zvlast)
- lwin.RegisterConfig(TextFrame, self.db.char)
- TextFrame:Hide()
- TextFrame:SetToplevel(true)
- TextFrame:EnableMouse(true)
- TextFrame:SetMovable(true)
- TextFrame:SetResizable(true)
- TextFrame:SetMinResize(100, 100)
- TextFrame:SetSize(200, 200)
- TextFrame:SetPoint("CENTER", UIParent, "CENTER", 0, 0) -- ze zacatku ukotvime doprostred
- lwin.RestorePosition(TextFrame) -- a ulozime (pozdeji nacteme) pozici a velikost framu
- TextFrame:SetBackdrop({
- bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
- tile = true,
- tileSize = 32,
- })
- TextFrame:SetScript("OnMouseDown", TextFrame_OnMouseDown)
- TextFrame:SetScript("OnMouseUp", TextFrame_OnMouseUp)
- -- tahlo pro resize framu
- local TextFrameDragHandle = CreateFrame("Frame", "TextFrameDragHandle", TextFrame)
- TextFrameDragHandle:SetSize(16, 16)
- TextFrameDragHandle:SetPoint("BOTTOMRIGHT", TextFrame, "BOTTOMRIGHT", 0, 0)
- TextFrameDragHandle:SetScript("OnMouseDown", TextFrame_DragDown)
- TextFrameDragHandle:SetScript("OnMouseUp", TextFrame_DragUp)
- if self.db.char.locked then
- TextFrameDragHandle:Hide()
- end
- TextFrame.dragHandle = TextFrameDragHandle
- -- nastavime texturu tomu tahlu
- local texture = TextFrameDragHandle:CreateTexture("TextFrameDragHandleTexture", "OVERLAY")
- texture:SetTexture("Interface\\AddOns\\TheGenesisAssignments11\\Textures\\draghandle")
- texture:SetBlendMode("ADD")
- texture:SetSize(16,16)
- texture:SetPoint("TOPLEFT", TextFrameDragHandle, "TOPLEFT", 0, 0)
- -- scrolling frame do ktereho potom budeme psat
- local scrollingFrame = CreateFrame("ScrollingMessageFrame", "ScrollingFrameTest", TextFrame)
- scrollingFrame:SetSize(180, 180)
- scrollingFrame:SetPoint("TOPLEFT", TextFrame, "TOPLEFT", 10, -10)
- scrollingFrame:SetPoint("BOTTOMRIGHT", TextFrame, "BOTTOMRIGHT", -10, 10)
- scrollingFrame:SetFading(false) -- at text nebledne casem
- scrollingFrame:SetMaxLines(70)
- scrollingFrame:SetJustifyH("LEFT")
- scrollingFrame:SetJustifyV("TOP")
- scrollingFrame:SetInsertMode("bottom")
- scrollingFrame:SetFont(self.defaultFont, self.db.char.fontSize, nil)
- scrollingFrame:EnableMouseWheel(true)
- scrollingFrame:SetScript("OnMouseWheel", function(self, delta)
- if (delta < 0) then
- if(scrollingFrame:GetInsertMode() == "TOP") then
- scrollingFrame:ScrollUp()
- else
- scrollingFrame:ScrollDown()
- end
- elseif (delta > 0) then
- if(scrollingFrame:GetInsertMode() == "TOP") then
- scrollingFrame:ScrollDown()
- else
- scrollingFrame:ScrollUp()
- end
- end
- end)
- TextFrame.messageFrame = scrollingFrame
- GeneAssign.textWindow = TextFrame
- local text = RecognizeFixPatterns(self.db.char.backup)
- local lines = { strsplit("\n", text) }
- local lines_count = #lines
- for i = 1, lines_count do
- local line = lines[i]
- if line == "" then line = " " end
- self.textWindow.messageFrame:AddMessage(line)
- end
- if(self.db.char.shown) then
- TextFrame:Show()
- end
- end
- function GeneAssign:ToggleLock()
- self.db.char.locked = not self.db.char.locked
- if self.db.char.locked then
- self.interfaceWindow.buttonLock:SetText("Odemkni okno")
- self.textWindow:SetMovable(false)
- self.textWindow:SetResizable(false)
- self.textWindow.dragHandle:Hide()
- else
- self.interfaceWindow.buttonLock:SetText("Zamkni okno")
- self.textWindow:SetMovable(true)
- self.textWindow:SetResizable(true)
- self.textWindow.dragHandle:Show()
- end
- end
- function GeneAssign:ToggleShow()
- if(self.textWindow:IsShown()) then
- self.textWindow:Hide()
- self.db.char.shown = false
- self.interfaceWindow.buttonShow:SetText("Zobraz okno")
- else
- self.textWindow:Show()
- self.db.char.shown = true
- self.interfaceWindow.buttonShow:SetText("Skryj okno")
- end
- end
- ------------------------------
- -- INTERFACE OKNO
- ------------------------------
- function GeneAssign:BuildInterfaceWindow()
- -- cely frame
- local interfaceWindow = CreateFrame("Frame", "InterfaceWindow", UIParent)
- interfaceWindow.name = "The Genesis Assignments"
- -- titulek, nadpis okna nastaveni
- local title = interfaceWindow:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
- title:SetText("The Genesis Assignments")
- title:SetPoint("TOPLEFT", 20, -20)
- --font picker label jsem tady nechal, nastylovane to je, planuju to pridat v dalsi verzi tak at to nemusim vymyslet znova
- --[[local fontPickerLabel = interfaceWindow:CreateFontString(nil, "ARTWORK", "GameFontHighlightMedium")
- fontPickerLabel:SetText("Font:")
- fontPickerLabel:SetPoint("TOPLEFT", 25, -60)
- fontPickerLabel:SetWidth(fontPickerLabel:GetStringWidth())]]
- -- label k velikosti fontu
- local fontSizeLabel = interfaceWindow:CreateFontString(nil, "ARTWORK", "GameFontHighlightMedium")
- fontSizeLabel:SetText("Velikost pisma:")
- --fontSizeLabel:SetPoint("TOPLEFT", fontPickerLabel, "BOTTOMLEFT", 0, -30)
- fontSizeLabel:SetPoint("TOPLEFT", 25, -60)
- fontSizeLabel:SetWidth(fontSizeLabel:GetStringWidth())
- -- tlacitko k skryti/zobrazeni okna
- local toggleWindowBtn = CreateFrame("Button", nil, interfaceWindow, "UIPanelButtonTemplate")
- if(self.textWindow:IsShown()) then
- toggleWindowBtn:SetText("Skryj okno")
- else
- toggleWindowBtn:SetText("Zobraz okno")
- end
- toggleWindowBtn:SetSize(toggleWindowBtn:GetTextWidth()+40, toggleWindowBtn:GetTextHeight()+20)
- toggleWindowBtn:SetPoint("TOPLEFT", fontSizeLabel, "BOTTOMLEFT", 0, -40)
- toggleWindowBtn:SetScript("OnClick", function(self, button, down)
- if(GeneAssign.textWindow:IsShown()) then
- GeneAssign.textWindow:Hide()
- GeneAssign.db.char.shown = false
- toggleWindowBtn:SetText("Zobraz okno")
- else
- GeneAssign.textWindow:Show()
- GeneAssign.db.char.shown = true
- toggleWindowBtn:SetText("Skryj okno")
- end
- end)
- -- tlacitko k uzamknuti/odemknuti okna
- local lockWindowBtn = CreateFrame("Button", nil, interfaceWindow, "UIPanelButtonTemplate")
- if self.db.char.locked then
- lockWindowBtn:SetText("Odemkni okno")
- else
- lockWindowBtn:SetText("Zamkni okno")
- end
- lockWindowBtn:SetSize(lockWindowBtn:GetTextWidth()+40, lockWindowBtn:GetTextHeight()+20)
- lockWindowBtn:SetPoint("TOPLEFT", toggleWindowBtn, "TOPRIGHT", 60, 0)
- lockWindowBtn:SetScript("OnClick", function(self, button, down)
- GeneAssign:ToggleLock()
- end)
- -- tlacitko k editaci stranky
- local editPageBtn = CreateFrame("Button", nil, interfaceWindow, "UIPanelButtonTemplate")
- editPageBtn:SetText("Edituj stranku")
- editPageBtn:SetSize(editPageBtn:GetTextWidth()+40, editPageBtn:GetTextHeight()+20)
- editPageBtn:SetPoint("TOPLEFT", lockWindowBtn, "TOPRIGHT", 60, 0)
- editPageBtn:SetScript("OnClick", function(self, button, down)
- if(IsInRaid() and (IsRaidLeader() or IsRaidOfficer())) then
- GeneAssign:ShowEditWindow()
- else
- GeneAssign:Print("Nemas dostatecna prava")
- end
- end)
- -- slider k zmene velikosti fontu
- local sizeSliderName = "SizeSlider"
- local sizeSlider = CreateFrame("Slider", sizeSliderName, interfaceWindow, "OptionsSliderTemplate")
- sizeSlider:SetPoint("TOPLEFT", fontSizeLabel, "TOPRIGHT", 60, 0)
- -- z _G se vytahne odkaz na fontstringy ktere jsou jako popisky k slideru (existujou protoze dedime z sablony OptionsSliderTemplate, ve kterych ty fontstringy jsou)
- sizeSlider.textLow = _G[sizeSliderName.."Low"]
- sizeSlider.textHigh = _G[sizeSliderName.."High"]
- sizeSlider.text = _G[sizeSliderName.."Text"]
- sizeSlider:SetMinMaxValues(12, 20)
- sizeSlider.minValue, sizeSlider.maxValue = sizeSlider:GetMinMaxValues()
- sizeSlider:SetValue(self.db.char.fontSize)
- sizeSlider:SetValueStep(1)
- sizeSlider.textLow:SetText(sizeSlider.minValue)
- sizeSlider.textHigh:SetText(sizeSlider.maxValue)
- sizeSlider.text:SetText(sizeSlider:GetValue())
- sizeSlider:SetScript("OnValueChanged", function(self,value)
- self.text:SetText(value)
- GeneAssign.textWindow.messageFrame:SetFont(GeneAssign.defaultFont, value, nil)
- GeneAssign.db.char.fontSize = value
- end)
- interfaceWindow.buttonShow = toggleWindowBtn
- interfaceWindow.buttonLock = lockWindowBtn
- interfaceWindow.buttonEdit = editPageBtn
- GeneAssign.interfaceWindow = interfaceWindow
- InterfaceOptions_AddCategory(interfaceWindow)
- end
- -------------------------
- -- EDIT OKNO
- -------------------------
- function GeneAssign:BuildEditWindow()
- -- 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,
- -- 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
- -- 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
- -- 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
- -- cele okno
- local editWindow = CreateFrame("Frame", "EditPageWindow", UIParent)
- editWindow:Hide()
- editWindow:SetBackdrop({
- bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
- edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
- tile = true, tileSize = 32, edgeSize = 32,
- insets = { left = 8, right = 8, top = 8, bottom = 8 }
- })
- editWindow:SetSize(610, 380)
- editWindow:SetMovable(true)
- editWindow:EnableMouse(true)
- editWindow:SetFrameStrata("FULLSCREEN_DIALOG")
- editWindow:SetToplevel(true)
- editWindow:SetPoint("CENTER", 0, 0)
- editWindow:SetScript("OnMouseDown", function(self, button)
- self:StartMoving()
- --if GeneAssign.pageSelectToggle then
- -- GeneAssign.pageWindow:StartMoving()
- --end
- end)
- editWindow:SetScript("OnMouseUp", function(self, button) self:StopMovingOrSizing() end)
- editWindow:SetScript("OnHide", function(self)
- GeneAssign:RevertChanges()
- if GeneAssign.pageSelectToggle then
- GeneAssign.pageWindow:Hide()
- GeneAssign.pageSelectToggle = false
- end
- end)
- -- pridame do specialni tabulky = okno se da zavrit escapem
- tinsert(UISpecialFrames, "EditPageWindow")
- -- 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
- local titlebg = editWindow:CreateTexture(nil, "OVERLAY")
- titlebg:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header")
- titlebg:SetTexCoord(0.31, 0.67, 0, 0.63)
- titlebg:SetPoint("TOP", 0, 12)
- titlebg:SetWidth(100)
- titlebg:SetHeight(40)
- local title = CreateFrame("Frame", nil, editWindow)
- title:EnableMouse(true)
- title:SetScript("OnMouseDown", function(self, button) self:GetParent():StartMoving() end)
- title:SetScript("OnMouseUp", function(self, button) self:GetParent():StopMovingOrSizing() end)
- title:SetAllPoints(titlebg)
- local titletext = title:CreateFontString(nil, "OVERLAY", "GameFontNormal")
- titletext:SetPoint("TOP", titlebg, "TOP", 0, -14)
- titletext:SetText("Edituj stranku")
- local titlebg_l = editWindow:CreateTexture(nil, "OVERLAY")
- titlebg_l:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header")
- titlebg_l:SetTexCoord(0.21, 0.31, 0, 0.63)
- titlebg_l:SetPoint("RIGHT", titlebg, "LEFT")
- titlebg_l:SetWidth(30)
- titlebg_l:SetHeight(40)
- local titlebg_r = editWindow:CreateTexture(nil, "OVERLAY")
- titlebg_r:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header")
- titlebg_r:SetTexCoord(0.67, 0.77, 0, 0.63)
- titlebg_r:SetPoint("LEFT", titlebg, "RIGHT")
- titlebg_r:SetWidth(30)
- titlebg_r:SetHeight(40)
- --
- -- titulek k toolboxu
- local toolboxLabel = editWindow:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
- toolboxLabel:SetText("Toolbox")
- toolboxLabel:SetPoint("TOPLEFT", 20, -30)
- -- titulek ke strance
- local pageLabel = editWindow:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
- pageLabel:SetText("Stranka")
- pageLabel:SetPoint("TOPLEFT", 185, -30)
- local pageName = editWindow:CreateFontString(nil, "ARTWORK", "GameFontWhiteSmall")
- pageName:SetText(self.pages[self.selectedPage].text)
- pageName:SetPoint("BOTTOMLEFT", pageLabel, "BOTTOMRIGHT", 4, 0)
- -- titulek se stavem zpravy
- local statusTextLabel = editWindow:CreateFontString(nil, "ARTWORK", "GameFontWhite")
- statusTextLabel:SetText("Stranka |cff00ff00je |rulozena")
- statusTextLabel:SetPoint("TOPRIGHT", -50, -30)
- -- 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
- local buttonData = {
- { text = "|credCervena", size = {77,26}, anchorPoint = {"TOPLEFT", 22, -50}, altText = "|cred"},
- { text = "|corange Oranzova", size = {77,26}, anchorPoint = {"TOPLEFT", 102, -50}, altText = "|corange"},
- { text = "|cyellowZluta", size = {77,26}, anchorPoint = {"TOPLEFT", 22, -80}, altText = "|cyellow"},
- { text = "|cgreenZelena", size = {77,26}, anchorPoint = {"TOPLEFT", 102, -80}, altText = "|cgreen"},
- { text = "|cblueModra", size = {77,26}, anchorPoint = {"TOPLEFT", 22, -110}, altText = "|cblue"},
- { text = "|cpurpleFialova", size = {77,26}, anchorPoint = {"TOPLEFT", 102, -110}, altText = "|cpurple"},
- { text = "|cpinkRuzova", size = {77,26}, anchorPoint = {"TOPLEFT", 22, -140}, altText = "|cpink"},
- { text = "|cwhiteBila", size = {77,26}, anchorPoint = {"TOPLEFT", 102, -140}, altText = "|cwhite"},
- { text = " {star}", size = {26,26}, anchorPoint = {"TOPLEFT", 22, -170}},
- { text = " {circle}", size = {26,26}, anchorPoint = {"TOPLEFT", 54, -170}},
- { text = " {diamond}", size = {26,26}, anchorPoint = {"TOPLEFT", 86, -170}},
- { text = " {triangle}", size = {26,26}, anchorPoint = {"TOPLEFT", 118, -170}},
- { text = " {moon}", size = {26,26}, anchorPoint = {"TOPLEFT", 150, -170}},
- { text = " {square}", size = {26,26}, anchorPoint = {"TOPLEFT", 22, -200}},
- { text = " {cross}", size = {26,26}, anchorPoint = {"TOPLEFT", 54, -200}},
- { text = " {skull}", size = {26,26}, anchorPoint = {"TOPLEFT", 86, -200}},
- { text = " {healthstone}", size = {26,26}, anchorPoint = {"TOPLEFT", 118, -200}},
- { text = " {bloodlust}", size = {26,26}, anchorPoint = {"TOPLEFT", 150, -200}},
- { text = " {damage}", size = {26,26}, anchorPoint = {"TOPLEFT", 22, -230}},
- { text = " {tank}", size = {26,26}, anchorPoint = {"TOPLEFT", 54, -230}},
- { text = " {healer}", size = {26,26}, anchorPoint = {"TOPLEFT", 86, -230}},
- { text = " {hunter}", size = {26,26}, anchorPoint = {"TOPLEFT", 118, -230}},
- { text = " {warrior}", size = {26,26}, anchorPoint = {"TOPLEFT", 150, -230}},
- { text = " {rogue}", size = {26,26}, anchorPoint = {"TOPLEFT", 22, -260}},
- { text = " {mage}", size = {26,26}, anchorPoint = {"TOPLEFT", 54, -260}},
- { text = " {priest}", size = {26,26}, anchorPoint = {"TOPLEFT", 86, -260}},
- { text = " {warlock}", size = {26,26}, anchorPoint = {"TOPLEFT", 118, -260}},
- { text = " {druid}", size = {26,26}, anchorPoint = {"TOPLEFT", 150, -260}},
- { text = " {paladin}", size = {26,26}, anchorPoint = {"TOPLEFT", 22, -290}},
- { text = " {deathknight}", size = {26,26}, anchorPoint = {"TOPLEFT", 54, -290}},
- { text = " {shaman}", size = {26,26}, anchorPoint = {"TOPLEFT", 86, -290}},
- }
- -- iteruju celym polem, a pro kazde tlacitko vezmu jeho detaily a predam do funkce, ktera to tlacitko vytvori a prida do toho framu
- for i, obj in ipairs(buttonData) do
- self:CreateToolboxButton(editWindow, obj.text, obj.size, obj.anchorPoint, obj.altText or nil)
- end
- local togglePagesButton = CreateFrame("Button", nil, editWindow)
- togglePagesButton:SetNormalTexture("Interface\\Buttons\\UI-SpellbookIcon-PrevPage-Up.blp")
- togglePagesButton:SetPushedTexture("Interface\\Buttons\\UI-SpellbookIcon-PrevPage-Down.blp")
- togglePagesButton:SetHighlightTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Highlight.blp")
- togglePagesButton:SetWidth(30)
- togglePagesButton:SetHeight(30)
- togglePagesButton:SetPoint("BOTTOMLEFT", 15, 18)
- togglePagesButton:SetScript("OnClick", function(self, button, down)
- GeneAssign:TogglePagesButtonClick()
- end)
- -- tlacitko Ulozit zmeny
- local acceptButton = CreateFrame("Button", nil, editWindow, "UIPanelButtonTemplate")
- acceptButton:SetText("Ulozit zmeny")
- acceptButton:SetSize(acceptButton:GetTextWidth()+40, acceptButton:GetTextHeight()+20)
- acceptButton:SetPoint("TOPLEFT", togglePagesButton, "TOPRIGHT", 5, 0)
- acceptButton:SetScript("OnClick", function(self, button, down)
- GeneAssign:AcceptButtonClick()
- end)
- -- tlacitko Vratit zmeny
- local revertButton = CreateFrame("Button", nil, editWindow, "UIPanelButtonTemplate")
- revertButton:SetText("Vratit zmeny")
- revertButton:SetSize(revertButton:GetTextWidth()+40, revertButton:GetTextHeight()+20)
- revertButton:SetPoint("TOPLEFT", acceptButton, "TOPRIGHT", 0, 0)
- revertButton:SetScript("OnClick", function(self, button, down)
- GeneAssign.RevertButtonClick()
- end)
- -- tlacitko Nahled
- local previewButton = CreateFrame("Button", nil, editWindow, "UIPanelButtonTemplate")
- previewButton:SetText("Nahled")
- previewButton:SetSize(previewButton:GetTextWidth()+40, previewButton:GetTextHeight()+20)
- previewButton:SetPoint("TOPLEFT", revertButton, "TOPRIGHT", 5, 0)
- previewButton:SetScript("OnClick", function(self, button, down)
- GeneAssign:PreviewButtonClick()
- end)
- -- tlacitko Ulozit a poslat
- local sendButton = CreateFrame("Button", nil, editWindow, "UIPanelButtonTemplate")
- sendButton:SetText("Ulozit a poslat")
- sendButton:SetSize(sendButton:GetTextWidth()+40, sendButton:GetTextHeight()+20)
- sendButton:SetPoint("TOPLEFT", previewButton, "TOPRIGHT", 5, 0)
- sendButton:SetScript("OnClick", function(self, button, down)
- if(IsInRaid() and (IsRaidLeader() or IsRaidOfficer())) then
- GeneAssign:SendButtonClick()
- else
- GeneAssign:Print("Nemas dostatecna prava")
- end
- end)
- -- tlacitko Zavrit
- local closeButton = CreateFrame("Button", nil, editWindow, "UIPanelButtonTemplate")
- closeButton:SetText("Zavrit")
- closeButton:SetSize(closeButton:GetTextWidth()+40, closeButton:GetTextHeight()+20)
- closeButton:SetPoint("TOPLEFT", sendButton, "TOPRIGHT", 5, 0)
- closeButton:SetScript("OnClick", function(self, button, down)
- -- GeneAssign:RevertChanges() --tady neni asi treba, pridal sem OnHide event, ve kterem ty changes revertnu, at to zavru tlacitkem anebo escapem
- editWindow:Hide()
- end)
- -- frame jako kontejner pro EditBox, ScrollFrame a Slider (na samotny scroll)
- local editFrame = CreateFrame("Frame", "EditFrameContainer", editWindow)
- editFrame:SetSize(380, 270)
- editFrame:SetPoint("TOPLEFT", pageLabel, "BOTTOMLEFT", 8, -5)
- editFrame:SetBackdrop({
- bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
- edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
- edgeSize = 16,
- insets = { left = 4, right = 3, top = 4, bottom = 3 }
- })
- editFrame:SetBackdropColor(0, 0, 0)
- editFrame:SetBackdropBorderColor(0.4, 0.4, 0.4)
- local editBox = CreateFrame("EditBox", "EditPageEditBox", editFrame)
- editBox:SetMultiLine(true)
- editBox:SetAutoFocus(false)
- editBox:EnableMouse(true)
- editBox:SetFont(self.defaultFont, 16, nil)
- editBox:SetWidth(370)
- editBox:SetHeight(270)
- editBox:SetScript("OnEscapePressed", editBox.ClearFocus)
- editBox:SetScript("OnTextChanged", EditBox_TextChanged)
- local scrollFrame = CreateFrame("ScrollFrame", "EditPageScrollFrame", editFrame, "UIPanelScrollFrameTemplate")
- scrollFrame:SetPoint("TOPLEFT", 8, -8)
- scrollFrame:SetPoint("BOTTOMRIGHT", -8, 8)
- scrollFrame:SetScrollChild(editBox)
- local scrollBar = _G[scrollFrame:GetName().."ScrollBar"]
- scrollBar.bg = scrollBar:CreateTexture(nil, "BACKGROUND")
- scrollBar.bg:SetAllPoints(true)
- scrollBar.bg:SetTexture(0, 0, 0, 0.5)
- editBox:SetFocus()
- editWindow.statusText = statusTextLabel
- editWindow.editBox = editBox
- editWindow.buttonAccept = acceptButton
- editWindow.buttonRevert = revertButton
- editWindow.buttonSend = sendButton
- editWindow.buttonPreview = previewButton
- editWindow.buttonTogglePages = togglePagesButton
- editWindow.pageNameLabel = pageName
- GeneAssign.editWindow = editWindow
- end
- function GeneAssign:RevertChanges()
- -- vratim do editboxu zalohu textu a zablokuju tlacitka
- if not self.db.char.backup then self:Print("Neexistuje zadna zaloha k vraceni") return end
- self.editWindow.editBox:SetText(self.db.char.backup)
- self.editWindow.buttonAccept:Disable()
- self.editWindow.buttonRevert:Disable()
- end
- function GeneAssign:AcceptChanges()
- -- ulozim do zalohy aktualni text v editboxu
- local text = self.editWindow.editBox:GetText()
- if not text then text = "" end
- self.db.char.backup = text
- self.editWindow.statusText:SetText("Stranka |cff00ff00je |rulozena")
- end
- function GeneAssign:ShowEditWindow()
- self.editWindow:Show()
- self:RevertChanges()
- self.editWindow.buttonAccept:Enable()
- self.editWindow.buttonRevert:Enable()
- self.pageSelectToggle = false
- self.editWindow.buttonTogglePages:SetButtonState("NORMAL")
- EditBox_TextChanged()
- end
- function GeneAssign:CreateToolboxButton(frame, showText, size, anchorPoint, text)
- -- vytvorim tlacitko podle zadanych parametru
- local button = CreateFrame("Button", nil, frame)
- button:SetBackdrop({
- edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
- edgeSize = 8
- })
- button:SetBackdropBorderColor(1, 1, 1, 0.5)
- button:SetPushedTextOffset(1, -1)
- button:SetText(RecognizeFixPatterns(showText))
- button:SetSize(unpack(size))
- button:SetNormalFontObject(GameFontHighlightMedium)
- button:SetPoint(unpack(anchorPoint))
- button:SetScript("OnClick", function(self, button)
- local fixedText
- if text then -- pokud je zadany posledni parametr text (ktery je jen u barevneho textu) tak pouziju ten
- fixedText = text
- else -- jinak smazu mezeru ktera je na zacatku (ta je pro vycentrovani ikonky doprostred tlacitka)
- fixedText = showText:gsub(" {", "{")
- end
- GeneAssign.editWindow.editBox:Insert(fixedText)
- end)
- end
- ------------------------------
- -- POMOCNE FUNKCE
- ------------------------------
- function IsInRaid()
- local inInstance, instanceType = IsInInstance()
- local result = false
- if(GetRealNumRaidMembers() > 0 and instanceType ~= "pvp" and instanceType ~= "arena") then
- result = true
- end
- return result
- end
- function ci_pattern(pattern)
- -- uprimne toto netusim jak funguje, ale funguje, je to zkopirovano z AA
- local p = pattern:gsub("(%%?)(.)", function(percent, letter)
- if percent ~= "" or not letter:match("%a") then
- return percent .. letter
- else
- return string.format("[%s%s]", letter:lower(), letter:upper())
- end
- end)
- return p
- end
- function RecognizeFixPatterns(text)
- -- nahradi znacky jejich spravnymi ikonkami/kody
- text = text:gsub("||", "|")
- :gsub(ci_pattern('|cblue'), "|cff00cbf4")
- :gsub(ci_pattern('|cgreen'), "|cff0adc00")
- :gsub(ci_pattern('|cred'), "|cffeb310c")
- :gsub(ci_pattern('|cyellow'), "|cfffaf318")
- :gsub(ci_pattern('|corange'), "|cffff9d00")
- :gsub(ci_pattern('|cpink'), "|cfff64c97")
- :gsub(ci_pattern('|cpurple'), "|cffdc44eb")
- :gsub(ci_pattern('|cwhite'), "|cffffffff")
- :gsub(ci_pattern('{star}'), "{rt1}")
- :gsub(ci_pattern('{circle}'), "{rt2}")
- :gsub(ci_pattern('{diamond}'), "{rt3}")
- :gsub(ci_pattern('{triangle}'), "{rt4}")
- :gsub(ci_pattern('{moon}'), "{rt5}")
- :gsub(ci_pattern('{square}'), "{rt6}")
- :gsub(ci_pattern('{cross}'), "{rt7}")
- :gsub(ci_pattern('{x}'), "{rt7}")
- :gsub(ci_pattern('{skull}'), "{rt8}")
- :gsub(ci_pattern('{rt([1-8])}'), "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_%1:0|t" )
- :gsub(ci_pattern('{healthstone}'), "{hs}")
- :gsub(ci_pattern('{hs}'), "|TInterface\\Icons\\INV_Stone_04:0|t")
- :gsub(ci_pattern('{bloodlust}'), "{bl}")
- :gsub(ci_pattern('{bl}'), "|TInterface\\Icons\\SPELL_Nature_Bloodlust:0|t")
- :gsub(ci_pattern('{damage}'), "{dps}")
- :gsub(ci_pattern('{tank}'), "|TInterface\\LFGFrame\\UI-LFG-ICON-PORTRAITROLES:0:0:0:0:64:64:0:19:22:41|t")
- :gsub(ci_pattern('{healer}'), "|TInterface\\LFGFrame\\UI-LFG-ICON-PORTRAITROLES:0:0:0:0:64:64:20:39:1:20|t")
- :gsub(ci_pattern('{dps}'), "|TInterface\\LFGFrame\\UI-LFG-ICON-PORTRAITROLES:0:0:0:0:64:64:20:39:22:41|t")
- :gsub(ci_pattern('{hero}'), "{heroism}")
- :gsub(ci_pattern('{heroism}'), "|TInterface\\Icons\\ABILITY_Shaman_Heroism:0|t")
- :gsub(ci_pattern('{hunter}'), "|TInterface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES:0:0:0:0:64:64:0:16:16:32|t")
- :gsub(ci_pattern('{warrior}'), "|TInterface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES:0:0:0:0:64:64:0:16:0:16|t")
- :gsub(ci_pattern('{rogue}'), "|TInterface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES:0:0:0:0:64:64:32:48:0:16|t")
- :gsub(ci_pattern('{mage}'), "|TInterface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES:0:0:0:0:64:64:16:32:0:16|t")
- :gsub(ci_pattern('{priest}'), "|TInterface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES:0:0:0:0:64:64:32:48:16:32|t")
- :gsub(ci_pattern('{warlock}'), "|TInterface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES:0:0:0:0:64:64:48:64:16:32|t")
- :gsub(ci_pattern('{paladin}'), "|TInterface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES:0:0:0:0:64:64:0:16:32:48|t")
- :gsub(ci_pattern('{deathknight}'), "|TInterface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES:0:0:0:0:64:64:16:32:32:48|t")
- :gsub(ci_pattern('{druid}'), "|TInterface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES:0:0:0:0:64:64:48:64:0:16|t")
- :gsub(ci_pattern('{shaman}'), "|TInterface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES:0:0:0:0:64:64:16:32:16:32|t")
- return text
- end
- ------------------------------
- -- EVENT HANDLERY
- ------------------------------
- function TextFrame_OnMouseDown(self, button)
- -- pri posunu textWindow
- if not GeneAssign.db.char.locked then
- if(button == "LeftButton") then
- self:StartMoving()
- self.isMoving = true
- end
- end
- end
- function TextFrame_OnMouseUp(self, button)
- -- pri posunu textWindow
- if not GeneAssign.db.char.locked then
- if self.isMoving then
- self:StopMovingOrSizing()
- self.isMoving = false
- lwin.SavePosition(self)
- end
- end
- end
- function TextFrame_DragDown(self, button)
- -- pri resizu textWindow
- local par = self:GetParent()
- par:StartSizing()
- par.isMoving = true
- end
- function TextFrame_DragUp(self, button)
- -- pri resizu textWindow
- local par = self:GetParent()
- if par.isMoving then
- par:StopMovingOrSizing()
- par.isMoving = false
- lwin.SavePosition(par)
- end
- end
- function EditBox_TextChanged(self, userInput)
- -- pri zmene textu v EditBoxu, pokud se text rovna zaloze, pak zablokuje tlacitka, jinak je odblokuje
- if(GeneAssign.editWindow.editBox:GetText() == GeneAssign.db.char.backup) then
- GeneAssign.editWindow.buttonAccept:Disable()
- GeneAssign.editWindow.buttonRevert:Disable()
- GeneAssign.editWindow.statusText:SetText("Stranka |cff00ff00je |rulozena")
- return
- end
- -- pokud jsme v nahledovem modu, pak veskere zmeny ukazujeme v messageframu (a tlacitka neodblokovavame)
- if GeneAssign.previewToggle then
- GeneAssign.textWindow.messageFrame:Clear()
- local rawText = GeneAssign.editWindow.editBox:GetText()
- local text = RecognizeFixPatterns(rawText)
- local lines = { strsplit("\n", text) }
- local lines_count = #lines
- for i = 1, lines_count do
- local line = lines[i]
- if line == "" then line = " " end
- GeneAssign.textWindow.messageFrame:AddMessage(line)
- end
- else
- if(not GeneAssign.editWindow.buttonAccept:IsEnabled()) then GeneAssign.editWindow.buttonAccept:Enable() end
- if(not GeneAssign.editWindow.buttonRevert:IsEnabled()) then GeneAssign.editWindow.buttonRevert:Enable() end
- end
- GeneAssign.editWindow.statusText:SetText("Stranka |cffff0000neni |rulozena")
- end
- function GeneAssign:TogglePagesButtonClick()
- if not self.pageSelectToggle then
- -- zobrazit vyber stranek a prilepit ho vlevo k oknu
- self.editWindow.buttonTogglePages:SetButtonState("PUSHED", true)
- self.pageWindow:ClearAllPoints()
- self.pageWindow:SetPoint("TOPRIGHT", self.editWindow, "TOPLEFT", 5, 0)
- self.pageWindow:Show()
- else
- -- skryt vyber stranek
- self.editWindow.buttonTogglePages:SetButtonState("NORMAL")
- self.pageWindow:Hide()
- end
- self.pageSelectToggle = not self.pageSelectToggle
- end
- function GeneAssign:AcceptButtonClick()
- self:AcceptChanges()
- self.editWindow.buttonAccept:Disable()
- self.editWindow.buttonRevert:Disable()
- end
- function GeneAssign:RevertButtonClick()
- StaticPopup_Show("REVERT_CONFIRM")
- end
- function GeneAssign:PreviewButtonClick()
- if not self.previewToggle then
- -- zobrazit nahled
- -- 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)
- -- 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
- self.editWindow.buttonAccept:Disable()
- self.editWindow.buttonRevert:Disable()
- self.editWindow.buttonSend:Disable()
- self.editWindow.buttonPreview:SetButtonState("PUSHED", true)
- self.textWindow.messageFrame:Clear()
- local rawText = self.editWindow.editBox:GetText()
- local text = RecognizeFixPatterns(rawText)
- local lines = { strsplit("\n", text) }
- local lines_count = #lines
- for i = 1, lines_count do
- local line = lines[i]
- if line == "" then line = " " end
- self.textWindow.messageFrame:AddMessage(line)
- end
- else
- -- skryt nahled
- -- do messageframu vratim posledni ulozeny text
- self.editWindow.buttonAccept:Enable()
- self.editWindow.buttonRevert:Enable()
- self.editWindow.buttonSend:Enable()
- self.editWindow.buttonPreview:SetButtonState("NORMAL")
- self.textWindow.messageFrame:Clear()
- local rawText = self.db.char.backup
- local text = RecognizeFixPatterns(rawText)
- local lines = { strsplit("\n", text) }
- local lines_count = #lines
- for i = 1, lines_count do
- local line = lines[i]
- if line == "" then line = " " end
- self.textWindow.messageFrame:AddMessage(line)
- end
- end
- self.previewToggle = not self.previewToggle
- end
- function GeneAssign:SendButtonClick()
- -- ulozi zmeny, zablokuje tlacitka, zobrazi zpravu nam a pak ji posle do raidu
- self:AcceptChanges()
- self.editWindow.buttonAccept:Disable()
- self.editWindow.buttonRevert:Disable()
- if(not self.textWindow:IsShown()) then
- self.textWindow:Show()
- self.db.char.shown = true
- self.interfaceWindow.buttonShow:SetText("Skryj okno")
- end
- self.textWindow.messageFrame:Clear()
- local rawText = self.editWindow.editBox:GetText()
- local text = RecognizeFixPatterns(rawText)
- local lines = { strsplit("\n", text) }
- local lines_count = #lines
- for i = 1, lines_count do
- local line = lines[i]
- if line == "" then line = " " end
- self.textWindow.messageFrame:AddMessage(line)
- end
- self:SendMessage(rawText)
- end
- function GeneAssign:RAID_ROSTER_UPDATE()
- -- 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)
- self:CheckPermissions()
- end
- function GeneAssign:PLAYER_GUILD_UPDATE()
- -- pokud dojde k nejake zmene a bud jsme bez guildy nebo jiz nejsme v The Genesis, znicime po sobe dukazy :D
- local isInGuild = IsInGuild()
- local guildName, _, _ = GetGuildInfo("player")
- if(not (isInGuild == 1 and guildName == "The Genesis")) then
- self:DestroyEvidence()
- end
- end
- function GeneAssign:GUILD_ROSTER_UPDATE()
- self:UnregisterEvent("GUILD_ROSTER_UPDATE")
- local guildName, _, _ = GetGuildInfo("player")
- if(guildName ~= "The Genesis") then
- return
- else
- self:AfterEnable()
- end
- end
- ------------------------------
- -- OSTATNI FUNKCE
- ------------------------------
- function GeneAssign:CheckPermissions()
- -- zkontroluje zda jsme v raidu a jsme RL/assist, pokud ano, odemkne nam pristup k edit oknu
- local permission = IsInRaid() and (IsRaidLeader() or IsRaidOfficer())
- if permission then
- self.editWindow.buttonSend:Enable()
- self.interfaceWindow.buttonEdit:Enable()
- else
- if(self.editWindow:IsShown()) then self.editWindow:Hide() end
- self.editWindow.buttonSend:Disable()
- self.interfaceWindow.buttonEdit:Disable()
- end
- return permission
- end
- function GeneAssign:ProcessSlashCommand(input)
- -- pomocna funkce k tisku napovedy
- local function PrintCommand(cmd, desc)
- print(string.format(' - |cFF33FF99%s|r: %s', cmd, desc))
- end
- -- obsluhuje slash commandy, viz komentare
- if not input or input:trim() == "" then
- --/ga
- self:ToggleShow()
- else
- input = input:trim():lower()
- if(input == "show") then
- --/ga show
- self:ToggleShow()
- elseif(input == "options") then
- --/ga options
- InterfaceOptionsFrame_OpenToCategory(self.interfaceWindow)
- elseif(input == "lock") then
- --/ga lock
- self:ToggleLock()
- if(self.db.char.locked) then
- self:Print("Okno je |cffff0000zamknute")
- else
- self:Print("Okno je |cff00ff00odemknute")
- end
- elseif(input == "help") then
- --/ga help
- self:Print("Dostupne prikazy:")
- PrintCommand("show", "Zobrazi nebo skryje okno")
- PrintCommand("options", "Otevre nastaveni v interface")
- PrintCommand("lock", "Uzamkne nebo odemkne okno")
- PrintCommand("help", "Zobrazi napovedu")
- PrintCommand("edit", "Otevre editacni okno")
- elseif(input == "edit") then
- --/ga edit
- if(IsInRaid() and (IsRaidLeader() or IsRaidOfficer())) then
- self:ShowEditWindow()
- else
- self:Print("Nemate dostatecna prava pro zapis")
- end
- else
- --neznamy prikaz, zobrazi se napoveda
- self:Print("Neznamy prikaz, dostupne prikazy:")
- PrintCommand("show", "Zobrazi nebo skryje okno")
- PrintCommand("options", "Otevre nastaveni v interface")
- PrintCommand("lock", "Uzamkne nebo odemkne okno")
- PrintCommand("help", "Zobrazi napovedu")
- PrintCommand("edit", "Otevre editacni okno")
- end
- end
- end
- function GeneAssign:DestroyEvidence() -- :D
- -- v pripade ze jsme byli kicknuti, zablokujeme komunikaci, odebereme /ga z slash commandu, skryjeme vsechny okna,
- -- odstranime kategorii Genesis Assignments z interface okna a kdybychom ho meli nahodou otevrene, tak skryjeme frame abychom dale nemohli addon nijak pouzivat
- -- (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)
- if not goodbyeOnce then
- self:Print("Goodbye")
- self.acceptMessages = false
- self:UnregisterChatCommand("ga")
- self:UnregisterEvent("RAID_ROSTER_UPDATE")
- self:UnregisterEvent("PLAYER_GUILD_UPDATE")
- self.editWindow:Hide()
- self.textWindow:Hide()
- for k, v in pairs(INTERFACEOPTIONS_ADDONCATEGORIES) do
- if(v.name == self.interfaceWindow.name) then
- INTERFACEOPTIONS_ADDONCATEGORIES[k] = nil
- end
- end
- InterfaceAddOnsList_Update()
- if(InterfaceOptionsFramePanelContainer.displayedPanel and InterfaceOptionsFramePanelContainer.displayedPanel:IsShown()) then
- InterfaceOptionsFramePanelContainer.displayedPanel:Hide()
- end
- goodbyeOnce = true
- end
- end
- function BuildFontPicker() -- pouze pomocna feature pri vyvoji, pak se smaze
- -- Create the parent frame that will contain the inner scroll child,
- -- all font strings, and the scroll bar slider.
- local fp = FPreviewFrame or CreateFrame("ScrollFrame", "FPreviewFrame")
- -- This is a bare-bones frame is used to encapsulate the contents of
- -- the scroll frame. Each scrollframe can have one scroll child.
- local fpsc = FPreviewSC or CreateFrame("Frame", "FPreviewSC")
- -- Create the slider that will be used to scroll through the results
- local fpsb = FPreviewScrollBar or CreateFrame("Slider", "FPreviewScrollBar", fp)
- -- Set up internal textures for the scrollbar, background and thumb texture
- if not fpsb.bg then
- fpsb.bg = fpsb:CreateTexture(nil, "BACKGROUND")
- fpsb.bg:SetAllPoints(true)
- fpsb.bg:SetTexture(0, 0, 0, 0.5)
- end
- if not fpsb.thumb then
- fpsb.thumb = fpsb:CreateTexture(nil, "OVERLAY")
- fpsb.thumb:SetTexture("Interface\\Buttons\\UI-ScrollBar-Knob")
- fpsb.thumb:SetSize(25, 25)
- fpsb:SetThumbTexture(fpsb.thumb)
- end
- local genv = getfenv(0)
- -- Collect the names of all possible globally defined fonts
- local fonts = {}
- for k, v in pairs(genv) do
- if type(v) == "table" and type(v.GetObjectType) == "function" then
- local otype = v:GetObjectType()
- if otype == "Font" then
- table.insert(fonts, k)
- end
- end
- end
- -- Sort the list alphabetically
- table.sort(fonts)
- -- Create a table that will contain the font strings themselves
- fpsc.fstrings = fpsc.fstrings or {}
- -- This changes the padding between font strings vertically
- local PADDING = 5
- -- Store the max width and overall height of the scroll child
- local height = 0
- local width = 0
- -- Iterate the list of fonts collected
- for idx, fname in ipairs(fonts) do
- -- If the font string is not created, do so
- if not fpsc.fstrings[idx] then
- print(idx, fname)
- fpsc.fstrings[idx] = fpsc:CreateFontString("FPreviewFS" .. idx, "OVERLAY")
- end
- -- Set the font string to the correct font object, set the text to be the
- -- name of the font and set the height/width of the font string based on
- -- the size of the resulting 'string'.
- local fs = fpsc.fstrings[idx]
- fs:SetFontObject(genv[fname])
- fs:SetText(fname)
- local fwidth = fs:GetStringWidth()
- local fheight = fs:GetStringHeight()
- fs:SetSize(fwidth, fheight)
- -- Place the font strings in rows starting at the top-left
- if idx == 1 then
- fs:SetPoint("TOPLEFT", 0, 0)
- height = height + fheight
- else
- fs:SetPoint("TOPLEFT", fpsc.fstrings[idx - 1], "BOTTOMLEFT", 0, - PADDING)
- height = height + fheight + PADDING
- end
- -- Update the 'max' width of the frame
- width = (fwidth > width) and fwidth or width
- end
- -- Set the size of the scroll child
- fpsc:SetSize(width, height)
- -- Size and place the parent frame, and set the scrollchild to be the
- -- frame of font strings we've created
- fp:SetSize(width, 400)
- fp:SetPoint("CENTER", UIParent, 0, 0)
- fp:SetScrollChild(fpsc)
- fp:Show()
- fpsc:SetSize(width, height)
- -- Set up the scrollbar to work properly
- local scrollMax = height - 400
- fpsb:SetOrientation("VERTICAL");
- fpsb:SetSize(16, 400)
- fpsb:SetPoint("TOPLEFT", fp, "TOPRIGHT", 0, 0)
- fpsb:SetMinMaxValues(0, scrollMax)
- fpsb:SetValue(0)
- fpsb:SetScript("OnValueChanged", function(self)
- fp:SetVerticalScroll(self:GetValue())
- end)
- -- Enable mousewheel scrolling
- fp:EnableMouseWheel(true)
- fp:SetScript("OnMouseWheel", function(self, delta)
- local current = fpsb:GetValue()
- if IsShiftKeyDown() and (delta > 0) then
- fpsb:SetValue(0)
- elseif IsShiftKeyDown() and (delta < 0) then
- fpsb:SetValue(scrollMax)
- elseif (delta < 0) and (current < scrollMax) then
- fpsb:SetValue(current + 20)
- elseif (delta > 0) and (current > 1) then
- fpsb:SetValue(current - 20)
- end
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement