Sliding Interface MKIII (CMS)

From The Official Visionaire Studio: Adventure Game Engine Wiki
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: Visionaire Studio supports all of the easing options listed on this page.


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

1. 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]
-- + --
email: afrlme@outlook.com
paypal: afrlme@zoho.com
patreon: https://www.patreon.com/AFRLme
portfolio: 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)
  
  if 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 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

Quick note: 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.

2. 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")


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]
-- + --
email: afrlme@outlook.com
paypal: afrlme@zoho.com
patreon: https://www.patreon.com/AFRLme
portfolio: 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, spos, tpos, duration, eIn, eOut)
  
  if 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} }, eOut)
  elseif 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} }, eIn)
  end
  
end

2. 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 in or out with & then you would insert a line of code that looks like something along the lines of this...


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


Version 3: Raw Script

Let's just call this section a bonus. Below, I am going to break down the to() tweening function & show you the syntax, & some examples of how you would use it for sliding an interface in or out, & finally an example of how you can toggle 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
sliding_interface_mk3.zip A working example of the script in action. Visionaire Studio 5.1.9.2+ required to run the included .ved file(s).