Sliding Interface MKII (CMS)

From The Official Visionaire Studio: Adventure Game Engine Wiki
Name Type By

Sliding Interface MKII Definition AFRLme

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

Instructions

1. Add the main script to the Visionaire Studio Script Editor & set the script as a definition script.
2a. Now you need to create some tables containing various information that will be used to slide the interface(s) in & out; the table must contain the same name as the target interface.

local t = {} -- creates an empty table
t["inventory_1"] = {x_in = -350, x_out = -20, y_in = 60, y_out = 60, xo = -50, yo = 0, dir =1, state = false} -- from left

2b. x_in is the closed coordinate that your interface is positioned on the x-axis & should be the same as the value set in the interface properties tab of the interface you want to slide.

2c. x_out is the coordinate position the interface will slide to (open) on the x-axis.

2d. y_in is the closed coordinate that your interface is positioned on the y-axis & should be the same as the value set in the interface properties tab of the interface you want to slide.

2e. y_out is the coordinate position the interface will slide to (open) on the x-axis.

2f. xo is the amount of pixels to offset the x-axis by (closed position) while mouse wheel mode is active (hide the interface). Set 0 to deactivate offset for x-axis. The offset should contain a positive or negative value depending on direction value, else it should contain 0.

2g. yo is the amount of pixels to offset the y-axis by (closed position) while mouse wheel mode is active (hide the interface). Set 0 to deactivate offset for y-axis. The offset should contain a positive or negative value depending on direction value, else it should contain 0.

2h. dir is the direction in which the interface should slide from. 1 = from left, 2 = from right, 3 = from top, 4 = from bottom.

2i. state controls whether interface is sliding out, in, or is open or closed; default value should be false.

3. You need to create a condition somewhere & name it mouse_wheel_mode. The default value should be set to false.

4a. Create a button for your interface, move to bottom of list, set button as action area, set object area around the part that will trigger interface slide out on hover.

4b. Add a mouse enter action (or left click action) to the button mentioned in 4a. Inside of this action you should add an if query...

if condition 'mouse_wheel_mode' is false
 execute a script > (see code block below this)
openInterface("interface_name", 3000, easeQuintInOut) -- open interface_name over 3 seconds with smooth easing (change easing to whatever you prefer)
end if


4c. Inside of the properties tab for the interface, add this action part to the action on leaving action...

if condition 'mouse_wheel_mode' is false
 execute a script > (see code block below this)
closeInterface("interface_name", 2000, easeBounceOut) -- close interface_name over 2 seconds with bounce out easing (change easing to whatever you prefer)
end if


5a. Inside of game > mouse properties: mouse wheel up you should add these action parts...

if condition 'mouse_wheel_mode' is true
 execute a script > (see code block below this)
openInterface("interface_name", 3000, easeQuintInOut)
end if


5b. Inside of game > mouse properties: mouse wheel down you should add these action parts...

if condition 'mouse_wheel_mode' is true
 execute a script > (see code block below this)
closeInterface("interface_name", 2000, easeBounceOut)
end if


6. To toggle mouse wheel mode, you need to create an object in your options menu or a key input command containing...

toggle condition 'mouse_wheel_mode'


7. Inside of your scenes, you should probably add inside of an at begin of scene action, an execute a script action containing...

closeInterface("interface_name", 0, easeNoneInOut) -- instantly resets interface_name back to closed position; just in case the interface was open when you changed scenes.

Main Script

