EasyLightwell

1 - Misbehavior circumvention + localization

Add

local lightwellname = GetSpellInfo(724)

and

LightwellButton:SetAttribute("name", lightwellname)

Change

LightwellButton:SetAttribute("macrotext", "/tar Lightwell \n/focus \n/targetlasttarget")

to

LightwellButton:SetAttribute("macrotext", "/cleartarget \n/targetexact "..lightwellname.." \n/focus \n/targetlasttarget")

and change

SecureHandlerWrapScript(LightwellButton, "PreClick", LightwellButton, [[
	self:SetAttribute("unit", "player")
	isRightClick = (button == "RightButton" or button == "BUTTON2")
	if not isRightClick then return end
	isClicked = not isClicked
	if isClicked then
		self:SetAttribute("macrotext2", "/tar Lightwell")
	else
		self:SetAttribute("macrotext2", "/targetlasttarget")
	end
]])

to

SecureHandlerWrapScript(LightwellButton, "PreClick", LightwellButton, [[
	self:SetAttribute("unit", "player")
	isRightClick = (button == "RightButton" or button == "BUTTON2")
	if not isRightClick then return end
	isClicked = not isClicked
	lightwellname = self:GetAttribute("name")
	if isClicked then
		self:SetAttribute("macrotext2", "/targetexact "..lightwellname)
	else
		self:SetAttribute("macrotext2", "/targetlasttarget")
	end
]])

etc...




Full code

(v0.1.2):

-- EasyLightwell version 0.0.5
-- Author: Kaels
-- This is an alpha release. It may be buggy. It may fail. It may kill your entire raid. 
-- It may make your computer explode. Use at your own risk.

-- Use /elw scale to set the scale of the button.
-- Leftclick and drag to move the button. It should save its position (per character) between sessions.

-- Button behaviour:
-- Leftclick: Sets your focus to the nearest lightwell.
-- MousewheelDown (while over the button only): Clicks the lightwell if it is your focus.
-- Rightclick: Alternates between targeting the nearest lightwell and targeting your last target.
-- Shift-Leftclick: Clears your focus.

-- Click and hold (out of combat): Enables keybinding. Any key you press will be bound to emulate the behaviour
-- of the click or click combination you are holding.

-- Use /elw save to save your keybindings after setting them; /elw cancel to restore the previous binds.
-- If this breaks your keybinds, it's not my fault.
local _, ns = ...
local guiframe

local lightwellname = GetSpellInfo(724)

local setTimer = CooldownFrame_SetTimer
local SecureHandlerWrapScript = SecureHandlerWrapScript
local CreateFrame, CreateFont = CreateFrame, CreateFont
local UnitIsFriend, UnitAura = UnitIsFriend, UnitAura
local tinsert, tremove = table.insert, table.remove
local strformat, strsub = string.format, string.sub
local setmetatable = setmetatable

local LightwellButton = CreateFrame("Button", "EasyLightwellButton", UIParent, "SecureActionButtonTemplate")
LightwellButton:SetPoint("CENTER")
LightwellButton:SetMovable()

local bigfont = CreateFont("EasyLightwellFont")
bigfont:SetFont("Interface\\Addons\\EasyLightwell\\media\\Ubuntu-M.ttf", 16, "OUTLINE")
local smallfont = CreateFont("EasyLightwellSmallFont")
smallfont:SetFont("Interface\\Addons\\EasyLightwell\\media\\Ubuntu-M.ttf", 10)


LightwellButton:SetFrameLevel(1)

LightwellButton:SetWidth(40)
LightwellButton:SetHeight(40)

local bg = LightwellButton:CreateTexture()
bg:SetAllPoints(LightwellButton)
bg:SetTexture(0.8, 0.6, 0.1, 1)

local timer = CreateFrame("Cooldown", nil, LightwellButton)
timer:SetAllPoints(LightwellButton)
timer:SetFrameLevel(2)
LightwellButton.LightwellRenewTimer = timer

local helper = CreateFrame("Frame", nil, LightwellButton)
helper:SetFrameLevel(3)
helper:SetAllPoints(LightwellButton)

local icon = helper:CreateTexture("EasyLightwellIcon")
local icontex = select(3, GetSpellInfo(724))
icon:SetPoint("TOPLEFT", 3, -3)
icon:SetPoint("BOTTOMRIGHT", -3, 3)
icon:SetTexture(icontex)
icon:SetTexCoord(0.05, 0.95, 0.1, 0.95)

local counter = helper:CreateFontString()
counter:SetPoint("CENTER")
counter:SetFontObject(bigfont)
counter.count = 0

