Skip to content

Commit c562f18

Browse files
committed
修改快捷键相关函数
1 parent 661e175 commit c562f18

File tree

12 files changed

+70
-46
lines changed

12 files changed

+70
-46
lines changed

MYDev_Snaplines/src/MYDev_Snaplines.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -493,14 +493,14 @@ MY.RegisterPanel(
493493
end
494494
})
495495
-- 注册快捷键
496-
MY.Game.AddHotKey("Dev_Snaplines" , _L["Snaplines"] , function() MYDev_Snaplines.bEnable = not MYDev_Snaplines.bEnable MYDev_Snaplines.ReloadUI() end, nil)
497-
MY.Game.AddHotKey("Dev_Snaplines_ShowTip" , _L["Snaplines - ShowTip"] , function() MYDev_Snaplines.bShowTip = not MYDev_Snaplines.bShowTip MYDev_Snaplines.ReloadUI() end, nil)
498-
MY.Game.AddHotKey("Dev_Snaplines_ShowData", _L["Snaplines - ShowData"], function() MYDev_Snaplines.bShowData = not MYDev_Snaplines.bShowData MYDev_Snaplines.ReloadUI() end, nil)
496+
MY.Game.RegisterHotKey("MY_Dev_Snaplines" , _L["Snaplines"] , function() MYDev_Snaplines.bEnable = not MYDev_Snaplines.bEnable MYDev_Snaplines.ReloadUI() end, nil)
497+
MY.Game.RegisterHotKey("MY_Dev_Snaplines_ShowTip" , _L["Snaplines - ShowTip"] , function() MYDev_Snaplines.bShowTip = not MYDev_Snaplines.bShowTip MYDev_Snaplines.ReloadUI() end, nil)
498+
MY.Game.RegisterHotKey("MY_Dev_Snaplines_ShowData", _L["Snaplines - ShowData"], function() MYDev_Snaplines.bShowData = not MYDev_Snaplines.bShowData MYDev_Snaplines.ReloadUI() end, nil)
499499
-- For Debug
500500
if IsDebugClient and IsDebugClient() then
501501
MY.RegisterInit("Dev_Snaplines_Hotkey", function()
502-
MY.Game.SetHotKey("Dev_Snaplines", 121)
503-
MY.Game.SetHotKey("Dev_Snaplines_ShowTip", 122)
504-
MY.Game.SetHotKey("Dev_Snaplines_ShowData", 123)
502+
MY.Game.SetHotKey("MY_Dev_Snaplines", 121)
503+
MY.Game.SetHotKey("MY_Dev_Snaplines_ShowTip", 122)
504+
MY.Game.SetHotKey("MY_Dev_Snaplines_ShowData", 123)
505505
end)
506506
end

MY_!Base/src/MY.Game.lua

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@
77
-- @Last modified time: 2016-12-06 14:49:07
88
-- @Ref: 借鉴大量海鳗源码 @haimanchajian.com
99
--------------------------------------------
10+
-----------------------------------------------------------------------------------------
11+
-- these global functions are accessed all the time by the event handler
12+
-- so caching them is worth the effort
13+
-----------------------------------------------------------------------------------------
14+
local setmetatable = setmetatable
15+
local ipairs, pairs, next, pcall = ipairs, pairs, next, pcall
16+
local sub, len, format, rep = string.sub, string.len, string.format, string.rep
17+
local find, byte, char, gsub = string.find, string.byte, string.char, string.gsub
18+
local type, tonumber, tostring = type, tonumber, tostring
19+
local floor, min, max, ceil = math.floor, math.min, math.max, math.ceil
20+
local huge, pi, sin, cos, tan = math.huge, math.pi, math.sin, math.cos, math.tan
21+
local insert, remove, concat, sort = table.insert, table.remove, table.concat, table.sort
22+
local pack, unpack = table.pack or function(...) return {...} end, table.unpack or unpack
23+
-- jx3 apis caching
24+
local wsub, wlen, wfind = wstring.sub, wstring.len, wstring.find
25+
local GetTime, GetLogicFrameCount = GetTime, GetLogicFrameCount
26+
local GetClientPlayer, GetPlayer, GetNpc = GetClientPlayer, GetPlayer, GetNpc
27+
local GetClientTeam, UI_GetClientPlayerID = GetClientTeam, UI_GetClientPlayerID
28+
-----------------------------------------------------------------------------------------
1029
-----------------------------------------------
1130
-- 本地函数和变量
1231
-----------------------------------------------
@@ -31,37 +50,28 @@ local _C = {}
3150
-- #######################################################################################################
3251
_Cache.tHotkey = {}
3352
-- 增加系统快捷键
34-
-- (void) MY.AddHotKey(string szName, string szTitle, func fnAction) -- 增加系统快捷键
35-
function MY.Game.AddHotKey(szName, szTitle, fnAction)
36-
if string.sub(szName, 1, 3) ~= "MY_" then
37-
szName = "MY_" .. szName
38-
end
39-
table.insert(_Cache.tHotkey, { szName = szName, szTitle = szTitle, fnAction = fnAction })
53+
-- (void) MY.RegisterHotKey(string szName, string szTitle, func fnAction) -- 增加系统快捷键
54+
function MY.Game.RegisterHotKey(szName, szTitle, fnAction)
55+
insert(_Cache.tHotkey, { szName = szName, szTitle = szTitle, fnAction = fnAction })
4056
end
41-
MY.AddHotKey = MY.Game.AddHotKey
57+
MY.RegisterHotKey = MY.Game.RegisterHotKey
4258

