📄 applebar.lua
字号:
function AppleBar_ThisSetText(text)
getglobal(this:GetName().."Text"):SetText(text);
end
function Apple1DropDown_OnShow()
UIDropDownMenu_Initialize(this, Apple1DropDown_Initialize);
UIDropDownMenu_SetSelectedID(Apple1DropDown,AppleBarSaved.AppleBarButton12.id/12)
UIDropDownMenu_SetWidth(40);
end
function Apple1DropDown_Initialize()
local info = {};
local i;
for i = 1,12 do
info = {};
info.text = i;
info.func = Apple1DropDown_OnClick;
UIDropDownMenu_AddButton(info);
end
end
function Apple1DropDown_OnClick()
UIDropDownMenu_SetSelectedID(Apple1DropDown, this:GetID());
AppleBarCommand("setid 1="..this:GetID());
end
function Apple2DropDown_OnShow()
UIDropDownMenu_Initialize(this, Apple2DropDown_Initialize);
UIDropDownMenu_SetSelectedID(Apple2DropDown,AppleBarSaved.AppleBarButton24.id/12)
UIDropDownMenu_SetWidth(40);
end
function Apple2DropDown_Initialize()
local info = {};
local i;
for i = 1,12 do
info = {};
info.text = i;
info.func = Apple2DropDown_OnClick;
UIDropDownMenu_AddButton(info);
end
end
function Apple2DropDown_OnClick()
UIDropDownMenu_SetSelectedID(Apple2DropDown, this:GetID());
AppleBarCommand("setid 2="..this:GetID());
end
function Apple3DropDown_OnShow()
UIDropDownMenu_Initialize(this, Apple3DropDown_Initialize);
UIDropDownMenu_SetSelectedID(Apple3DropDown,AppleBarSaved.AppleBarButton36.id/12)
UIDropDownMenu_SetWidth(40);
end
function Apple3DropDown_Initialize()
local info = {};
local i;
for i = 1,12 do
info = {};
info.text = i;
info.func = Apple3DropDown_OnClick;
UIDropDownMenu_AddButton(info);
end
end
function Apple3DropDown_OnClick()
UIDropDownMenu_SetSelectedID(Apple3DropDown, this:GetID());
AppleBarCommand("setid 3="..this:GetID());
end
function Apple4DropDown_OnShow()
UIDropDownMenu_Initialize(this, Apple4DropDown_Initialize);
UIDropDownMenu_SetSelectedID(Apple4DropDown,AppleBarSaved.AppleBarButton48.id/12)
UIDropDownMenu_SetWidth(40);
end
function Apple4DropDown_Initialize()
local info = {};
local i;
for i = 1,12 do
info = {};
info.text = i;
info.func = Apple4DropDown_OnClick;
UIDropDownMenu_AddButton(info);
end
end
function Apple4DropDown_OnClick()
UIDropDownMenu_SetSelectedID(Apple4DropDown, this:GetID());
AppleBarCommand("setid 4="..this:GetID());
end
function AppleBar_Init()
local i,k,v,a,b,c,d;
if(not AppleBarSaved) then
AppleBarSaved = {};
AppleBarSaved["LockIcon"] = nil;
AppleBarSaved["showgrid"] = 0;
AppleBarSaved["group"] = {};
AppleBarSaved["number"] = nil;
AppleBarSaved["scale"] = 1;
for i=1,48 do
AppleBarSaved["AppleBarButton"..i] = {};
AppleBarSaved["AppleBarButton"..i]["hotkey"] = nil;
AppleBarSaved["AppleBarButton"..i]["hide"] = 1;
AppleBarSaved["AppleBarButton"..i]["id"] = i+72;
end
end
for k,v in AppleBarSaved["group"] do
a,b,c,d = string.find(v["buttons"],"(%d+)-(%d+)")
if( v["type"] == "horizontal" ) then
for i=c+1,d do
getglobal("AppleBarButton"..i):ClearAllPoints();
getglobal("AppleBarButton"..i):SetPoint( "TOPLEFT", getglobal("AppleBarButton"..i-1), "TOPRIGHT", 3, 0 );
end
else
for i=c+1,d do
getglobal("AppleBarButton"..i):ClearAllPoints();
getglobal("AppleBarButton"..i):SetPoint( "TOPLEFT", getglobal("AppleBarButton"..i-1), "BOTTOMLEFT", 0, -3 );
end
end
end
for i=1,48 do
local button=getglobal("AppleBarButton"..i);
button:SetID(AppleBarSaved["AppleBarButton"..i]["id"]);
button:Hide();
if( AppleBarSaved["showgrid"] == 1 ) then
button.showgrid = 1;
end
if( AppleBarSaved["AppleBarButton"..i]["hide"]==1 ) then
button:Hide();
elseif( HasAction(AppleButton_GetPagedID(button)) ) then
button:Show();
elseif( AppleBarSaved["showgrid"] == 1 ) then
getglobal(button:GetName().."NormalTexture"):SetVertexColor(1.0, 1.0, 1.0, 0.5);
button:Show();
end
end
if(AppleBarSaved["number"]) then
setcount();
else
setcount(1);
end
if(not AppleBarSaved["scale"]) then
AppleBarSaved["scale"] = 1;
end
setsize(AppleBarSaved["scale"]);
table.insert(CooldownCount_ButtonNames, "AppleBarButton");
--CooldownCountAppleBar_Saved_GenerateButtonUpdateList = CooldownCount_GenerateButtonUpdateList;
--CooldownCount_GenerateButtonUpdateList = CooldownCountAppleBar_GenerateButtonUpdateList;
CooldownCount_RegenerateList();
ChatFrame1:AddMessage("AppleBar设置读取完成,输入/ab进行设置,按住Ctrl拖动按钮。");
end
function CooldownCountAppleBar_GenerateButtonUpdateList()
local updateList = CooldownCountAppleBar_Saved_GenerateButtonUpdateList();
for i = 1, 48 do
name = getglobal("AppleBarButton".. i);
if ( name) then
table.insert(updateList, name);
end
end
return updateList;
end
function setsize(scale)
local i,button;
for i = 1,48 do
button=getglobal("AppleBarButton"..i);
button:SetScale(scale);
end
end
function setcount(key)
local i;
if( key ) then
for i = 1,48 do
getglobal("AppleBarButton"..i.."Count"):SetText(i);
end
else
for i = 1,48 do
getglobal("AppleBarButton"..i.."Count"):SetText("");
AppleBar_UpdateCount(getglobal("AppleBarButton"..i));
end
end
end
function APPLEBARButtonBindingCode(key,keystate)
local button = getglobal("AppleBarButton"..key);
local temptexture = GetActionTexture(AppleButton_GetPagedID(button));
if(keystate == "down") then
PlaceAction(AppleButton_GetPagedID(button));
if(GetActionTexture(AppleButton_GetPagedID(button)) ~= temptexture) then
return;
end
AppleButtonDown(key);
end
if(keystate == "up") then
AppleButtonUp(key);
end
end
function AppleBarCommand(msg)
msg = string.lower(msg)
local a,b,c,d,e,i;
if( msg == "showgroup" ) then
AppleGroupShow();
return;
end
a,b,c,d= string.find(msg,"(.+) (.+)");
if(not c) then
AppleBarOptionsFrame:Show();
AppleBarHelp();
return;
end
if( c == "hide" ) then
a,b,c,d = string.find(d,"(.+)=(.+)");
if(c == "button") then
if(string.find(d,"-")) then
a,b,c,d = string.find(d,"(%d+)-(%d+)");
if(c>=d) then
ChatFrame1:AddMessage("必须把序号小的按钮放前面");
return;
end
for i=c,d do
AppleBarSaved["AppleBarButton"..i]["hide"] = 1;
getglobal("AppleBarButton"..i):Hide();
end
else
AppleBarSaved["AppleBarButton"..tonumber(d)]["hide"] = 1;
getglobal("AppleBarButton"..tonumber(d)):Hide();
end
end
elseif( c == "show" ) then
a,b,c,d = string.find(d,"(.+)=(.+)");
if(c == "button") then
if(string.find(d,"-")) then
a,b,c,d = string.find(d,"(%d+)-(%d+)");
if(c>=d) then
ChatFrame1:AddMessage("必须把序号小的按钮放前面");
return;
end
for i=c,d do
AppleBarSaved["AppleBarButton"..i]["hide"] = nil;
getglobal("AppleBarButton"..i):Show();
end
else
AppleBarSaved["AppleBarButton"..tonumber(d)]["hide"] = nil;
getglobal("AppleBarButton"..tonumber(d)):Show();
end
end
elseif( c == "showgrid" ) then
if( not d ) then
return;
end
if(d == "on") then
AppleBarSaved["showgrid"] = 1;
for i = 1,48 do
if(not AppleBarSaved["AppleBarButton"..i]["hide"]) then
AppleButton_ShowGrid(getglobal("AppleBarButton"..i));
end
getglobal("AppleBarButton"..i).showgrid = 1;
end
elseif( d == "off" ) then
AppleBarSaved["showgrid"] = 0;
for i = 1,48 do
if( not HasAction(AppleButton_GetPagedID(getglobal("AppleBarButton"..i)))) then
getglobal("AppleBarButton"..i):Hide();
end
getglobal("AppleBarButton"..i).showgrid = 0;
end
end
elseif( c == "shownumber" ) then
if( not d ) then
return;
end
if(d == "on") then
AppleBarSaved["number"] = 1;
setcount();
elseif( d == "off" ) then
AppleBarSaved["number"] = nil;
setcount(1);
end
elseif( c == "lockicon" ) then
if( not d ) then
return;
end
if(d == "on") then
AppleBarSaved["LockIcon"] = 1;
elseif( d == "off" ) then
AppleBarSaved["LockIcon"] = nil;
end
elseif( c == "setid" ) then
a,b,c,d = string.find(d,"(.+)=(.+)");
if( not c or not d) then
ChatFrame1:AddMessage("缺少参数");
return;
end
c=tonumber(c);
d=tonumber(d);
if(c<1 or c>4 or d<1 or d>12) then
ChatFrame1:AddMessage("参数错误");
return;
end
c = (c-1)*12+1;
d = (d-1)*12+1;
for a = c,c+11 do
local id = d+a-c;
getglobal("AppleBarButton"..a):SetID(id);
AppleBarButton_Update(getglobal("AppleBarButton"..a));
AppleBarSaved["AppleBarButton"..a]["id"] = id;
end
elseif( c == "group" ) then
a,b,c,d = string.find(d,"(.+)=(.+)");
if( d=="h" or d=="horizontal" ) then
a,b,c,d = string.find(c,"(%d+)-(%d+)");
--getglobal("AppleBarButton"..c):SetPoint( "RIGHT", getglobal("AppleBarButton"..d), "LEFT", -3*(d-c), 0 );
if(tonumber(c)>=tonumber(d)) then
ChatFrame1:AddMessage("必须把序号小的按钮放前面");
return;
end
for i=c+1,d do
getglobal("AppleBarButton"..i):ClearAllPoints();
getglobal("AppleBarButton"..i):SetPoint( "TOPLEFT", getglobal("AppleBarButton"..i-1), "TOPRIGHT", 3, 0 );
end
e={};
e["type"]="horizontal";
e["buttons"]=c.."-"..d;
tinsert(AppleBarSaved["group"],e);
elseif (d=="v" or d=="vertical") then
a,b,c,d = string.find(c,"(%d+)-(%d+)");
--getglobal("AppleBarButton"..c):SetPoint( "RIGHT", getglobal("AppleBarButton"..d), "LEFT", -3*(d-c), 0 );
if(tonumber(c)>=tonumber(d)) then
ChatFrame1:AddMessage("必须把序号小的按钮放前面");
return;
end
for i=c+1,d do
getglobal("AppleBarButton"..i):ClearAllPoints();
getglobal("AppleBarButton"..i):SetPoint( "TOPLEFT", getglobal("AppleBarButton"..i-1), "BOTTOMLEFT", 0, -3 );
end
e={};
e["type"]="vertical";
e["buttons"]=c.."-"..d;
tinsert(AppleBarSaved["group"],e);
end
elseif( c == "ungroup" ) then
if(AppleBarSaved["group"][tonumber(d)]) then
_,_,a,b = string.find(AppleBarSaved["group"][tonumber(d)]["buttons"],"(%d+)-(%d+)");
for i=a,b do
getglobal("AppleBarButton"..i):ClearAllPoints();
end
AppleBarSaved["group"][tonumber(d)] = nil;
AppleGroupShow();
else
ChatFrame1:AddMessage("无效的按钮组");
end
elseif( c == "showhotkey" ) then
if( not d ) then
return;
end
if(d == "on") then
AppleBarSaved["number"] = 1;
setcount(1);
elseif( d == "off" ) then
AppleBarSaved["number"] = nil;
setcount();
end
elseif( c == "setscale" ) then
if( not d ) then
ChatFrame1:AddMessage("必须输入缩放比例");
return;
end
d = tonumber(d);
if( not d ) then
ChatFrame1:AddMessage("无效的缩放比例");
return;
end
if(d < 0.5 or d > 1.5) then
ChatFrame1:AddMessage("缩放比例必须在0.5和1.5之间");
return;
end
AppleBarSaved["scale"] = d;
setsize(AppleBarSaved["scale"]);
end
end
function AppleBarOnUpdates(elapsed)
if(elapsed - currenttime > 2) then
AppleBar_Init();
AppleBarOnUpdate:Hide();
end
end
function AppleBarHelp()
ChatFrame1:AddMessage("月光快捷按钮使用帮助:",0,0.8,0);
ChatFrame1:AddMessage("/ab setid A=B:改变按钮的ID号,A和B的取值范围是1到12",0,0.8,0)
ChatFrame1:AddMessage("/ab group A-B=type:按钮要小的放前面,type可以是h(水平)或者v(垂直)",0,0.8,0)
ChatFrame1:AddMessage("/ab ungroup A:group是已经存在的按钮组",0,0.8,0)
ChatFrame1:AddMessage("/ab showgroup:显示当前按钮组情况",0,0.8,0)
ChatFrame1:AddMessage("/ab showgrid on|off:自动显示/隐藏空的按钮",0,0.8,0)
ChatFrame1:AddMessage("/ab show button=A-B:显示按钮A-B",0,0.8,0)
ChatFrame1:AddMessage("/ab hide button=A-B:隐藏按钮A-B",0,0.8,0)
ChatFrame1:AddMessage("/ab lockicon on|off:解锁/锁定图标",0,0.8,0)
ChatFrame1:AddMessage("/ab setscale X:设置按钮缩放比例",0,0.8,0)
end
function AppleBarMoving(button)
local k,v,canmove,num;
canmove = true;
num = tonumber(string.sub(button:GetName(),15));
for k,v in AppleBarSaved["group"] do
a,b,c,d = string.find(v["buttons"],"(%d+)-(%d+)")
c = tonumber(c);
d = tonumber(d);
if(num>=c and num<=d) then
if(num == c) then
break;
else
canmove = nil;
end
end
end
if( canmove ) then
button:StartMoving();
end
end
function AppleGroupShow()
local k,v;
for k,v in AppleBarSaved["group"] do
ChatFrame1:AddMessage("按钮组"..k..":".."按钮"..v["buttons"].." 对齐类型:"..v["type"]);
end
end
function scale_onshow()
getglobal(this:GetName().."Text"):SetText("按钮尺寸--"..floor(AppleBarSaved["scale"]*100).."%");
getglobal(this:GetName().."High"):SetText("150%");
getglobal(this:GetName().."Low"):SetText("50%");
this:SetMinMaxValues(0.5, 1.5);
this:SetValueStep(0.01);
this:SetValue(AppleBarSaved["scale"]);
this.tooltipText = "拖动进度条来改变增强按钮的尺寸";
end
function scale_onvaluechange()
AppleBarSaved["scale"] = this:GetValue();
getglobal(this:GetName().."Text"):SetText("按钮尺寸--"..floor(AppleBarSaved["scale"]*100).."%");
setsize(AppleBarSaved["scale"]);
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -