Sliding Interface MKII (CMS)

From The Official Visionaire Studio: Adventure Game Engine Wiki
Revision as of 12:14, 27 September 2014 by AFRLme (talk) (Created page with "{| class="ts" style="width:100%" |- ! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By |- | Sliding Interface MKII || Definitio...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Name Type By
Sliding Interface MKII Definition AFRLme

This script allows you to slide interfaces in/out, on mouse over/out, or via mouse wheel. Visionaire Studio 4.0+ 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.
2. Replace inventory with whatever name you gave your interface; names are case sensitive.

local int = "inventory"

3a. Now you need to create a table containing various information that will be used to slide the interface in & out; the table must contain the same name as the interface.

local t = {} -- creates an empty table (required once)
t["inventory"] = {x = 440, y_in = 670, y_out = 140, offset = 50, state = false} -- table containing x & y positions of the interface, amongst other values...

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

x = 450

3c. y_in is the default y coordinate of your interface (closed) & should be the same value set in the interface properties tab of the interface you want to slide.

y_in = 670

3d. y_out is the target coordinate of your interface (open position).

y_out = 140

3e. offset is the amount of pixels to offset the y value (closed position) while mouse wheel mode is active (hide the interface). Set 0 to deactivate offset.

offset = 50 -- adds 50 pixels to current y_in value

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

state = false

4. You need to create a condition somewhere & name it "mouse_wheel_mode". The default value should be set to false.
5a. 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.
6b. Add a mouse enter action (or left click action) to the button mentioned in 5a. 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)
end if

openInterface(3000, easeQuintInOut) -- open interface over 3 seconds with smooth easing (change easing to whatever you prefer)

6c. 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)
end if

closeInterface(3000, easeBounceInOut) -- close interface over 3 seconds. Interface bounces at end (change easing to whatever you prefer)

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

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

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

Main Script

--[[
Sliding Interface [v1] (26/09/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.
--]]

-- * variables * --
local int = "inventory" -- name of interface you want to slide in/out

-- * tables * --
local t = {} -- empty table
t["inventory"] = {x = 440, y_in = 670, y_out = 140, offset = 50, state = false} -- table containing x & y positions of the interface, amongst other values... 

-- * function that slides the interface out * --
function openInterface(delay, easing, p)
 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)
  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)
  startObjectTween(getObject("Interfaces[" .. int .. "]"), VInterfaceOffset, getObject("Interfaces[" .. int .. "]"):getPoint(VInterfaceOffset), {x = t[int].x, y = t[int].y_out}, delay, easing)
 end
end

-- * function that slides the interface in * --
function closeInterface(delay, easing, p, o)
  t[int]["state"] = false
  if getObject("Conditions[mouse_wheel_mode]"):getBool(VConditionValue) then o = t[int].offset else o = 0 end
  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)
  startObjectTween(getObject("Interfaces[" .. int .. "]"), VInterfaceOffset, getObject("Interfaces[" .. int .. "]"):getPoint(VInterfaceOffset), {x = t[int].x, y = t[int].y_in + o}, delay, easing)
end