--[[
Sliding Interface MKII [v3] (27/11/2014)
Written by AFRLme [Lee Clarke]
-- + --
alternatingfrequencies@hotmail.com | skype @ AFRLme
-- + --
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 variables * --
local p, ox, oy -- empty variables

-- * local tables * --
local t = {} -- empty table
t["inventory_1"] = {x_in = -350, x_out = -20, y_in = 60, y_out = 60, xo = -50, yo = 0, dir =1, state = false} -- from left
t["inventory_2"] = {x_in = 1230, x_out =  930, y_in = 60, y_out = 60, xo = 50, yo = 0, dir = 2, state = false} -- from right
t["inventory_3"] = {x_in = 440, x_out = 440, y_in = -550, y_out = -20, xo = 0, yo = -50, dir = 3, state = false} -- from top
t["inventory_4"] = {x_in = 440, x_out = 440, y_in = 670, y_out = 140, xo = 0, yo = 50, dir = 4, state = false} -- from bottom
 
-- * function that slides the interface out * --
function openInterface(int, delay, easing, dir)
 if t[int]["state"] ~= true then t[int]["state"] = true -- if not already sliding out then begin sliding out (safety measure to make sure it keeps sliding)
  if t[int].dir == 1 or t[int].dir == 2 then p = math.floor(( Interfaces[int].InterfaceOffset.x - t[int].x_out) / (t[int].x_in - t[int].x_out) * 100); delay = math.floor((delay / 100) * p ) end
  if t[int].dir == 3 or t[int].dir == 4 then p = math.floor(( Interfaces[int].InterfaceOffset.y - t[int].y_out) / (t[int].y_in - t[int].y_out) * 100); delay = math.floor((delay / 100) * p ) end
  startObjectTween( Interfaces[int], VInterfaceOffset, Interfaces[int].InterfaceOffset, {x = t[int].x_out, y = t[int].y_out}, delay, easing)
 end
end
 
-- * function that slides the interface in * --
function closeInterface(int, delay, easing, dir)
  t[int]["state"] = false
  if Conditions["mouse_wheel_mode"].ConditionValue then ox = t[int].xo; oy = t[int].yo else ox = 0; oy = 0 end
  if t[int].dir == 1 or t[int].dir == 2 then p = math.floor(( Interfaces[int].InterfaceOffset.x - t[int].x_in) / (t[int].x_out - t[int].x_in) * 100); delay = math.floor((delay / 100) * p ) end
  if t[int].dir == 3 or t[int].dir == 4 then p = math.floor(( Interfaces[int].InterfaceOffset.y - t[int].y_in) / (t[int].y_out - t[int].y_in) * 100); delay = math.floor((delay / 100) * p ) end
  startObjectTween( Interfaces[int], VInterfaceOffset, Interfaces[int].InterfaceOffset, {x = t[int].x_in + ox, y = t[int].y_in + oy}, delay, easing)
end


Alternative Script

This script is the same as the above script but uses the old getObject scripting method. At least Visionaire Studio 4.0 is required to run this script because of the startObjectTween function.

--[[
Sliding Interface MKII [v3] (27/11/2014)
Written by AFRLme [Lee Clarke]
-- + --
alternatingfrequencies@hotmail.com | skype @ AFRLme
-- + --
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 variables * --
local p, ox, oy -- empty variables

-- * local tables * --
local t = {} -- empty table
t["inventory_1"] = {x_in = -350, x_out = -20, y_in = 60, y_out = 60, xo = -50, yo = 0, dir =1, state = false} -- from left
t["inventory_2"] = {x_in = 1230, x_out =  930, y_in = 60, y_out = 60, xo = 50, yo = 0, dir = 2, state = false} -- from right
t["inventory_3"] = {x_in = 440, x_out = 440, y_in = -550, y_out = -20, xo = 0, yo = -50, dir = 3, state = false} -- from top
t["inventory_4"] = {x_in = 440, x_out = 440, y_in = 670, y_out = 140, xo = 0, yo = 50, dir = 4, state = false} -- from bottom
 
-- * function that slides the interface out * --
function openInterface(int, delay, easing, dir)
 if t[int]["state"] ~= true then t[int]["state"] = true -- if not already sliding out then begin sliding out (safety measure to make sure it keeps sliding)
  if t[int].dir == 1 or t[int].dir == 2 then p = math.floor((getObject("Interfaces[" .. int .. "]"):getPoint(VInterfaceOffset).x - t[int].x_out) / (t[int].x_in - t[int].x_out) * 100); delay = math.floor((delay / 100) * p) end
  if t[int].dir == 3 or t[int].dir == 4 then p = math.floor((getObject("Interfaces[" .. int .. "]"):getPoint(VInterfaceOffset).y - t[int].y_out) / (t[int].y_in - t[int].y_out) * 100); delay = math.floor((delay / 100) * p) end
  startObjectTween(getObject("Interfaces[" .. int .. "]"), VInterfaceOffset, getObject("Interfaces[" .. int .. "]"):getPoint(VInterfaceOffset), {x = t[int].x_out, y = t[int].y_out}, delay, easing)
 end
end
 
-- * function that slides the interface in * --
function closeInterface(int, delay, easing, dir)
  t[int]["state"] = false
  if getObject("Conditions[mouse_wheel_mode]"):getBool(VConditionValue) then ox = t[int].xo; oy = t[int].yo else ox = 0; oy = 0 end
  if t[int].dir == 1 or t[int].dir == 2 then p = math.floor((getObject("Interfaces[" .. int .. "]"):getPoint(VInterfaceOffset).x - t[int].x_in) / (t[int].x_out - t[int].x_in) * 100); delay = math.floor((delay / 100) * p) end
  if t[int].dir == 3 or t[int].dir == 4 then p = math.floor((getObject("Interfaces[" .. int .. "]"):getPoint(VInterfaceOffset).y - t[int].y_in) / (t[int].y_out - t[int].y_in) * 100); delay = math.floor((delay / 100) * p) end
  startObjectTween(getObject("Interfaces[" .. int .. "]"), VInterfaceOffset, getObject("Interfaces[" .. int .. "]"):getPoint(VInterfaceOffset), {x = t[int].x_in + ox, y = t[int].y_in + oy}, delay, easing)
end


Resources

Name Description
sliding_interface_vs4.zip A working example of the script in action. Visionaire Studio 4.0.1+ required to run the included .ved file.