⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 playerlinkmenu.lua

📁 时间太紧了
💻 LUA
字号:


local oldSetItemRef;
local PlayerLinkMenuDragging;

function PlayerLinkMenu_OnLoad()
  gLim_RegisterButton (
	"REG",
	"玩家链接设置",
	"Interface\\AddOns\\PlayerLinkMenu\\Icon",
	function()
		PlayerLinkMenu_ToggleOptionsFrame();
	end,
	1,
	2
	);
  -- Hook the new functions instead of the old ones.
  oldSetItemRef = SetItemRef;
  SetItemRef = PlayerLinkMenu_SetItemRef;

  SLASH_PLM1 = "/plm";
  SlashCmdList["PLM"] = function()
    PlayerLinkMenu_ToggleOptionsFrame();
  end

  this:RegisterForDrag("LeftButton");
  this:RegisterEvent("VARIABLES_LOADED");

  PlayerLinkMenuDragging = false;

  table.insert(UISpecialFrames, "PlayerLinkMenuFrame");
  table.insert(UISpecialFrames, "PlayerLinkMenuOptions");
end


function PlayerLinkMenu_OnEvent(event)
  if (event == "VARIABLES_LOADED") then
    if (VipersAddonsLoaded) then
      local tablePos = table.getn(VipersAddonsLoaded)+1;
      VipersAddonsLoaded[tablePos] = {};
      VipersAddonsLoaded[tablePos]["NAME"] = PLAYERLINKMENU_NAME;
      VipersAddonsLoaded[tablePos]["VERSION"] = PLAYERLINKMENU_VERSION;
      VipersAddonsLoaded[tablePos]["OPTIONSFRAME"] = "PlayerLinkMenuOptions";
    end

    PLAYERLINKMENU_PLAYERNAME = UnitName("player");

    -- Clean up settings from very old versions --
    if ((PlayerLinkMenuSettings) and (PlayerLinkMenuSettings["NONE"])) then
      PlayerLinkMenuSettings = {};
    end

    -- Register for new settings --
    if (not PlayerLinkMenuSettings) then
      PlayerLinkMenuSettings = {};
    end

    -- Register settings for each unique player name --
    if (not PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]) then
      PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME] = {};
      PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["HASMOVED"] = false;
      PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["POSBOTTOM"] = 95;
      PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["POSLEFT"] = 30;
      PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["MENUSETTINGS"] = {};
      for i, v in plmOptions do
        PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME][v.key] = v.default;
      end
    end

    -- Create new keys for each mouse button --
    if (PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["LEFT"] == nil) then
      -- Copy previous settings to the new keys and remote the old ones --
      local none, shift, ctrl, alt = 4, 3, 1, 2;
      if (PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["NONE"] ~= nil) then
        none = tonumber(PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["NONE"]);
        PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["NONE"] = nil;
      end
      if (PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["SHIFT"] ~= nil) then
        shift = tonumber(PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["SHIFT"]);
        PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["SHIFT"] = nil;
      end
      if (PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["CTRL"] ~= nil) then
        ctrl = tonumber(PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["CTRL"]);
        PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["CTRL"] = nil;
      end
      if (PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["ALT"] ~= nil) then
        alt = tonumber(PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["ALT"]);
        PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["ALT"] = nil;
      end

      PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["LEFT"] = {};
      PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["LEFT"]["NONE"] = none;
      PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["LEFT"]["SHIFT"] = shift;
      PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["LEFT"]["CTRL"] = ctrl;
      PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["LEFT"]["ALT"] = alt;
    end
    if (PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["RIGHT"] == nil) then
      PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["RIGHT"] = {};
      PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["RIGHT"]["NONE"] = 1;
      PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["RIGHT"]["SHIFT"] = 0;
      PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["RIGHT"]["CTRL"] = 0;
      PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["RIGHT"]["ALT"] = 0;
    end

    -- Create new key for storing user changes to the menu --
    if (PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["MENUSETTINGS"] == nil) then
      PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["MENUSETTINGS"] = {};
    end
    -- Set new keys, if any --
    for i, v in plmOptions do
      if (PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME][v.key] == nil) then
        PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME][v.key] = v.default;
      end
    end

    PLAYERLINKMENU_TIMEOUT = PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["TIMEOUT"];

    -- Create the actions currently enabled --
    PlayerLinkMenu_GenerateActions();

    return;
  end
