View Single Post
06-09-05, 07:58 AM   #7
Gello
A Molten Giant
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 521
It's not the best mod for an example of sliders, but Recap here has several sliders in RecapOptions.lua and RecapOptions.xml.

In the xml, I define the min/max/default of the slider in the slider's tag.

<Slider name="RecapIdleFightSlider" orientation="HORIZONTAL" enableMouse="true" minValue="5" maxValue="60" defaultValue="10" valueStep="1">

The scripts section only has tooltip bits and OnValueChanged:

<Scripts>
<OnEnter>
Recap_OnTooltip("IdleFightSlider");
</OnEnter>
<OnLeave>
GameTooltip:Hide();
</OnLeave>
<OnValueChanged>
Recap_IdleFightSlider_OnValueChanged(arg1);
</OnValueChanged>
</Scripts>


In/after the VARIABLES_LOADED event, I make recap_temp.Loaded=true and call Recap_InitializeOptions():

function Recap_InitializeOptions()
local chatname,chatid,i;
RecapAutoFadeSlider:SetValue(recap.Opt.AutoFadeTimer.value);
RecapIdleFightSlider:SetValue(recap.Opt.IdleFightTimer.value);
RecapMaxRowsSlider:SetValue(recap.Opt.MaxRows.value);
RecapMaxRankSlider:SetValue(recap.Opt.MaxRank.value);
etc
end

To set all the values from the last session.

Then OnValueChanged is very simple:

function Recap_IdleFightSlider_OnValueChanged(arg1)
if recap_temp.Loaded and arg1 then
RecapIdleFightSlider_Text:SetText(arg1.." seconds");
recap.Opt.IdleFightTimer.value = arg1;
end
end

Try moving stuff out of the OnLoad/OnShow and into your VARIABLES_LOADED event. That way you're not dependent on when the UI gets around to loading up your UI during startup.

I would think just running the update function would accomplish this, but I can't for the life of me get that DiivSkins_hbar1Update() function (posted earlier) to fire from anywhere other than the <OnValueChanged> call of the slider xml.
Don't try fitting everything into the xml. In many cases it's better to manipulate stuff in your OnEvent handlers than the control's own event handlers.

Last edited by Gello : 06-09-05 at 08:01 AM.
  Reply With Quote