CWDG论坛-专业魔兽插件's Archiver

qq59079493 发表于 2008-6-2 21:53

MinimapToggle 地图切换

请教 各位 谁能模仿 ChatToggle 制作个 MinimapToggle  每次按/script ToggleMinimap() 有些麻烦

    目前是 ChatToggle.lua

     -- ChatToggle 2.4.02
local CT_Ver="2.4.02"
local CTTag="|c00FFFF66Chattoggle "..CT_Ver.."|r: "
local CTstateOnMsg = "Automatically hiding chat windows when in combat"
local CTstateOffMsg = "Automatic chat window hiding is disabled"
local hidden = false
local CTg = getfenv(0)
local ORIG_ChatFrame_OnUpdate = ChatFrame_OnUpdate;
local function posthook(...)
   if (hidden) then
  this:Hide()
end
return ... -- this returns all the original's returns, which were passed to us   
end
function ChatFrame_OnUpdate(...)
return posthook(ORIG_ChatFrame_OnUpdate(...))
end
--  local constants
local HIDE = true
local SHOW = false
local function ChatMsg(msg)
DEFAULT_CHAT_FRAME:AddMessage(msg)
end
local function CToggle(action)
if (action == SHOW) then
  for i = 1,7 do
   if (CTChatWindows[i]) then
    CTg["ChatFrame"..i]:Show()
    CTg["ChatFrame"..i.."Tab"]:Show()
    CTg["ChatFrame"..i.."TabDockRegion"]:Show()
   end
  end
elseif (action == HIDE) then
  for i = 1,7 do
   local cframe = CTg["ChatFrame"..i]
   if(cframe:IsShown()) then
    CTg["ChatFrame"..i]:Hide()
    CTg["ChatFrame"..i.."Tab"]:Hide()
    CTg["ChatFrame"..i.."TabDockRegion"]:Hide()
    CTChatWindows[i] = true
   else
    CTChatWindows[i] = false
   end
  end
end
end
local function SetState(state)
if (state) then
  CTChatWindows["auto"] = true
  ChatMsg(CTTag..CTstateOnMsg)
else
  CTChatWindows["auto"] = false
  CToggle(SHOW)
  ChatMsg(CTTag..CTstateOffMsg)
end
end
function CTOnLoad()
this:RegisterEvent("PLAYER_ENTERING_WORLD")
this:RegisterEvent("PLAYER_REGEN_DISABLED")
this:RegisterEvent("PLAYER_REGEN_ENABLED")
-- define slash command handler
SlashCmdList["CHATTOGGLE"] = function(cmd)
  local msg
  if (cmd == "on") then
   SetState(true)
   msg = CTTag..CTstateOnMsg
  elseif (cmd == "off") then
   SetState(false)
   msg = CTTag..CTstateOffMsg
  else
   ChatMsg(CTTag.."use|c0066FF66  /chattogle (or /ct) <arg>:")
   ChatMsg("|c0066FF66  <arg> = on       - |rauto hide chat windows in combat")
   ChatMsg("|c0066FF66  <arg> = off   - |rdisable |c0033CC99ChatToggle|r")
   if(CTChatWindows["auto"]) then
    msg = "|c0066FFFFcurrent setting: "..CTstateOnMsg
   else
    msg = "|c0066FFFFcurrent setting: "..CTstateOffMsg
   end
  end
  ChatMsg(msg)
end
SLASH_CHATTOGGLE1 = "/chattoggle"
SLASH_CHATTOGGLE2 = "/ct"
end
function CTOnEvent()
if (event == "PLAYER_ENTERING_WORLD") then
  if( not CTChatWindows) then
   -- initialize table
   CTChatWindows = {}
   CTChatWindows["auto"] = true
   for i = 1,7 do
    local cframe = CTg["ChatFrame"..i]
    if (cframe:IsShown()) then
     CTChatWindows[i] = true
    else
     CTChatWindows[i] = false
    end
   end
  end
  CToggle(SHOW)
  hidden = false
  if(CTChatWindows["auto"]) then
   ChatMsg(CTTag.."loaded: "..CTstateOnMsg)
  else
   ChatMsg(CTTag.."loaded: "..CTstateOffMsg)
  end
elseif (CTChatWindows["auto"]) then
  if (event == "PLAYER_REGEN_DISABLED") then
   hidden = true
   CToggle(HIDE)
  elseif (event == "PLAYER_REGEN_ENABLED") then
   hidden = false
   CToggle(SHOW)
  end
end
end

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.