Sliding Interface MKIII (CMS)

From The Official Visionaire Studio: Adventure Game Engine Wiki
Revision as of 03:51, 15 August 2022 by AFRLme (talk | contribs)
Name Type By
Sliding Interface MKIII Definition AFRLme

This script allows you to slide interfaces in/out on mouse over/out, via mouse wheel, via key input, or via an interface button. Visionaire Studio 5+ is required to run this script.


Quick note #1: The interface will only slide in or out if the interface is fully in or out. You can't interrupt it once you start it sliding. The only way to interrupt it & maintain the correct speed would require math calculations to get the current percentage between the start position & target position, which in this case is more hassle than it's worth.
quick note #2: It's technically possible to slide an interface in or out with a single line of code, using the to() tweening function that I am using in the function examples below. However, we are using the functions so that we have less to type overall & the function can be used for multiple interfaces instead of having to write new code blocks for additional functions - just think of it as a workflow function used to save a bit of time in the long run.


Version 1: Tables

This version uses Lua tables/arrays for storing the positional, easing, & duration data for each interface you want to slide out. This version is easier to use overall as you don't need to manually specify all of the data each time into the function.

Instructions

1a. Add this script into the script section of the Visionaire Studio editor & set as a defintion type script...


--[[
Sliding Interface MKIII [v1] (14/08/2022)
Written by AFRLme [Lee Clarke]
-- + --
afrlme@outlook.com | https://afrl.me
-- + --
This script is donation optional. In game credit is non-negotiable.
You are free to: ¹ use it in your game(s). ² modify the script.
Do not remove - or edit - this comment block.
--]]

local tInt = {

["int_example_1"] = { In = {x = 390, y = 710}, Out = {x = 390, y = 530}, dur = 1000, eIn = easeQuintIn, eOut = easeBounceOut },
["int_example_2"] = { In = {x = 390, y = -190}, Out = {x = 390, y = -10}, dur = 1200, eIn = easeQuintIn, eOut = easeQuintOut }

}

function slideInt(int, dir)
  
  if dir and (Interfaces[int].Offset.x == tInt[int].In.x and Interfaces[int].Offset.y == tInt[int].In.y) then -- slide out
    Interfaces[int]:to(tInt[int].dur, { Offset = {x = tInt[int].Out.x, y = tInt[int].Out.y} }, tInt[int].eOut)
  elseif not dir and (Interfaces[int].Offset.x == tInt[int].Out.x and Interfaces[int].Offset.y == tInt[int].Out.y) then -- slide in
    Interfaces[int]:to(tInt[int].dur, { Offset = {x = tInt[int].In.x, y = tInt[int].In.y} }, tInt[int].eIn)
  end
  
end

1b. You need to edit the script above & insert the names of any interfaces you want to be able to slide in & out. You will also need to define the default position of the interfaces [In] & the target position of the interfaces [Out]. Don't forget to include the duration it should take the interface to slide in or out, or the easing you want to use.


Quick note: Visionaire Studio supports most of the easing options listed on this page, however in Visionaire Studio easings are written like this: easeQuintInOut, instead of this: easeInOutQuint.

2a. To use this script you need to create an execute a script action part inside of the key actions, mouse enters/leave actions, command actions, etc. that you want to use to slide an interface out with & then you would insert a line of code that looks like something along the lines of this...


slideInt("int_example_1", true)

2b. To slide the interface back in you would use the same steps as 2a, except the script would look like something along the lines of this...


slideInt("int_example_1", false)


Version 2: Function Only

This version requires you to input all required arguments needed for the interface to slide in or out, such as: the name of the interface you want to slide in or out, the default position (in) & the target position (out), a boolean value to determine if the interface should slide in or out, the duration in milliseconds that it should take for the interface to slide in or out, & finally the easing that you want to use. As you can probably tell this version is a lot more complicated as you will probably have to note down the relevant information for each interface you want to slide in or out somewhere.

Instructions

1. Add this script into the script section of the Visionaire Studio editor & set as a defintion type script...


--[[
Sliding Interface MKIII [v2] (14/08/2022)
Written by AFRLme [Lee Clarke]
-- + --
afrlme@outlook.com | https://afrl.me
-- + --
This script is donation optional. In game credit is non-negotiable.
You are free to: ¹ use it in your game(s). ² modify the script.
Do not remove - or edit - this comment block.
--]]

function slideInt(int, dir, spos, tpos, duration, easing)
  
  if dir and (Interfaces[int].Offset.x == spos.x and Interfaces[int].Offset.y == spos.y) then -- slide out
    Interfaces[int]:to(duration, { Offset = {x = tpos.x, y = tpos.y} }, easing)
  elseif not dir and (Interfaces[int].Offset.x == tpos.x and Interfaces[int].Offset.y == tpos.y) then -- slide in
    Interfaces[int]:to(duration, { Offset = {x = spos.x, y = spos.y} }, easing)
  end
  
end

2a. To use this script you need to create an execute a script action part inside of the key actions, mouse enters/leave actions, command actions, etc. that you want to use to slide an interface out with & then you would insert a line of code that looks like something along the lines of this...


slideInt("int_example", true, {x = 390, y = 710}, {x = 390, y = 530}, 1000, easeBounceOut)

2b. To slide the interface back in you would use the same steps as 2a, except the script would look like something along the lines of this...

slideInt("int_example", false, {x = 390, y = 710}, {x = 390, y = 530}, 1000, easeQuintIn)

Quick note: Visionaire Studio supports most of the easing options listed on this page, however in Visionaire Studio easings are written like this: easeQuintInOut, instead of this: easeInOutQuint.


Version 3: Raw Script

Let's just call this a bonus. In this example I am going to break down the to() tweening function & show you the syntax for it & a simple method of how you would use it for sliding an interface in or out & one for toggling an interface in & out.

Syntax

to(duration, {arguments}, easing, loop, pendulum)

Example 1: Slide Out

local int = Interfaces["int_example"]

if int.Offset.y == 710 then
 int:to(1000, { Offset = {x = int.Offset.x, y = 530} }, easeBounceOut)
end

Example 2: Slide In

local int = Interfaces["int_example"]

if int.Offset.y == 530 then
 int:to(1000, { Offset = {x = int.Offset.x, y = 710} }, easeQuintIn)
end

Example 3: Toggle

local int = Interfaces["int_example"]

if int.Offset.y == 710 then
 int:to(1000, { Offset = {x = int.Offset.x, y = 530} }, easeBounceOut)
elseif int.Offset.y == 530 then
 int:to(1000, { Offset = {x = int.Offset.x, y = 710} }, easeQuintIn)
end


Resources

Name Description
to add A working example of the script in action. Visionaire Studio 5.1.9.2+ required to run the included .ved file(s).