Thread Tools Display Modes
11-07-13, 02:43 PM   #81
Akatosh
A Black Drake
AddOn Compiler - Click to view compilations
Join Date: Jun 2013
Posts: 84
Hi!, I have a new question.

How can I do for change multiple text OnClick, in a panel?.

I explain I have 2 panels with stats info (Atack power, mastery, etc).

Code:
local base, posBuff, negBuff = UnitAttackPower("player")
local Melee_AP = base + posBuff + negBuff
self.text:SetText(string.format("|cffffffff%.i|r AP", Melee_AP))
Code:
local Total_DM = GetMasteryEffect("player")
self.text:SetText(string.format("|cffffffff%.1f%%|r M", Total_DM))
I want join that panels, and swap it OnClick, not a show / hide panel, just a swap of code on the section "OnUpdate", when I do click.

Thanks!!.
  Reply With Quote
11-08-13, 02:06 PM   #82
Akatosh
A Black Drake
AddOn Compiler - Click to view compilations
Join Date: Jun 2013
Posts: 84
I am making work the few neurons that I have and maybe that can work, but I dont find the way to make it.

for example:

Code:
local myPanel = kgPanels:FetchFrame("panel1")

If 1 click then

if pressed then
  myPanel:SetScript("OnUpdate",function(frame)
    local base, posBuff, negBuff = UnitAttackPower("player")
local Melee_AP = base + posBuff + negBuff
myPanel.text:SetText(string.format("|cffffffff%.i|r AP", Melee_AP))
  end)

elseif 2 click then

myPanel:SetScript("OnUpdate",function(frame)
 local Total_DM = GetMasteryEffect("player")
myPanel.text:SetText(string.format("|cffffffff%.1f%%|r M", Total_DM))
  end)

end
Need help!.

Thanks!!

Last edited by Akatosh : 11-08-13 at 08:00 PM.
  Reply With Quote
11-10-13, 12:14 AM   #83
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
1) You shouldn't manually use SetScript on kgPanels frames, as it may break kgPanels or cause unexpected behaviors.
2) Don't use :SetText(format(...)) -- use :SetFormattedText(...) instead to avoid the extra function call.
3) Only use OnUpdate scripts for things that actually require a timer, eg. "do X in 5 seconds" or "update this statusbar every 0.1 seconds so it fills up smoothly". Don't use them for things you can detect with an event or script, eg. "do this when the user clicks" or "do this when the player dies".

OnLoad:
Code:
self.showing = "AP"
OnEvent:
Code:
if self.showing == "AP" then
	local base, posBuff, negBuff = UnitAttackPower("player")
	self.text:SetFormattedText("|cffffffff%.i|r AP", base + posBuff + negBuff)
else
	self.text:SetFormattedText("|cffffffff%.i|r M", GetMasteryEffect("player"))
end
OnClick:
Code:
if self.showing == "AP" then
	self.showing = "MASTERY"
else
	self.showing = "AP"
end
self:GetScript("OnEvent")(self, "OnClick")
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 11-10-13 at 12:16 AM.
  Reply With Quote
11-10-13, 11:55 AM   #84
Akatosh
A Black Drake
AddOn Compiler - Click to view compilations
Join Date: Jun 2013
Posts: 84
Originally Posted by Phanx View Post
1) You shouldn't manually use SetScript on kgPanels frames, as it may break kgPanels or cause unexpected behaviors.
2) Don't use :SetText(format(...)) -- use :SetFormattedText(...) instead to avoid the extra function call.
3) Only use OnUpdate scripts for things that actually require a timer, eg. "do X in 5 seconds" or "update this statusbar every 0.1 seconds so it fills up smoothly". Don't use them for things you can detect with an event or script, eg. "do this when the user clicks" or "do this when the player dies".

OnLoad:
Code:
self.showing = "AP"
OnEvent:
Code:
if self.showing == "AP" then
	local base, posBuff, negBuff = UnitAttackPower("player")
	self.text:SetFormattedText("|cffffffff%.i|r AP", base + posBuff + negBuff)
else
	self.text:SetFormattedText("|cffffffff%.i|r M", GetMasteryEffect("player"))
end
OnClick:
Code:
if self.showing == "AP" then
	self.showing = "MASTERY"
else
	self.showing = "AP"
end
self:GetScript("OnEvent")(self, "OnClick")

Sorry I think that I dont explain me well.

I give more details:

I have 2 panels, 1 with a symbol ("+"), and the other (near) is a panel of stat info.

_______________
| + | stat panel |

when I press the panel with the symbol, the panel of stat info, toggle the stat, to other.

For example, Atack power, Spell power, Vengance, Crit chance, Haste, etc.

I have the code for every stat, only I need the way to toggle it when I click the panel of the symbol.

Thanks for the support Phanx.
  Reply With Quote