4359
-- 获取快捷键名称
44-
-- (string) MY.GetHotKeyName(string szName, boolean bBracket, boolean bShort) -- 取得快捷键名称
45-
function MY.Game.GetHotKeyName(szName, bBracket, bShort)
46-
if string.sub(szName, 1, 3) ~= "MY_" then
47-
szName = "MY_" .. szName
48-
end
60+
-- (string) MY.GetHotKeyDisplay(string szName, boolean bBracket, boolean bShort) -- 取得快捷键名称
61+
function MY.Game.GetHotKeyDisplay(szName, bBracket, bShort)
4962
local nKey, bShift, bCtrl, bAlt = Hotkey.Get(szName)
50-
local szKey = GetKeyShow(nKey, bShift, bCtrl, bAlt, bShort == true)
51-
if szKey ~= "" and bBracket then
52-
szKey = "(" .. szKey .. ")"
63+
local szDisplay = GetKeyShow(nKey, bShift, bCtrl, bAlt, bShort == true)
64+
if szDisplay ~= "" and bBracket then
65+
szDisplay = "(" .. szDisplay .. ")"
5366
end
54-
return szKey
67+
return szDisplay
5568
end
56-
MY.GetHotKeyName = MY.Game.GetHotKeyName
69+
MY.GetHotKeyDisplay = MY.Game.GetHotKeyDisplay
5770

5871
-- 获取快捷键
5972
-- (table) MY.GetHotKey(string szName, true , true ) -- 取得快捷键
6073
-- (number nKey, boolean bShift, boolean bCtrl, boolean bAlt) MY.GetHotKey(string szName, true , fasle) -- 取得快捷键
6174
function MY.Game.GetHotKey(szName, bBracket, bShort)
62-
if string.sub(szName, 1, 3) ~= "MY_" then
63-
szName = "MY_" .. szName
64-
end
6575
local nKey, bShift, bCtrl, bAlt = Hotkey.Get(szName)
6676
if nKey==0 then return nil end
6777
if bBracket then
@@ -79,10 +89,9 @@ MY.GetHotKey = MY.Game.GetHotKey
7989
-- (void) MY.SetHotKey(string szCommand, number nIndex, number nKey [, boolean bShift [, boolean bCtrl [, boolean bAlt] ] ]) -- 设置快捷键
8090
function MY.Game.SetHotKey(szCommand, nIndex, nKey, bShift, bCtrl, bAlt)
8191
if nIndex then
82-
if string.sub(szCommand, 1, 3) ~= "MY_" then
83-
szCommand = "MY_" .. szCommand
92+
if not nKey then
93+
nIndex, nKey = 1, nIndex
8494
end
85-
if not nKey then nIndex, nKey = 1, nIndex end
8695
Hotkey.Set(szCommand, nIndex, nKey, bShift == true, bCtrl == true, bAlt == true)
8796
else
8897
local szGroup = szCommand or MY.GetAddonInfo().szName
@@ -222,7 +231,7 @@ MY.RegisterInit('MYLIB#BIND_HOTKEY', function()
222231
Hotkey.AddBinding('MY_HotKey_Null_'..i, _L['none-function hotkey'], "", function() end, nil)
223232
end
224233
end)
225-
MY.Game.AddHotKey("MY_STOP_CASTING", _L["Stop cast skill"], function() GetClientPlayer().StopCurrentAction() end)
234+
MY.Game.RegisterHotKey("MY_STOP_CASTING", _L["Stop cast skill"], function() GetClientPlayer().StopCurrentAction() end)
226235
-- #######################################################################################################
227236
-- # # # # # # # # #
228237
-- # # # # # # # # # # # # # # # # # # # #
@@ -366,6 +375,17 @@ function MY.Game.GetObjectName(obj)
366375
end
367376
MY.GetObjectName = MY.Game.GetObjectName
368377

