Slide Out Any Interface

  • #1, by afrlmeThursday, 03. January 2013, 02:46 12 years ago
    Ok so spacepaw's slide out script really started to bug me after a while as I couldn't wrap me noggin' around half the code he'd written so I have wrote my own version in a much neater format, fully annotated & I've even included a project file for you to see it in action wink

    -- * instructions * --

    script type must be set to "definition"!

    the interface you want to slide out must have the same name as the interface mentioned in the script; in my case I named the interface "inventory" which you will see I used getObject to call the interface. if you call your interface something else then remember you need to change "inventory" in the script to whatever name you used.

    secondly the condition name must also reflect the one inside the script; in my case I called the condition "slide?" so just rename the one found in the script to whatever you use.

    you can speed up or slow down the speed that the interface slides in or out by increasing / decreasing the "+ 2" / "- 2" values found in the script. * plus/minus 2 is quite a nice smooth speed. I do not recommend going any higher than 10 at the most!

    the min_offset should be set to the default absolute position of your interface you wish to slide out & max_offset should be changed to whatever you need.

    *quick note if you want to center your interface x or y to the screen then you need to ... º x position for center equals: screen default resolution width - interface width / 2 (example: 1920 - 400 / 2 = 760) º y position for center equals: screen default resolution height - interface height / 2 (example: 1080 - 600 / 2 = 240)

    hover mouse over the interface to slide out. move mouse away from interface to slide back to default position.

    press "Q" to exit the demo!

    
    --[[
    Slide out any interface
    originally written by spacepaw
    rewritten, modified, fixed, annotated & cleaned by AFRLme
    --]]

    --[[ global getObject variable; used for getting & setting current interface position! replace "inventory" with whatever your interface is called! --]] local get_interface = getObject('Interfaces[inventory]')

    --[[ global values containing the minimum, maximum & current offset values! replace min_offset x,y with the default absolute position you set in the interface to be used for sliding replace max_offset x,y with the x,y position you want the interface to slide to! --]] local min_offset = {x = -350, y = 240} local max_offset = {x = -20, y = 240} local check_offset = get_interface:getPoint(VInterfaceOffset)

    -- * this is the main loop which checks if the interface needs to slide out/in or stay in the current position! * -- function OnMainLoop() --[[ check condition equals true false to decide if interface should slide out or in! replace "slide?" with whatever you name the condition! --]] local cond = getObject('Conditions[slide?]'):getBool(VConditionValue) if cond then -- * check if x equals less than max offset; if not then x = x + 2 else x = max offset! * -- if check_offset.x < max_offset.x then check_offset.x = check_offset.x + 2 end if check_offset.x > max_offset.x then check_offset.x = max_offset.x end -- * check if y equals less than max offset; if not then y = y + 2 else y = max offset! * -- if check_offset.y < max_offset.y then check_offset.y = check_offset.y + 2 end if check_offset.y > max_offset.y then check_offset.y = max_offset.y end else -- check if x equals more than min offset; if not then x = x - 2 else x = min offset! * -- if check_offset.x > min_offset.x then check_offset.x = check_offset.x - 2 end if check_offset.x < min_offset.x then check_offset.x = min_offset.x end -- check if y equals more than min offset; if not then y = y - 2 else y = min offset! * -- if check_offset.y > min_offset.y then check_offset.y = check_offset.y - 2 end if check_offset.y < min_offset.y then check_offset.y = min_offset.y end end -- * updates the current position of the interface * -- get_interface:setValue(VInterfaceOffset, check_offset) end

    -- * let's create the loop to check if the interface is in the correct position! * -- registerEventHandler("mainLoop", "OnMainLoop")

    script: pastebin project file: dropbox

    P.S: I may modify this in the future to also allow slide in/out of interface using mouse_wheel - like in Deponia - depending on if x condition = true or false ... not everyone has mouse_wheel; some laptops & mini mice etc ... I myself am currently using a wacom tablet as my mouse seeing as the touchpad on my paptop has stopped working!

    Imperator

    7278 Posts


  • #2, by petemqThursday, 03. January 2013, 11:49 12 years ago
    Thank you sooo much! After all this trouble it finally works! Awesome. And you even took the time to add comments to the code, so I can learn from that wink I O U

    Newbie

    5 Posts

  • #3, by afrlmeThursday, 03. January 2013, 12:23 12 years ago
    welcome - I added the comments for me too - to keep track of things - as my memory isn't too good wink

    Imperator

    7278 Posts

  • #4, by afrlmeThursday, 03. January 2013, 22:04 12 years ago
    * slight update ...

    changed the increment value from 5 to 2 as it slides out much smoother ... made the "less than or equal to" / "more than or equal to" values to "less than" / "more than" values to make the script a bit less taxing on cpu.

    added a few more lines of annotation & replaced the project file in my dropbox with the new one wink

    Imperator

    7278 Posts

  • #5, by petemqFriday, 04. January 2013, 10:39 12 years ago
    The nice thing about your script: I was able to choose different increments for x and y: My interface is supposed to slide out about 0,7 times x for every 1 time y. So I just chose the values 7 for x-increment and 10 for y-increment. Also, this leaves the possibility for having it slide in double-time or stuff like that. It's great!

    Newbie

    5 Posts

  • #6, by afrlmeFriday, 04. January 2013, 12:12 12 years ago
    nice one wink

    I will be adding mouse wheel support later the day.

    Imperator

    7278 Posts

  • #7, by afrlmeFriday, 04. January 2013, 19:35 12 years ago
    just added a script for a Deponia based slide out interface to the wiki here ... but it's not quite working properly yet - so I'm not including a project file demo for it yet.

    the bug is listed inside the notes section of the wiki & also commented into the script itself.

    Imperator

    7278 Posts

  • #8, by MegaTinyTuesday, 25. November 2014, 01:38 10 years ago
    I'm not sure what the policy is on reviving old posts is here but I just had to say this is amazing and is already making my game look about 4 million times smoother. Plus I just learnt some Lua script from this really well commented example! So I guess I want to say is: thanks a lot!

    Newbie

    3 Posts

  • #9, by MegaTinyTuesday, 25. November 2014, 01:39 10 years ago
    *what I want to say....

    Newbie

    3 Posts

  • #10, by afrlmeTuesday, 25. November 2014, 03:57 10 years ago
    err mate... this version is extremely extremely old! If you are working in Visionaire Studio 4+ then I recommend using my mkii 2 script.

    You really should check the wiki as I've added loads of scripts & examples to it.

    http://wiki.visionaire-tracker.net/wiki/Main_Page
    http://wiki.visionaire-tracker.net/wiki/Compiled_Index_of_Lu...

    It's technically possible to move an interface with a single line of code now thanks to the startObjectTween functions. The only reason I added additional lines to the mkii script was so that the speed would remain constant regardless of the interfaces open/close percentage when toggling it open or closed.

    Here's a quick example of how I'm opening the inventory interface of a game I'm currently helping develop.
    startObjectTween(Interfaces["int_inventory"], VInterfaceOffset, Interfaces["int_inventory"].InterfaceOffset, {x = 0, y = 0}, 1000, easeBounceOut) -- I'm sliding "int_inventory" interface to x0 & y0 over 1000ms (1s) with bounce easing on destination.
    

    ...the reason I am sliding to 0,0 is because the interface is hidden above the scene until I slide it down.

    P.S: Just checked the script on the pastebin link... damn I annotated the hell out of it! grin
    I tend to be a bit more sparse with the comments these days. I only comment certain parts.

    Imperator

    7278 Posts

  • #11, by unrealTuesday, 25. November 2014, 09:08 10 years ago
    Nice ! Is it possible to smooth the interface movements with easing functions ?

    Newbie

    66 Posts