function LightwellButton:UpdateCharges()
	local count = select(4, UnitAura("focus", "Lightwell Charges"))
	if not count then
		counter.count = nil
		return counter:SetText(nil)
	else
		counter.count = count
		return counter:SetFormattedText("|cffffff00%d|r", count)
	end
end

local pulse = LightwellButton:CreateAnimationGroup()
pulse:SetLooping("BOUNCE")
local pulsealpha = pulse:CreateAnimation("Alpha")
pulsealpha:SetChange(-0.4)
pulsealpha:SetSmoothing("IN_OUT")
pulsealpha:SetDuration(1)

LightwellButton.pulseAnimation = pulse

LightwellButton:RegisterForDrag("LeftButton")
LightwellButton:SetScript("OnDragStart", function(self)
	if UnitAffectingCombat("player") or not self:IsMovable() then return end
	return self:StartMoving()
end)

LightwellButton:SetScript("OnDragStop", function(self)
	if UnitAffectingCombat("player") or not self:IsMovable() then return end
	return self:StopMovingOrSizing()
end)


LightwellButton:SetAttribute("name", lightwellname)
LightwellButton:SetAttribute("type", "macro")
LightwellButton:SetAttribute("macrotext", "/cleartarget \n/targetexact "..lightwellname.." \n/focus \n/targetlasttarget")
LightwellButton:SetAttribute("shift-type1", "macro")
LightwellButton:SetAttribute("shift-macrotext1", "/clearfocus")
LightwellButton:SetAttribute("type2", "macro")
LightwellButton:SetAttribute("macrotext2", "/targetexact "..lightwellname)
LightwellButton:SetAttribute("unit", "focus")
LightwellButton:RegisterForClicks("AnyDown")


local oldmousewheeldown = GetBindingByKey("MOUSEWHEELDOWN")
local oldmousewheelup = GetBindingByKey("MOUSEWHEELUP")
SecureHandlerWrapScript(LightwellButton, "OnEnter", LightwellButton, [[
	self:SetAttribute("unit", "focus")
	self:SetBinding(1, "MOUSEWHEELDOWN", "INTERACTMOUSEOVER")
	self:SetBinding(1, "MOUSEWHEELUP", "CLICK EasyLightwellButton:LeftButton")
]])
if not oldmousewheeldown and not oldmousewheelup then
	SecureHandlerWrapScript(LightwellButton, "OnLeave", LightwellButton, [[
		self:SetAttribute("unit", "focus")
		self:SetBinding(1, "MOUSEWHEELDOWN", nil)
		self:SetBinding(1, "MOUSEWHEELUP", nil)
	]])
else
	SecureHandlerWrapScript(LightwellButton, "OnLeave", LightwellButton, strformat([[
		self:SetAttribute("unit", "focus")
		self:SetBinding(1, "MOUSEWHEELDOWN", %s)
		self:SetBinding(1, "MOUSEWHEELUP", %s)
	]], oldmousewheeldown, oldmousewheelup))
end

-- for some reason the macros don't fire if the frame's unit doesn't exist. Clunky hack to get around that.
SecureHandlerWrapScript(LightwellButton, "PreClick", LightwellButton, [[
	self:SetAttribute("unit", "player")
	isRightClick = (button == "RightButton" or button == "BUTTON2")
	if not isRightClick then return end
	isClicked = not isClicked
	lightwellname = self:GetAttribute("name")
	if isClicked then
		self:SetAttribute("macrotext2", "/targetexact "..lightwellname)
	else
		self:SetAttribute("macrotext2", "/targetlasttarget")
	end
]])

SecureHandlerWrapScript(LightwellButton, "PostClick", LightwellButton, [[
	self:SetAttribute("unit", "focus")
	self:CallMethod("SetIsLightwellAvailable")
]])

function LightwellButton:RegisterChatCommands()
	SLASH_EASYLIGHTWELL1, SLASH_EASYLIGHTWELL2 = "/elw", "/easylightwell"
	SlashCmdList["EASYLIGHTWELL"] = function(msg, editbox)
		if UnitAffectingCombat("player") then return
		else
			guiframe:Show()
		end
	end
end

LightwellButton:RegisterEvent("PLAYER_ENTERING_WORLD")
LightwellButton:SetScript("OnEvent", function(self)
	self:SetIsLightwellAvailable()
	self:RegisterChatCommands()
	guiframe = ns.guiframe
	EasyLightwellDB = EasyLightwellDB or { ["scale"] = 1 }
	LightwellButton.db = EasyLightwellDB
	local db = LightwellButton.db
	LightwellButton:SetScale(db.scale)
end)

