Thread Tools Display Modes
12-29-08, 02:50 PM   #1
Cralor
Mmm... cookies!!!
 
Cralor's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2007
Posts: 772
Scale slider

I'm trying to make a scale slider. I've already made one before, but for some reason I cannot get it to work for the Death Knight runes. Dragging the slider does nothing.

Creation of the Scale Slider.
Code:
rmslider = CreateFrame("Slider", "ScaleSlider", rmframe, "OptionsSliderTemplate")
    rmslider:SetMinMaxValues(0.5, 2.0)
    rmslider:SetValueStep(0.1)
    rmslider:SetWidth(160)
    getglobal('ScaleSliderLow'):SetText("Small")
    getglobal('ScaleSliderHigh'):SetText("Large")
    rmslider:SetScript('OnShow', function(self) self:SetValue(RuneMoverDB.scale) end)
    rmslider:SetScript('OnValueChanged', Slider_ValueChanged)
    rmslider:SetPoint('BOTTOM', rmtogether, 'BOTTOM', 0, -40)
The function for the slider OnValueChanged
Code:
function Slider_ValueChanged(self, value)
    RuneMoverDB.scale = value;
    rmscaletitle:SetText(math.floor(rmslider:GetValue()*10) / 10)
    for i, v in ipairs(runes) do
        v:SetScale(RuneMoverDB.scale)
    end
end
I've been using the same method as I did before. Save the new value from the slider, make it the new variable, and then set the scale again using the new variable.
I'm thinking it might have to do with the scaling of all 6 runes at once or something.

Thanks
__________________
Never be satisfied with satisfactory.

Last edited by Cralor : 12-29-08 at 02:53 PM.
  Reply With Quote
01-01-09, 06:42 PM   #2
Cralor
Mmm... cookies!!!
 
Cralor's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2007
Posts: 772
Any ideas on this one?
__________________
Never be satisfied with satisfactory.
  Reply With Quote
01-03-09, 01:57 PM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Have you tried doing just one SetScale on the whole RuneFrame, rather than on each individual rune?
  Reply With Quote
01-03-09, 10:38 PM   #4
Cralor
Mmm... cookies!!!
 
Cralor's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2007
Posts: 772
I actually have not. I will try it, thanks!
__________________
Never be satisfied with satisfactory.
  Reply With Quote
01-04-09, 01:51 PM   #5
Cralor
Mmm... cookies!!!
 
Cralor's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2007
Posts: 772
Code:
function Slider_ValueChanged(self, value)
    RuneMoverDB.scale = value;
    rmscaletitle:SetText(math.floor(rmslider:GetValue()*10) / 10)
    for i, v in ipairs(runes) do
        v:SetScale(RuneMoverDB.scale)
    end
end
changed to
Code:
function Slider_ValueChanged(self, value)
    RuneMoverDB.scale = value;
    rmscaletitle:SetText(math.floor(rmslider:GetValue()*10) / 10)
    RuneFrame:SetScale(RuneMoverDB.scale)
end
and it is still not working. Also to note, I cannot get the frames to become "movable", but that is another issue we can deal with later. I just wanted to let you know because maybe it has something to do this issue too.

Thanks!
__________________
Never be satisfied with satisfactory.
  Reply With Quote
01-05-09, 04:49 AM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Well, I'd suggest looking at any of the other rune addons that make the default rune frame movable for help with that.

As for your slider, try this:

Code:
local function Slider_ValueChanged(self)
	local newvalue = math.floor(self:GetValue() * 10) / 10
	RuneMoverDB.scale = newvalue
	RuneFrame:SetScale(newvalue)
end
If you're only creating one slider, you don't need to define the function outside of your SetScript; just do:

Code:
slider:SetScript("OnValueChanged", function(self)
	local newvalue = math.floor(self:GetValue() * 10) / 10
	RuneMoverDB.scale = newvalue
	RuneFrame:SetScale(newvalue)
end)
Also...

- Make sure you define the function as a local, not a global. What you posted, unless it includes a "local Slider_ValueChanged" somewhere before the part you posted, will define that as a global function - bad!

- Are you defining "rmscaletitle" anywhere? If not, that is likely the main reason your code is not working, and you should be seeing Lua errors. Always make sure you have errors enabled (or captured by an addon like BugSack) when you're developing. Error messages are generally quite instructive in telling you exactly where the problem is.

Finally, since I don't have tons of time to load and debug your code, if none of the above helps, you're might look at using Tekkub's excellent widget "library" tekKonfig-Slider, or you're welcome to use the code I use in ShieldsUp (the beta version, not release) to generate a slider. Both are marginally more efficient than what you're doing, since they don't litter the global namespace with named frames and named fontstrings that don't actually need to be named.
  Reply With Quote
