Thread Tools Display Modes
12-25-08, 07:17 PM   #1
fludder
A Fallenroot Satyr
 
fludder's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 23
XML Slider Question

I am working on developing a config GUI for Scott's nUI. I've used XML for the frames and buttons etc... Its worked well for buttons but I cant get my sliders to work. Here is what I am trying to do:

I need a slider that will perform the function of /nui framerate {n}


From the readme:
-- /nui framerate {n}

This option changes (or throttles) the maximum refresh rate for casting bars, bar animations and unit frames. Increase {n} for smoothness, decrease {n} for performance. The default is 30 frames per second.
</SNIP>
So to set up the slider I'm using:
Code:
	<Slider name="FramerateSlider"  virtual="false" setAllPoints="false" hidden="false"
		alpha="1" toplevel="false" frameStrata="PARENT" id="0" 
		enableMouse="true" enableKeyboard="false" 
		drawLayer="OVERLAY" minValue="10" maxValue="60" defaultValue="30" valueStep="2" orientation="HORIZONTAL">
		<Size x="241" y="20" />
		<Anchors>
			<Anchor point="TOPLEFT">
				<Offset x="121" y="-358" />
			</Anchor>
		</Anchors>
		<Scripts>
		</Scripts>
	</Slider>
now the script logic is where I am having trouble and I cant seem to find any info on the internet (looked in TONS of forums) on how to take the value of the slider and submit it on mouse release

for example with the button to switch from round <--> square minimap I'm using the following:
Code:
<Button name="SquareMiniMapButton" inherits="UIPanelButtonTemplate" text="On / Off">
	<Size x="100" y="20" />
		<Anchors>
			<Anchor point="TOPLEFT">
			<Offset x="16" y="-332" />
			</Anchor>
		</Anchors>
		<Scripts>
			<OnClick>local editbox = CreateFrame("EditBox", "myEditBox", UIParent, "ChatFrameEditBoxTemplate"); 
				editbox:SetText("/nui roundmap");
				ChatEdit_SendText(editbox);</OnClick>
		</Scripts>
</Button>
So I want to be able to do something like:
Code:
		<Scripts>
			<OnClick>local editbox = CreateFrame("EditBox", "myEditBox", UIParent, "ChatFrameEditBoxTemplate"); 
				editbox:SetText("/nui framerate {value from slider}");
				ChatEdit_SendText(editbox);</OnClick>
		</Scripts>
And I have // framerate, combatalpha, idlealpha, targetalpha, hud hgap, regenalpha, hud scale & bagscale // to build so any suggestions would be appreciated.

~Fludder
  Reply With Quote
12-25-08, 08:44 PM   #2
fludder
A Fallenroot Satyr
 
fludder's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 23
Hrmmm Maybe this?

I am at work tonight and I dont have a UI simulator installed here (If anyone knows of a good lightweight [Preferably Portable] simulator let me know please)

Digging arround in other people's code (Im not an engineer, Im a reverse-Engineer) I came up with this:

Frame.xml
Code:
	<Slider name="FramerateSlider" inherits="OptionsSliderTemplate" minvalue="1" maxvalue="120" defaultvalue="30" valuestep="1">
		<Anchors>
			<Anchor point="TOPLEFT">
				<Offset x="121" y="-358" />
			</Anchor>
		</Anchors>
		<Scripts>
			<OnLoad>
				FramerateSlider_InitSlider(this:GetName());
			</OnLoad>
			<OnValueChanged>
				getglobal(this:GetName().."FrameRate"):SetText(getglobal(this:GetName()):GetValue());
				local editbox = CreateFrame("EditBox", "myEditBox", UIParent, "ChatFrameEditBoxTemplate"); 
				editbox:SetText("/nui framerate" .."Framerate"..);
				ChatEdit_SendText(editbox);
			<OnValueChanged>
		</Scripts>
	</Slider>


Frame.lua
Code:
function FramerateSlider_InitSlider(slider)
    local sl = getglobal(slider)
	sl.tooltipText = "Increase for smoothness, decrease for performance. The default is 30 frames per second"; 
	getglobal(slider .. "Low"):SetText("1");
	getglobal(slider .. "High"):SetText("120"); 
	getglobal(slider .. "FrameRate"):SetText("30");
end

Will this corectly send
/nui framerate {FrameRate}
to the default chatframe?

~Fludder
  Reply With Quote
12-29-08, 08:29 AM   #3
Lane
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Jun 2005
Posts: 36
I had trouble getting my sliders to work too. I'm a beginner lua author and used the same approach you did. I did as much XML as I could for the layout and then used LUA for the logic. My code is kinda well commented because I copied a lot of other code that was well commented!

Take a look at this slider code (xml):
Code:
			<Slider name="$parent_Scale" inherits="OptionsSliderTemplate" minValue="1" maxValue="20" defaultValue="5" orientation="HORIZONTAL">
				<Size>
					<AbsDimension x="200" y="16"/>
				</Size>

				<Anchors>
					<Anchor point="BOTTOMLEFT" relativeTo="$parent_Locked">
						<Offset>
							<AbsDimension x="0" y="-60"/>
						</Offset>
					</Anchor>
				</Anchors>
				<Scripts>
				<OnLoad>
					getglobal(self:GetName().."High"):SetText("Big");
					getglobal(self:GetName().."Low"):SetText("Small");
					getglobal(self:GetName().."Text"):SetText("Scale");
				</OnLoad>
				<OnValueChanged>
				  RuneFrameC_Scale_OnValueChanged(self);
				</OnValueChanged>
			</Scripts>
			</Slider>
And this half of the code (lua):
Code:
function RuneFrameC_Scale_OnValueChanged(self)

  local scaleParam = self:GetValue()/5;
  RuneFrameC:SetScale(scaleParam);

end
I pass the whole slider object and use the inherent lua functions.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » XML Slider Question


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