Reply
Thread Tools Display Modes
Unread 12-10-05, 10:12 AM   #1
xmlover
A Fallenroot Satyr
Join Date: Oct 2005
Posts: 25
Q : how to get the SLIDER work.....

all i want is to set a value by a slider..... but it doesn't work,it can show as the scripts but click with no effect, seems it's disabled

Code:
<Slider name="MySlider1" inherits="OptionsSliderTemplate">
       <Size>
             <AbsDimension x="160" y="16"/>
       </Size>
       <Anchors>
             <Anchor point="TOPLEFT" relativeTo="WispCast_OptionsFrame_CheckButton_SMARTHEAL" relativePoint="BOTTOMLEFT">
                   <Offset>
	            <AbsDimension x="0" y="-20" />
	   </Offset>
             </Anchor>
       </Anchors>
       <Scripts>
	<OnLoad>
                       getglobal(this:GetName()).tooltipText=MyTooltipText1;
                       getglobal(this:GetName().."Text"):SetText(TEXT_MySlider1);
                       getglobal(this:GetName().."High"):SetText("MAX-1");
                       getglobal(this:GetName().."Low"):SetText("MIN-0");
                       SliderMiniMapButtonPos:SetMinMaxValues(0,1);
                       SliderMiniMapButtonPos:SetValueStep(0.01);
	</OnLoad>
	<OnValueChanged>
	         MyConfig.value1 = MySlider1:GetValue();
	</OnValueChanged>
       </Scripts>
</Slider>
some tips:
first i assume that the value has changed but the slider does not showed the click effect
so i run "/script DEFAULT_CHAT_FRAME:AddMessage("MyConfig.value1")"
and it always shows 0.99.............but i set the default value of the MyConfig.value1 to 1....
hmm..........................i was confused................


2 Qs

(1) How to get it to work?
(2) Are there any other useful offical function for the slider?

Last edited by xmlover : 12-10-05 at 10:46 AM.
xmlover is offline   Reply With Quote
Unread 12-10-05, 12:49 PM   #2
Gello
A Scalebane Royal Guard
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 444
<OnValueChanged> is called when the slider is loaded (the OnLoad is also). This happens before VARIABLES_LOADED. In the VARIABLES_LOADED or beyond you'll want to :SetValue. Are you able to MySlider1:SetValue(.5) to get it to work? At a glance I don't see anything wrong.

Btw, it takes less lines of code and imho improves the professionalism of a mod a great deal to make the minimap button draggable instead of a slider buried in options somewhere:

In addition to your minimap button's frame, make one frame devoted to an OnUpdate that's always hidden:

<Button name="MyMinimapButton">
<Scripts>
<OnLoad>
this:RegisterForDrag("LeftButton")
</OnLoad>
<OnDragStart>
this:LockHighlight()
MyMod_IconDraggingFrame:Show()
</OnDragStart>
<OnDragStop>
this:UnlockHighlight()
MyMod_IconDraggingFrame:Hide()
</OnDragStop>
</Button>

<Frame name="MyMod_IconDraggingFrame" hidden="true">
<Scripts>
<OnUpdate>
local xpos,ypos = GetCursorPosition()
local xmin,ymin = Minimap:GetLeft(), Minimap:GetBottom()
xpos = xmin-xpos/UIParent:GetScale()+70
ypos = ypos/UIParent:GetScale()-ymin-70
MySettings.IconPosition = math.deg(math.atan2(ypos,xpos))
MyMinimapButton:SetPoint("TOPLEFT","Minimap","TOPLEFT",52-(80*cos(MySettings.IconPosition or 45)),(80*sin(MySettings.IconPosition or 45))-52)
</OnUpdate>
</Scripts>
</Frame>

I usually put that last line in the OnUpdate into a local function move_icon, and call it after VARIABLES_LOADED and from within the OnUpdate. (tho of course the OnUpdate code is moved over to the lua file to call a local function made in lua file) No fuss movable minimap buttons that clings to the minimap edge as you drag it around.

Last edited by Gello : 12-10-05 at 12:54 PM.
Gello is offline   Reply With Quote
Unread 12-11-05, 01:14 AM   #3
xmlover
A Fallenroot Satyr
Join Date: Oct 2005
Posts: 25
OKOKOK,i made a mistake by copy the code.....

the name when i set the Value of the slider was the previous one.....

OK now

=================

good idea!!
use <OnUpdate>

but a idea,

i saw some infomation on WOWWIKI.com that <OnUpdate> calls every 0.1sec during the Gameplay

you use for change the position,will the codes be called so many times whenever the cursor is moving ?

Last edited by xmlover : 12-11-05 at 01:28 AM.
xmlover is offline   Reply With Quote
Unread 12-11-05, 02:44 AM   #4
Gello
A Scalebane Royal Guard
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 444
Yeah OnUpdates happen every frame. But OnUpdates don't happen at all while the frame is hidden. Note that the frame is hidden at start, and that OnDragStop hides the frame. It's only visible after OnDragStart. The button is moved and the OnUpdate runs for like 5 seconds for the lifetime of the mod.

If you want you can add throttling to the OnUpdate handler which is a very good idea in almost all situations. But since this OnUpdate hardly runs it's not necessary and a bit overkill.

A slider with named labels and stuff will take up more memory than a single frame with an OnUpdate. And it can be argued that the initialization of a slider is a lot more involved than the the infrequent movement of the button, when you can keep the position and then just move it on login to a SavedVariable.
Gello is offline   Reply With Quote
Unread 12-12-05, 12:01 AM   #5
xmlover
A Fallenroot Satyr
Join Date: Oct 2005
Posts: 25
oh,i got it

when a frame is HIDE ,it doesn't receive its <OnUpdate>.


and new question.

how to gray a slider and make it unusable?

it seems that the slider does not get a isable() method
xmlover is offline   Reply With Quote
Reply

Go BackWoWInterface » Developer Discussions » Lua/XML Help » Q : how to get the SLIDER work.....

Thread Tools
Display Modes

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