01-06-09, 03:52 PM   #7
Cralor
Mmm... cookies!!!
 
Cralor's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2007
Posts: 772
Thanks for the reply.

I actually have 3 different sliders, so that is why I have 3 different functions for them.

As for making the functions local, when would it be a good idea NOT to make them local? I haven't really learned about this much so that is why I haven't done any local functions.

The "rmscaletitle" is a little fontstring under my slider that shows the current value of the slider. This way the user can see what it actually is at that moment in time.

I've used the exact method I am right now with a fontstring and just used :SetFont instead of :SetScale, so I am really confused why it won't work for the runes.

As for looking at other addons, I am pretty sure there is no other addon that uses a scale slider to change the Blizzard Rune Frames

Thanks for your help so far.

EDIT: Anyway, since I am still stumped at this scale slider thing, I'll go ahead and post my other problem:

I made a checkbox to unlock and lock the runes. When I check or uncheck it nothing happens. (Exactly the same problem with my scale slider.) Here is the code:

Creation of the Checkbox
Code:
rmlock = CreateFrame("CheckButton", "RuneMover_FrameLock", rmframe, "OptionsCheckButtonTemplate");
_G[rmlock:GetName().."Text"]:SetText("Unlock Runes")
rmlock:SetScript('OnShow', function(self) self:SetChecked(RuneMoverDB.unlocked) end)
rmlock:SetScript('OnClick', RuneMover_Lock)
rmlock:SetPoint('BOTTOM', rmtitle, 'BOTTOM', 0, -40)
Lock/Unlock Function
Code:
function RuneMover_Lock(self)
    if self then
        RuneMoverDB.unlocked = self:GetChecked()
    end
    if RuneMoverDB.unlocked then
        for i, v in ipairs(runes) do
            v:EnableMouse(true)
            v:SetMovable(true)
            v:RegisterForDrag("LeftButton")
            v:SetScript("OnDragStart", function() v:StartMoving() end)
            v:SetScript("OnDragStop", function() v:StopMovingOrSizing()
            RuneMover_Save() end)
        end
    else
        for i, v in ipairs(runes) do
            v:EnableMouse(false)
            v:SetMovable(false)
        end
    end
end
__________________
Never be satisfied with satisfactory.

Last edited by Cralor : 01-06-09 at 03:57 PM.
  Reply With Quote
01-12-09, 06:35 PM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
As a general rule, everything should be local unless you need to be able to access it from outside of the file. So, for instance, if you want to have one file for functional code, and one file for GUI code, you will want to make your addon object global.

In keeping with the above, functions should be defined inside your addon object's namespace, so function RuneMover.Lock, not function RuneMover_Lock. Same goes for any variables you want to access from outside of their local scope. http://www.lua.org/pil/ has more information about global and local variables and scoping.

As for your slider, to be honest, I've never used the Blizzard templates for GUI widgets. I first used Ace2, then Ace3, then tekKonfig, and now write my own based on tekKonfig with some extra features like mousewheel support. The only obvious problem I see with your code is that your template names should be InterfaceOptionsCheckButtonTemplate and InterfaceOptionsSliderTemplate. Oh, and use _G[blah] instead of getglobal(blah). getglobal is just a function wrapper for the _G table lookup, so using it is calling a function for no reason.

Other than that, without having the entirety of your code to test, it's kind of hard to tell what's wrong.
  Reply With Quote
01-17-09, 11:08 AM   #9
Cralor
Mmm... cookies!!!
 
Cralor's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2007
Posts: 772
Thanks for the reply, Phanx.

I will read more about this local and namespace stuff. I need to get into that a bit. As for the changes you suggested, I will take those into account. Thanks.

I have some experience with Blizzard Options already. I have done it once but never released it, and I just uploaded RPText that uses both an Unlock/Lock checkbox and a Fontsize slider. I have tried the same techniques I used in RPText in RuneMover, but I am still having the same issues.

As for the template names, again, I highly doubt that is the issue, as I have it totally working with NO bugs in RPText. (EDIT: I believe the RuneMover slider and stuff is working, but the "actions" that SHOULD take place to the DK frames are not "working/executing".)

If you would like the entirety of the code, please just let me know.

Thanks for the many responses in an attempt to help me out!
__________________
Never be satisfied with satisfactory.
  Reply With Quote
01-17-09, 02:40 PM   #10
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Yeah, without seeing the whole code, there's a limit to how much I can help that's pretty much been reached already.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Scale slider

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