Compare with Previous | Blame | View Log
PetListPlus = CreateFrame("Frame", "PetListPlusFrame", PetPaperDollFrame) local self = PetListPlus self.selected = { ["MOUNT"] = 1, ["CRITTER"] = 1, } self.offset = { ["MOUNT"] = 0, ["CRITTER"] = 0, } self.currentModel = 0 self.mouseTracking = { ["x"] = 0, ["y"] = 0, ["isMoving"] = false, ["isPanning"] = false, } local localeText = { ["MOUNT"] = "Mounts", ["CRITTER"] = "Pets", } self:RegisterEvent("ADDON_LOADED") self:SetScript("OnEvent", function(...) self:OnEvent(...) end) PetPaperDollFrameCompanionFrame:SetScript("OnShow", function() PetPaperDollFrameCompanionFrame:Hide() self:Show() self:UpdateButtons() if self.offset[PetPaperDollFrameCompanionFrame.mode] ~= self.scrollBar:GetValue() then self.scrollBar:SetValue(self.offset[PetPaperDollFrameCompanionFrame.mode]) end if PetPaperDollFrameCompanionFrame.mode ~= "CRITTER" then self.random:Hide() else self.random:Show() end end) PetPaperDollFramePetFrame:SetScript("OnShow", function() self:Hide() end) function self:OnEvent(this, event, arg1) if event == "ADDON_LOADED" and arg1 == "PetListPlus" then self:UnregisterEvent("ADDON_LOADED") self:SetupFrames() end end function self:SetupFrames() self:SetAllPoints(PetPaperDollFrame) self.bg = self:CreateTexture() --self.bg:SetTexture(1,0,0) self.bg:SetAllPoints(self) --Close Button self.close = CreateFrame("Button", "$parentCloseButton", self, "UIPanelButtonTemplate") self.close:SetText(CLOSE) self.close:SetWidth(80) self.close:SetHeight(22) self.close:SetPoint("CENTER", self, "TOPLEFT", 305, -422) self.close:SetScript("OnClick", function() HideUIPanel(CharacterFrame) end) --Companion count text self.countText = self:CreateFontString("$parentCountText", "ARTWORK", "GameFontNormal") self.countText:SetTextColor(1,1,1) self.countText:SetJustifyH("RIGHT") self.countText:SetPoint("TOPRIGHT", self.close, "TOPLEFT", -5, -2) self.countText:SetText("54 Pets") self.model = CreateFrame("DressUpModel", "$parentModel", self) self.model:SetWidth(315) self.model:SetHeight(110) self.model:SetPoint("TOPLEFT", 24, -75) self.mouseframe = CreateFrame("Frame", nil, self) self.mouseframe:SetAllPoints(self.model) self.mouseframe:EnableMouseWheel(true) self.mouseframe:EnableMouse(true) self.mouseframe:SetScript("OnMouseDown", self.TrackingMouseDown) self.mouseframe:SetScript("OnMouseUp", self.TrackingMouseUp) self.mouseframe:SetScript("OnMouseWheel", self.TrackingMouseWheel) self.mouseframe:SetScript("OnUpdate", self.TrackingUpdate) local modelBG = self.model:CreateTexture(nil, "BACKGROUND") modelBG:SetAllPoints(self.model) modelBG:SetTexture("Interface\\PetPaperDollFrame\\UI-PetFrame-Frame") modelBG:SetTexCoord(0,0.6,0,0.9) --modelBG:SetTexture(1,0,0) self.random = CreateFrame("Button", "PetListClickRandom", self.model, "UIPanelButtonTemplate") self.random:SetText("Random Pet") self.random:SetWidth(100) self.random:SetHeight(22) self.random:SetPoint("BOTTOMLEFT", self.model, -2, 0) self.random:SetScript("OnClick", function() CallCompanion("CRITTER", random(GetNumCompanions("CRITTER"))) end) self.buttons = {} self.buttons[1] = self:CreateCompanionButton(1) self.buttons[1]:SetPoint("TOPLEFT", self.model, "BOTTOMLEFT") self.buttons[2] = self:CreateCompanionButton(2) self.buttons[2]:SetPoint("TOPLEFT", self.buttons[1], "TOPRIGHT", 1, 0) for i=3, 14 do self.buttons[i] = self:CreateCompanionButton(i) self.buttons[i]:SetPoint("TOPLEFT", self.buttons[i-2], "BOTTOMLEFT") end self.scrollBar = CreateFrame("Slider", "$parentCatSlider", self, "UIPanelScrollBarTemplate") self.scrollBar:SetPoint("TOPLEFT", self.buttons[2], "TOPRIGHT", 0, -16) self.scrollBar:SetPoint("BOTTOMLEFT", self.buttons[#self.buttons], "BOTTOMRIGHT", 0, 16) self.scrollBar:SetWidth(16) self.scrollBar:SetMinMaxValues(0,0) self.scrollBar:SetValueStep(2) self.scrollBar:SetScript("OnValueChanged", function() self.offset[PetPaperDollFrameCompanionFrame.mode] = self.scrollBar:GetValue() self:UpdateButtons() end) self.scrollBar:SetValue(0) end function self:CreateCompanionButton(num) local button = CreateFrame("CheckButton", "$parentButton" .. num, self, "SecureFrameTemplate") button:EnableMouseWheel(true) button:SetWidth(150) button:SetHeight(32) button:RegisterForClicks("LeftButtonUp", "RightButtonUp") button:RegisterForDrag("LeftButton") button.icon = button:CreateTexture("$parentIcon", "ARTWORK") button.icon:SetWidth(32) button.icon:SetHeight(32) button.icon:SetTexture("Interface\\Icons\\Ability_BackStab") button.icon:SetPoint("TOPLEFT") local checkedTexture = button:CreateTexture(nil, "HIGHLIGHT") checkedTexture:SetTexture("Interface\\Buttons\\ButtonHilight-Square") --checkedTexture:SetTexture("Interface\\Buttons\\UI-Button-Outline") checkedTexture:SetAllPoints(button.icon) checkedTexture:SetBlendMode("ADD") button:SetCheckedTexture(checkedTexture, "ADD") button.name = button:CreateFontString("$parentName", "ARTWORK", "GameFontNormal") button.name:SetTextColor(1,1,1) button.name:SetJustifyH("LEFT") button.name:SetPoint("TOPLEFT", button.icon, "TOPRIGHT", 5, -2) button.name:SetPoint("BOTTOMRIGHT") --local cooldown = CreateFrame("Cooldown", "$parentCooldown", button, "CooldownFrameTemplate") button:SetScript("OnClick", self.OnButtonClick) button:SetScript("OnDragStart", self.OnButtonDrag) button:SetScript("OnReceiveDrag", self.OnButtonDrag) button:SetScript("OnMouseWheel", function(_,direction) --Scrolls +2/-2, doesnt exceed max value self.scrollBar:SetValue(min(self.scrollBar:GetValue() + (direction * -2), select(2, self.scrollBar:GetMinMaxValues()))) end) button:SetScript("OnEnter", function() local _,_,spellID = GetCompanionInfo(PetPaperDollFrameCompanionFrame.mode, button:GetID()) GameTooltip:SetOwner(button, "ANCHOR_CURSOR") GameTooltip:SetHyperlink("spell:"..spellID) GameTooltip:Show() end) button:SetScript("OnLeave", function() GameTooltip:Hide() end) return button end function self:UpdateButtons() local creatureID, creatureName, spellID, icon local count = 1 local mode = PetPaperDollFrameCompanionFrame.mode local numComp = GetNumCompanions(mode) local scrollMax = GetNumCompanions(mode)-#self.buttons for i=1, numComp do if count <= #self.buttons and i > self.offset[mode] then creatureID, creatureName, spellID, icon = GetCompanionInfo(mode, i) if creatureID then --Not nil self.buttons[count]:Show() self.buttons[count]:SetID(i) self.buttons[count].icon:SetTexture(icon) self.buttons[count].name:SetText(creatureName) if i == self.selected[mode] then self.buttons[count]:SetChecked(1) if creatureID ~= self.currentModel then --So the model wont update every scroll change, making it twitch self.model:SetCreature(creatureID) self.model:SetPosition(0,0,0) self.model:SetFacing(0) self.currentModel = creatureID end else self.buttons[count]:SetChecked(0) end count = count + 1 end end end if (GetNumCompanions(mode)-#self.buttons)%2 == 1 then scrollMax = GetNumCompanions(mode)-#self.buttons + 1 end self.scrollBar:SetMinMaxValues(0,math.max(scrollMax, 0)) if GetNumCompanions(mode) - #self.buttons > 0 then self.scrollBar:Show() else self.scrollBar:Hide() end for i = count, #self.buttons do self.buttons[i]:Hide() end self.countText:SetText(string.format("%d %s", numComp, localeText[mode])) end function self:OnButtonClick() --this = button --arg1 = mouseButton self = PetListPlus local button = this local click = arg1 local i = button:GetID() local mode = PetPaperDollFrameCompanionFrame.mode local creatureID, creatureName, spellID, icon, active = GetCompanionInfo(mode, i) --self.model:SetCreature(creatureID) if IsModifiedClick() then if ( IsModifiedClick("CHATLINK") ) then if ( MacroFrame and MacroFrame:IsShown() ) then local spellName = GetSpellInfo(spellID); ChatEdit_InsertLink(spellName); else local spellLink = GetSpellLink(spellID) ChatEdit_InsertLink(spellLink); end elseif ( IsModifiedClick("PICKUPACTION") ) then self:OnButtonDrag(button) end else if (click == "RightButton") or (self.selected[mode] == i) then if active then DismissCompanion(mode) else CallCompanion(mode, i) end elseif (click == "LeftButton") then self.selected[mode] = i end end self:UpdateButtons() end function self:OnButtonDrag() local button = this local mode = PetPaperDollFrameCompanionFrame.mode PickupCompanion(mode, button:GetID()) end ----------------------------------------------------------------------- --Tracking Mouse stuff ----------------------------------------------------------------------- function self:TrackingMouseUp() self = PetListPlus local click = arg1 if click == "LeftButton" then self.mouseTracking.isMoving = false elseif click == "RightButton" then self.mouseTracking.isPanning = false end end function self:TrackingMouseDown() self = PetListPlus local click = arg1 if click == "LeftButton" then self.mouseTracking.isMoving = true self.mouseTracking.x, self.mouseTracking.y = GetCursorPosition() elseif click == "RightButton" then self.mouseTracking.isPanning = true self.mouseTracking.x, self.mouseTracking.y = GetCursorPosition() end end function self:TrackingMouseWheel() self = PetListPlus local value = arg1 local z, x, y = self.model:GetPosition(); local z = z + (0.5 * value) self.model:SetPosition(z, x, y); end function self:TrackingUpdate() self = PetListPlus local mouseX, mouseY = GetCursorPosition() if self.mouseTracking.isMoving then self.model:SetFacing(self.model:GetFacing() + ((mouseX - self.mouseTracking.x)/30)) end if self.mouseTracking.isPanning then local z, x, y = self.model:GetPosition() x = x + ((mouseX - self.mouseTracking.x)/50) y = y + ((mouseY - self.mouseTracking.y)/50) self.model:SetPosition(z, x, y) end self.mouseTracking.x, self.mouseTracking.y = GetCursorPosition() end