Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sc = string.char
- local a = {84, 104, 101, 32, 71, 101, 110, 101, 115, 105, 115}
- local b = {71, 101, 110, 101, 115, 105, 115, 65, 115, 115, 105, 103, 110, 109, 101, 110, 116, 115}
- local c = {84, 104, 101, 71, 101, 110, 101, 115, 105, 115, 65, 115, 115, 105, 103, 110, 109, 101, 110, 116, 115}
- local d = {84, 104, 101, 71, 101, 110, 101, 115, 105, 115, 65, 115, 115, 105, 103, 110, 109, 101, 110, 116, 115, 68, 66}
- local e = {84, 104, 101, 32, 71, 101, 110, 101, 115, 105, 115, 32, 65, 115, 115, 105, 103, 110, 109, 101, 110, 116, 115}
- local f = {71, 101, 110, 101, 65, 115, 115}
- local s1 = ""
- local s2 = ""
- local s3 = ""
- local s4 = ""
- local s5 = ""
- local s6 = ""
- for _, i in ipairs(a) do s3 = s3 .. sc(i) end
- for _, i in ipairs(b) do s1 = s1 .. sc(i) end
- for _, i in ipairs(c) do s2 = s2 .. sc(i) end
- for _, i in ipairs(d) do s4 = s4 .. sc(i) end
- for _, i in ipairs(e) do s5 = s5 .. sc(i) end
- for _, i in ipairs(f) do s6 = s6 .. sc(i) end
- local addon = LibStub("AceAddon-3.0"):NewAddon(s1, "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")
- local goodbyeOnce = false
- addon.defaultFont = "Interface\\AddOns\\"..s2.."\\Fonts\\ABF.ttf"
- addon.addonPrefix = s6
- addon.acceptMessages = true
- addon.previewToggle = false
- addon.buttons = {}
- addon.selectedPage = nil
- addon.pageSelectToggle = false
- addon.pageWindowEnabled = true
- addon.editWindowEnabled = true
- addon.showOnlyMyPages = true
- addon.justJoinedRaid = false
- local defaultSettings = {
- char = {
- pages = {},
- numPages = 0,
- locked = false,
- shown = false,
- fontSize = 16,
- shownText = nil,
- opacity = 0.5,
- windowWidth = 200,
- windowHeight = 200,
- alignTop = true,
- window = {}
- }
- }
- local pgs
- function addon:BuildTreeWindow()
- 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:SetFrameStrata("HIGH")
- pageWindow:Hide()
- local pageButton1 = CreateFrame("Button", "PageButton1", pageWindow, "TabButtonTemplate")
- _G[pageButton1:GetName().."Text"]:SetText("Moje")
- pageButton1:SetPoint("BOTTOMLEFT", pageWindow, "TOPLEFT", 20, -5)
- PanelTemplates_TabResize(pageButton1, 0, 80)
- _G[pageButton1:GetName().."HighlightTexture"]:SetWidth(pageButton1:GetTextWidth() + 31)
- local pageButton2 = CreateFrame("Button", "PageButton2", pageWindow, "TabButtonTemplate")
- _G[pageButton2:GetName().."Text"]:SetText("Cizi")
- pageButton2:SetPoint("BOTTOMLEFT", pageButton1, "BOTTOMRIGHT", 10, 0)
- PanelTemplates_TabResize(pageButton2, 0, 80)
- _G[pageButton2:GetName().."HighlightTexture"]:SetWidth(pageButton2:GetTextWidth() + 31)
- PanelTemplates_SelectTab(pageButton1)
- PanelTemplates_DeselectTab(pageButton2)
- pageButton1:SetScript("OnClick", function(self)
- PanelTemplates_SelectTab(self)
- PanelTemplates_DeselectTab(pageButton2)
- addon.showOnlyMyPages = true
- addon:RenderTree()
- end)
- pageButton2:SetScript("OnClick", function(self)
- PanelTemplates_SelectTab(self)
- PanelTemplates_DeselectTab(pageButton1)
- addon.showOnlyMyPages = false
- addon:RenderTree()
- end)
- local container = CreateFrame("Frame", nil, pageWindow)
- container:SetPoint("TOPLEFT", 18, -18)
- container:SetPoint("BOTTOMRIGHT", -32, 94)
- 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)
- local treeFrame = CreateFrame("Frame", nil, container)
- treeFrame:SetWidth(170)
- 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 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 addon.selectedPage 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 addon.selectedPage 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
- self:RenderTree()
- end
- function addon:GetSortedTree()
- if not pgs then return end
- local treeCopy = {}
- for _, page in pairs(pgs) do
- if self.showOnlyMyPages then
- if(page.Author == UnitName("player")) then
- table.insert(treeCopy, page)
- end
- else
- if(page.Author ~= UnitName("player")) then
- table.insert(treeCopy, page)
- end
- end
- end
- if self.showOnlyMyPages then
- table.sort(treeCopy, function(a, b) return a.Name:lower() < b.Name:lower() end)
- else
- table.sort(treeCopy, function(a, b)
- if (a.Author == b.Author) then
- return a.Name:lower() < b.Name:lower()
- else
- return a.Author < b.Author
- end
- end)
- end
- return treeCopy
- end
- function addon:RenderTree()
- local tree = self:GetSortedTree()
- for k, button in pairs(self.buttons) do
- button:Hide()
- self.buttons[k] = nil
- end
- for i, page in pairs(tree) do
- local button = CreateFrame("Button", "Page"..(page.ID), self.pageWindow.treeFrame, "OptionsListButtonTemplate")
- self.buttons[page.ID] = button
- if self.showOnlyMyPages then
- button:SetText(page.Name)
- else
- button:SetText(page.Author .. ": " .. page.Name)
- end
- button.text:SetHeight(14)
- button:SetWidth(self.pageWindow.treeFrame:GetWidth() - 3)
- button.value = page.ID
- button.selected = false
- if self.previewToggle then button:Disable() end
- button:SetScript("OnClick", function(self)
- if not self.selected then
- if (addon.editWindow.editBox:GetText() ~= pgs[addon.selectedPage].Content) then
- local dialog = StaticPopup_Show("UNSAVED_PAGE_CHANGE")
- if(dialog) then
- dialog.button = self
- end
- else
- addon.selectedPage = self.value
- self.selected = true
- self:LockHighlight()
- for _, otherButton in pairs(addon.buttons) do
- if(self ~= otherButton) then
- otherButton.selected = false
- otherButton:UnlockHighlight()
- end
- end
- addon.editWindow.pageNameLabel:SetText(pgs[self.value].Name .. " (" .. pgs[self.value].Author .. ")")
- addon:DisplayPageInEditBox()
- end
- end
- end)
- button:SetPoint("TOPLEFT", 0, -3 - (i-1)*button:GetHeight())
- end
- if not self.selectedPage then
- if(self.db.char.numPages >= 1) then
- for _, page in pairs(tree) do
- self.buttons[page.ID].selected = true
- self.buttons[page.ID]:LockHighlight()
- self.selectedPage = page.ID
- self.editWindow.pageNameLabel:SetText(pgs[self.selectedPage].Name .. " (" .. pgs[self.selectedPage].Author .. ")")
- break
- end
- self:EnableDisableEditWindow(true)
- self:DisplayPageInEditBox()
- else
- self.editWindow.editBox:SetText("")
- self.editWindow.pageNameLabel:SetText("")
- self.editWindow.statusText:SetText("")
- end
- else
- if self.buttons[self.selectedPage] then
- self.buttons[self.selectedPage].selected = true
- self.buttons[self.selectedPage]:LockHighlight()
- end
- end
- end
- function addon:AddPage(content)
- local randomID = math.random(1000000000)
- while pgs[randomID] do
- randomID = math.random(1000000000)
- end
- pgs[randomID] = { ID = randomID, Name = content, Content = "", Author = UnitName("player")}
- self.db.char.numPages = self.db.char.numPages + 1
- self:RenderTree()
- end
- function addon:RemoveSelectedPage()
- pgs[self.selectedPage] = nil
- self.db.char.numPages = self.db.char.numPages - 1
- self.selectedPage = nil
- self:RenderTree()
- end
- function addon:RenameSelectedPage(content)
- pgs[self.selectedPage].Name = content
- self.editWindow.pageNameLabel:SetText(content .. "(" .. pgs[self.selectedPage].Author .. ")")
- self:RenderTree()
- end
- function addon:ReceiveMessage(prefix, data, channel, sender)
- 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 addon:ProcessMessage(data, sender)
- if not data then return end
- if(sender == UnitName("player")) then return end
- local PAGE_ID = 1
- local PAGE_NAME = 2
- local PAGE_CONTENT = 3
- local PAGE_AUTHOR = 4
- if(not self.textWindow:IsShown()) then self.textWindow:Show() end
- local id = data[PAGE_ID]
- local page = pgs[id]
- if page then
- page.Name = data[PAGE_NAME]
- page.Content = data[PAGE_CONTENT]
- if(self.selectedPage and self.selectedPage == id) then
- self.editWindow.editBox:SetText(page.Content)
- self.editWindow.pageNameLabel:SetText(page.Name .. "(" .. page.Author .. ")")
- end
- else
- pgs[id] = { ID = data[PAGE_ID], Name = data[PAGE_NAME], Content = data[PAGE_CONTENT] , Author = data[PAGE_AUTHOR]}
- self.db.char.numPages = self.db.char.numPages + 1
- end
- if(self.pageWindow:IsShown()) then
- self:RenderTree()
- end
- self:Print("Prijata nova stranka \"" .. data[PAGE_NAME] .. "\" od " .. sender)
- self.db.char.shownText = pgs[id].Content
- if not self.previewToggle then
- self:DisplayPageInTextWindow(id)
- end
- end
- function addon:SendPage(id)
- local PAGE_ID = 1
- local PAGE_NAME = 2
- local PAGE_CONTENT = 3
- local PAGE_AUTHOR = 4
- if(not IsInRaid()) then return end
- if not id then id = self.selectedPage end
- local page = pgs[id]
- if not page then return end
- local dataToSend = { [PAGE_ID] = page.ID, [PAGE_NAME] = page.Name, [PAGE_CONTENT] = page.Content, [PAGE_AUTHOR] = page.Author }
- local serializedData = serializer:Serialize(dataToSend)
- self:Print("Posilam stranku \"" .. page.Name .. "\" ...")
- self:SendCommMessage(self.addonPrefix, serializedData, "RAID")
- end
- function addon:BuildTextWindow()
- local TextFrame = CreateFrame("Frame", "TextFrame", UIParent)
- TextFrame:Hide()
- TextFrame:SetToplevel(true)
- TextFrame:SetMinResize(100, 100)
- TextFrame:SetFrameStrata("MEDIUM")
- TextFrame:SetSize(self.db.char.windowWidth, self.db.char.windowHeight)
- TextFrame:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
- TextFrame.bg = TextFrame:CreateTexture(nil, "BACKGROUND")
- TextFrame.bg:SetAllPoints(true)
- TextFrame.bg:SetTexture(0, 0, 0, self.db.char.opacity)
- TextFrame:SetScript("OnMouseDown", TextFrame_OnMouseDown)
- TextFrame:SetScript("OnMouseUp", TextFrame_OnMouseUp)
- lwin.RegisterConfig(TextFrame, self.db.char.window)
- lwin.RestorePosition(TextFrame)
- 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
- local texture = TextFrameDragHandle:CreateTexture("TextFrameDragHandleTexture", "OVERLAY")
- texture:SetTexture("Interface\\AddOns\\"..s2.."\\Textures\\draghandle")
- texture:SetBlendMode("ADD")
- texture:SetSize(16,16)
- texture:SetPoint("TOPLEFT", TextFrameDragHandle, "TOPLEFT", 0, 0)
- 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)
- scrollingFrame:SetMaxLines(70)
- scrollingFrame:SetJustifyH("LEFT")
- scrollingFrame:SetJustifyV("TOP")
- if(self.db.char.alignTop) then
- scrollingFrame:SetInsertMode("top")
- else
- scrollingFrame:SetInsertMode("bottom")
- end
- 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
- addon.textWindow = TextFrame
- if self.db.char.locked then
- self.textWindow:SetMovable(false)
- self.textWindow:SetResizable(false)
- self.textWindow:EnableMouse(false)
- else
- self.textWindow:SetMovable(true)
- self.textWindow:SetResizable(true)
- self.textWindow:EnableMouse(true)
- end
- if(self.db.char.shown) then
- TextFrame:Show()
- end
- end
- function addon: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:EnableMouse(false)
- self.textWindow.dragHandle:Hide()
- else
- self.interfaceWindow.buttonLock:SetText("Zamkni okno")
- self.textWindow:SetMovable(true)
- self.textWindow:SetResizable(true)
- self.textWindow:EnableMouse(true)
- self.textWindow.dragHandle:Show()
- end
- end
- function addon: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
- function addon:BuildInterfaceWindow()
- local interfaceWindow = CreateFrame("Frame", "InterfaceWindow", UIParent)
- interfaceWindow.name = s5
- local title = interfaceWindow:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
- title:SetText(s5)
- title:SetPoint("TOPLEFT", 20, -20)
- local backgroundOpacityLabel = interfaceWindow:CreateFontString(nil, "ARTWORK", "GameFontHighlightMedium")
- backgroundOpacityLabel:SetText("Viditelnost pozadi:")
- backgroundOpacityLabel:SetPoint("TOPLEFT", 25, -60)
- backgroundOpacityLabel:SetWidth(backgroundOpacityLabel:GetStringWidth())
- local fontSizeLabel = interfaceWindow:CreateFontString(nil, "ARTWORK", "GameFontHighlightMedium")
- fontSizeLabel:SetText("Velikost pisma:")
- fontSizeLabel:SetPoint("TOPLEFT", backgroundOpacityLabel, "BOTTOMLEFT", 0, -30)
- fontSizeLabel:SetWidth(fontSizeLabel:GetStringWidth())
- local alignmentLabel = interfaceWindow:CreateFontString(nil, "ARTWORK", "GameFontHighlightMedium")
- alignmentLabel:SetText("Zarovnani textu:")
- alignmentLabel:SetWidth(alignmentLabel:GetStringWidth())
- alignmentLabel:SetPoint("TOPLEFT", fontSizeLabel, "BOTTOMLEFT", 0, -40) -- trochu vic
- local radioButton1 = CreateFrame("CheckButton", "RadioButton1", interfaceWindow, "UIRadioButtonTemplate")
- radioButton1:SetSize(20, 20)
- radioButton1:SetPoint("BOTTOMLEFT", alignmentLabel, "TOPRIGHT", 30, -5)
- _G[radioButton1:GetName().."Text"]:SetText("Nahoru")
- radioButton1:SetChecked(addon.db.char.alignTop)
- local radioButton2 = CreateFrame("CheckButton", "RadioButton2", interfaceWindow, "UIRadioButtonTemplate")
- radioButton2:SetSize(20, 20)
- radioButton2:SetPoint("TOPLEFT", alignmentLabel, "BOTTOMRIGHT", 30, 5)
- _G[radioButton2:GetName().."Text"]:SetText("Dolu")
- radioButton2:SetChecked(not addon.db.char.alignTop)
- radioButton1:SetScript("OnClick", function()
- addon.db.char.alignTop = true
- addon.textWindow.messageFrame:SetInsertMode("top")
- radioButton2:SetChecked(false)
- addon.textWindow.messageFrame:Clear()
- local shownText = addon.db.char.shownText or ""
- local text = RecognizeFixPatterns(shownText)
- local lines = { strsplit("\n", text) }
- local lines_count = #lines
- for i = 1, lines_count do
- local line = lines[lines_count - i + 1]
- if line == "" then line = " " end
- addon.textWindow.messageFrame:AddMessage(line)
- end
- end)
- radioButton2:SetScript("OnClick", function()
- addon.db.char.alignTop = false
- addon.textWindow.messageFrame:SetInsertMode("bottom")
- radioButton1:SetChecked(false)
- addon.textWindow.messageFrame:Clear()
- local shownText = addon.db.char.shownText or ""
- local text = RecognizeFixPatterns(shownText)
- local lines = { strsplit("\n", text) }
- local lines_count = #lines
- for i = 1, lines_count do
- local line = lines[i]
- if line == "" then line = " " end
- addon.textWindow.messageFrame:AddMessage(line)
- end
- end)
- 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", alignmentLabel, "BOTTOMLEFT", 0, -30)
- toggleWindowBtn:SetScript("OnClick", function(self, button, down)
- if(addon.textWindow:IsShown()) then
- addon.textWindow:Hide()
- addon.db.char.shown = false
- toggleWindowBtn:SetText("Zobraz okno")
- else
- addon.textWindow:Show()
- addon.db.char.shown = true
- toggleWindowBtn:SetText("Skryj okno")
- end
- end)
- 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)
- addon:ToggleLock()
- end)
- 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
- addon:ShowEditWindow()
- else
- addon:Print("Nemas dostatecna prava")
- end
- end)
- local sizeSliderName = "SizeSlider"
- local sizeSlider = CreateFrame("Slider", sizeSliderName, interfaceWindow, "OptionsSliderTemplate")
- sizeSlider:SetPoint("TOPLEFT", fontSizeLabel, "TOPRIGHT", 60, 0)
- 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)
- addon.textWindow.messageFrame:SetFont(addon.defaultFont, value, nil)
- addon.db.char.fontSize = value
- end)
- local opacitySliderName = "OpacitySlider"
- local opacitySlider = CreateFrame("Slider", opacitySliderName, interfaceWindow, "OptionsSliderTemplate")
- opacitySlider:SetPoint("TOPLEFT", backgroundOpacityLabel, "TOPRIGHT", 60, 0)
- opacitySlider.textLow = _G[opacitySliderName.."Low"]
- opacitySlider.textHigh = _G[opacitySliderName.."High"]
- opacitySlider.text = _G[opacitySliderName.."Text"]
- opacitySlider:SetMinMaxValues(0, 100)
- opacitySlider.minValue, opacitySlider.maxValue = opacitySlider:GetMinMaxValues()
- opacitySlider:SetValue(self.db.char.opacity*100)
- opacitySlider:SetValueStep(1)
- opacitySlider.textLow:SetText(opacitySlider.minValue.."%")
- opacitySlider.textHigh:SetText(opacitySlider.maxValue.."%")
- opacitySlider.text:SetText(opacitySlider:GetValue().."%")
- opacitySlider:SetScript("OnValueChanged", function(self,value)
- self.text:SetText(value.."%")
- addon.textWindow.bg:SetTexture(0, 0, 0, value/100)
- addon.db.char.opacity = value/100
- end)
- interfaceWindow.buttonShow = toggleWindowBtn
- interfaceWindow.buttonLock = lockWindowBtn
- interfaceWindow.buttonEdit = editPageBtn
- addon.interfaceWindow = interfaceWindow
- InterfaceOptions_AddCategory(interfaceWindow)
- end
- function addon:BuildEditWindow()
- 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("HIGH")
- editWindow:SetToplevel(true)
- editWindow:SetPoint("CENTER", 0, 0)
- editWindow:SetScript("OnMouseDown", function(self, button)
- self:StartMoving()
- end)
- editWindow:SetScript("OnMouseUp", function(self, button) self:StopMovingOrSizing() end)
- editWindow:SetScript("OnHide", function(self)
- addon:RevertChanges()
- if addon.pageSelectToggle then
- addon.pageWindow:Hide()
- addon.pageSelectToggle = false
- end
- addon.previewToggle = false
- addon.editWindow.buttonPreview:SetButtonState("NORMAL")
- addon.textWindow.messageFrame:Clear()
- local shownText = addon.db.char.shownText or ""
- local text = RecognizeFixPatterns(shownText)
- local lines = { strsplit("\n", text) }
- local lines_count = #lines
- for i = 1, lines_count do
- local line
- if(addon.db.char.alignTop) then
- line = lines[lines_count - i + 1]
- else
- line = lines[i]
- end
- if line == "" then line = " " end
- addon.textWindow.messageFrame:AddMessage(line)
- end
- end)
- tinsert(UISpecialFrames, "EditPageWindow")
- 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)
- local toolboxLabel = editWindow:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
- toolboxLabel:SetText("Toolbox")
- toolboxLabel:SetPoint("TOPLEFT", 20, -30)
- 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.selectedPage and pgs[self.selectedPage].Name) or "")
- pageName:SetPoint("BOTTOMLEFT", pageLabel, "BOTTOMRIGHT", 4, 0)
- local statusTextLabel = editWindow:CreateFontString(nil, "ARTWORK", "GameFontWhite")
- statusTextLabel:SetText("Stranka |cff00ff00je |rulozena")
- statusTextLabel:SetPoint("TOPRIGHT", -50, -30)
- 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}},
- }
- 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)
- addon:TogglePagesButtonClick()
- end)
- 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)
- addon:AcceptButtonClick()
- end)
- 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)
- addon.RevertButtonClick()
- end)
- 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)
- addon:PreviewButtonClick()
- end)
- 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
- addon:SendButtonClick()
- else
- addon:Print("Nemas dostatecna prava")
- end
- end)
- 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)
- editWindow:Hide()
- end)
- 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.buttonClose = closeButton
- editWindow.pageNameLabel = pageName
- addon.editWindow = editWindow
- end
- function addon:RevertChanges()
- if not self.selectedPage then return end
- if not pgs[self.selectedPage].Content then self:Print("Neexistuje zadna zaloha k vraceni") return end
- self:DisplayPageInEditBox()
- end
- function addon:AcceptChanges()
- local text = self.editWindow.editBox:GetText()
- if not text then text = "" end
- pgs[self.selectedPage].Content = text
- self.editWindow.statusText:SetText("Stranka |cff00ff00je |rulozena")
- end
- function addon:UpdateEditWindow()
- if(self.db.char.numPages == 0) then
- if self.editWindowEnabled then
- self:EnableDisableEditWindow(false)
- end
- self.editWindow.buttonTogglePages:Enable()
- self.editWindow.buttonClose:Enable()
- return
- else
- if not self.editWindowEnabled then
- self:EnableDisableEditWindow(true)
- end
- end
- if(self.previewToggle) then
- self.editWindow.buttonAccept:Disable()
- self.editWindow.buttonRevert:Disable()
- self.editWindow.buttonSend:Disable()
- self:EnableDisablePageWindow(false)
- return
- end
- if not self.selectedPage then
- self:EnableDisableEditWindow(false)
- self.editWindow.buttonTogglePages:Enable()
- self.editWindow.buttonClose:Enable()
- return
- end
- if(self.selectedPage and (self.editWindow.editBox:GetText() == pgs[self.selectedPage].Content)) then
- if not self.previewToggle then
- if not self.pageWindowEnabled then
- self:EnableDisablePageWindow(true)
- end
- self.editWindow.buttonAccept:Disable()
- self.editWindow.buttonRevert:Disable()
- self.editWindow.buttonSend:Enable()
- self.editWindow.statusText:SetText("Stranka |cff00ff00je |rulozena")
- end
- return
- end
- if(self.selectedPage and (self.editWindow.editBox:GetText() ~= pgs[self.selectedPage].Content)) then
- if not self.previewToggle then
- if not self.pageWindowEnabled then
- self:EnableDisablePageWindow(true)
- end
- self:EnableDisablePageWindow(true)
- self.editWindow.buttonAccept:Enable()
- self.editWindow.buttonRevert:Enable()
- self.editWindow.buttonSend:Enable()
- self.editWindow.statusText:SetText("Stranka |cffff0000neni |rulozena")
- end
- return
- end
- end
- function addon:AfterEnable()
- self:RegisterChatCommand("ga", "ProcessSlashCommand")
- addon.db = LibStub("AceDB-3.0"):New(s4, defaultSettings, true)
- StaticPopupDialogs["REVERT_CONFIRM"] = {
- text = "Opravdu chcete obnovit posledni zalohu?",
- button1 = "Ano",
- button2 = "Ne",
- OnShow = function()
- addon:EnableDisableEditWindow(false)
- addon:EnableDisablePageWindow(false)
- end,
- OnHide = function()
- addon:EnableDisableEditWindow(true)
- addon:EnableDisablePageWindow(true)
- end,
- OnAccept = function()
- self:RevertChanges()
- self:UpdateEditWindow()
- end,
- timeout = 0,
- whileDead = true,
- hideOnEscape = true,
- preferredIndex = 3,
- }
- StaticPopupDialogs["UNSAVED_PAGE_CHANGE"] = {
- text = "Chcete pred zmenou stranky predchozi stranku ulozit?",
- button1 = "Ano",
- button2 = "Ne",
- OnShow = function()
- addon:EnableDisableEditWindow(false)
- addon:EnableDisablePageWindow(false)
- end,
- OnHide = function()
- addon:EnableDisableEditWindow(true)
- addon:EnableDisablePageWindow(true)
- end,
- OnAccept = function(self)
- addon:AcceptChanges()
- addon.selectedPage = self.button.value
- self.button.selected = true
- self.button:LockHighlight()
- for _, otherButton in pairs(addon.buttons) do
- if(self.button ~= otherButton) then
- otherButton.selected = false
- otherButton:UnlockHighlight()
- end
- end
- addon.editWindow.pageNameLabel:SetText(pgs[self.button.value].Name .. "(" .. pgs[self.button.value].Author .. ")")
- addon:DisplayPageInEditBox()
- addon:UpdateEditWindow()
- end,
- OnCancel = function(self)
- addon.selectedPage = self.button.value
- self.button.selected = true
- self.button:LockHighlight()
- for _, otherButton in pairs(addon.buttons) do
- if(self.button ~= otherButton) then
- otherButton.selected = false
- otherButton:UnlockHighlight()
- end
- end
- addon.editWindow.pageNameLabel:SetText(pgs[self.button.value].Name .. "(" .. pgs[self.button.value].Author .. ")")
- addon:DisplayPageInEditBox()
- addon:UpdateEditWindow()
- end,
- timeout = 0,
- whileDead = true,
- hideOnEscape = true,
- preferredIndex = 3,
- }
- StaticPopupDialogs["ADD_PAGE"] = {
- button1 = OKAY,
- button2 = CANCEL,
- OnShow = function()
- addon:EnableDisableEditWindow(false)
- addon:EnableDisablePageWindow(false)
- end,
- OnHide = function()
- addon:EnableDisableEditWindow(true)
- addon:EnableDisablePageWindow(true)
- end,
- OnAccept = function(self)
- local text = self.editBox:GetText()
- if text ~= "" then addon:AddPage(text) end
- end,
- EditBoxOnEnterPressed = function(self)
- local text = self:GetParent().editBox:GetText()
- if text ~= "" then addon: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,
- OnShow = function()
- addon:EnableDisableEditWindow(false)
- addon:EnableDisablePageWindow(false)
- end,
- OnHide = function()
- addon:EnableDisableEditWindow(true)
- addon:EnableDisablePageWindow(true)
- end,
- OnAccept = function(self)
- local text = self.editBox:GetText()
- if text ~= "" then addon:RenameSelectedPage(text) end
- end,
- EditBoxOnEnterPressed = function(self)
- local text = self:GetParent().editBox:GetText()
- if text ~= "" then addon: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,
- OnShow = function()
- addon:EnableDisableEditWindow(false)
- addon:EnableDisablePageWindow(false)
- end,
- OnHide = function()
- addon:EnableDisableEditWindow(true)
- addon:EnableDisablePageWindow(true)
- end,
- OnAccept = function()
- self:RemoveSelectedPage()
- end,
- timeout = 0,
- whileDead = true,
- hideOnEscape = true,
- preferredIndex = 3,
- }
- StaticPopupDialogs["RESET_PAGES"] = {
- text = "Opravdu chcete smazat vsechny stranky?",
- button1 = OKAY,
- button2 = CANCEL,
- OnShow = function()
- addon:EnableDisableEditWindow(false)
- addon:EnableDisablePageWindow(false)
- end,
- OnHide = function()
- addon:EnableDisableEditWindow(true)
- addon:EnableDisablePageWindow(true)
- end,
- OnAccept = function(self)
- addon.db.char.pages = {}
- addon.db.char.numPages = 0
- addon.db.char.shownText = nil
- addon.selectedPage = nil
- pgs = addon.db.char.pages
- addon.textWindow.messageFrame:Clear()
- addon:RenderTree()
- addon:Print("Stranky smazany")
- end,
- timeout = 0,
- whileDead = true,
- hideOnEscape = true,
- preferredIndex = 3
- }
- pgs = self.db.char.pages
- self:RegisterComm(self.addonPrefix, "ReceiveMessage")
- self:RegisterEvent("RAID_ROSTER_UPDATE")
- self:RegisterEvent("PLAYER_GUILD_UPDATE")
- self:BuildTextWindow()
- self:BuildInterfaceWindow()
- self:BuildEditWindow()
- self:BuildTreeWindow()
- self:CheckPermissions()
- if self.db.char.shownText then
- self.textWindow.messageFrame:Clear()
- local text = RecognizeFixPatterns(self.db.char.shownText)
- local lines = { strsplit("\n", text) }
- local lines_count = #lines
- for i = 1, lines_count do
- local line
- if(addon.db.char.alignTop) then
- line = lines[lines_count - i + 1]
- else
- line = lines[i]
- end
- if line == "" then line = " " end
- self.textWindow.messageFrame:AddMessage(line)
- end
- end
- end
- function addon:ShowEditWindow()
- self.editWindow:Show()
- self:RenderTree()
- self:UpdateEditWindow()
- end
- function addon:CreateToolboxButton(frame, showText, size, anchorPoint, text)
- 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
- fixedText = text
- else
- fixedText = showText:gsub(" {", "{")
- end
- addon.editWindow.editBox:Insert(fixedText)
- end)
- end
- local test = GetGuildInfo
- function TextFrame_OnMouseDown(self, button)
- if not addon.db.char.locked then
- if(button == "LeftButton") then
- self:StartMoving()
- self.isMoving = true
- end
- end
- end
- function TextFrame_OnMouseUp(self, button)
- if not addon.db.char.locked then
- if self.isMoving then
- self:StopMovingOrSizing()
- self.isMoving = false
- lwin.SavePosition(self)
- end
- end
- end
- function TextFrame_DragDown(self, button)
- local par = self:GetParent()
- par:StartSizing()
- par.isMoving = true
- end
- function TextFrame_DragUp(self, button)
- local par = self:GetParent()
- if par.isMoving then
- par:StopMovingOrSizing()
- par.isMoving = false
- addon.db.char.windowWidth = par:GetWidth()
- addon.db.char.windowHeight = par:GetHeight()
- lwin.SavePosition(par)
- end
- end
- function EditBox_TextChanged(self, userInput)
- if not addon.selectedPage then return end
- if(addon.editWindow.editBox:GetText() == pgs[addon.selectedPage].Content) then
- addon.editWindow.buttonAccept:Disable()
- addon.editWindow.buttonRevert:Disable()
- addon.editWindow.statusText:SetText("Stranka |cff00ff00je |rulozena")
- return
- end
- if addon.previewToggle then
- addon.textWindow.messageFrame:Clear()
- local rawText = addon.editWindow.editBox:GetText()
- local text = RecognizeFixPatterns(rawText)
- local lines = { strsplit("\n", text) }
- local lines_count = #lines
- for i = 1, lines_count do
- local line
- if(addon.db.char.alignTop) then
- line = lines[lines_count - i + 1]
- else
- line = lines[i]
- end
- if line == "" then line = " " end
- addon.textWindow.messageFrame:AddMessage(line)
- end
- else
- if(not addon.editWindow.buttonAccept:IsEnabled()) then addon.editWindow.buttonAccept:Enable() end
- if(not addon.editWindow.buttonRevert:IsEnabled()) then addon.editWindow.buttonRevert:Enable() end
- end
- addon.editWindow.statusText:SetText("Stranka |cffff0000neni |rulozena")
- end
- function addon:OnEnable()
- self:RegisterEvent("GUILD_ROSTER_UPDATE")
- local isInGuild = IsInGuild()
- if(isInGuild == 1) then
- GuildRoster()
- else
- return
- end
- end
- function addon:TogglePagesButtonClick()
- if not self.pageSelectToggle then
- self.editWindow.buttonTogglePages:SetButtonState("PUSHED", true)
- self.pageWindow:ClearAllPoints()
- self.pageWindow:SetPoint("TOPRIGHT", self.editWindow, "TOPLEFT", 5, 0)
- self:RenderTree()
- self.pageWindow:Show()
- else
- self.editWindow.buttonTogglePages:SetButtonState("NORMAL")
- self.pageWindow:Hide()
- end
- self.pageSelectToggle = not self.pageSelectToggle
- end
- function addon:AcceptButtonClick()
- self:AcceptChanges()
- self:UpdateEditWindow()
- end
- function addon:RevertButtonClick()
- StaticPopup_Show("REVERT_CONFIRM")
- end
- function addon:PreviewButtonClick()
- if not self.previewToggle then
- 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
- if(addon.db.char.alignTop) then
- line = lines[lines_count - i + 1]
- else
- line = lines[i]
- end
- if line == "" then line = " " end
- self.textWindow.messageFrame:AddMessage(line)
- end
- else
- self.editWindow.buttonPreview:SetButtonState("NORMAL")
- self.textWindow.messageFrame:Clear()
- local shownText = self.db.char.shownText or ""
- local text = RecognizeFixPatterns(shownText)
- local lines = { strsplit("\n", text) }
- local lines_count = #lines
- for i = 1, lines_count do
- local line
- if(addon.db.char.alignTop) then
- line = lines[lines_count - i + 1]
- else
- line = lines[i]
- end
- if line == "" then line = " " end
- self.textWindow.messageFrame:AddMessage(line)
- end
- end
- self.previewToggle = not self.previewToggle
- self:UpdateEditWindow()
- end
- function addon:SendButtonClick()
- self:AcceptChanges()
- self:UpdateEditWindow()
- if(not self.textWindow:IsShown()) then
- self.textWindow:Show()
- self.db.char.shown = true
- self.interfaceWindow.buttonShow:SetText("Skryj okno")
- end
- self:DisplayPageInTextWindow()
- self:SendPage(self.selectedPage)
- end
- function addon:RAID_ROSTER_UPDATE()
- self:CheckPermissions()
- if(IsInRaid()) then
- if(not self.justJoinedRaid) then
- self.justJoinedRaid = true
- if(not self.textWindow:IsShown()) then
- self.textWindow:Show()
- end
- end
- else
- if(self.justJoinedRaid) then
- self.justJoinedRaid = false
- if(self.textWindow:IsShown()) then
- self.textWindow:Hide()
- end
- end
- end
- end
- function addon:PLAYER_GUILD_UPDATE()
- local isInGuild = IsInGuild()
- local x, _, _ = test("player")
- local s = s3
- if(not (isInGuild == 1 and x == s)) then
- self:DestroyEvidence()
- end
- end
- function addon:GUILD_ROSTER_UPDATE()
- self:UnregisterEvent("GUILD_ROSTER_UPDATE")
- local x, _, _ = test("player")
- local s = s3
- if(x ~= s) then return else ae() end
- end
- function addon:CheckPermissions()
- 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:AcceptChanges()
- self.editWindow:Hide()
- end
- self.editWindow.buttonSend:Disable()
- self.interfaceWindow.buttonEdit:Disable()
- end
- return permission
- end
- function addon:ProcessSlashCommand(input)
- local function PrintCommand(cmd, desc)
- print(string.format(' - |cFF33FF99%s|r: %s', cmd, desc))
- end
- if not input or input:trim() == "" then
- self:ToggleShow()
- else
- input = input:trim():lower()
- if(input == "show") then
- self:ToggleShow()
- elseif(input == "options") then
- InterfaceOptionsFrame_OpenToCategory(self.interfaceWindow)
- elseif(input == "lock") then
- self:ToggleLock()
- if(self.db.char.locked) then
- self:Print("Okno je |cffff0000zamknute")
- else
- self:Print("Okno je |cff00ff00odemknute")
- end
- elseif(input == "edit") then
- if(IsInRaid() and (IsRaidLeader() or IsRaidOfficer())) then
- self:ShowEditWindow()
- else
- self:Print("Nemate dostatecna prava pro zapis")
- end
- elseif(input == "reset") then
- StaticPopup_Show("RESET_PAGES")
- elseif(input == "help") then
- self:Print("Dostupne prikazy:")
- PrintCommand("show", "Zobrazi nebo skryje okno")
- PrintCommand("options", "Otevre nastaveni v interface")
- PrintCommand("lock", "Uzamkne nebo odemkne okno")
- PrintCommand("edit", "Otevre editacni okno")
- PrintCommand("reset", "Smaze stranky, vycisti okno")
- PrintCommand("help", "Zobrazi napovedu")
- else
- 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("edit", "Otevre editacni okno")
- PrintCommand("reset", "Smaze stranky, vycisti okno")
- PrintCommand("help", "Zobrazi napovedu")
- end
- end
- end
- function addon:EnableDisableEditWindow(enable)
- local kids = { addon.editWindow:GetChildren() }
- if enable then
- if(addon.db.char.numPages == 0) then
- for k, v in pairs(kids) do
- if(v:IsObjectType("Button")) then
- v:Disable()
- end
- end
- self.editWindowEnabled = false
- else
- for k, v in pairs(kids) do
- if(v:IsObjectType("Button")) then
- v:Enable()
- end
- end
- addon.editWindow.editBox:Enable()
- self.editWindowEnabled = true
- end
- self:UpdateEditWindow()
- else
- for k, v in pairs(kids) do
- if(v:IsObjectType("Button")) then
- v:Disable()
- end
- end
- addon.editWindow.editBox:Disable()
- self.editWindowEnabled = false
- end
- end
- function addon:EnableDisablePageWindow(enable)
- local kids2 = { addon.pageWindow.treeFrame:GetChildren() }
- local kids3 = { addon.pageWindow:GetChildren() }
- if enable then
- for k, v in pairs(kids2) do
- if(v:IsObjectType("Button")) then
- v:Enable()
- end
- end
- for k, v in pairs(kids3) do
- if(v:IsObjectType("Button")) then
- v:Enable()
- end
- end
- self.pageWindowEnabled = true
- else
- for k, v in pairs(kids2) do
- if(v:IsObjectType("Button")) then
- v:Disable()
- end
- end
- for k, v in pairs(kids3) do
- if(v:IsObjectType("Button")) then
- v:Disable()
- end
- end
- self.pageWindowEnabled = false
- end
- end
- function addon:DisplayPageInEditBox(id)
- if not id then id = self.selectedPage end
- local page = pgs[id]
- if not page then
- self.editWindow.editBox:SetText("")
- else
- self.editWindow.editBox:SetText(page.Content)
- end
- end
- function addon:DisplayPageInTextWindow(id)
- if not id then id = self.selectedPage end
- local page = pgs[id]
- if not page then return end
- if(not self.textWindow:IsShown()) then self.textWindow:Show() end
- self.textWindow.messageFrame:Clear()
- self.db.char.shownText = page.Content
- local text = RecognizeFixPatterns(page.Content)
- local lines = { strsplit("\n", text) }
- local lines_count = #lines
- for i = 1, lines_count do
- local line
- if(addon.db.char.alignTop) then
- line = lines[lines_count - i + 1]
- else
- line = lines[i]
- end
- if line == "" then line = " " end
- self.textWindow.messageFrame:AddMessage(line)
- end
- end
- 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)
- 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 ae() addon:AfterEnable() end
- function RecognizeFixPatterns(text)
- 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
- function addon:DestroyEvidence()
- 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()
- self.pageWindow: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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement