HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: Clipping/View distance Slider  (Read 1284 times)

ToY-Krun

  • General Accounts
  • *
  • Posts: 677
  • Support Volunteer
    • View Profile
Clipping/View distance Slider
« on: Oct 28, 16, 01:06:57 AM »

This is a longwinded approach done to show the fine detail of whats taking place as well as to show calling functions from methods etc.

If you place all of the following within the class methods script for your Game Options GUI
and point it to your slider, it will adjust your view distance on the client.

Saving that data to a config file is not in the scope of this (but rather easy and found in many other threads on the forums).

Code: [Select]
method _onSliderMouseDrag(args references Class GUIMouseEvent)
  slider as NodeRef of Class GUISlider = args.source
  when slider.parent.name
    is "viewdistance"
      val as Float
      if slider != None
        slider.range.min = 0
        slider.range.max = 100
        var min = slider.range.min
        var max = slider.range.max
        //println(min + " : " + max + " : " + slider.pos)
        val = slider.pos// + max
        AdjustViewDistance(val)
        //println(args.x + " : " + args.y)
      .     
    .
  . 
.
 
shared function AdjustViewDistance(amount as Float)
 
  //println(amount) 
  SetGraphicsOptionValue("FarClipDistance", amount)
.

Actually I'll go ahead and include just a quick example of saving it to file:


The following is a snippet of code from our video configuration script, which saves the settings locally.
you should be able to gather enough from it to work out your own solution:

Code: [Select]
method SaveVideoConfiguration() as Boolean
  fqn as String
  if IsHeroBlade()
    fqn = "/Video_Configuration/"
  else
    fqn = "Video_Configuration"
  .
  if $BASECLIENT.videoResolution.length = 0
    $CHAT._GotChatMessage( "invalid options list", "Info" )
    return false
  .
  data as String = "videoconfig|resolution:" + $BASECLIENT.videoResolution[1] + "x" + $BASECLIENT.videoResolution[2] + "*" + $BASECLIENT.videoResolution[3] + "|" + "directionalshadows:" + GetGraphicsOptionSwitch("DirectionalShadows")+ "|"
  if not( SaveLocalRepositoryData( fqn, SYSTEM.EXEC.THISSCRIPT, data ) )
    $CHAT._GotChatMessage( "did not save video config", "Info" )
    ScriptError( "Attempted to save video options to local repository, but return code was FALSE." )
  else
    $CHAT._GotChatMessage( "Video Configuration Saved", "System" )
  .
  return true
.

this is a very simple version, to better optimize it (and thus make it less readable by others :P ) interate the list of options (graphics etc) saving each one that has a valid setting.

in the last example, to save the view distance to the config file, you would use :
GetGraphicsOptionValue("FarClipDistance")
for the value of the current view distance, or , clip setting.
« Last Edit: Oct 28, 16, 01:35:23 AM by ToY-Krun »
Logged

ToY-Krun

  • General Accounts
  • *
  • Posts: 677
  • Support Volunteer
    • View Profile
Re: Clipping/View distance Slider
« Reply #1 on: Oct 28, 16, 01:20:58 AM »

Since i mentioned saving to config file, here is how that file is then loaded and then accessed:

in our e_baseClientClassMethods script there are the following:



Code: [Select]
method LoadVideoConfiguration() as Boolean
  fqn as String
  if IsHeroBlade()
    fqn = "/Video_Configuration/"
  else
    fqn = "Video_Configuration"
  .
  if DoesLocalRepositoryFQNExist(fqn)
    var myid = LoadLocalRepositoryData(fqn, SYSTEM.EXEC.THISSCRIPT)
    $CHAT._GotChatMessage( myid, "Info" )
  else
    $CHAT._GotChatMessage( "Did not find video config", "Info" )
  .
  return true
.

when its loaded by the backend, the following is called:

(same script)
Code: [Select]
function RepositoryDataDownloaded(name as String, requestTag as ID, successful as Boolean, data as String) as Boolean
 
  if FindString(data, "videoconfig") > 0 and $BASECLIENT._isAreaLoadComplete()
    $BASECLIENT.SetVideoConfiguration(data)
  .
 
  return true
.

method SetVideoConfiguration(data as String)
  msg as String = "$R******Video Config File Loaded******$R"
  args as List of String
  SplitBy(data, "|", args)
  //each arg contains a string which holds the video option as well as its setting(s)
  foreach arg in args
    msg += arg + "$R"
    //":" separates the option name from the setting(s)
    if FindString(arg, ":") > 0
      optionSet as List of String
      SplitBy(arg, ":", optionSet)
      foreach option in optionSet
        msg += "Option: " + option + "$R"       
        SetVideoOption(option, optionSet[2])
      .
    .
  .
  msg = msg + "Video Config File Loaded$R"
  msg = msg + "************$R"
  $CHAT._GotChatMessage( msg, "System" )
.

function SetVideoOption(option as String, value as String)
  when ToLower(option)
    is "resolution"
      x as Integer
      y as Integer
      r as Integer
      //"x" separates the x and y values of the resolution
      var div = FindString(value, "x")
      //"*" separates the x and y from the Hz value if any
      var rdiv = FindString(value, "*")
      x = Substring(value, 1, div - 1)
      y = SubString(value, div + 1, rdiv - 1)
      if rdiv < value.length
        r = SubString(value, rdiv + 1, value.length)
      .
      if r = 0
        r = 60
      .
      msg as String
      msg += x + ":"
      msg += y + ":"
      msg += r + ":"
      $CHAT._GotChatMessage( msg, "System")
      $BASECLIENT.SetResolution(x,y,r)
    .
    is "directionalshadows"
      SetGraphicsOptionSwitch("DirectionalShadows", value)
    .
    is "farclipdistance"
      SetGraphicsOptionValue("FarClipDistance", value)
    .
  .
  $BASECLIENT.videoConfig[option] = value
.

the videoConfig field on the Baseclient systemnode is a custom lookuplist which tracks the current settings client side for all video options,
and must be set from the config file each time the client is loaded.  its used to keep from having to load the config file additional times
during a session, and only populated upon initial client load, or when changes are made.



FINALLY:  you DONT want to call to save to config file everytime something is changed... you'll need to create a "Save" button which would then call
to save your options (all of them) at once.  and possible even a confirm afterwards, with the option to cancel and revert.
« Last Edit: Oct 28, 16, 01:36:15 AM by ToY-Krun »
Logged

ToY-Krun

  • General Accounts
  • *
  • Posts: 677
  • Support Volunteer
    • View Profile
Re: Clipping/View distance Slider
« Reply #2 on: Oct 28, 16, 01:40:01 AM »

One more thing to watch for, some options require the use of GetGraphicsOptionValue() and SetGraphicsOptionValue(), while others require SetGraphicsOptionSwitch() and GetGraphicsOptionSwitch() depending on the type of option.

You won't have to wonder much about which as the console errors will tell you :P

for some options, one version or the other is deprecated and will tell you so (while the function itself is still valid for other options)

Make sense? No?  Good, im not alone :)

Thazager

  • General Accounts
  • *
  • Posts: 1137
  • Never stop learning
    • View Profile
    • Heroes and Villains MMORPG
Re: Clipping/View distance Slider
« Reply #3 on: Oct 28, 16, 01:14:33 PM »

some clarity

The GetGraphicsOptionValue() and SetGraphicsOptionValue(), are used with a slider (usually, can also be text input box) with a max and min set in advance.

The GetGraphicsOptionSwitch() and SetGraphicsOptionSwitch(), are just toggles that can be set with a radio button.
Logged