end


function PlayerLinkMenu_GenerateActions()
  plmActionsInUse = {};
  for i, v in plmActions do
    pos = i;
    tmp = v;
    tmp.index = i;
    tmp.label = plmLabels[i];
    if (PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["MENUSETTINGS"][i] ~= nil) then
      for n, k in PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["MENUSETTINGS"][i] do
        tmp[n] = k;
      end
      if (tmp.pos) then
        pos = tmp.pos;
        tmp.pos = nil;
      end
    end
    if ((tmp.visible == true) and (tmp.onlyKey ~= true)) then
      plmActionsInUse[pos] = tmp;
    end
  end
end


function PlayerLinkMenu_OnClick()
  local id = this:GetID();
  if (PLAYERLINKMENU_STOREDNAME == nil) then
    return;
  end

  local doAction = plmActions[id].action;
  doAction(PLAYERLINKMENU_STOREDNAME);

  PLAYERLINKMENU_STOREDNAME = nil;
  PlayerLinkMenuFrame:Hide();
end


function PlayerLinkMenu_OnUpdate(elapsed)
  if ((not PlayerLinkMenuDragging) and (PlayerLinkMenuFrame:IsVisible())) then
    local timeleft = PlayerLinkMenuFrame.timeleft - elapsed;
    if (timeleft <= 0) then
      PlayerLinkMenuFrame:Hide();
      return;
    end
    PlayerLinkMenuFrame.timeleft = timeleft;
  end
end


function PlayerLinkMenu_OnDragStart()
  if (not PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["FROZEN"]) then
    PlayerLinkMenuDragging = true;
    PlayerLinkMenuFrame:StartMoving();
  end
end


function PlayerLinkMenu_OnDragStop()
  if (PlayerLinkMenuDragging) then
    PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["HASMOVED"] = true;
    PlayerLinkMenuFrame:StopMovingOrSizing();
    PlayerLinkMenuDragging = false;
    PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["POSLEFT"] = PlayerLinkMenuFrame:GetLeft();
    PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["POSBOTTOM"] = PlayerLinkMenuFrame:GetBottom();
  end
end


function PlayerLinkMenu_SetItemRef(link, text, button)
  local frameName = this:GetName();
  local link, text, button;
  if (not link) then
    link = arg1;
  end
  if (not text) then
    text = arg2;
  end
  if (not button) then
    button = arg3;
  end
  if ((not link) or (not button)) then
    return;
  end
  if (strsub(strlower(link), 1, 6) == "player") then
    local name = strsub(link, 8);
    if ((name) and (strlen(name) > 0)) then
      local offset = 1;
      local paramCutPos = string.find(name, " ", offset);
      while (paramCutPos) do
        offset = paramCutPos+1;
        paramCutPos = string.find(name, " ", offset);
      end
      name = strsub(name, offset);

      local doAction;
      local usedButton = "LEFT";
      local key = "NONE";
      if (button == "RightButton") then
        usedButton = "RIGHT";
      end
      if (IsShiftKeyDown()) then
        key = "SHIFT";
      elseif (IsControlKeyDown()) then
        key = "CTRL";
      elseif (IsAltKeyDown()) then
        key = "ALT";
      end
      doAction = PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME][usedButton][key];
      if (doAction > 0) then
        doAction = plmActions[doAction].action;
        doAction(name, frameName);
      end
    end
    return;
  end
  oldSetItemRef(link, text, button);
end


function PlayerLinkMenu_DoWhisper(name)
  DEFAULT_CHAT_FRAME.editBox.chatType = "WHISPER";
  DEFAULT_CHAT_FRAME.editBox.tellTarget = name;
  ChatEdit_UpdateHeader(DEFAULT_CHAT_FRAME.editBox);
  if (not DEFAULT_CHAT_FRAME.editBox:IsVisible()) then
    ChatFrame_OpenChat("", DEFAULT_CHAT_FRAME);
  end
end

-- 获取名字

function PlayerLinkMenu_GetName(name)
  DEFAULT_CHAT_FRAME.editBox:Hide();
  DEFAULT_CHAT_FRAME.editBox.chatType = "SAY";
  ChatEdit_UpdateHeader(DEFAULT_CHAT_FRAME.editBox);
  if (not DEFAULT_CHAT_FRAME.editBox:IsVisible()) then
    ChatFrame_OpenChat(name, DEFAULT_CHAT_FRAME);
  end
