Files
wow-forever-addons/Halbklick/Halbklick.lua
T
mikeandClaude Opus 5.5 b1598a7701 Halbklick: Klick-Zauber wie Clique, getrennt nach Rahmenhälften
Neues Addon: Belegungen gelten für den ganzen Einheitenrahmen oder nur für
die linke oder rechte Hälfte, wahlweise nur für freundliche oder feindliche
Einheiten. Ein geschützter OnClick-Vorab-Handler liest GetMousePosition()
und leitet belegte Klicks über Button31 an einen eigenen Proxy-Button
weiter. Fenster mit /hk, Tests gegen nachgebaute Secure-Umgebung, ZIP neu.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 11:10:22 +01:00

749 lines
26 KiB
Lua

-- Halbklick: Klick-Zauber auf Einheitenrahmen, aehnlich wie Clique. Jede
-- Belegung gilt fuer den ganzen Rahmen oder nur fuer seine linke oder rechte
-- Haelfte. So passen z. B. zwei Heilzauber auf dieselbe Maustaste.
--
-- /hk Fenster mit allen Belegungen (auch /halbklick)
-- /hk liste Belegungen im Chat auflisten
-- /hk status angemeldete Rahmen und Zustand
--
-- So funktioniert es: Jeder angemeldete Rahmen bekommt einen geschuetzten
-- Vorab-Handler fuer OnClick (WrapScript). Der laeuft auch im Kampf. Er liest
-- die Mausposition im Rahmen (GetMousePosition: 0 = linker, 1 = rechter Rand),
-- die Modifikatortasten und ob die Einheit freundlich oder feindlich ist, und
-- sucht dazu eine Belegung. Gibt es eine, stellt er Aktion und Einheit am
-- eigenen Button "HalbklickProxy" ein und leitet den Klick als "Button31" und
-- mit der Aktion "click" dorthin. Ohne passende Belegung bleibt der Klick, wie
-- er ist (Linksklick Ziel, Rechtsklick Menue).
--
-- Warum "Button31": Blizzards Unit-Buttons reichen den Tastennamen an
-- C_ClickBindings.GetBindingType weiter. Ein erfundener Name waere dort ein
-- Risiko, eine echte Maustaste nicht. Maeuse mit 31 Tasten gibt es praktisch
-- nicht. Ein echter, unbelegter Button31-Klick wird verworfen, damit er nicht
-- die letzte Aktion am Proxy wiederholt.
--
-- Der Proxy ist ein normaler SecureActionButton. Blizzards eigene Unit-Buttons
-- pruefen bei "target" und "menu" die Klick-Bindungen von C_ClickBindings und
-- verwerfen den Klick, wenn es dort keine gibt. Ueber den Proxy funktionieren
-- auch diese Aktionen mit jeder Tastenkombination.
--
-- Geschuetzter Code darf weder "{", "}" noch das Wort "function" enthalten.
-- Zaubernamen und Makrotexte stehen deshalb nie im Code der Snippets, sondern
-- in Attributen des Kopf-Frames ("hkt:<Kombination>" Aktion, "hkv:..." Wert).
local ADDON = ...
-- Belegte Klicks laufen als "Button31" zum Proxy (siehe CLICK_SNIPPET). Die
-- Attribute dafuer enden auf "31", so wie "type1" zu LeftButton gehoert.
local ROUTE_SUFFIX = "31"
local PREFIX_TYPE, PREFIX_VALUE = "hkt:", "hkv:"
local BUTTONS = { "LeftButton", "RightButton", "MiddleButton", "Button4", "Button5" }
local BUTTON_NAME = {
LeftButton = "Linksklick", RightButton = "Rechtsklick", MiddleButton = "Mittelklick",
}
local AREAS = {
{ key = "A", name = "ganzer Rahmen" },
{ key = "L", name = "linke Hälfte" },
{ key = "R", name = "rechte Hälfte" },
}
local REACTIONS = {
{ key = "any", name = "alle" },
{ key = "help", name = "freundlich" },
{ key = "harm", name = "feindlich" },
}
-- type = Aktion am SecureActionButton, value = braucht Zaubername bzw. Makrotext
local ACTIONS = {
{ key = "spell", name = "Zauber", type = "spell", value = true },
{ key = "macro", name = "Makro", type = "macro", value = true },
{ key = "target", name = "Ziel auswählen", type = "target" },
{ key = "focus", name = "Fokus setzen", type = "focus" },
{ key = "menu", name = "Menü öffnen", type = "togglemenu" },
}
local function byKey(list)
local t = {}
for i, e in ipairs(list) do t[e.key] = e; e.order = i end
return t
end
local AREA, REACTION, ACTION = byKey(AREAS), byKey(REACTIONS), byKey(ACTIONS)
local BUTTON_ORDER = {}
for i, b in ipairs(BUTTONS) do BUTTON_ORDER[b] = i end
-- Andere Klick-Zauber-Addons, die sich mit Halbklick in die Quere kommen
local RIVALS = { "Clique", "CliqueForever", "ForeverClick", "HealingForever", "RankClick" }
-- Feste Blizzard-Rahmen. Kompakte Gruppen- und Schlachtzugsrahmen kommen
-- zusaetzlich ueber CompactUnitFrame_SetUnit dazu, sobald sie eine Einheit haben.
local BLIZZARD_FRAMES = {
"PlayerFrame", "PetFrame", "TargetFrame", "TargetFrameToT", "FocusFrame", "FocusFrameToT",
"Boss1TargetFrame", "Boss2TargetFrame", "Boss3TargetFrame", "Boss4TargetFrame", "Boss5TargetFrame",
}
local db
local ev = CreateFrame("Frame")
local function say(s)
print("|cff66ddaaHalbklick:|r " .. s)
end
---------------------------------------------------------------- Belegungen
-- Modifikatoren in Blizzards Reihenfolge, genau wie im geschuetzten Snippet
local function currentMods()
return (IsAltKeyDown() and "alt-" or "")
.. (IsControlKeyDown() and "ctrl-" or "")
.. (IsShiftKeyDown() and "shift-" or "")
end
-- "shift-LeftButton:L:help" = Shift-Linksklick, linke Haelfte, freundliche Einheit
local function combo(b)
return b.mods .. b.button .. ":" .. b.area .. ":" .. b.reaction
end
local function buttonName(button)
local n = button:match("^Button(%d+)$")
return BUTTON_NAME[button] or (n and "Maustaste " .. n) or button
end
local function clickName(mods, button)
local parts = {}
if mods:find("alt-", 1, true) then parts[#parts + 1] = "Alt" end
if mods:find("ctrl-", 1, true) then parts[#parts + 1] = "Strg" end
if mods:find("shift-", 1, true) then parts[#parts + 1] = "Shift" end
parts[#parts + 1] = buttonName(button)
return table.concat(parts, " + ")
end
local function firstLine(s)
local line = s:match("^[^\n]*")
if line ~= s then line = line .. " ..." end
return line
end
local function describe(b)
local where = AREA[b.area].name
if b.reaction ~= "any" then where = where .. ", " .. REACTION[b.reaction].name end
local what
if b.action == "spell" then
what = b.value
elseif b.action == "macro" then
what = "Makro: " .. firstLine(b.value)
else
what = ACTION[b.action].name
end
return clickName(b.mods, b.button) .. " |cff999999(" .. where .. ")|r: " .. what
end
local function sortKey(b)
return string.format("%02d%s|%-16s|%d%d", BUTTON_ORDER[b.button] or 99, b.button, b.mods,
AREA[b.area].order, REACTION[b.reaction].order)
end
local function sortBindings()
table.sort(db.bindings, function(x, y) return sortKey(x) < sortKey(y) end)
end
-- Kaputte oder unbekannte Eintraege aus den SavedVariables verwerfen
local function valid(b)
if type(b) ~= "table" or type(b.button) ~= "string" or b.button == "" then return false end
if type(b.mods) ~= "string" or not AREA[b.area] or not REACTION[b.reaction] then return false end
local a = ACTION[b.action]
if not a then return false end
if a.value then return type(b.value) == "string" and b.value ~= "" end
return true
end
---------------------------------------------------------------- Geschuetzter Teil
local header = CreateFrame("Frame", "HalbklickHeader", UIParent, "SecureHandlerBaseTemplate")
-- Ohne Elternrahmen und ohne Groesse: unsichtbar, aber per Click() ausloesbar
local proxy = CreateFrame("Button", "HalbklickProxy", nil, "SecureActionButtonTemplate")
local INIT_SNIPPET = [[
H = self
P = self:GetFrameRef("proxy")
]]
-- Laeuft vor jedem Klick auf einen angemeldeten Rahmen, auch im Kampf.
-- self = der Rahmen, button = echte Maustaste. Rueckgabe "Button31" leitet
-- den Klick zum Proxy, nil laesst ihn unveraendert, false verwirft ihn.
local CLICK_SNIPPET = [[
local unit = self:GetAttribute("unit")
if not unit or not H then return end
local suffix = self:GetAttribute("unitsuffix")
local mods = (IsAltKeyDown() and "alt-" or "") .. (IsControlKeyDown() and "ctrl-" or "") .. (IsShiftKeyDown() and "shift-" or "")
local base = mods .. button .. ":"
local x = self:GetMousePosition()
local side = "A"
if x then
if x < 0.5 then side = "L" else side = "R" end
end
local who = unit .. (suffix or "")
local react = "any"
if PlayerCanAttack(who) then react = "harm" elseif PlayerCanAssist(who) then react = "help" end
local c = base .. side .. ":" .. react
local t = H:GetAttribute("hkt:" .. c)
if not t then c = base .. side .. ":any"; t = H:GetAttribute("hkt:" .. c) end
if not t then c = base .. "A:" .. react; t = H:GetAttribute("hkt:" .. c) end
if not t then c = base .. "A:any"; t = H:GetAttribute("hkt:" .. c) end
if not t then
if button == "Button31" then return false end
return
end
local v = H:GetAttribute("hkv:" .. c)
P:SetAttribute("unit", unit)
P:SetAttribute("unitsuffix", suffix)
P:SetAttribute("toggleForVehicle", self:GetAttribute("toggleForVehicle"))
P:SetAttribute("type", t)
if t == "spell" then P:SetAttribute("spell", v) else P:SetAttribute("spell", nil) end
if t == "macro" then P:SetAttribute("macrotext", v) else P:SetAttribute("macrotext", nil) end
return "Button31"
]]
local ready = false -- Kopf und Proxy eingerichtet
local registered = {} -- Rahmen -> true
local nRegistered = 0
local pendingFrames = {} -- nach dem Kampf: true = anmelden, false = abmelden
local pendingApply = false -- Belegungen nach dem Kampf uebertragen
local applied = {} -- Kombinationen, die gerade als Attribute am Kopf stehen
-- true, wenn geschuetzte Rahmen jetzt geaendert werden duerfen (also nicht im
-- Kampf). Richtet beim ersten Mal Kopf und Proxy ein.
local function setupSecure()
if InCombatLockdown() then return false end
if not ready then
-- Click() uebergibt kein "down". Ohne das hier wuerde der Proxy bei
-- ActionButtonUseKeyDown = 1 nur auf Druecken reagieren, also nie.
proxy:SetAttribute("useOnKeyDown", false)
proxy:RegisterForClicks("AnyUp")
header:SetFrameRef("proxy", proxy)
header:Execute(INIT_SNIPPET)
ready = true
end
return true
end
-- Belegungen als Attribute an den Kopf-Frame uebertragen (nur ausserhalb des Kampfes)
local function apply()
if not db then return false end
if not setupSecure() then
pendingApply = true
return false
end
pendingApply = false
for c in pairs(applied) do
header:SetAttribute(PREFIX_TYPE .. c, nil)
header:SetAttribute(PREFIX_VALUE .. c, nil)
applied[c] = nil
end
for _, b in ipairs(db.bindings) do
local c = combo(b)
header:SetAttribute(PREFIX_TYPE .. c, ACTION[b.action].type)
header:SetAttribute(PREFIX_VALUE .. c, b.value)
applied[c] = true
end
return true
end
local function eligible(f)
if type(f) ~= "table" or type(f.IsForbidden) ~= "function" or f:IsForbidden() then return false end
if f == proxy or type(f.HasScript) ~= "function" or not f:HasScript("OnClick") then return false end
-- ungeschuetzte Rahmen bekaemen im Kampf keinen Vorab-Handler
return f:IsProtected() and true or false
end
local function register(f)
if registered[f] or not eligible(f) then return end
if not setupSecure() then
pendingFrames[f] = true
return
end
pendingFrames[f] = nil
f:SetAttribute("*type" .. ROUTE_SUFFIX, "click")
f:SetAttribute("*clickbutton" .. ROUTE_SUFFIX, proxy)
header:WrapScript(f, "OnClick", CLICK_SNIPPET)
registered[f] = true
nRegistered = nRegistered + 1
end
local function unregister(f)
if not registered[f] then
pendingFrames[f] = nil
return
end
if InCombatLockdown() then
pendingFrames[f] = false
return
end
pendingFrames[f] = nil
header:UnwrapScript(f, "OnClick")
f:SetAttribute("*type" .. ROUTE_SUFFIX, nil)
f:SetAttribute("*clickbutton" .. ROUTE_SUFFIX, nil)
registered[f] = nil
nRegistered = nRegistered - 1
end
local function flush()
if InCombatLockdown() then return end
setupSecure()
for f, want in pairs(pendingFrames) do
pendingFrames[f] = nil
if want then register(f) else unregister(f) end
end
if pendingApply then apply() end
end
local function registerBlizzard()
for _, name in ipairs(BLIZZARD_FRAMES) do register(_G[name]) end
for _, name in ipairs({ "TargetFrame", "FocusFrame" }) do
local f = _G[name]
if type(f) == "table" then register(f.totFrame) end
end
local party = _G.PartyFrame
if type(party) == "table" then
for i = 1, 5 do
local m = party["MemberFrame" .. i]
if type(m) == "table" then
register(m)
register(m.PetFrame)
end
end
end
for i = 1, 5 do
register(_G["CompactPartyFrameMember" .. i])
register(_G["CompactPartyFramePet" .. i])
register(_G["CompactArenaFrameMember" .. i])
end
for i = 1, 80 do register(_G["CompactRaidFrame" .. i]) end
for g = 1, 8 do
for m = 1, 5 do register(_G["CompactRaidGroup" .. g .. "Member" .. m]) end
end
end
-- Gruppen- und Schlachtzugsrahmen entstehen nach und nach. Namensschilder
-- (ebenfalls CompactUnitFrames) bleiben aussen vor.
if type(CompactUnitFrame_SetUnit) == "function" then
hooksecurefunc("CompactUnitFrame_SetUnit", function(frame)
if type(frame) ~= "table" or type(frame.IsForbidden) ~= "function" or frame:IsForbidden() then return end
local name = frame:GetName()
if name and name:find("^Compact") then register(frame) end
end)
end
-- Schnittstelle fuer andere Rahmen-Addons, dieselbe wie bei Clique:
-- ClickCastFrames = ClickCastFrames or {}
-- ClickCastFrames[frame] = true (anmelden)
-- ClickCastFrames[frame] = nil (abmelden)
do
local early = ClickCastFrames
ClickCastFrames = setmetatable({}, {
__newindex = function(_, frame, value)
if value == nil or value == false then unregister(frame) else register(frame) end
end,
})
if type(early) == "table" then
for frame, value in pairs(early) do ClickCastFrames[frame] = value end
end
end
---------------------------------------------------------------- Fenster
local ui, rows, radios = nil, {}, {}
local draft, editing -- Belegung im Editor; Index in db.bindings beim Aendern
local refreshUI
local function resetDraft()
draft = { mods = "", area = "A", reaction = "any", action = "spell" }
editing = nil
if ui then ui.value:SetText("") end
end
resetDraft()
local function setStatus(text, isError)
if not ui then return end
ui.status:SetText(text or "")
if isError then ui.status:SetTextColor(1, 0.3, 0.3) else ui.status:SetTextColor(0.5, 1, 0.5) end
end
local function spellName(id)
if not id then return end
if C_Spell and C_Spell.GetSpellName then return C_Spell.GetSpellName(id) end
if GetSpellInfo then return (GetSpellInfo(id)) end
end
-- Zauber oder Makro, das gerade am Mauszeiger haengt, in den Editor uebernehmen
local function takeCursor()
local kind, info1, _, info3 = GetCursorInfo()
if kind == "spell" or kind == "petaction" then
local name = spellName(kind == "spell" and info3 or info1)
if not name then return end
draft.action = "spell"
ui.value:SetText(name)
elseif kind == "macro" then
local _, _, body = GetMacroInfo(info1)
if not body or body == "" then return end
draft.action = "macro"
ui.value:SetText(strtrim(body))
else
return
end
ClearCursor()
setStatus("")
refreshUI()
end
local function loadBinding(i)
local b = db.bindings[i]
if not b then return end
draft = { button = b.button, mods = b.mods, area = b.area, reaction = b.reaction, action = b.action }
editing = i
ui.value:SetText(b.value or "")
setStatus("")
refreshUI()
end
local function deleteBinding(i)
if not db.bindings[i] then return end
table.remove(db.bindings, i)
if editing == i then
resetDraft()
elseif editing and editing > i then
editing = editing - 1
end
if apply() then
setStatus("Belegung gelöscht.")
else
setStatus("Gelöscht. Wirkt nach dem Kampf.")
end
refreshUI()
end
local function saveDraft()
if not draft.button then
return setStatus("Erst ins Klickfeld klicken, um die Maustaste festzulegen.", true)
end
local a = ACTION[draft.action]
local value
if a.value then
value = strtrim(ui.value:GetText() or "")
if draft.action == "spell" then value = strtrim((value:gsub("%s*[\r\n]+%s*", " "))) end
if value == "" then
return setStatus(draft.action == "spell" and "Welcher Zauber? Namen eintragen oder hineinziehen."
or "Der Makrotext fehlt.", true)
end
end
local b = {
button = draft.button, mods = draft.mods, area = draft.area,
reaction = draft.reaction, action = draft.action, value = value,
}
-- Dieselbe Kombination gibt es nur einmal: die alte Belegung wird ersetzt
local c, replaced = combo(b), false
for i = #db.bindings, 1, -1 do
if i ~= editing and combo(db.bindings[i]) == c then
table.remove(db.bindings, i)
if editing and editing > i then editing = editing - 1 end
replaced = true
end
end
if editing then db.bindings[editing] = b else db.bindings[#db.bindings + 1] = b end
sortBindings()
local ok = apply()
resetDraft()
if not ok then
setStatus("Gespeichert. Wirkt nach dem Kampf.")
elseif replaced then
setStatus("Gespeichert, die alte Belegung dieser Kombination wurde ersetzt.")
else
setStatus("Gespeichert.")
end
refreshUI()
end
local function label(parent, text, x, y, font)
local fs = parent:CreateFontString(nil, "OVERLAY", font or "GameFontNormal")
fs:SetPoint("TOPLEFT", x, y)
fs:SetJustifyH("LEFT")
fs:SetText(text)
return fs
end
local function radioGroup(field, title, list, y)
label(ui, title, 16, y - 1)
local group = {}
for i, e in ipairs(list) do
local rb = CreateFrame("CheckButton", nil, ui, "UIRadioButtonTemplate")
local col, row = (i - 1) % 3, math.floor((i - 1) / 3)
rb:SetPoint("TOPLEFT", 96 + col * 126, y - row * 20)
local text = rb.text
if not text then
text = rb:CreateFontString(nil, "OVERLAY")
text:SetPoint("LEFT", rb, "RIGHT", 5, 0)
end
text:SetFontObject("GameFontHighlightSmall")
text:SetText(e.name)
rb:SetHitRectInsets(0, -100, 0, 0)
rb.key = e.key
rb:SetScript("OnClick", function()
draft[field] = e.key
refreshUI()
end)
group[#group + 1] = rb
end
radios[field] = group
end
local function getRow(i)
if rows[i] then return rows[i] end
local row = CreateFrame("Button", nil, ui.list)
row:SetHeight(20)
row:SetPoint("TOPLEFT", 0, -(i - 1) * 20)
row:SetPoint("RIGHT", ui.list, "RIGHT", 0, 0)
row:SetHighlightTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight", "ADD")
row.text = row:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
row.text:SetPoint("LEFT", 4, 0)
row.text:SetPoint("RIGHT", -24, 0)
row.text:SetJustifyH("LEFT")
row.text:SetWordWrap(false)
row:SetScript("OnClick", function(self) loadBinding(self.index) end)
row.del = CreateFrame("Button", nil, row, "UIPanelCloseButton")
row.del:SetSize(22, 22)
row.del:SetPoint("RIGHT", 0, 0)
row.del:SetScript("OnClick", function(self) deleteBinding(self:GetParent().index) end)
rows[i] = row
return row
end
function refreshUI()
if not ui or not db then return end
-- Liste
for i, b in ipairs(db.bindings) do
local row = getRow(i)
row.index = i
row.text:SetText(describe(b))
if editing == i then row:LockHighlight() else row:UnlockHighlight() end
row:Show()
end
for i = #db.bindings + 1, #rows do rows[i]:Hide() end
ui.list:SetHeight(math.max(1, #db.bindings * 20))
ui.empty:SetShown(#db.bindings == 0)
-- Editor
ui.editTitle:SetText(editing and "Belegung ändern" or "Neue Belegung")
ui.capture:SetText(draft.button and clickName(draft.mods, draft.button)
or "Hier mit der gewünschten Maustaste klicken")
for field, group in pairs(radios) do
for _, rb in ipairs(group) do rb:SetChecked(draft[field] == rb.key) end
end
local a = ACTION[draft.action]
if a.value then
ui.valueLabel:SetText(draft.action == "spell"
and "Zauber: Namen eintragen oder aus dem Zauberbuch hierher ziehen"
or "Makrotext: für die angeklickte Einheit [@mouseover] verwenden")
ui.valueBox:Show()
else
ui.valueLabel:SetText("")
ui.valueBox:Hide()
ui.value:ClearFocus()
end
ui.save:SetText(editing and "Ändern" or "Hinzufügen")
end
local function createUI()
ui = CreateFrame("Frame", "HalbklickFrame", UIParent, "BackdropTemplate")
ui:SetSize(480, 540)
ui:SetPoint("CENTER")
ui:SetFrameStrata("DIALOG")
ui:SetToplevel(true)
ui:SetClampedToScreen(true)
ui:SetMovable(true)
ui:EnableMouse(true)
ui:RegisterForDrag("LeftButton")
ui:SetScript("OnDragStart", ui.StartMoving)
ui:SetScript("OnDragStop", ui.StopMovingOrSizing)
ui:SetBackdrop({
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 14,
insets = { left = 4, right = 4, top = 4, bottom = 4 },
})
ui:SetBackdropColor(0.05, 0.05, 0.05, 0.95)
ui:SetBackdropBorderColor(0.6, 0.6, 0.6, 1)
ui:Hide()
tinsert(UISpecialFrames, "HalbklickFrame") -- Esc schliesst das Fenster
local close = CreateFrame("Button", nil, ui, "UIPanelCloseButton")
close:SetPoint("TOPRIGHT", -2, -2)
label(ui, "Halbklick", 16, -14, "GameFontNormalLarge")
label(ui, "Klick-Zauber, auf Wunsch getrennt nach linker und rechter Rahmenhälfte",
16, -36, "GameFontDisableSmall")
-- Liste der Belegungen
local scroll = CreateFrame("ScrollFrame", "HalbklickListe", ui, "UIPanelScrollFrameTemplate")
scroll:SetPoint("TOPLEFT", 14, -58)
scroll:SetPoint("TOPRIGHT", -34, -58)
scroll:SetHeight(180)
ui.list = CreateFrame("Frame", nil, scroll)
ui.list:SetSize(432, 1)
scroll:SetScrollChild(ui.list)
ui.empty = label(ui, "Noch keine Belegungen. Unten eine anlegen.", 18, -64, "GameFontDisable")
local line = ui:CreateTexture(nil, "ARTWORK")
line:SetColorTexture(0.6, 0.6, 0.6, 0.4)
line:SetHeight(1)
line:SetPoint("TOPLEFT", 12, -246)
line:SetPoint("TOPRIGHT", -12, -246)
-- Editor
ui.editTitle = label(ui, "", 16, -256, "GameFontNormalLarge")
label(ui, "Klick", 16, -287)
ui.capture = CreateFrame("Button", "HalbklickKlickfeld", ui, "UIPanelButtonTemplate")
ui.capture:SetSize(300, 26)
ui.capture:SetPoint("TOPLEFT", 96, -280)
ui.capture:RegisterForClicks("AnyUp")
ui.capture:SetScript("OnClick", function(_, button)
if GetCursorInfo() then return takeCursor() end
draft.button, draft.mods = button, currentMods()
setStatus("")
refreshUI()
end)
ui.capture:SetScript("OnReceiveDrag", takeCursor)
label(ui, "Shift, Strg oder Alt dabei gedrückt halten, um sie mit zu belegen",
96, -308, "GameFontDisableSmall")
radioGroup("area", "Bereich", AREAS, -328)
radioGroup("reaction", "Einheit", REACTIONS, -350)
radioGroup("action", "Aktion", ACTIONS, -372)
ui.valueLabel = label(ui, "", 16, -418, "GameFontNormalSmall")
ui.valueBox = CreateFrame("Frame", nil, ui, "BackdropTemplate")
ui.valueBox:SetPoint("TOPLEFT", 14, -432)
ui.valueBox:SetPoint("TOPRIGHT", -14, -432)
ui.valueBox:SetHeight(58)
ui.valueBox:SetBackdrop({
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 12,
insets = { left = 3, right = 3, top = 3, bottom = 3 },
})
ui.valueBox:SetBackdropColor(0, 0, 0, 0.8)
ui.valueBox:SetBackdropBorderColor(0.5, 0.5, 0.5, 1)
ui.value = CreateFrame("EditBox", "HalbklickWert", ui.valueBox)
ui.value:SetMultiLine(true)
ui.value:SetAutoFocus(false)
ui.value:SetMaxLetters(255) -- so lang darf ein Makro sein
ui.value:SetFontObject("ChatFontNormal")
ui.value:SetPoint("TOPLEFT", 8, -6)
ui.value:SetPoint("BOTTOMRIGHT", -8, 6)
ui.value:SetWidth(430)
ui.value:SetScript("OnEscapePressed", ui.value.ClearFocus)
ui.value:SetScript("OnReceiveDrag", takeCursor)
ui.value:HookScript("OnMouseDown", function() if GetCursorInfo() then takeCursor() end end)
ui.valueBox:EnableMouse(true)
ui.valueBox:SetScript("OnMouseDown", function()
if GetCursorInfo() then takeCursor() else ui.value:SetFocus() end
end)
ui.valueBox:SetScript("OnReceiveDrag", takeCursor)
ui.save = CreateFrame("Button", nil, ui, "UIPanelButtonTemplate")
ui.save:SetSize(110, 24)
ui.save:SetPoint("BOTTOMLEFT", 14, 16)
ui.save:SetScript("OnClick", saveDraft)
local new = CreateFrame("Button", nil, ui, "UIPanelButtonTemplate")
new:SetSize(80, 24)
new:SetPoint("LEFT", ui.save, "RIGHT", 6, 0)
new:SetText("Neu")
new:SetScript("OnClick", function()
resetDraft()
setStatus("")
refreshUI()
end)
ui.status = ui:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
ui.status:SetPoint("LEFT", new, "RIGHT", 10, 0)
ui.status:SetPoint("RIGHT", ui, "RIGHT", -14, 0)
ui.status:SetJustifyH("LEFT")
ui.status:SetWordWrap(true)
ui:SetScript("OnShow", function()
if InCombatLockdown() then setStatus("Im Kampf: Änderungen wirken erst danach.") end
refreshUI()
end)
end
local function toggleUI()
if not ui then createUI() end
ui:SetShown(not ui:IsShown())
end
---------------------------------------------------------------- Ereignisse
ev:RegisterEvent("ADDON_LOADED")
ev:RegisterEvent("PLAYER_LOGIN")
ev:RegisterEvent("PLAYER_ENTERING_WORLD")
ev:RegisterEvent("GROUP_ROSTER_UPDATE")
ev:RegisterEvent("PLAYER_REGEN_DISABLED")
ev:RegisterEvent("PLAYER_REGEN_ENABLED")
ev:SetScript("OnEvent", function(self, event, arg1)
if event == "ADDON_LOADED" then
if arg1 ~= ADDON then return end
self:UnregisterEvent("ADDON_LOADED")
HalbklickDB = HalbklickDB or {}
db = HalbklickDB
local list = {}
for _, b in ipairs(type(db.bindings) == "table" and db.bindings or {}) do
if valid(b) then list[#list + 1] = b end
end
db.bindings = list
sortBindings()
apply()
elseif event == "PLAYER_LOGIN" then
registerBlizzard()
local isLoaded = (C_AddOns and C_AddOns.IsAddOnLoaded) or IsAddOnLoaded
for _, name in ipairs(RIVALS) do
if isLoaded and isLoaded(name) then
say("|cffff5555Achtung:|r " .. name .. " ist auch aktiv. Zwei Klick-Zauber-Addons "
.. "stören sich gegenseitig, bitte nur eins verwenden.")
end
end
elseif event == "PLAYER_REGEN_ENABLED" then
flush()
if ui and ui:IsShown() then setStatus("") end
elseif event == "PLAYER_REGEN_DISABLED" then
if ui and ui:IsShown() then setStatus("Im Kampf: Änderungen wirken erst danach.") end
else -- PLAYER_ENTERING_WORLD, GROUP_ROSTER_UPDATE
registerBlizzard()
end
end)
---------------------------------------------------------------- Befehle
local function listBindings()
if #db.bindings == 0 then
say("Noch keine Belegungen. /hk öffnet das Fenster.")
return
end
for _, b in ipairs(db.bindings) do say(" " .. describe(b)) end
end
local function showStatus()
local waiting = 0
for _ in pairs(pendingFrames) do waiting = waiting + 1 end
say(#db.bindings .. " Belegung(en), " .. nRegistered .. " Rahmen angemeldet"
.. (waiting > 0 and (", " .. waiting .. " warten auf Kampfende") or "")
.. ((pendingApply or not ready) and ", Belegungen wirken nach dem Kampf" or "") .. ".")
end
SLASH_HALBKLICK1 = "/hk"
SLASH_HALBKLICK2 = "/halbklick"
SlashCmdList.HALBKLICK = function(input)
local cmd = strtrim(input or ""):lower()
if cmd == "" then
toggleUI()
elseif cmd == "liste" then
listBindings()
elseif cmd == "status" then
showStatus()
else
say("/hk Fenster öffnen, /hk liste Belegungen anzeigen, /hk status Zustand")
end
end