378+
function MY.GetDistance(nX, nY, nZ)
379+
local me = GetClientPlayer()
380+
if not nY and not nZ then
381+
local tar = nX
382+
nX, nY, nZ = tar.nX, tar.nY, tar.nZ
383+
elseif not nZ then
384+
return floor(((me.nX - nX) ^ 2 + (me.nY - nY) ^ 2) ^ 0.5)/64
385+
end
386+
return floor(((me.nX - nX) ^ 2 + (me.nY - nY) ^ 2 + (me.nZ/8 - nZ/8) ^ 2) ^ 0.5)/64
387+
end
388+
369389
do local MY_CACHE_BUFF = {}
370390
function MY.GetBuffName(dwBuffID, dwLevel)
371391
local xKey = dwBuffID
@@ -595,6 +615,9 @@ local MY_FORCE_COLOR = setmetatable({
595615
})
596616

597617
function MY.GetForceColor(dwForce)
618+
if dwForce == "all" then
619+
return MY_FORCE_COLOR
620+
end
598621
return unpack(MY_FORCE_COLOR[dwForce])
599622
end
600623
end

MY_!Base/src/MY.String.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ function MY.String.Trim(szText)
6767
end
6868
return (string.gsub(szText, "^%s*(.-)%s*$", "%1"))
6969
end
70+
MY.Trim = MY.String.Trim
7071

7172
function MY.String.LenW(str)
7273
return wstring.len(str)

MY_BagEx/src/MY_BagStatistics.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,4 +458,4 @@ local menu = {
458458
}
459459
MY.RegisterAddonMenu('MY_BAGSTATISTICS_MENU', menu)
460460
end
461-
MY.Game.AddHotKey("MY_BagStatistics", _L['MY_BagStatistics'], MY_BagStatistics.Toggle, nil)
461+
MY.Game.RegisterHotKey("MY_BagStatistics", _L['MY_BagStatistics'], MY_BagStatistics.Toggle, nil)

MY_ChatLog/src/MY_ChatLog.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,7 @@ local menu = {
12401240
}
12411241
MY.RegisterAddonMenu('MY_CHATLOG_MENU', menu)
12421242
end
1243-
MY.Game.AddHotKey("MY_ChatLog", _L['chat log'], MY_ChatLog.Toggle, nil)
1243+
MY.Game.RegisterHotKey("MY_ChatLog", _L['chat log'], MY_ChatLog.Toggle, nil)
12441244

12451245
local PS = {}
12461246
function PS.OnPanelActive(wnd)

MY_ChatMonitor/src/MY_ChatMonitor.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ _C.RegisterMsgMonitor = function()
590590
RegisterMsgMonitor(_C.OnMsgArrive, t)
591591
end
592592

