Page 1 of 1

[CubeScript][SOLUTION]Tricking guislider to use float?

PostPosted: 25 Oct 2011, 19:32
by ZeroKnight
Hey guys. Had an idea for a GUI that controls the display of the HUD much more in depth. Like sliders for Size and Opacity, color settings, etc. Pretty much all the settings I have in my Look 'N' Feel thread. However, a lot of settings use floats as their tag type, and guislider cannot handle float. (at least not very well) It will handle the value, but only the whole, and not the floating point... ie. it will slide from 1 - 5, but 1 - 5 exactly. I wont ever use 1.1 or 4.3, etc.

So, my question, could I somehow trick it into using a float? I had an idea to use 0 - 100 for the min and max, which can be interpreted as percentage, and then link it to the necessary var...but how would I make that var update dynamically as the slider value changed? I don't think I can...

Anyway, thoughts?

[EDIT]
There's always tweaking the source to let it use floats...or just an identical var specifically for handling floats. Like "guisliderf"

Re: [CubeScript] Tricking guislider to use float?

PostPosted: 25 Oct 2011, 21:09
by Wazubaba
This would help me as well, as I am working on an edit GUI, and would like to have a slider to control the transparency of the alpha material.

Re: [CubeScript] Tricking guislider to use float?

PostPosted: 26 Oct 2011, 06:56
by srbs
ZeroKnight {l Wrote}:So, my question, could I somehow trick it into using a float? I had an idea to use 0 - 100 for the min and max, which can be interpreted as percentage, and then link it to the necessary var...but how would I make that var update dynamically as the slider value changed? I don't think I can...

you can do 0-100, but you will need another variable:

{l Code}: {l Select All Code}
value_min = 1
value_max = 5
guitext $value
guislider var 0 100 [value = (+f (divf (*f (-f $value_max $value_min) $var) 100) $value_min) ]


Note: This code completely untested, fix yourself if necessary. :P
I may look into hacking around cubescript to get something more native working this weekend.

srbs

Re: [CubeScript] Tricking guislider to use float?

PostPosted: 26 Oct 2011, 17:07
by ZeroKnight
Thanks for the feedback, srbs. I'll play with this for a little bit and reply back when I can with more information.

If you do happen to look into it, I'd be much obligied if you did share what you come up with :) It could be of great use :)

Re: [CubeScript][SOLUTION]Tricking guislider to use float?

PostPosted: 03 Nov 2011, 19:16
by ZeroKnight
Success! It took some messing around, and an extra command in the "do-every" parameter of guislider, but thanks to the math provided by srbs, I have successfully tricked guislider!

{l Code}: {l Select All Code}
hbval = $hudblend
hudblend_min = 0.0
hudblend_max = 1.0
//more vars of the like will all go here

newgui "HUD++" [ //working title
   guiheader "HUD"
   guititle "Configure HUD Display Options"
   guibar
   guistrut .5
   guifont console [ guitext "Master Settings" ]
   guistrut 1
   guifont radar [ guitext "HUD Size:" ]
   guislider hudsize 0 (getvarmax hudsize)
   guistrut 1
   guifont radar [ guitext "HUD Opacity:" ]
   guitext $hudblend // for testing only
   guislider hbvar 0 100 [ hbval = (+f (divf (*f (-f $hudblend_max $hudblend_min) $hbvar) 100) $hudblend_min); hudblend $hbval ]
   guibar
]


It works! Try the slider! :D Thank you for the math setup, srbs :) Wazu, you should be able to implement this in your editing GUI. Just change the vars around.

Something like this:
{l Code}: {l Select All Code}
vaval = $valpha
valpha_min = (getvarmin valpha)
valpha_max = (getvarmax valpha)

   guifont radar [ guitext "valpha:" ]
   guitext $valpha // testing purposes
   guislider vavar 0 100 [ vaval = (+f (divf (*f (-f $valpha_max $valpha_min) $vavar) 100) $valpha_min); valpha $vaval ]
]


Haven't tried it, but it should definitely work.

Re: [CubeScript][SOLUTION]Tricking guislider to use float?

PostPosted: 05 Nov 2011, 04:17
by srbs
No problem!

And have a command to call:
{l Code}: {l Select All Code}
// (guifloatslider <varname> <holder varname> [<min> <max>])
guifloatslider = [
   guislider $arg2 0 100 [
      vmin = (? (> @numargs 2) @arg3 (getvarmin @arg1))
      vmax = (? (> @numargs 2) @arg4 (getvarmax @arg1))
      if(= $vmin $vmax) [ vmin = 0; vmax = 100 ]
      @arg1 (+f (divf (*f (-f $vmax $vmin) @arg2) 100) $vmin)
   ]
]


srbs