Author Topic: Multiple Sliders Affected By Eachother  (Read 3037 times)

jaised

  • Guest
Multiple Sliders Affected By Eachother
« on: July 13, 2012, 09:55:54 AM »
So here's the scenario:

I have multiple rows (prefab) containing a slider a piece. There is a pool of lets say 1000 resources. The rows are various things to spend those resources on. What I want to do is have the sliders display the allocation of those resources; and respond to the adding/subtracting of resources between them. For instance, Slider 1 is maxed to 1000, all other sliders read 0. If slider 1 is at 1000, and you move slider 2 to 100, Slider 1 will reduce to 900. The values would be equally dispersed in the case where Sliders 2,3 are at 500, and moving slider 1 to 100, would subtract Sliders 2,3 by 50 each resulting in: Slider 1: 100, Slider 2,3: 450.

Row 1    [Slider 1]
Row 2    [Slider 2]
Row 3    [Slider 3]

How would I go about doing this? I can't think of a nice, clean way to do this. Any help is greatly appreciated! Thank you in advance.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Multiple Sliders Affected By Eachother
« Reply #1 on: July 13, 2012, 11:05:44 AM »
Easiest solution? Think relative percentages. What's the total amount of resources? (1000). What was the dragged slider's value relative to that? Say 60% of 100 max, so 60. What were other sliders' relative values? Now adjust the dragged slider's value, and you get a new relative value, which diminishes or increases the value of other sliders. Figure out what this difference is (say, 1.1 for a 10% increase), and multiply the value of other sliders by the inverse to compensate (ie: divide by this value).