593-
MY.Game.AddHotKey("MY_ChatMonitor_Hotkey", _L["chat monitor"],
593+
MY.Game.RegisterHotKey("MY_ChatMonitor_Hotkey", _L["chat monitor"],
594594
function()
595595
if MY_ChatMonitor.bCapture then
596596
MY.UI(MY.GetFrame()):find('#Button_ChatMonitor_Switcher'):text(_L['start'])

MY_GKP/src/MY_GKP.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1717,7 +1717,7 @@ RegisterEvent("MONEY_UPDATE",function() --
17171717
_GKP.MoneyUpdate(arg0, arg1, arg2)
17181718
end)
17191719

1720-
MY.AddHotKey("MY_GKP", _L["Open/Close Golden Team Record"], _GKP.TogglePanel)
1720+
MY.RegisterHotKey("MY_GKP", _L["Open/Close Golden Team Record"], _GKP.TogglePanel)
17211721
MY.RegisterAddonMenu({ szOption = _L["Golden Team Record"], fnAction = _GKP.OpenPanel })
17221722

17231723
RegisterEvent("LOADING_END",function()

MY_Logoff/src/MY_Logoff.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ local menu = {
196196
MY.RegisterAddonMenu('MY_LOGOFF_MENU', menu)
197197
end
198198

199-
MY.Game.AddHotKey('LogOff_RUI', _L['return to role list'], function() Logoff(false) end, nil)
200-
MY.Game.AddHotKey('LogOff_RRL', _L['return to game login'], function() Logoff(true) end, nil)
201-
MY.Game.AddHotKey('LogOff_RUI_UNFIGHT', _L['return to role list while not fight'], function() Logoff(false, true) end, nil)
202-
MY.Game.AddHotKey('LogOff_RRL_UNFIGHT', _L['return to game login while not fight'], function() Logoff(true, true) end, nil)
203-
MY.Game.AddHotKey('LogOff_RUI_UNFIGHT_ALIVE', _L['return to role list while not fight and not dead'], function() Logoff(false, true, true) end, nil)
204-
MY.Game.AddHotKey('LogOff_RRL_UNFIGHT_ALIVE', _L['return to game login while not fight and not dead'], function() Logoff(true, true, true) end, nil)
199+
MY.Game.RegisterHotKey('MY_LogOff_RUI', _L['return to role list'], function() Logoff(false) end, nil)
200+
MY.Game.RegisterHotKey('MY_LogOff_RRL', _L['return to game login'], function() Logoff(true) end, nil)
201+
MY.Game.RegisterHotKey('MY_LogOff_RUI_UNFIGHT', _L['return to role list while not fight'], function() Logoff(false, true) end, nil)
202+
MY.Game.RegisterHotKey('MY_LogOff_RRL_UNFIGHT', _L['return to game login while not fight'], function() Logoff(true, true) end, nil)
203+
MY.Game.RegisterHotKey('MY_LogOff_RUI_UNFIGHT_ALIVE', _L['return to role list while not fight and not dead'], function() Logoff(false, true, true) end, nil)
204+
MY.Game.RegisterHotKey('MY_LogOff_RRL_UNFIGHT_ALIVE', _L['return to game login while not fight and not dead'], function() Logoff(true, true, true) end, nil)

MY_ScreenShot/src/MY_ScreenShot.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ _MY_ScreenShot.OnPanelDeactive = function( ... )
166166
end
167167
-- 快捷键绑定
168168
-----------------------------------------------
169-
MY.Game.AddHotKey("MY_ScreenShot_Hotkey", _L["shotscreen"], function() MY_ScreenShot.ShotScreen((MY_ScreenShot.GetConfig('bAutoHideUI') and MY_ScreenShot.Const.HIDE_UI) or nil) end, nil)
170-
MY.Game.AddHotKey("MY_ScreenShot_Hotkey_HideUI", _L["shotscreen without ui"], function() MY_ScreenShot.ShotScreen(MY_ScreenShot.Const.HIDE_UI) end, nil)
171-
MY.Game.AddHotKey("MY_ScreenShot_Hotkey_ShowUI", _L["shotscreen with ui"], function() MY_ScreenShot.ShotScreen(MY_ScreenShot.Const.SHOW_UI) end, nil)
169+
MY.Game.RegisterHotKey("MY_ScreenShot_Hotkey", _L["shotscreen"], function() MY_ScreenShot.ShotScreen((MY_ScreenShot.GetConfig('bAutoHideUI') and MY_ScreenShot.Const.HIDE_UI) or nil) end, nil)
170+
MY.Game.RegisterHotKey("MY_ScreenShot_Hotkey_HideUI", _L["shotscreen without ui"], function() MY_ScreenShot.ShotScreen(MY_ScreenShot.Const.HIDE_UI) end, nil)
171+
MY.Game.RegisterHotKey("MY_ScreenShot_Hotkey_ShowUI", _L["shotscreen with ui"], function() MY_ScreenShot.ShotScreen(MY_ScreenShot.Const.SHOW_UI) end, nil)
172172
MY.RegisterPanel( "ScreenShot", _L["screenshot helper"], _L['System'], "UI/Image/UICommon/Commonpanel.UITex|9", {255,127,0,200}, { OnPanelActive = _MY_ScreenShot.OnPanelActive, OnPanelDeactive = _MY_ScreenShot.OnPanelDeactive } )

MY_TalkEx/src/MY_TalkEx.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ _C.Talk = function()
7676
end
7777
end
7878
end
79-
MY.Game.AddHotKey("MY_TalkEx_Talk", _L["TalkEx Talk"], _C.Talk, nil)
79+
MY.Game.RegisterHotKey("MY_TalkEx_Talk", _L["TalkEx Talk"], _C.Talk, nil)
8080

8181
_C.Trick = function()
8282
if #MY_TalkEx.szTrickText == 0 then

0 commit comments

Comments
 (0)