Difference between revisions of "Sliding Interface MKIII (CMS)"

From The Official Visionaire Studio: Adventure Game Engine Wiki
 
(12 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By
 
! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By
 
|-
 
|-
| Sliding Interface MKIII || Definition || AFRLme
+
| Sliding Interface MKIII || Definition || [https://www.patreon.com/AFRLme AFRLme]
 
|}
 
|}
  
Line 12: Line 12:
 
| ''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 #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.
+
| ''Quick note #2: Visionaire Studio supports all of the easing options listed on this [https://www.visionaire-studio.com/luadocs/lua.html#easing page]''.
 
|}
 
|}
  
Line 22: Line 22:
 
=== Instructions ===
 
=== Instructions ===
  
1a. Add this script into the script section of the Visionaire Studio editor & set as a defintion type script...  
+
1. Add this script into the script section of the Visionaire Studio editor & set as a defintion type script...  
 
<hr>
 
<hr>
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
Line 29: Line 29:
 
Written by AFRLme [Lee Clarke]
 
Written by AFRLme [Lee Clarke]
 
-- + --
 
-- + --
afrlme@outlook.com | https://afrl.me
+
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.
 
This script is donation optional. In game credit is non-negotiable.
Line 43: Line 46:
 
}
 
}
  
function slideInt(int, dir)
+
function slideInt(int)
 
    
 
    
   if dir and (Interfaces[int].Offset.x == tInt[int].In.x and Interfaces[int].Offset.y == tInt[int].In.y) then -- slide out
+
   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)
 
     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
+
   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)
 
     Interfaces[int]:to(tInt[int].dur, { Offset = {x = tInt[int].In.x, y = tInt[int].In.y} }, tInt[int].eIn)
 
   end
 
   end
Line 53: Line 56:
 
end
 
end
 
</syntaxhighlight>
 
</syntaxhighlight>
<hr>
 
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.
 
 
<hr>
 
<hr>
 
{| class="ts"
 
{| class="ts"
 
|-
 
|-
| ''Quick note: Visionaire Studio supports most of the easing options listed on this [https://easings.net page], however in Visionaire Studio easings are written like this: <span class="green">easeQuintInOut</span>, instead of this: <span class="green">easeInOutQuint</span>''.
+
| ''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''.
 
|}
 
|}
 
<hr>
 
<hr>
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...
+
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...
 
<hr>
 
<hr>
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
slideInt("int_example_1", true)
+
slideInt("int_example_1")
</syntaxhighlight>
 
<hr>
 
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...
 
<hr>
 
<syntaxhighlight lang="lua">
 
slideInt("int_example_1", false)
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 87: Line 82:
 
Written by AFRLme [Lee Clarke]
 
Written by AFRLme [Lee Clarke]
 
-- + --
 
-- + --
afrlme@outlook.com | https://afrl.me
+
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.
 
This script is donation optional. In game credit is non-negotiable.
Line 94: Line 92:
 
--]]
 
--]]
  
function slideInt(int, dir, spos, tpos, duration, easing)
+
function slideInt(int, spos, tpos, duration, eIn, eOut)
 
    
 
    
   if dir and (Interfaces[int].Offset.x == spos.x and Interfaces[int].Offset.y == spos.y) then -- slide out
+
   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} }, easing)
+
     Interfaces[int]:to(duration, { Offset = {x = tpos.x, y = tpos.y} }, eOut)
   elseif not dir and (Interfaces[int].Offset.x == tpos.x and Interfaces[int].Offset.y == tpos.y) then -- slide in
+
   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} }, easing)
+
     Interfaces[int]:to(duration, { Offset = {x = spos.x, y = spos.y} }, eIn)
 
   end
 
   end
 
    
 
    
Line 105: Line 103:
 
</syntaxhighlight>
 
</syntaxhighlight>
 
<hr>
 
<hr>
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...
+
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...
 
<hr>
 
<hr>
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
slideInt("int_example", true, {x = 390, y = 710}, {x = 390, y = 530}, 1000, easeBounceOut)
+
slideInt("int_example", {x = 390, y = 710}, {x = 390, y = 530}, 1000, easeQuintIn, easeBounceOut)
 
</syntaxhighlight>
 
</syntaxhighlight>
<hr>
 
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...
 
<syntaxhighlight lang="lua">
 
slideInt("int_example", false, {x = 390, y = 710}, {x = 390, y = 530}, 1000, easeQuintIn)
 
</syntaxhighlight>
 
<hr>
 
{| class="ts"
 
|-
 
| ''Quick note: Visionaire Studio supports most of the easing options listed on this [https://easings.net page], however in Visionaire Studio easings are written like this: <span class="green">easeQuintInOut</span>, instead of this: <span class="green">easeInOutQuint</span>''.
 
|}
 
  
  
 
== Version 3: Raw Script ==
 
== 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.
+
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 ===
 
=== Syntax ===
Line 170: Line 158:
 
! style="text-align:left" | Name !! style="text-align:left" | Description
 
! style="text-align:left" | Name !! style="text-align:left" | Description
 
|-
 
|-
| [[media:sliding_interface_vs4.zip|to add]] || A working example of the script in action. ''Visionaire Studio 5.1.9.2+'' required to run the included .ved file(s).
+
| [[media:sliding_interface_mk3.zip|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).
 
|}{{toc}}
 
|}{{toc}}

Latest revision as of 13:35, 15 September 2022

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