11-11-13, 05:48 PM   #85
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Why use two panels? Are you doing something else when you click on the panel that's actually displaying the stats?
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
11-11-13, 09:35 PM   #86
Akatosh
A Black Drake
AddOn Compiler - Click to view compilations
Join Date: Jun 2013
Posts: 84
Originally Posted by Phanx View Post
Why use two panels? Are you doing something else when you click on the panel that's actually displaying the stats?
Maybe you have reason.. and join the two panels in one, be a good idea, to be honest put 2 panels be only a stetic question.

Exist an option for example, for when I log off, the panel conserve the text?.

For example I put MP5 instead, Mastery, the next time that I login the text be MP5.

Thanks.

Last edited by Akatosh : 11-11-13 at 10:40 PM.
  Reply With Quote
11-12-13, 01:04 AM   #87
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
As far as I know, kgPanels doesn't provide any way for panels to save data between sessions, so no, that's not possible. If you wanted to do that, you'd need to set up a separate panel for each stat (eg. one panel for Mastery, one panel for MP5) and make your "toggle" panel actually change your kgPanels hide/show settings for each panel, so those settings would be saved.

If you really want two panels (one to toggle, one to show the stats) then just remove the OnClick script from my last post from your stats panel, and add an OnClick script to your toggle panel (it doesn't need OnLoad or OnEvent scripts):

Code:
local statsPanel = kgPanels:FetchFrame("MyStatsPanel")
if statsPanel.showing == "AP" then
	statsPanel.showing = "MASTERY"
else
	statsPanel.showing = "AP"
end
statsPanel:GetScript("OnEvent")(statsPanel, "OnClick")
If you want to toggle between more than two stats (for example, to cycle between AP, MP5, and Mastery) you're best off using a table:

Stats panel OnLoad:
Code:
self.statIndex = 1

self.statOrder = {
	"AP",
	"CRIT",
	"MASTERY",
	-- add more stats here, in the order
	-- you want to cycle through them
}

self.statFuncs = {
	AP = function(self)
		local base, posBuff, negBuff = UnitAttackPower("player")
		self.text:SetFormattedText("|cffffffff%.i|r AP", base + posBuff + negBuff)
	end,
	MASTERY = function(self)
		self.text:SetFormattedText("|cffffffff%.i|r M", GetMasteryEffect("player"))
	end,
	CRIT = function(self)
		-- insert code for crit chance here
	end,
	-- add other stats here, in any order
}

self:GetScript("OnEvent")(self, "OnLoad")
Stats panel OnEvent:
Code:
local whichStat = self.statOrder[self.statIndex]
self.statFuncs[whichStat](self)
Stats panel OnClick:
Code:
self.statIndex = self.statIndex + 1
if self.statIndex > #self.statOrder then
	self.statIndex = 1
end
self:GetScript("OnEvent")(self, "OnClick")
or toggle panel OnClick if you want it to be separate:
Code:
local statsPanel = kgPanels:FetchFrame("MyStatsPanel")
statsPanel.statIndex = statsPanel.statIndex + 1
if statsPanel.statIndex > #statsPanel.statOrder then
	statsPanel.statIndex = 1
end
statsPanel:GetScript("OnEvent")(statsPanel, "OnClick")
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
11-12-13, 03:54 AM   #88
Akatosh
A Black Drake
AddOn Compiler - Click to view compilations
Join Date: Jun 2013
Posts: 84
Works well Phanx!!, thx, I made a little change to make that the text update on combat, not only when I make click on the panel... if you see my section "OnUpdate", you slain me for sure Xddddd.

A shame that Kgpanels cant save data...

PD: Exist any code to put a limit on the refresh of "OnUpdate"?.
  Reply With Quote
11-13-13, 11:47 PM   #89
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
You do not need an OnUpdate script for anything you are doing. If you want to update when you enter/leave combat, register for the events that fire when you enter/leave combat in your OnLoad script:

Code:
self:RegisterEvent("PLAYER_REGEN_DISABLED")
self:RegisterEvent("PLAYER_REGEN_ENABLED")
However, it's probably more logical to just register for the events that fire when your stats change, so your panels will always update themselves when your stats change:

Code:
self:RegisterEvent("COMBAT_RATING_UPDATE")
self:RegisterEvent("MASTERY_UPDATE")
self:RegisterUnitEvent("UNIT_ATTACK", "player")
self:RegisterUnitEvent("UNIT_ATTACK_POWER", "player")
self:RegisterUnitEvent("UNIT_RANGED_ATTACK_POWER", "player")
self:RegisterUnitEvent("UNIT_RANGEDDAMAGE", "player")
self:RegisterUnitEvent("UNIT_RESISTANCES", "player")
self:RegisterUnitEvent("UNIT_SPELL_HASTE", "player")
self:RegisterUnitEvent("UNIT_STATS", "player")
Not all stats need all events, so feel free to tailor the list for the stat(s) your panel(s) is/are actually using, though just leaving all the events shouldn't have any noticable impact.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Helps with Kgpanels!


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off