ns.LightwellButton, ns.bigfont, ns.smallfont = LightwellButton, bigfont, smallfont
User When Change
humfras Oct 20, 2012 at 18:37 UTC Changed description:
  LightwellButton:SetAttribute("name", lightwellname)
  <</code>>

- Change all
+ Change
  <<code>>
- "/tar Lightwell"
+ LightwellButton:SetAttribute("macrotext", "/tar Lightwell \n/focus \n/targetlasttarget")
  <</code>>
  to
  <<code>>
- "/targetexact "..lightwellname
+ LightwellButton:SetAttribute("macrotext", "/cleartarget \n/targetexact "..lightwellname.." \n/focus \n/targetlasttarget")
  <</code>>
  and change
----------------------------------------
  	end
  ]])
  <</code>>
+ etc...

  \\\\\\
  ===Full code===
----------------------------------------
  end)


+ LightwellButton:SetAttribute("name", lightwellname)
  LightwellButton:SetAttribute("type", "macro")
- LightwellButton:SetAttribute("macrotext", "/targetexact "..lightwellname.." \n/focus \n/targetlasttarget")
+ LightwellButton:SetAttribute("macrotext", "/cleartarget \n/targetexact "..lightwellname.." \n/focus \n/targetlasttarget")
  LightwellButton:SetAttribute("shift-type1", "macro")
  LightwellButton:SetAttribute("shift-macrotext1", "/clearfocus")
  LightwellButton:SetAttribute("type2", "macro")
----------------------------------------
  	isRightClick = (button == "RightButton" or button == "BUTTON2")
  	if not isRightClick then return end
  	isClicked = not isClicked
+ 	lightwellname = self:GetAttribute("name")
  	if isClicked then
  		self:SetAttribute("macrotext2", "/targetexact "..lightwellname)
  	else
humfras Oct 20, 2012 at 16:33 UTC Changed description:
  <<code lua>>
  local lightwellname = GetSpellInfo(724)
  <</code>>
+ and
+ <<code lua>>
+ LightwellButton:SetAttribute("name", lightwellname)
+ <</code>>
- and change all
+ Change all
  <<code>>
  "/tar Lightwell"
  <</code>>
  to
  <<code>>
  "/targetexact "..lightwellname
+ <</code>>
+
+ and change
+ <<code lua>>
+ SecureHandlerWrapScript(LightwellButton, "PreClick", LightwellButton, [[
+ 	self:SetAttribute("unit", "player")
+ 	isRightClick = (button == "RightButton" or button == "BUTTON2")
+ 	if not isRightClick then return end
+ 	isClicked = not isClicked
+ 	if isClicked then
+ 		self:SetAttribute("macrotext2", "/tar Lightwell")
+ 	else
+ 		self:SetAttribute("macrotext2", "/targetlasttarget")
+ 	end
+ ]])
+ <</code>>
+ to
+ <<code lua>>
+ SecureHandlerWrapScript(LightwellButton, "PreClick", LightwellButton, [[
+ 	self:SetAttribute("unit", "player")
+ 	isRightClick = (button == "RightButton" or button == "BUTTON2")
+ 	if not isRightClick then return end
+ 	isClicked = not isClicked
+ 	lightwellname = self:GetAttribute("name")
+ 	if isClicked then
+ 		self:SetAttribute("macrotext2", "/targetexact "..lightwellname)
+ 	else
+ 		self:SetAttribute("macrotext2", "/targetlasttarget")
+ 	end
+ ]])
  <</code>>
  \\\\\\
humfras Oct 20, 2012 at 16:26 UTC Changed description:
  "/targetexact "..lightwellname
  <</code>>

-
- Full code (v0.1.2):
+ \\\\\\
+ ===Full code===
- <<code[[http://wow.curseforge.com/addons/easylightwell/files/7-easy-lightwell-0-1-2/| lua>>]]
+ ([[http://wow.curseforge.com/addons/easylightwell/files/7-easy-lightwell-0-1-2/|v0.1.2]]):
+ <<code lua>>
  -- EasyLightwell version 0.0.5
  -- Author: Kaels
  -- This is an alpha release. It may be buggy. It may fail. It may kill your entire raid.
humfras Oct 20, 2012 at 16:24 UTC Create

You must login to post a comment. Don't have an account? Register to get one!

Facts

Last updated
Oct 20, 2012
Reported
Oct 20, 2012
Status
New - Issue has not had initial review yet.
Type
Enhancement - A change which is intended to better the project in some way
Priority
Medium - Normal priority.
Votes
0

Reported by

Possible assignees