end

-- 获取名字

function PlayerLinkMenu_DoWindow(name, frameName)
  PLAYERLINKMENU_STOREDNAME = name;
  PlayerLinkMenuFrame.timeleft = PLAYERLINKMENU_TIMEOUT;
  local width, btn;
  local maxWidth = 0;
  local titleOffset = 0;

  if (PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["SHOWNAME"]) then
    PlayerLinkMenuTitle:SetText(" "..name.." ");
    PlayerLinkMenuTitle:Show();
    maxWidth = PlayerLinkMenuTitle:GetStringWidth();
  else
    PlayerLinkMenuTitle:Hide();
    titleOffset = PLAYERLINKMENU_TITLE_HEIGHT;
  end

  local i = 1;
  local pos;
  for index, value in plmActionsInUse do
    btn = getglobal("PlayerLinkMenuButton"..i);
    if (btn == nil) then
      return;
    end

    btn:SetText(value.label);

    if (i == 1) then
      btn:ClearAllPoints();
      if (PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["SHOWNAME"]) then
        btn:SetPoint("TOP", "PlayerLinkMenuTitle", "BOTTOM", 0, -8);
      else
        btn:SetPoint("TOP", "PlayerLinkMenuFrame", "TOP", 0, -14);
      end
    elseif (i > 1) then
      btn:ClearAllPoints();
      btn:SetPoint("TOP", "PlayerLinkMenuButton"..(i-1), "BOTTOM", 0, -PLAYERLINKMENU_SPACER_SPACING);
    end

    if (PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["TOOLTIP"]) then
      btn.tooltip = value.tooltip;
    else
      btn.tooltip = nil;
    end

    pos = index;
    if (value.index) then
      pos = value.index;
    end
    btn:SetID(pos);
    btn:Show();

    width = btn:GetTextWidth();
    if (width > maxWidth) then
      maxWidth = width;
    end

    i = i + 1;
  end
  local buttons = i;

  if (i == 1) then
    PlayerLinkMenuFrame:Hide();
    return;
  end

  while (true) do
    btn = getglobal("PlayerLinkMenuButton"..i);
    if (btn) then
      btn:Hide();
    else
      break;
    end
    i = i + 1;
  end

  i = 1;
  for index, value in plmActionsInUse do
    local btn = getglobal("PlayerLinkMenuButton"..i);
    btn:SetWidth(maxWidth);
    i = i + 1;
  end

  local height = ((PLAYERLINKMENU_TITLE_HEIGHT - titleOffset) + (buttons * PLAYERLINKMENU_BUTTON_HEIGHT) + (2 * PLAYERLINKMENU_BORDER_HEIGHT));
  height = height + (buttons * PLAYERLINKMENU_SPACER_SPACING) + 4;
  local width = maxWidth + (2 * PLAYERLINKMENU_BORDER_WIDTH);

  if (PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["POSATCURSOR"]) then
    local mX, mY = GetCursorPosition();
    mX = math.floor(mX)+2;
    mY = math.floor(mY)+2;
    PlayerLinkMenuFrame:ClearAllPoints();
    PlayerLinkMenuFrame:SetPoint("BOTTOMLEFT", "UIParent", "BOTTOMLEFT", mX, mY);
  else
    PlayerLinkMenuFrame:ClearAllPoints();
    PlayerLinkMenuFrame:SetPoint("BOTTOMLEFT", "UIParent", "BOTTOMLEFT", PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["POSLEFT"], PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["POSBOTTOM"]);
  end

  PlayerLinkMenuFrame:SetHeight(height);
  PlayerLinkMenuFrame:SetWidth(width);
  PlayerLinkMenuFrame:Show();
end


function PlayerLinkMenu_ResetWindow()
  PlayerLinkMenuFrame:ClearAllPoints();
  PlayerLinkMenuFrame:SetPoint("BOTTOMLEFT", "UIParent", "BOTTOMLEFT", 30, 95);
  PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["HASMOVED"] = false;
  PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["POSBOTTOM"] = 95;
  PlayerLinkMenuSettings[PLAYERLINKMENU_PLAYERNAME]["POSLEFT"] = 30;
  if (DEFAULT_CHAT_FRAME) then
    DEFAULT_CHAT_FRAME:AddMessage("[Player Link Menu] 菜单窗口显示时间已恢复到默认设置.");
  end
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -