2 Star 0 Fork 0

mirrors_kylepixel/wow-ui-source

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
spellbookframe.lua 22.98 KB
一键复制 编辑 原始数据 按行查看 历史
dubcat 提交于 6年前 . 1.13.2.30128
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
MAX_SPELLS = 1024;
MAX_SKILLLINE_TABS = 8;
SPELLS_PER_PAGE = 12;
MAX_SPELL_PAGES = ceil(MAX_SPELLS / SPELLS_PER_PAGE);
BOOKTYPE_SPELL = "spell";
BOOKTYPE_PET = "pet";
local MaxSpellBookTypes = 3;
local SpellBookInfo = {};
SpellBookInfo[BOOKTYPE_SPELL] = {
showFrames = {"SpellBookSpellIconsFrame", "SpellBookSideTabsFrame", "SpellBookPageNavigationFrame"},
title = SPELLBOOK,
updateFunc = function() SpellBook_UpdatePlayerTab(); end
};
SpellBookInfo[BOOKTYPE_PET] = {
showFrames = {"SpellBookSpellIconsFrame", "SpellBookPageNavigationFrame"},
title = PET,
updateFunc = function() SpellBook_UpdatePetTab(); end
};
SPELLBOOK_PAGENUMBERS = {};
SpellBookFrames = { "SpellBookSpellIconsFrame", "SpellBookSideTabsFrame", "SpellBookPageNavigationFrame" };
local ceil = ceil;
local strlen = strlen;
local tinsert = tinsert;
local tremove = tremove;
function ToggleSpellBook(bookType)
if ( (not HasPetSpells() or not PetHasSpellbook()) and bookType == BOOKTYPE_PET ) then
return;
end
local isShown = SpellBookFrame:IsShown();
if ( isShown and (SpellBookFrame.bookType == bookType) ) then
HideUIPanel(SpellBookFrame);
return;
elseif isShown then
SpellBookFrame_PlayOpenSound()
SpellBookFrame.bookType = bookType;
SpellBookFrame_Update();
else
SpellBookFrame.bookType = bookType;
ShowUIPanel(SpellBookFrame);
end
end
function SpellBookFrame_OnLoad(self)
self:RegisterEvent("SPELLS_CHANGED");
self:RegisterEvent("LEARNED_SPELL_IN_TAB");
SpellBookFrame.bookType = BOOKTYPE_SPELL;
-- Init page nums
SPELLBOOK_PAGENUMBERS[1] = 1;
SPELLBOOK_PAGENUMBERS[2] = 1;
SPELLBOOK_PAGENUMBERS[3] = 1;
SPELLBOOK_PAGENUMBERS[4] = 1;
SPELLBOOK_PAGENUMBERS[5] = 1;
SPELLBOOK_PAGENUMBERS[6] = 1;
SPELLBOOK_PAGENUMBERS[7] = 1;
SPELLBOOK_PAGENUMBERS[8] = 1;
SPELLBOOK_PAGENUMBERS[BOOKTYPE_PET] = 1;
-- Set to the first tab by default
SpellBookFrame.selectedSkillLine = 1;
-- Initialize tab flashing
SpellBookFrame.flashTabs = nil;
end
function SpellBookFrame_OnEvent(self, event, ...)
if ( event == "SPELLS_CHANGED" ) then
if ( SpellBookFrame:IsVisible() ) then
if ( GetNumSpellTabs() < SpellBookFrame.selectedSkillLine ) then
SpellBookFrame.selectedSkillLine = 2;
end
SpellBookFrame_Update();
end
elseif ( event == "LEARNED_SPELL_IN_TAB" ) then
SpellBookFrame_Update();
local spellID, tabNum, isGuildSpell = ...;
local flashFrame = _G["SpellBookSkillLineTab"..tabNum.."Flash"];
if ( SpellBookFrame.bookType == BOOKTYPE_PET or isGuildSpell) then
return;
elseif ( tabNum <= GetNumSpellTabs() ) then
if ( flashFrame ) then
flashFrame:Show();
SpellBookFrame.flashTabs = 1;
end
end
end
end
function SpellBookFrame_OnShow(self)
SpellBookFrame_Update();
-- If there are tabs waiting to flash, then flash them... yeah..
if ( self.flashTabs ) then
UIFrameFlash(SpellBookTabFlashFrame, 0.5, 0.5, 30, nil);
end
-- Show multibar slots
MultiActionBar_ShowAllGrids();
UpdateMicroButtons();
SpellBookFrame_PlayOpenSound();
MicroButtonPulseStop(SpellbookMicroButton);
end
function SpellBookFrame_Update()
-- Hide all tabs
SpellBookFrameTabButton1:Hide();
SpellBookFrameTabButton2:Hide();
SpellBookFrameTabButton3:Hide();
-- Setup tabs
-- check to see if we have a pet
local hasPetSpells, petToken = HasPetSpells();
SpellBookFrame.petTitle = nil;
if ( hasPetSpells and PetHasSpellbook() ) then
SpellBookFrame_SetTabType(SpellBookFrameTabButton1, BOOKTYPE_SPELL);
SpellBookFrame_SetTabType(SpellBookFrameTabButton2, BOOKTYPE_PET, petToken);
elseif (SpellBookFrame.bookType == BOOKTYPE_PET) then
HideUIPanel(SpellBookFrame);
SpellBookFrame.bookType = BOOKTYPE_SPELL;
end
if ( SpellBookFrame.bookType == BOOKTYPE_SPELL ) then
SpellBookTitleText:SetText(SPELLBOOK);
else
SpellBookTitleText:SetText(SpellBookFrame.petTitle);
end
-- Make sure the correct tab is selected
for i=1,MaxSpellBookTypes do
local tab = _G["SpellBookFrameTabButton"..i];
if ( tab.bookType == SpellBookFrame.bookType ) then
SpellBookFrame.currentTab = tab;
end
end
-- setup display
for i, frame in ipairs(SpellBookFrames) do
local found = false;
for j,frame2 in ipairs(SpellBookInfo[SpellBookFrame.bookType].showFrames) do
if (frame == frame2) then
_G[frame]:Show();
found = true;
break;
end
end
if (found == false) then
_G[frame]:Hide();
end
end
local tabUpdate = SpellBookInfo[SpellBookFrame.bookType].updateFunc;
if(tabUpdate) then
tabUpdate()
end
end
function SpellBookFrame_SetTabType(tabButton, bookType, token)
if ( bookType == BOOKTYPE_SPELL ) then
tabButton.bookType = BOOKTYPE_SPELL;
tabButton.Text:SetText(SpellBookInfo[BOOKTYPE_SPELL].title);
tabButton.binding = "TOGGLESPELLBOOK";
else
tabButton.bookType = BOOKTYPE_PET;
tabButton.Text:SetText(_G["PET_TYPE_"..token]);
tabButton.binding = "TOGGLEPETBOOK";
SpellBookFrame.petTitle = _G["PET_TYPE_"..token];
end
if ( SpellBookFrame.bookType == bookType ) then
tabButton:Disable();
else
tabButton:Enable();
end
tabButton:Show();
end
function SpellBookFrame_UpdateSpells ()
for i = 1, SPELLS_PER_PAGE do
_G["SpellButton" .. i]:Show();
SpellButton_UpdateButton(_G["SpellButton" .. i]);
end
end
function SpellBookFrame_UpdatePages()
local currentPage, maxPages = SpellBook_GetCurrentPage();
if ( maxPages == nil or maxPages == 0 ) then
return;
end
if ( currentPage > maxPages ) then
if (SpellBookFrame.bookType == BOOKTYPE_SPELL ) then
SPELLBOOK_PAGENUMBERS[SpellBookFrame.selectedSkillLine] = maxPages;
else
SPELLBOOK_PAGENUMBERS[SpellBookFrame.bookType] = maxPages;
end
currentPage = maxPages;
if ( currentPage == 1 ) then
SpellBookPrevPageButton:Disable();
else
SpellBookPrevPageButton:Enable();
end
if ( currentPage == maxPages ) then
SpellBookNextPageButton:Disable();
else
SpellBookNextPageButton:Enable();
end
end
if ( currentPage == 1 ) then
SpellBookPrevPageButton:Disable();
else
SpellBookPrevPageButton:Enable();
end
if ( currentPage == maxPages ) then
SpellBookNextPageButton:Disable();
else
SpellBookNextPageButton:Enable();
end
SpellBookPageText:SetFormattedText(PAGE_NUMBER, currentPage);
end
function SpellBookFrame_PlayOpenSound()
if ( SpellBookFrame.bookType == BOOKTYPE_SPELL ) then
PlaySound(SOUNDKIT.IG_SPELLBOOK_OPEN);
elseif ( SpellBookFrame.bookType == BOOKTYPE_PET ) then
-- Need to change to pet book open sound
PlaySound(SOUNDKIT.IG_ABILITY_OPEN);
else
PlaySound(SOUNDKIT.IG_SPELLBOOK_OPEN);
end
end
function SpellBookFrame_PlayCloseSound()
if ( SpellBookFrame.bookType == BOOKTYPE_SPELL ) then
PlaySound(SOUNDKIT.IG_SPELLBOOK_CLOSE);
else
-- Need to change to pet book close sound
PlaySound(SOUNDKIT.IG_ABILITY_CLOSE);
end
end
function SpellBookFrame_OnHide(self)
SpellBookFrame_PlayCloseSound();
-- Stop the flash frame from flashing if its still flashing.. flash flash flash
UIFrameFlashStop(SpellBookTabFlashFrame);
-- Hide all the flashing textures
for i=1, MAX_SKILLLINE_TABS do
_G["SpellBookSkillLineTab"..i.."Flash"]:Hide();
end
-- Hide multibar slots
MultiActionBar_HideAllGrids();
-- Do this last, it can cause taint.
UpdateMicroButtons();
end
function SpellButton_OnLoad(self)
self:RegisterForDrag("LeftButton");
self:RegisterForClicks("LeftButtonUp", "RightButtonUp");
end
function SpellButton_OnEvent(self, event, ...)
if ( event == "SPELLS_CHANGED" or event == "UPDATE_SHAPESHIFT_FORM" ) then
-- need to listen for UPDATE_SHAPESHIFT_FORM because attack icons change when the shapeshift form changes
SpellButton_UpdateButton(self);
elseif ( event == "SPELL_UPDATE_COOLDOWN" ) then
SpellButton_UpdateCooldown(self);
-- Update tooltip
if ( GameTooltip:GetOwner() == self ) then
SpellButton_OnEnter(self);
end
elseif ( event == "CURRENT_SPELL_CAST_CHANGED" ) then
SpellButton_UpdateSelection(self);
elseif ( event == "CRAFT_SHOW" or event == "CRAFT_CLOSE" or event == "TRADE_SKILL_SHOW" or event == "TRADE_SKILL_CLOSE" ) then
SpellButton_UpdateSelection(self);
elseif ( event == "PET_BAR_UPDATE" ) then
if ( SpellBookFrame.bookType == BOOKTYPE_PET ) then
SpellButton_UpdateButton(self);
end
elseif ( event == "CURSOR_UPDATE" ) then
if ( self.spellGrabbed ) then
SpellButton_UpdateButton(self);
self.spellGrabbed = false;
end
end
end
function SpellButton_OnShow(self)
self:RegisterEvent("SPELLS_CHANGED");
self:RegisterEvent("SPELL_UPDATE_COOLDOWN");
self:RegisterEvent("CRAFT_SHOW");
self:RegisterEvent("CRAFT_CLOSE");
self:RegisterEvent("UPDATE_SHAPESHIFT_FORM");
self:RegisterEvent("CURRENT_SPELL_CAST_CHANGED");
self:RegisterEvent("TRADE_SKILL_SHOW");
self:RegisterEvent("TRADE_SKILL_CLOSE");
self:RegisterEvent("PET_BAR_UPDATE");
self:RegisterEvent("CURSOR_UPDATE");
end
function SpellButton_OnHide(self)
self:UnregisterEvent("SPELLS_CHANGED");
self:UnregisterEvent("SPELL_UPDATE_COOLDOWN");
self:UnregisterEvent("CRAFT_SHOW");
self:UnregisterEvent("CRAFT_CLOSE");
self:UnregisterEvent("UPDATE_SHAPESHIFT_FORM");
self:UnregisterEvent("CURRENT_SPELL_CAST_CHANGED");
self:UnregisterEvent("TRADE_SKILL_SHOW");
self:UnregisterEvent("TRADE_SKILL_CLOSE");
self:UnregisterEvent("PET_BAR_UPDATE");
self:UnregisterEvent("CURSOR_UPDATE");
end
function SpellButton_OnEnter(self)
local slot = SpellBook_GetSpellBookSlot(self);
GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
if ( GameTooltip:SetSpellBookItem(slot, SpellBookFrame.bookType) ) then
self.UpdateTooltip = SpellButton_OnEnter;
else
self.UpdateTooltip = nil;
end
GameTooltip:Show();
end
function SpellButton_OnLeave(self)
GameTooltip:Hide();
end
function SpellButton_OnClick(self, button)
local slot, slotType = SpellBook_GetSpellBookSlot(self);
if ( slot > MAX_SPELLS ) then
return;
end
if (self.isPassive) then
return;
end
if ( button ~= "LeftButton" and SpellBookFrame.bookType == BOOKTYPE_PET ) then
ToggleSpellAutocast(slot, SpellBookFrame.bookType);
else
local _, id = GetSpellBookItemInfo(slot, SpellBookFrame.bookType);
if ( SpellBookFrame.bookType ~= BOOKTYPE_SPELLBOOK ) then
CastSpell(slot, SpellBookFrame.bookType);
end
SpellButton_UpdateSelection(self);
end
end
function SpellButton_OnModifiedClick(self, button)
local slot = SpellBook_GetSpellBookSlot(self);
if ( slot > MAX_SPELLS ) then
return;
end
if ( IsModifiedClick("CHATLINK") ) then
if ( MacroFrameText and MacroFrameText:HasFocus() ) then
local spellName, subSpellName = GetSpellBookItemName(slot, SpellBookFrame.bookType);
if ( spellName and not IsPassiveSpell(slot, SpellBookFrame.bookType) ) then
if ( subSpellName and (strlen(subSpellName) > 0) ) then
ChatEdit_InsertLink(spellName.."("..subSpellName..")");
else
ChatEdit_InsertLink(spellName);
end
end
return;
else
local tradeSkillLink, tradeSkillSpellID = GetSpellTradeSkillLink(slot, SpellBookFrame.bookType);
if ( tradeSkillSpellID ) then
ChatEdit_InsertLink(tradeSkillLink);
else
ChatEdit_InsertLink(GetSpellLink(slot, SpellBookFrame.bookType));
end
return;
end
end
if ( IsModifiedClick("PICKUPACTION") ) then
PickupSpellBookItem(slot, SpellBookFrame.bookType);
return;
end
if ( IsModifiedClick("SELFCAST") ) then
CastSpell(slot, SpellBookFrame.bookType, true);
SpellButton_UpdateSelection(self);
return;
end
end
function SpellButton_OnDrag(self)
local slot, slotType = SpellBook_GetSpellBookSlot(self);
if (not slot or slot > MAX_SPELLS or not _G[self:GetName().."IconTexture"]:IsShown() or (slotType == "FUTURESPELL")) then
return;
end
self:SetChecked(false);
PickupSpellBookItem(slot, SpellBookFrame.bookType);
end
function SpellButton_OnReceiveDrag(self)
SpellButton_OnDrag(self);
end
function SpellButton_OnDragStart(self)
SpellButton_OnDrag(self);
self.spellGrabbed = true;
end
function SpellButton_UpdateSelection(self)
-- We only highlight professions that are open. We used to highlight active shapeshifts and pet
-- stances but we removed the highlight on those to avoid conflicting with the not-on-your-action-bar highlights.
local slot = SpellBook_GetSpellBookSlot(self);
if ( slot and IsSelectedSpellBookItem(slot, SpellBookFrame.bookType) ) then
self:SetChecked(true);
else
self:SetChecked(false);
end
end
function SpellButton_UpdateCooldown(self)
local cooldown = self.cooldown;
local slot, slotType = SpellBook_GetSpellBookSlot(self);
if (slot) then
local iconTexture = _G[self:GetName().."IconTexture"];
local start, duration, enable, modRate = GetSpellCooldown(slot, SpellBookFrame.bookType);
if (enable == 1) then
iconTexture:SetVertexColor(1.0, 1.0, 1.0);
else
iconTexture:SetVertexColor(0.4, 0.4, 0.4);
end
if (cooldown and start and duration) then
if (enable == 1) then
cooldown:Hide();
else
cooldown:Show();
end
CooldownFrame_Set(cooldown, start, duration, enable, false, modRate);
else
cooldown:Hide();
end
end
end
function SpellButton_UpdateButton(self)
if ( not SpellBookFrame.selectedSkillLine ) then
SpellBookFrame.selectedSkillLine = 2;
end
local _, _, offset, numSlots, _, offSpecID, shouldHide, specID = GetSpellTabInfo(SpellBookFrame.selectedSkillLine);
SpellBookFrame.selectedSkillLineNumSlots = numSlots;
SpellBookFrame.selectedSkillLineOffset = offset;
if (not self.SpellName.shadowX) then
self.SpellName.shadowX, self.SpellName.shadowY = self.SpellName:GetShadowOffset();
end
local slot, slotType, slotID = SpellBook_GetSpellBookSlot(self);
local name = self:GetName();
local iconTexture = _G[name.."IconTexture"];
local spellString = _G[name.."SpellName"];
local subSpellString = _G[name.."SubSpellName"];
local cooldown = _G[name.."Cooldown"];
local autoCastableTexture = _G[name.."AutoCastable"];
local slotFrame = _G[name.."SlotFrame"];
local normalTexture = _G[name.."NormalTexture"];
local highlightTexture = _G[name.."Highlight"];
local texture;
if ( slot ) then
texture = GetSpellTexture(slot, SpellBookFrame.bookType);
end
-- If no spell, hide everything and return, or kiosk mode and future spell
if ( not texture or (strlen(texture) == 0) or (slotType == "FUTURESPELL" and IsKioskModeEnabled())) then
iconTexture:Hide();
spellString:Hide();
subSpellString:Hide();
cooldown:Hide();
autoCastableTexture:Hide();
SpellBook_ReleaseAutoCastShine(self.shine);
self.shine = nil;
highlightTexture:SetTexture("Interface\\Buttons\\ButtonHilight-Square");
self:SetChecked(false);
self:Disable();
normalTexture:SetVertexColor(1.0, 1.0, 1.0);
highlightTexture:SetTexture("Interface\\Buttons\\ButtonHilight-Square");
return;
else
self:Enable();
end
SpellButton_UpdateCooldown(self);
local autoCastAllowed, autoCastEnabled = GetSpellAutocast(slot, SpellBookFrame.bookType);
if ( autoCastAllowed ) then
autoCastableTexture:Show();
else
autoCastableTexture:Hide();
end
if ( autoCastEnabled and not self.shine ) then
self.shine = SpellBook_GetAutoCastShine();
self.shine:Show();
self.shine:SetParent(self);
self.shine:SetPoint("CENTER", self, "CENTER");
AutoCastShine_AutoCastStart(self.shine);
elseif ( autoCastEnabled ) then
self.shine:Show();
self.shine:SetParent(self);
self.shine:SetPoint("CENTER", self, "CENTER");
AutoCastShine_AutoCastStart(self.shine);
elseif ( not autoCastEnabled ) then
SpellBook_ReleaseAutoCastShine(self.shine);
self.shine = nil;
end
local spellName, _, spellID = GetSpellBookItemName(slot, SpellBookFrame.bookType);
local isPassive = IsPassiveSpell(slot, SpellBookFrame.bookType);
self.isPassive = isPassive;
iconTexture:SetTexture(texture);
spellString:SetText(spellName);
self.SpellSubName:SetHeight(6);
subSpellString:SetText("");
if spellID then
local spell = Spell:CreateFromSpellID(spellID);
spell:ContinueOnSpellLoad(function()
local subSpellName = spell:GetSpellSubtext();
if ( subSpellName == "" ) then
if ( isPassive ) then
subSpellName = SPELL_PASSIVE;
end
end
subSpellString:SetText(subSpellName);
end);
end
if ( subSpellName == "" ) then
spellString:SetPoint("LEFT", self, "RIGHT", 5, 1);
else
spellString:SetPoint("LEFT", self, "RIGHT", 5, 3);
end
iconTexture:Show();
spellString:Show();
subSpellString:Show();
if ( isPassive ) then
normalTexture:SetVertexColor(0, 0, 0);
highlightTexture:SetTexture("Interface\\Buttons\\UI-PassiveHighlight");
spellString:SetTextColor(PASSIVE_SPELL_FONT_COLOR.r, PASSIVE_SPELL_FONT_COLOR.g, PASSIVE_SPELL_FONT_COLOR.b);
else
normalTexture:SetVertexColor(1.0, 1.0, 1.0);
highlightTexture:SetTexture("Interface\\Buttons\\ButtonHilight-Square");
spellString:SetTextColor(NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b);
end
SpellButton_UpdateSelection(self);
end
function SpellBookPrevPageButton_OnClick()
local pageNum = SpellBook_GetCurrentPage() - 1;
if ( SpellBookFrame.bookType == BOOKTYPE_SPELL ) then
PlaySound(SOUNDKIT.IG_ABILITY_PAGE_TURN);
SPELLBOOK_PAGENUMBERS[SpellBookFrame.selectedSkillLine] = pageNum;
else
-- Need to change to pet book pageturn sound
PlaySound(SOUNDKIT.IG_ABILITY_PAGE_TURN);
SPELLBOOK_PAGENUMBERS[SpellBookFrame.bookType] = pageNum;
end
SpellBookFrame_Update();
end
function SpellBookNextPageButton_OnClick()
local pageNum = SpellBook_GetCurrentPage() + 1;
if ( SpellBookFrame.bookType == BOOKTYPE_SPELL ) then
PlaySound(SOUNDKIT.IG_ABILITY_PAGE_TURN);
SPELLBOOK_PAGENUMBERS[SpellBookFrame.selectedSkillLine] = pageNum;
else
-- Need to change to pet book pageturn sound
PlaySound(SOUNDKIT.IG_ABILITY_PAGE_TURN);
SPELLBOOK_PAGENUMBERS[SpellBookFrame.bookType] = pageNum;
end
SpellBookFrame_Update();
end
function SpellBookSkillLineTab_OnClick(self)
local id = self:GetID();
if ( SpellBookFrame.selectedSkillLine ~= id ) then
PlaySound(SOUNDKIT.IG_ABILITY_PAGE_TURN);
SpellBookFrame.selectedSkillLine = id;
SpellBookFrame_Update();
else
self:SetChecked(true);
end
-- Stop tab flashing
if ( self ) then
local tabFlash = _G[self:GetName().."Flash"];
if ( tabFlash ) then
tabFlash:Hide();
end
end
end
function SpellBookFrameTabButton_OnClick(self)
self:Disable();
if SpellBookFrame.currentTab then
SpellBookFrame.currentTab:Enable();
end
SpellBookFrame.currentTab = self;
ToggleSpellBook(self.bookType);
end
function SpellBook_GetSpellBookSlot(spellButton)
local id = spellButton:GetID()
if ( SpellBookFrame.bookType == BOOKTYPE_PET ) then
local slot = id + (SPELLS_PER_PAGE * (SPELLBOOK_PAGENUMBERS[BOOKTYPE_PET] - 1));
if ( SpellBookFrame.numPetSpells and slot <= SpellBookFrame.numPetSpells) then
local slotType, slotID = GetSpellBookItemInfo(slot, SpellBookFrame.bookType);
return slot, slotType, slotID;
end
else
local relativeSlot = id + ( SPELLS_PER_PAGE * (SPELLBOOK_PAGENUMBERS[SpellBookFrame.selectedSkillLine] - 1));
if ( SpellBookFrame.selectedSkillLineNumSlots and relativeSlot <= SpellBookFrame.selectedSkillLineNumSlots) then
local slot = SpellBookFrame.selectedSkillLineOffset + relativeSlot;
local slotType, slotID = GetSpellBookItemInfo(slot, SpellBookFrame.bookType);
return slot, slotType, slotID;
end
end
return nil, nil, nil;
end
function SpellBook_GetButtonForID(id)
-- Currently the spell book is mapped such that odd numbered buttons from 1 - 11 match id 1 - 6, while even numbered buttons from 2 - 12 match 7 - 12
if (id > 6) then
return _G["SpellButton"..((id - 6) * 2)];
else
return _G["SpellButton"..(((id - 1) * 2) + 1)];
end
end
function SpellBookFrame_OpenToPageForSlot(slot, reason)
local alreadyOpen = SpellBookFrame:IsShown();
SpellBookFrame.bookType = BOOKTYPE_SPELL;
ShowUIPanel(SpellBookFrame);
if (SpellBookFrame.selectedSkillLine ~= 2) then
SpellBookFrame.selectedSkillLine = 2;
SpellBookFrame_Update();
end
if (alreadyOpen and reason == OPEN_REASON_PENDING_GLYPH) then
local page = SPELLBOOK_PAGENUMBERS[SpellBookFrame.selectedSkillLine];
for i = 1, 12 do
local slot = (i + ( SPELLS_PER_PAGE * (page - 1))) + SpellBookFrame.selectedSkillLineOffset;
local slotType, spellID = GetSpellBookItemInfo(slot, SpellBookFrame.bookType);
if (slotType == "SPELL") then
if (IsSpellValidForPendingGlyph(spellID)) then
SpellBookFrame_Update();
return;
end
end
end
end
local slotType, spellID = GetSpellBookItemInfo(slot, SpellBookFrame.bookType);
local relativeSlot = slot - SpellBookFrame.selectedSkillLineOffset;
local page = math.floor((relativeSlot - 1)/ SPELLS_PER_PAGE) + 1;
SPELLBOOK_PAGENUMBERS[SpellBookFrame.selectedSkillLine] = page;
SpellBookFrame_Update();
end
function SpellBookFrame_ClearAbilityHighlights()
for i = 1, SPELLS_PER_PAGE do
local button = _G["SpellButton"..i];
button.AbilityHighlightAnim:Stop();
button.AbilityHighlight:Hide();
end
end
function SpellBook_GetCurrentPage()
local currentPage, maxPages;
local numPetSpells = HasPetSpells() or 0;
if ( SpellBookFrame.bookType == BOOKTYPE_PET ) then
currentPage = SPELLBOOK_PAGENUMBERS[BOOKTYPE_PET];
maxPages = ceil(numPetSpells/SPELLS_PER_PAGE);
elseif ( SpellBookFrame.bookType == BOOKTYPE_SPELL) then
currentPage = SPELLBOOK_PAGENUMBERS[SpellBookFrame.selectedSkillLine];
local _, _, _, numSlots = GetSpellTabInfo(SpellBookFrame.selectedSkillLine);
maxPages = ceil(numSlots/SPELLS_PER_PAGE);
end
return currentPage, maxPages;
end
local maxShines = 1;
local shineGet = {}
function SpellBook_GetAutoCastShine ()
local shine = shineGet[1];
if ( shine ) then
tremove(shineGet, 1);
else
shine = CreateFrame("FRAME", "AutocastShine" .. maxShines, SpellBookFrame, "SpellBookShineTemplate");
maxShines = maxShines + 1;
end
return shine;
end
function SpellBook_ReleaseAutoCastShine (shine)
if ( not shine ) then
return;
end
shine:Hide();
AutoCastShine_AutoCastStop(shine);
tinsert(shineGet, shine);
end
-------------------------------------------------------------------
--------------------- Update functions for tabs --------------------
-------------------------------------------------------------------
function SpellBookFrame_UpdateSkillLineTabs()
local numSkillLineTabs = GetNumSpellTabs();
for i=1, MAX_SKILLLINE_TABS do
local skillLineTab = _G["SpellBookSkillLineTab"..i];
local prevTab = _G["SpellBookSkillLineTab"..i-1];
if ( i <= numSkillLineTabs and SpellBookFrame.bookType == BOOKTYPE_SPELL ) then
local name, texture, _, _, isGuild, offSpecID, shouldHide, specID = GetSpellTabInfo(i);
if ( shouldHide ) then
_G["SpellBookSkillLineTab"..i.."Flash"]:Hide();
skillLineTab:Hide();
else
skillLineTab:SetNormalTexture(texture);
skillLineTab.tooltip = name;
skillLineTab:Show();
-- Set the selected tab
if ( SpellBookFrame.selectedSkillLine == i ) then
skillLineTab:SetChecked(true);
else
skillLineTab:SetChecked(false);
end
end
else
_G["SpellBookSkillLineTab"..i.."Flash"]:Hide();
skillLineTab:Hide();
end
end
end
function SpellBook_UpdatePlayerTab()
-- Setup skillline tabs
local _, _, offset, numSlots = GetSpellTabInfo(SpellBookFrame.selectedSkillLine);
SpellBookFrame.selectedSkillLineOffset = offset;
SpellBookFrame.selectedSkillLineNumSlots = numSlots;
SpellBookFrame_UpdatePages();
SpellBookFrame_UpdateSkillLineTabs();
SpellBookFrame_UpdateSpells();
end
function SpellBook_UpdatePetTab(showing)
SpellBookFrame.numPetSpells = HasPetSpells() or 0;
SpellBookFrame_UpdatePages();
SpellBookFrame_UpdateSpells();
end
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_kylepixel/wow-ui-source.git
git@gitee.com:mirrors_kylepixel/wow-ui-source.git
mirrors_kylepixel
wow-ui-source
wow-ui-source
master

搜索帮助